@tonyclaw/llm-inspector 1.14.7 → 1.14.9
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/index-Dv-dj1xH.js +105 -0
- package/.output/public/assets/index-bqeypwJB.css +1 -0
- package/.output/public/assets/{main-BV7uNIIz.js → main-C8OUJKbz.js} +1 -1
- package/.output/server/_libs/lucide-react.mjs +87 -79
- package/.output/server/_libs/radix-ui__react-id.mjs +1 -1
- package/.output/server/_ssr/{index-BvHLASu8.mjs → index-_9xcAkkw.mjs} +861 -608
- package/.output/server/_ssr/index.mjs +2 -2
- package/.output/server/_ssr/{router-lUOA8pi6.mjs → router-CmanwZJc.mjs} +45 -14
- package/.output/server/{_tanstack-start-manifest_v-XNH7fVPN.mjs → _tanstack-start-manifest_v-BVIiyDeJ.mjs} +1 -1
- package/.output/server/index.mjs +23 -23
- package/package.json +1 -1
- package/src/components/ProxyViewer.tsx +137 -146
- package/src/components/providers/ProviderCard.tsx +79 -26
- package/src/components/providers/ProviderForm.tsx +37 -22
- package/src/components/providers/ProvidersPanel.tsx +79 -47
- package/src/components/providers/SettingsDialog.tsx +25 -15
- package/src/components/proxy-viewer/ConversationGroup.tsx +74 -11
- package/src/components/proxy-viewer/ConversationHeader.tsx +63 -2
- package/src/components/proxy-viewer/LogEntry.tsx +184 -54
- package/src/components/proxy-viewer/LogEntryHeader.tsx +148 -143
- package/src/components/proxy-viewer/ReplayDialog.tsx +16 -6
- package/src/components/proxy-viewer/StreamingChunkSequence.tsx +24 -16
- package/src/components/proxy-viewer/ThreadConnector.tsx +93 -0
- package/src/components/proxy-viewer/index.ts +2 -1
- package/src/lib/stopReason.ts +57 -0
- package/src/proxy/formats/anthropic/handler.ts +2 -5
- package/src/proxy/formats/openai/handler.ts +33 -7
- package/src/proxy/formats/openai/schemas.ts +1 -0
- package/src/proxy/formats/openai/stream.ts +24 -0
- package/src/proxy/handler.ts +8 -2
- package/src/proxy/schemas.ts +6 -3
- package/.output/public/assets/index-Cmi8TfeU.js +0 -105
- package/.output/public/assets/index-DXUNTCVh.css +0 -1
|
@@ -25,11 +25,41 @@ export const OpenAIFormatHandler: FormatHandler = {
|
|
|
25
25
|
extractTokens(responseBody: string): TokenUsage {
|
|
26
26
|
const parsed = parseOpenAIResponse(responseBody);
|
|
27
27
|
if (parsed) {
|
|
28
|
+
// OpenAI puts cached_tokens in usage.prompt_tokens_details (passthrough field)
|
|
29
|
+
let cacheReadInputTokens: number | null = null;
|
|
30
|
+
try {
|
|
31
|
+
const raw: unknown = JSON.parse(responseBody);
|
|
32
|
+
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
|
|
33
|
+
const usageDesc = Object.getOwnPropertyDescriptor(raw, "usage");
|
|
34
|
+
if (
|
|
35
|
+
usageDesc !== undefined &&
|
|
36
|
+
typeof usageDesc.value === "object" &&
|
|
37
|
+
usageDesc.value !== null
|
|
38
|
+
) {
|
|
39
|
+
const detailsDesc = Object.getOwnPropertyDescriptor(
|
|
40
|
+
usageDesc.value,
|
|
41
|
+
"prompt_tokens_details",
|
|
42
|
+
);
|
|
43
|
+
if (
|
|
44
|
+
detailsDesc !== undefined &&
|
|
45
|
+
typeof detailsDesc.value === "object" &&
|
|
46
|
+
detailsDesc.value !== null
|
|
47
|
+
) {
|
|
48
|
+
const cacheDesc = Object.getOwnPropertyDescriptor(detailsDesc.value, "cached_tokens");
|
|
49
|
+
if (cacheDesc !== undefined && typeof cacheDesc.value === "number") {
|
|
50
|
+
cacheReadInputTokens = cacheDesc.value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
// ignore parse errors
|
|
57
|
+
}
|
|
28
58
|
return {
|
|
29
59
|
inputTokens: parsed.usage.prompt_tokens ?? null,
|
|
30
60
|
outputTokens: parsed.usage.completion_tokens ?? null,
|
|
31
61
|
cacheCreationInputTokens: null,
|
|
32
|
-
cacheReadInputTokens
|
|
62
|
+
cacheReadInputTokens,
|
|
33
63
|
};
|
|
34
64
|
}
|
|
35
65
|
return {
|
|
@@ -55,12 +85,8 @@ export const OpenAIFormatHandler: FormatHandler = {
|
|
|
55
85
|
const json: unknown = JSON.parse(rawBody);
|
|
56
86
|
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
57
87
|
const keys = Object.keys(json);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (!keys.includes("system") && !keys.includes("tools")) {
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
88
|
+
// OpenAI has `model` and `messages` at the top level, but NOT `system`
|
|
89
|
+
return keys.includes("model") && keys.includes("messages") && !keys.includes("system");
|
|
64
90
|
}
|
|
65
91
|
return false;
|
|
66
92
|
} catch {
|
|
@@ -73,6 +73,7 @@ export const OpenAIRequestSchema = z.object({
|
|
|
73
73
|
tools: z.array(OpenAIToolDefinition).optional(),
|
|
74
74
|
tool_choice: z
|
|
75
75
|
.union([
|
|
76
|
+
z.enum(["auto", "none", "required"]),
|
|
76
77
|
z.object({ type: z.literal("auto") }),
|
|
77
78
|
z.object({ type: z.literal("none") }),
|
|
78
79
|
z.object({ type: z.literal("function"), function: z.object({ name: z.string() }) }),
|
|
@@ -93,6 +93,30 @@ export function extractOpenAIStream(
|
|
|
93
93
|
promptTokens = chunk.usage.prompt_tokens ?? 0;
|
|
94
94
|
completionTokens = chunk.usage.completion_tokens ?? 0;
|
|
95
95
|
log.inputTokens = promptTokens;
|
|
96
|
+
// Extract cached_tokens from raw parsed object (passthrough field in usage)
|
|
97
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
98
|
+
const usageDesc = Object.getOwnPropertyDescriptor(parsed, "usage");
|
|
99
|
+
if (
|
|
100
|
+
usageDesc !== undefined &&
|
|
101
|
+
typeof usageDesc.value === "object" &&
|
|
102
|
+
usageDesc.value !== null
|
|
103
|
+
) {
|
|
104
|
+
const detailsDesc = Object.getOwnPropertyDescriptor(
|
|
105
|
+
usageDesc.value,
|
|
106
|
+
"prompt_tokens_details",
|
|
107
|
+
);
|
|
108
|
+
if (
|
|
109
|
+
detailsDesc !== undefined &&
|
|
110
|
+
typeof detailsDesc.value === "object" &&
|
|
111
|
+
detailsDesc.value !== null
|
|
112
|
+
) {
|
|
113
|
+
const cacheDesc = Object.getOwnPropertyDescriptor(detailsDesc.value, "cached_tokens");
|
|
114
|
+
if (cacheDesc !== undefined && typeof cacheDesc.value === "number") {
|
|
115
|
+
log.cacheReadInputTokens = cacheDesc.value;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
96
120
|
usageCaptured = true;
|
|
97
121
|
}
|
|
98
122
|
|
package/src/proxy/handler.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { extractRequestMetadata } from "./schemas";
|
|
|
5
5
|
import { registry } from "./formats";
|
|
6
6
|
import { findProviderByModel } from "./providers";
|
|
7
7
|
import { getClientInfo } from "./socketTracker";
|
|
8
|
-
import { formatForPath, type FormatHandler } from "./formats";
|
|
8
|
+
import { formatForPath, formatRegistry, type FormatHandler } from "./formats";
|
|
9
9
|
import {
|
|
10
10
|
PROXY_IDENTITY,
|
|
11
11
|
PRESERVE_HEADERS,
|
|
@@ -308,6 +308,12 @@ export async function handleProxy(req: Request): Promise<Response> {
|
|
|
308
308
|
upstreamHeaders.forEach((value, key) => {
|
|
309
309
|
upstreamHeadersObj[key.toLowerCase()] = value;
|
|
310
310
|
});
|
|
311
|
+
// Detect the true format from the request body for accurate UI display.
|
|
312
|
+
// The path-based format (formatHandler.format) drives routing, but the body
|
|
313
|
+
// structure determines whether it's actually Anthropic or OpenAI.
|
|
314
|
+
const bodyFormat = formatRegistry.detectFormat(requestBody);
|
|
315
|
+
const displayApiFormat = bodyFormat !== "unknown" ? bodyFormat : formatHandler.format;
|
|
316
|
+
|
|
311
317
|
const log = await createLog(
|
|
312
318
|
req.method,
|
|
313
319
|
parsed.apiPath,
|
|
@@ -316,7 +322,7 @@ export async function handleProxy(req: Request): Promise<Response> {
|
|
|
316
322
|
clientInfo,
|
|
317
323
|
rawHeaders,
|
|
318
324
|
upstreamHeadersObj,
|
|
319
|
-
|
|
325
|
+
displayApiFormat,
|
|
320
326
|
model,
|
|
321
327
|
sessionId,
|
|
322
328
|
preAcquiredId,
|
package/src/proxy/schemas.ts
CHANGED
|
@@ -111,9 +111,12 @@ function detectFormat(rawBody: string | null): RequestFormat {
|
|
|
111
111
|
try {
|
|
112
112
|
const json: unknown = JSON.parse(rawBody);
|
|
113
113
|
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
const hasModel = safeGetProperty(json, "model") !== undefined;
|
|
115
|
+
const hasMessages = safeGetProperty(json, "messages") !== undefined;
|
|
116
|
+
if (hasModel && hasMessages) {
|
|
117
|
+
// Anthropic requests put `system` as a top-level key; OpenAI does not.
|
|
118
|
+
// Both formats can have `tools`, so we check `system` as the discriminator.
|
|
119
|
+
if (safeGetProperty(json, "system") !== undefined) {
|
|
117
120
|
return "anthropic";
|
|
118
121
|
}
|
|
119
122
|
const msgVal = safeGetProperty(json, "messages");
|