import { useState } from "react"; import { getThread, killThread, pauseThread, resumeThread } from "../api.ts"; import { useFetch } from "../hooks.ts"; type Props = { threadId: string; onBack: () => void; }; export function ThreadDetail({ threadId, onBack }: Props) { const { status, data, error } = useFetch(() => getThread(threadId), [threadId]); const [actionStatus, setActionStatus] = useState(null); async function handleAction(action: "kill" | "pause" | "resume") { setActionStatus(`${action}ing...`); try { const fn = action === "kill" ? killThread : action === "pause" ? pauseThread : resumeThread; await fn(threadId); setActionStatus(`${action} sent ✓`); } catch (e) { setActionStatus(`${action} failed: ${e instanceof Error ? e.message : String(e)}`); } } return (

{threadId}

{actionStatus && (

{actionStatus}

)} {status === "loading" &&

Loading...

} {status === "error" &&

Error: {error}

} {status === "ok" && (
{data.records.map((r) => (
{r.type} {r.role && ( {r.role} )} {r.timestamp && ( {new Date(r.timestamp).toLocaleTimeString()} )}
{r.content && (
                  {typeof r.content === "string" ? r.content : JSON.stringify(r.content, null, 2)}
                
)}
))}
)}
); }