From 723ee84925a1c5e803f2e5ac5d36e3179ca532b2 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Thu, 6 Aug 2026 17:08:40 +0800 Subject: [PATCH] feat(frontend): add assistant delete menu to prompt editor topbar Place a more-actions dropdown beside the assistant ID with confirmed delete that returns to the assistant list after removal. Co-authored-by: Cursor --- .../assistant-editor/prompt-editor.tsx | 57 +++++++++++++++++++ .../src/components/pages/AssistantPage.tsx | 14 +++++ 2 files changed, 71 insertions(+) diff --git a/frontend/src/components/assistant-editor/prompt-editor.tsx b/frontend/src/components/assistant-editor/prompt-editor.tsx index 214580e..261dcfd 100644 --- a/frontend/src/components/assistant-editor/prompt-editor.tsx +++ b/frontend/src/components/assistant-editor/prompt-editor.tsx @@ -18,8 +18,10 @@ import { Database, Loader2, MessageSquareText, + MoreHorizontal, Save, Sparkles, + Trash2, Webhook, Wrench, } from "lucide-react"; @@ -45,6 +47,12 @@ import { SectionCard } from "@/components/editor/section-card"; import { VisionConfigSection } from "@/components/editor/vision-config-section"; import { TurnConfigEditor } from "@/components/turn-config-editor"; import { Button } from "@/components/ui/button"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; import { TopbarPortal } from "@/components/layout/topbar-portal"; import { Input } from "@/components/ui/input"; import { @@ -118,6 +126,7 @@ type PromptEditorProps = { tools: Tool[]; onBack: () => void; onSave: () => void; + onDelete?: () => void | Promise; updateForm: ( key: K, value: AssistantForm[K], @@ -142,6 +151,7 @@ export function PromptEditor({ tools, onBack, onSave, + onDelete, updateForm, handlePromptVisionEnabledChange, handlePromptModelChange, @@ -171,6 +181,7 @@ export function PromptEditor({ const [activeSection, setActiveSection] = useState("conversation"); const [debugOpen, setDebugOpen] = useState(true); + const [deleting, setDeleting] = useState(false); useEffect(() => { const container = scrollContainerRef.current; @@ -283,6 +294,16 @@ export function PromptEditor({ }); } + async function handleDeleteSelect() { + if (!onDelete || deleting) return; + setDeleting(true); + try { + await onDelete(); + } finally { + setDeleting(false); + } + } + return ( <> @@ -294,6 +315,42 @@ export function PromptEditor({ onChange={(value) => updateForm("name", value)} /> + {onDelete && ( + + + + + + { + event.preventDefault(); + window.setTimeout(() => void handleDeleteSelect(), 0); + }} + > + + 删除 + + + + )}
diff --git a/frontend/src/components/pages/AssistantPage.tsx b/frontend/src/components/pages/AssistantPage.tsx index 33ad705..ea9cb88 100644 --- a/frontend/src/components/pages/AssistantPage.tsx +++ b/frontend/src/components/pages/AssistantPage.tsx @@ -639,6 +639,19 @@ export function AssistantPage(props: AssistantPageProps) { ); } + async function handleDeleteCurrentAssistant() { + if (!editingId) return; + const assistantName = form.name.trim() || "未命名助手"; + if (!window.confirm(`确认删除助手“${assistantName}”?`)) return; + setSaveError(null); + try { + await assistantsApi.remove(editingId); + router.push("/assistants"); + } catch (error) { + setSaveError(error instanceof Error ? error.message : "删除失败"); + } + } + // ---- 外部智能体平台(Dify / FastGPT)---- function fillAgentPlatformForm(a: Assistant): AgentPlatformForm { const next: AgentPlatformForm = { @@ -1611,6 +1624,7 @@ export function AssistantPage(props: AssistantPageProps) { tools={tools} onBack={() => router.push("/assistants")} onSave={() => void handleSavePrompt()} + onDelete={() => void handleDeleteCurrentAssistant()} updateForm={updateForm} handlePromptVisionEnabledChange={handlePromptVisionEnabledChange} handlePromptModelChange={handlePromptModelChange}