dsh-token-usage-ledger 0.0.0-stage → 0.0.37

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +1081 -0
  2. package/LICENSE +21 -0
  3. package/README.md +247 -2
  4. package/cordis.patch.yml +30 -0
  5. package/docs/token-usage-image01.png +0 -0
  6. package/docs/token-usage-image02.png +0 -0
  7. package/lib/client.js +4469 -0
  8. package/lib/host/aggregate.d.ts +132 -0
  9. package/lib/host/aggregate.js +840 -0
  10. package/lib/host/api.d.ts +118 -0
  11. package/lib/host/api.js +346 -0
  12. package/lib/host/backfill.d.ts +54 -0
  13. package/lib/host/backfill.js +265 -0
  14. package/lib/host/collector.d.ts +139 -0
  15. package/lib/host/collector.js +441 -0
  16. package/lib/host/ledger-io.d.ts +125 -0
  17. package/lib/host/ledger-io.js +211 -0
  18. package/lib/host/operation-error.d.ts +22 -0
  19. package/lib/host/operation-error.js +28 -0
  20. package/lib/host/paths.d.ts +35 -0
  21. package/lib/host/paths.js +63 -0
  22. package/lib/host/pricing-module.d.ts +112 -0
  23. package/lib/host/pricing-module.js +63 -0
  24. package/lib/host/pricing-modules/deepseek-2026-09-10.d.ts +31 -0
  25. package/lib/host/pricing-modules/deepseek-2026-09-10.js +67 -0
  26. package/lib/host/pricing-modules/index.d.ts +27 -0
  27. package/lib/host/pricing-modules/index.js +30 -0
  28. package/lib/host/pricing.d.ts +192 -0
  29. package/lib/host/pricing.js +287 -0
  30. package/lib/host/records.d.ts +47 -0
  31. package/lib/host/records.js +116 -0
  32. package/lib/host/runtime-marker.d.ts +67 -0
  33. package/lib/host/runtime-marker.js +71 -0
  34. package/lib/host/schema.d.ts +77 -0
  35. package/lib/host/schema.js +158 -0
  36. package/lib/host/store.d.ts +171 -0
  37. package/lib/host/store.js +337 -0
  38. package/lib/host/workspace-titles.d.ts +38 -0
  39. package/lib/host/workspace-titles.js +136 -0
  40. package/lib/host/zstd.d.ts +41 -0
  41. package/lib/host/zstd.js +134 -0
  42. package/lib/index.d.ts +82 -0
  43. package/lib/index.js +512 -0
  44. package/lib/shared/format.d.ts +415 -0
  45. package/lib/shared/format.js +714 -0
  46. package/lib/shared/protocol.d.ts +646 -0
  47. package/lib/shared/protocol.js +129 -0
  48. package/package.json +87 -4
package/lib/client.js ADDED
@@ -0,0 +1,4469 @@
1
+ // Generated by scripts/build-client.mjs — do not edit.
2
+ // Module-loader closure factory for dsh-token-usage-ledger. The loader calls factory(require)
3
+ // with a single argument, so module/exports must supply their own defaults.
4
+ "use strict";
5
+ window.__ModuleLoader__.load({
6
+ id: "dsh-token-usage-ledger",
7
+ factory: function (require, module = { exports: {} }, exports = module.exports) {
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name2 in all)
14
+ __defProp(target, name2, { get: all[name2], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/client/index.tsx
27
+ var index_exports = {};
28
+ __export(index_exports, {
29
+ apply: () => apply,
30
+ inject: () => inject,
31
+ name: () => name
32
+ });
33
+ module.exports = __toCommonJS(index_exports);
34
+ var import_react8 = require("react");
35
+
36
+ // src/client/boundary.tsx
37
+ var import_react = require("react");
38
+ var ErrorBoundary = class extends import_react.Component {
39
+ /**
40
+ * Create the boundary.
41
+ * @param props - boundary props.
42
+ */
43
+ constructor(props) {
44
+ super(props);
45
+ this.state = { failed: false };
46
+ }
47
+ /**
48
+ * Flip to the fallback as soon as a descendant throws.
49
+ * @returns the next state.
50
+ */
51
+ static getDerivedStateFromError() {
52
+ return { failed: true };
53
+ }
54
+ /**
55
+ * Report the failure once, without printing the message into the page.
56
+ * @param error - thrown value.
57
+ * @param info - React component stack information.
58
+ */
59
+ componentDidCatch(error, info) {
60
+ const where = info.componentStack?.split("\n")[1]?.trim() ?? "";
61
+ console.warn(
62
+ `[token-usage] panel render failed and was contained (${error.name || "Error"}${where.length > 0 ? ` at ${where}` : ""})`
63
+ );
64
+ }
65
+ /**
66
+ * Render children until a failure, then the fallback.
67
+ * @returns the subtree to render.
68
+ */
69
+ render() {
70
+ if (this.state.failed) return this.props.fallback ?? null;
71
+ return this.props.children ?? null;
72
+ }
73
+ };
74
+
75
+ // src/client/dashboard.tsx
76
+ var import_react7 = require("react");
77
+
78
+ // src/shared/protocol.ts
79
+ function isObject(value) {
80
+ return typeof value === "object" && value !== null && !Array.isArray(value);
81
+ }
82
+ function isSummaryResponseLike(value) {
83
+ if (!isObject(value)) return false;
84
+ if (typeof value["currency"] !== "string") return false;
85
+ if (typeof value["pluginVersion"] !== "string") return false;
86
+ const totals = value["totals"];
87
+ const allTime = value["allTime"];
88
+ const health = value["health"];
89
+ const pricing = value["pricing"];
90
+ const facets = value["facets"];
91
+ if (!isObject(totals) || !isObject(allTime) || !isObject(health)) return false;
92
+ if (!isObject(pricing) || !isObject(facets)) return false;
93
+ if (!Array.isArray(value["daily"])) return false;
94
+ if (!Array.isArray(value["byModel"]) || !Array.isArray(value["byWorkspace"])) return false;
95
+ if (!Array.isArray(facets["workspaces"]) || !Array.isArray(facets["models"])) return false;
96
+ if (typeof facets["records"] !== "number") return false;
97
+ if (typeof totals["total"] !== "number" || !isObject(totals["tokens"])) return false;
98
+ if (typeof pricing["currency"] !== "string") return false;
99
+ if (!Array.isArray(pricing["rows"]) || !Array.isArray(pricing["peakWindows"])) return false;
100
+ if (typeof pricing["offPeakRatio"] !== "number") return false;
101
+ return true;
102
+ }
103
+ var API_LIMITS = {
104
+ /** Default daily window. */
105
+ defaultDays: 90,
106
+ /** Maximum daily window the server will serialize. */
107
+ maxDays: 1825,
108
+ /**
109
+ * Largest number of ledger records the reader will hold.
110
+ *
111
+ * The reader streams the ledger, so this bounds MEMORY rather than file size;
112
+ * reaching it sets `HealthReport.ledgerTruncated` and keeps the newest records.
113
+ */
114
+ maxRecords: 5e5
115
+ };
116
+ var BACKUP_FORMAT = "dsh-token-usage-backup";
117
+ var BACKUP_FORMAT_VERSION = 1;
118
+ var BACKUP_LIMITS = {
119
+ /** Maximum JSON bytes accepted for one export/import operation. */
120
+ maxBytes: 64 * 1024 * 1024,
121
+ /** Maximum record count accepted from one backup file. */
122
+ maxRecords: 2e5
123
+ };
124
+ function isBackupFileLike(value) {
125
+ if (!isObject(value)) return false;
126
+ if (value["format"] !== BACKUP_FORMAT) return false;
127
+ if (typeof value["formatVersion"] !== "number" || !Number.isSafeInteger(value["formatVersion"])) {
128
+ return false;
129
+ }
130
+ if (value["formatVersion"] > BACKUP_FORMAT_VERSION) return false;
131
+ if (!Array.isArray(value["records"])) return false;
132
+ if (typeof value["recordCount"] !== "number" || !Number.isSafeInteger(value["recordCount"])) {
133
+ return false;
134
+ }
135
+ return value["recordCount"] === value["records"].length;
136
+ }
137
+
138
+ // src/client/api.ts
139
+ async function fetchSummary(request) {
140
+ const params = new URLSearchParams();
141
+ if (request.workspace !== null) params.set("workspace", request.workspace);
142
+ if (request.model !== null) params.set("model", request.model);
143
+ if (request.provider !== null) params.set("provider", request.provider);
144
+ params.set("days", String(request.days));
145
+ const url = `${request.path}/api/summary?${params.toString()}`;
146
+ let response;
147
+ try {
148
+ response = await fetch(url, {
149
+ method: "GET",
150
+ credentials: "same-origin",
151
+ headers: { accept: "application/json" },
152
+ ...request.signal === void 0 ? {} : { signal: request.signal }
153
+ });
154
+ } catch (error) {
155
+ if (error instanceof DOMException && error.name === "AbortError") {
156
+ return { ok: false, message: "\u5DF2\u53D6\u6D88" };
157
+ }
158
+ return { ok: false, message: `\u65E0\u6CD5\u8FDE\u63A5\u7EDF\u8BA1\u670D\u52A1\uFF1A${describe(error)}` };
159
+ }
160
+ if (!response.ok) {
161
+ const detail = await readErrorMessage(response);
162
+ return { ok: false, message: `\u7EDF\u8BA1\u670D\u52A1\u8FD4\u56DE ${String(response.status)}${detail}` };
163
+ }
164
+ try {
165
+ const body = await response.json();
166
+ if (!isSummaryResponseLike(body)) {
167
+ return { ok: false, message: "\u7EDF\u8BA1\u670D\u52A1\u8FD4\u56DE\u4E86\u65E0\u6CD5\u8BC6\u522B\u7684\u6570\u636E" };
168
+ }
169
+ return { ok: true, data: body };
170
+ } catch (error) {
171
+ return { ok: false, message: `\u7EDF\u8BA1\u54CD\u5E94\u89E3\u6790\u5931\u8D25\uFF1A${describe(error)}` };
172
+ }
173
+ }
174
+ async function fetchBackup(path, signal) {
175
+ const result = await requestJson(`${path}/api/export`, { method: "GET" }, signal);
176
+ if (result.ok === false) return result;
177
+ if (!isBackupFileLike(result.body)) {
178
+ return { ok: false, message: "\u5907\u4EFD\u54CD\u5E94\u683C\u5F0F\u65E0\u6CD5\u8BC6\u522B" };
179
+ }
180
+ return { ok: true, data: result.body };
181
+ }
182
+ async function importBackup(path, backup, signal) {
183
+ const result = await requestJson(
184
+ `${path}/api/import`,
185
+ {
186
+ method: "POST",
187
+ headers: { "content-type": "application/json" },
188
+ body: JSON.stringify(backup)
189
+ },
190
+ signal
191
+ );
192
+ if (result.ok === false) return result;
193
+ const body = result.body;
194
+ if (typeof body !== "object" || body === null) return { ok: false, message: "\u5BFC\u5165\u54CD\u5E94\u683C\u5F0F\u65E0\u6CD5\u8BC6\u522B" };
195
+ const value = body;
196
+ if (typeof value["added"] !== "number" || typeof value["duplicates"] !== "number" || typeof value["invalid"] !== "number" || typeof value["total"] !== "number") {
197
+ return { ok: false, message: "\u5BFC\u5165\u54CD\u5E94\u683C\u5F0F\u65E0\u6CD5\u8BC6\u522B" };
198
+ }
199
+ return {
200
+ ok: true,
201
+ data: {
202
+ added: value["added"],
203
+ duplicates: value["duplicates"],
204
+ invalid: value["invalid"],
205
+ total: value["total"],
206
+ unsupported: typeof value["unsupported"] === "number" ? value["unsupported"] : 0
207
+ }
208
+ };
209
+ }
210
+ async function runBackfill(path, dryRun, signal) {
211
+ const result = await requestJson(
212
+ `${path}/api/backfill`,
213
+ {
214
+ method: "POST",
215
+ headers: { "content-type": "application/json" },
216
+ body: JSON.stringify({ dryRun })
217
+ },
218
+ signal
219
+ );
220
+ if (result.ok === false) return result;
221
+ const body = result.body;
222
+ if (typeof body !== "object" || body === null) return { ok: false, message: "\u8865\u5F55\u54CD\u5E94\u683C\u5F0F\u65E0\u6CD5\u8BC6\u522B" };
223
+ const value = body;
224
+ const report = value["report"];
225
+ if (typeof value["dryRun"] !== "boolean" || typeof value["written"] !== "number" || typeof report !== "object" || report === null) {
226
+ return { ok: false, message: "\u8865\u5F55\u54CD\u5E94\u683C\u5F0F\u65E0\u6CD5\u8BC6\u522B" };
227
+ }
228
+ return { ok: true, data: body };
229
+ }
230
+ async function requestJson(url, init, signal) {
231
+ let response;
232
+ try {
233
+ response = await fetch(url, {
234
+ ...init,
235
+ credentials: "same-origin",
236
+ ...signal === void 0 ? {} : { signal }
237
+ });
238
+ } catch (error) {
239
+ if (error instanceof DOMException && error.name === "AbortError") {
240
+ return { ok: false, message: "\u5DF2\u53D6\u6D88" };
241
+ }
242
+ return { ok: false, message: `\u65E0\u6CD5\u8FDE\u63A5\u7EDF\u8BA1\u670D\u52A1\uFF1A${describe(error)}` };
243
+ }
244
+ if (!response.ok) {
245
+ const detail = await readErrorMessage(response);
246
+ return { ok: false, message: `\u7EDF\u8BA1\u670D\u52A1\u8FD4\u56DE ${String(response.status)}${detail}` };
247
+ }
248
+ try {
249
+ return { ok: true, body: await response.json() };
250
+ } catch (error) {
251
+ return { ok: false, message: `\u7EDF\u8BA1\u54CD\u5E94\u89E3\u6790\u5931\u8D25\uFF1A${describe(error)}` };
252
+ }
253
+ }
254
+ async function readErrorMessage(response) {
255
+ try {
256
+ const body = await response.json();
257
+ if (typeof body === "object" && body !== null && "message" in body) {
258
+ const detail = body.message;
259
+ if (typeof detail === "string" && detail.length > 0) return `\uFF1A${detail}`;
260
+ }
261
+ } catch {
262
+ }
263
+ return "";
264
+ }
265
+ function describe(error) {
266
+ return error instanceof Error ? error.message : String(error);
267
+ }
268
+
269
+ // src/client/barchart.tsx
270
+ var import_react2 = require("react");
271
+
272
+ // src/shared/format.ts
273
+ var TOKEN_UNITS = [
274
+ [1e12, "T"],
275
+ [1e9, "B"],
276
+ [1e6, "M"],
277
+ [1e3, "K"]
278
+ ];
279
+ function formatTokens(value) {
280
+ if (!Number.isFinite(value)) return "\u2014";
281
+ const sign = value < 0 ? "-" : "";
282
+ const abs = Math.abs(value);
283
+ for (const [scale, suffix] of TOKEN_UNITS) {
284
+ if (abs >= scale) {
285
+ const scaled = abs / scale;
286
+ const digits = scaled >= 100 ? 0 : scaled >= 10 ? 1 : 2;
287
+ return `${sign}${trimZeros(scaled.toFixed(digits))}${suffix}`;
288
+ }
289
+ }
290
+ return `${sign}${String(Math.round(abs))}`;
291
+ }
292
+ function formatTokensExact(value) {
293
+ if (!Number.isFinite(value)) return "\u2014";
294
+ return Math.round(value).toLocaleString("en-US");
295
+ }
296
+ function formatDuration(milliseconds) {
297
+ if (!Number.isFinite(milliseconds) || milliseconds < 0) return "\u2014";
298
+ if (milliseconds < 1e3) return `${String(Math.round(milliseconds))}ms`;
299
+ const seconds = milliseconds / 1e3;
300
+ if (seconds < 60) return `${trimZeros(seconds.toFixed(seconds < 10 ? 1 : 0))}\u79D2`;
301
+ const wholeMinutes = Math.floor(seconds / 60);
302
+ const restSeconds = Math.round(seconds % 60);
303
+ if (wholeMinutes < 60) {
304
+ return restSeconds === 0 ? `${String(wholeMinutes)}\u5206` : `${String(wholeMinutes)}\u5206${String(restSeconds)}\u79D2`;
305
+ }
306
+ const hours = Math.floor(wholeMinutes / 60);
307
+ const minutes = wholeMinutes % 60;
308
+ return minutes === 0 ? `${String(hours)}\u5C0F\u65F6` : `${String(hours)}\u5C0F\u65F6${String(minutes)}\u5206`;
309
+ }
310
+ function cacheRateAxis(rates) {
311
+ const valid = rates.filter((rate) => Number.isFinite(rate) && rate >= 0 && rate <= 1);
312
+ if (valid.length === 0) return { min: 0, max: 1, ticks: [1, 0.5, 0], clippedBelow: 0 };
313
+ const minimum = Math.min(...valid);
314
+ if (minimum >= 0.95) return { min: 0.95, max: 1, ticks: [1, 0.975, 0.95], clippedBelow: 0 };
315
+ const below95 = valid.filter((rate) => rate < 0.95).length;
316
+ if (below95 / valid.length <= 0.1) {
317
+ return { min: 0.95, max: 1, ticks: [1, 0.975, 0.95], clippedBelow: below95 };
318
+ }
319
+ if (minimum >= 0.9) return { min: 0.9, max: 1, ticks: [1, 0.95, 0.9], clippedBelow: 0 };
320
+ if (minimum >= 0.5) {
321
+ const floor = Math.floor(minimum * 10) / 10;
322
+ return { min: floor, max: 1, ticks: [1, (1 + floor) / 2, floor], clippedBelow: 0 };
323
+ }
324
+ return { min: 0, max: 1, ticks: [1, 0.5, 0], clippedBelow: 0 };
325
+ }
326
+ function trimZeros(value) {
327
+ return value.includes(".") ? value.replace(/\.?0+$/, "") : value;
328
+ }
329
+ function formatMoney(amount, currency) {
330
+ const symbol = currency === "CNY" ? "\xA5" : "$";
331
+ if (!Number.isFinite(amount)) return `${symbol}\u2014`;
332
+ if (amount === 0) return `${symbol}0`;
333
+ const abs = Math.abs(amount);
334
+ const sign = amount < 0 ? "-" : "";
335
+ if (abs >= 1e5) return `${sign}${symbol}${trimZeros((abs / 1e3).toFixed(1))}k`;
336
+ if (abs >= 100) return `${sign}${symbol}${abs.toFixed(0)}`;
337
+ if (abs >= 1) return `${sign}${symbol}${trimZeros(abs.toFixed(2))}`;
338
+ if (abs >= 0.01) return `${sign}${symbol}${trimZeros(abs.toFixed(4))}`;
339
+ return `${sign}${symbol}${abs.toFixed(6)}`;
340
+ }
341
+ function parseDay(key) {
342
+ const parts = key.split("-");
343
+ return { year: Number(parts[0]), month: Number(parts[1]), day: Number(parts[2]) };
344
+ }
345
+ function mondayIndex(key) {
346
+ const { year, month, day } = parseDay(key);
347
+ const jsDay = new Date(year, month - 1, day).getDay();
348
+ return (jsDay + 6) % 7;
349
+ }
350
+ function shiftDay(key, delta) {
351
+ const { year, month, day } = parseDay(key);
352
+ const date = new Date(year, month - 1, day);
353
+ date.setDate(date.getDate() + delta);
354
+ return dayKeyOf(date);
355
+ }
356
+ function dayKeyOf(date) {
357
+ const month = `${date.getMonth() + 1}`.padStart(2, "0");
358
+ const day = `${date.getDate()}`.padStart(2, "0");
359
+ return `${date.getFullYear()}-${month}-${day}`;
360
+ }
361
+ var FALLBACK_BACKUP_TIME_ZONE = "Asia/Shanghai";
362
+ function resolveBackupTimeZone() {
363
+ try {
364
+ const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
365
+ return typeof zone === "string" && zone.trim().length > 0 ? zone.trim() : FALLBACK_BACKUP_TIME_ZONE;
366
+ } catch {
367
+ return FALLBACK_BACKUP_TIME_ZONE;
368
+ }
369
+ }
370
+ function formatBackupTimestamp(now = /* @__PURE__ */ new Date(), timeZone) {
371
+ const requested = timeZone?.trim() ?? "";
372
+ const preferred = requested.length > 0 ? requested : resolveBackupTimeZone();
373
+ try {
374
+ return formatInTimeZone(now, preferred);
375
+ } catch {
376
+ try {
377
+ if (preferred !== FALLBACK_BACKUP_TIME_ZONE) {
378
+ return formatInTimeZone(now, FALLBACK_BACKUP_TIME_ZONE);
379
+ }
380
+ } catch {
381
+ }
382
+ return formatUtcPlus8(now);
383
+ }
384
+ }
385
+ function formatInTimeZone(now, timeZone) {
386
+ const parts = new Intl.DateTimeFormat("en-US", {
387
+ timeZone,
388
+ year: "numeric",
389
+ month: "2-digit",
390
+ day: "2-digit",
391
+ hour: "2-digit",
392
+ minute: "2-digit",
393
+ second: "2-digit",
394
+ hourCycle: "h23"
395
+ }).formatToParts(now);
396
+ const values = new Map(parts.map((part) => [part.type, part.value]));
397
+ return (values.get("year") ?? "") + (values.get("month") ?? "") + (values.get("day") ?? "") + (values.get("hour") ?? "") + (values.get("minute") ?? "") + (values.get("second") ?? "");
398
+ }
399
+ function formatUtcPlus8(now) {
400
+ const shifted = new Date(now.getTime() + 8 * 36e5);
401
+ const pad = (value) => String(value).padStart(2, "0");
402
+ return String(shifted.getUTCFullYear()) + pad(shifted.getUTCMonth() + 1) + pad(shifted.getUTCDate()) + pad(shifted.getUTCHours()) + pad(shifted.getUTCMinutes()) + pad(shifted.getUTCSeconds());
403
+ }
404
+ function mondayOf(key) {
405
+ return shiftDay(key, -mondayIndex(key));
406
+ }
407
+ function shortDayLabel(key) {
408
+ const { month, day } = parseDay(key);
409
+ return `${`${month}`.padStart(2, "0")}-${`${day}`.padStart(2, "0")}`;
410
+ }
411
+ function bucketDaily(points, granularity) {
412
+ if (granularity === "day") {
413
+ return points.map((point) => ({
414
+ key: point.date,
415
+ label: shortDayLabel(point.date),
416
+ longLabel: point.date,
417
+ startDay: point.date,
418
+ endDay: point.date,
419
+ turns: point.turns,
420
+ tokens: point.total,
421
+ tokenBuckets: { ...point.tokens },
422
+ cost: point.cost,
423
+ estimated: point.estimated,
424
+ ...point.estimatedReason === void 0 ? {} : { estimatedReason: point.estimatedReason }
425
+ }));
426
+ }
427
+ const buckets = [];
428
+ let current;
429
+ for (const point of points) {
430
+ const key = granularity === "week" ? mondayOf(point.date) : `${point.date.slice(0, 7)}-01`;
431
+ if (current === void 0 || current.key !== key) {
432
+ current = {
433
+ key,
434
+ label: labelForBucket(key, granularity),
435
+ longLabel: longLabelForBucket(key, granularity, point.date),
436
+ startDay: point.date,
437
+ endDay: point.date,
438
+ turns: 0,
439
+ tokens: 0,
440
+ tokenBuckets: { uncachedInput: 0, cacheRead: 0, cacheWrite: 0, output: 0, reasoning: 0 },
441
+ cost: 0,
442
+ estimated: false
443
+ };
444
+ buckets.push(current);
445
+ }
446
+ current.turns += point.turns;
447
+ current.tokens += point.total;
448
+ current.tokenBuckets.uncachedInput += point.tokens.uncachedInput;
449
+ current.tokenBuckets.cacheRead += point.tokens.cacheRead;
450
+ current.tokenBuckets.cacheWrite += point.tokens.cacheWrite;
451
+ current.tokenBuckets.output += point.tokens.output;
452
+ current.tokenBuckets.reasoning += point.tokens.reasoning;
453
+ current.cost += point.cost;
454
+ if (current.estimated) {
455
+ if (current.estimatedReason !== point.estimatedReason) delete current.estimatedReason;
456
+ } else if (point.estimatedReason !== void 0) {
457
+ current.estimatedReason = point.estimatedReason;
458
+ }
459
+ current.estimated = current.estimated || point.estimated;
460
+ current.endDay = point.date;
461
+ }
462
+ for (const bucket of buckets) {
463
+ bucket.longLabel = longLabelForBucket(bucket.key, granularity, bucket.endDay);
464
+ }
465
+ return buckets;
466
+ }
467
+ function labelForBucket(key, granularity) {
468
+ if (granularity === "month") return key.slice(0, 7);
469
+ if (granularity === "week") return `\u5468 ${shortDayLabel(key)}`;
470
+ return shortDayLabel(key);
471
+ }
472
+ function longLabelForBucket(key, granularity, endDay) {
473
+ if (granularity === "month") {
474
+ const { year, month } = parseDay(key);
475
+ return `${String(year)} \u5E74 ${String(month)} \u6708`;
476
+ }
477
+ if (granularity === "week") {
478
+ return `${key} ~ ${endDay}\uFF08\u5468\uFF09`;
479
+ }
480
+ return key;
481
+ }
482
+ function filterRange(points, from, to) {
483
+ return points.filter((point) => {
484
+ if (from.length > 0 && point.date < from) return false;
485
+ if (to.length > 0 && point.date > to) return false;
486
+ return true;
487
+ });
488
+ }
489
+ function niceAxis(max, tickCount = 4) {
490
+ if (!Number.isFinite(max) || max <= 0) {
491
+ return { bound: 1, ticks: [0, 1] };
492
+ }
493
+ const rough = max / Math.max(1, tickCount);
494
+ const magnitude = 10 ** Math.floor(Math.log10(rough));
495
+ const normalized = rough / magnitude;
496
+ const step = (normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 2.5 ? 2.5 : normalized <= 5 ? 5 : 10) * magnitude;
497
+ const bound = step * Math.max(1, tickCount);
498
+ const ticks = [];
499
+ for (let index = 0; index <= tickCount; index += 1) ticks.push(index * step);
500
+ return { bound, ticks };
501
+ }
502
+ function streaks(points) {
503
+ let longest = 0;
504
+ let running = 0;
505
+ let current = 0;
506
+ for (const point of points) {
507
+ if (point.turns > 0) {
508
+ running += 1;
509
+ longest = Math.max(longest, running);
510
+ } else {
511
+ running = 0;
512
+ }
513
+ }
514
+ for (let index = points.length - 1; index >= 0; index -= 1) {
515
+ const point = points[index];
516
+ if (point === void 0 || point.turns === 0) break;
517
+ current += 1;
518
+ }
519
+ return { current, longest };
520
+ }
521
+ var HEATMAP_SPAN_DAYS = 365;
522
+ var HEATMAP_FETCH_DAYS = HEATMAP_SPAN_DAYS + 6;
523
+ function heatmapWindow(points, anchorDay = dayKeyOf(/* @__PURE__ */ new Date()), spanDays = HEATMAP_SPAN_DAYS, ledgerFirstDay = "") {
524
+ const span = Math.max(1, Math.trunc(spanDays));
525
+ const requestedStart = shiftDay(anchorDay, -(span - 1));
526
+ const start = mondayOf(requestedStart);
527
+ const end = anchorDay;
528
+ const days = daysBetween(start, end) + 1;
529
+ const coverageStart = points[0]?.date ?? "";
530
+ const coverageEnd = points.at(-1)?.date ?? "";
531
+ const drawnStart = coverageStart === "" || coverageStart > start ? coverageStart : start;
532
+ const drawnEnd = coverageEnd === "" || coverageEnd < end ? coverageEnd : end;
533
+ const drawnDays = drawnStart === "" || drawnEnd === "" ? 0 : daysBetween(drawnStart, drawnEnd) + 1;
534
+ const previousEnd = shiftDay(end, -span);
535
+ const backLimit = ledgerFirstDay.length > 0 ? ledgerFirstDay : coverageStart;
536
+ const canPageBack = backLimit.length > 0 && coverageStart !== "" && previousEnd >= backLimit && previousEnd >= coverageStart;
537
+ return {
538
+ start,
539
+ end,
540
+ requestedStart,
541
+ coverageStart,
542
+ coverageEnd,
543
+ drawnStart,
544
+ drawnEnd,
545
+ drawnDays,
546
+ covered: drawnDays === days && drawnStart === start && drawnEnd === end,
547
+ canPageBack,
548
+ canPageForward: coverageEnd !== "" && end < coverageEnd,
549
+ days
550
+ };
551
+ }
552
+ function daysBetween(from, to) {
553
+ return Math.round((Date.parse(`${to}T00:00:00`) - Date.parse(`${from}T00:00:00`)) / 864e5);
554
+ }
555
+ function formatUnitPrice(value) {
556
+ if (!Number.isFinite(value)) return "\u2014";
557
+ if (value === 0) return "0";
558
+ const decimals = Math.abs(value) >= 1 ? 2 : Math.abs(value) >= 0.01 ? 3 : 4;
559
+ const text = value.toFixed(decimals);
560
+ return text.includes(".") ? text.replace(/0+$/, "").replace(/\.$/, "") : text;
561
+ }
562
+ function describeEstimate(reason) {
563
+ if (reason === "unknown-model") return "\u542B\u4F30\u7B97\u4EF7\u683C\uFF1A\u8BE5\u6A21\u578B\u4E0D\u5728\u4EF7\u76EE\u8868\u4E2D\uFF0C\u6309\u515C\u5E95\u6A21\u578B\u8BA1\u4EF7";
564
+ if (reason === "before-first-known-price") return "\u542B\u4F30\u7B97\u4EF7\u683C\uFF1A\u8BE5\u8F6E\u65E9\u4E8E\u4EF7\u683C\u8868\u5DF2\u77E5\u7684\u6700\u65E9\u751F\u6548\u65E5";
565
+ if (reason === "no-price-row") return "\u542B\u4F30\u7B97\u4EF7\u683C\uFF1A\u8BE5\u65F6\u6BB5\u6CA1\u6709\u5BF9\u5E94\u7684\u4EF7\u76EE\u884C";
566
+ return "\u542B\u4F30\u7B97\u4EF7\u683C\uFF08\u6A21\u578B\u672A\u77E5\u6216\u65E9\u4E8E\u4EF7\u683C\u8868\u751F\u6548\u65E5\uFF09";
567
+ }
568
+ function isDayKey(value) {
569
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
570
+ const { year, month, day } = parseDay(value);
571
+ const date = new Date(year, month - 1, day);
572
+ return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
573
+ }
574
+ function resolveRange(preset, end, customFrom, customTo) {
575
+ switch (preset) {
576
+ case "7d":
577
+ return { from: shiftDay(end, -6), to: end };
578
+ case "30d":
579
+ return { from: shiftDay(end, -29), to: end };
580
+ case "90d":
581
+ return { from: shiftDay(end, -89), to: end };
582
+ case "month": {
583
+ const { year, month } = parseDay(end);
584
+ return { from: `${String(year)}-${`${month}`.padStart(2, "0")}-01`, to: end };
585
+ }
586
+ case "all":
587
+ return { from: "", to: "" };
588
+ case "custom": {
589
+ const from = customFrom;
590
+ const to = customTo.length > 0 ? customTo : end;
591
+ if (from.length > 0 && to.length > 0 && from > to) return { from: to, to: from };
592
+ return { from, to };
593
+ }
594
+ }
595
+ }
596
+ function neededSpanDays(firstDay, today = dayKeyOf(/* @__PURE__ */ new Date())) {
597
+ const floor = Math.max(API_LIMITS.defaultDays, HEATMAP_FETCH_DAYS);
598
+ if (firstDay.length === 0) return floor;
599
+ const start = Date.parse(`${firstDay}T00:00:00`);
600
+ const end = Date.parse(`${today}T00:00:00`);
601
+ if (!Number.isFinite(start) || !Number.isFinite(end)) return floor;
602
+ const days = Math.ceil((end - start) / 864e5) + 1;
603
+ return Math.min(API_LIMITS.maxDays, Math.max(floor, days));
604
+ }
605
+ function pageSpanDays(anchorDay, today = dayKeyOf(/* @__PURE__ */ new Date())) {
606
+ const floor = Math.max(API_LIMITS.defaultDays, HEATMAP_FETCH_DAYS);
607
+ if (!isDayKey(anchorDay) || !isDayKey(today)) return floor;
608
+ const offset = daysBetween(anchorDay, today);
609
+ if (offset <= 0) return floor;
610
+ return Math.min(API_LIMITS.maxDays, Math.max(floor, offset + HEATMAP_FETCH_DAYS));
611
+ }
612
+
613
+ // src/client/barchart.tsx
614
+ function BarChart(props) {
615
+ const { buckets, metric, currency, emptyHint } = props;
616
+ const [hover, setHover] = (0, import_react2.useState)(null);
617
+ const values = (0, import_react2.useMemo)(
618
+ () => buckets.map((bucket) => metric === "tokens" ? bucket.tokens : bucket.cost),
619
+ [buckets, metric]
620
+ );
621
+ const axis = (0, import_react2.useMemo)(() => niceAxis(Math.max(0, ...values)), [values]);
622
+ const formatValue = (0, import_react2.useMemo)(
623
+ () => (value) => metric === "tokens" ? formatTokens(value) : formatMoney(value, currency),
624
+ [metric, currency]
625
+ );
626
+ const hasData = values.some((value) => value > 0);
627
+ const labelStride = Math.max(1, Math.ceil(buckets.length / 8));
628
+ const barGap = buckets.length > 120 ? 0 : buckets.length > 60 ? 1 : 2;
629
+ const dense = buckets.length > 120;
630
+ return (0, import_react2.createElement)(
631
+ "div",
632
+ null,
633
+ (0, import_react2.createElement)(
634
+ "div",
635
+ { className: "dsh-tu-plot" },
636
+ (0, import_react2.createElement)(
637
+ "div",
638
+ { className: "dsh-tu-yaxis", "aria-hidden": "true" },
639
+ ...axis.ticks.slice().reverse().map((tick) => (0, import_react2.createElement)("span", { key: `t-${String(tick)}` }, formatValue(tick)))
640
+ ),
641
+ (0, import_react2.createElement)(
642
+ "div",
643
+ { className: "dsh-tu-plot-body" },
644
+ (0, import_react2.createElement)(
645
+ "div",
646
+ {
647
+ className: "dsh-tu-bars",
648
+ "data-metric": metric,
649
+ role: "img",
650
+ "aria-label": `${metric === "tokens" ? "Token" : "\u8D39\u7528"}\u6D88\u8017\u67F1\u72B6\u56FE`,
651
+ style: { "--dsh-tu-bar-gap": `${String(barGap)}px` }
652
+ },
653
+ ...buckets.map((bucket, index) => {
654
+ const value = values[index] ?? 0;
655
+ const percent = axis.bound === 0 ? 0 : value / axis.bound * 100;
656
+ const label = metric === "tokens" ? `${formatTokensExact(value)} tokens` : formatMoney(value, currency);
657
+ return (0, import_react2.createElement)(
658
+ "div",
659
+ {
660
+ key: bucket.key,
661
+ className: "dsh-tu-bar-col",
662
+ onMouseEnter: (event) => {
663
+ setHover({ index, x: event.clientX, y: event.clientY });
664
+ },
665
+ onMouseMove: (event) => {
666
+ setHover({ index, x: event.clientX, y: event.clientY });
667
+ },
668
+ onMouseLeave: () => {
669
+ setHover(null);
670
+ }
671
+ },
672
+ (0, import_react2.createElement)("div", {
673
+ className: "dsh-tu-bar",
674
+ "data-estimated": bucket.estimated ? "true" : "false",
675
+ "data-zero": value === 0 ? "true" : "false",
676
+ style: {
677
+ height: `${String(Math.min(100, Math.max(percent, value > 0 ? 1 : 0)))}%`,
678
+ // The stylesheet's 1px floor keeps sub-pixel positive bars
679
+ // visible, but a zero-value day must be completely blank —
680
+ // otherwise it looks like a tiny real reading.
681
+ minHeight: value > 0 ? "1px" : "0"
682
+ },
683
+ title: `${bucket.longLabel}
684
+ ${label}`
685
+ })
686
+ );
687
+ })
688
+ ),
689
+ (0, import_react2.createElement)(
690
+ "div",
691
+ { className: "dsh-tu-axis" },
692
+ ...buckets.map(
693
+ (bucket, index) => index % labelStride === 0 || index === buckets.length - 1 ? (0, import_react2.createElement)("span", { key: bucket.key }, bucket.label) : null
694
+ ).filter((node) => node !== null)
695
+ ),
696
+ // Hundreds of hairlines fit the row but stop being readable, so say so
697
+ // instead of silently changing the granularity for the user.
698
+ dense ? (0, import_react2.createElement)(
699
+ "div",
700
+ { className: "dsh-tu-chart-hint" },
701
+ `${String(buckets.length)} \u4E2A\u6570\u636E\u70B9\u5DF2\u6392\u6EE1\u6574\u884C\uFF1B\u60F3\u770B\u6E05\u5355\u4E2A\u67F1\u5B50\u53EF\u5207\u5230\u300C\u6309\u5468 / \u6309\u6708\u300D`
702
+ ) : null
703
+ )
704
+ ),
705
+ hasData ? null : (0, import_react2.createElement)("div", { className: "dsh-tu-empty" }, emptyHint),
706
+ hover === null ? null : createTooltip(hover, buckets[hover.index], metric, currency, formatValue)
707
+ );
708
+ }
709
+ function createTooltip(hover, bucket, metric, currency, formatValue) {
710
+ if (bucket === void 0) return null;
711
+ const primary = metric === "tokens" ? `${formatTokensExact(bucket.tokens)} tokens` : formatMoney(bucket.cost, currency);
712
+ const secondary = metric === "tokens" ? formatMoney(bucket.cost, currency) : `${formatTokensExact(bucket.tokens)} tokens`;
713
+ return (0, import_react2.createElement)(
714
+ "div",
715
+ {
716
+ className: "dsh-tu-tooltip",
717
+ style: {
718
+ left: `${String(Math.min(hover.x + 14, Math.max(0, window.innerWidth - 300)))}px`,
719
+ top: `${String(Math.max(8, hover.y - 68))}px`
720
+ }
721
+ },
722
+ (0, import_react2.createElement)("div", null, bucket.longLabel),
723
+ (0, import_react2.createElement)("div", null, `${metric === "tokens" ? "Token" : "\u8D39\u7528"}\uFF1A`, (0, import_react2.createElement)("b", null, primary)),
724
+ (0, import_react2.createElement)("div", null, `${metric === "tokens" ? "\u8D39\u7528" : "Token"}\uFF1A`, (0, import_react2.createElement)("b", null, secondary)),
725
+ (0, import_react2.createElement)("div", null, "\u8F6E\u6B21\uFF1A", (0, import_react2.createElement)("b", null, String(bucket.turns))),
726
+ bucket.estimated ? (0, import_react2.createElement)("div", { className: "dsh-tu-subtle" }, describeEstimate(bucket.estimatedReason)) : null,
727
+ (0, import_react2.createElement)("div", { className: "dsh-tu-subtle" }, `\u65E5\u5747 ${formatValue(bucket.turns > 0 ? (metric === "tokens" ? bucket.tokens : bucket.cost) / daySpan(bucket) : 0)}`)
728
+ );
729
+ }
730
+ function daySpan(bucket) {
731
+ const start = Date.parse(`${bucket.startDay}T00:00:00`);
732
+ const end = Date.parse(`${bucket.endDay}T00:00:00`);
733
+ if (!Number.isFinite(start) || !Number.isFinite(end)) return 1;
734
+ return Math.max(1, Math.round((end - start) / 864e5) + 1);
735
+ }
736
+
737
+ // src/client/sidebar-entry.tsx
738
+ var import_react4 = require("react");
739
+
740
+ // src/client/icon.tsx
741
+ var import_react3 = require("react");
742
+ var BARS = [
743
+ { x: 3.4, y: 15.4, height: 5.6, opacity: 0.5 },
744
+ { x: 10.1, y: 12, height: 9, opacity: 0.72 },
745
+ { x: 16.8, y: 8.6, height: 12.4, opacity: 1 }
746
+ ];
747
+ var TREND_END = { x: 18.7, y: 4.8 };
748
+ function TokenUsageIcon(props) {
749
+ const size = typeof props.size === "number" && props.size > 0 ? props.size : 20;
750
+ const active = props.active === true;
751
+ return (0, import_react3.createElement)(
752
+ "svg",
753
+ {
754
+ width: size,
755
+ height: size,
756
+ viewBox: "0 0 24 24",
757
+ fill: "none",
758
+ // Decorative: in the footer button the accessible name comes from the
759
+ // button's own label, and `role="img"` + `aria-hidden` on the same element
760
+ // is a contradiction.
761
+ "aria-hidden": "true",
762
+ focusable: "false",
763
+ style: { display: "block", opacity: active ? 1 : 0.92 }
764
+ },
765
+ ...BARS.map(
766
+ (bar) => (0, import_react3.createElement)("rect", {
767
+ key: `bar-${String(bar.x)}`,
768
+ x: bar.x,
769
+ y: bar.y,
770
+ width: 3.8,
771
+ height: bar.height,
772
+ rx: 1.2,
773
+ fill: "currentColor",
774
+ opacity: bar.opacity
775
+ })
776
+ ),
777
+ (0, import_react3.createElement)("path", {
778
+ key: "trend",
779
+ d: `M 5.3 12.6 L 12 9 L ${String(TREND_END.x)} ${String(TREND_END.y)}`,
780
+ stroke: "currentColor",
781
+ strokeWidth: 1.7,
782
+ strokeLinecap: "round",
783
+ strokeLinejoin: "round",
784
+ opacity: 0.95
785
+ }),
786
+ (0, import_react3.createElement)("circle", {
787
+ key: "trend-end",
788
+ cx: TREND_END.x,
789
+ cy: TREND_END.y,
790
+ r: 1.9,
791
+ fill: "currentColor"
792
+ })
793
+ );
794
+ }
795
+
796
+ // src/client/sidebar-entry.tsx
797
+ var PANEL_ID = "token-usage";
798
+ var PANEL_LABEL = "Token\u6D88\u8017\u7EDF\u8BA1";
799
+ function TokenUsagePanelIcon(props) {
800
+ return (0, import_react4.createElement)(TokenUsageIcon, { size: props.size, active: props.active });
801
+ }
802
+
803
+ // src/client/insights.tsx
804
+ var import_react5 = require("react");
805
+ var STACK_SERIES = [
806
+ { key: "cacheRead", label: "\u7F13\u5B58\u547D\u4E2D" },
807
+ { key: "uncachedInput", label: "\u7F13\u5B58\u672A\u547D\u4E2D" },
808
+ { key: "cacheWrite", label: "\u7F13\u5B58\u5199\u5165" },
809
+ { key: "output", label: "\u8F93\u51FA" }
810
+ ];
811
+ function tokenTotal(tokens) {
812
+ return tokens.uncachedInput + tokens.cacheRead + tokens.cacheWrite + tokens.output;
813
+ }
814
+ function formatRateTick(rate) {
815
+ const percent = rate * 100;
816
+ return `${Number.isInteger(percent) ? String(percent) : percent.toFixed(1)}%`;
817
+ }
818
+ function CacheCompositionChart(props) {
819
+ const { buckets, emptyHint } = props;
820
+ const [hover, setHover] = (0, import_react5.useState)(null);
821
+ const values = buckets.map((bucket) => tokenTotal(bucket.tokenBuckets));
822
+ const axis = niceAxis(Math.max(0, ...values));
823
+ const hasData = values.some((value) => value > 0);
824
+ const labelStride = Math.max(1, Math.ceil(buckets.length / 8));
825
+ const barGap = buckets.length > 120 ? 0 : buckets.length > 60 ? 1 : 2;
826
+ return (0, import_react5.createElement)(
827
+ "div",
828
+ null,
829
+ (0, import_react5.createElement)(
830
+ "div",
831
+ { className: "dsh-tu-plot" },
832
+ (0, import_react5.createElement)(
833
+ "div",
834
+ { className: "dsh-tu-yaxis", "aria-hidden": "true" },
835
+ ...axis.ticks.slice().reverse().map((tick) => (0, import_react5.createElement)("span", { key: `ct-${String(tick)}` }, formatTokens(tick)))
836
+ ),
837
+ (0, import_react5.createElement)(
838
+ "div",
839
+ { className: "dsh-tu-plot-body" },
840
+ (0, import_react5.createElement)(
841
+ "div",
842
+ {
843
+ className: "dsh-tu-stacked-bars",
844
+ role: "img",
845
+ "aria-label": "Token \u6784\u6210\u5806\u53E0\u67F1\u72B6\u56FE\uFF1A\u7F13\u5B58\u547D\u4E2D\u3001\u672A\u547D\u4E2D\u3001\u5199\u5165\u4E0E\u8F93\u51FA",
846
+ style: { "--dsh-tu-bar-gap": `${String(barGap)}px` }
847
+ },
848
+ ...buckets.map((bucket, index) => {
849
+ const stack = STACK_SERIES.filter((series) => bucket.tokenBuckets[series.key] > 0);
850
+ return (0, import_react5.createElement)(
851
+ "div",
852
+ {
853
+ key: bucket.key,
854
+ className: "dsh-tu-stack-col",
855
+ "data-label": bucket.label,
856
+ onMouseEnter: (event) => {
857
+ setHover({ index, x: event.clientX, y: event.clientY });
858
+ },
859
+ onMouseMove: (event) => {
860
+ setHover({ index, x: event.clientX, y: event.clientY });
861
+ },
862
+ onMouseLeave: () => {
863
+ setHover(null);
864
+ }
865
+ },
866
+ ...stack.map((series) => {
867
+ const value = bucket.tokenBuckets[series.key];
868
+ const percent = axis.bound === 0 ? 0 : value / axis.bound * 100;
869
+ return (0, import_react5.createElement)("div", {
870
+ key: series.key,
871
+ className: "dsh-tu-stack-seg",
872
+ "data-series": series.key,
873
+ style: {
874
+ height: `${String(Math.min(100, percent))}%`,
875
+ minHeight: value > 0 ? "1px" : "0"
876
+ }
877
+ });
878
+ })
879
+ );
880
+ })
881
+ ),
882
+ (0, import_react5.createElement)(
883
+ "div",
884
+ { className: "dsh-tu-axis" },
885
+ ...buckets.map(
886
+ (bucket, index) => index % labelStride === 0 || index === buckets.length - 1 ? (0, import_react5.createElement)("span", { key: bucket.key }, bucket.label) : null
887
+ ).filter((node) => node !== null)
888
+ )
889
+ )
890
+ ),
891
+ hasData ? (0, import_react5.createElement)(
892
+ "div",
893
+ { className: "dsh-tu-stack-legend" },
894
+ ...STACK_SERIES.filter(
895
+ (series) => buckets.some((bucket) => bucket.tokenBuckets[series.key] > 0)
896
+ ).map(
897
+ (series) => (0, import_react5.createElement)(
898
+ "span",
899
+ { key: series.key, className: "dsh-tu-stack-legend-item" },
900
+ (0, import_react5.createElement)("span", { className: "dsh-tu-swatch", "data-series": series.key }),
901
+ series.label
902
+ )
903
+ )
904
+ ) : null,
905
+ hasData ? null : (0, import_react5.createElement)("div", { className: "dsh-tu-empty" }, emptyHint),
906
+ hover === null ? null : createCompositionTooltip(hover, buckets[hover.index])
907
+ );
908
+ }
909
+ function createCompositionTooltip(hover, bucket) {
910
+ if (bucket === void 0) return null;
911
+ const total = tokenTotal(bucket.tokenBuckets);
912
+ return (0, import_react5.createElement)(
913
+ "div",
914
+ {
915
+ className: "dsh-tu-tooltip",
916
+ style: {
917
+ left: `${String(Math.min(hover.x + 14, Math.max(0, window.innerWidth - 300)))}px`,
918
+ top: `${String(Math.max(8, hover.y - 92))}px`
919
+ }
920
+ },
921
+ (0, import_react5.createElement)("div", null, bucket.longLabel),
922
+ (0, import_react5.createElement)(
923
+ "div",
924
+ { className: "dsh-tu-tooltip-head" },
925
+ "\u5408\u8BA1 ",
926
+ (0, import_react5.createElement)("b", null, `${formatTokensExact(total)} tokens`)
927
+ ),
928
+ ...STACK_SERIES.filter((series) => bucket.tokenBuckets[series.key] > 0).map((series) => {
929
+ const value = bucket.tokenBuckets[series.key];
930
+ const share = total === 0 ? 0 : value / total * 100;
931
+ return (0, import_react5.createElement)(
932
+ "div",
933
+ { key: series.key, className: "dsh-tu-tooltip-row" },
934
+ (0, import_react5.createElement)("span", { className: "dsh-tu-swatch", "data-series": series.key }),
935
+ (0, import_react5.createElement)("span", { className: "dsh-tu-tooltip-label" }, series.label),
936
+ (0, import_react5.createElement)("b", null, `${formatTokensExact(value)} (${share.toFixed(1)}%)`)
937
+ );
938
+ }),
939
+ (0, import_react5.createElement)(
940
+ "div",
941
+ { className: "dsh-tu-tooltip-subtle" },
942
+ `\u8F6E\u6B21 ${String(bucket.turns)} \xB7 ${bucket.estimated ? "\u542B\u4F30\u7B97\u4EF7\u683C" : "\u4EF7\u683C\u7CBE\u786E"}`
943
+ )
944
+ );
945
+ }
946
+ function CacheRateLine(props) {
947
+ const { buckets, emptyHint } = props;
948
+ const points = buckets.map((bucket, index) => {
949
+ const input = bucket.tokenBuckets.cacheRead + bucket.tokenBuckets.uncachedInput;
950
+ return input > 0 ? { index, bucket, rate: bucket.tokenBuckets.cacheRead / input } : null;
951
+ }).filter((point) => point !== null);
952
+ const hasData = points.length > 0;
953
+ const axis = cacheRateAxis(points.map((point) => point.rate));
954
+ const span = axis.max - axis.min;
955
+ const coordinates = points.map((point) => {
956
+ const clipped = point.rate < axis.min;
957
+ return {
958
+ ...point,
959
+ clipped,
960
+ x: points.length === 1 ? 50 : point.index / Math.max(1, buckets.length - 1) * 100,
961
+ y: clipped ? 100 : 100 - (span === 0 ? 0 : (point.rate - axis.min) / span * 100)
962
+ };
963
+ });
964
+ const labelStride = Math.max(1, Math.ceil(buckets.length / 8));
965
+ return (0, import_react5.createElement)(
966
+ "div",
967
+ null,
968
+ hasData ? (0, import_react5.createElement)(
969
+ "div",
970
+ { className: "dsh-tu-rate-plot" },
971
+ (0, import_react5.createElement)(
972
+ "div",
973
+ { className: "dsh-tu-rate-yaxis", "aria-hidden": "true" },
974
+ ...axis.ticks.map(
975
+ (tick) => (0, import_react5.createElement)("span", { key: `rate-${String(tick)}` }, formatRateTick(tick))
976
+ )
977
+ ),
978
+ (0, import_react5.createElement)(
979
+ "div",
980
+ { className: "dsh-tu-rate-body" },
981
+ (0, import_react5.createElement)(
982
+ "div",
983
+ { className: "dsh-tu-rate-canvas" },
984
+ (0, import_react5.createElement)(
985
+ "svg",
986
+ {
987
+ className: "dsh-tu-rate-svg",
988
+ viewBox: "0 0 100 100",
989
+ preserveAspectRatio: "none",
990
+ role: "img",
991
+ "aria-label": "\u7F13\u5B58\u547D\u4E2D\u7387\u6298\u7EBF\u56FE"
992
+ },
993
+ (0, import_react5.createElement)("line", {
994
+ x1: 0,
995
+ y1: 50,
996
+ x2: 100,
997
+ y2: 50,
998
+ className: "dsh-tu-rate-grid",
999
+ vectorEffect: "non-scaling-stroke"
1000
+ }),
1001
+ (0, import_react5.createElement)("polyline", {
1002
+ points: coordinates.map((point) => `${point.x},${point.y}`).join(" "),
1003
+ className: "dsh-tu-rate-line",
1004
+ fill: "none",
1005
+ vectorEffect: "non-scaling-stroke"
1006
+ })
1007
+ ),
1008
+ ...coordinates.map(
1009
+ (point) => (0, import_react5.createElement)("span", {
1010
+ key: point.bucket.key,
1011
+ className: point.clipped ? "dsh-tu-rate-point dsh-tu-rate-point-clipped" : "dsh-tu-rate-point",
1012
+ "data-clipped": point.clipped ? "true" : void 0,
1013
+ title: `${point.bucket.longLabel}
1014
+ \u7F13\u5B58\u547D\u4E2D\u7387 ${(point.rate * 100).toFixed(1)}%` + (point.clipped ? "\n\u4F4E\u4E8E\u7EB5\u8F74\u4E0B\u9650\uFF0C\u70B9\u663E\u793A\u5728\u5E95\u90E8" : ""),
1015
+ style: {
1016
+ left: `${String(point.x)}%`,
1017
+ top: `${String(point.y)}%`
1018
+ }
1019
+ })
1020
+ )
1021
+ ),
1022
+ (0, import_react5.createElement)(
1023
+ "div",
1024
+ { className: "dsh-tu-axis" },
1025
+ ...buckets.map(
1026
+ (bucket, index) => index % labelStride === 0 || index === buckets.length - 1 ? (0, import_react5.createElement)("span", { key: bucket.key }, bucket.label) : null
1027
+ ).filter((node) => node !== null)
1028
+ )
1029
+ )
1030
+ ) : (0, import_react5.createElement)("div", { className: "dsh-tu-empty" }, emptyHint)
1031
+ );
1032
+ }
1033
+ var SECTOR_LIMIT = 5;
1034
+ var SECTOR_CENTER = 60;
1035
+ var SECTOR_OUTER = 52;
1036
+ function sectorArcPath(start, end, inner) {
1037
+ const point = (radius, angle) => `${(SECTOR_CENTER + radius * Math.cos(angle)).toFixed(3)} ${(SECTOR_CENTER + radius * Math.sin(angle)).toFixed(3)}`;
1038
+ const large = end - start > Math.PI ? 1 : 0;
1039
+ const outerStart = point(SECTOR_OUTER, start);
1040
+ const outerEnd = point(SECTOR_OUTER, end);
1041
+ if (inner <= 0) {
1042
+ return `M ${String(SECTOR_CENTER)} ${String(SECTOR_CENTER)} L ${outerStart} A ${String(SECTOR_OUTER)} ${String(SECTOR_OUTER)} 0 ${String(large)} 1 ${outerEnd} Z`;
1043
+ }
1044
+ const innerStart = point(inner, start);
1045
+ const innerEnd = point(inner, end);
1046
+ return `M ${outerStart} A ${String(SECTOR_OUTER)} ${String(SECTOR_OUTER)} 0 ${String(large)} 1 ${outerEnd} L ${innerEnd} A ${String(inner)} ${String(inner)} 0 ${String(large)} 0 ${innerStart} Z`;
1047
+ }
1048
+ function SectorChart(props) {
1049
+ const { slices, variant, centerLabel, centerValue, primaryLabel, formatValue, ariaLabel, emptyHint } = props;
1050
+ const [hover, setHover] = (0, import_react5.useState)(null);
1051
+ const positive = slices.filter((slice) => slice.value > 0).sort((left, right) => right.value - left.value);
1052
+ const total = positive.reduce((sum, slice) => sum + slice.value, 0);
1053
+ if (total <= 0) return (0, import_react5.createElement)("div", { className: "dsh-tu-empty" }, emptyHint);
1054
+ const shown = positive.slice(0, SECTOR_LIMIT - 1);
1055
+ const rest = positive.slice(SECTOR_LIMIT - 1);
1056
+ const restValue = rest.reduce((sum, slice) => sum + slice.value, 0);
1057
+ const all = restValue > 0 ? [
1058
+ ...shown,
1059
+ {
1060
+ key: "other",
1061
+ label: `\u5176\u5B83\uFF08${String(rest.length)} \u9879\uFF09`,
1062
+ value: restValue,
1063
+ series: 4,
1064
+ details: [{ label: "\u5206\u7C7B\u6570", value: String(rest.length) }]
1065
+ }
1066
+ ] : shown;
1067
+ const inner = variant === "donut" ? 34 : 0;
1068
+ const gap = all.length > 1 ? Math.min(0.025, Math.PI * 2 * 0.08 / all.length) : 0;
1069
+ let angle = -Math.PI / 2;
1070
+ const arcs = all.map((slice) => {
1071
+ const sweep = slice.value / total * Math.PI * 2;
1072
+ const start = angle + gap / 2;
1073
+ const end = angle + sweep - gap / 2;
1074
+ angle += sweep;
1075
+ return { slice, path: sectorArcPath(start, Math.max(start + 1e-3, end), inner) };
1076
+ });
1077
+ const hovered = hover === null ? void 0 : all[hover.index];
1078
+ const hoverShare = hovered === void 0 ? 0 : hovered.value / total * 100;
1079
+ return (0, import_react5.createElement)(
1080
+ "div",
1081
+ { className: "dsh-tu-sector-chart", "data-variant": variant },
1082
+ (0, import_react5.createElement)(
1083
+ "div",
1084
+ { className: "dsh-tu-sector-canvas" },
1085
+ (0, import_react5.createElement)(
1086
+ "svg",
1087
+ { viewBox: "0 0 120 120", role: "img", "aria-label": ariaLabel },
1088
+ variant === "donut" ? (0, import_react5.createElement)("circle", {
1089
+ cx: SECTOR_CENTER,
1090
+ cy: SECTOR_CENTER,
1091
+ r: (SECTOR_OUTER + inner) / 2,
1092
+ fill: "none",
1093
+ strokeWidth: SECTOR_OUTER - inner,
1094
+ className: "dsh-tu-sector-track"
1095
+ }) : null,
1096
+ ...arcs.map(
1097
+ (arc, index) => (0, import_react5.createElement)("path", {
1098
+ key: arc.slice.key,
1099
+ d: arc.path,
1100
+ className: "dsh-tu-sector-slice",
1101
+ "data-series": String(arc.slice.series),
1102
+ "data-hovered": hover?.index === index ? "true" : "false",
1103
+ onMouseEnter: (event) => {
1104
+ setHover({ index, x: event.clientX, y: event.clientY });
1105
+ },
1106
+ onMouseMove: (event) => {
1107
+ setHover({ index, x: event.clientX, y: event.clientY });
1108
+ },
1109
+ onMouseLeave: () => {
1110
+ setHover(null);
1111
+ },
1112
+ title: `${arc.slice.label}
1113
+ ${primaryLabel} ${formatValue(arc.slice.value)} \xB7 ${(arc.slice.value / total * 100).toFixed(1)}%`
1114
+ })
1115
+ ),
1116
+ variant === "donut" && centerValue !== void 0 ? (0, import_react5.createElement)(
1117
+ "text",
1118
+ { x: SECTOR_CENTER, y: 57, className: "dsh-tu-donut-center-value", textAnchor: "middle" },
1119
+ centerValue
1120
+ ) : null,
1121
+ variant === "donut" && centerLabel !== void 0 ? (0, import_react5.createElement)(
1122
+ "text",
1123
+ { x: SECTOR_CENTER, y: 71, className: "dsh-tu-donut-center-label", textAnchor: "middle" },
1124
+ centerLabel
1125
+ ) : null
1126
+ ),
1127
+ hovered === void 0 ? null : (0, import_react5.createElement)(
1128
+ "div",
1129
+ {
1130
+ className: "dsh-tu-tooltip",
1131
+ style: {
1132
+ left: `${String(Math.min(hover.x + 14, Math.max(0, window.innerWidth - 300)))}px`,
1133
+ top: `${String(Math.max(8, hover.y - 110))}px`
1134
+ }
1135
+ },
1136
+ (0, import_react5.createElement)("div", null, (0, import_react5.createElement)("b", null, hovered.label)),
1137
+ (0, import_react5.createElement)(
1138
+ "div",
1139
+ { className: "dsh-tu-tooltip-head" },
1140
+ `${primaryLabel} `,
1141
+ (0, import_react5.createElement)("b", null, formatValue(hovered.value)),
1142
+ ` \xB7 ${hoverShare.toFixed(1)}%`
1143
+ ),
1144
+ ...hovered.details.map(
1145
+ (detail) => (0, import_react5.createElement)(
1146
+ "div",
1147
+ { key: detail.label, className: "dsh-tu-tooltip-detail" },
1148
+ (0, import_react5.createElement)("span", { className: "dsh-tu-tooltip-label" }, detail.label),
1149
+ (0, import_react5.createElement)("b", null, detail.value)
1150
+ )
1151
+ ),
1152
+ (0, import_react5.createElement)("div", { className: "dsh-tu-tooltip-subtle" }, "\u60AC\u505C\u5176\u5B83\u6247\u5F62\u53EF\u67E5\u770B\u5BF9\u5E94\u5B57\u6BB5")
1153
+ )
1154
+ ),
1155
+ (0, import_react5.createElement)(
1156
+ "div",
1157
+ { className: "dsh-tu-sector-legend" },
1158
+ ...all.map(
1159
+ (slice) => (0, import_react5.createElement)(
1160
+ "span",
1161
+ { key: slice.key, className: "dsh-tu-sector-legend-item" },
1162
+ (0, import_react5.createElement)("span", { className: "dsh-tu-sector-swatch", "data-series": String(slice.series) }),
1163
+ slice.label
1164
+ )
1165
+ )
1166
+ )
1167
+ );
1168
+ }
1169
+ function HBarList(props) {
1170
+ const { items, formatValue, emptyHint } = props;
1171
+ const max = Math.max(1, ...items.map((item) => item.count));
1172
+ const total = items.reduce((sum, item) => sum + item.count, 0);
1173
+ if (total === 0) return (0, import_react5.createElement)("div", { className: "dsh-tu-empty" }, emptyHint);
1174
+ return (0, import_react5.createElement)(
1175
+ "div",
1176
+ { className: "dsh-tu-hbars" },
1177
+ ...items.map(
1178
+ (item) => (0, import_react5.createElement)(
1179
+ "div",
1180
+ { key: item.label, className: "dsh-tu-hbar-row" },
1181
+ (0, import_react5.createElement)("span", { className: "dsh-tu-hbar-label" }, item.label),
1182
+ (0, import_react5.createElement)(
1183
+ "span",
1184
+ { className: "dsh-tu-hbar-track" },
1185
+ (0, import_react5.createElement)("span", {
1186
+ className: "dsh-tu-hbar-fill",
1187
+ style: { width: `${String(item.count / max * 100)}%` }
1188
+ })
1189
+ ),
1190
+ (0, import_react5.createElement)("span", { className: "dsh-tu-hbar-value" }, formatValue(item.count))
1191
+ )
1192
+ )
1193
+ );
1194
+ }
1195
+ function HourActivityChart(props) {
1196
+ const { hours, currency, emptyHint } = props;
1197
+ const maxCalls = Math.max(0, ...hours.map((hour) => hour.calls));
1198
+ const hasData = maxCalls > 0;
1199
+ const labelHours = /* @__PURE__ */ new Set([0, 3, 6, 9, 12, 15, 18, 21]);
1200
+ const pad = (value) => String(value).padStart(2, "0");
1201
+ return (0, import_react5.createElement)(
1202
+ "div",
1203
+ null,
1204
+ hasData ? (0, import_react5.createElement)(
1205
+ "div",
1206
+ { className: "dsh-tu-hour-chart" },
1207
+ (0, import_react5.createElement)(
1208
+ "div",
1209
+ {
1210
+ className: "dsh-tu-hour-bars",
1211
+ role: "img",
1212
+ "aria-label": "24 \u5C0F\u65F6\u6D3B\u8DC3\u65F6\u6BB5\u67F1\u72B6\u56FE\uFF08\u672C\u5730\u65F6\u95F4\uFF09"
1213
+ },
1214
+ ...hours.map((hour) => {
1215
+ const level = hour.calls === 0 ? 0 : Math.max(1, Math.ceil(hour.calls / maxCalls * 4));
1216
+ const height = maxCalls === 0 ? 0 : hour.calls / maxCalls * 100;
1217
+ return (0, import_react5.createElement)(
1218
+ "div",
1219
+ {
1220
+ key: `hour-${String(hour.hour)}`,
1221
+ className: "dsh-tu-hour-col",
1222
+ title: [
1223
+ `${pad(hour.hour)}:00\u2013${pad(hour.hour)}:59`,
1224
+ `\u6A21\u578B\u8C03\u7528 ${String(hour.calls)} \u6B21`,
1225
+ `\u8F6E\u6B21\u5F00\u59CB ${String(hour.turns)} \u6B21`,
1226
+ `Token ${formatTokensExact(hour.tokens)}`,
1227
+ `\u8D39\u7528 ${formatMoney(hour.cost, currency)}`
1228
+ ].join("\n")
1229
+ },
1230
+ (0, import_react5.createElement)("div", {
1231
+ className: "dsh-tu-hour-bar",
1232
+ "data-level": String(level),
1233
+ "data-hour": String(hour.hour),
1234
+ style: {
1235
+ height: `${String(Math.min(100, height))}%`,
1236
+ minHeight: hour.calls > 0 ? "2px" : "0"
1237
+ }
1238
+ })
1239
+ );
1240
+ })
1241
+ ),
1242
+ (0, import_react5.createElement)(
1243
+ "div",
1244
+ { className: "dsh-tu-hour-axis" },
1245
+ ...hours.map(
1246
+ (hour) => (0, import_react5.createElement)(
1247
+ "span",
1248
+ { key: `label-${String(hour.hour)}` },
1249
+ labelHours.has(hour.hour) ? pad(hour.hour) : ""
1250
+ )
1251
+ )
1252
+ )
1253
+ ) : (0, import_react5.createElement)("div", { className: "dsh-tu-empty" }, emptyHint)
1254
+ );
1255
+ }
1256
+
1257
+ // src/client/heatmap.tsx
1258
+ var import_react6 = require("react");
1259
+ var WEEKDAY_LABELS = ["\u5468\u4E00", "\u5468\u4E8C", "\u5468\u4E09", "\u5468\u56DB", "\u5468\u4E94", "\u5468\u516D", "\u5468\u65E5"];
1260
+ function Heatmap(props) {
1261
+ const { points, metric, currency, range, firstDay } = props;
1262
+ const [hover, setHover] = (0, import_react6.useState)(null);
1263
+ const model = (0, import_react6.useMemo)(
1264
+ () => buildModel(points, metric, range, firstDay),
1265
+ [points, metric, range, firstDay]
1266
+ );
1267
+ return (0, import_react6.createElement)(
1268
+ "div",
1269
+ null,
1270
+ (0, import_react6.createElement)(
1271
+ "div",
1272
+ {
1273
+ className: "dsh-tu-heat",
1274
+ // The cell size is computed from this count and the container width in
1275
+ // CSS, so the label rows and the day rows cannot disagree about it.
1276
+ // Floored at 1: the count divides a length in CSS, and a literal 0 would
1277
+ // make the declaration invalid at computed-value time — which no
1278
+ // fallback rescues, collapsing every row to zero height.
1279
+ style: { "--dsh-tu-cols": String(Math.max(1, model.weeks.length)) }
1280
+ },
1281
+ (0, import_react6.createElement)(
1282
+ "div",
1283
+ { className: "dsh-tu-heat-weekdays", "aria-hidden": "true" },
1284
+ ...WEEKDAY_LABELS.map((label) => (0, import_react6.createElement)("span", { key: label }, label))
1285
+ ),
1286
+ (0, import_react6.createElement)(
1287
+ "div",
1288
+ { className: "dsh-tu-heat-scroll" },
1289
+ (0, import_react6.createElement)(
1290
+ "div",
1291
+ {
1292
+ className: "dsh-tu-heat-grid",
1293
+ role: "img",
1294
+ // The grid is one image for assistive tech (371 cells would be noise);
1295
+ // the name states which days it actually covers.
1296
+ "aria-label": `\u6BCF\u65E5\u6D88\u8017\u65E5\u5386\u70ED\u529B\u56FE\uFF1A${range.drawnStart || "\u2014"} \u81F3 ${range.drawnEnd || "\u2014"}`
1297
+ },
1298
+ ...model.weeks.map(
1299
+ (week) => (0, import_react6.createElement)(
1300
+ "div",
1301
+ { key: week.key, className: "dsh-tu-heat-col" },
1302
+ (0, import_react6.createElement)(
1303
+ "div",
1304
+ { className: "dsh-tu-heat-month" },
1305
+ week.monthLabel === void 0 ? null : (0, import_react6.createElement)("span", null, week.monthLabel)
1306
+ ),
1307
+ (0, import_react6.createElement)(
1308
+ "div",
1309
+ { className: "dsh-tu-heat-days" },
1310
+ ...week.cells.map(
1311
+ (cell) => (0, import_react6.createElement)("div", {
1312
+ key: cell.date,
1313
+ className: "dsh-tu-cell",
1314
+ // The day itself, so a test (or a future feature) can talk about
1315
+ // cells by date instead of by position.
1316
+ "data-date": cell.date,
1317
+ "data-level": cell.outside ? void 0 : String(cell.level),
1318
+ "data-outside": cell.outside ? "true" : void 0,
1319
+ "data-today": cell.date === model.today ? "true" : void 0,
1320
+ title: cell.outside ? void 0 : cell.point === void 0 ? `${cell.date}\u3000\u65E0\u8BB0\u5F55` : `${cell.date}${firstDay !== "" && cell.date < firstDay ? "\uFF08\u65E9\u4E8E\u8D26\u672C\u8D77\u70B9\uFF09" : ""}\u3000${formatTokensExact(cell.point.total)} tokens\u3000${formatMoney(cell.point.cost, currency)}\u3000${String(cell.point.turns)} \u8F6E`,
1321
+ onMouseEnter: (event) => {
1322
+ if (cell.outside) return;
1323
+ setHover({ date: cell.date, x: event.clientX, y: event.clientY });
1324
+ },
1325
+ onMouseLeave: () => {
1326
+ setHover(null);
1327
+ }
1328
+ })
1329
+ )
1330
+ )
1331
+ )
1332
+ )
1333
+ )
1334
+ )
1335
+ ),
1336
+ (0, import_react6.createElement)(
1337
+ "div",
1338
+ { className: "dsh-tu-legend" },
1339
+ (0, import_react6.createElement)("span", null, "\u5C11"),
1340
+ ...[0, 1, 2, 3, 4].map(
1341
+ (level) => (0, import_react6.createElement)("div", {
1342
+ key: `l-${String(level)}`,
1343
+ className: "dsh-tu-cell",
1344
+ "data-level": String(level)
1345
+ })
1346
+ ),
1347
+ (0, import_react6.createElement)("span", null, "\u591A"),
1348
+ (0, import_react6.createElement)(
1349
+ "span",
1350
+ { style: { marginLeft: "10px" } },
1351
+ model.max > 0 ? `\u6700\u6DF1\u8272 \u2248 ${metric === "tokens" ? formatTokens(model.scaleMax) : formatMoney(model.scaleMax, currency)} / \u5929` : "\u6682\u65E0\u6570\u636E"
1352
+ )
1353
+ ),
1354
+ hover === null ? null : createTooltip2(hover, points, currency)
1355
+ );
1356
+ }
1357
+ function buildModel(points, metric, range, firstDay) {
1358
+ const byDate = /* @__PURE__ */ new Map();
1359
+ for (const point of points) byDate.set(point.date, point);
1360
+ const today = dayKeyOf(/* @__PURE__ */ new Date());
1361
+ const start = range.start;
1362
+ const end = range.end;
1363
+ const coverageStart = range.coverageStart;
1364
+ const coverageEnd = range.coverageEnd;
1365
+ const values = points.filter((point) => point.date >= start && point.date <= end).map((point) => metric === "tokens" ? point.total : point.cost).filter((value) => value > 0).sort((a, b) => a - b);
1366
+ const max = values.at(-1) ?? 0;
1367
+ const scaleMax = quantile(values, 0.9);
1368
+ const gridStart = range.drawnStart === "" ? start : mondayOf(range.drawnStart);
1369
+ const weeks = [];
1370
+ let cursor = gridStart;
1371
+ let previousMonth = "";
1372
+ while (cursor <= end) {
1373
+ const cells = [];
1374
+ for (let offset = 0; offset < 7; offset += 1) {
1375
+ const date = shiftDay(cursor, offset);
1376
+ const unfetched = coverageStart === "" || date < coverageStart || coverageEnd !== "" && date > coverageEnd;
1377
+ if (date > end || unfetched) {
1378
+ cells.push({ date, point: void 0, level: 0, outside: true });
1379
+ continue;
1380
+ }
1381
+ const point = byDate.get(date);
1382
+ const value = point === void 0 ? 0 : metric === "tokens" ? point.total : point.cost;
1383
+ cells.push({ date, point, level: levelOf(value, scaleMax), outside: false });
1384
+ }
1385
+ const month = cursor.slice(0, 7);
1386
+ const monthLabel = month === previousMonth ? void 0 : `${String(Number(month.slice(5, 7)))}\u6708`;
1387
+ previousMonth = month;
1388
+ weeks.push({ key: cursor, monthLabel, cells });
1389
+ cursor = shiftDay(cursor, 7);
1390
+ }
1391
+ return { weeks, scaleMax, max, today };
1392
+ }
1393
+ function levelOf(value, scaleMax) {
1394
+ if (value <= 0) return 0;
1395
+ if (scaleMax <= 0) return 1;
1396
+ const ratio = value / scaleMax;
1397
+ if (ratio <= 0.25) return 1;
1398
+ if (ratio <= 0.5) return 2;
1399
+ if (ratio <= 0.8) return 3;
1400
+ return 4;
1401
+ }
1402
+ function quantile(sorted, fraction) {
1403
+ if (sorted.length === 0) return 0;
1404
+ const index = Math.min(sorted.length - 1, Math.max(0, Math.ceil(fraction * sorted.length) - 1));
1405
+ return sorted[index] ?? 0;
1406
+ }
1407
+ function createTooltip2(hover, points, currency) {
1408
+ const point = points.find((candidate) => candidate.date === hover.date);
1409
+ if (point === void 0) return null;
1410
+ return (0, import_react6.createElement)(
1411
+ "div",
1412
+ {
1413
+ className: "dsh-tu-tooltip",
1414
+ style: {
1415
+ left: `${String(Math.min(hover.x + 14, Math.max(0, window.innerWidth - 300)))}px`,
1416
+ top: `${String(Math.max(8, hover.y - 84))}px`
1417
+ }
1418
+ },
1419
+ (0, import_react6.createElement)("div", null, point.date),
1420
+ (0, import_react6.createElement)("div", null, "Token\uFF1A", (0, import_react6.createElement)("b", null, formatTokensExact(point.total))),
1421
+ (0, import_react6.createElement)("div", null, "\u8D39\u7528\uFF1A", (0, import_react6.createElement)("b", null, formatMoney(point.cost, currency))),
1422
+ (0, import_react6.createElement)("div", null, "\u8F6E\u6B21\uFF1A", (0, import_react6.createElement)("b", null, String(point.turns))),
1423
+ (0, import_react6.createElement)(
1424
+ "div",
1425
+ { className: "dsh-tu-subtle" },
1426
+ `\u547D\u4E2D\u7F13\u5B58 ${formatTokens(point.tokens.cacheRead)} / \u672A\u547D\u4E2D ${formatTokens(point.tokens.uncachedInput)} / \u8F93\u51FA ${formatTokens(point.tokens.output)}`
1427
+ )
1428
+ );
1429
+ }
1430
+
1431
+ // src/client/dashboard.tsx
1432
+ var API_PATH = "/dsh-token-usage";
1433
+ var PRESETS = [
1434
+ { id: "7d", label: "\u8FD1 7 \u5929" },
1435
+ { id: "30d", label: "\u8FD1 30 \u5929" },
1436
+ { id: "90d", label: "\u8FD1 90 \u5929" },
1437
+ { id: "month", label: "\u672C\u6708" },
1438
+ { id: "all", label: "\u5168\u90E8" },
1439
+ { id: "custom", label: "\u81EA\u5B9A\u4E49" }
1440
+ ];
1441
+ var GRANULARITIES = [
1442
+ { id: "day", label: "\u6309\u5929" },
1443
+ { id: "week", label: "\u6309\u5468" },
1444
+ { id: "month", label: "\u6309\u6708" }
1445
+ ];
1446
+ function TokenUsageDashboard(props) {
1447
+ const onSelect = props.onSelect;
1448
+ const [data, setData] = (0, import_react7.useState)(null);
1449
+ const [error, setError] = (0, import_react7.useState)(null);
1450
+ const [loading, setLoading] = (0, import_react7.useState)(true);
1451
+ const [reloadKey, setReloadKey] = (0, import_react7.useState)(0);
1452
+ const [workspace, setWorkspace] = (0, import_react7.useState)(null);
1453
+ const [model, setModel] = (0, import_react7.useState)(null);
1454
+ const [provider, setProvider] = (0, import_react7.useState)(null);
1455
+ const [granularity, setGranularity] = (0, import_react7.useState)("day");
1456
+ const [preset, setPreset] = (0, import_react7.useState)("30d");
1457
+ const [customFrom, setCustomFrom] = (0, import_react7.useState)("");
1458
+ const [customTo, setCustomTo] = (0, import_react7.useState)("");
1459
+ const [pricingHover, setPricingHover] = (0, import_react7.useState)(false);
1460
+ const [pricingPinned, setPricingPinned] = (0, import_react7.useState)(false);
1461
+ const [panelInfo, setPanelInfo] = (0, import_react7.useState)(null);
1462
+ const [toolPanel, setToolPanel] = (0, import_react7.useState)(null);
1463
+ const [toolBusy, setToolBusy] = (0, import_react7.useState)(false);
1464
+ const [toolNotice, setToolNotice] = (0, import_react7.useState)(null);
1465
+ const [dismissedHealthKey, setDismissedHealthKey] = (0, import_react7.useState)(null);
1466
+ const fileInputRef = (0, import_react7.useRef)(null);
1467
+ const [heatAnchor, setHeatAnchor] = (0, import_react7.useState)("");
1468
+ (0, import_react7.useEffect)(() => {
1469
+ if (!pricingPinned) return void 0;
1470
+ const onPointerDown = (event) => {
1471
+ const target = event.target;
1472
+ if (target instanceof Element && target.closest(".dsh-tu-anchor") !== null) return;
1473
+ setPricingPinned(false);
1474
+ };
1475
+ document.addEventListener("pointerdown", onPointerDown);
1476
+ return () => {
1477
+ document.removeEventListener("pointerdown", onPointerDown);
1478
+ };
1479
+ }, [pricingPinned]);
1480
+ (0, import_react7.useEffect)(() => {
1481
+ if (panelInfo === null) return void 0;
1482
+ const onPointerDown = (event) => {
1483
+ const target = event.target;
1484
+ if (target instanceof Element && target.closest(".dsh-tu-panel-info") !== null) return;
1485
+ setPanelInfo(null);
1486
+ };
1487
+ document.addEventListener("pointerdown", onPointerDown);
1488
+ return () => {
1489
+ document.removeEventListener("pointerdown", onPointerDown);
1490
+ };
1491
+ }, [panelInfo]);
1492
+ const [spanDays, setSpanDays] = (0, import_react7.useState)(HEATMAP_FETCH_DAYS);
1493
+ const today = dayKeyOf(/* @__PURE__ */ new Date());
1494
+ const heatEnd = heatAnchor === "" ? today : heatAnchor;
1495
+ const requestDays = (0, import_react7.useMemo)(
1496
+ () => Math.max(spanDays, pageSpanDays(heatEnd, today)),
1497
+ [spanDays, heatEnd, today]
1498
+ );
1499
+ (0, import_react7.useEffect)(() => {
1500
+ const controller = new AbortController();
1501
+ let cancelled = false;
1502
+ setLoading(true);
1503
+ void fetchSummary({
1504
+ path: API_PATH,
1505
+ workspace,
1506
+ model,
1507
+ provider,
1508
+ days: requestDays,
1509
+ signal: controller.signal
1510
+ }).then((result) => {
1511
+ if (cancelled) return;
1512
+ setLoading(false);
1513
+ if (result.ok) {
1514
+ setError(null);
1515
+ setData(result.data);
1516
+ const needed = neededSpanDays(result.data.facets.firstDay);
1517
+ if (needed > spanDays) setSpanDays(needed);
1518
+ } else {
1519
+ setError(result.message);
1520
+ }
1521
+ });
1522
+ return () => {
1523
+ cancelled = true;
1524
+ controller.abort();
1525
+ };
1526
+ }, [workspace, model, provider, requestDays, spanDays, reloadKey]);
1527
+ (0, import_react7.useEffect)(() => {
1528
+ if (data === null || workspace === null) return;
1529
+ const known = data.facets.workspaces.some(
1530
+ (facet) => facet.key === workspace || (facet.paths ?? []).some((path) => path.workspace === workspace)
1531
+ );
1532
+ if (!known) setWorkspace(null);
1533
+ }, [data, workspace]);
1534
+ const healthKey = data === null ? "" : healthNoticeKey(data.health);
1535
+ (0, import_react7.useEffect)(() => {
1536
+ if (dismissedHealthKey !== null && dismissedHealthKey !== healthKey) {
1537
+ setDismissedHealthKey(null);
1538
+ }
1539
+ }, [dismissedHealthKey, healthKey]);
1540
+ const lastDay = data?.facets.lastDay ?? "";
1541
+ const firstDayFacet = isDayKey(data?.facets.firstDay ?? "") ? data?.facets.firstDay ?? "" : "";
1542
+ const rangeEnd = isDayKey(lastDay) && lastDay > today ? lastDay : today;
1543
+ const workspaceFacets = data?.facets.workspaces ?? [];
1544
+ const workspaceIsFacetKey = workspace !== null && workspaceFacets.some((facet) => facet.key === workspace);
1545
+ const workspaceIsRawPath = workspace !== null && workspaceFacets.some(
1546
+ (facet) => (facet.paths ?? []).some((path) => path.workspace === workspace)
1547
+ );
1548
+ const { from, to } = (0, import_react7.useMemo)(
1549
+ () => resolveRange(preset, rangeEnd, customFrom, customTo),
1550
+ [preset, rangeEnd, customFrom, customTo]
1551
+ );
1552
+ const daily = data?.daily ?? [];
1553
+ const filteredDaily = (0, import_react7.useMemo)(() => filterRange(daily, from, to), [daily, from, to]);
1554
+ const buckets = (0, import_react7.useMemo)(
1555
+ () => bucketDaily(filteredDaily, granularity),
1556
+ [filteredDaily, granularity]
1557
+ );
1558
+ const rangeStats = (0, import_react7.useMemo)(() => {
1559
+ let tokens = 0;
1560
+ let cost = 0;
1561
+ let turns = 0;
1562
+ for (const point of filteredDaily) {
1563
+ tokens += point.total;
1564
+ cost += point.cost;
1565
+ turns += point.turns;
1566
+ }
1567
+ return { tokens, cost, turns };
1568
+ }, [filteredDaily]);
1569
+ const streak = (0, import_react7.useMemo)(() => streaks(filteredDaily), [filteredDaily]);
1570
+ const currency = data?.currency ?? "CNY";
1571
+ const analytics = data?.analytics;
1572
+ const rangeTokens = (0, import_react7.useMemo)(() => {
1573
+ const sum = { uncachedInput: 0, cacheRead: 0, cacheWrite: 0, output: 0, reasoning: 0 };
1574
+ for (const point of filteredDaily) {
1575
+ sum.uncachedInput += point.tokens.uncachedInput;
1576
+ sum.cacheRead += point.tokens.cacheRead;
1577
+ sum.cacheWrite += point.tokens.cacheWrite;
1578
+ sum.output += point.tokens.output;
1579
+ sum.reasoning += point.tokens.reasoning;
1580
+ }
1581
+ return sum;
1582
+ }, [filteredDaily]);
1583
+ const agents = analytics?.agents ?? [];
1584
+ const agentColorOrder = [...agents].sort((left, right) => right.cost - left.cost);
1585
+ const agentSeries = new Map(agentColorOrder.map((agent, index) => [agent.key, index % 5]));
1586
+ const agentCacheRate = (agent) => {
1587
+ const input = agent.cacheRead + agent.uncachedInput;
1588
+ return input > 0 ? `${(agent.cacheRead / input * 100).toFixed(1)}%` : "\u2014";
1589
+ };
1590
+ const agentCost = agents.reduce((sum, agent) => sum + agent.cost, 0);
1591
+ const agentTurns = agents.reduce((sum, agent) => sum + agent.turns, 0);
1592
+ const agentCostSlices = agents.filter((agent) => agent.cost > 0).map((agent) => ({
1593
+ key: `cost-${agent.key}`,
1594
+ label: agent.label,
1595
+ value: agent.cost,
1596
+ series: agentSeries.get(agent.key) ?? 0,
1597
+ details: [
1598
+ { label: "\u8F6E\u6B21", value: formatCount(agent.turns) },
1599
+ { label: "\u8C03\u7528", value: formatCount(agent.calls) },
1600
+ { label: "Token", value: formatTokens(agent.tokens) },
1601
+ { label: "\u7F13\u5B58\u547D\u4E2D", value: agentCacheRate(agent) }
1602
+ ]
1603
+ }));
1604
+ const agentTurnSlices = agents.filter((agent) => agent.turns > 0).map((agent) => ({
1605
+ key: `turn-${agent.key}`,
1606
+ label: agent.label,
1607
+ value: agent.turns,
1608
+ series: agentSeries.get(agent.key) ?? 0,
1609
+ details: [
1610
+ { label: "\u8C03\u7528", value: formatCount(agent.calls) },
1611
+ { label: "Token", value: formatTokens(agent.tokens) },
1612
+ { label: "\u8D39\u7528", value: formatMoney(agent.cost, currency) },
1613
+ { label: "\u7F13\u5B58\u547D\u4E2D", value: agentCacheRate(agent) }
1614
+ ]
1615
+ }));
1616
+ const windowSeries = { peak: 1, "off-peak": 2, unknown: 4 };
1617
+ const windowSlices = (analytics?.windows ?? []).filter((row) => row.calls > 0).map((row) => ({
1618
+ key: `window-${row.key}`,
1619
+ label: row.label,
1620
+ value: row.calls,
1621
+ series: windowSeries[row.key] ?? 4,
1622
+ details: [
1623
+ { label: "Token", value: formatTokens(row.tokens) },
1624
+ { label: "\u8D39\u7528", value: formatMoney(row.cost, currency) }
1625
+ ]
1626
+ }));
1627
+ const windowCalls = windowSlices.reduce((sum, slice) => sum + slice.value, 0);
1628
+ const cacheRates = buckets.map((bucket) => {
1629
+ const input = bucket.tokenBuckets.cacheRead + bucket.tokenBuckets.uncachedInput;
1630
+ return input > 0 ? bucket.tokenBuckets.cacheRead / input : null;
1631
+ }).filter((rate) => rate !== null);
1632
+ const cacheAxis = cacheRateAxis(cacheRates);
1633
+ const heatRange = (0, import_react7.useMemo)(
1634
+ () => heatmapWindow(daily, heatEnd, HEATMAP_SPAN_DAYS, firstDayFacet),
1635
+ [daily, heatEnd, firstDayFacet]
1636
+ );
1637
+ const pageHeat = (0, import_react7.useCallback)(
1638
+ (deltaDays) => {
1639
+ const next = shiftDay(heatEnd, deltaDays);
1640
+ const newest = heatRange.coverageEnd;
1641
+ setHeatAnchor(newest !== "" && next > newest ? newest : next);
1642
+ },
1643
+ [heatEnd, heatRange.coverageEnd]
1644
+ );
1645
+ const pageDaily = (0, import_react7.useMemo)(
1646
+ () => heatRange.drawnStart === "" || heatRange.drawnEnd === "" ? [] : filterRange(daily, heatRange.drawnStart, heatRange.drawnEnd),
1647
+ [daily, heatRange.drawnStart, heatRange.drawnEnd]
1648
+ );
1649
+ const onReload = (0, import_react7.useCallback)(() => {
1650
+ setReloadKey((value) => value + 1);
1651
+ }, []);
1652
+ const closeTools = () => {
1653
+ setToolPanel(null);
1654
+ setToolNotice(null);
1655
+ };
1656
+ const handleExport = async () => {
1657
+ setToolBusy(true);
1658
+ setToolNotice({ kind: "info", text: "\u6B63\u5728\u5BFC\u51FA\u5168\u90E8\u6570\u636E\u2026" });
1659
+ try {
1660
+ const result = await fetchBackup(API_PATH);
1661
+ if (!result.ok) {
1662
+ setToolNotice({ kind: "error", text: result.message });
1663
+ return;
1664
+ }
1665
+ downloadBackup(result.data);
1666
+ setToolNotice({ kind: "success", text: `\u5DF2\u5BFC\u51FA ${String(result.data.recordCount)} \u6761\u8BB0\u5F55` });
1667
+ } finally {
1668
+ setToolBusy(false);
1669
+ }
1670
+ };
1671
+ const handlePickImport = async (event) => {
1672
+ const file = event.target.files?.[0];
1673
+ event.target.value = "";
1674
+ if (file === void 0) return;
1675
+ setToolNotice(null);
1676
+ if (file.size > BACKUP_LIMITS.maxBytes) {
1677
+ setToolNotice({ kind: "error", text: "\u6587\u4EF6\u8D85\u8FC7 64 MiB\uFF0C\u65E0\u6CD5\u5BFC\u5165" });
1678
+ return;
1679
+ }
1680
+ try {
1681
+ const parsed = JSON.parse(await file.text());
1682
+ if (!isBackupFileLike(parsed)) {
1683
+ setToolNotice({ kind: "error", text: "\u4E0D\u662F\u672C\u63D2\u4EF6\u5BFC\u51FA\u7684\u5907\u4EFD\u6587\u4EF6\uFF0C\u6216\u6587\u4EF6\u5DF2\u635F\u574F" });
1684
+ return;
1685
+ }
1686
+ setToolPanel({ kind: "import", backup: parsed, fileName: file.name });
1687
+ } catch {
1688
+ setToolNotice({ kind: "error", text: "\u5907\u4EFD\u6587\u4EF6\u4E0D\u662F\u5408\u6CD5 JSON" });
1689
+ }
1690
+ };
1691
+ const handleConfirmImport = async () => {
1692
+ if (toolPanel?.kind !== "import") return;
1693
+ const panel = toolPanel;
1694
+ setToolBusy(true);
1695
+ setToolNotice({ kind: "info", text: "\u6B63\u5728\u5BFC\u5165\uFF0C\u5DF2\u5B58\u5728\u7684\u8BB0\u5F55\u4F1A\u88AB\u8DF3\u8FC7\u2026" });
1696
+ try {
1697
+ const result = await importBackup(API_PATH, panel.backup);
1698
+ if (!result.ok) {
1699
+ setToolNotice({ kind: "error", text: result.message });
1700
+ return;
1701
+ }
1702
+ setToolNotice({
1703
+ kind: "success",
1704
+ text: `\u5DF2\u5BFC\u5165 ${String(result.data.added)} \u6761\uFF1B\u8DF3\u8FC7\u91CD\u590D ${String(result.data.duplicates)} \u6761`
1705
+ });
1706
+ setToolPanel(null);
1707
+ onReload();
1708
+ } finally {
1709
+ setToolBusy(false);
1710
+ }
1711
+ };
1712
+ const handleScanBackfill = async () => {
1713
+ setToolBusy(true);
1714
+ setToolNotice({ kind: "info", text: "\u6B63\u5728\u626B\u63CF\u4F1A\u8BDD\u65E5\u5FD7\u2026" });
1715
+ try {
1716
+ const result = await runBackfill(API_PATH, true);
1717
+ if (!result.ok) {
1718
+ setToolNotice({ kind: "error", text: result.message });
1719
+ return;
1720
+ }
1721
+ setToolPanel({ kind: "backfill", preview: result.data });
1722
+ } finally {
1723
+ setToolBusy(false);
1724
+ }
1725
+ };
1726
+ const handleConfirmBackfill = async () => {
1727
+ if (toolPanel?.kind !== "backfill") return;
1728
+ setToolBusy(true);
1729
+ setToolNotice({ kind: "info", text: "\u6B63\u5728\u8865\u5F55\uFF0C\u53EA\u8FFD\u52A0\u7F3A\u5931\u8BB0\u5F55\u2026" });
1730
+ try {
1731
+ const result = await runBackfill(API_PATH, false);
1732
+ if (!result.ok) {
1733
+ setToolNotice({ kind: "error", text: result.message });
1734
+ return;
1735
+ }
1736
+ const count = result.data.written;
1737
+ setToolNotice({
1738
+ kind: "success",
1739
+ text: count === 0 ? "\u6CA1\u6709\u9700\u8981\u8865\u5F55\u7684\u8BB0\u5F55" : `\u5DF2\u8865\u5F55 ${String(count)} \u6761\u8BB0\u5F55`
1740
+ });
1741
+ setToolPanel(null);
1742
+ onReload();
1743
+ } finally {
1744
+ setToolBusy(false);
1745
+ }
1746
+ };
1747
+ const allModelFacets = data?.facets.models ?? [];
1748
+ const modelFacets = provider === null ? allModelFacets : allModelFacets.filter((facet) => facet.provider === provider);
1749
+ return (0, import_react7.createElement)(
1750
+ "div",
1751
+ { className: "dsh-tu-root" },
1752
+ (0, import_react7.createElement)(
1753
+ "div",
1754
+ { className: "dsh-tu-shell" },
1755
+ (0, import_react7.createElement)(
1756
+ "div",
1757
+ { className: "dsh-tu-header" },
1758
+ (0, import_react7.createElement)("h1", { className: "dsh-tu-title" }, PANEL_LABEL),
1759
+ data === null ? null : (0, import_react7.createElement)(
1760
+ "span",
1761
+ { className: "dsh-tu-version", title: "\u5F53\u524D\u63D2\u4EF6\u7248\u672C" },
1762
+ `v${data.pluginVersion}`
1763
+ ),
1764
+ (0, import_react7.createElement)(
1765
+ "span",
1766
+ { className: "dsh-tu-subtle" },
1767
+ data === null ? loading ? "\u6B63\u5728\u8BFB\u53D6\u672C\u5730\u8D26\u672C\u2026" : "\u672A\u8BFB\u53D6\u5230\u6570\u636E\uFF0C\u8BF7\u70B9\u5237\u65B0\u91CD\u8BD5" : `\u8D26\u672C ${String(data.facets.records)} \u6761 \xB7 ${data.facets.firstDay || "\u2014"} ~ ${data.facets.lastDay || "\u2014"}`
1768
+ ),
1769
+ // The spinning glyph is suppressed under `prefers-reduced-motion`, so the
1770
+ // busy state also gets a word — otherwise the only cue left is a slightly
1771
+ // dimmer icon.
1772
+ loading ? (0, import_react7.createElement)("span", { className: "dsh-tu-subtle", role: "status" }, "\u6B63\u5728\u5237\u65B0\u2026") : null,
1773
+ (0, import_react7.createElement)("span", { className: "dsh-tu-spacer" }),
1774
+ (0, import_react7.createElement)("input", {
1775
+ ref: fileInputRef,
1776
+ type: "file",
1777
+ accept: ".json,application/json",
1778
+ style: { display: "none" },
1779
+ onChange: (event) => {
1780
+ void handlePickImport(event);
1781
+ }
1782
+ }),
1783
+ (0, import_react7.createElement)(
1784
+ "button",
1785
+ {
1786
+ type: "button",
1787
+ className: "dsh-tu-icon-btn",
1788
+ "data-tool": "export",
1789
+ "aria-label": "\u5BFC\u51FA\u5168\u90E8\u6570\u636E\uFF08\u5907\u4EFD\uFF09",
1790
+ title: "\u5BFC\u51FA\u5168\u90E8\u6570\u636E\uFF08\u5907\u4EFD\uFF09\uFF1B\u6587\u4EF6\u542B\u4F1A\u8BDD ID\u3001\u5DE5\u4F5C\u533A\u8DEF\u5F84\u7B49\u660E\u7EC6\uFF0C\u8BF7\u59A5\u5584\u4FDD\u7BA1",
1791
+ onClick: () => {
1792
+ void handleExport();
1793
+ },
1794
+ disabled: toolBusy
1795
+ },
1796
+ exportGlyph()
1797
+ ),
1798
+ (0, import_react7.createElement)(
1799
+ "button",
1800
+ {
1801
+ type: "button",
1802
+ className: "dsh-tu-icon-btn",
1803
+ "data-tool": "import",
1804
+ "aria-label": "\u5BFC\u5165\u5907\u4EFD",
1805
+ title: "\u5BFC\u5165\u5907\u4EFD\u6587\u4EF6\uFF1B\u5DF2\u5B58\u5728/\u91CD\u590D\u7684\u8BB0\u5F55\u4F1A\u88AB\u8DF3\u8FC7",
1806
+ onClick: () => {
1807
+ fileInputRef.current?.click();
1808
+ },
1809
+ disabled: toolBusy
1810
+ },
1811
+ importGlyph()
1812
+ ),
1813
+ (0, import_react7.createElement)(
1814
+ "button",
1815
+ {
1816
+ type: "button",
1817
+ className: "dsh-tu-icon-btn",
1818
+ "data-tool": "backfill",
1819
+ "aria-label": "\u8865\u5F55\u7F3A\u5931\u6570\u636E",
1820
+ title: "\u626B\u63CF\u672C\u673A\u4F1A\u8BDD\u65E5\u5FD7\uFF0C\u8865\u5F55\u63D2\u4EF6\u5B89\u88C5\u524D\u6216\u8FD0\u884C\u4E2D\u7F3A\u5931\u7684\u8F6E\u6B21\uFF08\u53EF\u91CD\u590D\u6267\u884C\uFF0C\u4E0D\u4F1A\u91CD\u590D\u8BA1\u6570\uFF09",
1821
+ onClick: () => {
1822
+ void handleScanBackfill();
1823
+ },
1824
+ disabled: toolBusy
1825
+ },
1826
+ backfillGlyph()
1827
+ ),
1828
+ createPricingInfoButton(data, {
1829
+ open: pricingHover || pricingPinned,
1830
+ pinned: pricingPinned,
1831
+ setHover: setPricingHover,
1832
+ setPinned: setPricingPinned
1833
+ }),
1834
+ (0, import_react7.createElement)(
1835
+ "button",
1836
+ {
1837
+ type: "button",
1838
+ // Same seat as the info and close buttons: three 28px icon buttons
1839
+ // instead of one text button that did not line up with its
1840
+ // neighbours. The label survives as the accessible name and title.
1841
+ className: "dsh-tu-icon-btn",
1842
+ "data-busy": loading ? "true" : void 0,
1843
+ "aria-label": "\u5237\u65B0\u6570\u636E",
1844
+ "aria-busy": loading,
1845
+ title: loading ? "\u6B63\u5728\u5237\u65B0\u2026" : "\u5237\u65B0\u6570\u636E",
1846
+ onClick: onReload,
1847
+ disabled: loading
1848
+ },
1849
+ refreshGlyph()
1850
+ ),
1851
+ (0, import_react7.createElement)(
1852
+ "button",
1853
+ {
1854
+ type: "button",
1855
+ className: "dsh-tu-icon-btn",
1856
+ title: "\u5173\u95ED\uFF0C\u8FD4\u56DE\u5BF9\u8BDD",
1857
+ "aria-label": "\u5173\u95ED\u7EDF\u8BA1\u9762\u677F\uFF0C\u8FD4\u56DE\u5BF9\u8BDD",
1858
+ onClick: () => {
1859
+ onSelect?.(null);
1860
+ }
1861
+ },
1862
+ closeGlyph()
1863
+ )
1864
+ ),
1865
+ toolNotice === null ? null : createNoticeBar(toolNotice.kind, toolNotice.text, () => {
1866
+ setToolNotice(null);
1867
+ }),
1868
+ toolPanel === null ? null : createToolPanel(toolPanel, toolBusy, closeTools, handleConfirmImport, handleConfirmBackfill),
1869
+ error === null ? null : createNoticeBar("error", error, () => {
1870
+ setError(null);
1871
+ }),
1872
+ data === null || dismissedHealthKey === healthKey ? null : createHealthNotice(data, () => {
1873
+ setDismissedHealthKey(healthKey);
1874
+ }),
1875
+ // ---- filters. Placed ABOVE the cards because the workspace/model
1876
+ // selects really do change the numbers below them; each field's label
1877
+ // carries a title stating exactly what it scopes, since granularity and
1878
+ // date range deliberately do not touch the cumulative totals.
1879
+ (0, import_react7.createElement)(
1880
+ "div",
1881
+ { className: "dsh-tu-panel" },
1882
+ (0, import_react7.createElement)(
1883
+ "div",
1884
+ { className: "dsh-tu-filters" },
1885
+ (0, import_react7.createElement)(
1886
+ "div",
1887
+ { className: "dsh-tu-field" },
1888
+ (0, import_react7.createElement)("label", { title: "\u5F71\u54CD\u672C\u9762\u677F\u7684\u5168\u90E8\u7EDF\u8BA1\uFF1A\u7D2F\u8BA1\u5361\u7247\u3001\u56FE\u8868\u4E0E\u660E\u7EC6\u8868" }, "\u5DE5\u4F5C\u533A"),
1889
+ (0, import_react7.createElement)(
1890
+ "select",
1891
+ {
1892
+ className: "dsh-tu-select",
1893
+ "data-filter": "workspace",
1894
+ value: workspace ?? "",
1895
+ onChange: (event) => {
1896
+ setWorkspace(event.target.value === "" ? null : event.target.value);
1897
+ }
1898
+ },
1899
+ (0, import_react7.createElement)("option", { value: "" }, "\u5168\u90E8\u5DE5\u4F5C\u533A"),
1900
+ ...(data?.facets.workspaces ?? []).map((facet) => {
1901
+ const merged = facet.mergedCount ?? (facet.paths?.length ?? 1);
1902
+ return (0, import_react7.createElement)(
1903
+ "option",
1904
+ { key: facet.key, value: facet.key },
1905
+ `${facet.label}\uFF08${formatTokens(facet.tokens)}${merged > 1 ? ` \xB7 ${String(merged)} \u4E2A\u8DEF\u5F84` : ""}\uFF09`
1906
+ );
1907
+ }),
1908
+ ...workspaceIsRawPath && !workspaceIsFacetKey ? [
1909
+ (0, import_react7.createElement)(
1910
+ "option",
1911
+ { key: "__raw-workspace__", value: workspace ?? "" },
1912
+ `${workspace ?? ""}\uFF08\u5355\u8DEF\u5F84\uFF09`
1913
+ )
1914
+ ] : []
1915
+ )
1916
+ ),
1917
+ (0, import_react7.createElement)(
1918
+ "div",
1919
+ { className: "dsh-tu-field" },
1920
+ (0, import_react7.createElement)(
1921
+ "label",
1922
+ { title: "\u5F71\u54CD\u672C\u9762\u677F\u7684\u5168\u90E8\u7EDF\u8BA1\uFF1A\u7D2F\u8BA1\u5361\u7247\u3001\u56FE\u8868\u4E0E\u660E\u7EC6\u8868" },
1923
+ "\u63A5\u5165\u65B9"
1924
+ ),
1925
+ (0, import_react7.createElement)(
1926
+ "select",
1927
+ {
1928
+ className: "dsh-tu-select",
1929
+ "data-filter": "provider",
1930
+ value: provider ?? "",
1931
+ onChange: (event) => {
1932
+ const next = event.target.value === "" ? null : event.target.value;
1933
+ setProvider(next);
1934
+ if (next !== null && model !== null) {
1935
+ const selected = allModelFacets.find((facet) => facet.key === model);
1936
+ const modelProvider = selected?.provider ?? (model.includes("/") ? model.slice(0, model.indexOf("/")) : null);
1937
+ if (modelProvider !== next) setModel(null);
1938
+ }
1939
+ }
1940
+ },
1941
+ (0, import_react7.createElement)("option", { value: "" }, "\u5168\u90E8\u63A5\u5165\u65B9"),
1942
+ ...(data?.facets.providers ?? []).filter((facet) => facet.key !== "").map(
1943
+ (facet) => (0, import_react7.createElement)(
1944
+ "option",
1945
+ { key: facet.key, value: facet.key },
1946
+ `${facet.label}\uFF08${formatTokens(facet.tokens)}\uFF09`
1947
+ )
1948
+ )
1949
+ )
1950
+ ),
1951
+ (0, import_react7.createElement)(
1952
+ "div",
1953
+ { className: "dsh-tu-field" },
1954
+ (0, import_react7.createElement)("label", { title: "\u5F71\u54CD\u672C\u9762\u677F\u7684\u5168\u90E8\u7EDF\u8BA1\uFF1A\u7D2F\u8BA1\u5361\u7247\u3001\u56FE\u8868\u4E0E\u660E\u7EC6\u8868" }, "\u6A21\u578B"),
1955
+ (0, import_react7.createElement)(
1956
+ "select",
1957
+ {
1958
+ className: "dsh-tu-select",
1959
+ "data-filter": "model",
1960
+ value: model ?? "",
1961
+ onChange: (event) => {
1962
+ const next = event.target.value === "" ? null : event.target.value;
1963
+ setModel(next);
1964
+ if (next !== null) {
1965
+ const selected = allModelFacets.find((facet) => facet.key === next);
1966
+ if (selected?.provider !== void 0 && selected.provider.length > 0) {
1967
+ setProvider(selected.provider);
1968
+ }
1969
+ }
1970
+ }
1971
+ },
1972
+ (0, import_react7.createElement)("option", { value: "" }, "\u5168\u90E8\u6A21\u578B"),
1973
+ ...modelFacets.filter((facet) => facet.key !== "").map(
1974
+ (facet) => (0, import_react7.createElement)(
1975
+ "option",
1976
+ { key: facet.key, value: facet.key },
1977
+ // The key carries provider/model; show BOTH so two
1978
+ // same-model providers do not render as identical options.
1979
+ facet.provider === void 0 || facet.provider.length === 0 ? `${facet.label}\uFF08${formatTokens(facet.tokens)}\uFF09` : `${facet.label} \xB7 ${facet.provider}\uFF08${formatTokens(facet.tokens)}\uFF09`
1980
+ )
1981
+ )
1982
+ )
1983
+ ),
1984
+ (0, import_react7.createElement)(
1985
+ "div",
1986
+ { className: "dsh-tu-field" },
1987
+ (0, import_react7.createElement)("label", { title: "\u53EA\u5F71\u54CD\u4E0B\u9762\u7684\u67F1\u72B6\u56FE\uFF1B\u7D2F\u8BA1\u5361\u7247\u4E0E\u660E\u7EC6\u8868\u4E3A\u5168\u5386\u53F2\uFF0C\u4E0D\u968F\u65E5\u671F\u53D8\u5316" }, "\u7C92\u5EA6"),
1988
+ (0, import_react7.createElement)(
1989
+ "div",
1990
+ { className: "dsh-tu-group" },
1991
+ ...GRANULARITIES.map(
1992
+ (option) => (0, import_react7.createElement)(
1993
+ "button",
1994
+ {
1995
+ key: option.id,
1996
+ type: "button",
1997
+ className: "dsh-tu-btn",
1998
+ "data-active": granularity === option.id ? "true" : "false",
1999
+ onClick: () => {
2000
+ setGranularity(option.id);
2001
+ }
2002
+ },
2003
+ option.label
2004
+ )
2005
+ )
2006
+ )
2007
+ ),
2008
+ (0, import_react7.createElement)(
2009
+ "div",
2010
+ { className: "dsh-tu-field" },
2011
+ (0, import_react7.createElement)("label", { title: "\u53EA\u5F71\u54CD\u4E0B\u9762\u7684\u67F1\u72B6\u56FE\uFF1B\u7D2F\u8BA1\u5361\u7247\u4E0E\u660E\u7EC6\u8868\u4E3A\u5168\u5386\u53F2\uFF0C\u4E0D\u968F\u65E5\u671F\u53D8\u5316" }, "\u8303\u56F4"),
2012
+ (0, import_react7.createElement)(
2013
+ "div",
2014
+ { className: "dsh-tu-group" },
2015
+ ...PRESETS.map(
2016
+ (option) => (0, import_react7.createElement)(
2017
+ "button",
2018
+ {
2019
+ key: option.id,
2020
+ type: "button",
2021
+ className: "dsh-tu-btn",
2022
+ "data-active": preset === option.id ? "true" : "false",
2023
+ onClick: () => {
2024
+ if (option.id === "custom") {
2025
+ if (customTo === "") setCustomTo(rangeEnd);
2026
+ if (customFrom === "") setCustomFrom(shiftDay(rangeEnd, -29));
2027
+ }
2028
+ setPreset(option.id);
2029
+ }
2030
+ },
2031
+ option.label
2032
+ )
2033
+ )
2034
+ )
2035
+ ),
2036
+ preset !== "custom" ? null : (0, import_react7.createElement)(
2037
+ "div",
2038
+ { className: "dsh-tu-field" },
2039
+ (0, import_react7.createElement)("label", { title: "\u542B\u9996\u5C3E\u4E24\u5929\uFF1A\u8D77 = \u6B62 \u8868\u793A\u53EA\u770B\u8FD9\u4E00\u5929" }, "\u8D77\u6B62\u65E5\u671F"),
2040
+ (0, import_react7.createElement)(
2041
+ "div",
2042
+ { style: { display: "flex", gap: "6px", alignItems: "center" } },
2043
+ (0, import_react7.createElement)("input", {
2044
+ className: "dsh-tu-input",
2045
+ type: "date",
2046
+ value: customFrom,
2047
+ // Both bounds are inclusive: 起 = 止 is a one-day range. `max`
2048
+ // keeps the native picker from offering a start after the
2049
+ // end — the picker is where an inverted pair would be born.
2050
+ max: customTo.length > 0 ? customTo : void 0,
2051
+ onChange: (event) => {
2052
+ const next = event.target.value;
2053
+ setCustomFrom(next);
2054
+ if (next.length > 0 && customTo.length > 0 && next > customTo) setCustomTo(next);
2055
+ }
2056
+ }),
2057
+ (0, import_react7.createElement)("span", { className: "dsh-tu-subtle" }, "\u81F3"),
2058
+ (0, import_react7.createElement)("input", {
2059
+ className: "dsh-tu-input",
2060
+ type: "date",
2061
+ value: customTo,
2062
+ min: customFrom.length > 0 ? customFrom : void 0,
2063
+ onChange: (event) => {
2064
+ const next = event.target.value;
2065
+ setCustomTo(next);
2066
+ if (next.length > 0 && customFrom.length > 0 && next < customFrom) setCustomFrom(next);
2067
+ }
2068
+ })
2069
+ )
2070
+ )
2071
+ )
2072
+ ),
2073
+ // ---- cumulative cards. These follow the WORKSPACE/MODEL filter only:
2074
+ // the date range and granularity above scope the charts, not the totals.
2075
+ (0, import_react7.createElement)("div", { className: "dsh-tu-section-title" }, "\u7D2F\u8BA1\u7528\u91CF"),
2076
+ (0, import_react7.createElement)(
2077
+ "div",
2078
+ { className: "dsh-tu-cards" },
2079
+ createCard(
2080
+ "\u7D2F\u8BA1 Token",
2081
+ formatTokens(data?.totals.total ?? 0),
2082
+ data === null ? "" : hasFilter(workspace, model) ? `\u5168\u90E8\u5386\u53F2 ${formatTokens(data.allTime.total)}` : `${formatTokensExact(data.totals.total)} tokens`,
2083
+ "blue"
2084
+ ),
2085
+ createCard(
2086
+ "\u7D2F\u8BA1\u8D39\u7528",
2087
+ formatMoney(data?.totals.cost ?? 0, currency),
2088
+ data === null ? "" : hasFilter(workspace, model) ? `\u5168\u90E8\u5386\u53F2 ${formatMoney(data.allTime.cost, currency)}` : `${String(data.totals.turns)} \u8F6E \xB7 ${data.currency}`,
2089
+ "amber"
2090
+ ),
2091
+ createCard(
2092
+ "\u7D2F\u8BA1\u8F6E\u6B21",
2093
+ formatTokensExact(data?.totals.turns ?? 0),
2094
+ data === null ? "" : `\u6D3B\u8DC3 ${String(data.facets.activeDays)} \u5929`,
2095
+ "violet"
2096
+ ),
2097
+ createCard(
2098
+ "\u7F13\u5B58\u547D\u4E2D\u7387",
2099
+ formatPercent(data?.totals.tokens ?? void 0),
2100
+ "\u547D\u4E2D / \u5168\u90E8\u8F93\u5165 token",
2101
+ "green"
2102
+ ),
2103
+ createCard(
2104
+ "\u8FDE\u7EED\u4F7F\u7528",
2105
+ `${String(streak.current)} \u5929`,
2106
+ `\u6700\u957F ${String(streak.longest)} \u5929`,
2107
+ "rose"
2108
+ ),
2109
+ createCard(
2110
+ "\u8F93\u51FA Token",
2111
+ formatTokens(data?.totals.tokens.output ?? 0),
2112
+ data === null ? "" : `\u63A8\u7406 ${formatTokens(data.totals.tokens.reasoning)}`,
2113
+ "blue"
2114
+ )
2115
+ ),
2116
+ analytics === void 0 ? null : (0, import_react7.createElement)("div", { className: "dsh-tu-section-title" }, "\u4F7F\u7528\u6548\u7387"),
2117
+ analytics === void 0 ? null : (0, import_react7.createElement)(
2118
+ "div",
2119
+ { className: "dsh-tu-cards", "data-cards": "insights" },
2120
+ createCard(
2121
+ "\u6BCF\u8F6E\u8C03\u7528",
2122
+ `${formatCount(analytics.calls.medianPerTurn)} \u6B21`,
2123
+ `\u4E2D\u4F4D \xB7 90% \u7684\u8F6E\u6B21 \u2264 ${formatCount(analytics.calls.p90PerTurn)} \u6B21 \xB7 \u6700\u591A ${formatCount(analytics.calls.maxPerTurn)} \u6B21`,
2124
+ "blue"
2125
+ ),
2126
+ createCard(
2127
+ "\u591A\u6B21\u8C03\u7528\u8F6E\u6B21",
2128
+ analytics.calls.turns === 0 ? "\u2014" : `${(analytics.calls.multiCallTurns / analytics.calls.turns * 100).toFixed(0)}%`,
2129
+ `\u4E00\u8F6E\u5185 \u22652 \u6B21\u6A21\u578B\u8C03\u7528\uFF1A${formatCount(analytics.calls.multiCallTurns)} / ${formatCount(analytics.calls.turns)} \u8F6E`,
2130
+ "amber"
2131
+ ),
2132
+ createCard(
2133
+ "\u8F6E\u6B21\u8017\u65F6",
2134
+ formatDuration(analytics.durations.median),
2135
+ `\u4E2D\u4F4D \xB7 90% \u7684\u8F6E\u6B21 \u2264 ${formatDuration(analytics.durations.p90)} \xB7 \u6700\u957F ${formatDuration(analytics.durations.max)}`,
2136
+ "violet"
2137
+ ),
2138
+ createCard(
2139
+ "\u4F1A\u8BDD\u6570",
2140
+ formatCount(analytics.sessions.count),
2141
+ `\u5E73\u5747 ${analytics.sessions.averageTurns.toFixed(1)} \u8F6E/\u4F1A\u8BDD \xB7 \u4E2D\u4F4D ${formatCount(analytics.sessions.medianTurns)} \u8F6E`,
2142
+ "green"
2143
+ ),
2144
+ createCard(
2145
+ "\u6BCF\u8F6E\u8D39\u7528",
2146
+ formatMoney(analytics.calls.costPerTurnMedian, currency),
2147
+ `\u4E2D\u4F4D \xB7 \u6BCF\u8F6E Token \u4E2D\u4F4D ${formatTokens(analytics.calls.tokensPerTurnMedian)}`,
2148
+ "rose"
2149
+ )
2150
+ ),
2151
+ // ---- heatmap (its own row; companion figures on the row below)
2152
+ (0, import_react7.createElement)(
2153
+ "div",
2154
+ { className: "dsh-tu-panel", "data-panel": "heatmap" },
2155
+ (0, import_react7.createElement)(
2156
+ "div",
2157
+ { className: "dsh-tu-panel-head" },
2158
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-panel-title" }, "\u6BCF\u65E5\u6D88\u8017\u65E5\u5386"),
2159
+ (0, import_react7.createElement)("span", { className: "dsh-tu-spacer" }),
2160
+ (0, import_react7.createElement)(
2161
+ "div",
2162
+ { className: "dsh-tu-heat-bar" },
2163
+ (0, import_react7.createElement)(
2164
+ "button",
2165
+ {
2166
+ type: "button",
2167
+ className: "dsh-tu-btn",
2168
+ disabled: !heatRange.canPageBack || loading,
2169
+ title: heatRange.canPageBack ? `\u5411\u524D\u56DE\u770B ${String(HEATMAP_SPAN_DAYS)} \u5929` : (
2170
+ // Two different reasons for the same disabled button: the
2171
+ // ledger really has nothing older, or the payload was cut at
2172
+ // the read ceiling. Saying "no older data" in the second case
2173
+ // would be a lie.
2174
+ firstDayFacet !== "" && firstDayFacet < heatRange.coverageStart ? `\u5DF2\u8FBE\u8BFB\u53D6\u4E0A\u9650\uFF08\u6700\u591A ${String(API_LIMITS.maxDays)} \u5929\uFF09\uFF0C\u66F4\u65E9\u7684\u6570\u636E\u9700\u8981\u63D0\u9AD8\u4E0A\u9650` : "\u8D26\u672C\u91CC\u6CA1\u6709\u66F4\u65E9\u7684\u6570\u636E\u4E86"
2175
+ ),
2176
+ onClick: () => {
2177
+ pageHeat(-HEATMAP_SPAN_DAYS);
2178
+ }
2179
+ },
2180
+ "\u2190 \u4E0A\u4E00\u6BB5"
2181
+ ),
2182
+ (0, import_react7.createElement)(
2183
+ "span",
2184
+ { className: "dsh-tu-heat-range" },
2185
+ // When part of the page could not be fetched, the caption names the
2186
+ // days that ARE drawn instead of the nominal window: the grid hides
2187
+ // those cells, so claiming them would be the one dishonest label
2188
+ // left in this panel.
2189
+ heatRange.covered ? `${heatRange.start} ~ ${heatRange.end}\uFF08${String(heatRange.days)} \u5929\uFF09` : `${heatRange.drawnStart || "\u2014"} ~ ${heatRange.drawnEnd || "\u2014"}\uFF08\u5B9E\u7ED8 ${String(heatRange.drawnDays)} \u5929\uFF0C\u5176\u4F59\u672A\u53D6\u5230\uFF09`
2190
+ ),
2191
+ (0, import_react7.createElement)(
2192
+ "button",
2193
+ {
2194
+ type: "button",
2195
+ className: "dsh-tu-btn",
2196
+ disabled: !heatRange.canPageForward || loading,
2197
+ title: heatRange.canPageForward ? `\u5411\u540E\u56DE\u770B ${String(HEATMAP_SPAN_DAYS)} \u5929` : "\u5DF2\u7ECF\u5728\u6700\u65B0\u4E00\u6BB5",
2198
+ onClick: () => {
2199
+ pageHeat(HEATMAP_SPAN_DAYS);
2200
+ }
2201
+ },
2202
+ "\u4E0B\u4E00\u6BB5 \u2192"
2203
+ ),
2204
+ heatAnchor === "" ? null : (0, import_react7.createElement)(
2205
+ "button",
2206
+ {
2207
+ type: "button",
2208
+ className: "dsh-tu-btn",
2209
+ onClick: () => {
2210
+ setHeatAnchor("");
2211
+ }
2212
+ },
2213
+ "\u56DE\u5230\u4ECA\u5929"
2214
+ )
2215
+ )
2216
+ ),
2217
+ (0, import_react7.createElement)(
2218
+ "div",
2219
+ { className: "dsh-tu-heat-layout" },
2220
+ (0, import_react7.createElement)(Heatmap, {
2221
+ points: daily,
2222
+ metric: "tokens",
2223
+ currency,
2224
+ range: heatRange,
2225
+ firstDay: data?.facets.firstDay ?? ""
2226
+ }),
2227
+ heatStats(pageDaily, currency)
2228
+ ),
2229
+ ...heatCoverageNotes(heatRange, firstDayFacet)
2230
+ ),
2231
+ // ---- token bars: one stacked bar carries the whole composition, so the
2232
+ // tiny miss/output slices are not separate targets that are hard to hover.
2233
+ (0, import_react7.createElement)(
2234
+ "div",
2235
+ { className: "dsh-tu-panel", "data-panel": "tokens" },
2236
+ (0, import_react7.createElement)(
2237
+ "div",
2238
+ { className: "dsh-tu-panel-head" },
2239
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-panel-title" }, "Token \u6D88\u8017"),
2240
+ (0, import_react7.createElement)(
2241
+ "span",
2242
+ { className: "dsh-tu-subtle" },
2243
+ `${describeGranularity(granularity)} \xB7 \u5408\u8BA1 ${formatTokens(rangeStats.tokens)} tokens`
2244
+ )
2245
+ ),
2246
+ (0, import_react7.createElement)(CacheCompositionChart, {
2247
+ buckets,
2248
+ emptyHint: "\u8BE5\u8303\u56F4\u5185\u6CA1\u6709\u8BB0\u5F55\u5230 token \u6D88\u8017"
2249
+ })
2250
+ ),
2251
+ // ---- cost bars
2252
+ (0, import_react7.createElement)(
2253
+ "div",
2254
+ { className: "dsh-tu-panel", "data-panel": "cost" },
2255
+ (0, import_react7.createElement)(
2256
+ "div",
2257
+ { className: "dsh-tu-panel-head" },
2258
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-panel-title" }, "\u8D39\u7528\u6D88\u8017"),
2259
+ (0, import_react7.createElement)(
2260
+ "span",
2261
+ { className: "dsh-tu-subtle" },
2262
+ `${describeGranularity(granularity)} \xB7 \u5408\u8BA1 ${formatMoney(rangeStats.cost, currency)}`
2263
+ )
2264
+ ),
2265
+ (0, import_react7.createElement)(BarChart, {
2266
+ buckets,
2267
+ metric: "cost",
2268
+ currency,
2269
+ emptyHint: "\u8BE5\u8303\u56F4\u5185\u6CA1\u6709\u8BB0\u5F55\u5230\u8D39\u7528"
2270
+ })
2271
+ ),
2272
+ // ---- cache hit-rate trend (client range + granularity)
2273
+ (0, import_react7.createElement)(
2274
+ "div",
2275
+ { className: "dsh-tu-panel", "data-panel": "cache-rate" },
2276
+ (0, import_react7.createElement)(
2277
+ "div",
2278
+ { className: "dsh-tu-panel-head" },
2279
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-panel-title" }, "\u7F13\u5B58\u547D\u4E2D\u7387\u8D8B\u52BF"),
2280
+ (0, import_react7.createElement)(
2281
+ "span",
2282
+ { className: "dsh-tu-subtle" },
2283
+ `${describeGranularity(granularity)} \xB7 \u7EB5\u8F74 ${formatRateBound(cacheAxis.min)}\u2013100% \xB7 \u5F53\u524D\u8303\u56F4 ${formatPercent(rangeTokens)}`
2284
+ )
2285
+ ),
2286
+ (0, import_react7.createElement)(CacheRateLine, {
2287
+ buckets,
2288
+ emptyHint: "\u8BE5\u8303\u56F4\u5185\u6CA1\u6709\u53EF\u8BA1\u7B97\u7684\u7F13\u5B58\u547D\u4E2D\u7387"
2289
+ }),
2290
+ (0, import_react7.createElement)(
2291
+ "div",
2292
+ { className: "dsh-tu-stat-line" },
2293
+ (0, import_react7.createElement)("span", null, "\u547D\u4E2D ", (0, import_react7.createElement)("strong", null, formatTokens(rangeTokens.cacheRead))),
2294
+ (0, import_react7.createElement)("span", null, "\u672A\u547D\u4E2D ", (0, import_react7.createElement)("strong", null, formatTokens(rangeTokens.uncachedInput))),
2295
+ (0, import_react7.createElement)("span", null, "\u8F93\u51FA ", (0, import_react7.createElement)("strong", null, formatTokens(rangeTokens.output))),
2296
+ (0, import_react7.createElement)(
2297
+ "span",
2298
+ null,
2299
+ cacheAxis.clippedBelow > 0 ? `${String(cacheAxis.clippedBelow)} \u4E2A\u4F4E\u503C\u70B9\u4F4E\u4E8E ${formatRateBound(cacheAxis.min)}\uFF0C\u663E\u793A\u5728\u5E95\u90E8\uFF08\u60AC\u505C\u53EF\u770B\u5B9E\u9645\u503C\uFF09` : cacheAxis.min >= 0.95 ? "\u7EB5\u8F74\u653E\u5927\u5230 95%\u2013100%\uFF0C\u4FBF\u4E8E\u89C2\u5BDF 99% \u9644\u8FD1\u7684\u8D77\u4F0F" : "\u7EB5\u8F74\u6309\u5F53\u524D\u6570\u636E\u81EA\u52A8\u7F29\u653E"
2300
+ )
2301
+ )
2302
+ ),
2303
+ // ---- call / duration efficiency (all-time under the active filter)
2304
+ analytics === void 0 ? null : (0, import_react7.createElement)(
2305
+ "div",
2306
+ { className: "dsh-tu-panel", "data-panel": "efficiency" },
2307
+ (0, import_react7.createElement)(
2308
+ "div",
2309
+ { className: "dsh-tu-panel-head" },
2310
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-panel-title" }, "\u8C03\u7528\u4E0E\u8F6E\u6B21\u6548\u7387"),
2311
+ (0, import_react7.createElement)("span", { className: "dsh-tu-subtle" }, "\u5F53\u524D\u7B5B\u9009 \xB7 \u5168\u5386\u53F2"),
2312
+ (0, import_react7.createElement)("span", { className: "dsh-tu-spacer" }),
2313
+ createPanelInfoButton(
2314
+ "efficiency",
2315
+ "\u8C03\u7528\u4E0E\u8F6E\u6B21\u6548\u7387\u8BF4\u660E",
2316
+ panelInfo === "efficiency",
2317
+ [
2318
+ "\u201C\u591A\u6B21\u8C03\u7528\u8F6E\u6B21\u201D\u6307\u4E00\u8F6E\u5BF9\u8BDD\u5185\u53D1\u751F 2 \u6B21\u53CA\u4EE5\u4E0A\u6A21\u578B\u8C03\u7528\uFF08\u5DE5\u5177\u5FAA\u73AF/\u91CD\u8BD5\uFF09\uFF0C\u4E0D\u662F\u591A\u8F6E\u5BF9\u8BDD\u3002",
2319
+ "\u201C90% \u7684\u8F6E\u6B21 \u2264\u201D\u8868\u793A\u4E5D\u6210\u8F6E\u6B21\u7684\u8C03\u7528\u6B21\u6570/\u8017\u65F6\u4E0D\u8D85\u8FC7\u8BE5\u503C\uFF1B\u6A2A\u8F74\u9636\u68AF\u6309\u6BCF\u8F6E\u5B9E\u9645\u6A21\u578B\u8C03\u7528\u6B21\u6570/\u8F6E\u6B21\u8017\u65F6\u5206\u7EC4\u3002"
2320
+ ],
2321
+ setPanelInfo
2322
+ )
2323
+ ),
2324
+ (0, import_react7.createElement)(
2325
+ "div",
2326
+ { className: "dsh-tu-chart-grid" },
2327
+ createSubpanel(
2328
+ "\u6BCF\u8F6E\u6A21\u578B\u8C03\u7528\u6B21\u6570",
2329
+ (0, import_react7.createElement)(HBarList, {
2330
+ items: analytics.attemptBins,
2331
+ formatValue: (count) => `${formatCount(count)} \u8F6E`,
2332
+ emptyHint: "\u6682\u65E0\u8C03\u7528\u6570\u636E"
2333
+ }),
2334
+ (0, import_react7.createElement)(
2335
+ "div",
2336
+ { className: "dsh-tu-stat-line" },
2337
+ (0, import_react7.createElement)("span", null, "\u4E2D\u4F4D ", (0, import_react7.createElement)("strong", null, `${formatCount(analytics.calls.medianPerTurn)} \u6B21`)),
2338
+ (0, import_react7.createElement)("span", null, "90% \u7684\u8F6E\u6B21 \u2264 ", (0, import_react7.createElement)("strong", null, `${formatCount(analytics.calls.p90PerTurn)} \u6B21`)),
2339
+ (0, import_react7.createElement)("span", null, "\u5E73\u5747 ", (0, import_react7.createElement)("strong", null, `${analytics.calls.averagePerTurn.toFixed(1)} \u6B21`)),
2340
+ (0, import_react7.createElement)("span", null, "\u591A\u6B21\u8C03\u7528\u8F6E\u6B21 ", (0, import_react7.createElement)("strong", null, `${formatCount(analytics.calls.multiCallTurns)} \u8F6E`))
2341
+ )
2342
+ ),
2343
+ createSubpanel(
2344
+ "\u6BCF\u8F6E\u8017\u65F6",
2345
+ (0, import_react7.createElement)(HBarList, {
2346
+ items: analytics.durationBins,
2347
+ formatValue: (count) => `${formatCount(count)} \u8F6E`,
2348
+ emptyHint: "\u6682\u65E0\u8017\u65F6\u6570\u636E"
2349
+ }),
2350
+ (0, import_react7.createElement)(
2351
+ "div",
2352
+ { className: "dsh-tu-stat-line" },
2353
+ (0, import_react7.createElement)("span", null, "\u4E2D\u4F4D ", (0, import_react7.createElement)("strong", null, formatDuration(analytics.durations.median))),
2354
+ (0, import_react7.createElement)("span", null, "90% \u7684\u8F6E\u6B21 \u2264 ", (0, import_react7.createElement)("strong", null, formatDuration(analytics.durations.p90))),
2355
+ (0, import_react7.createElement)("span", null, "\u5E73\u5747 ", (0, import_react7.createElement)("strong", null, formatDuration(analytics.durations.average))),
2356
+ (0, import_react7.createElement)("span", null, "\u6700\u957F ", (0, import_react7.createElement)("strong", null, formatDuration(analytics.durations.max)))
2357
+ )
2358
+ )
2359
+ ),
2360
+ (0, import_react7.createElement)(
2361
+ "div",
2362
+ { className: "dsh-tu-stat-line" },
2363
+ (0, import_react7.createElement)("span", null, "\u4F1A\u8BDD ", (0, import_react7.createElement)("strong", null, `${formatCount(analytics.sessions.count)} \u4E2A`)),
2364
+ (0, import_react7.createElement)("span", null, "\u5E73\u5747\u8F6E\u6B21/\u4F1A\u8BDD ", (0, import_react7.createElement)("strong", null, analytics.sessions.averageTurns.toFixed(1))),
2365
+ (0, import_react7.createElement)("span", null, "\u6BCF\u4F1A\u8BDD Token \u4E2D\u4F4D ", (0, import_react7.createElement)("strong", null, formatTokens(analytics.sessions.medianTokens))),
2366
+ (0, import_react7.createElement)("span", null, "\u6BCF\u4F1A\u8BDD\u8D39\u7528\u4E2D\u4F4D ", (0, import_react7.createElement)("strong", null, formatMoney(analytics.sessions.medianCost, currency)))
2367
+ )
2368
+ ),
2369
+ // ---- local hour-of-day activity
2370
+ analytics === void 0 ? null : (0, import_react7.createElement)(
2371
+ "div",
2372
+ { className: "dsh-tu-panel", "data-panel": "hours" },
2373
+ (0, import_react7.createElement)(
2374
+ "div",
2375
+ { className: "dsh-tu-panel-head" },
2376
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-panel-title" }, "24 \u5C0F\u65F6\u6D3B\u8DC3\u65F6\u6BB5"),
2377
+ (0, import_react7.createElement)("span", { className: "dsh-tu-subtle" }, "\u672C\u5730\u65F6\u95F4 \xB7 \u5F53\u524D\u7B5B\u9009 \xB7 \u5168\u5386\u53F2"),
2378
+ (0, import_react7.createElement)("span", { className: "dsh-tu-spacer" }),
2379
+ createPanelInfoButton(
2380
+ "hours",
2381
+ "24 \u5C0F\u65F6\u6D3B\u8DC3\u65F6\u6BB5\u8BF4\u660E",
2382
+ panelInfo === "hours",
2383
+ [
2384
+ "\u6309\u6A21\u578B\u8C03\u7528\u7ED3\u7B97\u65F6\u95F4\u7684\u672C\u5730\u5C0F\u65F6\u7EDF\u8BA1\uFF1B\u4E00\u4E2A\u957F\u8F6E\u6B21\u53EF\u80FD\u8DE8\u591A\u4E2A\u5C0F\u65F6\uFF0C\u56E0\u6B64\u201C\u8F6E\u6B21\u5F00\u59CB\u201D\u4E0E\u8C03\u7528\u5C0F\u65F6\u7684\u53E3\u5F84\u4E0D\u540C\u3002",
2385
+ "\u67F1\u9AD8\u8868\u793A\u8BE5\u5C0F\u65F6\u5185\u7ED3\u7B97\u7684\u6A21\u578B\u8C03\u7528\u6B21\u6570\uFF1B\u60AC\u505C\u53EF\u67E5\u770B\u8BE5\u5C0F\u65F6\u7684\u8F6E\u6B21\u5F00\u59CB\u6570\u3001Token \u4E0E\u8D39\u7528\u3002"
2386
+ ],
2387
+ setPanelInfo
2388
+ )
2389
+ ),
2390
+ (0, import_react7.createElement)(HourActivityChart, {
2391
+ hours: analytics.hours,
2392
+ currency,
2393
+ emptyHint: "\u6682\u65E0\u53EF\u6309\u5C0F\u65F6\u5F52\u5C5E\u7684\u8C03\u7528\u6570\u636E"
2394
+ }),
2395
+ (0, import_react7.createElement)(
2396
+ "div",
2397
+ { className: "dsh-tu-stat-line" },
2398
+ ...analytics.hours.slice().sort((left, right) => right.calls - left.calls).slice(0, 3).map(
2399
+ (hour) => (0, import_react7.createElement)(
2400
+ "span",
2401
+ { key: `top-hour-${String(hour.hour)}` },
2402
+ `${String(hour.hour).padStart(2, "0")}:00 `,
2403
+ (0, import_react7.createElement)("strong", null, `${formatCount(hour.calls)} \u6B21\u8C03\u7528`)
2404
+ )
2405
+ )
2406
+ )
2407
+ ),
2408
+ // ---- agent / pricing-window breakdowns
2409
+ analytics === void 0 ? null : (0, import_react7.createElement)(
2410
+ "div",
2411
+ { className: "dsh-tu-panel", "data-panel": "agents-outcomes" },
2412
+ (0, import_react7.createElement)(
2413
+ "div",
2414
+ { className: "dsh-tu-panel-head" },
2415
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-panel-title" }, "Agent \u4E0E\u65F6\u6BB5"),
2416
+ (0, import_react7.createElement)("span", { className: "dsh-tu-subtle" }, "\u5F53\u524D\u7B5B\u9009 \xB7 \u5168\u5386\u53F2"),
2417
+ (0, import_react7.createElement)("span", { className: "dsh-tu-spacer" }),
2418
+ createPanelInfoButton(
2419
+ "agents",
2420
+ "Agent \u4E0E\u65F6\u6BB5\u8BF4\u660E",
2421
+ panelInfo === "agents",
2422
+ [
2423
+ "Agent \u540D\u79F0\uFF1Astandard=\u6807\u51C6\u6A21\u5F0F\uFF0Ccordis=\u521B\u9020\u6A21\u5F0F\uFF0Cminimal=\u6781\u7B80\u6A21\u5F0F\uFF0Ccode=\u4EE3\u7801\u6A21\u5F0F\uFF0Cptc=PTC \u6A21\u5F0F\uFF1B\u672A\u8BC6\u522B\u7684 preset \u4FDD\u7559\u539F\u59CB id\u3002",
2424
+ "\u9AD8\u5CF0/\u7A7A\u95F2\u6309\u6BCF\u6B21\u6A21\u578B\u8C03\u7528\u7ED3\u7B97\u65F6\u7684\u4EF7\u683C\u7A97\u53E3\u7EDF\u8BA1\uFF1B\u8D39\u7528/Token \u53EA\u7EDF\u8BA1\u8BE5\u7A97\u53E3\u5185\u7684\u8C03\u7528\u3002",
2425
+ "\u4E09\u5F20\u56FE\u5206\u522B\u5C55\u793A\u8D39\u7528\u5360\u6BD4\u3001\u8F6E\u6B21\u5206\u5E03\u4E0E\u9AD8\u5CF0/\u7A7A\u95F2\u8C03\u7528\uFF1B\u60AC\u505C\u4EFB\u4E00\u6247\u5F62\u53EF\u67E5\u770B\u8BE5\u5206\u7C7B\u7684\u8D39\u7528\u3001\u5360\u6BD4\u3001\u8F6E\u6B21\u3001\u8C03\u7528\u3001Token\u3001\u7F13\u5B58\u547D\u4E2D\u7B49\u5B8C\u6574\u5B57\u6BB5\u3002"
2426
+ ],
2427
+ setPanelInfo
2428
+ )
2429
+ ),
2430
+ (0, import_react7.createElement)(
2431
+ "div",
2432
+ { className: "dsh-tu-sector-grid" },
2433
+ createSubpanel(
2434
+ "Agent \u8D39\u7528\u5360\u6BD4",
2435
+ (0, import_react7.createElement)(SectorChart, {
2436
+ slices: agentCostSlices,
2437
+ variant: "donut",
2438
+ centerLabel: "\u7D2F\u8BA1\u8D39\u7528",
2439
+ centerValue: formatMoney(agentCost, currency),
2440
+ primaryLabel: "\u8D39\u7528",
2441
+ formatValue: (value) => formatMoney(value, currency),
2442
+ ariaLabel: "Agent \u8D39\u7528\u5360\u6BD4\u6247\u5F62\u56FE",
2443
+ emptyHint: "\u6682\u65E0\u53EF\u5206\u644A\u8D39\u7528"
2444
+ })
2445
+ ),
2446
+ createSubpanel(
2447
+ "Agent \u8F6E\u6B21\u5206\u5E03",
2448
+ (0, import_react7.createElement)(SectorChart, {
2449
+ slices: agentTurnSlices,
2450
+ variant: "pie",
2451
+ primaryLabel: "\u8F6E\u6B21",
2452
+ formatValue: (value) => formatCount(value),
2453
+ ariaLabel: "Agent \u8F6E\u6B21\u5360\u6BD4\u997C\u56FE",
2454
+ emptyHint: "\u6682\u65E0\u8F6E\u6B21\u6570\u636E"
2455
+ })
2456
+ ),
2457
+ createSubpanel(
2458
+ "\u9AD8\u5CF0 / \u7A7A\u95F2\u8C03\u7528",
2459
+ (0, import_react7.createElement)(SectorChart, {
2460
+ slices: windowSlices,
2461
+ variant: "donut",
2462
+ centerLabel: "\u7D2F\u8BA1\u8C03\u7528",
2463
+ centerValue: formatCount(windowCalls),
2464
+ primaryLabel: "\u8C03\u7528",
2465
+ formatValue: (value) => formatCount(value),
2466
+ ariaLabel: "\u9AD8\u5CF0\u7A7A\u95F2\u8C03\u7528\u5360\u6BD4\u6247\u5F62\u56FE",
2467
+ emptyHint: "\u6682\u65E0\u65F6\u6BB5\u6570\u636E"
2468
+ })
2469
+ )
2470
+ )
2471
+ ),
2472
+ // ---- breakdowns
2473
+ (0, import_react7.createElement)(
2474
+ "div",
2475
+ { className: "dsh-tu-panel", "data-panel": "by-model" },
2476
+ (0, import_react7.createElement)(
2477
+ "div",
2478
+ { className: "dsh-tu-panel-head" },
2479
+ (0, import_react7.createElement)(
2480
+ "h2",
2481
+ {
2482
+ className: "dsh-tu-panel-title",
2483
+ title: "\u540C\u540D\u6A21\u578B\u6765\u81EA\u4E0D\u540C\u63A5\u5165\u65B9\uFF08provider\uFF09\u65F6\u4F1A\u5206\u884C\u663E\u793A\uFF1B\u53EF\u7528\u4E0A\u65B9\u300C\u63A5\u5165\u65B9\u300D\u7B5B\u9009"
2484
+ },
2485
+ "\u6309\u6A21\u578B"
2486
+ )
2487
+ ),
2488
+ facetTable(data?.byModel ?? [], currency, "\u6A21\u578B")
2489
+ ),
2490
+ (0, import_react7.createElement)(
2491
+ "div",
2492
+ { className: "dsh-tu-panel", "data-panel": "by-workspace" },
2493
+ (0, import_react7.createElement)(
2494
+ "div",
2495
+ { className: "dsh-tu-panel-head" },
2496
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-panel-title" }, "\u6309\u5DE5\u4F5C\u533A")
2497
+ ),
2498
+ (0, import_react7.createElement)(WorkspaceTable, {
2499
+ facets: data?.byWorkspace ?? [],
2500
+ currency,
2501
+ onFilterPath: (path) => {
2502
+ setWorkspace(path);
2503
+ }
2504
+ })
2505
+ )
2506
+ )
2507
+ );
2508
+ }
2509
+ function heatCoverageNotes(range, ledgerFirstDay) {
2510
+ const notes = [];
2511
+ const capped = ledgerFirstDay !== "" && range.coverageStart !== "" && ledgerFirstDay < range.coverageStart;
2512
+ if (range.coverageStart === "" || range.drawnStart > range.start) {
2513
+ notes.push(
2514
+ (0, import_react7.createElement)(
2515
+ "div",
2516
+ { key: "left", className: "dsh-tu-heat-note" },
2517
+ capped ? `\u5DF2\u8FBE\u8BFB\u53D6\u4E0A\u9650\uFF08\u6700\u591A ${String(API_LIMITS.maxDays)} \u5929\uFF09\uFF0C${range.coverageStart} \u4E4B\u524D\u7684\u683C\u5B50\u672A\u53D6\u5230\uFF1B\u66F4\u65E9\u7684\u6570\u636E\u9700\u8981\u63D0\u9AD8\u4E0A\u9650` : `\u8D26\u672C\u81EA ${ledgerFirstDay || "\u2014"} \u8D77\uFF0C\u66F4\u65E9\u7684\u65E5\u671F\u6CA1\u6709\u8BB0\u5F55\uFF1B\u5DE6\u4FA7\u88AB\u9690\u85CF\u7684\u683C\u5B50\u8868\u793A\u300C\u672A\u53D6\u5230\u300D\uFF0C\u4E0D\u662F\u300C\u5F53\u5929\u96F6\u6D88\u8017\u300D`
2518
+ )
2519
+ );
2520
+ }
2521
+ if (range.coverageEnd !== "" && range.drawnEnd < range.end) {
2522
+ notes.push(
2523
+ (0, import_react7.createElement)(
2524
+ "div",
2525
+ { key: "right", className: "dsh-tu-heat-note" },
2526
+ `\u5DF2\u53D6\u5230 ${range.coverageEnd}\uFF1B\u4E4B\u540E\u7684\u683C\u5B50\u5C1A\u672A\u53D6\u5230\uFF08\u70B9\u300C\u5237\u65B0\u300D\u91CD\u65B0\u8BFB\u53D6\uFF09`
2527
+ )
2528
+ );
2529
+ }
2530
+ return notes;
2531
+ }
2532
+ function heatStats(points, currency) {
2533
+ const active = points.filter((point) => point.turns > 0);
2534
+ const totalTokens = active.reduce((sum, point) => sum + point.total, 0);
2535
+ const totalCost = active.reduce((sum, point) => sum + point.cost, 0);
2536
+ const totalTurns = active.reduce((sum, point) => sum + point.turns, 0);
2537
+ const busiest = active.reduce(
2538
+ (best, point) => best === void 0 || point.total > best.total ? point : best,
2539
+ void 0
2540
+ );
2541
+ const streak = streaks(points);
2542
+ const stats = [
2543
+ {
2544
+ label: "\u65E5\u5747 Token",
2545
+ value: active.length === 0 ? "\u2014" : formatTokens(totalTokens / active.length),
2546
+ foot: `${String(active.length)} \u5929\u6709\u8BB0\u5F55`
2547
+ },
2548
+ {
2549
+ label: "\u5355\u65E5\u6700\u9AD8",
2550
+ value: busiest === void 0 ? "\u2014" : formatTokens(busiest.total),
2551
+ foot: busiest?.date ?? ""
2552
+ },
2553
+ {
2554
+ label: "\u5E73\u5747\u6BCF\u8F6E",
2555
+ value: totalTurns === 0 ? "\u2014" : formatTokens(totalTokens / totalTurns),
2556
+ foot: `${formatTokensExact(totalTurns)} \u8F6E`
2557
+ },
2558
+ {
2559
+ label: "\u533A\u95F4\u8D39\u7528",
2560
+ value: formatMoney(totalCost, currency),
2561
+ foot: active.length === 0 ? "" : `\u65E5\u5747 ${formatMoney(totalCost / active.length, currency)}`
2562
+ },
2563
+ {
2564
+ label: "\u8FDE\u7EED\u4F7F\u7528",
2565
+ value: `${String(streak.current)} \u5929`,
2566
+ foot: `\u6700\u957F ${String(streak.longest)} \u5929`
2567
+ }
2568
+ ];
2569
+ return (0, import_react7.createElement)(
2570
+ "div",
2571
+ { className: "dsh-tu-heat-stats" },
2572
+ ...stats.map(
2573
+ (stat) => (0, import_react7.createElement)(
2574
+ "div",
2575
+ { key: stat.label, className: "dsh-tu-heat-stat" },
2576
+ (0, import_react7.createElement)("div", { className: "dsh-tu-heat-stat-label" }, stat.label),
2577
+ (0, import_react7.createElement)("div", { className: "dsh-tu-heat-stat-value" }, stat.value),
2578
+ stat.foot.length === 0 ? null : (0, import_react7.createElement)("div", { className: "dsh-tu-heat-stat-foot" }, stat.foot)
2579
+ )
2580
+ )
2581
+ );
2582
+ }
2583
+ function createToolPanel(panel, busy, onCancel, onConfirmImport, onConfirmBackfill) {
2584
+ const actions = (confirmLabel, onConfirm) => (0, import_react7.createElement)(
2585
+ "div",
2586
+ { className: "dsh-tu-tool-actions" },
2587
+ (0, import_react7.createElement)(
2588
+ "button",
2589
+ { type: "button", className: "dsh-tu-btn", onClick: onCancel, disabled: busy },
2590
+ "\u53D6\u6D88"
2591
+ ),
2592
+ (0, import_react7.createElement)(
2593
+ "button",
2594
+ {
2595
+ type: "button",
2596
+ className: "dsh-tu-btn",
2597
+ "data-active": "true",
2598
+ onClick: () => {
2599
+ void onConfirm();
2600
+ },
2601
+ disabled: busy
2602
+ },
2603
+ busy ? "\u5904\u7406\u4E2D\u2026" : confirmLabel
2604
+ )
2605
+ );
2606
+ if (panel.kind === "import") {
2607
+ return (0, import_react7.createElement)(
2608
+ "div",
2609
+ { className: "dsh-tu-tool-panel", "data-tool-panel": "import" },
2610
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-tool-title" }, "\u5BFC\u5165\u5907\u4EFD"),
2611
+ (0, import_react7.createElement)("p", null, `\u6587\u4EF6\uFF1A${panel.fileName}`),
2612
+ (0, import_react7.createElement)(
2613
+ "p",
2614
+ null,
2615
+ `\u5171 ${String(panel.backup.recordCount)} \u6761\u8BB0\u5F55\uFF1B\u5BFC\u5165\u53EA\u8FFD\u52A0\u7F3A\u5931\u8BB0\u5F55\uFF0C\u5DF2\u5B58\u5728/\u91CD\u590D\u4F1A\u81EA\u52A8\u8DF3\u8FC7\u3002\u5907\u4EFD\u6587\u4EF6\u5305\u542B\u4F1A\u8BDD ID\u3001\u5DE5\u4F5C\u533A\u8DEF\u5F84\u7B49\u660E\u7EC6\uFF0C\u8BF7\u59A5\u5584\u4FDD\u7BA1\u3002`
2616
+ ),
2617
+ actions("\u786E\u8BA4\u5BFC\u5165", onConfirmImport)
2618
+ );
2619
+ }
2620
+ const report = panel.preview.report;
2621
+ return (0, import_react7.createElement)(
2622
+ "div",
2623
+ { className: "dsh-tu-tool-panel", "data-tool-panel": "backfill" },
2624
+ (0, import_react7.createElement)("h2", { className: "dsh-tu-tool-title" }, "\u8865\u5F55\u6570\u636E"),
2625
+ (0, import_react7.createElement)(
2626
+ "p",
2627
+ null,
2628
+ `\u626B\u63CF\u4F1A\u8BDD\u65E5\u5FD7 ${String(report.logsScanned)} \u4E2A\uFF1A\u53EF\u8865\u5F55 ${String(report.turnsBackfillable)} \u6761\uFF1B\u5DF2\u5B58\u5728 ${String(report.turnsAlreadyRecorded)} \u6761\uFF0C\u5206\u53C9\u526F\u672C ${String(report.turnsInheritedCopy)} \u6761\uFF0C\u65E0\u6CD5\u5224\u5B9A ${String(report.turnsUndecidable)} \u6761\u3002`
2629
+ ),
2630
+ (0, import_react7.createElement)(
2631
+ "p",
2632
+ null,
2633
+ "\u8865\u5F55\u53EA\u8FFD\u52A0\u7F3A\u5931\u8BB0\u5F55\uFF0C\u53EF\u91CD\u590D\u6267\u884C\u4E0D\u4F1A\u91CD\u590D\u8BA1\u6570\uFF1B\u540C\u65F6\u8986\u76D6\u88C5\u63D2\u4EF6\u524D\u7684\u5386\u53F2\u548C\u8FD0\u884C\u4E2D\u6F0F\u8BB0\u4F46\u65E5\u5FD7\u53EF\u8FD8\u539F\u7684\u8F6E\u6B21\u3002"
2634
+ ),
2635
+ actions("\u786E\u8BA4\u8865\u5F55", onConfirmBackfill)
2636
+ );
2637
+ }
2638
+ function downloadBackup(backup) {
2639
+ const blob = new Blob([JSON.stringify(backup, null, 2)], { type: "application/json" });
2640
+ const url = URL.createObjectURL(blob);
2641
+ const anchor = document.createElement("a");
2642
+ const stamp = formatBackupTimestamp();
2643
+ anchor.href = url;
2644
+ anchor.download = `token-usage-backup-${stamp}.json`;
2645
+ anchor.style.display = "none";
2646
+ document.body.appendChild(anchor);
2647
+ anchor.click();
2648
+ anchor.remove();
2649
+ window.setTimeout(() => {
2650
+ URL.revokeObjectURL(url);
2651
+ }, 1e3);
2652
+ }
2653
+ function exportGlyph() {
2654
+ return (0, import_react7.createElement)(
2655
+ "svg",
2656
+ { width: 16, height: 16, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false" },
2657
+ (0, import_react7.createElement)("path", {
2658
+ d: "M8 2.6 L8 9.4 M5.2 6.6 L8 9.4 L10.8 6.6",
2659
+ fill: "none",
2660
+ stroke: "currentColor",
2661
+ strokeWidth: 1.5,
2662
+ strokeLinecap: "round",
2663
+ strokeLinejoin: "round"
2664
+ }),
2665
+ (0, import_react7.createElement)("path", {
2666
+ d: "M2.8 10.6 L2.8 13.2 L13.2 13.2 L13.2 10.6",
2667
+ fill: "none",
2668
+ stroke: "currentColor",
2669
+ strokeWidth: 1.5,
2670
+ strokeLinecap: "round",
2671
+ strokeLinejoin: "round"
2672
+ })
2673
+ );
2674
+ }
2675
+ function importGlyph() {
2676
+ return (0, import_react7.createElement)(
2677
+ "svg",
2678
+ { width: 16, height: 16, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false" },
2679
+ (0, import_react7.createElement)("path", {
2680
+ d: "M8 9.4 L8 2.6 M5.2 5.4 L8 2.6 L10.8 5.4",
2681
+ fill: "none",
2682
+ stroke: "currentColor",
2683
+ strokeWidth: 1.5,
2684
+ strokeLinecap: "round",
2685
+ strokeLinejoin: "round"
2686
+ }),
2687
+ (0, import_react7.createElement)("path", {
2688
+ d: "M2.8 10.6 L2.8 13.2 L13.2 13.2 L13.2 10.6",
2689
+ fill: "none",
2690
+ stroke: "currentColor",
2691
+ strokeWidth: 1.5,
2692
+ strokeLinecap: "round",
2693
+ strokeLinejoin: "round"
2694
+ })
2695
+ );
2696
+ }
2697
+ function backfillGlyph() {
2698
+ return (0, import_react7.createElement)(
2699
+ "svg",
2700
+ { width: 16, height: 16, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false" },
2701
+ (0, import_react7.createElement)("ellipse", {
2702
+ cx: 7,
2703
+ cy: 4,
2704
+ rx: 4.3,
2705
+ ry: 1.8,
2706
+ fill: "none",
2707
+ stroke: "currentColor",
2708
+ strokeWidth: 1.5
2709
+ }),
2710
+ (0, import_react7.createElement)("path", {
2711
+ d: "M2.7 4 L2.7 10.2 C2.7 11.8 4.6 12.8 7 12.8 C8.1 12.8 9.1 12.6 9.9 12.2",
2712
+ fill: "none",
2713
+ stroke: "currentColor",
2714
+ strokeWidth: 1.5,
2715
+ strokeLinecap: "round"
2716
+ }),
2717
+ (0, import_react7.createElement)("path", {
2718
+ d: "M2.7 7.1 C2.7 8.8 4.6 9.8 7 9.8",
2719
+ fill: "none",
2720
+ stroke: "currentColor",
2721
+ strokeWidth: 1.5,
2722
+ strokeLinecap: "round"
2723
+ }),
2724
+ (0, import_react7.createElement)("path", {
2725
+ d: "M12.8 9.4 L12.8 13.4 M10.8 11.4 L14.8 11.4",
2726
+ fill: "none",
2727
+ stroke: "currentColor",
2728
+ strokeWidth: 1.5,
2729
+ strokeLinecap: "round"
2730
+ })
2731
+ );
2732
+ }
2733
+ function refreshGlyph() {
2734
+ return (0, import_react7.createElement)(
2735
+ "svg",
2736
+ { width: 16, height: 16, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false" },
2737
+ // The arrow head sits above the arc, so the ink box is ~0.7px above the
2738
+ // viewBox centre: shifting the group keeps the spin centred on the glyph
2739
+ // instead of wobbling around (8, 8).
2740
+ (0, import_react7.createElement)(
2741
+ "g",
2742
+ { transform: "translate(0 0.7)" },
2743
+ (0, import_react7.createElement)("path", {
2744
+ d: "M13.2 8a5.2 5.2 0 1 1-1.9-4",
2745
+ fill: "none",
2746
+ stroke: "currentColor",
2747
+ strokeWidth: 1.5,
2748
+ strokeLinecap: "round"
2749
+ }),
2750
+ (0, import_react7.createElement)("path", {
2751
+ d: "M11.6 1.4 L11.6 4.4 L8.6 4.4",
2752
+ fill: "none",
2753
+ stroke: "currentColor",
2754
+ strokeWidth: 1.5,
2755
+ strokeLinecap: "round",
2756
+ strokeLinejoin: "round"
2757
+ })
2758
+ )
2759
+ );
2760
+ }
2761
+ function closeGlyph() {
2762
+ return (0, import_react7.createElement)(
2763
+ "svg",
2764
+ { width: 16, height: 16, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false" },
2765
+ (0, import_react7.createElement)("path", {
2766
+ d: "M4 4 L12 12 M12 4 L4 12",
2767
+ stroke: "currentColor",
2768
+ strokeWidth: 1.6,
2769
+ strokeLinecap: "round"
2770
+ })
2771
+ );
2772
+ }
2773
+ function infoGlyph() {
2774
+ return (0, import_react7.createElement)(
2775
+ "svg",
2776
+ { width: 16, height: 16, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false" },
2777
+ (0, import_react7.createElement)("circle", {
2778
+ cx: 8,
2779
+ cy: 8,
2780
+ r: 6.6,
2781
+ fill: "none",
2782
+ stroke: "currentColor",
2783
+ strokeWidth: 1.4
2784
+ }),
2785
+ (0, import_react7.createElement)("circle", { cx: 8, cy: 4.9, r: 0.95, fill: "currentColor" }),
2786
+ (0, import_react7.createElement)("path", {
2787
+ d: "M8 7.1 V11.4",
2788
+ stroke: "currentColor",
2789
+ strokeWidth: 1.5,
2790
+ strokeLinecap: "round"
2791
+ })
2792
+ );
2793
+ }
2794
+ function createPanelInfoButton(id, title, open, paragraphs, onToggle) {
2795
+ return (0, import_react7.createElement)(
2796
+ "div",
2797
+ { className: "dsh-tu-anchor dsh-tu-panel-info" },
2798
+ (0, import_react7.createElement)(
2799
+ "button",
2800
+ {
2801
+ type: "button",
2802
+ className: "dsh-tu-icon-btn",
2803
+ "aria-label": title,
2804
+ "aria-expanded": open,
2805
+ "aria-controls": open ? `dsh-tu-info-${id}` : void 0,
2806
+ title: `${title}\uFF08\u70B9\u51FB\u67E5\u770B\u8BF4\u660E\uFF09`,
2807
+ onClick: () => onToggle(open ? null : id),
2808
+ onKeyDown: (event) => {
2809
+ if (event.key === "Escape") onToggle(null);
2810
+ }
2811
+ },
2812
+ infoGlyph()
2813
+ ),
2814
+ open ? (0, import_react7.createElement)(
2815
+ "div",
2816
+ {
2817
+ id: `dsh-tu-info-${id}`,
2818
+ className: "dsh-tu-popover dsh-tu-panel-popover",
2819
+ role: "dialog",
2820
+ "aria-label": title
2821
+ },
2822
+ (0, import_react7.createElement)("h4", null, title),
2823
+ ...paragraphs.map((paragraph) => (0, import_react7.createElement)("p", { key: paragraph }, paragraph))
2824
+ ) : null
2825
+ );
2826
+ }
2827
+ function createPricingInfoButton(data, state) {
2828
+ const pricing = data?.pricing;
2829
+ const { open, pinned, setHover, setPinned } = state;
2830
+ return (0, import_react7.createElement)(
2831
+ "div",
2832
+ {
2833
+ className: "dsh-tu-anchor",
2834
+ onMouseEnter: () => {
2835
+ setHover(true);
2836
+ },
2837
+ onMouseLeave: () => {
2838
+ setHover(false);
2839
+ }
2840
+ },
2841
+ (0, import_react7.createElement)(
2842
+ "button",
2843
+ {
2844
+ type: "button",
2845
+ className: "dsh-tu-icon-btn",
2846
+ "aria-label": "\u4EF7\u683C\u8BA1\u7B97\u8BF4\u660E",
2847
+ "aria-expanded": open,
2848
+ title: "\u4EF7\u683C\u8BA1\u7B97\u8BF4\u660E\uFF08\u70B9\u51FB\u53EF\u56FA\u5B9A\uFF09",
2849
+ onKeyDown: (event) => {
2850
+ if (event.key === "Escape") setPinned(false);
2851
+ },
2852
+ onClick: () => {
2853
+ setPinned(!pinned);
2854
+ }
2855
+ },
2856
+ (0, import_react7.createElement)(
2857
+ "svg",
2858
+ { width: 16, height: 16, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false" },
2859
+ (0, import_react7.createElement)("circle", {
2860
+ cx: 8,
2861
+ cy: 8,
2862
+ r: 6.6,
2863
+ fill: "none",
2864
+ stroke: "currentColor",
2865
+ strokeWidth: 1.4
2866
+ }),
2867
+ (0, import_react7.createElement)("circle", { cx: 8, cy: 4.9, r: 0.95, fill: "currentColor" }),
2868
+ (0, import_react7.createElement)("path", {
2869
+ d: "M8 7.1 V11.4",
2870
+ stroke: "currentColor",
2871
+ strokeWidth: 1.5,
2872
+ strokeLinecap: "round"
2873
+ })
2874
+ )
2875
+ ),
2876
+ open ? (0, import_react7.createElement)(
2877
+ "div",
2878
+ { className: "dsh-tu-popover", role: "note" },
2879
+ (0, import_react7.createElement)("h4", null, "\u8D39\u7528\u662F\u600E\u4E48\u7B97\u51FA\u6765\u7684"),
2880
+ (0, import_react7.createElement)(
2881
+ "div",
2882
+ null,
2883
+ "\u91D1\u989D = ( \u7F13\u5B58\u672A\u547D\u4E2D \xD7 \u672A\u547D\u4E2D\u4EF7 + \u7F13\u5B58\u547D\u4E2D \xD7 \u547D\u4E2D\u4EF7 + \u7F13\u5B58\u5199\u5165 \xD7 \u672A\u547D\u4E2D\u4EF7 + \u8F93\u51FA \xD7 \u8F93\u51FA\u4EF7 ) \xF7 1e6 \xD7 \u65F6\u6BB5\u500D\u7387"
2884
+ ),
2885
+ // The formula alone is not checkable: show the prices it multiplies,
2886
+ // and the date they were read off the official page.
2887
+ createPriceTable(pricing),
2888
+ (0, import_react7.createElement)(
2889
+ "dl",
2890
+ null,
2891
+ (0, import_react7.createElement)("dt", null, "\u4EF7\u76EE\u7248\u672C"),
2892
+ (0, import_react7.createElement)("dd", null, `${pricing?.label ?? "\u2014"}\uFF08${pricing?.version ?? "\u2014"}\uFF09`),
2893
+ (0, import_react7.createElement)("dt", null, "\u65F6\u6BB5"),
2894
+ (0, import_react7.createElement)("dd", null, pricing?.peakRule ?? "\u2014"),
2895
+ (0, import_react7.createElement)("dt", null, "\u5B98\u7F51"),
2896
+ (0, import_react7.createElement)(
2897
+ "dd",
2898
+ null,
2899
+ (0, import_react7.createElement)("code", null, pricing?.source ?? "\u2014")
2900
+ ),
2901
+ (0, import_react7.createElement)("dt", null, "\u67E5\u8BE2\u65E5\u671F"),
2902
+ (0, import_react7.createElement)("dd", null, pricing?.checkedAt ?? "\u2014")
2903
+ ),
2904
+ (0, import_react7.createElement)(
2905
+ "div",
2906
+ { className: "dsh-tu-subtle" },
2907
+ "\xB7 \u7F13\u5B58\u5199\u5165\u6309\u300C\u7F13\u5B58\u672A\u547D\u4E2D\u300D\u8BA1\u4EF7\uFF1A\u5B98\u65B9\u672A\u5355\u72EC\u516C\u5E03\u5199\u5165\u4EF7\uFF1B",
2908
+ (0, import_react7.createElement)("br", null),
2909
+ "\xB7 \u63A8\u7406 token \u5DF2\u5305\u542B\u5728\u8F93\u51FA token \u5185\uFF0C\u4E0D\u91CD\u590D\u8BA1\u4EF7\uFF1B",
2910
+ (0, import_react7.createElement)("br", null),
2911
+ "\xB7 \u6BCF\u8F6E\u6309\u5176\u5404\u81EA\u7684\u7ED3\u7B97\u65F6\u523B\u5224\u5B9A\u65F6\u6BB5\u4E0E\u4EF7\u76EE\u884C\uFF1B",
2912
+ (0, import_react7.createElement)("br", null),
2913
+ "\xB7 \u8D39\u7528\u5728\u5199\u5165\u8D26\u672C\u65F6\u51BB\u7ED3\uFF0C\u4E4B\u540E\u8C03\u4EF7\u6216\u6539\u5E01\u79CD\u90FD\u4E0D\u4F1A\u6539\u5199\u5386\u53F2\uFF08\u53EF\u7528 scripts/recompute-cost.mjs \u663E\u5F0F\u91CD\u7B97\uFF09\u3002"
2914
+ )
2915
+ ) : null
2916
+ );
2917
+ }
2918
+ function createPriceTable(pricing) {
2919
+ if (pricing === void 0 || pricing.rows.length === 0) {
2920
+ return (0, import_react7.createElement)("div", { className: "dsh-tu-subtle" }, "\u4EF7\u76EE\u8868\u52A0\u8F7D\u4E2D\u2026");
2921
+ }
2922
+ const symbol = pricing.currency === "CNY" ? "\xA5" : "$";
2923
+ const per = `${symbol} / \u767E\u4E07 token`;
2924
+ const ratio = pricing.offPeakRatio;
2925
+ const hasPeak = pricing.peakWindows.length > 0 && ratio !== 1;
2926
+ const allOffPeak = pricing.peakWindows.length === 0 && ratio !== 1;
2927
+ const rowCountByModel = /* @__PURE__ */ new Map();
2928
+ for (const row of pricing.rows) {
2929
+ rowCountByModel.set(row.model, (rowCountByModel.get(row.model) ?? 0) + 1);
2930
+ }
2931
+ const body = [];
2932
+ for (const row of pricing.rows) {
2933
+ const showDate = (rowCountByModel.get(row.model) ?? 1) > 1;
2934
+ const modelChildren = [row.model];
2935
+ if (showDate) {
2936
+ modelChildren.push(
2937
+ (0, import_react7.createElement)(
2938
+ "div",
2939
+ { key: "date", className: "dsh-tu-subtle" },
2940
+ `\u751F\u6548 ${formatEffective(row.effectiveFrom)}`
2941
+ )
2942
+ );
2943
+ }
2944
+ const modelCell = (0, import_react7.createElement)("td", { rowSpan: hasPeak ? 2 : 1 }, ...modelChildren);
2945
+ const priceCells = (values) => values.map(
2946
+ (value, index) => (0, import_react7.createElement)("td", { key: `v${String(index)}` }, formatUnitPrice(value))
2947
+ );
2948
+ if (hasPeak) {
2949
+ body.push(
2950
+ (0, import_react7.createElement)(
2951
+ "tr",
2952
+ { key: `${row.model}-${row.effectiveFrom}-peak` },
2953
+ modelCell,
2954
+ (0, import_react7.createElement)("td", { className: "dsh-tu-price-window" }, "\u9AD8\u5CF0"),
2955
+ ...priceCells([row.cacheHit, row.cacheMiss, row.output])
2956
+ ),
2957
+ (0, import_react7.createElement)(
2958
+ "tr",
2959
+ { key: `${row.model}-${row.effectiveFrom}-off` },
2960
+ (0, import_react7.createElement)("td", { className: "dsh-tu-price-window" }, "\u7A7A\u95F2"),
2961
+ ...priceCells([row.cacheHit * ratio, row.cacheMiss * ratio, row.output * ratio])
2962
+ )
2963
+ );
2964
+ } else {
2965
+ const windowLabel = allOffPeak ? "\u7A7A\u95F2" : "\u6807\u51C6";
2966
+ const values = allOffPeak ? [row.cacheHit * ratio, row.cacheMiss * ratio, row.output * ratio] : [row.cacheHit, row.cacheMiss, row.output];
2967
+ body.push(
2968
+ (0, import_react7.createElement)(
2969
+ "tr",
2970
+ { key: `${row.model}-${row.effectiveFrom}` },
2971
+ modelCell,
2972
+ (0, import_react7.createElement)("td", { className: "dsh-tu-price-window" }, windowLabel),
2973
+ ...priceCells(values)
2974
+ )
2975
+ );
2976
+ }
2977
+ }
2978
+ const utcOffset = `UTC${pricing.timezoneOffsetMinutes >= 0 ? "+" : "-"}${String(Math.abs(pricing.timezoneOffsetMinutes) / 60)}`;
2979
+ const head = hasPeak ? `\u5B98\u65B9\u4EF7\u76EE\uFF08${per}\uFF09` : allOffPeak ? `\u4EF7\u76EE\uFF08${per}\uFF1B\u5F53\u524D\u65E0\u9AD8\u5CF0\u65F6\u6BB5\uFF0C\u5168\u90E8\u6309\u7A7A\u95F2\u4EF7\u8BA1\u8D39\uFF09` : `\u5B98\u65B9\u4EF7\u76EE\uFF08${per}\uFF1B\u65E0\u5CF0\u8C37\u5DEE\u5F02\uFF09`;
2980
+ const windowNote = hasPeak ? `\u9AD8\u5CF0 = \u5B98\u7F51\u516C\u5E03\u4EF7\uFF1B\u7A7A\u95F2 = \u9AD8\u5CF0 \xD7 ${String(ratio)}\uFF08\u6298\u7B97\u503C\uFF0C\u975E\u5B98\u7F51\u516C\u5E03\u4EF7\uFF09\uFF1B\u9AD8\u5CF0 ${pricing.peakWindows.join(" / ")}\uFF08${utcOffset}\uFF09\uFF0C\u5176\u4F59\u65F6\u6BB5\uFF08\u542B\u5468\u672B\uFF09\u6309\u7A7A\u95F2\u8BA1\u4EF7` : allOffPeak ? `\u5F53\u524D\u89C4\u5219\u6CA1\u6709\u9AD8\u5CF0\u65F6\u6BB5\uFF0C\u6240\u6709\u65F6\u6BB5\u6309\u5B98\u7F51\u4EF7 \xD7 ${String(ratio)}\uFF08\u7A7A\u95F2\u500D\u7387\uFF09\u8BA1\u8D39` : `\u9AD8\u5CF0\u4E0E\u7A7A\u95F2\u540C\u4EF7\uFF08\u7A7A\u95F2\u500D\u7387 \xD7${String(ratio)}\uFF09`;
2981
+ return (0, import_react7.createElement)(
2982
+ "div",
2983
+ { className: "dsh-tu-price" },
2984
+ (0, import_react7.createElement)("div", { className: "dsh-tu-price-head" }, head),
2985
+ (0, import_react7.createElement)(
2986
+ "table",
2987
+ null,
2988
+ (0, import_react7.createElement)(
2989
+ "thead",
2990
+ null,
2991
+ (0, import_react7.createElement)(
2992
+ "tr",
2993
+ null,
2994
+ (0, import_react7.createElement)("th", null, "\u6A21\u578B"),
2995
+ (0, import_react7.createElement)("th", { className: "dsh-tu-price-window" }, "\u65F6\u6BB5"),
2996
+ (0, import_react7.createElement)("th", null, "\u7F13\u5B58\u547D\u4E2D"),
2997
+ (0, import_react7.createElement)("th", null, "\u7F13\u5B58\u672A\u547D\u4E2D"),
2998
+ (0, import_react7.createElement)("th", null, "\u8F93\u51FA")
2999
+ )
3000
+ ),
3001
+ (0, import_react7.createElement)("tbody", null, ...body)
3002
+ ),
3003
+ // What is NOT the official number must say so: a config override is priced
3004
+ // from the deployment's own table, not from the page below.
3005
+ pricing.overriddenModels.length === 0 ? null : (0, import_react7.createElement)(
3006
+ "div",
3007
+ { className: "dsh-tu-subtle" },
3008
+ `\u672C\u5730\u914D\u7F6E\u8986\u76D6\u4E86 ${pricing.overriddenModels.join("\u3001")} \u7684\u4EF7\u683C\uFF0C\u4E0A\u9762\u8FD9\u51E0\u884C\u4ECD\u662F\u5B98\u7F51\u4EF7\uFF08\u7A7A\u95F2\u5217\u4E3A\u6309\u500D\u7387\u6298\u7B97\uFF09`
3009
+ ),
3010
+ (0, import_react7.createElement)("div", { className: "dsh-tu-subtle" }, windowNote),
3011
+ (0, import_react7.createElement)(
3012
+ "div",
3013
+ { className: "dsh-tu-subtle" },
3014
+ `\u751F\u6548 ${formatEffective(pricing.rows[0]?.effectiveFrom ?? "")}\uFF1B\u4EE5\u4E0A\u4E3A ${pricing.checkedAt} \u67E5\u8BE2\u5230\u7684\u5B98\u7F51\u4EF7\u683C\uFF08\u7A7A\u95F2\u5217\u4E3A\u6298\u7B97\uFF09\uFF0C\u4EE5\u5B98\u65B9\u9875\u9762\u4E0E\u8D26\u5355\u4E3A\u51C6`
3015
+ )
3016
+ );
3017
+ }
3018
+ function formatEffective(iso) {
3019
+ if (iso.length === 0) return "\u2014";
3020
+ const match = /^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/.exec(iso);
3021
+ return match === null ? iso : `${match[1]} ${match[2]}`;
3022
+ }
3023
+ function formatCount(value) {
3024
+ return Number.isFinite(value) ? Math.round(value).toLocaleString("en-US") : "\u2014";
3025
+ }
3026
+ function formatRateBound(rate) {
3027
+ const percent = rate * 100;
3028
+ return `${Number.isInteger(percent) ? String(percent) : percent.toFixed(1)}%`;
3029
+ }
3030
+ function createSubpanel(title, ...children) {
3031
+ return (0, import_react7.createElement)(
3032
+ "div",
3033
+ { className: "dsh-tu-subpanel" },
3034
+ (0, import_react7.createElement)("h3", { className: "dsh-tu-subpanel-title" }, title),
3035
+ ...children
3036
+ );
3037
+ }
3038
+ function createCard(label, value, foot, tone = "blue") {
3039
+ return (0, import_react7.createElement)(
3040
+ "div",
3041
+ { className: "dsh-tu-card", "data-tone": tone },
3042
+ (0, import_react7.createElement)("div", { className: "dsh-tu-card-label" }, label),
3043
+ (0, import_react7.createElement)("div", { className: "dsh-tu-card-value" }, value),
3044
+ foot.length === 0 ? null : (0, import_react7.createElement)("div", { className: "dsh-tu-card-foot" }, foot)
3045
+ );
3046
+ }
3047
+ function platformLabel(platform) {
3048
+ if (platform === "windows") return "Windows";
3049
+ if (platform === "unix") return "Linux/WSL";
3050
+ return "\u672A\u77E5\u5E73\u53F0";
3051
+ }
3052
+ function WorkspaceTable(props) {
3053
+ const [expanded, setExpanded] = (0, import_react7.useState)(null);
3054
+ const { facets, currency, onFilterPath } = props;
3055
+ if (facets.length === 0) {
3056
+ return (0, import_react7.createElement)("div", { className: "dsh-tu-empty" }, "\u6CA1\u6709\u6570\u636E");
3057
+ }
3058
+ const total = facets.reduce((sum, row) => sum + row.tokens, 0);
3059
+ const anyMerged = facets.some(
3060
+ (facet) => (facet.mergedCount ?? (facet.paths?.length ?? 1)) > 1
3061
+ );
3062
+ return (0, import_react7.createElement)(
3063
+ "div",
3064
+ null,
3065
+ anyMerged ? (0, import_react7.createElement)(
3066
+ "div",
3067
+ { className: "dsh-tu-subtle dsh-tu-ws-note" },
3068
+ "\u540C\u540D\u5DE5\u4F5C\u533A\u5DF2\u6309\u540D\u79F0\u5408\u5E76\uFF1B\u70B9\u51FB\u884C\u5185\u300CN \u4E2A\u8DEF\u5F84\u300D\u53EF\u5C55\u5F00\u5404\u8DEF\u5F84\u5C0F\u8BA1\uFF0C\u5E76\u53EF\u53EA\u67E5\u770B\u67D0\u4E00\u6761\u8DEF\u5F84\u3002"
3069
+ ) : null,
3070
+ (0, import_react7.createElement)(
3071
+ "table",
3072
+ { className: "dsh-tu-table" },
3073
+ (0, import_react7.createElement)(
3074
+ "thead",
3075
+ null,
3076
+ (0, import_react7.createElement)(
3077
+ "tr",
3078
+ null,
3079
+ (0, import_react7.createElement)("th", null, "\u5DE5\u4F5C\u533A"),
3080
+ (0, import_react7.createElement)("th", null, "\u8F6E\u6B21"),
3081
+ (0, import_react7.createElement)("th", null, "Token"),
3082
+ (0, import_react7.createElement)("th", null, "\u5360\u6BD4"),
3083
+ (0, import_react7.createElement)("th", null, "\u8D39\u7528")
3084
+ )
3085
+ ),
3086
+ (0, import_react7.createElement)(
3087
+ "tbody",
3088
+ null,
3089
+ ...facets.flatMap((facet) => {
3090
+ const paths = facet.paths ?? [];
3091
+ const merged = facet.mergedCount ?? (paths.length > 0 ? paths.length : 1);
3092
+ const share = total === 0 ? 0 : facet.tokens / total * 100;
3093
+ const rowKey = facet.key.length === 0 ? "(unattributed)" : facet.key;
3094
+ const rows = [
3095
+ (0, import_react7.createElement)(
3096
+ "tr",
3097
+ { key: rowKey },
3098
+ (0, import_react7.createElement)(
3099
+ "td",
3100
+ { title: facet.key },
3101
+ facet.label,
3102
+ facet.key.length === 0 ? (0, import_react7.createElement)("span", { className: "dsh-tu-tag" }, "\u672A\u6807\u6CE8") : null,
3103
+ merged > 1 ? (0, import_react7.createElement)(
3104
+ "button",
3105
+ {
3106
+ type: "button",
3107
+ className: "dsh-tu-tag dsh-tu-tag-btn",
3108
+ "aria-expanded": expanded === rowKey,
3109
+ title: paths.map(
3110
+ (path) => `${platformLabel(path.platform)}\uFF1A${path.workspace}
3111
+ ${formatTokensExact(path.turns)} \u8F6E \xB7 ${formatTokens(path.tokens)} token \xB7 ${formatMoney(path.cost, currency)}`
3112
+ ).join("\n"),
3113
+ onClick: () => {
3114
+ setExpanded(expanded === rowKey ? null : rowKey);
3115
+ }
3116
+ },
3117
+ `${String(merged)} \u4E2A\u8DEF\u5F84`
3118
+ ) : null
3119
+ ),
3120
+ (0, import_react7.createElement)("td", null, formatTokensExact(facet.turns)),
3121
+ (0, import_react7.createElement)("td", null, formatTokensExact(facet.tokens)),
3122
+ (0, import_react7.createElement)("td", null, `${share.toFixed(1)}%`),
3123
+ (0, import_react7.createElement)("td", null, formatMoney(facet.cost, currency))
3124
+ )
3125
+ ];
3126
+ if (expanded === rowKey && paths.length > 0) {
3127
+ rows.push(
3128
+ (0, import_react7.createElement)(
3129
+ "tr",
3130
+ { key: `${rowKey}-paths`, className: "dsh-tu-path-row" },
3131
+ (0, import_react7.createElement)(
3132
+ "td",
3133
+ { colSpan: 5 },
3134
+ (0, import_react7.createElement)(
3135
+ "div",
3136
+ { className: "dsh-tu-ws-paths" },
3137
+ ...paths.map(
3138
+ (path) => (0, import_react7.createElement)(
3139
+ "div",
3140
+ { key: path.workspace, className: "dsh-tu-ws-path" },
3141
+ (0, import_react7.createElement)(
3142
+ "span",
3143
+ { className: "dsh-tu-ws-platform" },
3144
+ platformLabel(path.platform)
3145
+ ),
3146
+ (0, import_react7.createElement)(
3147
+ "code",
3148
+ { className: "dsh-tu-ws-raw", title: path.workspace },
3149
+ path.workspace
3150
+ ),
3151
+ (0, import_react7.createElement)(
3152
+ "span",
3153
+ { className: "dsh-tu-ws-nums" },
3154
+ `${formatTokensExact(path.turns)} \u8F6E \xB7 ${formatTokens(path.tokens)} token \xB7 ${formatMoney(path.cost, currency)}`
3155
+ ),
3156
+ (0, import_react7.createElement)(
3157
+ "button",
3158
+ {
3159
+ type: "button",
3160
+ className: "dsh-tu-btn dsh-tu-ws-filter",
3161
+ onClick: () => {
3162
+ onFilterPath(path.workspace);
3163
+ }
3164
+ },
3165
+ "\u53EA\u770B\u6B64\u8DEF\u5F84"
3166
+ )
3167
+ )
3168
+ )
3169
+ )
3170
+ )
3171
+ )
3172
+ );
3173
+ }
3174
+ return rows;
3175
+ })
3176
+ )
3177
+ )
3178
+ );
3179
+ }
3180
+ function facetTable(facets, currency, firstHeader) {
3181
+ if (facets.length === 0) {
3182
+ return (0, import_react7.createElement)("div", { className: "dsh-tu-empty" }, "\u6CA1\u6709\u6570\u636E");
3183
+ }
3184
+ return (0, import_react7.createElement)(
3185
+ "table",
3186
+ { className: "dsh-tu-table" },
3187
+ (0, import_react7.createElement)(
3188
+ "thead",
3189
+ null,
3190
+ (0, import_react7.createElement)(
3191
+ "tr",
3192
+ null,
3193
+ (0, import_react7.createElement)("th", null, firstHeader),
3194
+ (0, import_react7.createElement)(
3195
+ "th",
3196
+ {
3197
+ title: "dsh \u4E0A\u62A5\u7684 provider id\uFF08\u63A5\u5165\u6E20\u9053/\u8D26\u53F7\uFF09\uFF1A\u540C\u4E00\u6A21\u578B\u53EF\u80FD\u901A\u8FC7\u4E0D\u540C\u63A5\u5165\u65B9\u4F7F\u7528\uFF0C\u56E0\u6B64\u5206\u884C\u663E\u793A"
3198
+ },
3199
+ "\u63A5\u5165\u65B9"
3200
+ ),
3201
+ (0, import_react7.createElement)(
3202
+ "th",
3203
+ {
3204
+ title: "\u8BE5\u6A21\u578B\u53C2\u4E0E\u8FC7\u7684\u8F6E\u6B21\u6570\uFF1B\u4E00\u8F6E\u5207\u6362\u591A\u4E2A\u6A21\u578B\u4F1A\u5206\u522B\u8BA1\u5165\u591A\u884C\uFF0C\u6545\u5404\u884C\u4E4B\u548C\u53EF\u80FD\u5927\u4E8E\u7D2F\u8BA1\u8F6E\u6B21"
3205
+ },
3206
+ "\u8F6E\u6B21"
3207
+ ),
3208
+ (0, import_react7.createElement)("th", null, "Token"),
3209
+ (0, import_react7.createElement)("th", null, "\u5360\u6BD4"),
3210
+ (0, import_react7.createElement)("th", null, "\u8D39\u7528")
3211
+ )
3212
+ ),
3213
+ (0, import_react7.createElement)(
3214
+ "tbody",
3215
+ null,
3216
+ ...facets.map((facet) => {
3217
+ const total = facets.reduce((sum, row) => sum + row.tokens, 0);
3218
+ const share = total === 0 ? 0 : facet.tokens / total * 100;
3219
+ return (0, import_react7.createElement)(
3220
+ "tr",
3221
+ { key: facet.key || "(unattributed)" },
3222
+ (0, import_react7.createElement)(
3223
+ "td",
3224
+ { title: facet.key },
3225
+ facet.label,
3226
+ facet.key.length === 0 ? (0, import_react7.createElement)("span", { className: "dsh-tu-tag" }, "\u672A\u6807\u6CE8") : null
3227
+ ),
3228
+ (0, import_react7.createElement)(
3229
+ "td",
3230
+ {
3231
+ title: facet.provider === void 0 || facet.provider.length === 0 ? "\u672A\u6807\u6CE8\u63A5\u5165\u65B9" : `${facet.provider}/${facet.label}`
3232
+ },
3233
+ facet.provider === void 0 || facet.provider.length === 0 ? "\u2014" : facet.provider
3234
+ ),
3235
+ (0, import_react7.createElement)("td", null, formatTokensExact(facet.turns)),
3236
+ (0, import_react7.createElement)("td", null, formatTokensExact(facet.tokens)),
3237
+ (0, import_react7.createElement)("td", null, `${share.toFixed(1)}%`),
3238
+ (0, import_react7.createElement)("td", null, formatMoney(facet.cost, currency))
3239
+ );
3240
+ })
3241
+ )
3242
+ );
3243
+ }
3244
+ function healthNoticeKey(health) {
3245
+ return [
3246
+ health.malformedLines,
3247
+ health.unsupportedRecords,
3248
+ health.writeErrors,
3249
+ health.skippedTurns,
3250
+ health.droppedRecords,
3251
+ health.pendingWrites,
3252
+ health.currencyMismatches,
3253
+ health.ledgerTruncated ? 1 : 0
3254
+ ].join("|");
3255
+ }
3256
+ function createNoticeBar(tone, text, onClose) {
3257
+ const alert = tone === "error" || tone === "warn";
3258
+ return (0, import_react7.createElement)(
3259
+ "div",
3260
+ {
3261
+ className: "dsh-tu-notice",
3262
+ "data-kind": tone,
3263
+ role: alert ? "alert" : "status",
3264
+ "aria-live": alert ? "assertive" : "polite"
3265
+ },
3266
+ (0, import_react7.createElement)("span", { className: "dsh-tu-notice-text" }, text),
3267
+ (0, import_react7.createElement)(
3268
+ "button",
3269
+ {
3270
+ type: "button",
3271
+ className: "dsh-tu-notice-close",
3272
+ title: "\u5173\u95ED\u901A\u77E5",
3273
+ "aria-label": "\u5173\u95ED\u901A\u77E5",
3274
+ onClick: onClose
3275
+ },
3276
+ closeGlyph()
3277
+ )
3278
+ );
3279
+ }
3280
+ function createHealthNotice(data, onDismiss) {
3281
+ const problems = [];
3282
+ if (data.health.malformedLines > 0) {
3283
+ problems.push(`${String(data.health.malformedLines)} \u884C\u8D26\u672C\u65E0\u6CD5\u89E3\u6790\uFF08\u5DF2\u8DF3\u8FC7\uFF09`);
3284
+ }
3285
+ if (data.health.unsupportedRecords > 0) {
3286
+ problems.push(
3287
+ `${String(data.health.unsupportedRecords)} \u884C\u8D26\u672C\u7531\u66F4\u65B0\u7248\u672C\u7684\u63D2\u4EF6\u5199\u5165\uFF0C\u5F53\u524D\u7248\u672C\u8BFB\u4E0D\u4E86\uFF08\u672A\u8BA1\u5165\uFF09`
3288
+ );
3289
+ }
3290
+ if (data.health.writeErrors > 0) {
3291
+ problems.push(
3292
+ `${String(data.health.writeErrors)} \u6B21\u5199\u5165\u5931\u8D25\uFF1A${data.health.lastWriteError || "\u672A\u77E5\u539F\u56E0"}`
3293
+ );
3294
+ }
3295
+ if (data.health.skippedTurns > 0) {
3296
+ problems.push(`${String(data.health.skippedTurns)} \u8F6E\u56E0\u7528\u91CF\u65E0\u6CD5\u786E\u8BC1\u800C\u672A\u8BB0\u5F55`);
3297
+ }
3298
+ if (data.health.droppedRecords > 0) {
3299
+ problems.push(`${String(data.health.droppedRecords)} \u6761\u8BB0\u5F55\u56E0\u53CD\u590D\u5199\u5165\u5931\u8D25\u88AB\u4E22\u5F03`);
3300
+ }
3301
+ if (data.health.pendingWrites > 0) {
3302
+ problems.push(`${String(data.health.pendingWrites)} \u6761\u5F85\u5199\u5165`);
3303
+ }
3304
+ if (data.health.currencyMismatches > 0) {
3305
+ problems.push(
3306
+ `${String(data.health.currencyMismatches)} \u6761\u8BB0\u5F55\u4EE5\u5176\u5B83\u5E01\u79CD\u8BA1\u4EF7\uFF0C\u5176\u91D1\u989D\u672A\u8BA1\u5165\u4EE5\u4E0A\u8D39\u7528\u5408\u8BA1\uFF08Token \u4ECD\u8BA1\u5165\uFF09`
3307
+ );
3308
+ }
3309
+ if (data.health.ledgerTruncated) {
3310
+ problems.push(
3311
+ `\u8D26\u672C\u8BB0\u5F55\u6570\u8D85\u8FC7\u8BFB\u53D6\u4E0A\u9650\uFF0C\u4EC5\u7EDF\u8BA1\u6700\u65B0 ${formatTokensExact(API_LIMITS.maxRecords)} \u6761`
3312
+ );
3313
+ }
3314
+ if (problems.length === 0) return null;
3315
+ return createNoticeBar("warn", `\u6CE8\u610F\uFF1A${problems.join("\uFF1B")}`, onDismiss);
3316
+ }
3317
+ function hasFilter(workspace, model) {
3318
+ return workspace !== null || model !== null;
3319
+ }
3320
+ function formatPercent(buckets) {
3321
+ if (buckets === void 0) return "\u2014";
3322
+ const prompt = buckets.cacheRead + buckets.uncachedInput;
3323
+ if (prompt === 0) return "\u2014";
3324
+ return `${(buckets.cacheRead / prompt * 100).toFixed(1)}%`;
3325
+ }
3326
+ function describeGranularity(granularity) {
3327
+ if (granularity === "day") return "\u6309\u5929";
3328
+ if (granularity === "week") return "\u6309\u5468\uFF08\u5468\u4E00\u8D77\uFF09";
3329
+ return "\u6309\u6708";
3330
+ }
3331
+
3332
+ // src/client/styles.ts
3333
+ var STYLE_ID = "dsh-token-usage-styles";
3334
+ var CSS = `
3335
+ .dsh-tu-root {
3336
+ height: 100%;
3337
+ overflow: auto;
3338
+ padding: 24px 28px 48px;
3339
+ box-sizing: border-box;
3340
+ background: var(--dsw-alias-bg-base);
3341
+ color: var(--dsw-alias-label-primary);
3342
+ font-size: 13px;
3343
+ line-height: 1.5;
3344
+ /* Fixed categorical palette for the new charts. Kept out of the theme tokens
3345
+ on purpose: these are series identities, not semantic state colours. */
3346
+ --dsh-tu-cat-0: #3b82f6;
3347
+ --dsh-tu-cat-1: #f59e0b;
3348
+ --dsh-tu-cat-2: #10b981;
3349
+ --dsh-tu-cat-3: #8b5cf6;
3350
+ --dsh-tu-cat-4: #ef4444;
3351
+ }
3352
+ /* Content width cap. It used to be 1180px, which left the calendar stuck at a
3353
+ 1142px content box no matter how wide the window got \u2014 on a large screen the
3354
+ empty space was then *outside* the shell while the calendar could not use it.
3355
+ 1440px keeps prose and tables readable while letting a year of weeks actually
3356
+ fill the row (the cell size caps at 22px, after which the gaps absorb the
3357
+ rest, so nothing turns into seven enormous rows). */
3358
+ .dsh-tu-shell { max-width: 1440px; margin: 0 auto; }
3359
+ .dsh-tu-header {
3360
+ display: flex;
3361
+ align-items: baseline;
3362
+ gap: 12px;
3363
+ flex-wrap: wrap;
3364
+ margin-bottom: 4px;
3365
+ }
3366
+ .dsh-tu-title { font-size: 20px; font-weight: 600; margin: 0; }
3367
+ .dsh-tu-subtle { color: var(--dsw-alias-label-secondary); font-size: 12px; }
3368
+ .dsh-tu-spacer { flex: 1 1 auto; }
3369
+ .dsh-tu-btn {
3370
+ appearance: none;
3371
+ border: 1px solid var(--dsw-alias-border-l1);
3372
+ background: var(--dsw-alias-bg-layer-1);
3373
+ color: var(--dsw-alias-label-primary);
3374
+ border-radius: 7px;
3375
+ padding: 5px 11px;
3376
+ font-size: 12px;
3377
+ cursor: pointer;
3378
+ transition: background .12s ease, border-color .12s ease;
3379
+ }
3380
+ .dsh-tu-btn:hover:not(:disabled) { border-color: var(--dsw-alias-border-l2); }
3381
+ .dsh-tu-btn:disabled { opacity: .5; cursor: default; }
3382
+ .dsh-tu-btn[data-active="true"] {
3383
+ border-color: var(--dsw-alias-brand-primary);
3384
+ color: var(--dsw-alias-brand-primary);
3385
+ }
3386
+ .dsh-tu-group { display: inline-flex; gap: 0; }
3387
+ .dsh-tu-group .dsh-tu-btn { border-radius: 0; margin-left: -1px; }
3388
+ .dsh-tu-group .dsh-tu-btn:first-child { border-radius: 7px 0 0 7px; margin-left: 0; }
3389
+ .dsh-tu-group .dsh-tu-btn:last-child { border-radius: 0 7px 7px 0; }
3390
+ /* The -1px pull collapses adjacent borders, which also lets the NEXT button's
3391
+ left border paint over the active one's right border \u2014 the selected button
3392
+ appeared to have three sides. Lifting it above its siblings restores all four. */
3393
+ .dsh-tu-group .dsh-tu-btn[data-active="true"] { position: relative; z-index: 1; }
3394
+
3395
+ .dsh-tu-section-title {
3396
+ display: flex;
3397
+ align-items: center;
3398
+ gap: 8px;
3399
+ margin: 18px 0 -6px;
3400
+ color: var(--dsw-alias-label-secondary);
3401
+ font-size: 11px;
3402
+ font-weight: 500;
3403
+ letter-spacing: .04em;
3404
+ }
3405
+ .dsh-tu-section-title::after {
3406
+ content: "";
3407
+ flex: 1 1 auto;
3408
+ height: 1px;
3409
+ background: var(--dsw-alias-border-l1);
3410
+ }
3411
+ .dsh-tu-cards {
3412
+ display: grid;
3413
+ grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
3414
+ gap: 12px;
3415
+ margin: 18px 0;
3416
+ }
3417
+ .dsh-tu-card {
3418
+ --dsh-tu-tone: var(--dsh-tu-cat-0);
3419
+ border: 1px solid var(--dsw-alias-border-l1);
3420
+ border-top: 3px solid var(--dsh-tu-tone);
3421
+ background: var(--dsw-alias-bg-layer-1);
3422
+ background-image: linear-gradient(
3423
+ 135deg,
3424
+ color-mix(in oklab, var(--dsh-tu-tone) 10%, transparent),
3425
+ transparent 58%
3426
+ );
3427
+ border-radius: 10px;
3428
+ padding: 12px 14px;
3429
+ min-width: 0;
3430
+ }
3431
+ .dsh-tu-card[data-tone="blue"] { --dsh-tu-tone: var(--dsh-tu-cat-0); }
3432
+ .dsh-tu-card[data-tone="amber"] { --dsh-tu-tone: var(--dsh-tu-cat-1); }
3433
+ .dsh-tu-card[data-tone="green"] { --dsh-tu-tone: var(--dsh-tu-cat-2); }
3434
+ .dsh-tu-card[data-tone="violet"] { --dsh-tu-tone: var(--dsh-tu-cat-3); }
3435
+ .dsh-tu-card[data-tone="rose"] { --dsh-tu-tone: var(--dsh-tu-cat-4); }
3436
+ .dsh-tu-card-label { color: var(--dsw-alias-label-secondary); font-size: 12px; }
3437
+ .dsh-tu-card-value {
3438
+ color: var(--dsh-tu-tone);
3439
+ font-size: 21px;
3440
+ font-weight: 600;
3441
+ margin-top: 3px;
3442
+ font-variant-numeric: tabular-nums;
3443
+ word-break: break-all;
3444
+ }
3445
+ .dsh-tu-card-foot { color: var(--dsw-alias-label-secondary); font-size: 11px; margin-top: 2px; }
3446
+
3447
+ .dsh-tu-panel {
3448
+ border: 1px solid var(--dsw-alias-border-l1);
3449
+ background: var(--dsw-alias-bg-layer-1);
3450
+ border-radius: 10px;
3451
+ padding: 16px 18px;
3452
+ margin-bottom: 14px;
3453
+ }
3454
+ .dsh-tu-panel-head {
3455
+ display: flex;
3456
+ align-items: center;
3457
+ gap: 10px;
3458
+ flex-wrap: wrap;
3459
+ margin-bottom: 12px;
3460
+ }
3461
+ .dsh-tu-panel-title { font-size: 14px; font-weight: 600; margin: 0; }
3462
+
3463
+ /* No bottom margin: the fields are the whole content of this box now that the
3464
+ old "\u5F53\u524D\u7B5B\u9009\u2026" summary line is gone. */
3465
+ .dsh-tu-filters {
3466
+ display: flex;
3467
+ flex-wrap: wrap;
3468
+ gap: 14px;
3469
+ align-items: flex-end;
3470
+ margin-bottom: 0;
3471
+ }
3472
+ .dsh-tu-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
3473
+ .dsh-tu-field > label { color: var(--dsw-alias-label-secondary); font-size: 11px; }
3474
+ .dsh-tu-select, .dsh-tu-input {
3475
+ appearance: none;
3476
+ border: 1px solid var(--dsw-alias-border-l1);
3477
+ background: var(--dsw-alias-bg-layer-2);
3478
+ color: var(--dsw-alias-label-primary);
3479
+ border-radius: 7px;
3480
+ padding: 5px 9px;
3481
+ font-size: 12px;
3482
+ font-family: inherit;
3483
+ max-width: 260px;
3484
+ }
3485
+ .dsh-tu-input[type="date"] { max-width: 150px; }
3486
+
3487
+ /* The gap is a variable because a year of days is ~400 bars: at a fixed 2px the
3488
+ gaps alone would need 800px and the row would spill past the panel. The
3489
+ component sets it from the bucket count (2 / 1 / 0). */
3490
+ .dsh-tu-bars {
3491
+ display: flex;
3492
+ align-items: flex-end;
3493
+ gap: var(--dsh-tu-bar-gap, 2px);
3494
+ height: 150px;
3495
+ /* Belt and braces: bars are sized to fit, and anything that still overflows
3496
+ must be clipped inside the panel rather than drawn over its neighbours. */
3497
+ overflow: hidden;
3498
+ }
3499
+ .dsh-tu-bar-col {
3500
+ flex: 1 1 0;
3501
+ /* The old min-width: 3px here was the actual bug: 400 columns could not shrink
3502
+ below 1200px plus gaps, so the chart escaped the panel's right edge. */
3503
+ min-width: 0;
3504
+ height: 100%;
3505
+ display: flex;
3506
+ flex-direction: column;
3507
+ justify-content: flex-end;
3508
+ position: relative;
3509
+ cursor: default;
3510
+ }
3511
+ .dsh-tu-bar {
3512
+ border-radius: 3px 3px 0 0;
3513
+ background: var(--dsw-alias-brand-primary);
3514
+ min-height: 1px;
3515
+ transition: opacity .12s ease;
3516
+ }
3517
+ .dsh-tu-bar-col:hover .dsh-tu-bar { opacity: .78; }
3518
+ .dsh-tu-bar[data-estimated="true"] { opacity: .55; }
3519
+ .dsh-tu-bar[data-zero="true"] { min-height: 0; opacity: 0; }
3520
+ .dsh-tu-bars[data-metric="cost"] .dsh-tu-bar {
3521
+ background: linear-gradient(180deg, var(--dsh-tu-cat-1), var(--dsh-tu-cat-4));
3522
+ }
3523
+ .dsh-tu-axis {
3524
+ display: flex;
3525
+ justify-content: space-between;
3526
+ color: var(--dsw-alias-label-secondary);
3527
+ font-size: 11px;
3528
+ margin-top: 6px;
3529
+ font-variant-numeric: tabular-nums;
3530
+ }
3531
+ .dsh-tu-chart-hint { color: var(--dsw-alias-label-secondary); font-size: 11px; margin-top: 4px; }
3532
+
3533
+ /* New derived-statistics panels. Two columns on a normal window, one on narrow
3534
+ windows; each subpanel owns its own title so the reader can tell which chart
3535
+ is which without a second outer heading. */
3536
+ .dsh-tu-chart-grid {
3537
+ display: grid;
3538
+ grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
3539
+ gap: 18px;
3540
+ align-items: start;
3541
+ }
3542
+ @media (max-width: 900px) {
3543
+ .dsh-tu-chart-grid { grid-template-columns: minmax(0, 1fr); }
3544
+ }
3545
+ .dsh-tu-sector-grid {
3546
+ display: grid;
3547
+ grid-template-columns: repeat(3, minmax(0, 1fr));
3548
+ gap: 16px;
3549
+ align-items: stretch;
3550
+ }
3551
+ @media (max-width: 1000px) {
3552
+ .dsh-tu-sector-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
3553
+ }
3554
+ .dsh-tu-sector-grid .dsh-tu-subpanel {
3555
+ border: 1px solid var(--dsw-alias-border-l1);
3556
+ border-radius: 10px;
3557
+ padding: 12px 12px 10px;
3558
+ background: var(--dsw-alias-bg-layer-2);
3559
+ }
3560
+ .dsh-tu-subpanel { min-width: 0; }
3561
+ .dsh-tu-three-grid {
3562
+ display: grid;
3563
+ grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
3564
+ gap: 18px;
3565
+ margin-top: 16px;
3566
+ }
3567
+ .dsh-tu-subpanel-title {
3568
+ margin: 0 0 8px;
3569
+ font-size: 12px;
3570
+ font-weight: 500;
3571
+ color: var(--dsw-alias-label-secondary);
3572
+ }
3573
+ .dsh-tu-panel-note {
3574
+ margin: 0 0 10px;
3575
+ color: var(--dsw-alias-label-secondary);
3576
+ font-size: 11px;
3577
+ }
3578
+ .dsh-tu-stat-line {
3579
+ display: flex;
3580
+ flex-wrap: wrap;
3581
+ gap: 6px 18px;
3582
+ margin: 8px 0 0;
3583
+ color: var(--dsw-alias-label-secondary);
3584
+ font-size: 11px;
3585
+ }
3586
+ .dsh-tu-stat-line strong { color: var(--dsw-alias-label-primary); font-weight: 600; }
3587
+ .dsh-tu-stacked-bars {
3588
+ display: flex;
3589
+ align-items: flex-end;
3590
+ gap: var(--dsh-tu-bar-gap, 2px);
3591
+ height: 150px;
3592
+ overflow: hidden;
3593
+ }
3594
+ .dsh-tu-stack-col {
3595
+ flex: 1 1 0;
3596
+ min-width: 0;
3597
+ height: 100%;
3598
+ display: flex;
3599
+ flex-direction: column-reverse;
3600
+ justify-content: flex-start;
3601
+ cursor: default;
3602
+ }
3603
+ .dsh-tu-stack-seg { width: 100%; min-height: 0; }
3604
+ .dsh-tu-stack-seg[data-series="cacheRead"] { background: var(--dsh-tu-cat-2); }
3605
+ .dsh-tu-stack-seg[data-series="uncachedInput"] { background: var(--dsh-tu-cat-1); }
3606
+ .dsh-tu-stack-seg[data-series="cacheWrite"] { background: var(--dsh-tu-cat-3); }
3607
+ .dsh-tu-stack-seg[data-series="output"] { background: var(--dsh-tu-cat-0); }
3608
+ .dsh-tu-stack-legend {
3609
+ display: flex;
3610
+ flex-wrap: wrap;
3611
+ gap: 6px 14px;
3612
+ margin-top: 8px;
3613
+ color: var(--dsw-alias-label-secondary);
3614
+ font-size: 11px;
3615
+ }
3616
+ .dsh-tu-stack-legend-item { display: inline-flex; align-items: center; gap: 5px; }
3617
+ .dsh-tu-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
3618
+ .dsh-tu-swatch[data-series="cacheRead"] { background: var(--dsh-tu-cat-2); }
3619
+ .dsh-tu-swatch[data-series="uncachedInput"] { background: var(--dsh-tu-cat-1); }
3620
+ .dsh-tu-swatch[data-series="cacheWrite"] { background: var(--dsh-tu-cat-3); }
3621
+ .dsh-tu-swatch[data-series="output"] { background: var(--dsh-tu-cat-0); }
3622
+
3623
+ .dsh-tu-rate-plot { display: flex; align-items: flex-start; }
3624
+ .dsh-tu-rate-yaxis {
3625
+ display: flex;
3626
+ flex-direction: column;
3627
+ justify-content: space-between;
3628
+ width: 42px;
3629
+ height: 120px;
3630
+ padding-right: 6px;
3631
+ color: var(--dsw-alias-label-secondary);
3632
+ font-size: 10px;
3633
+ text-align: right;
3634
+ font-variant-numeric: tabular-nums;
3635
+ }
3636
+ .dsh-tu-rate-body { flex: 1 1 auto; min-width: 0; }
3637
+ .dsh-tu-rate-canvas { position: relative; height: 120px; }
3638
+ .dsh-tu-rate-svg {
3639
+ position: absolute;
3640
+ inset: 0;
3641
+ display: block;
3642
+ width: 100%;
3643
+ height: 100%;
3644
+ overflow: visible;
3645
+ }
3646
+ .dsh-tu-rate-grid { stroke: var(--dsw-alias-border-l1); stroke-width: 1; stroke-dasharray: 2 2; }
3647
+ .dsh-tu-rate-line { stroke: var(--dsh-tu-cat-0); stroke-width: 1.8; }
3648
+ .dsh-tu-rate-point {
3649
+ position: absolute;
3650
+ z-index: 1;
3651
+ width: 6px;
3652
+ height: 6px;
3653
+ border-radius: 50%;
3654
+ background: var(--dsh-tu-cat-0);
3655
+ box-shadow: 0 0 0 1px var(--dsw-alias-bg-layer-1);
3656
+ transform: translate(-50%, -50%);
3657
+ cursor: default;
3658
+ }
3659
+ .dsh-tu-rate-point-clipped {
3660
+ background: var(--dsh-tu-cat-4);
3661
+ box-shadow: 0 0 0 1px var(--dsw-alias-bg-layer-1), 0 0 0 2px color-mix(in oklab, var(--dsh-tu-cat-4) 45%, transparent);
3662
+ }
3663
+
3664
+ .dsh-tu-donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
3665
+ .dsh-tu-donut { width: 148px; flex: 0 0 148px; }
3666
+ .dsh-tu-donut svg { display: block; width: 100%; height: auto; }
3667
+ .dsh-tu-donut-track { stroke: var(--dsw-alias-border-l1); }
3668
+ .dsh-tu-donut-seg[data-series="0"] { stroke: var(--dsh-tu-cat-0); }
3669
+ .dsh-tu-donut-seg[data-series="1"] { stroke: var(--dsh-tu-cat-1); }
3670
+ .dsh-tu-donut-seg[data-series="2"] { stroke: var(--dsh-tu-cat-2); }
3671
+ .dsh-tu-donut-seg[data-series="3"] { stroke: var(--dsh-tu-cat-3); }
3672
+ .dsh-tu-donut-seg[data-series="4"] { stroke: var(--dsh-tu-cat-4); }
3673
+ .dsh-tu-donut-center-value {
3674
+ fill: var(--dsw-alias-label-primary);
3675
+ font-size: 13px;
3676
+ font-weight: 600;
3677
+ }
3678
+ .dsh-tu-donut-center-label {
3679
+ fill: var(--dsw-alias-label-secondary);
3680
+ font-size: 9px;
3681
+ }
3682
+ .dsh-tu-donut-legend { flex: 0 1 260px; max-width: 260px; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
3683
+ .dsh-tu-donut-legend-row {
3684
+ display: grid;
3685
+ grid-template-columns: 10px minmax(0, 1fr) auto auto;
3686
+ gap: 6px;
3687
+ align-items: center;
3688
+ font-size: 11px;
3689
+ }
3690
+ .dsh-tu-donut-legend-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
3691
+ .dsh-tu-donut-legend-value, .dsh-tu-donut-legend-percent {
3692
+ color: var(--dsw-alias-label-secondary);
3693
+ font-variant-numeric: tabular-nums;
3694
+ }
3695
+
3696
+ .dsh-tu-sector-chart {
3697
+ display: flex;
3698
+ flex-direction: column;
3699
+ align-items: center;
3700
+ gap: 8px;
3701
+ }
3702
+ .dsh-tu-sector-canvas {
3703
+ position: relative;
3704
+ width: min(100%, 170px);
3705
+ aspect-ratio: 1;
3706
+ }
3707
+ .dsh-tu-sector-canvas svg { display: block; width: 100%; height: 100%; overflow: visible; }
3708
+ .dsh-tu-sector-track { stroke: var(--dsw-alias-border-l1); }
3709
+ .dsh-tu-sector-slice {
3710
+ stroke: var(--dsw-alias-bg-layer-1);
3711
+ stroke-width: 1.5;
3712
+ stroke-linejoin: round;
3713
+ cursor: default;
3714
+ transition: opacity .12s ease, filter .12s ease;
3715
+ }
3716
+ .dsh-tu-sector-slice:hover, .dsh-tu-sector-slice[data-hovered="true"] { opacity: .78; }
3717
+ .dsh-tu-sector-chart[data-variant="pie"] .dsh-tu-sector-slice { stroke-width: 2; }
3718
+ .dsh-tu-sector-slice[data-series="0"] { fill: var(--dsh-tu-cat-0); }
3719
+ .dsh-tu-sector-slice[data-series="1"] { fill: var(--dsh-tu-cat-1); }
3720
+ .dsh-tu-sector-slice[data-series="2"] { fill: var(--dsh-tu-cat-2); }
3721
+ .dsh-tu-sector-slice[data-series="3"] { fill: var(--dsh-tu-cat-3); }
3722
+ .dsh-tu-sector-slice[data-series="4"] { fill: var(--dsh-tu-cat-4); }
3723
+ .dsh-tu-sector-legend {
3724
+ display: flex;
3725
+ flex-wrap: wrap;
3726
+ justify-content: center;
3727
+ gap: 3px 10px;
3728
+ color: var(--dsw-alias-label-secondary);
3729
+ font-size: 10px;
3730
+ line-height: 1.5;
3731
+ }
3732
+ .dsh-tu-sector-legend-item { display: inline-flex; align-items: center; gap: 4px; }
3733
+ .dsh-tu-sector-swatch { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
3734
+ .dsh-tu-sector-swatch[data-series="0"] { background: var(--dsh-tu-cat-0); }
3735
+ .dsh-tu-sector-swatch[data-series="1"] { background: var(--dsh-tu-cat-1); }
3736
+ .dsh-tu-sector-swatch[data-series="2"] { background: var(--dsh-tu-cat-2); }
3737
+ .dsh-tu-sector-swatch[data-series="3"] { background: var(--dsh-tu-cat-3); }
3738
+ .dsh-tu-sector-swatch[data-series="4"] { background: var(--dsh-tu-cat-4); }
3739
+
3740
+ .dsh-tu-hbars { display: flex; flex-direction: column; gap: 6px; }
3741
+ .dsh-tu-hbar-row {
3742
+ display: grid;
3743
+ grid-template-columns: 58px minmax(0, 1fr) 54px;
3744
+ gap: 8px;
3745
+ align-items: center;
3746
+ font-size: 11px;
3747
+ }
3748
+ .dsh-tu-hbar-label { color: var(--dsw-alias-label-secondary); white-space: nowrap; }
3749
+ .dsh-tu-hbar-track {
3750
+ display: block;
3751
+ height: 12px;
3752
+ background: var(--dsw-alias-bg-layer-2);
3753
+ border-radius: 4px;
3754
+ overflow: hidden;
3755
+ }
3756
+ .dsh-tu-hbar-fill {
3757
+ display: block;
3758
+ height: 100%;
3759
+ min-width: 1px;
3760
+ background: var(--dsh-tu-cat-0);
3761
+ border-radius: 4px;
3762
+ }
3763
+ .dsh-tu-hbar-value {
3764
+ text-align: right;
3765
+ color: var(--dsw-alias-label-secondary);
3766
+ font-variant-numeric: tabular-nums;
3767
+ }
3768
+
3769
+ .dsh-tu-hour-chart { margin-top: 4px; }
3770
+ .dsh-tu-hour-bars {
3771
+ display: flex;
3772
+ align-items: flex-end;
3773
+ gap: 3px;
3774
+ height: 112px;
3775
+ overflow: hidden;
3776
+ }
3777
+ .dsh-tu-hour-col {
3778
+ flex: 1 1 0;
3779
+ min-width: 0;
3780
+ height: 100%;
3781
+ display: flex;
3782
+ align-items: flex-end;
3783
+ cursor: default;
3784
+ }
3785
+ .dsh-tu-hour-bar {
3786
+ width: 100%;
3787
+ min-height: 2px;
3788
+ border-radius: 3px 3px 0 0;
3789
+ background: var(--dsh-tu-cat-0);
3790
+ transition: opacity .12s ease;
3791
+ }
3792
+ .dsh-tu-hour-col:hover .dsh-tu-hour-bar { opacity: .78; }
3793
+ .dsh-tu-hour-bar[data-level="0"] { background: transparent; min-height: 0; }
3794
+ .dsh-tu-hour-bar[data-level="1"] {
3795
+ background: color-mix(in oklab, var(--dsh-tu-cat-0) 32%, var(--dsw-alias-bg-layer-2));
3796
+ }
3797
+ .dsh-tu-hour-bar[data-level="2"] {
3798
+ background: color-mix(in oklab, var(--dsh-tu-cat-0) 62%, var(--dsw-alias-bg-layer-2));
3799
+ }
3800
+ .dsh-tu-hour-bar[data-level="3"] {
3801
+ background: linear-gradient(180deg, var(--dsh-tu-cat-3), var(--dsh-tu-cat-0));
3802
+ }
3803
+ .dsh-tu-hour-bar[data-level="4"] {
3804
+ background: linear-gradient(180deg, var(--dsh-tu-cat-4), var(--dsh-tu-cat-3));
3805
+ }
3806
+ .dsh-tu-hour-axis {
3807
+ display: flex;
3808
+ gap: 3px;
3809
+ margin-top: 4px;
3810
+ color: var(--dsw-alias-label-secondary);
3811
+ font-size: 9px;
3812
+ font-variant-numeric: tabular-nums;
3813
+ }
3814
+ .dsh-tu-hour-axis span {
3815
+ flex: 1 1 0;
3816
+ min-width: 0;
3817
+ text-align: center;
3818
+ white-space: nowrap;
3819
+ }
3820
+
3821
+ .dsh-tu-mini-table { width: 100%; border-collapse: collapse; font-size: 11px; }
3822
+ .dsh-tu-table-scroll { overflow-x: auto; }
3823
+ .dsh-tu-mini-table th {
3824
+ text-align: right;
3825
+ color: var(--dsw-alias-label-secondary);
3826
+ font-weight: 500;
3827
+ padding: 3px 6px;
3828
+ border-bottom: 1px solid var(--dsw-alias-border-l1);
3829
+ white-space: nowrap;
3830
+ }
3831
+ .dsh-tu-mini-table td {
3832
+ text-align: right;
3833
+ padding: 4px 6px;
3834
+ border-bottom: 1px solid var(--dsw-alias-border-l1);
3835
+ font-variant-numeric: tabular-nums;
3836
+ white-space: nowrap;
3837
+ }
3838
+ .dsh-tu-mini-table th:first-child, .dsh-tu-mini-table td:first-child { text-align: left; }
3839
+ .dsh-tu-mini-table tr:last-child td { border-bottom: 0; }
3840
+
3841
+ /* Coverage notes under the calendar: only rendered when the payload could not
3842
+ draw the whole page (cells hidden for real). Their own class, so "no notes in
3843
+ the normal case" is assertable. */
3844
+ .dsh-tu-heat-note { color: var(--dsw-alias-label-secondary); font-size: 11px; margin-top: 6px; }
3845
+ .dsh-tu-yaxis {
3846
+ display: flex;
3847
+ flex-direction: column;
3848
+ justify-content: space-between;
3849
+ color: var(--dsw-alias-label-secondary);
3850
+ font-size: 10px;
3851
+ width: 50px;
3852
+ text-align: right;
3853
+ padding-right: 6px;
3854
+ height: 150px;
3855
+ font-variant-numeric: tabular-nums;
3856
+ }
3857
+ .dsh-tu-plot { display: flex; align-items: flex-start; }
3858
+ .dsh-tu-plot-body { flex: 1 1 auto; min-width: 0; }
3859
+
3860
+ /* The calendar owns its own row; the companion figures sit BELOW it on theirs.
3861
+ Side-by-side made the grid look cramped once it grew to a full year. */
3862
+ .dsh-tu-heat-layout {
3863
+ display: flex;
3864
+ flex-direction: column;
3865
+ gap: 16px;
3866
+ }
3867
+ .dsh-tu-heat-stats {
3868
+ display: grid;
3869
+ grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
3870
+ gap: 10px 22px;
3871
+ border-top: 1px solid var(--dsw-alias-border-l1);
3872
+ padding-top: 14px;
3873
+ }
3874
+ .dsh-tu-heat-stat { min-width: 0; }
3875
+ .dsh-tu-heat-stat-label { color: var(--dsw-alias-label-secondary); font-size: 11px; }
3876
+ .dsh-tu-heat-stat-value {
3877
+ font-size: 15px;
3878
+ font-weight: 600;
3879
+ font-variant-numeric: tabular-nums;
3880
+ margin-top: 1px;
3881
+ }
3882
+ .dsh-tu-heat-stat-foot { color: var(--dsw-alias-label-secondary); font-size: 10px; }
3883
+ /* The scroll container is the GRID only: scrolling it must not carry the
3884
+ weekday labels (or the month header) out of view on a multi-year span.
3885
+ The calendar FILLS its row: the cell size is derived from the container width
3886
+ (one number, --dsh-tu-cell, consumed by BOTH the weekday label rows and the
3887
+ day rows, so the two blocks cannot drift apart). It is clamped between a floor
3888
+ that stays legible and a cap that keeps a 4K screen from turning a year into
3889
+ seven enormous rows; when the floor is hit the grid overflows and the scroll
3890
+ container takes over. Without container units the cells keep the 14px fallback
3891
+ while the columns still stretch: the row holds its width, but the cells no
3892
+ longer track it (graceful degradation, not a return to the old fixed block). */
3893
+ .dsh-tu-heat {
3894
+ display: flex;
3895
+ gap: var(--dsh-tu-row-gap);
3896
+ flex: none;
3897
+ max-width: 100%;
3898
+ container-type: inline-size;
3899
+ /* Overridden inline with the page's column count. */
3900
+ --dsh-tu-cols: 53;
3901
+ --dsh-tu-gap: 3px;
3902
+ --dsh-tu-row-gap: 8px;
3903
+ --dsh-tu-label-w: 34px;
3904
+ --dsh-tu-cell-min: 9px;
3905
+ --dsh-tu-cell-max: 22px;
3906
+ --dsh-tu-cell: 14px;
3907
+ }
3908
+ /* One column per week, one gap between columns, plus the label column and the
3909
+ 8px gap of this flex row. */
3910
+ @supports (width: 1cqw) {
3911
+ .dsh-tu-heat {
3912
+ --dsh-tu-cell: clamp(
3913
+ var(--dsh-tu-cell-min),
3914
+ calc(
3915
+ (100cqw - var(--dsh-tu-label-w) - var(--dsh-tu-row-gap) - (var(--dsh-tu-cols) - 1) * var(--dsh-tu-gap) - 1px) /
3916
+ var(--dsh-tu-cols)
3917
+ ),
3918
+ var(--dsh-tu-cell-max)
3919
+ );
3920
+ }
3921
+ }
3922
+ .dsh-tu-heat-scroll { overflow-x: auto; padding-bottom: 4px; min-width: 0; flex: 1 1 auto; }
3923
+ .dsh-tu-heat-weekdays {
3924
+ display: grid;
3925
+ grid-template-rows: repeat(7, var(--dsh-tu-cell, 14px));
3926
+ gap: var(--dsh-tu-gap);
3927
+ color: var(--dsw-alias-label-secondary);
3928
+ font-size: 10px;
3929
+ /* 15px month header + the column's gap. */
3930
+ padding-top: calc(15px + var(--dsh-tu-gap));
3931
+ width: var(--dsh-tu-label-w);
3932
+ flex: none;
3933
+ }
3934
+ .dsh-tu-heat-weekdays span {
3935
+ line-height: var(--dsh-tu-cell, 14px);
3936
+ height: var(--dsh-tu-cell, 14px);
3937
+ white-space: nowrap;
3938
+ }
3939
+ /* Fill the scroller exactly when the cells fit, and let max-content force the
3940
+ horizontal scroll ONLY once the 9px floor is reached. A bare max-content
3941
+ width makes the grid's subpixel cell widths round up past the scroll
3942
+ container's rounded-down client width, which produced a 1px scrollbar at
3943
+ intermediate viewport widths (the UI assertion catches it). */
3944
+ .dsh-tu-heat-grid { display: flex; gap: var(--dsh-tu-gap); width: calc(100% - 1px); min-width: max-content; }
3945
+ .dsh-tu-heat-col {
3946
+ display: flex;
3947
+ flex-direction: column;
3948
+ gap: var(--dsh-tu-gap);
3949
+ /* Grow into the free space the cell cap leaves over (the cells then centre in
3950
+ their column, so the extra shows up as wider gaps and the row still ends
3951
+ flush); never shrink below one cell, which is what makes the grid scroll. */
3952
+ flex: 1 1 0;
3953
+ min-width: var(--dsh-tu-cell, 14px);
3954
+ }
3955
+ .dsh-tu-heat-month {
3956
+ height: 15px;
3957
+ color: var(--dsw-alias-label-secondary);
3958
+ font-size: 10px;
3959
+ line-height: 15px;
3960
+ white-space: nowrap;
3961
+ position: relative;
3962
+ }
3963
+ /* Anchored to the CELL, not to the column box: when the cell cap leaves surplus
3964
+ width the cells centre inside their column, and a label pinned to the column's
3965
+ left edge would drift away from the week it names. On a normal 53-column page
3966
+ the inset is under a pixel, so nothing visible changes. */
3967
+ .dsh-tu-heat-month span {
3968
+ position: absolute;
3969
+ left: auto;
3970
+ right: 0;
3971
+ }
3972
+ /* The day cells live in their own 7-row grid so the month header above them can
3973
+ never be auto-placed into a day row (which silently misaligned the weekday
3974
+ labels against their rows). */
3975
+ .dsh-tu-heat-days {
3976
+ display: grid;
3977
+ grid-template-rows: repeat(7, var(--dsh-tu-cell, 14px));
3978
+ gap: var(--dsh-tu-gap);
3979
+ justify-items: center;
3980
+ }
3981
+ .dsh-tu-cell {
3982
+ /* The fallback keeps the legend chips (outside the heat container) at their
3983
+ own size instead of collapsing to auto. */
3984
+ width: var(--dsh-tu-cell, 14px);
3985
+ height: var(--dsh-tu-cell, 14px);
3986
+ border-radius: 3px;
3987
+ background: var(--dsw-alias-bg-layer-2);
3988
+ border: 1px solid transparent;
3989
+ box-sizing: border-box;
3990
+ }
3991
+ .dsh-tu-cell[data-outside="true"] { visibility: hidden; }
3992
+ /* Green intensity ladder built ONLY from the theme's success family, so light
3993
+ and dark are handled by the design system rather than by a hardcoded
3994
+ 'prefers-color-scheme' block: '--dsw-alias-state-success-tertiary' is the
3995
+ palest green in light mode and a deep green in dark mode, and
3996
+ '--dsw-alias-state-success-primary' is the saturated end in both. Levels 2
3997
+ and 3 interpolate between them with enough separation to read as a ramp. */
3998
+ .dsh-tu-cell[data-level="0"] {
3999
+ /* Faint on purpose: "no usage" must be the QUIETEST cell on the board, so the
4000
+ lightest green still reads as more than it. */
4001
+ background: color-mix(in srgb, var(--dsw-alias-label-secondary) 9%, transparent);
4002
+ }
4003
+ .dsh-tu-cell[data-level="1"] {
4004
+ /* Mixed rather than pure tertiary: in the light theme plain green-100 is paler
4005
+ than the neutral empty chip, which made 1-25% days look EMPTIER than days
4006
+ with no usage at all. */
4007
+ background: color-mix(
4008
+ in oklab,
4009
+ var(--dsw-alias-state-success-primary) 30%,
4010
+ var(--dsw-alias-state-success-tertiary)
4011
+ );
4012
+ }
4013
+ .dsh-tu-cell[data-level="2"] {
4014
+ background: color-mix(
4015
+ in oklab,
4016
+ var(--dsw-alias-state-success-primary) 52%,
4017
+ var(--dsw-alias-state-success-tertiary)
4018
+ );
4019
+ }
4020
+ .dsh-tu-cell[data-level="3"] {
4021
+ background: color-mix(
4022
+ in oklab,
4023
+ var(--dsw-alias-state-success-primary) 76%,
4024
+ var(--dsw-alias-state-success-tertiary)
4025
+ );
4026
+ }
4027
+ .dsh-tu-cell[data-level="4"] { background: var(--dsw-alias-state-success-primary); }
4028
+ .dsh-tu-cell[data-today="true"] { border-color: var(--dsw-alias-label-primary); }
4029
+ .dsh-tu-legend {
4030
+ display: flex;
4031
+ align-items: center;
4032
+ gap: 5px;
4033
+ color: var(--dsw-alias-label-secondary);
4034
+ font-size: 11px;
4035
+ margin-top: 10px;
4036
+ flex-wrap: wrap;
4037
+ }
4038
+ .dsh-tu-legend .dsh-tu-cell { width: 11px; height: 11px; }
4039
+
4040
+ .dsh-tu-table { width: 100%; border-collapse: collapse; font-size: 12px; }
4041
+ .dsh-tu-table th {
4042
+ text-align: right;
4043
+ color: var(--dsw-alias-label-secondary);
4044
+ font-weight: 500;
4045
+ padding: 5px 8px;
4046
+ border-bottom: 1px solid var(--dsw-alias-border-l1);
4047
+ white-space: nowrap;
4048
+ }
4049
+ .dsh-tu-table th:first-child, .dsh-tu-table td:first-child { text-align: left; }
4050
+ .dsh-tu-table td {
4051
+ text-align: right;
4052
+ padding: 5px 8px;
4053
+ border-bottom: 1px solid var(--dsw-alias-border-l1);
4054
+ font-variant-numeric: tabular-nums;
4055
+ white-space: nowrap;
4056
+ }
4057
+ .dsh-tu-table tr:last-child td { border-bottom: none; }
4058
+ .dsh-tu-table td:first-child {
4059
+ font-variant-numeric: normal;
4060
+ max-width: 340px;
4061
+ overflow: hidden;
4062
+ text-overflow: ellipsis;
4063
+ }
4064
+ .dsh-tu-tag {
4065
+ display: inline-block;
4066
+ border: 1px solid var(--dsw-alias-border-l1);
4067
+ border-radius: 5px;
4068
+ padding: 0 5px;
4069
+ font-size: 10px;
4070
+ color: var(--dsw-alias-label-secondary);
4071
+ margin-left: 6px;
4072
+ }
4073
+ /* The merged-workspace path count is a real control (expands the row), so it
4074
+ keeps the tag look but gets button affordances instead of being decoration. */
4075
+ .dsh-tu-tag-btn {
4076
+ display: inline-flex;
4077
+ align-items: center;
4078
+ gap: 3px;
4079
+ background: transparent;
4080
+ font: inherit;
4081
+ font-size: 10px;
4082
+ line-height: 1.6;
4083
+ cursor: pointer;
4084
+ }
4085
+ .dsh-tu-tag-btn:hover { color: var(--dsw-alias-label-primary); border-color: var(--dsw-alias-border-l2); }
4086
+ .dsh-tu-tag-btn:focus-visible { outline: 2px solid var(--dsw-alias-label-primary); outline-offset: 1px; }
4087
+ .dsh-tu-notice {
4088
+ display: flex;
4089
+ align-items: flex-start;
4090
+ gap: 8px;
4091
+ border-radius: 8px;
4092
+ padding: 10px 13px;
4093
+ margin: 12px 0;
4094
+ font-size: 12px;
4095
+ line-height: 1.6;
4096
+ border: 1px solid var(--dsw-alias-border-l1);
4097
+ }
4098
+ .dsh-tu-notice-text { flex: 1 1 auto; min-width: 0; }
4099
+ .dsh-tu-notice-close {
4100
+ appearance: none;
4101
+ flex: 0 0 auto;
4102
+ display: inline-flex;
4103
+ align-items: center;
4104
+ justify-content: center;
4105
+ width: 22px;
4106
+ height: 22px;
4107
+ margin: -2px -4px -2px 0;
4108
+ padding: 0;
4109
+ border: 0;
4110
+ border-radius: 6px;
4111
+ background: transparent;
4112
+ color: inherit;
4113
+ cursor: pointer;
4114
+ opacity: .8;
4115
+ }
4116
+ .dsh-tu-notice-close:hover { background: var(--dsw-alias-interactive-bg-hover); opacity: 1; }
4117
+ .dsh-tu-notice-close:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }
4118
+ .dsh-tu-notice[data-kind="error"] {
4119
+ border-color: var(--dsw-alias-state-error-primary);
4120
+ color: var(--dsw-alias-state-error-primary);
4121
+ }
4122
+ .dsh-tu-notice[data-kind="warn"] {
4123
+ border-color: var(--dsw-alias-state-warn-primary);
4124
+ color: var(--dsw-alias-state-warn-primary);
4125
+ }
4126
+ .dsh-tu-notice[data-kind="success"] {
4127
+ border-color: var(--dsw-alias-state-success-primary);
4128
+ color: var(--dsw-alias-state-success-primary);
4129
+ }
4130
+ .dsh-tu-notice[data-kind="info"] {
4131
+ border-color: var(--dsw-alias-border-l2);
4132
+ color: var(--dsw-alias-label-secondary);
4133
+ }
4134
+ .dsh-tu-tool-panel {
4135
+ margin: 12px 0;
4136
+ padding: 12px 14px;
4137
+ border: 1px solid var(--dsw-alias-border-l1);
4138
+ border-radius: 10px;
4139
+ background: var(--dsw-alias-bg-layer-1);
4140
+ }
4141
+ .dsh-tu-tool-title {
4142
+ margin: 0 0 6px;
4143
+ font-size: 14px;
4144
+ font-weight: 600;
4145
+ }
4146
+ .dsh-tu-tool-panel p {
4147
+ margin: 4px 0;
4148
+ font-size: 12px;
4149
+ line-height: 1.6;
4150
+ color: var(--dsw-alias-label-secondary);
4151
+ }
4152
+ .dsh-tu-tool-actions {
4153
+ display: flex;
4154
+ justify-content: flex-end;
4155
+ gap: 8px;
4156
+ margin-top: 10px;
4157
+ }
4158
+ .dsh-tu-empty {
4159
+ text-align: center;
4160
+ color: var(--dsw-alias-label-secondary);
4161
+ padding: 40px 10px;
4162
+ }
4163
+ .dsh-tu-tooltip {
4164
+ position: fixed;
4165
+ z-index: 40;
4166
+ pointer-events: none;
4167
+ background: var(--dsw-alias-bg-overlay);
4168
+ color: var(--dsw-alias-label-primary);
4169
+ border: 1px solid var(--dsw-alias-border-l2);
4170
+ border-radius: 7px;
4171
+ padding: 7px 10px;
4172
+ font-size: 11px;
4173
+ box-shadow: 0 6px 20px rgb(0 0 0 / 22%);
4174
+ max-width: 280px;
4175
+ line-height: 1.6;
4176
+ }
4177
+ .dsh-tu-tooltip b { font-variant-numeric: tabular-nums; }
4178
+ .dsh-tu-tooltip-detail {
4179
+ display: flex;
4180
+ justify-content: space-between;
4181
+ gap: 16px;
4182
+ margin-top: 2px;
4183
+ font-size: 11px;
4184
+ }
4185
+ .dsh-tu-tooltip-head { margin-top: 3px; }
4186
+ .dsh-tu-tooltip-row {
4187
+ display: grid;
4188
+ grid-template-columns: 10px minmax(58px, 1fr) auto;
4189
+ align-items: center;
4190
+ gap: 5px;
4191
+ margin-top: 2px;
4192
+ }
4193
+ .dsh-tu-tooltip-label { color: var(--dsw-alias-label-secondary); }
4194
+ .dsh-tu-tooltip-subtle { color: var(--dsw-alias-label-secondary); margin-top: 4px; }
4195
+
4196
+ /* ---- header controls: close, pricing info, plugin version ---------------- */
4197
+ .dsh-tu-version {
4198
+ font-family: var(--ds-font-family-code, monospace);
4199
+ font-size: 11px;
4200
+ color: var(--dsw-alias-label-secondary);
4201
+ border: 1px solid var(--dsw-alias-border-l1);
4202
+ border-radius: 5px;
4203
+ padding: 0 5px;
4204
+ white-space: nowrap;
4205
+ }
4206
+ .dsh-tu-icon-btn {
4207
+ width: 28px;
4208
+ height: 28px;
4209
+ flex: none;
4210
+ display: inline-flex;
4211
+ align-items: center;
4212
+ justify-content: center;
4213
+ padding: 0;
4214
+ border: none;
4215
+ border-radius: 50%;
4216
+ background: transparent;
4217
+ color: var(--dsw-alias-label-secondary);
4218
+ font: inherit;
4219
+ cursor: pointer;
4220
+ }
4221
+ .dsh-tu-icon-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
4222
+ .dsh-tu-icon-btn:focus-visible { outline: 2px solid var(--dsw-alias-label-primary); outline-offset: -2px; }
4223
+ .dsh-tu-icon-btn:disabled { opacity: .55; cursor: default; }
4224
+ @keyframes dsh-tu-spin { to { transform: rotate(360deg); } }
4225
+ .dsh-tu-icon-btn[data-busy="true"] svg { animation: dsh-tu-spin .9s linear infinite; }
4226
+ @media (prefers-reduced-motion: reduce) {
4227
+ .dsh-tu-icon-btn[data-busy="true"] svg { animation: none; }
4228
+ }
4229
+
4230
+ /* Anchored popover (the explanation panel). Large text surfaces use the opaque
4231
+ raised-surface token below, not the harness's translucent menu material. */
4232
+ .dsh-tu-anchor { position: relative; display: inline-flex; }
4233
+ .dsh-tu-panel-info { align-items: center; }
4234
+ .dsh-tu-panel-popover {
4235
+ width: min(360px, calc(100vw - 40px));
4236
+ max-width: min(360px, calc(100vw - 40px));
4237
+ }
4238
+ .dsh-tu-panel-popover p { margin: 0 0 6px; }
4239
+ .dsh-tu-panel-popover p:last-child { margin-bottom: 0; }
4240
+ /* Price table inside the explanation popover: a real table, so the digits line
4241
+ up column-wise and can be compared at a glance. */
4242
+ .dsh-tu-price { margin: 8px 0 4px; }
4243
+ .dsh-tu-price-head { font-size: 11px; color: var(--dsw-alias-label-secondary); margin-bottom: 4px; }
4244
+ .dsh-tu-price table { border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; }
4245
+ .dsh-tu-price th {
4246
+ color: var(--dsw-alias-label-secondary);
4247
+ font-weight: 500;
4248
+ text-align: right;
4249
+ padding: 1px 0 3px 12px;
4250
+ white-space: nowrap;
4251
+ }
4252
+ .dsh-tu-price th:first-child { text-align: left; padding-left: 0; }
4253
+ .dsh-tu-price td { text-align: right; padding: 1px 0 1px 12px; white-space: nowrap; }
4254
+ /* The \u65F6\u6BB5 cell is the 1st cell on an off-peak row (the model cell above it has
4255
+ rowSpan) but the 2nd on a peak row. Aligning by class instead of nth-child
4256
+ keeps both rows' \u65F6\u6BB5/\u6570\u503C columns on the same x positions. */
4257
+ .dsh-tu-price .dsh-tu-price-window { text-align: left; padding-left: 8px; }
4258
+ .dsh-tu-price td:first-child { text-align: left; padding-left: 0; }
4259
+ .dsh-tu-price td.dsh-tu-price-window:first-child { padding-left: 8px; }
4260
+ .dsh-tu-price tbody tr + tr td { border-top: 1px solid var(--dsw-alias-border-l1); }
4261
+
4262
+ .dsh-tu-popover {
4263
+ position: absolute;
4264
+ top: calc(100% + 8px);
4265
+ right: 0;
4266
+ z-index: 30;
4267
+ width: 440px;
4268
+ max-width: min(440px, calc(100vw - 40px));
4269
+ /* Opaque surface: the menu material token (--dsw-specific-menu) is 58%/45%
4270
+ alpha on Windows and needs a backdrop blur this plugin does not paint, so
4271
+ using it here let page text show through the popover. A large explanation
4272
+ panel belongs on the raised-surface token, matching the dashboard cards. */
4273
+ background: var(--dsw-alias-bg-layer-1, var(--dsw-alias-bg-base));
4274
+ border: 1px solid var(--dsw-alias-border-l1);
4275
+ border-radius: 12px;
4276
+ box-shadow: var(--dsw-elevation-prominent, 0 8px 24px rgb(0 0 0 / 18%));
4277
+ padding: 12px 14px;
4278
+ font-size: 12px;
4279
+ line-height: 1.75;
4280
+ color: var(--dsw-alias-label-primary);
4281
+ text-align: left;
4282
+ /* The table got taller with the peak/off-peak split; keep the whole popover
4283
+ reachable inside the panel's scroll container instead of clipping it. */
4284
+ max-height: min(70vh, 560px);
4285
+ overflow-y: auto;
4286
+ overscroll-behavior: contain;
4287
+ }
4288
+ .dsh-tu-popover h4 { margin: 0 0 6px; font-size: 13px; font-weight: 600; }
4289
+ .dsh-tu-popover code {
4290
+ font-family: var(--ds-font-family-code, monospace);
4291
+ font-size: 11px;
4292
+ background: var(--dsw-alias-markdown-inline-code, var(--dsw-alias-bg-layer-2));
4293
+ border-radius: 4px;
4294
+ padding: 1px 4px;
4295
+ word-break: break-all;
4296
+ }
4297
+ .dsh-tu-popover dl { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
4298
+ .dsh-tu-popover dt { color: var(--dsw-alias-label-secondary); white-space: nowrap; }
4299
+ .dsh-tu-popover dd { margin: 0; word-break: break-word; }
4300
+ .dsh-tu-popover .dsh-tu-subtle { margin-top: 8px; }
4301
+
4302
+ /* ---- calendar toolbar (paging) ------------------------------------------- */
4303
+ .dsh-tu-heat-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
4304
+ .dsh-tu-heat-range {
4305
+ font-variant-numeric: tabular-nums;
4306
+ color: var(--dsw-alias-label-secondary);
4307
+ font-size: 12px;
4308
+ }
4309
+
4310
+ /* ---- workspace breakdown: merged rows + per-path detail ------------------ */
4311
+ .dsh-tu-ws-note { margin: 0 0 10px; }
4312
+ .dsh-tu-path-row > td {
4313
+ padding: 2px 0 8px;
4314
+ text-align: left;
4315
+ white-space: normal;
4316
+ font-variant-numeric: normal;
4317
+ }
4318
+ .dsh-tu-ws-paths {
4319
+ display: flex;
4320
+ flex-direction: column;
4321
+ gap: 4px;
4322
+ padding: 6px 10px;
4323
+ border-left: 2px solid var(--dsw-alias-border-l1);
4324
+ margin-left: 2px;
4325
+ }
4326
+ .dsh-tu-ws-path {
4327
+ display: flex;
4328
+ align-items: center;
4329
+ gap: 8px;
4330
+ flex-wrap: wrap;
4331
+ font-size: 11px;
4332
+ color: var(--dsw-alias-label-secondary);
4333
+ }
4334
+ .dsh-tu-ws-platform {
4335
+ flex: none;
4336
+ border: 1px solid var(--dsw-alias-border-l1);
4337
+ border-radius: 4px;
4338
+ padding: 0 4px;
4339
+ font-size: 10px;
4340
+ }
4341
+ .dsh-tu-ws-raw {
4342
+ font-family: var(--ds-font-family-code, monospace);
4343
+ color: var(--dsw-alias-label-primary);
4344
+ word-break: break-all;
4345
+ }
4346
+ .dsh-tu-ws-nums { font-variant-numeric: tabular-nums; }
4347
+ .dsh-tu-ws-filter { padding: 1px 8px; font-size: 11px; }
4348
+
4349
+ /* ---- contained render failure (see client/boundary.tsx) ------------------ */
4350
+ .dsh-tu-boundary { margin-top: 18px; }
4351
+ .dsh-tu-boundary .dsh-tu-empty { padding: 24px 10px; }
4352
+ `;
4353
+ function injectStyles() {
4354
+ if (typeof document === "undefined") return;
4355
+ if (document.getElementById(STYLE_ID) !== null) return;
4356
+ const element = document.createElement("style");
4357
+ element.id = STYLE_ID;
4358
+ element.textContent = CSS;
4359
+ document.head.appendChild(element);
4360
+ }
4361
+
4362
+ // src/client/index.tsx
4363
+ var name = "token-usage";
4364
+ var inject = ["slots"];
4365
+ function warnRegistrationFailure(what, error) {
4366
+ const detail = error instanceof Error ? error.message : String(error);
4367
+ console.warn(`[token-usage] could not register ${what}; only this plugin's UI is affected (${detail})`);
4368
+ }
4369
+ function DashboardFallback(props) {
4370
+ return (0, import_react8.createElement)(
4371
+ "div",
4372
+ { className: "dsh-tu-root" },
4373
+ (0, import_react8.createElement)(
4374
+ "div",
4375
+ { className: "dsh-tu-shell" },
4376
+ (0, import_react8.createElement)(
4377
+ "div",
4378
+ { className: "dsh-tu-panel dsh-tu-boundary" },
4379
+ (0, import_react8.createElement)("h2", { className: "dsh-tu-panel-title" }, PANEL_LABEL),
4380
+ (0, import_react8.createElement)(
4381
+ "div",
4382
+ { className: "dsh-tu-empty" },
4383
+ "\u7EDF\u8BA1\u9762\u677F\u6E32\u67D3\u5931\u8D25\u3002\u8BE5\u95EE\u9898\u53EA\u5F71\u54CD\u672C\u63D2\u4EF6\uFF0C\u4E0D\u5F71\u54CD dsh \u5176\u5B83\u529F\u80FD\uFF1B\u53EF\u8FD4\u56DE\u5BF9\u8BDD\u540E\u91CD\u8BD5\uFF0C\u6216\u91CD\u542F\u5E94\u7528\u3002"
4384
+ ),
4385
+ (0, import_react8.createElement)(
4386
+ "button",
4387
+ {
4388
+ type: "button",
4389
+ className: "dsh-tu-btn",
4390
+ onClick: () => {
4391
+ props.onSelect?.(null);
4392
+ }
4393
+ },
4394
+ "\u8FD4\u56DE\u5BF9\u8BDD"
4395
+ )
4396
+ )
4397
+ )
4398
+ );
4399
+ }
4400
+ function DashboardEntry(props) {
4401
+ return (0, import_react8.createElement)(
4402
+ ErrorBoundary,
4403
+ { fallback: (0, import_react8.createElement)(DashboardFallback, props) },
4404
+ (0, import_react8.createElement)(TokenUsageDashboard, props)
4405
+ );
4406
+ }
4407
+ function PanelIconEntry(props) {
4408
+ return (0, import_react8.createElement)(
4409
+ ErrorBoundary,
4410
+ { fallback: null },
4411
+ (0, import_react8.createElement)(TokenUsagePanelIcon, props)
4412
+ );
4413
+ }
4414
+ function apply(ctx) {
4415
+ ctx.effect(() => {
4416
+ injectStyles();
4417
+ return () => {
4418
+ };
4419
+ }, `${name}: styles`);
4420
+ const selectPanel = (panelId) => {
4421
+ try {
4422
+ const layout = ctx.get("layout");
4423
+ if (layout === void 0) return;
4424
+ layout.selectPanel(panelId);
4425
+ } catch (error) {
4426
+ warnRegistrationFailure("the layout bridge", error);
4427
+ }
4428
+ };
4429
+ try {
4430
+ ctx.slots.inject(
4431
+ "sidebar.panellist",
4432
+ () => ctx.slots.register(
4433
+ {
4434
+ name: "sidebar.panellist",
4435
+ id: PANEL_ID,
4436
+ // After the shipped entries: plugins = 0, schedules = 10. The list is
4437
+ // rendered before the workspace browser, which is exactly the
4438
+ // "below automation tasks, above workspaces" position requested.
4439
+ order: 20,
4440
+ // The sidebar resolves the accessible name and the wide-row text from
4441
+ // this metadata (`resolveSlotLabel(options.label) ?? id`).
4442
+ label: PANEL_LABEL
4443
+ },
4444
+ PanelIconEntry
4445
+ )
4446
+ );
4447
+ } catch (error) {
4448
+ warnRegistrationFailure("the sidebar entry", error);
4449
+ }
4450
+ try {
4451
+ ctx.slots.inject(
4452
+ "main",
4453
+ () => ctx.slots.register(
4454
+ {
4455
+ name: "main",
4456
+ key: PANEL_ID,
4457
+ inject: () => ({ onSelect: selectPanel })
4458
+ },
4459
+ DashboardEntry
4460
+ )
4461
+ );
4462
+ } catch (error) {
4463
+ warnRegistrationFailure("the dashboard panel", error);
4464
+ }
4465
+ }
4466
+
4467
+ return module.exports
4468
+ },
4469
+ })