"use client"; import * as React from "react"; import { useRouter } from "next/navigation"; import { ArrowDownToLine, Check, History, MessageSquare, Trash2, WandSparkles } from "lucide-react"; import { Button } from "@/components/ui/button"; import { toast } from "@/components/ui/toast"; import { ConfirmDialog } from "@/components/common/confirm-dialog"; import { RowMenu } from "@/components/projects/row-menu"; import { api, useApi } from "@/lib/client/api"; import { errorMessage } from "@/lib/client/humanize"; import { truncate } from "@/lib/utils"; import type { PromptPreset, PublicPrompt } from "@/lib/client/types"; import type { ActionSheetItem } from "@/components/ui/sheet"; interface PresetsResponse { promptPresets: PromptPreset[]; } /** * Legacy `prompt_presets` (pre-library system prompts). They still work in chat via `?prompt=`; * "Import to library" copies one into the new prompt library as a `system` prompt. */ export function LegacyPresets({ onImported }: { onImported?: (p: PublicPrompt) => void }) { const router = useRouter(); const q = useApi("/api/presets"); const [imported, setImported] = React.useState>(new Set()); const [busy, setBusy] = React.useState(null); const [deleting, setDeleting] = React.useState(null); const presets = React.useMemo(() => q.data?.promptPresets ?? [], [q.data]); if (q.isLoading || !presets.length) return null; const importOne = async (p: PromptPreset) => { setBusy(p.id); try { const res = await api<{ prompt: PublicPrompt }>("/api/prompts", { method: "POST", json: { kind: "system", name: p.name, description: p.description ?? null, content: p.systemPrompt, defaultModelKey: p.defaultModelKey ?? null, tags: ["imported"], folder: "Imported presets" }, }); setImported((s) => new Set(s).add(p.id)); toast.success(`Imported “${p.name}”`, "Find it in the library above. The legacy preset is unchanged."); onImported?.(res.prompt); } catch (e) { toast.error("Could not import", errorMessage(e)); } finally { setBusy(null); } }; const remove = async (p: PromptPreset) => { try { await api(`/api/presets?kind=prompt&id=${p.id}`, { method: "DELETE" }); await q.mutate(); toast.success("Legacy preset deleted"); } catch (e) { toast.error("Could not delete", errorMessage(e)); throw e; } }; const items = (p: PromptPreset): (ActionSheetItem | "separator")[] => [ { key: "import", label: imported.has(p.id) ? "Import again" : "Import to library", icon: , onSelect: () => void importOne(p) }, { key: "use", label: "Use in chat (legacy)", icon: , onSelect: () => router.push(`/app/chat?prompt=${p.id}`) }, "separator", { key: "delete", label: "Delete legacy preset", icon: , destructive: true, onSelect: () => setDeleting(p) }, ]; return (

Legacy presets

System prompts saved before the library existed. They keep working in chat; import them to get variables, folders and tags.

{presets.length > 1 ? ( ) : null}
    {presets.map((p) => (
  • {p.icon || }

    {p.name}

    {p.description || truncate(p.systemPrompt, 90)}

    {imported.has(p.id) ? ( Imported ) : ( )}
  • ))}
!o && setDeleting(null)} destructive title={`Delete legacy preset “${deleting?.name ?? ""}”?`} description="Conversations that used it are not affected. Import it first if you want to keep it in the library." confirmLabel="Delete" onConfirm={() => (deleting ? remove(deleting) : Promise.resolve())} />
); }