import { useQuery } from "@tanstack/react-query"; import { X } from "lucide-react"; import { getSessionDocuments } from "../api/sessions"; import type { SessionDocument, SessionSummary } from "../api/types"; import { Button } from "../components/ui/button"; import { SqlViewer } from "../viewers/SqlViewer"; import { SchemaLinkingViewer } from "../viewers/SchemaLinkingViewer"; import { MarkdownView } from "../viewers/MarkdownView"; interface Props { session: SessionSummary; onClose: () => void; onResume: (id: string) => void; } function statusLabel(s: SessionSummary): string { if (s.archived) return "Archived"; if (s.status === "finalized") return "Completed"; return `In progress · ${s.status}`; } function DocBody({ doc }: { doc: SessionDocument }) { if (doc.format === "sql") return ; if (doc.format === "markdown") return ; if (doc.format === "schema-linking") { try { const linking = JSON.parse(doc.content); return ; } catch { return
{doc.content}
; } } if (doc.format === "decisions") { const lines = doc.content.split("\n").filter(Boolean); return (
{`${lines.length} decisions`}
    {lines.map((line, i) => { let d: { type?: string; subject?: string; detail?: string }; try { d = JSON.parse(line); } catch { d = {}; } return
  • [{d.type}] {d.subject}{d.detail ? ` — ${d.detail}` : ""}
  • ; })}
); } return

{doc.content}

; } export function SessionDocumentsPanel({ session, onClose, onResume }: Props) { const { data: docs = [], isLoading } = useQuery({ queryKey: ["session-documents", session.id], queryFn: () => getSessionDocuments(session.id), }); const resumable = session.status !== "finalized" && !session.archived; return ( ); }