@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.
- package/.output/nitro.json +1 -1
- package/.output/public/assets/{CompareDrawer-nEHCEVP4.js → CompareDrawer-hc5OoAls.js} +1 -1
- package/.output/public/assets/{ProxyViewerContainer-BstBIX2B.js → ProxyViewerContainer-BMKBs8Qz.js} +14 -14
- package/.output/public/assets/{ReplayDialog-CUnBdt1Q.js → ReplayDialog-CN-KM2nu.js} +1 -1
- package/.output/public/assets/{RequestAnatomy-BU9VT2Sw.js → RequestAnatomy-B1kTlAUk.js} +1 -1
- package/.output/public/assets/{ResponseView-amxuKPKY.js → ResponseView-BchUjKjt.js} +1 -1
- package/.output/public/assets/{StreamingChunkSequence-DpscrQM2.js → StreamingChunkSequence-BQOxI9Hi.js} +1 -1
- package/.output/public/assets/_sessionId-CVw5e8TK.js +1 -0
- package/.output/public/assets/index-BdUTMQL6.js +1 -0
- package/.output/public/assets/{main-D56QvEyw.js → main-Blykwzsn.js} +2 -2
- package/.output/server/{_sessionId-ChwEDyI4.mjs → _sessionId-BUNZz2zZ.mjs} +2 -2
- package/.output/server/_ssr/{CompareDrawer-Ce2590rK.mjs → CompareDrawer-VaDYPM5G.mjs} +2 -2
- package/.output/server/_ssr/{ProxyViewerContainer-D6xM8A0S.mjs → ProxyViewerContainer-CpdWs7Pk.mjs} +9 -9
- package/.output/server/_ssr/{ReplayDialog-CB4KOlLe.mjs → ReplayDialog-DbfIjJhb.mjs} +3 -3
- package/.output/server/_ssr/{RequestAnatomy-CsWV3W03.mjs → RequestAnatomy-CrD8h6As.mjs} +2 -2
- package/.output/server/_ssr/{ResponseView-BuCCV3LU.mjs → ResponseView-BalvDwtU.mjs} +2 -2
- package/.output/server/_ssr/{StreamingChunkSequence-C5dE7V1d.mjs → StreamingChunkSequence-RxatDbPV.mjs} +2 -2
- package/.output/server/_ssr/{index-BeIi0CPv.mjs → index-11qAtV9d.mjs} +2 -2
- package/.output/server/_ssr/index.mjs +2 -2
- package/.output/server/_ssr/{router-Ca2MCyUX.mjs → router-C4OdRnqX.mjs} +69 -76
- package/.output/server/{_tanstack-start-manifest_v-CBAJfSAX.mjs → _tanstack-start-manifest_v-F6bwcl33.mjs} +1 -1
- package/.output/server/index.mjs +61 -61
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/components/ProxyViewer.tsx +1 -1
- package/src/components/ProxyViewerContainer.tsx +1 -1
- package/src/components/providers/ProviderForm.tsx +2 -2
- package/src/components/proxy-viewer/AgentTraceSummary.tsx +1 -1
- package/src/components/proxy-viewer/CompareDrawer.tsx +1 -1
- package/src/components/proxy-viewer/ConversationGroup.tsx +1 -1
- package/src/components/proxy-viewer/ConversationGroupList.tsx +1 -1
- package/src/components/proxy-viewer/ConversationHeader.tsx +1 -1
- package/src/components/proxy-viewer/LogEntry.tsx +1 -1
- package/src/components/proxy-viewer/LogEntryHeader.tsx +1 -1
- package/src/components/proxy-viewer/ReplayDialog.tsx +1 -1
- package/src/components/proxy-viewer/ResponseView.tsx +2 -2
- package/src/components/proxy-viewer/StreamingChunkSequence.tsx +1 -1
- package/src/components/proxy-viewer/TurnGroup.tsx +1 -1
- package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +1 -1
- package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +1 -1
- package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +2 -2
- package/src/components/proxy-viewer/formats/index.tsx +5 -3
- package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +1 -1
- package/src/components/proxy-viewer/log-formats/anthropic.ts +1 -4
- package/src/components/proxy-viewer/log-formats/index.ts +6 -6
- package/src/components/proxy-viewer/log-formats/openai.ts +1 -1
- package/src/components/proxy-viewer/log-formats/types.ts +2 -2
- package/src/components/proxy-viewer/viewerState.ts +1 -1
- package/src/contracts/anthropic.ts +235 -0
- package/src/contracts/index.ts +27 -0
- package/src/contracts/json.ts +32 -0
- package/src/contracts/log.ts +72 -0
- package/src/contracts/openai.ts +176 -0
- package/src/knowledge/distiller.ts +1 -1
- package/src/lib/export-logs.ts +1 -1
- package/src/lib/groupContract.ts +1 -1
- package/src/lib/objectUtils.ts +3 -3
- package/src/lib/providerTestContract.ts +1 -1
- package/src/lib/runContract.ts +1 -1
- package/src/lib/stopReason.ts +1 -1
- package/src/mcp/previewExtractor.ts +4 -7
- package/src/mcp/server.ts +1 -1
- package/src/mcp/toolHandlers.ts +1 -1
- package/src/proxy/formats/anthropic/anthropicProvider.ts +2 -2
- package/src/proxy/formats/anthropic/schemas.ts +12 -235
- package/src/proxy/formats/handler.ts +2 -2
- package/src/proxy/formats/index.ts +1 -1
- package/src/proxy/formats/jsonSchema.ts +2 -36
- package/src/proxy/formats/openai/alibabaProvider.ts +2 -2
- package/src/proxy/formats/openai/provider.ts +2 -2
- package/src/proxy/formats/openai/schemas.ts +14 -187
- package/src/proxy/formats/openai/zhipuProvider.ts +2 -2
- package/src/proxy/formats/{protocol.ts → providerAdapter.ts} +5 -5
- package/src/proxy/formats/providerRegistry.ts +7 -7
- package/src/proxy/formats/providers/index.ts +1 -1
- package/src/proxy/formats/registry.ts +16 -13
- package/src/proxy/handler.ts +1 -1
- package/src/proxy/openaiOrphanToolStrip.ts +1 -1
- package/src/proxy/providers.ts +1 -1
- package/src/proxy/schemas.ts +18 -80
- package/src/proxy/store.ts +2 -2
- package/src/proxy/upstream.ts +1 -1
- package/src/routes/api/logs.stream.ts +1 -1
- package/.output/public/assets/_sessionId-7c9bsOFT.js +0 -1
- package/.output/public/assets/index-B7a5OmIO.js +0 -1
|
@@ -1,187 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 {
|
|
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:
|
|
9
|
+
export const zhipuProvider: ProviderAdapter = {
|
|
10
10
|
name: "zhipu",
|
|
11
11
|
|
|
12
12
|
matches(model: string): boolean {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApiFormat, CapturedLog } from "../../contracts";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Provider
|
|
4
|
+
* Provider Adapter Interface
|
|
5
5
|
*
|
|
6
|
-
* Defines the contract that all
|
|
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
|
|
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:
|
|
49
|
+
transformRequest?(body: string, apiFormat: ApiFormat): string | null;
|
|
50
50
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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:
|
|
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:
|
|
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):
|
|
26
|
-
let fallback:
|
|
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
|
|
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():
|
|
45
|
+
getAll(): ProviderAdapter[] {
|
|
46
46
|
return [...this.providers];
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import type { FormatHandler } from "./handler";
|
|
2
|
-
import type {
|
|
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
|
-
*
|
|
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<
|
|
12
|
-
private pathMap = new Map<string,
|
|
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:
|
|
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:
|
|
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
|
|
35
|
-
|
|
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):
|
|
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
|
|
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
|
|
66
|
-
return formatRegistry.
|
|
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");
|
package/src/proxy/handler.ts
CHANGED
|
@@ -247,7 +247,7 @@ export async function handleProxy(req: Request): Promise<Response> {
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
// Always-on
|
|
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
|
|
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
|
package/src/proxy/providers.ts
CHANGED
|
@@ -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
|
|
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) {
|
package/src/proxy/schemas.ts
CHANGED
|
@@ -1,94 +1,32 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
14
|
+
// Import types and schemas from shared contracts
|
|
80
15
|
// ============================================================
|
|
81
16
|
|
|
82
|
-
// Re-export types and schemas from
|
|
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 "
|
|
24
|
+
} from "../contracts/anthropic";
|
|
88
25
|
export type {
|
|
26
|
+
AnthropicResponse,
|
|
89
27
|
InspectorResponse,
|
|
90
28
|
ResponseContentBlockType,
|
|
91
|
-
} from "
|
|
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 "
|
|
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
|
|
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.
|
package/src/proxy/store.ts
CHANGED
|
@@ -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 {
|
|
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 =
|
|
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 };
|
package/src/proxy/upstream.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type ApiRoute = {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Describes the
|
|
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 "../../
|
|
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};
|