@laoyuehanni/dsh-token-usage 0.4.2 → 0.4.4-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/README.zh.md +8 -7
- package/lib/client/SessionTable.d.ts.map +1 -1
- package/lib/client/SessionTable.js +10 -4
- package/lib/client/SessionTable.js.map +1 -1
- package/lib/client/TokenUsageCard.d.ts +7 -2
- package/lib/client/TokenUsageCard.d.ts.map +1 -1
- package/lib/client/TokenUsageCard.js +15 -5
- package/lib/client/TokenUsageCard.js.map +1 -1
- package/lib/client/TokenUsageSection.d.ts +9 -5
- package/lib/client/TokenUsageSection.d.ts.map +1 -1
- package/lib/client/TokenUsageSection.js +44 -16
- package/lib/client/TokenUsageSection.js.map +1 -1
- package/lib/client/TrendChart.d.ts +1 -1
- package/lib/client/TrendChart.d.ts.map +1 -1
- package/lib/client/TrendChart.js +39 -15
- package/lib/client/TrendChart.js.map +1 -1
- package/lib/client/UsageView.js +2 -2
- package/lib/client/UsageView.js.map +1 -1
- package/lib/client/card-form.d.ts +33 -4
- package/lib/client/card-form.d.ts.map +1 -1
- package/lib/client/card-form.js +20 -8
- package/lib/client/card-form.js.map +1 -1
- package/lib/client/format.d.ts.map +1 -1
- package/lib/client/format.js +12 -4
- package/lib/client/format.js.map +1 -1
- package/lib/client/index.d.ts +18 -3
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +137 -25
- package/lib/client/index.js.map +1 -1
- package/lib/client/locales.d.ts +11 -2
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/locales.js +22 -4
- package/lib/client/locales.js.map +1 -1
- package/lib/client/trend-chart/index.d.ts +1 -1
- package/lib/client/trend-chart/index.d.ts.map +1 -1
- package/lib/client/trend-chart/index.js +1 -1
- package/lib/client/trend-chart/index.js.map +1 -1
- package/lib/client/trend-chart/path.d.ts +46 -0
- package/lib/client/trend-chart/path.d.ts.map +1 -1
- package/lib/client/trend-chart/path.js +140 -0
- package/lib/client/trend-chart/path.js.map +1 -1
- package/lib/client/use-color-scheme.d.ts +6 -0
- package/lib/client/use-color-scheme.d.ts.map +1 -1
- package/lib/client/use-color-scheme.js +53 -1
- package/lib/client/use-color-scheme.js.map +1 -1
- package/lib/client.js +553 -115
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +30 -52
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +152 -143
- package/lib/index.js.map +1 -1
- package/lib/pricing.d.ts +36 -0
- package/lib/pricing.d.ts.map +1 -1
- package/lib/pricing.js +45 -4
- package/lib/pricing.js.map +1 -1
- package/lib/stats-route.d.ts.map +1 -1
- package/lib/stats-route.js +9 -7
- package/lib/stats-route.js.map +1 -1
- package/lib/stats.d.ts +23 -9
- package/lib/stats.d.ts.map +1 -1
- package/lib/stats.js +56 -22
- package/lib/stats.js.map +1 -1
- package/lib/sync-state.d.ts +17 -6
- package/lib/sync-state.d.ts.map +1 -1
- package/lib/sync-state.js +28 -6
- package/lib/sync-state.js.map +1 -1
- package/lib/sync.d.ts +102 -16
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +121 -13
- package/lib/sync.js.map +1 -1
- package/lib/usage-log.d.ts +49 -0
- package/lib/usage-log.d.ts.map +1 -1
- package/lib/usage-log.js +239 -1
- package/lib/usage-log.js.map +1 -1
- package/lib/usage-record.d.ts +20 -2
- package/lib/usage-record.d.ts.map +1 -1
- package/lib/usage-record.js +74 -3
- package/lib/usage-record.js.map +1 -1
- package/lib/wire.d.ts +3 -1
- package/lib/wire.d.ts.map +1 -1
- package/lib/wire.js +1 -1
- package/package.json +42 -36
package/lib/client.js
CHANGED
|
@@ -53,13 +53,25 @@ window.__ModuleLoader__.load({
|
|
|
53
53
|
/**
|
|
54
54
|
* The full-sync endpoint path: the card's manual "scan again" affordance.
|
|
55
55
|
* `POST` starts one full scan over every session log (the same scan the
|
|
56
|
-
* one-shot startup sync ran on first install — list +
|
|
56
|
+
* one-shot startup sync ran on first install — list + read + dedupe), and
|
|
57
57
|
* `GET` returns the live progress. The scan is fire-and-forget on the host
|
|
58
58
|
* side, so the card polls while it runs.
|
|
59
59
|
*/
|
|
60
60
|
const FULL_SYNC_PATH = "/token-usage/full-sync";
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/client/card-form.ts
|
|
63
|
+
/** Fallback target when neither configForms nor settingsScope is present in the host. */
|
|
64
|
+
function createFallbackTarget() {
|
|
65
|
+
return {
|
|
66
|
+
getSnapshot: () => ({
|
|
67
|
+
status: "unavailable",
|
|
68
|
+
writable: false
|
|
69
|
+
}),
|
|
70
|
+
subscribe: () => () => {},
|
|
71
|
+
set: async () => false,
|
|
72
|
+
unset: async () => false
|
|
73
|
+
};
|
|
74
|
+
}
|
|
63
75
|
/** The fields this card edits. */
|
|
64
76
|
const CARD_FIELDS = ["path", "pricingRegion"];
|
|
65
77
|
/**
|
|
@@ -72,7 +84,7 @@ window.__ModuleLoader__.load({
|
|
|
72
84
|
* never restates fields it did not see.
|
|
73
85
|
*/
|
|
74
86
|
var CardForm = class {
|
|
75
|
-
|
|
87
|
+
target;
|
|
76
88
|
snapshotValue;
|
|
77
89
|
listeners = /* @__PURE__ */ new Set();
|
|
78
90
|
drafts = {};
|
|
@@ -82,12 +94,12 @@ window.__ModuleLoader__.load({
|
|
|
82
94
|
migrationView;
|
|
83
95
|
pollTimer;
|
|
84
96
|
/**
|
|
85
|
-
* @param
|
|
97
|
+
* @param target - the configuration source backing the card (ConfigForm or SettingsScope).
|
|
86
98
|
*/
|
|
87
|
-
constructor(
|
|
88
|
-
this.
|
|
99
|
+
constructor(target) {
|
|
100
|
+
this.target = target;
|
|
89
101
|
this.snapshotValue = this.project();
|
|
90
|
-
|
|
102
|
+
target.subscribe(() => {
|
|
91
103
|
this.publish();
|
|
92
104
|
});
|
|
93
105
|
this.pollMigration();
|
|
@@ -172,8 +184,8 @@ window.__ModuleLoader__.load({
|
|
|
172
184
|
}
|
|
173
185
|
let landed = true;
|
|
174
186
|
try {
|
|
175
|
-
for (const [field, text] of intended) if (text === "") await this.
|
|
176
|
-
else await this.
|
|
187
|
+
for (const [field, text] of intended) if (text === "") await this.target.unset(field);
|
|
188
|
+
else await this.target.set(field, text);
|
|
177
189
|
for (const [field, text] of intended) if (text === "" ? this.stored(field) : this.storedValue(field) !== text) {
|
|
178
190
|
landed = false;
|
|
179
191
|
break;
|
|
@@ -245,7 +257,7 @@ window.__ModuleLoader__.load({
|
|
|
245
257
|
}
|
|
246
258
|
}
|
|
247
259
|
snapshot() {
|
|
248
|
-
return this.
|
|
260
|
+
return this.target.getSnapshot();
|
|
249
261
|
}
|
|
250
262
|
/** The raw user layer narrowed to a record; the wire answer is `unknown`. */
|
|
251
263
|
userLayer() {
|
|
@@ -542,9 +554,46 @@ window.__ModuleLoader__.load({
|
|
|
542
554
|
return () => observer.disconnect();
|
|
543
555
|
}, [rootRef]);
|
|
544
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* Hook reporting whether the current shell/page environment is in light mode.
|
|
559
|
+
* Evaluates `document.documentElement.style.colorScheme` first (the DSH shell
|
|
560
|
+
* rewrites this on every theme switch), falling back to `(prefers-color-scheme: light)`.
|
|
561
|
+
*/
|
|
562
|
+
function useIsLightMode() {
|
|
563
|
+
const [isLight, setIsLight] = (0, react.useState)(() => {
|
|
564
|
+
if (typeof document === "undefined") return false;
|
|
565
|
+
const rootScheme = document.documentElement.style.colorScheme;
|
|
566
|
+
if (rootScheme === "light") return true;
|
|
567
|
+
if (rootScheme === "dark") return false;
|
|
568
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia("(prefers-color-scheme: light)").matches : false;
|
|
569
|
+
});
|
|
570
|
+
(0, react.useEffect)(() => {
|
|
571
|
+
if (typeof document === "undefined") return;
|
|
572
|
+
const root = document.documentElement;
|
|
573
|
+
const media = typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia("(prefers-color-scheme: light)") : null;
|
|
574
|
+
const check = () => {
|
|
575
|
+
const scheme = root.style.colorScheme;
|
|
576
|
+
if (scheme === "light") setIsLight(true);
|
|
577
|
+
else if (scheme === "dark") setIsLight(false);
|
|
578
|
+
else setIsLight(media?.matches ?? false);
|
|
579
|
+
};
|
|
580
|
+
check();
|
|
581
|
+
const observer = new MutationObserver(check);
|
|
582
|
+
observer.observe(root, {
|
|
583
|
+
attributes: true,
|
|
584
|
+
attributeFilter: ["style"]
|
|
585
|
+
});
|
|
586
|
+
if (media?.addEventListener) media.addEventListener("change", check);
|
|
587
|
+
return () => {
|
|
588
|
+
observer.disconnect();
|
|
589
|
+
if (media?.removeEventListener) media.removeEventListener("change", check);
|
|
590
|
+
};
|
|
591
|
+
}, []);
|
|
592
|
+
return isLight;
|
|
593
|
+
}
|
|
545
594
|
//#endregion
|
|
546
595
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\QuotaButton.module.css.mjs
|
|
547
|
-
const css$12 = ".jYASuG_root{flex:none;display:inline-flex;position:relative}.jYASuG_trigger{width:28px;height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:999px;flex:none;place-items:center;padding:0;display:grid}.jYASuG_trigger svg{display:block}.jYASuG_trigger:hover,.jYASuG_trigger[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.jYASuG_trigger.jYASuG_icon-ok:hover,.jYASuG_trigger.jYASuG_icon-ok[aria-expanded=true]{color:var(--dsw-alias-state-success-primary)}.jYASuG_trigger.jYASuG_icon-warn:hover,.jYASuG_trigger.jYASuG_icon-warn[aria-expanded=true]{color:var(--dsw-alias-state-warn-primary)}.jYASuG_trigger.jYASuG_icon-exhausted:hover,.jYASuG_trigger.jYASuG_icon-exhausted[aria-expanded=true]{color:var(--dsw-alias-state-error-primary)}.jYASuG_icon-ok{color:var(--dsw-alias-state-success-primary)}.jYASuG_icon-warn{color:var(--dsw-alias-state-warn-primary)}.jYASuG_icon-exhausted{color:var(--dsw-alias-state-error-primary)}.jYASuG_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-menu);width:320px;max-width:calc(100vw - 32px);box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-secondary);text-align:left;cursor:default;border-radius:12px;padding:12px;font-size:12px;line-height:20px;position:absolute;bottom:calc(100% + 8px)}.jYASuG_header{justify-content:space-between;align-items:baseline;gap:8px;margin-bottom:10px;display:flex}.jYASuG_title{color:var(--dsw-alias-label-primary);white-space:nowrap;text-overflow:ellipsis;font-size:13px;font-weight:500;overflow:hidden}.jYASuG_plan{color:var(--dsw-alias-label-tertiary);font-weight:400}.jYASuG_updated{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;font-size:11px}.jYASuG_grid{grid-template-columns:repeat(var(--cols,3), 1fr);gap:14px;display:grid}.jYASuG_col{min-width:0}.jYASuG_label{color:var(--dsw-alias-label-tertiary);white-space:nowrap;text-overflow:ellipsis;margin-bottom:2px;font-size:11px;line-height:16px;overflow:hidden}.jYASuG_value{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;white-space:nowrap;margin-bottom:6px;font-size:13px;font-weight:600;line-height:18px}.jYASuG_meta{color:var(--dsw-alias-label-tertiary);font-size:11px;font-weight:400}.jYASuG_bar{background:var(--dsw-alias-interactive-bg-hover);border-radius:999px;height:4px;overflow:hidden}.jYASuG_fill{border-radius:999px;height:100%;transition:width .3s}.jYASuG_ok{background:var(--dsw-alias-state-success-primary)}.jYASuG_warn{background:var(--dsw-alias-state-warn-primary)}.jYASuG_exhausted{background:var(--dsw-alias-state-error-primary)}.jYASuG_aux{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;white-space:nowrap;margin-top:4px;font-size:11px;line-height:14px}.jYASuG_dot{vertical-align:middle;border-radius:50%;width:5px;height:5px;margin-right:3px;display:inline-block}.jYASuG_error{flex-direction:column;gap:8px;display:flex}.jYASuG_errorText{color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;font-size:12px;line-height:18px}.jYASuG_retry{color:var(--dsw-alias-label-primary);cursor:pointer;text-underline-offset:2px;background:0 0;border:none;align-self:flex-start;padding:0;font-size:12px;text-decoration:underline}.jYASuG_retry:hover{color:var(--dsw-alias-brand-primary)}";
|
|
596
|
+
const css$12 = ".jYASuG_root{flex:none;display:inline-flex;position:relative}.jYASuG_trigger{width:28px;height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:999px;flex:none;place-items:center;padding:0;display:grid}.jYASuG_trigger svg{display:block}.jYASuG_trigger:hover,.jYASuG_trigger[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.jYASuG_trigger.jYASuG_icon-ok:hover,.jYASuG_trigger.jYASuG_icon-ok[aria-expanded=true]{color:var(--dsw-alias-state-success-primary)}.jYASuG_trigger.jYASuG_icon-warn:hover,.jYASuG_trigger.jYASuG_icon-warn[aria-expanded=true]{color:var(--dsw-alias-state-warn-primary)}.jYASuG_trigger.jYASuG_icon-exhausted:hover,.jYASuG_trigger.jYASuG_icon-exhausted[aria-expanded=true]{color:var(--dsw-alias-state-error-primary)}.jYASuG_icon-ok{color:var(--dsw-alias-state-success-primary)}.jYASuG_icon-warn{color:var(--dsw-alias-state-warn-primary)}.jYASuG_icon-exhausted{color:var(--dsw-alias-state-error-primary)}.jYASuG_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-menu);width:320px;max-width:calc(100vw - 32px);backdrop-filter:var(--dsw-menu-backdrop-filter);box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-secondary);text-align:left;cursor:default;border-radius:12px;padding:12px;font-size:12px;line-height:20px;position:absolute;bottom:calc(100% + 8px)}.jYASuG_header{justify-content:space-between;align-items:baseline;gap:8px;margin-bottom:10px;display:flex}.jYASuG_title{color:var(--dsw-alias-label-primary);white-space:nowrap;text-overflow:ellipsis;font-size:13px;font-weight:500;overflow:hidden}.jYASuG_plan{color:var(--dsw-alias-label-tertiary);font-weight:400}.jYASuG_updated{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;font-size:11px}.jYASuG_grid{grid-template-columns:repeat(var(--cols,3), 1fr);gap:14px;display:grid}.jYASuG_col{min-width:0}.jYASuG_label{color:var(--dsw-alias-label-tertiary);white-space:nowrap;text-overflow:ellipsis;margin-bottom:2px;font-size:11px;line-height:16px;overflow:hidden}.jYASuG_value{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;white-space:nowrap;margin-bottom:6px;font-size:13px;font-weight:600;line-height:18px}.jYASuG_meta{color:var(--dsw-alias-label-tertiary);font-size:11px;font-weight:400}.jYASuG_bar{background:var(--dsw-alias-interactive-bg-hover);border-radius:999px;height:4px;overflow:hidden}.jYASuG_fill{border-radius:999px;height:100%;transition:width .3s}.jYASuG_ok{background:var(--dsw-alias-state-success-primary)}.jYASuG_warn{background:var(--dsw-alias-state-warn-primary)}.jYASuG_exhausted{background:var(--dsw-alias-state-error-primary)}.jYASuG_aux{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;white-space:nowrap;margin-top:4px;font-size:11px;line-height:14px}.jYASuG_dot{vertical-align:middle;border-radius:50%;width:5px;height:5px;margin-right:3px;display:inline-block}.jYASuG_error{flex-direction:column;gap:8px;display:flex}.jYASuG_errorText{color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;font-size:12px;line-height:18px}.jYASuG_retry{color:var(--dsw-alias-label-primary);cursor:pointer;text-underline-offset:2px;background:0 0;border:none;align-self:flex-start;padding:0;font-size:12px;text-decoration:underline}.jYASuG_retry:hover{color:var(--dsw-alias-brand-primary)}";
|
|
548
597
|
const tagId$12 = "@laoyuehanni/dsh-token-usage/QuotaButton.module.css";
|
|
549
598
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$12) + "]") === null) {
|
|
550
599
|
const tag = document.createElement("style");
|
|
@@ -1056,14 +1105,22 @@ window.__ModuleLoader__.load({
|
|
|
1056
1105
|
/** Known `LlmFailure.code`s that have a `fail.*` locale label. An unknown
|
|
1057
1106
|
* future code is not in this map and the tooltip renders it verbatim. */
|
|
1058
1107
|
const FAILURE_CODE_LABEL_KEYS = {
|
|
1108
|
+
ABORTED: "fail.ABORTED",
|
|
1109
|
+
AUTH: "fail.AUTH",
|
|
1110
|
+
CONTEXT_WINDOW_EXCEEDED: "fail.CONTEXT_WINDOW_EXCEEDED",
|
|
1111
|
+
EMPTY_RESPONSE: "fail.EMPTY_RESPONSE",
|
|
1112
|
+
FILES_API: "fail.FILES_API",
|
|
1113
|
+
INVALID_CREDENTIAL: "fail.INVALID_CREDENTIAL",
|
|
1114
|
+
INVALID_REQUEST: "fail.INVALID_REQUEST",
|
|
1115
|
+
MALFORMED_RESPONSE: "fail.MALFORMED_RESPONSE",
|
|
1116
|
+
MISSING_CREDENTIAL: "fail.MISSING_CREDENTIAL",
|
|
1117
|
+
QUOTA: "fail.QUOTA",
|
|
1059
1118
|
RATE_LIMIT: "fail.RATE_LIMIT",
|
|
1119
|
+
REQUEST_EXTENSION: "fail.REQUEST_EXTENSION",
|
|
1060
1120
|
SERVER: "fail.SERVER",
|
|
1121
|
+
STREAM_CLOSED: "fail.STREAM_CLOSED",
|
|
1061
1122
|
TIMEOUT: "fail.TIMEOUT",
|
|
1062
1123
|
TRANSPORT: "fail.TRANSPORT",
|
|
1063
|
-
EMPTY_RESPONSE: "fail.EMPTY_RESPONSE",
|
|
1064
|
-
QUOTA: "fail.QUOTA",
|
|
1065
|
-
CONTEXT_WINDOW_EXCEEDED: "fail.CONTEXT_WINDOW_EXCEEDED",
|
|
1066
|
-
INVALID_CREDENTIAL: "fail.INVALID_CREDENTIAL",
|
|
1067
1124
|
UNKNOWN: "fail.UNKNOWN"
|
|
1068
1125
|
};
|
|
1069
1126
|
/** One decimal below 10, integer otherwise, trailing `.0` stripped. */
|
|
@@ -1870,11 +1927,20 @@ window.__ModuleLoader__.load({
|
|
|
1870
1927
|
* @returns the card, or nothing when the namespace is unavailable.
|
|
1871
1928
|
*/
|
|
1872
1929
|
function TokenUsageCard(props) {
|
|
1873
|
-
const [open, setOpen] = (0, react.useState)(
|
|
1930
|
+
const [open, setOpen] = (0, react.useState)(props.view === "page");
|
|
1874
1931
|
const [picking, setPicking] = (0, react.useState)(false);
|
|
1875
1932
|
const { t } = props;
|
|
1876
1933
|
const state = props.useTokenUsageCard((snapshot) => snapshot);
|
|
1934
|
+
const discardRef = (0, react.useRef)(props.discard);
|
|
1935
|
+
discardRef.current = props.discard;
|
|
1936
|
+
(0, react.useEffect)(() => () => {
|
|
1937
|
+
discardRef.current();
|
|
1938
|
+
}, []);
|
|
1877
1939
|
if (!state.available) return null;
|
|
1940
|
+
if (props.view === "summary") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1941
|
+
className: TokenUsageCard_module_css_default.description,
|
|
1942
|
+
children: t("card.description")
|
|
1943
|
+
});
|
|
1878
1944
|
const migrating = state.migration !== void 0;
|
|
1879
1945
|
const lockInput = !state.writable || migrating;
|
|
1880
1946
|
const lockActions = !state.dirty || state.saving || migrating;
|
|
@@ -1913,6 +1979,7 @@ window.__ModuleLoader__.load({
|
|
|
1913
1979
|
total: body.total,
|
|
1914
1980
|
added: body.added,
|
|
1915
1981
|
skipped: body.skipped,
|
|
1982
|
+
removed: typeof body.removed === "number" ? body.removed : 0,
|
|
1916
1983
|
failedSessions: typeof body.failedSessions === "number" ? body.failedSessions : 0
|
|
1917
1984
|
};
|
|
1918
1985
|
return null;
|
|
@@ -1959,6 +2026,7 @@ window.__ModuleLoader__.load({
|
|
|
1959
2026
|
total: 0,
|
|
1960
2027
|
added: 0,
|
|
1961
2028
|
skipped: 0,
|
|
2029
|
+
removed: 0,
|
|
1962
2030
|
failedSessions: 0
|
|
1963
2031
|
});
|
|
1964
2032
|
return;
|
|
@@ -1994,7 +2062,7 @@ window.__ModuleLoader__.load({
|
|
|
1994
2062
|
className: TokenUsageCard_module_css_default.pending,
|
|
1995
2063
|
children: t("card.unsaved")
|
|
1996
2064
|
}) : null,
|
|
1997
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.
|
|
2065
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineMedium, { className: open ? `${TokenUsageCard_module_css_default.chevron} ${TokenUsageCard_module_css_default.chevronOpen}` : TokenUsageCard_module_css_default.chevron })
|
|
1998
2066
|
]
|
|
1999
2067
|
}), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2000
2068
|
className: TokenUsageCard_module_css_default.body,
|
|
@@ -2116,7 +2184,8 @@ window.__ModuleLoader__.load({
|
|
|
2116
2184
|
processed: String(fullSync.processed),
|
|
2117
2185
|
total: String(fullSync.total),
|
|
2118
2186
|
added: String(fullSync.added),
|
|
2119
|
-
skipped: String(fullSync.skipped)
|
|
2187
|
+
skipped: String(fullSync.skipped),
|
|
2188
|
+
removed: String(fullSync.removed)
|
|
2120
2189
|
}), fullSync.failedSessions > 0 ? t("card.fullSync.failuresNote", { count: String(fullSync.failedSessions) }) : ""]
|
|
2121
2190
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2122
2191
|
className: TokenUsageCard_module_css_default.fullSyncBar,
|
|
@@ -2131,7 +2200,8 @@ window.__ModuleLoader__.load({
|
|
|
2131
2200
|
role: "status",
|
|
2132
2201
|
children: [t("card.fullSync.done", {
|
|
2133
2202
|
added: String(fullSync.added),
|
|
2134
|
-
skipped: String(fullSync.skipped)
|
|
2203
|
+
skipped: String(fullSync.skipped),
|
|
2204
|
+
removed: String(fullSync.removed)
|
|
2135
2205
|
}), fullSync.failedSessions > 0 ? t("card.fullSync.failuresNote", { count: String(fullSync.failedSessions) }) : ""]
|
|
2136
2206
|
}) : null,
|
|
2137
2207
|
fullSync.status === "failed" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
@@ -2171,7 +2241,7 @@ window.__ModuleLoader__.load({
|
|
|
2171
2241
|
}
|
|
2172
2242
|
//#endregion
|
|
2173
2243
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\DateRangePicker.module.css.mjs
|
|
2174
|
-
const css$8 = ".aSiNOq_wrapper{flex:none;display:inline-flex;position:relative}.aSiNOq_trigger{box-sizing:border-box;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary);background-color:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;white-space:nowrap;border-radius:6px;flex:none;padding:4px 10px;font-size:13px;line-height:20px}.aSiNOq_trigger:hover,.aSiNOq_trigger[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover)}.aSiNOq_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-
|
|
2244
|
+
const css$8 = ".aSiNOq_wrapper{flex:none;display:inline-flex;position:relative}.aSiNOq_trigger{box-sizing:border-box;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary);background-color:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;white-space:nowrap;border-radius:6px;flex:none;padding:4px 10px;font-size:13px;line-height:20px}.aSiNOq_trigger:hover,.aSiNOq_trigger[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover)}.aSiNOq_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);width:266px;max-width:calc(100vw - 32px);box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-secondary);text-align:left;cursor:default;border-radius:12px;padding:10px;font-size:12px;line-height:20px;position:absolute;top:calc(100% + 6px);left:0}.aSiNOq_head{justify-content:space-between;align-items:center;gap:4px;margin-bottom:6px;display:flex}.aSiNOq_nav{width:24px;height:24px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:6px;flex:none;padding:0;font-size:14px;line-height:1}.aSiNOq_nav:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}.aSiNOq_monthTitle{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;font-size:13px;font-weight:500}.aSiNOq_weekdays,.aSiNOq_grid{grid-template-columns:repeat(7,1fr);gap:2px;display:grid}.aSiNOq_weekday{text-align:center;color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px}.aSiNOq_blank{visibility:hidden;height:26px}.aSiNOq_day{font-variant-numeric:tabular-nums;text-align:center;height:26px;color:var(--dsw-alias-label-primary);cursor:pointer;background:0 0;border:none;border-radius:6px;padding:0;font-size:12px;line-height:26px}.aSiNOq_day:hover{background:var(--dsw-alias-interactive-bg-hover)}.aSiNOq_dayToday{box-shadow:inset 0 0 0 1px var(--dsw-alias-border-l2)}.aSiNOq_dayAnchor,.aSiNOq_daySelected{color:var(--dsw-alias-brand-primary);box-shadow:inset 0 0 0 1px var(--dsw-alias-brand-primary);font-weight:600}.aSiNOq_dayInRange{background:var(--dsw-alias-interactive-bg-hover);border-radius:0}.aSiNOq_foot{border-top:1px solid var(--dsw-alias-border-l1);justify-content:flex-end;margin-top:8px;padding-top:8px;display:flex}.aSiNOq_clear{color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:6px;padding:2px 8px;font-size:12px;line-height:18px}.aSiNOq_clear:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}";
|
|
2175
2245
|
const tagId$8 = "@laoyuehanni/dsh-token-usage/DateRangePicker.module.css";
|
|
2176
2246
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$8) + "]") === null) {
|
|
2177
2247
|
const tag = document.createElement("style");
|
|
@@ -2401,7 +2471,7 @@ window.__ModuleLoader__.load({
|
|
|
2401
2471
|
}
|
|
2402
2472
|
//#endregion
|
|
2403
2473
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\MenuSelect.module.css.mjs
|
|
2404
|
-
const css$7 = ".KUIXpG_wrapper{display:inline-flex;position:relative}.KUIXpG_trigger{box-sizing:border-box;color:var(--dsw-alias-label-primary);background-color:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;white-space:nowrap;text-overflow:ellipsis;background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2381858C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E/%3C/svg%3E\");background-position:right 6px center;background-repeat:no-repeat;background-size:12px 12px;border-radius:6px;flex:none;padding:4px 24px 4px 8px;font-size:13px;line-height:20px;overflow:hidden}.KUIXpG_trigger:hover,.KUIXpG_trigger[aria-expanded=true]{background-color:var(--dsw-alias-interactive-bg-hover)}.KUIXpG_grow{flex:0 auto;min-width:0;max-width:220px}.KUIXpG_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-
|
|
2474
|
+
const css$7 = ".KUIXpG_wrapper{display:inline-flex;position:relative}.KUIXpG_trigger{box-sizing:border-box;color:var(--dsw-alias-label-primary);background-color:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;white-space:nowrap;text-overflow:ellipsis;background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2381858C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E/%3C/svg%3E\");background-position:right 6px center;background-repeat:no-repeat;background-size:12px 12px;border-radius:6px;flex:none;padding:4px 24px 4px 8px;font-size:13px;line-height:20px;overflow:hidden}.KUIXpG_trigger:hover,.KUIXpG_trigger[aria-expanded=true]{background-color:var(--dsw-alias-interactive-bg-hover)}.KUIXpG_grow{flex:0 auto;min-width:0;max-width:220px}.KUIXpG_panel{z-index:100;box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);min-width:100%;max-width:260px;max-height:240px;box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-secondary);text-align:left;cursor:default;border-radius:12px;padding:6px;font-size:13px;line-height:20px;position:absolute;top:calc(100% + 6px);left:0;overflow-y:auto}.KUIXpG_option{width:100%;color:var(--dsw-alias-label-primary);cursor:pointer;white-space:nowrap;background:0 0;border:none;border-radius:6px;justify-content:space-between;align-items:center;gap:12px;padding:4px 8px;font-size:13px;line-height:20px;display:flex}.KUIXpG_option:hover{background:var(--dsw-alias-interactive-bg-hover)}.KUIXpG_optionLabel{text-overflow:ellipsis;overflow:hidden}.KUIXpG_optionSelected{color:var(--dsw-alias-brand-primary)}.KUIXpG_check{color:var(--dsw-alias-brand-primary);flex:none}";
|
|
2405
2475
|
const tagId$7 = "@laoyuehanni/dsh-token-usage/MenuSelect.module.css";
|
|
2406
2476
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$7) + "]") === null) {
|
|
2407
2477
|
const tag = document.createElement("style");
|
|
@@ -3584,7 +3654,7 @@ window.__ModuleLoader__.load({
|
|
|
3584
3654
|
}
|
|
3585
3655
|
//#endregion
|
|
3586
3656
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\SessionTable.module.css.mjs
|
|
3587
|
-
const css$3 = ".DW1kVq_head{justify-content:flex-start;align-items:center;gap:8px;display:flex}.DW1kVq_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}.DW1kVq_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}.DW1kVq_segBtn:hover:not(.DW1kVq_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}.DW1kVq_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}.DW1kVq_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}.DW1kVq_tableWrap{max-height:420px;overflow:auto}.DW1kVq_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}.DW1kVq_table th,.DW1kVq_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}.DW1kVq_table th.DW1kVq_sessionHead,.DW1kVq_table td.DW1kVq_sessionCol{text-align:left;width:220px;max-width:220px}.DW1kVq_table td.DW1kVq_sessionIndent{padding-left:18px}.DW1kVq_table th{color:var(--dsw-alias-label-secondary);z-index:1;background:var(--dsw-alias-bg-layer-2);font-weight:
|
|
3657
|
+
const css$3 = ".DW1kVq_head{justify-content:flex-start;align-items:center;gap:8px;display:flex}.DW1kVq_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}.DW1kVq_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}.DW1kVq_segBtn:hover:not(.DW1kVq_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}.DW1kVq_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}.DW1kVq_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}.DW1kVq_tableWrap{max-height:420px;overflow:auto}.DW1kVq_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}.DW1kVq_table th,.DW1kVq_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}.DW1kVq_table th.DW1kVq_sessionHead,.DW1kVq_table td.DW1kVq_sessionCol{text-align:left;width:220px;max-width:220px}.DW1kVq_table td.DW1kVq_sessionIndent{padding-left:18px}.DW1kVq_table th{color:var(--dsw-alias-label-secondary);z-index:1;background:var(--dsw-alias-bg-layer-2);border-bottom:1.5px solid var(--dsw-alias-border-l2);font-weight:600;position:sticky;top:0}.DW1kVq_table tbody tr{transition:background-color .12s}.DW1kVq_table tbody tr:hover{background-color:var(--dsw-interactive-bg-hover)}.DW1kVq_costCol{font-weight:600}.DW1kVq_table td{color:var(--dsw-alias-label-primary)}.DW1kVq_sortBtn{font:inherit;color:inherit;cursor:pointer;white-space:nowrap;background:0 0;border:none;padding:0;font-weight:500}.DW1kVq_sortBtn:hover{color:var(--dsw-alias-label-primary)}.DW1kVq_sortMark{margin-left:3px;font-size:9px}.DW1kVq_sessionCell{align-items:baseline;gap:4px;max-width:208px;display:inline-flex}.DW1kVq_sessionName{text-overflow:ellipsis;white-space:nowrap;font:inherit;color:inherit;text-align:left;background:0 0;border:none;border-bottom:1.5px dashed #0000;max-width:100%;padding:0;overflow:hidden}.DW1kVq_jumpable{cursor:pointer;border-bottom-color:var(--dsw-alias-label-secondary);color:var(--dsw-alias-label-primary);text-decoration:none}.DW1kVq_jumpable:hover{border-bottom-color:var(--dsw-alias-label-primary)}.DW1kVq_badge{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;font-size:10px}.DW1kVq_dirTail{color:var(--dsw-alias-label-tertiary);text-overflow:ellipsis;font-size:10px;display:block;overflow:hidden}.DW1kVq_table td.DW1kVq_groupRow{border-bottom:none;padding-top:8px}.DW1kVq_table td.DW1kVq_groupHead{color:var(--dsw-alias-label-secondary);text-align:left;white-space:nowrap;font-size:11px;font-weight:600}.DW1kVq_groupCount{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;margin-left:6px}";
|
|
3588
3658
|
const tagId$3 = "@laoyuehanni/dsh-token-usage/SessionTable.module.css";
|
|
3589
3659
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$3) + "]") === null) {
|
|
3590
3660
|
const tag = document.createElement("style");
|
|
@@ -3595,6 +3665,7 @@ window.__ModuleLoader__.load({
|
|
|
3595
3665
|
}
|
|
3596
3666
|
var SessionTable_module_css_default = {
|
|
3597
3667
|
"badge": "DW1kVq_badge",
|
|
3668
|
+
"costCol": "DW1kVq_costCol",
|
|
3598
3669
|
"dirTail": "DW1kVq_dirTail",
|
|
3599
3670
|
"groupCount": "DW1kVq_groupCount",
|
|
3600
3671
|
"groupHead": "DW1kVq_groupHead",
|
|
@@ -3697,18 +3768,24 @@ window.__ModuleLoader__.load({
|
|
|
3697
3768
|
const [ctrlHeld, setCtrlHeld] = (0, react.useState)(false);
|
|
3698
3769
|
(0, react.useEffect)(() => {
|
|
3699
3770
|
const down = (event) => {
|
|
3700
|
-
if (event.key === "Control") setCtrlHeld(true);
|
|
3771
|
+
if (event.key === "Control" || event.key === "Meta") setCtrlHeld(true);
|
|
3701
3772
|
};
|
|
3702
3773
|
const up = (event) => {
|
|
3703
|
-
if (event.key === "Control") setCtrlHeld(false);
|
|
3774
|
+
if (event.key === "Control" || event.key === "Meta") setCtrlHeld(false);
|
|
3775
|
+
};
|
|
3776
|
+
const move = (event) => {
|
|
3777
|
+
const active = event.ctrlKey || event.metaKey;
|
|
3778
|
+
setCtrlHeld((previous) => previous === active ? previous : active);
|
|
3704
3779
|
};
|
|
3705
3780
|
const blur = () => setCtrlHeld(false);
|
|
3706
3781
|
window.addEventListener("keydown", down);
|
|
3707
3782
|
window.addEventListener("keyup", up);
|
|
3783
|
+
window.addEventListener("mousemove", move);
|
|
3708
3784
|
window.addEventListener("blur", blur);
|
|
3709
3785
|
return () => {
|
|
3710
3786
|
window.removeEventListener("keydown", down);
|
|
3711
3787
|
window.removeEventListener("keyup", up);
|
|
3788
|
+
window.removeEventListener("mousemove", move);
|
|
3712
3789
|
window.removeEventListener("blur", blur);
|
|
3713
3790
|
};
|
|
3714
3791
|
}, []);
|
|
@@ -3806,7 +3883,7 @@ window.__ModuleLoader__.load({
|
|
|
3806
3883
|
type: "button",
|
|
3807
3884
|
className: jump ? `${SessionTable_module_css_default["sessionName"]} ${SessionTable_module_css_default["jumpable"]}` : SessionTable_module_css_default["sessionName"],
|
|
3808
3885
|
title: jump ? t("session.openHint") : void 0,
|
|
3809
|
-
onClick: jump ? (event) => {
|
|
3886
|
+
onClick: jump || ctrlHeld ? (event) => {
|
|
3810
3887
|
event.preventDefault();
|
|
3811
3888
|
openSession?.(row.sessionId);
|
|
3812
3889
|
} : void 0,
|
|
@@ -3828,7 +3905,10 @@ window.__ModuleLoader__.load({
|
|
|
3828
3905
|
t
|
|
3829
3906
|
}) }),
|
|
3830
3907
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: formatTokens(totalTokens(row.totals)) }),
|
|
3831
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
3908
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
3909
|
+
className: SessionTable_module_css_default["costCol"],
|
|
3910
|
+
children: formatCost(row.cost, view)
|
|
3911
|
+
}),
|
|
3832
3912
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: dayKeyOf(new Date(row.lastTime)) })
|
|
3833
3913
|
] }, row.sessionId);
|
|
3834
3914
|
}
|
|
@@ -3898,32 +3978,141 @@ window.__ModuleLoader__.load({
|
|
|
3898
3978
|
return flags;
|
|
3899
3979
|
}
|
|
3900
3980
|
/**
|
|
3901
|
-
*
|
|
3981
|
+
* Generate a smooth cubic Bezier path using Fritsch-Carlson monotone cubic
|
|
3982
|
+
* Hermite interpolation. Preserves monotonicity so zero-filled plateaus stay
|
|
3983
|
+
* strictly flat at baseline without undershooting, and peaks round smoothly.
|
|
3984
|
+
*
|
|
3985
|
+
* @param xs - scaled x coordinates (monotonic ascending).
|
|
3986
|
+
* @param ys - scaled y coordinates.
|
|
3987
|
+
* @returns SVG `d` string containing M, L, and C commands.
|
|
3988
|
+
*/
|
|
3989
|
+
function monotoneSplinePath(xs, ys) {
|
|
3990
|
+
const n = xs.length;
|
|
3991
|
+
if (n === 0) return "";
|
|
3992
|
+
if (n === 1) return `M${xs[0].toFixed(1)},${ys[0].toFixed(1)}`;
|
|
3993
|
+
if (n === 2) return `M${xs[0].toFixed(1)},${ys[0].toFixed(1)} L${xs[1].toFixed(1)},${ys[1].toFixed(1)}`;
|
|
3994
|
+
const dx = [];
|
|
3995
|
+
const slopes = [];
|
|
3996
|
+
for (let i = 0; i < n - 1; i += 1) {
|
|
3997
|
+
const dX = xs[i + 1] - xs[i];
|
|
3998
|
+
const dY = ys[i + 1] - ys[i];
|
|
3999
|
+
dx.push(dX);
|
|
4000
|
+
slopes.push(dX === 0 ? 0 : dY / dX);
|
|
4001
|
+
}
|
|
4002
|
+
const m = new Array(n);
|
|
4003
|
+
m[0] = slopes[0];
|
|
4004
|
+
m[n - 1] = slopes[n - 2];
|
|
4005
|
+
for (let i = 1; i < n - 1; i += 1) {
|
|
4006
|
+
const s0 = slopes[i - 1];
|
|
4007
|
+
const s1 = slopes[i];
|
|
4008
|
+
if (s0 * s1 <= 0) m[i] = 0;
|
|
4009
|
+
else m[i] = (s0 + s1) / 2;
|
|
4010
|
+
}
|
|
4011
|
+
for (let i = 0; i < n - 1; i += 1) {
|
|
4012
|
+
const slope = slopes[i];
|
|
4013
|
+
if (slope === 0) {
|
|
4014
|
+
m[i] = 0;
|
|
4015
|
+
m[i + 1] = 0;
|
|
4016
|
+
} else {
|
|
4017
|
+
const alpha = m[i] / slope;
|
|
4018
|
+
const beta = m[i + 1] / slope;
|
|
4019
|
+
const dist = alpha * alpha + beta * beta;
|
|
4020
|
+
if (dist > 9) {
|
|
4021
|
+
const tau = 3 / Math.sqrt(dist);
|
|
4022
|
+
m[i] = tau * alpha * slope;
|
|
4023
|
+
m[i + 1] = tau * beta * slope;
|
|
4024
|
+
}
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
const parts = [`M${xs[0].toFixed(1)},${ys[0].toFixed(1)}`];
|
|
4028
|
+
for (let i = 0; i < n - 1; i += 1) {
|
|
4029
|
+
const dX = dx[i];
|
|
4030
|
+
const x0 = xs[i];
|
|
4031
|
+
const y0 = ys[i];
|
|
4032
|
+
const x1 = xs[i + 1];
|
|
4033
|
+
const y1 = ys[i + 1];
|
|
4034
|
+
const cp1x = x0 + dX / 3;
|
|
4035
|
+
const cp1y = y0 + m[i] * (dX / 3);
|
|
4036
|
+
const cp2x = x1 - dX / 3;
|
|
4037
|
+
const cp2y = y1 - m[i + 1] * (dX / 3);
|
|
4038
|
+
parts.push(`C${cp1x.toFixed(1)},${cp1y.toFixed(1)} ${cp2x.toFixed(1)},${cp2y.toFixed(1)} ${x1.toFixed(1)},${y1.toFixed(1)}`);
|
|
4039
|
+
}
|
|
4040
|
+
return parts.join(" ");
|
|
4041
|
+
}
|
|
4042
|
+
/**
|
|
4043
|
+
* Close a line/curve path down to the baseline (`yZero`) to form an area polygon.
|
|
4044
|
+
* Returns an empty string when the input path is empty or has fewer than 2 points.
|
|
3902
4045
|
*
|
|
3903
|
-
*
|
|
3904
|
-
*
|
|
3905
|
-
*
|
|
3906
|
-
*
|
|
3907
|
-
|
|
4046
|
+
* @param linePath - the line or curve `d` string.
|
|
4047
|
+
* @param xs - the plotted x coordinates.
|
|
4048
|
+
* @param yZero - the baseline y coordinate.
|
|
4049
|
+
* @returns SVG `d` string closed with Z for fill.
|
|
4050
|
+
*/
|
|
4051
|
+
function areaPath(linePath, xs, yZero) {
|
|
4052
|
+
if (linePath === "" || xs.length < 2) return "";
|
|
4053
|
+
const firstX = xs[0].toFixed(1);
|
|
4054
|
+
const lastX = xs[xs.length - 1].toFixed(1);
|
|
4055
|
+
const baseY = yZero.toFixed(1);
|
|
4056
|
+
return `${linePath} L${lastX},${baseY} L${firstX},${baseY} Z`;
|
|
4057
|
+
}
|
|
4058
|
+
/**
|
|
4059
|
+
* Return coordinates with gap hold points inserted so temporal series can be
|
|
4060
|
+
* smoothly interpolated with monotonic cubic splines without smearing idle spans.
|
|
3908
4061
|
*/
|
|
3909
|
-
function
|
|
3910
|
-
const { xs, ys, yZero,
|
|
3911
|
-
if (xs.length === 0) return
|
|
3912
|
-
|
|
3913
|
-
|
|
4062
|
+
function gapPatchedPoints(input) {
|
|
4063
|
+
const { xs, ys, yZero, hold, gaps, xEnds } = input;
|
|
4064
|
+
if (xs.length === 0) return {
|
|
4065
|
+
xs: [],
|
|
4066
|
+
ys: []
|
|
4067
|
+
};
|
|
4068
|
+
const outXs = [xs[0]];
|
|
4069
|
+
const outYs = [ys[0]];
|
|
3914
4070
|
for (let index = 0; index < xs.length - 1; index += 1) {
|
|
3915
4071
|
const xNext = xs[index + 1];
|
|
3916
4072
|
const yNext = ys[index + 1];
|
|
3917
|
-
if (
|
|
4073
|
+
if (gaps?.[index] === true) {
|
|
3918
4074
|
const ends = xEnds ?? xs;
|
|
3919
4075
|
const xEnd = ends[index];
|
|
3920
4076
|
const nextWidth = Math.max(ends[index + 1] - xNext, 0);
|
|
3921
4077
|
const xHold = Math.max(xEnd, xNext - nextWidth);
|
|
3922
4078
|
const holdY = hold === "previous" ? ys[index] : yZero;
|
|
3923
|
-
|
|
3924
|
-
|
|
4079
|
+
if (xEnd > outXs[outXs.length - 1]) {
|
|
4080
|
+
outXs.push(xEnd);
|
|
4081
|
+
outYs.push(holdY);
|
|
4082
|
+
}
|
|
4083
|
+
if (xHold > xEnd) {
|
|
4084
|
+
outXs.push(xHold);
|
|
4085
|
+
outYs.push(holdY);
|
|
4086
|
+
}
|
|
4087
|
+
outXs.push(xNext);
|
|
4088
|
+
outYs.push(yNext);
|
|
4089
|
+
} else {
|
|
4090
|
+
outXs.push(xNext);
|
|
4091
|
+
outYs.push(yNext);
|
|
4092
|
+
}
|
|
3925
4093
|
}
|
|
3926
|
-
return
|
|
4094
|
+
return {
|
|
4095
|
+
xs: outXs,
|
|
4096
|
+
ys: outYs
|
|
4097
|
+
};
|
|
4098
|
+
}
|
|
4099
|
+
/**
|
|
4100
|
+
* Generate a smooth spline path for either equidistant or gap-patched temporal series.
|
|
4101
|
+
*/
|
|
4102
|
+
function smoothSeriesPath(input) {
|
|
4103
|
+
const { xs, ys, yZero, gaps, xEnds, hold } = input;
|
|
4104
|
+
if (gaps !== void 0 && gaps.some((g) => g)) {
|
|
4105
|
+
const patched = gapPatchedPoints({
|
|
4106
|
+
xs,
|
|
4107
|
+
ys,
|
|
4108
|
+
yZero,
|
|
4109
|
+
hold,
|
|
4110
|
+
gaps,
|
|
4111
|
+
xEnds
|
|
4112
|
+
});
|
|
4113
|
+
return monotoneSplinePath(patched.xs, patched.ys);
|
|
4114
|
+
}
|
|
4115
|
+
return monotoneSplinePath(xs, ys);
|
|
3927
4116
|
}
|
|
3928
4117
|
//#endregion
|
|
3929
4118
|
//#region src/trend-bucket.ts
|
|
@@ -4199,7 +4388,7 @@ window.__ModuleLoader__.load({
|
|
|
4199
4388
|
}
|
|
4200
4389
|
//#endregion
|
|
4201
4390
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\TrendChart.module.css.mjs
|
|
4202
|
-
const css$2 = ".DWJgoW_chart{width:100%;height:auto;display:block}.DWJgoW_axis{stroke:var(--dsw-alias-border-
|
|
4391
|
+
const css$2 = ".DWJgoW_chart{user-select:none;width:100%;height:auto;display:block}.DWJgoW_axis{stroke:var(--dsw-alias-border-l1);stroke-width:1px}.DWJgoW_grid{stroke:var(--dsw-alias-border-l2);stroke-width:1px;stroke-dasharray:4 4;stroke-opacity:.6}.DWJgoW_area{pointer-events:none}.DWJgoW_line{fill:none;stroke:var(--dsw-alias-label-primary);stroke-width:1.8px;stroke-linejoin:round;stroke-linecap:round}.DWJgoW_chartLight .DWJgoW_dotHalo,[style*=\"color-scheme: light\"] .DWJgoW_chart .DWJgoW_dotHalo{fill:color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent)}.DWJgoW_chartLight .DWJgoW_grid,[style*=\"color-scheme: light\"] .DWJgoW_chart .DWJgoW_grid{stroke-opacity:.45}@media (prefers-color-scheme:light){.DWJgoW_chart:not([data-theme=dark]) .DWJgoW_dotHalo{fill:color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent)}.DWJgoW_chart:not([data-theme=dark]) .DWJgoW_grid{stroke-opacity:.45}}.DWJgoW_dot{fill:var(--dsw-alias-label-primary)}.DWJgoW_dotHalo{fill:color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent)}.DWJgoW_dotActive{fill:var(--dsw-alias-label-primary);stroke:var(--dsw-alias-bg-layer-1);stroke-width:2px}.DWJgoW_guide{stroke:var(--dsw-alias-label-secondary);stroke-width:1px;stroke-dasharray:3 3;stroke-opacity:.45}.DWJgoW_hit{cursor:crosshair;outline:none}.DWJgoW_pointLabel rect{fill:var(--dsw-alias-bg-layer-3);stroke:var(--dsw-alias-border-l2);stroke-width:1px;filter:drop-shadow(0 3px 8px #00000047)}.DWJgoW_pointLabel text{fill:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;font-size:11px;font-weight:500}.DWJgoW_tick{fill:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums;font-size:11px}.DWJgoW_empty{text-align:center;color:var(--dsw-alias-label-secondary);margin:0;padding:24px 0;font-size:13px}";
|
|
4203
4392
|
const tagId$2 = "@laoyuehanni/dsh-token-usage/TrendChart.module.css";
|
|
4204
4393
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$2) + "]") === null) {
|
|
4205
4394
|
const tag = document.createElement("style");
|
|
@@ -4209,10 +4398,13 @@ window.__ModuleLoader__.load({
|
|
|
4209
4398
|
document.head.appendChild(tag);
|
|
4210
4399
|
}
|
|
4211
4400
|
var TrendChart_module_css_default = {
|
|
4401
|
+
"area": "DWJgoW_area",
|
|
4212
4402
|
"axis": "DWJgoW_axis",
|
|
4213
4403
|
"chart": "DWJgoW_chart",
|
|
4404
|
+
"chartLight": "DWJgoW_chartLight",
|
|
4214
4405
|
"dot": "DWJgoW_dot",
|
|
4215
4406
|
"dotActive": "DWJgoW_dotActive",
|
|
4407
|
+
"dotHalo": "DWJgoW_dotHalo",
|
|
4216
4408
|
"empty": "DWJgoW_empty",
|
|
4217
4409
|
"grid": "DWJgoW_grid",
|
|
4218
4410
|
"guide": "DWJgoW_guide",
|
|
@@ -4295,6 +4487,9 @@ window.__ModuleLoader__.load({
|
|
|
4295
4487
|
* @returns the SVG chart, or a placeholder for an empty range.
|
|
4296
4488
|
*/
|
|
4297
4489
|
function TrendChart({ rows, hours, requests, from, to, mode = "interval", t }) {
|
|
4490
|
+
const isLight = useIsLightMode();
|
|
4491
|
+
const gradientId = (0, react.useId)();
|
|
4492
|
+
const [active, setActive] = (0, react.useState)(null);
|
|
4298
4493
|
const base = buildChartPoints({
|
|
4299
4494
|
rows,
|
|
4300
4495
|
hours,
|
|
@@ -4319,20 +4514,19 @@ window.__ModuleLoader__.load({
|
|
|
4319
4514
|
const innerHeight = 140;
|
|
4320
4515
|
const { xs, xEnds, innerWidth } = scaleSeries(series, LEFT, 784);
|
|
4321
4516
|
const radius = dotRadius(points.length);
|
|
4322
|
-
const [active, setActive] = (0, react.useState)(null);
|
|
4323
4517
|
const activePoint = active === null ? null : points[active] ?? null;
|
|
4324
4518
|
const y = (tokens) => 152 - tokens / top * innerHeight;
|
|
4325
|
-
const
|
|
4519
|
+
const ys = points.map((point) => y(point.tokens));
|
|
4520
|
+
const yZero = y(0);
|
|
4521
|
+
const path = smoothSeriesPath({
|
|
4326
4522
|
xs,
|
|
4327
|
-
ys
|
|
4328
|
-
yZero
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
xEnds: xEnds ?? xs,
|
|
4333
|
-
hold: mode === "cumulative" ? "previous" : "zero"
|
|
4334
|
-
} : {}
|
|
4523
|
+
ys,
|
|
4524
|
+
yZero,
|
|
4525
|
+
gaps: series.mode === "temporal" ? gapAfter(series.points) : void 0,
|
|
4526
|
+
xEnds: series.mode === "temporal" ? xEnds ?? xs : void 0,
|
|
4527
|
+
hold: mode === "cumulative" ? "previous" : "zero"
|
|
4335
4528
|
});
|
|
4529
|
+
const area = areaPath(path, xs, yZero);
|
|
4336
4530
|
const chartAria = mode === "cumulative" ? t("chart.ariaCumulative") : series.mode === "temporal" ? t("chart.ariaRequests") : hours !== void 0 ? t("chart.ariaHour") : t("chart.aria");
|
|
4337
4531
|
const hitExtent = (index) => {
|
|
4338
4532
|
if (points.length === 1) return {
|
|
@@ -4350,13 +4544,55 @@ window.__ModuleLoader__.load({
|
|
|
4350
4544
|
width: half * 2
|
|
4351
4545
|
};
|
|
4352
4546
|
};
|
|
4547
|
+
const handleMouseMove = (event) => {
|
|
4548
|
+
if (points.length <= 1) return;
|
|
4549
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
4550
|
+
if (rect.width <= 0) return;
|
|
4551
|
+
const svgX = (event.clientX - rect.left) / rect.width * WIDTH;
|
|
4552
|
+
let closest = 0;
|
|
4553
|
+
let minDiff = Math.abs(xs[0] - svgX);
|
|
4554
|
+
for (let i = 1; i < xs.length; i += 1) {
|
|
4555
|
+
const diff = Math.abs(xs[i] - svgX);
|
|
4556
|
+
if (diff < minDiff) {
|
|
4557
|
+
minDiff = diff;
|
|
4558
|
+
closest = i;
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
setActive(closest);
|
|
4562
|
+
};
|
|
4353
4563
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
4354
4564
|
role: "img",
|
|
4355
4565
|
"aria-label": chartAria,
|
|
4356
4566
|
viewBox: `0 0 ${WIDTH} ${HEIGHT}`,
|
|
4357
|
-
className: TrendChart_module_css_default.chart,
|
|
4567
|
+
className: `${TrendChart_module_css_default.chart} ${isLight ? TrendChart_module_css_default.chartLight : ""}`.trim(),
|
|
4568
|
+
"data-theme": isLight ? "light" : "dark",
|
|
4569
|
+
onMouseMove: handleMouseMove,
|
|
4358
4570
|
onMouseLeave: () => setActive(null),
|
|
4359
4571
|
children: [
|
|
4572
|
+
isLight ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
|
|
4573
|
+
id: gradientId,
|
|
4574
|
+
x1: "0",
|
|
4575
|
+
y1: "0",
|
|
4576
|
+
x2: "0",
|
|
4577
|
+
y2: "1",
|
|
4578
|
+
children: [
|
|
4579
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
|
|
4580
|
+
offset: "0%",
|
|
4581
|
+
stopColor: "var(--dsw-alias-label-primary)",
|
|
4582
|
+
stopOpacity: "0.045"
|
|
4583
|
+
}),
|
|
4584
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
|
|
4585
|
+
offset: "55%",
|
|
4586
|
+
stopColor: "var(--dsw-alias-label-primary)",
|
|
4587
|
+
stopOpacity: "0.012"
|
|
4588
|
+
}),
|
|
4589
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
|
|
4590
|
+
offset: "100%",
|
|
4591
|
+
stopColor: "var(--dsw-alias-label-primary)",
|
|
4592
|
+
stopOpacity: "0.0"
|
|
4593
|
+
})
|
|
4594
|
+
]
|
|
4595
|
+
}) }) : null,
|
|
4360
4596
|
ticks.map((tick) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
4361
4597
|
x1: LEFT,
|
|
4362
4598
|
y1: y(tick),
|
|
@@ -4377,16 +4613,34 @@ window.__ModuleLoader__.load({
|
|
|
4377
4613
|
y2: y(0),
|
|
4378
4614
|
className: TrendChart_module_css_default.axis
|
|
4379
4615
|
}),
|
|
4616
|
+
isLight && area !== "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
4617
|
+
d: area,
|
|
4618
|
+
fill: `url(#${gradientId})`,
|
|
4619
|
+
className: TrendChart_module_css_default.area
|
|
4620
|
+
}) : null,
|
|
4380
4621
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
4381
4622
|
d: path,
|
|
4382
4623
|
className: TrendChart_module_css_default.line
|
|
4383
4624
|
}),
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4625
|
+
activePoint !== null && active !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", {
|
|
4626
|
+
pointerEvents: "none",
|
|
4627
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
4628
|
+
cx: xs[active],
|
|
4629
|
+
cy: y(activePoint.tokens),
|
|
4630
|
+
r: radius + 3.5,
|
|
4631
|
+
className: TrendChart_module_css_default.dotHalo
|
|
4632
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
4633
|
+
cx: xs[active],
|
|
4634
|
+
cy: y(activePoint.tokens),
|
|
4635
|
+
r: radius,
|
|
4636
|
+
className: TrendChart_module_css_default.dotActive
|
|
4637
|
+
})]
|
|
4638
|
+
}) : points.length === 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
4639
|
+
cx: xs[0],
|
|
4640
|
+
cy: y(points[0].tokens),
|
|
4641
|
+
r: radius,
|
|
4642
|
+
className: TrendChart_module_css_default.dot
|
|
4643
|
+
}) : null,
|
|
4390
4644
|
activePoint !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
4391
4645
|
x1: xs[active],
|
|
4392
4646
|
y1: y(activePoint.tokens),
|
|
@@ -4413,7 +4667,7 @@ window.__ModuleLoader__.load({
|
|
|
4413
4667
|
}),
|
|
4414
4668
|
activePoint !== null ? (() => {
|
|
4415
4669
|
const label = tipOf(t, activePoint, mode);
|
|
4416
|
-
const labelWidth = label.length * 6.2 +
|
|
4670
|
+
const labelWidth = label.length * 6.2 + 14;
|
|
4417
4671
|
const center = xs[active];
|
|
4418
4672
|
const left = Math.min(Math.max(center - labelWidth / 2, LEFT), 784 - labelWidth);
|
|
4419
4673
|
const labelY = Math.max(y(activePoint.tokens) - 12, 20);
|
|
@@ -4422,13 +4676,13 @@ window.__ModuleLoader__.load({
|
|
|
4422
4676
|
pointerEvents: "none",
|
|
4423
4677
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
4424
4678
|
x: left,
|
|
4425
|
-
y: labelY -
|
|
4679
|
+
y: labelY - 14,
|
|
4426
4680
|
width: labelWidth,
|
|
4427
|
-
height:
|
|
4428
|
-
rx:
|
|
4681
|
+
height: 22,
|
|
4682
|
+
rx: 6
|
|
4429
4683
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
4430
4684
|
x: left + labelWidth / 2,
|
|
4431
|
-
y: labelY,
|
|
4685
|
+
y: labelY + 1,
|
|
4432
4686
|
textAnchor: "middle",
|
|
4433
4687
|
children: label
|
|
4434
4688
|
})]
|
|
@@ -4446,7 +4700,7 @@ window.__ModuleLoader__.load({
|
|
|
4446
4700
|
}
|
|
4447
4701
|
//#endregion
|
|
4448
4702
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\TokenUsageSection.module.css.mjs
|
|
4449
|
-
const css$1 = ".RbkiSa_section{flex-direction:column;gap:16px;width:100%;display:flex}.RbkiSa_head{justify-content:space-between;align-items:center;gap:12px;display:flex}.RbkiSa_title{color:var(--dsw-alias-label-primary);margin:0;font-size:16px;font-weight:600}.RbkiSa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}.RbkiSa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}.RbkiSa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:14px;font-weight:600}.RbkiSa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}.RbkiSa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}.RbkiSa_segBtn:hover:not(.RbkiSa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}.RbkiSa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}.RbkiSa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}.RbkiSa_tableWrap{max-height:420px;overflow:auto}.RbkiSa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:500px;font-size:12px}.RbkiSa_table th,.RbkiSa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}.RbkiSa_table th.RbkiSa_modelHead,.RbkiSa_table td.RbkiSa_modelCol{text-align:left;width:150px;max-width:150px}.RbkiSa_table th{color:var(--dsw-alias-label-secondary);z-index:1;background:var(--dsw-alias-bg-layer-2);font-weight:
|
|
4703
|
+
const css$1 = ".RbkiSa_section{flex-direction:column;gap:16px;width:100%;display:flex}.RbkiSa_head{justify-content:space-between;align-items:center;gap:12px;display:flex}.RbkiSa_title{color:var(--dsw-alias-label-primary);margin:0;font-size:16px;font-weight:600}.RbkiSa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}.RbkiSa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}.RbkiSa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:14px;font-weight:600}.RbkiSa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}.RbkiSa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}.RbkiSa_segBtn:hover:not(.RbkiSa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}.RbkiSa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}.RbkiSa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}.RbkiSa_tableWrap{max-height:420px;overflow:auto}.RbkiSa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:500px;font-size:12px}.RbkiSa_table th,.RbkiSa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}.RbkiSa_table th.RbkiSa_modelHead,.RbkiSa_table td.RbkiSa_modelCol{text-align:left;width:150px;max-width:150px}.RbkiSa_table th{color:var(--dsw-alias-label-secondary);z-index:1;background:var(--dsw-alias-bg-layer-2);border-bottom:1.5px solid var(--dsw-alias-border-l2);font-weight:600;position:sticky;top:0}.RbkiSa_table tbody tr{transition:background-color .12s}.RbkiSa_table tbody tr:hover{background-color:var(--dsw-interactive-bg-hover)}.RbkiSa_costCol{font-weight:600}.RbkiSa_zeroDim{color:var(--dsw-alias-label-tertiary);opacity:.55}.RbkiSa_table td{color:var(--dsw-alias-label-primary)}.RbkiSa_empty{color:var(--dsw-alias-label-secondary);margin:0;font-size:13px}.RbkiSa_button{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;border-radius:6px;padding:4px 12px;font-size:13px;line-height:20px}.RbkiSa_button:hover{background:var(--dsw-interactive-bg-hover)}.RbkiSa_filters{flex-wrap:nowrap;align-items:center;gap:8px;display:flex}.RbkiSa_cards{grid-template-columns:repeat(auto-fit,minmax(110px,1fr));gap:8px;display:grid}.RbkiSa_warning{color:var(--dsw-alias-state-warn-label);background:var(--dsw-alias-state-warn-tertiary);border-radius:6px;margin:0;padding:6px 10px;font-size:12px}.RbkiSa_modelCell{align-items:center;gap:4px;max-width:138px;display:inline-flex;position:relative}.RbkiSa_modelName{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}button.RbkiSa_modelName{max-width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:none;margin:0;padding:0}button.RbkiSa_modelName:hover{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary))}.RbkiSa_unpricedTag{color:var(--dsw-alias-state-warn-label);background:var(--dsw-alias-state-warn-tertiary);border-radius:8px;flex:none;padding:0 6px;font-size:10px;line-height:16px}.RbkiSa_pricingLink{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary));cursor:pointer;white-space:nowrap;background:0 0;border:none;border-radius:6px;flex:none;margin-left:auto;padding:4px 8px;font-size:13px;line-height:20px}.RbkiSa_pricingLink:hover{background:var(--dsw-interactive-bg-hover)}";
|
|
4450
4704
|
const tagId$1 = "@laoyuehanni/dsh-token-usage/TokenUsageSection.module.css";
|
|
4451
4705
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
|
|
4452
4706
|
const tag = document.createElement("style");
|
|
@@ -4458,6 +4712,7 @@ window.__ModuleLoader__.load({
|
|
|
4458
4712
|
var TokenUsageSection_module_css_default = {
|
|
4459
4713
|
"button": "RbkiSa_button",
|
|
4460
4714
|
"cards": "RbkiSa_cards",
|
|
4715
|
+
"costCol": "RbkiSa_costCol",
|
|
4461
4716
|
"empty": "RbkiSa_empty",
|
|
4462
4717
|
"error": "RbkiSa_error",
|
|
4463
4718
|
"filters": "RbkiSa_filters",
|
|
@@ -4467,7 +4722,6 @@ window.__ModuleLoader__.load({
|
|
|
4467
4722
|
"modelHead": "RbkiSa_modelHead",
|
|
4468
4723
|
"modelName": "RbkiSa_modelName",
|
|
4469
4724
|
"muted": "RbkiSa_muted",
|
|
4470
|
-
"pricingButton": "RbkiSa_pricingButton",
|
|
4471
4725
|
"pricingLink": "RbkiSa_pricingLink",
|
|
4472
4726
|
"section": "RbkiSa_section",
|
|
4473
4727
|
"segActive": "RbkiSa_segActive",
|
|
@@ -4478,7 +4732,8 @@ window.__ModuleLoader__.load({
|
|
|
4478
4732
|
"tableWrap": "RbkiSa_tableWrap",
|
|
4479
4733
|
"title": "RbkiSa_title",
|
|
4480
4734
|
"unpricedTag": "RbkiSa_unpricedTag",
|
|
4481
|
-
"warning": "RbkiSa_warning"
|
|
4735
|
+
"warning": "RbkiSa_warning",
|
|
4736
|
+
"zeroDim": "RbkiSa_zeroDim"
|
|
4482
4737
|
};
|
|
4483
4738
|
//#endregion
|
|
4484
4739
|
//#region src/client/TokenUsageSection.tsx
|
|
@@ -4487,10 +4742,11 @@ window.__ModuleLoader__.load({
|
|
|
4487
4742
|
* the host route and renders the filter bar (inclusive day range, model
|
|
4488
4743
|
* select, 1d/7d/30d quick ranges where 1d spans today 00:00–23:59), the
|
|
4489
4744
|
* total-usage strip, the daily-token trend chart, and the per-model detail
|
|
4490
|
-
* table with the hit rate last — all following the active filters.
|
|
4491
|
-
* priced model row's
|
|
4492
|
-
*
|
|
4493
|
-
*
|
|
4745
|
+
* table with the hit rate last — all following the active filters. A
|
|
4746
|
+
* priced model name is the row's price affordance (one click opens
|
|
4747
|
+
* PricingDialog.tsx); unpriced rows keep the in-cell tag. The filter
|
|
4748
|
+
* row's tail link opens the filter-free pricing-overview dialog
|
|
4749
|
+
* (PricingOverviewDialog.tsx). There is no refresh
|
|
4494
4750
|
* button: entering the page or changing a filter refetches (the route
|
|
4495
4751
|
* answers no-store); only the error state keeps a retry.
|
|
4496
4752
|
*
|
|
@@ -4633,6 +4889,30 @@ window.__ModuleLoader__.load({
|
|
|
4633
4889
|
function TokenUsageSection({ t, close, sessionListed, openSession }) {
|
|
4634
4890
|
const rootRef = (0, react.useRef)(null);
|
|
4635
4891
|
useColorSchemeMirror(rootRef);
|
|
4892
|
+
const [toastText, setToastText] = (0, react.useState)(null);
|
|
4893
|
+
const [toastSeq, setToastSeq] = (0, react.useState)(0);
|
|
4894
|
+
const showToast = (0, react.useCallback)((text) => {
|
|
4895
|
+
setToastSeq((previous) => previous + 1);
|
|
4896
|
+
setToastText(text);
|
|
4897
|
+
}, []);
|
|
4898
|
+
const dismissToast = (0, react.useCallback)(() => {
|
|
4899
|
+
setToastText(null);
|
|
4900
|
+
}, []);
|
|
4901
|
+
const handleOpenSession = (0, react.useCallback)((id) => {
|
|
4902
|
+
if (!openSession) return;
|
|
4903
|
+
const result = openSession(id);
|
|
4904
|
+
if (result && typeof result === "object" && "ok" in result) {
|
|
4905
|
+
if (result.ok) close();
|
|
4906
|
+
else if (result.reason === "workspaceDeleted") showToast(t("session.workspaceDeleted"));
|
|
4907
|
+
return;
|
|
4908
|
+
}
|
|
4909
|
+
if (result === true) close();
|
|
4910
|
+
}, [
|
|
4911
|
+
openSession,
|
|
4912
|
+
close,
|
|
4913
|
+
showToast,
|
|
4914
|
+
t
|
|
4915
|
+
]);
|
|
4636
4916
|
const [filters, setFilters] = (0, react.useState)(() => ({
|
|
4637
4917
|
model: "",
|
|
4638
4918
|
...quickRange(1)
|
|
@@ -4832,21 +5112,21 @@ window.__ModuleLoader__.load({
|
|
|
4832
5112
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tr", { children: [
|
|
4833
5113
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
4834
5114
|
className: TokenUsageSection_module_css_default["modelCol"],
|
|
4835
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.
|
|
5115
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4836
5116
|
className: TokenUsageSection_module_css_default["modelCell"],
|
|
4837
|
-
children:
|
|
4838
|
-
className: TokenUsageSection_module_css_default["modelName"],
|
|
4839
|
-
children: row.model
|
|
4840
|
-
}), rules !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
5117
|
+
children: rules !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
4841
5118
|
type: "button",
|
|
4842
|
-
className: TokenUsageSection_module_css_default["
|
|
5119
|
+
className: TokenUsageSection_module_css_default["modelName"],
|
|
4843
5120
|
"aria-label": t("pricing.view", { model: row.model }),
|
|
4844
5121
|
onClick: () => setDetailModel(row.model),
|
|
4845
|
-
children:
|
|
4846
|
-
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
5122
|
+
children: row.model
|
|
5123
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
5124
|
+
className: TokenUsageSection_module_css_default["modelName"],
|
|
5125
|
+
children: row.model
|
|
5126
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4847
5127
|
className: TokenUsageSection_module_css_default["unpricedTag"],
|
|
4848
5128
|
children: t("pricing.unpriced")
|
|
4849
|
-
})]
|
|
5129
|
+
})] })
|
|
4850
5130
|
})
|
|
4851
5131
|
}),
|
|
4852
5132
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RequestsCell, {
|
|
@@ -4855,12 +5135,27 @@ window.__ModuleLoader__.load({
|
|
|
4855
5135
|
failuresByCode: row.totals.failuresByCode,
|
|
4856
5136
|
t
|
|
4857
5137
|
}) }),
|
|
4858
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5138
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5139
|
+
className: TokenUsageSection_module_css_default["costCol"],
|
|
5140
|
+
children: rules !== void 0 ? formatCost(row.cost, view) : "—"
|
|
5141
|
+
}),
|
|
4859
5142
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: formatTokens(totalTokens(row.totals)) }),
|
|
4860
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
5143
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5144
|
+
className: row.totals.inputTokens === 0 ? TokenUsageSection_module_css_default["zeroDim"] : void 0,
|
|
5145
|
+
children: formatTokens(row.totals.inputTokens)
|
|
5146
|
+
}),
|
|
5147
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5148
|
+
className: row.totals.outputTokens === 0 ? TokenUsageSection_module_css_default["zeroDim"] : void 0,
|
|
5149
|
+
children: formatTokens(row.totals.outputTokens)
|
|
5150
|
+
}),
|
|
5151
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5152
|
+
className: row.totals.cacheReadTokens === 0 ? TokenUsageSection_module_css_default["zeroDim"] : void 0,
|
|
5153
|
+
children: formatTokens(row.totals.cacheReadTokens)
|
|
5154
|
+
}),
|
|
5155
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5156
|
+
className: row.totals.cacheWriteTokens === 0 ? TokenUsageSection_module_css_default["zeroDim"] : void 0,
|
|
5157
|
+
children: formatTokens(row.totals.cacheWriteTokens)
|
|
5158
|
+
}),
|
|
4864
5159
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HitRateText, { totals: row.totals }) })
|
|
4865
5160
|
] }, row.model);
|
|
4866
5161
|
}) })]
|
|
@@ -4871,9 +5166,7 @@ window.__ModuleLoader__.load({
|
|
|
4871
5166
|
t,
|
|
4872
5167
|
...sessionListed !== void 0 && openSession !== void 0 ? {
|
|
4873
5168
|
sessionListed,
|
|
4874
|
-
openSession:
|
|
4875
|
-
if (openSession(id)) close();
|
|
4876
|
-
}
|
|
5169
|
+
openSession: handleOpenSession
|
|
4877
5170
|
} : {}
|
|
4878
5171
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
4879
5172
|
className: TokenUsageSection_module_css_default["muted"],
|
|
@@ -4886,13 +5179,18 @@ window.__ModuleLoader__.load({
|
|
|
4886
5179
|
onClose: () => setDetailModel(null),
|
|
4887
5180
|
t
|
|
4888
5181
|
}) : null
|
|
4889
|
-
] })
|
|
5182
|
+
] }),
|
|
5183
|
+
toastText !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Toast, {
|
|
5184
|
+
text: toastText,
|
|
5185
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconWarningOutlineRegular, {}),
|
|
5186
|
+
onDone: dismissToast
|
|
5187
|
+
}, toastSeq)
|
|
4890
5188
|
]
|
|
4891
5189
|
});
|
|
4892
5190
|
}
|
|
4893
5191
|
//#endregion
|
|
4894
5192
|
//#region \0dsh-css:D:\Code\dsh-token-usage\src\client\UsageView.module.css.mjs
|
|
4895
|
-
const css = "._0MkXVa_root{box-sizing:border-box;width:100%;padding:12px calc(var(--dsh-composer-side-clearance,16px) + 16px);padding-bottom:calc(var(--dsh-composer-height,152px) + 16px);flex-direction:column;gap:12px;max-width:1400px;height:100%;min-height:0;margin:0 auto;display:flex;overflow-y:auto}._0MkXVa_head{flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:12px;display:flex}._0MkXVa_headRight{align-items:center;gap:10px;display:flex}._0MkXVa_back{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;padding:3px 10px;font-size:12px}._0MkXVa_back:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}._0MkXVa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}._0MkXVa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}._0MkXVa_segBtn:hover:not(._0MkXVa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}._0MkXVa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}._0MkXVa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}._0MkXVa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}._0MkXVa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}._0MkXVa_empty{color:var(--dsw-alias-label-secondary);text-align:center;margin:24px 0 0;font-size:13px}._0MkXVa_button{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;align-self:flex-start;padding:3px 10px;font-size:12px}._0MkXVa_warning{color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-label-secondary));margin:0;font-size:12px}._0MkXVa_note{color:var(--dsw-alias-label-tertiary);margin:0;font-size:11px}._0MkXVa_cards{grid-template-columns:repeat(6,minmax(0,1fr));gap:10px;display:grid}._0MkXVa_tokenStrip{color:var(--dsw-alias-label-secondary);flex-wrap:wrap;gap:18px;padding:6px 2px 0;font-size:12px;display:flex}._0MkXVa_tokenStrip b{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums}._0MkXVa_mid{grid-template-columns:minmax(0,3fr) minmax(0,2fr);align-items:start;gap:14px;display:grid}._0MkXVa_chartCol,._0MkXVa_modelCol,._0MkXVa_subagents{flex-direction:column;gap:6px;min-width:0;display:flex}._0MkXVa_subagentsHead,._0MkXVa_chartHead{align-items:center;gap:8px;display:flex}._0MkXVa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:13px;font-weight:600}._0MkXVa_tableWrap{overflow-x:auto}._0MkXVa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}._0MkXVa_table th,._0MkXVa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}._0MkXVa_table th:first-child,._0MkXVa_table td:first-child,._0MkXVa_modelHead{text-align:left}._0MkXVa_modelCell{font-variant-numeric:normal;text-overflow:ellipsis;max-width:180px;overflow:hidden}._0MkXVa_childLink{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary));cursor:pointer;text-align:left;text-overflow:ellipsis;white-space:nowrap;background:0 0;border:none;max-width:220px;padding:0;font-size:12px;overflow:hidden}._0MkXVa_childLink:hover{text-decoration:underline}._0MkXVa_nestedBadge{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;margin-left:6px;font-size:11px}@media (width<=900px){._0MkXVa_cards{grid-template-columns:repeat(3,minmax(0,1fr))}._0MkXVa_mid{grid-template-columns:1fr}}";
|
|
5193
|
+
const css = "._0MkXVa_root{box-sizing:border-box;width:100%;padding:12px calc(var(--dsh-composer-side-clearance,16px) + 16px);padding-bottom:calc(var(--dsh-composer-height,152px) + 16px);flex-direction:column;gap:12px;max-width:1400px;height:100%;min-height:0;margin:0 auto;display:flex;overflow-y:auto}._0MkXVa_head{flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:12px;display:flex}._0MkXVa_headRight{align-items:center;gap:10px;display:flex}._0MkXVa_back{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;padding:3px 10px;font-size:12px}._0MkXVa_back:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}._0MkXVa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}._0MkXVa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}._0MkXVa_segBtn:hover:not(._0MkXVa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}._0MkXVa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}._0MkXVa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}._0MkXVa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}._0MkXVa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}._0MkXVa_empty{color:var(--dsw-alias-label-secondary);text-align:center;margin:24px 0 0;font-size:13px}._0MkXVa_button{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;align-self:flex-start;padding:3px 10px;font-size:12px}._0MkXVa_warning{color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-label-secondary));margin:0;font-size:12px}._0MkXVa_note{color:var(--dsw-alias-label-tertiary);margin:0;font-size:11px}._0MkXVa_cards{grid-template-columns:repeat(6,minmax(0,1fr));gap:10px;display:grid}._0MkXVa_tokenStrip{color:var(--dsw-alias-label-secondary);flex-wrap:wrap;gap:18px;padding:6px 2px 0;font-size:12px;display:flex}._0MkXVa_tokenStrip b{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums}._0MkXVa_mid{grid-template-columns:minmax(0,3fr) minmax(0,2fr);align-items:start;gap:14px;display:grid}._0MkXVa_chartCol,._0MkXVa_modelCol,._0MkXVa_subagents{flex-direction:column;gap:6px;min-width:0;display:flex}._0MkXVa_subagentsHead,._0MkXVa_chartHead{align-items:center;gap:8px;display:flex}._0MkXVa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:13px;font-weight:600}._0MkXVa_tableWrap{overflow-x:auto}._0MkXVa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}._0MkXVa_table th,._0MkXVa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}._0MkXVa_table tbody tr{transition:background-color .12s}._0MkXVa_table tbody tr:hover{background-color:var(--dsw-interactive-bg-hover)}._0MkXVa_table th{border-bottom:1.5px solid var(--dsw-alias-border-l2);font-weight:600}._0MkXVa_costCol{font-weight:600}._0MkXVa_zeroDim{color:var(--dsw-alias-label-tertiary);opacity:.55}._0MkXVa_table th:first-child,._0MkXVa_table td:first-child,._0MkXVa_modelHead{text-align:left}._0MkXVa_modelCell{font-variant-numeric:normal;text-overflow:ellipsis;max-width:180px;overflow:hidden}._0MkXVa_childLink{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary));cursor:pointer;text-align:left;text-overflow:ellipsis;white-space:nowrap;background:0 0;border:none;max-width:220px;padding:0;font-size:12px;overflow:hidden}._0MkXVa_childLink:hover{text-decoration:underline}._0MkXVa_nestedBadge{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;margin-left:6px;font-size:11px}@media (width<=900px){._0MkXVa_cards{grid-template-columns:repeat(3,minmax(0,1fr))}._0MkXVa_mid{grid-template-columns:1fr}}";
|
|
4896
5194
|
const tagId = "@laoyuehanni/dsh-token-usage/UsageView.module.css";
|
|
4897
5195
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
4898
5196
|
const tag = document.createElement("style");
|
|
@@ -4908,6 +5206,7 @@ window.__ModuleLoader__.load({
|
|
|
4908
5206
|
"chartCol": "_0MkXVa_chartCol",
|
|
4909
5207
|
"chartHead": "_0MkXVa_chartHead",
|
|
4910
5208
|
"childLink": "_0MkXVa_childLink",
|
|
5209
|
+
"costCol": "_0MkXVa_costCol",
|
|
4911
5210
|
"empty": "_0MkXVa_empty",
|
|
4912
5211
|
"error": "_0MkXVa_error",
|
|
4913
5212
|
"head": "_0MkXVa_head",
|
|
@@ -4929,7 +5228,8 @@ window.__ModuleLoader__.load({
|
|
|
4929
5228
|
"table": "_0MkXVa_table",
|
|
4930
5229
|
"tableWrap": "_0MkXVa_tableWrap",
|
|
4931
5230
|
"tokenStrip": "_0MkXVa_tokenStrip",
|
|
4932
|
-
"warning": "_0MkXVa_warning"
|
|
5231
|
+
"warning": "_0MkXVa_warning",
|
|
5232
|
+
"zeroDim": "_0MkXVa_zeroDim"
|
|
4933
5233
|
};
|
|
4934
5234
|
//#endregion
|
|
4935
5235
|
//#region src/client/UsageView.tsx
|
|
@@ -5247,12 +5547,27 @@ window.__ModuleLoader__.load({
|
|
|
5247
5547
|
failuresByCode: row.totals.failuresByCode,
|
|
5248
5548
|
t
|
|
5249
5549
|
}) }),
|
|
5250
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5550
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5551
|
+
className: row.totals.inputTokens === 0 ? UsageView_module_css_default["zeroDim"] : void 0,
|
|
5552
|
+
children: formatTokens(row.totals.inputTokens)
|
|
5553
|
+
}),
|
|
5554
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5555
|
+
className: row.totals.outputTokens === 0 ? UsageView_module_css_default["zeroDim"] : void 0,
|
|
5556
|
+
children: formatTokens(row.totals.outputTokens)
|
|
5557
|
+
}),
|
|
5558
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5559
|
+
className: row.totals.cacheReadTokens === 0 ? UsageView_module_css_default["zeroDim"] : void 0,
|
|
5560
|
+
children: formatTokens(row.totals.cacheReadTokens)
|
|
5561
|
+
}),
|
|
5562
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5563
|
+
className: row.totals.cacheWriteTokens === 0 ? UsageView_module_css_default["zeroDim"] : void 0,
|
|
5564
|
+
children: formatTokens(row.totals.cacheWriteTokens)
|
|
5565
|
+
}),
|
|
5254
5566
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HitRateText, { totals: row.totals }) }),
|
|
5255
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5567
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5568
|
+
className: UsageView_module_css_default["costCol"],
|
|
5569
|
+
children: formatCost(row.cost, view)
|
|
5570
|
+
})
|
|
5256
5571
|
] }, row.model)) })]
|
|
5257
5572
|
})
|
|
5258
5573
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
@@ -5325,7 +5640,10 @@ window.__ModuleLoader__.load({
|
|
|
5325
5640
|
}),
|
|
5326
5641
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: row?.total.requests.toLocaleString() ?? "—" }),
|
|
5327
5642
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: row !== void 0 ? formatTokens(totalTokens(row.total)) : "—" }),
|
|
5328
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5643
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
5644
|
+
className: UsageView_module_css_default["costCol"],
|
|
5645
|
+
children: row !== void 0 ? formatCost(row.totalCost, view) : "—"
|
|
5646
|
+
}),
|
|
5329
5647
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: row !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HitRateText, { totals: row.total }) : "—" }),
|
|
5330
5648
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: childStats !== void 0 && childStats.ttftSteps > 0 ? formatTtft(childStats.ttftMs / childStats.ttftSteps) : "—" }),
|
|
5331
5649
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: childStats !== void 0 && childStats.decodeMs > 0 ? `${formatSpeed(childStats.decodeTokens / (childStats.decodeMs / 1e3))} tok/s` : "—" })
|
|
@@ -5388,6 +5706,14 @@ window.__ModuleLoader__.load({
|
|
|
5388
5706
|
"fail.QUOTA": "配额耗尽",
|
|
5389
5707
|
"fail.CONTEXT_WINDOW_EXCEEDED": "上下文超限",
|
|
5390
5708
|
"fail.INVALID_CREDENTIAL": "凭证无效",
|
|
5709
|
+
"fail.AUTH": "鉴权失败",
|
|
5710
|
+
"fail.INVALID_REQUEST": "请求无效",
|
|
5711
|
+
"fail.MISSING_CREDENTIAL": "缺少凭证",
|
|
5712
|
+
"fail.ABORTED": "已中止",
|
|
5713
|
+
"fail.REQUEST_EXTENSION": "请求扩展失败",
|
|
5714
|
+
"fail.FILES_API": "文件接口异常",
|
|
5715
|
+
"fail.STREAM_CLOSED": "流中断",
|
|
5716
|
+
"fail.MALFORMED_RESPONSE": "响应异常",
|
|
5391
5717
|
"fail.UNKNOWN": "未知错误",
|
|
5392
5718
|
"stat.totalTokens": "总 token",
|
|
5393
5719
|
"stat.hitRate": "命中率",
|
|
@@ -5407,6 +5733,7 @@ window.__ModuleLoader__.load({
|
|
|
5407
5733
|
"session.subagentBadge": "子会话",
|
|
5408
5734
|
"session.lastActive": "最近活跃",
|
|
5409
5735
|
"session.openHint": "按住 Ctrl 点击打开该会话(用量页签跟随该会话上次的选择)",
|
|
5736
|
+
"session.workspaceDeleted": "该会话所属工作区已删除,无法跳转",
|
|
5410
5737
|
"pricing.title": "模型定价",
|
|
5411
5738
|
"pricing.view": "查看 {model} 定价",
|
|
5412
5739
|
"pricing.viewShort": "定价",
|
|
@@ -5468,9 +5795,9 @@ window.__ModuleLoader__.load({
|
|
|
5468
5795
|
"card.fullSync.hint": "手动扫一遍所有 session 日志,把可能漏掉的历史请求补进来(已记录的会跳过)。",
|
|
5469
5796
|
"card.fullSync.button": "开始扫描",
|
|
5470
5797
|
"card.fullSync.running": "扫描中…",
|
|
5471
|
-
"card.fullSync.progress": "已处理 {processed}/{total} 个 session,新增 {added} 条,跳过 {skipped} 条",
|
|
5798
|
+
"card.fullSync.progress": "已处理 {processed}/{total} 个 session,新增 {added} 条,跳过 {skipped} 条,删除 {removed} 条",
|
|
5472
5799
|
"card.fullSync.failuresNote": ",无法读取 {count} 个 session 已跳过",
|
|
5473
|
-
"card.fullSync.done": "扫描完成:新增 {added} 条,跳过 {skipped} 条",
|
|
5800
|
+
"card.fullSync.done": "扫描完成:新增 {added} 条,跳过 {skipped} 条,删除 {removed} 条",
|
|
5474
5801
|
"card.fullSync.failed": "扫描失败:{error}",
|
|
5475
5802
|
"loadFailed": "统计加载失败:{message}",
|
|
5476
5803
|
"empty": "暂无数据。可调整筛选条件;模型请求成功后会自动写入,安装前已发生的历史记录会在首次启动时自动补齐。",
|
|
@@ -5553,6 +5880,14 @@ window.__ModuleLoader__.load({
|
|
|
5553
5880
|
"fail.QUOTA": "Quota exceeded",
|
|
5554
5881
|
"fail.CONTEXT_WINDOW_EXCEEDED": "Context exceeded",
|
|
5555
5882
|
"fail.INVALID_CREDENTIAL": "Invalid credential",
|
|
5883
|
+
"fail.AUTH": "Auth failed",
|
|
5884
|
+
"fail.INVALID_REQUEST": "Invalid request",
|
|
5885
|
+
"fail.MISSING_CREDENTIAL": "Missing credential",
|
|
5886
|
+
"fail.ABORTED": "Aborted",
|
|
5887
|
+
"fail.REQUEST_EXTENSION": "Request extension failed",
|
|
5888
|
+
"fail.FILES_API": "Files API error",
|
|
5889
|
+
"fail.STREAM_CLOSED": "Stream closed",
|
|
5890
|
+
"fail.MALFORMED_RESPONSE": "Malformed response",
|
|
5556
5891
|
"fail.UNKNOWN": "Unknown error",
|
|
5557
5892
|
"stat.totalTokens": "Total",
|
|
5558
5893
|
"stat.hitRate": "Hit %",
|
|
@@ -5572,6 +5907,7 @@ window.__ModuleLoader__.load({
|
|
|
5572
5907
|
"session.subagentBadge": "Subagent",
|
|
5573
5908
|
"session.lastActive": "Last active",
|
|
5574
5909
|
"session.openHint": "Ctrl+click to open this session (the usage tab follows its last selection)",
|
|
5910
|
+
"session.workspaceDeleted": "The workspace for this session has been deleted and cannot be opened",
|
|
5575
5911
|
"pricing.title": "Model pricing",
|
|
5576
5912
|
"pricing.view": "View rates for {model}",
|
|
5577
5913
|
"pricing.viewShort": "Rates",
|
|
@@ -5633,9 +5969,9 @@ window.__ModuleLoader__.load({
|
|
|
5633
5969
|
"card.fullSync.hint": "Walk every session log once and fold any historical requests the log does not yet hold (rows already recorded are skipped).",
|
|
5634
5970
|
"card.fullSync.button": "Start scan",
|
|
5635
5971
|
"card.fullSync.running": "Scanning…",
|
|
5636
|
-
"card.fullSync.progress": "Processed {processed}/{total} sessions, added {added}, skipped {skipped}",
|
|
5972
|
+
"card.fullSync.progress": "Processed {processed}/{total} sessions, added {added}, skipped {skipped}, removed {removed}",
|
|
5637
5973
|
"card.fullSync.failuresNote": ", {count} unreadable sessions skipped",
|
|
5638
|
-
"card.fullSync.done": "Scan complete: added {added}, skipped {skipped}",
|
|
5974
|
+
"card.fullSync.done": "Scan complete: added {added}, skipped {skipped}, removed {removed}",
|
|
5639
5975
|
"card.fullSync.failed": "Scan failed: {error}",
|
|
5640
5976
|
"loadFailed": "Failed to load stats: {message}",
|
|
5641
5977
|
"empty": "No data yet. Adjust the filters; requests are written automatically after each successful model call, and pre-install history is backfilled automatically on the first startup.",
|
|
@@ -5691,18 +6027,41 @@ window.__ModuleLoader__.load({
|
|
|
5691
6027
|
* imported: a client package must not depend on a Host package.
|
|
5692
6028
|
*/
|
|
5693
6029
|
const TOKEN_USAGE_NS = "token-usage";
|
|
6030
|
+
/**
|
|
6031
|
+
* Candidate keys under which the Host may serve this plugin's settings
|
|
6032
|
+
* form. The 0.1.7 host keys `ConfigForms.get` by the plugin's ENTRY ID (the
|
|
6033
|
+
* namespace); the full package name stays as a fallback for a host that keyed
|
|
6034
|
+
* it by package instead.
|
|
6035
|
+
*/
|
|
6036
|
+
const CONFIG_FORM_KEYS = [TOKEN_USAGE_NS, "@laoyuehanni/dsh-token-usage"];
|
|
6037
|
+
/**
|
|
6038
|
+
* Resolve the form target from the describe mirror's LIVE namespace list.
|
|
6039
|
+
* The 0.1.7 `ConfigForms.get()` unconditionally creates and caches a
|
|
6040
|
+
* controller for ANY key — it never returns undefined — so key validity must
|
|
6041
|
+
* come from the namespaces the mirror actually serves. A `get()` on a key the
|
|
6042
|
+
* mirror does not list yields a controller stuck at 'unavailable' forever,
|
|
6043
|
+
* and the card renders nothing. No view yet (mirror still loading) answers
|
|
6044
|
+
* undefined so the caller keeps its current target.
|
|
6045
|
+
*/
|
|
6046
|
+
const resolveConfigFormsTarget = (forms) => {
|
|
6047
|
+
const namespaces = typeof forms.describe === "function" ? forms.describe()?.getSnapshot()?.view?.namespaces : void 0;
|
|
6048
|
+
if (namespaces === void 0) return void 0;
|
|
6049
|
+
const served = CONFIG_FORM_KEYS.find((key) => namespaces.some((row) => row.ns === key));
|
|
6050
|
+
return served === void 0 ? void 0 : forms.get(served);
|
|
6051
|
+
};
|
|
5694
6052
|
/** Required services: the slot registry, the locale dictionaries, the
|
|
5695
|
-
*
|
|
5696
|
-
*
|
|
5697
|
-
*
|
|
6053
|
+
* workspace navigation service (its native directory picker backs the card's
|
|
6054
|
+
* browse button), and the session controller (the stats page's Ctrl+click
|
|
6055
|
+
* session jump reads the list and opens the target). Configuration sources
|
|
6056
|
+
* (`configForms` in dsh 0.1.7+, `settingsScope` in pre-0.1.7) attach dynamically. */
|
|
5698
6057
|
const inject = [
|
|
5699
6058
|
"slots",
|
|
5700
6059
|
"locale",
|
|
5701
6060
|
"connection",
|
|
5702
6061
|
"remote",
|
|
5703
|
-
"settingsScope",
|
|
5704
6062
|
"uiWorkspace",
|
|
5705
|
-
"sessions"
|
|
6063
|
+
"sessions",
|
|
6064
|
+
"workspaces"
|
|
5706
6065
|
];
|
|
5707
6066
|
/**
|
|
5708
6067
|
* Register the dictionary pair, then the settings page and the plugin
|
|
@@ -5715,12 +6074,32 @@ window.__ModuleLoader__.load({
|
|
|
5715
6074
|
en
|
|
5716
6075
|
}), "token-usage: dictionaries");
|
|
5717
6076
|
const t = ctx.locale.bind(NS);
|
|
5718
|
-
const
|
|
5719
|
-
const
|
|
6077
|
+
const getSessions = () => ctx.get?.("sessions") ?? ctx.sessions;
|
|
6078
|
+
const getUiWorkspace = () => ctx.get?.("uiWorkspace") ?? ctx.uiWorkspace;
|
|
6079
|
+
const getWorkspaces = () => ctx.get?.("workspaces") ?? ctx.workspaces;
|
|
6080
|
+
const isSessionInController = (id) => {
|
|
6081
|
+
return (getSessions()?.list?.getSnapshot())?.byId?.[id] !== void 0;
|
|
6082
|
+
};
|
|
6083
|
+
const isWorkspaceAlive = (id) => {
|
|
6084
|
+
const ws = getWorkspaces()?.list?.getSnapshot();
|
|
6085
|
+
if (!ws || ws.phase === "pending") return true;
|
|
6086
|
+
const sid = id;
|
|
6087
|
+
return ws.items.some((item) => item.sessionIds.includes(sid));
|
|
6088
|
+
};
|
|
6089
|
+
const sessionListed = (id) => {
|
|
6090
|
+
return isSessionInController(id) && isWorkspaceAlive(id);
|
|
6091
|
+
};
|
|
5720
6092
|
const openSession = (id) => {
|
|
5721
|
-
if (!
|
|
5722
|
-
|
|
5723
|
-
|
|
6093
|
+
if (!isSessionInController(id)) return {
|
|
6094
|
+
ok: false,
|
|
6095
|
+
reason: "sessionNotFound"
|
|
6096
|
+
};
|
|
6097
|
+
if (!isWorkspaceAlive(id)) return {
|
|
6098
|
+
ok: false,
|
|
6099
|
+
reason: "workspaceDeleted"
|
|
6100
|
+
};
|
|
6101
|
+
getUiWorkspace()?.openSession(id);
|
|
6102
|
+
return { ok: true };
|
|
5724
6103
|
};
|
|
5725
6104
|
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
5726
6105
|
name: "settings.section",
|
|
@@ -5762,16 +6141,75 @@ window.__ModuleLoader__.load({
|
|
|
5762
6141
|
locale: NS,
|
|
5763
6142
|
inject: () => ({ modelDirectory })
|
|
5764
6143
|
}, QuotaButton));
|
|
5765
|
-
const
|
|
6144
|
+
const lookupCurrentTarget = () => {
|
|
6145
|
+
const configForms = ctx.get("configForms");
|
|
6146
|
+
if (configForms && typeof configForms.get === "function") {
|
|
6147
|
+
const byMirror = resolveConfigFormsTarget(configForms);
|
|
6148
|
+
if (byMirror !== void 0) return byMirror;
|
|
6149
|
+
}
|
|
6150
|
+
const settingsScope = ctx.get("settingsScope");
|
|
6151
|
+
if (settingsScope && typeof settingsScope.bind === "function") return settingsScope.bind({ namespace: TOKEN_USAGE_NS });
|
|
6152
|
+
};
|
|
6153
|
+
let activeTarget = lookupCurrentTarget() ?? createFallbackTarget();
|
|
6154
|
+
const targetListeners = /* @__PURE__ */ new Set();
|
|
6155
|
+
let unsubActive = activeTarget.subscribe(() => {
|
|
6156
|
+
for (const listener of targetListeners) listener();
|
|
6157
|
+
});
|
|
6158
|
+
const switchTarget = (next) => {
|
|
6159
|
+
if (next === activeTarget) return;
|
|
6160
|
+
unsubActive?.();
|
|
6161
|
+
activeTarget = next;
|
|
6162
|
+
unsubActive = activeTarget.subscribe(() => {
|
|
6163
|
+
for (const listener of targetListeners) listener();
|
|
6164
|
+
});
|
|
6165
|
+
for (const listener of targetListeners) listener();
|
|
6166
|
+
};
|
|
6167
|
+
ctx.inject(["configForms"], (configCtx) => {
|
|
6168
|
+
configCtx.effect(() => {
|
|
6169
|
+
const forms = configCtx.get("configForms");
|
|
6170
|
+
if (!forms || typeof forms.get !== "function") return () => {};
|
|
6171
|
+
const mirror = typeof forms.describe === "function" ? forms.describe() : void 0;
|
|
6172
|
+
const resolve = () => {
|
|
6173
|
+
const target = resolveConfigFormsTarget(forms);
|
|
6174
|
+
if (target !== void 0) switchTarget(target);
|
|
6175
|
+
};
|
|
6176
|
+
resolve();
|
|
6177
|
+
mirror?.ensure?.();
|
|
6178
|
+
const unsubscribe = mirror?.subscribe(() => {
|
|
6179
|
+
resolve();
|
|
6180
|
+
});
|
|
6181
|
+
return () => {
|
|
6182
|
+
unsubscribe?.();
|
|
6183
|
+
};
|
|
6184
|
+
}, "token-usage: configForms dynamic target");
|
|
6185
|
+
});
|
|
6186
|
+
ctx.inject(["settingsScope"], (scopeCtx) => {
|
|
6187
|
+
scopeCtx.effect(() => {
|
|
6188
|
+
const scopeService = scopeCtx.get("settingsScope");
|
|
6189
|
+
if (scopeService && typeof scopeService.bind === "function") switchTarget(scopeService.bind({ namespace: TOKEN_USAGE_NS }));
|
|
6190
|
+
return () => {};
|
|
6191
|
+
}, "token-usage: settingsScope dynamic target");
|
|
6192
|
+
});
|
|
6193
|
+
const form = new CardForm({
|
|
6194
|
+
getSnapshot: () => activeTarget.getSnapshot(),
|
|
6195
|
+
subscribe: (listener) => {
|
|
6196
|
+
targetListeners.add(listener);
|
|
6197
|
+
return () => {
|
|
6198
|
+
targetListeners.delete(listener);
|
|
6199
|
+
};
|
|
6200
|
+
},
|
|
6201
|
+
set: (field, value) => activeTarget.set(field, value),
|
|
6202
|
+
unset: (field) => activeTarget.unset(field)
|
|
6203
|
+
});
|
|
5766
6204
|
const store = form.bind();
|
|
5767
|
-
ctx.slots.inject("
|
|
5768
|
-
name: "
|
|
5769
|
-
key:
|
|
6205
|
+
ctx.slots.inject("plugins.bundle.config", () => ctx.slots.register({
|
|
6206
|
+
name: "plugins.bundle.config",
|
|
6207
|
+
key: "@laoyuehanni/dsh-token-usage",
|
|
5770
6208
|
locale: NS,
|
|
5771
6209
|
inject: () => ({
|
|
5772
6210
|
hooks: { tokenUsageCard: store },
|
|
5773
6211
|
...form.actions(),
|
|
5774
|
-
pickDirectory: () => ctx.uiWorkspace
|
|
6212
|
+
pickDirectory: () => ctx.get("uiWorkspace")?.pickDirectory?.() ?? Promise.resolve(null)
|
|
5775
6213
|
})
|
|
5776
6214
|
}, TokenUsageCard));
|
|
5777
6215
|
}
|