diff --git a/src/components/ExternalToolEditor.tsx b/src/components/ExternalToolEditor.tsx index 51e06fa..fda230c 100644 --- a/src/components/ExternalToolEditor.tsx +++ b/src/components/ExternalToolEditor.tsx @@ -1,5 +1,5 @@ import { CopyOutlined, DownOutlined, MinusCircleOutlined, PlusOutlined, RightOutlined } from '@ant-design/icons'; -import { App as AntApp, Button, Card, Form, Input, Modal, Select, Space } from 'antd'; +import { App as AntApp, Button, Card, Form, Input, Modal, Select, Space, Tabs } from 'antd'; import { useEffect, useRef, useState } from 'react'; import { AgentAPI, ExternalToolApi, ExternalToolApiRouting, ExternalToolPlugin, ExternalToolPluginPayload } from '../api'; @@ -150,9 +150,19 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS const [form] = Form.useForm(); const isEditing = Boolean(plugin); const apis = Form.useWatch('apis', form) || []; + const allValues = Form.useWatch([], form); const [expandedApiIndexes, setExpandedApiIndexes] = useState([]); + const [jsonContent, setJsonContent] = useState(''); + const [activeTab, setActiveTab] = useState('visual'); + const [isSyncing, setIsSyncing] = useState(false); const previousApiCountRef = useRef(0); + useEffect(() => { + if (allValues && !isSyncing) { + setJsonContent(JSON.stringify(allValues, null, 2)); + } + }, [allValues, isSyncing]); + useEffect(() => { if (!open) { previousApiCountRef.current = 0; @@ -181,6 +191,21 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS previousApiCountRef.current = apiCount; }, [apis.length, open]); + const handleJsonChange = (e: React.ChangeEvent) => { + const val = e.target.value; + setJsonContent(val); + try { + const parsed = JSON.parse(val); + if (parsed && typeof parsed === 'object') { + setIsSyncing(true); + form.setFieldsValue(parsed); + setTimeout(() => setIsSyncing(false), 0); + } + } catch (e) { + // 格式不正确时不更新表单 + } + }; + const toggleApiCard = (index: number) => { setExpandedApiIndexes((current) => current.includes(index) ? current.filter((item) => item !== index) : [...current, index], @@ -280,265 +305,298 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS } }} > -
-
- - - - - - -
- - - - - - -
- - + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + {(routingFields, { add: addUseWhen, remove: removeUseWhen }, { errors }) => ( + +
+
+ useWhen +
至少一项,描述什么情况下应该调用这个 API。
+
+ +
+ {routingFields.map((routingField) => ( + + + + + +
+ {routingFields.map((routingField) => ( + + + + + + + {exampleFields.map((exampleField) => ( + + + + + - - {routingFields.map((routingField) => ( - - - - - - - {routingFields.map((routingField) => ( - - - - - - - {exampleFields.map((exampleField) => ( - - - - -