fix: 复制工具集后若取消编辑则移除临时副本

main
sp mac bookpro 2605 2026-07-22 14:13:26 +08:00
parent 7f5b7f0537
commit c02c83083d
2 changed files with 22 additions and 5 deletions

View File

@ -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,

View File

@ -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}
/>
</>
)}