@tonyclaw/agent-inspector 2.0.37 → 2.0.38

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 (85) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/assets/{CompareDrawer-nEHCEVP4.js → CompareDrawer-hc5OoAls.js} +1 -1
  3. package/.output/public/assets/{ProxyViewerContainer-BstBIX2B.js → ProxyViewerContainer-BMKBs8Qz.js} +14 -14
  4. package/.output/public/assets/{ReplayDialog-CUnBdt1Q.js → ReplayDialog-CN-KM2nu.js} +1 -1
  5. package/.output/public/assets/{RequestAnatomy-BU9VT2Sw.js → RequestAnatomy-B1kTlAUk.js} +1 -1
  6. package/.output/public/assets/{ResponseView-amxuKPKY.js → ResponseView-BchUjKjt.js} +1 -1
  7. package/.output/public/assets/{StreamingChunkSequence-DpscrQM2.js → StreamingChunkSequence-BQOxI9Hi.js} +1 -1
  8. package/.output/public/assets/_sessionId-CVw5e8TK.js +1 -0
  9. package/.output/public/assets/index-BdUTMQL6.js +1 -0
  10. package/.output/public/assets/{main-D56QvEyw.js → main-Blykwzsn.js} +2 -2
  11. package/.output/server/{_sessionId-ChwEDyI4.mjs → _sessionId-BUNZz2zZ.mjs} +2 -2
  12. package/.output/server/_ssr/{CompareDrawer-Ce2590rK.mjs → CompareDrawer-VaDYPM5G.mjs} +2 -2
  13. package/.output/server/_ssr/{ProxyViewerContainer-D6xM8A0S.mjs → ProxyViewerContainer-CpdWs7Pk.mjs} +9 -9
  14. package/.output/server/_ssr/{ReplayDialog-CB4KOlLe.mjs → ReplayDialog-DbfIjJhb.mjs} +3 -3
  15. package/.output/server/_ssr/{RequestAnatomy-CsWV3W03.mjs → RequestAnatomy-CrD8h6As.mjs} +2 -2
  16. package/.output/server/_ssr/{ResponseView-BuCCV3LU.mjs → ResponseView-BalvDwtU.mjs} +2 -2
  17. package/.output/server/_ssr/{StreamingChunkSequence-C5dE7V1d.mjs → StreamingChunkSequence-RxatDbPV.mjs} +2 -2
  18. package/.output/server/_ssr/{index-BeIi0CPv.mjs → index-11qAtV9d.mjs} +2 -2
  19. package/.output/server/_ssr/index.mjs +2 -2
  20. package/.output/server/_ssr/{router-Ca2MCyUX.mjs → router-C4OdRnqX.mjs} +69 -76
  21. package/.output/server/{_tanstack-start-manifest_v-CBAJfSAX.mjs → _tanstack-start-manifest_v-F6bwcl33.mjs} +1 -1
  22. package/.output/server/index.mjs +61 -61
  23. package/README.md +1 -1
  24. package/package.json +1 -1
  25. package/src/components/ProxyViewer.tsx +1 -1
  26. package/src/components/ProxyViewerContainer.tsx +1 -1
  27. package/src/components/providers/ProviderForm.tsx +2 -2
  28. package/src/components/proxy-viewer/AgentTraceSummary.tsx +1 -1
  29. package/src/components/proxy-viewer/CompareDrawer.tsx +1 -1
  30. package/src/components/proxy-viewer/ConversationGroup.tsx +1 -1
  31. package/src/components/proxy-viewer/ConversationGroupList.tsx +1 -1
  32. package/src/components/proxy-viewer/ConversationHeader.tsx +1 -1
  33. package/src/components/proxy-viewer/LogEntry.tsx +1 -1
  34. package/src/components/proxy-viewer/LogEntryHeader.tsx +1 -1
  35. package/src/components/proxy-viewer/ReplayDialog.tsx +1 -1
  36. package/src/components/proxy-viewer/ResponseView.tsx +2 -2
  37. package/src/components/proxy-viewer/StreamingChunkSequence.tsx +1 -1
  38. package/src/components/proxy-viewer/TurnGroup.tsx +1 -1
  39. package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +1 -1
  40. package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +1 -1
  41. package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +2 -2
  42. package/src/components/proxy-viewer/formats/index.tsx +5 -3
  43. package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +1 -1
  44. package/src/components/proxy-viewer/log-formats/anthropic.ts +1 -4
  45. package/src/components/proxy-viewer/log-formats/index.ts +6 -6
  46. package/src/components/proxy-viewer/log-formats/openai.ts +1 -1
  47. package/src/components/proxy-viewer/log-formats/types.ts +2 -2
  48. package/src/components/proxy-viewer/viewerState.ts +1 -1
  49. package/src/contracts/anthropic.ts +235 -0
  50. package/src/contracts/index.ts +27 -0
  51. package/src/contracts/json.ts +32 -0
  52. package/src/contracts/log.ts +72 -0
  53. package/src/contracts/openai.ts +176 -0
  54. package/src/knowledge/distiller.ts +1 -1
  55. package/src/lib/export-logs.ts +1 -1
  56. package/src/lib/groupContract.ts +1 -1
  57. package/src/lib/objectUtils.ts +3 -3
  58. package/src/lib/providerTestContract.ts +1 -1
  59. package/src/lib/runContract.ts +1 -1
  60. package/src/lib/stopReason.ts +1 -1
  61. package/src/mcp/previewExtractor.ts +4 -7
  62. package/src/mcp/server.ts +1 -1
  63. package/src/mcp/toolHandlers.ts +1 -1
  64. package/src/proxy/formats/anthropic/anthropicProvider.ts +2 -2
  65. package/src/proxy/formats/anthropic/schemas.ts +12 -235
  66. package/src/proxy/formats/handler.ts +2 -2
  67. package/src/proxy/formats/index.ts +1 -1
  68. package/src/proxy/formats/jsonSchema.ts +2 -36
  69. package/src/proxy/formats/openai/alibabaProvider.ts +2 -2
  70. package/src/proxy/formats/openai/provider.ts +2 -2
  71. package/src/proxy/formats/openai/schemas.ts +14 -187
  72. package/src/proxy/formats/openai/zhipuProvider.ts +2 -2
  73. package/src/proxy/formats/{protocol.ts → providerAdapter.ts} +5 -5
  74. package/src/proxy/formats/providerRegistry.ts +7 -7
  75. package/src/proxy/formats/providers/index.ts +1 -1
  76. package/src/proxy/formats/registry.ts +16 -13
  77. package/src/proxy/handler.ts +1 -1
  78. package/src/proxy/openaiOrphanToolStrip.ts +1 -1
  79. package/src/proxy/providers.ts +1 -1
  80. package/src/proxy/schemas.ts +18 -80
  81. package/src/proxy/store.ts +2 -2
  82. package/src/proxy/upstream.ts +1 -1
  83. package/src/routes/api/logs.stream.ts +1 -1
  84. package/.output/public/assets/_sessionId-7c9bsOFT.js +0 -1
  85. package/.output/public/assets/index-B7a5OmIO.js +0 -1
@@ -1,187 +1,14 @@
1
- import { z } from "zod";
2
- import { JsonValueSchema } from "../jsonSchema";
3
-
4
- // OpenAI Chat Completions Schemas
5
-
6
- export const OpenAIMessageContent = z.union([
7
- z.string(),
8
- z.array(
9
- z.discriminatedUnion("type", [
10
- z.object({ type: z.literal("text"), text: z.string() }),
11
- z.object({
12
- type: z.literal("image_url"),
13
- image_url: z.object({ url: z.string(), detail: z.string().optional() }),
14
- }),
15
- ]),
16
- ),
17
- ]);
18
-
19
- export const OpenAIMessage = z.object({
20
- role: z.enum(["system", "user", "assistant", "tool"]),
21
- content: OpenAIMessageContent,
22
- name: z.string().optional(),
23
- reasoning_content: z.string().optional(),
24
- thinking: z.string().optional(), // Some providers use 'thinking' field
25
- think: z.string().optional(), // MiniMax uses 'think' field
26
- });
27
-
28
- export const OpenAIFunctionCall = z.object({
29
- name: z.string(),
30
- arguments: z.string(),
31
- });
32
-
33
- /** A single OpenAI tool_call (the modern multi-tool form, returned by most
34
- * providers in `choices[].message.tool_calls`). `function.arguments` is
35
- * a JSON-encoded string per the OpenAI spec — we keep it as a string at
36
- * parse time and let the renderer decide whether to JSON-parse it for
37
- * display. */
38
- export const OpenAIToolCallSchema = z.object({
39
- index: z.number().optional(),
40
- id: z.string().optional(),
41
- type: z.literal("function").optional(),
42
- function: z.object({
43
- name: z.string().optional(),
44
- arguments: z.string().optional(),
45
- }),
46
- });
47
-
48
- export type OpenAIToolCall = z.infer<typeof OpenAIToolCallSchema>;
49
-
50
- const OpenAIMessageWithFunctionCall = OpenAIMessage.extend({
51
- content: z
52
- .union([z.string(), z.array(z.object({ type: z.literal("text"), text: z.string() }))])
53
- .optional(),
54
- function_call: OpenAIFunctionCall.optional(),
55
- tool_calls: z.array(OpenAIToolCallSchema).optional(),
56
- });
57
-
58
- export const OpenAIToolDefinition = z.object({
59
- type: z.literal("function"),
60
- function: z.object({
61
- name: z.string(),
62
- description: z.string().optional(),
63
- parameters: z.record(z.string(), JsonValueSchema),
64
- }),
65
- });
66
-
67
- export const OpenAIRequestSchema = z.object({
68
- model: z.string(),
69
- messages: z.array(OpenAIMessage),
70
- temperature: z.number().optional(),
71
- max_tokens: z.number().optional(),
72
- stream: z.boolean().optional(),
73
- tools: z.array(OpenAIToolDefinition).optional(),
74
- tool_choice: z
75
- .union([
76
- z.enum(["auto", "none", "required"]),
77
- z.object({ type: z.literal("auto") }),
78
- z.object({ type: z.literal("none") }),
79
- z.object({ type: z.literal("function"), function: z.object({ name: z.string() }) }),
80
- ])
81
- .optional(),
82
- user: z.string().optional(),
83
- });
84
-
85
- export const OpenAIChoiceDelta = z.object({
86
- role: z.enum(["assistant"]).optional(),
87
- content: z.string().nullable().optional(),
88
- reasoning_content: z.string().nullable().optional(),
89
- thinking: z.string().nullable().optional(), // Some providers use 'thinking' field
90
- think: z.string().nullable().optional(), // MiniMax uses 'think' field
91
- function_call: z
92
- .object({ name: z.string().optional(), arguments: z.string().optional() })
93
- .nullable()
94
- .optional(),
95
- tool_calls: z
96
- .array(
97
- z.object({
98
- index: z.number(),
99
- id: z.string().optional(),
100
- type: z.literal("function").optional(),
101
- function: z.object({
102
- name: z.string().optional(),
103
- arguments: z.string().optional(),
104
- }),
105
- }),
106
- )
107
- .nullable()
108
- .optional(),
109
- });
110
-
111
- export const OpenAIChoice = z.object({
112
- index: z.number(),
113
- message: z
114
- .object({
115
- role: z.enum(["assistant"]),
116
- content: z.string().nullable(),
117
- reasoning_content: z.string().optional(),
118
- thinking: z.string().optional(), // Some providers use 'thinking' field in message
119
- think: z.string().optional(), // MiniMax uses 'think' field in message
120
- function_call: z.object({ name: z.string(), arguments: z.string() }).nullable().optional(),
121
- tool_calls: z.array(OpenAIToolCallSchema).optional(),
122
- })
123
- .optional(),
124
- delta: OpenAIChoiceDelta.optional(),
125
- finish_reason: z.string().nullable(),
126
- });
127
-
128
- export const OpenAIResponseSchema = z
129
- .object({
130
- id: z.string(),
131
- object: z.literal("chat.completion"),
132
- created: z.number(),
133
- model: z.string(),
134
- choices: z.array(OpenAIChoice),
135
- usage: z
136
- .object({
137
- prompt_tokens: z.number().nullable().optional(),
138
- completion_tokens: z.number().nullable().optional(),
139
- total_tokens: z.number().nullable().optional(),
140
- })
141
- .passthrough(), // Allow extra fields like prompt_tokens_details, completion_tokens_details
142
- service_tier: z.string().nullable().optional(),
143
- system_fingerprint: z.string().nullable().optional(),
144
- })
145
- .passthrough(); // Allow extra fields like refusal, annotations, audio
146
-
147
- // Schema for actual OpenAI SSE chunk format (not wrapped in event/data)
148
- export const OpenAISSERawChunkSchema = z
149
- .object({
150
- id: z.string(),
151
- object: z.literal("chat.completion.chunk"),
152
- created: z.number(),
153
- model: z.string(),
154
- choices: z.array(
155
- z.object({
156
- index: z.number(),
157
- delta: OpenAIChoiceDelta,
158
- finish_reason: z.string().nullable().optional(),
159
- }),
160
- ),
161
- usage: z
162
- .object({
163
- prompt_tokens: z.number().nullable().optional(),
164
- completion_tokens: z.number().nullable().optional(),
165
- total_tokens: z.number().nullable().optional(),
166
- })
167
- .passthrough()
168
- .nullable()
169
- .optional(),
170
- })
171
- .passthrough(); // Allow extra fields in chunks
172
-
173
- export type OpenAIResponse = z.infer<typeof OpenAIResponseSchema>;
174
-
175
- /**
176
- * Parse an OpenAI response body.
177
- */
178
- export function parseOpenAIResponse(rawBody: string): OpenAIResponse | null {
179
- try {
180
- const json: unknown = JSON.parse(rawBody);
181
- const result = OpenAIResponseSchema.safeParse(json);
182
- if (result.success) return result.data;
183
- return null;
184
- } catch {
185
- return null;
186
- }
187
- }
1
+ export {
2
+ OpenAIChoice,
3
+ OpenAIChoiceDelta,
4
+ OpenAIFunctionCall,
5
+ OpenAIMessage,
6
+ OpenAIMessageContent,
7
+ OpenAIRequestSchema,
8
+ OpenAIResponseSchema,
9
+ OpenAISSERawChunkSchema,
10
+ OpenAIToolCallSchema,
11
+ OpenAIToolDefinition,
12
+ parseOpenAIResponse,
13
+ } from "../../../contracts/openai";
14
+ export type { OpenAIResponse, OpenAIToolCall } from "../../../contracts/openai";
@@ -1,12 +1,12 @@
1
1
  import type { CapturedLog } from "../../schemas";
2
- import type { ProviderProtocol } from "../protocol";
2
+ import type { ProviderAdapter } from "../providerAdapter";
3
3
  import { registry } from "../providers";
4
4
  import { extractOpenAIStream } from "./stream";
5
5
 
6
6
  const DEFAULT_ZHIPU_UPSTREAM = "https://open.bigmodel.cn/api/paas/v4";
7
7
  const ZHIPU_MODEL_PREFIXES = ["glm-", "charglm-", "cogview-", "embedding-", "rerank-"];
8
8
 
9
- export const zhipuProvider: ProviderProtocol = {
9
+ export const zhipuProvider: ProviderAdapter = {
10
10
  name: "zhipu",
11
11
 
12
12
  matches(model: string): boolean {
@@ -1,12 +1,12 @@
1
- import type { CapturedLog, RequestFormat } from "../schemas";
1
+ import type { ApiFormat, CapturedLog } from "../../contracts";
2
2
 
3
3
  /**
4
- * Provider Protocol Interface
4
+ * Provider Adapter Interface
5
5
  *
6
- * Defines the contract that all providers must implement to support
6
+ * Defines the contract that all provider adapters must implement to support
7
7
  * different LLM APIs (Anthropic, OpenAI, etc.).
8
8
  */
9
- export type ProviderProtocol = {
9
+ export type ProviderAdapter = {
10
10
  /** Provider identifier (e.g., "anthropic", "openai") */
11
11
  name: string;
12
12
 
@@ -46,5 +46,5 @@ export type ProviderProtocol = {
46
46
  * @param apiFormat - Request format (anthropic/openai/unknown)
47
47
  * @returns Transformed body or null to use original
48
48
  */
49
- transformRequest?(body: string, apiFormat: RequestFormat): string | null;
49
+ transformRequest?(body: string, apiFormat: ApiFormat): string | null;
50
50
  };
@@ -1,4 +1,4 @@
1
- import type { ProviderProtocol } from "./protocol";
1
+ import type { ProviderAdapter } from "./providerAdapter";
2
2
 
3
3
  /**
4
4
  * Provider Registry
@@ -7,13 +7,13 @@ import type { ProviderProtocol } from "./protocol";
7
7
  * Providers register themselves at module load time.
8
8
  */
9
9
  class ProviderRegistryImpl {
10
- private providers: ProviderProtocol[] = [];
10
+ private providers: ProviderAdapter[] = [];
11
11
 
12
12
  /**
13
13
  * Register a provider with the registry.
14
14
  * @param provider - Provider implementation to register
15
15
  */
16
- register(provider: ProviderProtocol): void {
16
+ register(provider: ProviderAdapter): void {
17
17
  this.providers.push(provider);
18
18
  }
19
19
 
@@ -22,8 +22,8 @@ class ProviderRegistryImpl {
22
22
  * @param model - Model name to match
23
23
  * @returns Matching provider or null if none found
24
24
  */
25
- findProvider(model: string): ProviderProtocol | null {
26
- let fallback: ProviderProtocol | null = null;
25
+ findProvider(model: string): ProviderAdapter | null {
26
+ let fallback: ProviderAdapter | null = null;
27
27
 
28
28
  for (const provider of this.providers) {
29
29
  if (provider.matches(model)) {
@@ -31,7 +31,7 @@ class ProviderRegistryImpl {
31
31
  if (provider.name !== "anthropic") {
32
32
  return provider;
33
33
  }
34
- // Anthropic is the fallback only use if nothing else matches
34
+ // Anthropic is the fallback; only use if nothing else matches
35
35
  fallback = provider;
36
36
  }
37
37
  }
@@ -42,7 +42,7 @@ class ProviderRegistryImpl {
42
42
  * Get all registered providers.
43
43
  * @returns Array of all registered providers
44
44
  */
45
- getAll(): ProviderProtocol[] {
45
+ getAll(): ProviderAdapter[] {
46
46
  return [...this.providers];
47
47
  }
48
48
  }
@@ -1,3 +1,3 @@
1
1
  // Provider types and registry
2
- export type { ProviderProtocol } from "../protocol";
2
+ export type { ProviderAdapter } from "../providerAdapter";
3
3
  export { registry } from "../providerRegistry";
@@ -1,26 +1,26 @@
1
1
  import type { FormatHandler } from "./handler";
2
- import type { RequestFormat } from "../schemas";
2
+ import type { ApiFormat } from "../schemas";
3
3
  import { PATH_V1_CHAT_COMPLETIONS, PATH_CHAT_COMPLETIONS, PATH_V1_MESSAGES } from "../constants";
4
4
 
5
5
  /**
6
- * Format registry maps request paths and formats to their FormatHandler.
6
+ * API format registry maps request paths and API formats to their FormatHandler.
7
7
  *
8
8
  * Registered at module load time by each format's init module.
9
9
  */
10
10
  class FormatRegistryImpl {
11
- private handlers = new Map<RequestFormat, FormatHandler>();
12
- private pathMap = new Map<string, RequestFormat>();
11
+ private handlers = new Map<ApiFormat, FormatHandler>();
12
+ private pathMap = new Map<string, ApiFormat>();
13
13
 
14
14
  register(handler: FormatHandler): void {
15
15
  this.handlers.set(handler.format, handler);
16
16
  }
17
17
 
18
- registerPath(path: string, format: RequestFormat): void {
18
+ registerPath(path: string, format: ApiFormat): void {
19
19
  this.pathMap.set(path, format);
20
20
  }
21
21
 
22
22
  /** Get handler by format identifier */
23
- get(format: RequestFormat): FormatHandler | undefined {
23
+ get(format: ApiFormat): FormatHandler | undefined {
24
24
  return this.handlers.get(format);
25
25
  }
26
26
 
@@ -31,14 +31,14 @@ class FormatRegistryImpl {
31
31
  return format === undefined ? undefined : this.handlers.get(format);
32
32
  }
33
33
 
34
- /** Get the wire format matching a request path without requiring handlers. */
35
- getFormatByPath(path: string): RequestFormat | undefined {
34
+ /** Get the API format matching a request path without requiring handlers. */
35
+ getApiFormatByPath(path: string): ApiFormat | undefined {
36
36
  const messagesPath = path.split("?")[0] ?? "";
37
37
  return this.pathMap.get(messagesPath);
38
38
  }
39
39
 
40
- /** Detect format from request body content */
41
- detectFormat(rawBody: string | null): RequestFormat {
40
+ /** Detect API format from request body content */
41
+ detectFormat(rawBody: string | null): ApiFormat {
42
42
  if (rawBody === null) return "unknown";
43
43
  for (const handler of this.handlers.values()) {
44
44
  if (handler.detectFormat(rawBody)) return handler.format;
@@ -58,14 +58,17 @@ export function formatForPath(path: string): FormatHandler | null {
58
58
  }
59
59
 
60
60
  /**
61
- * Resolve the wire format from the request endpoint. The endpoint is
61
+ * Resolve the API format from the request endpoint. The endpoint is
62
62
  * authoritative because Anthropic and OpenAI request bodies overlap for
63
63
  * simple message-only calls.
64
64
  */
65
- export function requestFormatForPath(path: string): RequestFormat {
66
- return formatRegistry.getFormatByPath(path) ?? "unknown";
65
+ export function apiFormatForPath(path: string): ApiFormat {
66
+ return formatRegistry.getApiFormatByPath(path) ?? "unknown";
67
67
  }
68
68
 
69
+ /** Backward-compatible alias for older internal imports. */
70
+ export const requestFormatForPath = apiFormatForPath;
71
+
69
72
  // Register known paths
70
73
  formatRegistry.registerPath(PATH_V1_MESSAGES, "anthropic");
71
74
  formatRegistry.registerPath(PATH_V1_CHAT_COMPLETIONS, "openai");
@@ -247,7 +247,7 @@ export async function handleProxy(req: Request): Promise<Response> {
247
247
  }
248
248
  }
249
249
 
250
- // Always-on protocol guard: OpenAI Chat Completions requires every
250
+ // Always-on OpenAI Chat Completions format guard: every
251
251
  // `role: "tool"` message to reference a `tool_call_id` present in a
252
252
  // preceding assistant message's `tool_calls`. Buggy clients sometimes
253
253
  // record a tool result without the matching assistant tool_call, which
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OpenAI Chat Completions protocol guard: orphan `tool` messages.
2
+ * OpenAI Chat Completions format guard: orphan `tool` messages.
3
3
  *
4
4
  * The OpenAI Chat Completions spec requires every message with
5
5
  * `role: "tool"` to reference a `tool_call_id` that appears in a preceding
@@ -232,7 +232,7 @@ migrateFromLegacyConfLocation(store);
232
232
  * Expands the old `{ format, baseUrl }` representation into the matching
233
233
  * format-specific URL. Once either format-specific field exists, the record is
234
234
  * already on the current schema and must be preserved exactly: an empty or
235
- * missing counterpart means that protocol was intentionally not configured.
235
+ * missing counterpart means that API format was intentionally not configured.
236
236
  */
237
237
  export function migrateProvider(p: ProviderConfig): ProviderConfig {
238
238
  if (p.anthropicBaseUrl !== undefined || p.openaiBaseUrl !== undefined) {
@@ -1,94 +1,32 @@
1
1
  import { z } from "zod";
2
2
 
3
- // Import JsonValueSchema from shared location to avoid circular dependency
4
- import { JsonValueSchema, type JsonValue } from "./formats/jsonSchema";
5
-
6
- export { JsonValueSchema };
7
- export type { JsonValue };
8
-
9
- export type RequestFormat = "anthropic" | "openai" | "unknown";
10
-
11
- /**
12
- * A single SSE event from a streaming response.
13
- */
14
- export const StreamingChunkSchema = z.object({
15
- index: z.number(),
16
- timestamp: z.number(),
17
- type: z.string(),
18
- data: JsonValueSchema,
19
- });
20
-
21
- export type StreamingChunk = z.infer<typeof StreamingChunkSchema>;
22
-
23
- const StreamingChunksArraySchema = z.object({
24
- chunks: z.array(StreamingChunkSchema),
25
- truncated: z.boolean().optional().default(false),
26
- });
27
-
28
- export const CapturedLogSchema = z.object({
29
- id: z.number(),
30
- timestamp: z.string(),
31
- method: z.string(),
32
- path: z.string(),
33
- model: z.string().nullable(),
34
- sessionId: z.string().nullable(),
35
- rawRequestBody: z.string().nullable(),
36
- responseStatus: z.number().nullable(),
37
- responseText: z.string().nullable(),
38
- inputTokens: z.number().nullable(),
39
- outputTokens: z.number().nullable(),
40
- cacheCreationInputTokens: z.number().nullable(),
41
- cacheReadInputTokens: z.number().nullable(),
42
- elapsedMs: z.number().nullable(),
43
- firstChunkMs: z.number().nullable().optional(),
44
- totalStreamMs: z.number().nullable().optional(),
45
- tokensPerSecond: z.number().nullable().optional(),
46
- streaming: z.boolean(),
47
- userAgent: z.string().nullable(),
48
- origin: z.string().nullable(),
49
- rawHeaders: z.record(z.string(), z.string()).optional(),
50
- /** Headers sent to the upstream LLM */
51
- headers: z.record(z.string(), z.string()).optional(),
52
- apiFormat: z.enum(["anthropic", "openai", "unknown"]).default("unknown"),
53
- isTest: z.boolean().optional().default(false),
54
- replayOfLogId: z.number().nullable().optional(),
55
- providerName: z.string().nullable().optional(),
56
- clientPort: z.number().nullable().optional(),
57
- clientPid: z.number().nullable().optional(),
58
- clientCwd: z.string().nullable().optional(),
59
- clientProjectFolder: z.string().nullable().optional(),
60
- streamingChunks: StreamingChunksArraySchema.optional(),
61
- streamingChunksPath: z.string().nullable().optional(),
62
- rawRequestBodyBytes: z.number().int().nonnegative().nullable().optional(),
63
- responseTextBytes: z.number().int().nonnegative().nullable().optional(),
64
- bodyContentMode: z.enum(["full", "compact", "truncated"]).optional(),
65
- /** Error message from streaming response (e.g., SSE error event) */
66
- error: z.string().nullable().optional(),
67
- });
68
-
69
- export type CapturedLog = z.infer<typeof CapturedLogSchema>;
70
-
71
- export type TokenUsage = {
72
- inputTokens: number | null;
73
- outputTokens: number | null;
74
- cacheCreationInputTokens: number | null;
75
- cacheReadInputTokens: number | null;
76
- };
3
+ export { CapturedLogSchema, JsonValueSchema, StreamingChunkSchema } from "../contracts";
4
+ export type {
5
+ CapturedLog,
6
+ ApiFormat,
7
+ JsonValue,
8
+ RequestFormat,
9
+ StreamingChunk,
10
+ TokenUsage,
11
+ } from "../contracts";
77
12
 
78
13
  // ============================================================
79
- // Import types and schemas from formats
14
+ // Import types and schemas from shared contracts
80
15
  // ============================================================
81
16
 
82
- // Re-export types and schemas from formats for backward compatibility
17
+ // Re-export types and schemas from shared contracts for backward compatibility
83
18
  export {
19
+ AnthropicRequestSchema,
20
+ AnthropicResponseSchema,
84
21
  InspectorRequestSchema,
85
22
  InspectorResponseSchema,
86
23
  SseEventSchema,
87
- } from "./formats/anthropic/schemas";
24
+ } from "../contracts/anthropic";
88
25
  export type {
26
+ AnthropicResponse,
89
27
  InspectorResponse,
90
28
  ResponseContentBlockType,
91
- } from "./formats/anthropic/schemas";
29
+ } from "../contracts/anthropic";
92
30
 
93
31
  export {
94
32
  OpenAIRequestSchema,
@@ -97,7 +35,7 @@ export {
97
35
  type OpenAIResponse,
98
36
  type OpenAIToolCall,
99
37
  parseOpenAIResponse,
100
- } from "./formats/openai/schemas";
38
+ } from "../contracts/openai";
101
39
 
102
40
  // Schema for model name in request body (used for routing)
103
41
  const RequestModelSchema = z.object({
@@ -141,7 +79,7 @@ function extractSessionIdFromHeaders(headers: Headers): string | null {
141
79
  * for routing + log creation: the model (used for provider selection) and the
142
80
  * session id (from `metadata.user_id` or the `x-session-affinity` header).
143
81
  *
144
- * Returning `null` for either field is a valid outcome callers must handle
82
+ * Returning `null` for either field is a valid outcome; callers must handle
145
83
  * "unknown" gracefully. Callers that already have the body string should use
146
84
  * this instead of re-parsing with `extractModelFromBody` and a second pass
147
85
  * for the session id.
@@ -34,7 +34,7 @@ import type { SessionInfo, SessionLogSummary } from "../lib/sessionInfoContract"
34
34
  import { buildSessionInfo, buildSessionLogSummary } from "./sessionInfo";
35
35
  import type { CapturedLog } from "./schemas";
36
36
  import { CapturedLogSchema } from "./schemas";
37
- import { requestFormatForPath } from "./formats/registry";
37
+ import { apiFormatForPath } from "./formats/registry";
38
38
  import {
39
39
  clearSessionRegistry,
40
40
  getLogSessionId,
@@ -112,7 +112,7 @@ function evictOldestIfNeeded(): void {
112
112
 
113
113
  function normalizeLog(log: CapturedLog): CapturedLog {
114
114
  const sessionId = getLogSessionId(log);
115
- const pathFormat = requestFormatForPath(log.path);
115
+ const pathFormat = apiFormatForPath(log.path);
116
116
  const apiFormat = pathFormat === "unknown" ? log.apiFormat : pathFormat;
117
117
  if (sessionId === log.sessionId && apiFormat === log.apiFormat) return log;
118
118
  return { ...log, sessionId, apiFormat };
@@ -18,7 +18,7 @@ export type ApiRoute = {
18
18
  };
19
19
 
20
20
  /**
21
- * Describes the protocol implied by the client-facing path.
21
+ * Describes the API route implied by the client-facing path.
22
22
  *
23
23
  * The path is the source of truth for request/response format. ProviderConfig.format
24
24
  * is only a fallback for old provider records that do not have a format-specific URL.
@@ -1,6 +1,6 @@
1
1
  import { createFileRoute } from "@tanstack/react-router";
2
2
  import { compactLogForList, onLogUpdate, getLogSessionId, listLogsPage } from "../../proxy/store";
3
- import { type CapturedLog } from "../../proxy/schemas";
3
+ import { type CapturedLog } from "../../contracts";
4
4
 
5
5
  const INITIAL_STREAM_LOG_LIMIT = 100;
6
6
 
@@ -1 +0,0 @@
1
- import{R as s,j as e}from"./main-D56QvEyw.js";import{P as i}from"./ProxyViewerContainer-BstBIX2B.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-BstBIX2B.js";import"./main-D56QvEyw.js";const r=o;export{r as component};