import { type PointerEvent, useRef, useState } from "react"; import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, Spinner, Textarea } from "@tutti-os/ui-system"; import type { AgentHostQuickPrompt } from "../../../../host/agentHostApi"; import type { AgentQuickPromptDraft, AgentQuickPromptLibraryController } from "./useAgentQuickPromptLibrary"; const MAX_TITLE_CODE_POINTS = 80; const MAX_CONTENT_BYTES = 32 * 1024; export function AgentQuickPromptEditorDialog({ controller }: { controller: AgentQuickPromptLibraryController; }): React.JSX.Element { const { labels } = controller; const source = controller.mode === "edit" ? controller.selectedPrompt : null; const [draft, setDraft] = useState( () => controller.initialDraft ?? promptDraft(source) ); const [validationError, setValidationError] = useState(null); const cancelRequestedOnPointerDownRef = useRef(false); const submit = async (): Promise => { const error = validateDraft(draft, labels); if (error) { setValidationError(error); return; } setValidationError(null); await controller.saveDraft({ title: draft.title.trim(), content: draft.content }); }; const mutationError = controller.mutationError === "conflict" ? labels.conflict : controller.mutationError === "generic" ? labels.mutationError : null; return ( { if (!open && !controller.isSaving) { controller.closeDialog(); } }} > { // The dialog is portalled but still participates in the Composer's // React event tree. Keep Enter inside the form so a keyboard save // cannot reach the Composer submit shortcut after the dialog closes. if (event.key === "Enter") event.stopPropagation(); }} onEscapeKeyDown={(event) => { if (controller.isSaving) event.preventDefault(); }} onInteractOutside={(event) => { if (controller.isSaving) event.preventDefault(); }} > {source ? labels.editTitle : labels.createTitle} {labels.contentPlaceholder}
{ event.preventDefault(); void submit(); }} >