@eum-agent/context-management 0.0.0-stage → 1.0.1
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/dist/index.js +3574 -0
- package/package.json +51 -3
- package/ui/ui.js +947 -0
- package/README.md +0 -3
package/ui/ui.js
ADDED
|
@@ -0,0 +1,947 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
//#region ui-src/lib/status.ts
|
|
4
|
+
/** Coalesces watched IDs into bounded collections and fences late replies to connection and watch epochs. */
|
|
5
|
+
function createContextStatusView(ctx) {
|
|
6
|
+
const values = /* @__PURE__ */ new Map();
|
|
7
|
+
const watched = /* @__PURE__ */ new Map();
|
|
8
|
+
const queued = /* @__PURE__ */ new Set();
|
|
9
|
+
const active = /* @__PURE__ */ new Map();
|
|
10
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
11
|
+
let nextEpoch = 0, generation = 0, scheduled = false;
|
|
12
|
+
let online = ctx.gateway.connection.status === "online";
|
|
13
|
+
const notify = () => {
|
|
14
|
+
for (const listener of [...listeners]) listener();
|
|
15
|
+
};
|
|
16
|
+
const schedule = (ids = []) => {
|
|
17
|
+
for (const id of ids) if (watched.has(id)) queued.add(id);
|
|
18
|
+
if (scheduled || ctx.signal.aborted) return;
|
|
19
|
+
scheduled = true;
|
|
20
|
+
queueMicrotask(() => {
|
|
21
|
+
scheduled = false;
|
|
22
|
+
if (ctx.signal.aborted || !online) return;
|
|
23
|
+
const selected = [...queued].filter((id) => watched.has(id) && !active.has(id));
|
|
24
|
+
for (let offset = 0; offset < selected.length; offset += 31) {
|
|
25
|
+
const sessionIds = selected.slice(offset, offset + 31), token = Symbol(), at = generation;
|
|
26
|
+
const epochs = sessionIds.map((id) => watched.get(id).epoch);
|
|
27
|
+
for (const id of sessionIds) {
|
|
28
|
+
queued.delete(id);
|
|
29
|
+
active.set(id, token);
|
|
30
|
+
}
|
|
31
|
+
ctx.invoke("statuses", { sessionIds }).then(({ results }) => {
|
|
32
|
+
if (ctx.signal.aborted || generation !== at || results.length !== sessionIds.length) return;
|
|
33
|
+
if (results.some((one, index) => one.index !== index || one.target !== sessionIds[index])) return;
|
|
34
|
+
let changed = false;
|
|
35
|
+
for (const [index, one] of results.entries()) {
|
|
36
|
+
if (watched.get(one.target)?.epoch !== epochs[index] || !one.ok) continue;
|
|
37
|
+
if (one.value === null) {
|
|
38
|
+
changed = values.delete(one.target) || changed;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if ((values.get(one.target)?.revision ?? -1) > one.value.revision) continue;
|
|
42
|
+
values.set(one.target, one.value);
|
|
43
|
+
changed = true;
|
|
44
|
+
}
|
|
45
|
+
if (changed) notify();
|
|
46
|
+
}).catch(() => {}).finally(() => {
|
|
47
|
+
for (const id of sessionIds) if (active.get(id) === token) active.delete(id);
|
|
48
|
+
if (queued.size) schedule();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
ctx.on("statusChanged", (event) => {
|
|
54
|
+
if (event.sessionId) schedule([event.sessionId]);
|
|
55
|
+
});
|
|
56
|
+
ctx.onCore("session.updated", () => schedule([...watched.keys()]));
|
|
57
|
+
ctx.gateway.watchConnection((connection) => {
|
|
58
|
+
const next = connection.status === "online";
|
|
59
|
+
if (next !== online) {
|
|
60
|
+
generation++;
|
|
61
|
+
active.clear();
|
|
62
|
+
}
|
|
63
|
+
if (next && !online) schedule([...watched.keys()]);
|
|
64
|
+
online = next;
|
|
65
|
+
});
|
|
66
|
+
ctx.signal.addEventListener("abort", () => {
|
|
67
|
+
generation++;
|
|
68
|
+
queued.clear();
|
|
69
|
+
active.clear();
|
|
70
|
+
values.clear();
|
|
71
|
+
listeners.clear();
|
|
72
|
+
}, { once: true });
|
|
73
|
+
return {
|
|
74
|
+
get: (sessionId) => values.get(sessionId),
|
|
75
|
+
subscribe(listener) {
|
|
76
|
+
listeners.add(listener);
|
|
77
|
+
return () => listeners.delete(listener);
|
|
78
|
+
},
|
|
79
|
+
watch(sessionId) {
|
|
80
|
+
const current = watched.get(sessionId);
|
|
81
|
+
watched.set(sessionId, current ? {
|
|
82
|
+
...current,
|
|
83
|
+
count: current.count + 1
|
|
84
|
+
} : {
|
|
85
|
+
count: 1,
|
|
86
|
+
epoch: ++nextEpoch
|
|
87
|
+
});
|
|
88
|
+
if (!current) schedule([sessionId]);
|
|
89
|
+
let stopped = false;
|
|
90
|
+
return () => {
|
|
91
|
+
if (stopped) return;
|
|
92
|
+
stopped = true;
|
|
93
|
+
const current = watched.get(sessionId);
|
|
94
|
+
if (!current) return;
|
|
95
|
+
if (current.count > 1) watched.set(sessionId, {
|
|
96
|
+
...current,
|
|
97
|
+
count: current.count - 1
|
|
98
|
+
});
|
|
99
|
+
else {
|
|
100
|
+
watched.delete(sessionId);
|
|
101
|
+
queued.delete(sessionId);
|
|
102
|
+
active.delete(sessionId);
|
|
103
|
+
if (values.delete(sessionId)) notify();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region ui-src/lib/failure.ts
|
|
111
|
+
/** Presents gateway failures through the plugin's host controls. */
|
|
112
|
+
function failureText(value, t) {
|
|
113
|
+
if (value == null || value === "") return null;
|
|
114
|
+
if (typeof value === "string") return value === t("connection.offline") ? null : value;
|
|
115
|
+
if (typeof value === "object") {
|
|
116
|
+
const failure = value;
|
|
117
|
+
const kind = failure.kind ?? failure.failure;
|
|
118
|
+
if (kind === "offline" || kind === "authentication") return null;
|
|
119
|
+
if (kind === "refused") return failure.reason ?? failure.message ?? String(value);
|
|
120
|
+
}
|
|
121
|
+
return value instanceof Error ? value.message : String(value);
|
|
122
|
+
}
|
|
123
|
+
function useFailureToast(host) {
|
|
124
|
+
const toast = host.ui.useToast();
|
|
125
|
+
return useCallback((failure, title) => {
|
|
126
|
+
const text = failureText(failure, host.i18n.t);
|
|
127
|
+
if (text === null) return;
|
|
128
|
+
toast.add({
|
|
129
|
+
id: `failure:${title ?? ""}:${text}`,
|
|
130
|
+
tone: "destructive",
|
|
131
|
+
title: title ?? text,
|
|
132
|
+
...title === void 0 ? {} : { description: text }
|
|
133
|
+
});
|
|
134
|
+
}, [host, toast]);
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region ui-src/lib/context-window.ts
|
|
138
|
+
/** Compact token capacity: round decimal catalogue values use 1000; binary capacities use 1024. */
|
|
139
|
+
function formatContextWindow(value) {
|
|
140
|
+
if (!value || !Number.isFinite(value) || value < 0) return "—";
|
|
141
|
+
const unit = value % 1e3 === 0 ? 1e3 : 1024;
|
|
142
|
+
const millions = value >= unit * unit;
|
|
143
|
+
return `${Number((value / (millions ? unit * unit : unit)).toFixed(1))}${millions ? "M" : "K"}`;
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region ui-src/components/context-usage.tsx
|
|
147
|
+
var REASONS = /* @__PURE__ */ new Set([
|
|
148
|
+
"capacity_unknown",
|
|
149
|
+
"context_projection_degraded",
|
|
150
|
+
"fixed_context_too_large",
|
|
151
|
+
"recovery_unavailable",
|
|
152
|
+
"summary_budget_too_small",
|
|
153
|
+
"summary_failed",
|
|
154
|
+
"summary_no_gain",
|
|
155
|
+
"summary_network_error",
|
|
156
|
+
"summary_invalid",
|
|
157
|
+
"summary_unavailable",
|
|
158
|
+
"summary_provider_unavailable",
|
|
159
|
+
"summary_group_too_large",
|
|
160
|
+
"protected_context_exceeds_budget",
|
|
161
|
+
"context_still_exceeds_budget",
|
|
162
|
+
"cancelled"
|
|
163
|
+
]);
|
|
164
|
+
/** Cells in the popover's window map, one per half percent of the window. */
|
|
165
|
+
var CELLS = 200;
|
|
166
|
+
/** Share of the window at which the meter turns from green to yellow, and from yellow to red. */
|
|
167
|
+
var LEVELS = {
|
|
168
|
+
mid: 60,
|
|
169
|
+
high: 80
|
|
170
|
+
};
|
|
171
|
+
function contextLevel(share) {
|
|
172
|
+
if (share >= LEVELS.high) return "high";
|
|
173
|
+
if (share >= LEVELS.mid) return "mid";
|
|
174
|
+
return "low";
|
|
175
|
+
}
|
|
176
|
+
/** A token count at a glance, always with exactly one decimal so a column of
|
|
177
|
+
* them reads alike: plain under a thousand, then K and M. */
|
|
178
|
+
function compactTokens(value) {
|
|
179
|
+
if (value < 1e3) return value.toFixed(1);
|
|
180
|
+
if (value < 999950) return `${(value / 1e3).toFixed(1)}K`;
|
|
181
|
+
return `${(value / 1e6).toFixed(1)}M`;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* A number drawn so that a column of them lines up on the decimal point: the
|
|
185
|
+
* whole part right-aligned, then the fraction and the unit together in one
|
|
186
|
+
* left-aligned slot of fixed width, empty when the number has neither.
|
|
187
|
+
*/
|
|
188
|
+
function AlignedNumber({ text, className }) {
|
|
189
|
+
const match = /^(<?\d+)(\.\d+)?([A-Za-z%]*)$/.exec(text);
|
|
190
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
191
|
+
className: `${className} cu-num`,
|
|
192
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
193
|
+
className: "cu-num-int",
|
|
194
|
+
children: match ? match[1] : text
|
|
195
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
196
|
+
className: "cu-num-tail",
|
|
197
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
198
|
+
className: "cu-num-frac",
|
|
199
|
+
children: match?.[2] ?? ""
|
|
200
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
201
|
+
className: "cu-num-unit",
|
|
202
|
+
children: match?.[3] ?? ""
|
|
203
|
+
})]
|
|
204
|
+
})]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Integer shares of `total` in proportion to `weights`, by largest remainder,
|
|
209
|
+
* earlier entries first on a tie; the shares always sum to `total`.
|
|
210
|
+
*/
|
|
211
|
+
function apportion(total, weights) {
|
|
212
|
+
const whole = weights.reduce((sum, weight) => sum + weight, 0);
|
|
213
|
+
if (whole === 0) return weights.map(() => 0);
|
|
214
|
+
const exact = weights.map((weight) => weight / whole * total);
|
|
215
|
+
const shares = exact.map(Math.floor);
|
|
216
|
+
let left = total - shares.reduce((sum, share) => sum + share, 0);
|
|
217
|
+
const order = exact.map((value, index) => ({
|
|
218
|
+
index,
|
|
219
|
+
fraction: value - Math.floor(value)
|
|
220
|
+
})).sort((a, b) => b.fraction - a.fraction || a.index - b.index);
|
|
221
|
+
for (const { index } of order) {
|
|
222
|
+
if (left === 0) break;
|
|
223
|
+
shares[index] = (shares[index] ?? 0) + 1;
|
|
224
|
+
left -= 1;
|
|
225
|
+
}
|
|
226
|
+
return shares;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The map's cells in reading order: the used cells (the total over the window,
|
|
230
|
+
* capped at the whole map) shared out across the categories in their fixed
|
|
231
|
+
* order, then free room. A category too small for one cell has none here and
|
|
232
|
+
* still has its legend row.
|
|
233
|
+
*/
|
|
234
|
+
function cellsOf(occupancy, window) {
|
|
235
|
+
const used = Math.min(CELLS, Math.round(occupancy.inputTokens / window * CELLS));
|
|
236
|
+
const categories = occupancy.categories;
|
|
237
|
+
const filled = categories === void 0 ? Array.from({ length: used }, () => "used") : apportion(used, categories.map((one) => one.tokens)).flatMap((count, index) => Array.from({ length: count }, () => categories[index]?.category ?? "used"));
|
|
238
|
+
return [...filled, ...Array.from({ length: CELLS - filled.length }, () => "free")];
|
|
239
|
+
}
|
|
240
|
+
/** Elapsed time is display-only; it never cancels a context operation. */
|
|
241
|
+
function PreparationProgress({ startedAt, completedChunks, t }) {
|
|
242
|
+
const [now, setNow] = useState(Date.now);
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
if (startedAt === void 0) return;
|
|
245
|
+
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
246
|
+
return () => clearInterval(timer);
|
|
247
|
+
}, [startedAt]);
|
|
248
|
+
return /* @__PURE__ */ jsxs("p", {
|
|
249
|
+
role: "status",
|
|
250
|
+
children: [
|
|
251
|
+
t("usage.preparing"),
|
|
252
|
+
startedAt !== void 0 && ` · ${t("usage.elapsed", { seconds: Math.max(0, Math.floor((now - startedAt) / 1e3)) })}`,
|
|
253
|
+
completedChunks !== void 0 && ` · ${t("usage.completedChunks", { count: completedChunks })}`
|
|
254
|
+
]
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
/** Draws the host's occupancy as a meter, its window map and the legend by category. */
|
|
258
|
+
function contextUsageFor(host) {
|
|
259
|
+
return function ContextUsage({ sessionId }) {
|
|
260
|
+
const state = useSyncExternalStore(host.host.subscribe, host.host.get);
|
|
261
|
+
const fail = useFailureToast(host);
|
|
262
|
+
const [toolsOpen, setToolsOpen] = useState(false);
|
|
263
|
+
const [pending, setPending] = useState(false);
|
|
264
|
+
const running = useRef(false);
|
|
265
|
+
const t = host.i18n.t;
|
|
266
|
+
const context = useSyncExternalStore(host.context.subscribe, () => host.context.get(sessionId));
|
|
267
|
+
useEffect(() => host.context.watch(sessionId), [sessionId]);
|
|
268
|
+
const currentOccupancy = context?.occupancy?.source === "unmeasured" ? void 0 : context?.occupancy;
|
|
269
|
+
const historical = currentOccupancy === void 0 ? context?.lastObservation : void 0;
|
|
270
|
+
const occupancy = currentOccupancy ?? historical?.occupancy;
|
|
271
|
+
const measurement = historical?.measurement ?? context?.measurement;
|
|
272
|
+
const limit = measurement?.contextWindow;
|
|
273
|
+
const share = occupancy === void 0 || limit === void 0 ? void 0 : Math.min(100, Math.round(occupancy.inputTokens / limit * 100));
|
|
274
|
+
const level = share === void 0 ? void 0 : contextLevel(share);
|
|
275
|
+
const mark = occupancy?.source === "estimated" ? "~" : "";
|
|
276
|
+
const operation = context?.operation;
|
|
277
|
+
const blocked = context?.measurement?.inputBudget !== void 0 && context.measurement.inputTokens > context.measurement.inputBudget;
|
|
278
|
+
const reason = context?.lastResult?.reason ?? context?.diagnostic;
|
|
279
|
+
const reasonText = reason === void 0 ? void 0 : t(REASONS.has(reason) ? `usage.reason.${reason}` : "usage.failed");
|
|
280
|
+
const tokens = (value) => value === void 0 ? "—" : compactTokens(value);
|
|
281
|
+
const percent = (value) => {
|
|
282
|
+
if (limit === void 0) return "";
|
|
283
|
+
const share = value / limit * 100;
|
|
284
|
+
return value > 0 && share < .05 ? "<0.1%" : `${share.toFixed(1)}%`;
|
|
285
|
+
};
|
|
286
|
+
const rows = occupancy === void 0 ? [] : [...occupancy.categories === void 0 ? [{
|
|
287
|
+
key: "used",
|
|
288
|
+
tokens: occupancy.inputTokens
|
|
289
|
+
}] : occupancy.categories.filter((one) => one.tokens > 0).map((one) => ({
|
|
290
|
+
key: one.category,
|
|
291
|
+
tokens: one.tokens
|
|
292
|
+
})), ...limit === void 0 ? [] : [{
|
|
293
|
+
key: "free",
|
|
294
|
+
tokens: Math.max(0, limit - occupancy.inputTokens)
|
|
295
|
+
}]];
|
|
296
|
+
const owners = [...occupancy?.tools ?? []].filter((one) => one.tokens > 0).sort((a, b) => b.tokens - a.tokens);
|
|
297
|
+
async function run(action) {
|
|
298
|
+
if (running.current) return;
|
|
299
|
+
running.current = true;
|
|
300
|
+
setPending(true);
|
|
301
|
+
try {
|
|
302
|
+
await action();
|
|
303
|
+
} catch {
|
|
304
|
+
fail(t("usage.failed"));
|
|
305
|
+
} finally {
|
|
306
|
+
running.current = false;
|
|
307
|
+
setPending(false);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function cancel() {
|
|
311
|
+
if (operation === void 0) return Promise.resolve();
|
|
312
|
+
return run(() => host.call("cancel", {
|
|
313
|
+
sessionId,
|
|
314
|
+
operationId: operation.operationId
|
|
315
|
+
}));
|
|
316
|
+
}
|
|
317
|
+
function retry() {
|
|
318
|
+
return run(() => host.call("compact", { sessionId }));
|
|
319
|
+
}
|
|
320
|
+
function nameOf(key) {
|
|
321
|
+
if (key === "used") return t("usage.used");
|
|
322
|
+
if (key === "free") return t("usage.free");
|
|
323
|
+
return t(`usage.category.${key}`);
|
|
324
|
+
}
|
|
325
|
+
return /* @__PURE__ */ jsxs(host.ui.Popover, {
|
|
326
|
+
width: 360,
|
|
327
|
+
label: t("usage.context"),
|
|
328
|
+
side: "top",
|
|
329
|
+
align: "end",
|
|
330
|
+
className: "cu-panel",
|
|
331
|
+
trigger: /* @__PURE__ */ jsxs(host.ui.Button, {
|
|
332
|
+
variant: "plain",
|
|
333
|
+
className: "cu",
|
|
334
|
+
"data-level": level,
|
|
335
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
336
|
+
className: "cu-name",
|
|
337
|
+
children: t("usage.context")
|
|
338
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
339
|
+
...share === void 0 ? {} : {
|
|
340
|
+
role: "progressbar",
|
|
341
|
+
"aria-label": t("usage.context"),
|
|
342
|
+
"aria-valuemin": 0,
|
|
343
|
+
"aria-valuemax": 100,
|
|
344
|
+
"aria-valuenow": share
|
|
345
|
+
},
|
|
346
|
+
className: "cu-bar",
|
|
347
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
348
|
+
className: "cu-fill",
|
|
349
|
+
style: { inlineSize: `${share ?? 0}%` }
|
|
350
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
351
|
+
className: share === void 0 ? "cu-unknown" : "cu-share",
|
|
352
|
+
children: share === void 0 ? t("usage.unmeasured") : `${mark}${share}%`
|
|
353
|
+
})]
|
|
354
|
+
})]
|
|
355
|
+
}),
|
|
356
|
+
children: [
|
|
357
|
+
/* @__PURE__ */ jsxs("p", {
|
|
358
|
+
className: "cu-head",
|
|
359
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
360
|
+
className: "cu-head-name",
|
|
361
|
+
children: t("usage.context")
|
|
362
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
363
|
+
className: "cu-head-value",
|
|
364
|
+
children: [share !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
365
|
+
className: "cu-head-share",
|
|
366
|
+
children: `${mark}${share}%`
|
|
367
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
368
|
+
className: "cu-head-count",
|
|
369
|
+
children: occupancy === void 0 ? "—" : limit === void 0 ? tokens(occupancy.inputTokens) : t("usage.headCount", {
|
|
370
|
+
used: tokens(occupancy.inputTokens),
|
|
371
|
+
window: formatContextWindow(limit)
|
|
372
|
+
})
|
|
373
|
+
})]
|
|
374
|
+
})]
|
|
375
|
+
}),
|
|
376
|
+
historical && /* @__PURE__ */ jsx("p", {
|
|
377
|
+
className: "cu-note",
|
|
378
|
+
children: t("usage.lastObservation")
|
|
379
|
+
}),
|
|
380
|
+
occupancy !== void 0 && limit !== void 0 && /* @__PURE__ */ jsx("div", {
|
|
381
|
+
className: "cu-map",
|
|
382
|
+
"aria-hidden": "true",
|
|
383
|
+
"data-level": level,
|
|
384
|
+
children: cellsOf(occupancy, limit).map((key, index) => /* @__PURE__ */ jsx("span", {
|
|
385
|
+
className: "cu-cell",
|
|
386
|
+
"data-cell": key
|
|
387
|
+
}, index))
|
|
388
|
+
}),
|
|
389
|
+
rows.length > 0 && /* @__PURE__ */ jsx("ul", {
|
|
390
|
+
className: "cu-legend",
|
|
391
|
+
"data-level": level,
|
|
392
|
+
children: rows.map((row) => /* @__PURE__ */ jsxs("li", {
|
|
393
|
+
className: "cu-legend-item",
|
|
394
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
395
|
+
className: "cu-legend-row",
|
|
396
|
+
children: [
|
|
397
|
+
/* @__PURE__ */ jsx("span", {
|
|
398
|
+
className: "cu-swatch",
|
|
399
|
+
"data-cell": row.key,
|
|
400
|
+
"aria-hidden": "true"
|
|
401
|
+
}),
|
|
402
|
+
row.key === "tools" && owners.length > 0 ? /* @__PURE__ */ jsx(host.ui.Button, {
|
|
403
|
+
variant: "plain",
|
|
404
|
+
type: "button",
|
|
405
|
+
className: "cu-legend-name cu-tools-toggle",
|
|
406
|
+
"aria-expanded": toolsOpen,
|
|
407
|
+
onClick: () => setToolsOpen(!toolsOpen),
|
|
408
|
+
children: nameOf(row.key)
|
|
409
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
410
|
+
className: "cu-legend-name",
|
|
411
|
+
children: nameOf(row.key)
|
|
412
|
+
}),
|
|
413
|
+
/* @__PURE__ */ jsx(AlignedNumber, {
|
|
414
|
+
className: "cu-legend-count",
|
|
415
|
+
text: tokens(row.tokens)
|
|
416
|
+
}),
|
|
417
|
+
/* @__PURE__ */ jsx(AlignedNumber, {
|
|
418
|
+
className: "cu-legend-share",
|
|
419
|
+
text: percent(row.tokens)
|
|
420
|
+
})
|
|
421
|
+
]
|
|
422
|
+
}), row.key === "tools" && toolsOpen && /* @__PURE__ */ jsx("ul", {
|
|
423
|
+
className: "cu-owners",
|
|
424
|
+
children: owners.map((one) => /* @__PURE__ */ jsxs("li", {
|
|
425
|
+
className: "cu-legend-row cu-owner",
|
|
426
|
+
children: [
|
|
427
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true" }),
|
|
428
|
+
/* @__PURE__ */ jsx("span", {
|
|
429
|
+
className: "cu-owner-name",
|
|
430
|
+
children: one.owner ?? t("usage.builtin")
|
|
431
|
+
}),
|
|
432
|
+
/* @__PURE__ */ jsx(AlignedNumber, {
|
|
433
|
+
className: "cu-legend-count",
|
|
434
|
+
text: tokens(one.tokens)
|
|
435
|
+
}),
|
|
436
|
+
/* @__PURE__ */ jsx(AlignedNumber, {
|
|
437
|
+
className: "cu-legend-share",
|
|
438
|
+
text: percent(one.tokens)
|
|
439
|
+
})
|
|
440
|
+
]
|
|
441
|
+
}, one.owner ?? ""))
|
|
442
|
+
})]
|
|
443
|
+
}, row.key))
|
|
444
|
+
}),
|
|
445
|
+
occupancy !== void 0 && /* @__PURE__ */ jsxs("p", {
|
|
446
|
+
className: "cu-note",
|
|
447
|
+
children: [t(occupancy.source === "reported" ? "usage.noteReported" : "usage.noteEstimated"), occupancy.categories === void 0 && ` ${t("usage.noSplit")}`]
|
|
448
|
+
}),
|
|
449
|
+
/* @__PURE__ */ jsxs("dl", {
|
|
450
|
+
className: "cu-stats",
|
|
451
|
+
children: [
|
|
452
|
+
measurement?.inputBudget !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", { children: t("usage.inputBudget") }), /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx(AlignedNumber, {
|
|
453
|
+
className: "cu-stat",
|
|
454
|
+
text: tokens(measurement.inputBudget)
|
|
455
|
+
}) })] }),
|
|
456
|
+
measurement !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", { children: t("usage.outputReserve") }), /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx(AlignedNumber, {
|
|
457
|
+
className: "cu-stat",
|
|
458
|
+
text: tokens(measurement.outputReserve)
|
|
459
|
+
}) })] }),
|
|
460
|
+
/* @__PURE__ */ jsx("dt", { children: t("usage.actual") }),
|
|
461
|
+
/* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx(AlignedNumber, {
|
|
462
|
+
className: "cu-stat",
|
|
463
|
+
text: tokens(historical?.actualInputTokens ?? context?.actualInputTokens)
|
|
464
|
+
}) }),
|
|
465
|
+
/* @__PURE__ */ jsx("dt", { children: t("usage.total") }),
|
|
466
|
+
/* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx(AlignedNumber, {
|
|
467
|
+
className: "cu-stat",
|
|
468
|
+
text: tokens(context?.totalTokens ?? state.tokensUsed ?? void 0)
|
|
469
|
+
}) }),
|
|
470
|
+
/* @__PURE__ */ jsx("dt", { children: t("usage.auxiliary") }),
|
|
471
|
+
/* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx(AlignedNumber, {
|
|
472
|
+
className: "cu-stat",
|
|
473
|
+
text: tokens(context?.auxiliaryTokens)
|
|
474
|
+
}) })
|
|
475
|
+
]
|
|
476
|
+
}),
|
|
477
|
+
measurement?.outputReserveSource !== void 0 && /* @__PURE__ */ jsx("p", {
|
|
478
|
+
className: "cu-note",
|
|
479
|
+
children: t(`usage.reserveSource.${measurement.outputReserveSource}`)
|
|
480
|
+
}),
|
|
481
|
+
operation !== void 0 && /* @__PURE__ */ jsx(PreparationProgress, {
|
|
482
|
+
startedAt: operation.startedAt,
|
|
483
|
+
completedChunks: operation.completedChunks,
|
|
484
|
+
t
|
|
485
|
+
}),
|
|
486
|
+
context?.lastResult && /* @__PURE__ */ jsxs("section", {
|
|
487
|
+
"aria-label": t(operation ? "usage.previousResult" : "usage.latestResult"),
|
|
488
|
+
children: [
|
|
489
|
+
/* @__PURE__ */ jsx("p", {
|
|
490
|
+
className: "cu-note",
|
|
491
|
+
children: t(operation ? "usage.previousResult" : "usage.latestResult")
|
|
492
|
+
}),
|
|
493
|
+
/* @__PURE__ */ jsxs("p", {
|
|
494
|
+
role: "status",
|
|
495
|
+
className: "cu-note",
|
|
496
|
+
children: [
|
|
497
|
+
t(context.lastResult.status === "changed" && context.lastResult.layer === "none" ? "usage.previewChanged" : `usage.${context.lastResult.status}`),
|
|
498
|
+
context.lastResult.layer !== "none" && ` · ${context.lastResult.layer}`,
|
|
499
|
+
" · ",
|
|
500
|
+
t(`usage.trigger.${context.lastResult.trigger}`),
|
|
501
|
+
" · ",
|
|
502
|
+
context.lastResult.elapsedMs,
|
|
503
|
+
" ms",
|
|
504
|
+
context.lastResult.before && context.lastResult.after && ` · ${tokens(context.lastResult.before.inputTokens)} → ${tokens(context.lastResult.after.inputTokens)}`,
|
|
505
|
+
context.lastResult.summaryModel && ` · ${t("usage.summaryModel")} ${context.lastResult.summaryModel.model}`,
|
|
506
|
+
context.lastResult.completedChunks !== void 0 && ` · ${t("usage.completedChunks", { count: context.lastResult.completedChunks })}`
|
|
507
|
+
]
|
|
508
|
+
}),
|
|
509
|
+
context.lastResult.reason && reasonText && /* @__PURE__ */ jsx(host.ui.Alert, {
|
|
510
|
+
tone: "warning",
|
|
511
|
+
children: reasonText
|
|
512
|
+
})
|
|
513
|
+
]
|
|
514
|
+
}),
|
|
515
|
+
!context?.lastResult?.reason && reasonText && /* @__PURE__ */ jsx(host.ui.Alert, {
|
|
516
|
+
tone: "warning",
|
|
517
|
+
children: reasonText
|
|
518
|
+
}),
|
|
519
|
+
context?.lastResult?.status === "failed" && operation === void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
|
|
520
|
+
role: "status",
|
|
521
|
+
className: "cu-note",
|
|
522
|
+
children: t(blocked ? "usage.blocked" : "usage.canContinue")
|
|
523
|
+
}), /* @__PURE__ */ jsx(host.ui.Button, {
|
|
524
|
+
variant: "ghost",
|
|
525
|
+
type: "button",
|
|
526
|
+
loading: pending,
|
|
527
|
+
disabled: pending || state.connection !== "online" || state.phase !== void 0 && state.phase !== "idle",
|
|
528
|
+
onClick: () => void retry(),
|
|
529
|
+
children: t("usage.retry")
|
|
530
|
+
})] }),
|
|
531
|
+
operation !== void 0 && /* @__PURE__ */ jsx(host.ui.Button, {
|
|
532
|
+
variant: "ghost",
|
|
533
|
+
type: "button",
|
|
534
|
+
loading: pending,
|
|
535
|
+
disabled: pending || state.connection !== "online",
|
|
536
|
+
onClick: () => void cancel(),
|
|
537
|
+
children: t("usage.cancel")
|
|
538
|
+
})
|
|
539
|
+
]
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region ui-src/components/tool-preview.tsx
|
|
545
|
+
/** Observes only mounted tool lines and withdraws together with the Context extension. */
|
|
546
|
+
function registerPreviewNotice(ctx, status) {
|
|
547
|
+
ctx.i18n.register({
|
|
548
|
+
"en-US": { toolPreview: "The model received a preview; the original tool result is retained here." },
|
|
549
|
+
"zh-CN": { toolPreview: "模型收到的是预览,此处保留工具返回的原文。" }
|
|
550
|
+
}, "en-US");
|
|
551
|
+
function Notice({ sessionId, call }) {
|
|
552
|
+
useSyncExternalStore(ctx.i18n.subscribe, ctx.i18n.language);
|
|
553
|
+
useEffect(() => sessionId === void 0 ? void 0 : status.watch(sessionId), [sessionId]);
|
|
554
|
+
if (!useSyncExternalStore(status.subscribe, () => sessionId === void 0 ? void 0 : status.get(sessionId))?.previews?.some((one) => one.toolUseId === call.id && one.truncated)) return null;
|
|
555
|
+
return /* @__PURE__ */ jsx("p", {
|
|
556
|
+
className: "text-xs text-muted-foreground",
|
|
557
|
+
children: ctx.i18n.t("toolPreview")
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
ctx.slots.register("chat.tool.presentation", {
|
|
561
|
+
id: "preview-notice",
|
|
562
|
+
describe: () => ({ notice: Notice })
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region src/tool-names.ts
|
|
567
|
+
/** Canonical names shared by tool registration and browser presentation. */
|
|
568
|
+
var TOOL_NAMES = [
|
|
569
|
+
"context_search",
|
|
570
|
+
"context_restore",
|
|
571
|
+
"session_note",
|
|
572
|
+
"tool_search",
|
|
573
|
+
"tool_call"
|
|
574
|
+
];
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region ui-src/metadata.ts
|
|
577
|
+
var CATALOGUES = {
|
|
578
|
+
"en-US": {
|
|
579
|
+
section: "Built-in plugins",
|
|
580
|
+
group: "Context",
|
|
581
|
+
context_search: "Search history",
|
|
582
|
+
context_restore: "Restore history",
|
|
583
|
+
session_note: "Update session notes",
|
|
584
|
+
tool_search: "Search tools",
|
|
585
|
+
tool_call: "Call tool"
|
|
586
|
+
},
|
|
587
|
+
"zh-CN": {
|
|
588
|
+
section: "内置插件",
|
|
589
|
+
group: "上下文",
|
|
590
|
+
context_search: "搜索历史上下文",
|
|
591
|
+
context_restore: "恢复历史上下文",
|
|
592
|
+
session_note: "更新会话笔记",
|
|
593
|
+
tool_search: "检索工具",
|
|
594
|
+
tool_call: "调用工具"
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
var names = new Set(TOOL_NAMES);
|
|
598
|
+
/** Registers presentation facets with the same activation lifetime as the tools. */
|
|
599
|
+
function registerMetadata(ctx) {
|
|
600
|
+
ctx.i18n.register(CATALOGUES, "en-US");
|
|
601
|
+
ctx.i18n.contribute(Object.fromEntries(Object.entries(CATALOGUES).map(([language, catalogue]) => [language, Object.fromEntries([...names].map((tool) => [`transcript.actions.${tool}`, catalogue[tool] ?? tool]))])), "en-US");
|
|
602
|
+
ctx.slots.register("chat.tool.presentation", {
|
|
603
|
+
id: "tool-metadata",
|
|
604
|
+
describe: ({ call }) => {
|
|
605
|
+
if (!names.has(call.name)) return void 0;
|
|
606
|
+
const input = call.input !== null && typeof call.input === "object" ? call.input : {};
|
|
607
|
+
const summary = [
|
|
608
|
+
"path",
|
|
609
|
+
"url",
|
|
610
|
+
"query",
|
|
611
|
+
"command",
|
|
612
|
+
"skill",
|
|
613
|
+
"id",
|
|
614
|
+
"name",
|
|
615
|
+
"task",
|
|
616
|
+
"prompt"
|
|
617
|
+
].flatMap((key) => typeof input[key] === "string" ? [input[key]] : []).slice(0, 2).join(" · ").replace(/\s+/g, " ").slice(0, 240);
|
|
618
|
+
return {
|
|
619
|
+
label: names.has(call.name) ? ctx.i18n.t(call.name) : call.name,
|
|
620
|
+
icon: "hammer",
|
|
621
|
+
summary
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
ctx.slots.register("shell.tools.group", {
|
|
626
|
+
id: "tool-groups",
|
|
627
|
+
describe: (tool) => {
|
|
628
|
+
if (tool.plugin !== ctx.plugin) return void 0;
|
|
629
|
+
return {
|
|
630
|
+
key: `plugin:${ctx.plugin}`,
|
|
631
|
+
label: ctx.i18n.t("group"),
|
|
632
|
+
source: ctx.plugin,
|
|
633
|
+
sectionLabel: ctx.i18n.t("section"),
|
|
634
|
+
sectionOrder: 1,
|
|
635
|
+
order: 2
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region ui-src/lib/commands.ts
|
|
642
|
+
/** Registers the manual context command with the plugin's withdrawal lifetime. */
|
|
643
|
+
function registerCommands(ctx) {
|
|
644
|
+
const t = ctx.i18n.t;
|
|
645
|
+
const reason = (key, fallback) => {
|
|
646
|
+
const value = key === void 0 ? "" : t(`usage.reason.${key}`);
|
|
647
|
+
return value && value !== `usage.reason.${key}` ? value : t(fallback);
|
|
648
|
+
};
|
|
649
|
+
function message(result) {
|
|
650
|
+
switch (result.status) {
|
|
651
|
+
case "changed": {
|
|
652
|
+
const before = result.before?.inputTokens;
|
|
653
|
+
const after = result.after?.inputTokens;
|
|
654
|
+
if (before === void 0 || after === void 0) return t("compact.changed");
|
|
655
|
+
const format = new Intl.NumberFormat(ctx.i18n.language());
|
|
656
|
+
return t("compact.changedTokens", {
|
|
657
|
+
before: format.format(before),
|
|
658
|
+
after: format.format(after)
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
case "unchanged": return reason(result.reason, "compact.unchanged");
|
|
662
|
+
case "failed": throw Error(reason(result.reason, "compact.failed"));
|
|
663
|
+
case "cancelled": throw Error(t("compact.cancelled"));
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
const compact = {
|
|
667
|
+
kind: "run",
|
|
668
|
+
name: "compact",
|
|
669
|
+
description: () => t("commands.compact"),
|
|
670
|
+
async run(_, target) {
|
|
671
|
+
if (target.sessionId === null) throw Error("context preparation requires a session");
|
|
672
|
+
try {
|
|
673
|
+
return { message: message(await ctx.invoke("compact", { sessionId: target.sessionId })) };
|
|
674
|
+
} catch (error) {
|
|
675
|
+
const kind = error?.failure;
|
|
676
|
+
if (kind === "offline" || kind === "authentication") throw error;
|
|
677
|
+
throw Error(failureText(error, t) ?? String(error));
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
ctx.slots.register("chat.composer.commands", {
|
|
682
|
+
id: "contextCommands",
|
|
683
|
+
order: -10,
|
|
684
|
+
namespace: "host",
|
|
685
|
+
label: () => t("commands.source"),
|
|
686
|
+
errorLabel: "",
|
|
687
|
+
executionTimeoutMs: 0,
|
|
688
|
+
commands: (target) => target.sessionId === null ? [] : [compact]
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region ui-src/lib/tool-preload.ts
|
|
693
|
+
function object(value) {
|
|
694
|
+
if (value === void 0) return {};
|
|
695
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error("Tool preload configuration must be an object");
|
|
696
|
+
return value;
|
|
697
|
+
}
|
|
698
|
+
function read(value) {
|
|
699
|
+
const overrides = object(object(value).toolPreload);
|
|
700
|
+
for (const [name, enabled] of Object.entries(overrides)) {
|
|
701
|
+
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(name) || typeof enabled !== "boolean") throw new Error("Tool preload overrides must map valid tool names to booleans");
|
|
702
|
+
if (name === "tool_search" || name === "tool_call") throw new Error("System tool preload cannot be overridden");
|
|
703
|
+
}
|
|
704
|
+
return { ...overrides };
|
|
705
|
+
}
|
|
706
|
+
/** Retains other owner fields and replaces sparse overrides; invalid data throws before editing. */
|
|
707
|
+
var toolPreloadConfiguration = {
|
|
708
|
+
owner: "@eum-agent/context-management",
|
|
709
|
+
read,
|
|
710
|
+
replace: (value, overrides) => {
|
|
711
|
+
read(value);
|
|
712
|
+
const toolPreload = read({ toolPreload: overrides });
|
|
713
|
+
return {
|
|
714
|
+
...object(value),
|
|
715
|
+
toolPreload
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
//#endregion
|
|
720
|
+
//#region ui-src/locales/en-US.ts
|
|
721
|
+
/** Context surface translations. */
|
|
722
|
+
var catalogue$1 = {
|
|
723
|
+
connection: {
|
|
724
|
+
offline: "Not connected to the gateway",
|
|
725
|
+
authenticationRequired: "Authentication is unavailable. Run yaoguang webui to reopen this page."
|
|
726
|
+
},
|
|
727
|
+
commands: {
|
|
728
|
+
source: "Built-in",
|
|
729
|
+
compact: "Compact this session's context"
|
|
730
|
+
},
|
|
731
|
+
compact: {
|
|
732
|
+
changed: "Compacted",
|
|
733
|
+
changedTokens: "Compacted: {{before}} → {{after}} tokens",
|
|
734
|
+
unchanged: "Nothing to compact",
|
|
735
|
+
failed: "Compaction failed",
|
|
736
|
+
cancelled: "Compaction was cancelled"
|
|
737
|
+
},
|
|
738
|
+
status: { context: "Context usage" },
|
|
739
|
+
usage: {
|
|
740
|
+
lastObservation: "Showing the last saved context observation until a new measurement is available. This value is not used for current request capacity checks.",
|
|
741
|
+
context: "Context",
|
|
742
|
+
unmeasured: "unmeasured",
|
|
743
|
+
used: "Used",
|
|
744
|
+
headCount: "({{used}} of {{window}})",
|
|
745
|
+
free: "Free",
|
|
746
|
+
builtin: "Built in",
|
|
747
|
+
noteReported: "The total is the usage the model endpoint reported; categories are apportioned by content.",
|
|
748
|
+
noteEstimated: "The total is an estimate until the reply arrives; categories are apportioned by content.",
|
|
749
|
+
noSplit: "No category split this time.",
|
|
750
|
+
category: {
|
|
751
|
+
system: "System prompt",
|
|
752
|
+
rules: "Rules files",
|
|
753
|
+
skills: "Skills",
|
|
754
|
+
agents: "Agent catalogue",
|
|
755
|
+
tools: "Tools",
|
|
756
|
+
messages: "Conversation",
|
|
757
|
+
volatile: "Live facts",
|
|
758
|
+
files: "Images"
|
|
759
|
+
},
|
|
760
|
+
actual: "Last actual input",
|
|
761
|
+
total: "Total consumption",
|
|
762
|
+
inputBudget: "Safe input budget",
|
|
763
|
+
outputReserve: "Reserved for output",
|
|
764
|
+
reserveSource: {
|
|
765
|
+
capacity: "Output reserve uses model capacity",
|
|
766
|
+
enforced: "Output reserve uses the enforced request limit"
|
|
767
|
+
},
|
|
768
|
+
completedChunks: "Saved summaries: {{count}}",
|
|
769
|
+
completedChunks_one: "Saved summaries: {{count}}",
|
|
770
|
+
blocked: "Input still exceeds the budget. Retry compaction, choose a larger model, or start a new session.",
|
|
771
|
+
canContinue: "Input remains within budget; the task can continue with the saved context.",
|
|
772
|
+
retry: "Retry compaction",
|
|
773
|
+
auxiliary: "Including summary consumption",
|
|
774
|
+
preparing: "Preparing context",
|
|
775
|
+
elapsed: "{{seconds}} seconds elapsed",
|
|
776
|
+
cancel: "Cancel preparation",
|
|
777
|
+
changed: "Compacted",
|
|
778
|
+
unchanged: "No compaction needed",
|
|
779
|
+
failed: "Context preparation failed",
|
|
780
|
+
previewChanged: "Tool result previews reduced",
|
|
781
|
+
previousResult: "Previous context preparation",
|
|
782
|
+
latestResult: "Latest context preparation",
|
|
783
|
+
cancelled: "Cancelled",
|
|
784
|
+
summaryModel: "Summary model",
|
|
785
|
+
trigger: {
|
|
786
|
+
auto: "Automatic preparation",
|
|
787
|
+
manual: "Manual preparation",
|
|
788
|
+
"model-switch": "Model switch preparation"
|
|
789
|
+
},
|
|
790
|
+
reason: {
|
|
791
|
+
capacity_unknown: "Model window unknown; configure the context capacity",
|
|
792
|
+
context_projection_degraded: "Invalid compaction record; the last valid view is retained",
|
|
793
|
+
fixed_context_too_large: "Required content exceeds the window; choose a larger model window",
|
|
794
|
+
recovery_unavailable: "Enable history search and original restoration tools",
|
|
795
|
+
summary_budget_too_small: "Not enough space to generate a summary",
|
|
796
|
+
summary_network_error: "The summary connection failed or stopped responding; saved summaries are retained",
|
|
797
|
+
summary_invalid: "The summary was invalid; the previous context is retained",
|
|
798
|
+
summary_provider_unavailable: "The model endpoint could not produce a summary; check the connection settings and retry",
|
|
799
|
+
summary_unavailable: "Automatic summary attempts stopped after failures; retry manually when ready",
|
|
800
|
+
summary_group_too_large: "A protected history group is too large to summarize; choose a larger model",
|
|
801
|
+
protected_context_exceeds_budget: "Required content exceeds the safe input budget; choose a larger model",
|
|
802
|
+
summary_failed: "Summary failed; you can retry manually",
|
|
803
|
+
summary_no_gain: "Summary did not reduce input; the previous view is retained",
|
|
804
|
+
context_still_exceeds_budget: "The summary is saved, but the request still exceeds the model input limit",
|
|
805
|
+
cancelled: "Preparation was cancelled"
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
//#endregion
|
|
810
|
+
//#region ui-src/locales/zh-CN.ts
|
|
811
|
+
/** Context surface translations. */
|
|
812
|
+
var catalogue = {
|
|
813
|
+
connection: {
|
|
814
|
+
offline: "未连接到网关服务",
|
|
815
|
+
authenticationRequired: "认证不可用,请运行 yaoguang webui 重新打开"
|
|
816
|
+
},
|
|
817
|
+
commands: {
|
|
818
|
+
source: "内置",
|
|
819
|
+
compact: "压缩这个会话的上下文"
|
|
820
|
+
},
|
|
821
|
+
compact: {
|
|
822
|
+
changed: "已压缩",
|
|
823
|
+
changedTokens: "已压缩:{{before}} → {{after}} tokens",
|
|
824
|
+
unchanged: "无需压缩",
|
|
825
|
+
failed: "压缩失败",
|
|
826
|
+
cancelled: "压缩已取消"
|
|
827
|
+
},
|
|
828
|
+
status: { context: "上下文占用" },
|
|
829
|
+
usage: {
|
|
830
|
+
lastObservation: "显示上次保存的上下文统计;新测量完成后更新。此值不用于当前请求的容量判断。",
|
|
831
|
+
context: "上下文",
|
|
832
|
+
unmeasured: "未测得",
|
|
833
|
+
used: "已用",
|
|
834
|
+
headCount: "({{used}} of {{window}})",
|
|
835
|
+
free: "可用",
|
|
836
|
+
builtin: "内置",
|
|
837
|
+
noteReported: "总数取自模型接口回报的用量,各类按内容比例分配。",
|
|
838
|
+
noteEstimated: "总数为估算,收到回复后更新;各类按内容比例分配。",
|
|
839
|
+
noSplit: "这次没有算出分类。",
|
|
840
|
+
category: {
|
|
841
|
+
system: "系统提示词",
|
|
842
|
+
rules: "规则文件",
|
|
843
|
+
skills: "技能",
|
|
844
|
+
agents: "智能体目录",
|
|
845
|
+
tools: "工具",
|
|
846
|
+
messages: "对话消息",
|
|
847
|
+
volatile: "实时信息",
|
|
848
|
+
files: "图片"
|
|
849
|
+
},
|
|
850
|
+
actual: "最近实际输入",
|
|
851
|
+
total: "累计消耗",
|
|
852
|
+
inputBudget: "安全输入预算",
|
|
853
|
+
outputReserve: "输出预留",
|
|
854
|
+
reserveSource: {
|
|
855
|
+
capacity: "按模型输出容量预留",
|
|
856
|
+
enforced: "按本次请求的有效输出上限预留"
|
|
857
|
+
},
|
|
858
|
+
completedChunks: "已保存 {{count}} 段摘要",
|
|
859
|
+
blocked: "输入仍超出预算,可重试整理、切换更大窗口的模型或新建会话。",
|
|
860
|
+
canContinue: "输入仍在安全预算内,任务可使用已保存的上下文继续。",
|
|
861
|
+
retry: "重试整理",
|
|
862
|
+
auxiliary: "其中摘要消耗",
|
|
863
|
+
preparing: "正在准备上下文",
|
|
864
|
+
elapsed: "已用时 {{seconds}} 秒",
|
|
865
|
+
cancel: "取消准备",
|
|
866
|
+
changed: "已压缩",
|
|
867
|
+
unchanged: "无需压缩",
|
|
868
|
+
failed: "上下文准备失败",
|
|
869
|
+
previewChanged: "已缩减工具结果预览",
|
|
870
|
+
previousResult: "上次上下文准备",
|
|
871
|
+
latestResult: "最近一次上下文准备",
|
|
872
|
+
cancelled: "已取消",
|
|
873
|
+
summaryModel: "摘要模型",
|
|
874
|
+
trigger: {
|
|
875
|
+
auto: "自动准备",
|
|
876
|
+
manual: "手动准备",
|
|
877
|
+
"model-switch": "模型切换准备"
|
|
878
|
+
},
|
|
879
|
+
reason: {
|
|
880
|
+
capacity_unknown: "模型窗口未知,请配置上下文容量",
|
|
881
|
+
context_projection_degraded: "压缩记录校验失败,已保留最后有效视图",
|
|
882
|
+
fixed_context_too_large: "当前必须保留的内容超出窗口,请切换更大窗口的模型",
|
|
883
|
+
recovery_unavailable: "需要启用历史搜索和原文恢复工具",
|
|
884
|
+
summary_budget_too_small: "剩余空间不足以生成摘要",
|
|
885
|
+
summary_network_error: "摘要连接失败或长时间没有响应,已完成的摘要已保留",
|
|
886
|
+
summary_invalid: "摘要结果无效,已保留原上下文",
|
|
887
|
+
summary_provider_unavailable: "模型服务未能生成摘要,请检查接入配置后重试",
|
|
888
|
+
summary_unavailable: "摘要连续失败,已停止自动重试,可手动重试",
|
|
889
|
+
summary_group_too_large: "一组必须完整保留的历史超过摘要容量,请切换更大窗口的模型",
|
|
890
|
+
protected_context_exceeds_budget: "必须保留的内容超出安全输入预算,请切换更大窗口的模型",
|
|
891
|
+
summary_failed: "摘要生成失败,可稍后手动重试",
|
|
892
|
+
summary_no_gain: "摘要没有缩减收益,已保留原视图",
|
|
893
|
+
context_still_exceeds_budget: "摘要已保存,但当前请求仍超过模型输入上限",
|
|
894
|
+
cancelled: "已取消本次准备"
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region ui-src/styles.css?raw
|
|
900
|
+
var styles_default = "/* A portalled panel can be the scope root; :where preserves selector specificity. */\n:is(:where(:scope).cu-panel, .cu-panel) {\n overflow-wrap: anywhere;\n}\n:is(:where(:scope).cu-panel, .cu-panel) > p {\n margin: 0 0 0.5rem;\n}\n.cu {\n --cu-tone: var(--meter-low);\n display: flex;\n align-items: center;\n padding: 0;\n height: auto;\n}\n.cu[data-level=\"mid\"],\n.cu-map[data-level=\"mid\"],\n.cu-legend[data-level=\"mid\"] {\n --cu-tone: var(--meter-mid);\n}\n.cu[data-level=\"high\"],\n.cu-map[data-level=\"high\"],\n.cu-legend[data-level=\"high\"] {\n --cu-tone: var(--meter-high);\n}\n.cu-map,\n.cu-legend {\n --cu-tone: var(--meter-low);\n}\n.cu-bar {\n position: relative;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 7rem;\n height: 1.125rem;\n overflow: hidden;\n border-radius: var(--radius-xs);\n background: var(--meter-free);\n}\n.cu-fill {\n position: absolute;\n inset-block: 0;\n inset-inline-start: 0;\n background: var(--cu-tone);\n transition: inline-size 240ms ease;\n}\n.cu-share,\n.cu-unknown {\n position: relative;\n color: var(--foreground);\n font-variant-numeric: tabular-nums;\n line-height: 1;\n}\n.cu-unknown {\n color: var(--muted-foreground);\n}\n.cu-name {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n}\n.cu-head {\n display: flex;\n align-items: baseline;\n justify-content: space-between;\n gap: 0.75rem;\n}\n.cu-head-name {\n font-weight: 600;\n}\n.cu-head-value {\n display: inline-flex;\n align-items: baseline;\n gap: 0.25rem;\n font-variant-numeric: tabular-nums;\n}\n.cu-head-share {\n font-weight: 600;\n}\n.cu-head-count {\n color: var(--muted-foreground);\n}\n/* A column of numbers aligned on the decimal point: the whole part is\n right-aligned by the cell, the fraction and the unit share one fixed slot. */\n.cu-num {\n display: inline-flex;\n justify-content: flex-end;\n font-variant-numeric: tabular-nums;\n}\n.cu-num-tail {\n display: inline-block;\n min-inline-size: 3ch;\n text-align: start;\n}\n.cu-head-count,\n.cu-legend-count,\n.cu-legend-share,\n.cu-stats dd {\n font-variant-numeric: tabular-nums;\n}\n.cu-map {\n display: grid;\n grid-template-columns: repeat(20, 1fr);\n gap: 2px;\n margin-block-end: 0.75rem;\n}\n.cu-cell {\n aspect-ratio: 1;\n border-radius: 2px;\n background: var(--meter-free);\n}\n:is(:where(:scope).cu-panel, .cu-panel) [data-cell=\"used\"] {\n background: var(--cu-tone);\n}\n:is(:where(:scope).cu-panel, .cu-panel) [data-cell=\"system\"] {\n background: var(--meter-cat-system);\n}\n:is(:where(:scope).cu-panel, .cu-panel) [data-cell=\"rules\"] {\n background: var(--meter-cat-rules);\n}\n:is(:where(:scope).cu-panel, .cu-panel) [data-cell=\"skills\"] {\n background: var(--meter-cat-skills);\n}\n:is(:where(:scope).cu-panel, .cu-panel) [data-cell=\"agents\"] {\n background: var(--meter-cat-agents);\n}\n:is(:where(:scope).cu-panel, .cu-panel) [data-cell=\"tools\"] {\n background: var(--meter-cat-tools);\n}\n:is(:where(:scope).cu-panel, .cu-panel) [data-cell=\"messages\"] {\n background: var(--meter-cat-messages);\n}\n:is(:where(:scope).cu-panel, .cu-panel) [data-cell=\"volatile\"] {\n background: var(--meter-cat-volatile);\n}\n:is(:where(:scope).cu-panel, .cu-panel) [data-cell=\"files\"] {\n background: var(--meter-cat-files);\n}\n.cu-legend {\n display: grid;\n gap: 0.25rem;\n margin: 0 0 0.75rem;\n padding: 0;\n list-style: none;\n}\n.cu-legend-row {\n display: grid;\n grid-template-columns: 0.625rem 1fr auto 3.5rem;\n align-items: center;\n gap: 0.5rem;\n}\n.cu-owners {\n display: grid;\n gap: 0.25rem;\n margin: 0.25rem 0 0;\n padding: 0;\n list-style: none;\n}\n.cu-owner-name {\n overflow: hidden;\n color: var(--muted-foreground);\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.cu-tools-toggle {\n padding: 0;\n border: 0;\n background: none;\n color: inherit;\n font: inherit;\n text-align: start;\n text-decoration: underline dotted;\n text-underline-offset: 3px;\n cursor: pointer;\n}\n.cu-swatch {\n width: 0.625rem;\n height: 0.625rem;\n border-radius: 2px;\n background: var(--meter-free);\n}\n.cu-legend-count,\n.cu-legend-share {\n text-align: end;\n}\n.cu-legend-share,\n.cu-note {\n color: var(--muted-foreground);\n}\n.cu-stats {\n display: grid;\n grid-template-columns: 1fr auto;\n gap: 0.25rem 0.75rem;\n margin: 0 0 0.5rem;\n padding-block-start: 0.5rem;\n border-block-start: 1px solid var(--border);\n}\n.cu-stats dt {\n color: var(--muted-foreground);\n}\n.cu-stats dd {\n margin: 0;\n text-align: end;\n}\n";
|
|
901
|
+
//#endregion
|
|
902
|
+
//#region ui-src/index.tsx
|
|
903
|
+
function flatten(value, prefix = "") {
|
|
904
|
+
return Object.fromEntries(Object.entries(value).flatMap(([key, item]) => typeof item === "string" ? [[prefix + key, item]] : Object.entries(flatten(item, `${prefix}${key}.`))));
|
|
905
|
+
}
|
|
906
|
+
var runtimeVersion = 5;
|
|
907
|
+
/** Optional Agent preference editor service, withdrawn with the Context browser owner. */
|
|
908
|
+
var provides = ["tool-preload:configuration"];
|
|
909
|
+
var register = (ctx) => {
|
|
910
|
+
ctx.services.provide("tool-preload:configuration", toolPreloadConfiguration);
|
|
911
|
+
ctx.i18n.register({
|
|
912
|
+
"en-US": flatten(catalogue$1),
|
|
913
|
+
"zh-CN": flatten(catalogue)
|
|
914
|
+
}, "en-US");
|
|
915
|
+
ctx.styles.add(styles_default, { layer: "unlayered" });
|
|
916
|
+
const status = createContextStatusView(ctx);
|
|
917
|
+
const Context = contextUsageFor({
|
|
918
|
+
ui: ctx.ui,
|
|
919
|
+
host: ctx.host,
|
|
920
|
+
context: status,
|
|
921
|
+
i18n: ctx.i18n,
|
|
922
|
+
call: (method, params) => ctx.invoke(method, params ?? {})
|
|
923
|
+
});
|
|
924
|
+
function Status({ sessionId }) {
|
|
925
|
+
useSyncExternalStore(ctx.i18n.subscribe, ctx.i18n.language);
|
|
926
|
+
return sessionId === null ? /* @__PURE__ */ jsxs("p", {
|
|
927
|
+
className: "flex items-center gap-1.5",
|
|
928
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
929
|
+
className: "sr-only",
|
|
930
|
+
children: ctx.i18n.t("status.context")
|
|
931
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
932
|
+
className: "tabular-nums",
|
|
933
|
+
children: "—"
|
|
934
|
+
})]
|
|
935
|
+
}) : /* @__PURE__ */ jsx(Context, { sessionId });
|
|
936
|
+
}
|
|
937
|
+
ctx.slots.register("chat.status.item", {
|
|
938
|
+
id: "context",
|
|
939
|
+
order: 20,
|
|
940
|
+
component: Status
|
|
941
|
+
});
|
|
942
|
+
registerCommands(ctx);
|
|
943
|
+
registerMetadata(ctx);
|
|
944
|
+
registerPreviewNotice(ctx, status);
|
|
945
|
+
};
|
|
946
|
+
//#endregion
|
|
947
|
+
export { provides, register, runtimeVersion };
|