import { useState } from 'react'; import { Table, Button, Modal, Form, Input, Select, Switch, Popconfirm, Tag } from 'antd'; import { PlusOutlined } from '@ant-design/icons'; import { useInjectionRules, useCreateInjectionRule, useDeleteInjectionRule, useToggleInjectionRule } from '../../application/useLLMGateway'; import type { InjectionRule } from '../../infrastructure/llm-gateway.api'; const { TextArea } = Input; export function InjectionRulesTab() { const { data, isLoading } = useInjectionRules(); const createMutation = useCreateInjectionRule(); const deleteMutation = useDeleteInjectionRule(); const toggleMutation = useToggleInjectionRule(); const [createOpen, setCreateOpen] = useState(false); const [form] = Form.useForm(); const handleCreate = async () => { const values = await form.validateFields(); await createMutation.mutateAsync(values); setCreateOpen(false); form.resetFields(); }; const columns = [ { title: '名称', dataIndex: 'name', key: 'name' }, { title: '位置', dataIndex: 'position', key: 'position', render: (v: string) => {v === 'prepend' ? '前置' : '追加'}, }, { title: '内容预览', dataIndex: 'content', key: 'content', ellipsis: true, width: 300, }, { title: '匹配模型', dataIndex: 'matchModels', key: 'matchModels', render: (v: string[]) => v?.includes('*') ? 全部 : v?.map((m: string) => {m}), }, { title: '状态', dataIndex: 'enabled', key: 'enabled', render: (v: boolean, record: InjectionRule) => ( toggleMutation.mutate(record.id)} /> ), }, { title: '操作', key: 'actions', render: (_: any, record: InjectionRule) => ( deleteMutation.mutate(record.id)}> ), }, ]; return ( <>
setCreateOpen(false)} confirmLoading={createMutation.isPending} width={600} >