@andersonbcdefg/transcript-viewer 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,45 @@
1
- # Temporary Holding Version
1
+ # @andersonbcdefg/transcript-viewer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Parsers and a React viewer for coding-agent transcripts (JSONL). Shared by
4
+ ccviewer and the ccremote dashboard.
5
+
6
+ ```tsx
7
+ import { ConversationVisualizer, parseJsonlContent } from "@andersonbcdefg/transcript-viewer";
8
+ import "@andersonbcdefg/transcript-viewer/styles.css";
9
+
10
+ const parsed = parseJsonlContent(jsonlText, "run-123");
11
+ if (!("error" in parsed)) {
12
+ return <ConversationVisualizer conversation={parsed.conversations[0]} />;
13
+ }
14
+ ```
15
+
16
+ The viewer must go through a bundler (Vite, Next.js, webpack) because
17
+ `react-syntax-highlighter` ships bundler-only ESM. For plain Node (servers,
18
+ CLIs), import just the parsers:
19
+
20
+ ```ts
21
+ import { parseJsonlContent } from "@andersonbcdefg/transcript-viewer/parsers";
22
+ ```
23
+
24
+ Styles are plain CSS scoped under `.tv` (no Tailwind needed). Theme by
25
+ overriding the `--tv-*` custom properties, e.g. `--tv-font-sans`,
26
+ `--tv-accent`, `--tv-bg`.
27
+
28
+ ## Supported formats
29
+
30
+ Claude Code JSONL, Claude headless, Codex JSONL, Codex headless, Cursor
31
+ headless, Gemini headless.
32
+
33
+ ## TODO (v2)
34
+
35
+ - Pi transcripts are misdetected as Claude JSONL (roles come through as
36
+ `toolResult`, tool calls are not paired). Add a dedicated `pi` parser.
37
+ - Devin and OpenCode transcripts are not handled yet.
38
+ - ccremote `ccremote.event` lines render as System messages; consider a
39
+ compact event row instead.
40
+
41
+ ## Development
42
+
43
+ `pnpm build` emits `dist/` (ESM + types + `styles.css`). Inside the ccviewer
44
+ repo, the app resolves this package from `src/` via the `ccviewer-source`
45
+ export condition, so no build is needed for local development.
@@ -0,0 +1,15 @@
1
+ import type { ConversationView } from "./types.js";
2
+ export declare const SOURCE_LABELS: Record<string, string>;
3
+ /**
4
+ * Maps a link URL found in a message to the URL to render, or returns null to
5
+ * keep it. Lets hosts point links like `/tmp/outputs/report.md` at real files.
6
+ */
7
+ export type TransformLinkUrl = (url: string) => string | null;
8
+ export type ConversationVisualizerProps = {
9
+ conversation: ConversationView | null;
10
+ sidechainsByAgentId?: Map<string, ConversationView>;
11
+ className?: string;
12
+ /** Rewrites link URLs inside messages (e.g. agent output paths to real files). */
13
+ transformLinkUrl?: TransformLinkUrl;
14
+ };
15
+ export default function ConversationVisualizer({ conversation, sidechainsByAgentId, className, transformLinkUrl, }: ConversationVisualizerProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,358 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ArrowDown, Check, ChevronRight, Copy } from "lucide-react";
3
+ import { createContext, isValidElement, useCallback, useContext, useRef, useState, } from "react";
4
+ import Markdown, { defaultUrlTransform } from "react-markdown";
5
+ import { PrismLight as SyntaxHighlighter } from "react-syntax-highlighter";
6
+ import bash from "react-syntax-highlighter/dist/esm/languages/prism/bash";
7
+ import diff from "react-syntax-highlighter/dist/esm/languages/prism/diff";
8
+ import javascript from "react-syntax-highlighter/dist/esm/languages/prism/javascript";
9
+ import json from "react-syntax-highlighter/dist/esm/languages/prism/json";
10
+ import jsx from "react-syntax-highlighter/dist/esm/languages/prism/jsx";
11
+ import markdown from "react-syntax-highlighter/dist/esm/languages/prism/markdown";
12
+ import python from "react-syntax-highlighter/dist/esm/languages/prism/python";
13
+ import sql from "react-syntax-highlighter/dist/esm/languages/prism/sql";
14
+ import tsx from "react-syntax-highlighter/dist/esm/languages/prism/tsx";
15
+ import typescript from "react-syntax-highlighter/dist/esm/languages/prism/typescript";
16
+ import yaml from "react-syntax-highlighter/dist/esm/languages/prism/yaml";
17
+ import { oneLight } from "react-syntax-highlighter/dist/esm/styles/prism";
18
+ import remarkBreaks from "remark-breaks";
19
+ import remarkGfm from "remark-gfm";
20
+ const LANGUAGES = {
21
+ bash,
22
+ diff,
23
+ javascript,
24
+ json,
25
+ jsx,
26
+ markdown,
27
+ python,
28
+ sql,
29
+ tsx,
30
+ typescript,
31
+ yaml,
32
+ };
33
+ const LANGUAGE_ALIASES = {
34
+ sh: "bash",
35
+ shell: "bash",
36
+ zsh: "bash",
37
+ console: "bash",
38
+ js: "javascript",
39
+ mjs: "javascript",
40
+ ts: "typescript",
41
+ py: "python",
42
+ yml: "yaml",
43
+ md: "markdown",
44
+ patch: "diff",
45
+ };
46
+ for (const [name, grammar] of Object.entries(LANGUAGES)) {
47
+ SyntaxHighlighter.registerLanguage(name, grammar);
48
+ }
49
+ const resolveLanguage = (lang) => {
50
+ if (!lang)
51
+ return "text";
52
+ const lower = lang.toLowerCase();
53
+ const resolved = LANGUAGE_ALIASES[lower] ?? lower;
54
+ return resolved in LANGUAGES ? resolved : "text";
55
+ };
56
+ const CODE_STYLE = {
57
+ margin: 0,
58
+ padding: "0.625rem 0.75rem",
59
+ background: "var(--tv-code-bg)",
60
+ fontFamily: "var(--tv-font-mono)",
61
+ fontSize: "var(--tv-mono-size)",
62
+ lineHeight: 1.55,
63
+ borderRadius: 0,
64
+ };
65
+ const CodeBlock = ({ language, code }) => (_jsx(SyntaxHighlighter, { language: resolveLanguage(language), style: oneLight, customStyle: CODE_STYLE, codeTagProps: { style: { fontFamily: "inherit", fontSize: "inherit" } }, wrapLongLines: true, children: code }));
66
+ export const SOURCE_LABELS = {
67
+ mitm: "MITM",
68
+ "claude-jsonl": "Claude JSONL",
69
+ "codex-jsonl": "Codex JSONL",
70
+ "claude-headless": "Claude Headless",
71
+ "codex-headless": "Codex Headless",
72
+ "gemini-headless": "Gemini Headless",
73
+ "cursor-headless": "Cursor Headless",
74
+ };
75
+ const ROLE_LABELS = {
76
+ user: "User",
77
+ assistant: "Assistant",
78
+ system: "System",
79
+ tool: "Tool",
80
+ developer: "Developer",
81
+ };
82
+ // Generate a copyable text representation of message blocks
83
+ const generateCopyText = (blocks) => {
84
+ if (!blocks?.length)
85
+ return "";
86
+ return blocks
87
+ .map((block) => {
88
+ if (block.type === "tool_use" || block.type === "tool_call") {
89
+ const toolName = block.json && typeof block.json === "object" && "name" in block.json
90
+ ? block.json.name
91
+ : block.text || "tool";
92
+ return `[Tool: ${toolName}]`;
93
+ }
94
+ if (block.type === "tool_result") {
95
+ const text = block.text || "";
96
+ const preview = text.split("\n").slice(0, 2).join(" ").slice(0, 80);
97
+ return `[Result: ${preview}${text.length > 80 ? "..." : ""}]`;
98
+ }
99
+ if (block.type === "thinking") {
100
+ const text = block.text || "";
101
+ const preview = text.slice(0, 100);
102
+ return `[Thinking: ${preview}${text.length > 100 ? "..." : ""}]`;
103
+ }
104
+ return block.text || "";
105
+ })
106
+ .join("\n\n");
107
+ };
108
+ const CopyButton = ({ blocks, }) => {
109
+ const [copied, setCopied] = useState(false);
110
+ const handleCopy = useCallback(async () => {
111
+ const text = generateCopyText(blocks);
112
+ if (!text)
113
+ return;
114
+ try {
115
+ await navigator.clipboard.writeText(text);
116
+ setCopied(true);
117
+ setTimeout(() => setCopied(false), 2000);
118
+ }
119
+ catch (err) {
120
+ console.error("Failed to copy:", err);
121
+ }
122
+ }, [blocks]);
123
+ return (_jsx("button", { type: "button", onClick: handleCopy, className: "tv-icon-button", title: "Copy message", "aria-label": copied ? "Copied" : "Copy message", children: copied ? _jsx(Check, { size: 14 }) : _jsx(Copy, { size: 14 }) }));
124
+ };
125
+ const Chevron = ({ expanded }) => (_jsx(ChevronRight, { size: 14, className: `tv-chevron${expanded ? " tv-chevron--open" : ""}`, "aria-hidden": "true" }));
126
+ const formatTime = (iso) => {
127
+ try {
128
+ return new Date(iso).toLocaleString();
129
+ }
130
+ catch {
131
+ return iso;
132
+ }
133
+ };
134
+ const clip = (value, size = 120) => {
135
+ if (!value)
136
+ return "";
137
+ if (value.length <= size)
138
+ return value;
139
+ return `${value.slice(0, size)}...`;
140
+ };
141
+ const formatDetail = (detail) => {
142
+ if (typeof detail.content === "string")
143
+ return detail.content;
144
+ return JSON.stringify(detail.content, null, 2);
145
+ };
146
+ const textOf = (node) => {
147
+ if (typeof node === "string" || typeof node === "number")
148
+ return String(node);
149
+ if (Array.isArray(node))
150
+ return node.map(textOf).join("");
151
+ return "";
152
+ };
153
+ const MARKDOWN_COMPONENTS = {
154
+ // Fenced code arrives as <pre><code class="language-x">; unwrap it here so
155
+ // the `code` override below only ever sees inline code.
156
+ pre: ({ children }) => {
157
+ const child = Array.isArray(children) ? children[0] : children;
158
+ if (isValidElement(child)) {
159
+ const props = child.props;
160
+ const language = /language-([\w+-]+)/.exec(props.className || "")?.[1];
161
+ return (_jsx("div", { className: "tv-codeblock", children: _jsx(CodeBlock, { language: language, code: textOf(props.children).replace(/\n$/, "") }) }));
162
+ }
163
+ return _jsx("pre", { className: "tv-pre", children: children });
164
+ },
165
+ code: ({ children }) => _jsx("code", { className: "tv-inline-code", children: children }),
166
+ table: ({ children }) => (_jsx("div", { className: "tv-table-wrap", children: _jsx("table", { children: children }) })),
167
+ a: ({ href, children }) => (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", children: children })),
168
+ };
169
+ // Agents write single newlines as line breaks, so honor them like a terminal would.
170
+ const REMARK_PLUGINS = [remarkGfm, remarkBreaks];
171
+ const LinkTransformContext = createContext(null);
172
+ const MarkdownContent = ({ children }) => {
173
+ const transformLinkUrl = useContext(LinkTransformContext);
174
+ // The host's transform runs before react-markdown's sanitizer, so schemes
175
+ // like `sandbox:` or `file:` can be rewritten before they would be dropped.
176
+ const urlTransform = (url) => defaultUrlTransform(transformLinkUrl?.(url) ?? url);
177
+ return (_jsx("div", { className: "tv-prose", children: _jsx(Markdown, { remarkPlugins: REMARK_PLUGINS, components: MARKDOWN_COMPONENTS, urlTransform: urlTransform, children: children }) }));
178
+ };
179
+ const EmbeddedSidechain = ({ sidechain, sidechainsByAgentId, depth, }) => {
180
+ const [expanded, setExpanded] = useState(false);
181
+ // Limit nesting depth to prevent infinite recursion
182
+ if (depth > 3) {
183
+ return (_jsxs("div", { className: "tv-sidechain tv-sidechain--flat", children: ["Subagent (max depth reached): ", sidechain.previewUser || sidechain.title] }));
184
+ }
185
+ return (_jsxs("div", { className: "tv-sidechain", children: [_jsxs("button", { type: "button", onClick: () => setExpanded(!expanded), className: "tv-row-button", children: [_jsx(Chevron, { expanded: expanded }), _jsx("span", { className: "tv-sidechain-label", children: "Subagent" }), _jsx("span", { className: "tv-row-preview", children: clip(sidechain.previewUser || sidechain.title, 80) }), _jsxs("span", { className: "tv-row-meta", children: [sidechain.messages.length, " msgs"] })] }), expanded && (_jsx("div", { className: "tv-sidechain-body", children: sidechain.messages.map((msg, idx) => (_jsx(Bubble
186
+ // biome-ignore lint/suspicious/noArrayIndexKey: static list
187
+ , { kind: msg.role, blocks: msg.blocks, sidechainsByAgentId: sidechainsByAgentId, depth: depth }, `sidechain-${idx}`))) }))] }));
188
+ };
189
+ const COLLAPSIBLE_TAGS = ["INSTRUCTIONS", "environment_context"];
190
+ // Extract Python code from shell commands like:
191
+ // - python3 -c "code here"
192
+ // - python3 - <<'PY'\ncode\nPY
193
+ // - python -c 'code here'
194
+ const extractPythonCode = (command) => {
195
+ const heredocMatch = command.match(/python3?\s+-\s*<<['"]?(\w+)['"]?\n([\s\S]*?)\n\1(?:\s|$)/);
196
+ if (heredocMatch) {
197
+ return heredocMatch[2].trim();
198
+ }
199
+ const dashCMatch = command.match(/python3?\s+-c\s+(['"])([\s\S]*?)\1/);
200
+ if (dashCMatch) {
201
+ return dashCMatch[2]
202
+ .replace(/\\n/g, "\n")
203
+ .replace(/\\t/g, "\t")
204
+ .replace(/\\'/g, "'")
205
+ .replace(/\\"/g, '"')
206
+ .trim();
207
+ }
208
+ return null;
209
+ };
210
+ const parseTaggedSections = (text) => {
211
+ const segments = [];
212
+ const tagPattern = new RegExp(`<(${COLLAPSIBLE_TAGS.join("|")})>([\\s\\S]*?)</\\1>`, "g");
213
+ let lastIndex = 0;
214
+ let match = tagPattern.exec(text);
215
+ while (match !== null) {
216
+ if (match.index > lastIndex) {
217
+ const before = text.slice(lastIndex, match.index).trim();
218
+ if (before)
219
+ segments.push({ type: "text", content: before });
220
+ }
221
+ segments.push({ type: "tagged", tag: match[1], content: match[2].trim() });
222
+ lastIndex = match.index + match[0].length;
223
+ match = tagPattern.exec(text);
224
+ }
225
+ if (lastIndex < text.length) {
226
+ const after = text.slice(lastIndex).trim();
227
+ if (after)
228
+ segments.push({ type: "text", content: after });
229
+ }
230
+ return segments.length ? segments : [{ type: "text", content: text }];
231
+ };
232
+ const CollapsibleTaggedSection = ({ tag, content, }) => {
233
+ const [expanded, setExpanded] = useState(false);
234
+ const lines = content.split("\n");
235
+ const preview = lines.slice(0, 3).join("\n");
236
+ const hasMore = lines.length > 3;
237
+ return (_jsx("div", { className: "tv-panel", children: _jsxs("button", { type: "button", onClick: () => setExpanded(!expanded), className: "tv-row-button tv-row-button--top", children: [_jsx(Chevron, { expanded: expanded }), _jsxs("div", { className: "tv-row-stack", children: [_jsx("div", { className: "tv-row-label", children: tag }), _jsxs("pre", { className: "tv-mono-text", children: [expanded ? content : preview, !expanded && hasMore ? "..." : ""] })] })] }) }));
238
+ };
239
+ const ToolCallBlock = ({ block }) => {
240
+ const [expanded, setExpanded] = useState(false);
241
+ const toolName = block.json && typeof block.json === "object" && "name" in block.json
242
+ ? block.json.name
243
+ : block.text;
244
+ // Claude uses 'input' (object), Codex uses 'arguments' (JSON string)
245
+ let toolInput = null;
246
+ if (block.json && typeof block.json === "object") {
247
+ if ("input" in block.json) {
248
+ toolInput = block.json.input;
249
+ }
250
+ else if ("arguments" in block.json) {
251
+ const args = block.json.arguments;
252
+ try {
253
+ toolInput = args ? JSON.parse(args) : null;
254
+ }
255
+ catch {
256
+ toolInput = args;
257
+ }
258
+ }
259
+ }
260
+ const shellCommand = toolInput && typeof toolInput === "object" && "command" in toolInput
261
+ ? toolInput.command
262
+ : null;
263
+ const pythonCode = typeof shellCommand === "string" ? extractPythonCode(shellCommand) : null;
264
+ const inputPreview = toolInput ? JSON.stringify(toolInput) : "";
265
+ return (_jsxs("div", { className: "tv-panel tv-tool-call", children: [_jsxs("button", { type: "button", onClick: () => setExpanded(!expanded), className: "tv-row-button", children: [_jsx(Chevron, { expanded: expanded }), _jsxs("code", { className: "tv-tool-signature", children: [_jsx("span", { className: "tv-tool-name", children: toolName }), expanded ? "" : ` ${clip(inputPreview, 140)}`] })] }), expanded && Boolean(toolInput) && (_jsx("div", { className: "tv-panel-body", children: pythonCode ? (_jsx(CodeBlock, { language: "python", code: pythonCode })) : (_jsx("pre", { className: "tv-mono-text tv-mono-text--padded", children: typeof toolInput === "string"
266
+ ? toolInput
267
+ : JSON.stringify(toolInput, null, 2) })) }))] }));
268
+ };
269
+ const ToolResultBlock = ({ block, sidechainsByAgentId, depth, }) => {
270
+ const [expanded, setExpanded] = useState(false);
271
+ const sidechain = block.agentId && sidechainsByAgentId?.get(block.agentId);
272
+ const text = block.text || "-";
273
+ const lines = text.split("\n");
274
+ let preview = lines.slice(0, 3).join("\n");
275
+ let hasMore = lines.length > 3;
276
+ if (preview.length > 800) {
277
+ preview = preview.slice(0, 800);
278
+ hasMore = true;
279
+ }
280
+ return (_jsxs("div", { className: "tv-stack", children: [sidechain && (_jsx(EmbeddedSidechain, { sidechain: sidechain, sidechainsByAgentId: sidechainsByAgentId, depth: depth + 1 })), _jsx("div", { className: "tv-panel tv-tool-result", children: _jsxs("button", { type: "button", onClick: () => setExpanded(!expanded), className: "tv-row-button tv-row-button--top", disabled: !hasMore, children: [hasMore ? (_jsx(Chevron, { expanded: expanded })) : (_jsx("span", { className: "tv-chevron-spacer" })), _jsxs("div", { className: "tv-row-stack", children: [_jsx("div", { className: "tv-row-label", children: "Output" }), _jsxs("pre", { className: "tv-mono-text", children: [expanded ? text : preview, !expanded && hasMore ? "..." : ""] })] })] }) })] }));
281
+ };
282
+ // Render a single block - tool calls and results collapse; text renders as markdown
283
+ const BlockRenderer = ({ block, sidechainsByAgentId, depth, }) => {
284
+ if (block.type === "tool_use" || block.type === "tool_call") {
285
+ return _jsx(ToolCallBlock, { block: block });
286
+ }
287
+ if (block.type === "tool_result") {
288
+ return (_jsx(ToolResultBlock, { block: block, sidechainsByAgentId: sidechainsByAgentId, depth: depth }));
289
+ }
290
+ if (block.type === "thinking") {
291
+ return (_jsxs("div", { className: "tv-thinking", children: [_jsx("div", { className: "tv-row-label", children: "Thinking" }), _jsx(MarkdownContent, { children: block.text || "-" })] }));
292
+ }
293
+ const text = block.text || "-";
294
+ const segments = parseTaggedSections(text);
295
+ if (segments.length === 1 && segments[0].type === "text") {
296
+ return _jsx(MarkdownContent, { children: text });
297
+ }
298
+ return (_jsx("div", { className: "tv-stack", children: segments.map((segment, idx) => segment.type === "tagged" ? (_jsx(CollapsibleTaggedSection
299
+ // biome-ignore lint/suspicious/noArrayIndexKey: static parsed segments
300
+ , { tag: segment.tag, content: segment.content }, idx)) : (
301
+ // biome-ignore lint/suspicious/noArrayIndexKey: static parsed segments
302
+ _jsx(MarkdownContent, { children: segment.content }, idx))) }));
303
+ };
304
+ const Bubble = ({ kind, blocks, sidechainsByAgentId, depth = 0, }) => {
305
+ const roleClass = ROLE_LABELS[kind] ? kind : "other";
306
+ return (_jsxs("div", { className: `tv-msg tv-msg--${roleClass}`, children: [_jsxs("div", { className: "tv-msg-header", children: [_jsx("div", { className: "tv-msg-role", children: ROLE_LABELS[kind] ?? kind }), _jsx(CopyButton, { blocks: blocks })] }), _jsx("div", { className: "tv-stack", children: blocks?.length ? (blocks.map((block, idx) => (_jsx(BlockRenderer
307
+ // biome-ignore lint/suspicious/noArrayIndexKey: static list
308
+ , { block: block, sidechainsByAgentId: sidechainsByAgentId, depth: depth }, `block-${idx}`)))) : (_jsx("span", { className: "tv-muted", children: "-" })) })] }));
309
+ };
310
+ const formatDuration = (ms) => {
311
+ if (ms < 1000)
312
+ return `${ms}ms`;
313
+ const seconds = Math.floor(ms / 1000);
314
+ if (seconds < 60)
315
+ return `${seconds}s`;
316
+ const minutes = Math.floor(seconds / 60);
317
+ const remainingSeconds = seconds % 60;
318
+ return `${minutes}m ${remainingSeconds}s`;
319
+ };
320
+ const formatCost = (cost) => {
321
+ if (cost === undefined || cost === null)
322
+ return "-";
323
+ return `$${cost.toFixed(4)}`;
324
+ };
325
+ const Metric = ({ label, value }) => (_jsxs("div", { className: "tv-metric", children: [_jsx("span", { className: "tv-metric-label", children: label }), _jsx("span", { className: "tv-metric-value", children: value })] }));
326
+ const ResultSummaryView = ({ summary }) => {
327
+ const [showDetails, setShowDetails] = useState(false);
328
+ const usage = summary.usage && typeof summary.usage === "object"
329
+ ? summary.usage
330
+ : null;
331
+ return (_jsxs("div", { className: "tv-summary", children: [_jsxs("div", { className: "tv-summary-header", children: [_jsx("div", { className: "tv-summary-title", children: "Result summary" }), _jsx("span", { className: `tv-badge ${summary.is_error ? "tv-badge--error" : "tv-badge--ok"}`, children: summary.is_error ? "Error" : "Success" })] }), summary.result &&
332
+ (summary.is_error ? (_jsx("pre", { className: "tv-summary-error", children: summary.result })) : (_jsx("div", { className: "tv-summary-result", children: _jsx(MarkdownContent, { children: summary.result }) }))), _jsxs("div", { className: "tv-metrics", children: [summary.duration_ms > 0 && (_jsx(Metric, { label: "Duration", value: formatDuration(summary.duration_ms) })), summary.num_turns > 0 && (_jsx(Metric, { label: "Turns", value: String(summary.num_turns) })), summary.total_cost_usd !== undefined && (_jsx(Metric, { label: "Cost", value: formatCost(summary.total_cost_usd) })), summary.duration_api_ms !== undefined && (_jsx(Metric, { label: "API time", value: formatDuration(summary.duration_api_ms) })), usage?.input_tokens !== undefined && (_jsx(Metric, { label: "Input tokens", value: usage.input_tokens.toLocaleString() })), usage?.output_tokens !== undefined && (_jsx(Metric, { label: "Output tokens", value: usage.output_tokens.toLocaleString() })), usage?.cached_input_tokens !== undefined && (_jsx(Metric, { label: "Cached", value: usage.cached_input_tokens.toLocaleString() }))] }), summary.permission_denials && summary.permission_denials.length > 0 && (_jsxs("div", { className: "tv-summary-section", children: [_jsxs("div", { className: "tv-row-label", children: ["Denied tool calls (", summary.permission_denials.length, ")"] }), _jsx("div", { className: "tv-stack tv-stack--tight", children: summary.permission_denials.map((denial, idx) => (_jsxs("div", { className: "tv-denial", children: [_jsx("code", { className: "tv-tool-name", children: denial.tool_name }), typeof denial.tool_input?.description === "string" && (_jsxs("span", { className: "tv-muted", children: [" ", "- ", denial.tool_input.description] }))] }, idx))) })] })), (summary.usage || summary.modelUsage) && (_jsxs("div", { className: "tv-summary-section", children: [_jsxs("button", { type: "button", onClick: () => setShowDetails(!showDetails), className: "tv-link-button", children: [_jsx(Chevron, { expanded: showDetails }), "Usage details"] }), showDetails && (_jsx("pre", { className: "tv-mono-text tv-mono-text--box", children: JSON.stringify({ usage: summary.usage, modelUsage: summary.modelUsage }, null, 2) }))] }))] }));
333
+ };
334
+ export default function ConversationVisualizer({ conversation, sidechainsByAgentId, className, transformLinkUrl, }) {
335
+ const lastAssistantRef = useRef(null);
336
+ const rootClass = className ? `tv ${className}` : "tv";
337
+ if (!conversation) {
338
+ return (_jsx("div", { className: rootClass, children: _jsx("div", { className: "tv-empty", children: "Select a conversation to see its messages." }) }));
339
+ }
340
+ const lastAssistantIdx = conversation.messages.reduce((last, msg, idx) => (msg.role === "assistant" ? idx : last), -1);
341
+ const scrollToResult = () => {
342
+ lastAssistantRef.current?.scrollIntoView({
343
+ behavior: "smooth",
344
+ block: "start",
345
+ });
346
+ };
347
+ const sourceLabel = SOURCE_LABELS[conversation.source] || conversation.source;
348
+ const metaParts = [];
349
+ if (conversation.subtitle)
350
+ metaParts.push(conversation.subtitle);
351
+ if (conversation.model)
352
+ metaParts.push(conversation.model);
353
+ if (conversation.status !== null && conversation.status !== undefined)
354
+ metaParts.push(`HTTP ${conversation.status}`);
355
+ if (conversation.createdAt)
356
+ metaParts.push(formatTime(conversation.createdAt));
357
+ return (_jsx(LinkTransformContext.Provider, { value: transformLinkUrl ?? null, children: _jsxs("div", { className: rootClass, children: [_jsxs("div", { className: "tv-header", children: [_jsxs("div", { className: "tv-header-text", children: [_jsx("h2", { className: "tv-title", children: conversation.title }), metaParts.length ? (_jsx("p", { className: "tv-meta", children: metaParts.join(" · ") })) : null] }), _jsxs("div", { className: "tv-header-actions", children: [lastAssistantIdx >= 0 && (_jsxs("button", { type: "button", onClick: scrollToResult, className: "tv-button tv-button--primary", title: "Jump to the final assistant message", children: [_jsx(ArrowDown, { size: 14 }), "Final message"] })), _jsx("span", { className: "tv-tag", children: sourceLabel }), conversation.tags?.map((tag) => (_jsx("span", { className: "tv-tag", children: tag }, tag)))] })] }), _jsx("section", { className: "tv-messages", children: conversation.messages.map((msg, idx) => (_jsx("div", { ref: idx === lastAssistantIdx ? lastAssistantRef : undefined, className: "tv-msg-anchor", children: _jsx(Bubble, { kind: msg.role, blocks: msg.blocks, sidechainsByAgentId: sidechainsByAgentId, depth: 0 }) }, `${msg.role}-${idx}`))) }), conversation.resultSummary && (_jsx("section", { className: "tv-section", children: _jsx(ResultSummaryView, { summary: conversation.resultSummary }) })), conversation.details?.length ? (_jsx("section", { className: "tv-section tv-stack", children: conversation.details.map((detail, idx) => (_jsxs("details", { className: "tv-details", children: [_jsx("summary", { children: detail.title }), _jsx("pre", { className: "tv-mono-text tv-mono-text--box", children: formatDetail(detail) })] }, `${detail.title}-${idx}`))) })) : null] }) }));
358
+ }
@@ -0,0 +1,5 @@
1
+ export type { ConversationVisualizerProps, TransformLinkUrl, } from "./ConversationVisualizer.js";
2
+ export { default as ConversationVisualizer, SOURCE_LABELS, } from "./ConversationVisualizer.js";
3
+ export type { JsonlKind, ParseError, ParseResult } from "./parsers.js";
4
+ export { parseClaudeContent, parseCodexContent, parseCodexHeadlessContent, parseCursorHeadlessContent, parseGeminiHeadlessContent, parseHeadlessContent, parseJsonlContent, } from "./parsers.js";
5
+ export type { ConversationSource, ConversationView, DetailSection, MessageBlock, MessageView, PermissionDenial, ResultSummary, } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as ConversationVisualizer, SOURCE_LABELS, } from "./ConversationVisualizer.js";
2
+ export { parseClaudeContent, parseCodexContent, parseCodexHeadlessContent, parseCursorHeadlessContent, parseGeminiHeadlessContent, parseHeadlessContent, parseJsonlContent, } from "./parsers.js";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Client-side JSONL parsers for Claude, Codex, and Claude Headless formats.
3
+ * These are TypeScript ports of the server-side parsers in conversation-sources.mjs,
4
+ * designed to run in the browser for URL mode.
5
+ */
6
+ import type { ConversationView } from "./types.js";
7
+ export declare function parseClaudeContent(content: string, sourceId?: string): ConversationView | null;
8
+ export declare function parseCodexContent(content: string, sourceId?: string): ConversationView | null;
9
+ export declare function parseHeadlessContent(content: string, sourceId?: string): ConversationView | null;
10
+ /**
11
+ * Parse Codex headless format.
12
+ * Events: thread.started, turn.started, item.completed, item.started, item.updated, turn.completed
13
+ * item.type: reasoning, command_execution, file_change, todo_list, agent_message
14
+ */
15
+ export declare function parseCodexHeadlessContent(content: string, sourceId?: string): ConversationView | null;
16
+ /**
17
+ * Parse Cursor headless format.
18
+ * Events: user, system/init, thinking/delta (skip), thinking/completed (skip if empty), assistant, tool_call/started, tool_call/completed, result
19
+ */
20
+ export declare function parseCursorHeadlessContent(content: string, sourceId?: string): ConversationView | null;
21
+ /**
22
+ * Parse Gemini headless format.
23
+ * Events: user, init, message, tool_use, tool_result, result
24
+ */
25
+ export declare function parseGeminiHeadlessContent(content: string, sourceId?: string): ConversationView | null;
26
+ export type JsonlKind = "claude-jsonl" | "codex-jsonl" | "claude-headless" | "codex-headless" | "gemini-headless" | "cursor-headless";
27
+ export interface ParseResult {
28
+ conversations: ConversationView[];
29
+ kind: JsonlKind;
30
+ }
31
+ export interface ParseError {
32
+ error: string;
33
+ }
34
+ /**
35
+ * Detect format and parse JSONL content.
36
+ * Returns { conversations, kind } on success, { error } on failure.
37
+ */
38
+ export declare function parseJsonlContent(content: string, sourceId: string): ParseResult | ParseError;