"use client"; import { useState } from "react"; import { Brain, Plus } from "lucide-react"; import { useMemory, useAddMemory, usePatchMemory, useDeleteMemory } from "@/lib/hooks"; import { MemoryEntry } from "@/components/MemoryEntry"; const TABS = [ { id: "memory", label: "Agent", color: "#f59e0b" }, { id: "user", label: "User", color: "#38bdf8" }, ] 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 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 barColor = pct > 85 ? "#ef4444" : pct > 65 ? "#f59e0b" : "#38bdf8"; const handleAdd = () => { if (!newText.trim()) return; addMutation.mutate({ target: tab, content: newText.trim() }, { onSuccess: () => { setNewText(""); setAdding(false); }, }); }; const handlePatch = (oldText: string, newContent: string) => { patchMutation.mutate({ target: tab, old_text: oldText, content: newContent }); }; const handleDelete = (oldText: string) => { deleteMutation.mutate({ target: tab, old_text: oldText }); }; return (

Memory

{/* Tabs */}
{TABS.map((t) => ( ))}
{/* Usage bar */} {usage && (
{tab === "memory" ? "Agent memory" : "User profile"} {usage}
)} {/* Add form */} {adding && (