diff --git a/webapp/packages/supersonic-fe/src/global.less b/webapp/packages/supersonic-fe/src/global.less index aa9cffb97..235288718 100644 --- a/webapp/packages/supersonic-fe/src/global.less +++ b/webapp/packages/supersonic-fe/src/global.less @@ -273,6 +273,12 @@ ol { .supersonicForm { padding: 0 20px; :global { + .ant-form-item-label { + .anticon { + position: relative; + top: 2px; + } + } .ant-input-search .ant-input-search-button { height: 42px; } diff --git a/webapp/packages/supersonic-fe/src/pages/Agent/AgentDetail.tsx b/webapp/packages/supersonic-fe/src/pages/Agent/AgentDetail.tsx new file mode 100644 index 000000000..8e6558f16 --- /dev/null +++ b/webapp/packages/supersonic-fe/src/pages/Agent/AgentDetail.tsx @@ -0,0 +1,53 @@ +import { ArrowLeftOutlined } from '@ant-design/icons'; +import { Switch } from 'antd'; +import styles from './style.less'; +import { AgentType } from './type'; +import AgentForm from './AgentForm'; + +type Props = { + currentAgent?: AgentType; + onSaveAgent: (agent: AgentType, noTip?: boolean) => Promise; + onCreateToolBtnClick?: () => void; + goBack: () => void; +}; + +const ToolsSection: React.FC = ({ + currentAgent, + onSaveAgent, + onCreateToolBtnClick, + goBack, +}) => { + return ( +
+
+ +
{currentAgent?.name}
+
+ {currentAgent?.status === 0 ? '已禁用' : 已启用} + { + e.stopPropagation(); + }} + > + { + onSaveAgent({ ...currentAgent, status: value ? 1 : 0 }, true); + }} + /> + +
+
+
+ +
+
+ ); +}; + +export default ToolsSection; diff --git a/webapp/packages/supersonic-fe/src/pages/Agent/AgentModal.tsx b/webapp/packages/supersonic-fe/src/pages/Agent/AgentForm.tsx similarity index 63% rename from webapp/packages/supersonic-fe/src/pages/Agent/AgentModal.tsx rename to webapp/packages/supersonic-fe/src/pages/Agent/AgentForm.tsx index 4a4bd27c4..efd9c4fd1 100644 --- a/webapp/packages/supersonic-fe/src/pages/Agent/AgentModal.tsx +++ b/webapp/packages/supersonic-fe/src/pages/Agent/AgentForm.tsx @@ -16,7 +16,8 @@ import { AgentType } from './type'; import { useEffect, useState } from 'react'; import styles from './style.less'; import { DeleteOutlined, PlusOutlined } from '@ant-design/icons'; -import { uuid } from '@/utils/utils'; +import { uuid, jsonParse } from '@/utils/utils'; +import ToolsSection from './ToolsSection'; import globalStyles from '@/global.less'; const FormItem = Form.Item; @@ -25,18 +26,27 @@ const { TextArea } = Input; type Props = { editAgent?: AgentType; onSaveAgent: (agent: AgentType) => Promise; - onCancel: () => void; + onCreateToolBtnClick?: () => void; }; -const AgentModal: React.FC = ({ editAgent, onSaveAgent, onCancel }) => { +const defaultAgentConfig = { + simpleMode: false, + debugMode: true, +}; + +const AgentForm: React.FC = ({ editAgent, onSaveAgent, onCreateToolBtnClick }) => { const [saveLoading, setSaveLoading] = useState(false); const [examples, setExamples] = useState<{ id: string; question?: string }[]>([]); + const [activeKey, setActiveKey] = useState('basic'); const [formData, setFormData] = useState({ enableSearch: true, llmConfig: { timeOut: 60, provider: 'OPEN_AI', }, + agentConfig: { + ...defaultAgentConfig, + }, }); const [form] = Form.useForm(); @@ -46,7 +56,14 @@ const AgentModal: React.FC = ({ editAgent, onSaveAgent, onCancel }) => { if (!sourceData.llmConfig) { delete sourceData.llmConfig; } - form.setFieldsValue({ ...sourceData, enableSearch: editAgent.enableSearch !== 0 }); + + const config = jsonParse(editAgent.agentConfig, {}); + + form.setFieldsValue({ + ...sourceData, + enableSearch: editAgent.enableSearch !== 0, + agentConfig: { ...defaultAgentConfig, ...config }, + }); if (editAgent.examples) { setExamples(editAgent.examples.map((question) => ({ id: uuid(), question }))); } @@ -56,7 +73,7 @@ const AgentModal: React.FC = ({ editAgent, onSaveAgent, onCancel }) => { }, [editAgent]); const layout = { - labelCol: { span: 6 }, + labelCol: { span: 4 }, wrapperCol: { span: 16 }, // layout: 'vertical', }; @@ -64,10 +81,12 @@ const AgentModal: React.FC = ({ editAgent, onSaveAgent, onCancel }) => { const onOk = async () => { const values = await form.validateFields(); setSaveLoading(true); - await onSaveAgent({ + const config = jsonParse(editAgent?.agentConfig, {}); + await onSaveAgent?.({ id: editAgent?.id, ...(editAgent || {}), ...values, + agentConfig: JSON.stringify({ ...config, ...values.agentConfig }) as any, examples: examples.map((example) => example.question), enableSearch: values.enableSearch ? 1 : 0, }); @@ -77,8 +96,9 @@ const AgentModal: React.FC = ({ editAgent, onSaveAgent, onCancel }) => { const formTabList = [ { label: '基本信息', + key: 'basic', children: ( - <> +
= ({ editAgent, onSaveAgent, onCancel }) => { + + + + + + + +
{examples.map((example) => { @@ -153,14 +191,15 @@ const AgentModal: React.FC = ({ editAgent, onSaveAgent, onCancel }) => {