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) => {