@tonyclaw/agent-inspector 2.0.7 → 2.0.8

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 (32) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/assets/{CompareDrawer-BhRYPp6T.js → CompareDrawer-Djb4XFZS.js} +1 -1
  3. package/.output/public/assets/{ProxyViewerContainer-BHq0dkQG.js → ProxyViewerContainer-CWdkPZsJ.js} +5 -5
  4. package/.output/public/assets/{ReplayDialog-Ch0gwg6B.js → ReplayDialog-DBPMIs2I.js} +1 -1
  5. package/.output/public/assets/RequestAnatomy-FBfRNQN7.js +1 -0
  6. package/.output/public/assets/{ResponseView-hRLar32x.js → ResponseView-Db4pJL7U.js} +1 -1
  7. package/.output/public/assets/{StreamingChunkSequence-DCJ_gUHa.js → StreamingChunkSequence-BH175O6R.js} +1 -1
  8. package/.output/public/assets/_sessionId-3ipVoQtW.js +1 -0
  9. package/.output/public/assets/index-Bo1dGS4R.css +1 -0
  10. package/.output/public/assets/index-CJgaCJo8.js +1 -0
  11. package/.output/public/assets/{main-BlDtK0Nn.js → main-CwhqfJqM.js} +8 -8
  12. package/.output/server/{_sessionId-Dy7rsLS4.mjs → _sessionId-DzBy9gLa.mjs} +2 -2
  13. package/.output/server/_ssr/{CompareDrawer-CkVX-ARV.mjs → CompareDrawer-C5NBvE2e.mjs} +2 -2
  14. package/.output/server/_ssr/{ProxyViewerContainer-B5a9p3j5.mjs → ProxyViewerContainer-DiZjOTQT.mjs} +9 -8
  15. package/.output/server/_ssr/{ReplayDialog-hXY6H9fB.mjs → ReplayDialog-EpvTwFvp.mjs} +3 -3
  16. package/.output/server/_ssr/{RequestAnatomy-B6MS7VvA.mjs → RequestAnatomy-DaQjhixp.mjs} +455 -3
  17. package/.output/server/_ssr/{ResponseView-ByjxwUnp.mjs → ResponseView-D8tGHCGY.mjs} +2 -2
  18. package/.output/server/_ssr/{StreamingChunkSequence-C5Kb8siT.mjs → StreamingChunkSequence-DGQnb1QE.mjs} +2 -2
  19. package/.output/server/_ssr/{index-BZXtj42m.mjs → index-N25hqa7t.mjs} +2 -2
  20. package/.output/server/_ssr/index.mjs +2 -2
  21. package/.output/server/_ssr/{router-CVQaVF_3.mjs → router-Bf0m6F0G.mjs} +20 -4
  22. package/.output/server/{_tanstack-start-manifest_v-Bpe5ZC56.mjs → _tanstack-start-manifest_v-DlAyJ5DB.mjs} +1 -1
  23. package/.output/server/index.mjs +59 -59
  24. package/package.json +1 -1
  25. package/src/components/proxy-viewer/LogEntry.tsx +2 -1
  26. package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +197 -1
  27. package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +414 -0
  28. package/src/routes/__root.tsx +27 -0
  29. package/.output/public/assets/RequestAnatomy-CKbvIgaN.js +0 -1
  30. package/.output/public/assets/_sessionId-BJTz6t5l.js +0 -1
  31. package/.output/public/assets/index-Cf9U0Ekq.js +0 -1
  32. package/.output/public/assets/index-DTdv7nzl.css +0 -1
@@ -0,0 +1,414 @@
1
+ import { safeGetOwnProperty } from "../../../lib/objectUtils";
2
+ import type { AnatomyRole, AnatomySegment } from "./types";
3
+
4
+ export type ContextRiskLevel = "unknown" | "ok" | "watch" | "danger";
5
+
6
+ export type ContextWindowSource = "request" | "model-rule" | "unknown";
7
+
8
+ export type ContextWindow = {
9
+ tokens: number | null;
10
+ label: string;
11
+ source: ContextWindowSource;
12
+ };
13
+
14
+ export type RoleUsage = {
15
+ role: AnatomyRole;
16
+ label: string;
17
+ tokens: number;
18
+ percent: number;
19
+ };
20
+
21
+ export type ContextDiagnostic = {
22
+ kind: "duplicate" | "history-bloat" | "tool-schema" | "system-heavy";
23
+ severity: "watch" | "danger";
24
+ title: string;
25
+ detail: string;
26
+ };
27
+
28
+ export type ContextIntelligence = {
29
+ model: string | null;
30
+ contextWindow: ContextWindow;
31
+ estimatedInputTokens: number;
32
+ outputReserveTokens: number | null;
33
+ windowUsedTokens: number | null;
34
+ remainingInputTokens: number | null;
35
+ remainingAfterReserveTokens: number | null;
36
+ usagePercent: number | null;
37
+ riskLevel: ContextRiskLevel;
38
+ roleUsages: RoleUsage[];
39
+ largestRole: RoleUsage | null;
40
+ diagnostics: ContextDiagnostic[];
41
+ };
42
+
43
+ type MatchMode = "prefix" | "includes";
44
+
45
+ type ModelContextRule = {
46
+ family: string;
47
+ tokens: number;
48
+ mode: MatchMode;
49
+ patterns: readonly string[];
50
+ };
51
+
52
+ const WATCH_USAGE_PERCENT = 0.75;
53
+ const DANGER_USAGE_PERCENT = 0.9;
54
+ const LONG_TOOL_SCHEMA_TOKENS = 8_000;
55
+ const LARGE_ROLE_PERCENT = 0.35;
56
+ const DUPLICATE_MIN_TOKENS = 40;
57
+ const DUPLICATE_MIN_CHARS = 160;
58
+ const HISTORY_BLOAT_SEGMENTS = 18;
59
+ const HISTORY_BLOAT_TOKENS = 60_000;
60
+ const HISTORY_BLOAT_PERCENT = 0.7;
61
+ const SYSTEM_HEAVY_TOKENS = 3_000;
62
+ const SYSTEM_HEAVY_PERCENT = 0.3;
63
+
64
+ const EXPLICIT_CONTEXT_WINDOW_FIELDS = [
65
+ "context_window",
66
+ "contextWindow",
67
+ "context_length",
68
+ "contextLength",
69
+ "max_context_length",
70
+ "maxContextLength",
71
+ "max_input_tokens",
72
+ "maxInputTokens",
73
+ ] as const;
74
+
75
+ const OUTPUT_RESERVE_FIELDS = [
76
+ "max_tokens",
77
+ "maxTokens",
78
+ "max_completion_tokens",
79
+ "maxCompletionTokens",
80
+ "max_output_tokens",
81
+ "maxOutputTokens",
82
+ ] as const;
83
+
84
+ const MODEL_CONTEXT_RULES: readonly ModelContextRule[] = [
85
+ {
86
+ family: "OpenAI GPT-4.1",
87
+ tokens: 1_047_576,
88
+ mode: "prefix",
89
+ patterns: ["gpt-4.1"],
90
+ },
91
+ {
92
+ family: "OpenAI GPT-4o",
93
+ tokens: 128_000,
94
+ mode: "prefix",
95
+ patterns: ["gpt-4o"],
96
+ },
97
+ {
98
+ family: "OpenAI o-series",
99
+ tokens: 128_000,
100
+ mode: "prefix",
101
+ patterns: ["o1", "o3", "o4"],
102
+ },
103
+ {
104
+ family: "Anthropic Claude",
105
+ tokens: 200_000,
106
+ mode: "prefix",
107
+ patterns: ["claude-"],
108
+ },
109
+ {
110
+ family: "DeepSeek",
111
+ tokens: 64_000,
112
+ mode: "prefix",
113
+ patterns: ["deepseek-"],
114
+ },
115
+ {
116
+ family: "MiniMax",
117
+ tokens: 1_000_000,
118
+ mode: "includes",
119
+ patterns: ["minimax"],
120
+ },
121
+ ];
122
+
123
+ const ROLE_LABELS: Record<AnatomyRole, string> = {
124
+ system: "System",
125
+ user: "User messages",
126
+ assistant: "Assistant messages",
127
+ tool: "Tool results",
128
+ tools: "Tool definitions",
129
+ };
130
+
131
+ function readPositiveInteger(value: unknown): number | null {
132
+ if (typeof value === "number") {
133
+ if (Number.isFinite(value) && value > 0) return Math.floor(value);
134
+ return null;
135
+ }
136
+
137
+ if (typeof value === "string") {
138
+ const parsed = Number(value);
139
+ if (Number.isFinite(parsed) && parsed > 0) return Math.floor(parsed);
140
+ }
141
+
142
+ return null;
143
+ }
144
+
145
+ function readPositiveIntegerField(parsed: unknown, fields: readonly string[]): number | null {
146
+ for (const field of fields) {
147
+ const value = readPositiveInteger(safeGetOwnProperty(parsed, field));
148
+ if (value !== null) return value;
149
+ }
150
+ return null;
151
+ }
152
+
153
+ export function readRequestModel(parsed: unknown): string | null {
154
+ const value = safeGetOwnProperty(parsed, "model");
155
+ if (typeof value !== "string") return null;
156
+ const trimmed = value.trim();
157
+ return trimmed === "" ? null : trimmed;
158
+ }
159
+
160
+ function matchesRule(model: string, rule: ModelContextRule): boolean {
161
+ switch (rule.mode) {
162
+ case "prefix":
163
+ return rule.patterns.some((pattern) => model.startsWith(pattern));
164
+ case "includes":
165
+ return rule.patterns.some((pattern) => model.includes(pattern));
166
+ }
167
+ }
168
+
169
+ export function resolveContextWindow(model: string | null, parsed: unknown): ContextWindow {
170
+ const explicitWindow = readPositiveIntegerField(parsed, EXPLICIT_CONTEXT_WINDOW_FIELDS);
171
+ if (explicitWindow !== null) {
172
+ return {
173
+ tokens: explicitWindow,
174
+ label: "Request metadata",
175
+ source: "request",
176
+ };
177
+ }
178
+
179
+ if (model === null) {
180
+ return {
181
+ tokens: null,
182
+ label: "Unknown model",
183
+ source: "unknown",
184
+ };
185
+ }
186
+
187
+ const normalized = model.trim().toLowerCase();
188
+ for (const rule of MODEL_CONTEXT_RULES) {
189
+ if (matchesRule(normalized, rule)) {
190
+ return {
191
+ tokens: rule.tokens,
192
+ label: rule.family,
193
+ source: "model-rule",
194
+ };
195
+ }
196
+ }
197
+
198
+ return {
199
+ tokens: null,
200
+ label: "No local rule",
201
+ source: "unknown",
202
+ };
203
+ }
204
+
205
+ function clampPercent(value: number): number {
206
+ if (value < 0) return 0;
207
+ if (value > 1) return 1;
208
+ return value;
209
+ }
210
+
211
+ function riskLevel(usagePercent: number | null): ContextRiskLevel {
212
+ if (usagePercent === null) return "unknown";
213
+ if (usagePercent >= DANGER_USAGE_PERCENT) return "danger";
214
+ if (usagePercent >= WATCH_USAGE_PERCENT) return "watch";
215
+ return "ok";
216
+ }
217
+
218
+ function sumSegments(segments: readonly AnatomySegment[], role: AnatomyRole): number {
219
+ return segments
220
+ .filter((segment) => segment.role === role)
221
+ .reduce((sum, segment) => sum + segment.size, 0);
222
+ }
223
+
224
+ function buildRoleUsages(segments: readonly AnatomySegment[], total: number): RoleUsage[] {
225
+ const roles: AnatomyRole[] = ["system", "user", "assistant", "tool", "tools"];
226
+ return roles
227
+ .map((role) => {
228
+ const tokens = sumSegments(segments, role);
229
+ return {
230
+ role,
231
+ label: ROLE_LABELS[role],
232
+ tokens,
233
+ percent: total > 0 ? tokens / total : 0,
234
+ };
235
+ })
236
+ .filter((usage) => usage.tokens > 0)
237
+ .sort((a, b) => b.tokens - a.tokens);
238
+ }
239
+
240
+ function normalizeDuplicateText(text: string): string {
241
+ return text.replace(/\s+/g, " ").trim().toLowerCase();
242
+ }
243
+
244
+ function duplicateDiagnostic(segments: readonly AnatomySegment[]): ContextDiagnostic | null {
245
+ type DuplicateBucket = {
246
+ count: number;
247
+ tokens: number;
248
+ firstTokens: number;
249
+ label: string;
250
+ };
251
+
252
+ const buckets = new Map<string, DuplicateBucket>();
253
+ for (const segment of segments) {
254
+ if (segment.size < DUPLICATE_MIN_TOKENS) continue;
255
+ if (segment.characters < DUPLICATE_MIN_CHARS) continue;
256
+ const normalized = normalizeDuplicateText(segment.text);
257
+ if (normalized === "") continue;
258
+ const existing = buckets.get(normalized);
259
+ if (existing === undefined) {
260
+ buckets.set(normalized, {
261
+ count: 1,
262
+ tokens: segment.size,
263
+ firstTokens: segment.size,
264
+ label: segment.label,
265
+ });
266
+ continue;
267
+ }
268
+ buckets.set(normalized, {
269
+ count: existing.count + 1,
270
+ tokens: existing.tokens + segment.size,
271
+ firstTokens: existing.firstTokens,
272
+ label: existing.label,
273
+ });
274
+ }
275
+
276
+ let repeatedGroups = 0;
277
+ let repeatedSegments = 0;
278
+ let repeatedTokens = 0;
279
+ let largest: DuplicateBucket | null = null;
280
+ for (const bucket of buckets.values()) {
281
+ if (bucket.count < 2) continue;
282
+ repeatedGroups += 1;
283
+ repeatedSegments += bucket.count;
284
+ repeatedTokens += bucket.tokens - bucket.firstTokens;
285
+ if (largest === null || bucket.tokens > largest.tokens) largest = bucket;
286
+ }
287
+
288
+ if (repeatedGroups === 0 || largest === null) return null;
289
+
290
+ return {
291
+ kind: "duplicate",
292
+ severity: repeatedTokens >= LONG_TOOL_SCHEMA_TOKENS ? "danger" : "watch",
293
+ title: "Duplicate context",
294
+ detail: `${String(repeatedSegments)} repeated blocks across ${String(
295
+ repeatedGroups,
296
+ )} group${repeatedGroups === 1 ? "" : "s"}, ~${String(repeatedTokens)} repeated tokens.`,
297
+ };
298
+ }
299
+
300
+ function diagnosticsForRolePressure(
301
+ roleUsages: readonly RoleUsage[],
302
+ total: number,
303
+ messageSegmentCount: number,
304
+ ): ContextDiagnostic[] {
305
+ const diagnostics: ContextDiagnostic[] = [];
306
+ const toolUsage = roleUsages.find((usage) => usage.role === "tools") ?? null;
307
+ if (
308
+ toolUsage !== null &&
309
+ (toolUsage.tokens >= LONG_TOOL_SCHEMA_TOKENS ||
310
+ (toolUsage.percent >= LARGE_ROLE_PERCENT && toolUsage.tokens >= SYSTEM_HEAVY_TOKENS))
311
+ ) {
312
+ diagnostics.push({
313
+ kind: "tool-schema",
314
+ severity: toolUsage.tokens >= LONG_TOOL_SCHEMA_TOKENS ? "danger" : "watch",
315
+ title: "Large tool schema",
316
+ detail: `Tool definitions take ${Math.round(toolUsage.percent * 100)}% of request context.`,
317
+ });
318
+ }
319
+
320
+ const systemUsage = roleUsages.find((usage) => usage.role === "system") ?? null;
321
+ if (
322
+ systemUsage !== null &&
323
+ systemUsage.tokens >= SYSTEM_HEAVY_TOKENS &&
324
+ systemUsage.percent >= SYSTEM_HEAVY_PERCENT
325
+ ) {
326
+ diagnostics.push({
327
+ kind: "system-heavy",
328
+ severity: "watch",
329
+ title: "Large system prompt",
330
+ detail: `System instructions take ${Math.round(systemUsage.percent * 100)}% of request context.`,
331
+ });
332
+ }
333
+
334
+ const historyTokens = roleUsages
335
+ .filter((usage) => usage.role === "user" || usage.role === "assistant" || usage.role === "tool")
336
+ .reduce((sum, usage) => sum + usage.tokens, 0);
337
+ const historyPercent = total > 0 ? historyTokens / total : 0;
338
+ if (
339
+ messageSegmentCount >= HISTORY_BLOAT_SEGMENTS &&
340
+ (historyTokens >= HISTORY_BLOAT_TOKENS || historyPercent >= HISTORY_BLOAT_PERCENT)
341
+ ) {
342
+ diagnostics.push({
343
+ kind: "history-bloat",
344
+ severity: historyPercent >= 0.85 ? "danger" : "watch",
345
+ title: "Conversation history growth",
346
+ detail: `${String(messageSegmentCount)} message blocks take ${Math.round(
347
+ historyPercent * 100,
348
+ )}% of request context.`,
349
+ });
350
+ }
351
+
352
+ return diagnostics;
353
+ }
354
+
355
+ export function analyzeContextIntelligence({
356
+ segments,
357
+ inputTokens,
358
+ parsed,
359
+ model,
360
+ }: {
361
+ segments: readonly AnatomySegment[];
362
+ inputTokens: number | null;
363
+ parsed: unknown;
364
+ model: string | null;
365
+ }): ContextIntelligence {
366
+ const totalEstimatedTokens = segments.reduce((sum, segment) => sum + segment.size, 0);
367
+ const requestModel = model ?? readRequestModel(parsed);
368
+ const estimatedInputTokens = inputTokens ?? totalEstimatedTokens;
369
+ const outputReserveTokens = readPositiveIntegerField(parsed, OUTPUT_RESERVE_FIELDS);
370
+ const contextWindow = resolveContextWindow(requestModel, parsed);
371
+ const reservedTokens = outputReserveTokens ?? 0;
372
+ const windowUsedTokens =
373
+ contextWindow.tokens === null ? null : estimatedInputTokens + reservedTokens;
374
+ const remainingInputTokens =
375
+ contextWindow.tokens === null ? null : contextWindow.tokens - estimatedInputTokens;
376
+ const remainingAfterReserveTokens =
377
+ contextWindow.tokens === null
378
+ ? null
379
+ : contextWindow.tokens - estimatedInputTokens - reservedTokens;
380
+ const usagePercent =
381
+ contextWindow.tokens === null || windowUsedTokens === null
382
+ ? null
383
+ : clampPercent(windowUsedTokens / contextWindow.tokens);
384
+ const roleUsages = buildRoleUsages(segments, totalEstimatedTokens);
385
+ const largestRole = roleUsages[0] ?? null;
386
+ const messageSegmentCount = segments.filter((segment) => segment.role !== "tools").length;
387
+ const duplicate = duplicateDiagnostic(segments);
388
+ const diagnostics = diagnosticsForRolePressure(
389
+ roleUsages,
390
+ totalEstimatedTokens,
391
+ messageSegmentCount,
392
+ );
393
+ if (duplicate !== null) diagnostics.unshift(duplicate);
394
+
395
+ return {
396
+ model: requestModel,
397
+ contextWindow,
398
+ estimatedInputTokens,
399
+ outputReserveTokens,
400
+ windowUsedTokens,
401
+ remainingInputTokens,
402
+ remainingAfterReserveTokens,
403
+ usagePercent,
404
+ riskLevel: riskLevel(usagePercent),
405
+ roleUsages,
406
+ largestRole,
407
+ diagnostics,
408
+ };
409
+ }
410
+
411
+ export const CONTEXT_USAGE_THRESHOLDS = {
412
+ watch: WATCH_USAGE_PERCENT,
413
+ danger: DANGER_USAGE_PERCENT,
414
+ } as const;
@@ -18,6 +18,7 @@ export const Route = createRootRoute({
18
18
  ],
19
19
  }),
20
20
  component: RootComponent,
21
+ notFoundComponent: RootNotFoundComponent,
21
22
  });
22
23
 
23
24
  function RootComponent() {
@@ -28,6 +29,32 @@ function RootComponent() {
28
29
  );
29
30
  }
30
31
 
32
+ function RootNotFoundComponent() {
33
+ return (
34
+ <RootDocument>
35
+ <main className="min-h-screen bg-background text-foreground">
36
+ <div className="mx-auto flex min-h-screen w-full max-w-3xl flex-col justify-center px-6 py-16">
37
+ <div className="border-border/70 bg-card/60 rounded-lg border p-8 shadow-sm">
38
+ <div className="text-muted-foreground font-mono text-xs uppercase tracking-wider">
39
+ 404
40
+ </div>
41
+ <h1 className="mt-3 text-2xl font-semibold">Page not found</h1>
42
+ <p className="text-muted-foreground mt-3 max-w-xl text-sm leading-6">
43
+ This route is not part of the Agent Inspector UI or API surface.
44
+ </p>
45
+ <a
46
+ href="/"
47
+ className="bg-primary text-primary-foreground hover:bg-primary/90 mt-6 inline-flex h-9 items-center justify-center rounded-md px-4 text-sm font-medium transition-colors"
48
+ >
49
+ Open Agent Inspector
50
+ </a>
51
+ </div>
52
+ </div>
53
+ </main>
54
+ </RootDocument>
55
+ );
56
+ }
57
+
31
58
  function RootDocument({ children }: Readonly<{ children: ReactNode }>) {
32
59
  return (
33
60
  <html lang="en" className="dark">
@@ -1 +0,0 @@
1
- import{r as f,j as e}from"./main-BlDtK0Nn.js";import{c as A,f as h,s as D,b as y,t as R,v as L,w as T}from"./ProxyViewerContainer-BHq0dkQG.js";const F=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],U=A("info",F),B={system:"System",user:"User",assistant:"Assistant",tool:"Tool Results",tools:"Tool Definitions"},_={system:"bg-sky-500/70",user:"bg-emerald-500/70",assistant:"bg-violet-500/70",tool:"bg-sky-400/55",tools:"bg-slate-500/70"},V={system:"focus-visible:ring-sky-300",user:"focus-visible:ring-emerald-300",assistant:"focus-visible:ring-violet-300",tool:"focus-visible:ring-sky-300",tools:"focus-visible:ring-slate-300"},C=12,$=1,I=80,O=24;function q(o){return o.length<=O?o:`${o.slice(0,O-3)}...`}function G(o){const r=o.replace(/\s+/g," ").trim();return r.length<=I?r:`${r.slice(0,I)}...`}function E(o){return o>=10?`${o.toFixed(0)}%`:o>=1?`${o.toFixed(1)}%`:o>0?"<1%":"0%"}const W=f.memo(function({segments:r,totalTokens:i,showLabels:x=!0,onActivate:m}){const c=f.useMemo(()=>i>0?i:r.reduce((s,t)=>s+t.size,0),[r,i]),n=r.slice(0,C),l=r.slice(C),u=l.reduce((s,t)=>s+t.size,0),d=l.length,p=C,M=p+d-1,b=d>0,g=m!==void 0,S=f.useMemo(()=>n.reduce((s,t)=>s+t.size,0),[n]),w=f.useMemo(()=>`Request context: ~${h(c)} tokens across ${r.length} segment${r.length===1?"":"s"}`,[r.length,c]);return r.length===0||c<=0?e.jsx("div",{role:"img","aria-label":w,className:"h-6"}):e.jsx(D,{delayDuration:150,children:e.jsxs("div",{role:"img","aria-label":w,className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"relative flex h-6 w-full overflow-hidden rounded border border-border/40 bg-muted/30","data-testid":"anatomy-segment-bar",children:[n.map((s,t)=>{const a=c>0?s.size/c*100:0,v=Math.max($,a),j=y("h-full border-r border-background/80 last:border-r-0",g?"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",_[s.role],g?V[s.role]:""),N={width:`${v}%`},z=`${s.label}, ${E(a)}, ~${h(s.size)} tokens`;return e.jsxs(R,{children:[e.jsx(L,{asChild:!0,children:g?e.jsx("button",{type:"button",role:"button",tabIndex:0,onClick:()=>m(s),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),m(s))},"data-anatomy-path":s.path,"aria-label":z,className:j,style:N}):e.jsx("span",{"aria-label":z,className:j,style:N})}),e.jsxs(T,{side:"bottom",className:"max-w-sm text-xs p-2 space-y-0.5",children:[e.jsxs("div",{className:"font-semibold",children:[s.label," - ",E(a)," - ~",h(s.size)," ","tokens"]}),e.jsx("div",{className:"text-muted-foreground",children:B[s.role]}),e.jsxs("div",{className:"text-muted-foreground",children:[s.characters.toLocaleString()," chars"]}),s.text.length>0&&e.jsx("div",{className:"text-muted-foreground/90 break-words whitespace-pre-wrap",children:G(s.text)})]})]},`${s.path}-${t}`)}),b&&e.jsxs(R,{children:[e.jsx(L,{asChild:!0,children:e.jsxs("div",{role:"img","aria-label":`${d} additional segments`,className:"flex h-full items-center justify-center bg-muted-foreground/30 px-1.5 text-[10px] font-mono text-background",style:{width:`${Math.max($,u/c*100)}%`},children:["... +",d]})}),e.jsxs(T,{side:"bottom",className:"text-xs",children:[d," more segment",d===1?"":"s"," (indices"," ",p,"-",M,")"]})]})]}),x&&e.jsxs("div",{className:"flex w-full gap-1 text-[10px] text-muted-foreground",children:[n.map((s,t)=>{const a=c>0?s.size/c*100:0,v=Math.max($,a);return e.jsxs("div",{className:"flex flex-col gap-0.5 truncate",style:{width:`${v}%`},title:`${s.label} - ${E(a)} - ~${h(s.size)} tokens`,children:[e.jsx("span",{className:"truncate font-mono text-foreground/80",children:q(s.label)}),e.jsxs("span",{className:"truncate font-mono text-muted-foreground/70",children:[E(a)," - ~",h(s.size)]})]},`label-${s.path}-${t}`)}),b&&e.jsxs("div",{className:"flex flex-col gap-0.5 truncate text-muted-foreground",style:{width:`${Math.max($,u/c*100)}%`},children:[e.jsxs("span",{className:"truncate font-mono text-foreground/60",children:["... +",d]}),e.jsxs("span",{className:"truncate font-mono text-muted-foreground/60",children:["~",h(u)]})]})]}),S<c*.1&&e.jsx("div",{className:"h-0"})]})})}),H=.25,J=5,K=["system","user","assistant","tool","tools"],X={system:"instructions",user:"user turns",assistant:"assistant turns",tool:"tool results",tools:"tool schemas"},Y=[{value:"role",label:"By Role"},{value:"segment",label:"By Segment"}];function P(o){return o>=10?`${o.toFixed(0)}%`:o>=1?`${o.toFixed(1)}%`:o>0?"<1%":"0%"}function Q(o){const r=[];for(const i of K){const x=o.filter(u=>u.role===i);if(x.length===0)continue;const m=x.reduce((u,d)=>u+d.size,0),c=x.reduce((u,d)=>u+d.characters,0),n=B[i],l=`${x.length} segment${x.length===1?"":"s"} grouped as ${X[i]}`;r.push({role:i,label:n,size:m,characters:c,text:l,path:`role:${i}`})}return r}function Z(o){return[...o].sort((r,i)=>i.size-r.size).slice(0,J)}function se({parsed:o,inputTokens:r,onSegmentActivate:i,segments:x}){const[m,c]=f.useState("role"),n=f.useMemo(()=>x??null,[x]),l=f.useMemo(()=>(n??[]).reduce((t,a)=>t+a.size,0),[n]),u=f.useMemo(()=>n===null?[]:Q(n),[n]),d=f.useMemo(()=>n===null?[]:Z(n),[n]),p=f.useMemo(()=>n===null||r===null||l===0?!1:Math.abs(r-l)/Math.max(r,l)>=H,[r,n,l]);if(n===null||n.length===0||o===null&&x===void 0)return null;const M=r!==null&&p?"text-amber-400":"text-muted-foreground",b=m==="role"?u:n,g=l>0?l:b.reduce((t,a)=>t+a.size,0),S=m==="segment"?i:void 0,w=`${String(n.length)} segment${n.length===1?"":"s"}`,s=r===null?"Provider input unknown":`Provider input ${h(r)}`;return e.jsx(D,{delayDuration:150,children:e.jsxs("div",{className:"px-4 py-3 space-y-3","data-testid":"anatomy-root",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Request Context"}),e.jsxs("div",{className:y("mt-0.5 text-xs font-mono tabular-nums",M),children:["Estimated ~",h(l)," tokens | ",s," | ",w]})]}),e.jsx("div",{className:"inline-flex shrink-0 rounded border border-border bg-muted/20 p-0.5",role:"group","aria-label":"Context breakdown mode",children:Y.map(t=>e.jsx("button",{type:"button","aria-pressed":m===t.value,onClick:()=>c(t.value),className:y("h-6 rounded-sm px-2 text-[11px] font-medium transition-colors",m===t.value?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:t.label},t.value))})]}),p&&e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-xs text-amber-400",children:[e.jsxs(R,{children:[e.jsx(L,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex items-center hover:text-amber-300","aria-label":"Token estimate differs from provider input",children:e.jsx(U,{className:"size-3.5"})})}),e.jsx(T,{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."})]}),"Estimate differs from provider-reported input."]}),e.jsx(W,{segments:b,totalTokens:g,showLabels:m==="segment",onActivate:S}),e.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[11px] text-muted-foreground",children:u.map(t=>{const a=l>0?t.size/l*100:0;return e.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:y("size-2.5 rounded-[2px]",_[t.role])}),e.jsx("span",{children:t.label}),e.jsx("span",{className:"font-mono text-muted-foreground/70",children:P(a)})]},t.role)})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Top Contributors"}),e.jsx("div",{className:"grid gap-1",children:d.map((t,a)=>{const v=l>0?t.size/l*100:0,j=i,N=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-muted-foreground/70",children:String(a+1)}),e.jsx("span",{"aria-hidden":"true",className:y("size-2.5 shrink-0 rounded-[2px]",_[t.role])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:t.label}),e.jsxs("span",{className:"shrink-0 font-mono text-muted-foreground",children:[P(v)," | ~",h(t.size)]})]});return j!==void 0?e.jsx("button",{type:"button",onClick:()=>j(t),className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",title:"Jump to this request block",children:N},`${t.path}-${a}`):e.jsx("div",{className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",children:N},`${t.path}-${a}`)})})]})]})})}export{se as RequestAnatomy};
@@ -1 +0,0 @@
1
- import{R as s,j as e}from"./main-BlDtK0Nn.js";import{P as i}from"./ProxyViewerContainer-BHq0dkQG.js";function t(){const{sessionId:o}=s.useParams();return e.jsx(i,{initialSessionId:o},o)}export{t as component};
@@ -1 +0,0 @@
1
- import{P as o}from"./ProxyViewerContainer-BHq0dkQG.js";import"./main-BlDtK0Nn.js";const r=o;export{r as component};