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 <cursoragent@cursor.com>
This commit is contained in:
@@ -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<void>;
|
||||
updateForm: <K extends keyof AssistantForm>(
|
||||
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<PromptSectionId>("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 (
|
||||
<>
|
||||
<TopbarPortal>
|
||||
@@ -294,6 +315,42 @@ export function PromptEditor({
|
||||
onChange={(value) => updateForm("name", value)}
|
||||
/>
|
||||
<AssistantIdentity assistantId={assistantId} />
|
||||
{onDelete && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon-sm"
|
||||
className="border-hairline-strong text-muted-foreground hover:text-foreground"
|
||||
disabled={!assistantId || deleting}
|
||||
aria-label="更多操作"
|
||||
>
|
||||
{deleting ? (
|
||||
<Loader2 size={15} className="animate-spin" />
|
||||
) : (
|
||||
<MoreHorizontal size={15} />
|
||||
)}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
align="start"
|
||||
className="w-32 min-w-32 rounded-xl border border-hairline bg-popover p-1"
|
||||
>
|
||||
<DropdownMenuItem
|
||||
variant="destructive"
|
||||
className="rounded-lg"
|
||||
disabled={deleting}
|
||||
onSelect={(event) => {
|
||||
event.preventDefault();
|
||||
window.setTimeout(() => void handleDeleteSelect(), 0);
|
||||
}}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
删除
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user