@tonyclaw/agent-inspector 2.0.6 → 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 (43) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/assets/CompareDrawer-Djb4XFZS.js +1 -0
  3. package/.output/public/assets/ProxyViewerContainer-CWdkPZsJ.js +114 -0
  4. package/.output/public/assets/ReplayDialog-DBPMIs2I.js +1 -0
  5. package/.output/public/assets/RequestAnatomy-FBfRNQN7.js +1 -0
  6. package/.output/public/assets/ResponseView-Db4pJL7U.js +1 -0
  7. package/.output/public/assets/StreamingChunkSequence-BH175O6R.js +1 -0
  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-CKnTJ4-O.js → main-CwhqfJqM.js} +8 -8
  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-B-x9fRY3.mjs → _sessionId-DzBy9gLa.mjs} +58 -5
  15. package/.output/server/_ssr/{CompareDrawer-BQVNsAY2.mjs → CompareDrawer-C5NBvE2e.mjs} +9 -8
  16. package/.output/server/_ssr/{ProxyViewerContainer-CYm2Dw19.mjs → ProxyViewerContainer-DiZjOTQT.mjs} +857 -32
  17. package/.output/server/_ssr/{ReplayDialog-CaMQBc79.mjs → ReplayDialog-EpvTwFvp.mjs} +7 -8
  18. package/.output/server/_ssr/{RequestAnatomy--P5arRH2.mjs → RequestAnatomy-DaQjhixp.mjs} +512 -7
  19. package/.output/server/_ssr/{ResponseView-RtFwNvgD.mjs → ResponseView-D8tGHCGY.mjs} +5 -74
  20. package/.output/server/_ssr/{StreamingChunkSequence-B5HPkzab.mjs → StreamingChunkSequence-DGQnb1QE.mjs} +8 -7
  21. package/.output/server/_ssr/{index-CZIKZU43.mjs → index-N25hqa7t.mjs} +58 -5
  22. package/.output/server/_ssr/index.mjs +2 -2
  23. package/.output/server/_ssr/{router-DGPt3MUc.mjs → router-Bf0m6F0G.mjs} +22 -6
  24. package/.output/server/{_tanstack-start-manifest_v-BzH4pNaI.mjs → _tanstack-start-manifest_v-DlAyJ5DB.mjs} +1 -1
  25. package/.output/server/index.mjs +61 -68
  26. package/package.json +1 -1
  27. package/src/components/proxy-viewer/LogEntry.tsx +17 -2
  28. package/src/components/proxy-viewer/RequestToolsPanel.tsx +292 -0
  29. package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +197 -1
  30. package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +414 -0
  31. package/src/components/proxy-viewer/requestTools.ts +213 -0
  32. package/src/routes/__root.tsx +27 -0
  33. package/.output/public/assets/CompareDrawer-DDmqSAfl.js +0 -1
  34. package/.output/public/assets/ProxyViewerContainer-Cxpdziwd.js +0 -101
  35. package/.output/public/assets/ReplayDialog-Bt5DGzlh.js +0 -1
  36. package/.output/public/assets/RequestAnatomy-BxX3_N9S.js +0 -1
  37. package/.output/public/assets/ResponseView-Bl_5S9gZ.js +0 -1
  38. package/.output/public/assets/StreamingChunkSequence-RJMwNf6F.js +0 -1
  39. package/.output/public/assets/_sessionId-b4isaoDp.js +0 -1
  40. package/.output/public/assets/index-BZ4x5UI6.js +0 -1
  41. package/.output/public/assets/index-C624DUk9.css +0 -1
  42. package/.output/public/assets/json-viewer-CRL_gWEZ.js +0 -14
  43. package/.output/server/_ssr/json-viewer-d4obyRaA.mjs +0 -515
@@ -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;
@@ -0,0 +1,213 @@
1
+ import { safeGetOwnProperty } from "../../lib/objectUtils";
2
+
3
+ export type RequestToolCategory = "file" | "shell" | "browser" | "web" | "mcp" | "code" | "other";
4
+
5
+ export type RequestToolDefinition = {
6
+ name: string;
7
+ description: string | null;
8
+ descriptionPreview: string | null;
9
+ category: RequestToolCategory;
10
+ parameterCount: number;
11
+ requiredParameters: string[];
12
+ schema: unknown | null;
13
+ };
14
+
15
+ export type RequestToolCategorySummary = {
16
+ category: RequestToolCategory;
17
+ count: number;
18
+ };
19
+
20
+ export type RequestToolsSummary = {
21
+ tools: RequestToolDefinition[];
22
+ toolChoiceLabel: string | null;
23
+ categories: RequestToolCategorySummary[];
24
+ };
25
+
26
+ const CATEGORY_ORDER: RequestToolCategory[] = [
27
+ "file",
28
+ "shell",
29
+ "browser",
30
+ "web",
31
+ "mcp",
32
+ "code",
33
+ "other",
34
+ ];
35
+
36
+ function firstTextSlice(value: string): string {
37
+ const normalized = value.replace(/\s+/g, " ").trim();
38
+ if (normalized.length <= 120) return normalized;
39
+ return `${normalized.slice(0, 119)}...`;
40
+ }
41
+
42
+ function previewDescription(description: string | null): string | null {
43
+ if (description === null) return null;
44
+ const normalized = description.replace(/\s+/g, " ").trim();
45
+ if (normalized.length === 0) return null;
46
+ const sentenceEnd = normalized.search(/[.!?。!?]/);
47
+ if (sentenceEnd >= 24) return firstTextSlice(normalized.slice(0, sentenceEnd + 1));
48
+ return firstTextSlice(normalized);
49
+ }
50
+
51
+ function lowerHaystack(name: string, description: string | null): string {
52
+ return `${name} ${description ?? ""}`.toLowerCase();
53
+ }
54
+
55
+ function includesAny(value: string, needles: readonly string[]): boolean {
56
+ return needles.some((needle) => value.includes(needle));
57
+ }
58
+
59
+ function categorizeTool(name: string, description: string | null): RequestToolCategory {
60
+ const haystack = lowerHaystack(name, description);
61
+ if (
62
+ name.startsWith("mcp__") ||
63
+ name.startsWith("inspector_") ||
64
+ includesAny(haystack, [" mcp", "model context protocol"])
65
+ ) {
66
+ return "mcp";
67
+ }
68
+ if (
69
+ includesAny(haystack, ["bash", "shell", "terminal", "command", "powershell", "exec", "process"])
70
+ ) {
71
+ return "shell";
72
+ }
73
+ if (
74
+ includesAny(haystack, [
75
+ "browser",
76
+ "playwright",
77
+ "screenshot",
78
+ "click",
79
+ "navigate",
80
+ "page",
81
+ "tab",
82
+ ])
83
+ ) {
84
+ return "browser";
85
+ }
86
+ if (
87
+ includesAny(haystack, [
88
+ "read",
89
+ "write",
90
+ "edit",
91
+ "file",
92
+ "glob",
93
+ "grep",
94
+ "patch",
95
+ "filesystem",
96
+ "directory",
97
+ ])
98
+ ) {
99
+ return "file";
100
+ }
101
+ if (includesAny(haystack, ["web", "search", "http", "url", "fetch"])) {
102
+ return "web";
103
+ }
104
+ if (includesAny(haystack, ["code", "typescript", "javascript", "python", "repl"])) {
105
+ return "code";
106
+ }
107
+ return "other";
108
+ }
109
+
110
+ function parameterNames(schema: unknown): string[] {
111
+ const properties = safeGetOwnProperty(schema, "properties");
112
+ if (properties === null || typeof properties !== "object" || Array.isArray(properties)) {
113
+ return [];
114
+ }
115
+ return Object.keys(properties).sort((a, b) => a.localeCompare(b));
116
+ }
117
+
118
+ function requiredParameterNames(schema: unknown): string[] {
119
+ const required = safeGetOwnProperty(schema, "required");
120
+ if (!Array.isArray(required)) return [];
121
+ const names: string[] = [];
122
+ for (const item of required) {
123
+ if (typeof item === "string" && item.length > 0) names.push(item);
124
+ }
125
+ return names.sort((a, b) => a.localeCompare(b));
126
+ }
127
+
128
+ function parseAnthropicTool(tool: unknown): RequestToolDefinition | null {
129
+ const name = safeGetOwnProperty(tool, "name");
130
+ if (typeof name !== "string" || name.length === 0) return null;
131
+ const description = safeGetOwnProperty(tool, "description");
132
+ const schema = safeGetOwnProperty(tool, "input_schema") ?? null;
133
+ const normalizedDescription = typeof description === "string" ? description : null;
134
+ return {
135
+ name,
136
+ description: normalizedDescription,
137
+ descriptionPreview: previewDescription(normalizedDescription),
138
+ category: categorizeTool(name, normalizedDescription),
139
+ parameterCount: parameterNames(schema).length,
140
+ requiredParameters: requiredParameterNames(schema),
141
+ schema,
142
+ };
143
+ }
144
+
145
+ function parseOpenAITool(tool: unknown): RequestToolDefinition | null {
146
+ const fn = safeGetOwnProperty(tool, "function");
147
+ const name = safeGetOwnProperty(fn, "name");
148
+ if (typeof name !== "string" || name.length === 0) return null;
149
+ const description = safeGetOwnProperty(fn, "description");
150
+ const schema = safeGetOwnProperty(fn, "parameters") ?? null;
151
+ const normalizedDescription = typeof description === "string" ? description : null;
152
+ return {
153
+ name,
154
+ description: normalizedDescription,
155
+ descriptionPreview: previewDescription(normalizedDescription),
156
+ category: categorizeTool(name, normalizedDescription),
157
+ parameterCount: parameterNames(schema).length,
158
+ requiredParameters: requiredParameterNames(schema),
159
+ schema,
160
+ };
161
+ }
162
+
163
+ function parseTool(tool: unknown): RequestToolDefinition | null {
164
+ const openAITool = parseOpenAITool(tool);
165
+ if (openAITool !== null) return openAITool;
166
+ return parseAnthropicTool(tool);
167
+ }
168
+
169
+ function formatToolChoice(choice: unknown): string | null {
170
+ if (choice === undefined || choice === null) return null;
171
+ if (typeof choice === "string") return choice;
172
+ const type = safeGetOwnProperty(choice, "type");
173
+ const name = safeGetOwnProperty(choice, "name");
174
+ const fnName = safeGetOwnProperty(safeGetOwnProperty(choice, "function"), "name");
175
+ if (typeof type === "string" && typeof fnName === "string" && fnName.length > 0) {
176
+ return `${type}: ${fnName}`;
177
+ }
178
+ if (typeof type === "string" && typeof name === "string" && name.length > 0) {
179
+ return `${type}: ${name}`;
180
+ }
181
+ if (typeof type === "string") return type;
182
+ const encoded = JSON.stringify(choice);
183
+ return encoded === undefined ? null : firstTextSlice(encoded);
184
+ }
185
+
186
+ function summarizeCategories(tools: RequestToolDefinition[]): RequestToolCategorySummary[] {
187
+ const counts = new Map<RequestToolCategory, number>();
188
+ for (const tool of tools) {
189
+ counts.set(tool.category, (counts.get(tool.category) ?? 0) + 1);
190
+ }
191
+ return CATEGORY_ORDER.flatMap((category) => {
192
+ const count = counts.get(category) ?? 0;
193
+ return count > 0 ? [{ category, count }] : [];
194
+ });
195
+ }
196
+
197
+ export function parseRequestTools(parsed: unknown): RequestToolsSummary | null {
198
+ const rawTools = safeGetOwnProperty(parsed, "tools");
199
+ if (!Array.isArray(rawTools) || rawTools.length === 0) return null;
200
+
201
+ const tools: RequestToolDefinition[] = [];
202
+ for (const rawTool of rawTools) {
203
+ const tool = parseTool(rawTool);
204
+ if (tool !== null) tools.push(tool);
205
+ }
206
+ if (tools.length === 0) return null;
207
+
208
+ return {
209
+ tools,
210
+ toolChoiceLabel: formatToolChoice(safeGetOwnProperty(parsed, "tool_choice")),
211
+ categories: summarizeCategories(tools),
212
+ };
213
+ }
@@ -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">