@laoyuehanni/dsh-token-usage 0.4.3 → 0.4.5
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/README.md +4 -3
- package/README.zh.md +4 -3
- package/lib/client/CostDeltaFlyLabel.js +1 -1
- package/lib/client/CostDeltaFlyLabel.js.map +1 -1
- package/lib/client/CostPill.d.ts +74 -0
- package/lib/client/CostPill.d.ts.map +1 -0
- package/lib/client/CostPill.js +242 -0
- package/lib/client/CostPill.js.map +1 -0
- package/lib/client/SessionTable.d.ts.map +1 -1
- package/lib/client/SessionTable.js +10 -4
- package/lib/client/SessionTable.js.map +1 -1
- package/lib/client/TokenUsageCard.d.ts +7 -2
- package/lib/client/TokenUsageCard.d.ts.map +1 -1
- package/lib/client/TokenUsageCard.js +11 -4
- package/lib/client/TokenUsageCard.js.map +1 -1
- package/lib/client/TokenUsageSection.d.ts +4 -1
- package/lib/client/TokenUsageSection.d.ts.map +1 -1
- package/lib/client/TokenUsageSection.js +30 -4
- package/lib/client/TokenUsageSection.js.map +1 -1
- package/lib/client/TrendChart.d.ts +1 -1
- package/lib/client/TrendChart.d.ts.map +1 -1
- package/lib/client/TrendChart.js +39 -15
- package/lib/client/TrendChart.js.map +1 -1
- package/lib/client/UsageView.js +2 -2
- package/lib/client/UsageView.js.map +1 -1
- package/lib/client/card-form.d.ts +33 -4
- package/lib/client/card-form.d.ts.map +1 -1
- package/lib/client/card-form.js +20 -8
- package/lib/client/card-form.js.map +1 -1
- package/lib/client/cost-inflate-motion.d.ts +7 -2
- package/lib/client/cost-inflate-motion.d.ts.map +1 -1
- package/lib/client/cost-inflate-motion.js +14 -10
- package/lib/client/cost-inflate-motion.js.map +1 -1
- package/lib/client/format.d.ts +7 -5
- package/lib/client/format.d.ts.map +1 -1
- package/lib/client/format.js +11 -7
- package/lib/client/format.js.map +1 -1
- package/lib/client/index.d.ts +18 -3
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +154 -47
- package/lib/client/index.js.map +1 -1
- package/lib/client/locales.d.ts +13 -3
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/locales.js +26 -6
- package/lib/client/locales.js.map +1 -1
- package/lib/client/trend-chart/index.d.ts +1 -1
- package/lib/client/trend-chart/index.d.ts.map +1 -1
- package/lib/client/trend-chart/index.js +1 -1
- package/lib/client/trend-chart/index.js.map +1 -1
- package/lib/client/trend-chart/path.d.ts +46 -0
- package/lib/client/trend-chart/path.d.ts.map +1 -1
- package/lib/client/trend-chart/path.js +140 -0
- package/lib/client/trend-chart/path.js.map +1 -1
- package/lib/client/use-color-scheme.d.ts +6 -0
- package/lib/client/use-color-scheme.d.ts.map +1 -1
- package/lib/client/use-color-scheme.js +53 -1
- package/lib/client/use-color-scheme.js.map +1 -1
- package/lib/client/use-cost-inflate.d.ts +4 -4
- package/lib/client/use-cost-inflate.js +5 -5
- package/lib/client/use-cost-inflate.js.map +1 -1
- package/lib/client.js +1913 -1250
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +30 -52
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +140 -133
- package/lib/index.js.map +1 -1
- package/lib/stats.d.ts +1 -1
- package/lib/stats.d.ts.map +1 -1
- package/lib/stats.js +1 -1
- package/lib/stats.js.map +1 -1
- package/lib/sync-state.d.ts +17 -6
- package/lib/sync-state.d.ts.map +1 -1
- package/lib/sync-state.js +28 -6
- package/lib/sync-state.js.map +1 -1
- package/lib/sync.d.ts +25 -0
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +35 -4
- package/lib/sync.js.map +1 -1
- package/lib/usage-log.d.ts +14 -0
- package/lib/usage-log.d.ts.map +1 -1
- package/lib/usage-log.js +128 -1
- package/lib/usage-log.js.map +1 -1
- package/lib/usage-record.d.ts +20 -2
- package/lib/usage-record.d.ts.map +1 -1
- package/lib/usage-record.js +74 -3
- package/lib/usage-record.js.map +1 -1
- package/package.json +42 -36
package/lib/client.js
CHANGED
|
@@ -5,8 +5,8 @@ window.__ModuleLoader__.load({
|
|
|
5
5
|
var exports = module.exports;
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
7
|
let react = require("react");
|
|
8
|
-
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
9
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
10
10
|
//#region src/wire.ts
|
|
11
11
|
/** The stats endpoint path, served by the host half's webServer route. */
|
|
12
12
|
const STATS_PATH = "/token-usage/stats";
|
|
@@ -60,6 +60,18 @@ window.__ModuleLoader__.load({
|
|
|
60
60
|
const FULL_SYNC_PATH = "/token-usage/full-sync";
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/client/card-form.ts
|
|
63
|
+
/** Fallback target when neither configForms nor settingsScope is present in the host. */
|
|
64
|
+
function createFallbackTarget() {
|
|
65
|
+
return {
|
|
66
|
+
getSnapshot: () => ({
|
|
67
|
+
status: "unavailable",
|
|
68
|
+
writable: false
|
|
69
|
+
}),
|
|
70
|
+
subscribe: () => () => {},
|
|
71
|
+
set: async () => false,
|
|
72
|
+
unset: async () => false
|
|
73
|
+
};
|
|
74
|
+
}
|
|
63
75
|
/** The fields this card edits. */
|
|
64
76
|
const CARD_FIELDS = ["path", "pricingRegion"];
|
|
65
77
|
/**
|
|
@@ -72,7 +84,7 @@ window.__ModuleLoader__.load({
|
|
|
72
84
|
* never restates fields it did not see.
|
|
73
85
|
*/
|
|
74
86
|
var CardForm = class {
|
|
75
|
-
|
|
87
|
+
target;
|
|
76
88
|
snapshotValue;
|
|
77
89
|
listeners = /* @__PURE__ */ new Set();
|
|
78
90
|
drafts = {};
|
|
@@ -82,12 +94,12 @@ window.__ModuleLoader__.load({
|
|
|
82
94
|
migrationView;
|
|
83
95
|
pollTimer;
|
|
84
96
|
/**
|
|
85
|
-
* @param
|
|
97
|
+
* @param target - the configuration source backing the card (ConfigForm or SettingsScope).
|
|
86
98
|
*/
|
|
87
|
-
constructor(
|
|
88
|
-
this.
|
|
99
|
+
constructor(target) {
|
|
100
|
+
this.target = target;
|
|
89
101
|
this.snapshotValue = this.project();
|
|
90
|
-
|
|
102
|
+
target.subscribe(() => {
|
|
91
103
|
this.publish();
|
|
92
104
|
});
|
|
93
105
|
this.pollMigration();
|
|
@@ -172,8 +184,8 @@ window.__ModuleLoader__.load({
|
|
|
172
184
|
}
|
|
173
185
|
let landed = true;
|
|
174
186
|
try {
|
|
175
|
-
for (const [field, text] of intended) if (text === "") await this.
|
|
176
|
-
else await this.
|
|
187
|
+
for (const [field, text] of intended) if (text === "") await this.target.unset(field);
|
|
188
|
+
else await this.target.set(field, text);
|
|
177
189
|
for (const [field, text] of intended) if (text === "" ? this.stored(field) : this.storedValue(field) !== text) {
|
|
178
190
|
landed = false;
|
|
179
191
|
break;
|
|
@@ -245,7 +257,7 @@ window.__ModuleLoader__.load({
|
|
|
245
257
|
}
|
|
246
258
|
}
|
|
247
259
|
snapshot() {
|
|
248
|
-
return this.
|
|
260
|
+
return this.target.getSnapshot();
|
|
249
261
|
}
|
|
250
262
|
/** The raw user layer narrowed to a record; the wire answer is `unknown`. */
|
|
251
263
|
userLayer() {
|
|
@@ -390,666 +402,119 @@ window.__ModuleLoader__.load({
|
|
|
390
402
|
return debounced;
|
|
391
403
|
}
|
|
392
404
|
//#endregion
|
|
393
|
-
//#region src/client/
|
|
394
|
-
/**
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const REMAIN_YELLOW = 60;
|
|
398
|
-
const REMAIN_RED = 20;
|
|
399
|
-
/** Whole-number percent, one decimal kept when it exists (`62%`, `87.5%`). */
|
|
400
|
-
function formatQuotaPercent(value) {
|
|
401
|
-
const rounded = Math.round(value * 10) / 10;
|
|
402
|
-
return `${Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1)}%`;
|
|
403
|
-
}
|
|
404
|
-
/** A money figure with its symbol: `$6.80` / `¥110.00`. */
|
|
405
|
-
function formatQuotaMoney(value, unit) {
|
|
406
|
-
return `${unit === "usd" ? "$" : "¥"}${value.toFixed(2)}`;
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* The used share of one window, 0–100, whichever direction the provider
|
|
410
|
-
* reported: the explicit `usedPercent`, else `remainingPercent` inverted,
|
|
411
|
-
* else the balance fraction (`1 - remaining/max`). Undefined when the
|
|
412
|
-
* window carries no computable ratio (a balance without a total).
|
|
413
|
-
*/
|
|
414
|
-
function quotaUsedPercent(window) {
|
|
415
|
-
if (window.usedPercent !== void 0) return clampPercent(window.usedPercent);
|
|
416
|
-
if (window.remainingPercent !== void 0) return clampPercent(100 - window.remainingPercent);
|
|
417
|
-
if (window.remainingValue !== void 0 && window.maxValue !== void 0 && window.maxValue > 0) return clampPercent((1 - window.remainingValue / window.maxValue) * 100);
|
|
405
|
+
//#region src/client/day.ts
|
|
406
|
+
/** Total tokens across the four buckets (billed input = input + cacheRead + cacheWrite). */
|
|
407
|
+
function totalTokens(totals) {
|
|
408
|
+
return totals.inputTokens + totals.outputTokens + totals.cacheReadTokens + totals.cacheWriteTokens;
|
|
418
409
|
}
|
|
419
|
-
/**
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
function quotaRemainingPercent(window) {
|
|
425
|
-
if (window.remainingPercent !== void 0) return clampPercent(window.remainingPercent);
|
|
426
|
-
if (window.usedPercent !== void 0) return clampPercent(100 - window.usedPercent);
|
|
427
|
-
if (window.remainingValue !== void 0 && window.maxValue !== void 0 && window.maxValue > 0) return clampPercent(window.remainingValue / window.maxValue * 100);
|
|
410
|
+
/** Local `YYYY-MM-DD` key of a date, matching the host's day-file convention. */
|
|
411
|
+
function dayKeyOf(date) {
|
|
412
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
413
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
414
|
+
return `${date.getFullYear()}-${month}-${day}`;
|
|
428
415
|
}
|
|
429
|
-
/**
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
function quotaSeverityOf(window) {
|
|
435
|
-
const remaining = quotaRemainingPercent(window);
|
|
436
|
-
if (remaining === void 0) return window.remainingValue !== void 0 && window.remainingValue <= 0 ? "exhausted" : "ok";
|
|
437
|
-
if (remaining < REMAIN_RED) return "exhausted";
|
|
438
|
-
if (remaining <= REMAIN_YELLOW) return "warn";
|
|
439
|
-
return "ok";
|
|
416
|
+
/** Local day key of today shifted by whole days (test seam on `now`). */
|
|
417
|
+
function shiftedDayKey(deltaDays, now = () => /* @__PURE__ */ new Date()) {
|
|
418
|
+
const date = now();
|
|
419
|
+
date.setDate(date.getDate() + deltaDays);
|
|
420
|
+
return dayKeyOf(date);
|
|
440
421
|
}
|
|
441
|
-
/**
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
* the weekly pool runs low). Undefined when there is no window at all.
|
|
447
|
-
*/
|
|
448
|
-
function finestQuotaWindow(windows) {
|
|
449
|
-
const rank = {
|
|
450
|
-
five_hour: 0,
|
|
451
|
-
weekly: 1,
|
|
452
|
-
monthly: 2,
|
|
453
|
-
balance: 3
|
|
422
|
+
/** The month view holding one day key. */
|
|
423
|
+
function monthViewOf(dayKey) {
|
|
424
|
+
return {
|
|
425
|
+
year: Number(dayKey.slice(0, 4)),
|
|
426
|
+
month: Number(dayKey.slice(5, 7)) - 1
|
|
454
427
|
};
|
|
455
|
-
let pick;
|
|
456
|
-
for (const window of windows) if (pick === void 0 || rank[window.tier] < rank[pick.tier]) pick = window;
|
|
457
|
-
return pick;
|
|
458
428
|
}
|
|
459
|
-
/**
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
if (window === void 0) return 0;
|
|
467
|
-
const remaining = quotaRemainingPercent(window);
|
|
468
|
-
if (remaining !== void 0) return remaining / 100;
|
|
469
|
-
if (window.remainingValue !== void 0 && window.remainingValue > 0) return 1;
|
|
470
|
-
return 0;
|
|
429
|
+
/** The month view shifted by whole months (year overflow normalized). */
|
|
430
|
+
function shiftMonth(view, deltaMonths) {
|
|
431
|
+
const total = view.year * 12 + view.month + deltaMonths;
|
|
432
|
+
return {
|
|
433
|
+
year: Math.floor(total / 12),
|
|
434
|
+
month: (total % 12 + 12) % 12
|
|
435
|
+
};
|
|
471
436
|
}
|
|
472
437
|
/**
|
|
473
|
-
* The
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
438
|
+
* The month grid of one month view: Monday-first whole weeks covering the
|
|
439
|
+
* month, so every column aligns under its weekday header. Days of the
|
|
440
|
+
* neighbouring months carry `inMonth: false` — the caller renders them as
|
|
441
|
+
* blank placeholders, keeping the shown month's date texts unique (for
|
|
442
|
+
* tests and screen readers).
|
|
478
443
|
*/
|
|
479
|
-
function
|
|
480
|
-
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
444
|
+
function monthGrid(view) {
|
|
445
|
+
const leading = (new Date(view.year, view.month, 1).getDay() + 6) % 7;
|
|
446
|
+
const daysInMonth = new Date(view.year, view.month + 1, 0).getDate();
|
|
447
|
+
const total = Math.ceil((leading + daysInMonth) / 7) * 7;
|
|
448
|
+
const cells = [];
|
|
449
|
+
for (let index = 0; index < total; index++) {
|
|
450
|
+
const cursor = new Date(view.year, view.month, 1 - leading + index);
|
|
451
|
+
cells.push({
|
|
452
|
+
day: dayKeyOf(cursor),
|
|
453
|
+
inMonth: cursor.getFullYear() === view.year && cursor.getMonth() === view.month
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
return cells;
|
|
484
457
|
}
|
|
485
458
|
/**
|
|
486
|
-
* The
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
* @param
|
|
490
|
-
* @param
|
|
459
|
+
* The zero-filled daily token series over a day range: every calendar day of
|
|
460
|
+
* the range appears once (days without records plot as zero). Absent bounds
|
|
461
|
+
* fall back to the first/last row day; no rows and no range yield [].
|
|
462
|
+
* @param rows - the (already filtered) per-day rows.
|
|
463
|
+
* @param from - first day key, inclusive.
|
|
464
|
+
* @param to - last day key, inclusive.
|
|
491
465
|
*/
|
|
492
|
-
function
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
466
|
+
function daySeries(rows, from, to) {
|
|
467
|
+
const first = from ?? rows[0]?.day;
|
|
468
|
+
const last = to ?? (rows.length > 0 ? rows[rows.length - 1].day : void 0);
|
|
469
|
+
if (first === void 0 || last === void 0 || first > last) return [];
|
|
470
|
+
const tokens = new Map(rows.map((row) => [row.day, totalTokens(row.totals)]));
|
|
471
|
+
const points = [];
|
|
472
|
+
const cursor = /* @__PURE__ */ new Date(`${first}T00:00:00`);
|
|
473
|
+
const end = /* @__PURE__ */ new Date(`${last}T00:00:00`);
|
|
474
|
+
while (cursor <= end) {
|
|
475
|
+
const day = dayKeyOf(cursor);
|
|
476
|
+
points.push({
|
|
477
|
+
day,
|
|
478
|
+
tokens: tokens.get(day) ?? 0
|
|
479
|
+
});
|
|
480
|
+
cursor.setDate(cursor.getDate() + 1);
|
|
481
|
+
}
|
|
482
|
+
return points;
|
|
504
483
|
}
|
|
505
|
-
/**
|
|
506
|
-
function
|
|
507
|
-
|
|
484
|
+
/** Local `YYYY-MM-DDTHH` key of a date, matching the host's hour convention. */
|
|
485
|
+
function hourKeyOf(date) {
|
|
486
|
+
const hour = String(date.getHours()).padStart(2, "0");
|
|
487
|
+
return `${dayKeyOf(date)}T${hour}`;
|
|
508
488
|
}
|
|
509
|
-
//#endregion
|
|
510
|
-
//#region src/client/use-color-scheme.ts
|
|
511
|
-
/**
|
|
512
|
-
* Shared browser-half hook: mirror the shell's root `color-scheme` onto a
|
|
513
|
-
* plugin-owned root element. The shell sets the property on
|
|
514
|
-
* `document.documentElement` only, so form controls inside plugin surfaces
|
|
515
|
-
* render with the UA default (white) in dark mode; scoping the property to
|
|
516
|
-
* the surface's root fixes selects, inputs, and dialogs without touching
|
|
517
|
-
* anything outside it. Used by the settings section and the conversation
|
|
518
|
-
* view tab.
|
|
519
|
-
*
|
|
520
|
-
* @module token-usage/client/use-color-scheme
|
|
521
|
-
*/
|
|
522
489
|
/**
|
|
523
|
-
*
|
|
524
|
-
*
|
|
490
|
+
* The zero-filled hourly token series over a day range: every whole hour of
|
|
491
|
+
* the range appears once (hours without records plot as zero), so a single
|
|
492
|
+
* day yields the full 00:00–23:00 sequence and future hours of today read
|
|
493
|
+
* zero. The per-(hour, model) rows fold by hour. Absent bounds fall back to
|
|
494
|
+
* the first/last row hour; no rows and no range yield [].
|
|
495
|
+
* @param rows - the (already filtered) per-hour × per-model rows.
|
|
496
|
+
* @param from - first day key (`YYYY-MM-DD`), inclusive; the series starts
|
|
497
|
+
* at that day's 00:00.
|
|
498
|
+
* @param to - last day key, inclusive; the series ends at that day's 23:00.
|
|
525
499
|
*/
|
|
526
|
-
function
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
attributeFilter: ["style"]
|
|
500
|
+
function hourSeries(rows, from, to) {
|
|
501
|
+
const first = from !== void 0 ? `${from}T00` : rows[0]?.hour;
|
|
502
|
+
const last = to !== void 0 ? `${to}T23` : rows.length > 0 ? rows[rows.length - 1].hour : void 0;
|
|
503
|
+
if (first === void 0 || last === void 0 || first > last) return [];
|
|
504
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
505
|
+
for (const row of rows) tokens.set(row.hour, (tokens.get(row.hour) ?? 0) + totalTokens(row.totals));
|
|
506
|
+
const points = [];
|
|
507
|
+
const cursor = /* @__PURE__ */ new Date(`${first.slice(0, 10)}T${first.slice(11)}:00:00`);
|
|
508
|
+
const end = /* @__PURE__ */ new Date(`${last.slice(0, 10)}T${last.slice(11)}:00:00`);
|
|
509
|
+
while (cursor <= end) {
|
|
510
|
+
const hour = hourKeyOf(cursor);
|
|
511
|
+
points.push({
|
|
512
|
+
hour,
|
|
513
|
+
tokens: tokens.get(hour) ?? 0
|
|
541
514
|
});
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
//#endregion
|
|
546
|
-
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\QuotaButton.module.css.mjs
|
|
547
|
-
const css$12 = ".jYASuG_root{flex:none;display:inline-flex;position:relative}.jYASuG_trigger{width:28px;height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:999px;flex:none;place-items:center;padding:0;display:grid}.jYASuG_trigger svg{display:block}.jYASuG_trigger:hover,.jYASuG_trigger[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.jYASuG_trigger.jYASuG_icon-ok:hover,.jYASuG_trigger.jYASuG_icon-ok[aria-expanded=true]{color:var(--dsw-alias-state-success-primary)}.jYASuG_trigger.jYASuG_icon-warn:hover,.jYASuG_trigger.jYASuG_icon-warn[aria-expanded=true]{color:var(--dsw-alias-state-warn-primary)}.jYASuG_trigger.jYASuG_icon-exhausted:hover,.jYASuG_trigger.jYASuG_icon-exhausted[aria-expanded=true]{color:var(--dsw-alias-state-error-primary)}.jYASuG_icon-ok{color:var(--dsw-alias-state-success-primary)}.jYASuG_icon-warn{color:var(--dsw-alias-state-warn-primary)}.jYASuG_icon-exhausted{color:var(--dsw-alias-state-error-primary)}.jYASuG_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-menu);width:320px;max-width:calc(100vw - 32px);box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-secondary);text-align:left;cursor:default;border-radius:12px;padding:12px;font-size:12px;line-height:20px;position:absolute;bottom:calc(100% + 8px)}.jYASuG_header{justify-content:space-between;align-items:baseline;gap:8px;margin-bottom:10px;display:flex}.jYASuG_title{color:var(--dsw-alias-label-primary);white-space:nowrap;text-overflow:ellipsis;font-size:13px;font-weight:500;overflow:hidden}.jYASuG_plan{color:var(--dsw-alias-label-tertiary);font-weight:400}.jYASuG_updated{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;font-size:11px}.jYASuG_grid{grid-template-columns:repeat(var(--cols,3), 1fr);gap:14px;display:grid}.jYASuG_col{min-width:0}.jYASuG_label{color:var(--dsw-alias-label-tertiary);white-space:nowrap;text-overflow:ellipsis;margin-bottom:2px;font-size:11px;line-height:16px;overflow:hidden}.jYASuG_value{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;white-space:nowrap;margin-bottom:6px;font-size:13px;font-weight:600;line-height:18px}.jYASuG_meta{color:var(--dsw-alias-label-tertiary);font-size:11px;font-weight:400}.jYASuG_bar{background:var(--dsw-alias-interactive-bg-hover);border-radius:999px;height:4px;overflow:hidden}.jYASuG_fill{border-radius:999px;height:100%;transition:width .3s}.jYASuG_ok{background:var(--dsw-alias-state-success-primary)}.jYASuG_warn{background:var(--dsw-alias-state-warn-primary)}.jYASuG_exhausted{background:var(--dsw-alias-state-error-primary)}.jYASuG_aux{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;white-space:nowrap;margin-top:4px;font-size:11px;line-height:14px}.jYASuG_dot{vertical-align:middle;border-radius:50%;width:5px;height:5px;margin-right:3px;display:inline-block}.jYASuG_error{flex-direction:column;gap:8px;display:flex}.jYASuG_errorText{color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;font-size:12px;line-height:18px}.jYASuG_retry{color:var(--dsw-alias-label-primary);cursor:pointer;text-underline-offset:2px;background:0 0;border:none;align-self:flex-start;padding:0;font-size:12px;text-decoration:underline}.jYASuG_retry:hover{color:var(--dsw-alias-brand-primary)}";
|
|
548
|
-
const tagId$12 = "@laoyuehanni/dsh-token-usage/QuotaButton.module.css";
|
|
549
|
-
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$12) + "]") === null) {
|
|
550
|
-
const tag = document.createElement("style");
|
|
551
|
-
tag.dataset.plugin = "@laoyuehanni/dsh-token-usage";
|
|
552
|
-
tag.dataset.pluginCss = tagId$12;
|
|
553
|
-
tag.textContent = css$12;
|
|
554
|
-
document.head.appendChild(tag);
|
|
555
|
-
}
|
|
556
|
-
var QuotaButton_module_css_default = {
|
|
557
|
-
"aux": "jYASuG_aux",
|
|
558
|
-
"bar": "jYASuG_bar",
|
|
559
|
-
"col": "jYASuG_col",
|
|
560
|
-
"dot": "jYASuG_dot",
|
|
561
|
-
"error": "jYASuG_error",
|
|
562
|
-
"errorText": "jYASuG_errorText",
|
|
563
|
-
"exhausted": "jYASuG_exhausted",
|
|
564
|
-
"fill": "jYASuG_fill",
|
|
565
|
-
"grid": "jYASuG_grid",
|
|
566
|
-
"header": "jYASuG_header",
|
|
567
|
-
"icon-exhausted": "jYASuG_icon-exhausted",
|
|
568
|
-
"icon-ok": "jYASuG_icon-ok",
|
|
569
|
-
"icon-warn": "jYASuG_icon-warn",
|
|
570
|
-
"label": "jYASuG_label",
|
|
571
|
-
"meta": "jYASuG_meta",
|
|
572
|
-
"ok": "jYASuG_ok",
|
|
573
|
-
"panel": "jYASuG_panel",
|
|
574
|
-
"plan": "jYASuG_plan",
|
|
575
|
-
"retry": "jYASuG_retry",
|
|
576
|
-
"root": "jYASuG_root",
|
|
577
|
-
"title": "jYASuG_title",
|
|
578
|
-
"trigger": "jYASuG_trigger",
|
|
579
|
-
"updated": "jYASuG_updated",
|
|
580
|
-
"value": "jYASuG_value",
|
|
581
|
-
"warn": "jYASuG_warn"
|
|
582
|
-
};
|
|
583
|
-
//#endregion
|
|
584
|
-
//#region src/client/QuotaButton.tsx
|
|
585
|
-
/**
|
|
586
|
-
* Input-bar quota button (browser half): a 28×28 round trigger registered
|
|
587
|
-
* into the `conversation.input.right` slot (it renders left of the model
|
|
588
|
-
* chip — the host's fixed tool-row order). The glyph is a remaining-share
|
|
589
|
-
* ring (ContextMeter family) colored by the finest window. Clicking opens a
|
|
590
|
-
* width-tiered popup (amount-only 200px / one progress bar 232px / two
|
|
591
|
-
* bars 320px) centered on the button with the current provider's quota
|
|
592
|
-
* windows: progress columns (5 小时 / 每周) for coding-plan providers, an
|
|
593
|
-
* amount row for balance providers.
|
|
594
|
-
*
|
|
595
|
-
* The provider follows the model CHIP's live selection (the shell's
|
|
596
|
-
* model-selection service reports the host's next selection before any
|
|
597
|
-
* request is sent); without that service the host falls back to the last
|
|
598
|
-
* request's provider, else the default selection.
|
|
599
|
-
*
|
|
600
|
-
* The button SELF-GATES: it renders nothing while the host cannot
|
|
601
|
-
* determine a provider (`no-provider`), the provider has no quota adapter
|
|
602
|
-
* (`unsupported`), or the feature is off (`disabled`) — switching
|
|
603
|
-
* providers makes it appear again. A supported provider whose query fails
|
|
604
|
-
* KEEPS the button and shows the error with a retry inside the panel.
|
|
605
|
-
*
|
|
606
|
-
* The hover tooltip reads provider name + the finest window's exact
|
|
607
|
-
* remaining figure (percent, or the amount when no ratio exists).
|
|
608
|
-
*
|
|
609
|
-
* The interaction copies ContextMeter verbatim (click toggles, document
|
|
610
|
-
* pointerdown outside closes, Escape closes); mutual exclusion with the
|
|
611
|
-
* ContextMeter panel falls out of both components' outside-close
|
|
612
|
-
* handlers — opening one closes the other on its next pointerdown.
|
|
613
|
-
*
|
|
614
|
-
* @module token-usage/client/QuotaButton
|
|
615
|
-
*/
|
|
616
|
-
/** The poll cadence fallback (seconds) while no payload has named one. */
|
|
617
|
-
const DEFAULT_POLL_SEC = 60;
|
|
618
|
-
/** Panel width tiers (px), by how much the windows paint: a lone amount
|
|
619
|
-
* reads at a glance, one progress bar needs breathing room, two bars (the
|
|
620
|
-
* 5-hour + weekly coding plans, or a long error body) the full plate. Kept
|
|
621
|
-
* in sync with the CSS max-width clamp. */
|
|
622
|
-
const PANEL_WIDTH_BALANCE = 200;
|
|
623
|
-
const PANEL_WIDTH_SINGLE = 232;
|
|
624
|
-
const PANEL_WIDTH_FULL = 320;
|
|
625
|
-
const PANEL_VIEWPORT_MARGIN = 16;
|
|
626
|
-
/** Tier → label key; the locale dictionaries carry both languages. */
|
|
627
|
-
const TIER_LABEL_KEYS = {
|
|
628
|
-
five_hour: "quota.tier.fiveHour",
|
|
629
|
-
weekly: "quota.tier.weekly",
|
|
630
|
-
monthly: "quota.tier.monthly",
|
|
631
|
-
balance: "quota.tier.balance"
|
|
632
|
-
};
|
|
633
|
-
/**
|
|
634
|
-
* Render the input-bar quota button for the active session's provider.
|
|
635
|
-
* @param props - the framework session id, the locale seat, and the
|
|
636
|
-
* optional model-directory holder (the chip's live selection).
|
|
637
|
-
* @returns the trigger + panel, or null while hidden (see the module note).
|
|
638
|
-
*/
|
|
639
|
-
function QuotaButton({ sessionId, t, modelDirectory }) {
|
|
640
|
-
const rootRef = (0, react.useRef)(null);
|
|
641
|
-
useColorSchemeMirror(rootRef);
|
|
642
|
-
const [open, setOpen] = (0, react.useState)(false);
|
|
643
|
-
const [panelLeft, setPanelLeft] = (0, react.useState)(void 0);
|
|
644
|
-
const measurePanelLeft = (0, react.useCallback)((width) => {
|
|
645
|
-
const wrapper = rootRef.current;
|
|
646
|
-
if (wrapper === null) return;
|
|
647
|
-
const { left: wrapperLeft, width: wrapperWidth } = wrapper.getBoundingClientRect();
|
|
648
|
-
const panelWidth = Math.min(width, window.innerWidth - 32);
|
|
649
|
-
const desired = (wrapperWidth - panelWidth) / 2;
|
|
650
|
-
const minLeft = PANEL_VIEWPORT_MARGIN - wrapperLeft;
|
|
651
|
-
const maxLeft = window.innerWidth - PANEL_VIEWPORT_MARGIN - panelWidth - wrapperLeft;
|
|
652
|
-
setPanelLeft(Math.min(Math.max(desired, minLeft), Math.max(minLeft, maxLeft)));
|
|
653
|
-
}, []);
|
|
654
|
-
const modelService = modelDirectory?.service;
|
|
655
|
-
const readChipProvider = () => {
|
|
656
|
-
if (sessionId === "" || modelService === void 0) return void 0;
|
|
657
|
-
try {
|
|
658
|
-
return modelService.directoryFor(sessionId).store.getSnapshot().current?.provider ?? void 0;
|
|
659
|
-
} catch {
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
};
|
|
663
|
-
const [chipProvider, setChipProvider] = (0, react.useState)(readChipProvider);
|
|
664
|
-
(0, react.useEffect)(() => {
|
|
665
|
-
setChipProvider(readChipProvider());
|
|
666
|
-
if (sessionId === "" || modelService === void 0) return;
|
|
667
|
-
let directory;
|
|
668
|
-
try {
|
|
669
|
-
directory = modelService.directoryFor(sessionId);
|
|
670
|
-
} catch {
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
return directory.store.subscribe(() => {
|
|
674
|
-
setChipProvider(readChipProvider());
|
|
675
|
-
});
|
|
676
|
-
}, [sessionId, modelService]);
|
|
677
|
-
const [resource, retry] = useAsyncResource((signal) => fetchQuotaPayload(sessionId, chipProvider, signal), [sessionId, chipProvider], {
|
|
678
|
-
silentAfterFirst: true,
|
|
679
|
-
retryToken: 0
|
|
680
|
-
});
|
|
681
|
-
const payload = resource.status === "ready" ? resource.value : null;
|
|
682
|
-
const panelWidth = panelWidthOf(payload);
|
|
683
|
-
const pollMs = (payload?.intervalSec ?? DEFAULT_POLL_SEC) * 1e3;
|
|
684
|
-
(0, react.useEffect)(() => {
|
|
685
|
-
const timer = setInterval(retry, pollMs);
|
|
686
|
-
return () => {
|
|
687
|
-
clearInterval(timer);
|
|
688
|
-
};
|
|
689
|
-
}, [pollMs, retry]);
|
|
690
|
-
const visible = payload !== null && (payload.status === "ok" || payload.status === "error");
|
|
691
|
-
(0, react.useEffect)(() => {
|
|
692
|
-
if (!visible && open) setOpen(false);
|
|
693
|
-
}, [visible, open]);
|
|
694
|
-
(0, react.useEffect)(() => {
|
|
695
|
-
if (!open) return;
|
|
696
|
-
const onPointerDown = (event) => {
|
|
697
|
-
if (event.target instanceof Node && rootRef.current?.contains(event.target) === true) return;
|
|
698
|
-
setOpen(false);
|
|
699
|
-
};
|
|
700
|
-
const onKeyDown = (event) => {
|
|
701
|
-
if (event.key === "Escape") setOpen(false);
|
|
702
|
-
};
|
|
703
|
-
document.addEventListener("pointerdown", onPointerDown);
|
|
704
|
-
document.addEventListener("keydown", onKeyDown);
|
|
705
|
-
return () => {
|
|
706
|
-
document.removeEventListener("pointerdown", onPointerDown);
|
|
707
|
-
document.removeEventListener("keydown", onKeyDown);
|
|
708
|
-
};
|
|
709
|
-
}, [open]);
|
|
710
|
-
(0, react.useEffect)(() => {
|
|
711
|
-
if (!open) return;
|
|
712
|
-
const onViewportChange = () => {
|
|
713
|
-
measurePanelLeft(panelWidth);
|
|
714
|
-
};
|
|
715
|
-
measurePanelLeft(panelWidth);
|
|
716
|
-
window.addEventListener("resize", onViewportChange);
|
|
717
|
-
window.addEventListener("scroll", onViewportChange, true);
|
|
718
|
-
return () => {
|
|
719
|
-
window.removeEventListener("resize", onViewportChange);
|
|
720
|
-
window.removeEventListener("scroll", onViewportChange, true);
|
|
721
|
-
};
|
|
722
|
-
}, [
|
|
723
|
-
open,
|
|
724
|
-
panelWidth,
|
|
725
|
-
measurePanelLeft
|
|
726
|
-
]);
|
|
727
|
-
if (!visible || payload === null) return null;
|
|
728
|
-
const finest = finestQuotaWindow(payload.status === "ok" ? payload.windows : []);
|
|
729
|
-
const severity = finest === void 0 ? "ok" : quotaSeverityOf(finest);
|
|
730
|
-
const triggerClass = [QuotaButton_module_css_default.trigger];
|
|
731
|
-
if (severity === "warn") triggerClass.push(QuotaButton_module_css_default["icon-warn"]);
|
|
732
|
-
else if (severity === "exhausted") triggerClass.push(QuotaButton_module_css_default["icon-exhausted"]);
|
|
733
|
-
else if (finest !== void 0 && quotaRemainingPercent(finest) !== void 0) triggerClass.push(QuotaButton_module_css_default["icon-ok"]);
|
|
734
|
-
const triggerClassName = triggerClass.join(" ").trim();
|
|
735
|
-
const figure = quotaTriggerFigure(finest);
|
|
736
|
-
const triggerTip = figure === void 0 ? t("quota.trigger") : t("quota.triggerSummary", {
|
|
737
|
-
name: payload.providerName ?? payload.provider,
|
|
738
|
-
figure
|
|
739
|
-
});
|
|
740
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
741
|
-
ref: rootRef,
|
|
742
|
-
className: QuotaButton_module_css_default.root,
|
|
743
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
|
|
744
|
-
label: triggerTip,
|
|
745
|
-
side: "top",
|
|
746
|
-
delayMs: 200,
|
|
747
|
-
disabled: open,
|
|
748
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
749
|
-
type: "button",
|
|
750
|
-
className: triggerClassName,
|
|
751
|
-
"aria-haspopup": "dialog",
|
|
752
|
-
"aria-expanded": open,
|
|
753
|
-
"aria-label": t("quota.trigger"),
|
|
754
|
-
onClick: () => {
|
|
755
|
-
if (!open) {
|
|
756
|
-
retry();
|
|
757
|
-
measurePanelLeft(panelWidth);
|
|
758
|
-
}
|
|
759
|
-
setOpen(!open);
|
|
760
|
-
},
|
|
761
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaGlyph, { share: quotaIconFillShare(finest) })
|
|
762
|
-
})
|
|
763
|
-
}), open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
764
|
-
className: QuotaButton_module_css_default.panel,
|
|
765
|
-
role: "dialog",
|
|
766
|
-
"aria-label": t("quota.panel"),
|
|
767
|
-
style: {
|
|
768
|
-
width: `${String(panelWidth)}px`,
|
|
769
|
-
...panelLeft === void 0 ? {} : { left: `${String(panelLeft)}px` }
|
|
770
|
-
},
|
|
771
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
772
|
-
className: QuotaButton_module_css_default.header,
|
|
773
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
774
|
-
className: QuotaButton_module_css_default.title,
|
|
775
|
-
children: [payload.providerName ?? payload.provider, payload.status === "ok" && payload.planTier !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
776
|
-
className: QuotaButton_module_css_default.plan,
|
|
777
|
-
children: [" · ", payload.planTier]
|
|
778
|
-
}) : null]
|
|
779
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
780
|
-
className: QuotaButton_module_css_default.updated,
|
|
781
|
-
children: t("quota.updatedAt", { time: formatQuotaClock(payload.fetchedAt) })
|
|
782
|
-
})]
|
|
783
|
-
}), payload.status === "error" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
784
|
-
className: QuotaButton_module_css_default.error,
|
|
785
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
786
|
-
className: QuotaButton_module_css_default.errorText,
|
|
787
|
-
children: errorText(payload.error, t)
|
|
788
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
789
|
-
type: "button",
|
|
790
|
-
className: QuotaButton_module_css_default.retry,
|
|
791
|
-
onClick: retry,
|
|
792
|
-
children: t("quota.retry")
|
|
793
|
-
})]
|
|
794
|
-
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
795
|
-
className: QuotaButton_module_css_default.grid,
|
|
796
|
-
style: { "--cols": String(Math.min(payload.windows.length, 3)) },
|
|
797
|
-
children: payload.windows.map((window, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaColumn, {
|
|
798
|
-
window,
|
|
799
|
-
t
|
|
800
|
-
}, `${window.tier}:${String(index)}`))
|
|
801
|
-
})]
|
|
802
|
-
})]
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
/** Ring geometry matches ContextMeter: 14px viewBox, r 5.5, 2px stroke.
|
|
806
|
-
* Circumference feeds the remaining-share dasharray, starting at 12
|
|
807
|
-
* o'clock. A 0 share omits the fill stroke — a round cap at 0 would still
|
|
808
|
-
* paint a dot. */
|
|
809
|
-
const RING_R = 5.5;
|
|
810
|
-
const RING_C = 2 * Math.PI * RING_R;
|
|
811
|
-
/** Round caps paint half a stroke width beyond each dash end; their
|
|
812
|
-
* combined reach is what the dash compensation subtracts, so the painted
|
|
813
|
-
* arc (dash + caps) equals the nominal share and the caps cannot seal the
|
|
814
|
-
* 12-o'clock gap. */
|
|
815
|
-
const RING_CAP_REACH = 2;
|
|
816
|
-
/** The trigger glyph: a ContextMeter-family donut whose fill arc is the
|
|
817
|
-
* remaining share of the finest window. Color comes from the button's
|
|
818
|
-
* severity class (`currentColor`); this only draws the arc. */
|
|
819
|
-
function QuotaGlyph({ share }) {
|
|
820
|
-
const clamped = Math.min(1, Math.max(0, share));
|
|
821
|
-
const nominal = clamped * RING_C;
|
|
822
|
-
const dashLen = clamped >= 1 ? RING_C : nominal <= RING_CAP_REACH ? nominal : nominal - RING_CAP_REACH;
|
|
823
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
824
|
-
viewBox: "0 0 14 14",
|
|
825
|
-
width: "14",
|
|
826
|
-
height: "14",
|
|
827
|
-
"aria-hidden": "true",
|
|
828
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
829
|
-
cx: "7",
|
|
830
|
-
cy: "7",
|
|
831
|
-
r: RING_R,
|
|
832
|
-
fill: "none",
|
|
833
|
-
stroke: "currentColor",
|
|
834
|
-
strokeWidth: "2",
|
|
835
|
-
opacity: "0.22"
|
|
836
|
-
}), clamped > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
837
|
-
cx: "7",
|
|
838
|
-
cy: "7",
|
|
839
|
-
r: RING_R,
|
|
840
|
-
fill: "none",
|
|
841
|
-
stroke: "currentColor",
|
|
842
|
-
strokeWidth: "2",
|
|
843
|
-
strokeLinecap: clamped < 1 ? "round" : "butt",
|
|
844
|
-
strokeDasharray: `${dashLen.toFixed(3)} ${RING_C.toFixed(3)}`,
|
|
845
|
-
transform: "rotate(-90 7 7)"
|
|
846
|
-
}) : null]
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
/** One progress column: label / value / bar / aux. The value and the bar
|
|
850
|
-
* both carry the REMAINING share (the traffic-light standard reads what is
|
|
851
|
-
* left), colored by severity. */
|
|
852
|
-
function QuotaColumn({ window, t }) {
|
|
853
|
-
const remaining = quotaRemainingPercent(window);
|
|
854
|
-
const severity = quotaSeverityOf(window);
|
|
855
|
-
const label = t(TIER_LABEL_KEYS[window.tier]);
|
|
856
|
-
let value;
|
|
857
|
-
let meta;
|
|
858
|
-
if (window.tier === "balance" && window.remainingValue !== void 0) {
|
|
859
|
-
const unit = window.unit ?? "cny";
|
|
860
|
-
value = formatQuotaMoney(window.remainingValue, unit);
|
|
861
|
-
if (window.maxValue !== void 0) meta = `/ ${formatQuotaMoney(window.maxValue, unit)}`;
|
|
862
|
-
} else value = remaining !== void 0 ? formatQuotaPercent(remaining) : "—";
|
|
863
|
-
const aux = window.resetAt !== void 0 ? t("quota.resetIn", { time: formatResetCountdown(window.resetAt, Date.now()) }) : void 0;
|
|
864
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
865
|
-
className: QuotaButton_module_css_default.col,
|
|
866
|
-
children: [
|
|
867
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
868
|
-
className: QuotaButton_module_css_default.label,
|
|
869
|
-
children: label
|
|
870
|
-
}),
|
|
871
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
872
|
-
className: QuotaButton_module_css_default.value,
|
|
873
|
-
children: [value, meta !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
874
|
-
className: QuotaButton_module_css_default.meta,
|
|
875
|
-
children: [" ", meta]
|
|
876
|
-
}) : null]
|
|
877
|
-
}),
|
|
878
|
-
remaining !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
879
|
-
className: QuotaButton_module_css_default.bar,
|
|
880
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
881
|
-
className: `${QuotaButton_module_css_default.fill} ${QuotaButton_module_css_default[severity]}`,
|
|
882
|
-
style: { width: `${String(Math.round(remaining))}%` }
|
|
883
|
-
})
|
|
884
|
-
}),
|
|
885
|
-
aux !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
886
|
-
className: QuotaButton_module_css_default.aux,
|
|
887
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: `${QuotaButton_module_css_default.dot} ${QuotaButton_module_css_default[severity]}` }), aux]
|
|
888
|
-
})
|
|
889
|
-
]
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
/** The panel's width tier for one payload: what the windows PAINT decides —
|
|
893
|
-
* a lone amount (no computable bar, the DeepSeek shape) reads at the
|
|
894
|
-
* minimal plate, one bar (a weekly-only plan, or a balance with a spend
|
|
895
|
-
* total like OpenRouter) the middle one, two or more bars the full plate.
|
|
896
|
-
* Errors and payloads without windows read the full plate (their copy
|
|
897
|
-
* runs long). */
|
|
898
|
-
function panelWidthOf(payload) {
|
|
899
|
-
if (payload === null || payload.status !== "ok") return PANEL_WIDTH_FULL;
|
|
900
|
-
const bars = payload.windows.filter((window) => quotaUsedPercent(window) !== void 0).length;
|
|
901
|
-
if (bars === 0) return payload.windows.length > 0 ? PANEL_WIDTH_BALANCE : PANEL_WIDTH_FULL;
|
|
902
|
-
return bars === 1 ? PANEL_WIDTH_SINGLE : PANEL_WIDTH_FULL;
|
|
903
|
-
}
|
|
904
|
-
/** Friendly locale copy for one normalized query error. */
|
|
905
|
-
function errorText(error, t) {
|
|
906
|
-
switch (error.kind) {
|
|
907
|
-
case "auth": return t("quota.error.auth", { message: error.message });
|
|
908
|
-
case "no-credential": return t("quota.error.noCredential", { ref: error.message });
|
|
909
|
-
case "http": return t("quota.error.http", { message: error.message });
|
|
910
|
-
case "network": return t("quota.error.network", { message: error.message });
|
|
911
|
-
case "parse": return t("quota.error.parse", { message: error.message });
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
/** Defensive shape check: a misrouted response must not paint the button. */
|
|
915
|
-
function looksLikeQuotaPayload(value) {
|
|
916
|
-
return typeof value === "object" && value !== null && typeof value.status === "string" && typeof value.intervalSec === "number";
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* Fetch the quota payload for the active session, naming the chip-selected
|
|
920
|
-
* provider when one is known. Throws on transport failure or a payload that
|
|
921
|
-
* does not look like one, so the hook can keep the previous render
|
|
922
|
-
* (silentAfterFirst) or stay hidden (first failure).
|
|
923
|
-
*/
|
|
924
|
-
async function fetchQuotaPayload(sessionId, provider, signal) {
|
|
925
|
-
const params = new URLSearchParams();
|
|
926
|
-
if (sessionId !== "") params.set("session", sessionId);
|
|
927
|
-
if (provider !== void 0 && provider !== "") params.set("provider", provider);
|
|
928
|
-
const encoded = params.toString();
|
|
929
|
-
const query = encoded === "" ? "" : `?${encoded}`;
|
|
930
|
-
const response = await fetch(QUOTA_PATH + query, {
|
|
931
|
-
headers: { accept: "application/json" },
|
|
932
|
-
signal
|
|
933
|
-
});
|
|
934
|
-
if (!response.ok) throw new Error(`HTTP ${String(response.status)}`);
|
|
935
|
-
const value = await response.json();
|
|
936
|
-
if (!looksLikeQuotaPayload(value)) throw new Error("unexpected quota response");
|
|
937
|
-
return value;
|
|
938
|
-
}
|
|
939
|
-
//#endregion
|
|
940
|
-
//#region src/client/day.ts
|
|
941
|
-
/** Total tokens across the four buckets (billed input = input + cacheRead + cacheWrite). */
|
|
942
|
-
function totalTokens(totals) {
|
|
943
|
-
return totals.inputTokens + totals.outputTokens + totals.cacheReadTokens + totals.cacheWriteTokens;
|
|
944
|
-
}
|
|
945
|
-
/** Local `YYYY-MM-DD` key of a date, matching the host's day-file convention. */
|
|
946
|
-
function dayKeyOf(date) {
|
|
947
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
948
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
949
|
-
return `${date.getFullYear()}-${month}-${day}`;
|
|
950
|
-
}
|
|
951
|
-
/** Local day key of today shifted by whole days (test seam on `now`). */
|
|
952
|
-
function shiftedDayKey(deltaDays, now = () => /* @__PURE__ */ new Date()) {
|
|
953
|
-
const date = now();
|
|
954
|
-
date.setDate(date.getDate() + deltaDays);
|
|
955
|
-
return dayKeyOf(date);
|
|
956
|
-
}
|
|
957
|
-
/** The month view holding one day key. */
|
|
958
|
-
function monthViewOf(dayKey) {
|
|
959
|
-
return {
|
|
960
|
-
year: Number(dayKey.slice(0, 4)),
|
|
961
|
-
month: Number(dayKey.slice(5, 7)) - 1
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
/** The month view shifted by whole months (year overflow normalized). */
|
|
965
|
-
function shiftMonth(view, deltaMonths) {
|
|
966
|
-
const total = view.year * 12 + view.month + deltaMonths;
|
|
967
|
-
return {
|
|
968
|
-
year: Math.floor(total / 12),
|
|
969
|
-
month: (total % 12 + 12) % 12
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
/**
|
|
973
|
-
* The month grid of one month view: Monday-first whole weeks covering the
|
|
974
|
-
* month, so every column aligns under its weekday header. Days of the
|
|
975
|
-
* neighbouring months carry `inMonth: false` — the caller renders them as
|
|
976
|
-
* blank placeholders, keeping the shown month's date texts unique (for
|
|
977
|
-
* tests and screen readers).
|
|
978
|
-
*/
|
|
979
|
-
function monthGrid(view) {
|
|
980
|
-
const leading = (new Date(view.year, view.month, 1).getDay() + 6) % 7;
|
|
981
|
-
const daysInMonth = new Date(view.year, view.month + 1, 0).getDate();
|
|
982
|
-
const total = Math.ceil((leading + daysInMonth) / 7) * 7;
|
|
983
|
-
const cells = [];
|
|
984
|
-
for (let index = 0; index < total; index++) {
|
|
985
|
-
const cursor = new Date(view.year, view.month, 1 - leading + index);
|
|
986
|
-
cells.push({
|
|
987
|
-
day: dayKeyOf(cursor),
|
|
988
|
-
inMonth: cursor.getFullYear() === view.year && cursor.getMonth() === view.month
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
return cells;
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* The zero-filled daily token series over a day range: every calendar day of
|
|
995
|
-
* the range appears once (days without records plot as zero). Absent bounds
|
|
996
|
-
* fall back to the first/last row day; no rows and no range yield [].
|
|
997
|
-
* @param rows - the (already filtered) per-day rows.
|
|
998
|
-
* @param from - first day key, inclusive.
|
|
999
|
-
* @param to - last day key, inclusive.
|
|
1000
|
-
*/
|
|
1001
|
-
function daySeries(rows, from, to) {
|
|
1002
|
-
const first = from ?? rows[0]?.day;
|
|
1003
|
-
const last = to ?? (rows.length > 0 ? rows[rows.length - 1].day : void 0);
|
|
1004
|
-
if (first === void 0 || last === void 0 || first > last) return [];
|
|
1005
|
-
const tokens = new Map(rows.map((row) => [row.day, totalTokens(row.totals)]));
|
|
1006
|
-
const points = [];
|
|
1007
|
-
const cursor = /* @__PURE__ */ new Date(`${first}T00:00:00`);
|
|
1008
|
-
const end = /* @__PURE__ */ new Date(`${last}T00:00:00`);
|
|
1009
|
-
while (cursor <= end) {
|
|
1010
|
-
const day = dayKeyOf(cursor);
|
|
1011
|
-
points.push({
|
|
1012
|
-
day,
|
|
1013
|
-
tokens: tokens.get(day) ?? 0
|
|
1014
|
-
});
|
|
1015
|
-
cursor.setDate(cursor.getDate() + 1);
|
|
1016
|
-
}
|
|
1017
|
-
return points;
|
|
1018
|
-
}
|
|
1019
|
-
/** Local `YYYY-MM-DDTHH` key of a date, matching the host's hour convention. */
|
|
1020
|
-
function hourKeyOf(date) {
|
|
1021
|
-
const hour = String(date.getHours()).padStart(2, "0");
|
|
1022
|
-
return `${dayKeyOf(date)}T${hour}`;
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
* The zero-filled hourly token series over a day range: every whole hour of
|
|
1026
|
-
* the range appears once (hours without records plot as zero), so a single
|
|
1027
|
-
* day yields the full 00:00–23:00 sequence and future hours of today read
|
|
1028
|
-
* zero. The per-(hour, model) rows fold by hour. Absent bounds fall back to
|
|
1029
|
-
* the first/last row hour; no rows and no range yield [].
|
|
1030
|
-
* @param rows - the (already filtered) per-hour × per-model rows.
|
|
1031
|
-
* @param from - first day key (`YYYY-MM-DD`), inclusive; the series starts
|
|
1032
|
-
* at that day's 00:00.
|
|
1033
|
-
* @param to - last day key, inclusive; the series ends at that day's 23:00.
|
|
1034
|
-
*/
|
|
1035
|
-
function hourSeries(rows, from, to) {
|
|
1036
|
-
const first = from !== void 0 ? `${from}T00` : rows[0]?.hour;
|
|
1037
|
-
const last = to !== void 0 ? `${to}T23` : rows.length > 0 ? rows[rows.length - 1].hour : void 0;
|
|
1038
|
-
if (first === void 0 || last === void 0 || first > last) return [];
|
|
1039
|
-
const tokens = /* @__PURE__ */ new Map();
|
|
1040
|
-
for (const row of rows) tokens.set(row.hour, (tokens.get(row.hour) ?? 0) + totalTokens(row.totals));
|
|
1041
|
-
const points = [];
|
|
1042
|
-
const cursor = /* @__PURE__ */ new Date(`${first.slice(0, 10)}T${first.slice(11)}:00:00`);
|
|
1043
|
-
const end = /* @__PURE__ */ new Date(`${last.slice(0, 10)}T${last.slice(11)}:00:00`);
|
|
1044
|
-
while (cursor <= end) {
|
|
1045
|
-
const hour = hourKeyOf(cursor);
|
|
1046
|
-
points.push({
|
|
1047
|
-
hour,
|
|
1048
|
-
tokens: tokens.get(hour) ?? 0
|
|
1049
|
-
});
|
|
1050
|
-
cursor.setHours(cursor.getHours() + 1);
|
|
1051
|
-
}
|
|
1052
|
-
return points;
|
|
515
|
+
cursor.setHours(cursor.getHours() + 1);
|
|
516
|
+
}
|
|
517
|
+
return points;
|
|
1053
518
|
}
|
|
1054
519
|
//#endregion
|
|
1055
520
|
//#region src/client/format.ts
|
|
@@ -1134,9 +599,11 @@ window.__ModuleLoader__.load({
|
|
|
1134
599
|
band: bandOf(rate)
|
|
1135
600
|
};
|
|
1136
601
|
}
|
|
1137
|
-
/** The RMB display view: amounts render as stored.
|
|
602
|
+
/** The RMB display view: amounts render as stored. The CNY sign is the
|
|
603
|
+
* fullwidth ¥ (U+FFE5) — the standard RMB glyph in a Chinese UI, and the
|
|
604
|
+
* suffix the number-first cost idiom reads naturally with. */
|
|
1138
605
|
const CNY_VIEW = {
|
|
1139
|
-
symbol: "
|
|
606
|
+
symbol: "¥",
|
|
1140
607
|
rate: 1
|
|
1141
608
|
};
|
|
1142
609
|
/**
|
|
@@ -1152,15 +619,17 @@ window.__ModuleLoader__.load({
|
|
|
1152
619
|
} : CNY_VIEW;
|
|
1153
620
|
}
|
|
1154
621
|
/**
|
|
1155
|
-
* Cost as display text: the view's symbol
|
|
1156
|
-
*
|
|
1157
|
-
*
|
|
622
|
+
* Cost as display text: two decimals plus the view's symbol SUFFIXED —
|
|
623
|
+
* `1.25¥` — matching the dock row's number-first unit idiom (`12.2M tok`,
|
|
624
|
+
* `98%`), where every reading leads with its magnitude. USD divides the
|
|
625
|
+
* wire's RMB amount by the exchange rate (`0.18$` under a rate-7 view).
|
|
626
|
+
* A cost is always shown, never omitted.
|
|
1158
627
|
* @param cost - a non-negative cost in ¥ (as carried on the wire).
|
|
1159
628
|
* @param view - the display currency view.
|
|
1160
|
-
* @returns e.g.
|
|
629
|
+
* @returns e.g. `1.25¥`, or `0.18$` under a rate-7 USD view.
|
|
1161
630
|
*/
|
|
1162
631
|
function formatCost(cost, view = CNY_VIEW) {
|
|
1163
|
-
return `${
|
|
632
|
+
return `${(cost / view.rate).toFixed(2)}${view.symbol}`;
|
|
1164
633
|
}
|
|
1165
634
|
/**
|
|
1166
635
|
* A per-million-token rate as display text, converted through the view:
|
|
@@ -1237,582 +706,1363 @@ window.__ModuleLoader__.load({
|
|
|
1237
706
|
return code;
|
|
1238
707
|
}
|
|
1239
708
|
//#endregion
|
|
1240
|
-
//#region
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
709
|
+
//#region src/client/session-stats.ts
|
|
710
|
+
/** Build a session-parent → direct-subagent-children index in one O(n) pass:
|
|
711
|
+
* every session whose `origin === 'subagent'` lands in its `parentId`'s
|
|
712
|
+
* bucket, in iteration order (so the result matches {@link directSubagentIds}).
|
|
713
|
+
* @param rows - the retained session-summary mirror.
|
|
714
|
+
* @returns the immutable child index.
|
|
715
|
+
*/
|
|
716
|
+
function buildChildIndex(rows) {
|
|
717
|
+
const index = /* @__PURE__ */ new Map();
|
|
718
|
+
for (const [id, summary] of Object.entries(rows)) {
|
|
719
|
+
if (summary.origin !== "subagent" || summary.parentId === void 0) continue;
|
|
720
|
+
const bucket = index.get(summary.parentId);
|
|
721
|
+
if (bucket === void 0) index.set(summary.parentId, [id]);
|
|
722
|
+
else bucket.push(id);
|
|
723
|
+
}
|
|
724
|
+
return index;
|
|
725
|
+
}
|
|
726
|
+
/** Look up the direct subagent children of one session. Falls back to a
|
|
727
|
+
* fresh {@link buildChildIndex} when the caller has no cached index. */
|
|
728
|
+
function directSubagentIds(rows, parentId, index) {
|
|
729
|
+
if (index !== void 0) return index.get(parentId) ?? [];
|
|
730
|
+
return buildChildIndex(rows).get(parentId) ?? [];
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* The whole subagent subtree of one session, including the root itself,
|
|
734
|
+
* using the parent → children index for an O(n) walk regardless of depth.
|
|
735
|
+
* Cycles are bounded by a `seen` set (a depth-first traversal visits each
|
|
736
|
+
* id once), so a self-referential or cyclic record set returns the root
|
|
737
|
+
* alone. Stacks are reversed after pushing so siblings come back out in
|
|
738
|
+
* insertion order, matching the runtime's lineage index.
|
|
739
|
+
* @param rows - the retained session-summary mirror (unused when the
|
|
740
|
+
* caller already built an index).
|
|
741
|
+
* @param rootId - the scope's root session id.
|
|
742
|
+
* @param index - optional precomputed index from {@link buildChildIndex}.
|
|
743
|
+
* @returns the root and its subagent descendants, depth-first.
|
|
744
|
+
*/
|
|
745
|
+
function subtreeIds(rows, rootId, index = buildChildIndex(rows)) {
|
|
746
|
+
const out = [rootId];
|
|
747
|
+
if (!index.has(rootId) && rows[rootId] === void 0) return out;
|
|
748
|
+
const seen = /* @__PURE__ */ new Set([rootId]);
|
|
749
|
+
const stack = [];
|
|
750
|
+
const seedChildren = index.get(rootId) ?? [];
|
|
751
|
+
for (let i = seedChildren.length - 1; i >= 0; i -= 1) stack.push(seedChildren[i]);
|
|
752
|
+
while (stack.length > 0) {
|
|
753
|
+
const current = stack.pop();
|
|
754
|
+
if (seen.has(current)) continue;
|
|
755
|
+
seen.add(current);
|
|
756
|
+
out.push(current);
|
|
757
|
+
const children = index.get(current) ?? [];
|
|
758
|
+
for (let i = children.length - 1; i >= 0; i -= 1) stack.push(children[i]);
|
|
759
|
+
}
|
|
760
|
+
return out;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* The immediate subagent parent of one session, when the record names one.
|
|
764
|
+
* The check is on `parentId` rather than `origin` so a mirrored summary that
|
|
765
|
+
* lost its origin tag still answers its lineage — the index is built once
|
|
766
|
+
* per render and shared across all three helpers via {@link ChildIndex}.
|
|
767
|
+
* @param rows - the retained session-summary mirror.
|
|
768
|
+
* @param id - the current focus session id.
|
|
769
|
+
* @returns the parent session id, or undefined when the record has no
|
|
770
|
+
* parent link (a top-level session or an ordinary fork).
|
|
771
|
+
*/
|
|
772
|
+
function subagentParentOf(rows, id) {
|
|
773
|
+
const parent = rows[id]?.parentId;
|
|
774
|
+
return parent === void 0 || parent === id ? void 0 : parent;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Sum one or more `SessionStatsProjection` values over a scope. A scope with
|
|
778
|
+
* no value at all yields `undefined` — the view renders an em-dash for an
|
|
779
|
+
* absent capability. The `contributing` count lets the caller tell
|
|
780
|
+
* "every scope session was empty" apart from "the scope itself was empty".
|
|
781
|
+
* @param values - the per-session projection values (typically drawn from
|
|
782
|
+
* the mirror + the live hook).
|
|
783
|
+
* @returns the summed buckets plus the contributing count, or undefined
|
|
784
|
+
* when no projection was present.
|
|
785
|
+
*/
|
|
786
|
+
function aggregateProjections(values) {
|
|
787
|
+
let ttftMs = 0;
|
|
788
|
+
let ttftSteps = 0;
|
|
789
|
+
let decodeMs = 0;
|
|
790
|
+
let decodeTokens = 0;
|
|
791
|
+
let contributing = 0;
|
|
792
|
+
for (const stats of values) {
|
|
793
|
+
if (stats === void 0) continue;
|
|
794
|
+
contributing += 1;
|
|
795
|
+
ttftMs += stats.ttftMs;
|
|
796
|
+
ttftSteps += stats.ttftSteps;
|
|
797
|
+
decodeMs += stats.decodeMs;
|
|
798
|
+
decodeTokens += stats.decodeTokens;
|
|
799
|
+
}
|
|
800
|
+
if (contributing === 0) return void 0;
|
|
801
|
+
return {
|
|
802
|
+
ttftMs,
|
|
803
|
+
ttftSteps,
|
|
804
|
+
decodeMs,
|
|
805
|
+
decodeTokens,
|
|
806
|
+
contributing
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Compact fingerprint of one session's retained stats projection — bumps on
|
|
811
|
+
* every finished request step (same signal that drives TTFT / throughput).
|
|
812
|
+
*/
|
|
813
|
+
function sessionStatsFingerprint(stats) {
|
|
814
|
+
if (stats === void 0) return "-";
|
|
815
|
+
return [
|
|
816
|
+
stats.steps,
|
|
817
|
+
stats.ttftSteps,
|
|
818
|
+
stats.decodeTokens,
|
|
819
|
+
stats.turns
|
|
820
|
+
].join(".");
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Build a debounce key from mirror `updatedAt` plus `sessionStats` churn.
|
|
824
|
+
* The active session reads live projection values from `useProjection`; every
|
|
825
|
+
* other scoped id reads the mirror copy.
|
|
826
|
+
*/
|
|
827
|
+
function buildStatsFreshnessKey(ids, options) {
|
|
828
|
+
return ids.map((id) => {
|
|
829
|
+
const row = options.rows[id];
|
|
830
|
+
const stats = id === options.activeSessionId ? options.liveSessionStats ?? row?.projectionValues?.sessionStats : row?.projectionValues?.sessionStats;
|
|
831
|
+
return `${id}:${String(row?.updatedAt ?? 0)}:${sessionStatsFingerprint(stats)}`;
|
|
832
|
+
}).join(",");
|
|
1249
833
|
}
|
|
1250
|
-
var hit_rate_band_module_css_default = {
|
|
1251
|
-
"band_amber": "t6JM8a_band_amber",
|
|
1252
|
-
"band_critical": "t6JM8a_band_critical",
|
|
1253
|
-
"band_healthy": "t6JM8a_band_healthy",
|
|
1254
|
-
"band_lime": "t6JM8a_band_lime"
|
|
1255
|
-
};
|
|
1256
834
|
//#endregion
|
|
1257
|
-
//#region src/client/
|
|
1258
|
-
/**
|
|
1259
|
-
|
|
1260
|
-
|
|
835
|
+
//#region src/client/use-color-scheme.ts
|
|
836
|
+
/**
|
|
837
|
+
* Shared browser-half hook: mirror the shell's root `color-scheme` onto a
|
|
838
|
+
* plugin-owned root element. The shell sets the property on
|
|
839
|
+
* `document.documentElement` only, so form controls inside plugin surfaces
|
|
840
|
+
* render with the UA default (white) in dark mode; scoping the property to
|
|
841
|
+
* the surface's root fixes selects, inputs, and dialogs without touching
|
|
842
|
+
* anything outside it. Used by the settings section and the conversation
|
|
843
|
+
* view tab.
|
|
844
|
+
*
|
|
845
|
+
* @module token-usage/client/use-color-scheme
|
|
846
|
+
*/
|
|
847
|
+
/**
|
|
848
|
+
* Mirror the shell's `color-scheme` inline style onto the given root element.
|
|
849
|
+
* @param rootRef - the surface's root element ref.
|
|
850
|
+
*/
|
|
851
|
+
function useColorSchemeMirror(rootRef) {
|
|
852
|
+
(0, react.useEffect)(() => {
|
|
853
|
+
const root = document.documentElement;
|
|
854
|
+
const element = rootRef.current;
|
|
855
|
+
if (element === null) return;
|
|
856
|
+
const sync = () => {
|
|
857
|
+
const scheme = root.style.colorScheme;
|
|
858
|
+
if (scheme !== "") element.style.colorScheme = scheme;
|
|
859
|
+
else element.style.removeProperty("color-scheme");
|
|
860
|
+
};
|
|
861
|
+
sync();
|
|
862
|
+
const observer = new MutationObserver(sync);
|
|
863
|
+
observer.observe(root, {
|
|
864
|
+
attributes: true,
|
|
865
|
+
attributeFilter: ["style"]
|
|
866
|
+
});
|
|
867
|
+
return () => observer.disconnect();
|
|
868
|
+
}, [rootRef]);
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Hook reporting whether the current shell/page environment is in light mode.
|
|
872
|
+
* Evaluates `document.documentElement.style.colorScheme` first (the DSH shell
|
|
873
|
+
* rewrites this on every theme switch), falling back to `(prefers-color-scheme: light)`.
|
|
874
|
+
*/
|
|
875
|
+
function useIsLightMode() {
|
|
876
|
+
const [isLight, setIsLight] = (0, react.useState)(() => {
|
|
877
|
+
if (typeof document === "undefined") return false;
|
|
878
|
+
const rootScheme = document.documentElement.style.colorScheme;
|
|
879
|
+
if (rootScheme === "light") return true;
|
|
880
|
+
if (rootScheme === "dark") return false;
|
|
881
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia("(prefers-color-scheme: light)").matches : false;
|
|
882
|
+
});
|
|
883
|
+
(0, react.useEffect)(() => {
|
|
884
|
+
if (typeof document === "undefined") return;
|
|
885
|
+
const root = document.documentElement;
|
|
886
|
+
const media = typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia("(prefers-color-scheme: light)") : null;
|
|
887
|
+
const check = () => {
|
|
888
|
+
const scheme = root.style.colorScheme;
|
|
889
|
+
if (scheme === "light") setIsLight(true);
|
|
890
|
+
else if (scheme === "dark") setIsLight(false);
|
|
891
|
+
else setIsLight(media?.matches ?? false);
|
|
892
|
+
};
|
|
893
|
+
check();
|
|
894
|
+
const observer = new MutationObserver(check);
|
|
895
|
+
observer.observe(root, {
|
|
896
|
+
attributes: true,
|
|
897
|
+
attributeFilter: ["style"]
|
|
898
|
+
});
|
|
899
|
+
if (media?.addEventListener) media.addEventListener("change", check);
|
|
900
|
+
return () => {
|
|
901
|
+
observer.disconnect();
|
|
902
|
+
if (media?.removeEventListener) media.removeEventListener("change", check);
|
|
903
|
+
};
|
|
904
|
+
}, []);
|
|
905
|
+
return isLight;
|
|
906
|
+
}
|
|
907
|
+
//#endregion
|
|
908
|
+
//#region src/client/cost-inflate-motion.ts
|
|
909
|
+
/** The user's motion preference: both runners refuse to animate (returning
|
|
910
|
+
* null) when the OS asks for reduced motion. Exported so the chip hook can
|
|
911
|
+
* skip spawning the DOM for flies that would never animate — a static +Δ
|
|
912
|
+
* flash reads as a glitch, not information. */
|
|
913
|
+
function motionAllowed() {
|
|
914
|
+
return typeof window.matchMedia !== "function" || !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
915
|
+
}
|
|
916
|
+
function waapiAvailable(el) {
|
|
917
|
+
return typeof el.animate === "function";
|
|
918
|
+
}
|
|
919
|
+
/** Scale bounce on the cost figure (`costPop`). The mix base is the pill's
|
|
920
|
+
* resting tertiary (NOT label-primary): the pill reads tertiary beside the
|
|
921
|
+
* official pills, and a primary-tinted final frame would leave the figure
|
|
922
|
+
* permanently highlighted after the animation's fill. */
|
|
923
|
+
function runCostPop(el, v) {
|
|
924
|
+
if (!motionAllowed() || !waapiAvailable(el)) return null;
|
|
925
|
+
const popScale = Number(v.popScale);
|
|
926
|
+
const echo = 1 + (popScale - 1) * .28;
|
|
927
|
+
const warnMix = v.warnMix;
|
|
928
|
+
return el.animate([
|
|
929
|
+
{
|
|
930
|
+
transform: "scale(1)",
|
|
931
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
transform: `scale(${String(popScale)})`,
|
|
935
|
+
color: `color-mix(in srgb, var(--dsw-alias-state-warn-primary) ${warnMix}, var(--dsw-alias-label-tertiary))`,
|
|
936
|
+
offset: .35
|
|
937
|
+
},
|
|
938
|
+
{
|
|
939
|
+
transform: `scale(${String(echo)})`,
|
|
940
|
+
color: `color-mix(in srgb, var(--dsw-alias-state-warn-primary) ${warnMix}, var(--dsw-alias-label-tertiary))`,
|
|
941
|
+
offset: .7
|
|
942
|
+
},
|
|
943
|
+
{
|
|
944
|
+
transform: "scale(1)",
|
|
945
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
946
|
+
}
|
|
947
|
+
], {
|
|
948
|
+
duration: v.inflateMs,
|
|
949
|
+
easing: "cubic-bezier(0.25, 0.85, 0.35, 1)"
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
/** +Δ label fall (`deltaFall`). Caller must position the element (absolute,
|
|
953
|
+
* below the pill — the dock sits under the composer, so the label falls
|
|
954
|
+
* away from the message scrollport rather than climbing into it). */
|
|
955
|
+
function runDeltaFly(el, v) {
|
|
956
|
+
if (!motionAllowed() || !waapiAvailable(el)) return null;
|
|
957
|
+
return el.animate([
|
|
958
|
+
{
|
|
959
|
+
opacity: 0,
|
|
960
|
+
transform: "translate(-50%, 20%)"
|
|
961
|
+
},
|
|
962
|
+
{
|
|
963
|
+
opacity: 1,
|
|
964
|
+
transform: "translate(-50%, 20%)",
|
|
965
|
+
offset: .15
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
opacity: 0,
|
|
969
|
+
transform: `translate(calc(-50% + ${v.flyX}), calc(100% + ${v.flyY}))`
|
|
970
|
+
}
|
|
971
|
+
], {
|
|
972
|
+
duration: v.inflateMs,
|
|
973
|
+
easing: "cubic-bezier(0.22, 0.55, 0.25, 1)",
|
|
974
|
+
fill: "both"
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
//#endregion
|
|
978
|
+
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\CostPill.module.css.mjs
|
|
979
|
+
const css$12 = ".RmjJ5q_root{min-width:0;display:inline-flex;position:relative}.RmjJ5q_pill{box-sizing:border-box;max-width:100%;color:var(--dsw-alias-label-tertiary);font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px));font-variant-numeric:tabular-nums;white-space:nowrap;background:0 0;border:none;border-radius:999px;align-items:center;gap:6px;padding:1px 8px;display:inline-flex}.RmjJ5q_glyph{flex:none;width:14px;height:14px}button.RmjJ5q_pill{cursor:pointer}button.RmjJ5q_pill:hover,button.RmjJ5q_pill[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}.RmjJ5q_cost{transform-origin:50%;z-index:2;display:inline-flex;position:relative}.RmjJ5q_deltaLayer{pointer-events:none;z-index:3;position:absolute;inset:0;overflow:visible}.RmjJ5q_deltaFly{color:var(--dsw-alias-state-warn-primary);font-variant-numeric:tabular-nums;white-space:nowrap;pointer-events:none;text-shadow:0 0 8px color-mix(in srgb, var(--dsw-alias-state-warn-primary) 35%, transparent);margin-top:2px;font-size:11px;font-weight:600;position:absolute;top:100%;left:50%}@media (prefers-reduced-motion:reduce){.RmjJ5q_deltaFly{display:none}}.RmjJ5q_panel{background:var(--dsw-specific-menu);width:300px;backdrop-filter:var(--dsw-menu-backdrop-filter);border:1px solid var(--dsw-alias-border-inverted);box-shadow:var(--dsw-shadow-lv3);z-index:30;font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);color:var(--dsw-alias-label-primary);border-radius:12px;padding:12px 14px;position:absolute;bottom:calc(100% + 8px)}.RmjJ5q_panelHead{border-bottom:1px solid var(--dsw-alias-border-l1);justify-content:space-between;align-items:baseline;padding-bottom:8px;display:flex}.RmjJ5q_panelTitle{align-items:center;gap:6px;font-weight:600;display:inline-flex}.RmjJ5q_scopeTag{color:var(--dsw-alias-label-secondary);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:1px 5px;font-size:10px;font-weight:400}.RmjJ5q_panelTotal{font-variant-numeric:tabular-nums;font-size:14px;font-weight:600}.RmjJ5q_usageLine{font-variant-numeric:tabular-nums;align-items:center;gap:6px;margin-top:8px;display:flex}.RmjJ5q_dot{color:var(--dsw-alias-separator-primary)}.RmjJ5q_rows{flex-direction:column;margin-top:8px;display:flex}.RmjJ5q_row{font-variant-numeric:tabular-nums;justify-content:space-between;padding:4px 0;display:flex}.RmjJ5q_rowLabel{color:var(--dsw-alias-label-secondary);align-items:center;gap:6px;display:inline-flex}.RmjJ5q_rowValue{color:var(--dsw-alias-label-primary)}.RmjJ5q_rowSub .RmjJ5q_rowValue{color:var(--dsw-alias-label-secondary)}.RmjJ5q_tok{color:var(--dsw-alias-label-tertiary);margin-left:6px;font-size:11px}.RmjJ5q_groupLabel{color:var(--dsw-alias-label-tertiary);letter-spacing:.06em;margin-top:10px;font-size:10px}.RmjJ5q_requests{color:var(--dsw-alias-label-tertiary);font-size:11px}.RmjJ5q_unpriced .RmjJ5q_rowLabel,.RmjJ5q_unpriced .RmjJ5q_rowValue{color:var(--dsw-alias-label-tertiary);font-style:italic}.RmjJ5q_pending{color:var(--dsw-alias-label-tertiary)}";
|
|
980
|
+
const tagId$12 = "@laoyuehanni/dsh-token-usage/CostPill.module.css";
|
|
981
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$12) + "]") === null) {
|
|
982
|
+
const tag = document.createElement("style");
|
|
983
|
+
tag.dataset.plugin = "@laoyuehanni/dsh-token-usage";
|
|
984
|
+
tag.dataset.pluginCss = tagId$12;
|
|
985
|
+
tag.textContent = css$12;
|
|
986
|
+
document.head.appendChild(tag);
|
|
1261
987
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
988
|
+
var CostPill_module_css_default = {
|
|
989
|
+
"cost": "RmjJ5q_cost",
|
|
990
|
+
"deltaFly": "RmjJ5q_deltaFly",
|
|
991
|
+
"deltaLayer": "RmjJ5q_deltaLayer",
|
|
992
|
+
"dot": "RmjJ5q_dot",
|
|
993
|
+
"glyph": "RmjJ5q_glyph",
|
|
994
|
+
"groupLabel": "RmjJ5q_groupLabel",
|
|
995
|
+
"panel": "RmjJ5q_panel",
|
|
996
|
+
"panelHead": "RmjJ5q_panelHead",
|
|
997
|
+
"panelTitle": "RmjJ5q_panelTitle",
|
|
998
|
+
"panelTotal": "RmjJ5q_panelTotal",
|
|
999
|
+
"pending": "RmjJ5q_pending",
|
|
1000
|
+
"pill": "RmjJ5q_pill",
|
|
1001
|
+
"requests": "RmjJ5q_requests",
|
|
1002
|
+
"root": "RmjJ5q_root",
|
|
1003
|
+
"row": "RmjJ5q_row",
|
|
1004
|
+
"rowLabel": "RmjJ5q_rowLabel",
|
|
1005
|
+
"rowSub": "RmjJ5q_rowSub",
|
|
1006
|
+
"rowValue": "RmjJ5q_rowValue",
|
|
1007
|
+
"rows": "RmjJ5q_rows",
|
|
1008
|
+
"scopeTag": "RmjJ5q_scopeTag",
|
|
1009
|
+
"tok": "RmjJ5q_tok",
|
|
1010
|
+
"unpriced": "RmjJ5q_unpriced",
|
|
1011
|
+
"usageLine": "RmjJ5q_usageLine"
|
|
1012
|
+
};
|
|
1013
|
+
//#endregion
|
|
1014
|
+
//#region src/client/CostDeltaFlyLabel.tsx
|
|
1015
|
+
/** One +Δ fly label; animation starts on mount via WAAPI. */
|
|
1016
|
+
function CostDeltaFlyLabel({ text, vars }) {
|
|
1017
|
+
const ref = (0, react.useRef)(null);
|
|
1018
|
+
(0, react.useLayoutEffect)(() => {
|
|
1019
|
+
const el = ref.current;
|
|
1020
|
+
if (el === null) return;
|
|
1021
|
+
const anim = runDeltaFly(el, vars);
|
|
1022
|
+
if (anim === null) {
|
|
1023
|
+
el.style.visibility = "hidden";
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
return () => {
|
|
1027
|
+
anim.cancel();
|
|
1028
|
+
};
|
|
1029
|
+
}, [vars]);
|
|
1268
1030
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1269
|
-
|
|
1031
|
+
ref,
|
|
1032
|
+
className: CostPill_module_css_default["deltaFly"],
|
|
1270
1033
|
children: text
|
|
1271
1034
|
});
|
|
1272
1035
|
}
|
|
1273
1036
|
//#endregion
|
|
1274
|
-
//#region src/client/
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
*/
|
|
1281
|
-
function buildChildIndex(rows) {
|
|
1282
|
-
const index = /* @__PURE__ */ new Map();
|
|
1283
|
-
for (const [id, summary] of Object.entries(rows)) {
|
|
1284
|
-
if (summary.origin !== "subagent" || summary.parentId === void 0) continue;
|
|
1285
|
-
const bucket = index.get(summary.parentId);
|
|
1286
|
-
if (bucket === void 0) index.set(summary.parentId, [id]);
|
|
1287
|
-
else bucket.push(id);
|
|
1288
|
-
}
|
|
1289
|
-
return index;
|
|
1037
|
+
//#region src/client/cost-inflate.ts
|
|
1038
|
+
const MISS_RATE_CAP = .55;
|
|
1039
|
+
const OUT_CAP = 32e3;
|
|
1040
|
+
/** Clamp to the unit interval. */
|
|
1041
|
+
function clamp01(n) {
|
|
1042
|
+
return Math.max(0, Math.min(1, n));
|
|
1290
1043
|
}
|
|
1291
|
-
/**
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1044
|
+
/** Token totals of one refresh minus the previous snapshot (non-negative). */
|
|
1045
|
+
function deltaTotals(prev, next) {
|
|
1046
|
+
return {
|
|
1047
|
+
requests: Math.max(0, next.requests - prev.requests),
|
|
1048
|
+
inputTokens: Math.max(0, next.inputTokens - prev.inputTokens),
|
|
1049
|
+
outputTokens: Math.max(0, next.outputTokens - prev.outputTokens),
|
|
1050
|
+
cacheReadTokens: Math.max(0, next.cacheReadTokens - prev.cacheReadTokens),
|
|
1051
|
+
cacheWriteTokens: Math.max(0, next.cacheWriteTokens - prev.cacheWriteTokens)
|
|
1052
|
+
};
|
|
1296
1053
|
}
|
|
1297
1054
|
/**
|
|
1298
|
-
*
|
|
1299
|
-
*
|
|
1300
|
-
* Cycles are bounded by a `seen` set (a depth-first traversal visits each
|
|
1301
|
-
* id once), so a self-referential or cyclic record set returns the root
|
|
1302
|
-
* alone. Stacks are reversed after pushing so siblings come back out in
|
|
1303
|
-
* insertion order, matching the runtime's lineage index.
|
|
1304
|
-
* @param rows - the retained session-summary mirror (unused when the
|
|
1305
|
-
* caller already built an index).
|
|
1306
|
-
* @param rootId - the scope's root session id.
|
|
1307
|
-
* @param index - optional precomputed index from {@link buildChildIndex}.
|
|
1308
|
-
* @returns the root and its subagent descendants, depth-first.
|
|
1055
|
+
* Single-step intensity from the latest request's token delta (not session
|
|
1056
|
+
* cumulative hit rate): `I = clamp01(0.55·norm(miss) + 0.45·norm(output))`.
|
|
1309
1057
|
*/
|
|
1310
|
-
function
|
|
1311
|
-
const
|
|
1312
|
-
|
|
1313
|
-
const
|
|
1314
|
-
|
|
1315
|
-
const seedChildren = index.get(rootId) ?? [];
|
|
1316
|
-
for (let i = seedChildren.length - 1; i >= 0; i -= 1) stack.push(seedChildren[i]);
|
|
1317
|
-
while (stack.length > 0) {
|
|
1318
|
-
const current = stack.pop();
|
|
1319
|
-
if (seen.has(current)) continue;
|
|
1320
|
-
seen.add(current);
|
|
1321
|
-
out.push(current);
|
|
1322
|
-
const children = index.get(current) ?? [];
|
|
1323
|
-
for (let i = children.length - 1; i >= 0; i -= 1) stack.push(children[i]);
|
|
1324
|
-
}
|
|
1325
|
-
return out;
|
|
1058
|
+
function computeIntensityFromDelta(delta) {
|
|
1059
|
+
const served = delta.inputTokens + delta.cacheReadTokens;
|
|
1060
|
+
const miss = clamp01((1 - (served > 0 ? delta.cacheReadTokens / served : .5)) / MISS_RATE_CAP);
|
|
1061
|
+
const out = clamp01(delta.outputTokens / OUT_CAP);
|
|
1062
|
+
return clamp01(.55 * miss + .45 * out);
|
|
1326
1063
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
* The check is on `parentId` rather than `origin` so a mirrored summary that
|
|
1330
|
-
* lost its origin tag still answers its lineage — the index is built once
|
|
1331
|
-
* per render and shared across all three helpers via {@link ChildIndex}.
|
|
1332
|
-
* @param rows - the retained session-summary mirror.
|
|
1333
|
-
* @param id - the current focus session id.
|
|
1334
|
-
* @returns the parent session id, or undefined when the record has no
|
|
1335
|
-
* parent link (a top-level session or an ordinary fork).
|
|
1336
|
-
*/
|
|
1337
|
-
function subagentParentOf(rows, id) {
|
|
1338
|
-
const parent = rows[id]?.parentId;
|
|
1339
|
-
return parent === void 0 || parent === id ? void 0 : parent;
|
|
1064
|
+
function lerp(a, b, t) {
|
|
1065
|
+
return a + (b - a) * t;
|
|
1340
1066
|
}
|
|
1341
|
-
/**
|
|
1342
|
-
|
|
1343
|
-
* no value at all yields `undefined` — the view renders an em-dash for an
|
|
1344
|
-
* absent capability. The `contributing` count lets the caller tell
|
|
1345
|
-
* "every scope session was empty" apart from "the scope itself was empty".
|
|
1346
|
-
* @param values - the per-session projection values (typically drawn from
|
|
1347
|
-
* the mirror + the live hook).
|
|
1348
|
-
* @returns the summed buckets plus the contributing count, or undefined
|
|
1349
|
-
* when no projection was present.
|
|
1350
|
-
*/
|
|
1351
|
-
function aggregateProjections(values) {
|
|
1352
|
-
let ttftMs = 0;
|
|
1353
|
-
let ttftSteps = 0;
|
|
1354
|
-
let decodeMs = 0;
|
|
1355
|
-
let decodeTokens = 0;
|
|
1356
|
-
let contributing = 0;
|
|
1357
|
-
for (const stats of values) {
|
|
1358
|
-
if (stats === void 0) continue;
|
|
1359
|
-
contributing += 1;
|
|
1360
|
-
ttftMs += stats.ttftMs;
|
|
1361
|
-
ttftSteps += stats.ttftSteps;
|
|
1362
|
-
decodeMs += stats.decodeMs;
|
|
1363
|
-
decodeTokens += stats.decodeTokens;
|
|
1364
|
-
}
|
|
1365
|
-
if (contributing === 0) return void 0;
|
|
1067
|
+
/** Map step intensity I to animation parameters. */
|
|
1068
|
+
function animVars(I) {
|
|
1366
1069
|
return {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1070
|
+
inflateMs: Math.round(lerp(1e3, 1800, I)),
|
|
1071
|
+
popScale: lerp(1.08, 1.32, I).toFixed(3),
|
|
1072
|
+
warnMix: `${Math.round(lerp(0, 55, I))}%`,
|
|
1073
|
+
flyY: `${lerp(22, 38, I).toFixed(1)}px`,
|
|
1074
|
+
flyX: `${((Math.random() - .5) * 10).toFixed(1)}px`
|
|
1372
1075
|
};
|
|
1373
1076
|
}
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/client/use-cost-inflate.ts
|
|
1374
1079
|
/**
|
|
1375
|
-
*
|
|
1376
|
-
*
|
|
1080
|
+
* Request-driven cost-figure inflate animation for the composer-dock usage
|
|
1081
|
+
* pill: detects new usage from summary deltas and drives WAAPI motion on
|
|
1082
|
+
* the cost figure and ephemeral +Δ fly labels.
|
|
1083
|
+
*
|
|
1084
|
+
* @module token-usage/client/use-cost-inflate
|
|
1377
1085
|
*/
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
stats.turns
|
|
1385
|
-
].join(".");
|
|
1086
|
+
const MIN_WIRE_DELTA_COST = 5e-4;
|
|
1087
|
+
function hasUsageChurn(prev, summary) {
|
|
1088
|
+
const delta = deltaTotals(prev.totals, summary.total);
|
|
1089
|
+
if (delta.requests > 0) return true;
|
|
1090
|
+
if (summary.totalCost - prev.totalCost > MIN_WIRE_DELTA_COST) return true;
|
|
1091
|
+
return totalTokens(delta) > 0;
|
|
1386
1092
|
}
|
|
1387
1093
|
/**
|
|
1388
|
-
*
|
|
1389
|
-
*
|
|
1390
|
-
*
|
|
1094
|
+
* Hook the pill uses to play costPop + deltaFall on each new request.
|
|
1095
|
+
* @param scopeKey - changes reset the diff baseline.
|
|
1096
|
+
* @param costRef - the live cost figure span (WAAPI target).
|
|
1391
1097
|
*/
|
|
1392
|
-
function
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1098
|
+
function useCostInflate(scopeKey, costRef) {
|
|
1099
|
+
const prevRef = (0, react.useRef)(null);
|
|
1100
|
+
const flyIdRef = (0, react.useRef)(0);
|
|
1101
|
+
const timersRef = (0, react.useRef)([]);
|
|
1102
|
+
const flyCountRef = (0, react.useRef)(0);
|
|
1103
|
+
const popAnimRef = (0, react.useRef)(null);
|
|
1104
|
+
const [flies, setFlies] = (0, react.useState)([]);
|
|
1105
|
+
const [flyOverflow, setFlyOverflow] = (0, react.useState)(false);
|
|
1106
|
+
const clearTimers = (0, react.useCallback)(() => {
|
|
1107
|
+
for (const id of timersRef.current) window.clearTimeout(id);
|
|
1108
|
+
timersRef.current = [];
|
|
1109
|
+
}, []);
|
|
1110
|
+
const schedule = (0, react.useCallback)((fn, ms) => {
|
|
1111
|
+
const id = window.setTimeout(fn, ms);
|
|
1112
|
+
timersRef.current.push(id);
|
|
1113
|
+
}, []);
|
|
1114
|
+
const reset = (0, react.useCallback)(() => {
|
|
1115
|
+
clearTimers();
|
|
1116
|
+
popAnimRef.current?.cancel();
|
|
1117
|
+
popAnimRef.current = null;
|
|
1118
|
+
prevRef.current = null;
|
|
1119
|
+
flyIdRef.current = 0;
|
|
1120
|
+
flyCountRef.current = 0;
|
|
1121
|
+
setFlies([]);
|
|
1122
|
+
setFlyOverflow(false);
|
|
1123
|
+
}, [clearTimers]);
|
|
1124
|
+
(0, react.useEffect)(() => {
|
|
1125
|
+
reset();
|
|
1126
|
+
}, [scopeKey, reset]);
|
|
1127
|
+
(0, react.useEffect)(() => () => {
|
|
1128
|
+
clearTimers();
|
|
1129
|
+
}, [clearTimers]);
|
|
1130
|
+
const maybeClearOverflow = (0, react.useCallback)(() => {
|
|
1131
|
+
if (flyCountRef.current <= 0) setFlyOverflow(false);
|
|
1132
|
+
}, []);
|
|
1133
|
+
const playCostPop = (0, react.useCallback)((v) => {
|
|
1134
|
+
const el = costRef.current;
|
|
1135
|
+
if (el === null) return;
|
|
1136
|
+
popAnimRef.current?.cancel();
|
|
1137
|
+
popAnimRef.current = runCostPop(el, v);
|
|
1138
|
+
}, [costRef]);
|
|
1139
|
+
return {
|
|
1140
|
+
flies,
|
|
1141
|
+
flyOverflow,
|
|
1142
|
+
onSummary: (0, react.useCallback)((summary) => {
|
|
1143
|
+
const nextSnapshot = {
|
|
1144
|
+
totals: summary.total,
|
|
1145
|
+
totalCost: summary.totalCost
|
|
1146
|
+
};
|
|
1147
|
+
const prev = prevRef.current;
|
|
1148
|
+
prevRef.current = nextSnapshot;
|
|
1149
|
+
if (prev === null) return;
|
|
1150
|
+
if (!hasUsageChurn(prev, summary)) return;
|
|
1151
|
+
if (!motionAllowed()) return;
|
|
1152
|
+
const v = animVars(computeIntensityFromDelta(deltaTotals(prev.totals, summary.total)));
|
|
1153
|
+
setFlyOverflow(true);
|
|
1154
|
+
window.requestAnimationFrame(() => {
|
|
1155
|
+
playCostPop(v);
|
|
1156
|
+
});
|
|
1157
|
+
const wireDeltaCost = summary.totalCost - prev.totalCost;
|
|
1158
|
+
if (wireDeltaCost > MIN_WIRE_DELTA_COST) {
|
|
1159
|
+
const view = currencyViewOf(summary);
|
|
1160
|
+
const text = `+${(wireDeltaCost / view.rate).toFixed(2)}${view.symbol}`;
|
|
1161
|
+
const id = ++flyIdRef.current;
|
|
1162
|
+
flyCountRef.current += 1;
|
|
1163
|
+
setFlies((current) => [...current, {
|
|
1164
|
+
id,
|
|
1165
|
+
text,
|
|
1166
|
+
vars: v
|
|
1167
|
+
}]);
|
|
1168
|
+
schedule(() => {
|
|
1169
|
+
flyCountRef.current -= 1;
|
|
1170
|
+
setFlies((current) => current.filter((fly) => fly.id !== id));
|
|
1171
|
+
maybeClearOverflow();
|
|
1172
|
+
}, v.inflateMs + 40);
|
|
1173
|
+
} else schedule(maybeClearOverflow, v.inflateMs + 40);
|
|
1174
|
+
}, [
|
|
1175
|
+
maybeClearOverflow,
|
|
1176
|
+
playCostPop,
|
|
1177
|
+
schedule
|
|
1178
|
+
]),
|
|
1179
|
+
reset
|
|
1180
|
+
};
|
|
1398
1181
|
}
|
|
1399
1182
|
//#endregion
|
|
1400
|
-
//#region src/client/
|
|
1401
|
-
/**
|
|
1402
|
-
*
|
|
1403
|
-
*
|
|
1404
|
-
*
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1183
|
+
//#region src/client/CostPill.tsx
|
|
1184
|
+
/**
|
|
1185
|
+
* Composer-dock usage pill (browser half): a cost trigger registered into
|
|
1186
|
+
* the `conversation.composer.dock` slot (`order: 10`, after the official
|
|
1187
|
+
* stats pills at `order: 0`), rendered as one capsule in the official
|
|
1188
|
+
* StatsPills skin. The figure is the WITH-SUBAGENTS fold — the one number
|
|
1189
|
+
* no official surface carries — suffixed with a quiet "with subagents"
|
|
1190
|
+
* badge only when the scope actually spans a subtree; a solo session's
|
|
1191
|
+
* cost renders bare, same scope as the official pills beside it.
|
|
1192
|
+
*
|
|
1193
|
+
* Clicking opens a detail panel (harness menu chrome, upward of the dock)
|
|
1194
|
+
* that explains the total: the folded token figure and cache-hit rate next
|
|
1195
|
+
* to it (official pills carry only the single-session token count, so the
|
|
1196
|
+
* subtree share has no home but here), the session / subagents split, and
|
|
1197
|
+
* a per-model breakdown with the unpriced-models footnote. Panel data is
|
|
1198
|
+
* LAZY: the trigger polls `fields=chip` (totals only, subtree scope); the
|
|
1199
|
+
* two richer reads (`fields=session` for byModel, a solo-session `chip`
|
|
1200
|
+
* read for the split) fire when the panel first opens and again whenever
|
|
1201
|
+
* request churn debounces through.
|
|
1202
|
+
*
|
|
1203
|
+
* The pill refreshes at REQUEST granularity (the header chip's former
|
|
1204
|
+
* cadence, inherited whole): `sessionStats` projection churn plus mirror
|
|
1205
|
+
* `updatedAt` is debounced 250 ms into one fetch, a failed FIRST fetch
|
|
1206
|
+
* retries itself on a 3 s cadence, and later failures keep the prior
|
|
1207
|
+
* figures. When cost rises on a new request the figure plays `costPop`
|
|
1208
|
+
* and a +Δ label FALLS below the pill (the dock sits under the composer;
|
|
1209
|
+
* the header chip's upward rise would climb into the message scrollport).
|
|
1210
|
+
* Reduced-motion users get silent figure updates.
|
|
1211
|
+
*
|
|
1212
|
+
* Visibility contract: a session with no recorded requests renders
|
|
1213
|
+
* nothing; a transient fetch miss keeps the previous render.
|
|
1214
|
+
*
|
|
1215
|
+
* @module token-usage/client/CostPill
|
|
1216
|
+
*/
|
|
1217
|
+
/** Refresh debounce: bursts of session-mirror updates (one request's events)
|
|
1218
|
+
* collapse into a single fetch — the header chip's request-scale cadence. */
|
|
1219
|
+
const REFRESH_DEBOUNCE_MS$1 = 250;
|
|
1220
|
+
/** Self-heal cadence after a failed first fetch: refresh failures after the
|
|
1221
|
+
* first land keep the prior figures (silent mode) and self-heal on the next
|
|
1222
|
+
* request churn, so they never reach the error state. */
|
|
1223
|
+
const FETCH_FAILURE_RETRY_MS = 3e3;
|
|
1224
|
+
/** Detail panel width (px); the viewport-clamped centering uses it. */
|
|
1225
|
+
const PANEL_WIDTH = 300;
|
|
1226
|
+
const PANEL_VIEWPORT_MARGIN$1 = 16;
|
|
1227
|
+
/**
|
|
1228
|
+
* Subtract a solo-session summary from its subtree fold.
|
|
1229
|
+
* @param tree - the subtree-scoped folded summary.
|
|
1230
|
+
* @param self - the solo-session summary (same session, no children).
|
|
1231
|
+
* @returns the two shares; costs and tokens are additive so subtraction is
|
|
1232
|
+
* exact, and the hit rate is NEVER split (a ratio is not subtractable — the
|
|
1233
|
+
* panel recomputes the folded rate from the tree totals instead).
|
|
1234
|
+
*/
|
|
1235
|
+
function splitUsage(tree, self) {
|
|
1236
|
+
const sub = (whole, part) => whole - part > 0 ? whole - part : 0;
|
|
1237
|
+
return {
|
|
1238
|
+
selfCost: self.totalCost,
|
|
1239
|
+
subsCost: sub(tree.totalCost, self.totalCost),
|
|
1240
|
+
selfTokens: totalTokens(self.total),
|
|
1241
|
+
subsTokens: sub(totalTokens(tree.total), totalTokens(self.total))
|
|
1242
|
+
};
|
|
1410
1243
|
}
|
|
1411
|
-
/**
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1244
|
+
/**
|
|
1245
|
+
* Render the composer-dock usage pill for the active session. Renders
|
|
1246
|
+
* nothing when the session has no recorded usage or while the first fetch
|
|
1247
|
+
* is in flight — the "data has no value, the block does not render" rule.
|
|
1248
|
+
* @param props - framework session id, the session-list mirror, and the locale seat.
|
|
1249
|
+
* @returns the pill (plus its open detail panel), or null when empty/unavailable.
|
|
1250
|
+
*/
|
|
1251
|
+
function CostPill({ sessionId, useSessions, useProjection, t }) {
|
|
1252
|
+
const rootRef = (0, react.useRef)(null);
|
|
1253
|
+
const costRef = (0, react.useRef)(null);
|
|
1254
|
+
useColorSchemeMirror(rootRef);
|
|
1255
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
1256
|
+
const byId = useSessions((state) => state.byId);
|
|
1257
|
+
const childIndex = (0, react.useMemo)(() => buildChildIndex(byId), [byId]);
|
|
1258
|
+
const scopeIds = (0, react.useMemo)(() => sessionId === "" ? [] : subtreeIds(byId, sessionId, childIndex), [
|
|
1259
|
+
byId,
|
|
1260
|
+
sessionId,
|
|
1261
|
+
childIndex
|
|
1262
|
+
]);
|
|
1263
|
+
const hasSubs = scopeIds.length > 1;
|
|
1264
|
+
const freshnessKey = buildStatsFreshnessKey(scopeIds, {
|
|
1265
|
+
activeSessionId: sessionId,
|
|
1266
|
+
rows: byId,
|
|
1267
|
+
liveSessionStats: useProjection("sessionStats")
|
|
1268
|
+
});
|
|
1269
|
+
const debouncedKey = useDebouncedValue(`${scopeIds.join("\n")}\n\t${freshnessKey}`, REFRESH_DEBOUNCE_MS$1);
|
|
1270
|
+
const { flies, onSummary } = useCostInflate(scopeIds.join("\n"), costRef);
|
|
1271
|
+
const [treeRes, retryTree] = useAsyncResource((signal) => {
|
|
1272
|
+
const [idsPart] = debouncedKey.split("\n ");
|
|
1273
|
+
return fetchSummary$1((idsPart ?? "").split("\n").filter((id) => id !== ""), "chip", signal);
|
|
1274
|
+
}, [debouncedKey], {
|
|
1275
|
+
silentAfterFirst: true,
|
|
1276
|
+
retryToken: 0
|
|
1277
|
+
});
|
|
1278
|
+
const summary = treeRes.status === "ready" ? treeRes.value : null;
|
|
1279
|
+
(0, react.useEffect)(() => {
|
|
1280
|
+
if (summary !== null) onSummary(summary);
|
|
1281
|
+
}, [summary, onSummary]);
|
|
1282
|
+
(0, react.useEffect)(() => {
|
|
1283
|
+
if (treeRes.status !== "error") return;
|
|
1284
|
+
const timer = window.setTimeout(retryTree, FETCH_FAILURE_RETRY_MS);
|
|
1285
|
+
return () => {
|
|
1286
|
+
window.clearTimeout(timer);
|
|
1287
|
+
};
|
|
1288
|
+
}, [treeRes, retryTree]);
|
|
1289
|
+
const [detailRes] = useAsyncResource((signal) => {
|
|
1290
|
+
if (!open) return Promise.resolve(null);
|
|
1291
|
+
const [idsPart] = debouncedKey.split("\n ");
|
|
1292
|
+
return fetchSummary$1((idsPart ?? "").split("\n").filter((id) => id !== ""), "session", signal);
|
|
1293
|
+
}, [open, debouncedKey], {
|
|
1294
|
+
silentAfterFirst: true,
|
|
1295
|
+
retryToken: 0
|
|
1296
|
+
});
|
|
1297
|
+
const [selfRes] = useAsyncResource((signal) => {
|
|
1298
|
+
if (!open || sessionId === "") return Promise.resolve(null);
|
|
1299
|
+
return fetchSummary$1([sessionId], "chip", signal);
|
|
1300
|
+
}, [
|
|
1301
|
+
open,
|
|
1302
|
+
sessionId,
|
|
1303
|
+
debouncedKey
|
|
1436
1304
|
], {
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1305
|
+
silentAfterFirst: true,
|
|
1306
|
+
retryToken: 0
|
|
1307
|
+
});
|
|
1308
|
+
(0, react.useEffect)(() => {
|
|
1309
|
+
setOpen(false);
|
|
1310
|
+
}, [sessionId]);
|
|
1311
|
+
(0, react.useEffect)(() => {
|
|
1312
|
+
if (!open) return;
|
|
1313
|
+
const onPointerDown = (event) => {
|
|
1314
|
+
if (event.target instanceof Node && rootRef.current?.contains(event.target) === true) return;
|
|
1315
|
+
setOpen(false);
|
|
1316
|
+
};
|
|
1317
|
+
const onKeyDown = (event) => {
|
|
1318
|
+
if (event.key === "Escape") setOpen(false);
|
|
1319
|
+
};
|
|
1320
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
1321
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1322
|
+
return () => {
|
|
1323
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
1324
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1325
|
+
};
|
|
1326
|
+
}, [open]);
|
|
1327
|
+
const [panelLeft, setPanelLeft] = (0, react.useState)(void 0);
|
|
1328
|
+
const measurePanelLeft = (0, react.useCallback)(() => {
|
|
1329
|
+
const wrapper = rootRef.current;
|
|
1330
|
+
if (wrapper === null) return;
|
|
1331
|
+
const { left: wrapperLeft, width: wrapperWidth } = wrapper.getBoundingClientRect();
|
|
1332
|
+
const panelWidth = Math.min(PANEL_WIDTH, window.innerWidth - 32);
|
|
1333
|
+
const desired = (wrapperWidth - panelWidth) / 2;
|
|
1334
|
+
const minLeft = PANEL_VIEWPORT_MARGIN$1 - wrapperLeft;
|
|
1335
|
+
const maxLeft = window.innerWidth - PANEL_VIEWPORT_MARGIN$1 - panelWidth - wrapperLeft;
|
|
1336
|
+
setPanelLeft(Math.min(Math.max(desired, minLeft), Math.max(minLeft, maxLeft)));
|
|
1337
|
+
}, []);
|
|
1338
|
+
(0, react.useEffect)(() => {
|
|
1339
|
+
if (!open) return;
|
|
1340
|
+
measurePanelLeft();
|
|
1341
|
+
window.addEventListener("resize", measurePanelLeft);
|
|
1342
|
+
return () => {
|
|
1343
|
+
window.removeEventListener("resize", measurePanelLeft);
|
|
1344
|
+
};
|
|
1345
|
+
}, [open, measurePanelLeft]);
|
|
1346
|
+
if (summary === null || summary.total.requests === 0) return null;
|
|
1347
|
+
const view = currencyViewOf(summary);
|
|
1348
|
+
const costText = formatCost(summary.totalCost, view);
|
|
1349
|
+
const tokensValue = formatTokens(totalTokens(summary.total));
|
|
1350
|
+
const hit = hitRateDisplay(summary.total);
|
|
1351
|
+
const ariaLabel = hasSubs ? t("pill.costWithSubs", { value: costText }) : t("pill.cost", { value: costText });
|
|
1352
|
+
const selfSummary = selfRes.status === "ready" ? selfRes.value : null;
|
|
1353
|
+
const detail = detailRes.status === "ready" ? detailRes.value : null;
|
|
1354
|
+
const split = selfSummary !== null ? splitUsage(summary, selfSummary) : null;
|
|
1355
|
+
const subCount = scopeIds.length - 1;
|
|
1356
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1357
|
+
ref: rootRef,
|
|
1358
|
+
className: CostPill_module_css_default.root,
|
|
1359
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1360
|
+
type: "button",
|
|
1361
|
+
className: CostPill_module_css_default.pill,
|
|
1362
|
+
"aria-haspopup": "dialog",
|
|
1363
|
+
"aria-expanded": open,
|
|
1364
|
+
"aria-label": `${ariaLabel},${t("panel.openHint")}`,
|
|
1365
|
+
onClick: () => {
|
|
1366
|
+
setOpen(!open);
|
|
1367
|
+
},
|
|
1368
|
+
children: [
|
|
1369
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
1370
|
+
className: CostPill_module_css_default.glyph,
|
|
1371
|
+
viewBox: "0 0 14 14",
|
|
1372
|
+
width: "14",
|
|
1373
|
+
height: "14",
|
|
1374
|
+
"aria-hidden": true,
|
|
1375
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1376
|
+
cx: "7",
|
|
1377
|
+
cy: "7",
|
|
1378
|
+
r: "5.5",
|
|
1379
|
+
fill: "none",
|
|
1380
|
+
stroke: "currentColor",
|
|
1381
|
+
strokeWidth: "1.2"
|
|
1382
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
1383
|
+
d: "M4.8 4.5 L7 7.2 L9.2 4.5 M7 7.2 V10 M5.2 8 H8.8 M5.2 9.4 H8.8",
|
|
1384
|
+
fill: "none",
|
|
1385
|
+
stroke: "currentColor",
|
|
1386
|
+
strokeWidth: "1.2"
|
|
1387
|
+
})]
|
|
1388
|
+
}),
|
|
1389
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1390
|
+
ref: costRef,
|
|
1391
|
+
className: CostPill_module_css_default.cost,
|
|
1392
|
+
children: costText
|
|
1393
|
+
}),
|
|
1394
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1395
|
+
className: CostPill_module_css_default.deltaLayer,
|
|
1396
|
+
"aria-hidden": "true",
|
|
1397
|
+
children: flies.map((fly) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostDeltaFlyLabel, {
|
|
1398
|
+
text: fly.text,
|
|
1399
|
+
vars: fly.vars
|
|
1400
|
+
}, fly.id))
|
|
1401
|
+
})
|
|
1402
|
+
]
|
|
1403
|
+
}), open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1404
|
+
className: CostPill_module_css_default.panel,
|
|
1405
|
+
role: "dialog",
|
|
1406
|
+
"aria-label": t("panel.title"),
|
|
1407
|
+
style: { left: panelLeft },
|
|
1408
|
+
children: [
|
|
1409
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1410
|
+
className: CostPill_module_css_default.panelHead,
|
|
1411
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1412
|
+
className: CostPill_module_css_default.panelTitle,
|
|
1413
|
+
children: [t("panel.title"), hasSubs && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1414
|
+
className: CostPill_module_css_default.scopeTag,
|
|
1415
|
+
children: t("pill.scopeTag")
|
|
1416
|
+
})]
|
|
1417
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1418
|
+
className: CostPill_module_css_default.panelTotal,
|
|
1419
|
+
children: costText
|
|
1420
|
+
})]
|
|
1421
|
+
}),
|
|
1422
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1423
|
+
className: CostPill_module_css_default.usageLine,
|
|
1424
|
+
children: [
|
|
1425
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("panel.tokens", { value: tokensValue }) }),
|
|
1426
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1427
|
+
className: CostPill_module_css_default.dot,
|
|
1428
|
+
children: "·"
|
|
1429
|
+
}),
|
|
1430
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("panel.hitRate", { value: hit.text }) })
|
|
1431
|
+
]
|
|
1432
|
+
}),
|
|
1433
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1434
|
+
className: CostPill_module_css_default.rows,
|
|
1435
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1436
|
+
className: CostPill_module_css_default.row,
|
|
1437
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1438
|
+
className: CostPill_module_css_default.rowLabel,
|
|
1439
|
+
children: t("panel.self")
|
|
1440
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1441
|
+
className: CostPill_module_css_default.rowValue,
|
|
1442
|
+
children: split === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1443
|
+
className: CostPill_module_css_default.pending,
|
|
1444
|
+
children: "…"
|
|
1445
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [formatCost(split.selfCost, view), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1446
|
+
className: CostPill_module_css_default.tok,
|
|
1447
|
+
children: t("panel.tokens", { value: formatTokens(split.selfTokens) })
|
|
1448
|
+
})] })
|
|
1449
|
+
})]
|
|
1450
|
+
}), hasSubs && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1451
|
+
className: `${CostPill_module_css_default.row} ${CostPill_module_css_default.rowSub}`,
|
|
1452
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1453
|
+
className: CostPill_module_css_default.rowLabel,
|
|
1454
|
+
children: t("panel.subs", { count: subCount })
|
|
1455
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1456
|
+
className: CostPill_module_css_default.rowValue,
|
|
1457
|
+
children: split === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1458
|
+
className: CostPill_module_css_default.pending,
|
|
1459
|
+
children: "…"
|
|
1460
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [formatCost(split.subsCost, view), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1461
|
+
className: CostPill_module_css_default.tok,
|
|
1462
|
+
children: t("panel.tokens", { value: formatTokens(split.subsTokens) })
|
|
1463
|
+
})] })
|
|
1464
|
+
})]
|
|
1465
|
+
})]
|
|
1466
|
+
}),
|
|
1467
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1468
|
+
className: CostPill_module_css_default.groupLabel,
|
|
1469
|
+
children: t("panel.byModel")
|
|
1470
|
+
}),
|
|
1471
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1472
|
+
className: CostPill_module_css_default.rows,
|
|
1473
|
+
children: detail === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1474
|
+
className: CostPill_module_css_default.row,
|
|
1475
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1476
|
+
className: CostPill_module_css_default.pending,
|
|
1477
|
+
children: "…"
|
|
1478
|
+
})
|
|
1479
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [detail.byModel.map((row) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelRow, {
|
|
1480
|
+
row,
|
|
1481
|
+
view
|
|
1482
|
+
}, row.model)), detail.unpricedModels.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1483
|
+
className: `${CostPill_module_css_default.row} ${CostPill_module_css_default.unpriced}`,
|
|
1484
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1485
|
+
className: CostPill_module_css_default.rowLabel,
|
|
1486
|
+
children: t("panel.unpriced", { count: detail.unpricedModels.length })
|
|
1487
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1488
|
+
className: CostPill_module_css_default.rowValue,
|
|
1489
|
+
children: t("panel.unpricedNote")
|
|
1490
|
+
})]
|
|
1491
|
+
})] })
|
|
1492
|
+
})
|
|
1493
|
+
]
|
|
1494
|
+
})]
|
|
1440
1495
|
});
|
|
1441
1496
|
}
|
|
1442
|
-
/**
|
|
1443
|
-
function
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
{
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
}
|
|
1459
|
-
], {
|
|
1460
|
-
duration: v.inflateMs,
|
|
1461
|
-
easing: "cubic-bezier(0.22, 0.55, 0.25, 1)",
|
|
1462
|
-
fill: "both"
|
|
1497
|
+
/** One per-model breakdown row: model id + request count, billed cost, tokens. */
|
|
1498
|
+
function ModelRow({ row, view }) {
|
|
1499
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1500
|
+
className: CostPill_module_css_default.row,
|
|
1501
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1502
|
+
className: CostPill_module_css_default.rowLabel,
|
|
1503
|
+
children: [row.model, /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1504
|
+
className: CostPill_module_css_default.requests,
|
|
1505
|
+
children: ["× ", row.totals.requests]
|
|
1506
|
+
})]
|
|
1507
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1508
|
+
className: CostPill_module_css_default.rowValue,
|
|
1509
|
+
children: [formatCost(row.cost, view), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1510
|
+
className: CostPill_module_css_default.tok,
|
|
1511
|
+
children: formatTokens(totalTokens(row.totals))
|
|
1512
|
+
})]
|
|
1513
|
+
})]
|
|
1463
1514
|
});
|
|
1464
1515
|
}
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$10) + "]") === null) {
|
|
1470
|
-
const tag = document.createElement("style");
|
|
1471
|
-
tag.dataset.plugin = "@laoyuehanni/dsh-token-usage";
|
|
1472
|
-
tag.dataset.pluginCss = tagId$10;
|
|
1473
|
-
tag.textContent = css$10;
|
|
1474
|
-
document.head.appendChild(tag);
|
|
1516
|
+
/** Defensive shape check: an older host build or a misrouted response
|
|
1517
|
+
* would otherwise paint the pill with garbage. */
|
|
1518
|
+
function looksLikeUsageSummary(value) {
|
|
1519
|
+
return typeof value === "object" && value !== null && typeof value.total === "object" && value.total !== null;
|
|
1475
1520
|
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
if (anim === null) {
|
|
1496
|
-
el.style.visibility = "hidden";
|
|
1497
|
-
return;
|
|
1498
|
-
}
|
|
1499
|
-
return () => {
|
|
1500
|
-
anim.cancel();
|
|
1501
|
-
};
|
|
1502
|
-
}, [vars]);
|
|
1503
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1504
|
-
ref,
|
|
1505
|
-
className: SessionStatsChip_module_css_default["deltaFly"],
|
|
1506
|
-
children: text
|
|
1521
|
+
/**
|
|
1522
|
+
* Fetch one stats summary. Throws on transport failure (network, abort,
|
|
1523
|
+
* non-2xx response, or a payload that doesn't look like a stats summary) so
|
|
1524
|
+
* the hook can keep the previous render in place.
|
|
1525
|
+
* @param sessionIds - the scope's session ids; an empty list skips the
|
|
1526
|
+
* fetch (returning null rather than throwing, so the hook's first-load
|
|
1527
|
+
* gate stays at "loading").
|
|
1528
|
+
* @param fields - `chip` for totals-only reads, `session` when byModel is
|
|
1529
|
+
* needed (the detail panel's per-model block).
|
|
1530
|
+
* @param signal - the cancellation signal from the hook.
|
|
1531
|
+
*/
|
|
1532
|
+
async function fetchSummary$1(sessionIds, fields, signal) {
|
|
1533
|
+
if (sessionIds.length === 0) return null;
|
|
1534
|
+
const response = await fetch(STATS_PATH + encodeStatsQuery({
|
|
1535
|
+
sessionIds,
|
|
1536
|
+
fields
|
|
1537
|
+
}), {
|
|
1538
|
+
headers: { accept: "application/json" },
|
|
1539
|
+
signal
|
|
1507
1540
|
});
|
|
1541
|
+
if (!response.ok) throw new Error(`HTTP ${String(response.status)}`);
|
|
1542
|
+
const value = await response.json();
|
|
1543
|
+
if (!looksLikeUsageSummary(value)) throw new Error("unexpected stats response");
|
|
1544
|
+
return value;
|
|
1508
1545
|
}
|
|
1509
1546
|
//#endregion
|
|
1510
|
-
//#region src/client/
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1547
|
+
//#region src/client/quota-format.ts
|
|
1548
|
+
/** Severity thresholds on the REMAINING share (percent) — the traffic-light
|
|
1549
|
+
* standard: above 60 reads green (plenty left), 20–60 yellow (watch it),
|
|
1550
|
+
* below 20 red (effectively gone). */
|
|
1551
|
+
const REMAIN_YELLOW = 60;
|
|
1552
|
+
const REMAIN_RED = 20;
|
|
1553
|
+
/** Whole-number percent, one decimal kept when it exists (`62%`, `87.5%`). */
|
|
1554
|
+
function formatQuotaPercent(value) {
|
|
1555
|
+
const rounded = Math.round(value * 10) / 10;
|
|
1556
|
+
return `${Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1)}%`;
|
|
1557
|
+
}
|
|
1558
|
+
/** A money figure with its symbol: `$6.80` / `¥110.00`. */
|
|
1559
|
+
function formatQuotaMoney(value, unit) {
|
|
1560
|
+
return `${unit === "usd" ? "$" : "¥"}${value.toFixed(2)}`;
|
|
1516
1561
|
}
|
|
1517
|
-
/**
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1562
|
+
/**
|
|
1563
|
+
* The used share of one window, 0–100, whichever direction the provider
|
|
1564
|
+
* reported: the explicit `usedPercent`, else `remainingPercent` inverted,
|
|
1565
|
+
* else the balance fraction (`1 - remaining/max`). Undefined when the
|
|
1566
|
+
* window carries no computable ratio (a balance without a total).
|
|
1567
|
+
*/
|
|
1568
|
+
function quotaUsedPercent(window) {
|
|
1569
|
+
if (window.usedPercent !== void 0) return clampPercent(window.usedPercent);
|
|
1570
|
+
if (window.remainingPercent !== void 0) return clampPercent(100 - window.remainingPercent);
|
|
1571
|
+
if (window.remainingValue !== void 0 && window.maxValue !== void 0 && window.maxValue > 0) return clampPercent((1 - window.remainingValue / window.maxValue) * 100);
|
|
1526
1572
|
}
|
|
1527
1573
|
/**
|
|
1528
|
-
*
|
|
1529
|
-
*
|
|
1574
|
+
* The remaining share of one window, 0–100 — the severity input (severity
|
|
1575
|
+
* reads what is LEFT, not what is spent). Mirrors {@link quotaUsedPercent}'s
|
|
1576
|
+
* fallback chain in the opposite direction.
|
|
1530
1577
|
*/
|
|
1531
|
-
function
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
return clamp01(.55 * miss + .45 * out);
|
|
1578
|
+
function quotaRemainingPercent(window) {
|
|
1579
|
+
if (window.remainingPercent !== void 0) return clampPercent(window.remainingPercent);
|
|
1580
|
+
if (window.usedPercent !== void 0) return clampPercent(100 - window.usedPercent);
|
|
1581
|
+
if (window.remainingValue !== void 0 && window.maxValue !== void 0 && window.maxValue > 0) return clampPercent(window.remainingValue / window.maxValue * 100);
|
|
1536
1582
|
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1583
|
+
/** Map a remaining share (percent) to the traffic-light band: green above
|
|
1584
|
+
* 60, yellow 20–60, red below 20. A window with no computable ratio reads
|
|
1585
|
+
* by its absolute amount: an overdrawn/empty balance (≤ 0) is red,
|
|
1586
|
+
* anything else uncolored — a plain balance never paints alarm just for
|
|
1587
|
+
* lacking a total. */
|
|
1588
|
+
function quotaSeverityOf(window) {
|
|
1589
|
+
const remaining = quotaRemainingPercent(window);
|
|
1590
|
+
if (remaining === void 0) return window.remainingValue !== void 0 && window.remainingValue <= 0 ? "exhausted" : "ok";
|
|
1591
|
+
if (remaining < REMAIN_RED) return "exhausted";
|
|
1592
|
+
if (remaining <= REMAIN_YELLOW) return "warn";
|
|
1593
|
+
return "ok";
|
|
1539
1594
|
}
|
|
1540
|
-
/**
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1595
|
+
/**
|
|
1596
|
+
* The FINEST-granularity window of a payload — 5-hour over weekly over
|
|
1597
|
+
* monthly over balance. The trigger icon reads this one, not the worst
|
|
1598
|
+
* across windows: the finest unit is the constraint the session is
|
|
1599
|
+
* currently acting inside (a calm 5-hour window carries the icon even when
|
|
1600
|
+
* the weekly pool runs low). Undefined when there is no window at all.
|
|
1601
|
+
*/
|
|
1602
|
+
function finestQuotaWindow(windows) {
|
|
1603
|
+
const rank = {
|
|
1604
|
+
five_hour: 0,
|
|
1605
|
+
weekly: 1,
|
|
1606
|
+
monthly: 2,
|
|
1607
|
+
balance: 3
|
|
1548
1608
|
};
|
|
1609
|
+
let pick;
|
|
1610
|
+
for (const window of windows) if (pick === void 0 || rank[window.tier] < rank[pick.tier]) pick = window;
|
|
1611
|
+
return pick;
|
|
1549
1612
|
}
|
|
1550
|
-
//#endregion
|
|
1551
|
-
//#region src/client/use-cost-inflate.ts
|
|
1552
1613
|
/**
|
|
1553
|
-
*
|
|
1554
|
-
*
|
|
1555
|
-
*
|
|
1556
|
-
*
|
|
1557
|
-
* @module token-usage/client/use-cost-inflate
|
|
1614
|
+
* Fill share of the trigger ring, 0–1. Ratio windows map the remaining
|
|
1615
|
+
* percent; a funded balance without a total paints a full ring (the color
|
|
1616
|
+
* stays neutral — amounts tint only at ≤ 0); empty / overdrawn / missing
|
|
1617
|
+
* windows leave the track only.
|
|
1558
1618
|
*/
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
const
|
|
1562
|
-
if (
|
|
1563
|
-
if (
|
|
1564
|
-
return
|
|
1619
|
+
function quotaIconFillShare(window) {
|
|
1620
|
+
if (window === void 0) return 0;
|
|
1621
|
+
const remaining = quotaRemainingPercent(window);
|
|
1622
|
+
if (remaining !== void 0) return remaining / 100;
|
|
1623
|
+
if (window.remainingValue !== void 0 && window.remainingValue > 0) return 1;
|
|
1624
|
+
return 0;
|
|
1565
1625
|
}
|
|
1566
1626
|
/**
|
|
1567
|
-
*
|
|
1568
|
-
*
|
|
1569
|
-
*
|
|
1627
|
+
* The trigger tooltip's figure for one window: the remaining share as a
|
|
1628
|
+
* percent when a ratio exists (any direction, or the balance fraction),
|
|
1629
|
+
* else the remaining amount (a ratio-less balance, the DeepSeek shape);
|
|
1630
|
+
* undefined when the window carries neither (nothing to show beyond the
|
|
1631
|
+
* plain label).
|
|
1570
1632
|
*/
|
|
1571
|
-
function
|
|
1572
|
-
|
|
1573
|
-
const
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
}, [costRef]);
|
|
1612
|
-
return {
|
|
1613
|
-
flies,
|
|
1614
|
-
flyOverflow,
|
|
1615
|
-
onSummary: (0, react.useCallback)((summary) => {
|
|
1616
|
-
const nextSnapshot = {
|
|
1617
|
-
totals: summary.total,
|
|
1618
|
-
totalCost: summary.totalCost
|
|
1619
|
-
};
|
|
1620
|
-
const prev = prevRef.current;
|
|
1621
|
-
prevRef.current = nextSnapshot;
|
|
1622
|
-
if (prev === null) return;
|
|
1623
|
-
if (!hasUsageChurn(prev, summary)) return;
|
|
1624
|
-
if (!motionAllowed()) return;
|
|
1625
|
-
const v = animVars(computeIntensityFromDelta(deltaTotals(prev.totals, summary.total)));
|
|
1626
|
-
setFlyOverflow(true);
|
|
1627
|
-
window.requestAnimationFrame(() => {
|
|
1628
|
-
playCostPop(v);
|
|
1629
|
-
});
|
|
1630
|
-
const wireDeltaCost = summary.totalCost - prev.totalCost;
|
|
1631
|
-
if (wireDeltaCost > MIN_WIRE_DELTA_COST) {
|
|
1632
|
-
const view = currencyViewOf(summary);
|
|
1633
|
-
const text = `+${view.symbol}${(wireDeltaCost / view.rate).toFixed(2)}`;
|
|
1634
|
-
const id = ++flyIdRef.current;
|
|
1635
|
-
flyCountRef.current += 1;
|
|
1636
|
-
setFlies((current) => [...current, {
|
|
1637
|
-
id,
|
|
1638
|
-
text,
|
|
1639
|
-
vars: v
|
|
1640
|
-
}]);
|
|
1641
|
-
schedule(() => {
|
|
1642
|
-
flyCountRef.current -= 1;
|
|
1643
|
-
setFlies((current) => current.filter((fly) => fly.id !== id));
|
|
1644
|
-
maybeClearOverflow();
|
|
1645
|
-
}, v.inflateMs + 40);
|
|
1646
|
-
} else schedule(maybeClearOverflow, v.inflateMs + 40);
|
|
1647
|
-
}, [
|
|
1648
|
-
maybeClearOverflow,
|
|
1649
|
-
playCostPop,
|
|
1650
|
-
schedule
|
|
1651
|
-
]),
|
|
1652
|
-
reset
|
|
1653
|
-
};
|
|
1633
|
+
function quotaTriggerFigure(window) {
|
|
1634
|
+
if (window === void 0) return void 0;
|
|
1635
|
+
const remaining = quotaRemainingPercent(window);
|
|
1636
|
+
if (remaining !== void 0) return formatQuotaPercent(remaining);
|
|
1637
|
+
if (window.remainingValue !== void 0) return formatQuotaMoney(window.remainingValue, window.unit ?? "cny");
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* The reset countdown in the shell's compact shape: `2h 14m` under a day,
|
|
1641
|
+
* `48m` under an hour, `1d 3h` above; a non-positive remainder reads `0m`
|
|
1642
|
+
* (the next poll refreshes the stale window).
|
|
1643
|
+
* @param resetAt - epoch ms of the window's reset.
|
|
1644
|
+
* @param now - epoch ms the countdown is taken at.
|
|
1645
|
+
*/
|
|
1646
|
+
function formatResetCountdown(resetAt, now) {
|
|
1647
|
+
const minutes = Math.max(0, Math.floor((resetAt - now) / 6e4));
|
|
1648
|
+
if (minutes < 60) return `${String(minutes)}m`;
|
|
1649
|
+
const hours = Math.floor(minutes / 60);
|
|
1650
|
+
if (hours < 24) return `${String(hours)}h ${String(minutes % 60)}m`;
|
|
1651
|
+
return `${String(Math.floor(hours / 24))}d ${String(hours % 24)}h`;
|
|
1652
|
+
}
|
|
1653
|
+
/** A wall-clock `HH:MM` stamp of an epoch-ms time (the "updated at" figure). */
|
|
1654
|
+
function formatQuotaClock(ms) {
|
|
1655
|
+
const date = new Date(ms);
|
|
1656
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
1657
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
1658
|
+
}
|
|
1659
|
+
/** Clamp into 0–100. */
|
|
1660
|
+
function clampPercent(value) {
|
|
1661
|
+
return Math.min(100, Math.max(0, value));
|
|
1662
|
+
}
|
|
1663
|
+
//#endregion
|
|
1664
|
+
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\QuotaButton.module.css.mjs
|
|
1665
|
+
const css$11 = ".jYASuG_root{flex:none;display:inline-flex;position:relative}.jYASuG_trigger{width:28px;height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:999px;flex:none;place-items:center;padding:0;display:grid}.jYASuG_trigger svg{display:block}.jYASuG_trigger:hover,.jYASuG_trigger[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.jYASuG_trigger.jYASuG_icon-ok:hover,.jYASuG_trigger.jYASuG_icon-ok[aria-expanded=true]{color:var(--dsw-alias-state-success-primary)}.jYASuG_trigger.jYASuG_icon-warn:hover,.jYASuG_trigger.jYASuG_icon-warn[aria-expanded=true]{color:var(--dsw-alias-state-warn-primary)}.jYASuG_trigger.jYASuG_icon-exhausted:hover,.jYASuG_trigger.jYASuG_icon-exhausted[aria-expanded=true]{color:var(--dsw-alias-state-error-primary)}.jYASuG_icon-ok{color:var(--dsw-alias-state-success-primary)}.jYASuG_icon-warn{color:var(--dsw-alias-state-warn-primary)}.jYASuG_icon-exhausted{color:var(--dsw-alias-state-error-primary)}.jYASuG_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-menu);width:320px;max-width:calc(100vw - 32px);backdrop-filter:var(--dsw-menu-backdrop-filter);box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-secondary);text-align:left;cursor:default;border-radius:12px;padding:12px;font-size:12px;line-height:20px;position:absolute;bottom:calc(100% + 8px)}.jYASuG_header{justify-content:space-between;align-items:baseline;gap:8px;margin-bottom:10px;display:flex}.jYASuG_title{color:var(--dsw-alias-label-primary);white-space:nowrap;text-overflow:ellipsis;font-size:13px;font-weight:500;overflow:hidden}.jYASuG_plan{color:var(--dsw-alias-label-tertiary);font-weight:400}.jYASuG_updated{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;font-size:11px}.jYASuG_grid{grid-template-columns:repeat(var(--cols,3), 1fr);gap:14px;display:grid}.jYASuG_col{min-width:0}.jYASuG_label{color:var(--dsw-alias-label-tertiary);white-space:nowrap;text-overflow:ellipsis;margin-bottom:2px;font-size:11px;line-height:16px;overflow:hidden}.jYASuG_value{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;white-space:nowrap;margin-bottom:6px;font-size:13px;font-weight:600;line-height:18px}.jYASuG_meta{color:var(--dsw-alias-label-tertiary);font-size:11px;font-weight:400}.jYASuG_bar{background:var(--dsw-alias-interactive-bg-hover);border-radius:999px;height:4px;overflow:hidden}.jYASuG_fill{border-radius:999px;height:100%;transition:width .3s}.jYASuG_ok{background:var(--dsw-alias-state-success-primary)}.jYASuG_warn{background:var(--dsw-alias-state-warn-primary)}.jYASuG_exhausted{background:var(--dsw-alias-state-error-primary)}.jYASuG_aux{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;white-space:nowrap;margin-top:4px;font-size:11px;line-height:14px}.jYASuG_dot{vertical-align:middle;border-radius:50%;width:5px;height:5px;margin-right:3px;display:inline-block}.jYASuG_error{flex-direction:column;gap:8px;display:flex}.jYASuG_errorText{color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;font-size:12px;line-height:18px}.jYASuG_retry{color:var(--dsw-alias-label-primary);cursor:pointer;text-underline-offset:2px;background:0 0;border:none;align-self:flex-start;padding:0;font-size:12px;text-decoration:underline}.jYASuG_retry:hover{color:var(--dsw-alias-brand-primary)}";
|
|
1666
|
+
const tagId$11 = "@laoyuehanni/dsh-token-usage/QuotaButton.module.css";
|
|
1667
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$11) + "]") === null) {
|
|
1668
|
+
const tag = document.createElement("style");
|
|
1669
|
+
tag.dataset.plugin = "@laoyuehanni/dsh-token-usage";
|
|
1670
|
+
tag.dataset.pluginCss = tagId$11;
|
|
1671
|
+
tag.textContent = css$11;
|
|
1672
|
+
document.head.appendChild(tag);
|
|
1654
1673
|
}
|
|
1674
|
+
var QuotaButton_module_css_default = {
|
|
1675
|
+
"aux": "jYASuG_aux",
|
|
1676
|
+
"bar": "jYASuG_bar",
|
|
1677
|
+
"col": "jYASuG_col",
|
|
1678
|
+
"dot": "jYASuG_dot",
|
|
1679
|
+
"error": "jYASuG_error",
|
|
1680
|
+
"errorText": "jYASuG_errorText",
|
|
1681
|
+
"exhausted": "jYASuG_exhausted",
|
|
1682
|
+
"fill": "jYASuG_fill",
|
|
1683
|
+
"grid": "jYASuG_grid",
|
|
1684
|
+
"header": "jYASuG_header",
|
|
1685
|
+
"icon-exhausted": "jYASuG_icon-exhausted",
|
|
1686
|
+
"icon-ok": "jYASuG_icon-ok",
|
|
1687
|
+
"icon-warn": "jYASuG_icon-warn",
|
|
1688
|
+
"label": "jYASuG_label",
|
|
1689
|
+
"meta": "jYASuG_meta",
|
|
1690
|
+
"ok": "jYASuG_ok",
|
|
1691
|
+
"panel": "jYASuG_panel",
|
|
1692
|
+
"plan": "jYASuG_plan",
|
|
1693
|
+
"retry": "jYASuG_retry",
|
|
1694
|
+
"root": "jYASuG_root",
|
|
1695
|
+
"title": "jYASuG_title",
|
|
1696
|
+
"trigger": "jYASuG_trigger",
|
|
1697
|
+
"updated": "jYASuG_updated",
|
|
1698
|
+
"value": "jYASuG_value",
|
|
1699
|
+
"warn": "jYASuG_warn"
|
|
1700
|
+
};
|
|
1655
1701
|
//#endregion
|
|
1656
|
-
//#region src/client/
|
|
1702
|
+
//#region src/client/QuotaButton.tsx
|
|
1657
1703
|
/**
|
|
1658
|
-
*
|
|
1659
|
-
* into the `conversation.
|
|
1660
|
-
*
|
|
1661
|
-
*
|
|
1662
|
-
*
|
|
1663
|
-
*
|
|
1664
|
-
*
|
|
1665
|
-
*
|
|
1666
|
-
*
|
|
1667
|
-
*
|
|
1668
|
-
*
|
|
1669
|
-
*
|
|
1670
|
-
*
|
|
1671
|
-
*
|
|
1672
|
-
*
|
|
1704
|
+
* Input-bar quota button (browser half): a 28×28 round trigger registered
|
|
1705
|
+
* into the `conversation.input.right` slot (it renders left of the model
|
|
1706
|
+
* chip — the host's fixed tool-row order). The glyph is a remaining-share
|
|
1707
|
+
* ring (ContextMeter family) colored by the finest window. Clicking opens a
|
|
1708
|
+
* width-tiered popup (amount-only 200px / one progress bar 232px / two
|
|
1709
|
+
* bars 320px) centered on the button with the current provider's quota
|
|
1710
|
+
* windows: progress columns (5 小时 / 每周) for coding-plan providers, an
|
|
1711
|
+
* amount row for balance providers.
|
|
1712
|
+
*
|
|
1713
|
+
* The provider follows the model CHIP's live selection (the shell's
|
|
1714
|
+
* model-selection service reports the host's next selection before any
|
|
1715
|
+
* request is sent); without that service the host falls back to the last
|
|
1716
|
+
* request's provider, else the default selection.
|
|
1717
|
+
*
|
|
1718
|
+
* The button SELF-GATES: it renders nothing while the host cannot
|
|
1719
|
+
* determine a provider (`no-provider`), the provider has no quota adapter
|
|
1720
|
+
* (`unsupported`), or the feature is off (`disabled`) — switching
|
|
1721
|
+
* providers makes it appear again. A supported provider whose query fails
|
|
1722
|
+
* KEEPS the button and shows the error with a retry inside the panel.
|
|
1723
|
+
*
|
|
1724
|
+
* The hover tooltip reads provider name + the finest window's exact
|
|
1725
|
+
* remaining figure (percent, or the amount when no ratio exists).
|
|
1673
1726
|
*
|
|
1674
|
-
*
|
|
1675
|
-
*
|
|
1676
|
-
*
|
|
1677
|
-
*
|
|
1678
|
-
* Amber/lime fill the warm→cool gap so the four stops read as one progression.
|
|
1727
|
+
* The interaction copies ContextMeter verbatim (click toggles, document
|
|
1728
|
+
* pointerdown outside closes, Escape closes); mutual exclusion with the
|
|
1729
|
+
* ContextMeter panel falls out of both components' outside-close
|
|
1730
|
+
* handlers — opening one closes the other on its next pointerdown.
|
|
1679
1731
|
*
|
|
1680
|
-
* @module token-usage/client/
|
|
1732
|
+
* @module token-usage/client/QuotaButton
|
|
1681
1733
|
*/
|
|
1682
|
-
/**
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
*
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
const
|
|
1734
|
+
/** The poll cadence fallback (seconds) while no payload has named one. */
|
|
1735
|
+
const DEFAULT_POLL_SEC = 60;
|
|
1736
|
+
/** Panel width tiers (px), by how much the windows paint: a lone amount
|
|
1737
|
+
* reads at a glance, one progress bar needs breathing room, two bars (the
|
|
1738
|
+
* 5-hour + weekly coding plans, or a long error body) the full plate. Kept
|
|
1739
|
+
* in sync with the CSS max-width clamp. */
|
|
1740
|
+
const PANEL_WIDTH_BALANCE = 200;
|
|
1741
|
+
const PANEL_WIDTH_SINGLE = 232;
|
|
1742
|
+
const PANEL_WIDTH_FULL = 320;
|
|
1743
|
+
const PANEL_VIEWPORT_MARGIN = 16;
|
|
1744
|
+
/** Tier → label key; the locale dictionaries carry both languages. */
|
|
1745
|
+
const TIER_LABEL_KEYS = {
|
|
1746
|
+
five_hour: "quota.tier.fiveHour",
|
|
1747
|
+
weekly: "quota.tier.weekly",
|
|
1748
|
+
monthly: "quota.tier.monthly",
|
|
1749
|
+
balance: "quota.tier.balance"
|
|
1750
|
+
};
|
|
1691
1751
|
/**
|
|
1692
|
-
* Render the
|
|
1693
|
-
*
|
|
1694
|
-
*
|
|
1695
|
-
*
|
|
1696
|
-
* @param props - framework session id, the session-list mirror, and the locale seat.
|
|
1697
|
-
* @returns the chip strip, or null when the data is empty/unavailable.
|
|
1752
|
+
* Render the input-bar quota button for the active session's provider.
|
|
1753
|
+
* @param props - the framework session id, the locale seat, and the
|
|
1754
|
+
* optional model-directory holder (the chip's live selection).
|
|
1755
|
+
* @returns the trigger + panel, or null while hidden (see the module note).
|
|
1698
1756
|
*/
|
|
1699
|
-
function
|
|
1757
|
+
function QuotaButton({ sessionId, t, modelDirectory }) {
|
|
1700
1758
|
const rootRef = (0, react.useRef)(null);
|
|
1701
|
-
const costRef = (0, react.useRef)(null);
|
|
1702
1759
|
useColorSchemeMirror(rootRef);
|
|
1703
|
-
const
|
|
1704
|
-
const
|
|
1705
|
-
const
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
});
|
|
1715
|
-
const
|
|
1716
|
-
const
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1760
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
1761
|
+
const [panelLeft, setPanelLeft] = (0, react.useState)(void 0);
|
|
1762
|
+
const measurePanelLeft = (0, react.useCallback)((width) => {
|
|
1763
|
+
const wrapper = rootRef.current;
|
|
1764
|
+
if (wrapper === null) return;
|
|
1765
|
+
const { left: wrapperLeft, width: wrapperWidth } = wrapper.getBoundingClientRect();
|
|
1766
|
+
const panelWidth = Math.min(width, window.innerWidth - 32);
|
|
1767
|
+
const desired = (wrapperWidth - panelWidth) / 2;
|
|
1768
|
+
const minLeft = PANEL_VIEWPORT_MARGIN - wrapperLeft;
|
|
1769
|
+
const maxLeft = window.innerWidth - PANEL_VIEWPORT_MARGIN - panelWidth - wrapperLeft;
|
|
1770
|
+
setPanelLeft(Math.min(Math.max(desired, minLeft), Math.max(minLeft, maxLeft)));
|
|
1771
|
+
}, []);
|
|
1772
|
+
const modelService = modelDirectory?.service;
|
|
1773
|
+
const readChipProvider = () => {
|
|
1774
|
+
if (sessionId === "" || modelService === void 0) return void 0;
|
|
1775
|
+
try {
|
|
1776
|
+
return modelService.directoryFor(sessionId).store.getSnapshot().current?.provider ?? void 0;
|
|
1777
|
+
} catch {
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
const [chipProvider, setChipProvider] = (0, react.useState)(readChipProvider);
|
|
1782
|
+
(0, react.useEffect)(() => {
|
|
1783
|
+
setChipProvider(readChipProvider());
|
|
1784
|
+
if (sessionId === "" || modelService === void 0) return;
|
|
1785
|
+
let directory;
|
|
1786
|
+
try {
|
|
1787
|
+
directory = modelService.directoryFor(sessionId);
|
|
1788
|
+
} catch {
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
return directory.store.subscribe(() => {
|
|
1792
|
+
setChipProvider(readChipProvider());
|
|
1793
|
+
});
|
|
1794
|
+
}, [sessionId, modelService]);
|
|
1795
|
+
const [resource, retry] = useAsyncResource((signal) => fetchQuotaPayload(sessionId, chipProvider, signal), [sessionId, chipProvider], {
|
|
1721
1796
|
silentAfterFirst: true,
|
|
1722
1797
|
retryToken: 0
|
|
1723
1798
|
});
|
|
1724
|
-
const
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1799
|
+
const payload = resource.status === "ready" ? resource.value : null;
|
|
1800
|
+
const panelWidth = panelWidthOf(payload);
|
|
1801
|
+
const pollMs = (payload?.intervalSec ?? DEFAULT_POLL_SEC) * 1e3;
|
|
1802
|
+
(0, react.useEffect)(() => {
|
|
1803
|
+
const timer = setInterval(retry, pollMs);
|
|
1804
|
+
return () => {
|
|
1805
|
+
clearInterval(timer);
|
|
1806
|
+
};
|
|
1807
|
+
}, [pollMs, retry]);
|
|
1808
|
+
const visible = payload !== null && (payload.status === "ok" || payload.status === "error");
|
|
1809
|
+
(0, react.useEffect)(() => {
|
|
1810
|
+
if (!visible && open) setOpen(false);
|
|
1811
|
+
}, [visible, open]);
|
|
1812
|
+
(0, react.useEffect)(() => {
|
|
1813
|
+
if (!open) return;
|
|
1814
|
+
const onPointerDown = (event) => {
|
|
1815
|
+
if (event.target instanceof Node && rootRef.current?.contains(event.target) === true) return;
|
|
1816
|
+
setOpen(false);
|
|
1817
|
+
};
|
|
1818
|
+
const onKeyDown = (event) => {
|
|
1819
|
+
if (event.key === "Escape") setOpen(false);
|
|
1820
|
+
};
|
|
1821
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
1822
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1823
|
+
return () => {
|
|
1824
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
1825
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1826
|
+
};
|
|
1827
|
+
}, [open]);
|
|
1828
|
+
(0, react.useEffect)(() => {
|
|
1829
|
+
if (!open) return;
|
|
1830
|
+
const onViewportChange = () => {
|
|
1831
|
+
measurePanelLeft(panelWidth);
|
|
1832
|
+
};
|
|
1833
|
+
measurePanelLeft(panelWidth);
|
|
1834
|
+
window.addEventListener("resize", onViewportChange);
|
|
1835
|
+
window.addEventListener("scroll", onViewportChange, true);
|
|
1836
|
+
return () => {
|
|
1837
|
+
window.removeEventListener("resize", onViewportChange);
|
|
1838
|
+
window.removeEventListener("scroll", onViewportChange, true);
|
|
1839
|
+
};
|
|
1840
|
+
}, [
|
|
1841
|
+
open,
|
|
1842
|
+
panelWidth,
|
|
1843
|
+
measurePanelLeft
|
|
1844
|
+
]);
|
|
1845
|
+
if (!visible || payload === null) return null;
|
|
1846
|
+
const finest = finestQuotaWindow(payload.status === "ok" ? payload.windows : []);
|
|
1847
|
+
const severity = finest === void 0 ? "ok" : quotaSeverityOf(finest);
|
|
1848
|
+
const triggerClass = [QuotaButton_module_css_default.trigger];
|
|
1849
|
+
if (severity === "warn") triggerClass.push(QuotaButton_module_css_default["icon-warn"]);
|
|
1850
|
+
else if (severity === "exhausted") triggerClass.push(QuotaButton_module_css_default["icon-exhausted"]);
|
|
1851
|
+
else if (finest !== void 0 && quotaRemainingPercent(finest) !== void 0) triggerClass.push(QuotaButton_module_css_default["icon-ok"]);
|
|
1852
|
+
const triggerClassName = triggerClass.join(" ").trim();
|
|
1853
|
+
const figure = quotaTriggerFigure(finest);
|
|
1854
|
+
const triggerTip = figure === void 0 ? t("quota.trigger") : t("quota.triggerSummary", {
|
|
1855
|
+
name: payload.providerName ?? payload.provider,
|
|
1856
|
+
figure
|
|
1857
|
+
});
|
|
1858
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1859
|
+
ref: rootRef,
|
|
1860
|
+
className: QuotaButton_module_css_default.root,
|
|
1861
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
|
|
1862
|
+
label: triggerTip,
|
|
1863
|
+
side: "top",
|
|
1864
|
+
delayMs: 200,
|
|
1865
|
+
disabled: open,
|
|
1866
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1867
|
+
type: "button",
|
|
1868
|
+
className: triggerClassName,
|
|
1869
|
+
"aria-haspopup": "dialog",
|
|
1870
|
+
"aria-expanded": open,
|
|
1871
|
+
"aria-label": t("quota.trigger"),
|
|
1872
|
+
onClick: () => {
|
|
1873
|
+
if (!open) {
|
|
1874
|
+
retry();
|
|
1875
|
+
measurePanelLeft(panelWidth);
|
|
1876
|
+
}
|
|
1877
|
+
setOpen(!open);
|
|
1878
|
+
},
|
|
1879
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaGlyph, { share: quotaIconFillShare(finest) })
|
|
1880
|
+
})
|
|
1881
|
+
}), open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1882
|
+
className: QuotaButton_module_css_default.panel,
|
|
1883
|
+
role: "dialog",
|
|
1884
|
+
"aria-label": t("quota.panel"),
|
|
1885
|
+
style: {
|
|
1886
|
+
width: `${String(panelWidth)}px`,
|
|
1887
|
+
...panelLeft === void 0 ? {} : { left: `${String(panelLeft)}px` }
|
|
1888
|
+
},
|
|
1889
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1890
|
+
className: QuotaButton_module_css_default.header,
|
|
1891
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1892
|
+
className: QuotaButton_module_css_default.title,
|
|
1893
|
+
children: [payload.providerName ?? payload.provider, payload.status === "ok" && payload.planTier !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1894
|
+
className: QuotaButton_module_css_default.plan,
|
|
1895
|
+
children: [" · ", payload.planTier]
|
|
1896
|
+
}) : null]
|
|
1897
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1898
|
+
className: QuotaButton_module_css_default.updated,
|
|
1899
|
+
children: t("quota.updatedAt", { time: formatQuotaClock(payload.fetchedAt) })
|
|
1900
|
+
})]
|
|
1901
|
+
}), payload.status === "error" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1902
|
+
className: QuotaButton_module_css_default.error,
|
|
1903
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1904
|
+
className: QuotaButton_module_css_default.errorText,
|
|
1905
|
+
children: errorText(payload.error, t)
|
|
1906
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1907
|
+
type: "button",
|
|
1908
|
+
className: QuotaButton_module_css_default.retry,
|
|
1909
|
+
onClick: retry,
|
|
1910
|
+
children: t("quota.retry")
|
|
1911
|
+
})]
|
|
1912
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1913
|
+
className: QuotaButton_module_css_default.grid,
|
|
1914
|
+
style: { "--cols": String(Math.min(payload.windows.length, 3)) },
|
|
1915
|
+
children: payload.windows.map((window, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaColumn, {
|
|
1916
|
+
window,
|
|
1917
|
+
t
|
|
1918
|
+
}, `${window.tier}:${String(index)}`))
|
|
1919
|
+
})]
|
|
1920
|
+
})]
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
/** Ring geometry matches ContextMeter: 14px viewBox, r 5.5, 2px stroke.
|
|
1924
|
+
* Circumference feeds the remaining-share dasharray, starting at 12
|
|
1925
|
+
* o'clock. A 0 share omits the fill stroke — a round cap at 0 would still
|
|
1926
|
+
* paint a dot. */
|
|
1927
|
+
const RING_R = 5.5;
|
|
1928
|
+
const RING_C = 2 * Math.PI * RING_R;
|
|
1929
|
+
/** Round caps paint half a stroke width beyond each dash end; their
|
|
1930
|
+
* combined reach is what the dash compensation subtracts, so the painted
|
|
1931
|
+
* arc (dash + caps) equals the nominal share and the caps cannot seal the
|
|
1932
|
+
* 12-o'clock gap. */
|
|
1933
|
+
const RING_CAP_REACH = 2;
|
|
1934
|
+
/** The trigger glyph: a ContextMeter-family donut whose fill arc is the
|
|
1935
|
+
* remaining share of the finest window. Color comes from the button's
|
|
1936
|
+
* severity class (`currentColor`); this only draws the arc. */
|
|
1937
|
+
function QuotaGlyph({ share }) {
|
|
1938
|
+
const clamped = Math.min(1, Math.max(0, share));
|
|
1939
|
+
const nominal = clamped * RING_C;
|
|
1940
|
+
const dashLen = clamped >= 1 ? RING_C : nominal <= RING_CAP_REACH ? nominal : nominal - RING_CAP_REACH;
|
|
1941
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
1942
|
+
viewBox: "0 0 14 14",
|
|
1943
|
+
width: "14",
|
|
1944
|
+
height: "14",
|
|
1945
|
+
"aria-hidden": "true",
|
|
1946
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1947
|
+
cx: "7",
|
|
1948
|
+
cy: "7",
|
|
1949
|
+
r: RING_R,
|
|
1950
|
+
fill: "none",
|
|
1951
|
+
stroke: "currentColor",
|
|
1952
|
+
strokeWidth: "2",
|
|
1953
|
+
opacity: "0.22"
|
|
1954
|
+
}), clamped > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1955
|
+
cx: "7",
|
|
1956
|
+
cy: "7",
|
|
1957
|
+
r: RING_R,
|
|
1958
|
+
fill: "none",
|
|
1959
|
+
stroke: "currentColor",
|
|
1960
|
+
strokeWidth: "2",
|
|
1961
|
+
strokeLinecap: clamped < 1 ? "round" : "butt",
|
|
1962
|
+
strokeDasharray: `${dashLen.toFixed(3)} ${RING_C.toFixed(3)}`,
|
|
1963
|
+
transform: "rotate(-90 7 7)"
|
|
1964
|
+
}) : null]
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
/** One progress column: label / value / bar / aux. The value and the bar
|
|
1968
|
+
* both carry the REMAINING share (the traffic-light standard reads what is
|
|
1969
|
+
* left), colored by severity. */
|
|
1970
|
+
function QuotaColumn({ window, t }) {
|
|
1971
|
+
const remaining = quotaRemainingPercent(window);
|
|
1972
|
+
const severity = quotaSeverityOf(window);
|
|
1973
|
+
const label = t(TIER_LABEL_KEYS[window.tier]);
|
|
1974
|
+
let value;
|
|
1975
|
+
let meta;
|
|
1976
|
+
if (window.tier === "balance" && window.remainingValue !== void 0) {
|
|
1977
|
+
const unit = window.unit ?? "cny";
|
|
1978
|
+
value = formatQuotaMoney(window.remainingValue, unit);
|
|
1979
|
+
if (window.maxValue !== void 0) meta = `/ ${formatQuotaMoney(window.maxValue, unit)}`;
|
|
1980
|
+
} else value = remaining !== void 0 ? formatQuotaPercent(remaining) : "—";
|
|
1981
|
+
const aux = window.resetAt !== void 0 ? t("quota.resetIn", { time: formatResetCountdown(window.resetAt, Date.now()) }) : void 0;
|
|
1741
1982
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1742
|
-
|
|
1743
|
-
className: `${SessionStatsChip_module_css_default["strip"]}${flyOverflow ? ` ${SessionStatsChip_module_css_default["stripFlyOverflow"]}` : ""}`,
|
|
1744
|
-
role: "group",
|
|
1745
|
-
"aria-label": t("view.usage"),
|
|
1983
|
+
className: QuotaButton_module_css_default.col,
|
|
1746
1984
|
children: [
|
|
1747
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("
|
|
1748
|
-
className:
|
|
1749
|
-
|
|
1750
|
-
children: tokensText
|
|
1985
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1986
|
+
className: QuotaButton_module_css_default.label,
|
|
1987
|
+
children: label
|
|
1751
1988
|
}),
|
|
1752
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1753
|
-
className:
|
|
1754
|
-
|
|
1755
|
-
|
|
1989
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1990
|
+
className: QuotaButton_module_css_default.value,
|
|
1991
|
+
children: [value, meta !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1992
|
+
className: QuotaButton_module_css_default.meta,
|
|
1993
|
+
children: [" ", meta]
|
|
1994
|
+
}) : null]
|
|
1756
1995
|
}),
|
|
1757
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1758
|
-
className:
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
children: flies.map((fly) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostDeltaFlyLabel, {
|
|
1768
|
-
text: fly.text,
|
|
1769
|
-
vars: fly.vars
|
|
1770
|
-
}, fly.id))
|
|
1771
|
-
})]
|
|
1996
|
+
remaining !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1997
|
+
className: QuotaButton_module_css_default.bar,
|
|
1998
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1999
|
+
className: `${QuotaButton_module_css_default.fill} ${QuotaButton_module_css_default[severity]}`,
|
|
2000
|
+
style: { width: `${String(Math.round(remaining))}%` }
|
|
2001
|
+
})
|
|
2002
|
+
}),
|
|
2003
|
+
aux !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2004
|
+
className: QuotaButton_module_css_default.aux,
|
|
2005
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: `${QuotaButton_module_css_default.dot} ${QuotaButton_module_css_default[severity]}` }), aux]
|
|
1772
2006
|
})
|
|
1773
2007
|
]
|
|
1774
2008
|
});
|
|
1775
2009
|
}
|
|
1776
|
-
/**
|
|
1777
|
-
*
|
|
1778
|
-
|
|
1779
|
-
|
|
2010
|
+
/** The panel's width tier for one payload: what the windows PAINT decides —
|
|
2011
|
+
* a lone amount (no computable bar, the DeepSeek shape) reads at the
|
|
2012
|
+
* minimal plate, one bar (a weekly-only plan, or a balance with a spend
|
|
2013
|
+
* total like OpenRouter) the middle one, two or more bars the full plate.
|
|
2014
|
+
* Errors and payloads without windows read the full plate (their copy
|
|
2015
|
+
* runs long). */
|
|
2016
|
+
function panelWidthOf(payload) {
|
|
2017
|
+
if (payload === null || payload.status !== "ok") return PANEL_WIDTH_FULL;
|
|
2018
|
+
const bars = payload.windows.filter((window) => quotaUsedPercent(window) !== void 0).length;
|
|
2019
|
+
if (bars === 0) return payload.windows.length > 0 ? PANEL_WIDTH_BALANCE : PANEL_WIDTH_FULL;
|
|
2020
|
+
return bars === 1 ? PANEL_WIDTH_SINGLE : PANEL_WIDTH_FULL;
|
|
2021
|
+
}
|
|
2022
|
+
/** Friendly locale copy for one normalized query error. */
|
|
2023
|
+
function errorText(error, t) {
|
|
2024
|
+
switch (error.kind) {
|
|
2025
|
+
case "auth": return t("quota.error.auth", { message: error.message });
|
|
2026
|
+
case "no-credential": return t("quota.error.noCredential", { ref: error.message });
|
|
2027
|
+
case "http": return t("quota.error.http", { message: error.message });
|
|
2028
|
+
case "network": return t("quota.error.network", { message: error.message });
|
|
2029
|
+
case "parse": return t("quota.error.parse", { message: error.message });
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
/** Defensive shape check: a misrouted response must not paint the button. */
|
|
2033
|
+
function looksLikeQuotaPayload(value) {
|
|
2034
|
+
return typeof value === "object" && value !== null && typeof value.status === "string" && typeof value.intervalSec === "number";
|
|
1780
2035
|
}
|
|
1781
2036
|
/**
|
|
1782
|
-
* Fetch the
|
|
1783
|
-
*
|
|
1784
|
-
*
|
|
1785
|
-
*
|
|
1786
|
-
* hook's `silentAfterFirst` flag is what suppresses the resulting error
|
|
1787
|
-
* state.
|
|
1788
|
-
* @param sessionIds - the active session plus its subagent descendants;
|
|
1789
|
-
* an empty list skips the fetch (returning null rather than throwing, so
|
|
1790
|
-
* the hook's first-load gate stays at "loading").
|
|
1791
|
-
* @param signal - the cancellation signal from the hook.
|
|
2037
|
+
* Fetch the quota payload for the active session, naming the chip-selected
|
|
2038
|
+
* provider when one is known. Throws on transport failure or a payload that
|
|
2039
|
+
* does not look like one, so the hook can keep the previous render
|
|
2040
|
+
* (silentAfterFirst) or stay hidden (first failure).
|
|
1792
2041
|
*/
|
|
1793
|
-
async function
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
2042
|
+
async function fetchQuotaPayload(sessionId, provider, signal) {
|
|
2043
|
+
const params = new URLSearchParams();
|
|
2044
|
+
if (sessionId !== "") params.set("session", sessionId);
|
|
2045
|
+
if (provider !== void 0 && provider !== "") params.set("provider", provider);
|
|
2046
|
+
const encoded = params.toString();
|
|
2047
|
+
const query = encoded === "" ? "" : `?${encoded}`;
|
|
2048
|
+
const response = await fetch(QUOTA_PATH + query, {
|
|
1799
2049
|
headers: { accept: "application/json" },
|
|
1800
2050
|
signal
|
|
1801
2051
|
});
|
|
1802
2052
|
if (!response.ok) throw new Error(`HTTP ${String(response.status)}`);
|
|
1803
2053
|
const value = await response.json();
|
|
1804
|
-
if (!
|
|
2054
|
+
if (!looksLikeQuotaPayload(value)) throw new Error("unexpected quota response");
|
|
1805
2055
|
return value;
|
|
1806
2056
|
}
|
|
1807
2057
|
//#endregion
|
|
1808
2058
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\TokenUsageCard.module.css.mjs
|
|
1809
|
-
const css$
|
|
1810
|
-
const tagId$
|
|
1811
|
-
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$
|
|
2059
|
+
const css$10 = "._1bMeTa_card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}._1bMeTa_card:hover{border-color:var(--dsw-alias-label-dimmed)}._1bMeTa_cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}._1bMeTa_header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}._1bMeTa_header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}._1bMeTa_headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}._1bMeTa_name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}._1bMeTa_description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}._1bMeTa_pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}._1bMeTa_chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}._1bMeTa_chevronOpen{transform:rotate(180deg)}._1bMeTa_body{border-top:1px solid var(--dsw-alias-border-l2);flex-direction:column;gap:10px;margin:0 16px;padding:12px 0 8px;display:flex}._1bMeTa_note{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}._1bMeTa_field{flex-direction:column;gap:4px;display:flex}._1bMeTa_fieldLabel{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.5}._1bMeTa_input{box-sizing:border-box;width:100%;font:inherit;color:var(--dsw-alias-label-primary);background-color:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);appearance:none;border-radius:6px;padding:4px 8px;font-size:13px;line-height:20px}._1bMeTa_input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-1px}._1bMeTa_input:disabled{opacity:.6}._1bMeTa_inputRow{align-items:center;gap:6px;display:flex}._1bMeTa_inputRow ._1bMeTa_input{flex:1;min-width:0}._1bMeTa_browse{appearance:none;border:1px solid var(--dsw-alias-border-l2);font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;white-space:nowrap;background:0 0;border-radius:6px;flex:none;padding:4px 10px;font-size:13px;line-height:20px}._1bMeTa_browse:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}._1bMeTa_browse:disabled{opacity:.4;cursor:default}._1bMeTa_browse:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}._1bMeTa_hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}._1bMeTa_migration{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);border-radius:6px;flex-direction:column;gap:4px;padding:8px 10px;display:flex}._1bMeTa_migrationLabel{color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;font-size:12px;line-height:1.5}._1bMeTa_migrationBar{background:var(--dsw-alias-bg-multi-select);border-radius:2px;height:4px;display:block;overflow:hidden}._1bMeTa_migrationFill{background:var(--dsw-alias-brand-primary);border-radius:2px;height:100%;transition:width .2s;display:block}._1bMeTa_footer{border-top:1px solid var(--dsw-alias-border-l2);justify-content:flex-end;align-items:center;gap:8px;padding:8px 0 4px;display:flex}._1bMeTa_failed{min-width:0;color:var(--dsw-alias-label-error);flex:1;margin:0;font-size:12px;line-height:1.5}._1bMeTa_discard,._1bMeTa_save{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}._1bMeTa_discard{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}._1bMeTa_discard:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}._1bMeTa_save{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}._1bMeTa_discard:disabled,._1bMeTa_save:disabled{opacity:.4;cursor:default}._1bMeTa_discard:focus-visible,._1bMeTa_save:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}._1bMeTa_fullSync{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);border-radius:8px;flex-direction:column;gap:8px;padding:10px 12px;display:flex}._1bMeTa_fullSyncHeader{flex-direction:column;gap:2px;display:flex}._1bMeTa_fullSyncTitle{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:600;line-height:1.4}._1bMeTa_fullSyncHint{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:1.5}._1bMeTa_fullSyncButton{appearance:none;border:1px solid var(--dsw-alias-border-l2);font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;white-space:nowrap;background:0 0;border-radius:6px;align-self:flex-start;padding:4px 12px;font-size:13px;line-height:20px}._1bMeTa_fullSyncButton:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}._1bMeTa_fullSyncButton:disabled{opacity:.5;cursor:default}._1bMeTa_fullSyncButton:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}._1bMeTa_fullSyncProgress{flex-direction:column;gap:4px;display:flex}._1bMeTa_fullSyncProgressLabel{color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;font-size:12px;line-height:1.5}._1bMeTa_fullSyncBar{background:var(--dsw-alias-bg-multi-select);border-radius:2px;height:4px;display:block;overflow:hidden}._1bMeTa_fullSyncFill{background:var(--dsw-alias-brand-primary);border-radius:2px;height:100%;transition:width .2s;display:block}._1bMeTa_fullSyncResult{color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;margin:0;font-size:12px;line-height:1.5}._1bMeTa_fullSyncError{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}";
|
|
2060
|
+
const tagId$10 = "@laoyuehanni/dsh-token-usage/TokenUsageCard.module.css";
|
|
2061
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$10) + "]") === null) {
|
|
1812
2062
|
const tag = document.createElement("style");
|
|
1813
2063
|
tag.dataset.plugin = "@laoyuehanni/dsh-token-usage";
|
|
1814
|
-
tag.dataset.pluginCss = tagId$
|
|
1815
|
-
tag.textContent = css$
|
|
2064
|
+
tag.dataset.pluginCss = tagId$10;
|
|
2065
|
+
tag.textContent = css$10;
|
|
1816
2066
|
document.head.appendChild(tag);
|
|
1817
2067
|
}
|
|
1818
2068
|
var TokenUsageCard_module_css_default = {
|
|
@@ -1878,11 +2128,20 @@ window.__ModuleLoader__.load({
|
|
|
1878
2128
|
* @returns the card, or nothing when the namespace is unavailable.
|
|
1879
2129
|
*/
|
|
1880
2130
|
function TokenUsageCard(props) {
|
|
1881
|
-
const [open, setOpen] = (0, react.useState)(
|
|
2131
|
+
const [open, setOpen] = (0, react.useState)(props.view === "page");
|
|
1882
2132
|
const [picking, setPicking] = (0, react.useState)(false);
|
|
1883
2133
|
const { t } = props;
|
|
1884
2134
|
const state = props.useTokenUsageCard((snapshot) => snapshot);
|
|
2135
|
+
const discardRef = (0, react.useRef)(props.discard);
|
|
2136
|
+
discardRef.current = props.discard;
|
|
2137
|
+
(0, react.useEffect)(() => () => {
|
|
2138
|
+
discardRef.current();
|
|
2139
|
+
}, []);
|
|
1885
2140
|
if (!state.available) return null;
|
|
2141
|
+
if (props.view === "summary") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2142
|
+
className: TokenUsageCard_module_css_default.description,
|
|
2143
|
+
children: t("card.description")
|
|
2144
|
+
});
|
|
1886
2145
|
const migrating = state.migration !== void 0;
|
|
1887
2146
|
const lockInput = !state.writable || migrating;
|
|
1888
2147
|
const lockActions = !state.dirty || state.saving || migrating;
|
|
@@ -2004,7 +2263,7 @@ window.__ModuleLoader__.load({
|
|
|
2004
2263
|
className: TokenUsageCard_module_css_default.pending,
|
|
2005
2264
|
children: t("card.unsaved")
|
|
2006
2265
|
}) : null,
|
|
2007
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.
|
|
2266
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineMedium, { className: open ? `${TokenUsageCard_module_css_default.chevron} ${TokenUsageCard_module_css_default.chevronOpen}` : TokenUsageCard_module_css_default.chevron })
|
|
2008
2267
|
]
|
|
2009
2268
|
}), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2010
2269
|
className: TokenUsageCard_module_css_default.body,
|
|
@@ -2183,13 +2442,13 @@ window.__ModuleLoader__.load({
|
|
|
2183
2442
|
}
|
|
2184
2443
|
//#endregion
|
|
2185
2444
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\DateRangePicker.module.css.mjs
|
|
2186
|
-
const css$
|
|
2187
|
-
const tagId$
|
|
2188
|
-
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$
|
|
2445
|
+
const css$9 = ".aSiNOq_wrapper{flex:none;display:inline-flex;position:relative}.aSiNOq_trigger{box-sizing:border-box;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary);background-color:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;white-space:nowrap;border-radius:6px;flex:none;padding:4px 10px;font-size:13px;line-height:20px}.aSiNOq_trigger:hover,.aSiNOq_trigger[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover)}.aSiNOq_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);width:266px;max-width:calc(100vw - 32px);box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-secondary);text-align:left;cursor:default;border-radius:12px;padding:10px;font-size:12px;line-height:20px;position:absolute;top:calc(100% + 6px);left:0}.aSiNOq_head{justify-content:space-between;align-items:center;gap:4px;margin-bottom:6px;display:flex}.aSiNOq_nav{width:24px;height:24px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:6px;flex:none;padding:0;font-size:14px;line-height:1}.aSiNOq_nav:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}.aSiNOq_monthTitle{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;font-size:13px;font-weight:500}.aSiNOq_weekdays,.aSiNOq_grid{grid-template-columns:repeat(7,1fr);gap:2px;display:grid}.aSiNOq_weekday{text-align:center;color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px}.aSiNOq_blank{visibility:hidden;height:26px}.aSiNOq_day{font-variant-numeric:tabular-nums;text-align:center;height:26px;color:var(--dsw-alias-label-primary);cursor:pointer;background:0 0;border:none;border-radius:6px;padding:0;font-size:12px;line-height:26px}.aSiNOq_day:hover{background:var(--dsw-alias-interactive-bg-hover)}.aSiNOq_dayToday{box-shadow:inset 0 0 0 1px var(--dsw-alias-border-l2)}.aSiNOq_dayAnchor,.aSiNOq_daySelected{color:var(--dsw-alias-brand-primary);box-shadow:inset 0 0 0 1px var(--dsw-alias-brand-primary);font-weight:600}.aSiNOq_dayInRange{background:var(--dsw-alias-interactive-bg-hover);border-radius:0}.aSiNOq_foot{border-top:1px solid var(--dsw-alias-border-l1);justify-content:flex-end;margin-top:8px;padding-top:8px;display:flex}.aSiNOq_clear{color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:6px;padding:2px 8px;font-size:12px;line-height:18px}.aSiNOq_clear:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}";
|
|
2446
|
+
const tagId$9 = "@laoyuehanni/dsh-token-usage/DateRangePicker.module.css";
|
|
2447
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$9) + "]") === null) {
|
|
2189
2448
|
const tag = document.createElement("style");
|
|
2190
2449
|
tag.dataset.plugin = "@laoyuehanni/dsh-token-usage";
|
|
2191
|
-
tag.dataset.pluginCss = tagId$
|
|
2192
|
-
tag.textContent = css$
|
|
2450
|
+
tag.dataset.pluginCss = tagId$9;
|
|
2451
|
+
tag.textContent = css$9;
|
|
2193
2452
|
document.head.appendChild(tag);
|
|
2194
2453
|
}
|
|
2195
2454
|
var DateRangePicker_module_css_default = {
|
|
@@ -2412,8 +2671,42 @@ window.__ModuleLoader__.load({
|
|
|
2412
2671
|
});
|
|
2413
2672
|
}
|
|
2414
2673
|
//#endregion
|
|
2674
|
+
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\hit-rate-band.module.css.mjs
|
|
2675
|
+
const css$8 = ".t6JM8a_band_critical{color:var(--dsw-alias-state-error-primary,#dc2626)}.t6JM8a_band_amber{color:#f59e0b}.t6JM8a_band_lime{color:#84cc16}.t6JM8a_band_healthy{color:var(--dsw-alias-state-success-primary,#16a34a)}";
|
|
2676
|
+
const tagId$8 = "@laoyuehanni/dsh-token-usage/hit-rate-band.module.css";
|
|
2677
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$8) + "]") === null) {
|
|
2678
|
+
const tag = document.createElement("style");
|
|
2679
|
+
tag.dataset.plugin = "@laoyuehanni/dsh-token-usage";
|
|
2680
|
+
tag.dataset.pluginCss = tagId$8;
|
|
2681
|
+
tag.textContent = css$8;
|
|
2682
|
+
document.head.appendChild(tag);
|
|
2683
|
+
}
|
|
2684
|
+
var hit_rate_band_module_css_default = {
|
|
2685
|
+
"band_amber": "t6JM8a_band_amber",
|
|
2686
|
+
"band_critical": "t6JM8a_band_critical",
|
|
2687
|
+
"band_healthy": "t6JM8a_band_healthy",
|
|
2688
|
+
"band_lime": "t6JM8a_band_lime"
|
|
2689
|
+
};
|
|
2690
|
+
//#endregion
|
|
2691
|
+
//#region src/client/HitRateText.tsx
|
|
2692
|
+
/** CSS-module class for one hit-rate colour bucket. */
|
|
2693
|
+
function bandClassOf(band) {
|
|
2694
|
+
return hit_rate_band_module_css_default[`band_${band}`] ?? "";
|
|
2695
|
+
}
|
|
2696
|
+
/**
|
|
2697
|
+
* Render a hit-rate percentage (or `—`) in its threshold colour.
|
|
2698
|
+
* @param totals - the aggregated token buckets the rate is computed from.
|
|
2699
|
+
*/
|
|
2700
|
+
function HitRateText({ totals }) {
|
|
2701
|
+
const { text, band } = hitRateDisplay(totals);
|
|
2702
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2703
|
+
className: bandClassOf(band),
|
|
2704
|
+
children: text
|
|
2705
|
+
});
|
|
2706
|
+
}
|
|
2707
|
+
//#endregion
|
|
2415
2708
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\MenuSelect.module.css.mjs
|
|
2416
|
-
const css$7 = ".KUIXpG_wrapper{display:inline-flex;position:relative}.KUIXpG_trigger{box-sizing:border-box;color:var(--dsw-alias-label-primary);background-color:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;white-space:nowrap;text-overflow:ellipsis;background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2381858C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E/%3C/svg%3E\");background-position:right 6px center;background-repeat:no-repeat;background-size:12px 12px;border-radius:6px;flex:none;padding:4px 24px 4px 8px;font-size:13px;line-height:20px;overflow:hidden}.KUIXpG_trigger:hover,.KUIXpG_trigger[aria-expanded=true]{background-color:var(--dsw-alias-interactive-bg-hover)}.KUIXpG_grow{flex:0 auto;min-width:0;max-width:220px}.KUIXpG_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-
|
|
2709
|
+
const css$7 = ".KUIXpG_wrapper{display:inline-flex;position:relative}.KUIXpG_trigger{box-sizing:border-box;color:var(--dsw-alias-label-primary);background-color:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;white-space:nowrap;text-overflow:ellipsis;background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2381858C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E/%3C/svg%3E\");background-position:right 6px center;background-repeat:no-repeat;background-size:12px 12px;border-radius:6px;flex:none;padding:4px 24px 4px 8px;font-size:13px;line-height:20px;overflow:hidden}.KUIXpG_trigger:hover,.KUIXpG_trigger[aria-expanded=true]{background-color:var(--dsw-alias-interactive-bg-hover)}.KUIXpG_grow{flex:0 auto;min-width:0;max-width:220px}.KUIXpG_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);min-width:100%;max-width:260px;max-height:240px;box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-secondary);text-align:left;cursor:default;border-radius:12px;padding:6px;font-size:13px;line-height:20px;position:absolute;top:calc(100% + 6px);left:0;overflow-y:auto}.KUIXpG_option{width:100%;color:var(--dsw-alias-label-primary);cursor:pointer;white-space:nowrap;background:0 0;border:none;border-radius:6px;justify-content:space-between;align-items:center;gap:12px;padding:4px 8px;font-size:13px;line-height:20px;display:flex}.KUIXpG_option:hover{background:var(--dsw-alias-interactive-bg-hover)}.KUIXpG_optionLabel{text-overflow:ellipsis;overflow:hidden}.KUIXpG_optionSelected{color:var(--dsw-alias-brand-primary)}.KUIXpG_check{color:var(--dsw-alias-brand-primary);flex:none}";
|
|
2417
2710
|
const tagId$7 = "@laoyuehanni/dsh-token-usage/MenuSelect.module.css";
|
|
2418
2711
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$7) + "]") === null) {
|
|
2419
2712
|
const tag = document.createElement("style");
|
|
@@ -3596,7 +3889,7 @@ window.__ModuleLoader__.load({
|
|
|
3596
3889
|
}
|
|
3597
3890
|
//#endregion
|
|
3598
3891
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\SessionTable.module.css.mjs
|
|
3599
|
-
const css$3 = ".DW1kVq_head{justify-content:flex-start;align-items:center;gap:8px;display:flex}.DW1kVq_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}.DW1kVq_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}.DW1kVq_segBtn:hover:not(.DW1kVq_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}.DW1kVq_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}.DW1kVq_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}.DW1kVq_tableWrap{max-height:420px;overflow:auto}.DW1kVq_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}.DW1kVq_table th,.DW1kVq_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}.DW1kVq_table th.DW1kVq_sessionHead,.DW1kVq_table td.DW1kVq_sessionCol{text-align:left;width:220px;max-width:220px}.DW1kVq_table td.DW1kVq_sessionIndent{padding-left:18px}.DW1kVq_table th{color:var(--dsw-alias-label-secondary);z-index:1;background:var(--dsw-alias-bg-layer-2);font-weight:
|
|
3892
|
+
const css$3 = ".DW1kVq_head{justify-content:flex-start;align-items:center;gap:8px;display:flex}.DW1kVq_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}.DW1kVq_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}.DW1kVq_segBtn:hover:not(.DW1kVq_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}.DW1kVq_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}.DW1kVq_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}.DW1kVq_tableWrap{max-height:420px;overflow:auto}.DW1kVq_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}.DW1kVq_table th,.DW1kVq_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}.DW1kVq_table th.DW1kVq_sessionHead,.DW1kVq_table td.DW1kVq_sessionCol{text-align:left;width:220px;max-width:220px}.DW1kVq_table td.DW1kVq_sessionIndent{padding-left:18px}.DW1kVq_table th{color:var(--dsw-alias-label-secondary);z-index:1;background:var(--dsw-alias-bg-layer-2);border-bottom:1.5px solid var(--dsw-alias-border-l2);font-weight:600;position:sticky;top:0}.DW1kVq_table tbody tr{transition:background-color .12s}.DW1kVq_table tbody tr:hover{background-color:var(--dsw-interactive-bg-hover)}.DW1kVq_costCol{font-weight:600}.DW1kVq_table td{color:var(--dsw-alias-label-primary)}.DW1kVq_sortBtn{font:inherit;color:inherit;cursor:pointer;white-space:nowrap;background:0 0;border:none;padding:0;font-weight:500}.DW1kVq_sortBtn:hover{color:var(--dsw-alias-label-primary)}.DW1kVq_sortMark{margin-left:3px;font-size:9px}.DW1kVq_sessionCell{align-items:baseline;gap:4px;max-width:208px;display:inline-flex}.DW1kVq_sessionName{text-overflow:ellipsis;white-space:nowrap;font:inherit;color:inherit;text-align:left;background:0 0;border:none;border-bottom:1.5px dashed #0000;max-width:100%;padding:0;overflow:hidden}.DW1kVq_jumpable{cursor:pointer;border-bottom-color:var(--dsw-alias-label-secondary);color:var(--dsw-alias-label-primary);text-decoration:none}.DW1kVq_jumpable:hover{border-bottom-color:var(--dsw-alias-label-primary)}.DW1kVq_badge{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;font-size:10px}.DW1kVq_dirTail{color:var(--dsw-alias-label-tertiary);text-overflow:ellipsis;font-size:10px;display:block;overflow:hidden}.DW1kVq_table td.DW1kVq_groupRow{border-bottom:none;padding-top:8px}.DW1kVq_table td.DW1kVq_groupHead{color:var(--dsw-alias-label-secondary);text-align:left;white-space:nowrap;font-size:11px;font-weight:600}.DW1kVq_groupCount{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;margin-left:6px}";
|
|
3600
3893
|
const tagId$3 = "@laoyuehanni/dsh-token-usage/SessionTable.module.css";
|
|
3601
3894
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$3) + "]") === null) {
|
|
3602
3895
|
const tag = document.createElement("style");
|
|
@@ -3607,6 +3900,7 @@ window.__ModuleLoader__.load({
|
|
|
3607
3900
|
}
|
|
3608
3901
|
var SessionTable_module_css_default = {
|
|
3609
3902
|
"badge": "DW1kVq_badge",
|
|
3903
|
+
"costCol": "DW1kVq_costCol",
|
|
3610
3904
|
"dirTail": "DW1kVq_dirTail",
|
|
3611
3905
|
"groupCount": "DW1kVq_groupCount",
|
|
3612
3906
|
"groupHead": "DW1kVq_groupHead",
|
|
@@ -3709,18 +4003,24 @@ window.__ModuleLoader__.load({
|
|
|
3709
4003
|
const [ctrlHeld, setCtrlHeld] = (0, react.useState)(false);
|
|
3710
4004
|
(0, react.useEffect)(() => {
|
|
3711
4005
|
const down = (event) => {
|
|
3712
|
-
if (event.key === "Control") setCtrlHeld(true);
|
|
4006
|
+
if (event.key === "Control" || event.key === "Meta") setCtrlHeld(true);
|
|
3713
4007
|
};
|
|
3714
4008
|
const up = (event) => {
|
|
3715
|
-
if (event.key === "Control") setCtrlHeld(false);
|
|
4009
|
+
if (event.key === "Control" || event.key === "Meta") setCtrlHeld(false);
|
|
4010
|
+
};
|
|
4011
|
+
const move = (event) => {
|
|
4012
|
+
const active = event.ctrlKey || event.metaKey;
|
|
4013
|
+
setCtrlHeld((previous) => previous === active ? previous : active);
|
|
3716
4014
|
};
|
|
3717
4015
|
const blur = () => setCtrlHeld(false);
|
|
3718
4016
|
window.addEventListener("keydown", down);
|
|
3719
4017
|
window.addEventListener("keyup", up);
|
|
4018
|
+
window.addEventListener("mousemove", move);
|
|
3720
4019
|
window.addEventListener("blur", blur);
|
|
3721
4020
|
return () => {
|
|
3722
4021
|
window.removeEventListener("keydown", down);
|
|
3723
4022
|
window.removeEventListener("keyup", up);
|
|
4023
|
+
window.removeEventListener("mousemove", move);
|
|
3724
4024
|
window.removeEventListener("blur", blur);
|
|
3725
4025
|
};
|
|
3726
4026
|
}, []);
|
|
@@ -3818,7 +4118,7 @@ window.__ModuleLoader__.load({
|
|
|
3818
4118
|
type: "button",
|
|
3819
4119
|
className: jump ? `${SessionTable_module_css_default["sessionName"]} ${SessionTable_module_css_default["jumpable"]}` : SessionTable_module_css_default["sessionName"],
|
|
3820
4120
|
title: jump ? t("session.openHint") : void 0,
|
|
3821
|
-
onClick: jump ? (event) => {
|
|
4121
|
+
onClick: jump || ctrlHeld ? (event) => {
|
|
3822
4122
|
event.preventDefault();
|
|
3823
4123
|
openSession?.(row.sessionId);
|
|
3824
4124
|
} : void 0,
|
|
@@ -3840,7 +4140,10 @@ window.__ModuleLoader__.load({
|
|
|
3840
4140
|
t
|
|
3841
4141
|
}) }),
|
|
3842
4142
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: formatTokens(totalTokens(row.totals)) }),
|
|
3843
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
4143
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
4144
|
+
className: SessionTable_module_css_default["costCol"],
|
|
4145
|
+
children: formatCost(row.cost, view)
|
|
4146
|
+
}),
|
|
3844
4147
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: dayKeyOf(new Date(row.lastTime)) })
|
|
3845
4148
|
] }, row.sessionId);
|
|
3846
4149
|
}
|
|
@@ -3910,32 +4213,141 @@ window.__ModuleLoader__.load({
|
|
|
3910
4213
|
return flags;
|
|
3911
4214
|
}
|
|
3912
4215
|
/**
|
|
3913
|
-
*
|
|
4216
|
+
* Generate a smooth cubic Bezier path using Fritsch-Carlson monotone cubic
|
|
4217
|
+
* Hermite interpolation. Preserves monotonicity so zero-filled plateaus stay
|
|
4218
|
+
* strictly flat at baseline without undershooting, and peaks round smoothly.
|
|
4219
|
+
*
|
|
4220
|
+
* @param xs - scaled x coordinates (monotonic ascending).
|
|
4221
|
+
* @param ys - scaled y coordinates.
|
|
4222
|
+
* @returns SVG `d` string containing M, L, and C commands.
|
|
4223
|
+
*/
|
|
4224
|
+
function monotoneSplinePath(xs, ys) {
|
|
4225
|
+
const n = xs.length;
|
|
4226
|
+
if (n === 0) return "";
|
|
4227
|
+
if (n === 1) return `M${xs[0].toFixed(1)},${ys[0].toFixed(1)}`;
|
|
4228
|
+
if (n === 2) return `M${xs[0].toFixed(1)},${ys[0].toFixed(1)} L${xs[1].toFixed(1)},${ys[1].toFixed(1)}`;
|
|
4229
|
+
const dx = [];
|
|
4230
|
+
const slopes = [];
|
|
4231
|
+
for (let i = 0; i < n - 1; i += 1) {
|
|
4232
|
+
const dX = xs[i + 1] - xs[i];
|
|
4233
|
+
const dY = ys[i + 1] - ys[i];
|
|
4234
|
+
dx.push(dX);
|
|
4235
|
+
slopes.push(dX === 0 ? 0 : dY / dX);
|
|
4236
|
+
}
|
|
4237
|
+
const m = new Array(n);
|
|
4238
|
+
m[0] = slopes[0];
|
|
4239
|
+
m[n - 1] = slopes[n - 2];
|
|
4240
|
+
for (let i = 1; i < n - 1; i += 1) {
|
|
4241
|
+
const s0 = slopes[i - 1];
|
|
4242
|
+
const s1 = slopes[i];
|
|
4243
|
+
if (s0 * s1 <= 0) m[i] = 0;
|
|
4244
|
+
else m[i] = (s0 + s1) / 2;
|
|
4245
|
+
}
|
|
4246
|
+
for (let i = 0; i < n - 1; i += 1) {
|
|
4247
|
+
const slope = slopes[i];
|
|
4248
|
+
if (slope === 0) {
|
|
4249
|
+
m[i] = 0;
|
|
4250
|
+
m[i + 1] = 0;
|
|
4251
|
+
} else {
|
|
4252
|
+
const alpha = m[i] / slope;
|
|
4253
|
+
const beta = m[i + 1] / slope;
|
|
4254
|
+
const dist = alpha * alpha + beta * beta;
|
|
4255
|
+
if (dist > 9) {
|
|
4256
|
+
const tau = 3 / Math.sqrt(dist);
|
|
4257
|
+
m[i] = tau * alpha * slope;
|
|
4258
|
+
m[i + 1] = tau * beta * slope;
|
|
4259
|
+
}
|
|
4260
|
+
}
|
|
4261
|
+
}
|
|
4262
|
+
const parts = [`M${xs[0].toFixed(1)},${ys[0].toFixed(1)}`];
|
|
4263
|
+
for (let i = 0; i < n - 1; i += 1) {
|
|
4264
|
+
const dX = dx[i];
|
|
4265
|
+
const x0 = xs[i];
|
|
4266
|
+
const y0 = ys[i];
|
|
4267
|
+
const x1 = xs[i + 1];
|
|
4268
|
+
const y1 = ys[i + 1];
|
|
4269
|
+
const cp1x = x0 + dX / 3;
|
|
4270
|
+
const cp1y = y0 + m[i] * (dX / 3);
|
|
4271
|
+
const cp2x = x1 - dX / 3;
|
|
4272
|
+
const cp2y = y1 - m[i + 1] * (dX / 3);
|
|
4273
|
+
parts.push(`C${cp1x.toFixed(1)},${cp1y.toFixed(1)} ${cp2x.toFixed(1)},${cp2y.toFixed(1)} ${x1.toFixed(1)},${y1.toFixed(1)}`);
|
|
4274
|
+
}
|
|
4275
|
+
return parts.join(" ");
|
|
4276
|
+
}
|
|
4277
|
+
/**
|
|
4278
|
+
* Close a line/curve path down to the baseline (`yZero`) to form an area polygon.
|
|
4279
|
+
* Returns an empty string when the input path is empty or has fewer than 2 points.
|
|
3914
4280
|
*
|
|
3915
|
-
*
|
|
3916
|
-
*
|
|
3917
|
-
*
|
|
3918
|
-
*
|
|
3919
|
-
|
|
4281
|
+
* @param linePath - the line or curve `d` string.
|
|
4282
|
+
* @param xs - the plotted x coordinates.
|
|
4283
|
+
* @param yZero - the baseline y coordinate.
|
|
4284
|
+
* @returns SVG `d` string closed with Z for fill.
|
|
4285
|
+
*/
|
|
4286
|
+
function areaPath(linePath, xs, yZero) {
|
|
4287
|
+
if (linePath === "" || xs.length < 2) return "";
|
|
4288
|
+
const firstX = xs[0].toFixed(1);
|
|
4289
|
+
const lastX = xs[xs.length - 1].toFixed(1);
|
|
4290
|
+
const baseY = yZero.toFixed(1);
|
|
4291
|
+
return `${linePath} L${lastX},${baseY} L${firstX},${baseY} Z`;
|
|
4292
|
+
}
|
|
4293
|
+
/**
|
|
4294
|
+
* Return coordinates with gap hold points inserted so temporal series can be
|
|
4295
|
+
* smoothly interpolated with monotonic cubic splines without smearing idle spans.
|
|
3920
4296
|
*/
|
|
3921
|
-
function
|
|
3922
|
-
const { xs, ys, yZero,
|
|
3923
|
-
if (xs.length === 0) return
|
|
3924
|
-
|
|
3925
|
-
|
|
4297
|
+
function gapPatchedPoints(input) {
|
|
4298
|
+
const { xs, ys, yZero, hold, gaps, xEnds } = input;
|
|
4299
|
+
if (xs.length === 0) return {
|
|
4300
|
+
xs: [],
|
|
4301
|
+
ys: []
|
|
4302
|
+
};
|
|
4303
|
+
const outXs = [xs[0]];
|
|
4304
|
+
const outYs = [ys[0]];
|
|
3926
4305
|
for (let index = 0; index < xs.length - 1; index += 1) {
|
|
3927
4306
|
const xNext = xs[index + 1];
|
|
3928
4307
|
const yNext = ys[index + 1];
|
|
3929
|
-
if (
|
|
4308
|
+
if (gaps?.[index] === true) {
|
|
3930
4309
|
const ends = xEnds ?? xs;
|
|
3931
4310
|
const xEnd = ends[index];
|
|
3932
4311
|
const nextWidth = Math.max(ends[index + 1] - xNext, 0);
|
|
3933
4312
|
const xHold = Math.max(xEnd, xNext - nextWidth);
|
|
3934
4313
|
const holdY = hold === "previous" ? ys[index] : yZero;
|
|
3935
|
-
|
|
3936
|
-
|
|
4314
|
+
if (xEnd > outXs[outXs.length - 1]) {
|
|
4315
|
+
outXs.push(xEnd);
|
|
4316
|
+
outYs.push(holdY);
|
|
4317
|
+
}
|
|
4318
|
+
if (xHold > xEnd) {
|
|
4319
|
+
outXs.push(xHold);
|
|
4320
|
+
outYs.push(holdY);
|
|
4321
|
+
}
|
|
4322
|
+
outXs.push(xNext);
|
|
4323
|
+
outYs.push(yNext);
|
|
4324
|
+
} else {
|
|
4325
|
+
outXs.push(xNext);
|
|
4326
|
+
outYs.push(yNext);
|
|
4327
|
+
}
|
|
3937
4328
|
}
|
|
3938
|
-
return
|
|
4329
|
+
return {
|
|
4330
|
+
xs: outXs,
|
|
4331
|
+
ys: outYs
|
|
4332
|
+
};
|
|
4333
|
+
}
|
|
4334
|
+
/**
|
|
4335
|
+
* Generate a smooth spline path for either equidistant or gap-patched temporal series.
|
|
4336
|
+
*/
|
|
4337
|
+
function smoothSeriesPath(input) {
|
|
4338
|
+
const { xs, ys, yZero, gaps, xEnds, hold } = input;
|
|
4339
|
+
if (gaps !== void 0 && gaps.some((g) => g)) {
|
|
4340
|
+
const patched = gapPatchedPoints({
|
|
4341
|
+
xs,
|
|
4342
|
+
ys,
|
|
4343
|
+
yZero,
|
|
4344
|
+
hold,
|
|
4345
|
+
gaps,
|
|
4346
|
+
xEnds
|
|
4347
|
+
});
|
|
4348
|
+
return monotoneSplinePath(patched.xs, patched.ys);
|
|
4349
|
+
}
|
|
4350
|
+
return monotoneSplinePath(xs, ys);
|
|
3939
4351
|
}
|
|
3940
4352
|
//#endregion
|
|
3941
4353
|
//#region src/trend-bucket.ts
|
|
@@ -4211,7 +4623,7 @@ window.__ModuleLoader__.load({
|
|
|
4211
4623
|
}
|
|
4212
4624
|
//#endregion
|
|
4213
4625
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\TrendChart.module.css.mjs
|
|
4214
|
-
const css$2 = ".DWJgoW_chart{width:100%;height:auto;display:block}.DWJgoW_axis{stroke:var(--dsw-alias-border-
|
|
4626
|
+
const css$2 = ".DWJgoW_chart{user-select:none;width:100%;height:auto;display:block}.DWJgoW_axis{stroke:var(--dsw-alias-border-l1);stroke-width:1px}.DWJgoW_grid{stroke:var(--dsw-alias-border-l2);stroke-width:1px;stroke-dasharray:4 4;stroke-opacity:.6}.DWJgoW_area{pointer-events:none}.DWJgoW_line{fill:none;stroke:var(--dsw-alias-label-primary);stroke-width:1.8px;stroke-linejoin:round;stroke-linecap:round}.DWJgoW_chartLight .DWJgoW_dotHalo,[style*=\"color-scheme: light\"] .DWJgoW_chart .DWJgoW_dotHalo{fill:color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent)}.DWJgoW_chartLight .DWJgoW_grid,[style*=\"color-scheme: light\"] .DWJgoW_chart .DWJgoW_grid{stroke-opacity:.45}@media (prefers-color-scheme:light){.DWJgoW_chart:not([data-theme=dark]) .DWJgoW_dotHalo{fill:color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent)}.DWJgoW_chart:not([data-theme=dark]) .DWJgoW_grid{stroke-opacity:.45}}.DWJgoW_dot{fill:var(--dsw-alias-label-primary)}.DWJgoW_dotHalo{fill:color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent)}.DWJgoW_dotActive{fill:var(--dsw-alias-label-primary);stroke:var(--dsw-alias-bg-layer-1);stroke-width:2px}.DWJgoW_guide{stroke:var(--dsw-alias-label-secondary);stroke-width:1px;stroke-dasharray:3 3;stroke-opacity:.45}.DWJgoW_hit{cursor:crosshair;outline:none}.DWJgoW_pointLabel rect{fill:var(--dsw-alias-bg-layer-3);stroke:var(--dsw-alias-border-l2);stroke-width:1px;filter:drop-shadow(0 3px 8px #00000047)}.DWJgoW_pointLabel text{fill:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;font-size:11px;font-weight:500}.DWJgoW_tick{fill:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums;font-size:11px}.DWJgoW_empty{text-align:center;color:var(--dsw-alias-label-secondary);margin:0;padding:24px 0;font-size:13px}";
|
|
4215
4627
|
const tagId$2 = "@laoyuehanni/dsh-token-usage/TrendChart.module.css";
|
|
4216
4628
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$2) + "]") === null) {
|
|
4217
4629
|
const tag = document.createElement("style");
|
|
@@ -4221,10 +4633,13 @@ window.__ModuleLoader__.load({
|
|
|
4221
4633
|
document.head.appendChild(tag);
|
|
4222
4634
|
}
|
|
4223
4635
|
var TrendChart_module_css_default = {
|
|
4636
|
+
"area": "DWJgoW_area",
|
|
4224
4637
|
"axis": "DWJgoW_axis",
|
|
4225
4638
|
"chart": "DWJgoW_chart",
|
|
4639
|
+
"chartLight": "DWJgoW_chartLight",
|
|
4226
4640
|
"dot": "DWJgoW_dot",
|
|
4227
4641
|
"dotActive": "DWJgoW_dotActive",
|
|
4642
|
+
"dotHalo": "DWJgoW_dotHalo",
|
|
4228
4643
|
"empty": "DWJgoW_empty",
|
|
4229
4644
|
"grid": "DWJgoW_grid",
|
|
4230
4645
|
"guide": "DWJgoW_guide",
|
|
@@ -4307,6 +4722,9 @@ window.__ModuleLoader__.load({
|
|
|
4307
4722
|
* @returns the SVG chart, or a placeholder for an empty range.
|
|
4308
4723
|
*/
|
|
4309
4724
|
function TrendChart({ rows, hours, requests, from, to, mode = "interval", t }) {
|
|
4725
|
+
const isLight = useIsLightMode();
|
|
4726
|
+
const gradientId = (0, react.useId)();
|
|
4727
|
+
const [active, setActive] = (0, react.useState)(null);
|
|
4310
4728
|
const base = buildChartPoints({
|
|
4311
4729
|
rows,
|
|
4312
4730
|
hours,
|
|
@@ -4331,20 +4749,19 @@ window.__ModuleLoader__.load({
|
|
|
4331
4749
|
const innerHeight = 140;
|
|
4332
4750
|
const { xs, xEnds, innerWidth } = scaleSeries(series, LEFT, 784);
|
|
4333
4751
|
const radius = dotRadius(points.length);
|
|
4334
|
-
const [active, setActive] = (0, react.useState)(null);
|
|
4335
4752
|
const activePoint = active === null ? null : points[active] ?? null;
|
|
4336
4753
|
const y = (tokens) => 152 - tokens / top * innerHeight;
|
|
4337
|
-
const
|
|
4754
|
+
const ys = points.map((point) => y(point.tokens));
|
|
4755
|
+
const yZero = y(0);
|
|
4756
|
+
const path = smoothSeriesPath({
|
|
4338
4757
|
xs,
|
|
4339
|
-
ys
|
|
4340
|
-
yZero
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
xEnds: xEnds ?? xs,
|
|
4345
|
-
hold: mode === "cumulative" ? "previous" : "zero"
|
|
4346
|
-
} : {}
|
|
4758
|
+
ys,
|
|
4759
|
+
yZero,
|
|
4760
|
+
gaps: series.mode === "temporal" ? gapAfter(series.points) : void 0,
|
|
4761
|
+
xEnds: series.mode === "temporal" ? xEnds ?? xs : void 0,
|
|
4762
|
+
hold: mode === "cumulative" ? "previous" : "zero"
|
|
4347
4763
|
});
|
|
4764
|
+
const area = areaPath(path, xs, yZero);
|
|
4348
4765
|
const chartAria = mode === "cumulative" ? t("chart.ariaCumulative") : series.mode === "temporal" ? t("chart.ariaRequests") : hours !== void 0 ? t("chart.ariaHour") : t("chart.aria");
|
|
4349
4766
|
const hitExtent = (index) => {
|
|
4350
4767
|
if (points.length === 1) return {
|
|
@@ -4362,13 +4779,55 @@ window.__ModuleLoader__.load({
|
|
|
4362
4779
|
width: half * 2
|
|
4363
4780
|
};
|
|
4364
4781
|
};
|
|
4782
|
+
const handleMouseMove = (event) => {
|
|
4783
|
+
if (points.length <= 1) return;
|
|
4784
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
4785
|
+
if (rect.width <= 0) return;
|
|
4786
|
+
const svgX = (event.clientX - rect.left) / rect.width * WIDTH;
|
|
4787
|
+
let closest = 0;
|
|
4788
|
+
let minDiff = Math.abs(xs[0] - svgX);
|
|
4789
|
+
for (let i = 1; i < xs.length; i += 1) {
|
|
4790
|
+
const diff = Math.abs(xs[i] - svgX);
|
|
4791
|
+
if (diff < minDiff) {
|
|
4792
|
+
minDiff = diff;
|
|
4793
|
+
closest = i;
|
|
4794
|
+
}
|
|
4795
|
+
}
|
|
4796
|
+
setActive(closest);
|
|
4797
|
+
};
|
|
4365
4798
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
4366
4799
|
role: "img",
|
|
4367
4800
|
"aria-label": chartAria,
|
|
4368
4801
|
viewBox: `0 0 ${WIDTH} ${HEIGHT}`,
|
|
4369
|
-
className: TrendChart_module_css_default.chart,
|
|
4802
|
+
className: `${TrendChart_module_css_default.chart} ${isLight ? TrendChart_module_css_default.chartLight : ""}`.trim(),
|
|
4803
|
+
"data-theme": isLight ? "light" : "dark",
|
|
4804
|
+
onMouseMove: handleMouseMove,
|
|
4370
4805
|
onMouseLeave: () => setActive(null),
|
|
4371
4806
|
children: [
|
|
4807
|
+
isLight ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
|
|
4808
|
+
id: gradientId,
|
|
4809
|
+
x1: "0",
|
|
4810
|
+
y1: "0",
|
|
4811
|
+
x2: "0",
|
|
4812
|
+
y2: "1",
|
|
4813
|
+
children: [
|
|
4814
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
|
|
4815
|
+
offset: "0%",
|
|
4816
|
+
stopColor: "var(--dsw-alias-label-primary)",
|
|
4817
|
+
stopOpacity: "0.045"
|
|
4818
|
+
}),
|
|
4819
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
|
|
4820
|
+
offset: "55%",
|
|
4821
|
+
stopColor: "var(--dsw-alias-label-primary)",
|
|
4822
|
+
stopOpacity: "0.012"
|
|
4823
|
+
}),
|
|
4824
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
|
|
4825
|
+
offset: "100%",
|
|
4826
|
+
stopColor: "var(--dsw-alias-label-primary)",
|
|
4827
|
+
stopOpacity: "0.0"
|
|
4828
|
+
})
|
|
4829
|
+
]
|
|
4830
|
+
}) }) : null,
|
|
4372
4831
|
ticks.map((tick) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
4373
4832
|
x1: LEFT,
|
|
4374
4833
|
y1: y(tick),
|
|
@@ -4389,16 +4848,34 @@ window.__ModuleLoader__.load({
|
|
|
4389
4848
|
y2: y(0),
|
|
4390
4849
|
className: TrendChart_module_css_default.axis
|
|
4391
4850
|
}),
|
|
4851
|
+
isLight && area !== "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
4852
|
+
d: area,
|
|
4853
|
+
fill: `url(#${gradientId})`,
|
|
4854
|
+
className: TrendChart_module_css_default.area
|
|
4855
|
+
}) : null,
|
|
4392
4856
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
4393
4857
|
d: path,
|
|
4394
4858
|
className: TrendChart_module_css_default.line
|
|
4395
4859
|
}),
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4860
|
+
activePoint !== null && active !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", {
|
|
4861
|
+
pointerEvents: "none",
|
|
4862
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
4863
|
+
cx: xs[active],
|
|
4864
|
+
cy: y(activePoint.tokens),
|
|
4865
|
+
r: radius + 3.5,
|
|
4866
|
+
className: TrendChart_module_css_default.dotHalo
|
|
4867
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
4868
|
+
cx: xs[active],
|
|
4869
|
+
cy: y(activePoint.tokens),
|
|
4870
|
+
r: radius,
|
|
4871
|
+
className: TrendChart_module_css_default.dotActive
|
|
4872
|
+
})]
|
|
4873
|
+
}) : points.length === 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
4874
|
+
cx: xs[0],
|
|
4875
|
+
cy: y(points[0].tokens),
|
|
4876
|
+
r: radius,
|
|
4877
|
+
className: TrendChart_module_css_default.dot
|
|
4878
|
+
}) : null,
|
|
4402
4879
|
activePoint !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
4403
4880
|
x1: xs[active],
|
|
4404
4881
|
y1: y(activePoint.tokens),
|
|
@@ -4425,7 +4902,7 @@ window.__ModuleLoader__.load({
|
|
|
4425
4902
|
}),
|
|
4426
4903
|
activePoint !== null ? (() => {
|
|
4427
4904
|
const label = tipOf(t, activePoint, mode);
|
|
4428
|
-
const labelWidth = label.length * 6.2 +
|
|
4905
|
+
const labelWidth = label.length * 6.2 + 14;
|
|
4429
4906
|
const center = xs[active];
|
|
4430
4907
|
const left = Math.min(Math.max(center - labelWidth / 2, LEFT), 784 - labelWidth);
|
|
4431
4908
|
const labelY = Math.max(y(activePoint.tokens) - 12, 20);
|
|
@@ -4434,13 +4911,13 @@ window.__ModuleLoader__.load({
|
|
|
4434
4911
|
pointerEvents: "none",
|
|
4435
4912
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
4436
4913
|
x: left,
|
|
4437
|
-
y: labelY -
|
|
4914
|
+
y: labelY - 14,
|
|
4438
4915
|
width: labelWidth,
|
|
4439
|
-
height:
|
|
4440
|
-
rx:
|
|
4916
|
+
height: 22,
|
|
4917
|
+
rx: 6
|
|
4441
4918
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
4442
4919
|
x: left + labelWidth / 2,
|
|
4443
|
-
y: labelY,
|
|
4920
|
+
y: labelY + 1,
|
|
4444
4921
|
textAnchor: "middle",
|
|
4445
4922
|
children: label
|
|
4446
4923
|
})]
|
|
@@ -4458,7 +4935,7 @@ window.__ModuleLoader__.load({
|
|
|
4458
4935
|
}
|
|
4459
4936
|
//#endregion
|
|
4460
4937
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\TokenUsageSection.module.css.mjs
|
|
4461
|
-
const css$1 = ".RbkiSa_section{flex-direction:column;gap:16px;width:100%;display:flex}.RbkiSa_head{justify-content:space-between;align-items:center;gap:12px;display:flex}.RbkiSa_title{color:var(--dsw-alias-label-primary);margin:0;font-size:16px;font-weight:600}.RbkiSa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}.RbkiSa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}.RbkiSa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:14px;font-weight:600}.RbkiSa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}.RbkiSa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}.RbkiSa_segBtn:hover:not(.RbkiSa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}.RbkiSa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}.RbkiSa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}.RbkiSa_tableWrap{max-height:420px;overflow:auto}.RbkiSa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:500px;font-size:12px}.RbkiSa_table th,.RbkiSa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}.RbkiSa_table th.RbkiSa_modelHead,.RbkiSa_table td.RbkiSa_modelCol{text-align:left;width:150px;max-width:150px}.RbkiSa_table th{color:var(--dsw-alias-label-secondary);z-index:1;background:var(--dsw-alias-bg-layer-2);font-weight:
|
|
4938
|
+
const css$1 = ".RbkiSa_section{flex-direction:column;gap:16px;width:100%;display:flex}.RbkiSa_head{justify-content:space-between;align-items:center;gap:12px;display:flex}.RbkiSa_title{color:var(--dsw-alias-label-primary);margin:0;font-size:16px;font-weight:600}.RbkiSa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}.RbkiSa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}.RbkiSa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:14px;font-weight:600}.RbkiSa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}.RbkiSa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}.RbkiSa_segBtn:hover:not(.RbkiSa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}.RbkiSa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}.RbkiSa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}.RbkiSa_tableWrap{max-height:420px;overflow:auto}.RbkiSa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:500px;font-size:12px}.RbkiSa_table th,.RbkiSa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}.RbkiSa_table th.RbkiSa_modelHead,.RbkiSa_table td.RbkiSa_modelCol{text-align:left;width:150px;max-width:150px}.RbkiSa_table th{color:var(--dsw-alias-label-secondary);z-index:1;background:var(--dsw-alias-bg-layer-2);border-bottom:1.5px solid var(--dsw-alias-border-l2);font-weight:600;position:sticky;top:0}.RbkiSa_table tbody tr{transition:background-color .12s}.RbkiSa_table tbody tr:hover{background-color:var(--dsw-interactive-bg-hover)}.RbkiSa_costCol{font-weight:600}.RbkiSa_zeroDim{color:var(--dsw-alias-label-tertiary);opacity:.55}.RbkiSa_table td{color:var(--dsw-alias-label-primary)}.RbkiSa_empty{color:var(--dsw-alias-label-secondary);margin:0;font-size:13px}.RbkiSa_button{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;border-radius:6px;padding:4px 12px;font-size:13px;line-height:20px}.RbkiSa_button:hover{background:var(--dsw-interactive-bg-hover)}.RbkiSa_filters{flex-wrap:nowrap;align-items:center;gap:8px;display:flex}.RbkiSa_cards{grid-template-columns:repeat(auto-fit,minmax(110px,1fr));gap:8px;display:grid}.RbkiSa_warning{color:var(--dsw-alias-state-warn-label);background:var(--dsw-alias-state-warn-tertiary);border-radius:6px;margin:0;padding:6px 10px;font-size:12px}.RbkiSa_modelCell{align-items:center;gap:4px;max-width:138px;display:inline-flex;position:relative}.RbkiSa_modelName{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}button.RbkiSa_modelName{max-width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:none;margin:0;padding:0}button.RbkiSa_modelName:hover{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary))}.RbkiSa_unpricedTag{color:var(--dsw-alias-state-warn-label);background:var(--dsw-alias-state-warn-tertiary);border-radius:8px;flex:none;padding:0 6px;font-size:10px;line-height:16px}.RbkiSa_pricingLink{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary));cursor:pointer;white-space:nowrap;background:0 0;border:none;border-radius:6px;flex:none;margin-left:auto;padding:4px 8px;font-size:13px;line-height:20px}.RbkiSa_pricingLink:hover{background:var(--dsw-interactive-bg-hover)}";
|
|
4462
4939
|
const tagId$1 = "@laoyuehanni/dsh-token-usage/TokenUsageSection.module.css";
|
|
4463
4940
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
|
|
4464
4941
|
const tag = document.createElement("style");
|
|
@@ -4470,6 +4947,7 @@ window.__ModuleLoader__.load({
|
|
|
4470
4947
|
var TokenUsageSection_module_css_default = {
|
|
4471
4948
|
"button": "RbkiSa_button",
|
|
4472
4949
|
"cards": "RbkiSa_cards",
|
|
4950
|
+
"costCol": "RbkiSa_costCol",
|
|
4473
4951
|
"empty": "RbkiSa_empty",
|
|
4474
4952
|
"error": "RbkiSa_error",
|
|
4475
4953
|
"filters": "RbkiSa_filters",
|
|
@@ -4489,7 +4967,8 @@ window.__ModuleLoader__.load({
|
|
|
4489
4967
|
"tableWrap": "RbkiSa_tableWrap",
|
|
4490
4968
|
"title": "RbkiSa_title",
|
|
4491
4969
|
"unpricedTag": "RbkiSa_unpricedTag",
|
|
4492
|
-
"warning": "RbkiSa_warning"
|
|
4970
|
+
"warning": "RbkiSa_warning",
|
|
4971
|
+
"zeroDim": "RbkiSa_zeroDim"
|
|
4493
4972
|
};
|
|
4494
4973
|
//#endregion
|
|
4495
4974
|
//#region src/client/TokenUsageSection.tsx
|
|
@@ -4645,6 +5124,30 @@ window.__ModuleLoader__.load({
|
|
|
4645
5124
|
function TokenUsageSection({ t, close, sessionListed, openSession }) {
|
|
4646
5125
|
const rootRef = (0, react.useRef)(null);
|
|
4647
5126
|
useColorSchemeMirror(rootRef);
|
|
5127
|
+
const [toastText, setToastText] = (0, react.useState)(null);
|
|
5128
|
+
const [toastSeq, setToastSeq] = (0, react.useState)(0);
|
|
5129
|
+
const showToast = (0, react.useCallback)((text) => {
|
|
5130
|
+
setToastSeq((previous) => previous + 1);
|
|
5131
|
+
setToastText(text);
|
|
5132
|
+
}, []);
|
|
5133
|
+
const dismissToast = (0, react.useCallback)(() => {
|
|
5134
|
+
setToastText(null);
|
|
5135
|
+
}, []);
|
|
5136
|
+
const handleOpenSession = (0, react.useCallback)((id) => {
|
|
5137
|
+
if (!openSession) return;
|
|
5138
|
+
const result = openSession(id);
|
|
5139
|
+
if (result && typeof result === "object" && "ok" in result) {
|
|
5140
|
+
if (result.ok) close();
|
|
5141
|
+
else if (result.reason === "workspaceDeleted") showToast(t("session.workspaceDeleted"));
|
|
5142
|
+
return;
|
|
5143
|
+
}
|
|
5144
|
+
if (result === true) close();
|
|
5145
|
+
}, [
|
|
5146
|
+
openSession,
|
|
5147
|
+
close,
|
|
5148
|
+
showToast,
|
|
5149
|
+
t
|
|
5150
|
+
]);
|
|
4648
5151
|
const [filters, setFilters] = (0, react.useState)(() => ({
|
|
4649
5152
|
model: "",
|
|
4650
5153
|
...quickRange(1)
|
|
@@ -4867,12 +5370,27 @@ window.__ModuleLoader__.load({
|
|
|
4867
5370
|
failuresByCode: row.totals.failuresByCode,
|
|
4868
5371
|
t
|
|
4869
5372
|
}) }),
|
|
4870
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5373
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5374
|
+
className: TokenUsageSection_module_css_default["costCol"],
|
|
5375
|
+
children: rules !== void 0 ? formatCost(row.cost, view) : "—"
|
|
5376
|
+
}),
|
|
4871
5377
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: formatTokens(totalTokens(row.totals)) }),
|
|
4872
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
5378
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5379
|
+
className: row.totals.inputTokens === 0 ? TokenUsageSection_module_css_default["zeroDim"] : void 0,
|
|
5380
|
+
children: formatTokens(row.totals.inputTokens)
|
|
5381
|
+
}),
|
|
5382
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5383
|
+
className: row.totals.outputTokens === 0 ? TokenUsageSection_module_css_default["zeroDim"] : void 0,
|
|
5384
|
+
children: formatTokens(row.totals.outputTokens)
|
|
5385
|
+
}),
|
|
5386
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5387
|
+
className: row.totals.cacheReadTokens === 0 ? TokenUsageSection_module_css_default["zeroDim"] : void 0,
|
|
5388
|
+
children: formatTokens(row.totals.cacheReadTokens)
|
|
5389
|
+
}),
|
|
5390
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5391
|
+
className: row.totals.cacheWriteTokens === 0 ? TokenUsageSection_module_css_default["zeroDim"] : void 0,
|
|
5392
|
+
children: formatTokens(row.totals.cacheWriteTokens)
|
|
5393
|
+
}),
|
|
4876
5394
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HitRateText, { totals: row.totals }) })
|
|
4877
5395
|
] }, row.model);
|
|
4878
5396
|
}) })]
|
|
@@ -4883,9 +5401,7 @@ window.__ModuleLoader__.load({
|
|
|
4883
5401
|
t,
|
|
4884
5402
|
...sessionListed !== void 0 && openSession !== void 0 ? {
|
|
4885
5403
|
sessionListed,
|
|
4886
|
-
openSession:
|
|
4887
|
-
if (openSession(id)) close();
|
|
4888
|
-
}
|
|
5404
|
+
openSession: handleOpenSession
|
|
4889
5405
|
} : {}
|
|
4890
5406
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
4891
5407
|
className: TokenUsageSection_module_css_default["muted"],
|
|
@@ -4898,13 +5414,18 @@ window.__ModuleLoader__.load({
|
|
|
4898
5414
|
onClose: () => setDetailModel(null),
|
|
4899
5415
|
t
|
|
4900
5416
|
}) : null
|
|
4901
|
-
] })
|
|
5417
|
+
] }),
|
|
5418
|
+
toastText !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Toast, {
|
|
5419
|
+
text: toastText,
|
|
5420
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconWarningOutlineRegular, {}),
|
|
5421
|
+
onDone: dismissToast
|
|
5422
|
+
}, toastSeq)
|
|
4902
5423
|
]
|
|
4903
5424
|
});
|
|
4904
5425
|
}
|
|
4905
5426
|
//#endregion
|
|
4906
5427
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\UsageView.module.css.mjs
|
|
4907
|
-
const css = "._0MkXVa_root{box-sizing:border-box;width:100%;padding:12px calc(var(--dsh-composer-side-clearance,16px) + 16px);padding-bottom:calc(var(--dsh-composer-height,152px) + 16px);flex-direction:column;gap:12px;max-width:1400px;height:100%;min-height:0;margin:0 auto;display:flex;overflow-y:auto}._0MkXVa_head{flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:12px;display:flex}._0MkXVa_headRight{align-items:center;gap:10px;display:flex}._0MkXVa_back{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;padding:3px 10px;font-size:12px}._0MkXVa_back:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}._0MkXVa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}._0MkXVa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}._0MkXVa_segBtn:hover:not(._0MkXVa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}._0MkXVa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}._0MkXVa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}._0MkXVa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}._0MkXVa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}._0MkXVa_empty{color:var(--dsw-alias-label-secondary);text-align:center;margin:24px 0 0;font-size:13px}._0MkXVa_button{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;align-self:flex-start;padding:3px 10px;font-size:12px}._0MkXVa_warning{color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-label-secondary));margin:0;font-size:12px}._0MkXVa_note{color:var(--dsw-alias-label-tertiary);margin:0;font-size:11px}._0MkXVa_cards{grid-template-columns:repeat(6,minmax(0,1fr));gap:10px;display:grid}._0MkXVa_tokenStrip{color:var(--dsw-alias-label-secondary);flex-wrap:wrap;gap:18px;padding:6px 2px 0;font-size:12px;display:flex}._0MkXVa_tokenStrip b{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums}._0MkXVa_mid{grid-template-columns:minmax(0,3fr) minmax(0,2fr);align-items:start;gap:14px;display:grid}._0MkXVa_chartCol,._0MkXVa_modelCol,._0MkXVa_subagents{flex-direction:column;gap:6px;min-width:0;display:flex}._0MkXVa_subagentsHead,._0MkXVa_chartHead{align-items:center;gap:8px;display:flex}._0MkXVa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:13px;font-weight:600}._0MkXVa_tableWrap{overflow-x:auto}._0MkXVa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}._0MkXVa_table th,._0MkXVa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}._0MkXVa_table th:first-child,._0MkXVa_table td:first-child,._0MkXVa_modelHead{text-align:left}._0MkXVa_modelCell{font-variant-numeric:normal;text-overflow:ellipsis;max-width:180px;overflow:hidden}._0MkXVa_childLink{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary));cursor:pointer;text-align:left;text-overflow:ellipsis;white-space:nowrap;background:0 0;border:none;max-width:220px;padding:0;font-size:12px;overflow:hidden}._0MkXVa_childLink:hover{text-decoration:underline}._0MkXVa_nestedBadge{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;margin-left:6px;font-size:11px}@media (width<=900px){._0MkXVa_cards{grid-template-columns:repeat(3,minmax(0,1fr))}._0MkXVa_mid{grid-template-columns:1fr}}";
|
|
5428
|
+
const css = "._0MkXVa_root{box-sizing:border-box;width:100%;padding:12px calc(var(--dsh-composer-side-clearance,16px) + 16px);padding-bottom:calc(var(--dsh-composer-height,152px) + 16px);flex-direction:column;gap:12px;max-width:1400px;height:100%;min-height:0;margin:0 auto;display:flex;overflow-y:auto}._0MkXVa_head{flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:12px;display:flex}._0MkXVa_headRight{align-items:center;gap:10px;display:flex}._0MkXVa_back{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;padding:3px 10px;font-size:12px}._0MkXVa_back:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}._0MkXVa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}._0MkXVa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}._0MkXVa_segBtn:hover:not(._0MkXVa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}._0MkXVa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}._0MkXVa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}._0MkXVa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}._0MkXVa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}._0MkXVa_empty{color:var(--dsw-alias-label-secondary);text-align:center;margin:24px 0 0;font-size:13px}._0MkXVa_button{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;align-self:flex-start;padding:3px 10px;font-size:12px}._0MkXVa_warning{color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-label-secondary));margin:0;font-size:12px}._0MkXVa_note{color:var(--dsw-alias-label-tertiary);margin:0;font-size:11px}._0MkXVa_cards{grid-template-columns:repeat(6,minmax(0,1fr));gap:10px;display:grid}._0MkXVa_tokenStrip{color:var(--dsw-alias-label-secondary);flex-wrap:wrap;gap:18px;padding:6px 2px 0;font-size:12px;display:flex}._0MkXVa_tokenStrip b{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums}._0MkXVa_mid{grid-template-columns:minmax(0,3fr) minmax(0,2fr);align-items:start;gap:14px;display:grid}._0MkXVa_chartCol,._0MkXVa_modelCol,._0MkXVa_subagents{flex-direction:column;gap:6px;min-width:0;display:flex}._0MkXVa_subagentsHead,._0MkXVa_chartHead{align-items:center;gap:8px;display:flex}._0MkXVa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:13px;font-weight:600}._0MkXVa_tableWrap{overflow-x:auto}._0MkXVa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}._0MkXVa_table th,._0MkXVa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}._0MkXVa_table tbody tr{transition:background-color .12s}._0MkXVa_table tbody tr:hover{background-color:var(--dsw-interactive-bg-hover)}._0MkXVa_table th{border-bottom:1.5px solid var(--dsw-alias-border-l2);font-weight:600}._0MkXVa_costCol{font-weight:600}._0MkXVa_zeroDim{color:var(--dsw-alias-label-tertiary);opacity:.55}._0MkXVa_table th:first-child,._0MkXVa_table td:first-child,._0MkXVa_modelHead{text-align:left}._0MkXVa_modelCell{font-variant-numeric:normal;text-overflow:ellipsis;max-width:180px;overflow:hidden}._0MkXVa_childLink{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary));cursor:pointer;text-align:left;text-overflow:ellipsis;white-space:nowrap;background:0 0;border:none;max-width:220px;padding:0;font-size:12px;overflow:hidden}._0MkXVa_childLink:hover{text-decoration:underline}._0MkXVa_nestedBadge{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;margin-left:6px;font-size:11px}@media (width<=900px){._0MkXVa_cards{grid-template-columns:repeat(3,minmax(0,1fr))}._0MkXVa_mid{grid-template-columns:1fr}}";
|
|
4908
5429
|
const tagId = "@laoyuehanni/dsh-token-usage/UsageView.module.css";
|
|
4909
5430
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
4910
5431
|
const tag = document.createElement("style");
|
|
@@ -4920,6 +5441,7 @@ window.__ModuleLoader__.load({
|
|
|
4920
5441
|
"chartCol": "_0MkXVa_chartCol",
|
|
4921
5442
|
"chartHead": "_0MkXVa_chartHead",
|
|
4922
5443
|
"childLink": "_0MkXVa_childLink",
|
|
5444
|
+
"costCol": "_0MkXVa_costCol",
|
|
4923
5445
|
"empty": "_0MkXVa_empty",
|
|
4924
5446
|
"error": "_0MkXVa_error",
|
|
4925
5447
|
"head": "_0MkXVa_head",
|
|
@@ -4941,7 +5463,8 @@ window.__ModuleLoader__.load({
|
|
|
4941
5463
|
"table": "_0MkXVa_table",
|
|
4942
5464
|
"tableWrap": "_0MkXVa_tableWrap",
|
|
4943
5465
|
"tokenStrip": "_0MkXVa_tokenStrip",
|
|
4944
|
-
"warning": "_0MkXVa_warning"
|
|
5466
|
+
"warning": "_0MkXVa_warning",
|
|
5467
|
+
"zeroDim": "_0MkXVa_zeroDim"
|
|
4945
5468
|
};
|
|
4946
5469
|
//#endregion
|
|
4947
5470
|
//#region src/client/UsageView.tsx
|
|
@@ -5259,12 +5782,27 @@ window.__ModuleLoader__.load({
|
|
|
5259
5782
|
failuresByCode: row.totals.failuresByCode,
|
|
5260
5783
|
t
|
|
5261
5784
|
}) }),
|
|
5262
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5785
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5786
|
+
className: row.totals.inputTokens === 0 ? UsageView_module_css_default["zeroDim"] : void 0,
|
|
5787
|
+
children: formatTokens(row.totals.inputTokens)
|
|
5788
|
+
}),
|
|
5789
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5790
|
+
className: row.totals.outputTokens === 0 ? UsageView_module_css_default["zeroDim"] : void 0,
|
|
5791
|
+
children: formatTokens(row.totals.outputTokens)
|
|
5792
|
+
}),
|
|
5793
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5794
|
+
className: row.totals.cacheReadTokens === 0 ? UsageView_module_css_default["zeroDim"] : void 0,
|
|
5795
|
+
children: formatTokens(row.totals.cacheReadTokens)
|
|
5796
|
+
}),
|
|
5797
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5798
|
+
className: row.totals.cacheWriteTokens === 0 ? UsageView_module_css_default["zeroDim"] : void 0,
|
|
5799
|
+
children: formatTokens(row.totals.cacheWriteTokens)
|
|
5800
|
+
}),
|
|
5266
5801
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HitRateText, { totals: row.totals }) }),
|
|
5267
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5802
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5803
|
+
className: UsageView_module_css_default["costCol"],
|
|
5804
|
+
children: formatCost(row.cost, view)
|
|
5805
|
+
})
|
|
5268
5806
|
] }, row.model)) })]
|
|
5269
5807
|
})
|
|
5270
5808
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
@@ -5337,7 +5875,10 @@ window.__ModuleLoader__.load({
|
|
|
5337
5875
|
}),
|
|
5338
5876
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: row?.total.requests.toLocaleString() ?? "—" }),
|
|
5339
5877
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: row !== void 0 ? formatTokens(totalTokens(row.total)) : "—" }),
|
|
5340
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5878
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5879
|
+
className: UsageView_module_css_default["costCol"],
|
|
5880
|
+
children: row !== void 0 ? formatCost(row.totalCost, view) : "—"
|
|
5881
|
+
}),
|
|
5341
5882
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: row !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HitRateText, { totals: row.total }) : "—" }),
|
|
5342
5883
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: childStats !== void 0 && childStats.ttftSteps > 0 ? formatTtft(childStats.ttftMs / childStats.ttftSteps) : "—" }),
|
|
5343
5884
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: childStats !== void 0 && childStats.decodeMs > 0 ? `${formatSpeed(childStats.decodeTokens / (childStats.decodeMs / 1e3))} tok/s` : "—" })
|
|
@@ -5427,6 +5968,7 @@ window.__ModuleLoader__.load({
|
|
|
5427
5968
|
"session.subagentBadge": "子会话",
|
|
5428
5969
|
"session.lastActive": "最近活跃",
|
|
5429
5970
|
"session.openHint": "按住 Ctrl 点击打开该会话(用量页签跟随该会话上次的选择)",
|
|
5971
|
+
"session.workspaceDeleted": "该会话所属工作区已删除,无法跳转",
|
|
5430
5972
|
"pricing.title": "模型定价",
|
|
5431
5973
|
"pricing.view": "查看 {model} 定价",
|
|
5432
5974
|
"pricing.viewShort": "定价",
|
|
@@ -5520,9 +6062,18 @@ window.__ModuleLoader__.load({
|
|
|
5520
6062
|
"view.subagents.titleCol": "会话",
|
|
5521
6063
|
"view.subagents.nested": "含 {count} 个子会话",
|
|
5522
6064
|
"view.note": "注:token 与费用来自本插件的请求记录(安装后);平均首token 与 token速度来自 DSH 会话投影(含安装前历史)。",
|
|
5523
|
-
"
|
|
5524
|
-
"
|
|
5525
|
-
"
|
|
6065
|
+
"pill.cost": "费用 {value}",
|
|
6066
|
+
"pill.costWithSubs": "费用(含子会话){value}",
|
|
6067
|
+
"pill.scopeTag": "含子会话",
|
|
6068
|
+
"panel.title": "用量明细",
|
|
6069
|
+
"panel.openHint": "点击展开用量明细",
|
|
6070
|
+
"panel.tokens": "{value} tok",
|
|
6071
|
+
"panel.hitRate": "缓存命中 {value}",
|
|
6072
|
+
"panel.self": "本会话",
|
|
6073
|
+
"panel.subs": "子会话 ×{count}",
|
|
6074
|
+
"panel.byModel": "按模型",
|
|
6075
|
+
"panel.unpriced": "未定价模型 ×{count}",
|
|
6076
|
+
"panel.unpricedNote": "仅计 token",
|
|
5526
6077
|
"quota.trigger": "供应商配额",
|
|
5527
6078
|
"quota.triggerSummary": "{name} · {figure}",
|
|
5528
6079
|
"quota.panel": "供应商配额面板",
|
|
@@ -5600,6 +6151,7 @@ window.__ModuleLoader__.load({
|
|
|
5600
6151
|
"session.subagentBadge": "Subagent",
|
|
5601
6152
|
"session.lastActive": "Last active",
|
|
5602
6153
|
"session.openHint": "Ctrl+click to open this session (the usage tab follows its last selection)",
|
|
6154
|
+
"session.workspaceDeleted": "The workspace for this session has been deleted and cannot be opened",
|
|
5603
6155
|
"pricing.title": "Model pricing",
|
|
5604
6156
|
"pricing.view": "View rates for {model}",
|
|
5605
6157
|
"pricing.viewShort": "Rates",
|
|
@@ -5693,9 +6245,18 @@ window.__ModuleLoader__.load({
|
|
|
5693
6245
|
"view.subagents.titleCol": "Session",
|
|
5694
6246
|
"view.subagents.nested": "With {count} subagents",
|
|
5695
6247
|
"view.note": "Note: tokens and cost come from this plugin's request log (post-install); average TTFT and token speed come from the DSH session projection (includes pre-install history).",
|
|
5696
|
-
"
|
|
5697
|
-
"
|
|
5698
|
-
"
|
|
6248
|
+
"pill.cost": "Cost {value}",
|
|
6249
|
+
"pill.costWithSubs": "Cost with subagents {value}",
|
|
6250
|
+
"pill.scopeTag": "with subagents",
|
|
6251
|
+
"panel.title": "Usage details",
|
|
6252
|
+
"panel.openHint": "click to open usage details",
|
|
6253
|
+
"panel.tokens": "{value} tok",
|
|
6254
|
+
"panel.hitRate": "cache hit {value}",
|
|
6255
|
+
"panel.self": "This session",
|
|
6256
|
+
"panel.subs": "Subagents ×{count}",
|
|
6257
|
+
"panel.byModel": "By model",
|
|
6258
|
+
"panel.unpriced": "Unpriced model ×{count}",
|
|
6259
|
+
"panel.unpricedNote": "tokens only",
|
|
5699
6260
|
"quota.trigger": "Provider quota",
|
|
5700
6261
|
"quota.triggerSummary": "{name} · {figure}",
|
|
5701
6262
|
"quota.panel": "Provider quota panel",
|
|
@@ -5719,18 +6280,41 @@ window.__ModuleLoader__.load({
|
|
|
5719
6280
|
* imported: a client package must not depend on a Host package.
|
|
5720
6281
|
*/
|
|
5721
6282
|
const TOKEN_USAGE_NS = "token-usage";
|
|
6283
|
+
/**
|
|
6284
|
+
* Candidate keys under which the Host may serve this plugin's settings
|
|
6285
|
+
* form. The 0.1.7 host keys `ConfigForms.get` by the plugin's ENTRY ID (the
|
|
6286
|
+
* namespace); the full package name stays as a fallback for a host that keyed
|
|
6287
|
+
* it by package instead.
|
|
6288
|
+
*/
|
|
6289
|
+
const CONFIG_FORM_KEYS = [TOKEN_USAGE_NS, "@laoyuehanni/dsh-token-usage"];
|
|
6290
|
+
/**
|
|
6291
|
+
* Resolve the form target from the describe mirror's LIVE namespace list.
|
|
6292
|
+
* The 0.1.7 `ConfigForms.get()` unconditionally creates and caches a
|
|
6293
|
+
* controller for ANY key — it never returns undefined — so key validity must
|
|
6294
|
+
* come from the namespaces the mirror actually serves. A `get()` on a key the
|
|
6295
|
+
* mirror does not list yields a controller stuck at 'unavailable' forever,
|
|
6296
|
+
* and the card renders nothing. No view yet (mirror still loading) answers
|
|
6297
|
+
* undefined so the caller keeps its current target.
|
|
6298
|
+
*/
|
|
6299
|
+
const resolveConfigFormsTarget = (forms) => {
|
|
6300
|
+
const namespaces = typeof forms.describe === "function" ? forms.describe()?.getSnapshot()?.view?.namespaces : void 0;
|
|
6301
|
+
if (namespaces === void 0) return void 0;
|
|
6302
|
+
const served = CONFIG_FORM_KEYS.find((key) => namespaces.some((row) => row.ns === key));
|
|
6303
|
+
return served === void 0 ? void 0 : forms.get(served);
|
|
6304
|
+
};
|
|
5722
6305
|
/** Required services: the slot registry, the locale dictionaries, the
|
|
5723
|
-
*
|
|
5724
|
-
*
|
|
5725
|
-
*
|
|
6306
|
+
* workspace navigation service (its native directory picker backs the card's
|
|
6307
|
+
* browse button), and the session controller (the stats page's Ctrl+click
|
|
6308
|
+
* session jump reads the list and opens the target). Configuration sources
|
|
6309
|
+
* (`configForms` in dsh 0.1.7+, `settingsScope` in pre-0.1.7) attach dynamically. */
|
|
5726
6310
|
const inject = [
|
|
5727
6311
|
"slots",
|
|
5728
6312
|
"locale",
|
|
5729
6313
|
"connection",
|
|
5730
6314
|
"remote",
|
|
5731
|
-
"settingsScope",
|
|
5732
6315
|
"uiWorkspace",
|
|
5733
|
-
"sessions"
|
|
6316
|
+
"sessions",
|
|
6317
|
+
"workspaces"
|
|
5734
6318
|
];
|
|
5735
6319
|
/**
|
|
5736
6320
|
* Register the dictionary pair, then the settings page and the plugin
|
|
@@ -5743,12 +6327,32 @@ window.__ModuleLoader__.load({
|
|
|
5743
6327
|
en
|
|
5744
6328
|
}), "token-usage: dictionaries");
|
|
5745
6329
|
const t = ctx.locale.bind(NS);
|
|
5746
|
-
const
|
|
5747
|
-
const
|
|
6330
|
+
const getSessions = () => ctx.get?.("sessions") ?? ctx.sessions;
|
|
6331
|
+
const getUiWorkspace = () => ctx.get?.("uiWorkspace") ?? ctx.uiWorkspace;
|
|
6332
|
+
const getWorkspaces = () => ctx.get?.("workspaces") ?? ctx.workspaces;
|
|
6333
|
+
const isSessionInController = (id) => {
|
|
6334
|
+
return (getSessions()?.list?.getSnapshot())?.byId?.[id] !== void 0;
|
|
6335
|
+
};
|
|
6336
|
+
const isWorkspaceAlive = (id) => {
|
|
6337
|
+
const ws = getWorkspaces()?.list?.getSnapshot();
|
|
6338
|
+
if (!ws || ws.phase === "pending") return true;
|
|
6339
|
+
const sid = id;
|
|
6340
|
+
return ws.items.some((item) => item.sessionIds.includes(sid));
|
|
6341
|
+
};
|
|
6342
|
+
const sessionListed = (id) => {
|
|
6343
|
+
return isSessionInController(id) && isWorkspaceAlive(id);
|
|
6344
|
+
};
|
|
5748
6345
|
const openSession = (id) => {
|
|
5749
|
-
if (!
|
|
5750
|
-
|
|
5751
|
-
|
|
6346
|
+
if (!isSessionInController(id)) return {
|
|
6347
|
+
ok: false,
|
|
6348
|
+
reason: "sessionNotFound"
|
|
6349
|
+
};
|
|
6350
|
+
if (!isWorkspaceAlive(id)) return {
|
|
6351
|
+
ok: false,
|
|
6352
|
+
reason: "workspaceDeleted"
|
|
6353
|
+
};
|
|
6354
|
+
getUiWorkspace()?.openSession(id);
|
|
6355
|
+
return { ok: true };
|
|
5752
6356
|
};
|
|
5753
6357
|
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
5754
6358
|
name: "settings.section",
|
|
@@ -5768,12 +6372,12 @@ window.__ModuleLoader__.load({
|
|
|
5768
6372
|
label: () => t("view.usage"),
|
|
5769
6373
|
locale: NS
|
|
5770
6374
|
}, UsageView));
|
|
5771
|
-
ctx.slots.inject("conversation.
|
|
5772
|
-
name: "conversation.
|
|
5773
|
-
id: "
|
|
5774
|
-
order:
|
|
6375
|
+
ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
|
|
6376
|
+
name: "conversation.composer.dock",
|
|
6377
|
+
id: "token-usage-cost",
|
|
6378
|
+
order: 10,
|
|
5775
6379
|
locale: NS
|
|
5776
|
-
},
|
|
6380
|
+
}, CostPill));
|
|
5777
6381
|
const modelDirectory = { service: void 0 };
|
|
5778
6382
|
ctx.inject(["modelDirectories"], (modelCtx) => {
|
|
5779
6383
|
modelCtx.effect(() => {
|
|
@@ -5790,16 +6394,75 @@ window.__ModuleLoader__.load({
|
|
|
5790
6394
|
locale: NS,
|
|
5791
6395
|
inject: () => ({ modelDirectory })
|
|
5792
6396
|
}, QuotaButton));
|
|
5793
|
-
const
|
|
6397
|
+
const lookupCurrentTarget = () => {
|
|
6398
|
+
const configForms = ctx.get("configForms");
|
|
6399
|
+
if (configForms && typeof configForms.get === "function") {
|
|
6400
|
+
const byMirror = resolveConfigFormsTarget(configForms);
|
|
6401
|
+
if (byMirror !== void 0) return byMirror;
|
|
6402
|
+
}
|
|
6403
|
+
const settingsScope = ctx.get("settingsScope");
|
|
6404
|
+
if (settingsScope && typeof settingsScope.bind === "function") return settingsScope.bind({ namespace: TOKEN_USAGE_NS });
|
|
6405
|
+
};
|
|
6406
|
+
let activeTarget = lookupCurrentTarget() ?? createFallbackTarget();
|
|
6407
|
+
const targetListeners = /* @__PURE__ */ new Set();
|
|
6408
|
+
let unsubActive = activeTarget.subscribe(() => {
|
|
6409
|
+
for (const listener of targetListeners) listener();
|
|
6410
|
+
});
|
|
6411
|
+
const switchTarget = (next) => {
|
|
6412
|
+
if (next === activeTarget) return;
|
|
6413
|
+
unsubActive?.();
|
|
6414
|
+
activeTarget = next;
|
|
6415
|
+
unsubActive = activeTarget.subscribe(() => {
|
|
6416
|
+
for (const listener of targetListeners) listener();
|
|
6417
|
+
});
|
|
6418
|
+
for (const listener of targetListeners) listener();
|
|
6419
|
+
};
|
|
6420
|
+
ctx.inject(["configForms"], (configCtx) => {
|
|
6421
|
+
configCtx.effect(() => {
|
|
6422
|
+
const forms = configCtx.get("configForms");
|
|
6423
|
+
if (!forms || typeof forms.get !== "function") return () => {};
|
|
6424
|
+
const mirror = typeof forms.describe === "function" ? forms.describe() : void 0;
|
|
6425
|
+
const resolve = () => {
|
|
6426
|
+
const target = resolveConfigFormsTarget(forms);
|
|
6427
|
+
if (target !== void 0) switchTarget(target);
|
|
6428
|
+
};
|
|
6429
|
+
resolve();
|
|
6430
|
+
mirror?.ensure?.();
|
|
6431
|
+
const unsubscribe = mirror?.subscribe(() => {
|
|
6432
|
+
resolve();
|
|
6433
|
+
});
|
|
6434
|
+
return () => {
|
|
6435
|
+
unsubscribe?.();
|
|
6436
|
+
};
|
|
6437
|
+
}, "token-usage: configForms dynamic target");
|
|
6438
|
+
});
|
|
6439
|
+
ctx.inject(["settingsScope"], (scopeCtx) => {
|
|
6440
|
+
scopeCtx.effect(() => {
|
|
6441
|
+
const scopeService = scopeCtx.get("settingsScope");
|
|
6442
|
+
if (scopeService && typeof scopeService.bind === "function") switchTarget(scopeService.bind({ namespace: TOKEN_USAGE_NS }));
|
|
6443
|
+
return () => {};
|
|
6444
|
+
}, "token-usage: settingsScope dynamic target");
|
|
6445
|
+
});
|
|
6446
|
+
const form = new CardForm({
|
|
6447
|
+
getSnapshot: () => activeTarget.getSnapshot(),
|
|
6448
|
+
subscribe: (listener) => {
|
|
6449
|
+
targetListeners.add(listener);
|
|
6450
|
+
return () => {
|
|
6451
|
+
targetListeners.delete(listener);
|
|
6452
|
+
};
|
|
6453
|
+
},
|
|
6454
|
+
set: (field, value) => activeTarget.set(field, value),
|
|
6455
|
+
unset: (field) => activeTarget.unset(field)
|
|
6456
|
+
});
|
|
5794
6457
|
const store = form.bind();
|
|
5795
|
-
ctx.slots.inject("
|
|
5796
|
-
name: "
|
|
5797
|
-
key:
|
|
6458
|
+
ctx.slots.inject("plugins.bundle.config", () => ctx.slots.register({
|
|
6459
|
+
name: "plugins.bundle.config",
|
|
6460
|
+
key: "@laoyuehanni/dsh-token-usage",
|
|
5798
6461
|
locale: NS,
|
|
5799
6462
|
inject: () => ({
|
|
5800
6463
|
hooks: { tokenUsageCard: store },
|
|
5801
6464
|
...form.actions(),
|
|
5802
|
-
pickDirectory: () => ctx.uiWorkspace
|
|
6465
|
+
pickDirectory: () => ctx.get("uiWorkspace")?.pickDirectory?.() ?? Promise.resolve(null)
|
|
5803
6466
|
})
|
|
5804
6467
|
}, TokenUsageCard));
|
|
5805
6468
|
}
|