import { ThreadState } from "../schema.js"; interface Node { type: "node"; value: ThreadState; path: string[]; } interface Fork { type: "fork"; items: Array>; } interface Sequence { type: "sequence"; items: Array | Fork>; } interface ValidFork { type: "fork"; items: Array>; } interface ValidSequence { type: "sequence"; items: [Node, ...(Node | ValidFork)[]]; } // forks export type CheckpointBranchPath = string[]; export type MessageBranch = { current: CheckpointBranchPath; options: CheckpointBranchPath[]; }; export function DebugSegmentsView(props: { sequence: ValidSequence; }) { const concatContent = (value: ThreadState) => { let content; try { content = value.values?.messages?.at(-1)?.content ?? ""; } catch { content = JSON.stringify(value.values); } content = content.replace(/(\n|\r\n)/g, ""); if (content.length <= 23) return content; return `${content.slice(0, 10)}...${content.slice(-10)}`; }; return (
{props.sequence.items.map((item, index) => { if (item.type === "fork") { return (
{item.items.map((fork, idx) => { const [first] = fork.items; return (
Fork{" "} ...{first.path.at(-1)?.slice(-4)}
); })}
); } if (item.type === "node") { return (
                ({item.value.metadata?.step}) ...
                {item.value.checkpoint.checkpoint_id?.slice(-4)} (
                {item.value.metadata?.source}): {concatContent(item.value)}
              
); } return null; })}
); }