diff --git a/src/pages/AgentEditor/hooks/useAgentEditor.ts b/src/pages/AgentEditor/hooks/useAgentEditor.ts index 3b82dd1..a3f5ebf 100644 --- a/src/pages/AgentEditor/hooks/useAgentEditor.ts +++ b/src/pages/AgentEditor/hooks/useAgentEditor.ts @@ -236,6 +236,10 @@ export function useAgentEditor({ id, isNew, form, message, navigate }: UseAgentE const handleDeletePlugin = async (pluginId: string) => { if (!id) return; + if (pluginId.startsWith('temp_')) { + setAgent((prev) => prev ? { ...prev, plugins: (prev.plugins || []).filter((plugin) => plugin.id !== pluginId) } : prev); + return; + } try { await AgentAPI.deletePlugin(id, pluginId); setAgent((prev) => prev ? { ...prev, plugins: (prev.plugins || []).filter((plugin) => plugin.id !== pluginId) } : prev); @@ -273,6 +277,16 @@ export function useAgentEditor({ id, isNew, form, message, navigate }: UseAgentE return newPlugin; }; + const cleanupTempPlugins = () => { + setAgent((prev) => { + if (!prev) return prev; + return { + ...prev, + plugins: (prev.plugins || []).filter((p) => !p.id.startsWith('temp_')), + }; + }); + }; + const beforeUploadKnowledge = async (file: any) => { if (!id) { message.warning('请先保存智能体基础信息后再上传'); @@ -381,6 +395,7 @@ export function useAgentEditor({ id, isNew, form, message, navigate }: UseAgentE handleDeleteSkill, handleDeletePlugin, handleCopyPlugin, + cleanupTempPlugins, liveAgent, currentName, markDirty, diff --git a/src/pages/AgentEditor/index.tsx b/src/pages/AgentEditor/index.tsx index a2a5475..0c90c63 100644 --- a/src/pages/AgentEditor/index.tsx +++ b/src/pages/AgentEditor/index.tsx @@ -58,6 +58,7 @@ export default function AgentEditor() { handleDeleteSkill, handleDeletePlugin, handleCopyPlugin, + cleanupTempPlugins, liveAgent, currentName, markDirty, @@ -166,11 +167,12 @@ export default function AgentEditor() { open={externalToolEditorOpen} agentId={id!} plugin={agent?.plugins?.find((plugin) => plugin.id === editingPluginId)} - onClose={() => { - setExternalToolEditorOpen(false); - setEditingPluginId(null); - }} - onSaved={refresh} + onClose={() => { + setExternalToolEditorOpen(false); + setEditingPluginId(null); + cleanupTempPlugins(); + }} + onSaved={refresh} /> )}