import { useState, useCallback } from 'react' import { api, getToken } from '../../api/client' interface MemoryEntry { id: string; user_id: string; content: string; summary: string; keywords: string[]; category: string; priority: number; } export default function MemoryPage() { const [memories, setMemories] = useState([]) const [search, setSearch] = useState('') const [loading, setLoading] = useState(false) const [newContent, setNewContent] = useState('') const fetchMemories = useCallback(async (q?: string) => { setLoading(true) try { const token = getToken() const path = q ? `/api/v1/memory/search?q=${encodeURIComponent(q)}` : '/api/v1/memory' const res = await fetch(path, { headers: { Authorization: `Bearer ${token}` } }) const data = await res.json() setMemories(Array.isArray(data?.data) ? data.data : []) } catch { } finally { setLoading(false) } }, []) const handleAdd = async () => { if (!newContent.trim()) return const token = getToken() await fetch('/api/v1/memory', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }, body: JSON.stringify({ content: newContent, category: 'fact', priority: 0.5 }), }) setNewContent('') fetchMemories(search || undefined) } const handleDelete = async (id: string) => { const token = getToken() await fetch(`/api/v1/memory/${id}`, { method: 'DELETE', headers: { Authorization: `Bearer ${token}` } }) fetchMemories(search || undefined) } return (

记忆管理

{/* Search */}
setSearch(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') fetchMemories(search) }} placeholder="搜索记忆..." className="flex-1 bg-[#000] border border-[#404040] focus:border-[#277AF7] rounded-[14px] px-4 py-2.5 text-sm text-[#F2F2F2] placeholder:text-white/30 outline-none" />
{/* Add */}
setNewContent(e.target.value)} placeholder="添加新记忆..." className="flex-1 bg-[#000] border border-[#404040] focus:border-[#277AF7] rounded-[14px] px-4 py-2.5 text-sm text-[#F2F2F2] placeholder:text-white/30 outline-none" />
{/* List */} {loading ? (

加载中...

) : memories.length === 0 ? (

暂无记忆

) : (
{memories.map(m => (

{m.content}

{m.category} {m.keywords?.slice(0, 3).map((kw, i) => ( {kw} ))}
))}
)}
) }