Files
buzz/desktop/src/features/agents/ui/PersonaDeleteDialog.tsx
Tyler 4d58deafaa Archive managed agents when deleted (#2135)
Signed-off-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co>
Signed-off-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co>
2026-07-20 08:03:57 -07:00

87 lines
2.7 KiB
TypeScript

import type { AgentPersona } from "@/shared/api/types";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/shared/ui/alert-dialog";
import { Button } from "@/shared/ui/button";
type PersonaDeleteDialogProps = {
open: boolean;
persona: AgentPersona | null;
/** Number of managed-agent instances backed by this persona. Omit or pass 0 to suppress the instance-count sentence. */
instanceCount?: number;
onConfirm: (persona: AgentPersona) => void;
onOpenChange: (open: boolean) => void;
};
/**
* Confirmation copy for deleting a persona. Pure so the cascade archival
* disclosure stays unit-testable without a renderer: whenever instances are
* cascade-deleted, each one's identity is also archived on the relay
* (NIP-IA), and that durable side effect must be disclosed before the
* destructive confirm — matching the direct agent-delete dialog.
*/
export function personaDeleteDescription(
persona: AgentPersona | null,
instanceCount: number,
): string {
if (!persona) {
return "Delete this agent.";
}
if (instanceCount === 0) {
return `Delete ${persona.displayName}.`;
}
const cascade =
instanceCount === 1
? "Also deletes 1 agent instance and archives its identity on the relay, so it no longer appears in member lists or mention suggestions."
: `Also deletes ${instanceCount} agent instances and archives their identities on the relay, so they no longer appear in member lists or mention suggestions.`;
return `Delete ${persona.displayName}. ${cascade}`;
}
export function PersonaDeleteDialog({
open,
persona,
instanceCount = 0,
onConfirm,
onOpenChange,
}: PersonaDeleteDialogProps) {
return (
<AlertDialog onOpenChange={onOpenChange} open={open}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete agent?</AlertDialogTitle>
<AlertDialogDescription>
{personaDeleteDescription(persona, instanceCount)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel asChild>
<Button type="button" variant="outline">
Cancel
</Button>
</AlertDialogCancel>
<AlertDialogAction asChild>
<Button
onClick={() => {
if (persona) {
onConfirm(persona);
}
}}
type="button"
variant="destructive"
>
Delete
</Button>
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}