import { ChevronRight, Loader2 } from 'lucide-react' import { useState } from 'react' import { EvidenceList } from './EvidenceList' import { Progress } from './Progress' import { STEPS } from '@/lib/content' import { seconds } from '@/lib/format' import { running, type RunState } from '@/lib/run' /** How the answer was made, like Claude's "thinking": open while the system works (each * step ticks off with what it found), then folded to one line ("Worked 19 s · 6 steps") * that opens again on click. The passages the model read are inside it. */ export function Trace({ run, lastEventAt }: { run: RunState; lastEventAt: number }) { const [opened, setOpened] = useState(null) // null: follow the run const working = run.phase === 'running' const open = opened ?? working const done = run.steps.filter((s) => s.status === 'done').length const step = running(run) const total = run.answer?.latency_ms let summary: string if (working) summary = step && run.live ? `${STEPS[step.name]?.title ?? step.name}…` : 'Searching and answering…' else if (run.live) summary = `Worked ${seconds(total)} · ${done} step${done === 1 ? '' : 's'}` else summary = `Worked ${seconds(total)} · one search and one model call` if (run.phase === 'error') summary = 'Stopped before an answer' return (
{open && (
{run.evidence && (
Read {run.evidence.length} passages
)}
)}
) }