@cassius0924/dsh-usage-dashboard 0.3.0
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/LICENSE +21 -0
- package/README.md +190 -0
- package/cordis.patch.yml +10 -0
- package/lib/client.js +1607 -0
- package/lib/client.js.map +7 -0
- package/lib/index.js +433 -0
- package/lib/index.js.map +7 -0
- package/lib/types/client/api.d.ts +9 -0
- package/lib/types/client/cache.d.ts +22 -0
- package/lib/types/client/charts.d.ts +43 -0
- package/lib/types/client/context.d.ts +16 -0
- package/lib/types/client/dashboard.d.ts +12 -0
- package/lib/types/client/index.d.ts +15 -0
- package/lib/types/client/prefs.d.ts +14 -0
- package/lib/types/client/store.d.ts +10 -0
- package/lib/types/client/styles.d.ts +2 -0
- package/lib/types/client/widget.d.ts +9 -0
- package/lib/types/context.d.ts +63 -0
- package/lib/types/contract.d.ts +157 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/memo.d.ts +23 -0
- package/lib/types/pricing.d.ts +43 -0
- package/lib/types/trust-fence.d.ts +8 -0
- package/lib/types/usage.d.ts +12 -0
- package/lib/types/wire.d.ts +2 -0
- package/package.json +82 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,1607 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({ id: "@cassius0924/dsh-usage-dashboard", factory: (require) => { var module = { exports: {} }; var exports = module.exports;
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name2 in all)
|
|
9
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/client/index.tsx
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
apply: () => apply,
|
|
25
|
+
inject: () => inject,
|
|
26
|
+
name: () => name
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/client/dashboard.tsx
|
|
31
|
+
var import_react2 = require("react");
|
|
32
|
+
|
|
33
|
+
// src/client/cache.ts
|
|
34
|
+
var LS_VERSION = 1;
|
|
35
|
+
function loadPersisted(storageKey) {
|
|
36
|
+
if (typeof localStorage === "undefined") return null;
|
|
37
|
+
try {
|
|
38
|
+
const raw = localStorage.getItem(`${storageKey}:v${LS_VERSION}`);
|
|
39
|
+
if (raw === null) return null;
|
|
40
|
+
const parsed = JSON.parse(raw);
|
|
41
|
+
if (parsed.data === void 0 || typeof parsed.at !== "number") return null;
|
|
42
|
+
return { data: parsed.data, at: parsed.at };
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function persist(storageKey, hit) {
|
|
48
|
+
if (typeof localStorage === "undefined") return;
|
|
49
|
+
try {
|
|
50
|
+
localStorage.setItem(`${storageKey}:v${LS_VERSION}`, JSON.stringify(hit));
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function createCache(ttlMs, storageKey) {
|
|
55
|
+
let hit = storageKey === void 0 ? null : loadPersisted(storageKey);
|
|
56
|
+
return {
|
|
57
|
+
get: () => hit,
|
|
58
|
+
getFresh: () => hit !== null && Date.now() - hit.at < ttlMs ? hit.data : null,
|
|
59
|
+
put: (data) => {
|
|
60
|
+
hit = { data, at: Date.now() };
|
|
61
|
+
if (storageKey !== void 0) persist(storageKey, hit);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/client/api.ts
|
|
67
|
+
var BALANCE_TTL_MS = 6e4;
|
|
68
|
+
var USAGE_TTL_MS = 5 * 6e4;
|
|
69
|
+
async function getJson(path, cache) {
|
|
70
|
+
const res = await fetch(path, { headers: { accept: "application/json" }, cache });
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
return { ok: false, error: `HTTP ${res.status}` };
|
|
73
|
+
}
|
|
74
|
+
return res.json();
|
|
75
|
+
}
|
|
76
|
+
var balanceCache = createCache(BALANCE_TTL_MS, "dsh-usage-dashboard:balance");
|
|
77
|
+
var usageCache = createCache(USAGE_TTL_MS, "dsh-usage-dashboard:usage");
|
|
78
|
+
var getCachedBalance = () => balanceCache.get()?.data ?? null;
|
|
79
|
+
var getCachedUsage = () => usageCache.get()?.data ?? null;
|
|
80
|
+
var getCachedUsageAt = () => usageCache.get()?.at ?? null;
|
|
81
|
+
var usageListeners = /* @__PURE__ */ new Set();
|
|
82
|
+
var subscribeUsage = (fn) => {
|
|
83
|
+
usageListeners.add(fn);
|
|
84
|
+
return () => {
|
|
85
|
+
usageListeners.delete(fn);
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
async function fetchBalance(force = false) {
|
|
89
|
+
if (!force) {
|
|
90
|
+
const hit = balanceCache.getFresh();
|
|
91
|
+
if (hit !== null) return hit;
|
|
92
|
+
}
|
|
93
|
+
const suffix = force ? "?refresh=1" : "";
|
|
94
|
+
const res = await getJson(`/api/dsh-usage-dashboard/balance${suffix}`, force ? "no-store" : "default");
|
|
95
|
+
if (res.ok) balanceCache.put(res);
|
|
96
|
+
return res;
|
|
97
|
+
}
|
|
98
|
+
async function fetchUsage(force = false) {
|
|
99
|
+
if (!force) {
|
|
100
|
+
const hit = usageCache.getFresh();
|
|
101
|
+
if (hit !== null) return hit;
|
|
102
|
+
}
|
|
103
|
+
const suffix = force ? "?refresh=1" : "";
|
|
104
|
+
const res = await getJson(`/api/dsh-usage-dashboard/usage${suffix}`, force ? "no-store" : "default");
|
|
105
|
+
if (res.ok) {
|
|
106
|
+
usageCache.put(res);
|
|
107
|
+
for (const listener of [...usageListeners]) listener();
|
|
108
|
+
}
|
|
109
|
+
return res;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/client/charts.tsx
|
|
113
|
+
var import_react = require("react");
|
|
114
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
115
|
+
function useChartTip() {
|
|
116
|
+
const wrapRef = (0, import_react.useRef)(null);
|
|
117
|
+
const [tip, setTip] = (0, import_react.useState)(null);
|
|
118
|
+
const show = (e, text) => {
|
|
119
|
+
const wrap = wrapRef.current;
|
|
120
|
+
if (text === void 0 || text === "" || wrap === null) return;
|
|
121
|
+
const rect = wrap.getBoundingClientRect();
|
|
122
|
+
const x = Math.min(Math.max(e.clientX - rect.left, 70), Math.max(rect.width - 70, 70));
|
|
123
|
+
setTip({ x, y: e.clientY - rect.top, lines: text.split(" \xB7 ") });
|
|
124
|
+
};
|
|
125
|
+
return { wrapRef, tip, show, hide: () => setTip(null) };
|
|
126
|
+
}
|
|
127
|
+
function ChartTip(props) {
|
|
128
|
+
const { tip } = props;
|
|
129
|
+
if (tip === null) return null;
|
|
130
|
+
const [head, ...rows] = tip.lines;
|
|
131
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dq-tip", style: { left: `${tip.x}px`, top: `${tip.y}px` }, role: "tooltip", children: [
|
|
132
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-tip-head", children: head }),
|
|
133
|
+
rows.map((row, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-tip-row", children: row }, i))
|
|
134
|
+
] });
|
|
135
|
+
}
|
|
136
|
+
var MODEL_COLORS = ["#4176e6", "#2da44e", "#e16f24", "#8250df", "#bf8700", "#cf222e", "#1f883d", "#0969da"];
|
|
137
|
+
function Bars(props) {
|
|
138
|
+
const { data, height = 120, labelEvery = 1 } = props;
|
|
139
|
+
const { wrapRef, tip, show, hide } = useChartTip();
|
|
140
|
+
let max = 0;
|
|
141
|
+
for (const datum of data) if (datum.value > max) max = datum.value;
|
|
142
|
+
const scale = max > 0 ? max : 1;
|
|
143
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dq-chart-wrap", ref: wrapRef, onPointerLeave: hide, children: [
|
|
144
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-bars", style: { height: `${height + 18}px` }, children: data.map((datum, i) => {
|
|
145
|
+
const h = Math.max(1, Math.round(datum.value / scale * height));
|
|
146
|
+
const text = datum.title ?? `${datum.label}: ${datum.value.toLocaleString()}`;
|
|
147
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
148
|
+
"div",
|
|
149
|
+
{
|
|
150
|
+
className: "dq-bar-col",
|
|
151
|
+
"aria-label": text,
|
|
152
|
+
onPointerMove: (e) => show(e, text),
|
|
153
|
+
children: [
|
|
154
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-bar", style: { height: `${h}px` } }),
|
|
155
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-bar-label", style: { visibility: i % labelEvery === 0 ? "visible" : "hidden" }, children: datum.label })
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
i
|
|
159
|
+
);
|
|
160
|
+
}) }),
|
|
161
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChartTip, { tip })
|
|
162
|
+
] });
|
|
163
|
+
}
|
|
164
|
+
function GroupedBars(props) {
|
|
165
|
+
const { series, height = 120, labelEvery = 1 } = props;
|
|
166
|
+
const { wrapRef, tip, show, hide } = useChartTip();
|
|
167
|
+
const count = series.length > 0 ? series[0].bars.length : 0;
|
|
168
|
+
let max = 0;
|
|
169
|
+
for (const s of series) for (const datum of s.bars) if (datum.value > max) max = datum.value;
|
|
170
|
+
const scale = max > 0 ? max : 1;
|
|
171
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dq-chart-wrap", ref: wrapRef, onPointerLeave: hide, children: [
|
|
172
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-bars", style: { height: `${height + 18}px` }, children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dq-bar-col", children: [
|
|
173
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-bar-group", children: series.map((s) => {
|
|
174
|
+
const datum = s.bars[i];
|
|
175
|
+
const h = Math.max(1, Math.round(datum.value / scale * height));
|
|
176
|
+
const text = datum.title ?? `${s.key}: ${datum.value.toLocaleString()}`;
|
|
177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
178
|
+
"div",
|
|
179
|
+
{
|
|
180
|
+
className: "dq-bar",
|
|
181
|
+
style: { height: `${h}px`, background: s.color },
|
|
182
|
+
"aria-label": text,
|
|
183
|
+
onPointerMove: (e) => show(e, text)
|
|
184
|
+
},
|
|
185
|
+
s.key
|
|
186
|
+
);
|
|
187
|
+
}) }),
|
|
188
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-bar-label", style: { visibility: i % labelEvery === 0 ? "visible" : "hidden" }, children: series[0].bars[i].label })
|
|
189
|
+
] }, i)) }),
|
|
190
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChartTip, { tip })
|
|
191
|
+
] });
|
|
192
|
+
}
|
|
193
|
+
function heatColor(level) {
|
|
194
|
+
if (level <= 0) return "rgba(120,130,150,0.12)";
|
|
195
|
+
if (level === 1) return "rgba(65,118,230,0.25)";
|
|
196
|
+
if (level === 2) return "rgba(65,118,230,0.5)";
|
|
197
|
+
if (level === 3) return "rgba(65,118,230,0.75)";
|
|
198
|
+
return "rgba(65,118,230,1)";
|
|
199
|
+
}
|
|
200
|
+
var DOW_LABELS = ["", "\u4E00", "", "\u4E09", "", "\u4E94", ""];
|
|
201
|
+
function Heatmap(props) {
|
|
202
|
+
const { data } = props;
|
|
203
|
+
const { wrapRef, tip, show, hide } = useChartTip();
|
|
204
|
+
let max = 0;
|
|
205
|
+
for (const datum of data) if (datum.total > max) max = datum.total;
|
|
206
|
+
let firstDow = 0;
|
|
207
|
+
if (data.length > 0) {
|
|
208
|
+
const dt = /* @__PURE__ */ new Date(`${data[0].date}T00:00:00`);
|
|
209
|
+
firstDow = Number.isNaN(dt.getTime()) ? 0 : dt.getDay();
|
|
210
|
+
}
|
|
211
|
+
const cells = [];
|
|
212
|
+
for (let i = 0; i < firstDow; i++) cells.push(null);
|
|
213
|
+
for (const datum of data) cells.push(datum);
|
|
214
|
+
while (cells.length % 7 !== 0) cells.push(null);
|
|
215
|
+
const weeks = [];
|
|
216
|
+
for (let i = 0; i < cells.length; i += 7) weeks.push(cells.slice(i, i + 7));
|
|
217
|
+
let lastMonth = "";
|
|
218
|
+
const monthLabels = weeks.map((week) => {
|
|
219
|
+
const first = week.find((cell) => cell !== null);
|
|
220
|
+
if (first === void 0 || first === null) return "";
|
|
221
|
+
const month = first.date.slice(0, 7);
|
|
222
|
+
if (month === lastMonth) return "";
|
|
223
|
+
lastMonth = month;
|
|
224
|
+
return `${Number(first.date.slice(5, 7))}\u6708`;
|
|
225
|
+
});
|
|
226
|
+
const levelOf = (total) => {
|
|
227
|
+
if (total <= 0) return 0;
|
|
228
|
+
const r = max > 0 ? total / max : 0;
|
|
229
|
+
return r < 0.25 ? 1 : r < 0.5 ? 2 : r < 0.75 ? 3 : 4;
|
|
230
|
+
};
|
|
231
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dq-heat dq-chart-wrap", ref: wrapRef, onPointerLeave: hide, children: [
|
|
232
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dq-heat-grid", children: [
|
|
233
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-heat-dows", "aria-hidden": "true", children: DOW_LABELS.map((label, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-heat-dow", children: label }, i)) }),
|
|
234
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dq-heat-cols", children: [
|
|
235
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-heat-months", "aria-hidden": "true", children: monthLabels.map((label, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-heat-month", children: label }, i)) }),
|
|
236
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-heatmap", children: weeks.map((week, w) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-heat-week", children: week.map((datum, d) => {
|
|
237
|
+
if (datum === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dq-heat-cell dq-heat-cell--pad" }, d);
|
|
238
|
+
const text = `${datum.date} \xB7 ${datum.total.toLocaleString()} tokens \xB7 \xA5${datum.cost.toFixed(2)} \xB7 ${datum.calls} \u6B21\u8C03\u7528`;
|
|
239
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
240
|
+
"div",
|
|
241
|
+
{
|
|
242
|
+
className: "dq-heat-cell",
|
|
243
|
+
style: { background: heatColor(levelOf(datum.total)) },
|
|
244
|
+
"aria-label": text,
|
|
245
|
+
onPointerMove: (e) => show(e, text)
|
|
246
|
+
},
|
|
247
|
+
d
|
|
248
|
+
);
|
|
249
|
+
}) }, w)) })
|
|
250
|
+
] })
|
|
251
|
+
] }),
|
|
252
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChartTip, { tip }),
|
|
253
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dq-heat-scale", children: [
|
|
254
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "\u5C11" }),
|
|
255
|
+
[0, 1, 2, 3, 4].map((level) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dq-heat-key", style: { background: heatColor(level) } }, level)),
|
|
256
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "\u591A" })
|
|
257
|
+
] })
|
|
258
|
+
] });
|
|
259
|
+
}
|
|
260
|
+
var fmt = (v) => {
|
|
261
|
+
const n = Number(v);
|
|
262
|
+
if (!Number.isFinite(n)) return String(v);
|
|
263
|
+
return n.toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
264
|
+
};
|
|
265
|
+
var fmtInt = (v) => Math.round(Number(v) || 0).toLocaleString();
|
|
266
|
+
var fmtCompact = (v) => {
|
|
267
|
+
const n = Number(v) || 0;
|
|
268
|
+
if (n >= 1e8) return `${(n / 1e8).toFixed(1)}\u4EBF`;
|
|
269
|
+
if (n >= 1e4) return `${(n / 1e4).toFixed(1)}\u4E07`;
|
|
270
|
+
return Math.round(n).toLocaleString();
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/client/prefs.ts
|
|
274
|
+
var PREFIX = "dsh-usage-dashboard:pref:";
|
|
275
|
+
var VERSION = 1;
|
|
276
|
+
var keyOf = (key) => `${PREFIX}${key}:v${VERSION}`;
|
|
277
|
+
function loadPref(key, isValid, fallback) {
|
|
278
|
+
if (typeof localStorage === "undefined") return fallback;
|
|
279
|
+
try {
|
|
280
|
+
const raw = localStorage.getItem(keyOf(key));
|
|
281
|
+
if (raw === null) return fallback;
|
|
282
|
+
const parsed = JSON.parse(raw);
|
|
283
|
+
return isValid(parsed) ? parsed : fallback;
|
|
284
|
+
} catch {
|
|
285
|
+
return fallback;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function savePref(key, value) {
|
|
289
|
+
if (typeof localStorage === "undefined") return;
|
|
290
|
+
try {
|
|
291
|
+
localStorage.setItem(keyOf(key), JSON.stringify(value));
|
|
292
|
+
} catch {
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
var isBoolean = (value) => typeof value === "boolean";
|
|
296
|
+
|
|
297
|
+
// src/client/store.ts
|
|
298
|
+
function createStore(key, isValid, fallback) {
|
|
299
|
+
let current = loadPref(key, isValid, fallback);
|
|
300
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
301
|
+
return {
|
|
302
|
+
get: () => current,
|
|
303
|
+
set: (value) => {
|
|
304
|
+
current = value;
|
|
305
|
+
savePref(key, value);
|
|
306
|
+
for (const listener of [...listeners]) listener();
|
|
307
|
+
},
|
|
308
|
+
subscribe: (fn) => {
|
|
309
|
+
listeners.add(fn);
|
|
310
|
+
return () => {
|
|
311
|
+
listeners.delete(fn);
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
var isThreshold = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
317
|
+
var widgetVisibleStore = createStore("widget.visible", isBoolean, true);
|
|
318
|
+
var lowBalanceStore = createStore("alert.lowBalance", isThreshold, 10);
|
|
319
|
+
|
|
320
|
+
// src/client/dashboard.tsx
|
|
321
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
322
|
+
function Skel(props) {
|
|
323
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-skel", style: { width: `${props.w}px`, height: `${props.h}px` } });
|
|
324
|
+
}
|
|
325
|
+
function BalanceSkeleton() {
|
|
326
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-balance-grid", children: [
|
|
327
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
328
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 56, h: 11 }),
|
|
329
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 150, h: 22 })
|
|
330
|
+
] }),
|
|
331
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
332
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 28, h: 11 }),
|
|
333
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 48, h: 22 })
|
|
334
|
+
] })
|
|
335
|
+
] });
|
|
336
|
+
}
|
|
337
|
+
function UsageSkeleton() {
|
|
338
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
339
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-usage-totals", children: [44, 44, 62, 62].map((w, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
340
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w, h: 11 }),
|
|
341
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: w > 70 ? 84 : 56, h: 20 })
|
|
342
|
+
] }, i)) }),
|
|
343
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 140, h: 12 }),
|
|
344
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-skel-bars", children: Array.from({ length: 30 }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-skel dq-skel-bar", style: { height: `${18 + i * 37 % 82}px` } }, i)) })
|
|
345
|
+
] });
|
|
346
|
+
}
|
|
347
|
+
function Delta(props) {
|
|
348
|
+
const { current, previous, label } = props;
|
|
349
|
+
if (previous <= 0) {
|
|
350
|
+
if (current <= 0) return null;
|
|
351
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-delta dq-delta--new", title: `${label}\u6CA1\u6709\u7528\u91CF\uFF0C\u65E0\u4ECE\u5BF9\u6BD4`, children: "\u65E0\u5BF9\u6BD4" });
|
|
352
|
+
}
|
|
353
|
+
const percent = Math.round((current - previous) / previous * 100);
|
|
354
|
+
const title = `${label} \xA5${fmt(previous)}`;
|
|
355
|
+
if (percent === 0) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-delta dq-delta--flat", title, children: "\u6301\u5E73" });
|
|
356
|
+
const up = percent > 0;
|
|
357
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: `dq-delta ${up ? "dq-delta--up" : "dq-delta--down"}`, title, children: [
|
|
358
|
+
up ? "\u2191" : "\u2193",
|
|
359
|
+
Math.abs(percent),
|
|
360
|
+
"% ",
|
|
361
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-delta-label", children: label })
|
|
362
|
+
] });
|
|
363
|
+
}
|
|
364
|
+
function Period(props) {
|
|
365
|
+
const { period, previous, compare } = props;
|
|
366
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-period", children: [
|
|
367
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-period-head", children: [
|
|
368
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-period-label", children: props.label }),
|
|
369
|
+
previous !== void 0 && compare !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Delta, { current: period.cost, previous: previous.cost, label: compare })
|
|
370
|
+
] }),
|
|
371
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-period-cost", children: [
|
|
372
|
+
"\xA5 ",
|
|
373
|
+
fmt(period.cost)
|
|
374
|
+
] }),
|
|
375
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-period-sub", children: [
|
|
376
|
+
fmtCompact(period.total),
|
|
377
|
+
" tokens \xB7 ",
|
|
378
|
+
fmtInt(period.calls),
|
|
379
|
+
" \u6B21\u8C03\u7528"
|
|
380
|
+
] })
|
|
381
|
+
] });
|
|
382
|
+
}
|
|
383
|
+
var rate = (value) => `\xA5${value.toLocaleString(void 0, { maximumFractionDigits: 3 })}`;
|
|
384
|
+
function PricingNote(props) {
|
|
385
|
+
const { pricing } = props;
|
|
386
|
+
const split = pricing.splitActive;
|
|
387
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("details", { className: "dq-pricing", children: [
|
|
388
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("summary", { className: "dq-pricing-summary", children: [
|
|
389
|
+
"\u8BA1\u4EF7\u8BF4\u660E",
|
|
390
|
+
split && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: `dq-pricing-now${pricing.inPeakNow ? " dq-pricing-now--peak" : ""}`, children: [
|
|
391
|
+
"\u5F53\u524D ",
|
|
392
|
+
pricing.inPeakNow ? "\u9AD8\u5CF0\u65F6\u6BB5" : "\u95F2\u65F6"
|
|
393
|
+
] })
|
|
394
|
+
] }),
|
|
395
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-pricing-body", children: [
|
|
396
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("table", { className: "dq-pricing-table", children: [
|
|
397
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { children: [
|
|
398
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { children: "\u6A21\u578B" }),
|
|
399
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { children: split ? "\u65F6\u6BB5" : "\u5355\u4EF7" }),
|
|
400
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { children: "\u8F93\u5165\xB7\u7F13\u5B58\u547D\u4E2D" }),
|
|
401
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { children: "\u8F93\u5165\xB7\u672A\u547D\u4E2D" }),
|
|
402
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { children: "\u8F93\u51FA" })
|
|
403
|
+
] }) }),
|
|
404
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tbody", { children: pricing.tiers.map((tier) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react2.Fragment, { children: [
|
|
405
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { children: [
|
|
406
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { rowSpan: tier.offPeak !== null ? 2 : 1, children: tier.model }),
|
|
407
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { children: split ? "\u9AD8\u5CF0" : "\u56FA\u5B9A" }),
|
|
408
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { children: rate(tier.peak.cacheHit) }),
|
|
409
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { children: rate(tier.peak.input) }),
|
|
410
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { children: rate(tier.peak.output) })
|
|
411
|
+
] }),
|
|
412
|
+
tier.offPeak !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { children: [
|
|
413
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { children: "\u95F2\u65F6" }),
|
|
414
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { children: rate(tier.offPeak.cacheHit) }),
|
|
415
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { children: rate(tier.offPeak.input) }),
|
|
416
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { children: rate(tier.offPeak.output) })
|
|
417
|
+
] })
|
|
418
|
+
] }, tier.model)) })
|
|
419
|
+
] }),
|
|
420
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "dq-pricing-foot", children: [
|
|
421
|
+
"\u5355\u4F4D\uFF1A",
|
|
422
|
+
pricing.currency,
|
|
423
|
+
" / \u767E\u4E07 tokens\u3002",
|
|
424
|
+
split ? `\u9AD8\u5CF0\u65F6\u6BB5\u4E3A\u5317\u4EAC\u65F6\u95F4 ${pricing.peakWindows.join("\u3001")}\uFF0C\u5176\u4F59\u4E3A\u95F2\u65F6\uFF08\u4EF7\u683C\u51CF\u534A\uFF09\uFF1B${pricing.switchDate} \u4E4B\u524D\u7684\u7528\u91CF\u4ECD\u6309\u65E7\u4EF7\u4F30\u7B97\u3002` : `${pricing.switchDate} 00:00 \u8D77\u6539\u4E3A\u5CF0\u8C37\u5B9A\u4EF7\uFF08\u9AD8\u5CF0 ${pricing.peakWindows.join("\u3001")}\uFF0C\u95F2\u65F6\u4EF7\u683C\u51CF\u534A\uFF09\uFF0C\u5C4A\u65F6\u672C\u9875\u4F1A\u6309\u6BCF\u6761\u8BB0\u5F55\u7684\u65F6\u95F4\u81EA\u52A8\u5206\u6BB5\u8BA1\u4EF7\u3002`,
|
|
425
|
+
"\u672A\u77E5\u6A21\u578B\u6309 deepseek-v4-pro \u8BA1\u4EF7\u3002"
|
|
426
|
+
] })
|
|
427
|
+
] })
|
|
428
|
+
] });
|
|
429
|
+
}
|
|
430
|
+
function Stat(props) {
|
|
431
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
432
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-label", children: props.label }),
|
|
433
|
+
props.children
|
|
434
|
+
] });
|
|
435
|
+
}
|
|
436
|
+
function Link(props) {
|
|
437
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { className: "dq-link", href: props.href, target: "_blank", rel: "noreferrer", children: props.children });
|
|
438
|
+
}
|
|
439
|
+
var modelKeyOf = (m) => m.provider !== "" ? `${m.provider}/${m.model}` : m.model;
|
|
440
|
+
var modelNameOf = (m) => m.model !== "" ? m.model : "\u672A\u77E5\u6A21\u578B";
|
|
441
|
+
function CacheCard(props) {
|
|
442
|
+
const { totals } = props;
|
|
443
|
+
const prompt = totals.input + totals.cache;
|
|
444
|
+
if (prompt === 0) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709 prompt token \u53EF\u7EDF\u8BA1\u7F13\u5B58\u547D\u4E2D\u3002" });
|
|
445
|
+
const rate2 = totals.cache / prompt;
|
|
446
|
+
const wouldHaveCost = totals.cost + totals.cacheSavings;
|
|
447
|
+
const low = rate2 < 0.6;
|
|
448
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-cache", children: [
|
|
449
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-cache-figures", children: [
|
|
450
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
451
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-label", children: "\u7F13\u5B58\u547D\u4E2D\u7387" }),
|
|
452
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `dq-stat-value${low ? " dq-stat-value--warn" : " dq-stat-value--ok"}`, children: [
|
|
453
|
+
(rate2 * 100).toFixed(1),
|
|
454
|
+
"%"
|
|
455
|
+
] })
|
|
456
|
+
] }),
|
|
457
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
458
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-label", children: "\u5DF2\u8282\u7701\u8D39\u7528\uFF08\u4F30\u7B97\uFF09" }),
|
|
459
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat-value", children: [
|
|
460
|
+
"\xA5 ",
|
|
461
|
+
fmt(totals.cacheSavings)
|
|
462
|
+
] })
|
|
463
|
+
] }),
|
|
464
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
465
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-label", children: "\u82E5\u5168\u90E8\u672A\u547D\u4E2D" }),
|
|
466
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat-value dq-muted-value", children: [
|
|
467
|
+
"\xA5 ",
|
|
468
|
+
fmt(wouldHaveCost)
|
|
469
|
+
] })
|
|
470
|
+
] })
|
|
471
|
+
] }),
|
|
472
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-cache-track", role: "img", "aria-label": `\u7F13\u5B58\u547D\u4E2D ${(rate2 * 100).toFixed(1)}%\uFF0C\u672A\u547D\u4E2D ${((1 - rate2) * 100).toFixed(1)}%`, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-cache-fill", style: { width: `${rate2 * 100}%` } }) }),
|
|
473
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-cache-legend", children: [
|
|
474
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
475
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-legend-swatch dq-legend-swatch--hit" }),
|
|
476
|
+
"\u7F13\u5B58\u547D\u4E2D ",
|
|
477
|
+
fmtCompact(totals.cache)
|
|
478
|
+
] }),
|
|
479
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
480
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-legend-swatch dq-legend-swatch--miss" }),
|
|
481
|
+
"\u672A\u547D\u4E2D ",
|
|
482
|
+
fmtCompact(totals.input),
|
|
483
|
+
"\uFF08\u6309\u672A\u547D\u4E2D\u4EF7\u8BA1\u8D39\uFF09"
|
|
484
|
+
] })
|
|
485
|
+
] }),
|
|
486
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dq-cache-foot", children: low ? "\u547D\u4E2D\u7387\u504F\u4F4E\uFF1A\u9891\u7E41\u6539\u52A8 system prompt / \u5DE5\u5177\u5B9A\u4E49\u4F1A\u8BA9\u524D\u7F00\u7F13\u5B58\u5931\u6548\uFF0C\u628A\u7A33\u5B9A\u5185\u5BB9\u653E\u5728\u5BF9\u8BDD\u6700\u524D\u9762\u80FD\u63D0\u9AD8\u547D\u4E2D\u7387\u3002" : "\u524D\u7F00\u7F13\u5B58\u628A\u91CD\u590D\u7684 prompt \u524D\u7F00\u6309\u547D\u4E2D\u4EF7\u8BA1\u8D39\uFF0C\u662F\u8FD9\u4EFD\u8D26\u5355\u4E0A\u6700\u5927\u7684\u7701\u94B1\u6760\u6746\u3002" })
|
|
487
|
+
] });
|
|
488
|
+
}
|
|
489
|
+
function PeakCard(props) {
|
|
490
|
+
const { split, pricing, currentCost } = props;
|
|
491
|
+
const total = split.peak.total + split.offPeak.total;
|
|
492
|
+
if (total === 0) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709\u53EF\u6309\u65F6\u6BB5\u5F52\u7C7B\u7684\u7528\u91CF\u3002" });
|
|
493
|
+
const peakShare = split.peak.total / total;
|
|
494
|
+
const shiftSaving = split.peakEraCost - split.offPeakEraCost;
|
|
495
|
+
const increase = split.peakEraCost - currentCost;
|
|
496
|
+
const increasePercent = currentCost > 0 ? increase / currentCost * 100 : 0;
|
|
497
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-peak", children: [
|
|
498
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
499
|
+
"div",
|
|
500
|
+
{
|
|
501
|
+
className: "dq-peak-track",
|
|
502
|
+
role: "img",
|
|
503
|
+
"aria-label": `\u9AD8\u5CF0\u65F6\u6BB5 ${(peakShare * 100).toFixed(1)}%\uFF0C\u95F2\u65F6 ${((1 - peakShare) * 100).toFixed(1)}%`,
|
|
504
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-peak-fill", style: { width: `${peakShare * 100}%` } })
|
|
505
|
+
}
|
|
506
|
+
),
|
|
507
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-peak-legend", children: [
|
|
508
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
509
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-legend-swatch dq-legend-swatch--peak" }),
|
|
510
|
+
"\u9AD8\u5CF0 ",
|
|
511
|
+
(peakShare * 100).toFixed(1),
|
|
512
|
+
"% \xB7 ",
|
|
513
|
+
fmtCompact(split.peak.total),
|
|
514
|
+
" tokens \xB7 ",
|
|
515
|
+
fmtInt(split.peak.calls),
|
|
516
|
+
" \u6B21"
|
|
517
|
+
] }),
|
|
518
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
519
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-legend-swatch dq-legend-swatch--offpeak" }),
|
|
520
|
+
"\u95F2\u65F6 ",
|
|
521
|
+
((1 - peakShare) * 100).toFixed(1),
|
|
522
|
+
"% \xB7 ",
|
|
523
|
+
fmtCompact(split.offPeak.total),
|
|
524
|
+
" tokens \xB7 ",
|
|
525
|
+
fmtInt(split.offPeak.calls),
|
|
526
|
+
" \u6B21"
|
|
527
|
+
] })
|
|
528
|
+
] }),
|
|
529
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-peak-figures", children: [
|
|
530
|
+
!pricing.splitActive && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
531
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-label", children: "\u540C\u6837\u7528\u91CF\u5728\u65B0\u4EF7\u4E0B" }),
|
|
532
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat-value", children: [
|
|
533
|
+
"\xA5 ",
|
|
534
|
+
fmt(split.peakEraCost),
|
|
535
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dq-peak-delta", children: [
|
|
536
|
+
"\u8F83\u73B0\u4EF7 +",
|
|
537
|
+
increasePercent.toFixed(0),
|
|
538
|
+
"%"
|
|
539
|
+
] })
|
|
540
|
+
] })
|
|
541
|
+
] }),
|
|
542
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
543
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-label", children: "\u82E5\u9AD8\u5CF0\u7528\u91CF\u90FD\u632A\u5230\u95F2\u65F6" }),
|
|
544
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat-value", children: [
|
|
545
|
+
"\xA5 ",
|
|
546
|
+
fmt(split.offPeakEraCost),
|
|
547
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dq-peak-delta dq-peak-delta--save", children: [
|
|
548
|
+
"\u53EF\u7701 \xA5",
|
|
549
|
+
fmt(shiftSaving)
|
|
550
|
+
] })
|
|
551
|
+
] })
|
|
552
|
+
] })
|
|
553
|
+
] }),
|
|
554
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "dq-peak-foot", children: [
|
|
555
|
+
"\u9AD8\u5CF0\u65F6\u6BB5\u4E3A\u5317\u4EAC\u65F6\u95F4 ",
|
|
556
|
+
pricing.peakWindows.join("\u3001"),
|
|
557
|
+
"\uFF0C\u95F2\u65F6\u4EF7\u683C\u51CF\u534A\u3002",
|
|
558
|
+
pricing.splitActive ? "\u628A\u6279\u91CF\u3001\u53EF\u5EF6\u540E\u7684\u4EFB\u52A1\u653E\u5230\u95F2\u65F6\u8DD1\uFF0C\u540C\u6837\u7684 token \u53EA\u8981\u4E00\u534A\u7684\u94B1\u3002" : `\u65B0\u4EF7 ${pricing.switchDate} 00:00 \u751F\u6548\uFF1B\u4E0A\u9762\u4E24\u4E2A\u6570\u5B57\u662F\u6309\u4F60\u5DF2\u6709\u7684\u5168\u90E8\u7528\u91CF\u91CD\u7B97\u7684\u3002`
|
|
559
|
+
] })
|
|
560
|
+
] });
|
|
561
|
+
}
|
|
562
|
+
function agoText(ms) {
|
|
563
|
+
const minutes = Math.floor((Date.now() - ms) / 6e4);
|
|
564
|
+
if (minutes < 1) return "\u521A\u521A";
|
|
565
|
+
if (minutes < 60) return `${minutes} \u5206\u949F\u524D`;
|
|
566
|
+
const hours = Math.floor(minutes / 60);
|
|
567
|
+
if (hours < 24) return `${hours} \u5C0F\u65F6\u524D`;
|
|
568
|
+
return `${Math.floor(hours / 24)} \u5929\u524D`;
|
|
569
|
+
}
|
|
570
|
+
function SessionRanking(props) {
|
|
571
|
+
const { sessions, count, totalCost } = props;
|
|
572
|
+
if (sessions.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709\u4EA7\u751F\u8D39\u7528\u7684\u4F1A\u8BDD\u3002" });
|
|
573
|
+
const top = sessions[0].cost;
|
|
574
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
575
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ol", { className: "dq-sessions", children: sessions.map((s) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { className: "dq-session", children: [
|
|
576
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-session-head", children: [
|
|
577
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-session-title", title: `${s.title}
|
|
578
|
+
${s.id}`, children: s.title }),
|
|
579
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dq-session-cost", children: [
|
|
580
|
+
"\xA5 ",
|
|
581
|
+
fmt(s.cost)
|
|
582
|
+
] })
|
|
583
|
+
] }),
|
|
584
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-session-track", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-session-fill", style: { width: `${Math.max(s.cost / (top || 1) * 100, 1.5)}%` } }) }),
|
|
585
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-session-sub", children: [
|
|
586
|
+
fmtCompact(s.total),
|
|
587
|
+
" tokens \xB7 ",
|
|
588
|
+
fmtInt(s.calls),
|
|
589
|
+
" \u6B21\u8C03\u7528 \xB7 ",
|
|
590
|
+
agoText(s.lastActive),
|
|
591
|
+
totalCost > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
592
|
+
" \xB7 \u5360 ",
|
|
593
|
+
(s.cost / totalCost * 100).toFixed(1),
|
|
594
|
+
"%"
|
|
595
|
+
] })
|
|
596
|
+
] })
|
|
597
|
+
] }, s.id)) }),
|
|
598
|
+
count > sessions.length && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "dq-session-foot", children: [
|
|
599
|
+
"\u5171 ",
|
|
600
|
+
fmtInt(count),
|
|
601
|
+
" \u4E2A\u4F1A\u8BDD\u6709\u7528\u91CF\uFF0C\u4E0A\u9762\u662F\u6700\u8D35\u7684 ",
|
|
602
|
+
sessions.length,
|
|
603
|
+
" \u4E2A\u3002"
|
|
604
|
+
] })
|
|
605
|
+
] });
|
|
606
|
+
}
|
|
607
|
+
function ModelRanking(props) {
|
|
608
|
+
const { models, totalCost } = props;
|
|
609
|
+
if (models.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709\u53EF\u5F52\u7C7B\u7684\u6A21\u578B\u7528\u91CF\u3002" });
|
|
610
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-rank", children: models.map((m) => {
|
|
611
|
+
const key = modelKeyOf(m);
|
|
612
|
+
const share = totalCost > 0 ? m.cost / totalCost : 0;
|
|
613
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-rank-row", children: [
|
|
614
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-rank-head", children: [
|
|
615
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dq-rank-name", title: key, children: [
|
|
616
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-legend-swatch", style: { background: props.colorOf(key) } }),
|
|
617
|
+
modelNameOf(m)
|
|
618
|
+
] }),
|
|
619
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dq-rank-cost", children: [
|
|
620
|
+
"\xA5 ",
|
|
621
|
+
fmt(m.cost),
|
|
622
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dq-rank-share", children: [
|
|
623
|
+
(share * 100).toFixed(1),
|
|
624
|
+
"%"
|
|
625
|
+
] })
|
|
626
|
+
] })
|
|
627
|
+
] }),
|
|
628
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
629
|
+
"div",
|
|
630
|
+
{
|
|
631
|
+
className: "dq-rank-track",
|
|
632
|
+
role: "img",
|
|
633
|
+
"aria-label": `${modelNameOf(m)} \u5360\u603B\u8D39\u7528 ${(share * 100).toFixed(1)}%`,
|
|
634
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-rank-fill", style: { width: `${Math.max(share * 100, 1.5)}%`, background: props.colorOf(key) } })
|
|
635
|
+
}
|
|
636
|
+
),
|
|
637
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-rank-sub", children: [
|
|
638
|
+
fmtCompact(m.total),
|
|
639
|
+
" tokens \xB7 ",
|
|
640
|
+
fmtInt(m.calls),
|
|
641
|
+
" \u6B21\u8C03\u7528 \xB7 \u8F93\u5165 ",
|
|
642
|
+
fmtCompact(m.input),
|
|
643
|
+
" / \u8F93\u51FA ",
|
|
644
|
+
fmtCompact(m.output),
|
|
645
|
+
" / \u7F13\u5B58 ",
|
|
646
|
+
fmtCompact(m.cache)
|
|
647
|
+
] })
|
|
648
|
+
] }, key);
|
|
649
|
+
}) });
|
|
650
|
+
}
|
|
651
|
+
function ModelPicker(props) {
|
|
652
|
+
const { models } = props;
|
|
653
|
+
if (models.length === 0) return null;
|
|
654
|
+
const [open, setOpen] = (0, import_react2.useState)(false);
|
|
655
|
+
const rootRef = (0, import_react2.useRef)(null);
|
|
656
|
+
(0, import_react2.useEffect)(() => {
|
|
657
|
+
if (!open) return;
|
|
658
|
+
const onDown = (e) => {
|
|
659
|
+
if (rootRef.current !== null && !rootRef.current.contains(e.target)) setOpen(false);
|
|
660
|
+
};
|
|
661
|
+
document.addEventListener("mousedown", onDown);
|
|
662
|
+
return () => document.removeEventListener("mousedown", onDown);
|
|
663
|
+
}, [open]);
|
|
664
|
+
const toggle = (key) => {
|
|
665
|
+
props.onChange(
|
|
666
|
+
props.selected.includes(key) ? props.selected.filter((k) => k !== key) : [...props.selected, key]
|
|
667
|
+
);
|
|
668
|
+
};
|
|
669
|
+
const label = props.selected.length === 0 ? "\u5168\u90E8\u6A21\u578B" : `\u6A21\u578B \xD7${props.selected.length}`;
|
|
670
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-model-picker", ref: rootRef, children: [
|
|
671
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "dq-model-btn", onClick: () => setOpen(!open), children: label }),
|
|
672
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-model-menu", children: [
|
|
673
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "dq-model-item dq-model-item--all", children: [
|
|
674
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
675
|
+
"input",
|
|
676
|
+
{
|
|
677
|
+
type: "checkbox",
|
|
678
|
+
checked: props.selected.length === 0,
|
|
679
|
+
onChange: () => props.onChange([])
|
|
680
|
+
}
|
|
681
|
+
),
|
|
682
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "\u5168\u90E8\u6A21\u578B" })
|
|
683
|
+
] }),
|
|
684
|
+
models.map((m) => {
|
|
685
|
+
const key = modelKeyOf(m);
|
|
686
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "dq-model-item", children: [
|
|
687
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "checkbox", checked: props.selected.includes(key), onChange: () => toggle(key) }),
|
|
688
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-legend-swatch", style: { background: props.colorOf(key) } }),
|
|
689
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: modelNameOf(m) }),
|
|
690
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-model-tag", children: fmtCompact(m.total) })
|
|
691
|
+
] }, key);
|
|
692
|
+
})
|
|
693
|
+
] })
|
|
694
|
+
] });
|
|
695
|
+
}
|
|
696
|
+
function BalanceDashboard() {
|
|
697
|
+
const cachedBalance = getCachedBalance();
|
|
698
|
+
const cachedUsage = getCachedUsage();
|
|
699
|
+
const [balance, setBalance] = (0, import_react2.useState)(cachedBalance?.data ?? null);
|
|
700
|
+
const [usage, setUsage] = (0, import_react2.useState)(cachedUsage?.data ?? null);
|
|
701
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
702
|
+
const [notice, setNotice] = (0, import_react2.useState)(null);
|
|
703
|
+
const [loadingBalance, setLoadingBalance] = (0, import_react2.useState)(cachedBalance === null);
|
|
704
|
+
const [loadingUsage, setLoadingUsage] = (0, import_react2.useState)(cachedUsage === null);
|
|
705
|
+
const [refreshing, setRefreshing] = (0, import_react2.useState)(false);
|
|
706
|
+
const hadDataRef = (0, import_react2.useRef)(cachedBalance !== null || cachedUsage !== null);
|
|
707
|
+
const [widgetOn, setWidgetOn] = (0, import_react2.useState)(widgetVisibleStore.get());
|
|
708
|
+
const [lowBalance, setLowBalance] = (0, import_react2.useState)(lowBalanceStore.get());
|
|
709
|
+
const [barMode, setBarMode] = (0, import_react2.useState)("daily");
|
|
710
|
+
const [selectedModels, setSelectedModels] = (0, import_react2.useState)([]);
|
|
711
|
+
const errText = (err) => err?.message ?? String(err);
|
|
712
|
+
const load = async (force) => {
|
|
713
|
+
setError(null);
|
|
714
|
+
setNotice(null);
|
|
715
|
+
setRefreshing(true);
|
|
716
|
+
const balanceTask = fetchBalance(force).then((res) => {
|
|
717
|
+
if (res.ok && res.data !== void 0) {
|
|
718
|
+
setBalance(res.data);
|
|
719
|
+
hadDataRef.current = true;
|
|
720
|
+
return null;
|
|
721
|
+
}
|
|
722
|
+
return res.error ?? "\u4F59\u989D\u52A0\u8F7D\u5931\u8D25";
|
|
723
|
+
}, (err) => errText(err)).then((result) => {
|
|
724
|
+
setLoadingBalance(false);
|
|
725
|
+
return result;
|
|
726
|
+
});
|
|
727
|
+
const usageTask = fetchUsage(force).then((res) => {
|
|
728
|
+
if (res.ok && res.data !== void 0) {
|
|
729
|
+
setUsage(res.data);
|
|
730
|
+
hadDataRef.current = true;
|
|
731
|
+
return null;
|
|
732
|
+
}
|
|
733
|
+
return res.error ?? "\u7528\u91CF\u52A0\u8F7D\u5931\u8D25";
|
|
734
|
+
}, (err) => errText(err)).then((result) => {
|
|
735
|
+
setLoadingUsage(false);
|
|
736
|
+
return result;
|
|
737
|
+
});
|
|
738
|
+
const [balanceError, usageError] = await Promise.all([balanceTask, usageTask]);
|
|
739
|
+
setRefreshing(false);
|
|
740
|
+
if (balanceError !== null && usageError !== null) {
|
|
741
|
+
if (hadDataRef.current) setNotice(`\u5237\u65B0\u5931\u8D25\uFF0C\u6B63\u5728\u5C55\u793A\u7F13\u5B58\u6570\u636E\uFF08${balanceError}\uFF09`);
|
|
742
|
+
else setError(balanceError);
|
|
743
|
+
} else if (balanceError !== null) {
|
|
744
|
+
setNotice(`\u4F59\u989D\u5237\u65B0\u5931\u8D25\uFF0C\u6B63\u5728\u5C55\u793A\u7F13\u5B58\u4F59\u989D\uFF08${balanceError}\uFF09`);
|
|
745
|
+
} else if (usageError !== null) {
|
|
746
|
+
setNotice(`\u7528\u91CF\u5237\u65B0\u5931\u8D25\uFF0C\u6B63\u5728\u5C55\u793A\u7F13\u5B58\u7528\u91CF\uFF08${usageError}\uFF09`);
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
(0, import_react2.useEffect)(() => {
|
|
750
|
+
void load(false);
|
|
751
|
+
}, []);
|
|
752
|
+
const toggle = () => {
|
|
753
|
+
const next = !widgetOn;
|
|
754
|
+
setWidgetOn(next);
|
|
755
|
+
widgetVisibleStore.set(next);
|
|
756
|
+
};
|
|
757
|
+
const changeLowBalance = (value) => {
|
|
758
|
+
setLowBalance(value);
|
|
759
|
+
lowBalanceStore.set(value);
|
|
760
|
+
};
|
|
761
|
+
const primary = balance !== null && balance.balances.length > 0 ? balance.balances[0] : null;
|
|
762
|
+
const recentDays = (usage?.daily ?? []).slice(-7);
|
|
763
|
+
const avgDailyCost = recentDays.length > 0 ? recentDays.reduce((sum, d) => sum + d.cost, 0) / recentDays.length : 0;
|
|
764
|
+
const balanceValue = primary !== null ? Number(primary.total) : Number.NaN;
|
|
765
|
+
const balanceLow = lowBalance > 0 && Number.isFinite(balanceValue) && balanceValue < lowBalance;
|
|
766
|
+
const daysLeft = avgDailyCost > 0 && Number.isFinite(balanceValue) ? balanceValue / avgDailyCost : null;
|
|
767
|
+
const daysLeftText = daysLeft === null ? "\u2014" : daysLeft >= 365 ? "> 365 \u5929" : `${daysLeft < 10 ? daysLeft.toFixed(1) : Math.round(daysLeft)} \u5929`;
|
|
768
|
+
const runwayTitle = daysLeft === null ? `\u8FD1 ${recentDays.length || 7} \u5929\u6CA1\u6709\u7528\u91CF\uFF0C\u65E0\u6CD5\u4F30\u7B97` : `\u6309\u8FD1 ${recentDays.length} \u5929\u65E5\u5747 \xA5${fmt(avgDailyCost)} \u4F30\u7B97\uFF08\u542B\u65E0\u7528\u91CF\u7684\u65E5\u5B50\uFF1B\u4ECA\u5929\u5C1A\u672A\u8FC7\u5B8C\uFF09`;
|
|
769
|
+
const dailyBars = (usage?.daily ?? []).map((d) => ({
|
|
770
|
+
label: d.date.slice(8, 10),
|
|
771
|
+
value: d.total,
|
|
772
|
+
title: `${d.date} \xB7 ${fmtInt(d.total)} tokens \xB7 \xA5${fmt(d.cost)} \xB7 ${d.calls} \u6B21\u8C03\u7528`
|
|
773
|
+
}));
|
|
774
|
+
const hourlyBars = (usage?.hourly ?? []).map((h) => ({
|
|
775
|
+
label: String(h.hour),
|
|
776
|
+
value: h.total,
|
|
777
|
+
title: `${h.hour} \u70B9 \xB7 ${fmtInt(h.total)} tokens \xB7 ${h.calls} \u6B21\u8C03\u7528`
|
|
778
|
+
}));
|
|
779
|
+
const chartPeak = (barMode === "daily" ? dailyBars : hourlyBars).reduce((peak, bar) => bar.value > peak ? bar.value : peak, 0);
|
|
780
|
+
const modelList = [...usage?.models ?? []].sort((a, b) => b.cost - a.cost);
|
|
781
|
+
const availableModelKeys = new Set(modelList.map(modelKeyOf));
|
|
782
|
+
const effectiveSelection = selectedModels.filter((k) => availableModelKeys.has(k));
|
|
783
|
+
const colorOf = (key) => {
|
|
784
|
+
const index = modelList.findIndex((m) => modelKeyOf(m) === key);
|
|
785
|
+
return MODEL_COLORS[(index < 0 ? 0 : index) % MODEL_COLORS.length];
|
|
786
|
+
};
|
|
787
|
+
const modelCostTotal = modelList.reduce((sum, m) => sum + m.cost, 0);
|
|
788
|
+
const grouped = effectiveSelection.map((key) => {
|
|
789
|
+
const m = modelList.find((x) => modelKeyOf(x) === key);
|
|
790
|
+
const name2 = m === void 0 ? key : modelNameOf(m);
|
|
791
|
+
const color = colorOf(key);
|
|
792
|
+
if (barMode === "daily") {
|
|
793
|
+
return {
|
|
794
|
+
key,
|
|
795
|
+
name: name2,
|
|
796
|
+
color,
|
|
797
|
+
bars: (m?.daily ?? []).map((p, i) => ({
|
|
798
|
+
label: (usage?.daily ?? [])[i]?.date.slice(8, 10) ?? "",
|
|
799
|
+
value: p.total,
|
|
800
|
+
title: `${name2} \xB7 ${(usage?.daily ?? [])[i]?.date ?? ""} \xB7 ${fmtInt(p.total)} tokens \xB7 \xA5${fmt(p.cost)} \xB7 ${p.calls} \u6B21\u8C03\u7528`
|
|
801
|
+
}))
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
return {
|
|
805
|
+
key,
|
|
806
|
+
name: name2,
|
|
807
|
+
color,
|
|
808
|
+
bars: (m?.hourly ?? []).map((p, i) => ({
|
|
809
|
+
label: String(i),
|
|
810
|
+
value: p.total,
|
|
811
|
+
title: `${name2} \xB7 ${i} \u70B9 \xB7 ${fmtInt(p.total)} tokens \xB7 \xA5${fmt(p.cost)} \xB7 ${p.calls} \u6B21\u8C03\u7528`
|
|
812
|
+
}))
|
|
813
|
+
};
|
|
814
|
+
});
|
|
815
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-balance", children: [
|
|
816
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-status-row", children: [
|
|
817
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
818
|
+
(loadingBalance || loadingUsage) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-muted", children: "\u52A0\u8F7D\u4E2D\u2026" }),
|
|
819
|
+
!loadingBalance && !loadingUsage && refreshing && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-muted", children: "\u66F4\u65B0\u4E2D\u2026" }),
|
|
820
|
+
notice !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-warn", children: notice }),
|
|
821
|
+
error !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-error", children: error })
|
|
822
|
+
] }),
|
|
823
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
824
|
+
"button",
|
|
825
|
+
{
|
|
826
|
+
type: "button",
|
|
827
|
+
className: "dq-refresh-btn",
|
|
828
|
+
title: "\u5F3A\u5236\u5237\u65B0\uFF08\u7ED5\u8FC7\u7F13\u5B58\uFF09",
|
|
829
|
+
disabled: refreshing,
|
|
830
|
+
"aria-busy": refreshing,
|
|
831
|
+
onClick: () => {
|
|
832
|
+
void load(true);
|
|
833
|
+
},
|
|
834
|
+
children: [
|
|
835
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: `dq-refresh-icon${refreshing ? " dq-refresh-icon--spin" : ""}`, children: "\u21BB" }),
|
|
836
|
+
refreshing ? "\u5237\u65B0\u4E2D" : "\u5237\u65B0"
|
|
837
|
+
]
|
|
838
|
+
}
|
|
839
|
+
)
|
|
840
|
+
] }),
|
|
841
|
+
balanceLow && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-alert", role: "status", children: [
|
|
842
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-alert-icon", "aria-hidden": "true", children: "!" }),
|
|
843
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
844
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("strong", { children: [
|
|
845
|
+
"\u4F59\u989D ",
|
|
846
|
+
fmt(balanceValue),
|
|
847
|
+
" ",
|
|
848
|
+
primary?.currency,
|
|
849
|
+
" \u5DF2\u4F4E\u4E8E\u9884\u8B66\u7EBF ",
|
|
850
|
+
fmt(lowBalance)
|
|
851
|
+
] }),
|
|
852
|
+
daysLeft !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
853
|
+
"\uFF0C\u6309\u8FD1\u671F\u7528\u91CF\u4F30\u8BA1\u8FD8\u80FD\u6491 ",
|
|
854
|
+
daysLeftText
|
|
855
|
+
] }),
|
|
856
|
+
"\u3002",
|
|
857
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { className: "dq-alert-link", href: "https://platform.deepseek.com/top_up", target: "_blank", rel: "noreferrer", children: "\u53BB\u5145\u503C" })
|
|
858
|
+
] })
|
|
859
|
+
] }),
|
|
860
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-card", children: [
|
|
861
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-card-title", children: "\u8D26\u6237\u4F59\u989D" }),
|
|
862
|
+
primary !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-balance-grid", children: [
|
|
863
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
864
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-label", children: "\u5269\u4F59\u4F59\u989D" }),
|
|
865
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat-value dq-remaining", children: [
|
|
866
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
867
|
+
fmt(primary.total),
|
|
868
|
+
" ",
|
|
869
|
+
primary.currency
|
|
870
|
+
] }),
|
|
871
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-remaining-breakdown", children: [
|
|
872
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
873
|
+
"\u5145\u503C\u989D\u5EA6 ",
|
|
874
|
+
fmt(primary.toppedUp)
|
|
875
|
+
] }),
|
|
876
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dq-remaining-granted", children: [
|
|
877
|
+
"\u8D60\u9001\u989D\u5EA6 ",
|
|
878
|
+
fmt(primary.granted)
|
|
879
|
+
] })
|
|
880
|
+
] })
|
|
881
|
+
] })
|
|
882
|
+
] }),
|
|
883
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
884
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-label", children: "\u9884\u8BA1\u53EF\u7528" }),
|
|
885
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
886
|
+
"div",
|
|
887
|
+
{
|
|
888
|
+
className: `dq-stat-value dq-runway${daysLeft !== null && daysLeft < 3 ? " dq-stat-value--bad" : ""}`,
|
|
889
|
+
title: runwayTitle,
|
|
890
|
+
children: daysLeftText
|
|
891
|
+
}
|
|
892
|
+
)
|
|
893
|
+
] }),
|
|
894
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Stat, { label: "\u72B6\u6001", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: `dq-stat-value${balance?.isAvailable === false ? " dq-stat-value--bad" : " dq-stat-value--ok"}`, children: balance?.isAvailable === false ? "\u4E0D\u53EF\u7528" : "\u53EF\u7528" }) })
|
|
895
|
+
] }) : loadingBalance ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BalanceSkeleton, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8BFB\u4E0D\u5230\u4F59\u989D\u3002\u8BF7\u786E\u8BA4\u300C\u8BBE\u7F6E \u2192 \u6A21\u578B\u300D\u91CC\u5DF2\u586B DEEPSEEK_API_KEY\uFF0C\u7136\u540E\u70B9\u53F3\u4E0A\u89D2\u5237\u65B0\u3002" })
|
|
896
|
+
] }),
|
|
897
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-card", children: [
|
|
898
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-card-title", children: "\u6D88\u8017\u6982\u89C8\uFF08\u8D39\u7528\u4E3A\u4F30\u7B97\uFF09" }),
|
|
899
|
+
usage !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-period-grid", children: [
|
|
900
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Period, { label: "\u4ECA\u65E5", period: usage.summary.today, previous: usage.summary.yesterday, compare: "\u8F83\u6628\u65E5" }),
|
|
901
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Period, { label: "\u672C\u6708", period: usage.summary.month, previous: usage.summary.lastMonthToDate, compare: "\u8F83\u4E0A\u6708\u540C\u671F" }),
|
|
902
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
903
|
+
Period,
|
|
904
|
+
{
|
|
905
|
+
label: "\u7D2F\u8BA1",
|
|
906
|
+
period: { total: usage.totals.total, cost: usage.totals.cost, calls: usage.totals.calls }
|
|
907
|
+
}
|
|
908
|
+
)
|
|
909
|
+
] }) : loadingUsage ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-period-grid", children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-period", children: [
|
|
910
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 40, h: 11 }),
|
|
911
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 104, h: 24 }),
|
|
912
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 132, h: 11 })
|
|
913
|
+
] }, i)) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709\u53EF\u7EDF\u8BA1\u7684\u6D88\u8017\u3002" }),
|
|
914
|
+
usage !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PricingNote, { pricing: usage.pricing })
|
|
915
|
+
] }),
|
|
916
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-card", children: [
|
|
917
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-card-title", children: "DSH \u7528\u91CF\uFF08tokens\uFF09" }),
|
|
918
|
+
usage !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
919
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-usage-totals", children: [
|
|
920
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Stat, { label: "\u8F93\u5165", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-value", children: fmtCompact(usage.totals.input) }) }),
|
|
921
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Stat, { label: "\u8F93\u51FA", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-value", children: fmtCompact(usage.totals.output) }) }),
|
|
922
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Stat, { label: "\u7F13\u5B58\u547D\u4E2D", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-value", children: fmtCompact(usage.totals.cache) }) }),
|
|
923
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Stat, { label: "\u6A21\u578B\u8C03\u7528", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-stat-value", children: fmtInt(usage.totals.calls) }) })
|
|
924
|
+
] }),
|
|
925
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-chart-block-head", children: [
|
|
926
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-chart-title", children: [
|
|
927
|
+
barMode === "daily" ? "\u8FD1 30 \u5929 \xB7 \u9010\u5929\u7528\u91CF" : "\u6309\u5C0F\u65F6\u5206\u5E03\uFF080\u201323 \u70B9\uFF09",
|
|
928
|
+
chartPeak > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dq-chart-peak", children: [
|
|
929
|
+
"\u5CF0\u503C ",
|
|
930
|
+
fmtCompact(chartPeak),
|
|
931
|
+
" tokens"
|
|
932
|
+
] })
|
|
933
|
+
] }),
|
|
934
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-chart-controls", children: [
|
|
935
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ModelPicker, { models: modelList, selected: effectiveSelection, colorOf, onChange: setSelectedModels }),
|
|
936
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-chart-switch", role: "tablist", "aria-label": "\u5207\u6362\u56FE\u8868\u7EF4\u5EA6", children: [
|
|
937
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
938
|
+
"button",
|
|
939
|
+
{
|
|
940
|
+
type: "button",
|
|
941
|
+
role: "tab",
|
|
942
|
+
"aria-selected": barMode === "daily",
|
|
943
|
+
className: `dq-chart-switch-btn${barMode === "daily" ? " dq-chart-switch-btn--on" : ""}`,
|
|
944
|
+
onClick: () => setBarMode("daily"),
|
|
945
|
+
children: "\u9010\u5929"
|
|
946
|
+
}
|
|
947
|
+
),
|
|
948
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
949
|
+
"button",
|
|
950
|
+
{
|
|
951
|
+
type: "button",
|
|
952
|
+
role: "tab",
|
|
953
|
+
"aria-selected": barMode === "hourly",
|
|
954
|
+
className: `dq-chart-switch-btn${barMode === "hourly" ? " dq-chart-switch-btn--on" : ""}`,
|
|
955
|
+
onClick: () => setBarMode("hourly"),
|
|
956
|
+
children: "\u9010\u5C0F\u65F6"
|
|
957
|
+
}
|
|
958
|
+
)
|
|
959
|
+
] })
|
|
960
|
+
] })
|
|
961
|
+
] }),
|
|
962
|
+
grouped.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
963
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
964
|
+
GroupedBars,
|
|
965
|
+
{
|
|
966
|
+
series: grouped,
|
|
967
|
+
height: barMode === "daily" ? 120 : 100,
|
|
968
|
+
labelEvery: barMode === "daily" ? 5 : 3
|
|
969
|
+
}
|
|
970
|
+
),
|
|
971
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-legend", children: grouped.map((s) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dq-legend-item", children: [
|
|
972
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-legend-swatch", style: { background: s.color } }),
|
|
973
|
+
s.name
|
|
974
|
+
] }, s.key)) })
|
|
975
|
+
] }) : barMode === "daily" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Bars, { data: dailyBars, height: 120, labelEvery: 5 }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Bars, { data: hourlyBars, height: 100, labelEvery: 3 }),
|
|
976
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-chart-title", children: "\u8FD1 12 \u5468 \xB7 \u6BCF\u65E5\u7528\u91CF\u70ED\u529B\u56FE" }),
|
|
977
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Heatmap, { data: usage.heatmap })
|
|
978
|
+
] }) : loadingUsage ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UsageSkeleton, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709\u7528\u91CF\u8BB0\u5F55\u3002\u5728 DSH \u91CC\u8DD1\u4E00\u8F6E\u5BF9\u8BDD\uFF0C\u8FD9\u91CC\u4F1A\u51FA\u73B0\u9010\u5929 / \u9010\u5C0F\u65F6\u7EDF\u8BA1\u4E0E\u8D39\u7528\u4F30\u7B97\u3002" })
|
|
979
|
+
] }),
|
|
980
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-card", children: [
|
|
981
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-card-title", children: "\u9AD8\u5CF0 / \u95F2\u65F6\u5206\u5E03" }),
|
|
982
|
+
usage !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PeakCard, { split: usage.peakSplit, pricing: usage.pricing, currentCost: usage.totals.cost }) : loadingUsage ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
983
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-peak-track" }),
|
|
984
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-peak-figures", children: [
|
|
985
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 120, h: 11 }),
|
|
986
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 96, h: 20 })
|
|
987
|
+
] })
|
|
988
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709\u53EF\u6309\u65F6\u6BB5\u5F52\u7C7B\u7684\u7528\u91CF\u3002" })
|
|
989
|
+
] }),
|
|
990
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-card", children: [
|
|
991
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-card-title", children: "\u7F13\u5B58\u547D\u4E2D\u4E0E\u8282\u7701" }),
|
|
992
|
+
usage !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CacheCard, { totals: usage.totals }) : loadingUsage ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-cache-figures", children: [60, 96, 72].map((w, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-stat", children: [
|
|
993
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w, h: 11 }),
|
|
994
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 72, h: 20 })
|
|
995
|
+
] }, i)) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709 prompt token \u53EF\u7EDF\u8BA1\u7F13\u5B58\u547D\u4E2D\u3002" })
|
|
996
|
+
] }),
|
|
997
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-card", children: [
|
|
998
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-card-title", children: "\u6A21\u578B\u6210\u672C\u6392\u884C" }),
|
|
999
|
+
usage !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ModelRanking, { models: modelList, totalCost: modelCostTotal, colorOf }) : loadingUsage ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-rank", children: [0, 1].map((i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-rank-row", children: [
|
|
1000
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 148, h: 13 }),
|
|
1001
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-rank-track" }),
|
|
1002
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 230, h: 11 })
|
|
1003
|
+
] }, i)) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709\u53EF\u5F52\u7C7B\u7684\u6A21\u578B\u7528\u91CF\u3002" })
|
|
1004
|
+
] }),
|
|
1005
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-card", children: [
|
|
1006
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-card-title", children: "\u4F1A\u8BDD\u6210\u672C\u6392\u884C" }),
|
|
1007
|
+
usage !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SessionRanking, { sessions: usage.sessions, count: usage.sessionCount, totalCost: usage.totals.cost }) : loadingUsage ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-sessions", children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-session", children: [
|
|
1008
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 200, h: 13 }),
|
|
1009
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-session-track" }),
|
|
1010
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Skel, { w: 250, h: 11 })
|
|
1011
|
+
] }, i)) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-empty", children: "\u8FD8\u6CA1\u6709\u4EA7\u751F\u8D39\u7528\u7684\u4F1A\u8BDD\u3002" })
|
|
1012
|
+
] }),
|
|
1013
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-card", children: [
|
|
1014
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-card-title", children: "\u5B98\u65B9\u5E73\u53F0" }),
|
|
1015
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-links", children: [
|
|
1016
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Link, { href: "https://platform.deepseek.com/usage", children: "\u67E5\u770B\u989D\u5EA6 / \u7528\u91CF" }),
|
|
1017
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Link, { href: "https://platform.deepseek.com/api_keys", children: "\u751F\u6210 API Key" }),
|
|
1018
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Link, { href: "https://status.deepseek.com", children: "\u670D\u52A1\u72B6\u6001" })
|
|
1019
|
+
] })
|
|
1020
|
+
] }),
|
|
1021
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-card", children: [
|
|
1022
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dq-card-title", children: "\u8BBE\u7F6E" }),
|
|
1023
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "dq-toggle", children: [
|
|
1024
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "checkbox", checked: widgetOn, onChange: toggle }),
|
|
1025
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "\u663E\u793A\u53F3\u4E0B\u89D2\u60AC\u6D6E\u989D\u5EA6\u7A97\u53E3" })
|
|
1026
|
+
] }),
|
|
1027
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-setting", children: [
|
|
1028
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { className: "dq-setting-label", htmlFor: "dq-low-balance", children: "\u4F59\u989D\u9884\u8B66\u7EBF" }),
|
|
1029
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dq-setting-control", children: [
|
|
1030
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1031
|
+
"input",
|
|
1032
|
+
{
|
|
1033
|
+
id: "dq-low-balance",
|
|
1034
|
+
className: "dq-number",
|
|
1035
|
+
type: "number",
|
|
1036
|
+
min: 0,
|
|
1037
|
+
step: 1,
|
|
1038
|
+
value: lowBalance,
|
|
1039
|
+
onChange: (e) => changeLowBalance(Math.max(0, Number(e.target.value) || 0))
|
|
1040
|
+
}
|
|
1041
|
+
),
|
|
1042
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dq-setting-hint", children: lowBalance > 0 ? `\u4F59\u989D\u4F4E\u4E8E ${fmt(lowBalance)} ${primary?.currency ?? "CNY"} \u65F6\uFF0C\u8FD9\u91CC\u548C\u60AC\u6D6E\u7A97\u90FD\u4F1A\u8F6C\u4E3A\u8B66\u793A\u8272\u3002\u586B 0 \u5173\u95ED\u3002` : "\u5DF2\u5173\u95ED\u4F59\u989D\u9884\u8B66\u3002\u586B\u4E00\u4E2A\u5927\u4E8E 0 \u7684\u6570\u5F00\u542F\u3002" })
|
|
1043
|
+
] })
|
|
1044
|
+
] })
|
|
1045
|
+
] })
|
|
1046
|
+
] });
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// src/client/styles.ts
|
|
1050
|
+
var css = `
|
|
1051
|
+
.dsh-quota-root{position:absolute;right:16px;bottom:16px;z-index:2147483000;pointer-events:auto;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;font-size:13px;line-height:1.45;color:var(--dsw-alias-label-primary,#1f2328);transition:left .28s cubic-bezier(.22,1,.36,1),top .28s cubic-bezier(.22,1,.36,1)}
|
|
1052
|
+
.dsh-quota-root.dsh-quota-dragging{transition:none}
|
|
1053
|
+
.dsh-quota-card,.dsh-quota-card *{box-sizing:border-box}
|
|
1054
|
+
.dsh-quota-card{background:var(--dsw-alias-bg-overlay,#ffffff);border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.12));border-radius:12px;box-shadow:0 8px 24px rgba(0,0,0,.18);padding:12px 14px;min-width:208px;max-width:270px;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);cursor:grab;touch-action:none;user-select:none;-webkit-user-select:none}
|
|
1055
|
+
.dsh-quota-root.dsh-quota-dragging .dsh-quota-card{cursor:grabbing;box-shadow:0 12px 32px rgba(0,0,0,.28)}
|
|
1056
|
+
.dsh-quota-header{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:8px;min-width:0}
|
|
1057
|
+
.dsh-quota-title{font-weight:600;font-size:13px;color:var(--dsw-alias-label-primary,#1f2328);display:flex;align-items:center;gap:6px;min-width:0;overflow:hidden}
|
|
1058
|
+
.dsh-quota-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1059
|
+
.dsh-quota-grip{color:var(--dsw-alias-label-secondary,#59636e);opacity:.7;font-size:11px;letter-spacing:0;cursor:grab;flex:none}
|
|
1060
|
+
.dsh-quota-dot{width:8px;height:8px;border-radius:50%;background:var(--dsw-alias-state-success-primary,#2da44e);flex:none}
|
|
1061
|
+
.dsh-quota-dot--error{background:var(--dsw-alias-state-error-primary,#cf222e)}
|
|
1062
|
+
.dsh-quota-dot--warn{background:var(--dsw-alias-state-warning-primary,#bf8700)}
|
|
1063
|
+
.dsh-quota-total--low{color:var(--dsw-alias-state-warning-primary,#9a6700)!important}
|
|
1064
|
+
.dsh-quota-dot--idle{background:var(--dsw-alias-label-secondary,#59636e);opacity:.6}
|
|
1065
|
+
.dsh-quota-collapsed-total{font-weight:700;font-size:13px;color:var(--dsw-alias-brand-primary,#0969da);flex:none;font-variant-numeric:tabular-nums}
|
|
1066
|
+
.dsh-quota-actions{display:flex;gap:2px;flex:none}
|
|
1067
|
+
.dsh-quota-btn{border:none;background:transparent;cursor:pointer;color:var(--dsw-alias-label-secondary,#59636e);padding:3px 7px;border-radius:6px;font-size:13px;line-height:1}
|
|
1068
|
+
.dsh-quota-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.06));color:var(--dsw-alias-label-primary,#1f2328)}
|
|
1069
|
+
.dsh-quota-btn:active:not(:disabled){transform:scale(.92)}
|
|
1070
|
+
.dsh-quota-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#0969da);outline-offset:1px}
|
|
1071
|
+
.dsh-quota-btn:disabled{opacity:.5;cursor:default}
|
|
1072
|
+
.dsh-quota-body{color:var(--dsw-alias-label-secondary,#59636e)}
|
|
1073
|
+
.dsh-quota-remaining-label{font-size:11px;color:var(--dsw-alias-label-tertiary,#59636e);margin-bottom:2px}
|
|
1074
|
+
.dsh-quota-total{font-size:24px;font-weight:700;color:var(--dsw-alias-label-primary,#1f2328);letter-spacing:-.02em;font-variant-numeric:tabular-nums}
|
|
1075
|
+
.dsh-quota-currency{font-size:14px;font-weight:600;margin-left:3px;color:var(--dsw-alias-label-secondary,#59636e)}
|
|
1076
|
+
.dsh-quota-row{display:flex;justify-content:space-between;gap:12px;margin-top:6px;font-size:12px}
|
|
1077
|
+
.dsh-quota-label{color:var(--dsw-alias-label-secondary,#59636e)}
|
|
1078
|
+
.dsh-quota-value{color:var(--dsw-alias-label-primary,#1f2328);font-variant-numeric:tabular-nums}
|
|
1079
|
+
.dsh-quota-error{color:var(--dsw-alias-state-error-primary,#cf222e)}
|
|
1080
|
+
.dq-balance{display:flex;flex-direction:column;gap:16px;padding:20px 24px 48px;max-width:860px;margin:0 auto;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;font-size:13px;line-height:1.5;color:var(--dsw-alias-label-primary,#1f2328)}
|
|
1081
|
+
.dq-card{background:var(--dsw-alias-bg-layer-1,#ffffff);border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08));border-radius:12px;padding:16px}
|
|
1082
|
+
.dq-card-title{font-size:12px;font-weight:600;color:var(--dsw-alias-label-secondary,#59636e);margin:0 0 12px;letter-spacing:.02em}
|
|
1083
|
+
.dq-balance-grid{display:flex;flex-wrap:wrap;gap:12px 24px}
|
|
1084
|
+
.dq-stat{min-width:110px}
|
|
1085
|
+
.dq-stat-label{font-size:11px;color:var(--dsw-alias-label-tertiary,#59636e);margin-bottom:2px}
|
|
1086
|
+
.dq-stat-value{font-size:18px;font-weight:650;color:var(--dsw-alias-label-primary,#1f2328);font-variant-numeric:tabular-nums}
|
|
1087
|
+
.dq-stat-value--ok{color:var(--dsw-alias-state-success-primary,#2da44e)}
|
|
1088
|
+
.dq-stat-value--bad{color:var(--dsw-alias-state-error-primary,#cf222e)}
|
|
1089
|
+
.dq-runway{cursor:help;text-decoration:underline dotted var(--dsw-alias-border-l2,rgba(0,0,0,.25));text-underline-offset:4px}
|
|
1090
|
+
.dq-remaining{position:relative;cursor:help}
|
|
1091
|
+
.dq-remaining-breakdown{display:none;position:absolute;top:calc(100% + 6px);left:0;z-index:20;flex-direction:column;gap:4px;padding:8px 10px;background:var(--dsw-alias-bg-overlay,#ffffff);border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.12));border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,.15);white-space:nowrap;font-size:12px;font-weight:500;color:var(--dsw-alias-label-primary,#1f2328)}
|
|
1092
|
+
.dq-remaining:hover .dq-remaining-breakdown{display:flex}
|
|
1093
|
+
.dq-remaining-granted{color:var(--dsw-alias-label-tertiary,#59636e);font-weight:400;font-size:11px}
|
|
1094
|
+
.dq-period-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}
|
|
1095
|
+
@media (max-width:620px){.dq-period-grid{grid-template-columns:1fr}}
|
|
1096
|
+
.dq-period{background:var(--dsw-alias-bg-layer-2,rgba(120,130,150,.06));border-radius:10px;padding:12px 14px;min-width:0}
|
|
1097
|
+
.dq-period-head{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:4px}
|
|
1098
|
+
.dq-period-label{font-size:11px;color:var(--dsw-alias-label-tertiary,#59636e)}
|
|
1099
|
+
.dq-period-cost{font-size:22px;font-weight:680;letter-spacing:-.01em;color:var(--dsw-alias-label-primary,#1f2328);font-variant-numeric:tabular-nums;line-height:1.25}
|
|
1100
|
+
.dq-period-sub{font-size:11.5px;color:var(--dsw-alias-label-secondary,#59636e);margin-top:2px;font-variant-numeric:tabular-nums;line-height:1.45}
|
|
1101
|
+
.dq-delta{display:inline-flex;align-items:center;gap:3px;font-size:11px;font-weight:600;padding:1px 6px;border-radius:999px;white-space:nowrap;cursor:help;font-variant-numeric:tabular-nums}
|
|
1102
|
+
.dq-delta--up{color:var(--dsw-alias-state-warning-primary,#9a6700);background:rgba(191,135,0,.14)}
|
|
1103
|
+
.dq-delta--down{color:var(--dsw-alias-state-success-primary,#1a7f37);background:rgba(45,164,78,.14)}
|
|
1104
|
+
.dq-delta--flat,.dq-delta--new{color:var(--dsw-alias-label-tertiary,#59636e);background:rgba(120,130,150,.14);font-weight:500}
|
|
1105
|
+
.dq-delta-label{font-weight:400;opacity:.8}
|
|
1106
|
+
.dq-pricing{margin-top:12px;border-top:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08));padding-top:10px}
|
|
1107
|
+
.dq-pricing-summary{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--dsw-alias-label-secondary,#59636e);cursor:pointer;list-style:none;width:fit-content;border-radius:6px;padding:2px 4px;margin-left:-4px}
|
|
1108
|
+
.dq-pricing-summary::-webkit-details-marker{display:none}
|
|
1109
|
+
.dq-pricing-summary::before{content:"\u25B8";display:inline-block;font-size:10px;opacity:.7;transition:transform .15s ease}
|
|
1110
|
+
.dq-pricing[open] .dq-pricing-summary::before{transform:rotate(90deg)}
|
|
1111
|
+
.dq-pricing-summary:hover{color:var(--dsw-alias-label-primary,#1f2328)}
|
|
1112
|
+
.dq-pricing-summary:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#0969da);outline-offset:2px}
|
|
1113
|
+
.dq-pricing-now{font-size:11px;font-weight:600;padding:1px 7px;border-radius:999px;color:var(--dsw-alias-label-tertiary,#59636e);background:rgba(120,130,150,.14)}
|
|
1114
|
+
.dq-pricing-now--peak{color:var(--dsw-alias-state-warning-primary,#9a6700);background:rgba(191,135,0,.14)}
|
|
1115
|
+
.dq-pricing-body{margin-top:10px;overflow-x:auto}
|
|
1116
|
+
.dq-pricing-table{border-collapse:collapse;font-size:11.5px;font-variant-numeric:tabular-nums;min-width:100%}
|
|
1117
|
+
.dq-pricing-table th{text-align:left;font-weight:500;color:var(--dsw-alias-label-tertiary,#59636e);padding:4px 12px 4px 0;white-space:nowrap;border-bottom:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08))}
|
|
1118
|
+
.dq-pricing-table td{padding:4px 12px 4px 0;color:var(--dsw-alias-label-primary,#1f2328);white-space:nowrap;vertical-align:top}
|
|
1119
|
+
.dq-pricing-table tbody tr+tr td{border-top:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.05))}
|
|
1120
|
+
.dq-pricing-foot{margin:8px 0 0;font-size:11.5px;line-height:1.6;color:var(--dsw-alias-label-secondary,#59636e)}
|
|
1121
|
+
.dq-peak-track{height:8px;border-radius:999px;background:var(--dsw-alias-state-success-primary,#2da44e);opacity:.85;overflow:hidden}
|
|
1122
|
+
.dq-peak-fill{height:100%;border-radius:999px;background:var(--dsw-alias-state-warning-primary,#bf8700);transition:width .35s cubic-bezier(.22,1,.36,1)}
|
|
1123
|
+
.dq-peak-legend{display:flex;flex-wrap:wrap;gap:6px 20px;margin-top:8px;font-size:11.5px;color:var(--dsw-alias-label-secondary,#59636e);font-variant-numeric:tabular-nums}
|
|
1124
|
+
.dq-peak-legend span{display:inline-flex;align-items:center;gap:6px}
|
|
1125
|
+
.dq-legend-swatch--peak{background:var(--dsw-alias-state-warning-primary,#bf8700)}
|
|
1126
|
+
.dq-legend-swatch--offpeak{background:var(--dsw-alias-state-success-primary,#2da44e);opacity:.85}
|
|
1127
|
+
.dq-peak-figures{display:flex;flex-wrap:wrap;gap:12px 32px;margin-top:14px}
|
|
1128
|
+
.dq-peak-delta{font-size:11px;font-weight:500;margin-left:8px;color:var(--dsw-alias-state-warning-primary,#9a6700)}
|
|
1129
|
+
.dq-peak-delta--save{color:var(--dsw-alias-state-success-primary,#1a7f37)}
|
|
1130
|
+
.dq-peak-foot{margin:10px 0 0;font-size:11.5px;line-height:1.6;color:var(--dsw-alias-label-secondary,#59636e)}
|
|
1131
|
+
.dq-cache-figures{display:flex;flex-wrap:wrap;gap:12px 32px;margin-bottom:12px}
|
|
1132
|
+
.dq-muted-value{color:var(--dsw-alias-label-secondary,#59636e)!important;font-weight:550}
|
|
1133
|
+
.dq-stat-value--warn{color:var(--dsw-alias-state-warning-primary,#9a6700)}
|
|
1134
|
+
.dq-cache-track{height:8px;border-radius:999px;background:var(--dsw-alias-state-warning-primary,#bf8700);overflow:hidden}
|
|
1135
|
+
.dq-cache-fill{height:100%;border-radius:999px;background:var(--dsw-alias-state-success-primary,#2da44e);transition:width .35s cubic-bezier(.22,1,.36,1)}
|
|
1136
|
+
.dq-cache-legend{display:flex;flex-wrap:wrap;gap:6px 18px;margin-top:8px;font-size:11.5px;color:var(--dsw-alias-label-secondary,#59636e);font-variant-numeric:tabular-nums}
|
|
1137
|
+
.dq-cache-legend span{display:inline-flex;align-items:center;gap:6px}
|
|
1138
|
+
.dq-legend-swatch--hit{background:var(--dsw-alias-state-success-primary,#2da44e)}
|
|
1139
|
+
.dq-legend-swatch--miss{background:var(--dsw-alias-state-warning-primary,#bf8700)}
|
|
1140
|
+
.dq-cache-foot{margin:10px 0 0;font-size:11.5px;line-height:1.6;color:var(--dsw-alias-label-secondary,#59636e)}
|
|
1141
|
+
.dq-sessions{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:14px}
|
|
1142
|
+
.dq-session{display:flex;flex-direction:column;gap:5px;min-width:0}
|
|
1143
|
+
.dq-session-head{display:flex;align-items:baseline;justify-content:space-between;gap:12px}
|
|
1144
|
+
.dq-session-title{font-size:13px;font-weight:550;color:var(--dsw-alias-label-primary,#1f2328);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1145
|
+
.dq-session-cost{font-size:14px;font-weight:650;color:var(--dsw-alias-label-primary,#1f2328);font-variant-numeric:tabular-nums;flex:none}
|
|
1146
|
+
.dq-session-track{height:6px;border-radius:999px;background:var(--dsw-alias-bg-layer-2,rgba(120,130,150,.12));overflow:hidden}
|
|
1147
|
+
.dq-session-fill{height:100%;border-radius:999px;background:var(--dsw-alias-state-business-primary,#4176e6);transition:width .35s cubic-bezier(.22,1,.36,1)}
|
|
1148
|
+
.dq-session-sub{font-size:11.5px;color:var(--dsw-alias-label-secondary,#59636e);font-variant-numeric:tabular-nums;line-height:1.5}
|
|
1149
|
+
.dq-session-foot{margin:12px 0 0;font-size:11.5px;color:var(--dsw-alias-label-tertiary,#59636e)}
|
|
1150
|
+
.dq-rank{display:flex;flex-direction:column;gap:14px}
|
|
1151
|
+
.dq-rank-row{display:flex;flex-direction:column;gap:5px;min-width:0}
|
|
1152
|
+
.dq-rank-head{display:flex;align-items:baseline;justify-content:space-between;gap:12px}
|
|
1153
|
+
.dq-rank-name{display:inline-flex;align-items:center;gap:7px;font-size:13px;font-weight:550;color:var(--dsw-alias-label-primary,#1f2328);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1154
|
+
.dq-rank-cost{display:inline-flex;align-items:baseline;gap:8px;font-size:14px;font-weight:650;color:var(--dsw-alias-label-primary,#1f2328);font-variant-numeric:tabular-nums;flex:none}
|
|
1155
|
+
.dq-rank-share{font-size:11px;font-weight:500;color:var(--dsw-alias-label-tertiary,#59636e);min-width:30px;text-align:right}
|
|
1156
|
+
.dq-rank-track{height:6px;border-radius:999px;background:var(--dsw-alias-bg-layer-2,rgba(120,130,150,.12));overflow:hidden}
|
|
1157
|
+
.dq-rank-fill{height:100%;border-radius:999px;transition:width .35s cubic-bezier(.22,1,.36,1)}
|
|
1158
|
+
.dq-rank-sub{font-size:11.5px;color:var(--dsw-alias-label-secondary,#59636e);font-variant-numeric:tabular-nums;line-height:1.5}
|
|
1159
|
+
.dq-alert{display:flex;align-items:flex-start;gap:10px;padding:12px 14px;border-radius:10px;font-size:12.5px;line-height:1.6;color:var(--dsw-alias-state-warning-primary,#7a5200);background:rgba(191,135,0,.12);border:1px solid rgba(191,135,0,.35)}
|
|
1160
|
+
.dq-alert-icon{flex:none;width:18px;height:18px;border-radius:50%;background:var(--dsw-alias-state-warning-primary,#bf8700);color:#fff;font-weight:700;font-size:12px;line-height:18px;text-align:center}
|
|
1161
|
+
.dq-alert strong{font-weight:650}
|
|
1162
|
+
.dq-alert-link{margin-left:8px;color:inherit;text-decoration:underline;text-underline-offset:2px;white-space:nowrap}
|
|
1163
|
+
.dq-setting{display:flex;align-items:flex-start;gap:12px;margin-top:14px;padding-top:14px;border-top:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08))}
|
|
1164
|
+
.dq-setting-label{font-size:13px;color:var(--dsw-alias-label-primary,#1f2328);padding-top:6px;flex:none}
|
|
1165
|
+
.dq-setting-control{display:flex;align-items:center;gap:10px;flex-wrap:wrap;min-width:0}
|
|
1166
|
+
.dq-setting-hint{font-size:11.5px;color:var(--dsw-alias-label-secondary,#59636e);line-height:1.5}
|
|
1167
|
+
.dq-number{width:82px;padding:5px 8px;font-size:13px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.16));background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#1f2328);font-variant-numeric:tabular-nums}
|
|
1168
|
+
.dq-number:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#0969da);outline-offset:1px;border-color:transparent}
|
|
1169
|
+
.dq-links{display:flex;flex-wrap:wrap;gap:8px}
|
|
1170
|
+
.dq-link{display:inline-flex;align-items:center;gap:6px;padding:7px 12px;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));border-radius:8px;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-state-business-primary,#0969da);text-decoration:none;font-size:13px;font-weight:500;cursor:pointer}
|
|
1171
|
+
.dq-link:hover{border-color:var(--dsw-alias-state-business-primary,#0969da);background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.04))}
|
|
1172
|
+
.dq-toggle{display:flex;align-items:center;gap:10px;cursor:pointer;font-size:13px}
|
|
1173
|
+
.dq-toggle input{width:16px;height:16px;accent-color:var(--dsw-alias-state-business-primary,#0969da);cursor:pointer}
|
|
1174
|
+
.dq-toggle input:focus-visible,.dq-model-item input:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#0969da);outline-offset:2px}
|
|
1175
|
+
.dq-link:focus-visible,.dq-model-btn:focus-visible,.dq-chart-switch-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#0969da);outline-offset:2px}
|
|
1176
|
+
.dq-usage-totals{display:flex;flex-wrap:wrap;gap:12px 24px;margin-bottom:16px}
|
|
1177
|
+
.dq-chart-peak{margin-left:10px;font-size:11px;font-weight:400;color:var(--dsw-alias-label-tertiary,#59636e);font-variant-numeric:tabular-nums}
|
|
1178
|
+
.dq-chart-title{font-size:12px;font-weight:600;color:var(--dsw-alias-label-secondary,#59636e);margin:18px 0 8px}
|
|
1179
|
+
.dq-chart-title:first-of-type{margin-top:0}
|
|
1180
|
+
.dq-chart-block-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:18px 0 8px}
|
|
1181
|
+
.dq-chart-block-head .dq-chart-title{margin:0}
|
|
1182
|
+
.dq-chart-controls{display:flex;align-items:center;gap:8px;flex:none}
|
|
1183
|
+
.dq-model-picker{position:relative}
|
|
1184
|
+
.dq-model-btn{border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-secondary,#59636e);border-radius:8px;padding:4px 10px;font-size:12px;cursor:pointer;display:inline-flex;align-items:center;gap:6px}
|
|
1185
|
+
.dq-model-btn:hover{border-color:var(--dsw-alias-state-business-primary,#0969da);color:var(--dsw-alias-state-business-primary,#0969da)}
|
|
1186
|
+
.dq-model-btn::after{content:"\u25BE";font-size:10px;opacity:.7}
|
|
1187
|
+
.dq-model-menu{position:absolute;right:0;top:calc(100% + 6px);z-index:30;min-width:190px;max-height:280px;overflow-y:auto;background:var(--dsw-alias-bg-overlay,#fff);border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.12));border-radius:10px;box-shadow:0 8px 24px rgba(0,0,0,.16);padding:6px;display:flex;flex-direction:column;gap:2px}
|
|
1188
|
+
.dq-model-item{display:flex;align-items:center;gap:8px;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;color:var(--dsw-alias-label-primary,#1f2328)}
|
|
1189
|
+
.dq-model-item:hover{background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.06))}
|
|
1190
|
+
.dq-model-item input{width:14px;height:14px;accent-color:var(--dsw-alias-state-business-primary,#0969da);cursor:pointer;flex:none}
|
|
1191
|
+
.dq-model-item span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1192
|
+
.dq-model-item--all{border-bottom:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08));padding-bottom:8px;margin-bottom:2px;border-radius:6px}
|
|
1193
|
+
.dq-model-tag{color:var(--dsw-alias-label-tertiary,#59636e);font-size:11px;flex:none}
|
|
1194
|
+
.dq-bar-group{display:flex;align-items:flex-end;gap:2px;height:100%;width:100%}
|
|
1195
|
+
.dq-bar-group .dq-bar{flex:1 1 0;min-width:0}
|
|
1196
|
+
.dq-legend{display:flex;flex-wrap:wrap;gap:6px 14px;margin-top:8px;font-size:12px;color:var(--dsw-alias-label-secondary,#59636e)}
|
|
1197
|
+
.dq-legend-item{display:inline-flex;align-items:center;gap:6px}
|
|
1198
|
+
.dq-legend-swatch{width:10px;height:10px;border-radius:3px;flex:none}
|
|
1199
|
+
.dq-chart-switch{display:inline-flex;align-items:center;gap:2px;padding:2px;background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.06));border-radius:999px;flex:none}
|
|
1200
|
+
.dq-chart-switch-btn{border:none;background:transparent;color:var(--dsw-alias-label-secondary,#59636e);font-size:12px;line-height:1;padding:5px 12px;border-radius:999px;cursor:pointer;transition:background .15s ease,color .15s ease}
|
|
1201
|
+
.dq-chart-switch-btn:hover{color:var(--dsw-alias-label-primary,#1f2328)}
|
|
1202
|
+
.dq-chart-switch-btn--on{background:var(--dsw-alias-bg-overlay,#fff);color:var(--dsw-alias-label-primary,#1f2328);box-shadow:0 1px 3px rgba(0,0,0,.14)}
|
|
1203
|
+
.dq-chart-wrap{position:relative}
|
|
1204
|
+
.dq-tip{position:absolute;transform:translate(-50%,14px);z-index:40;pointer-events:none;background:var(--dsw-alias-bg-inverse,#1f2328);color:var(--dsw-alias-label-inverse,#fff);border-radius:8px;padding:7px 10px;font-size:11.5px;line-height:1.55;white-space:nowrap;box-shadow:0 6px 20px rgba(0,0,0,.28);font-variant-numeric:tabular-nums}
|
|
1205
|
+
.dq-tip-head{font-weight:650;margin-bottom:2px}
|
|
1206
|
+
.dq-tip-row{opacity:.85}
|
|
1207
|
+
.dq-bars{display:flex;align-items:flex-end;gap:2px;width:100%}
|
|
1208
|
+
.dq-bar-col{flex:1 1 0;min-width:0;display:flex;flex-direction:column;justify-content:flex-end;align-items:stretch}
|
|
1209
|
+
.dq-bar{background:var(--dsw-alias-state-business-primary,#4176e6);border-radius:2px 2px 0 0;min-height:1px;transition:filter .12s ease}
|
|
1210
|
+
.dq-bar-col{cursor:default}
|
|
1211
|
+
.dq-bar-col:hover .dq-bar{filter:brightness(1.18) saturate(1.1)}
|
|
1212
|
+
.dq-heat-cell:not(.dq-heat-cell--pad):hover{outline:1.5px solid var(--dsw-alias-label-primary,#1f2328);outline-offset:1px}
|
|
1213
|
+
.dq-bar-label{font-size:9px;color:var(--dsw-alias-label-tertiary,#59636e);text-align:center;margin-top:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1214
|
+
.dq-heat{display:flex;flex-direction:column;gap:8px;max-width:100%}
|
|
1215
|
+
.dq-heat-grid{display:flex;gap:6px;overflow-x:auto;padding-bottom:2px}
|
|
1216
|
+
.dq-heat-dows{display:flex;flex-direction:column;gap:3px;padding-top:17px;flex:none}
|
|
1217
|
+
.dq-heat-dow{height:12px;line-height:12px;font-size:9px;color:var(--dsw-alias-label-tertiary,#59636e);text-align:right;width:12px}
|
|
1218
|
+
.dq-heat-cols{display:flex;flex-direction:column;gap:2px;min-width:0}
|
|
1219
|
+
.dq-heat-months{display:flex;gap:3px;height:12px}
|
|
1220
|
+
.dq-heat-month{width:12px;flex:none;font-size:9px;line-height:12px;color:var(--dsw-alias-label-tertiary,#59636e);white-space:nowrap;overflow:visible}
|
|
1221
|
+
.dq-heatmap{display:flex;gap:3px;width:max-content}
|
|
1222
|
+
.dq-heat-week{display:flex;flex-direction:column;gap:3px}
|
|
1223
|
+
.dq-heat-cell{width:12px;height:12px;border-radius:2px;flex:none}
|
|
1224
|
+
.dq-heat-cell--pad{background:transparent}
|
|
1225
|
+
.dq-heat-key{width:12px;height:12px;border-radius:2px;flex:none}
|
|
1226
|
+
.dq-heat-scale{display:flex;align-items:center;gap:3px;font-size:10px;color:var(--dsw-alias-label-tertiary,#59636e);align-self:flex-end}
|
|
1227
|
+
.dq-heat-scale>span:first-child{margin-right:2px}
|
|
1228
|
+
.dq-heat-scale>span:last-child{margin-left:2px}
|
|
1229
|
+
.dq-muted{color:var(--dsw-alias-label-secondary,#59636e)}
|
|
1230
|
+
.dq-error{color:var(--dsw-alias-state-error-primary,#cf222e)}
|
|
1231
|
+
.dq-warn{color:var(--dsw-alias-state-warning-primary,#9a6700)}
|
|
1232
|
+
.dq-empty{color:var(--dsw-alias-label-secondary,#59636e);font-size:12.5px;line-height:1.6;padding:6px 0}
|
|
1233
|
+
.dq-skel{background:linear-gradient(90deg,rgba(125,135,155,.10) 25%,rgba(125,135,155,.20) 37%,rgba(125,135,155,.10) 63%);background-size:400% 100%;border-radius:5px;animation:dq-shimmer 1.5s ease-in-out infinite}
|
|
1234
|
+
.dq-stat .dq-skel+.dq-skel{margin-top:6px}
|
|
1235
|
+
.dq-skel-bars{display:flex;align-items:flex-end;gap:2px;width:100%;height:120px;margin-top:10px}
|
|
1236
|
+
.dq-skel-bar{flex:1 1 0;min-width:0;border-radius:2px 2px 0 0}
|
|
1237
|
+
@keyframes dq-shimmer{0%{background-position:100% 50%}100%{background-position:0 50%}}
|
|
1238
|
+
@media (prefers-reduced-motion:reduce){.dq-skel{animation:none}.dq-refresh-icon--spin{animation:none}}
|
|
1239
|
+
.dq-status-row{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:20px}
|
|
1240
|
+
.dq-status-row .dq-muted,.dq-status-row .dq-error{font-size:12px}
|
|
1241
|
+
.dq-refresh-btn{display:inline-flex;align-items:center;gap:5px;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-secondary,#59636e);border-radius:8px;padding:5px 10px;font-size:12px;cursor:pointer;transition:border-color .15s ease,color .15s ease}
|
|
1242
|
+
.dq-refresh-btn:hover:not(:disabled){border-color:var(--dsw-alias-state-business-primary,#0969da);color:var(--dsw-alias-state-business-primary,#0969da)}
|
|
1243
|
+
.dq-refresh-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#0969da);outline-offset:2px}
|
|
1244
|
+
.dq-refresh-btn:disabled{cursor:default;opacity:.6}
|
|
1245
|
+
.dq-refresh-icon{display:inline-block;line-height:1}
|
|
1246
|
+
.dq-refresh-icon--spin{animation:dq-spin .9s linear infinite}
|
|
1247
|
+
@keyframes dq-spin{to{transform:rotate(360deg)}}
|
|
1248
|
+
`;
|
|
1249
|
+
|
|
1250
|
+
// src/client/widget.tsx
|
|
1251
|
+
var import_react3 = require("react");
|
|
1252
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1253
|
+
var MARGIN = 16;
|
|
1254
|
+
var CORNER_KEY = "widget.corner";
|
|
1255
|
+
var COLLAPSED_KEY = "widget.collapsed";
|
|
1256
|
+
var isCorner = (value) => value === "tl" || value === "tr" || value === "bl" || value === "br";
|
|
1257
|
+
function getMainColumn(frame) {
|
|
1258
|
+
const anchor = frame.querySelector('[data-slot="conversation"]');
|
|
1259
|
+
const column = anchor?.parentElement ?? null;
|
|
1260
|
+
return column === frame ? null : column;
|
|
1261
|
+
}
|
|
1262
|
+
function slotBox(frame, slot, side) {
|
|
1263
|
+
const anchor = frame.querySelector(`[data-slot="${slot}"]`);
|
|
1264
|
+
if (anchor === null) return null;
|
|
1265
|
+
if (side === "child") {
|
|
1266
|
+
const rect = anchor.firstElementChild?.getBoundingClientRect() ?? null;
|
|
1267
|
+
return rect !== null && rect.height > 0 ? rect : null;
|
|
1268
|
+
}
|
|
1269
|
+
let el = anchor.parentElement;
|
|
1270
|
+
for (let depth = 0; depth < 4 && el !== null && el !== frame; depth++) {
|
|
1271
|
+
const rect = el.getBoundingClientRect();
|
|
1272
|
+
if (rect.height > 0) return rect;
|
|
1273
|
+
el = el.parentElement;
|
|
1274
|
+
}
|
|
1275
|
+
return null;
|
|
1276
|
+
}
|
|
1277
|
+
var MIN_REGION_HEIGHT = 140;
|
|
1278
|
+
function getBounds(node) {
|
|
1279
|
+
const fallback = { left: 0, top: 0, right: 1e5, bottom: 1e5 };
|
|
1280
|
+
if (node === null) return fallback;
|
|
1281
|
+
const overlay = typeof node.closest === "function" ? node.closest("[data-shell-overlay]") : null;
|
|
1282
|
+
const frame = overlay?.parentElement ?? null;
|
|
1283
|
+
if (frame === null) return fallback;
|
|
1284
|
+
const frameRect = frame.getBoundingClientRect();
|
|
1285
|
+
let left = frameRect.left;
|
|
1286
|
+
let right = frameRect.right;
|
|
1287
|
+
let top = frameRect.top;
|
|
1288
|
+
const mainRect = getMainColumn(frame)?.getBoundingClientRect() ?? null;
|
|
1289
|
+
if (mainRect !== null && mainRect.width > 0) {
|
|
1290
|
+
left = mainRect.left;
|
|
1291
|
+
right = mainRect.right;
|
|
1292
|
+
top = mainRect.top;
|
|
1293
|
+
} else {
|
|
1294
|
+
const sidebarRect = frame.children[0]?.getBoundingClientRect() ?? null;
|
|
1295
|
+
if (sidebarRect !== null) left = sidebarRect.right;
|
|
1296
|
+
}
|
|
1297
|
+
let bottom = frameRect.bottom;
|
|
1298
|
+
const headerRect = slotBox(frame, "conversation.session.header", "child");
|
|
1299
|
+
if (headerRect !== null && headerRect.bottom > top && headerRect.bottom < bottom - MIN_REGION_HEIGHT) {
|
|
1300
|
+
top = headerRect.bottom;
|
|
1301
|
+
}
|
|
1302
|
+
const composerRect = slotBox(frame, "conversation.composer.dock", "ancestor");
|
|
1303
|
+
if (composerRect !== null && composerRect.top < bottom && composerRect.top > top + MIN_REGION_HEIGHT) {
|
|
1304
|
+
bottom = composerRect.top;
|
|
1305
|
+
}
|
|
1306
|
+
return { left, top, right, bottom };
|
|
1307
|
+
}
|
|
1308
|
+
function cornerPos(corner, node, bounds) {
|
|
1309
|
+
const rect = node?.getBoundingClientRect();
|
|
1310
|
+
const w = rect?.width ?? 0;
|
|
1311
|
+
const h = rect?.height ?? 0;
|
|
1312
|
+
const xLeft = bounds.left + MARGIN;
|
|
1313
|
+
const yTop = bounds.top + MARGIN;
|
|
1314
|
+
const xRight = bounds.right - w - MARGIN;
|
|
1315
|
+
const yBottom = bounds.bottom - h - MARGIN;
|
|
1316
|
+
if (corner === "tl") return { x: xLeft, y: yTop };
|
|
1317
|
+
if (corner === "tr") return { x: xRight, y: yTop };
|
|
1318
|
+
if (corner === "bl") return { x: xLeft, y: yBottom };
|
|
1319
|
+
return { x: xRight, y: yBottom };
|
|
1320
|
+
}
|
|
1321
|
+
function QuotaWidget() {
|
|
1322
|
+
const [visible, setVisible] = (0, import_react3.useState)(widgetVisibleStore.get());
|
|
1323
|
+
(0, import_react3.useEffect)(() => widgetVisibleStore.subscribe(() => setVisible(widgetVisibleStore.get())), []);
|
|
1324
|
+
const [lowBalance, setLowBalance] = (0, import_react3.useState)(lowBalanceStore.get());
|
|
1325
|
+
(0, import_react3.useEffect)(() => lowBalanceStore.subscribe(() => setLowBalance(lowBalanceStore.get())), []);
|
|
1326
|
+
const cachedBalance = getCachedBalance();
|
|
1327
|
+
const [data, setData] = (0, import_react3.useState)(cachedBalance?.data ?? null);
|
|
1328
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
1329
|
+
const [loading, setLoading] = (0, import_react3.useState)(cachedBalance === null);
|
|
1330
|
+
const [collapsed, setCollapsed] = (0, import_react3.useState)(() => loadPref(COLLAPSED_KEY, isBoolean, false));
|
|
1331
|
+
const [pos, setPos] = (0, import_react3.useState)(null);
|
|
1332
|
+
const [corner, setCorner] = (0, import_react3.useState)(() => loadPref(CORNER_KEY, isCorner, "br"));
|
|
1333
|
+
const [dragging, setDragging] = (0, import_react3.useState)(false);
|
|
1334
|
+
const rootRef = (0, import_react3.useRef)(null);
|
|
1335
|
+
const dragRef = (0, import_react3.useRef)(null);
|
|
1336
|
+
const readUsage = () => {
|
|
1337
|
+
const cached = getCachedUsage();
|
|
1338
|
+
return { data: cached?.ok === true ? cached.data ?? null : null, at: getCachedUsageAt() };
|
|
1339
|
+
};
|
|
1340
|
+
const [usage, setUsage] = (0, import_react3.useState)(readUsage);
|
|
1341
|
+
(0, import_react3.useEffect)(() => subscribeUsage(() => setUsage(readUsage())), []);
|
|
1342
|
+
const load = async (showLoading, force = false) => {
|
|
1343
|
+
if (showLoading) setLoading(true);
|
|
1344
|
+
try {
|
|
1345
|
+
const res = await fetchBalance(force);
|
|
1346
|
+
if (res.ok && res.data !== void 0) {
|
|
1347
|
+
setData(res.data);
|
|
1348
|
+
setError(null);
|
|
1349
|
+
} else {
|
|
1350
|
+
setData(null);
|
|
1351
|
+
setError(res.error ?? "\u67E5\u8BE2\u5931\u8D25");
|
|
1352
|
+
}
|
|
1353
|
+
} catch (err) {
|
|
1354
|
+
setData(null);
|
|
1355
|
+
setError(err?.message ?? String(err));
|
|
1356
|
+
} finally {
|
|
1357
|
+
setLoading(false);
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
(0, import_react3.useEffect)(() => {
|
|
1361
|
+
void load(true);
|
|
1362
|
+
const id = setInterval(() => {
|
|
1363
|
+
void load(false);
|
|
1364
|
+
}, 6e4);
|
|
1365
|
+
return () => clearInterval(id);
|
|
1366
|
+
}, []);
|
|
1367
|
+
(0, import_react3.useLayoutEffect)(() => {
|
|
1368
|
+
if (!visible) return;
|
|
1369
|
+
const node = rootRef.current;
|
|
1370
|
+
if (node === null) return;
|
|
1371
|
+
const place = () => {
|
|
1372
|
+
if (dragRef.current !== null) return;
|
|
1373
|
+
const next = cornerPos(corner, node, getBounds(node));
|
|
1374
|
+
setPos((prev) => prev !== null && prev.x === next.x && prev.y === next.y ? prev : next);
|
|
1375
|
+
};
|
|
1376
|
+
place();
|
|
1377
|
+
const frame = node.closest("[data-shell-overlay]")?.parentElement;
|
|
1378
|
+
let observer = null;
|
|
1379
|
+
if (frame !== null && typeof ResizeObserver === "function") {
|
|
1380
|
+
observer = new ResizeObserver(place);
|
|
1381
|
+
observer.observe(frame);
|
|
1382
|
+
const main = getMainColumn(frame);
|
|
1383
|
+
if (main !== null) observer.observe(main);
|
|
1384
|
+
}
|
|
1385
|
+
window.addEventListener("resize", place);
|
|
1386
|
+
const poll = setInterval(place, 1e3);
|
|
1387
|
+
return () => {
|
|
1388
|
+
observer?.disconnect();
|
|
1389
|
+
window.removeEventListener("resize", place);
|
|
1390
|
+
clearInterval(poll);
|
|
1391
|
+
};
|
|
1392
|
+
}, [visible, corner, collapsed]);
|
|
1393
|
+
const snapToNearest = (session) => {
|
|
1394
|
+
const node = rootRef.current;
|
|
1395
|
+
if (node === null) return;
|
|
1396
|
+
const { width: w, height: h, bounds: b } = session;
|
|
1397
|
+
const corners = [
|
|
1398
|
+
{ c: "tl", x: b.left + MARGIN, y: b.top + MARGIN },
|
|
1399
|
+
{ c: "tr", x: b.right - w - MARGIN, y: b.top + MARGIN },
|
|
1400
|
+
{ c: "bl", x: b.left + MARGIN, y: b.bottom - h - MARGIN },
|
|
1401
|
+
{ c: "br", x: b.right - w - MARGIN, y: b.bottom - h - MARGIN }
|
|
1402
|
+
];
|
|
1403
|
+
const rect = node.getBoundingClientRect();
|
|
1404
|
+
const cx = rect.left + rect.width / 2;
|
|
1405
|
+
const cy = rect.top + rect.height / 2;
|
|
1406
|
+
let best = corners[0];
|
|
1407
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
1408
|
+
for (const candidate of corners) {
|
|
1409
|
+
const ccx = candidate.x + w / 2;
|
|
1410
|
+
const ccy = candidate.y + h / 2;
|
|
1411
|
+
const distance = (ccx - cx) ** 2 + (ccy - cy) ** 2;
|
|
1412
|
+
if (distance < bestDistance) {
|
|
1413
|
+
bestDistance = distance;
|
|
1414
|
+
best = candidate;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
setCorner(best.c);
|
|
1418
|
+
savePref(CORNER_KEY, best.c);
|
|
1419
|
+
setPos({ x: best.x, y: best.y });
|
|
1420
|
+
};
|
|
1421
|
+
const endDrag = (snap) => {
|
|
1422
|
+
const session = dragRef.current;
|
|
1423
|
+
if (session === null) return;
|
|
1424
|
+
dragRef.current = null;
|
|
1425
|
+
setDragging(false);
|
|
1426
|
+
const node = rootRef.current;
|
|
1427
|
+
if (node !== null && typeof node.releasePointerCapture === "function") {
|
|
1428
|
+
try {
|
|
1429
|
+
node.releasePointerCapture(session.pointerId);
|
|
1430
|
+
} catch {
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
if (snap) {
|
|
1434
|
+
if (typeof requestAnimationFrame === "function") {
|
|
1435
|
+
requestAnimationFrame(() => snapToNearest(session));
|
|
1436
|
+
} else {
|
|
1437
|
+
snapToNearest(session);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
const onPointerDown = (e) => {
|
|
1442
|
+
if (e.button !== 0) return;
|
|
1443
|
+
const target = e.target;
|
|
1444
|
+
if (target !== null && typeof target.closest === "function" && target.closest("button") !== null) return;
|
|
1445
|
+
const node = rootRef.current;
|
|
1446
|
+
if (node === null) return;
|
|
1447
|
+
const bounds = getBounds(node);
|
|
1448
|
+
const rect = node.getBoundingClientRect();
|
|
1449
|
+
dragRef.current = {
|
|
1450
|
+
pointerId: e.pointerId,
|
|
1451
|
+
startX: e.clientX,
|
|
1452
|
+
startY: e.clientY,
|
|
1453
|
+
originX: rect.left,
|
|
1454
|
+
originY: rect.top,
|
|
1455
|
+
width: rect.width,
|
|
1456
|
+
height: rect.height,
|
|
1457
|
+
bounds
|
|
1458
|
+
};
|
|
1459
|
+
node.setPointerCapture(e.pointerId);
|
|
1460
|
+
setDragging(true);
|
|
1461
|
+
e.preventDefault();
|
|
1462
|
+
};
|
|
1463
|
+
const onPointerMove = (e) => {
|
|
1464
|
+
const session = dragRef.current;
|
|
1465
|
+
if (session === null || session.pointerId !== e.pointerId) return;
|
|
1466
|
+
if ((e.buttons & 1) === 0) {
|
|
1467
|
+
endDrag(true);
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
const dx = e.clientX - session.startX;
|
|
1471
|
+
const dy = e.clientY - session.startY;
|
|
1472
|
+
const maxX = session.bounds.right - session.width - MARGIN;
|
|
1473
|
+
const maxY = session.bounds.bottom - session.height - MARGIN;
|
|
1474
|
+
const minX = session.bounds.left + MARGIN;
|
|
1475
|
+
const minY = session.bounds.top + MARGIN;
|
|
1476
|
+
setPos({
|
|
1477
|
+
x: Math.max(minX, Math.min(session.originX + dx, maxX)),
|
|
1478
|
+
y: Math.max(minY, Math.min(session.originY + dy, maxY))
|
|
1479
|
+
});
|
|
1480
|
+
};
|
|
1481
|
+
const onPointerUp = (e) => {
|
|
1482
|
+
const session = dragRef.current;
|
|
1483
|
+
if (session === null || session.pointerId !== e.pointerId) return;
|
|
1484
|
+
endDrag(true);
|
|
1485
|
+
};
|
|
1486
|
+
if (!visible) return null;
|
|
1487
|
+
const primary = data !== null && data.balances.length > 0 ? data.balances[0] : null;
|
|
1488
|
+
const balanceValue = primary !== null ? Number(primary.total) : Number.NaN;
|
|
1489
|
+
const low = lowBalance > 0 && Number.isFinite(balanceValue) && balanceValue < lowBalance;
|
|
1490
|
+
const dotClass = primary === null ? "dsh-quota-dot dsh-quota-dot--idle" : data?.isAvailable === false ? "dsh-quota-dot dsh-quota-dot--error" : low ? "dsh-quota-dot dsh-quota-dot--warn" : "dsh-quota-dot";
|
|
1491
|
+
const ageMinutes = usage.at === null ? null : Math.floor((Date.now() - usage.at) / 6e4);
|
|
1492
|
+
const usageAgeText = ageMinutes === null || ageMinutes < 1 ? "\u521A\u521A\u66F4\u65B0" : `${ageMinutes} \u5206\u949F\u524D\u7684\u6570\u636E\uFF0C\u70B9 \u21BB \u66F4\u65B0`;
|
|
1493
|
+
let body = null;
|
|
1494
|
+
if (!collapsed) {
|
|
1495
|
+
if (loading && data === null && error === null) {
|
|
1496
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "dsh-quota-body", children: "\u67E5\u8BE2\u4E2D\u2026" });
|
|
1497
|
+
} else if (error !== null && data === null) {
|
|
1498
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "dsh-quota-body dsh-quota-error", children: error });
|
|
1499
|
+
} else if (primary !== null) {
|
|
1500
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsh-quota-body", children: [
|
|
1501
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "dsh-quota-remaining-label", children: "\u5269\u4F59\u4F59\u989D" }),
|
|
1502
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { title: low ? `\u4F59\u989D\u4F4E\u4E8E\u9884\u8B66\u7EBF ${fmt(lowBalance)}` : void 0, children: [
|
|
1503
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `dsh-quota-total${low ? " dsh-quota-total--low" : ""}`, children: fmt(primary.total) }),
|
|
1504
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "dsh-quota-currency", children: primary.currency })
|
|
1505
|
+
] }),
|
|
1506
|
+
usage.data !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsh-quota-row", title: `\u4ECA\u65E5\u6D88\u8017\uFF08\u4F30\u7B97\uFF09\xB7 ${usageAgeText}`, children: [
|
|
1507
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "dsh-quota-label", children: "\u4ECA\u65E5\u6D88\u8017" }),
|
|
1508
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "dsh-quota-value", children: [
|
|
1509
|
+
"\xA5 ",
|
|
1510
|
+
fmt(usage.data.summary.today.cost)
|
|
1511
|
+
] })
|
|
1512
|
+
] }),
|
|
1513
|
+
data?.isAvailable === false && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsh-quota-row", children: [
|
|
1514
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "dsh-quota-label", children: "\u72B6\u6001" }),
|
|
1515
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "dsh-quota-value dsh-quota-error", children: "\u4E0D\u53EF\u7528" })
|
|
1516
|
+
] })
|
|
1517
|
+
] });
|
|
1518
|
+
} else {
|
|
1519
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "dsh-quota-body dsh-quota-error", children: "\u6682\u65E0\u4F59\u989D\u6570\u636E" });
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
const style = pos !== null ? { left: `${pos.x}px`, top: `${pos.y}px`, right: "auto", bottom: "auto" } : void 0;
|
|
1523
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: `dsh-quota-root${dragging ? " dsh-quota-dragging" : ""}`, style, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1524
|
+
"div",
|
|
1525
|
+
{
|
|
1526
|
+
ref: rootRef,
|
|
1527
|
+
className: "dsh-quota-card",
|
|
1528
|
+
title: "\u62D6\u52A8\u5230\u56DB\u4E2A\u89D2\u843D",
|
|
1529
|
+
onPointerDown,
|
|
1530
|
+
onPointerMove,
|
|
1531
|
+
onPointerUp,
|
|
1532
|
+
onPointerCancel: () => endDrag(false),
|
|
1533
|
+
onLostPointerCapture: () => endDrag(false),
|
|
1534
|
+
children: [
|
|
1535
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsh-quota-header", children: [
|
|
1536
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsh-quota-title", children: [
|
|
1537
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "dsh-quota-grip", title: "\u62D6\u52A8\u4EE5\u79FB\u52A8", children: "\u2807" }),
|
|
1538
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: dotClass }),
|
|
1539
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "dsh-quota-name", children: "DeepSeek \u989D\u5EA6" }),
|
|
1540
|
+
collapsed && primary !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: `dsh-quota-collapsed-total${low ? " dsh-quota-total--low" : ""}`, children: [
|
|
1541
|
+
fmt(primary.total),
|
|
1542
|
+
" ",
|
|
1543
|
+
primary.currency
|
|
1544
|
+
] })
|
|
1545
|
+
] }),
|
|
1546
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsh-quota-actions", children: [
|
|
1547
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1548
|
+
"button",
|
|
1549
|
+
{
|
|
1550
|
+
className: "dsh-quota-btn",
|
|
1551
|
+
type: "button",
|
|
1552
|
+
title: "\u5237\u65B0\u4F59\u989D\u4E0E\u4ECA\u65E5\u7528\u91CF",
|
|
1553
|
+
"aria-label": "\u5237\u65B0\u4F59\u989D\u4E0E\u4ECA\u65E5\u7528\u91CF",
|
|
1554
|
+
disabled: loading,
|
|
1555
|
+
onClick: () => {
|
|
1556
|
+
void load(true, true);
|
|
1557
|
+
void fetchUsage(true);
|
|
1558
|
+
},
|
|
1559
|
+
children: "\u21BB"
|
|
1560
|
+
}
|
|
1561
|
+
),
|
|
1562
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1563
|
+
"button",
|
|
1564
|
+
{
|
|
1565
|
+
className: "dsh-quota-btn",
|
|
1566
|
+
type: "button",
|
|
1567
|
+
title: collapsed ? "\u5C55\u5F00" : "\u6536\u8D77",
|
|
1568
|
+
"aria-label": collapsed ? "\u5C55\u5F00\u989D\u5EA6\u7A97\u53E3" : "\u6536\u8D77\u989D\u5EA6\u7A97\u53E3",
|
|
1569
|
+
"aria-expanded": !collapsed,
|
|
1570
|
+
onClick: () => {
|
|
1571
|
+
const next = !collapsed;
|
|
1572
|
+
setCollapsed(next);
|
|
1573
|
+
savePref(COLLAPSED_KEY, next);
|
|
1574
|
+
},
|
|
1575
|
+
children: collapsed ? "+" : "\u2212"
|
|
1576
|
+
}
|
|
1577
|
+
)
|
|
1578
|
+
] })
|
|
1579
|
+
] }),
|
|
1580
|
+
body
|
|
1581
|
+
]
|
|
1582
|
+
}
|
|
1583
|
+
) });
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
// src/client/index.tsx
|
|
1587
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1588
|
+
var name = "dsh-usage-dashboard";
|
|
1589
|
+
var inject = ["slots"];
|
|
1590
|
+
function apply(ctx) {
|
|
1591
|
+
if (typeof document !== "undefined") {
|
|
1592
|
+
const tag = document.createElement("style");
|
|
1593
|
+
tag.dataset.plugin = "dsh-usage-dashboard";
|
|
1594
|
+
tag.textContent = css;
|
|
1595
|
+
document.head.appendChild(tag);
|
|
1596
|
+
}
|
|
1597
|
+
ctx.slots.inject("shell.overlay", () => ctx.slots.register(
|
|
1598
|
+
{ name: "shell.overlay", id: "deepseek-quota", order: 1e3, label: "DeepSeek \u989D\u5EA6" },
|
|
1599
|
+
() => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(QuotaWidget, {})
|
|
1600
|
+
));
|
|
1601
|
+
ctx.slots.inject("conversation.view", () => ctx.slots.register(
|
|
1602
|
+
{ name: "conversation.view", id: "balance", order: 20, label: "\u989D\u5EA6" },
|
|
1603
|
+
() => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(BalanceDashboard, {})
|
|
1604
|
+
));
|
|
1605
|
+
}
|
|
1606
|
+
return module.exports; } });
|
|
1607
|
+
//# sourceMappingURL=client.js.map
|