"use client"; import { useState } from "react"; import { Plus } from "lucide-react"; import { useMemory, useAddMemory, usePatchMemory, useDeleteMemory } from "@/lib/hooks"; import { MemoryEntry } from "@/components/MemoryEntry"; import { useToast } from "@/components/Toast"; const TABS = [ { id: "memory", label: "Agent" }, { id: "user", label: "User" }, ] as const; export default function MemoryPage() { const [tab, setTab] = useState<"memory" | "user">("memory"); const [adding, setAdding] = useState(false); const [newText, setNewText] = useState(""); const { data, isLoading } = useMemory(); const addMutation = useAddMemory(); const patchMutation = usePatchMemory(); const deleteMutation = useDeleteMemory(); const { toast } = useToast(); const target = data?.targets?.find((t) => t.target === tab); const entries = target?.entries || []; const usage = target?.usage || ""; const pctMatch = usage.match(/(\d+)%/); const pct = pctMatch ? parseInt(pctMatch[1]) : 0; const handleAdd = () => { if (!newText.trim()) return; addMutation.mutate({ target: tab, content: newText.trim() }, { onSuccess: () => { setNewText(""); setAdding(false); toast("Entry added"); }, onError: () => toast("Failed to add entry", "error"), }); }; const handlePatch = (oldText: string, newContent: string) => { patchMutation.mutate({ target: tab, old_text: oldText, content: newContent }, { onSuccess: () => toast("Entry updated"), onError: () => toast("Failed to update", "error"), }); }; const handleDelete = (oldText: string) => { deleteMutation.mutate({ target: tab, old_text: oldText }, { onSuccess: () => toast("Entry deleted"), onError: () => toast("Failed to delete", "error"), }); }; return (

Memory

{TABS.map((t) => ( ))}
{usage && (
85 ? "#ff3b30" : "var(--accent)" }} />
{usage}
)} {adding && (