fix: 修复 KnowledgeSettingsPanel 崩溃并优化工具集复制为纯前端操作
parent
16051c1f7a
commit
7f5b7f0537
|
|
@ -57,6 +57,7 @@ export interface ExternalToolPlugin extends ExternalToolPluginPayload {
|
||||||
id: string;
|
id: string;
|
||||||
enabled: number;
|
enabled: number;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
|
isTemp?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Agent {
|
export interface Agent {
|
||||||
|
|
|
||||||
|
|
@ -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);
|
await AgentAPI.updatePlugin(agentId, plugin.id, payload);
|
||||||
message.success('外部工具更新成功');
|
message.success('外部工具更新成功');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -213,13 +213,13 @@ export default function KnowledgeSettingsPanel({
|
||||||
<Space size={6} wrap className="agent-editor-plugin-meta">
|
<Space size={6} wrap className="agent-editor-plugin-meta">
|
||||||
<Tag>{plugin.authType || 'none'}</Tag>
|
<Tag>{plugin.authType || 'none'}</Tag>
|
||||||
<span>{plugin.baseUrl}</span>
|
<span>{plugin.baseUrl}</span>
|
||||||
<span>{plugin.apis.length} 个 API</span>
|
<span>{plugin.apis?.length ?? 0} 个 API</span>
|
||||||
</Space>
|
</Space>
|
||||||
<Collapse
|
<Collapse
|
||||||
ghost
|
ghost
|
||||||
size="small"
|
size="small"
|
||||||
className="agent-editor-plugin-apis"
|
className="agent-editor-plugin-apis"
|
||||||
items={plugin.apis.map((api) => ({
|
items={plugin.apis?.map((api) => ({
|
||||||
key: api.id || api.name,
|
key: api.id || api.name,
|
||||||
label: (
|
label: (
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
|
|
@ -243,7 +243,7 @@ export default function KnowledgeSettingsPanel({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
}))}
|
})) || []}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
))}
|
))}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
if (!id || !agent) return;
|
||||||
const plugin = agent.plugins?.find((p) => p.id === pluginId);
|
const plugin = agent.plugins?.find((p) => p.id === pluginId);
|
||||||
if (!plugin) return;
|
if (!plugin) return;
|
||||||
|
|
||||||
try {
|
const newPlugin = {
|
||||||
const copyPayload = {
|
...plugin,
|
||||||
name: `${plugin.name}-copy`,
|
id: `temp_${Date.now()}`,
|
||||||
description: plugin.description,
|
name: `${plugin.name}-copy`,
|
||||||
baseUrl: plugin.baseUrl,
|
apis: plugin.apis?.map((api) => ({
|
||||||
authType: plugin.authType,
|
...api,
|
||||||
authConfig: plugin.authConfig,
|
name: `${api.name}-copy`,
|
||||||
apis: plugin.apis.map((api) => ({
|
id: undefined,
|
||||||
name: `${api.name}-copy`,
|
})) || [],
|
||||||
description: api.description,
|
isTemp: true,
|
||||||
method: api.method,
|
};
|
||||||
path: api.path,
|
|
||||||
headers: api.headers,
|
setAgent((prev) => {
|
||||||
parametersSchema: api.parametersSchema,
|
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 newPlugin;
|
||||||
return {
|
|
||||||
...prev,
|
|
||||||
plugins: [...(prev.plugins || []), newPlugin],
|
|
||||||
};
|
|
||||||
});
|
|
||||||
message.success('外部工具复制成功');
|
|
||||||
return newPlugin;
|
|
||||||
} catch (e: any) {
|
|
||||||
message.error('外部工具复制失败:' + (e?.message ?? e));
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const beforeUploadKnowledge = async (file: any) => {
|
const beforeUploadKnowledge = async (file: any) => {
|
||||||
|
|
|
||||||
|
|
@ -104,15 +104,11 @@ export default function AgentEditor() {
|
||||||
setEditingPluginId(null);
|
setEditingPluginId(null);
|
||||||
setExternalToolEditorOpen(true);
|
setExternalToolEditorOpen(true);
|
||||||
}}
|
}}
|
||||||
onCopyExternalTool={async (pluginId) => {
|
onCopyExternalTool={(pluginId) => {
|
||||||
try {
|
const newPlugin = handleCopyPlugin(pluginId);
|
||||||
const newPlugin = await handleCopyPlugin(pluginId);
|
if (newPlugin) {
|
||||||
if (newPlugin) {
|
setEditingPluginId(newPlugin.id);
|
||||||
setEditingPluginId(newPlugin.id);
|
setExternalToolEditorOpen(true);
|
||||||
setExternalToolEditorOpen(true);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// error handled in hook
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onEditExternalTool={(pluginId) => {
|
onEditExternalTool={(pluginId) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue