From 7f5b7f05374b508a6fb657641c5a00d6235c1550 Mon Sep 17 00:00:00 2001 From: sp mac bookpro 2605 Date: Wed, 22 Jul 2026 14:01:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20KnowledgeSettingsPa?= =?UTF-8?q?nel=20=E5=B4=A9=E6=BA=83=E5=B9=B6=E4=BC=98=E5=8C=96=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E9=9B=86=E5=A4=8D=E5=88=B6=E4=B8=BA=E7=BA=AF=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/agents.ts | 1 + src/components/ExternalToolEditor.tsx | 2 +- .../capability/KnowledgeSettingsPanel.tsx | 6 +-- src/pages/AgentEditor/hooks/useAgentEditor.ts | 51 ++++++++----------- src/pages/AgentEditor/index.tsx | 14 ++--- 5 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/api/agents.ts b/src/api/agents.ts index 90cfbcb..fdc29bf 100644 --- a/src/api/agents.ts +++ b/src/api/agents.ts @@ -57,6 +57,7 @@ export interface ExternalToolPlugin extends ExternalToolPluginPayload { id: string; enabled: number; createdAt: number; + isTemp?: boolean; } export interface Agent { diff --git a/src/components/ExternalToolEditor.tsx b/src/components/ExternalToolEditor.tsx index 851ddd6..b6069fc 100644 --- a/src/components/ExternalToolEditor.tsx +++ b/src/components/ExternalToolEditor.tsx @@ -107,7 +107,7 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS })), }; - if (plugin) { + if (plugin && !plugin.id.startsWith('temp_')) { await AgentAPI.updatePlugin(agentId, plugin.id, payload); message.success('外部工具更新成功'); } else { diff --git a/src/pages/AgentEditor/components/capability/KnowledgeSettingsPanel.tsx b/src/pages/AgentEditor/components/capability/KnowledgeSettingsPanel.tsx index 8f7823e..5356001 100644 --- a/src/pages/AgentEditor/components/capability/KnowledgeSettingsPanel.tsx +++ b/src/pages/AgentEditor/components/capability/KnowledgeSettingsPanel.tsx @@ -213,13 +213,13 @@ export default function KnowledgeSettingsPanel({ {plugin.authType || 'none'} {plugin.baseUrl} - {plugin.apis.length} 个 API + {plugin.apis?.length ?? 0} 个 API ({ + items={plugin.apis?.map((api) => ({ key: api.id || api.name, label: ( @@ -243,7 +243,7 @@ export default function KnowledgeSettingsPanel({ ), - }))} + })) || []} /> ))} diff --git a/src/pages/AgentEditor/hooks/useAgentEditor.ts b/src/pages/AgentEditor/hooks/useAgentEditor.ts index b10c3db..3b82dd1 100644 --- a/src/pages/AgentEditor/hooks/useAgentEditor.ts +++ b/src/pages/AgentEditor/hooks/useAgentEditor.ts @@ -245,41 +245,32 @@ export function useAgentEditor({ id, isNew, form, message, navigate }: UseAgentE } }; - const handleCopyPlugin = async (pluginId: string) => { + const handleCopyPlugin = (pluginId: string) => { if (!id || !agent) return; const plugin = agent.plugins?.find((p) => p.id === pluginId); if (!plugin) return; - try { - const copyPayload = { - name: `${plugin.name}-copy`, - description: plugin.description, - baseUrl: plugin.baseUrl, - authType: plugin.authType, - authConfig: plugin.authConfig, - apis: plugin.apis.map((api) => ({ - name: `${api.name}-copy`, - description: api.description, - method: api.method, - path: api.path, - headers: api.headers, - parametersSchema: api.parametersSchema, - })), + const newPlugin = { + ...plugin, + id: `temp_${Date.now()}`, + name: `${plugin.name}-copy`, + apis: plugin.apis?.map((api) => ({ + ...api, + name: `${api.name}-copy`, + id: undefined, + })) || [], + isTemp: true, + }; + + setAgent((prev) => { + if (!prev) return prev; + return { + ...prev, + plugins: [...(prev.plugins || []), newPlugin], }; - const newPlugin = await AgentAPI.bindPlugin(id, copyPayload as any); - setAgent((prev) => { - if (!prev) return prev; - return { - ...prev, - plugins: [...(prev.plugins || []), newPlugin], - }; - }); - message.success('外部工具复制成功'); - return newPlugin; - } catch (e: any) { - message.error('外部工具复制失败:' + (e?.message ?? e)); - throw e; - } + }); + + return newPlugin; }; const beforeUploadKnowledge = async (file: any) => { diff --git a/src/pages/AgentEditor/index.tsx b/src/pages/AgentEditor/index.tsx index 87a714a..a2a5475 100644 --- a/src/pages/AgentEditor/index.tsx +++ b/src/pages/AgentEditor/index.tsx @@ -104,15 +104,11 @@ export default function AgentEditor() { setEditingPluginId(null); setExternalToolEditorOpen(true); }} - onCopyExternalTool={async (pluginId) => { - try { - const newPlugin = await handleCopyPlugin(pluginId); - if (newPlugin) { - setEditingPluginId(newPlugin.id); - setExternalToolEditorOpen(true); - } - } catch (e) { - // error handled in hook + onCopyExternalTool={(pluginId) => { + const newPlugin = handleCopyPlugin(pluginId); + if (newPlugin) { + setEditingPluginId(newPlugin.id); + setExternalToolEditorOpen(true); } }} onEditExternalTool={(pluginId) => {