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 { 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);
|
||||
message.success('外部工具更新成功');
|
||||
} else {
|
||||
|
|
@ -215,11 +215,30 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS
|
|||
title={`API ${index + 1}`}
|
||||
className="agent-editor-tool-card"
|
||||
extra={
|
||||
fields.length > 1 ? (
|
||||
<Button type="text" danger icon={<MinusCircleOutlined />} onClick={() => remove(field.name)}>
|
||||
<Space>
|
||||
<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>
|
||||
) : null
|
||||
) : null}
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<div className="agent-editor-tool-grid">
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ interface CapabilitySettingsProps {
|
|||
onEditSkill: (skillId: string) => void;
|
||||
onDeleteSkill: (skillId: string) => Promise<void>;
|
||||
onCreateExternalTool: () => void;
|
||||
onCopyExternalTool: (pluginId: string) => void;
|
||||
onEditExternalTool: (pluginId: string) => void;
|
||||
onDeleteExternalTool: (pluginId: string) => Promise<void>;
|
||||
markDirty: () => void;
|
||||
|
|
@ -43,7 +42,6 @@ export default function CapabilitySettings({
|
|||
onEditSkill,
|
||||
onDeleteSkill,
|
||||
onCreateExternalTool,
|
||||
onCopyExternalTool,
|
||||
onEditExternalTool,
|
||||
onDeleteExternalTool,
|
||||
markDirty,
|
||||
|
|
@ -80,7 +78,6 @@ export default function CapabilitySettings({
|
|||
onEditSkill={onEditSkill}
|
||||
onDeleteSkill={onDeleteSkill}
|
||||
onCreateExternalTool={onCreateExternalTool}
|
||||
onCopyExternalTool={onCopyExternalTool}
|
||||
onEditExternalTool={onEditExternalTool}
|
||||
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 { Agent } from '../../../../api';
|
||||
import { STATUS_TAG } from '../../constants';
|
||||
|
|
@ -11,7 +11,6 @@ interface KnowledgeSettingsPanelProps {
|
|||
onEditSkill: (skillId: string) => void;
|
||||
onDeleteSkill: (skillId: string) => Promise<void>;
|
||||
onCreateExternalTool: () => void;
|
||||
onCopyExternalTool: (pluginId: string) => void;
|
||||
onEditExternalTool: (pluginId: string) => void;
|
||||
onDeleteExternalTool: (pluginId: string) => Promise<void>;
|
||||
}
|
||||
|
|
@ -24,7 +23,6 @@ export default function KnowledgeSettingsPanel({
|
|||
onEditSkill,
|
||||
onDeleteSkill,
|
||||
onCreateExternalTool,
|
||||
onCopyExternalTool,
|
||||
onEditExternalTool,
|
||||
onDeleteExternalTool,
|
||||
}: KnowledgeSettingsPanelProps) {
|
||||
|
|
@ -195,9 +193,6 @@ export default function KnowledgeSettingsPanel({
|
|||
}
|
||||
extra={
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -236,10 +236,6 @@ 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);
|
||||
|
|
@ -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) => {
|
||||
if (!id) {
|
||||
message.warning('请先保存智能体基础信息后再上传');
|
||||
|
|
@ -394,8 +352,6 @@ export function useAgentEditor({ id, isNew, form, message, navigate }: UseAgentE
|
|||
handleDeleteKnowledge,
|
||||
handleDeleteSkill,
|
||||
handleDeletePlugin,
|
||||
handleCopyPlugin,
|
||||
cleanupTempPlugins,
|
||||
liveAgent,
|
||||
currentName,
|
||||
markDirty,
|
||||
|
|
|
|||
|
|
@ -57,8 +57,6 @@ export default function AgentEditor() {
|
|||
handleDeleteKnowledge,
|
||||
handleDeleteSkill,
|
||||
handleDeletePlugin,
|
||||
handleCopyPlugin,
|
||||
cleanupTempPlugins,
|
||||
liveAgent,
|
||||
currentName,
|
||||
markDirty,
|
||||
|
|
@ -105,13 +103,6 @@ export default function AgentEditor() {
|
|||
setEditingPluginId(null);
|
||||
setExternalToolEditorOpen(true);
|
||||
}}
|
||||
onCopyExternalTool={(pluginId) => {
|
||||
const newPlugin = handleCopyPlugin(pluginId);
|
||||
if (newPlugin) {
|
||||
setEditingPluginId(newPlugin.id);
|
||||
setExternalToolEditorOpen(true);
|
||||
}
|
||||
}}
|
||||
onEditExternalTool={(pluginId) => {
|
||||
setEditingPluginId(pluginId);
|
||||
setExternalToolEditorOpen(true);
|
||||
|
|
@ -170,7 +161,6 @@ export default function AgentEditor() {
|
|||
onClose={() => {
|
||||
setExternalToolEditorOpen(false);
|
||||
setEditingPluginId(null);
|
||||
cleanupTempPlugins();
|
||||
}}
|
||||
onSaved={refresh}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue