feat: 移除复制工具集功能,新增 API 级别复制功能
parent
c02c83083d
commit
5f947b4d64
|
|
@ -1,4 +1,4 @@
|
||||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
import { CopyOutlined, MinusCircleOutlined, PlusOutlined } 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 } from 'antd';
|
||||||
import { AgentAPI, ExternalToolApi, ExternalToolPlugin, ExternalToolPluginPayload } from '../api';
|
import { AgentAPI, ExternalToolApi, ExternalToolPlugin, ExternalToolPluginPayload } from '../api';
|
||||||
|
|
||||||
|
|
@ -107,7 +107,7 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (plugin && !plugin.id.startsWith('temp_')) {
|
if (plugin) {
|
||||||
await AgentAPI.updatePlugin(agentId, plugin.id, payload);
|
await AgentAPI.updatePlugin(agentId, plugin.id, payload);
|
||||||
message.success('外部工具更新成功');
|
message.success('外部工具更新成功');
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -215,11 +215,30 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS
|
||||||
title={`API ${index + 1}`}
|
title={`API ${index + 1}`}
|
||||||
className="agent-editor-tool-card"
|
className="agent-editor-tool-card"
|
||||||
extra={
|
extra={
|
||||||
fields.length > 1 ? (
|
<Space>
|
||||||
<Button type="text" danger icon={<MinusCircleOutlined />} onClick={() => remove(field.name)}>
|
<Button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
icon={<CopyOutlined />}
|
||||||
|
onClick={() => {
|
||||||
|
const currentApis = form.getFieldValue('apis') || [];
|
||||||
|
const apiToCopy = currentApis[field.name];
|
||||||
|
if (apiToCopy) {
|
||||||
|
add({
|
||||||
|
...apiToCopy,
|
||||||
|
name: `${apiToCopy.name}-copy`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
复制
|
||||||
|
</Button>
|
||||||
|
{fields.length > 1 ? (
|
||||||
|
<Button type="text" danger size="small" icon={<MinusCircleOutlined />} onClick={() => remove(field.name)}>
|
||||||
删除
|
删除
|
||||||
</Button>
|
</Button>
|
||||||
) : null
|
) : null}
|
||||||
|
</Space>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className="agent-editor-tool-grid">
|
<div className="agent-editor-tool-grid">
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ interface CapabilitySettingsProps {
|
||||||
onEditSkill: (skillId: string) => void;
|
onEditSkill: (skillId: string) => void;
|
||||||
onDeleteSkill: (skillId: string) => Promise<void>;
|
onDeleteSkill: (skillId: string) => Promise<void>;
|
||||||
onCreateExternalTool: () => void;
|
onCreateExternalTool: () => void;
|
||||||
onCopyExternalTool: (pluginId: string) => void;
|
|
||||||
onEditExternalTool: (pluginId: string) => void;
|
onEditExternalTool: (pluginId: string) => void;
|
||||||
onDeleteExternalTool: (pluginId: string) => Promise<void>;
|
onDeleteExternalTool: (pluginId: string) => Promise<void>;
|
||||||
markDirty: () => void;
|
markDirty: () => void;
|
||||||
|
|
@ -43,7 +42,6 @@ export default function CapabilitySettings({
|
||||||
onEditSkill,
|
onEditSkill,
|
||||||
onDeleteSkill,
|
onDeleteSkill,
|
||||||
onCreateExternalTool,
|
onCreateExternalTool,
|
||||||
onCopyExternalTool,
|
|
||||||
onEditExternalTool,
|
onEditExternalTool,
|
||||||
onDeleteExternalTool,
|
onDeleteExternalTool,
|
||||||
markDirty,
|
markDirty,
|
||||||
|
|
@ -80,7 +78,6 @@ export default function CapabilitySettings({
|
||||||
onEditSkill={onEditSkill}
|
onEditSkill={onEditSkill}
|
||||||
onDeleteSkill={onDeleteSkill}
|
onDeleteSkill={onDeleteSkill}
|
||||||
onCreateExternalTool={onCreateExternalTool}
|
onCreateExternalTool={onCreateExternalTool}
|
||||||
onCopyExternalTool={onCopyExternalTool}
|
|
||||||
onEditExternalTool={onEditExternalTool}
|
onEditExternalTool={onEditExternalTool}
|
||||||
onDeleteExternalTool={onDeleteExternalTool}
|
onDeleteExternalTool={onDeleteExternalTool}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { ApiOutlined, CopyOutlined, DatabaseOutlined, DeleteOutlined, EditOutlined, PlusOutlined, ToolOutlined } from '@ant-design/icons';
|
import { ApiOutlined, DatabaseOutlined, DeleteOutlined, EditOutlined, PlusOutlined, ToolOutlined } from '@ant-design/icons';
|
||||||
import { Button, Card, Collapse, Input, List, Popconfirm, Space, Tag } from 'antd';
|
import { Button, Card, Collapse, Input, List, Popconfirm, Space, Tag } from 'antd';
|
||||||
import { Agent } from '../../../../api';
|
import { Agent } from '../../../../api';
|
||||||
import { STATUS_TAG } from '../../constants';
|
import { STATUS_TAG } from '../../constants';
|
||||||
|
|
@ -11,7 +11,6 @@ interface KnowledgeSettingsPanelProps {
|
||||||
onEditSkill: (skillId: string) => void;
|
onEditSkill: (skillId: string) => void;
|
||||||
onDeleteSkill: (skillId: string) => Promise<void>;
|
onDeleteSkill: (skillId: string) => Promise<void>;
|
||||||
onCreateExternalTool: () => void;
|
onCreateExternalTool: () => void;
|
||||||
onCopyExternalTool: (pluginId: string) => void;
|
|
||||||
onEditExternalTool: (pluginId: string) => void;
|
onEditExternalTool: (pluginId: string) => void;
|
||||||
onDeleteExternalTool: (pluginId: string) => Promise<void>;
|
onDeleteExternalTool: (pluginId: string) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +23,6 @@ export default function KnowledgeSettingsPanel({
|
||||||
onEditSkill,
|
onEditSkill,
|
||||||
onDeleteSkill,
|
onDeleteSkill,
|
||||||
onCreateExternalTool,
|
onCreateExternalTool,
|
||||||
onCopyExternalTool,
|
|
||||||
onEditExternalTool,
|
onEditExternalTool,
|
||||||
onDeleteExternalTool,
|
onDeleteExternalTool,
|
||||||
}: KnowledgeSettingsPanelProps) {
|
}: KnowledgeSettingsPanelProps) {
|
||||||
|
|
@ -195,9 +193,6 @@ export default function KnowledgeSettingsPanel({
|
||||||
}
|
}
|
||||||
extra={
|
extra={
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="text" size="small" icon={<CopyOutlined />} onClick={() => onCopyExternalTool(plugin.id)}>
|
|
||||||
复制
|
|
||||||
</Button>
|
|
||||||
<Button type="text" size="small" icon={<EditOutlined />} onClick={() => onEditExternalTool(plugin.id)}>
|
<Button type="text" size="small" icon={<EditOutlined />} onClick={() => onEditExternalTool(plugin.id)}>
|
||||||
编辑
|
编辑
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -236,10 +236,6 @@ export function useAgentEditor({ id, isNew, form, message, navigate }: UseAgentE
|
||||||
|
|
||||||
const handleDeletePlugin = async (pluginId: string) => {
|
const handleDeletePlugin = async (pluginId: string) => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
if (pluginId.startsWith('temp_')) {
|
|
||||||
setAgent((prev) => prev ? { ...prev, plugins: (prev.plugins || []).filter((plugin) => plugin.id !== pluginId) } : prev);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await AgentAPI.deletePlugin(id, pluginId);
|
await AgentAPI.deletePlugin(id, pluginId);
|
||||||
setAgent((prev) => prev ? { ...prev, plugins: (prev.plugins || []).filter((plugin) => plugin.id !== pluginId) } : prev);
|
setAgent((prev) => prev ? { ...prev, plugins: (prev.plugins || []).filter((plugin) => plugin.id !== pluginId) } : prev);
|
||||||
|
|
@ -249,44 +245,6 @@ export function useAgentEditor({ id, isNew, form, message, navigate }: UseAgentE
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCopyPlugin = (pluginId: string) => {
|
|
||||||
if (!id || !agent) return;
|
|
||||||
const plugin = agent.plugins?.find((p) => p.id === pluginId);
|
|
||||||
if (!plugin) return;
|
|
||||||
|
|
||||||
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],
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
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) => {
|
const beforeUploadKnowledge = async (file: any) => {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
message.warning('请先保存智能体基础信息后再上传');
|
message.warning('请先保存智能体基础信息后再上传');
|
||||||
|
|
@ -394,8 +352,6 @@ export function useAgentEditor({ id, isNew, form, message, navigate }: UseAgentE
|
||||||
handleDeleteKnowledge,
|
handleDeleteKnowledge,
|
||||||
handleDeleteSkill,
|
handleDeleteSkill,
|
||||||
handleDeletePlugin,
|
handleDeletePlugin,
|
||||||
handleCopyPlugin,
|
|
||||||
cleanupTempPlugins,
|
|
||||||
liveAgent,
|
liveAgent,
|
||||||
currentName,
|
currentName,
|
||||||
markDirty,
|
markDirty,
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,6 @@ export default function AgentEditor() {
|
||||||
handleDeleteKnowledge,
|
handleDeleteKnowledge,
|
||||||
handleDeleteSkill,
|
handleDeleteSkill,
|
||||||
handleDeletePlugin,
|
handleDeletePlugin,
|
||||||
handleCopyPlugin,
|
|
||||||
cleanupTempPlugins,
|
|
||||||
liveAgent,
|
liveAgent,
|
||||||
currentName,
|
currentName,
|
||||||
markDirty,
|
markDirty,
|
||||||
|
|
@ -105,13 +103,6 @@ export default function AgentEditor() {
|
||||||
setEditingPluginId(null);
|
setEditingPluginId(null);
|
||||||
setExternalToolEditorOpen(true);
|
setExternalToolEditorOpen(true);
|
||||||
}}
|
}}
|
||||||
onCopyExternalTool={(pluginId) => {
|
|
||||||
const newPlugin = handleCopyPlugin(pluginId);
|
|
||||||
if (newPlugin) {
|
|
||||||
setEditingPluginId(newPlugin.id);
|
|
||||||
setExternalToolEditorOpen(true);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onEditExternalTool={(pluginId) => {
|
onEditExternalTool={(pluginId) => {
|
||||||
setEditingPluginId(pluginId);
|
setEditingPluginId(pluginId);
|
||||||
setExternalToolEditorOpen(true);
|
setExternalToolEditorOpen(true);
|
||||||
|
|
@ -170,7 +161,6 @@ export default function AgentEditor() {
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setExternalToolEditorOpen(false);
|
setExternalToolEditorOpen(false);
|
||||||
setEditingPluginId(null);
|
setEditingPluginId(null);
|
||||||
cleanupTempPlugins();
|
|
||||||
}}
|
}}
|
||||||
onSaved={refresh}
|
onSaved={refresh}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue