import React, { useEffect, useState } from 'react'; import { useAppContext } from '../context/AppContext'; const Memory: React.FC = () => { const { q } = useAppContext(); const [files, setFiles] = useState([]); const [active, setActive] = useState(''); const [content, setContent] = useState(''); async function loadFiles() { const r = await fetch(`/webui/api/memory${q}`); const j = await r.json(); setFiles(Array.isArray(j.files) ? j.files : []); } const qp = (k: string, v: string) => `${q}${q ? '&' : '?'}${k}=${encodeURIComponent(v)}`; async function openFile(path: string) { const r = await fetch(`/webui/api/memory${qp('path', path)}`); const j = await r.json(); setActive(path); setContent(j.content || ''); } async function saveFile() { if (!active) return; await fetch(`/webui/api/memory${q}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ path: active, content }), }); await loadFiles(); } async function removeFile(path: string) { await fetch(`/webui/api/memory${qp('path', path)}`, { method: 'DELETE' }); if (active === path) { setActive(''); setContent(''); } await loadFiles(); } async function createFile() { const name = prompt('memory file name', `note-${Date.now()}.md`); if (!name) return; await fetch(`/webui/api/memory${q}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ path: name, content: '' }), }); await loadFiles(); await openFile(name); } useEffect(() => { loadFiles().catch(() => {}); }, [q]); return (

{active || 'No file selected'}