@tonyclaw/agent-inspector 2.0.5 → 2.0.7

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.
Files changed (49) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/assets/CompareDrawer-BhRYPp6T.js +1 -0
  3. package/.output/public/assets/ProxyViewerContainer-BHq0dkQG.js +114 -0
  4. package/.output/public/assets/ReplayDialog-Ch0gwg6B.js +1 -0
  5. package/.output/public/assets/RequestAnatomy-CKbvIgaN.js +1 -0
  6. package/.output/public/assets/ResponseView-hRLar32x.js +1 -0
  7. package/.output/public/assets/StreamingChunkSequence-DCJ_gUHa.js +1 -0
  8. package/.output/public/assets/_sessionId-BJTz6t5l.js +1 -0
  9. package/.output/public/assets/index-Cf9U0Ekq.js +1 -0
  10. package/.output/public/assets/index-DTdv7nzl.css +1 -0
  11. package/.output/public/assets/{main-2NlGzgOe.js → main-BlDtK0Nn.js} +2 -2
  12. package/.output/server/_libs/lucide-react.mjs +170 -108
  13. package/.output/server/_libs/radix-ui__react-collapsible.mjs +2 -2
  14. package/.output/server/{_sessionId-DWCTasJU.mjs → _sessionId-Dy7rsLS4.mjs} +58 -5
  15. package/.output/server/_ssr/{CompareDrawer-DhrN1uC2.mjs → CompareDrawer-CkVX-ARV.mjs} +9 -8
  16. package/.output/server/_ssr/{ProxyViewerContainer-DRl51s_n.mjs → ProxyViewerContainer-B5a9p3j5.mjs} +856 -32
  17. package/.output/server/_ssr/{ReplayDialog-BQT_ygxC.mjs → ReplayDialog-hXY6H9fB.mjs} +7 -8
  18. package/.output/server/_ssr/RequestAnatomy-B6MS7VvA.mjs +576 -0
  19. package/.output/server/_ssr/{ResponseView-e0kL2C3x.mjs → ResponseView-ByjxwUnp.mjs} +5 -74
  20. package/.output/server/_ssr/{StreamingChunkSequence-BJG-m7xs.mjs → StreamingChunkSequence-C5Kb8siT.mjs} +8 -7
  21. package/.output/server/_ssr/{index-Dea3OeRw.mjs → index-BZXtj42m.mjs} +58 -5
  22. package/.output/server/_ssr/index.mjs +2 -2
  23. package/.output/server/_ssr/{router-Dl7oh0zx.mjs → router-CVQaVF_3.mjs} +5 -5
  24. package/.output/server/{_tanstack-start-manifest_v-m-FJNBVf.mjs → _tanstack-start-manifest_v-Bpe5ZC56.mjs} +1 -1
  25. package/.output/server/index.mjs +58 -65
  26. package/package.json +1 -1
  27. package/src/components/proxy-viewer/LogEntry.tsx +18 -4
  28. package/src/components/proxy-viewer/LogEntryHeader.tsx +3 -3
  29. package/src/components/proxy-viewer/RequestToolsPanel.tsx +292 -0
  30. package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +196 -45
  31. package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +92 -67
  32. package/src/components/proxy-viewer/anatomy/types.ts +15 -13
  33. package/src/components/proxy-viewer/log-formats/anthropic.ts +1 -1
  34. package/src/components/proxy-viewer/log-formats/openai.ts +1 -1
  35. package/src/components/proxy-viewer/log-formats/types.ts +1 -1
  36. package/src/components/proxy-viewer/requestTools.ts +213 -0
  37. package/src/components/ui/json-viewer.tsx +1 -1
  38. package/.output/public/assets/CompareDrawer-3nRwtk8J.js +0 -1
  39. package/.output/public/assets/ProxyViewerContainer-CbW5VRER.js +0 -101
  40. package/.output/public/assets/ReplayDialog-Cl62N9PI.js +0 -1
  41. package/.output/public/assets/RequestAnatomy-DgQWGvjs.js +0 -1
  42. package/.output/public/assets/ResponseView-Cvc-ct4E.js +0 -1
  43. package/.output/public/assets/StreamingChunkSequence-BCQaCAIe.js +0 -1
  44. package/.output/public/assets/_sessionId-CcD_aLGq.js +0 -1
  45. package/.output/public/assets/index-B_dffD3u.js +0 -1
  46. package/.output/public/assets/index-CX796gvi.css +0 -1
  47. package/.output/public/assets/json-viewer-IXejqXB0.js +0 -14
  48. package/.output/server/_ssr/RequestAnatomy-DS2tZOgq.mjs +0 -353
  49. package/.output/server/_ssr/json-viewer-DDU55MLK.mjs +0 -515
@@ -1,10 +1,9 @@
1
1
  import { r as reactExports, j as jsxRuntimeExports } from "../_libs/react.mjs";
2
- import { u as useProviders, D as Dialog, b as DialogContent, d as DialogHeader, e as DialogTitle, T as Tabs, h as TabsList, i as TabsTrigger, j as TabsContent, k as TooltipProvider, l as Tooltip, m as TooltipTrigger, n as TooltipContent, o as Button } from "./ProxyViewerContainer-DRl51s_n.mjs";
3
- import { ResponseView } from "./ResponseView-e0kL2C3x.mjs";
4
- import "./router-Dl7oh0zx.mjs";
2
+ import { u as useProviders, D as Dialog, b as DialogContent, d as DialogHeader, e as DialogTitle, T as Tabs, h as TabsList, i as TabsTrigger, j as TabsContent, k as TooltipProvider, l as Tooltip, m as TooltipTrigger, n as TooltipContent, o as Button } from "./ProxyViewerContainer-B5a9p3j5.mjs";
3
+ import { ResponseView } from "./ResponseView-ByjxwUnp.mjs";
4
+ import "./router-CVQaVF_3.mjs";
5
5
  import "../_libs/modelcontextprotocol__server.mjs";
6
6
  import "../_libs/jszip.mjs";
7
- import "./json-viewer-DDU55MLK.mjs";
8
7
  import { I as RotateCcw } from "../_libs/lucide-react.mjs";
9
8
  import { d as object, c as boolean, n as number, b as string } from "../_libs/zod.mjs";
10
9
  import "../_libs/swr.mjs";
@@ -58,9 +57,6 @@ import "../_libs/radix-ui__react-arrow.mjs";
58
57
  import "../_libs/radix-ui__react-use-size.mjs";
59
58
  import "../_libs/radix-ui__react-use-previous.mjs";
60
59
  import "../_libs/@radix-ui/react-visually-hidden+[...].mjs";
61
- import "../_libs/radix-ui__react-tooltip.mjs";
62
- import "../_libs/radix-ui__react-tabs.mjs";
63
- import "../_libs/radix-ui__react-roving-focus.mjs";
64
60
  import "../_libs/react-markdown.mjs";
65
61
  import "../_libs/devlop.mjs";
66
62
  import "../_libs/unified.mjs";
@@ -115,9 +111,12 @@ import "../_libs/inline-style-parser.mjs";
115
111
  import "../_libs/hast-util-whitespace.mjs";
116
112
  import "../_libs/estree-util-is-identifier-name.mjs";
117
113
  import "../_libs/html-url-attributes.mjs";
118
- import "../_libs/radix-ui__react-separator.mjs";
114
+ import "../_libs/radix-ui__react-tooltip.mjs";
115
+ import "../_libs/radix-ui__react-tabs.mjs";
116
+ import "../_libs/radix-ui__react-roving-focus.mjs";
119
117
  import "../_libs/radix-ui__react-collapsible.mjs";
120
118
  import "../_libs/radix-ui__react-scroll-area.mjs";
119
+ import "../_libs/radix-ui__react-separator.mjs";
121
120
  import "../_libs/tanstack__react-router.mjs";
122
121
  import "../_libs/tiny-warning.mjs";
123
122
  import "../_libs/tanstack__router-core.mjs";
@@ -0,0 +1,576 @@
1
+ import { r as reactExports, j as jsxRuntimeExports } from "../_libs/react.mjs";
2
+ import { f as formatTokens, k as TooltipProvider, c as cn, l as Tooltip, m as TooltipTrigger, n as TooltipContent } from "./ProxyViewerContainer-B5a9p3j5.mjs";
3
+ import "./router-CVQaVF_3.mjs";
4
+ import "../_libs/modelcontextprotocol__server.mjs";
5
+ import "../_libs/jszip.mjs";
6
+ import { aa as Info } from "../_libs/lucide-react.mjs";
7
+ import "../_libs/swr.mjs";
8
+ import "../_libs/use-sync-external-store.mjs";
9
+ import "../_libs/dequal.mjs";
10
+ import "../_libs/clsx.mjs";
11
+ import "../_libs/tailwind-merge.mjs";
12
+ import "../_libs/class-variance-authority.mjs";
13
+ import "../_libs/radix-ui__react-dialog.mjs";
14
+ import "../_libs/radix-ui__primitive.mjs";
15
+ import "../_libs/radix-ui__react-compose-refs.mjs";
16
+ import "../_libs/radix-ui__react-context.mjs";
17
+ import "../_libs/radix-ui__react-id.mjs";
18
+ import "../_libs/@radix-ui/react-use-layout-effect+[...].mjs";
19
+ import "../_libs/@radix-ui/react-use-controllable-state+[...].mjs";
20
+ import "../_libs/@radix-ui/react-dismissable-layer+[...].mjs";
21
+ import "../_libs/radix-ui__react-primitive.mjs";
22
+ import "../_libs/react-dom.mjs";
23
+ import "util";
24
+ import "async_hooks";
25
+ import "stream";
26
+ import "crypto";
27
+ import "../_libs/radix-ui__react-slot.mjs";
28
+ import "../_libs/@radix-ui/react-use-callback-ref+[...].mjs";
29
+ import "../_libs/@radix-ui/react-use-escape-keydown+[...].mjs";
30
+ import "../_libs/radix-ui__react-focus-scope.mjs";
31
+ import "../_libs/radix-ui__react-portal.mjs";
32
+ import "../_libs/radix-ui__react-presence.mjs";
33
+ import "../_libs/radix-ui__react-focus-guards.mjs";
34
+ import "../_libs/react-remove-scroll.mjs";
35
+ import "tslib";
36
+ import "../_libs/react-remove-scroll-bar.mjs";
37
+ import "../_libs/react-style-singleton.mjs";
38
+ import "../_libs/get-nonce.mjs";
39
+ import "../_libs/use-sidecar.mjs";
40
+ import "../_libs/use-callback-ref.mjs";
41
+ import "../_libs/aria-hidden.mjs";
42
+ import "../_libs/diff.mjs";
43
+ import "../_libs/tanstack__react-virtual.mjs";
44
+ import "../_libs/tanstack__virtual-core.mjs";
45
+ import "../_libs/radix-ui__react-select.mjs";
46
+ import "../_libs/radix-ui__number.mjs";
47
+ import "../_libs/radix-ui__react-collection.mjs";
48
+ import "../_libs/radix-ui__react-direction.mjs";
49
+ import "../_libs/radix-ui__react-popper.mjs";
50
+ import "../_libs/floating-ui__react-dom.mjs";
51
+ import "../_libs/floating-ui__dom.mjs";
52
+ import "../_libs/floating-ui__core.mjs";
53
+ import "../_libs/floating-ui__utils.mjs";
54
+ import "../_libs/radix-ui__react-arrow.mjs";
55
+ import "../_libs/radix-ui__react-use-size.mjs";
56
+ import "../_libs/radix-ui__react-use-previous.mjs";
57
+ import "../_libs/@radix-ui/react-visually-hidden+[...].mjs";
58
+ import "../_libs/react-markdown.mjs";
59
+ import "../_libs/devlop.mjs";
60
+ import "../_libs/unified.mjs";
61
+ import "../_libs/bail.mjs";
62
+ import "../_libs/extend.mjs";
63
+ import "../_libs/is-plain-obj.mjs";
64
+ import "../_libs/trough.mjs";
65
+ import "../_libs/vfile.mjs";
66
+ import "../_libs/vfile-message.mjs";
67
+ import "../_libs/unist-util-stringify-position.mjs";
68
+ import "node:process";
69
+ import "node:path";
70
+ import "node:url";
71
+ import "../_libs/remark-parse.mjs";
72
+ import "../_libs/mdast-util-from-markdown.mjs";
73
+ import "../_libs/micromark-util-decode-numeric-character-reference+[...].mjs";
74
+ import "../_libs/micromark-util-decode-string.mjs";
75
+ import "../_libs/decode-named-character-reference+[...].mjs";
76
+ import "../_libs/character-entities.mjs";
77
+ import "../_libs/micromark-util-normalize-identifier+[...].mjs";
78
+ import "../_libs/micromark.mjs";
79
+ import "../_libs/micromark-util-combine-extensions+[...].mjs";
80
+ import "../_libs/micromark-util-chunked.mjs";
81
+ import "../_libs/micromark-factory-space.mjs";
82
+ import "../_libs/micromark-util-character.mjs";
83
+ import "../_libs/micromark-core-commonmark.mjs";
84
+ import "../_libs/micromark-util-classify-character+[...].mjs";
85
+ import "../_libs/micromark-util-resolve-all.mjs";
86
+ import "../_libs/micromark-util-subtokenize.mjs";
87
+ import "../_libs/micromark-factory-destination.mjs";
88
+ import "../_libs/micromark-factory-label.mjs";
89
+ import "../_libs/micromark-factory-title.mjs";
90
+ import "../_libs/micromark-factory-whitespace.mjs";
91
+ import "../_libs/micromark-util-html-tag-name.mjs";
92
+ import "../_libs/mdast-util-to-string.mjs";
93
+ import "../_libs/remark-rehype.mjs";
94
+ import "../_libs/mdast-util-to-hast.mjs";
95
+ import "../_libs/ungap__structured-clone.mjs";
96
+ import "../_libs/micromark-util-sanitize-uri.mjs";
97
+ import "../_libs/unist-util-position.mjs";
98
+ import "../_libs/trim-lines.mjs";
99
+ import "../_libs/unist-util-visit.mjs";
100
+ import "../_libs/unist-util-visit-parents.mjs";
101
+ import "../_libs/unist-util-is.mjs";
102
+ import "../_libs/hast-util-to-jsx-runtime.mjs";
103
+ import "../_libs/comma-separated-tokens.mjs";
104
+ import "../_libs/property-information.mjs";
105
+ import "../_libs/space-separated-tokens.mjs";
106
+ import "../_libs/style-to-js.mjs";
107
+ import "../_libs/style-to-object.mjs";
108
+ import "../_libs/inline-style-parser.mjs";
109
+ import "../_libs/hast-util-whitespace.mjs";
110
+ import "../_libs/estree-util-is-identifier-name.mjs";
111
+ import "../_libs/html-url-attributes.mjs";
112
+ import "../_libs/zod.mjs";
113
+ import "../_libs/radix-ui__react-tooltip.mjs";
114
+ import "../_libs/radix-ui__react-tabs.mjs";
115
+ import "../_libs/radix-ui__react-roving-focus.mjs";
116
+ import "../_libs/radix-ui__react-collapsible.mjs";
117
+ import "../_libs/radix-ui__react-scroll-area.mjs";
118
+ import "../_libs/tanstack__react-router.mjs";
119
+ import "../_libs/tiny-warning.mjs";
120
+ import "../_libs/tanstack__router-core.mjs";
121
+ import "../_libs/cookie-es.mjs";
122
+ import "../_libs/tanstack__history.mjs";
123
+ import "../_libs/tiny-invariant.mjs";
124
+ import "../_libs/seroval.mjs";
125
+ import "../_libs/seroval-plugins.mjs";
126
+ import "node:stream/web";
127
+ import "node:stream";
128
+ import "../_libs/isbot.mjs";
129
+ import "node:fs";
130
+ import "node:fs/promises";
131
+ import "node:buffer";
132
+ import "node:child_process";
133
+ import "../_libs/conf.mjs";
134
+ import "node:util";
135
+ import "node:crypto";
136
+ import "node:assert";
137
+ import "../_libs/dot-prop.mjs";
138
+ import "../_libs/env-paths.mjs";
139
+ import "node:os";
140
+ import "../_libs/atomically.mjs";
141
+ import "../_libs/stubborn-fs.mjs";
142
+ import "../_libs/stubborn-utils.mjs";
143
+ import "../_libs/when-exit.mjs";
144
+ import "../_libs/ajv.mjs";
145
+ import "../_libs/fast-deep-equal.mjs";
146
+ import "../_libs/json-schema-traverse.mjs";
147
+ import "../_libs/fast-uri.mjs";
148
+ import "../_libs/ajv-formats.mjs";
149
+ import "../_libs/debounce-fn.mjs";
150
+ import "../_libs/mimic-function.mjs";
151
+ import "../_libs/semver.mjs";
152
+ import "../_libs/uint8array-extras.mjs";
153
+ import "node:worker_threads";
154
+ import "../_libs/readable-stream.mjs";
155
+ import "events";
156
+ import "node:string_decoder";
157
+ import "../_libs/process-nextick-args.mjs";
158
+ import "../_libs/isarray.mjs";
159
+ import "../_libs/safe-buffer.mjs";
160
+ import "buffer";
161
+ import "../_libs/core-util-is.mjs";
162
+ import "../_libs/inherits.mjs";
163
+ import "../_libs/util-deprecate.mjs";
164
+ import "../_libs/lie.mjs";
165
+ import "../_libs/immediate.mjs";
166
+ import "../_libs/setimmediate.mjs";
167
+ import "../_libs/pako.mjs";
168
+ const ANATOMY_ROLE_LABELS = {
169
+ system: "System",
170
+ user: "User",
171
+ assistant: "Assistant",
172
+ tool: "Tool Results",
173
+ tools: "Tool Definitions"
174
+ };
175
+ const ROLE_COLOR_CLASSES = {
176
+ system: "bg-sky-500/70",
177
+ user: "bg-emerald-500/70",
178
+ assistant: "bg-violet-500/70",
179
+ tool: "bg-sky-400/55",
180
+ tools: "bg-slate-500/70"
181
+ };
182
+ const ROLE_FOCUS_RING = {
183
+ system: "focus-visible:ring-sky-300",
184
+ user: "focus-visible:ring-emerald-300",
185
+ assistant: "focus-visible:ring-violet-300",
186
+ tool: "focus-visible:ring-sky-300",
187
+ tools: "focus-visible:ring-slate-300"
188
+ };
189
+ const MAX_VISIBLE_SEGMENTS = 12;
190
+ const MIN_SEGMENT_PERCENT = 1;
191
+ const TOOLTIP_PREVIEW_LIMIT = 80;
192
+ const LABEL_TRUNCATE_LIMIT = 24;
193
+ function truncateLabel(label) {
194
+ if (label.length <= LABEL_TRUNCATE_LIMIT) return label;
195
+ return `${label.slice(0, LABEL_TRUNCATE_LIMIT - 3)}...`;
196
+ }
197
+ function truncatePreview(text) {
198
+ const singleLine = text.replace(/\s+/g, " ").trim();
199
+ if (singleLine.length <= TOOLTIP_PREVIEW_LIMIT) return singleLine;
200
+ return `${singleLine.slice(0, TOOLTIP_PREVIEW_LIMIT)}...`;
201
+ }
202
+ function formatPercent$1(value) {
203
+ if (value >= 10) return `${value.toFixed(0)}%`;
204
+ if (value >= 1) return `${value.toFixed(1)}%`;
205
+ if (value > 0) return "<1%";
206
+ return "0%";
207
+ }
208
+ const SegmentBar = reactExports.memo(function SegmentBar2({
209
+ segments,
210
+ totalTokens,
211
+ showLabels = true,
212
+ onActivate
213
+ }) {
214
+ const total = reactExports.useMemo(() => {
215
+ if (totalTokens > 0) return totalTokens;
216
+ return segments.reduce((sum, segment) => sum + segment.size, 0);
217
+ }, [segments, totalTokens]);
218
+ const visibleSegments = segments.slice(0, MAX_VISIBLE_SEGMENTS);
219
+ const overflowSegments = segments.slice(MAX_VISIBLE_SEGMENTS);
220
+ const overflowSize = overflowSegments.reduce((sum, segment) => sum + segment.size, 0);
221
+ const overflowCount = overflowSegments.length;
222
+ const overflowStartIndex = MAX_VISIBLE_SEGMENTS;
223
+ const overflowEndIndex = overflowStartIndex + overflowCount - 1;
224
+ const hasOverflow = overflowCount > 0;
225
+ const interactive = onActivate !== void 0;
226
+ const visibleTotal = reactExports.useMemo(
227
+ () => visibleSegments.reduce((sum, segment) => sum + segment.size, 0),
228
+ [visibleSegments]
229
+ );
230
+ const ariaLabel = reactExports.useMemo(
231
+ () => `Request context: ~${formatTokens(total)} tokens across ${segments.length} segment${segments.length === 1 ? "" : "s"}`,
232
+ [segments.length, total]
233
+ );
234
+ if (segments.length === 0 || total <= 0) {
235
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { role: "img", "aria-label": ariaLabel, className: "h-6" });
236
+ }
237
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipProvider, { delayDuration: 150, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { role: "img", "aria-label": ariaLabel, className: "flex flex-col gap-1.5", children: [
238
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(
239
+ "div",
240
+ {
241
+ className: "relative flex h-6 w-full overflow-hidden rounded border border-border/40 bg-muted/30",
242
+ "data-testid": "anatomy-segment-bar",
243
+ children: [
244
+ visibleSegments.map((segment, index) => {
245
+ const rawPercent = total > 0 ? segment.size / total * 100 : 0;
246
+ const percent = Math.max(MIN_SEGMENT_PERCENT, rawPercent);
247
+ const segmentClassName = cn(
248
+ "h-full border-r border-background/80 last:border-r-0",
249
+ interactive ? "opacity-90 hover:opacity-100 focus:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background" : "opacity-90",
250
+ ROLE_COLOR_CLASSES[segment.role],
251
+ interactive ? ROLE_FOCUS_RING[segment.role] : ""
252
+ );
253
+ const segmentStyle = { width: `${percent}%` };
254
+ const ariaText = `${segment.label}, ${formatPercent$1(rawPercent)}, ~${formatTokens(
255
+ segment.size
256
+ )} tokens`;
257
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(Tooltip, { children: [
258
+ /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipTrigger, { asChild: true, children: interactive ? /* @__PURE__ */ jsxRuntimeExports.jsx(
259
+ "button",
260
+ {
261
+ type: "button",
262
+ role: "button",
263
+ tabIndex: 0,
264
+ onClick: () => onActivate(segment),
265
+ onKeyDown: (event) => {
266
+ if (event.key === "Enter" || event.key === " ") {
267
+ event.preventDefault();
268
+ onActivate(segment);
269
+ }
270
+ },
271
+ "data-anatomy-path": segment.path,
272
+ "aria-label": ariaText,
273
+ className: segmentClassName,
274
+ style: segmentStyle
275
+ }
276
+ ) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { "aria-label": ariaText, className: segmentClassName, style: segmentStyle }) }),
277
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(TooltipContent, { side: "bottom", className: "max-w-sm text-xs p-2 space-y-0.5", children: [
278
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-semibold", children: [
279
+ segment.label,
280
+ " - ",
281
+ formatPercent$1(rawPercent),
282
+ " - ~",
283
+ formatTokens(segment.size),
284
+ " ",
285
+ "tokens"
286
+ ] }),
287
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground", children: ANATOMY_ROLE_LABELS[segment.role] }),
288
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-muted-foreground", children: [
289
+ segment.characters.toLocaleString(),
290
+ " chars"
291
+ ] }),
292
+ segment.text.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground/90 break-words whitespace-pre-wrap", children: truncatePreview(segment.text) })
293
+ ] })
294
+ ] }, `${segment.path}-${index}`);
295
+ }),
296
+ hasOverflow && /* @__PURE__ */ jsxRuntimeExports.jsxs(Tooltip, { children: [
297
+ /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
298
+ "div",
299
+ {
300
+ role: "img",
301
+ "aria-label": `${overflowCount} additional segments`,
302
+ className: "flex h-full items-center justify-center bg-muted-foreground/30 px-1.5 text-[10px] font-mono text-background",
303
+ style: {
304
+ width: `${Math.max(MIN_SEGMENT_PERCENT, overflowSize / total * 100)}%`
305
+ },
306
+ children: [
307
+ "... +",
308
+ overflowCount
309
+ ]
310
+ }
311
+ ) }),
312
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(TooltipContent, { side: "bottom", className: "text-xs", children: [
313
+ overflowCount,
314
+ " more segment",
315
+ overflowCount === 1 ? "" : "s",
316
+ " (indices",
317
+ " ",
318
+ overflowStartIndex,
319
+ "-",
320
+ overflowEndIndex,
321
+ ")"
322
+ ] })
323
+ ] })
324
+ ]
325
+ }
326
+ ),
327
+ showLabels && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex w-full gap-1 text-[10px] text-muted-foreground", children: [
328
+ visibleSegments.map((segment, index) => {
329
+ const rawPercent = total > 0 ? segment.size / total * 100 : 0;
330
+ const percent = Math.max(MIN_SEGMENT_PERCENT, rawPercent);
331
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
332
+ "div",
333
+ {
334
+ className: "flex flex-col gap-0.5 truncate",
335
+ style: { width: `${percent}%` },
336
+ title: `${segment.label} - ${formatPercent$1(rawPercent)} - ~${formatTokens(
337
+ segment.size
338
+ )} tokens`,
339
+ children: [
340
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate font-mono text-foreground/80", children: truncateLabel(segment.label) }),
341
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "truncate font-mono text-muted-foreground/70", children: [
342
+ formatPercent$1(rawPercent),
343
+ " - ~",
344
+ formatTokens(segment.size)
345
+ ] })
346
+ ]
347
+ },
348
+ `label-${segment.path}-${index}`
349
+ );
350
+ }),
351
+ hasOverflow && /* @__PURE__ */ jsxRuntimeExports.jsxs(
352
+ "div",
353
+ {
354
+ className: "flex flex-col gap-0.5 truncate text-muted-foreground",
355
+ style: { width: `${Math.max(MIN_SEGMENT_PERCENT, overflowSize / total * 100)}%` },
356
+ children: [
357
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "truncate font-mono text-foreground/60", children: [
358
+ "... +",
359
+ overflowCount
360
+ ] }),
361
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "truncate font-mono text-muted-foreground/60", children: [
362
+ "~",
363
+ formatTokens(overflowSize)
364
+ ] })
365
+ ]
366
+ }
367
+ )
368
+ ] }),
369
+ visibleTotal < total * 0.1 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-0" })
370
+ ] }) });
371
+ });
372
+ const DIVERGENCE_AMBER_THRESHOLD = 0.25;
373
+ const TOP_CONTRIBUTOR_COUNT = 5;
374
+ const ROLE_ORDER = ["system", "user", "assistant", "tool", "tools"];
375
+ const ROLE_DESCRIPTIONS = {
376
+ system: "instructions",
377
+ user: "user turns",
378
+ assistant: "assistant turns",
379
+ tool: "tool results",
380
+ tools: "tool schemas"
381
+ };
382
+ const VIEW_MODE_OPTIONS = [
383
+ { value: "role", label: "By Role" },
384
+ { value: "segment", label: "By Segment" }
385
+ ];
386
+ function formatPercent(value) {
387
+ if (value >= 10) return `${value.toFixed(0)}%`;
388
+ if (value >= 1) return `${value.toFixed(1)}%`;
389
+ if (value > 0) return "<1%";
390
+ return "0%";
391
+ }
392
+ function aggregateByRole(segments) {
393
+ const result = [];
394
+ for (const role of ROLE_ORDER) {
395
+ const matching = segments.filter((segment) => segment.role === role);
396
+ if (matching.length === 0) continue;
397
+ const size = matching.reduce((sum, segment) => sum + segment.size, 0);
398
+ const characters = matching.reduce((sum, segment) => sum + segment.characters, 0);
399
+ const label = ANATOMY_ROLE_LABELS[role];
400
+ const text = `${matching.length} segment${matching.length === 1 ? "" : "s"} grouped as ${ROLE_DESCRIPTIONS[role]}`;
401
+ result.push({
402
+ role,
403
+ label,
404
+ size,
405
+ characters,
406
+ text,
407
+ path: `role:${role}`
408
+ });
409
+ }
410
+ return result;
411
+ }
412
+ function topContributors(segments) {
413
+ return [...segments].sort((a, b) => b.size - a.size).slice(0, TOP_CONTRIBUTOR_COUNT);
414
+ }
415
+ function RequestAnatomy({
416
+ parsed,
417
+ inputTokens,
418
+ onSegmentActivate,
419
+ segments: providedSegments
420
+ }) {
421
+ const [viewMode, setViewMode] = reactExports.useState("role");
422
+ const segments = reactExports.useMemo(() => providedSegments ?? null, [providedSegments]);
423
+ const total = reactExports.useMemo(
424
+ () => (segments ?? []).reduce((sum, segment) => sum + segment.size, 0),
425
+ [segments]
426
+ );
427
+ const roleSegments = reactExports.useMemo(
428
+ () => segments === null ? [] : aggregateByRole(segments),
429
+ [segments]
430
+ );
431
+ const topSegments = reactExports.useMemo(
432
+ () => segments === null ? [] : topContributors(segments),
433
+ [segments]
434
+ );
435
+ const showDivergenceWarning = reactExports.useMemo(() => {
436
+ if (segments === null) return false;
437
+ if (inputTokens === null) return false;
438
+ if (total === 0) return false;
439
+ const ratio = Math.abs(inputTokens - total) / Math.max(inputTokens, total);
440
+ return ratio >= DIVERGENCE_AMBER_THRESHOLD;
441
+ }, [inputTokens, segments, total]);
442
+ if (segments === null) return null;
443
+ if (segments.length === 0) return null;
444
+ if (parsed === null && providedSegments === void 0) return null;
445
+ const summaryColorClass = inputTokens !== null && showDivergenceWarning ? "text-amber-400" : "text-muted-foreground";
446
+ const displayedSegments = viewMode === "role" ? roleSegments : segments;
447
+ const displayedTotal = total > 0 ? total : displayedSegments.reduce((sum, item) => sum + item.size, 0);
448
+ const activateSegment = viewMode === "segment" ? onSegmentActivate : void 0;
449
+ const segmentCountLabel = `${String(segments.length)} segment${segments.length === 1 ? "" : "s"}`;
450
+ const providerInputLabel = inputTokens === null ? "Provider input unknown" : `Provider input ${formatTokens(inputTokens)}`;
451
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipProvider, { delayDuration: 150, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-4 py-3 space-y-3", "data-testid": "anatomy-root", children: [
452
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [
453
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
454
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-semibold text-foreground", children: "Request Context" }),
455
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cn("mt-0.5 text-xs font-mono tabular-nums", summaryColorClass), children: [
456
+ "Estimated ~",
457
+ formatTokens(total),
458
+ " tokens | ",
459
+ providerInputLabel,
460
+ " | ",
461
+ segmentCountLabel
462
+ ] })
463
+ ] }),
464
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
465
+ "div",
466
+ {
467
+ className: "inline-flex shrink-0 rounded border border-border bg-muted/20 p-0.5",
468
+ role: "group",
469
+ "aria-label": "Context breakdown mode",
470
+ children: VIEW_MODE_OPTIONS.map((option) => /* @__PURE__ */ jsxRuntimeExports.jsx(
471
+ "button",
472
+ {
473
+ type: "button",
474
+ "aria-pressed": viewMode === option.value,
475
+ onClick: () => setViewMode(option.value),
476
+ className: cn(
477
+ "h-6 rounded-sm px-2 text-[11px] font-medium transition-colors",
478
+ viewMode === option.value ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
479
+ ),
480
+ children: option.label
481
+ },
482
+ option.value
483
+ ))
484
+ }
485
+ )
486
+ ] }),
487
+ showDivergenceWarning && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "inline-flex items-center gap-1.5 text-xs text-amber-400", children: [
488
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Tooltip, { children: [
489
+ /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
490
+ "button",
491
+ {
492
+ type: "button",
493
+ className: "inline-flex items-center hover:text-amber-300",
494
+ "aria-label": "Token estimate differs from provider input",
495
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(Info, { className: "size-3.5" })
496
+ }
497
+ ) }),
498
+ /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipContent, { className: "max-w-xs text-xs", children: "The bar uses a local token estimate. Provider input tokens remain the source of truth for billing and context-window usage." })
499
+ ] }),
500
+ "Estimate differs from provider-reported input."
501
+ ] }),
502
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
503
+ SegmentBar,
504
+ {
505
+ segments: displayedSegments,
506
+ totalTokens: displayedTotal,
507
+ showLabels: viewMode === "segment",
508
+ onActivate: activateSegment
509
+ }
510
+ ),
511
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[11px] text-muted-foreground", children: roleSegments.map((segment) => {
512
+ const percent = total > 0 ? segment.size / total * 100 : 0;
513
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "inline-flex items-center gap-1.5", children: [
514
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
515
+ "span",
516
+ {
517
+ "aria-hidden": "true",
518
+ className: cn("size-2.5 rounded-[2px]", ROLE_COLOR_CLASSES[segment.role])
519
+ }
520
+ ),
521
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: segment.label }),
522
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono text-muted-foreground/70", children: formatPercent(percent) })
523
+ ] }, segment.role);
524
+ }) }),
525
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
526
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-medium text-foreground", children: "Top Contributors" }),
527
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid gap-1", children: topSegments.map((segment, index) => {
528
+ const percent = total > 0 ? segment.size / total * 100 : 0;
529
+ const activate = onSegmentActivate;
530
+ const content = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
531
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "w-5 shrink-0 text-right font-mono text-muted-foreground/70", children: String(index + 1) }),
532
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
533
+ "span",
534
+ {
535
+ "aria-hidden": "true",
536
+ className: cn(
537
+ "size-2.5 shrink-0 rounded-[2px]",
538
+ ROLE_COLOR_CLASSES[segment.role]
539
+ )
540
+ }
541
+ ),
542
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "min-w-0 flex-1 truncate text-left", children: segment.label }),
543
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "shrink-0 font-mono text-muted-foreground", children: [
544
+ formatPercent(percent),
545
+ " | ~",
546
+ formatTokens(segment.size)
547
+ ] })
548
+ ] });
549
+ if (activate !== void 0) {
550
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
551
+ "button",
552
+ {
553
+ type: "button",
554
+ onClick: () => activate(segment),
555
+ className: "flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",
556
+ title: "Jump to this request block",
557
+ children: content
558
+ },
559
+ `${segment.path}-${index}`
560
+ );
561
+ }
562
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
563
+ "div",
564
+ {
565
+ className: "flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",
566
+ children: content
567
+ },
568
+ `${segment.path}-${index}`
569
+ );
570
+ }) })
571
+ ] })
572
+ ] }) });
573
+ }
574
+ export {
575
+ RequestAnatomy
576
+ };