@linxiraos/pi-stats 1.4.6 → 1.4.9
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/CHANGELOG.md +15 -1
- package/README.md +18 -18
- package/dist/client/index.js +86 -86
- package/dist/types/chunked-insert.d.ts +32 -0
- package/dist/types/client/api.d.ts +4 -0
- package/dist/types/client/app/CloseButton.d.ts +7 -0
- package/dist/types/client/app/keys.d.ts +9 -0
- package/dist/types/client/traces/SpanDrawer.d.ts +9 -3
- package/dist/types/client/traces/TimelineCanvas.d.ts +3 -1
- package/dist/types/client/traces/TraceView.d.ts +13 -0
- package/dist/types/client/traces/index.d.ts +5 -0
- package/dist/types/client/traces/trace-colors.d.ts +3 -1
- package/dist/types/client/ui/SearchInput.d.ts +2 -1
- package/dist/types/db.d.ts +5 -5
- package/dist/types/index.d.ts +1 -1
- package/dist/types/parser.d.ts +1 -1
- package/dist/types/port-conflict.d.ts +9 -3
- package/dist/types/server.d.ts +14 -3
- package/dist/types/shared-types.d.ts +3 -2
- package/dist/types/trace.d.ts +27 -1
- package/dist/types/types.d.ts +6 -1
- package/package.json +12 -10
- package/src/chunked-insert.ts +89 -0
- package/src/client/api.ts +13 -0
- package/src/client/app/CloseButton.tsx +56 -0
- package/src/client/app/Shell.tsx +4 -11
- package/src/client/app/keys.ts +21 -0
- package/src/client/data/query.ts +12 -4
- package/src/client/react-css.d.ts +8 -0
- package/src/client/traces/SpanDrawer.tsx +58 -10
- package/src/client/traces/TimelineCanvas.tsx +13 -4
- package/src/client/traces/TraceView.tsx +171 -153
- package/src/client/traces/TranscriptList.tsx +1 -1
- package/src/client/traces/index.ts +5 -0
- package/src/client/traces/trace-colors.ts +14 -10
- package/src/client/ui/Card.tsx +2 -2
- package/src/client/ui/Drawer.tsx +2 -2
- package/src/client/ui/SearchInput.tsx +9 -1
- package/src/client/ui/Stat.tsx +2 -5
- package/src/db.ts +203 -151
- package/src/index.ts +1 -1
- package/src/parser.ts +22 -6
- package/src/port-conflict.ts +67 -30
- package/src/server.ts +63 -31
- package/src/shared-types.ts +3 -2
- package/src/trace.ts +119 -35
- package/src/types.ts +6 -1
package/src/client/data/query.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* can resolve to that same object; an unchanged reference does not re-render.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
import { toError } from "@linxiraos/pi-utils/type-guards";
|
|
18
19
|
import { startTransition, useCallback, useEffect, useReducer, useRef, useState } from "react";
|
|
19
20
|
import { currentLiveVersion, useLiveVersion } from "./live";
|
|
20
21
|
import { cachedEntry, type Inflight, inflightRequest, loadQuery, type QueryFetcher, releaseQuery } from "./query-store";
|
|
@@ -60,6 +61,7 @@ export function useQuery<T>(key: readonly unknown[], fetcher: QueryFetcher<T>, o
|
|
|
60
61
|
const version = useLiveVersion(enabled);
|
|
61
62
|
|
|
62
63
|
const [, rerender] = useReducer((n: number) => n + 1, 0);
|
|
64
|
+
const [settled, recheck] = useReducer((n: number) => n + 1, 0);
|
|
63
65
|
const [error, setError] = useState<{ key: string; error: Error } | null>(null);
|
|
64
66
|
const [refreshing, setRefreshing] = useState(false);
|
|
65
67
|
|
|
@@ -82,8 +84,10 @@ export function useQuery<T>(key: readonly unknown[], fetcher: QueryFetcher<T>, o
|
|
|
82
84
|
waiting.current = { key: targetKey, request };
|
|
83
85
|
// Join the new request before leaving the old one, so a shared request isn't aborted in between.
|
|
84
86
|
if (current) releaseQuery(current.key, current.request);
|
|
87
|
+
let succeeded = false;
|
|
85
88
|
request.promise
|
|
86
89
|
.then(data => {
|
|
90
|
+
succeeded = true;
|
|
87
91
|
if (keyRef.current !== targetKey) return;
|
|
88
92
|
// Revalidated to the very same object: nothing on screen changes.
|
|
89
93
|
if (data === shownBefore) {
|
|
@@ -97,11 +101,15 @@ export function useQuery<T>(key: readonly unknown[], fetcher: QueryFetcher<T>, o
|
|
|
97
101
|
})
|
|
98
102
|
.catch((err: unknown) => {
|
|
99
103
|
if (keyRef.current !== targetKey || request.controller.signal.aborted) return;
|
|
100
|
-
setError({ key: targetKey, error:
|
|
104
|
+
setError({ key: targetKey, error: toError(err) });
|
|
101
105
|
})
|
|
102
106
|
.finally(() => {
|
|
103
|
-
if (waiting.current?.request
|
|
104
|
-
|
|
107
|
+
if (waiting.current?.request !== request) return;
|
|
108
|
+
waiting.current = null;
|
|
109
|
+
if (keyRef.current !== targetKey) return;
|
|
110
|
+
setRefreshing(false);
|
|
111
|
+
// A newer live version may have arrived while this older request was in flight.
|
|
112
|
+
if (succeeded && (cachedEntry(targetKey)?.version ?? -1) < currentLiveVersion()) recheck();
|
|
105
113
|
});
|
|
106
114
|
}, []);
|
|
107
115
|
|
|
@@ -128,7 +136,7 @@ export function useQuery<T>(key: readonly unknown[], fetcher: QueryFetcher<T>, o
|
|
|
128
136
|
}
|
|
129
137
|
const timer = setTimeout(() => run(keyString), wait);
|
|
130
138
|
return () => clearTimeout(timer);
|
|
131
|
-
}, [keyString, enabled, version, run, leave]);
|
|
139
|
+
}, [keyString, enabled, version, settled, run, leave]);
|
|
132
140
|
|
|
133
141
|
useEffect(() => {
|
|
134
142
|
if (!enabled || !pollMs) return;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Detail drawer for a selected trace span.
|
|
3
|
-
* demand (
|
|
2
|
+
* Detail drawer for a selected trace span. Loads the full journal entry on
|
|
3
|
+
* demand (live API or embedded snapshot) and renders per-kind detail: model usage grid
|
|
4
4
|
* + text blocks, tool args/result, user text, subagent task text.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { toError } from "@linxiraos/pi-utils/type-guards";
|
|
8
|
+
import { Check, Copy, X } from "lucide-react";
|
|
8
9
|
import { type ReactNode, useEffect, useRef, useState } from "react";
|
|
9
10
|
import { getSessionEntryDetail } from "../api";
|
|
10
11
|
import { formatDurationMs, formatInteger } from "../data/formatters";
|
|
11
12
|
import { t } from "../i18n";
|
|
12
13
|
import type { TraceSpan, TraceTrack } from "../types";
|
|
13
|
-
import { Badge, Drawer, ErrorState, JsonBlock, KeyValues, Skeleton } from "../ui";
|
|
14
|
+
import { Badge, Drawer, type DrawerProps, ErrorState, JsonBlock, KeyValues, Skeleton } from "../ui";
|
|
15
|
+
|
|
16
|
+
export type TraceEntryLoader = (file: string, entryId: string, signal: AbortSignal) => Promise<{ entry: unknown }>;
|
|
14
17
|
|
|
15
18
|
export interface SpanDrawerProps {
|
|
16
19
|
span: TraceSpan | null;
|
|
@@ -18,6 +21,9 @@ export interface SpanDrawerProps {
|
|
|
18
21
|
onClose: () => void;
|
|
19
22
|
/** Selects the first span of the given child track ("open child track"). */
|
|
20
23
|
onOpenChildTrack?: (childTrackId: string) => void;
|
|
24
|
+
loadEntry?: TraceEntryLoader;
|
|
25
|
+
inline?: boolean;
|
|
26
|
+
onNavigate?: (trackId: string, entryId: string) => void;
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
/** Loose structural view of a fetched journal entry (validated field-by-field). */
|
|
@@ -61,7 +67,33 @@ function textBlocks(content: unknown): Array<{ kind: string; text: string }> {
|
|
|
61
67
|
return blocks;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
|
|
70
|
+
function InlineSpanDetail({ title, subtitle, actions, onClose, children }: DrawerProps) {
|
|
71
|
+
return (
|
|
72
|
+
<section className="traces-inline-detail" aria-label="Selected span details">
|
|
73
|
+
<header className="drawer-header">
|
|
74
|
+
<div className="drawer-titles">
|
|
75
|
+
<h2 className="drawer-title">{title}</h2>
|
|
76
|
+
{subtitle !== undefined && <div className="drawer-subtitle">{subtitle}</div>}
|
|
77
|
+
</div>
|
|
78
|
+
{actions}
|
|
79
|
+
<button type="button" className="btn" data-icon="true" onClick={onClose} aria-label="Close span details">
|
|
80
|
+
<X size={16} />
|
|
81
|
+
</button>
|
|
82
|
+
</header>
|
|
83
|
+
<div className="drawer-body">{children}</div>
|
|
84
|
+
</section>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function SpanDrawer({
|
|
89
|
+
span,
|
|
90
|
+
track,
|
|
91
|
+
onClose,
|
|
92
|
+
onOpenChildTrack,
|
|
93
|
+
loadEntry = getSessionEntryDetail,
|
|
94
|
+
inline = false,
|
|
95
|
+
onNavigate,
|
|
96
|
+
}: SpanDrawerProps) {
|
|
65
97
|
const [entry, setEntry] = useState<unknown>(null);
|
|
66
98
|
const [loading, setLoading] = useState(false);
|
|
67
99
|
const [error, setError] = useState<Error | null>(null);
|
|
@@ -76,19 +108,19 @@ export function SpanDrawer({ span, track, onClose, onOpenChildTrack }: SpanDrawe
|
|
|
76
108
|
if (!span || !track || !span.entryId) return;
|
|
77
109
|
setLoading(true);
|
|
78
110
|
const controller = new AbortController();
|
|
79
|
-
|
|
111
|
+
loadEntry(track.file, span.entryId, controller.signal)
|
|
80
112
|
.then(data => {
|
|
81
113
|
if (!controller.signal.aborted) setEntry(data.entry);
|
|
82
114
|
})
|
|
83
115
|
.catch(err => {
|
|
84
116
|
if (controller.signal.aborted) return;
|
|
85
|
-
setError(
|
|
117
|
+
setError(toError(err));
|
|
86
118
|
})
|
|
87
119
|
.finally(() => {
|
|
88
120
|
if (!controller.signal.aborted) setLoading(false);
|
|
89
121
|
});
|
|
90
122
|
return () => controller.abort();
|
|
91
|
-
}, [span, track]);
|
|
123
|
+
}, [span, track, loadEntry]);
|
|
92
124
|
|
|
93
125
|
useEffect(() => () => window.clearTimeout(copyResetRef.current), []);
|
|
94
126
|
|
|
@@ -172,8 +204,10 @@ export function SpanDrawer({ span, track, onClose, onOpenChildTrack }: SpanDrawe
|
|
|
172
204
|
});
|
|
173
205
|
}
|
|
174
206
|
|
|
207
|
+
const DetailShell = inline ? InlineSpanDetail : Drawer;
|
|
208
|
+
|
|
175
209
|
return (
|
|
176
|
-
<
|
|
210
|
+
<DetailShell
|
|
177
211
|
open
|
|
178
212
|
onClose={onClose}
|
|
179
213
|
title={span.label}
|
|
@@ -200,6 +234,20 @@ export function SpanDrawer({ span, track, onClose, onOpenChildTrack }: SpanDrawe
|
|
|
200
234
|
>
|
|
201
235
|
<div className="stack traces-drawer">
|
|
202
236
|
<KeyValues items={metrics} />
|
|
237
|
+
{onNavigate && track && span.entryId && (
|
|
238
|
+
<div>
|
|
239
|
+
<button
|
|
240
|
+
type="button"
|
|
241
|
+
className="btn"
|
|
242
|
+
data-size="sm"
|
|
243
|
+
onClick={() => {
|
|
244
|
+
if (span.entryId) onNavigate(track.id, span.entryId);
|
|
245
|
+
}}
|
|
246
|
+
>
|
|
247
|
+
Jump to transcript
|
|
248
|
+
</button>
|
|
249
|
+
</div>
|
|
250
|
+
)}
|
|
203
251
|
|
|
204
252
|
{msg?.errorMessage && (
|
|
205
253
|
<div className="stack" style={{ gap: 6 }}>
|
|
@@ -263,6 +311,6 @@ export function SpanDrawer({ span, track, onClose, onOpenChildTrack }: SpanDrawe
|
|
|
263
311
|
<JsonBlock data={entry} title={t("trace.raw-entry")} initialCollapsed={true} />
|
|
264
312
|
)}
|
|
265
313
|
</div>
|
|
266
|
-
</
|
|
314
|
+
</DetailShell>
|
|
267
315
|
);
|
|
268
316
|
}
|
|
@@ -33,6 +33,8 @@ export interface TimelineCanvasProps {
|
|
|
33
33
|
collapsed: ReadonlySet<string>;
|
|
34
34
|
onToggleCollapse: (trackId: string) => void;
|
|
35
35
|
traceStart: number;
|
|
36
|
+
/** Live route focuses immediately; embedded viewers wait for user interaction. */
|
|
37
|
+
autoFocus?: boolean;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
const RULER_H = 28;
|
|
@@ -223,6 +225,7 @@ export function TimelineCanvas({
|
|
|
223
225
|
collapsed,
|
|
224
226
|
onToggleCollapse,
|
|
225
227
|
traceStart,
|
|
228
|
+
autoFocus = true,
|
|
226
229
|
}: TimelineCanvasProps) {
|
|
227
230
|
const colors = useTraceTheme();
|
|
228
231
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
@@ -464,12 +467,12 @@ export function TimelineCanvas({
|
|
|
464
467
|
return;
|
|
465
468
|
}
|
|
466
469
|
event.preventDefault();
|
|
470
|
+
event.stopPropagation();
|
|
467
471
|
};
|
|
468
472
|
|
|
469
|
-
// Focus the canvas on mount so keyboard navigation works immediately.
|
|
470
473
|
useEffect(() => {
|
|
471
|
-
canvasRef.current?.focus({ preventScroll: true });
|
|
472
|
-
}, []);
|
|
474
|
+
if (autoFocus) canvasRef.current?.focus({ preventScroll: true });
|
|
475
|
+
}, [autoFocus]);
|
|
473
476
|
|
|
474
477
|
// Scene: everything except hover/selection, so pointer moves never repaint it.
|
|
475
478
|
useEffect(() => {
|
|
@@ -604,7 +607,13 @@ export function TimelineCanvas({
|
|
|
604
607
|
)}
|
|
605
608
|
</div>
|
|
606
609
|
|
|
607
|
-
{tooltip &&
|
|
610
|
+
{tooltip &&
|
|
611
|
+
createPortal(
|
|
612
|
+
tooltip,
|
|
613
|
+
containerRef.current?.getRootNode() instanceof ShadowRoot
|
|
614
|
+
? (containerRef.current.getRootNode() as ShadowRoot)
|
|
615
|
+
: document.body,
|
|
616
|
+
)}
|
|
608
617
|
</div>
|
|
609
618
|
);
|
|
610
619
|
}
|
|
@@ -13,7 +13,7 @@ import type { SessionTrace, TraceSpan, TraceSpanKind, TraceTrack } from "../type
|
|
|
13
13
|
import { Card, ChartSkeleton, PageHeader, QueryView, SearchInput, Segmented } from "../ui";
|
|
14
14
|
import { AggregatesPanel } from "./AggregatesPanel";
|
|
15
15
|
import { Minimap } from "./Minimap";
|
|
16
|
-
import { SpanDrawer } from "./SpanDrawer";
|
|
16
|
+
import { SpanDrawer, type TraceEntryLoader } from "./SpanDrawer";
|
|
17
17
|
import { SummaryStrip } from "./SummaryStrip";
|
|
18
18
|
import { TimelineCanvas, type TimelineViewport } from "./TimelineCanvas";
|
|
19
19
|
import { TranscriptList } from "./TranscriptList";
|
|
@@ -49,6 +49,56 @@ export function TraceView({ file, active, onBack }: TraceViewProps) {
|
|
|
49
49
|
// A previous session's trace must never render under this file's header.
|
|
50
50
|
const trace = query.stale ? null : query.data;
|
|
51
51
|
|
|
52
|
+
return (
|
|
53
|
+
<div className="stack traces-view">
|
|
54
|
+
<div>
|
|
55
|
+
<button type="button" className="btn" data-variant="ghost" data-size="sm" onClick={onBack}>
|
|
56
|
+
<ArrowLeft size={14} aria-hidden="true" />
|
|
57
|
+
Sessions
|
|
58
|
+
</button>
|
|
59
|
+
</div>
|
|
60
|
+
<PageHeader
|
|
61
|
+
title={<span className="traces-title truncate">{trace?.title ?? file.split("/").pop()}</span>}
|
|
62
|
+
description={trace?.cwd ? <span className="mono">{trace.cwd}</span> : undefined}
|
|
63
|
+
actions={
|
|
64
|
+
<button
|
|
65
|
+
type="button"
|
|
66
|
+
className="btn"
|
|
67
|
+
data-variant="ghost"
|
|
68
|
+
data-icon="true"
|
|
69
|
+
onClick={query.refetch}
|
|
70
|
+
aria-label="Refresh trace"
|
|
71
|
+
title="Refresh trace"
|
|
72
|
+
>
|
|
73
|
+
<RefreshCw size={14} className={query.refreshing ? "traces-spin" : undefined} />
|
|
74
|
+
</button>
|
|
75
|
+
}
|
|
76
|
+
/>
|
|
77
|
+
<QueryView query={{ ...query, data: trace }} skeleton={<ChartSkeleton height={420} />}>
|
|
78
|
+
{loaded => <SessionTraceView trace={loaded} />}
|
|
79
|
+
</QueryView>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Data and host integration supplied to the shared live/offline trace viewer. */
|
|
85
|
+
export interface SessionTraceViewProps {
|
|
86
|
+
trace: SessionTrace;
|
|
87
|
+
view?: "timeline" | "full";
|
|
88
|
+
loadEntry?: TraceEntryLoader;
|
|
89
|
+
/** Embedded viewers keep details inside their own layout, without a modal. */
|
|
90
|
+
embedded?: boolean;
|
|
91
|
+
onNavigate?: (trackId: string, entryId: string) => void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Data-driven viewer shared by the live route and self-contained HTML exports. */
|
|
95
|
+
export function SessionTraceView({
|
|
96
|
+
trace,
|
|
97
|
+
view = "full",
|
|
98
|
+
loadEntry,
|
|
99
|
+
embedded = false,
|
|
100
|
+
onNavigate,
|
|
101
|
+
}: SessionTraceViewProps) {
|
|
52
102
|
const [mode, setMode] = useState<AxisMode>("time");
|
|
53
103
|
const [compressIdle, setCompressIdle] = useState(true);
|
|
54
104
|
const [selection, setSelection] = useState<string | null>(null);
|
|
@@ -220,185 +270,153 @@ export function TraceView({ file, active, onBack }: TraceViewProps) {
|
|
|
220
270
|
);
|
|
221
271
|
const closeDrawer = useCallback(() => setDrawerOpen(false), []);
|
|
222
272
|
|
|
223
|
-
const traceStart = trace
|
|
224
|
-
|
|
225
|
-
const traceQuery = { ...query, data: trace };
|
|
273
|
+
const traceStart = trace.startedAt;
|
|
226
274
|
|
|
227
275
|
return (
|
|
228
|
-
<div className="stack traces-view">
|
|
229
|
-
<
|
|
230
|
-
|
|
231
|
-
<ArrowLeft size={14} aria-hidden="true" />
|
|
232
|
-
{t("trace.sessions")}
|
|
233
|
-
</button>
|
|
234
|
-
</div>
|
|
235
|
-
<PageHeader
|
|
236
|
-
title={<span className="traces-title truncate">{trace?.title ?? file.split("/").pop()}</span>}
|
|
237
|
-
description={trace?.cwd ? <span className="mono">{trace.cwd}</span> : undefined}
|
|
238
|
-
actions={
|
|
239
|
-
<button
|
|
240
|
-
type="button"
|
|
241
|
-
className="btn"
|
|
242
|
-
data-variant="ghost"
|
|
243
|
-
data-icon="true"
|
|
244
|
-
onClick={query.refetch}
|
|
245
|
-
aria-label={t("trace.refresh")}
|
|
246
|
-
title={t("trace.refresh")}
|
|
247
|
-
>
|
|
248
|
-
<RefreshCw size={14} className={query.refreshing ? "traces-spin" : undefined} />
|
|
249
|
-
</button>
|
|
250
|
-
}
|
|
251
|
-
/>
|
|
276
|
+
<div className="stack traces-view" data-view={view}>
|
|
277
|
+
{view === "full" && <SummaryStrip summary={trace.summary} />}
|
|
278
|
+
{allSpans.length === 0 && <p className="muted">No spans recorded in this session.</p>}
|
|
252
279
|
|
|
253
|
-
<
|
|
254
|
-
{
|
|
280
|
+
<Card
|
|
281
|
+
index={1}
|
|
282
|
+
title={t("trace.timeline")}
|
|
283
|
+
description={t("trace.timeline-hint")}
|
|
284
|
+
actions={
|
|
255
285
|
<>
|
|
256
|
-
<
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
286
|
+
<button
|
|
287
|
+
type="button"
|
|
288
|
+
className="btn"
|
|
289
|
+
data-variant="ghost"
|
|
290
|
+
data-size="sm"
|
|
291
|
+
onClick={() => collapseAll(false)}
|
|
292
|
+
>
|
|
293
|
+
{t("trace.expand-all")}
|
|
294
|
+
</button>
|
|
295
|
+
<button
|
|
296
|
+
type="button"
|
|
297
|
+
className="btn"
|
|
298
|
+
data-variant="ghost"
|
|
299
|
+
data-size="sm"
|
|
300
|
+
onClick={() => collapseAll(true)}
|
|
301
|
+
>
|
|
302
|
+
{t("trace.collapse-all")}
|
|
303
|
+
</button>
|
|
304
|
+
</>
|
|
305
|
+
}
|
|
306
|
+
>
|
|
307
|
+
<div className="stack">
|
|
308
|
+
<div className="traces-toolbar">
|
|
309
|
+
<Segmented
|
|
310
|
+
options={MODE_OPTIONS}
|
|
311
|
+
value={mode}
|
|
312
|
+
onChange={setMode}
|
|
313
|
+
size="sm"
|
|
314
|
+
aria-label={t("trace.axis-mode")}
|
|
315
|
+
/>
|
|
316
|
+
{mode === "time" && (
|
|
317
|
+
<label className="traces-check">
|
|
318
|
+
<input
|
|
319
|
+
type="checkbox"
|
|
320
|
+
checked={compressIdle}
|
|
321
|
+
onChange={event => setCompressIdle(event.target.checked)}
|
|
322
|
+
/>
|
|
323
|
+
{t("trace.compress-idle")}
|
|
324
|
+
</label>
|
|
325
|
+
)}
|
|
326
|
+
<div className="traces-search">
|
|
327
|
+
<SearchInput
|
|
328
|
+
value={search}
|
|
329
|
+
onChange={value => {
|
|
330
|
+
setSearch(value);
|
|
331
|
+
setMatchIndex(0);
|
|
332
|
+
}}
|
|
333
|
+
label={t("trace.search-placeholder")}
|
|
334
|
+
placeholder={t("trace.search-placeholder")}
|
|
335
|
+
width={200}
|
|
336
|
+
/>
|
|
337
|
+
{search.trim() && (
|
|
263
338
|
<>
|
|
339
|
+
<span className="num muted traces-match-count">
|
|
340
|
+
{matches.length === 0
|
|
341
|
+
? "0"
|
|
342
|
+
: `${(matchIndex % Math.max(matches.length, 1)) + 1}/${matches.length}`}
|
|
343
|
+
</span>
|
|
264
344
|
<button
|
|
265
345
|
type="button"
|
|
266
346
|
className="btn"
|
|
267
347
|
data-variant="ghost"
|
|
268
348
|
data-size="sm"
|
|
269
|
-
|
|
349
|
+
data-icon="true"
|
|
350
|
+
onClick={() => cycleMatch(-1)}
|
|
351
|
+
aria-label={t("trace.previous-match")}
|
|
352
|
+
disabled={matches.length === 0}
|
|
270
353
|
>
|
|
271
|
-
{
|
|
354
|
+
<ChevronLeft size={14} />
|
|
272
355
|
</button>
|
|
273
356
|
<button
|
|
274
357
|
type="button"
|
|
275
358
|
className="btn"
|
|
276
359
|
data-variant="ghost"
|
|
277
360
|
data-size="sm"
|
|
278
|
-
|
|
361
|
+
data-icon="true"
|
|
362
|
+
onClick={() => cycleMatch(1)}
|
|
363
|
+
aria-label={t("trace.next-match")}
|
|
364
|
+
disabled={matches.length === 0}
|
|
279
365
|
>
|
|
280
|
-
{
|
|
366
|
+
<ChevronRight size={14} />
|
|
281
367
|
</button>
|
|
282
368
|
</>
|
|
283
|
-
}
|
|
284
|
-
>
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}}
|
|
311
|
-
placeholder={t("trace.search-placeholder")}
|
|
312
|
-
width={200}
|
|
313
|
-
/>
|
|
314
|
-
{search.trim() && (
|
|
315
|
-
<>
|
|
316
|
-
<span className="num muted traces-match-count">
|
|
317
|
-
{matches.length === 0
|
|
318
|
-
? "0"
|
|
319
|
-
: `${(matchIndex % Math.max(matches.length, 1)) + 1}/${matches.length}`}
|
|
320
|
-
</span>
|
|
321
|
-
<button
|
|
322
|
-
type="button"
|
|
323
|
-
className="btn"
|
|
324
|
-
data-variant="ghost"
|
|
325
|
-
data-size="sm"
|
|
326
|
-
data-icon="true"
|
|
327
|
-
onClick={() => cycleMatch(-1)}
|
|
328
|
-
aria-label={t("trace.previous-match")}
|
|
329
|
-
disabled={matches.length === 0}
|
|
330
|
-
>
|
|
331
|
-
<ChevronLeft size={14} />
|
|
332
|
-
</button>
|
|
333
|
-
<button
|
|
334
|
-
type="button"
|
|
335
|
-
className="btn"
|
|
336
|
-
data-variant="ghost"
|
|
337
|
-
data-size="sm"
|
|
338
|
-
data-icon="true"
|
|
339
|
-
onClick={() => cycleMatch(1)}
|
|
340
|
-
aria-label={t("trace.next-match")}
|
|
341
|
-
disabled={matches.length === 0}
|
|
342
|
-
>
|
|
343
|
-
<ChevronRight size={14} />
|
|
344
|
-
</button>
|
|
345
|
-
</>
|
|
346
|
-
)}
|
|
347
|
-
</div>
|
|
348
|
-
<div className="traces-legend">
|
|
349
|
-
{LEGEND.map(item => (
|
|
350
|
-
<span key={item.kind} className="traces-legend-item">
|
|
351
|
-
<span
|
|
352
|
-
className="swatch"
|
|
353
|
-
style={{ background: `var(${CATEGORY_VARS[item.kind]})` }}
|
|
354
|
-
/>
|
|
355
|
-
{item.label}
|
|
356
|
-
</span>
|
|
357
|
-
))}
|
|
358
|
-
</div>
|
|
359
|
-
</div>
|
|
360
|
-
<Minimap
|
|
361
|
-
tracks={tracks}
|
|
362
|
-
scale={scale}
|
|
363
|
-
viewport={effectiveViewport}
|
|
364
|
-
onViewportChange={setViewport}
|
|
365
|
-
/>
|
|
366
|
-
<TimelineCanvas
|
|
367
|
-
tracks={tracks}
|
|
368
|
-
scale={scale}
|
|
369
|
-
viewport={effectiveViewport}
|
|
370
|
-
onViewportChange={setViewport}
|
|
371
|
-
selected={selected}
|
|
372
|
-
onSelect={selectAndOpen}
|
|
373
|
-
matchIds={matchIds}
|
|
374
|
-
collapsed={collapsed}
|
|
375
|
-
onToggleCollapse={toggleCollapse}
|
|
376
|
-
traceStart={traceStart}
|
|
377
|
-
/>
|
|
378
|
-
</div>
|
|
379
|
-
</Card>
|
|
380
|
-
|
|
381
|
-
<Card index={2} title={t("trace.transcript")} description={t("trace.transcript-description")} flush>
|
|
382
|
-
<TranscriptList
|
|
383
|
-
tracks={tracks}
|
|
384
|
-
selection={selection}
|
|
385
|
-
onSelect={openFromTranscript}
|
|
386
|
-
search={search}
|
|
387
|
-
matchIds={matchIds}
|
|
388
|
-
traceStart={traceStart}
|
|
389
|
-
/>
|
|
390
|
-
</Card>
|
|
391
|
-
<AggregatesPanel toolStats={loaded.summary.toolStats} index={3} />
|
|
392
|
-
</>
|
|
393
|
-
)}
|
|
394
|
-
</QueryView>
|
|
369
|
+
)}
|
|
370
|
+
</div>
|
|
371
|
+
<div className="traces-legend">
|
|
372
|
+
{LEGEND.map(item => (
|
|
373
|
+
<span key={item.kind} className="traces-legend-item">
|
|
374
|
+
<span className="swatch" style={{ background: `var(${CATEGORY_VARS[item.kind]})` }} />
|
|
375
|
+
{item.label}
|
|
376
|
+
</span>
|
|
377
|
+
))}
|
|
378
|
+
</div>
|
|
379
|
+
</div>
|
|
380
|
+
<Minimap tracks={tracks} scale={scale} viewport={effectiveViewport} onViewportChange={setViewport} />
|
|
381
|
+
<TimelineCanvas
|
|
382
|
+
tracks={tracks}
|
|
383
|
+
scale={scale}
|
|
384
|
+
viewport={effectiveViewport}
|
|
385
|
+
onViewportChange={setViewport}
|
|
386
|
+
selected={selected}
|
|
387
|
+
onSelect={selectAndOpen}
|
|
388
|
+
matchIds={matchIds}
|
|
389
|
+
collapsed={collapsed}
|
|
390
|
+
onToggleCollapse={toggleCollapse}
|
|
391
|
+
traceStart={traceStart}
|
|
392
|
+
autoFocus={!embedded}
|
|
393
|
+
/>
|
|
394
|
+
</div>
|
|
395
|
+
</Card>
|
|
395
396
|
|
|
396
397
|
<SpanDrawer
|
|
397
398
|
span={drawerOpen ? (selected?.span ?? null) : null}
|
|
398
399
|
track={selected?.track ?? null}
|
|
399
400
|
onClose={closeDrawer}
|
|
400
401
|
onOpenChildTrack={openChildTrack}
|
|
402
|
+
loadEntry={loadEntry}
|
|
403
|
+
inline={embedded}
|
|
404
|
+
onNavigate={onNavigate}
|
|
401
405
|
/>
|
|
406
|
+
|
|
407
|
+
{view === "full" && (
|
|
408
|
+
<Card index={2} title={t("trace.transcript")} description={t("trace.transcript-description")} flush>
|
|
409
|
+
<TranscriptList
|
|
410
|
+
tracks={tracks}
|
|
411
|
+
selection={selection}
|
|
412
|
+
onSelect={openFromTranscript}
|
|
413
|
+
search={search}
|
|
414
|
+
matchIds={matchIds}
|
|
415
|
+
traceStart={traceStart}
|
|
416
|
+
/>
|
|
417
|
+
</Card>
|
|
418
|
+
)}
|
|
419
|
+
{view === "full" && <AggregatesPanel toolStats={trace.summary.toolStats} index={3} />}
|
|
402
420
|
</div>
|
|
403
421
|
);
|
|
404
422
|
}
|
|
@@ -104,7 +104,7 @@ export const TranscriptList = memo(function TranscriptList({
|
|
|
104
104
|
const chipText = row.span?.kind ?? row.marker?.kind ?? "";
|
|
105
105
|
const rowContent = (
|
|
106
106
|
<>
|
|
107
|
-
<span className="traces-kind" style={{ "--traces-kind-color": color }
|
|
107
|
+
<span className="traces-kind" style={{ "--traces-kind-color": color }}>
|
|
108
108
|
{chipText}
|
|
109
109
|
</span>
|
|
110
110
|
{row.depth > 0 && (
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Shared trace UI for live dashboards and embedded offline viewers. */
|
|
2
|
+
export type { SessionTrace } from "../types";
|
|
3
|
+
export type { TraceEntryLoader } from "./SpanDrawer";
|
|
4
|
+
export { SessionTraceView, type SessionTraceViewProps } from "./TraceView";
|
|
5
|
+
export { TraceThemeRoot } from "./trace-colors";
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* design tokens so canvas drawing follows the active theme.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { useEffect, useMemo, useState } from "react";
|
|
6
|
+
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
7
7
|
import type { TraceSpanKind } from "../types";
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
/** Embedded viewers resolve canvas colors from their scoped style root. */
|
|
10
|
+
export const TraceThemeRoot = createContext<HTMLElement | null>(null);
|
|
9
11
|
|
|
10
12
|
export interface TraceTheme {
|
|
11
13
|
/** Span fill per category. */
|
|
@@ -42,8 +44,8 @@ export const CATEGORY_VARS: Record<TraceSpanKind, string> = {
|
|
|
42
44
|
background: "--ink-4",
|
|
43
45
|
};
|
|
44
46
|
|
|
45
|
-
function readTheme(): TraceTheme {
|
|
46
|
-
const style = getComputedStyle(
|
|
47
|
+
function readTheme(root: HTMLElement): TraceTheme {
|
|
48
|
+
const style = getComputedStyle(root);
|
|
47
49
|
const v = (name: string, fallback: string) => style.getPropertyValue(name).trim() || fallback;
|
|
48
50
|
return {
|
|
49
51
|
category: {
|
|
@@ -69,16 +71,18 @@ function readTheme(): TraceTheme {
|
|
|
69
71
|
|
|
70
72
|
/**
|
|
71
73
|
* Current trace palette. Re-reads the tokens whenever the resolved theme
|
|
72
|
-
* changes
|
|
74
|
+
* changes, without loading the live dashboard's theme preference store.
|
|
73
75
|
*/
|
|
74
76
|
export function useTraceTheme(): TraceTheme {
|
|
75
|
-
const
|
|
77
|
+
const root = useContext(TraceThemeRoot) ?? document.documentElement;
|
|
76
78
|
const [attrVersion, setAttrVersion] = useState(0);
|
|
77
79
|
useEffect(() => {
|
|
78
80
|
const observer = new MutationObserver(() => setAttrVersion(n => n + 1));
|
|
79
|
-
|
|
81
|
+
const options = { attributes: true, attributeFilter: ["data-theme", "style", "class"] };
|
|
82
|
+
observer.observe(document.documentElement, options);
|
|
83
|
+
if (root !== document.documentElement) observer.observe(root, options);
|
|
80
84
|
return () => observer.disconnect();
|
|
81
|
-
}, []);
|
|
82
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies:
|
|
83
|
-
return useMemo(readTheme, [
|
|
85
|
+
}, [root]);
|
|
86
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: attrVersion triggers a CSS token re-read.
|
|
87
|
+
return useMemo(() => readTheme(root), [root, attrVersion]);
|
|
84
88
|
}
|