/**
* MemoryCard — Expandable card showing memory content + metadata
*/
import { useState } from 'react';
import type { ScoredMemory } from '../api/client';
import TypeBadge from './TypeBadge';
import ScoreBar from './ScoreBar';
interface MemoryCardProps {
scored: ScoredMemory;
onForget?: (memoryId: string) => void;
}
export default function MemoryCard({ scored, onForget }: MemoryCardProps) {
const [expanded, setExpanded] = useState(false);
const { memory, score, cosine_similarity } = scored;
const timeAgo = formatTimeAgo(memory.created_at);
return (
setExpanded(!expanded)}
>
{/* Header */}
{timeAgo}
{/* Content */}
{memory.content}
{/* Score bars */}
{/* Expanded metadata */}
{expanded && (
{JSON.stringify(memory.metadata, null, 2)}
Accesses: {memory.access_count}
Recency: {memory.recency_score.toFixed(3)}
ID: {memory.id.slice(0, 8)}…
{onForget && (
)}
)}
);
}
function formatTimeAgo(dateStr: string): string {
const date = new Date(dateStr);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffMin = Math.floor(diffMs / 60000);
if (diffMin < 1) return 'just now';
if (diffMin < 60) return `${diffMin}m ago`;
const diffHr = Math.floor(diffMin / 60);
if (diffHr < 24) return `${diffHr}h ago`;
const diffDays = Math.floor(diffHr / 24);
return `${diffDays}d ago`;
}