@andersonbcdefg/transcript-viewer 0.0.0-stage → 0.1.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 +44 -2
- package/dist/ConversationVisualizer.d.ts +8 -0
- package/dist/ConversationVisualizer.js +351 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -0
- package/dist/parsers.d.ts +38 -0
- package/dist/parsers.js +1284 -0
- package/dist/styles.css +665 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.js +1 -0
- package/package.json +47 -3
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @andersonbcdefg/transcript-viewer
|
|
2
2
|
|
|
3
|
-
|
|
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,8 @@
|
|
|
1
|
+
import type { ConversationView } from "./types.js";
|
|
2
|
+
export declare const SOURCE_LABELS: Record<string, string>;
|
|
3
|
+
export type ConversationVisualizerProps = {
|
|
4
|
+
conversation: ConversationView | null;
|
|
5
|
+
sidechainsByAgentId?: Map<string, ConversationView>;
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
export default function ConversationVisualizer({ conversation, sidechainsByAgentId, className, }: ConversationVisualizerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowDown, Check, ChevronRight, Copy } from "lucide-react";
|
|
3
|
+
import { isValidElement, useCallback, useRef, useState, } from "react";
|
|
4
|
+
import Markdown, {} 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 MarkdownContent = ({ children }) => (_jsx("div", { className: "tv-prose", children: _jsx(Markdown, { remarkPlugins: REMARK_PLUGINS, components: MARKDOWN_COMPONENTS, children: children }) }));
|
|
172
|
+
const EmbeddedSidechain = ({ sidechain, sidechainsByAgentId, depth, }) => {
|
|
173
|
+
const [expanded, setExpanded] = useState(false);
|
|
174
|
+
// Limit nesting depth to prevent infinite recursion
|
|
175
|
+
if (depth > 3) {
|
|
176
|
+
return (_jsxs("div", { className: "tv-sidechain tv-sidechain--flat", children: ["Subagent (max depth reached): ", sidechain.previewUser || sidechain.title] }));
|
|
177
|
+
}
|
|
178
|
+
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
|
|
179
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static list
|
|
180
|
+
, { kind: msg.role, blocks: msg.blocks, sidechainsByAgentId: sidechainsByAgentId, depth: depth }, `sidechain-${idx}`))) }))] }));
|
|
181
|
+
};
|
|
182
|
+
const COLLAPSIBLE_TAGS = ["INSTRUCTIONS", "environment_context"];
|
|
183
|
+
// Extract Python code from shell commands like:
|
|
184
|
+
// - python3 -c "code here"
|
|
185
|
+
// - python3 - <<'PY'\ncode\nPY
|
|
186
|
+
// - python -c 'code here'
|
|
187
|
+
const extractPythonCode = (command) => {
|
|
188
|
+
const heredocMatch = command.match(/python3?\s+-\s*<<['"]?(\w+)['"]?\n([\s\S]*?)\n\1(?:\s|$)/);
|
|
189
|
+
if (heredocMatch) {
|
|
190
|
+
return heredocMatch[2].trim();
|
|
191
|
+
}
|
|
192
|
+
const dashCMatch = command.match(/python3?\s+-c\s+(['"])([\s\S]*?)\1/);
|
|
193
|
+
if (dashCMatch) {
|
|
194
|
+
return dashCMatch[2]
|
|
195
|
+
.replace(/\\n/g, "\n")
|
|
196
|
+
.replace(/\\t/g, "\t")
|
|
197
|
+
.replace(/\\'/g, "'")
|
|
198
|
+
.replace(/\\"/g, '"')
|
|
199
|
+
.trim();
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
};
|
|
203
|
+
const parseTaggedSections = (text) => {
|
|
204
|
+
const segments = [];
|
|
205
|
+
const tagPattern = new RegExp(`<(${COLLAPSIBLE_TAGS.join("|")})>([\\s\\S]*?)</\\1>`, "g");
|
|
206
|
+
let lastIndex = 0;
|
|
207
|
+
let match = tagPattern.exec(text);
|
|
208
|
+
while (match !== null) {
|
|
209
|
+
if (match.index > lastIndex) {
|
|
210
|
+
const before = text.slice(lastIndex, match.index).trim();
|
|
211
|
+
if (before)
|
|
212
|
+
segments.push({ type: "text", content: before });
|
|
213
|
+
}
|
|
214
|
+
segments.push({ type: "tagged", tag: match[1], content: match[2].trim() });
|
|
215
|
+
lastIndex = match.index + match[0].length;
|
|
216
|
+
match = tagPattern.exec(text);
|
|
217
|
+
}
|
|
218
|
+
if (lastIndex < text.length) {
|
|
219
|
+
const after = text.slice(lastIndex).trim();
|
|
220
|
+
if (after)
|
|
221
|
+
segments.push({ type: "text", content: after });
|
|
222
|
+
}
|
|
223
|
+
return segments.length ? segments : [{ type: "text", content: text }];
|
|
224
|
+
};
|
|
225
|
+
const CollapsibleTaggedSection = ({ tag, content, }) => {
|
|
226
|
+
const [expanded, setExpanded] = useState(false);
|
|
227
|
+
const lines = content.split("\n");
|
|
228
|
+
const preview = lines.slice(0, 3).join("\n");
|
|
229
|
+
const hasMore = lines.length > 3;
|
|
230
|
+
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 ? "..." : ""] })] })] }) }));
|
|
231
|
+
};
|
|
232
|
+
const ToolCallBlock = ({ block }) => {
|
|
233
|
+
const [expanded, setExpanded] = useState(false);
|
|
234
|
+
const toolName = block.json && typeof block.json === "object" && "name" in block.json
|
|
235
|
+
? block.json.name
|
|
236
|
+
: block.text;
|
|
237
|
+
// Claude uses 'input' (object), Codex uses 'arguments' (JSON string)
|
|
238
|
+
let toolInput = null;
|
|
239
|
+
if (block.json && typeof block.json === "object") {
|
|
240
|
+
if ("input" in block.json) {
|
|
241
|
+
toolInput = block.json.input;
|
|
242
|
+
}
|
|
243
|
+
else if ("arguments" in block.json) {
|
|
244
|
+
const args = block.json.arguments;
|
|
245
|
+
try {
|
|
246
|
+
toolInput = args ? JSON.parse(args) : null;
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
toolInput = args;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const shellCommand = toolInput && typeof toolInput === "object" && "command" in toolInput
|
|
254
|
+
? toolInput.command
|
|
255
|
+
: null;
|
|
256
|
+
const pythonCode = typeof shellCommand === "string" ? extractPythonCode(shellCommand) : null;
|
|
257
|
+
const inputPreview = toolInput ? JSON.stringify(toolInput) : "";
|
|
258
|
+
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"
|
|
259
|
+
? toolInput
|
|
260
|
+
: JSON.stringify(toolInput, null, 2) })) }))] }));
|
|
261
|
+
};
|
|
262
|
+
const ToolResultBlock = ({ block, sidechainsByAgentId, depth, }) => {
|
|
263
|
+
const [expanded, setExpanded] = useState(false);
|
|
264
|
+
const sidechain = block.agentId && sidechainsByAgentId?.get(block.agentId);
|
|
265
|
+
const text = block.text || "-";
|
|
266
|
+
const lines = text.split("\n");
|
|
267
|
+
let preview = lines.slice(0, 3).join("\n");
|
|
268
|
+
let hasMore = lines.length > 3;
|
|
269
|
+
if (preview.length > 800) {
|
|
270
|
+
preview = preview.slice(0, 800);
|
|
271
|
+
hasMore = true;
|
|
272
|
+
}
|
|
273
|
+
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 ? "..." : ""] })] })] }) })] }));
|
|
274
|
+
};
|
|
275
|
+
// Render a single block - tool calls and results collapse; text renders as markdown
|
|
276
|
+
const BlockRenderer = ({ block, sidechainsByAgentId, depth, }) => {
|
|
277
|
+
if (block.type === "tool_use" || block.type === "tool_call") {
|
|
278
|
+
return _jsx(ToolCallBlock, { block: block });
|
|
279
|
+
}
|
|
280
|
+
if (block.type === "tool_result") {
|
|
281
|
+
return (_jsx(ToolResultBlock, { block: block, sidechainsByAgentId: sidechainsByAgentId, depth: depth }));
|
|
282
|
+
}
|
|
283
|
+
if (block.type === "thinking") {
|
|
284
|
+
return (_jsxs("div", { className: "tv-thinking", children: [_jsx("div", { className: "tv-row-label", children: "Thinking" }), _jsx(MarkdownContent, { children: block.text || "-" })] }));
|
|
285
|
+
}
|
|
286
|
+
const text = block.text || "-";
|
|
287
|
+
const segments = parseTaggedSections(text);
|
|
288
|
+
if (segments.length === 1 && segments[0].type === "text") {
|
|
289
|
+
return _jsx(MarkdownContent, { children: text });
|
|
290
|
+
}
|
|
291
|
+
return (_jsx("div", { className: "tv-stack", children: segments.map((segment, idx) => segment.type === "tagged" ? (_jsx(CollapsibleTaggedSection
|
|
292
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static parsed segments
|
|
293
|
+
, { tag: segment.tag, content: segment.content }, idx)) : (
|
|
294
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static parsed segments
|
|
295
|
+
_jsx(MarkdownContent, { children: segment.content }, idx))) }));
|
|
296
|
+
};
|
|
297
|
+
const Bubble = ({ kind, blocks, sidechainsByAgentId, depth = 0, }) => {
|
|
298
|
+
const roleClass = ROLE_LABELS[kind] ? kind : "other";
|
|
299
|
+
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
|
|
300
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static list
|
|
301
|
+
, { block: block, sidechainsByAgentId: sidechainsByAgentId, depth: depth }, `block-${idx}`)))) : (_jsx("span", { className: "tv-muted", children: "-" })) })] }));
|
|
302
|
+
};
|
|
303
|
+
const formatDuration = (ms) => {
|
|
304
|
+
if (ms < 1000)
|
|
305
|
+
return `${ms}ms`;
|
|
306
|
+
const seconds = Math.floor(ms / 1000);
|
|
307
|
+
if (seconds < 60)
|
|
308
|
+
return `${seconds}s`;
|
|
309
|
+
const minutes = Math.floor(seconds / 60);
|
|
310
|
+
const remainingSeconds = seconds % 60;
|
|
311
|
+
return `${minutes}m ${remainingSeconds}s`;
|
|
312
|
+
};
|
|
313
|
+
const formatCost = (cost) => {
|
|
314
|
+
if (cost === undefined || cost === null)
|
|
315
|
+
return "-";
|
|
316
|
+
return `$${cost.toFixed(4)}`;
|
|
317
|
+
};
|
|
318
|
+
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 })] }));
|
|
319
|
+
const ResultSummaryView = ({ summary }) => {
|
|
320
|
+
const [showDetails, setShowDetails] = useState(false);
|
|
321
|
+
const usage = summary.usage && typeof summary.usage === "object"
|
|
322
|
+
? summary.usage
|
|
323
|
+
: null;
|
|
324
|
+
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 &&
|
|
325
|
+
(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) }))] }))] }));
|
|
326
|
+
};
|
|
327
|
+
export default function ConversationVisualizer({ conversation, sidechainsByAgentId, className, }) {
|
|
328
|
+
const lastAssistantRef = useRef(null);
|
|
329
|
+
const rootClass = className ? `tv ${className}` : "tv";
|
|
330
|
+
if (!conversation) {
|
|
331
|
+
return (_jsx("div", { className: rootClass, children: _jsx("div", { className: "tv-empty", children: "Select a conversation to see its messages." }) }));
|
|
332
|
+
}
|
|
333
|
+
const lastAssistantIdx = conversation.messages.reduce((last, msg, idx) => (msg.role === "assistant" ? idx : last), -1);
|
|
334
|
+
const scrollToResult = () => {
|
|
335
|
+
lastAssistantRef.current?.scrollIntoView({
|
|
336
|
+
behavior: "smooth",
|
|
337
|
+
block: "start",
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
const sourceLabel = SOURCE_LABELS[conversation.source] || conversation.source;
|
|
341
|
+
const metaParts = [];
|
|
342
|
+
if (conversation.subtitle)
|
|
343
|
+
metaParts.push(conversation.subtitle);
|
|
344
|
+
if (conversation.model)
|
|
345
|
+
metaParts.push(conversation.model);
|
|
346
|
+
if (conversation.status !== null && conversation.status !== undefined)
|
|
347
|
+
metaParts.push(`HTTP ${conversation.status}`);
|
|
348
|
+
if (conversation.createdAt)
|
|
349
|
+
metaParts.push(formatTime(conversation.createdAt));
|
|
350
|
+
return (_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] }));
|
|
351
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { ConversationVisualizerProps } 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;
|