"use client"; import useSWR, { mutate } from "swr"; import { Brain } from "lucide-react"; import { api, fetcher } from "@/lib/client/fetcher"; import { Toggle, toast } from "../ui"; export const CATEGORIES: { id: string; label: string }[] = [ { id: "preference", label: "Préférences" }, { id: "writing", label: "Rédaction" }, { id: "research", label: "Recherche" }, { id: "project", label: "Projets" }, { id: "infrastructure", label: "Infrastructure" }, { id: "objective", label: "Objectifs" }, { id: "concept", label: "Concepts" }, { id: "context", label: "Contexte" }, ]; export const categoryLabel = (id: string) => CATEGORIES.find(c => c.id === id)?.label ?? id; export interface MemorySettings { enabled: boolean; autoExtract: boolean; requireApproval: boolean } interface SettingsResp { settings: { memory?: MemorySettings } } export function useMemorySettings() { const { data, mutate: m } = useSWR("/api/settings", fetcher); const value: MemorySettings = { enabled: true, autoExtract: true, requireApproval: false, ...(data?.settings.memory ?? {}) }; async function update(patch: Partial) { const next = { ...value, ...patch }; await api("/api/settings", { method: "PATCH", json: { key: "memory", value: next } }); await m(); void mutate("/api/settings"); toast("Réglages de mémoire enregistrés", "ok"); } return { value, update, loaded: !!data }; } /** Three memory toggles, reused by /memory and /settings. */ export function MemoryToggles({ compact }: { compact?: boolean }) { const { value, update, loaded } = useMemorySettings(); const rows: { key: keyof MemorySettings; label: string; hint: string }[] = [ { key: "enabled", label: "Mémoire activée", hint: "Les souvenirs actifs sont injectés dans le contexte des conversations." }, { key: "autoExtract", label: "Extraction automatique", hint: "Un modèle économique propose des faits durables après chaque échange." }, { key: "requireApproval", label: "Approbation requise", hint: "Les nouveaux souvenirs extraits restent candidats jusqu'à ton accord." }, ]; return (
{rows.map(r => ( ))}
); } export function MemoryIcon({ className }: { className?: string }) { return ; }