@tonyclaw/agent-inspector 3.1.8 → 3.1.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/backend/nitro.json +1 -1
- package/.output/cli.js +14 -4
- package/.output/server/_ssr/index.mjs +1 -1
- package/.output/server/_ssr/{router-CHcOqlej.mjs → router-Lc1aOs3g.mjs} +270 -3
- package/.output/server/index.mjs +1 -1
- package/.output/ui/assets/{CompareDrawer-D6p2D3aR.js → CompareDrawer-YdfnAMiC.js} +1 -1
- package/.output/ui/assets/{InspectorPet-DteVBsK4.js → InspectorPet-Bt0vxGL8.js} +1 -1
- package/.output/ui/assets/ProxyViewerContainer-D4_GM20S.js +59 -0
- package/.output/ui/assets/{ReplayDialog-BxfD3Ni8.js → ReplayDialog-9BWotxhQ.js} +1 -1
- package/.output/ui/assets/{RequestAnatomy-Bc-HEy3u.js → RequestAnatomy-0VrsjZmK.js} +1 -1
- package/.output/ui/assets/ResponseView-mmW2Z9sl.js +2 -0
- package/.output/ui/assets/StreamingChunkSequence-ZC90PIBc.js +1 -0
- package/.output/ui/assets/{_sessionId-MXVCdKA6.js → _sessionId-C84un6eF.js} +1 -1
- package/.output/ui/assets/{_sessionId-Dm2fmwl6.js → _sessionId-CB7Eytuo.js} +1 -1
- package/.output/ui/assets/{index-r-7cZ1UL.js → index-2feCKPew.js} +2 -2
- package/.output/ui/assets/{index-aah_H3hN.js → index-7oLdSt17.js} +1 -1
- package/.output/ui/assets/{index-BuF4rMwu.js → index-BswExFrv.js} +1 -1
- package/.output/ui/assets/index-IBEDJoV_.css +1 -0
- package/.output/ui/assets/{index-Dr_GO75d.js → index-YEgoJRUl.js} +1 -1
- package/.output/ui/assets/{json-viewer-Dikr00zS.js → json-viewer-CJ96a0P_.js} +1 -1
- package/.output/ui/assets/{jszip.min-zWpW-aD7.js → jszip.min-BDO1ePnu.js} +1 -1
- package/.output/ui/index.html +2 -2
- package/.output/workers/logFinalizer.worker.js +10 -0
- package/.output/workers/sessionWorkerEntry.js +10 -0
- package/package.json +4 -4
- package/src/components/proxy-viewer/AnswerMarkdown.tsx +37 -7
- package/src/components/proxy-viewer/LogEntry.tsx +82 -32
- package/src/components/proxy-viewer/ResponseView.tsx +33 -3
- package/src/components/proxy-viewer/StreamingChunkSequence.tsx +60 -3
- package/src/components/proxy-viewer/viewerState.ts +11 -169
- package/src/contracts/index.ts +2 -0
- package/src/contracts/log.ts +13 -0
- package/src/lib/toolTrace.ts +290 -0
- package/src/proxy/logIndex.ts +4 -0
- package/src/proxy/schemas.ts +2 -0
- package/src/proxy/sqliteLogIndex.ts +24 -2
- package/src/proxy/store.ts +3 -0
- package/.output/ui/assets/ProxyViewerContainer-Dw723CdA.js +0 -59
- package/.output/ui/assets/ResponseView-Be5xdsIm.js +0 -2
- package/.output/ui/assets/StreamingChunkSequence-Cd5G2xRQ.js +0 -1
- package/.output/ui/assets/index-BvXp42al.css +0 -1
package/.output/cli.js
CHANGED
|
@@ -20,7 +20,7 @@ var init_package = __esm({
|
|
|
20
20
|
"package.json"() {
|
|
21
21
|
package_default = {
|
|
22
22
|
name: "@tonyclaw/agent-inspector",
|
|
23
|
-
version: "3.1.
|
|
23
|
+
version: "3.1.9",
|
|
24
24
|
type: "module",
|
|
25
25
|
description: "Agent observability and knowledge capture layer for AI coding tools.",
|
|
26
26
|
license: "MIT",
|
|
@@ -166,9 +166,9 @@ var init_package = __esm({
|
|
|
166
166
|
zod: "^4.4.3"
|
|
167
167
|
},
|
|
168
168
|
optionalDependencies: {
|
|
169
|
-
"@tonyclaw/agent-inspector-backend-darwin-arm64": "3.1.
|
|
170
|
-
"@tonyclaw/agent-inspector-backend-linux-x64-gnu": "3.1.
|
|
171
|
-
"@tonyclaw/agent-inspector-backend-win32-x64-msvc": "3.1.
|
|
169
|
+
"@tonyclaw/agent-inspector-backend-darwin-arm64": "3.1.9",
|
|
170
|
+
"@tonyclaw/agent-inspector-backend-linux-x64-gnu": "3.1.9",
|
|
171
|
+
"@tonyclaw/agent-inspector-backend-win32-x64-msvc": "3.1.9",
|
|
172
172
|
"better-sqlite3": "^12.11.1",
|
|
173
173
|
rcedit: "4.0.1"
|
|
174
174
|
},
|
|
@@ -22122,6 +22122,15 @@ var StreamingChunkSchema = external_exports.object({
|
|
|
22122
22122
|
type: external_exports.string(),
|
|
22123
22123
|
data: JsonValueSchema
|
|
22124
22124
|
});
|
|
22125
|
+
var ToolTraceEventSchema = external_exports.object({
|
|
22126
|
+
id: external_exports.string(),
|
|
22127
|
+
logId: LogIdSchema,
|
|
22128
|
+
index: external_exports.number().int().nonnegative(),
|
|
22129
|
+
provider: external_exports.enum(["anthropic", "openai"]),
|
|
22130
|
+
name: external_exports.string(),
|
|
22131
|
+
argumentsText: external_exports.string().nullable(),
|
|
22132
|
+
argumentsPreview: external_exports.string().nullable()
|
|
22133
|
+
});
|
|
22125
22134
|
var StreamingChunksArraySchema = external_exports.object({
|
|
22126
22135
|
chunks: external_exports.array(StreamingChunkSchema),
|
|
22127
22136
|
truncated: external_exports.boolean().optional().default(false)
|
|
@@ -22181,6 +22190,7 @@ var CapturedLogSchema = external_exports.object({
|
|
|
22181
22190
|
droppedBytes: external_exports.number().int().nonnegative().optional(),
|
|
22182
22191
|
captureIncompleteReason: CaptureIncompleteReasonSchema.nullable().optional(),
|
|
22183
22192
|
warnings: external_exports.array(external_exports.string()).optional(),
|
|
22193
|
+
toolTraceEvents: external_exports.array(ToolTraceEventSchema).optional(),
|
|
22184
22194
|
/** Error message from streaming response (e.g., SSE error event) */
|
|
22185
22195
|
error: external_exports.string().nullable().optional()
|
|
22186
22196
|
});
|
|
@@ -1162,7 +1162,7 @@ var getBaseManifest = getProdBaseManifest;
|
|
|
1162
1162
|
var createEarlyHintsForRequest = createEarlyHintsCollector;
|
|
1163
1163
|
async function loadEntries() {
|
|
1164
1164
|
const [routerEntry, startEntry, pluginAdapters] = await Promise.all([
|
|
1165
|
-
import("./router-
|
|
1165
|
+
import("./router-Lc1aOs3g.mjs"),
|
|
1166
1166
|
import("./start-COQu_AgD.mjs"),
|
|
1167
1167
|
import("./empty-plugin-adapters-BFgPZ6_d.mjs")
|
|
1168
1168
|
]);
|
|
@@ -440,6 +440,15 @@ const StreamingChunkSchema$1 = object({
|
|
|
440
440
|
type: string(),
|
|
441
441
|
data: JsonValueSchema
|
|
442
442
|
});
|
|
443
|
+
const ToolTraceEventSchema = object({
|
|
444
|
+
id: string(),
|
|
445
|
+
logId: LogIdSchema,
|
|
446
|
+
index: number().int().nonnegative(),
|
|
447
|
+
provider: _enum(["anthropic", "openai"]),
|
|
448
|
+
name: string(),
|
|
449
|
+
argumentsText: string().nullable(),
|
|
450
|
+
argumentsPreview: string().nullable()
|
|
451
|
+
});
|
|
443
452
|
const StreamingChunksArraySchema = object({
|
|
444
453
|
chunks: array(StreamingChunkSchema$1),
|
|
445
454
|
truncated: boolean().optional().default(false)
|
|
@@ -499,6 +508,7 @@ const CapturedLogSchema = object({
|
|
|
499
508
|
droppedBytes: number().int().nonnegative().optional(),
|
|
500
509
|
captureIncompleteReason: CaptureIncompleteReasonSchema.nullable().optional(),
|
|
501
510
|
warnings: array(string()).optional(),
|
|
511
|
+
toolTraceEvents: array(ToolTraceEventSchema).optional(),
|
|
502
512
|
/** Error message from streaming response (e.g., SSE error event) */
|
|
503
513
|
error: string().nullable().optional()
|
|
504
514
|
});
|
|
@@ -2911,6 +2921,252 @@ function textByteLength(value) {
|
|
|
2911
2921
|
if (value === null) return null;
|
|
2912
2922
|
return new TextEncoder().encode(value).byteLength;
|
|
2913
2923
|
}
|
|
2924
|
+
const PREVIEW_LIMIT = 180;
|
|
2925
|
+
function resolveLogFormat(log) {
|
|
2926
|
+
const pathFormat = apiFormatForPath(log.path);
|
|
2927
|
+
return pathFormat === "unknown" ? log.apiFormat : pathFormat;
|
|
2928
|
+
}
|
|
2929
|
+
function responseMayContainToolTrace(log, format) {
|
|
2930
|
+
const responseText = log.responseText;
|
|
2931
|
+
if (responseText === null) return false;
|
|
2932
|
+
switch (format) {
|
|
2933
|
+
case "anthropic":
|
|
2934
|
+
return responseText.includes("tool_use");
|
|
2935
|
+
case "openai":
|
|
2936
|
+
return responseText.includes("tool_calls") || responseText.includes("function_call");
|
|
2937
|
+
case "unknown":
|
|
2938
|
+
return false;
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
function parseJsonResponse(responseText) {
|
|
2942
|
+
if (responseText === null) return null;
|
|
2943
|
+
try {
|
|
2944
|
+
const parsed = JSON.parse(responseText);
|
|
2945
|
+
if (typeof parsed === "string") {
|
|
2946
|
+
return JSON.parse(parsed);
|
|
2947
|
+
}
|
|
2948
|
+
return parsed;
|
|
2949
|
+
} catch {
|
|
2950
|
+
return null;
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
function previewValue(value) {
|
|
2954
|
+
if (value === void 0 || value === null) return null;
|
|
2955
|
+
const raw = typeof value === "string" ? value : JSON.stringify(value);
|
|
2956
|
+
if (raw === void 0) return null;
|
|
2957
|
+
const normalized = raw.replace(/\s+/g, " ").trim();
|
|
2958
|
+
if (normalized.length === 0) return null;
|
|
2959
|
+
return normalized.length > PREVIEW_LIMIT ? `${normalized.slice(0, PREVIEW_LIMIT - 1)}...` : normalized;
|
|
2960
|
+
}
|
|
2961
|
+
function copyValue(value) {
|
|
2962
|
+
if (value === void 0 || value === null) return null;
|
|
2963
|
+
if (typeof value === "string") return value.length > 0 ? value : null;
|
|
2964
|
+
const raw = JSON.stringify(value, null, 2);
|
|
2965
|
+
return raw === void 0 || raw.length === 0 ? null : raw;
|
|
2966
|
+
}
|
|
2967
|
+
function makeEvent({
|
|
2968
|
+
log,
|
|
2969
|
+
provider,
|
|
2970
|
+
index,
|
|
2971
|
+
name: name2,
|
|
2972
|
+
input
|
|
2973
|
+
}) {
|
|
2974
|
+
return {
|
|
2975
|
+
id: `${String(log.id)}-${provider}-tool-${String(index)}`,
|
|
2976
|
+
logId: log.id,
|
|
2977
|
+
index,
|
|
2978
|
+
provider,
|
|
2979
|
+
name: name2,
|
|
2980
|
+
argumentsText: copyValue(input),
|
|
2981
|
+
argumentsPreview: previewValue(input)
|
|
2982
|
+
};
|
|
2983
|
+
}
|
|
2984
|
+
function extractAnthropicResponseToolTraceEvents(log) {
|
|
2985
|
+
const parsed = parseJsonResponse(log.responseText);
|
|
2986
|
+
const content = safeGetOwnProperty(parsed, "content");
|
|
2987
|
+
if (!Array.isArray(content)) return [];
|
|
2988
|
+
const events = [];
|
|
2989
|
+
for (const block of content) {
|
|
2990
|
+
const type = safeGetOwnProperty(block, "type");
|
|
2991
|
+
if (type !== "tool_use") continue;
|
|
2992
|
+
const name2 = safeGetOwnProperty(block, "name");
|
|
2993
|
+
if (typeof name2 !== "string" || name2.length === 0) continue;
|
|
2994
|
+
const input = safeGetOwnProperty(block, "input");
|
|
2995
|
+
events.push(makeEvent({ log, provider: "anthropic", index: events.length, name: name2, input }));
|
|
2996
|
+
}
|
|
2997
|
+
return events;
|
|
2998
|
+
}
|
|
2999
|
+
function extractOpenAIResponseToolTraceEvents(log) {
|
|
3000
|
+
const parsed = parseJsonResponse(log.responseText);
|
|
3001
|
+
const choices = safeGetOwnProperty(parsed, "choices");
|
|
3002
|
+
const events = [];
|
|
3003
|
+
if (Array.isArray(choices)) {
|
|
3004
|
+
for (const choice of choices) {
|
|
3005
|
+
const message = safeGetOwnProperty(choice, "message");
|
|
3006
|
+
const toolCalls = safeGetOwnProperty(message, "tool_calls");
|
|
3007
|
+
if (Array.isArray(toolCalls)) {
|
|
3008
|
+
for (const call of toolCalls) {
|
|
3009
|
+
const fn = safeGetOwnProperty(call, "function");
|
|
3010
|
+
const name2 = safeGetOwnProperty(fn, "name");
|
|
3011
|
+
if (typeof name2 !== "string" || name2.length === 0) continue;
|
|
3012
|
+
const args = safeGetOwnProperty(fn, "arguments");
|
|
3013
|
+
events.push(
|
|
3014
|
+
makeEvent({ log, provider: "openai", index: events.length, name: name2, input: args })
|
|
3015
|
+
);
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
const functionCall = safeGetOwnProperty(message, "function_call");
|
|
3019
|
+
const functionCallName = safeGetOwnProperty(functionCall, "name");
|
|
3020
|
+
if (typeof functionCallName === "string" && functionCallName.length > 0) {
|
|
3021
|
+
const args = safeGetOwnProperty(functionCall, "arguments");
|
|
3022
|
+
events.push(
|
|
3023
|
+
makeEvent({
|
|
3024
|
+
log,
|
|
3025
|
+
provider: "openai",
|
|
3026
|
+
index: events.length,
|
|
3027
|
+
name: functionCallName,
|
|
3028
|
+
input: args
|
|
3029
|
+
})
|
|
3030
|
+
);
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
const output = safeGetOwnProperty(parsed, "output");
|
|
3035
|
+
if (Array.isArray(output)) {
|
|
3036
|
+
for (const item of output) {
|
|
3037
|
+
if (safeGetOwnProperty(item, "type") !== "function_call") continue;
|
|
3038
|
+
const name2 = safeGetOwnProperty(item, "name");
|
|
3039
|
+
if (typeof name2 !== "string" || name2.length === 0) continue;
|
|
3040
|
+
const args = safeGetOwnProperty(item, "arguments");
|
|
3041
|
+
events.push(makeEvent({ log, provider: "openai", index: events.length, name: name2, input: args }));
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
3044
|
+
return events;
|
|
3045
|
+
}
|
|
3046
|
+
function chunkData(chunk) {
|
|
3047
|
+
if (typeof chunk.data === "string") {
|
|
3048
|
+
try {
|
|
3049
|
+
return JSON.parse(chunk.data);
|
|
3050
|
+
} catch {
|
|
3051
|
+
return chunk.data;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
return chunk.data;
|
|
3055
|
+
}
|
|
3056
|
+
function appendUniqueEvent(events, seen, event) {
|
|
3057
|
+
const key = `${event.provider}:${event.name}:${event.index}`;
|
|
3058
|
+
if (seen.has(key)) return;
|
|
3059
|
+
seen.add(key);
|
|
3060
|
+
events.push(event);
|
|
3061
|
+
}
|
|
3062
|
+
function extractAnthropicChunkToolTraceEvents(log) {
|
|
3063
|
+
const chunks = log.streamingChunks?.chunks ?? [];
|
|
3064
|
+
const events = [];
|
|
3065
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3066
|
+
for (const chunk of chunks) {
|
|
3067
|
+
const data = chunkData(chunk);
|
|
3068
|
+
const contentBlock = safeGetOwnProperty(data, "content_block");
|
|
3069
|
+
if (safeGetOwnProperty(contentBlock, "type") !== "tool_use") continue;
|
|
3070
|
+
const name2 = safeGetOwnProperty(contentBlock, "name");
|
|
3071
|
+
if (typeof name2 !== "string" || name2.length === 0) continue;
|
|
3072
|
+
const input = safeGetOwnProperty(contentBlock, "input");
|
|
3073
|
+
appendUniqueEvent(
|
|
3074
|
+
events,
|
|
3075
|
+
seen,
|
|
3076
|
+
makeEvent({ log, provider: "anthropic", index: chunk.index, name: name2, input })
|
|
3077
|
+
);
|
|
3078
|
+
}
|
|
3079
|
+
return events.map((event, index) => ({
|
|
3080
|
+
...event,
|
|
3081
|
+
id: `${String(log.id)}-anthropic-tool-${String(index)}`,
|
|
3082
|
+
index
|
|
3083
|
+
}));
|
|
3084
|
+
}
|
|
3085
|
+
function extractOpenAIChunkToolTraceEvents(log) {
|
|
3086
|
+
const chunks = log.streamingChunks?.chunks ?? [];
|
|
3087
|
+
const events = [];
|
|
3088
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3089
|
+
for (const chunk of chunks) {
|
|
3090
|
+
const data = chunkData(chunk);
|
|
3091
|
+
const choices = safeGetOwnProperty(data, "choices");
|
|
3092
|
+
if (Array.isArray(choices)) {
|
|
3093
|
+
for (const choice of choices) {
|
|
3094
|
+
const delta = safeGetOwnProperty(choice, "delta");
|
|
3095
|
+
const toolCalls = safeGetOwnProperty(delta, "tool_calls");
|
|
3096
|
+
if (Array.isArray(toolCalls)) {
|
|
3097
|
+
for (const call of toolCalls) {
|
|
3098
|
+
const fn = safeGetOwnProperty(call, "function");
|
|
3099
|
+
const name2 = safeGetOwnProperty(fn, "name");
|
|
3100
|
+
if (typeof name2 !== "string" || name2.length === 0) continue;
|
|
3101
|
+
const args = safeGetOwnProperty(fn, "arguments");
|
|
3102
|
+
appendUniqueEvent(
|
|
3103
|
+
events,
|
|
3104
|
+
seen,
|
|
3105
|
+
makeEvent({ log, provider: "openai", index: events.length, name: name2, input: args })
|
|
3106
|
+
);
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
const functionCall = safeGetOwnProperty(delta, "function_call");
|
|
3110
|
+
const functionCallName = safeGetOwnProperty(functionCall, "name");
|
|
3111
|
+
if (typeof functionCallName === "string" && functionCallName.length > 0) {
|
|
3112
|
+
const args = safeGetOwnProperty(functionCall, "arguments");
|
|
3113
|
+
appendUniqueEvent(
|
|
3114
|
+
events,
|
|
3115
|
+
seen,
|
|
3116
|
+
makeEvent({
|
|
3117
|
+
log,
|
|
3118
|
+
provider: "openai",
|
|
3119
|
+
index: events.length,
|
|
3120
|
+
name: functionCallName,
|
|
3121
|
+
input: args
|
|
3122
|
+
})
|
|
3123
|
+
);
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
const item = safeGetOwnProperty(data, "item");
|
|
3128
|
+
if (safeGetOwnProperty(item, "type") === "function_call") {
|
|
3129
|
+
const name2 = safeGetOwnProperty(item, "name");
|
|
3130
|
+
if (typeof name2 === "string" && name2.length > 0) {
|
|
3131
|
+
const args = safeGetOwnProperty(item, "arguments");
|
|
3132
|
+
appendUniqueEvent(
|
|
3133
|
+
events,
|
|
3134
|
+
seen,
|
|
3135
|
+
makeEvent({ log, provider: "openai", index: events.length, name: name2, input: args })
|
|
3136
|
+
);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
return events.map((event, index) => ({
|
|
3141
|
+
...event,
|
|
3142
|
+
id: `${String(log.id)}-openai-tool-${String(index)}`,
|
|
3143
|
+
index
|
|
3144
|
+
}));
|
|
3145
|
+
}
|
|
3146
|
+
function extractToolTraceEvents(log) {
|
|
3147
|
+
if (log.toolTraceEvents !== void 0 && log.toolTraceEvents.length > 0) {
|
|
3148
|
+
return log.toolTraceEvents;
|
|
3149
|
+
}
|
|
3150
|
+
const format = resolveLogFormat(log);
|
|
3151
|
+
if (responseMayContainToolTrace(log, format)) {
|
|
3152
|
+
switch (format) {
|
|
3153
|
+
case "anthropic":
|
|
3154
|
+
return extractAnthropicResponseToolTraceEvents(log);
|
|
3155
|
+
case "openai":
|
|
3156
|
+
return extractOpenAIResponseToolTraceEvents(log);
|
|
3157
|
+
case "unknown":
|
|
3158
|
+
return [];
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
switch (format) {
|
|
3162
|
+
case "anthropic":
|
|
3163
|
+
return extractAnthropicChunkToolTraceEvents(log);
|
|
3164
|
+
case "openai":
|
|
3165
|
+
return extractOpenAIChunkToolTraceEvents(log);
|
|
3166
|
+
case "unknown":
|
|
3167
|
+
return [];
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
2914
3170
|
const SQLITE_INDEX_FILE = "inspector.sqlite";
|
|
2915
3171
|
const SQLITE_PACKAGE_NAME$1 = "better-sqlite3";
|
|
2916
3172
|
const BUN_SQLITE_MODULE_NAME$1 = "bun:sqlite";
|
|
@@ -2953,6 +3209,7 @@ CREATE TABLE IF NOT EXISTS log_index (
|
|
|
2953
3209
|
dropped_bytes INTEGER NOT NULL DEFAULT 0,
|
|
2954
3210
|
capture_incomplete_reason TEXT,
|
|
2955
3211
|
warnings_json TEXT,
|
|
3212
|
+
tool_trace_events_json TEXT,
|
|
2956
3213
|
error TEXT
|
|
2957
3214
|
);
|
|
2958
3215
|
CREATE INDEX IF NOT EXISTS idx_log_index_session_id_id ON log_index(session_id, id);
|
|
@@ -2998,9 +3255,10 @@ INSERT INTO log_index (
|
|
|
2998
3255
|
dropped_bytes,
|
|
2999
3256
|
capture_incomplete_reason,
|
|
3000
3257
|
warnings_json,
|
|
3258
|
+
tool_trace_events_json,
|
|
3001
3259
|
error
|
|
3002
3260
|
) VALUES (
|
|
3003
|
-
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
3261
|
+
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
3004
3262
|
)
|
|
3005
3263
|
ON CONFLICT(id) DO UPDATE SET
|
|
3006
3264
|
file = excluded.file,
|
|
@@ -3039,6 +3297,7 @@ ON CONFLICT(id) DO UPDATE SET
|
|
|
3039
3297
|
dropped_bytes = excluded.dropped_bytes,
|
|
3040
3298
|
capture_incomplete_reason = excluded.capture_incomplete_reason,
|
|
3041
3299
|
warnings_json = excluded.warnings_json,
|
|
3300
|
+
tool_trace_events_json = excluded.tool_trace_events_json,
|
|
3042
3301
|
error = excluded.error
|
|
3043
3302
|
`;
|
|
3044
3303
|
let sqliteStatePromise = null;
|
|
@@ -3118,7 +3377,8 @@ const REQUIRED_SCHEMA_COLUMNS = [
|
|
|
3118
3377
|
{ name: "capture_incomplete", definition: "INTEGER NOT NULL DEFAULT 0" },
|
|
3119
3378
|
{ name: "dropped_chunks", definition: "INTEGER NOT NULL DEFAULT 0" },
|
|
3120
3379
|
{ name: "dropped_bytes", definition: "INTEGER NOT NULL DEFAULT 0" },
|
|
3121
|
-
{ name: "capture_incomplete_reason", definition: "TEXT" }
|
|
3380
|
+
{ name: "capture_incomplete_reason", definition: "TEXT" },
|
|
3381
|
+
{ name: "tool_trace_events_json", definition: "TEXT" }
|
|
3122
3382
|
];
|
|
3123
3383
|
function ensureSchemaColumns(db) {
|
|
3124
3384
|
const rows = allPrepared$1(db, "PRAGMA table_info(log_index)");
|
|
@@ -3253,6 +3513,9 @@ function closeSqliteLogIndex() {
|
|
|
3253
3513
|
function warningJson(warnings) {
|
|
3254
3514
|
return warnings === void 0 ? null : JSON.stringify(warnings);
|
|
3255
3515
|
}
|
|
3516
|
+
function toolTraceEventsJson(summary) {
|
|
3517
|
+
return summary?.toolTraceEvents === void 0 ? null : JSON.stringify(summary.toolTraceEvents);
|
|
3518
|
+
}
|
|
3256
3519
|
function boolToInt(value) {
|
|
3257
3520
|
return value ? 1 : 0;
|
|
3258
3521
|
}
|
|
@@ -3296,6 +3559,7 @@ function entryParams(entry) {
|
|
|
3296
3559
|
summary?.droppedBytes ?? 0,
|
|
3297
3560
|
summary?.captureIncompleteReason ?? null,
|
|
3298
3561
|
warningJson(summary?.warnings),
|
|
3562
|
+
toolTraceEventsJson(summary),
|
|
3299
3563
|
summary?.error ?? null
|
|
3300
3564
|
];
|
|
3301
3565
|
}
|
|
@@ -3800,6 +4064,7 @@ function createLogIndexEntryMetadata(log) {
|
|
|
3800
4064
|
droppedBytes: log.droppedBytes ?? 0,
|
|
3801
4065
|
captureIncompleteReason: log.captureIncompleteReason ?? null,
|
|
3802
4066
|
warnings: log.warnings,
|
|
4067
|
+
toolTraceEvents: extractToolTraceEvents(log),
|
|
3803
4068
|
error: log.error ?? null
|
|
3804
4069
|
}
|
|
3805
4070
|
};
|
|
@@ -4768,6 +5033,7 @@ function compactLogForList(log) {
|
|
|
4768
5033
|
rawHeaders: void 0,
|
|
4769
5034
|
headers: void 0,
|
|
4770
5035
|
streamingChunks: void 0,
|
|
5036
|
+
toolTraceEvents: log.toolTraceEvents ?? extractToolTraceEvents(log),
|
|
4771
5037
|
rawRequestBodyBytes: log.rawRequestBodyBytes ?? textByteLength(log.rawRequestBody),
|
|
4772
5038
|
responseTextBytes: log.responseTextBytes ?? textByteLength(log.responseText),
|
|
4773
5039
|
bodyContentMode: "compact"
|
|
@@ -4812,6 +5078,7 @@ function compactLogFromIndexSummary(summary) {
|
|
|
4812
5078
|
droppedBytes: summary.droppedBytes,
|
|
4813
5079
|
captureIncompleteReason: summary.captureIncompleteReason,
|
|
4814
5080
|
warnings: summary.warnings,
|
|
5081
|
+
toolTraceEvents: summary.toolTraceEvents,
|
|
4815
5082
|
error: summary.error
|
|
4816
5083
|
});
|
|
4817
5084
|
}
|
|
@@ -13717,7 +13984,7 @@ const Route$K = createFileRoute("/api/models")({
|
|
|
13717
13984
|
}
|
|
13718
13985
|
});
|
|
13719
13986
|
const name = "@tonyclaw/agent-inspector";
|
|
13720
|
-
const version = "3.1.
|
|
13987
|
+
const version = "3.1.9";
|
|
13721
13988
|
const packageJson = {
|
|
13722
13989
|
name,
|
|
13723
13990
|
version
|
package/.output/server/index.mjs
CHANGED
|
@@ -20,7 +20,7 @@ const assets = {
|
|
|
20
20
|
"/assets/index-D4LX-sw-.js": {
|
|
21
21
|
"type": "text/javascript; charset=utf-8",
|
|
22
22
|
"etag": '"4ca46-80Birfu694YvXXxcAJa6ekM4QWE"',
|
|
23
|
-
"mtime": "2026-07-
|
|
23
|
+
"mtime": "2026-07-20T06:29:03.696Z",
|
|
24
24
|
"size": 313926,
|
|
25
25
|
"path": "../backend-public/assets/index-D4LX-sw-.js"
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as p,j as t,x as f,C as z,E as ne}from"./index-r-7cZ1UL.js";import{c as re,g as A,r as D,a as R,X as ae,B as oe,R as ie,C as de,M as V,b as J,d as B,e as F,f as le,h as ce,L as ue}from"./ProxyViewerContainer-Dw723CdA.js";const me=[["line",{x1:"5",x2:"19",y1:"9",y2:"9",key:"1nwqeh"}],["line",{x1:"5",x2:"19",y1:"15",y2:"15",key:"g8yjpy"}]],xe=re("equal",me),fe="";function y(e){if(e.length===0)return fe;let s="";for(let n=0;n<e.length;n++){const a=e[n];a!==void 0&&(typeof a=="number"?s+=`[${a}]`:n===0?s+=a:s+=`.${a}`)}return s}function pe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function $(e){if(typeof e=="string")try{return C(JSON.parse(e))}catch{return{kind:"primitive",value:e}}return C(e)}function C(e){if(e===null)return{kind:"primitive",value:null};if(typeof e=="string")return{kind:"primitive",value:e};if(typeof e=="number")return{kind:"primitive",value:e};if(typeof e=="boolean")return{kind:"primitive",value:e};if(Array.isArray(e))return{kind:"array",value:e.map(s=>C(s))};if(pe(e)){const s={};for(const n of Object.keys(e).sort())s[n]=C(e[n]);return{kind:"object",value:s}}return{kind:"primitive",value:null}}function he(e,s){const n=[];return S([],e,s,n),n}function S(e,s,n,a){const c=y(e);if(q(s,n)){a.push({kind:"equal",path:c,value:s});return}if(s.kind!==n.kind){a.push({kind:"changed",path:c,left:s,right:n});return}if(s.kind==="primitive"&&n.kind==="primitive"){a.push({kind:"changed",path:c,left:s,right:n});return}if(s.kind==="object"&&n.kind==="object"){const l=Object.keys(s.value),r=Object.keys(n.value),o=new Set(r);for(const d of l){const x=s.value[d];if(x!==void 0)if(!o.has(d))a.push({kind:"removed",path:y([...e,d]),value:x});else{const h=n.value[d];if(h===void 0)continue;S([...e,d],x,h,a)}}for(const d of r){if(l.includes(d))continue;const x=n.value[d];x!==void 0&&a.push({kind:"added",path:y([...e,d]),value:x})}return}if(s.kind==="array"&&n.kind==="array"){const l=Math.min(s.value.length,n.value.length);for(let r=0;r<l;r++){const o=s.value[r],d=n.value[r];o===void 0||d===void 0||S([...e,r],o,d,a)}for(let r=l;r<n.value.length;r++){const o=n.value[r];o!==void 0&&a.push({kind:"added",path:y([...e,r]),value:o})}for(let r=l;r<s.value.length;r++){const o=s.value[r];o!==void 0&&a.push({kind:"removed",path:y([...e,r]),value:o})}}}function q(e,s){if(e.kind!==s.kind)return!1;if(e.kind==="primitive"&&s.kind==="primitive")return e.value===s.value;if(e.kind==="array"&&s.kind==="array"){if(e.value.length!==s.value.length)return!1;for(let n=0;n<e.value.length;n++){const a=e.value[n],c=s.value[n];if(a===void 0||c===void 0||!q(a,c))return!1}return!0}if(e.kind==="object"&&s.kind==="object"){const n=Object.keys(e.value),a=Object.keys(s.value);if(n.length!==a.length)return!1;for(const c of n){const l=e.value[c],r=s.value[c];if(l===void 0||r===void 0||!q(l,r))return!1}return!0}return!1}function v(e,s=80){let n;switch(e.kind){case"primitive":n=e.value===null?"null":JSON.stringify(e.value);break;case"array":n=`[… ${e.value.length} items]`;break;case"object":n=`{… ${Object.keys(e.value).length} keys}`;break}return n.length>s&&(n=`${n.slice(0,s-1)}…`),n}const be="flex flex-col gap-3 border-b border-border px-3 py-3 sm:flex-row sm:items-start sm:gap-4 sm:px-4",ge="grid min-w-0 grid-cols-1 gap-x-2 gap-y-0.5 px-3 py-2 text-xs md:grid-cols-[200px_minmax(0,1fr)_minmax(0,1fr)]";function N(e,s=2){return JSON.stringify(T(e),null,s)}function T(e){switch(e.kind){case"primitive":return e.value;case"array":return e.value.map(T);case"object":{const s={};for(const[n,a]of Object.entries(e.value))s[n]=T(a);return s}}}function w({text:e,defaultExpandDepth:s}){return t.jsx(p.Suspense,{fallback:t.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:t.jsx(ue,{text:e,defaultExpandDepth:s})})}function _(e){if(e==="")return"";for(let s=e.length-1;s>=0;s--){const n=e[s];if(n==="."||n==="[")return e.substring(0,s)}return""}function K(e){return e.kind==="equal"&&(e.value.kind==="object"||e.value.kind==="array")}function ve(e){const s=[];let n=0;for(;n<e.length;){const a=e[n];if(a!==void 0&&K(a)){const c=_(a.path);let l=n+1;for(;l<e.length;){const r=e[l];if(r===void 0||!K(r)||_(r.path)!==c)break;l++}if(l-n>1){const r=[];for(let o=n;o<l;o++){const d=e[o];d!==void 0&&d.kind==="equal"&&r.push(d)}s.push({kind:"equal-run",ops:r}),n=l;continue}}a!==void 0&&s.push({kind:"single",op:a}),n++}return s}const H={added:{icon:J,accent:"text-status-success",bg:"bg-status-success/5 hover:bg-status-success/10",border:"border-l-status-success",label:"ADDED"},removed:{icon:V,accent:"text-status-danger",bg:"bg-status-danger/5 hover:bg-status-danger/10",border:"border-l-status-danger",label:"REMOVED"},changed:{icon:B,accent:"text-status-watch",bg:"bg-status-watch/5 hover:bg-status-watch/10",border:"border-l-status-watch",label:"CHANGED"},equal:{icon:xe,accent:"text-muted-foreground/70",bg:"bg-muted/20 hover:bg-muted/30",border:"border-l-muted-foreground/20",label:"EQUAL"}};function ke({ops:e,expanded:s,onToggle:n}){const a=e[0],c=e[e.length-1];if(a===void 0||c===void 0)return t.jsx("div",{className:"text-muted-foreground/40 text-xs",children:"—"});const l=a.path,r=c.path,o=e.length===1?l:`${l} … ${r}`,d=a.value.kind==="array"?`${e.length} equal arrays`:a.value.kind==="object"?`${e.length} equal objects`:"equal",x=H.equal;return t.jsxs("div",{className:f("border-l-4 rounded-sm",x.border,x.bg),children:[t.jsxs("button",{type:"button",onClick:n,className:"w-full text-left flex items-center gap-2 px-3 py-1.5 text-xs text-muted-foreground cursor-pointer",children:[t.jsx(F,{className:f("size-3 transition-transform shrink-0",s&&"rotate-90")}),t.jsx(x.icon,{className:f("size-3 shrink-0",x.accent)}),t.jsx("span",{className:"font-mono truncate flex-1",title:`${l} … ${r}`,children:o}),t.jsx("span",{className:f("text-[10px] uppercase tracking-wider shrink-0",x.accent),children:x.label}),t.jsxs("span",{className:"text-muted-foreground/60 shrink-0",children:["(",d,")"]})]}),s&&t.jsx("div",{className:"ml-5 mt-1 mb-2 space-y-2 pr-2",children:e.map(h=>t.jsxs("div",{className:"border border-border/50 rounded p-2 bg-muted/20",children:[t.jsx("div",{className:"font-mono text-xs text-muted-foreground mb-1",children:h.path}),t.jsx(w,{text:N(h.value),defaultExpandDepth:0})]},h.path))})]})}function je({op:e,idx:s,copiedPath:n,onCopyPath:a,expanded:c,onToggle:l}){const r=H[e.kind],o=r.icon,d=e.kind==="added"||e.kind==="removed"?e.value.kind==="object"||e.value.kind==="array":e.kind==="changed"?e.left.kind==="object"||e.left.kind==="array"||e.right.kind==="object"||e.right.kind==="array":!1,x=e.kind==="changed"?[{text:v(e.left,400),tone:"text-status-danger line-through"},{text:v(e.right,400),tone:"text-status-success"}]:e.kind==="removed"?[{text:v(e.value,400),tone:"text-status-danger line-through"}]:e.kind==="added"?[{text:v(e.value,400),tone:"text-status-success"}]:[{text:v(e.value,400),tone:"text-muted-foreground"}],h=n===e.path&&e.path!=="";return t.jsxs("div",{"data-diff-idx":s,"data-diff-kind":e.kind,className:f("border-l-4 rounded-sm px-3 py-2 my-0.5 transition-colors",r.border,r.bg),children:[t.jsxs("button",{type:"button",onClick:l,disabled:!d,className:f("w-full flex items-center gap-2 text-xs text-left rounded-sm",d?"cursor-pointer":"cursor-default"),"aria-expanded":d?c:void 0,"aria-label":d?c?`Collapse ${e.path||"root"}`:`Expand ${e.path||"root"}`:void 0,children:[d?t.jsx(F,{className:f("size-3 shrink-0 transition-transform",r.accent,c&&"rotate-90")}):t.jsx("span",{className:"size-3 shrink-0","aria-hidden":"true"}),t.jsx(o,{className:f("size-3.5 shrink-0",r.accent),strokeWidth:2.5}),t.jsx("span",{className:"font-mono truncate flex-1 min-w-0",title:e.path||"(root)",children:e.path===""?"(root)":e.path}),t.jsx("span",{className:f("text-[9px] font-bold uppercase tracking-wider shrink-0 px-1.5 py-0.5 rounded",r.accent,e.kind==="equal"?"bg-muted/40":"bg-background/60"),children:r.label}),e.path!==""&&t.jsx("span",{role:"button",tabIndex:0,onClick:b=>{b.stopPropagation(),a(e.path)},onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.stopPropagation(),b.preventDefault(),a(e.path))},className:f("shrink-0 p-1 rounded transition-colors cursor-pointer inline-flex items-center justify-center",h?"text-status-success":"text-muted-foreground/50 hover:text-foreground hover:bg-muted"),"aria-label":h?"Copied":"Copy",title:h?"Copied!":"Copy",children:h?t.jsx(le,{className:"size-3"}):t.jsx(ce,{className:"size-3"})})]}),x.map((b,E)=>t.jsx("div",{className:f("font-mono text-xs mt-1 break-all pl-5",b.tone),children:b.text},E)),t.jsx("div",{className:"overflow-hidden transition-all duration-200",style:{maxHeight:c&&d?"2000px":"0"},"aria-hidden":!c,children:c&&d&&e.kind!=="equal"?t.jsx(ye,{op:e}):null})]})}function ye({op:e}){if(e.kind==="added"||e.kind==="removed")return t.jsx("div",{className:"pl-5 mt-2 border border-border/50 rounded p-2 bg-muted/20",children:t.jsx(w,{text:N(e.value),defaultExpandDepth:0})});const s=e.left.kind==="object"||e.left.kind==="array",n=e.right.kind==="object"||e.right.kind==="array";return!s&&!n?t.jsx("div",{className:"pl-5 mt-2 text-xs text-muted-foreground/70 italic",children:"Primitive values are shown inline above."}):t.jsxs("div",{className:"pl-5 mt-2 grid grid-cols-1 md:grid-cols-2 gap-2",children:[t.jsxs("div",{className:"rounded border border-status-danger/30 bg-status-danger/5 p-2",children:[t.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-wider text-status-danger",children:"Old"}),t.jsx(w,{text:N(e.left),defaultExpandDepth:0})]}),t.jsxs("div",{className:"rounded border border-status-success/30 bg-status-success/5 p-2",children:[t.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-wider text-status-success",children:"New"}),t.jsx(w,{text:N(e.right),defaultExpandDepth:0})]})]})}function Ne({counts:e,onJumpTo:s}){const n=e.added+e.removed+e.changed;return t.jsxs("div",{className:"px-4 py-2 border-b border-border bg-muted/20 flex items-center gap-2 text-xs flex-wrap",children:[t.jsxs("span",{className:"text-muted-foreground font-medium",children:[n," ",n===1?"change":"changes"]}),t.jsxs("button",{type:"button",onClick:()=>s("removed"),disabled:e.removed===0,className:f("inline-flex items-center gap-1 px-2 py-0.5 rounded-full border cursor-pointer transition-colors",e.removed>0?"border-status-danger/40 bg-status-danger/10 text-status-danger hover:bg-status-danger/20":"border-border text-muted-foreground/40 cursor-not-allowed"),title:e.removed>0?"Jump to first removed":"No removals",children:[t.jsx(V,{className:"size-3"}),e.removed," removed"]}),t.jsxs("button",{type:"button",onClick:()=>s("added"),disabled:e.added===0,className:f("inline-flex items-center gap-1 px-2 py-0.5 rounded-full border cursor-pointer transition-colors",e.added>0?"border-status-success/40 bg-status-success/10 text-status-success hover:bg-status-success/20":"border-border text-muted-foreground/40 cursor-not-allowed"),title:e.added>0?"Jump to first added":"No additions",children:[t.jsx(J,{className:"size-3"}),e.added," added"]}),t.jsxs("button",{type:"button",onClick:()=>s("changed"),disabled:e.changed===0,className:f("inline-flex items-center gap-1 px-2 py-0.5 rounded-full border cursor-pointer transition-colors",e.changed>0?"border-status-watch/40 bg-status-watch/10 text-status-watch hover:bg-status-watch/20":"border-border text-muted-foreground/40 cursor-not-allowed"),title:e.changed>0?"Jump to first changed":"No changes",children:[t.jsx(B,{className:"size-3"}),e.changed," changed"]})]})}function we({mode:e,onChange:s}){return t.jsxs("div",{className:"inline-flex rounded-md border border-border overflow-hidden",children:[t.jsxs("button",{type:"button",onClick:()=>s("unified"),"aria-pressed":e==="unified",className:f("flex items-center gap-1 px-2 py-1 text-xs transition-colors cursor-pointer",e==="unified"?"bg-muted text-foreground":"hover:bg-muted/50 text-muted-foreground"),title:"Unified view (single column, emphasized diffs)",children:[t.jsx(ie,{className:"size-3"}),"Unified"]}),t.jsxs("button",{type:"button",onClick:()=>s("split"),"aria-pressed":e==="split",className:f("flex items-center gap-1 px-2 py-1 text-xs transition-colors border-l border-border cursor-pointer",e==="split"?"bg-muted text-foreground":"hover:bg-muted/50 text-muted-foreground"),title:"Split view (path | left | right)",children:[t.jsx(de,{className:"size-3"}),"Split"]})]})}function M({log:e,side:s,displayNumber:n}){const a=R(e);return t.jsxs("div",{className:"flex-1 min-w-0 space-y-1 text-xs",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(oe,{variant:"outline",className:f("text-[10px] px-1.5 py-0 h-5 font-mono shrink-0",s==="left"?"border-status-danger/40 text-status-danger":"border-status-success/40 text-status-success"),children:s==="left"?"← Left":"Right →"}),t.jsxs("span",{className:"font-mono text-status-info",title:`Log ID ${String(e.id)}`,children:["#",n]}),e.model!==null&&t.jsx("span",{className:"min-w-0 truncate font-mono leading-snug text-muted-foreground",children:e.model})]}),t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 font-mono text-muted-foreground",children:[e.cacheCreationInputTokens!==null&&e.cacheCreationInputTokens>0&&t.jsxs("span",{className:"text-status-success",children:["KV Cache +",z(e.cacheCreationInputTokens)]}),e.cacheReadInputTokens!==null&&e.cacheReadInputTokens>0&&t.jsxs("span",{className:"text-status-accent",children:["KV Cache ~",z(e.cacheReadInputTokens)]}),t.jsx("span",{className:"truncate",title:e.timestamp,children:e.timestamp})]}),t.jsxs("div",{className:"text-muted-foreground/70 font-mono truncate",title:a,children:["session: ",a]})]})}function Se({left:e,right:s,leftDisplayNumber:n,rightDisplayNumber:a,onClose:c}){const l=p.useRef(null),r=p.useRef(null),o=p.useRef(null),d=p.useMemo(()=>{const i=A(D(e)).analyzeRequest(e.rawRequestBody),u=A(D(s)).analyzeRequest(s.rawRequestBody),m=$(i.comparisonValue),g=$(u.comparisonValue);return he(m,g)},[e.apiFormat,e.path,e.rawRequestBody,s.apiFormat,s.path,s.rawRequestBody]),x=p.useMemo(()=>ve(d),[d]),h=p.useMemo(()=>{let i=0,u=0,m=0;for(const g of x)if(g.kind==="single")switch(g.op.kind){case"added":i++;break;case"removed":u++;break;case"changed":m++;break}return{added:i,removed:u,changed:m}},[x]),[b,E]=p.useState(new Set),U=i=>{E(u=>{const m=new Set(u);return m.has(i)?m.delete(i):m.add(i),m})},[G,I]=p.useState(new Set),Q=i=>{I(u=>{const m=new Set(u);return m.has(i)?m.delete(i):m.add(i),m})};p.useEffect(()=>{I(new Set)},[e.id,s.id]);const[O,W]=p.useState("unified"),P=p.useRef(null),[X,L]=p.useState(null),j=p.useRef(null),Y=i=>{ne(i).then(u=>{u&&(L(i),j.current!==null&&clearTimeout(j.current),j.current=setTimeout(()=>L(null),1500))})};p.useEffect(()=>()=>{j.current!==null&&clearTimeout(j.current)},[]);const Z=i=>{const u=x.findIndex(k=>k.kind==="single"&&k.op.kind===i);if(u===-1)return;const m=P.current;if(m===null)return;const g=m.querySelector(`[data-diff-idx="${u}"]`);g!==null&&g.scrollIntoView({behavior:"smooth",block:"center"})};p.useEffect(()=>{o.current=document.activeElement instanceof HTMLElement?document.activeElement:null,r.current?.focus();const i=m=>{m.key==="Escape"&&c()};document.addEventListener("keydown",i);const u=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",i),document.body.style.overflow=u,o.current?.focus()}},[c]);const ee=i=>{if(i.stopPropagation(),i.key!=="Tab")return;const u=l.current;if(u===null)return;const m=Array.from(u.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), [tabindex]:not([tabindex="-1"])')),g=m[0],k=m[m.length-1];if(!(g===void 0||k===void 0)){if(i.shiftKey&&document.activeElement===g){i.preventDefault(),k.focus();return}!i.shiftKey&&document.activeElement===k&&(i.preventDefault(),g.focus())}},te=R(e)===R(s),se=d.length===1&&d[0]?.kind==="equal";return t.jsxs("div",{className:"fixed inset-0 z-50 flex justify-end",role:"dialog","aria-modal":"true","aria-label":"Compare two log requests",children:[t.jsx("button",{type:"button",onClick:c,"aria-label":"Close compare drawer",className:"absolute inset-0 bg-black/40 cursor-default",tabIndex:-1}),t.jsxs("div",{ref:l,className:f("relative overflow-x-hidden bg-background border-l border-border shadow-xl","w-full md:w-[70vw] max-w-[1100px] flex flex-col h-full"),onClick:i=>i.stopPropagation(),onKeyDown:ee,children:[t.jsxs("div",{className:be,children:[t.jsxs("div",{className:"grid min-w-0 flex-1 grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4",children:[t.jsx(M,{log:e,side:"left",displayNumber:n}),t.jsx(M,{log:s,side:"right",displayNumber:a})]}),t.jsxs("div",{className:"flex w-full shrink-0 items-center justify-between gap-2 sm:w-auto sm:justify-start",children:[t.jsx(we,{mode:O,onChange:W}),t.jsx("button",{ref:r,type:"button",onClick:c,"aria-label":"Close",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted cursor-pointer",children:t.jsx(ae,{className:"size-4"})})]})]}),!te&&t.jsx("div",{className:"border-b border-border bg-warning/10 px-4 py-1.5 text-xs text-foreground",children:"Heads up: the two selected logs are from different sessions."}),se?t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto flex items-center justify-center text-muted-foreground text-sm",children:"The two Request payloads are identical."}):t.jsxs(t.Fragment,{children:[t.jsx(Ne,{counts:h,onJumpTo:Z}),t.jsx("div",{ref:P,className:"flex-1 min-h-0 overflow-y-auto",children:O==="unified"?t.jsx("div",{className:"px-3 py-2 space-y-0.5",children:x.map((i,u)=>{if(i.kind==="equal-run")return t.jsx(ke,{ops:i.ops,expanded:b.has(u),onToggle:()=>U(u)},`r${u}`);const m=i.op;return t.jsx(je,{op:m,idx:u,copiedPath:X,onCopyPath:Y,expanded:G.has(u),onToggle:()=>Q(u)},`o${u}`)})}):t.jsx(Ce,{grouped:x,left:e,right:s,leftDisplayNumber:n,rightDisplayNumber:a})})]})]})]})}function Ce({grouped:e,left:s,right:n,leftDisplayNumber:a,rightDisplayNumber:c}){return t.jsxs("div",{"data-compare-layout":"responsive-split",className:ge,children:[t.jsxs("div",{className:"col-span-1 mb-2 grid grid-cols-1 gap-x-2 gap-y-1 border-b border-border pb-2 text-[10px] uppercase tracking-wider text-muted-foreground md:col-span-3 md:grid-cols-[200px_minmax(0,1fr)_minmax(0,1fr)]",children:[t.jsx("span",{children:"Path"}),t.jsxs("span",{title:`Log ID ${String(s.id)}`,children:["Left (Log #",a,")"]}),t.jsxs("span",{title:`Log ID ${String(n.id)}`,children:["Right (Log #",c,")"]})]}),e.map((l,r)=>{if(l.kind==="equal-run")return t.jsxs("div",{className:"col-span-1 px-2 py-1 text-xs text-muted-foreground/60 md:col-span-3",children:[l.ops.length," equal siblings collapsed — switch to Unified to expand"]},r);const o=l.op;return o.kind==="equal"?t.jsxs("div",{className:"col-span-1 grid min-w-0 grid-cols-1 gap-x-2 gap-y-1 px-2 py-0.5 text-muted-foreground md:col-span-3 md:grid-cols-[200px_minmax(0,1fr)_minmax(0,1fr)]",children:[t.jsx("span",{className:"font-mono text-xs truncate",title:o.path,children:o.path}),t.jsx("span",{className:"font-mono text-xs break-all opacity-60",children:v(o.value,200)}),t.jsx("span",{className:"font-mono text-xs break-all opacity-60",children:v(o.value,200)})]},r):o.kind==="added"?t.jsxs("div",{className:"col-span-1 rounded border-l-2 border-l-status-success bg-status-success/5 px-2 py-1 text-xs md:col-span-3",children:[t.jsx("div",{className:"font-mono text-xs text-muted-foreground mb-0.5",children:o.path}),t.jsxs("div",{className:"font-mono break-all text-status-success",children:["+ ",v(o.value,400)]})]},r):o.kind==="removed"?t.jsxs("div",{className:"col-span-1 rounded border-l-2 border-l-status-danger bg-status-danger/5 px-2 py-1 text-xs md:col-span-3",children:[t.jsx("div",{className:"font-mono text-xs text-muted-foreground mb-0.5",children:o.path}),t.jsxs("div",{className:"font-mono break-all text-status-danger line-through",children:["− ",v(o.value,400)]})]},r):t.jsxs("div",{className:"col-span-1 rounded border-l-2 border-l-status-watch bg-status-watch/5 px-2 py-1 text-xs md:col-span-3",children:[t.jsx("div",{className:"font-mono text-xs text-muted-foreground mb-1",children:o.path}),t.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[t.jsx("div",{className:"font-mono break-all text-status-danger line-through",children:v(o.left,400)}),t.jsx("div",{className:"font-mono break-all text-status-success",children:v(o.right,400)})]})]},r)})]})}export{be as COMPARE_RESPONSIVE_HEADER_CLASS_NAME,ge as COMPARE_RESPONSIVE_SPLIT_CLASS_NAME,Se as CompareDrawer};
|
|
1
|
+
import{r as p,j as t,x as f,C as z,E as ne}from"./index-2feCKPew.js";import{c as re,g as A,r as D,a as R,X as ae,B as oe,R as ie,C as de,M as V,b as J,d as B,e as F,f as le,h as ce,L as ue}from"./ProxyViewerContainer-D4_GM20S.js";const me=[["line",{x1:"5",x2:"19",y1:"9",y2:"9",key:"1nwqeh"}],["line",{x1:"5",x2:"19",y1:"15",y2:"15",key:"g8yjpy"}]],xe=re("equal",me),fe="";function y(e){if(e.length===0)return fe;let s="";for(let n=0;n<e.length;n++){const a=e[n];a!==void 0&&(typeof a=="number"?s+=`[${a}]`:n===0?s+=a:s+=`.${a}`)}return s}function pe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function $(e){if(typeof e=="string")try{return C(JSON.parse(e))}catch{return{kind:"primitive",value:e}}return C(e)}function C(e){if(e===null)return{kind:"primitive",value:null};if(typeof e=="string")return{kind:"primitive",value:e};if(typeof e=="number")return{kind:"primitive",value:e};if(typeof e=="boolean")return{kind:"primitive",value:e};if(Array.isArray(e))return{kind:"array",value:e.map(s=>C(s))};if(pe(e)){const s={};for(const n of Object.keys(e).sort())s[n]=C(e[n]);return{kind:"object",value:s}}return{kind:"primitive",value:null}}function he(e,s){const n=[];return S([],e,s,n),n}function S(e,s,n,a){const c=y(e);if(q(s,n)){a.push({kind:"equal",path:c,value:s});return}if(s.kind!==n.kind){a.push({kind:"changed",path:c,left:s,right:n});return}if(s.kind==="primitive"&&n.kind==="primitive"){a.push({kind:"changed",path:c,left:s,right:n});return}if(s.kind==="object"&&n.kind==="object"){const l=Object.keys(s.value),r=Object.keys(n.value),o=new Set(r);for(const d of l){const x=s.value[d];if(x!==void 0)if(!o.has(d))a.push({kind:"removed",path:y([...e,d]),value:x});else{const h=n.value[d];if(h===void 0)continue;S([...e,d],x,h,a)}}for(const d of r){if(l.includes(d))continue;const x=n.value[d];x!==void 0&&a.push({kind:"added",path:y([...e,d]),value:x})}return}if(s.kind==="array"&&n.kind==="array"){const l=Math.min(s.value.length,n.value.length);for(let r=0;r<l;r++){const o=s.value[r],d=n.value[r];o===void 0||d===void 0||S([...e,r],o,d,a)}for(let r=l;r<n.value.length;r++){const o=n.value[r];o!==void 0&&a.push({kind:"added",path:y([...e,r]),value:o})}for(let r=l;r<s.value.length;r++){const o=s.value[r];o!==void 0&&a.push({kind:"removed",path:y([...e,r]),value:o})}}}function q(e,s){if(e.kind!==s.kind)return!1;if(e.kind==="primitive"&&s.kind==="primitive")return e.value===s.value;if(e.kind==="array"&&s.kind==="array"){if(e.value.length!==s.value.length)return!1;for(let n=0;n<e.value.length;n++){const a=e.value[n],c=s.value[n];if(a===void 0||c===void 0||!q(a,c))return!1}return!0}if(e.kind==="object"&&s.kind==="object"){const n=Object.keys(e.value),a=Object.keys(s.value);if(n.length!==a.length)return!1;for(const c of n){const l=e.value[c],r=s.value[c];if(l===void 0||r===void 0||!q(l,r))return!1}return!0}return!1}function v(e,s=80){let n;switch(e.kind){case"primitive":n=e.value===null?"null":JSON.stringify(e.value);break;case"array":n=`[… ${e.value.length} items]`;break;case"object":n=`{… ${Object.keys(e.value).length} keys}`;break}return n.length>s&&(n=`${n.slice(0,s-1)}…`),n}const be="flex flex-col gap-3 border-b border-border px-3 py-3 sm:flex-row sm:items-start sm:gap-4 sm:px-4",ge="grid min-w-0 grid-cols-1 gap-x-2 gap-y-0.5 px-3 py-2 text-xs md:grid-cols-[200px_minmax(0,1fr)_minmax(0,1fr)]";function N(e,s=2){return JSON.stringify(T(e),null,s)}function T(e){switch(e.kind){case"primitive":return e.value;case"array":return e.value.map(T);case"object":{const s={};for(const[n,a]of Object.entries(e.value))s[n]=T(a);return s}}}function w({text:e,defaultExpandDepth:s}){return t.jsx(p.Suspense,{fallback:t.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:t.jsx(ue,{text:e,defaultExpandDepth:s})})}function _(e){if(e==="")return"";for(let s=e.length-1;s>=0;s--){const n=e[s];if(n==="."||n==="[")return e.substring(0,s)}return""}function K(e){return e.kind==="equal"&&(e.value.kind==="object"||e.value.kind==="array")}function ve(e){const s=[];let n=0;for(;n<e.length;){const a=e[n];if(a!==void 0&&K(a)){const c=_(a.path);let l=n+1;for(;l<e.length;){const r=e[l];if(r===void 0||!K(r)||_(r.path)!==c)break;l++}if(l-n>1){const r=[];for(let o=n;o<l;o++){const d=e[o];d!==void 0&&d.kind==="equal"&&r.push(d)}s.push({kind:"equal-run",ops:r}),n=l;continue}}a!==void 0&&s.push({kind:"single",op:a}),n++}return s}const H={added:{icon:J,accent:"text-status-success",bg:"bg-status-success/5 hover:bg-status-success/10",border:"border-l-status-success",label:"ADDED"},removed:{icon:V,accent:"text-status-danger",bg:"bg-status-danger/5 hover:bg-status-danger/10",border:"border-l-status-danger",label:"REMOVED"},changed:{icon:B,accent:"text-status-watch",bg:"bg-status-watch/5 hover:bg-status-watch/10",border:"border-l-status-watch",label:"CHANGED"},equal:{icon:xe,accent:"text-muted-foreground/70",bg:"bg-muted/20 hover:bg-muted/30",border:"border-l-muted-foreground/20",label:"EQUAL"}};function ke({ops:e,expanded:s,onToggle:n}){const a=e[0],c=e[e.length-1];if(a===void 0||c===void 0)return t.jsx("div",{className:"text-muted-foreground/40 text-xs",children:"—"});const l=a.path,r=c.path,o=e.length===1?l:`${l} … ${r}`,d=a.value.kind==="array"?`${e.length} equal arrays`:a.value.kind==="object"?`${e.length} equal objects`:"equal",x=H.equal;return t.jsxs("div",{className:f("border-l-4 rounded-sm",x.border,x.bg),children:[t.jsxs("button",{type:"button",onClick:n,className:"w-full text-left flex items-center gap-2 px-3 py-1.5 text-xs text-muted-foreground cursor-pointer",children:[t.jsx(F,{className:f("size-3 transition-transform shrink-0",s&&"rotate-90")}),t.jsx(x.icon,{className:f("size-3 shrink-0",x.accent)}),t.jsx("span",{className:"font-mono truncate flex-1",title:`${l} … ${r}`,children:o}),t.jsx("span",{className:f("text-[10px] uppercase tracking-wider shrink-0",x.accent),children:x.label}),t.jsxs("span",{className:"text-muted-foreground/60 shrink-0",children:["(",d,")"]})]}),s&&t.jsx("div",{className:"ml-5 mt-1 mb-2 space-y-2 pr-2",children:e.map(h=>t.jsxs("div",{className:"border border-border/50 rounded p-2 bg-muted/20",children:[t.jsx("div",{className:"font-mono text-xs text-muted-foreground mb-1",children:h.path}),t.jsx(w,{text:N(h.value),defaultExpandDepth:0})]},h.path))})]})}function je({op:e,idx:s,copiedPath:n,onCopyPath:a,expanded:c,onToggle:l}){const r=H[e.kind],o=r.icon,d=e.kind==="added"||e.kind==="removed"?e.value.kind==="object"||e.value.kind==="array":e.kind==="changed"?e.left.kind==="object"||e.left.kind==="array"||e.right.kind==="object"||e.right.kind==="array":!1,x=e.kind==="changed"?[{text:v(e.left,400),tone:"text-status-danger line-through"},{text:v(e.right,400),tone:"text-status-success"}]:e.kind==="removed"?[{text:v(e.value,400),tone:"text-status-danger line-through"}]:e.kind==="added"?[{text:v(e.value,400),tone:"text-status-success"}]:[{text:v(e.value,400),tone:"text-muted-foreground"}],h=n===e.path&&e.path!=="";return t.jsxs("div",{"data-diff-idx":s,"data-diff-kind":e.kind,className:f("border-l-4 rounded-sm px-3 py-2 my-0.5 transition-colors",r.border,r.bg),children:[t.jsxs("button",{type:"button",onClick:l,disabled:!d,className:f("w-full flex items-center gap-2 text-xs text-left rounded-sm",d?"cursor-pointer":"cursor-default"),"aria-expanded":d?c:void 0,"aria-label":d?c?`Collapse ${e.path||"root"}`:`Expand ${e.path||"root"}`:void 0,children:[d?t.jsx(F,{className:f("size-3 shrink-0 transition-transform",r.accent,c&&"rotate-90")}):t.jsx("span",{className:"size-3 shrink-0","aria-hidden":"true"}),t.jsx(o,{className:f("size-3.5 shrink-0",r.accent),strokeWidth:2.5}),t.jsx("span",{className:"font-mono truncate flex-1 min-w-0",title:e.path||"(root)",children:e.path===""?"(root)":e.path}),t.jsx("span",{className:f("text-[9px] font-bold uppercase tracking-wider shrink-0 px-1.5 py-0.5 rounded",r.accent,e.kind==="equal"?"bg-muted/40":"bg-background/60"),children:r.label}),e.path!==""&&t.jsx("span",{role:"button",tabIndex:0,onClick:b=>{b.stopPropagation(),a(e.path)},onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.stopPropagation(),b.preventDefault(),a(e.path))},className:f("shrink-0 p-1 rounded transition-colors cursor-pointer inline-flex items-center justify-center",h?"text-status-success":"text-muted-foreground/50 hover:text-foreground hover:bg-muted"),"aria-label":h?"Copied":"Copy",title:h?"Copied!":"Copy",children:h?t.jsx(le,{className:"size-3"}):t.jsx(ce,{className:"size-3"})})]}),x.map((b,E)=>t.jsx("div",{className:f("font-mono text-xs mt-1 break-all pl-5",b.tone),children:b.text},E)),t.jsx("div",{className:"overflow-hidden transition-all duration-200",style:{maxHeight:c&&d?"2000px":"0"},"aria-hidden":!c,children:c&&d&&e.kind!=="equal"?t.jsx(ye,{op:e}):null})]})}function ye({op:e}){if(e.kind==="added"||e.kind==="removed")return t.jsx("div",{className:"pl-5 mt-2 border border-border/50 rounded p-2 bg-muted/20",children:t.jsx(w,{text:N(e.value),defaultExpandDepth:0})});const s=e.left.kind==="object"||e.left.kind==="array",n=e.right.kind==="object"||e.right.kind==="array";return!s&&!n?t.jsx("div",{className:"pl-5 mt-2 text-xs text-muted-foreground/70 italic",children:"Primitive values are shown inline above."}):t.jsxs("div",{className:"pl-5 mt-2 grid grid-cols-1 md:grid-cols-2 gap-2",children:[t.jsxs("div",{className:"rounded border border-status-danger/30 bg-status-danger/5 p-2",children:[t.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-wider text-status-danger",children:"Old"}),t.jsx(w,{text:N(e.left),defaultExpandDepth:0})]}),t.jsxs("div",{className:"rounded border border-status-success/30 bg-status-success/5 p-2",children:[t.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-wider text-status-success",children:"New"}),t.jsx(w,{text:N(e.right),defaultExpandDepth:0})]})]})}function Ne({counts:e,onJumpTo:s}){const n=e.added+e.removed+e.changed;return t.jsxs("div",{className:"px-4 py-2 border-b border-border bg-muted/20 flex items-center gap-2 text-xs flex-wrap",children:[t.jsxs("span",{className:"text-muted-foreground font-medium",children:[n," ",n===1?"change":"changes"]}),t.jsxs("button",{type:"button",onClick:()=>s("removed"),disabled:e.removed===0,className:f("inline-flex items-center gap-1 px-2 py-0.5 rounded-full border cursor-pointer transition-colors",e.removed>0?"border-status-danger/40 bg-status-danger/10 text-status-danger hover:bg-status-danger/20":"border-border text-muted-foreground/40 cursor-not-allowed"),title:e.removed>0?"Jump to first removed":"No removals",children:[t.jsx(V,{className:"size-3"}),e.removed," removed"]}),t.jsxs("button",{type:"button",onClick:()=>s("added"),disabled:e.added===0,className:f("inline-flex items-center gap-1 px-2 py-0.5 rounded-full border cursor-pointer transition-colors",e.added>0?"border-status-success/40 bg-status-success/10 text-status-success hover:bg-status-success/20":"border-border text-muted-foreground/40 cursor-not-allowed"),title:e.added>0?"Jump to first added":"No additions",children:[t.jsx(J,{className:"size-3"}),e.added," added"]}),t.jsxs("button",{type:"button",onClick:()=>s("changed"),disabled:e.changed===0,className:f("inline-flex items-center gap-1 px-2 py-0.5 rounded-full border cursor-pointer transition-colors",e.changed>0?"border-status-watch/40 bg-status-watch/10 text-status-watch hover:bg-status-watch/20":"border-border text-muted-foreground/40 cursor-not-allowed"),title:e.changed>0?"Jump to first changed":"No changes",children:[t.jsx(B,{className:"size-3"}),e.changed," changed"]})]})}function we({mode:e,onChange:s}){return t.jsxs("div",{className:"inline-flex rounded-md border border-border overflow-hidden",children:[t.jsxs("button",{type:"button",onClick:()=>s("unified"),"aria-pressed":e==="unified",className:f("flex items-center gap-1 px-2 py-1 text-xs transition-colors cursor-pointer",e==="unified"?"bg-muted text-foreground":"hover:bg-muted/50 text-muted-foreground"),title:"Unified view (single column, emphasized diffs)",children:[t.jsx(ie,{className:"size-3"}),"Unified"]}),t.jsxs("button",{type:"button",onClick:()=>s("split"),"aria-pressed":e==="split",className:f("flex items-center gap-1 px-2 py-1 text-xs transition-colors border-l border-border cursor-pointer",e==="split"?"bg-muted text-foreground":"hover:bg-muted/50 text-muted-foreground"),title:"Split view (path | left | right)",children:[t.jsx(de,{className:"size-3"}),"Split"]})]})}function M({log:e,side:s,displayNumber:n}){const a=R(e);return t.jsxs("div",{className:"flex-1 min-w-0 space-y-1 text-xs",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(oe,{variant:"outline",className:f("text-[10px] px-1.5 py-0 h-5 font-mono shrink-0",s==="left"?"border-status-danger/40 text-status-danger":"border-status-success/40 text-status-success"),children:s==="left"?"← Left":"Right →"}),t.jsxs("span",{className:"font-mono text-status-info",title:`Log ID ${String(e.id)}`,children:["#",n]}),e.model!==null&&t.jsx("span",{className:"min-w-0 truncate font-mono leading-snug text-muted-foreground",children:e.model})]}),t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 font-mono text-muted-foreground",children:[e.cacheCreationInputTokens!==null&&e.cacheCreationInputTokens>0&&t.jsxs("span",{className:"text-status-success",children:["KV Cache +",z(e.cacheCreationInputTokens)]}),e.cacheReadInputTokens!==null&&e.cacheReadInputTokens>0&&t.jsxs("span",{className:"text-status-accent",children:["KV Cache ~",z(e.cacheReadInputTokens)]}),t.jsx("span",{className:"truncate",title:e.timestamp,children:e.timestamp})]}),t.jsxs("div",{className:"text-muted-foreground/70 font-mono truncate",title:a,children:["session: ",a]})]})}function Se({left:e,right:s,leftDisplayNumber:n,rightDisplayNumber:a,onClose:c}){const l=p.useRef(null),r=p.useRef(null),o=p.useRef(null),d=p.useMemo(()=>{const i=A(D(e)).analyzeRequest(e.rawRequestBody),u=A(D(s)).analyzeRequest(s.rawRequestBody),m=$(i.comparisonValue),g=$(u.comparisonValue);return he(m,g)},[e.apiFormat,e.path,e.rawRequestBody,s.apiFormat,s.path,s.rawRequestBody]),x=p.useMemo(()=>ve(d),[d]),h=p.useMemo(()=>{let i=0,u=0,m=0;for(const g of x)if(g.kind==="single")switch(g.op.kind){case"added":i++;break;case"removed":u++;break;case"changed":m++;break}return{added:i,removed:u,changed:m}},[x]),[b,E]=p.useState(new Set),U=i=>{E(u=>{const m=new Set(u);return m.has(i)?m.delete(i):m.add(i),m})},[G,I]=p.useState(new Set),Q=i=>{I(u=>{const m=new Set(u);return m.has(i)?m.delete(i):m.add(i),m})};p.useEffect(()=>{I(new Set)},[e.id,s.id]);const[O,W]=p.useState("unified"),P=p.useRef(null),[X,L]=p.useState(null),j=p.useRef(null),Y=i=>{ne(i).then(u=>{u&&(L(i),j.current!==null&&clearTimeout(j.current),j.current=setTimeout(()=>L(null),1500))})};p.useEffect(()=>()=>{j.current!==null&&clearTimeout(j.current)},[]);const Z=i=>{const u=x.findIndex(k=>k.kind==="single"&&k.op.kind===i);if(u===-1)return;const m=P.current;if(m===null)return;const g=m.querySelector(`[data-diff-idx="${u}"]`);g!==null&&g.scrollIntoView({behavior:"smooth",block:"center"})};p.useEffect(()=>{o.current=document.activeElement instanceof HTMLElement?document.activeElement:null,r.current?.focus();const i=m=>{m.key==="Escape"&&c()};document.addEventListener("keydown",i);const u=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",i),document.body.style.overflow=u,o.current?.focus()}},[c]);const ee=i=>{if(i.stopPropagation(),i.key!=="Tab")return;const u=l.current;if(u===null)return;const m=Array.from(u.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), [tabindex]:not([tabindex="-1"])')),g=m[0],k=m[m.length-1];if(!(g===void 0||k===void 0)){if(i.shiftKey&&document.activeElement===g){i.preventDefault(),k.focus();return}!i.shiftKey&&document.activeElement===k&&(i.preventDefault(),g.focus())}},te=R(e)===R(s),se=d.length===1&&d[0]?.kind==="equal";return t.jsxs("div",{className:"fixed inset-0 z-50 flex justify-end",role:"dialog","aria-modal":"true","aria-label":"Compare two log requests",children:[t.jsx("button",{type:"button",onClick:c,"aria-label":"Close compare drawer",className:"absolute inset-0 bg-black/40 cursor-default",tabIndex:-1}),t.jsxs("div",{ref:l,className:f("relative overflow-x-hidden bg-background border-l border-border shadow-xl","w-full md:w-[70vw] max-w-[1100px] flex flex-col h-full"),onClick:i=>i.stopPropagation(),onKeyDown:ee,children:[t.jsxs("div",{className:be,children:[t.jsxs("div",{className:"grid min-w-0 flex-1 grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4",children:[t.jsx(M,{log:e,side:"left",displayNumber:n}),t.jsx(M,{log:s,side:"right",displayNumber:a})]}),t.jsxs("div",{className:"flex w-full shrink-0 items-center justify-between gap-2 sm:w-auto sm:justify-start",children:[t.jsx(we,{mode:O,onChange:W}),t.jsx("button",{ref:r,type:"button",onClick:c,"aria-label":"Close",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted cursor-pointer",children:t.jsx(ae,{className:"size-4"})})]})]}),!te&&t.jsx("div",{className:"border-b border-border bg-warning/10 px-4 py-1.5 text-xs text-foreground",children:"Heads up: the two selected logs are from different sessions."}),se?t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto flex items-center justify-center text-muted-foreground text-sm",children:"The two Request payloads are identical."}):t.jsxs(t.Fragment,{children:[t.jsx(Ne,{counts:h,onJumpTo:Z}),t.jsx("div",{ref:P,className:"flex-1 min-h-0 overflow-y-auto",children:O==="unified"?t.jsx("div",{className:"px-3 py-2 space-y-0.5",children:x.map((i,u)=>{if(i.kind==="equal-run")return t.jsx(ke,{ops:i.ops,expanded:b.has(u),onToggle:()=>U(u)},`r${u}`);const m=i.op;return t.jsx(je,{op:m,idx:u,copiedPath:X,onCopyPath:Y,expanded:G.has(u),onToggle:()=>Q(u)},`o${u}`)})}):t.jsx(Ce,{grouped:x,left:e,right:s,leftDisplayNumber:n,rightDisplayNumber:a})})]})]})]})}function Ce({grouped:e,left:s,right:n,leftDisplayNumber:a,rightDisplayNumber:c}){return t.jsxs("div",{"data-compare-layout":"responsive-split",className:ge,children:[t.jsxs("div",{className:"col-span-1 mb-2 grid grid-cols-1 gap-x-2 gap-y-1 border-b border-border pb-2 text-[10px] uppercase tracking-wider text-muted-foreground md:col-span-3 md:grid-cols-[200px_minmax(0,1fr)_minmax(0,1fr)]",children:[t.jsx("span",{children:"Path"}),t.jsxs("span",{title:`Log ID ${String(s.id)}`,children:["Left (Log #",a,")"]}),t.jsxs("span",{title:`Log ID ${String(n.id)}`,children:["Right (Log #",c,")"]})]}),e.map((l,r)=>{if(l.kind==="equal-run")return t.jsxs("div",{className:"col-span-1 px-2 py-1 text-xs text-muted-foreground/60 md:col-span-3",children:[l.ops.length," equal siblings collapsed — switch to Unified to expand"]},r);const o=l.op;return o.kind==="equal"?t.jsxs("div",{className:"col-span-1 grid min-w-0 grid-cols-1 gap-x-2 gap-y-1 px-2 py-0.5 text-muted-foreground md:col-span-3 md:grid-cols-[200px_minmax(0,1fr)_minmax(0,1fr)]",children:[t.jsx("span",{className:"font-mono text-xs truncate",title:o.path,children:o.path}),t.jsx("span",{className:"font-mono text-xs break-all opacity-60",children:v(o.value,200)}),t.jsx("span",{className:"font-mono text-xs break-all opacity-60",children:v(o.value,200)})]},r):o.kind==="added"?t.jsxs("div",{className:"col-span-1 rounded border-l-2 border-l-status-success bg-status-success/5 px-2 py-1 text-xs md:col-span-3",children:[t.jsx("div",{className:"font-mono text-xs text-muted-foreground mb-0.5",children:o.path}),t.jsxs("div",{className:"font-mono break-all text-status-success",children:["+ ",v(o.value,400)]})]},r):o.kind==="removed"?t.jsxs("div",{className:"col-span-1 rounded border-l-2 border-l-status-danger bg-status-danger/5 px-2 py-1 text-xs md:col-span-3",children:[t.jsx("div",{className:"font-mono text-xs text-muted-foreground mb-0.5",children:o.path}),t.jsxs("div",{className:"font-mono break-all text-status-danger line-through",children:["− ",v(o.value,400)]})]},r):t.jsxs("div",{className:"col-span-1 rounded border-l-2 border-l-status-watch bg-status-watch/5 px-2 py-1 text-xs md:col-span-3",children:[t.jsx("div",{className:"font-mono text-xs text-muted-foreground mb-1",children:o.path}),t.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[t.jsx("div",{className:"font-mono break-all text-status-danger line-through",children:v(o.left,400)}),t.jsx("div",{className:"font-mono break-all text-status-success",children:v(o.right,400)})]})]},r)})]})}export{be as COMPARE_RESPONSIVE_HEADER_CLASS_NAME,ge as COMPARE_RESPONSIVE_SPLIT_CLASS_NAME,Se as CompareDrawer};
|