@tonyclaw/agent-inspector 2.0.10 → 2.0.12
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-BWMipEjS.js → CompareDrawer-ClM_uVRy.js} +1 -1
- package/.output/public/assets/ProxyViewerContainer-CTNNzXSa.js +114 -0
- package/.output/public/assets/{ReplayDialog-DaSzZsvM.js → ReplayDialog-7rp7N_KJ.js} +1 -1
- package/.output/public/assets/RequestAnatomy-sL2FFo_N.js +1 -0
- package/.output/public/assets/ResponseView-Cjlf3b6-.js +1 -0
- package/.output/public/assets/{StreamingChunkSequence-B4atnL99.js → StreamingChunkSequence-Ctx3sT3r.js} +1 -1
- package/.output/public/assets/_sessionId-DEWzDQ8-.js +1 -0
- package/.output/public/assets/index-DGIIhZTn.js +1 -0
- package/.output/public/assets/index-D_nZj9Vt.css +1 -0
- package/.output/public/assets/{main-DE6Y4-wV.js → main-FvIQopAy.js} +2 -2
- package/.output/server/_libs/lucide-react.mjs +51 -39
- package/.output/server/{_sessionId-61HO9rUI.mjs → _sessionId-BDSgtrsI.mjs} +2 -2
- package/.output/server/_ssr/{CompareDrawer-CSPqneYm.mjs → CompareDrawer-Cqvv0I3x.mjs} +3 -3
- package/.output/server/_ssr/{ProxyViewerContainer-DrSMa5O7.mjs → ProxyViewerContainer-C0YEoG8N.mjs} +1611 -183
- package/.output/server/_ssr/{ReplayDialog-Dn3naENv.mjs → ReplayDialog-CrsynUKI.mjs} +4 -4
- package/.output/server/_ssr/RequestAnatomy-CR_JUkcL.mjs +688 -0
- package/.output/server/_ssr/{ResponseView-CwXAWOoE.mjs → ResponseView-Dba2Et69.mjs} +3 -3
- package/.output/server/_ssr/{StreamingChunkSequence-DRSR2FfN.mjs → StreamingChunkSequence-BIMHLstI.mjs} +2 -2
- package/.output/server/_ssr/{index-D4zn5CAg.mjs → index-DveIUTm5.mjs} +2 -2
- package/.output/server/_ssr/index.mjs +2 -2
- package/.output/server/_ssr/{router-CSRaa_tu.mjs → router-D0yXVG0Q.mjs} +85 -22
- package/.output/server/{_tanstack-start-manifest_v-CfvVUYYj.mjs → _tanstack-start-manifest_v-pe0xJFuQ.mjs} +1 -1
- package/.output/server/index.mjs +70 -70
- package/package.json +1 -1
- package/src/components/ProxyViewer.tsx +453 -52
- package/src/components/providers/ProviderCard.tsx +45 -2
- package/src/components/providers/ProviderForm.tsx +245 -80
- package/src/components/providers/ProvidersPanel.tsx +7 -1
- package/src/components/proxy-viewer/ConversationGroup.tsx +18 -1
- package/src/components/proxy-viewer/LogEntry.tsx +25 -0
- package/src/components/proxy-viewer/TurnGroup.tsx +15 -0
- package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +144 -80
- package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +70 -5
- package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +196 -0
- package/src/components/proxy-viewer/logFocus.ts +33 -0
- package/src/lib/providerModelMetadata.ts +64 -12
- package/src/lib/utils.ts +7 -0
- package/src/proxy/providers.ts +25 -0
- package/src/routes/api/providers.ts +3 -0
- package/.output/public/assets/ProxyViewerContainer-DIAgurux.js +0 -114
- package/.output/public/assets/RequestAnatomy-BfQmPHCd.js +0 -1
- package/.output/public/assets/ResponseView-CblEWDMx.js +0 -1
- package/.output/public/assets/_sessionId-DUzYnZXV.js +0 -1
- package/.output/public/assets/index-CxhRsekH.css +0 -1
- package/.output/public/assets/index-jagRsQaV.js +0 -1
- package/.output/server/_ssr/RequestAnatomy-D1X3f3AX.mjs +0 -1322
|
@@ -1,1322 +0,0 @@
|
|
|
1
|
-
import { r as reactExports, j as jsxRuntimeExports } from "../_libs/react.mjs";
|
|
2
|
-
import { u as useProviders, f as formatTokens, k as TooltipProvider, c as cn, l as Tooltip, m as TooltipTrigger, n as TooltipContent, p as countCharacters, q as estimateTokens } from "./ProxyViewerContainer-DrSMa5O7.mjs";
|
|
3
|
-
import { s as safeGetOwnProperty, k as resolveProviderContextWindow, l as isPlainRecord } from "./router-CSRaa_tu.mjs";
|
|
4
|
-
import "../_libs/jszip.mjs";
|
|
5
|
-
import "../_libs/modelcontextprotocol__server.mjs";
|
|
6
|
-
import { aa as Info } from "../_libs/lucide-react.mjs";
|
|
7
|
-
import "../_libs/swr.mjs";
|
|
8
|
-
import "../_libs/use-sync-external-store.mjs";
|
|
9
|
-
import "../_libs/dequal.mjs";
|
|
10
|
-
import "../_libs/clsx.mjs";
|
|
11
|
-
import "../_libs/tailwind-merge.mjs";
|
|
12
|
-
import "../_libs/class-variance-authority.mjs";
|
|
13
|
-
import "../_libs/radix-ui__react-dialog.mjs";
|
|
14
|
-
import "../_libs/radix-ui__primitive.mjs";
|
|
15
|
-
import "../_libs/radix-ui__react-compose-refs.mjs";
|
|
16
|
-
import "../_libs/radix-ui__react-context.mjs";
|
|
17
|
-
import "../_libs/radix-ui__react-id.mjs";
|
|
18
|
-
import "../_libs/@radix-ui/react-use-layout-effect+[...].mjs";
|
|
19
|
-
import "../_libs/@radix-ui/react-use-controllable-state+[...].mjs";
|
|
20
|
-
import "../_libs/@radix-ui/react-dismissable-layer+[...].mjs";
|
|
21
|
-
import "../_libs/radix-ui__react-primitive.mjs";
|
|
22
|
-
import "../_libs/react-dom.mjs";
|
|
23
|
-
import "util";
|
|
24
|
-
import "async_hooks";
|
|
25
|
-
import "stream";
|
|
26
|
-
import "crypto";
|
|
27
|
-
import "../_libs/radix-ui__react-slot.mjs";
|
|
28
|
-
import "../_libs/@radix-ui/react-use-callback-ref+[...].mjs";
|
|
29
|
-
import "../_libs/@radix-ui/react-use-escape-keydown+[...].mjs";
|
|
30
|
-
import "../_libs/radix-ui__react-focus-scope.mjs";
|
|
31
|
-
import "../_libs/radix-ui__react-portal.mjs";
|
|
32
|
-
import "../_libs/radix-ui__react-presence.mjs";
|
|
33
|
-
import "../_libs/radix-ui__react-focus-guards.mjs";
|
|
34
|
-
import "../_libs/react-remove-scroll.mjs";
|
|
35
|
-
import "tslib";
|
|
36
|
-
import "../_libs/react-remove-scroll-bar.mjs";
|
|
37
|
-
import "../_libs/react-style-singleton.mjs";
|
|
38
|
-
import "../_libs/get-nonce.mjs";
|
|
39
|
-
import "../_libs/use-sidecar.mjs";
|
|
40
|
-
import "../_libs/use-callback-ref.mjs";
|
|
41
|
-
import "../_libs/aria-hidden.mjs";
|
|
42
|
-
import "../_libs/diff.mjs";
|
|
43
|
-
import "../_libs/tanstack__react-virtual.mjs";
|
|
44
|
-
import "../_libs/tanstack__virtual-core.mjs";
|
|
45
|
-
import "../_libs/radix-ui__react-select.mjs";
|
|
46
|
-
import "../_libs/radix-ui__number.mjs";
|
|
47
|
-
import "../_libs/radix-ui__react-collection.mjs";
|
|
48
|
-
import "../_libs/radix-ui__react-direction.mjs";
|
|
49
|
-
import "../_libs/radix-ui__react-popper.mjs";
|
|
50
|
-
import "../_libs/floating-ui__react-dom.mjs";
|
|
51
|
-
import "../_libs/floating-ui__dom.mjs";
|
|
52
|
-
import "../_libs/floating-ui__core.mjs";
|
|
53
|
-
import "../_libs/floating-ui__utils.mjs";
|
|
54
|
-
import "../_libs/radix-ui__react-arrow.mjs";
|
|
55
|
-
import "../_libs/radix-ui__react-use-size.mjs";
|
|
56
|
-
import "../_libs/radix-ui__react-use-previous.mjs";
|
|
57
|
-
import "../_libs/@radix-ui/react-visually-hidden+[...].mjs";
|
|
58
|
-
import "../_libs/react-markdown.mjs";
|
|
59
|
-
import "../_libs/devlop.mjs";
|
|
60
|
-
import "../_libs/unified.mjs";
|
|
61
|
-
import "../_libs/bail.mjs";
|
|
62
|
-
import "../_libs/extend.mjs";
|
|
63
|
-
import "../_libs/is-plain-obj.mjs";
|
|
64
|
-
import "../_libs/trough.mjs";
|
|
65
|
-
import "../_libs/vfile.mjs";
|
|
66
|
-
import "../_libs/vfile-message.mjs";
|
|
67
|
-
import "../_libs/unist-util-stringify-position.mjs";
|
|
68
|
-
import "node:process";
|
|
69
|
-
import "node:path";
|
|
70
|
-
import "node:url";
|
|
71
|
-
import "../_libs/remark-parse.mjs";
|
|
72
|
-
import "../_libs/mdast-util-from-markdown.mjs";
|
|
73
|
-
import "../_libs/micromark-util-decode-numeric-character-reference+[...].mjs";
|
|
74
|
-
import "../_libs/micromark-util-decode-string.mjs";
|
|
75
|
-
import "../_libs/decode-named-character-reference+[...].mjs";
|
|
76
|
-
import "../_libs/character-entities.mjs";
|
|
77
|
-
import "../_libs/micromark-util-normalize-identifier+[...].mjs";
|
|
78
|
-
import "../_libs/micromark.mjs";
|
|
79
|
-
import "../_libs/micromark-util-combine-extensions+[...].mjs";
|
|
80
|
-
import "../_libs/micromark-util-chunked.mjs";
|
|
81
|
-
import "../_libs/micromark-factory-space.mjs";
|
|
82
|
-
import "../_libs/micromark-util-character.mjs";
|
|
83
|
-
import "../_libs/micromark-core-commonmark.mjs";
|
|
84
|
-
import "../_libs/micromark-util-classify-character+[...].mjs";
|
|
85
|
-
import "../_libs/micromark-util-resolve-all.mjs";
|
|
86
|
-
import "../_libs/micromark-util-subtokenize.mjs";
|
|
87
|
-
import "../_libs/micromark-factory-destination.mjs";
|
|
88
|
-
import "../_libs/micromark-factory-label.mjs";
|
|
89
|
-
import "../_libs/micromark-factory-title.mjs";
|
|
90
|
-
import "../_libs/micromark-factory-whitespace.mjs";
|
|
91
|
-
import "../_libs/micromark-util-html-tag-name.mjs";
|
|
92
|
-
import "../_libs/mdast-util-to-string.mjs";
|
|
93
|
-
import "../_libs/remark-rehype.mjs";
|
|
94
|
-
import "../_libs/mdast-util-to-hast.mjs";
|
|
95
|
-
import "../_libs/ungap__structured-clone.mjs";
|
|
96
|
-
import "../_libs/micromark-util-sanitize-uri.mjs";
|
|
97
|
-
import "../_libs/unist-util-position.mjs";
|
|
98
|
-
import "../_libs/trim-lines.mjs";
|
|
99
|
-
import "../_libs/unist-util-visit.mjs";
|
|
100
|
-
import "../_libs/unist-util-visit-parents.mjs";
|
|
101
|
-
import "../_libs/unist-util-is.mjs";
|
|
102
|
-
import "../_libs/hast-util-to-jsx-runtime.mjs";
|
|
103
|
-
import "../_libs/comma-separated-tokens.mjs";
|
|
104
|
-
import "../_libs/property-information.mjs";
|
|
105
|
-
import "../_libs/space-separated-tokens.mjs";
|
|
106
|
-
import "../_libs/style-to-js.mjs";
|
|
107
|
-
import "../_libs/style-to-object.mjs";
|
|
108
|
-
import "../_libs/inline-style-parser.mjs";
|
|
109
|
-
import "../_libs/hast-util-whitespace.mjs";
|
|
110
|
-
import "../_libs/estree-util-is-identifier-name.mjs";
|
|
111
|
-
import "../_libs/html-url-attributes.mjs";
|
|
112
|
-
import "../_libs/zod.mjs";
|
|
113
|
-
import "../_libs/radix-ui__react-tooltip.mjs";
|
|
114
|
-
import "../_libs/radix-ui__react-tabs.mjs";
|
|
115
|
-
import "../_libs/radix-ui__react-roving-focus.mjs";
|
|
116
|
-
import "../_libs/radix-ui__react-collapsible.mjs";
|
|
117
|
-
import "../_libs/radix-ui__react-scroll-area.mjs";
|
|
118
|
-
import "../_libs/tanstack__react-router.mjs";
|
|
119
|
-
import "../_libs/tiny-warning.mjs";
|
|
120
|
-
import "../_libs/tanstack__router-core.mjs";
|
|
121
|
-
import "../_libs/cookie-es.mjs";
|
|
122
|
-
import "../_libs/tanstack__history.mjs";
|
|
123
|
-
import "../_libs/tiny-invariant.mjs";
|
|
124
|
-
import "../_libs/seroval.mjs";
|
|
125
|
-
import "../_libs/seroval-plugins.mjs";
|
|
126
|
-
import "node:stream/web";
|
|
127
|
-
import "node:stream";
|
|
128
|
-
import "../_libs/isbot.mjs";
|
|
129
|
-
import "node:fs";
|
|
130
|
-
import "node:fs/promises";
|
|
131
|
-
import "node:buffer";
|
|
132
|
-
import "node:child_process";
|
|
133
|
-
import "../_libs/conf.mjs";
|
|
134
|
-
import "node:util";
|
|
135
|
-
import "node:crypto";
|
|
136
|
-
import "node:assert";
|
|
137
|
-
import "../_libs/dot-prop.mjs";
|
|
138
|
-
import "../_libs/env-paths.mjs";
|
|
139
|
-
import "node:os";
|
|
140
|
-
import "../_libs/atomically.mjs";
|
|
141
|
-
import "../_libs/stubborn-fs.mjs";
|
|
142
|
-
import "../_libs/stubborn-utils.mjs";
|
|
143
|
-
import "../_libs/when-exit.mjs";
|
|
144
|
-
import "../_libs/ajv.mjs";
|
|
145
|
-
import "../_libs/fast-deep-equal.mjs";
|
|
146
|
-
import "../_libs/json-schema-traverse.mjs";
|
|
147
|
-
import "../_libs/fast-uri.mjs";
|
|
148
|
-
import "../_libs/ajv-formats.mjs";
|
|
149
|
-
import "../_libs/debounce-fn.mjs";
|
|
150
|
-
import "../_libs/mimic-function.mjs";
|
|
151
|
-
import "../_libs/semver.mjs";
|
|
152
|
-
import "../_libs/uint8array-extras.mjs";
|
|
153
|
-
import "node:worker_threads";
|
|
154
|
-
import "../_libs/readable-stream.mjs";
|
|
155
|
-
import "events";
|
|
156
|
-
import "node:string_decoder";
|
|
157
|
-
import "../_libs/process-nextick-args.mjs";
|
|
158
|
-
import "../_libs/isarray.mjs";
|
|
159
|
-
import "../_libs/safe-buffer.mjs";
|
|
160
|
-
import "buffer";
|
|
161
|
-
import "../_libs/core-util-is.mjs";
|
|
162
|
-
import "../_libs/inherits.mjs";
|
|
163
|
-
import "../_libs/util-deprecate.mjs";
|
|
164
|
-
import "../_libs/lie.mjs";
|
|
165
|
-
import "../_libs/immediate.mjs";
|
|
166
|
-
import "../_libs/setimmediate.mjs";
|
|
167
|
-
import "../_libs/pako.mjs";
|
|
168
|
-
const WATCH_USAGE_PERCENT = 0.75;
|
|
169
|
-
const DANGER_USAGE_PERCENT = 0.9;
|
|
170
|
-
const LONG_TOOL_SCHEMA_TOKENS = 8e3;
|
|
171
|
-
const LARGE_ROLE_PERCENT = 0.35;
|
|
172
|
-
const DUPLICATE_MIN_TOKENS = 40;
|
|
173
|
-
const DUPLICATE_MIN_CHARS = 160;
|
|
174
|
-
const DUPLICATE_NESTED_MAX_DEPTH = 5;
|
|
175
|
-
const DUPLICATE_NESTED_MAX_CANDIDATES_PER_SEGMENT = 8;
|
|
176
|
-
const HISTORY_BLOAT_SEGMENTS = 18;
|
|
177
|
-
const HISTORY_BLOAT_TOKENS = 6e4;
|
|
178
|
-
const HISTORY_BLOAT_PERCENT = 0.7;
|
|
179
|
-
const SYSTEM_HEAVY_TOKENS = 3e3;
|
|
180
|
-
const SYSTEM_HEAVY_PERCENT = 0.3;
|
|
181
|
-
const DUPLICATE_PREVIEW_CHARS = 160;
|
|
182
|
-
const DUPLICATE_NESTED_FIELD_NAMES = /* @__PURE__ */ new Set([
|
|
183
|
-
"answer",
|
|
184
|
-
"body",
|
|
185
|
-
"content",
|
|
186
|
-
"data",
|
|
187
|
-
"error",
|
|
188
|
-
"message",
|
|
189
|
-
"markdown",
|
|
190
|
-
"output",
|
|
191
|
-
"response",
|
|
192
|
-
"result",
|
|
193
|
-
"stderr",
|
|
194
|
-
"stdout",
|
|
195
|
-
"text",
|
|
196
|
-
"transcript"
|
|
197
|
-
]);
|
|
198
|
-
const EXPLICIT_CONTEXT_WINDOW_FIELDS = [
|
|
199
|
-
"context_window",
|
|
200
|
-
"contextWindow",
|
|
201
|
-
"context_length",
|
|
202
|
-
"contextLength",
|
|
203
|
-
"max_context_length",
|
|
204
|
-
"maxContextLength",
|
|
205
|
-
"max_input_tokens",
|
|
206
|
-
"maxInputTokens"
|
|
207
|
-
];
|
|
208
|
-
const OUTPUT_RESERVE_FIELDS = [
|
|
209
|
-
"max_tokens",
|
|
210
|
-
"maxTokens",
|
|
211
|
-
"max_completion_tokens",
|
|
212
|
-
"maxCompletionTokens",
|
|
213
|
-
"max_output_tokens",
|
|
214
|
-
"maxOutputTokens"
|
|
215
|
-
];
|
|
216
|
-
const MODEL_CONTEXT_RULES = [
|
|
217
|
-
{
|
|
218
|
-
family: "OpenAI GPT-4.1",
|
|
219
|
-
tokens: 1047576,
|
|
220
|
-
mode: "prefix",
|
|
221
|
-
patterns: ["gpt-4.1"]
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
family: "OpenAI GPT-4o",
|
|
225
|
-
tokens: 128e3,
|
|
226
|
-
mode: "prefix",
|
|
227
|
-
patterns: ["gpt-4o"]
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
family: "OpenAI o-series",
|
|
231
|
-
tokens: 128e3,
|
|
232
|
-
mode: "prefix",
|
|
233
|
-
patterns: ["o1", "o3", "o4"]
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
family: "Anthropic Claude",
|
|
237
|
-
tokens: 2e5,
|
|
238
|
-
mode: "prefix",
|
|
239
|
-
patterns: ["claude-"]
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
family: "DeepSeek V4",
|
|
243
|
-
tokens: 1e6,
|
|
244
|
-
mode: "prefix",
|
|
245
|
-
patterns: ["deepseek-v4-pro", "deepseek-v4-flash"]
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
family: "DeepSeek",
|
|
249
|
-
tokens: 64e3,
|
|
250
|
-
mode: "prefix",
|
|
251
|
-
patterns: ["deepseek-"]
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
family: "MiniMax M3",
|
|
255
|
-
tokens: 1e6,
|
|
256
|
-
mode: "includes",
|
|
257
|
-
patterns: ["minimax-m3"]
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
family: "MiniMax M2",
|
|
261
|
-
tokens: 204800,
|
|
262
|
-
mode: "includes",
|
|
263
|
-
patterns: ["minimax-m2.7", "minimax-m2.5", "minimax-m2.1"]
|
|
264
|
-
}
|
|
265
|
-
];
|
|
266
|
-
const ROLE_LABELS = {
|
|
267
|
-
system: "System",
|
|
268
|
-
user: "User messages",
|
|
269
|
-
assistant: "Assistant messages",
|
|
270
|
-
tool: "Tool results",
|
|
271
|
-
tools: "Tool definitions"
|
|
272
|
-
};
|
|
273
|
-
function readPositiveInteger(value) {
|
|
274
|
-
if (typeof value === "number") {
|
|
275
|
-
if (Number.isFinite(value) && value > 0) return Math.floor(value);
|
|
276
|
-
return null;
|
|
277
|
-
}
|
|
278
|
-
if (typeof value === "string") {
|
|
279
|
-
const parsed = Number(value);
|
|
280
|
-
if (Number.isFinite(parsed) && parsed > 0) return Math.floor(parsed);
|
|
281
|
-
}
|
|
282
|
-
return null;
|
|
283
|
-
}
|
|
284
|
-
function readPositiveIntegerField(parsed, fields) {
|
|
285
|
-
for (const field of fields) {
|
|
286
|
-
const value = readPositiveInteger(safeGetOwnProperty(parsed, field));
|
|
287
|
-
if (value !== null) return value;
|
|
288
|
-
}
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
function readRequestModel(parsed) {
|
|
292
|
-
const value = safeGetOwnProperty(parsed, "model");
|
|
293
|
-
if (typeof value !== "string") return null;
|
|
294
|
-
const trimmed = value.trim();
|
|
295
|
-
return trimmed === "" ? null : trimmed;
|
|
296
|
-
}
|
|
297
|
-
function matchesRule(model, rule) {
|
|
298
|
-
switch (rule.mode) {
|
|
299
|
-
case "prefix":
|
|
300
|
-
return rule.patterns.some((pattern) => model.startsWith(pattern));
|
|
301
|
-
case "includes":
|
|
302
|
-
return rule.patterns.some((pattern) => model.includes(pattern));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
function resolveContextWindow(model, parsed, providers = []) {
|
|
306
|
-
const explicitWindow = readPositiveIntegerField(parsed, EXPLICIT_CONTEXT_WINDOW_FIELDS);
|
|
307
|
-
if (explicitWindow !== null) {
|
|
308
|
-
return {
|
|
309
|
-
tokens: explicitWindow,
|
|
310
|
-
label: "Request metadata",
|
|
311
|
-
source: "request"
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
const providerWindow = resolveProviderContextWindow(model, providers);
|
|
315
|
-
if (providerWindow !== null) {
|
|
316
|
-
return {
|
|
317
|
-
tokens: providerWindow.tokens,
|
|
318
|
-
label: `${providerWindow.providerName} config`,
|
|
319
|
-
source: "provider"
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
if (model === null) {
|
|
323
|
-
return {
|
|
324
|
-
tokens: null,
|
|
325
|
-
label: "Unknown model",
|
|
326
|
-
source: "unknown"
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
const normalized = model.trim().toLowerCase().replace(/\s+/g, "-");
|
|
330
|
-
for (const rule of MODEL_CONTEXT_RULES) {
|
|
331
|
-
if (matchesRule(normalized, rule)) {
|
|
332
|
-
return {
|
|
333
|
-
tokens: rule.tokens,
|
|
334
|
-
label: `${rule.family} local rule`,
|
|
335
|
-
source: "model-rule"
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return {
|
|
340
|
-
tokens: null,
|
|
341
|
-
label: "No local rule",
|
|
342
|
-
source: "unknown"
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
function clampPercent(value) {
|
|
346
|
-
if (value < 0) return 0;
|
|
347
|
-
if (value > 1) return 1;
|
|
348
|
-
return value;
|
|
349
|
-
}
|
|
350
|
-
function riskLevel(usagePercent) {
|
|
351
|
-
if (usagePercent === null) return "unknown";
|
|
352
|
-
if (usagePercent >= DANGER_USAGE_PERCENT) return "danger";
|
|
353
|
-
if (usagePercent >= WATCH_USAGE_PERCENT) return "watch";
|
|
354
|
-
return "ok";
|
|
355
|
-
}
|
|
356
|
-
function sumSegments(segments, role) {
|
|
357
|
-
return segments.filter((segment) => segment.role === role).reduce((sum, segment) => sum + segment.size, 0);
|
|
358
|
-
}
|
|
359
|
-
function buildRoleUsages(segments, total) {
|
|
360
|
-
const roles = ["system", "user", "assistant", "tool", "tools"];
|
|
361
|
-
return roles.map((role) => {
|
|
362
|
-
const tokens = sumSegments(segments, role);
|
|
363
|
-
return {
|
|
364
|
-
role,
|
|
365
|
-
label: ROLE_LABELS[role],
|
|
366
|
-
tokens,
|
|
367
|
-
percent: total > 0 ? tokens / total : 0
|
|
368
|
-
};
|
|
369
|
-
}).filter((usage) => usage.tokens > 0).sort((a, b) => b.tokens - a.tokens);
|
|
370
|
-
}
|
|
371
|
-
function normalizeDuplicateText(text) {
|
|
372
|
-
return text.replace(/\s+/g, " ").trim().toLowerCase();
|
|
373
|
-
}
|
|
374
|
-
function duplicatePreview(text) {
|
|
375
|
-
const singleLine = text.replace(/\s+/g, " ").trim();
|
|
376
|
-
if (singleLine.length <= DUPLICATE_PREVIEW_CHARS) return singleLine;
|
|
377
|
-
return `${singleLine.slice(0, DUPLICATE_PREVIEW_CHARS - 3)}...`;
|
|
378
|
-
}
|
|
379
|
-
function duplicateSegmentRef(candidate) {
|
|
380
|
-
return {
|
|
381
|
-
role: candidate.role,
|
|
382
|
-
label: candidate.label,
|
|
383
|
-
path: candidate.path,
|
|
384
|
-
tokens: candidate.tokens,
|
|
385
|
-
characters: candidate.characters
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
function duplicateCandidateFromSegment(segment) {
|
|
389
|
-
return {
|
|
390
|
-
role: segment.role,
|
|
391
|
-
label: segment.label,
|
|
392
|
-
path: segment.path,
|
|
393
|
-
tokens: segment.size,
|
|
394
|
-
characters: segment.characters,
|
|
395
|
-
text: segment.text
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
function jsonLikeText(text) {
|
|
399
|
-
const trimmed = text.trim();
|
|
400
|
-
return trimmed.startsWith("{") || trimmed.startsWith("[");
|
|
401
|
-
}
|
|
402
|
-
function parseJsonLikeText(text) {
|
|
403
|
-
if (!jsonLikeText(text)) return null;
|
|
404
|
-
try {
|
|
405
|
-
const parsed = JSON.parse(text);
|
|
406
|
-
return parsed;
|
|
407
|
-
} catch {
|
|
408
|
-
return null;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
function normalizePathFieldName(field) {
|
|
412
|
-
return field.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
413
|
-
}
|
|
414
|
-
function lastNamedPathField(path) {
|
|
415
|
-
for (let index = path.length - 1; index >= 0; index -= 1) {
|
|
416
|
-
const field = path[index] ?? "";
|
|
417
|
-
if (field.startsWith("[") && field.endsWith("]")) continue;
|
|
418
|
-
return field;
|
|
419
|
-
}
|
|
420
|
-
return null;
|
|
421
|
-
}
|
|
422
|
-
function nestedDuplicateFieldPath(path) {
|
|
423
|
-
const field = lastNamedPathField(path);
|
|
424
|
-
if (field === null) return false;
|
|
425
|
-
return DUPLICATE_NESTED_FIELD_NAMES.has(normalizePathFieldName(field));
|
|
426
|
-
}
|
|
427
|
-
function formatNestedDuplicatePath(path) {
|
|
428
|
-
return path.map((part) => part.startsWith("[") ? part : `.${part}`).join("").replace(/^\./, "");
|
|
429
|
-
}
|
|
430
|
-
function duplicateCandidateFromNestedText(segment, text, path) {
|
|
431
|
-
const characters = countCharacters(text);
|
|
432
|
-
if (characters < DUPLICATE_MIN_CHARS) return null;
|
|
433
|
-
const tokens = estimateTokens(text);
|
|
434
|
-
if (tokens < DUPLICATE_MIN_TOKENS) return null;
|
|
435
|
-
return {
|
|
436
|
-
role: segment.role,
|
|
437
|
-
label: `${segment.label} ${formatNestedDuplicatePath(path)}`,
|
|
438
|
-
path: segment.path,
|
|
439
|
-
tokens,
|
|
440
|
-
characters,
|
|
441
|
-
text
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
function collectNestedDuplicateCandidates({
|
|
445
|
-
value,
|
|
446
|
-
segment,
|
|
447
|
-
path,
|
|
448
|
-
depth,
|
|
449
|
-
candidates
|
|
450
|
-
}) {
|
|
451
|
-
if (candidates.length >= DUPLICATE_NESTED_MAX_CANDIDATES_PER_SEGMENT) return;
|
|
452
|
-
if (depth > DUPLICATE_NESTED_MAX_DEPTH) return;
|
|
453
|
-
if (typeof value === "string") {
|
|
454
|
-
if (!nestedDuplicateFieldPath(path)) return;
|
|
455
|
-
const candidate = duplicateCandidateFromNestedText(segment, value, path);
|
|
456
|
-
if (candidate !== null) candidates.push(candidate);
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
if (Array.isArray(value)) {
|
|
460
|
-
value.forEach(
|
|
461
|
-
(item, index) => collectNestedDuplicateCandidates({
|
|
462
|
-
value: item,
|
|
463
|
-
segment,
|
|
464
|
-
path: [...path, `[${String(index)}]`],
|
|
465
|
-
depth: depth + 1,
|
|
466
|
-
candidates
|
|
467
|
-
})
|
|
468
|
-
);
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
if (!isPlainRecord(value)) return;
|
|
472
|
-
Object.entries(value).forEach(
|
|
473
|
-
([key, child]) => collectNestedDuplicateCandidates({
|
|
474
|
-
value: child,
|
|
475
|
-
segment,
|
|
476
|
-
path: [...path, key],
|
|
477
|
-
depth: depth + 1,
|
|
478
|
-
candidates
|
|
479
|
-
})
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
function duplicateCandidatesForSegment(segment) {
|
|
483
|
-
const segmentCandidate = duplicateCandidateFromSegment(segment);
|
|
484
|
-
const parsed = parseJsonLikeText(segment.text);
|
|
485
|
-
if (parsed === null) return [segmentCandidate];
|
|
486
|
-
const candidates = [];
|
|
487
|
-
collectNestedDuplicateCandidates({
|
|
488
|
-
value: parsed,
|
|
489
|
-
segment,
|
|
490
|
-
path: [],
|
|
491
|
-
depth: 0,
|
|
492
|
-
candidates
|
|
493
|
-
});
|
|
494
|
-
const normalizedSegment = normalizeDuplicateText(segment.text);
|
|
495
|
-
const seen = /* @__PURE__ */ new Set([normalizedSegment]);
|
|
496
|
-
const uniqueNested = candidates.filter((candidate) => {
|
|
497
|
-
const normalized = normalizeDuplicateText(candidate.text);
|
|
498
|
-
if (normalized === "") return false;
|
|
499
|
-
if (seen.has(normalized)) return false;
|
|
500
|
-
seen.add(normalized);
|
|
501
|
-
return true;
|
|
502
|
-
});
|
|
503
|
-
return [segmentCandidate, ...uniqueNested];
|
|
504
|
-
}
|
|
505
|
-
function duplicateContextGroups(segments) {
|
|
506
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
507
|
-
for (const segment of segments) {
|
|
508
|
-
const candidates = duplicateCandidatesForSegment(segment);
|
|
509
|
-
for (const candidate of candidates) {
|
|
510
|
-
if (candidate.tokens < DUPLICATE_MIN_TOKENS) continue;
|
|
511
|
-
if (candidate.characters < DUPLICATE_MIN_CHARS) continue;
|
|
512
|
-
const normalized = normalizeDuplicateText(candidate.text);
|
|
513
|
-
if (normalized === "") continue;
|
|
514
|
-
const existing = buckets.get(normalized);
|
|
515
|
-
if (existing === void 0) {
|
|
516
|
-
buckets.set(normalized, {
|
|
517
|
-
tokens: candidate.tokens,
|
|
518
|
-
candidates: [candidate]
|
|
519
|
-
});
|
|
520
|
-
continue;
|
|
521
|
-
}
|
|
522
|
-
buckets.set(normalized, {
|
|
523
|
-
tokens: existing.tokens + candidate.tokens,
|
|
524
|
-
candidates: [...existing.candidates, candidate]
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
const groups = [];
|
|
529
|
-
for (const bucket of buckets.values()) {
|
|
530
|
-
if (bucket.candidates.length < 2) continue;
|
|
531
|
-
const firstCandidate = bucket.candidates[0] ?? null;
|
|
532
|
-
if (firstCandidate === null) continue;
|
|
533
|
-
const repeatedTokens = bucket.tokens - firstCandidate.tokens;
|
|
534
|
-
groups.push({
|
|
535
|
-
key: `${firstCandidate.path}:${firstCandidate.label}:${String(
|
|
536
|
-
bucket.candidates.length
|
|
537
|
-
)}:${String(bucket.tokens)}`,
|
|
538
|
-
count: bucket.candidates.length,
|
|
539
|
-
totalTokens: bucket.tokens,
|
|
540
|
-
repeatedTokens,
|
|
541
|
-
preview: duplicatePreview(firstCandidate.text),
|
|
542
|
-
firstLabel: firstCandidate.label,
|
|
543
|
-
segments: bucket.candidates.map(duplicateSegmentRef)
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
return groups.sort(
|
|
547
|
-
(left, right) => right.repeatedTokens - left.repeatedTokens || right.totalTokens - left.totalTokens
|
|
548
|
-
);
|
|
549
|
-
}
|
|
550
|
-
function duplicateDiagnostic(duplicateGroups) {
|
|
551
|
-
if (duplicateGroups.length === 0) return null;
|
|
552
|
-
const repeatedGroups = duplicateGroups.length;
|
|
553
|
-
const repeatedSegments = duplicateGroups.reduce((sum, group) => sum + group.count, 0);
|
|
554
|
-
const repeatedTokens = duplicateGroups.reduce((sum, group) => sum + group.repeatedTokens, 0);
|
|
555
|
-
return {
|
|
556
|
-
kind: "duplicate",
|
|
557
|
-
severity: repeatedTokens >= LONG_TOOL_SCHEMA_TOKENS ? "danger" : "watch",
|
|
558
|
-
title: "Duplicate context",
|
|
559
|
-
detail: `${String(repeatedSegments)} repeated blocks across ${String(
|
|
560
|
-
repeatedGroups
|
|
561
|
-
)} group${repeatedGroups === 1 ? "" : "s"}, ~${String(repeatedTokens)} repeated tokens.`
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
function diagnosticsForRolePressure(roleUsages, total, messageSegmentCount) {
|
|
565
|
-
const diagnostics = [];
|
|
566
|
-
const toolUsage = roleUsages.find((usage) => usage.role === "tools") ?? null;
|
|
567
|
-
if (toolUsage !== null && (toolUsage.tokens >= LONG_TOOL_SCHEMA_TOKENS || toolUsage.percent >= LARGE_ROLE_PERCENT && toolUsage.tokens >= SYSTEM_HEAVY_TOKENS)) {
|
|
568
|
-
diagnostics.push({
|
|
569
|
-
kind: "tool-schema",
|
|
570
|
-
severity: toolUsage.tokens >= LONG_TOOL_SCHEMA_TOKENS ? "danger" : "watch",
|
|
571
|
-
title: "Large tool schema",
|
|
572
|
-
detail: `Tool definitions take ${Math.round(toolUsage.percent * 100)}% of request context.`
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
const systemUsage = roleUsages.find((usage) => usage.role === "system") ?? null;
|
|
576
|
-
if (systemUsage !== null && systemUsage.tokens >= SYSTEM_HEAVY_TOKENS && systemUsage.percent >= SYSTEM_HEAVY_PERCENT) {
|
|
577
|
-
diagnostics.push({
|
|
578
|
-
kind: "system-heavy",
|
|
579
|
-
severity: "watch",
|
|
580
|
-
title: "Large system prompt",
|
|
581
|
-
detail: `System instructions take ${Math.round(systemUsage.percent * 100)}% of request context.`
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
const historyTokens = roleUsages.filter((usage) => usage.role === "user" || usage.role === "assistant" || usage.role === "tool").reduce((sum, usage) => sum + usage.tokens, 0);
|
|
585
|
-
const historyPercent = total > 0 ? historyTokens / total : 0;
|
|
586
|
-
if (messageSegmentCount >= HISTORY_BLOAT_SEGMENTS && (historyTokens >= HISTORY_BLOAT_TOKENS || historyPercent >= HISTORY_BLOAT_PERCENT)) {
|
|
587
|
-
diagnostics.push({
|
|
588
|
-
kind: "history-bloat",
|
|
589
|
-
severity: historyPercent >= 0.85 ? "danger" : "watch",
|
|
590
|
-
title: "Conversation history growth",
|
|
591
|
-
detail: `${String(messageSegmentCount)} message blocks take ${Math.round(
|
|
592
|
-
historyPercent * 100
|
|
593
|
-
)}% of request context.`
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
return diagnostics;
|
|
597
|
-
}
|
|
598
|
-
function analyzeContextIntelligence({
|
|
599
|
-
segments,
|
|
600
|
-
inputTokens,
|
|
601
|
-
parsed,
|
|
602
|
-
model,
|
|
603
|
-
providers = []
|
|
604
|
-
}) {
|
|
605
|
-
const totalEstimatedTokens = segments.reduce((sum, segment) => sum + segment.size, 0);
|
|
606
|
-
const requestModel = model ?? readRequestModel(parsed);
|
|
607
|
-
const estimatedInputTokens = inputTokens ?? totalEstimatedTokens;
|
|
608
|
-
const outputReserveTokens = readPositiveIntegerField(parsed, OUTPUT_RESERVE_FIELDS);
|
|
609
|
-
const contextWindow = resolveContextWindow(requestModel, parsed, providers);
|
|
610
|
-
const reservedTokens = outputReserveTokens ?? 0;
|
|
611
|
-
const windowUsedTokens = contextWindow.tokens === null ? null : estimatedInputTokens + reservedTokens;
|
|
612
|
-
const remainingInputTokens = contextWindow.tokens === null ? null : contextWindow.tokens - estimatedInputTokens;
|
|
613
|
-
const remainingAfterReserveTokens = contextWindow.tokens === null ? null : contextWindow.tokens - estimatedInputTokens - reservedTokens;
|
|
614
|
-
const usagePercent = contextWindow.tokens === null || windowUsedTokens === null ? null : clampPercent(windowUsedTokens / contextWindow.tokens);
|
|
615
|
-
const roleUsages = buildRoleUsages(segments, totalEstimatedTokens);
|
|
616
|
-
const largestRole = roleUsages[0] ?? null;
|
|
617
|
-
const messageSegmentCount = segments.filter((segment) => segment.role !== "tools").length;
|
|
618
|
-
const duplicateGroups = duplicateContextGroups(segments);
|
|
619
|
-
const duplicate = duplicateDiagnostic(duplicateGroups);
|
|
620
|
-
const diagnostics = diagnosticsForRolePressure(
|
|
621
|
-
roleUsages,
|
|
622
|
-
totalEstimatedTokens,
|
|
623
|
-
messageSegmentCount
|
|
624
|
-
);
|
|
625
|
-
if (duplicate !== null) diagnostics.unshift(duplicate);
|
|
626
|
-
return {
|
|
627
|
-
model: requestModel,
|
|
628
|
-
contextWindow,
|
|
629
|
-
estimatedInputTokens,
|
|
630
|
-
outputReserveTokens,
|
|
631
|
-
windowUsedTokens,
|
|
632
|
-
remainingInputTokens,
|
|
633
|
-
remainingAfterReserveTokens,
|
|
634
|
-
usagePercent,
|
|
635
|
-
riskLevel: riskLevel(usagePercent),
|
|
636
|
-
roleUsages,
|
|
637
|
-
largestRole,
|
|
638
|
-
diagnostics,
|
|
639
|
-
duplicateGroups
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
const CONTEXT_USAGE_THRESHOLDS = {
|
|
643
|
-
watch: WATCH_USAGE_PERCENT,
|
|
644
|
-
danger: DANGER_USAGE_PERCENT
|
|
645
|
-
};
|
|
646
|
-
const ANATOMY_ROLE_LABELS = {
|
|
647
|
-
system: "System",
|
|
648
|
-
user: "User",
|
|
649
|
-
assistant: "Assistant",
|
|
650
|
-
tool: "Tool Results",
|
|
651
|
-
tools: "Tool Definitions"
|
|
652
|
-
};
|
|
653
|
-
const ROLE_COLOR_CLASSES = {
|
|
654
|
-
system: "bg-sky-500/70",
|
|
655
|
-
user: "bg-emerald-500/70",
|
|
656
|
-
assistant: "bg-violet-500/70",
|
|
657
|
-
tool: "bg-sky-400/55",
|
|
658
|
-
tools: "bg-slate-500/70"
|
|
659
|
-
};
|
|
660
|
-
const ROLE_FOCUS_RING = {
|
|
661
|
-
system: "focus-visible:ring-sky-300",
|
|
662
|
-
user: "focus-visible:ring-emerald-300",
|
|
663
|
-
assistant: "focus-visible:ring-violet-300",
|
|
664
|
-
tool: "focus-visible:ring-sky-300",
|
|
665
|
-
tools: "focus-visible:ring-slate-300"
|
|
666
|
-
};
|
|
667
|
-
const MAX_VISIBLE_SEGMENTS = 12;
|
|
668
|
-
const MIN_SEGMENT_PERCENT = 1;
|
|
669
|
-
const TOOLTIP_PREVIEW_LIMIT = 80;
|
|
670
|
-
const LABEL_TRUNCATE_LIMIT = 24;
|
|
671
|
-
function truncateLabel(label) {
|
|
672
|
-
if (label.length <= LABEL_TRUNCATE_LIMIT) return label;
|
|
673
|
-
return `${label.slice(0, LABEL_TRUNCATE_LIMIT - 3)}...`;
|
|
674
|
-
}
|
|
675
|
-
function truncatePreview(text) {
|
|
676
|
-
const singleLine = text.replace(/\s+/g, " ").trim();
|
|
677
|
-
if (singleLine.length <= TOOLTIP_PREVIEW_LIMIT) return singleLine;
|
|
678
|
-
return `${singleLine.slice(0, TOOLTIP_PREVIEW_LIMIT)}...`;
|
|
679
|
-
}
|
|
680
|
-
function formatPercent$1(value) {
|
|
681
|
-
if (value >= 10) return `${value.toFixed(0)}%`;
|
|
682
|
-
if (value >= 1) return `${value.toFixed(1)}%`;
|
|
683
|
-
if (value > 0) return "<1%";
|
|
684
|
-
return "0%";
|
|
685
|
-
}
|
|
686
|
-
const SegmentBar = reactExports.memo(function SegmentBar2({
|
|
687
|
-
segments,
|
|
688
|
-
totalTokens,
|
|
689
|
-
showLabels = true,
|
|
690
|
-
onActivate
|
|
691
|
-
}) {
|
|
692
|
-
const total = reactExports.useMemo(() => {
|
|
693
|
-
if (totalTokens > 0) return totalTokens;
|
|
694
|
-
return segments.reduce((sum, segment) => sum + segment.size, 0);
|
|
695
|
-
}, [segments, totalTokens]);
|
|
696
|
-
const visibleSegments = segments.slice(0, MAX_VISIBLE_SEGMENTS);
|
|
697
|
-
const overflowSegments = segments.slice(MAX_VISIBLE_SEGMENTS);
|
|
698
|
-
const overflowSize = overflowSegments.reduce((sum, segment) => sum + segment.size, 0);
|
|
699
|
-
const overflowCount = overflowSegments.length;
|
|
700
|
-
const overflowStartIndex = MAX_VISIBLE_SEGMENTS;
|
|
701
|
-
const overflowEndIndex = overflowStartIndex + overflowCount - 1;
|
|
702
|
-
const hasOverflow = overflowCount > 0;
|
|
703
|
-
const interactive = onActivate !== void 0;
|
|
704
|
-
const visibleTotal = reactExports.useMemo(
|
|
705
|
-
() => visibleSegments.reduce((sum, segment) => sum + segment.size, 0),
|
|
706
|
-
[visibleSegments]
|
|
707
|
-
);
|
|
708
|
-
const ariaLabel = reactExports.useMemo(
|
|
709
|
-
() => `Request context: ~${formatTokens(total)} tokens across ${segments.length} segment${segments.length === 1 ? "" : "s"}`,
|
|
710
|
-
[segments.length, total]
|
|
711
|
-
);
|
|
712
|
-
if (segments.length === 0 || total <= 0) {
|
|
713
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { role: "img", "aria-label": ariaLabel, className: "h-6" });
|
|
714
|
-
}
|
|
715
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipProvider, { delayDuration: 150, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { role: "img", "aria-label": ariaLabel, className: "flex flex-col gap-1.5", children: [
|
|
716
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
717
|
-
"div",
|
|
718
|
-
{
|
|
719
|
-
className: "relative flex h-6 w-full overflow-hidden rounded border border-border/40 bg-muted/30",
|
|
720
|
-
"data-testid": "anatomy-segment-bar",
|
|
721
|
-
children: [
|
|
722
|
-
visibleSegments.map((segment, index) => {
|
|
723
|
-
const rawPercent = total > 0 ? segment.size / total * 100 : 0;
|
|
724
|
-
const percent = Math.max(MIN_SEGMENT_PERCENT, rawPercent);
|
|
725
|
-
const segmentClassName = cn(
|
|
726
|
-
"h-full border-r border-background/80 last:border-r-0",
|
|
727
|
-
interactive ? "opacity-90 hover:opacity-100 focus:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background" : "opacity-90",
|
|
728
|
-
ROLE_COLOR_CLASSES[segment.role],
|
|
729
|
-
interactive ? ROLE_FOCUS_RING[segment.role] : ""
|
|
730
|
-
);
|
|
731
|
-
const segmentStyle = { width: `${percent}%` };
|
|
732
|
-
const ariaText = `${segment.label}, ${formatPercent$1(rawPercent)}, ~${formatTokens(
|
|
733
|
-
segment.size
|
|
734
|
-
)} tokens`;
|
|
735
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs(Tooltip, { children: [
|
|
736
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(TooltipTrigger, { asChild: true, children: interactive ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
737
|
-
"button",
|
|
738
|
-
{
|
|
739
|
-
type: "button",
|
|
740
|
-
role: "button",
|
|
741
|
-
tabIndex: 0,
|
|
742
|
-
onClick: () => onActivate(segment),
|
|
743
|
-
onKeyDown: (event) => {
|
|
744
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
745
|
-
event.preventDefault();
|
|
746
|
-
onActivate(segment);
|
|
747
|
-
}
|
|
748
|
-
},
|
|
749
|
-
"data-anatomy-path": segment.path,
|
|
750
|
-
"aria-label": ariaText,
|
|
751
|
-
className: segmentClassName,
|
|
752
|
-
style: segmentStyle
|
|
753
|
-
}
|
|
754
|
-
) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { "aria-label": ariaText, className: segmentClassName, style: segmentStyle }) }),
|
|
755
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(TooltipContent, { side: "bottom", className: "max-w-sm text-xs p-2 space-y-0.5", children: [
|
|
756
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-semibold", children: [
|
|
757
|
-
segment.label,
|
|
758
|
-
" - ",
|
|
759
|
-
formatPercent$1(rawPercent),
|
|
760
|
-
" - ~",
|
|
761
|
-
formatTokens(segment.size),
|
|
762
|
-
" ",
|
|
763
|
-
"tokens"
|
|
764
|
-
] }),
|
|
765
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground", children: ANATOMY_ROLE_LABELS[segment.role] }),
|
|
766
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-muted-foreground", children: [
|
|
767
|
-
segment.characters.toLocaleString(),
|
|
768
|
-
" chars"
|
|
769
|
-
] }),
|
|
770
|
-
segment.text.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground/90 break-words whitespace-pre-wrap", children: truncatePreview(segment.text) })
|
|
771
|
-
] })
|
|
772
|
-
] }, `${segment.path}-${index}`);
|
|
773
|
-
}),
|
|
774
|
-
hasOverflow && /* @__PURE__ */ jsxRuntimeExports.jsxs(Tooltip, { children: [
|
|
775
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
776
|
-
"div",
|
|
777
|
-
{
|
|
778
|
-
role: "img",
|
|
779
|
-
"aria-label": `${overflowCount} additional segments`,
|
|
780
|
-
className: "flex h-full items-center justify-center bg-muted-foreground/30 px-1.5 text-[10px] font-mono text-background",
|
|
781
|
-
style: {
|
|
782
|
-
width: `${Math.max(MIN_SEGMENT_PERCENT, overflowSize / total * 100)}%`
|
|
783
|
-
},
|
|
784
|
-
children: [
|
|
785
|
-
"... +",
|
|
786
|
-
overflowCount
|
|
787
|
-
]
|
|
788
|
-
}
|
|
789
|
-
) }),
|
|
790
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(TooltipContent, { side: "bottom", className: "text-xs", children: [
|
|
791
|
-
overflowCount,
|
|
792
|
-
" more segment",
|
|
793
|
-
overflowCount === 1 ? "" : "s",
|
|
794
|
-
" (indices",
|
|
795
|
-
" ",
|
|
796
|
-
overflowStartIndex,
|
|
797
|
-
"-",
|
|
798
|
-
overflowEndIndex,
|
|
799
|
-
")"
|
|
800
|
-
] })
|
|
801
|
-
] })
|
|
802
|
-
]
|
|
803
|
-
}
|
|
804
|
-
),
|
|
805
|
-
showLabels && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex w-full gap-1 text-[10px] text-muted-foreground", children: [
|
|
806
|
-
visibleSegments.map((segment, index) => {
|
|
807
|
-
const rawPercent = total > 0 ? segment.size / total * 100 : 0;
|
|
808
|
-
const percent = Math.max(MIN_SEGMENT_PERCENT, rawPercent);
|
|
809
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
810
|
-
"div",
|
|
811
|
-
{
|
|
812
|
-
className: "flex flex-col gap-0.5 truncate",
|
|
813
|
-
style: { width: `${percent}%` },
|
|
814
|
-
title: `${segment.label} - ${formatPercent$1(rawPercent)} - ~${formatTokens(
|
|
815
|
-
segment.size
|
|
816
|
-
)} tokens`,
|
|
817
|
-
children: [
|
|
818
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate font-mono text-foreground/80", children: truncateLabel(segment.label) }),
|
|
819
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "truncate font-mono text-muted-foreground/70", children: [
|
|
820
|
-
formatPercent$1(rawPercent),
|
|
821
|
-
" - ~",
|
|
822
|
-
formatTokens(segment.size)
|
|
823
|
-
] })
|
|
824
|
-
]
|
|
825
|
-
},
|
|
826
|
-
`label-${segment.path}-${index}`
|
|
827
|
-
);
|
|
828
|
-
}),
|
|
829
|
-
hasOverflow && /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
830
|
-
"div",
|
|
831
|
-
{
|
|
832
|
-
className: "flex flex-col gap-0.5 truncate text-muted-foreground",
|
|
833
|
-
style: { width: `${Math.max(MIN_SEGMENT_PERCENT, overflowSize / total * 100)}%` },
|
|
834
|
-
children: [
|
|
835
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "truncate font-mono text-foreground/60", children: [
|
|
836
|
-
"... +",
|
|
837
|
-
overflowCount
|
|
838
|
-
] }),
|
|
839
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "truncate font-mono text-muted-foreground/60", children: [
|
|
840
|
-
"~",
|
|
841
|
-
formatTokens(overflowSize)
|
|
842
|
-
] })
|
|
843
|
-
]
|
|
844
|
-
}
|
|
845
|
-
)
|
|
846
|
-
] }),
|
|
847
|
-
visibleTotal < total * 0.1 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-0" })
|
|
848
|
-
] }) });
|
|
849
|
-
});
|
|
850
|
-
const DIVERGENCE_AMBER_THRESHOLD = 0.25;
|
|
851
|
-
const TOP_CONTRIBUTOR_COUNT = 5;
|
|
852
|
-
const DUPLICATE_GROUP_DISPLAY_COUNT = 4;
|
|
853
|
-
const DUPLICATE_SEGMENT_DISPLAY_COUNT = 6;
|
|
854
|
-
const ROLE_ORDER = ["system", "user", "assistant", "tool", "tools"];
|
|
855
|
-
const ROLE_DESCRIPTIONS = {
|
|
856
|
-
system: "instructions",
|
|
857
|
-
user: "user turns",
|
|
858
|
-
assistant: "assistant turns",
|
|
859
|
-
tool: "tool results",
|
|
860
|
-
tools: "tool schemas"
|
|
861
|
-
};
|
|
862
|
-
const VIEW_MODE_OPTIONS = [
|
|
863
|
-
{ value: "role", label: "By Role" },
|
|
864
|
-
{ value: "segment", label: "By Segment" }
|
|
865
|
-
];
|
|
866
|
-
const RISK_CLASS = {
|
|
867
|
-
unknown: "bg-muted-foreground/50",
|
|
868
|
-
ok: "bg-emerald-500/70",
|
|
869
|
-
watch: "bg-amber-400/75",
|
|
870
|
-
danger: "bg-red-500/80"
|
|
871
|
-
};
|
|
872
|
-
const RISK_TEXT_CLASS = {
|
|
873
|
-
unknown: "text-muted-foreground",
|
|
874
|
-
ok: "text-emerald-400",
|
|
875
|
-
watch: "text-amber-300",
|
|
876
|
-
danger: "text-red-300"
|
|
877
|
-
};
|
|
878
|
-
function formatPercent(value) {
|
|
879
|
-
if (value >= 10) return `${value.toFixed(0)}%`;
|
|
880
|
-
if (value >= 1) return `${value.toFixed(1)}%`;
|
|
881
|
-
if (value > 0) return "<1%";
|
|
882
|
-
return "0%";
|
|
883
|
-
}
|
|
884
|
-
function formatUsagePercent(value) {
|
|
885
|
-
if (value === null) return "Unknown";
|
|
886
|
-
return formatPercent(value * 100);
|
|
887
|
-
}
|
|
888
|
-
function formatRemainingTokens(value) {
|
|
889
|
-
if (value === null) return "Unknown";
|
|
890
|
-
if (value < 0) return `-${formatTokens(Math.abs(value))}`;
|
|
891
|
-
return formatTokens(value);
|
|
892
|
-
}
|
|
893
|
-
function formatContextLimit(intelligence) {
|
|
894
|
-
if (intelligence.contextWindow.tokens === null) return "Unknown";
|
|
895
|
-
return formatTokens(intelligence.contextWindow.tokens);
|
|
896
|
-
}
|
|
897
|
-
function formatContextSource(intelligence) {
|
|
898
|
-
switch (intelligence.contextWindow.source) {
|
|
899
|
-
case "request":
|
|
900
|
-
return intelligence.contextWindow.label;
|
|
901
|
-
case "provider":
|
|
902
|
-
return intelligence.contextWindow.label;
|
|
903
|
-
case "model-rule":
|
|
904
|
-
return intelligence.contextWindow.label;
|
|
905
|
-
case "unknown":
|
|
906
|
-
return intelligence.model === null ? intelligence.contextWindow.label : `${intelligence.contextWindow.label}: ${intelligence.model}`;
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
function diagnosticTone(diagnostic) {
|
|
910
|
-
switch (diagnostic.severity) {
|
|
911
|
-
case "watch":
|
|
912
|
-
return "border-amber-400/30 bg-amber-400/8 text-amber-100";
|
|
913
|
-
case "danger":
|
|
914
|
-
return "border-red-400/35 bg-red-500/10 text-red-100";
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
function ContextIntelligenceStrip({
|
|
918
|
-
intelligence
|
|
919
|
-
}) {
|
|
920
|
-
const usageWidth = intelligence.usagePercent === null ? 0 : Math.max(1, intelligence.usagePercent * 100);
|
|
921
|
-
const outputReserveLabel = intelligence.outputReserveTokens === null ? "No output reserve" : `Output reserve ${formatTokens(intelligence.outputReserveTokens)}`;
|
|
922
|
-
const largestRole = intelligence.largestRole;
|
|
923
|
-
const visibleDiagnostics = intelligence.duplicateGroups.length === 0 ? intelligence.diagnostics : intelligence.diagnostics.filter((diagnostic) => diagnostic.kind !== "duplicate");
|
|
924
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
|
|
925
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid gap-x-4 gap-y-2 border-y border-border/60 py-2 text-xs sm:grid-cols-4", children: [
|
|
926
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
927
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] font-medium uppercase text-muted-foreground", children: "Window" }),
|
|
928
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-0.5 truncate font-mono text-foreground", children: formatContextLimit(intelligence) }),
|
|
929
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "truncate text-[11px] text-muted-foreground", children: formatContextSource(intelligence) })
|
|
930
|
-
] }),
|
|
931
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
932
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] font-medium uppercase text-muted-foreground", children: "Used" }),
|
|
933
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: cn("mt-0.5 font-mono", RISK_TEXT_CLASS[intelligence.riskLevel]), children: formatUsagePercent(intelligence.usagePercent) }),
|
|
934
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "truncate text-[11px] text-muted-foreground", children: outputReserveLabel })
|
|
935
|
-
] }),
|
|
936
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
937
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] font-medium uppercase text-muted-foreground", children: "Remaining" }),
|
|
938
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-0.5 font-mono text-foreground", children: formatRemainingTokens(intelligence.remainingAfterReserveTokens) }),
|
|
939
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "truncate text-[11px] text-muted-foreground", children: [
|
|
940
|
-
"Input only ",
|
|
941
|
-
formatRemainingTokens(intelligence.remainingInputTokens)
|
|
942
|
-
] })
|
|
943
|
-
] }),
|
|
944
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
945
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] font-medium uppercase text-muted-foreground", children: "Largest" }),
|
|
946
|
-
largestRole === null ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-0.5 text-muted-foreground", children: "Unknown" }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
947
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-0.5 flex min-w-0 items-center gap-1.5", children: [
|
|
948
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
949
|
-
"span",
|
|
950
|
-
{
|
|
951
|
-
"aria-hidden": "true",
|
|
952
|
-
className: cn(
|
|
953
|
-
"size-2.5 shrink-0 rounded-[2px]",
|
|
954
|
-
ROLE_COLOR_CLASSES[largestRole.role]
|
|
955
|
-
)
|
|
956
|
-
}
|
|
957
|
-
),
|
|
958
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate text-foreground", children: largestRole.label })
|
|
959
|
-
] }),
|
|
960
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "truncate font-mono text-[11px] text-muted-foreground", children: [
|
|
961
|
-
formatPercent(largestRole.percent * 100),
|
|
962
|
-
" | ~",
|
|
963
|
-
formatTokens(largestRole.tokens)
|
|
964
|
-
] })
|
|
965
|
-
] })
|
|
966
|
-
] })
|
|
967
|
-
] }),
|
|
968
|
-
intelligence.contextWindow.tokens !== null && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
|
|
969
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative h-2 overflow-hidden rounded-full bg-muted/40", children: [
|
|
970
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
971
|
-
"div",
|
|
972
|
-
{
|
|
973
|
-
className: cn("h-full rounded-full", RISK_CLASS[intelligence.riskLevel]),
|
|
974
|
-
style: { width: `${String(usageWidth)}%` }
|
|
975
|
-
}
|
|
976
|
-
),
|
|
977
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
978
|
-
"div",
|
|
979
|
-
{
|
|
980
|
-
"aria-hidden": "true",
|
|
981
|
-
className: "absolute top-0 h-full w-px bg-amber-200/70",
|
|
982
|
-
style: { left: `${String(CONTEXT_USAGE_THRESHOLDS.watch * 100)}%` }
|
|
983
|
-
}
|
|
984
|
-
),
|
|
985
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
986
|
-
"div",
|
|
987
|
-
{
|
|
988
|
-
"aria-hidden": "true",
|
|
989
|
-
className: "absolute top-0 h-full w-px bg-red-200/80",
|
|
990
|
-
style: { left: `${String(CONTEXT_USAGE_THRESHOLDS.danger * 100)}%` }
|
|
991
|
-
}
|
|
992
|
-
)
|
|
993
|
-
] }),
|
|
994
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-[10px] text-muted-foreground", children: [
|
|
995
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Context window" }),
|
|
996
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
|
|
997
|
-
"Watch ",
|
|
998
|
-
formatUsagePercent(CONTEXT_USAGE_THRESHOLDS.watch),
|
|
999
|
-
" / Danger",
|
|
1000
|
-
" ",
|
|
1001
|
-
formatUsagePercent(CONTEXT_USAGE_THRESHOLDS.danger)
|
|
1002
|
-
] })
|
|
1003
|
-
] })
|
|
1004
|
-
] }),
|
|
1005
|
-
visibleDiagnostics.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid gap-1.5 sm:grid-cols-2", children: visibleDiagnostics.map((diagnostic) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
1006
|
-
"div",
|
|
1007
|
-
{
|
|
1008
|
-
className: cn("rounded border px-2 py-1.5 text-xs", diagnosticTone(diagnostic)),
|
|
1009
|
-
children: [
|
|
1010
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium", children: diagnostic.title }),
|
|
1011
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-0.5 text-[11px] text-muted-foreground", children: diagnostic.detail })
|
|
1012
|
-
]
|
|
1013
|
-
},
|
|
1014
|
-
`${diagnostic.kind}-${diagnostic.title}`
|
|
1015
|
-
)) })
|
|
1016
|
-
] });
|
|
1017
|
-
}
|
|
1018
|
-
function resolveDuplicateSegment(duplicateSegment, segments) {
|
|
1019
|
-
return segments.find((segment) => segment.path === duplicateSegment.path) ?? null;
|
|
1020
|
-
}
|
|
1021
|
-
function DuplicateContentPanel({
|
|
1022
|
-
groups,
|
|
1023
|
-
segments,
|
|
1024
|
-
onSegmentActivate
|
|
1025
|
-
}) {
|
|
1026
|
-
if (groups.length === 0) return null;
|
|
1027
|
-
const visibleGroups = groups.slice(0, DUPLICATE_GROUP_DISPLAY_COUNT);
|
|
1028
|
-
const hiddenGroupCount = groups.length - visibleGroups.length;
|
|
1029
|
-
const totalRepeatedTokens = groups.reduce((sum, group) => sum + group.repeatedTokens, 0);
|
|
1030
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "space-y-2 rounded border border-border/70 bg-muted/15 p-2", children: [
|
|
1031
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
|
|
1032
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-medium text-foreground", children: "Duplicate Content" }),
|
|
1033
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-mono text-[11px] text-muted-foreground", children: [
|
|
1034
|
-
String(groups.length),
|
|
1035
|
-
" group",
|
|
1036
|
-
groups.length === 1 ? "" : "s",
|
|
1037
|
-
" | ~",
|
|
1038
|
-
formatTokens(totalRepeatedTokens),
|
|
1039
|
-
" repeated"
|
|
1040
|
-
] })
|
|
1041
|
-
] }),
|
|
1042
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-2", children: visibleGroups.map((group, groupIndex) => {
|
|
1043
|
-
const visibleSegments = group.segments.slice(0, DUPLICATE_SEGMENT_DISPLAY_COUNT);
|
|
1044
|
-
const hiddenSegmentCount = group.segments.length - visibleSegments.length;
|
|
1045
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
1046
|
-
"div",
|
|
1047
|
-
{
|
|
1048
|
-
className: "space-y-1.5 border-t border-border/50 pt-2 first:border-t-0 first:pt-0",
|
|
1049
|
-
children: [
|
|
1050
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex min-w-0 items-center gap-2 text-xs", children: [
|
|
1051
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "w-5 shrink-0 text-right font-mono text-muted-foreground/70", children: String(groupIndex + 1) }),
|
|
1052
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "min-w-0 flex-1 truncate text-foreground", children: group.firstLabel }),
|
|
1053
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "shrink-0 font-mono text-muted-foreground", children: [
|
|
1054
|
-
"x",
|
|
1055
|
-
String(group.count),
|
|
1056
|
-
" | ~",
|
|
1057
|
-
formatTokens(group.repeatedTokens),
|
|
1058
|
-
" saved"
|
|
1059
|
-
] })
|
|
1060
|
-
] }),
|
|
1061
|
-
group.preview.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "ml-7 line-clamp-2 break-words rounded bg-background/40 px-2 py-1 font-mono text-[11px] leading-4 text-muted-foreground", children: group.preview }),
|
|
1062
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "ml-7 flex flex-wrap gap-1", children: [
|
|
1063
|
-
visibleSegments.map((duplicateSegment, segmentIndex) => {
|
|
1064
|
-
const target = resolveDuplicateSegment(duplicateSegment, segments);
|
|
1065
|
-
const activate = target === null || onSegmentActivate === void 0 ? void 0 : onSegmentActivate;
|
|
1066
|
-
const label = `${duplicateSegment.label} ~${formatTokens(
|
|
1067
|
-
duplicateSegment.tokens
|
|
1068
|
-
)}`;
|
|
1069
|
-
if (activate === void 0 || target === null) {
|
|
1070
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1071
|
-
"span",
|
|
1072
|
-
{
|
|
1073
|
-
className: "inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground",
|
|
1074
|
-
title: label,
|
|
1075
|
-
children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate", children: label })
|
|
1076
|
-
},
|
|
1077
|
-
`${duplicateSegment.path}-${segmentIndex}`
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1081
|
-
"button",
|
|
1082
|
-
{
|
|
1083
|
-
type: "button",
|
|
1084
|
-
onClick: () => activate(target),
|
|
1085
|
-
className: "inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",
|
|
1086
|
-
title: "Jump to this duplicate block",
|
|
1087
|
-
children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate", children: label })
|
|
1088
|
-
},
|
|
1089
|
-
`${duplicateSegment.path}-${segmentIndex}`
|
|
1090
|
-
);
|
|
1091
|
-
}),
|
|
1092
|
-
hiddenSegmentCount > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex h-6 items-center rounded border border-border/40 px-1.5 font-mono text-[11px] text-muted-foreground/70", children: [
|
|
1093
|
-
"+",
|
|
1094
|
-
String(hiddenSegmentCount)
|
|
1095
|
-
] })
|
|
1096
|
-
] })
|
|
1097
|
-
]
|
|
1098
|
-
},
|
|
1099
|
-
group.key
|
|
1100
|
-
);
|
|
1101
|
-
}) }),
|
|
1102
|
-
hiddenGroupCount > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "border-t border-border/50 pt-2 font-mono text-[11px] text-muted-foreground", children: [
|
|
1103
|
-
"+",
|
|
1104
|
-
String(hiddenGroupCount),
|
|
1105
|
-
" more duplicate group",
|
|
1106
|
-
hiddenGroupCount === 1 ? "" : "s"
|
|
1107
|
-
] })
|
|
1108
|
-
] });
|
|
1109
|
-
}
|
|
1110
|
-
function aggregateByRole(segments) {
|
|
1111
|
-
const result = [];
|
|
1112
|
-
for (const role of ROLE_ORDER) {
|
|
1113
|
-
const matching = segments.filter((segment) => segment.role === role);
|
|
1114
|
-
if (matching.length === 0) continue;
|
|
1115
|
-
const size = matching.reduce((sum, segment) => sum + segment.size, 0);
|
|
1116
|
-
const characters = matching.reduce((sum, segment) => sum + segment.characters, 0);
|
|
1117
|
-
const label = ANATOMY_ROLE_LABELS[role];
|
|
1118
|
-
const text = `${matching.length} segment${matching.length === 1 ? "" : "s"} grouped as ${ROLE_DESCRIPTIONS[role]}`;
|
|
1119
|
-
result.push({
|
|
1120
|
-
role,
|
|
1121
|
-
label,
|
|
1122
|
-
size,
|
|
1123
|
-
characters,
|
|
1124
|
-
text,
|
|
1125
|
-
path: `role:${role}`
|
|
1126
|
-
});
|
|
1127
|
-
}
|
|
1128
|
-
return result;
|
|
1129
|
-
}
|
|
1130
|
-
function topContributors(segments) {
|
|
1131
|
-
return [...segments].sort((a, b) => b.size - a.size).slice(0, TOP_CONTRIBUTOR_COUNT);
|
|
1132
|
-
}
|
|
1133
|
-
function RequestAnatomy({
|
|
1134
|
-
parsed,
|
|
1135
|
-
inputTokens,
|
|
1136
|
-
model = null,
|
|
1137
|
-
onSegmentActivate,
|
|
1138
|
-
segments: providedSegments
|
|
1139
|
-
}) {
|
|
1140
|
-
const { providers } = useProviders();
|
|
1141
|
-
const [viewMode, setViewMode] = reactExports.useState("role");
|
|
1142
|
-
const segments = reactExports.useMemo(() => providedSegments ?? null, [providedSegments]);
|
|
1143
|
-
const total = reactExports.useMemo(
|
|
1144
|
-
() => (segments ?? []).reduce((sum, segment) => sum + segment.size, 0),
|
|
1145
|
-
[segments]
|
|
1146
|
-
);
|
|
1147
|
-
const roleSegments = reactExports.useMemo(
|
|
1148
|
-
() => segments === null ? [] : aggregateByRole(segments),
|
|
1149
|
-
[segments]
|
|
1150
|
-
);
|
|
1151
|
-
const topSegments = reactExports.useMemo(
|
|
1152
|
-
() => segments === null ? [] : topContributors(segments),
|
|
1153
|
-
[segments]
|
|
1154
|
-
);
|
|
1155
|
-
const intelligence = reactExports.useMemo(
|
|
1156
|
-
() => segments === null ? null : analyzeContextIntelligence({
|
|
1157
|
-
segments,
|
|
1158
|
-
inputTokens,
|
|
1159
|
-
parsed,
|
|
1160
|
-
model,
|
|
1161
|
-
providers
|
|
1162
|
-
}),
|
|
1163
|
-
[inputTokens, model, parsed, providers, segments]
|
|
1164
|
-
);
|
|
1165
|
-
const showDivergenceWarning = reactExports.useMemo(() => {
|
|
1166
|
-
if (segments === null) return false;
|
|
1167
|
-
if (inputTokens === null) return false;
|
|
1168
|
-
if (total === 0) return false;
|
|
1169
|
-
const ratio = Math.abs(inputTokens - total) / Math.max(inputTokens, total);
|
|
1170
|
-
return ratio >= DIVERGENCE_AMBER_THRESHOLD;
|
|
1171
|
-
}, [inputTokens, segments, total]);
|
|
1172
|
-
if (segments === null) return null;
|
|
1173
|
-
if (segments.length === 0) return null;
|
|
1174
|
-
if (parsed === null && providedSegments === void 0) return null;
|
|
1175
|
-
const summaryColorClass = inputTokens !== null && showDivergenceWarning ? "text-amber-400" : "text-muted-foreground";
|
|
1176
|
-
const displayedSegments = viewMode === "role" ? roleSegments : segments;
|
|
1177
|
-
const displayedTotal = total > 0 ? total : displayedSegments.reduce((sum, item) => sum + item.size, 0);
|
|
1178
|
-
const activateSegment = viewMode === "segment" ? onSegmentActivate : void 0;
|
|
1179
|
-
const segmentCountLabel = `${String(segments.length)} segment${segments.length === 1 ? "" : "s"}`;
|
|
1180
|
-
const providerInputLabel = inputTokens === null ? "Provider input unknown" : `Provider input ${formatTokens(inputTokens)}`;
|
|
1181
|
-
const contextLimitLabel = intelligence === null ? "Limit unknown" : `Limit ${formatContextLimit(intelligence)}`;
|
|
1182
|
-
const usageLabel = intelligence === null ? "Usage unknown" : `${formatUsagePercent(intelligence.usagePercent)} used`;
|
|
1183
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipProvider, { delayDuration: 150, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-4 py-3 space-y-3", "data-testid": "anatomy-root", children: [
|
|
1184
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [
|
|
1185
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
1186
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-semibold text-foreground", children: "Request Context" }),
|
|
1187
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cn("mt-0.5 text-xs font-mono tabular-nums", summaryColorClass), children: [
|
|
1188
|
-
"Estimated ~",
|
|
1189
|
-
formatTokens(total),
|
|
1190
|
-
" tokens | ",
|
|
1191
|
-
providerInputLabel,
|
|
1192
|
-
" | ",
|
|
1193
|
-
contextLimitLabel,
|
|
1194
|
-
" |",
|
|
1195
|
-
" ",
|
|
1196
|
-
usageLabel,
|
|
1197
|
-
" | ",
|
|
1198
|
-
segmentCountLabel
|
|
1199
|
-
] })
|
|
1200
|
-
] }),
|
|
1201
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1202
|
-
"div",
|
|
1203
|
-
{
|
|
1204
|
-
className: "inline-flex shrink-0 rounded border border-border bg-muted/20 p-0.5",
|
|
1205
|
-
role: "group",
|
|
1206
|
-
"aria-label": "Context breakdown mode",
|
|
1207
|
-
children: VIEW_MODE_OPTIONS.map((option) => /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1208
|
-
"button",
|
|
1209
|
-
{
|
|
1210
|
-
type: "button",
|
|
1211
|
-
"aria-pressed": viewMode === option.value,
|
|
1212
|
-
onClick: () => setViewMode(option.value),
|
|
1213
|
-
className: cn(
|
|
1214
|
-
"h-6 rounded-sm px-2 text-[11px] font-medium transition-colors",
|
|
1215
|
-
viewMode === option.value ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
1216
|
-
),
|
|
1217
|
-
children: option.label
|
|
1218
|
-
},
|
|
1219
|
-
option.value
|
|
1220
|
-
))
|
|
1221
|
-
}
|
|
1222
|
-
)
|
|
1223
|
-
] }),
|
|
1224
|
-
showDivergenceWarning && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "inline-flex items-center gap-1.5 text-xs text-amber-400", children: [
|
|
1225
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(Tooltip, { children: [
|
|
1226
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1227
|
-
"button",
|
|
1228
|
-
{
|
|
1229
|
-
type: "button",
|
|
1230
|
-
className: "inline-flex items-center hover:text-amber-300",
|
|
1231
|
-
"aria-label": "Token estimate differs from provider input",
|
|
1232
|
-
children: /* @__PURE__ */ jsxRuntimeExports.jsx(Info, { className: "size-3.5" })
|
|
1233
|
-
}
|
|
1234
|
-
) }),
|
|
1235
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(TooltipContent, { className: "max-w-xs text-xs", children: "The bar uses a local token estimate. Provider input tokens remain the source of truth for billing and context-window usage." })
|
|
1236
|
-
] }),
|
|
1237
|
-
"Estimate differs from provider-reported input."
|
|
1238
|
-
] }),
|
|
1239
|
-
intelligence !== null && /* @__PURE__ */ jsxRuntimeExports.jsx(ContextIntelligenceStrip, { intelligence }),
|
|
1240
|
-
intelligence !== null && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1241
|
-
DuplicateContentPanel,
|
|
1242
|
-
{
|
|
1243
|
-
groups: intelligence.duplicateGroups,
|
|
1244
|
-
segments,
|
|
1245
|
-
onSegmentActivate
|
|
1246
|
-
}
|
|
1247
|
-
),
|
|
1248
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1249
|
-
SegmentBar,
|
|
1250
|
-
{
|
|
1251
|
-
segments: displayedSegments,
|
|
1252
|
-
totalTokens: displayedTotal,
|
|
1253
|
-
showLabels: viewMode === "segment",
|
|
1254
|
-
onActivate: activateSegment
|
|
1255
|
-
}
|
|
1256
|
-
),
|
|
1257
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[11px] text-muted-foreground", children: roleSegments.map((segment) => {
|
|
1258
|
-
const percent = total > 0 ? segment.size / total * 100 : 0;
|
|
1259
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "inline-flex items-center gap-1.5", children: [
|
|
1260
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1261
|
-
"span",
|
|
1262
|
-
{
|
|
1263
|
-
"aria-hidden": "true",
|
|
1264
|
-
className: cn("size-2.5 rounded-[2px]", ROLE_COLOR_CLASSES[segment.role])
|
|
1265
|
-
}
|
|
1266
|
-
),
|
|
1267
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: segment.label }),
|
|
1268
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono text-muted-foreground/70", children: formatPercent(percent) })
|
|
1269
|
-
] }, segment.role);
|
|
1270
|
-
}) }),
|
|
1271
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
|
|
1272
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-medium text-foreground", children: "Top Contributors" }),
|
|
1273
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid gap-1", children: topSegments.map((segment, index) => {
|
|
1274
|
-
const percent = total > 0 ? segment.size / total * 100 : 0;
|
|
1275
|
-
const activate = onSegmentActivate;
|
|
1276
|
-
const content = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
1277
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "w-5 shrink-0 text-right font-mono text-muted-foreground/70", children: String(index + 1) }),
|
|
1278
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1279
|
-
"span",
|
|
1280
|
-
{
|
|
1281
|
-
"aria-hidden": "true",
|
|
1282
|
-
className: cn(
|
|
1283
|
-
"size-2.5 shrink-0 rounded-[2px]",
|
|
1284
|
-
ROLE_COLOR_CLASSES[segment.role]
|
|
1285
|
-
)
|
|
1286
|
-
}
|
|
1287
|
-
),
|
|
1288
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "min-w-0 flex-1 truncate text-left", children: segment.label }),
|
|
1289
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "shrink-0 font-mono text-muted-foreground", children: [
|
|
1290
|
-
formatPercent(percent),
|
|
1291
|
-
" | ~",
|
|
1292
|
-
formatTokens(segment.size)
|
|
1293
|
-
] })
|
|
1294
|
-
] });
|
|
1295
|
-
if (activate !== void 0) {
|
|
1296
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1297
|
-
"button",
|
|
1298
|
-
{
|
|
1299
|
-
type: "button",
|
|
1300
|
-
onClick: () => activate(segment),
|
|
1301
|
-
className: "flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",
|
|
1302
|
-
title: "Jump to this request block",
|
|
1303
|
-
children: content
|
|
1304
|
-
},
|
|
1305
|
-
`${segment.path}-${index}`
|
|
1306
|
-
);
|
|
1307
|
-
}
|
|
1308
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1309
|
-
"div",
|
|
1310
|
-
{
|
|
1311
|
-
className: "flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",
|
|
1312
|
-
children: content
|
|
1313
|
-
},
|
|
1314
|
-
`${segment.path}-${index}`
|
|
1315
|
-
);
|
|
1316
|
-
}) })
|
|
1317
|
-
] })
|
|
1318
|
-
] }) });
|
|
1319
|
-
}
|
|
1320
|
-
export {
|
|
1321
|
-
RequestAnatomy
|
|
1322
|
-
};
|