@andersonbcdefg/transcript-viewer 0.1.0 → 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.
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { ConversationView } from "./types.js";
|
|
2
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;
|
|
3
8
|
export type ConversationVisualizerProps = {
|
|
4
9
|
conversation: ConversationView | null;
|
|
5
10
|
sidechainsByAgentId?: Map<string, ConversationView>;
|
|
6
11
|
className?: string;
|
|
12
|
+
/** Rewrites link URLs inside messages (e.g. agent output paths to real files). */
|
|
13
|
+
transformLinkUrl?: TransformLinkUrl;
|
|
7
14
|
};
|
|
8
|
-
export default function ConversationVisualizer({ conversation, sidechainsByAgentId, className, }: ConversationVisualizerProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export default function ConversationVisualizer({ conversation, sidechainsByAgentId, className, transformLinkUrl, }: ConversationVisualizerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { ArrowDown, Check, ChevronRight, Copy } from "lucide-react";
|
|
3
|
-
import { isValidElement, useCallback, useRef, useState, } from "react";
|
|
4
|
-
import Markdown, {} from "react-markdown";
|
|
3
|
+
import { createContext, isValidElement, useCallback, useContext, useRef, useState, } from "react";
|
|
4
|
+
import Markdown, { defaultUrlTransform } from "react-markdown";
|
|
5
5
|
import { PrismLight as SyntaxHighlighter } from "react-syntax-highlighter";
|
|
6
6
|
import bash from "react-syntax-highlighter/dist/esm/languages/prism/bash";
|
|
7
7
|
import diff from "react-syntax-highlighter/dist/esm/languages/prism/diff";
|
|
@@ -168,7 +168,14 @@ const MARKDOWN_COMPONENTS = {
|
|
|
168
168
|
};
|
|
169
169
|
// Agents write single newlines as line breaks, so honor them like a terminal would.
|
|
170
170
|
const REMARK_PLUGINS = [remarkGfm, remarkBreaks];
|
|
171
|
-
const
|
|
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
|
+
};
|
|
172
179
|
const EmbeddedSidechain = ({ sidechain, sidechainsByAgentId, depth, }) => {
|
|
173
180
|
const [expanded, setExpanded] = useState(false);
|
|
174
181
|
// Limit nesting depth to prevent infinite recursion
|
|
@@ -324,7 +331,7 @@ const ResultSummaryView = ({ summary }) => {
|
|
|
324
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 &&
|
|
325
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) }))] }))] }));
|
|
326
333
|
};
|
|
327
|
-
export default function ConversationVisualizer({ conversation, sidechainsByAgentId, className, }) {
|
|
334
|
+
export default function ConversationVisualizer({ conversation, sidechainsByAgentId, className, transformLinkUrl, }) {
|
|
328
335
|
const lastAssistantRef = useRef(null);
|
|
329
336
|
const rootClass = className ? `tv ${className}` : "tv";
|
|
330
337
|
if (!conversation) {
|
|
@@ -347,5 +354,5 @@ export default function ConversationVisualizer({ conversation, sidechainsByAgent
|
|
|
347
354
|
metaParts.push(`HTTP ${conversation.status}`);
|
|
348
355
|
if (conversation.createdAt)
|
|
349
356
|
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] }));
|
|
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] }) }));
|
|
351
358
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ConversationVisualizerProps } from "./ConversationVisualizer.js";
|
|
1
|
+
export type { ConversationVisualizerProps, TransformLinkUrl, } from "./ConversationVisualizer.js";
|
|
2
2
|
export { default as ConversationVisualizer, SOURCE_LABELS, } from "./ConversationVisualizer.js";
|
|
3
3
|
export type { JsonlKind, ParseError, ParseResult } from "./parsers.js";
|
|
4
4
|
export { parseClaudeContent, parseCodexContent, parseCodexHeadlessContent, parseCursorHeadlessContent, parseGeminiHeadlessContent, parseHeadlessContent, parseJsonlContent, } from "./parsers.js";
|