@tonyclaw/agent-inspector 2.0.11 → 2.0.13
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-C9OWdxHM.js → CompareDrawer-CrMyE23D.js} +1 -1
- package/.output/public/assets/ProxyViewerContainer-BZuo0px3.js +114 -0
- package/.output/public/assets/{ReplayDialog-CwE6I1Pe.js → ReplayDialog-TQGhDdTa.js} +1 -1
- package/.output/public/assets/RequestAnatomy-D6kQYtfa.js +1 -0
- package/.output/public/assets/ResponseView-C6ybWuB8.js +1 -0
- package/.output/public/assets/{StreamingChunkSequence-CLcLZ7-W.js → StreamingChunkSequence-Bvs59_-I.js} +1 -1
- package/.output/public/assets/_sessionId-BNG_mnaH.js +1 -0
- package/.output/public/assets/index-BUxIwHhC.js +1 -0
- package/.output/public/assets/index-D_nZj9Vt.css +1 -0
- package/.output/public/assets/{main-D1Xanzu7.js → main-DvFSJlOd.js} +2 -2
- package/.output/server/_libs/lucide-react.mjs +51 -39
- package/.output/server/{_sessionId-D3IyPpws.mjs → _sessionId-DHYJxPb7.mjs} +2 -2
- package/.output/server/_ssr/{CompareDrawer-BIMThqxy.mjs → CompareDrawer-meimDBeA.mjs} +3 -3
- package/.output/server/_ssr/{ProxyViewerContainer-BiBdKWtj.mjs → ProxyViewerContainer-Co-WKq6u.mjs} +1610 -183
- package/.output/server/_ssr/{ReplayDialog-D_wiDyM2.mjs → ReplayDialog-cclcGyR9.mjs} +4 -4
- package/.output/server/_ssr/RequestAnatomy-to_rezzu.mjs +882 -0
- package/.output/server/_ssr/{ResponseView-Drk5ghmL.mjs → ResponseView-CZZI4IZd.mjs} +3 -3
- package/.output/server/_ssr/{StreamingChunkSequence-F889rmG0.mjs → StreamingChunkSequence-BTF4xSYX.mjs} +2 -2
- package/.output/server/_ssr/{index-CaPniq9z.mjs → index-D2fpJFP5.mjs} +2 -2
- package/.output/server/_ssr/index.mjs +2 -2
- package/.output/server/_ssr/{router-C7S8FRth.mjs → router-RDBAF-Iu.mjs} +85 -22
- package/.output/server/{_tanstack-start-manifest_v-CVTkFOdT.mjs → _tanstack-start-manifest_v-DB9sseoH.mjs} +1 -1
- package/.output/server/index.mjs +58 -58
- package/package.json +1 -1
- package/src/components/ProxyViewer.tsx +454 -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 +366 -99
- package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +22 -4
- 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-CNzay4u8.js +0 -114
- package/.output/public/assets/RequestAnatomy-DEehC3yz.js +0 -1
- package/.output/public/assets/ResponseView-CE5UsuUq.js +0 -1
- package/.output/public/assets/_sessionId-DE__tPTo.js +0 -1
- package/.output/public/assets/index-BFO4Jmw5.js +0 -1
- package/.output/public/assets/index-CDzZ7l_S.css +0 -1
- package/.output/server/_ssr/RequestAnatomy-5UiMTESr.mjs +0 -1383
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
import { r as reactExports, j as jsxRuntimeExports } from "../_libs/react.mjs";
|
|
2
|
+
import { u as useProviders, p as analyzeContextIntelligence, f as formatTokens, k as TooltipProvider, c as cn, l as Tooltip, m as TooltipTrigger, n as TooltipContent, S as SegmentBar, R as ROLE_COLOR_CLASSES, A as ANATOMY_ROLE_LABELS, q as formatContextWindowTokens, C as CONTEXT_USAGE_THRESHOLDS } from "./ProxyViewerContainer-Co-WKq6u.mjs";
|
|
3
|
+
import "./router-RDBAF-Iu.mjs";
|
|
4
|
+
import "../_libs/modelcontextprotocol__server.mjs";
|
|
5
|
+
import "../_libs/jszip.mjs";
|
|
6
|
+
import { ac as Info, b as ChevronDown, f as ChevronRight } 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 DIVERGENCE_AMBER_THRESHOLD = 0.25;
|
|
169
|
+
const TOP_CONTRIBUTOR_COUNT = 5;
|
|
170
|
+
const DUPLICATE_GROUP_DISPLAY_COUNT = 4;
|
|
171
|
+
const DUPLICATE_SEGMENT_DISPLAY_COUNT = 6;
|
|
172
|
+
const TOOL_SCHEMA_SAVINGS_RATIO = 0.25;
|
|
173
|
+
const SYSTEM_PROMPT_SAVINGS_RATIO = 0.2;
|
|
174
|
+
const HISTORY_SAVINGS_RATIO = 0.2;
|
|
175
|
+
const ROLE_ORDER = ["system", "user", "assistant", "tool", "tools"];
|
|
176
|
+
const ROLE_DESCRIPTIONS = {
|
|
177
|
+
system: "instructions",
|
|
178
|
+
user: "user turns",
|
|
179
|
+
assistant: "assistant turns",
|
|
180
|
+
tool: "tool results",
|
|
181
|
+
tools: "tool schemas"
|
|
182
|
+
};
|
|
183
|
+
const VIEW_MODE_OPTIONS = [
|
|
184
|
+
{ value: "role", label: "By Role" },
|
|
185
|
+
{ value: "segment", label: "By Segment" }
|
|
186
|
+
];
|
|
187
|
+
const RISK_CLASS = {
|
|
188
|
+
unknown: "bg-muted-foreground/50",
|
|
189
|
+
ok: "bg-emerald-500/70",
|
|
190
|
+
watch: "bg-amber-400/75",
|
|
191
|
+
danger: "bg-red-500/80"
|
|
192
|
+
};
|
|
193
|
+
const RISK_TEXT_CLASS = {
|
|
194
|
+
unknown: "text-muted-foreground",
|
|
195
|
+
ok: "text-emerald-400",
|
|
196
|
+
watch: "text-amber-300",
|
|
197
|
+
danger: "text-red-300"
|
|
198
|
+
};
|
|
199
|
+
const HEALTH_BADGE_CLASS = {
|
|
200
|
+
ok: "border-emerald-400/30 bg-emerald-400/8 text-emerald-200",
|
|
201
|
+
optimizable: "border-amber-400/30 bg-amber-400/8 text-amber-100",
|
|
202
|
+
risk: "border-red-400/35 bg-red-500/10 text-red-100"
|
|
203
|
+
};
|
|
204
|
+
const HEALTH_LABEL = {
|
|
205
|
+
ok: "OK",
|
|
206
|
+
optimizable: "Optimizable",
|
|
207
|
+
risk: "Risk"
|
|
208
|
+
};
|
|
209
|
+
function formatPercent(value) {
|
|
210
|
+
if (value >= 10) return `${value.toFixed(0)}%`;
|
|
211
|
+
if (value >= 1) return `${value.toFixed(1)}%`;
|
|
212
|
+
if (value > 0) return "<1%";
|
|
213
|
+
return "0%";
|
|
214
|
+
}
|
|
215
|
+
function formatUsagePercent(value) {
|
|
216
|
+
if (value === null) return "Unknown";
|
|
217
|
+
return formatPercent(value * 100);
|
|
218
|
+
}
|
|
219
|
+
function formatRemainingTokens(value) {
|
|
220
|
+
if (value === null) return "Unknown";
|
|
221
|
+
if (value < 0) return `-${formatTokens(Math.abs(value))}`;
|
|
222
|
+
return formatTokens(value);
|
|
223
|
+
}
|
|
224
|
+
function formatContextLimit(intelligence) {
|
|
225
|
+
if (intelligence.contextWindow.tokens === null) return "Unknown";
|
|
226
|
+
return formatContextWindowTokens(intelligence.contextWindow.tokens);
|
|
227
|
+
}
|
|
228
|
+
function formatContextSource(intelligence) {
|
|
229
|
+
switch (intelligence.contextWindow.source) {
|
|
230
|
+
case "request":
|
|
231
|
+
return intelligence.contextWindow.label;
|
|
232
|
+
case "provider":
|
|
233
|
+
return intelligence.contextWindow.label;
|
|
234
|
+
case "model-rule":
|
|
235
|
+
return intelligence.contextWindow.label;
|
|
236
|
+
case "unknown":
|
|
237
|
+
return intelligence.model === null ? intelligence.contextWindow.label : `${intelligence.contextWindow.label}: ${intelligence.model}`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function advisorTone(severity) {
|
|
241
|
+
switch (severity) {
|
|
242
|
+
case "watch":
|
|
243
|
+
return "border-amber-400/30 bg-amber-400/8 text-amber-100";
|
|
244
|
+
case "danger":
|
|
245
|
+
return "border-red-400/35 bg-red-500/10 text-red-100";
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function formatContextHealth(health) {
|
|
249
|
+
const label = HEALTH_LABEL[health.level];
|
|
250
|
+
if (health.level === "ok") return label;
|
|
251
|
+
const countLabel = health.level === "risk" ? `${String(health.opportunityCount)} signal${health.opportunityCount === 1 ? "" : "s"}` : `${String(health.opportunityCount)} opportunit${health.opportunityCount === 1 ? "y" : "ies"}`;
|
|
252
|
+
if (health.reclaimableTokens <= 0) return `${label} | ${countLabel}`;
|
|
253
|
+
return `${label} | ${countLabel} | ~${formatTokens(health.reclaimableTokens)} tokens`;
|
|
254
|
+
}
|
|
255
|
+
function ContextHealthBadge({ health }) {
|
|
256
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
257
|
+
"span",
|
|
258
|
+
{
|
|
259
|
+
className: cn(
|
|
260
|
+
"inline-flex h-5 max-w-full items-center rounded border px-1.5 font-mono text-[10px]",
|
|
261
|
+
HEALTH_BADGE_CLASS[health.level]
|
|
262
|
+
),
|
|
263
|
+
"aria-label": `Context health ${formatContextHealth(health)}`,
|
|
264
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate", children: formatContextHealth(health) })
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
function roleUsageTokens(intelligence, role) {
|
|
269
|
+
return intelligence.roleUsages.find((usage) => usage.role === role)?.tokens ?? 0;
|
|
270
|
+
}
|
|
271
|
+
function roleUsagePercent(intelligence, role) {
|
|
272
|
+
return intelligence.roleUsages.find((usage) => usage.role === role)?.percent ?? 0;
|
|
273
|
+
}
|
|
274
|
+
function estimatedSaving(tokens, ratio) {
|
|
275
|
+
if (tokens <= 0) return null;
|
|
276
|
+
const saving = Math.round(tokens * ratio);
|
|
277
|
+
return saving > 0 ? saving : null;
|
|
278
|
+
}
|
|
279
|
+
function largestSegmentForRole(segments, role) {
|
|
280
|
+
return [...segments].filter((segment) => segment.role === role).sort((left, right) => right.size - left.size)[0] ?? null;
|
|
281
|
+
}
|
|
282
|
+
function largestSegmentForHistory(segments) {
|
|
283
|
+
return [...segments].filter(
|
|
284
|
+
(segment) => segment.role === "user" || segment.role === "assistant" || segment.role === "tool"
|
|
285
|
+
).sort((left, right) => right.size - left.size)[0] ?? null;
|
|
286
|
+
}
|
|
287
|
+
function firstDuplicateTarget(groups, segments) {
|
|
288
|
+
const firstGroup = groups[0] ?? null;
|
|
289
|
+
if (firstGroup === null) return null;
|
|
290
|
+
const firstSegment = firstGroup.segments[0] ?? null;
|
|
291
|
+
if (firstSegment === null) return null;
|
|
292
|
+
return resolveDuplicateSegment(firstSegment, segments);
|
|
293
|
+
}
|
|
294
|
+
function duplicateSaving(groups) {
|
|
295
|
+
const saving = groups.reduce((sum, group) => sum + group.repeatedTokens, 0);
|
|
296
|
+
return saving > 0 ? saving : null;
|
|
297
|
+
}
|
|
298
|
+
function historyTokens(intelligence) {
|
|
299
|
+
return roleUsageTokens(intelligence, "user") + roleUsageTokens(intelligence, "assistant") + roleUsageTokens(intelligence, "tool");
|
|
300
|
+
}
|
|
301
|
+
function advisorItemFromDiagnostic({
|
|
302
|
+
diagnostic,
|
|
303
|
+
intelligence,
|
|
304
|
+
segments
|
|
305
|
+
}) {
|
|
306
|
+
switch (diagnostic.kind) {
|
|
307
|
+
case "duplicate":
|
|
308
|
+
return {
|
|
309
|
+
key: "duplicate",
|
|
310
|
+
kind: "duplicate",
|
|
311
|
+
severity: diagnostic.severity,
|
|
312
|
+
title: "Duplicate content",
|
|
313
|
+
impact: diagnostic.detail,
|
|
314
|
+
action: "Remove repeated blocks or keep one canonical copy in the next request.",
|
|
315
|
+
savingTokens: duplicateSaving(intelligence.duplicateGroups),
|
|
316
|
+
target: firstDuplicateTarget(intelligence.duplicateGroups, segments)
|
|
317
|
+
};
|
|
318
|
+
case "tool-schema": {
|
|
319
|
+
const tokens = roleUsageTokens(intelligence, "tools");
|
|
320
|
+
const percent = roleUsagePercent(intelligence, "tools");
|
|
321
|
+
return {
|
|
322
|
+
key: "tool-schema",
|
|
323
|
+
kind: "tool-schema",
|
|
324
|
+
severity: diagnostic.severity,
|
|
325
|
+
title: "Tool schema pressure",
|
|
326
|
+
impact: `Tool definitions use ~${formatTokens(tokens)} tokens (${formatPercent(
|
|
327
|
+
percent * 100
|
|
328
|
+
)}).`,
|
|
329
|
+
action: "Disable unused tools or shorten verbose schema descriptions.",
|
|
330
|
+
savingTokens: estimatedSaving(tokens, TOOL_SCHEMA_SAVINGS_RATIO),
|
|
331
|
+
target: largestSegmentForRole(segments, "tools")
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
case "system-heavy": {
|
|
335
|
+
const tokens = roleUsageTokens(intelligence, "system");
|
|
336
|
+
const percent = roleUsagePercent(intelligence, "system");
|
|
337
|
+
return {
|
|
338
|
+
key: "system-heavy",
|
|
339
|
+
kind: "system-heavy",
|
|
340
|
+
severity: diagnostic.severity,
|
|
341
|
+
title: "Large system prompt",
|
|
342
|
+
impact: `System instructions use ~${formatTokens(tokens)} tokens (${formatPercent(
|
|
343
|
+
percent * 100
|
|
344
|
+
)}).`,
|
|
345
|
+
action: "Compress repeated policy text and move stable guidance into reusable memory.",
|
|
346
|
+
savingTokens: estimatedSaving(tokens, SYSTEM_PROMPT_SAVINGS_RATIO),
|
|
347
|
+
target: largestSegmentForRole(segments, "system")
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
case "history-bloat": {
|
|
351
|
+
const tokens = historyTokens(intelligence);
|
|
352
|
+
return {
|
|
353
|
+
key: "history-bloat",
|
|
354
|
+
kind: "history-bloat",
|
|
355
|
+
severity: diagnostic.severity,
|
|
356
|
+
title: "Conversation history growth",
|
|
357
|
+
impact: diagnostic.detail,
|
|
358
|
+
action: "Summarize older turns and trim resolved tool outputs before continuing.",
|
|
359
|
+
savingTokens: estimatedSaving(tokens, HISTORY_SAVINGS_RATIO),
|
|
360
|
+
target: largestSegmentForHistory(segments)
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function buildContextAdvisorItems({
|
|
366
|
+
intelligence,
|
|
367
|
+
segments
|
|
368
|
+
}) {
|
|
369
|
+
const items = [];
|
|
370
|
+
if (intelligence.riskLevel === "watch" || intelligence.riskLevel === "danger") {
|
|
371
|
+
items.push({
|
|
372
|
+
key: "context-pressure",
|
|
373
|
+
kind: "context-pressure",
|
|
374
|
+
severity: intelligence.riskLevel === "danger" ? "danger" : "watch",
|
|
375
|
+
title: "Context window pressure",
|
|
376
|
+
impact: `${formatUsagePercent(intelligence.usagePercent)} used, ${formatRemainingTokens(
|
|
377
|
+
intelligence.remainingAfterReserveTokens
|
|
378
|
+
)} remaining after output reserve.`,
|
|
379
|
+
action: "Start with the largest context block, then remove duplicates or summarize history.",
|
|
380
|
+
savingTokens: null,
|
|
381
|
+
target: [...segments].sort((left, right) => right.size - left.size)[0] ?? null
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
if (intelligence.contextWindow.source === "unknown") {
|
|
385
|
+
items.push({
|
|
386
|
+
key: "context-window",
|
|
387
|
+
kind: "context-window",
|
|
388
|
+
severity: "watch",
|
|
389
|
+
title: "Context window unknown",
|
|
390
|
+
impact: "Agent Inspector cannot calculate remaining space for this model.",
|
|
391
|
+
action: "Add model metadata in Provider settings so risk and remaining space are accurate.",
|
|
392
|
+
savingTokens: null,
|
|
393
|
+
target: null
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
intelligence.diagnostics.forEach((diagnostic) => {
|
|
397
|
+
items.push(advisorItemFromDiagnostic({ diagnostic, intelligence, segments }));
|
|
398
|
+
});
|
|
399
|
+
return items;
|
|
400
|
+
}
|
|
401
|
+
function ContextAdvisorPanel({
|
|
402
|
+
items,
|
|
403
|
+
onSegmentActivate
|
|
404
|
+
}) {
|
|
405
|
+
if (items.length === 0) return null;
|
|
406
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "space-y-2 rounded border border-border/70 bg-muted/15 p-2", children: [
|
|
407
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
|
|
408
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-medium text-foreground", children: "Context Advisor" }),
|
|
409
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-mono text-[11px] text-muted-foreground", children: [
|
|
410
|
+
String(items.length),
|
|
411
|
+
" issue",
|
|
412
|
+
items.length === 1 ? "" : "s"
|
|
413
|
+
] })
|
|
414
|
+
] }),
|
|
415
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid gap-2", children: items.map((item) => {
|
|
416
|
+
const target = item.target;
|
|
417
|
+
const canJump = target !== null && onSegmentActivate !== void 0;
|
|
418
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
419
|
+
"div",
|
|
420
|
+
{
|
|
421
|
+
className: cn("rounded border px-2 py-1.5 text-xs", advisorTone(item.severity)),
|
|
422
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex min-w-0 flex-wrap items-start justify-between gap-2", children: [
|
|
423
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
424
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium", children: item.title }),
|
|
425
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-0.5 text-[11px] text-muted-foreground", children: [
|
|
426
|
+
"Impact: ",
|
|
427
|
+
item.impact
|
|
428
|
+
] }),
|
|
429
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-0.5 text-[11px] text-muted-foreground", children: [
|
|
430
|
+
"Action: ",
|
|
431
|
+
item.action
|
|
432
|
+
] })
|
|
433
|
+
] }),
|
|
434
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [
|
|
435
|
+
item.savingTokens !== null && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-mono text-[11px] text-muted-foreground", children: [
|
|
436
|
+
"Save ~",
|
|
437
|
+
formatTokens(item.savingTokens)
|
|
438
|
+
] }),
|
|
439
|
+
canJump && target !== null && onSegmentActivate !== void 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
440
|
+
"button",
|
|
441
|
+
{
|
|
442
|
+
type: "button",
|
|
443
|
+
onClick: () => onSegmentActivate(target),
|
|
444
|
+
className: "inline-flex h-6 items-center gap-1 rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",
|
|
445
|
+
title: "Jump to the most relevant context block",
|
|
446
|
+
children: [
|
|
447
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "size-3" }),
|
|
448
|
+
"Jump"
|
|
449
|
+
]
|
|
450
|
+
}
|
|
451
|
+
)
|
|
452
|
+
] })
|
|
453
|
+
] })
|
|
454
|
+
},
|
|
455
|
+
item.key
|
|
456
|
+
);
|
|
457
|
+
}) })
|
|
458
|
+
] });
|
|
459
|
+
}
|
|
460
|
+
function ContextIntelligenceStrip({
|
|
461
|
+
intelligence,
|
|
462
|
+
segments,
|
|
463
|
+
onSegmentActivate
|
|
464
|
+
}) {
|
|
465
|
+
const usageWidth = intelligence.usagePercent === null ? 0 : Math.max(1, intelligence.usagePercent * 100);
|
|
466
|
+
const outputReserveLabel = intelligence.outputReserveTokens === null ? "No output reserve" : `Output reserve ${formatTokens(intelligence.outputReserveTokens)}`;
|
|
467
|
+
const largestRole = intelligence.largestRole;
|
|
468
|
+
const advisorItems = buildContextAdvisorItems({ intelligence, segments });
|
|
469
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
|
|
470
|
+
/* @__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: [
|
|
471
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
472
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] font-medium uppercase text-muted-foreground", children: "Window" }),
|
|
473
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-0.5 truncate font-mono text-foreground", children: formatContextLimit(intelligence) }),
|
|
474
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "truncate text-[11px] text-muted-foreground", children: formatContextSource(intelligence) })
|
|
475
|
+
] }),
|
|
476
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
477
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] font-medium uppercase text-muted-foreground", children: "Used" }),
|
|
478
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: cn("mt-0.5 font-mono", RISK_TEXT_CLASS[intelligence.riskLevel]), children: formatUsagePercent(intelligence.usagePercent) }),
|
|
479
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "truncate text-[11px] text-muted-foreground", children: outputReserveLabel })
|
|
480
|
+
] }),
|
|
481
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
482
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] font-medium uppercase text-muted-foreground", children: "Remaining" }),
|
|
483
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-0.5 font-mono text-foreground", children: formatRemainingTokens(intelligence.remainingAfterReserveTokens) }),
|
|
484
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "truncate text-[11px] text-muted-foreground", children: [
|
|
485
|
+
"Input only ",
|
|
486
|
+
formatRemainingTokens(intelligence.remainingInputTokens)
|
|
487
|
+
] })
|
|
488
|
+
] }),
|
|
489
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
490
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] font-medium uppercase text-muted-foreground", children: "Largest" }),
|
|
491
|
+
largestRole === null ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-0.5 text-muted-foreground", children: "Unknown" }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
492
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-0.5 flex min-w-0 items-center gap-1.5", children: [
|
|
493
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
494
|
+
"span",
|
|
495
|
+
{
|
|
496
|
+
"aria-hidden": "true",
|
|
497
|
+
className: cn(
|
|
498
|
+
"size-2.5 shrink-0 rounded-[2px]",
|
|
499
|
+
ROLE_COLOR_CLASSES[largestRole.role]
|
|
500
|
+
)
|
|
501
|
+
}
|
|
502
|
+
),
|
|
503
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate text-foreground", children: largestRole.label })
|
|
504
|
+
] }),
|
|
505
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "truncate font-mono text-[11px] text-muted-foreground", children: [
|
|
506
|
+
formatPercent(largestRole.percent * 100),
|
|
507
|
+
" | ~",
|
|
508
|
+
formatTokens(largestRole.tokens)
|
|
509
|
+
] })
|
|
510
|
+
] })
|
|
511
|
+
] })
|
|
512
|
+
] }),
|
|
513
|
+
intelligence.contextWindow.tokens !== null && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
|
|
514
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative h-2 overflow-hidden rounded-full bg-muted/40", children: [
|
|
515
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
516
|
+
"div",
|
|
517
|
+
{
|
|
518
|
+
className: cn("h-full rounded-full", RISK_CLASS[intelligence.riskLevel]),
|
|
519
|
+
style: { width: `${String(usageWidth)}%` }
|
|
520
|
+
}
|
|
521
|
+
),
|
|
522
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
523
|
+
"div",
|
|
524
|
+
{
|
|
525
|
+
"aria-hidden": "true",
|
|
526
|
+
className: "absolute top-0 h-full w-px bg-amber-200/70",
|
|
527
|
+
style: { left: `${String(CONTEXT_USAGE_THRESHOLDS.watch * 100)}%` }
|
|
528
|
+
}
|
|
529
|
+
),
|
|
530
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
531
|
+
"div",
|
|
532
|
+
{
|
|
533
|
+
"aria-hidden": "true",
|
|
534
|
+
className: "absolute top-0 h-full w-px bg-red-200/80",
|
|
535
|
+
style: { left: `${String(CONTEXT_USAGE_THRESHOLDS.danger * 100)}%` }
|
|
536
|
+
}
|
|
537
|
+
)
|
|
538
|
+
] }),
|
|
539
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-[10px] text-muted-foreground", children: [
|
|
540
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Context window" }),
|
|
541
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
|
|
542
|
+
"Watch ",
|
|
543
|
+
formatUsagePercent(CONTEXT_USAGE_THRESHOLDS.watch),
|
|
544
|
+
" / Danger",
|
|
545
|
+
" ",
|
|
546
|
+
formatUsagePercent(CONTEXT_USAGE_THRESHOLDS.danger)
|
|
547
|
+
] })
|
|
548
|
+
] })
|
|
549
|
+
] }),
|
|
550
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(ContextAdvisorPanel, { items: advisorItems, onSegmentActivate })
|
|
551
|
+
] });
|
|
552
|
+
}
|
|
553
|
+
function resolveDuplicateSegment(duplicateSegment, segments) {
|
|
554
|
+
return segments.find((segment) => segment.path === duplicateSegment.path) ?? null;
|
|
555
|
+
}
|
|
556
|
+
function DuplicateContentPanel({
|
|
557
|
+
groups,
|
|
558
|
+
segments,
|
|
559
|
+
onSegmentActivate
|
|
560
|
+
}) {
|
|
561
|
+
const [expanded, setExpanded] = reactExports.useState(false);
|
|
562
|
+
if (groups.length === 0) return null;
|
|
563
|
+
const visibleGroups = groups.slice(0, DUPLICATE_GROUP_DISPLAY_COUNT);
|
|
564
|
+
const hiddenGroupCount = groups.length - visibleGroups.length;
|
|
565
|
+
const totalRepeatedTokens = groups.reduce((sum, group) => sum + group.repeatedTokens, 0);
|
|
566
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "space-y-2 rounded border border-border/70 bg-muted/15 p-2", children: [
|
|
567
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
568
|
+
"button",
|
|
569
|
+
{
|
|
570
|
+
type: "button",
|
|
571
|
+
onClick: () => setExpanded((current) => !current),
|
|
572
|
+
"aria-expanded": expanded,
|
|
573
|
+
className: "flex w-full flex-wrap items-center justify-between gap-2 rounded px-1 py-0.5 text-left transition-colors hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
|
|
574
|
+
children: [
|
|
575
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex min-w-0 items-center gap-1.5", children: [
|
|
576
|
+
expanded ? /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronDown, { className: "size-3.5 shrink-0 text-muted-foreground" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "size-3.5 shrink-0 text-muted-foreground" }),
|
|
577
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate text-xs font-medium text-foreground", children: "Duplicate Content" })
|
|
578
|
+
] }),
|
|
579
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-mono text-[11px] text-muted-foreground", children: [
|
|
580
|
+
String(groups.length),
|
|
581
|
+
" group",
|
|
582
|
+
groups.length === 1 ? "" : "s",
|
|
583
|
+
" | ~",
|
|
584
|
+
formatTokens(totalRepeatedTokens),
|
|
585
|
+
" repeated"
|
|
586
|
+
] })
|
|
587
|
+
]
|
|
588
|
+
}
|
|
589
|
+
),
|
|
590
|
+
expanded && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
591
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-2", children: visibleGroups.map((group, groupIndex) => {
|
|
592
|
+
const visibleSegments = group.segments.slice(0, DUPLICATE_SEGMENT_DISPLAY_COUNT);
|
|
593
|
+
const hiddenSegmentCount = group.segments.length - visibleSegments.length;
|
|
594
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
595
|
+
"div",
|
|
596
|
+
{
|
|
597
|
+
className: "space-y-1.5 border-t border-border/50 pt-2 first:border-t-0 first:pt-0",
|
|
598
|
+
children: [
|
|
599
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex min-w-0 items-center gap-2 text-xs", children: [
|
|
600
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "w-5 shrink-0 text-right font-mono text-muted-foreground/70", children: String(groupIndex + 1) }),
|
|
601
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "min-w-0 flex-1 truncate text-foreground", children: group.firstLabel }),
|
|
602
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "shrink-0 font-mono text-muted-foreground", children: [
|
|
603
|
+
"x",
|
|
604
|
+
String(group.count),
|
|
605
|
+
" | ~",
|
|
606
|
+
formatTokens(group.repeatedTokens),
|
|
607
|
+
" saved"
|
|
608
|
+
] })
|
|
609
|
+
] }),
|
|
610
|
+
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 }),
|
|
611
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "ml-7 flex flex-wrap gap-1", children: [
|
|
612
|
+
visibleSegments.map((duplicateSegment, segmentIndex) => {
|
|
613
|
+
const target = resolveDuplicateSegment(duplicateSegment, segments);
|
|
614
|
+
const activate = target === null || onSegmentActivate === void 0 ? void 0 : onSegmentActivate;
|
|
615
|
+
const label = `${duplicateSegment.label} ~${formatTokens(
|
|
616
|
+
duplicateSegment.tokens
|
|
617
|
+
)}`;
|
|
618
|
+
if (activate === void 0 || target === null) {
|
|
619
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
620
|
+
"span",
|
|
621
|
+
{
|
|
622
|
+
className: "inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground",
|
|
623
|
+
title: label,
|
|
624
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate", children: label })
|
|
625
|
+
},
|
|
626
|
+
`${duplicateSegment.path}-${segmentIndex}`
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
630
|
+
"button",
|
|
631
|
+
{
|
|
632
|
+
type: "button",
|
|
633
|
+
onClick: () => activate(target),
|
|
634
|
+
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",
|
|
635
|
+
title: "Jump to this duplicate block",
|
|
636
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate", children: label })
|
|
637
|
+
},
|
|
638
|
+
`${duplicateSegment.path}-${segmentIndex}`
|
|
639
|
+
);
|
|
640
|
+
}),
|
|
641
|
+
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: [
|
|
642
|
+
"+",
|
|
643
|
+
String(hiddenSegmentCount)
|
|
644
|
+
] })
|
|
645
|
+
] })
|
|
646
|
+
]
|
|
647
|
+
},
|
|
648
|
+
group.key
|
|
649
|
+
);
|
|
650
|
+
}) }),
|
|
651
|
+
hiddenGroupCount > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "border-t border-border/50 pt-2 font-mono text-[11px] text-muted-foreground", children: [
|
|
652
|
+
"+",
|
|
653
|
+
String(hiddenGroupCount),
|
|
654
|
+
" more duplicate group",
|
|
655
|
+
hiddenGroupCount === 1 ? "" : "s"
|
|
656
|
+
] })
|
|
657
|
+
] })
|
|
658
|
+
] });
|
|
659
|
+
}
|
|
660
|
+
function aggregateByRole(segments) {
|
|
661
|
+
const result = [];
|
|
662
|
+
for (const role of ROLE_ORDER) {
|
|
663
|
+
const matching = segments.filter((segment) => segment.role === role);
|
|
664
|
+
if (matching.length === 0) continue;
|
|
665
|
+
const size = matching.reduce((sum, segment) => sum + segment.size, 0);
|
|
666
|
+
const characters = matching.reduce((sum, segment) => sum + segment.characters, 0);
|
|
667
|
+
const label = ANATOMY_ROLE_LABELS[role];
|
|
668
|
+
const text = `${matching.length} segment${matching.length === 1 ? "" : "s"} grouped as ${ROLE_DESCRIPTIONS[role]}`;
|
|
669
|
+
result.push({
|
|
670
|
+
role,
|
|
671
|
+
label,
|
|
672
|
+
size,
|
|
673
|
+
characters,
|
|
674
|
+
text,
|
|
675
|
+
path: `role:${role}`
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
return result;
|
|
679
|
+
}
|
|
680
|
+
function topContributors(segments) {
|
|
681
|
+
return [...segments].sort((a, b) => b.size - a.size).slice(0, TOP_CONTRIBUTOR_COUNT);
|
|
682
|
+
}
|
|
683
|
+
function RequestAnatomy({
|
|
684
|
+
parsed,
|
|
685
|
+
inputTokens,
|
|
686
|
+
model = null,
|
|
687
|
+
onSegmentActivate,
|
|
688
|
+
segments: providedSegments
|
|
689
|
+
}) {
|
|
690
|
+
const { providers } = useProviders();
|
|
691
|
+
const [viewMode, setViewMode] = reactExports.useState("role");
|
|
692
|
+
const segments = reactExports.useMemo(() => providedSegments ?? null, [providedSegments]);
|
|
693
|
+
const total = reactExports.useMemo(
|
|
694
|
+
() => (segments ?? []).reduce((sum, segment) => sum + segment.size, 0),
|
|
695
|
+
[segments]
|
|
696
|
+
);
|
|
697
|
+
const roleSegments = reactExports.useMemo(
|
|
698
|
+
() => segments === null ? [] : aggregateByRole(segments),
|
|
699
|
+
[segments]
|
|
700
|
+
);
|
|
701
|
+
const topSegments = reactExports.useMemo(
|
|
702
|
+
() => segments === null ? [] : topContributors(segments),
|
|
703
|
+
[segments]
|
|
704
|
+
);
|
|
705
|
+
const intelligence = reactExports.useMemo(
|
|
706
|
+
() => segments === null ? null : analyzeContextIntelligence({
|
|
707
|
+
segments,
|
|
708
|
+
inputTokens,
|
|
709
|
+
parsed,
|
|
710
|
+
model,
|
|
711
|
+
providers
|
|
712
|
+
}),
|
|
713
|
+
[inputTokens, model, parsed, providers, segments]
|
|
714
|
+
);
|
|
715
|
+
const showDivergenceWarning = reactExports.useMemo(() => {
|
|
716
|
+
if (segments === null) return false;
|
|
717
|
+
if (inputTokens === null) return false;
|
|
718
|
+
if (total === 0) return false;
|
|
719
|
+
const ratio = Math.abs(inputTokens - total) / Math.max(inputTokens, total);
|
|
720
|
+
return ratio >= DIVERGENCE_AMBER_THRESHOLD;
|
|
721
|
+
}, [inputTokens, segments, total]);
|
|
722
|
+
if (segments === null) return null;
|
|
723
|
+
if (segments.length === 0) return null;
|
|
724
|
+
if (parsed === null && providedSegments === void 0) return null;
|
|
725
|
+
const summaryColorClass = inputTokens !== null && showDivergenceWarning ? "text-amber-400" : "text-muted-foreground";
|
|
726
|
+
const displayedSegments = viewMode === "role" ? roleSegments : segments;
|
|
727
|
+
const displayedTotal = total > 0 ? total : displayedSegments.reduce((sum, item) => sum + item.size, 0);
|
|
728
|
+
const activateSegment = viewMode === "segment" ? onSegmentActivate : void 0;
|
|
729
|
+
const segmentCountLabel = `${String(segments.length)} segment${segments.length === 1 ? "" : "s"}`;
|
|
730
|
+
const providerInputLabel = inputTokens === null ? "Provider input unknown" : `Provider input ${formatTokens(inputTokens)}`;
|
|
731
|
+
const contextLimitLabel = intelligence === null ? "Limit unknown" : `Limit ${formatContextLimit(intelligence)}`;
|
|
732
|
+
const usageLabel = intelligence === null ? "Usage unknown" : `${formatUsagePercent(intelligence.usagePercent)} used`;
|
|
733
|
+
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: [
|
|
734
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [
|
|
735
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
|
|
736
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [
|
|
737
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-semibold text-foreground", children: "Request Context" }),
|
|
738
|
+
intelligence !== null && /* @__PURE__ */ jsxRuntimeExports.jsx(ContextHealthBadge, { health: intelligence.health })
|
|
739
|
+
] }),
|
|
740
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cn("mt-0.5 text-xs font-mono tabular-nums", summaryColorClass), children: [
|
|
741
|
+
"Estimated ~",
|
|
742
|
+
formatTokens(total),
|
|
743
|
+
" tokens | ",
|
|
744
|
+
providerInputLabel,
|
|
745
|
+
" | ",
|
|
746
|
+
contextLimitLabel,
|
|
747
|
+
" |",
|
|
748
|
+
" ",
|
|
749
|
+
usageLabel,
|
|
750
|
+
" | ",
|
|
751
|
+
segmentCountLabel
|
|
752
|
+
] })
|
|
753
|
+
] }),
|
|
754
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
755
|
+
"div",
|
|
756
|
+
{
|
|
757
|
+
className: "inline-flex shrink-0 rounded border border-border bg-muted/20 p-0.5",
|
|
758
|
+
role: "group",
|
|
759
|
+
"aria-label": "Context breakdown mode",
|
|
760
|
+
children: VIEW_MODE_OPTIONS.map((option) => /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
761
|
+
"button",
|
|
762
|
+
{
|
|
763
|
+
type: "button",
|
|
764
|
+
"aria-pressed": viewMode === option.value,
|
|
765
|
+
onClick: () => setViewMode(option.value),
|
|
766
|
+
className: cn(
|
|
767
|
+
"h-6 rounded-sm px-2 text-[11px] font-medium transition-colors",
|
|
768
|
+
viewMode === option.value ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
769
|
+
),
|
|
770
|
+
children: option.label
|
|
771
|
+
},
|
|
772
|
+
option.value
|
|
773
|
+
))
|
|
774
|
+
}
|
|
775
|
+
)
|
|
776
|
+
] }),
|
|
777
|
+
showDivergenceWarning && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "inline-flex items-center gap-1.5 text-xs text-amber-400", children: [
|
|
778
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Tooltip, { children: [
|
|
779
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
780
|
+
"button",
|
|
781
|
+
{
|
|
782
|
+
type: "button",
|
|
783
|
+
className: "inline-flex items-center hover:text-amber-300",
|
|
784
|
+
"aria-label": "Token estimate differs from provider input",
|
|
785
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx(Info, { className: "size-3.5" })
|
|
786
|
+
}
|
|
787
|
+
) }),
|
|
788
|
+
/* @__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." })
|
|
789
|
+
] }),
|
|
790
|
+
"Estimate differs from provider-reported input."
|
|
791
|
+
] }),
|
|
792
|
+
intelligence !== null && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
793
|
+
ContextIntelligenceStrip,
|
|
794
|
+
{
|
|
795
|
+
intelligence,
|
|
796
|
+
segments,
|
|
797
|
+
onSegmentActivate
|
|
798
|
+
}
|
|
799
|
+
),
|
|
800
|
+
intelligence !== null && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
801
|
+
DuplicateContentPanel,
|
|
802
|
+
{
|
|
803
|
+
groups: intelligence.duplicateGroups,
|
|
804
|
+
segments,
|
|
805
|
+
onSegmentActivate
|
|
806
|
+
}
|
|
807
|
+
),
|
|
808
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
809
|
+
SegmentBar,
|
|
810
|
+
{
|
|
811
|
+
segments: displayedSegments,
|
|
812
|
+
totalTokens: displayedTotal,
|
|
813
|
+
showLabels: viewMode === "segment",
|
|
814
|
+
onActivate: activateSegment
|
|
815
|
+
}
|
|
816
|
+
),
|
|
817
|
+
/* @__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) => {
|
|
818
|
+
const percent = total > 0 ? segment.size / total * 100 : 0;
|
|
819
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "inline-flex items-center gap-1.5", children: [
|
|
820
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
821
|
+
"span",
|
|
822
|
+
{
|
|
823
|
+
"aria-hidden": "true",
|
|
824
|
+
className: cn("size-2.5 rounded-[2px]", ROLE_COLOR_CLASSES[segment.role])
|
|
825
|
+
}
|
|
826
|
+
),
|
|
827
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: segment.label }),
|
|
828
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono text-muted-foreground/70", children: formatPercent(percent) })
|
|
829
|
+
] }, segment.role);
|
|
830
|
+
}) }),
|
|
831
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
|
|
832
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-medium text-foreground", children: "Top Contributors" }),
|
|
833
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid gap-1", children: topSegments.map((segment, index) => {
|
|
834
|
+
const percent = total > 0 ? segment.size / total * 100 : 0;
|
|
835
|
+
const activate = onSegmentActivate;
|
|
836
|
+
const content = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
837
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "w-5 shrink-0 text-right font-mono text-muted-foreground/70", children: String(index + 1) }),
|
|
838
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
839
|
+
"span",
|
|
840
|
+
{
|
|
841
|
+
"aria-hidden": "true",
|
|
842
|
+
className: cn(
|
|
843
|
+
"size-2.5 shrink-0 rounded-[2px]",
|
|
844
|
+
ROLE_COLOR_CLASSES[segment.role]
|
|
845
|
+
)
|
|
846
|
+
}
|
|
847
|
+
),
|
|
848
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "min-w-0 flex-1 truncate text-left", children: segment.label }),
|
|
849
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "shrink-0 font-mono text-muted-foreground", children: [
|
|
850
|
+
formatPercent(percent),
|
|
851
|
+
" | ~",
|
|
852
|
+
formatTokens(segment.size)
|
|
853
|
+
] })
|
|
854
|
+
] });
|
|
855
|
+
if (activate !== void 0) {
|
|
856
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
857
|
+
"button",
|
|
858
|
+
{
|
|
859
|
+
type: "button",
|
|
860
|
+
onClick: () => activate(segment),
|
|
861
|
+
className: "flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",
|
|
862
|
+
title: "Jump to this request block",
|
|
863
|
+
children: content
|
|
864
|
+
},
|
|
865
|
+
`${segment.path}-${index}`
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
869
|
+
"div",
|
|
870
|
+
{
|
|
871
|
+
className: "flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",
|
|
872
|
+
children: content
|
|
873
|
+
},
|
|
874
|
+
`${segment.path}-${index}`
|
|
875
|
+
);
|
|
876
|
+
}) })
|
|
877
|
+
] })
|
|
878
|
+
] }) });
|
|
879
|
+
}
|
|
880
|
+
export {
|
|
881
|
+
RequestAnatomy
|
|
882
|
+
};
|