From f56cfdd6a2cfd37afb96eccf8201cc7a2bc3a23e Mon Sep 17 00:00:00 2001 From: Finessse Date: Sat, 20 Dec 2025 15:01:24 +0700 Subject: [PATCH] webui: add memory management panel --- webui/src/App.tsx | 360 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 360 insertions(+) diff --git a/webui/src/App.tsx b/webui/src/App.tsx index fcab146c..2debff70 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -80,6 +80,24 @@ export default function App() { const [semanticNamespace, setSemanticNamespace] = useState(''); const [semanticLimit, setSemanticLimit] = useState(50); const [semanticItems, setSemanticItems] = useState(''); + const [memorySessions, setMemorySessions] = useState([]); + const [memorySession, setMemorySession] = useState(''); + const [memoryDetails, setMemoryDetails] = useState(null); + const [memoryEvents, setMemoryEvents] = useState(''); + const [memoryAnchors, setMemoryAnchors] = useState(''); + const [memoryEventsLimit, setMemoryEventsLimit] = useState(120); + const [memoryAnchorsLimit, setMemoryAnchorsLimit] = useState(20); + const [memoryTodo, setMemoryTodo] = useState(''); + const [memoryPinned, setMemoryPinned] = useState(''); + const [memorySummary, setMemorySummary] = useState(''); + const [memoryImportReplace, setMemoryImportReplace] = useState(false); + const [memoryPrune, setMemoryPrune] = useState({ + maxAgeDays: 30, + maxSessions: 200, + maxBytesPerSession: 2000000, + maxNamespaces: 200, + maxBytesPerNamespace: 2000000, + }); const showToast = (message: string, type: 'success' | 'error' = 'success') => { setToast({ message, type }); @@ -321,6 +339,167 @@ export default function App() { setSemanticItems(lines.join('\n\n')); }; + const loadMemorySessions = async () => { + const res = await mgmtFetch('/v0/management/memory/sessions?limit=200'); + const sessions = res.sessions || []; + setMemorySessions(sessions); + if (!memorySession && sessions.length > 0) { + setMemorySession(sessions[0].key); + } + }; + + const loadMemorySessionDetails = async () => { + if (!memorySession) { + setMemoryDetails(null); + return; + } + const res = await mgmtFetch(`/v0/management/memory/session?session=${encodeURIComponent(memorySession)}`); + const session = res.session || null; + setMemoryDetails(session); + if (session) { + setMemorySummary(session.summary || ''); + setMemoryPinned(session.pinned || ''); + setMemoryTodo(session.todo || ''); + } + }; + + const loadMemoryEvents = async () => { + if (!memorySession) { + setMemoryEvents('Select a session.'); + return; + } + const res = await mgmtFetch(`/v0/management/memory/events?session=${encodeURIComponent(memorySession)}&limit=${encodeURIComponent(memoryEventsLimit)}`); + const events = res.events || []; + if (!Array.isArray(events) || events.length === 0) { + setMemoryEvents('No events.'); + return; + } + const lines = events.map((e: any) => { + const ts = e.ts || ''; + const kind = e.kind || ''; + const role = e.role || ''; + const text = (e.text || '').toString(); + return `[${ts}][${kind}][${role}] ${text}`; + }); + setMemoryEvents(lines.join('\n\n')); + }; + + const loadMemoryAnchors = async () => { + if (!memorySession) { + setMemoryAnchors('Select a session.'); + return; + } + const res = await mgmtFetch(`/v0/management/memory/anchors?session=${encodeURIComponent(memorySession)}&limit=${encodeURIComponent(memoryAnchorsLimit)}`); + const anchors = res.anchors || []; + if (!Array.isArray(anchors) || anchors.length === 0) { + setMemoryAnchors('No anchors.'); + return; + } + const lines = anchors.map((a: any) => { + const ts = a.ts || ''; + const summary = (a.summary || '').toString(); + return `[${ts}]\n${summary}`; + }); + setMemoryAnchors(lines.join('\n\n---\n\n')); + }; + + const saveMemoryTodo = async () => { + if (!memorySession) return; + await mgmtFetch('/v0/management/memory/todo', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ session: memorySession, value: memoryTodo }), + }); + await loadMemorySessionDetails(); + showToast('Saved TODO', 'success'); + }; + + const saveMemoryPinned = async () => { + if (!memorySession) return; + await mgmtFetch('/v0/management/memory/pinned', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ session: memorySession, value: memoryPinned }), + }); + await loadMemorySessionDetails(); + showToast('Saved pinned context', 'success'); + }; + + const saveMemorySummary = async () => { + if (!memorySession) return; + await mgmtFetch('/v0/management/memory/summary', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ session: memorySession, value: memorySummary }), + }); + await loadMemorySessionDetails(); + showToast('Saved anchor summary', 'success'); + }; + + const deleteMemorySession = async () => { + if (!memorySession) return; + await mgmtFetch(`/v0/management/memory/session?session=${encodeURIComponent(memorySession)}`, { + method: 'DELETE', + }); + setMemorySession(''); + setMemoryDetails(null); + setMemoryEvents(''); + setMemoryAnchors(''); + await loadMemorySessions(); + showToast('Deleted session', 'success'); + }; + + const exportMemorySession = async () => { + if (!memorySession || !mgmtKey) return; + const res = await fetch(`/v0/management/memory/export?session=${encodeURIComponent(memorySession)}`, { + headers: { 'X-Management-Key': mgmtKey }, + }); + if (!res.ok) { + const msg = await res.text(); + throw new Error(msg); + } + const blob = await res.blob(); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = `proxypilot-session-${memorySession}.zip`; + a.click(); + URL.revokeObjectURL(url); + }; + + const importMemorySession = async (file: File | null) => { + if (!file || !memorySession || !mgmtKey) return; + const form = new FormData(); + form.append('file', file); + const res = await fetch(`/v0/management/memory/import?session=${encodeURIComponent(memorySession)}&replace=${memoryImportReplace ? 'true' : 'false'}`, { + method: 'POST', + headers: { 'X-Management-Key': mgmtKey }, + body: form, + }); + if (!res.ok) { + const msg = await res.text(); + throw new Error(msg); + } + await loadMemorySessionDetails(); + showToast('Imported session', 'success'); + }; + + const pruneMemory = async () => { + await mgmtFetch('/v0/management/memory/prune', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + max_age_days: memoryPrune.maxAgeDays, + max_sessions: memoryPrune.maxSessions, + max_bytes_per_session: memoryPrune.maxBytesPerSession, + max_namespaces: memoryPrune.maxNamespaces, + max_bytes_per_namespace: memoryPrune.maxBytesPerNamespace, + }), + }); + await loadMemorySessions(); + showToast('Prune completed', 'success'); + }; + useEffect(() => { if (!mgmtKey) return; setMgmtError(null); @@ -331,6 +510,7 @@ export default function App() { await loadRecentRouting(); await loadSemanticHealth(); await loadSemanticNamespaces(); + await loadMemorySessions(); await tailLogs('stdout'); } catch (e) { setMgmtError(e instanceof Error ? e.message : String(e)); @@ -818,6 +998,186 @@ export default function App() { +
+ + + Memory + Anchors, pinned context, TODOs, and session history + + +
+ + + + + + +
+ +
+ + setMemoryEventsLimit(parseInt(e.target.value || '120', 10))} + /> + setMemoryAnchorsLimit(parseInt(e.target.value || '20', 10))} + /> + + {memoryDetails?.updated_at ? `Updated ${memoryDetails.updated_at}` : 'No session loaded.'} + +
+ +
+
+
Anchor summary
+