@pinkbanana/dsh-balance 0.4.0 → 0.5.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/README.md +13 -2
- package/README_EN.md +13 -2
- package/lib/client.js +743 -6
- package/lib/client.js.map +1 -1
- package/lib/index.js +495 -3
- package/lib/index.js.map +1 -1
- package/lib/types/billing.d.ts +119 -0
- package/lib/types/client/BillingTab.d.ts +18 -0
- package/lib/types/client/DeepSeekPanel.d.ts +3 -2
- package/lib/types/client/format.d.ts +1 -0
- package/lib/types/client/index.d.ts +1 -0
- package/lib/types/client/locales.d.ts +44 -0
- package/lib/types/client/pricing.d.ts +1 -0
- package/lib/types/client/styles.d.ts +1 -1
- package/lib/types/index.d.ts +3 -0
- package/lib/types/pricing.d.ts +7 -0
- package/package.json +9 -3
package/lib/client.js
CHANGED
|
@@ -12,7 +12,87 @@ window.__ModuleLoader__.load({
|
|
|
12
12
|
/** The same-origin endpoint that proxies DeepSeek's `/models` API. */
|
|
13
13
|
const MODELS_ROUTE = "/dsh-balance/api/models";
|
|
14
14
|
//#endregion
|
|
15
|
+
//#region src/pricing.ts
|
|
16
|
+
/** Shared DeepSeek pricing schedule used by Host billing and the client indicator. */
|
|
17
|
+
const BEIJING_OFFSET_MS = 288e5;
|
|
18
|
+
const DAY_MS = 864e5;
|
|
19
|
+
/** The current V4 schedule became effective at 00:00 Beijing time on 2026-08-17. */
|
|
20
|
+
const PEAK_EFFECTIVE_FROM = Date.parse("2026-08-17T00:00:00+08:00");
|
|
21
|
+
const PEAK_WINDOWS = [[9, 12], [14, 18]];
|
|
22
|
+
const BOUNDARY_SECONDS = [
|
|
23
|
+
32400,
|
|
24
|
+
43200,
|
|
25
|
+
50400,
|
|
26
|
+
64800
|
|
27
|
+
];
|
|
28
|
+
/** Hour of day in Beijing time (UTC+8), 0–23. */
|
|
29
|
+
function beijingHour(date) {
|
|
30
|
+
return new Date(date.getTime() + BEIJING_OFFSET_MS).getUTCHours();
|
|
31
|
+
}
|
|
32
|
+
/** Whether the given instant falls inside a DeepSeek peak-pricing window. */
|
|
33
|
+
function isPeakHour(date) {
|
|
34
|
+
if (date.getTime() < PEAK_EFFECTIVE_FROM) return false;
|
|
35
|
+
const hour = beijingHour(date);
|
|
36
|
+
return PEAK_WINDOWS.some(([start, end]) => hour >= start && hour < end);
|
|
37
|
+
}
|
|
38
|
+
/** The next instant at which the current pricing period ends (Beijing time). */
|
|
39
|
+
function nextPeriodChange(date) {
|
|
40
|
+
const ms = date.getTime();
|
|
41
|
+
const beijing = new Date(ms + BEIJING_OFFSET_MS);
|
|
42
|
+
const secondsIntoDay = beijing.getUTCHours() * 3600 + beijing.getUTCMinutes() * 60 + beijing.getUTCSeconds();
|
|
43
|
+
let boundary = BOUNDARY_SECONDS.find((seconds) => secondsIntoDay < seconds);
|
|
44
|
+
if (boundary === void 0) boundary = 118800;
|
|
45
|
+
const dayStartMs = Math.floor(ms / DAY_MS) * DAY_MS;
|
|
46
|
+
return /* @__PURE__ */ new Date(dayStartMs + boundary * 1e3 - BEIJING_OFFSET_MS);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/billing.ts
|
|
50
|
+
const USAGE_ROUTE = "/dsh-balance/api/usage";
|
|
51
|
+
const BILLING_PRICING_VERSION = "deepseek-v4-2026-08-17";
|
|
52
|
+
const CURRENT_PRICES = {
|
|
53
|
+
"deepseek-v4-flash": {
|
|
54
|
+
cacheHitUsdPerMillion: .007,
|
|
55
|
+
cacheMissUsdPerMillion: .22,
|
|
56
|
+
outputUsdPerMillion: .66
|
|
57
|
+
},
|
|
58
|
+
"deepseek-v4-pro": {
|
|
59
|
+
cacheHitUsdPerMillion: .022,
|
|
60
|
+
cacheMissUsdPerMillion: .66,
|
|
61
|
+
outputUsdPerMillion: 1.98
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
[...Object.entries({
|
|
65
|
+
"deepseek-chat": {
|
|
66
|
+
cacheHitUsdPerMillion: .07,
|
|
67
|
+
cacheMissUsdPerMillion: .27,
|
|
68
|
+
outputUsdPerMillion: 1.1
|
|
69
|
+
},
|
|
70
|
+
"deepseek-reasoner": {
|
|
71
|
+
cacheHitUsdPerMillion: .14,
|
|
72
|
+
cacheMissUsdPerMillion: .55,
|
|
73
|
+
outputUsdPerMillion: 2.19
|
|
74
|
+
}
|
|
75
|
+
}).map(([model, rates]) => ({
|
|
76
|
+
provider: "deepseek",
|
|
77
|
+
model,
|
|
78
|
+
effectiveFrom: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
79
|
+
pricingVersion: "deepseek-legacy",
|
|
80
|
+
...rates
|
|
81
|
+
})), ...Object.entries(CURRENT_PRICES).map(([model, rates]) => ({
|
|
82
|
+
provider: "deepseek",
|
|
83
|
+
model,
|
|
84
|
+
effectiveFrom: new Date(PEAK_EFFECTIVE_FROM).toISOString(),
|
|
85
|
+
pricingVersion: BILLING_PRICING_VERSION,
|
|
86
|
+
...rates
|
|
87
|
+
}))];
|
|
88
|
+
//#endregion
|
|
15
89
|
//#region src/client/format.ts
|
|
90
|
+
function formatClockTime(date, locale) {
|
|
91
|
+
return new Intl.DateTimeFormat(locale, {
|
|
92
|
+
hour: "2-digit",
|
|
93
|
+
minute: "2-digit"
|
|
94
|
+
}).format(date);
|
|
95
|
+
}
|
|
16
96
|
function displayAmount(value, currency, locale) {
|
|
17
97
|
const amount = Number(value);
|
|
18
98
|
if (!Number.isFinite(amount)) return `${value} ${currency}`;
|
|
@@ -30,9 +110,17 @@ window.__ModuleLoader__.load({
|
|
|
30
110
|
//#endregion
|
|
31
111
|
//#region src/client/BalanceDock.tsx
|
|
32
112
|
const REFRESH_INTERVAL_MS = 6e4;
|
|
113
|
+
const PEAK_TICK_MS = 3e4;
|
|
33
114
|
/** Compact ambient balance readout below the active-session composer card. */
|
|
34
115
|
function BalanceDock({ loadBalance, t }) {
|
|
35
116
|
const [result, setResult] = (0, react.useState)();
|
|
117
|
+
const [now, setNow] = (0, react.useState)(() => /* @__PURE__ */ new Date());
|
|
118
|
+
(0, react.useEffect)(() => {
|
|
119
|
+
const timer = window.setInterval(() => setNow(/* @__PURE__ */ new Date()), PEAK_TICK_MS);
|
|
120
|
+
return () => {
|
|
121
|
+
window.clearInterval(timer);
|
|
122
|
+
};
|
|
123
|
+
}, []);
|
|
36
124
|
(0, react.useEffect)(() => {
|
|
37
125
|
let controller;
|
|
38
126
|
const load = () => {
|
|
@@ -64,15 +152,21 @@ window.__ModuleLoader__.load({
|
|
|
64
152
|
}, [result, t]);
|
|
65
153
|
const state = result === void 0 ? "loading" : result.ok && result.isAvailable ? "available" : result.ok ? "empty" : "error";
|
|
66
154
|
const accessibleState = result?.ok === true ? t(result.isAvailable ? "balance.available" : "balance.unavailable") : void 0;
|
|
155
|
+
const pricingActive = now.getTime() >= PEAK_EFFECTIVE_FROM;
|
|
156
|
+
const isPeak = pricingActive && isPeakHour(now);
|
|
157
|
+
const periodLabel = pricingActive ? t(isPeak ? "pricing.peak" : "pricing.offPeak") : void 0;
|
|
158
|
+
const periodTitle = pricingActive ? t(isPeak ? "pricing.peakHint" : "pricing.offPeakHint", { time: formatClockTime(nextPeriodChange(now), t("locale.tag")) }) : void 0;
|
|
67
159
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
68
160
|
className: "dsh-balance-dock",
|
|
69
161
|
role: "status",
|
|
70
162
|
"aria-live": "polite",
|
|
71
|
-
|
|
163
|
+
title: periodTitle,
|
|
164
|
+
"aria-label": `${t("dock.label")}: ${summary}${accessibleState === void 0 ? "" : `. ${accessibleState}`}${periodLabel === void 0 ? "" : `. ${periodLabel}`}`,
|
|
72
165
|
children: [
|
|
73
166
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
74
167
|
className: "dsh-balance-dock-dot",
|
|
75
168
|
"data-state": state,
|
|
169
|
+
"data-peak": isPeak ? "true" : void 0,
|
|
76
170
|
"aria-hidden": "true"
|
|
77
171
|
}),
|
|
78
172
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("dock.label") }),
|
|
@@ -116,6 +210,50 @@ window.__ModuleLoader__.load({
|
|
|
116
210
|
"models.count": "当前可用 {count} 个模型",
|
|
117
211
|
"models.empty": "DeepSeek 未返回任何可用模型。",
|
|
118
212
|
"models.owner": "由 {owner} 提供",
|
|
213
|
+
"billing.tab": "消费",
|
|
214
|
+
"billing.title": "API 消费统计",
|
|
215
|
+
"billing.copy": "按会话、模型和日期统计实际 provider usage;日期按 {timeZone} 分组。",
|
|
216
|
+
"billing.range": "统计范围",
|
|
217
|
+
"billing.todayRange": "今日",
|
|
218
|
+
"billing.sevenDays": "最近 7 天",
|
|
219
|
+
"billing.thirtyDays": "最近 30 天",
|
|
220
|
+
"billing.allTime": "全部时间",
|
|
221
|
+
"billing.refresh": "刷新消费",
|
|
222
|
+
"billing.loading": "正在读取消费记录…",
|
|
223
|
+
"billing.empty": "暂无消费记录。",
|
|
224
|
+
"billing.totalCost": "总消费",
|
|
225
|
+
"billing.todayCost": "今日消费",
|
|
226
|
+
"billing.today": "日期 {date}",
|
|
227
|
+
"billing.pricedRequests": "已计费请求 {count} 次",
|
|
228
|
+
"billing.tokens": "Token 总量",
|
|
229
|
+
"billing.requestCount": "{count} 次请求",
|
|
230
|
+
"billing.share": "占已知消费 {percent}",
|
|
231
|
+
"billing.unpriced": "未计费请求",
|
|
232
|
+
"billing.unpricedHint": "缺少 usage 或价格未知,不进行估算",
|
|
233
|
+
"billing.fixedRate": "固定汇率换算",
|
|
234
|
+
"billing.tokensBreakdown": "输入 {input} · 输出 {output} · Cache hit {cacheHit} · Cache write {cacheWrite}",
|
|
235
|
+
"billing.byModel": "按模型",
|
|
236
|
+
"billing.bySession": "按会话",
|
|
237
|
+
"billing.byDay": "按日期",
|
|
238
|
+
"billing.sessionTitle": "当前会话消费",
|
|
239
|
+
"billing.sessionCopy": "仅展示当前会话的 token 与计费结果,不展示 prompt 内容。",
|
|
240
|
+
"billing.requestDetails": "请求明细",
|
|
241
|
+
"billing.unknownModel": "未知模型",
|
|
242
|
+
"billing.inputOutput": "输入 {input} · 输出 {output}",
|
|
243
|
+
"billing.notPriced": "未计费",
|
|
244
|
+
"billing.reason.missing-usage": "缺少 provider usage",
|
|
245
|
+
"billing.reason.unknown-provider": "未知 provider",
|
|
246
|
+
"billing.reason.unknown-model": "未知模型价格",
|
|
247
|
+
"billing.reason.missing-request-metadata": "缺少请求模型信息",
|
|
248
|
+
"billing.error.FORBIDDEN": "此统计仅允许从本机访问",
|
|
249
|
+
"billing.error.INVALID_REQUEST": "消费统计参数无效",
|
|
250
|
+
"billing.error.METHOD_NOT_ALLOWED": "请求方法不受支持",
|
|
251
|
+
"billing.error.SESSION_NOT_FOUND": "找不到指定会话",
|
|
252
|
+
"billing.error.UPSTREAM_UNAVAILABLE": "无法读取会话消费记录",
|
|
253
|
+
"pricing.peak": "高峰时段",
|
|
254
|
+
"pricing.offPeak": "低谷时段",
|
|
255
|
+
"pricing.peakHint": "DeepSeek 高峰时段,API 价格为低谷的两倍,{time} 恢复低谷价",
|
|
256
|
+
"pricing.offPeakHint": "DeepSeek 低谷时段,API 价格为高峰的一半,{time} 进入高峰",
|
|
119
257
|
"meta.updated": "更新于 {time}",
|
|
120
258
|
"meta.cached": " · 缓存",
|
|
121
259
|
"error.FORBIDDEN": "此查询仅允许从本机访问",
|
|
@@ -153,6 +291,50 @@ window.__ModuleLoader__.load({
|
|
|
153
291
|
"models.count": "{count} models available",
|
|
154
292
|
"models.empty": "DeepSeek returned no available models.",
|
|
155
293
|
"models.owner": "Provided by {owner}",
|
|
294
|
+
"billing.tab": "Usage",
|
|
295
|
+
"billing.title": "API Usage",
|
|
296
|
+
"billing.copy": "Actual provider usage grouped by session, model, and date; dates use {timeZone}.",
|
|
297
|
+
"billing.range": "Usage range",
|
|
298
|
+
"billing.todayRange": "Today",
|
|
299
|
+
"billing.sevenDays": "Last 7 days",
|
|
300
|
+
"billing.thirtyDays": "Last 30 days",
|
|
301
|
+
"billing.allTime": "All time",
|
|
302
|
+
"billing.refresh": "Refresh usage",
|
|
303
|
+
"billing.loading": "Loading usage records…",
|
|
304
|
+
"billing.empty": "No usage records.",
|
|
305
|
+
"billing.totalCost": "Total cost",
|
|
306
|
+
"billing.todayCost": "Today’s cost",
|
|
307
|
+
"billing.today": "Date {date}",
|
|
308
|
+
"billing.pricedRequests": "{count} priced requests",
|
|
309
|
+
"billing.tokens": "Total tokens",
|
|
310
|
+
"billing.requestCount": "{count} requests",
|
|
311
|
+
"billing.share": "{percent} of priced cost",
|
|
312
|
+
"billing.unpriced": "Unpriced requests",
|
|
313
|
+
"billing.unpricedHint": "Missing usage or unknown pricing; no estimate is made",
|
|
314
|
+
"billing.fixedRate": "fixed-rate conversion",
|
|
315
|
+
"billing.tokensBreakdown": "Input {input} · Output {output} · Cache hit {cacheHit} · Cache write {cacheWrite}",
|
|
316
|
+
"billing.byModel": "By model",
|
|
317
|
+
"billing.bySession": "By session",
|
|
318
|
+
"billing.byDay": "By day",
|
|
319
|
+
"billing.sessionTitle": "Current session usage",
|
|
320
|
+
"billing.sessionCopy": "Token and billing metadata only; prompt content is never shown.",
|
|
321
|
+
"billing.requestDetails": "Request details",
|
|
322
|
+
"billing.unknownModel": "Unknown model",
|
|
323
|
+
"billing.inputOutput": "Input {input} · Output {output}",
|
|
324
|
+
"billing.notPriced": "Unpriced",
|
|
325
|
+
"billing.reason.missing-usage": "Provider usage is missing",
|
|
326
|
+
"billing.reason.unknown-provider": "Unknown provider",
|
|
327
|
+
"billing.reason.unknown-model": "Unknown model pricing",
|
|
328
|
+
"billing.reason.missing-request-metadata": "Request model metadata is missing",
|
|
329
|
+
"billing.error.FORBIDDEN": "This usage view is available only from the local machine",
|
|
330
|
+
"billing.error.INVALID_REQUEST": "The usage query is invalid",
|
|
331
|
+
"billing.error.METHOD_NOT_ALLOWED": "This request method is not supported",
|
|
332
|
+
"billing.error.SESSION_NOT_FOUND": "The requested session was not found",
|
|
333
|
+
"billing.error.UPSTREAM_UNAVAILABLE": "Could not read session usage records",
|
|
334
|
+
"pricing.peak": "Peak hours",
|
|
335
|
+
"pricing.offPeak": "Off-peak hours",
|
|
336
|
+
"pricing.peakHint": "DeepSeek peak hours — API prices are double. Off-peak pricing resumes at {time}",
|
|
337
|
+
"pricing.offPeakHint": "DeepSeek off-peak hours — API prices are halved. Peak pricing starts at {time}",
|
|
156
338
|
"meta.updated": "Updated {time}",
|
|
157
339
|
"meta.cached": " · Cached",
|
|
158
340
|
"error.FORBIDDEN": "This query is available only from the local machine",
|
|
@@ -385,9 +567,444 @@ window.__ModuleLoader__.load({
|
|
|
385
567
|
});
|
|
386
568
|
}
|
|
387
569
|
//#endregion
|
|
570
|
+
//#region src/client/BillingTab.tsx
|
|
571
|
+
function formatTokens(value) {
|
|
572
|
+
return new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(value);
|
|
573
|
+
}
|
|
574
|
+
function amount(value, currency, locale) {
|
|
575
|
+
return value === null ? "—" : displayAmount(String(value), currency, locale);
|
|
576
|
+
}
|
|
577
|
+
function localDateKey(timeZone, date = /* @__PURE__ */ new Date()) {
|
|
578
|
+
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
579
|
+
timeZone,
|
|
580
|
+
year: "numeric",
|
|
581
|
+
month: "2-digit",
|
|
582
|
+
day: "2-digit"
|
|
583
|
+
}).formatToParts(date);
|
|
584
|
+
const values = Object.fromEntries(parts.map((part) => [part.type, part.value]));
|
|
585
|
+
return `${values.year ?? "0000"}-${values.month ?? "00"}-${values.day ?? "00"}`;
|
|
586
|
+
}
|
|
587
|
+
function dateDaysAgo(timeZone, days) {
|
|
588
|
+
const local = new Date((/* @__PURE__ */ new Date()).toLocaleString("en-US", { timeZone }));
|
|
589
|
+
local.setDate(local.getDate() - days);
|
|
590
|
+
return localDateKey(timeZone, local);
|
|
591
|
+
}
|
|
592
|
+
function totalForDay(summary, date) {
|
|
593
|
+
return summary.byDay.find((item) => item.date === date) ?? {
|
|
594
|
+
requests: 0,
|
|
595
|
+
pricedRequests: 0,
|
|
596
|
+
unpricedRequests: 0,
|
|
597
|
+
inputTokens: 0,
|
|
598
|
+
outputTokens: 0,
|
|
599
|
+
cacheReadTokens: 0,
|
|
600
|
+
cacheWriteTokens: 0,
|
|
601
|
+
costUsd: 0,
|
|
602
|
+
costCny: summary.usdToCny === null ? null : 0
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
function ErrorMessage({ result, t }) {
|
|
606
|
+
if (result.ok === true) return null;
|
|
607
|
+
const key = `billing.error.${result.code}`;
|
|
608
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
609
|
+
className: "dsh-balance-error",
|
|
610
|
+
role: "alert",
|
|
611
|
+
children: [t(key), result.message ? ` (${result.message})` : ""]
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
function CostLabel({ totals, t }) {
|
|
615
|
+
const locale = t("locale.tag");
|
|
616
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
617
|
+
className: "dsh-billing-cost-value",
|
|
618
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: amount(totals.costUsd, "USD", locale) }), totals.costCny !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
|
|
619
|
+
amount(totals.costCny, "CNY", locale),
|
|
620
|
+
" ",
|
|
621
|
+
t("billing.fixedRate")
|
|
622
|
+
] }) : null]
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
function SummaryCards({ summary, t }) {
|
|
626
|
+
const today = totalForDay(summary, localDateKey(summary.timeZone));
|
|
627
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
628
|
+
className: "dsh-billing-card-grid",
|
|
629
|
+
children: [
|
|
630
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
631
|
+
className: "dsh-billing-card dsh-billing-card-primary",
|
|
632
|
+
children: [
|
|
633
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.totalCost") }),
|
|
634
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
635
|
+
totals: summary.totals,
|
|
636
|
+
t
|
|
637
|
+
}),
|
|
638
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.pricedRequests", { count: summary.totals.pricedRequests }) })
|
|
639
|
+
]
|
|
640
|
+
}),
|
|
641
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
642
|
+
className: "dsh-billing-card",
|
|
643
|
+
children: [
|
|
644
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.todayCost") }),
|
|
645
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
646
|
+
totals: today,
|
|
647
|
+
t
|
|
648
|
+
}),
|
|
649
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.today", { date: localDateKey(summary.timeZone) }) })
|
|
650
|
+
]
|
|
651
|
+
}),
|
|
652
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
653
|
+
className: "dsh-billing-card",
|
|
654
|
+
children: [
|
|
655
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.tokens") }),
|
|
656
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: formatTokens(summary.totals.inputTokens + summary.totals.outputTokens) }),
|
|
657
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
658
|
+
totals: summary.totals,
|
|
659
|
+
t
|
|
660
|
+
}),
|
|
661
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.requestCount", { count: summary.totals.requests }) })
|
|
662
|
+
]
|
|
663
|
+
}),
|
|
664
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
665
|
+
className: "dsh-billing-card",
|
|
666
|
+
"data-warning": summary.totals.unpricedRequests > 0 ? "true" : "false",
|
|
667
|
+
children: [
|
|
668
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.unpriced") }),
|
|
669
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: formatTokens(summary.totals.unpricedRequests) }),
|
|
670
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.unpricedHint") })
|
|
671
|
+
]
|
|
672
|
+
})
|
|
673
|
+
]
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
function TotalsCaption({ totals, t }) {
|
|
677
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
678
|
+
className: "dsh-billing-secondary",
|
|
679
|
+
children: t("billing.tokensBreakdown", {
|
|
680
|
+
input: formatTokens(totals.inputTokens),
|
|
681
|
+
output: formatTokens(totals.outputTokens),
|
|
682
|
+
cacheHit: formatTokens(totals.cacheReadTokens),
|
|
683
|
+
cacheWrite: formatTokens(totals.cacheWriteTokens)
|
|
684
|
+
})
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
function ModelRows({ summary, t }) {
|
|
688
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
689
|
+
className: "dsh-billing-list",
|
|
690
|
+
children: summary.byModel.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
691
|
+
className: "dsh-balance-status",
|
|
692
|
+
children: t("billing.empty")
|
|
693
|
+
}) : summary.byModel.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
694
|
+
className: "dsh-billing-list-row",
|
|
695
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("code", { children: [
|
|
696
|
+
item.provider,
|
|
697
|
+
"/",
|
|
698
|
+
item.model
|
|
699
|
+
] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
700
|
+
totals: item,
|
|
701
|
+
t
|
|
702
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
703
|
+
className: "dsh-billing-list-value",
|
|
704
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
705
|
+
totals: item,
|
|
706
|
+
t
|
|
707
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", { children: [
|
|
708
|
+
t("billing.requestCount", { count: item.requests }),
|
|
709
|
+
" · ",
|
|
710
|
+
t("billing.share", { percent: `${summary.totals.costUsd === 0 ? 0 : Math.round(item.costUsd / summary.totals.costUsd * 100)}%` })
|
|
711
|
+
] })]
|
|
712
|
+
})]
|
|
713
|
+
}, `${item.provider}/${item.model}`))
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
function UsageTables({ summary, t }) {
|
|
717
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
718
|
+
className: "dsh-billing-table-grid",
|
|
719
|
+
children: [
|
|
720
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
721
|
+
className: "dsh-billing-list-section",
|
|
722
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.byModel") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelRows, {
|
|
723
|
+
summary,
|
|
724
|
+
t
|
|
725
|
+
})]
|
|
726
|
+
}),
|
|
727
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
728
|
+
className: "dsh-billing-list-section",
|
|
729
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.bySession") }), summary.bySession.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
730
|
+
className: "dsh-balance-status",
|
|
731
|
+
children: t("billing.empty")
|
|
732
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
733
|
+
className: "dsh-billing-list",
|
|
734
|
+
children: summary.bySession.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
735
|
+
className: "dsh-billing-list-row",
|
|
736
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
737
|
+
className: "dsh-billing-session-title",
|
|
738
|
+
children: item.title
|
|
739
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
740
|
+
totals: item,
|
|
741
|
+
t
|
|
742
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
743
|
+
className: "dsh-billing-list-value",
|
|
744
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
745
|
+
totals: item,
|
|
746
|
+
t
|
|
747
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.requestCount", { count: item.requests }) })]
|
|
748
|
+
})]
|
|
749
|
+
}, item.sessionId))
|
|
750
|
+
})]
|
|
751
|
+
}),
|
|
752
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
753
|
+
className: "dsh-billing-list-section dsh-billing-list-wide",
|
|
754
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.byDay") }), summary.byDay.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
755
|
+
className: "dsh-balance-status",
|
|
756
|
+
children: t("billing.empty")
|
|
757
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
758
|
+
className: "dsh-billing-list",
|
|
759
|
+
children: summary.byDay.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
760
|
+
className: "dsh-billing-list-row",
|
|
761
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
762
|
+
className: "dsh-billing-session-title",
|
|
763
|
+
children: item.date
|
|
764
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
765
|
+
totals: item,
|
|
766
|
+
t
|
|
767
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
768
|
+
className: "dsh-billing-list-value",
|
|
769
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
770
|
+
totals: item,
|
|
771
|
+
t
|
|
772
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.requestCount", { count: item.requests }) })]
|
|
773
|
+
})]
|
|
774
|
+
}, item.date))
|
|
775
|
+
})]
|
|
776
|
+
})
|
|
777
|
+
]
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
function RequestRows({ requests, t }) {
|
|
781
|
+
const locale = t("locale.tag");
|
|
782
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
783
|
+
className: "dsh-billing-request-list",
|
|
784
|
+
children: requests.map((request) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
785
|
+
className: "dsh-billing-request-row",
|
|
786
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
787
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: new Date(request.time).toLocaleString(locale) }),
|
|
788
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: request.model ?? t("billing.unknownModel") }),
|
|
789
|
+
request.unknownReason !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
|
|
790
|
+
className: "dsh-billing-secondary",
|
|
791
|
+
children: t(`billing.reason.${request.unknownReason}`)
|
|
792
|
+
}) : null
|
|
793
|
+
] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
794
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.inputOutput", {
|
|
795
|
+
input: formatTokens(request.inputTokens),
|
|
796
|
+
output: formatTokens(request.outputTokens)
|
|
797
|
+
}) }),
|
|
798
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
|
|
799
|
+
className: "dsh-billing-secondary",
|
|
800
|
+
children: t("billing.tokensBreakdown", {
|
|
801
|
+
input: formatTokens(request.inputTokens),
|
|
802
|
+
output: formatTokens(request.outputTokens),
|
|
803
|
+
cacheHit: formatTokens(request.cacheReadTokens),
|
|
804
|
+
cacheWrite: formatTokens(request.cacheWriteTokens)
|
|
805
|
+
})
|
|
806
|
+
}),
|
|
807
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: request.costUsd === null ? t("billing.notPriced") : amount(request.costUsd, "USD", locale) })
|
|
808
|
+
] })]
|
|
809
|
+
}, `${request.turn}:${request.step}:${request.time}`))
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
function useUsageResult(loadUsage, options, revision) {
|
|
813
|
+
const [result, setResult] = (0, react.useState)();
|
|
814
|
+
const [loading, setLoading] = (0, react.useState)(true);
|
|
815
|
+
const load = (0, react.useCallback)(async (forceRefresh, signal) => {
|
|
816
|
+
setLoading(true);
|
|
817
|
+
try {
|
|
818
|
+
setResult(await loadUsage({
|
|
819
|
+
...options,
|
|
820
|
+
forceRefresh
|
|
821
|
+
}, signal));
|
|
822
|
+
} catch (error) {
|
|
823
|
+
if (!signal.aborted) setResult({
|
|
824
|
+
ok: false,
|
|
825
|
+
code: "UPSTREAM_UNAVAILABLE",
|
|
826
|
+
message: error instanceof Error ? error.message : ""
|
|
827
|
+
});
|
|
828
|
+
} finally {
|
|
829
|
+
if (!signal.aborted) setLoading(false);
|
|
830
|
+
}
|
|
831
|
+
}, [loadUsage, options]);
|
|
832
|
+
(0, react.useEffect)(() => {
|
|
833
|
+
const controller = new AbortController();
|
|
834
|
+
load(false, controller.signal);
|
|
835
|
+
return () => {
|
|
836
|
+
controller.abort();
|
|
837
|
+
};
|
|
838
|
+
}, [load, revision]);
|
|
839
|
+
return {
|
|
840
|
+
result,
|
|
841
|
+
loading,
|
|
842
|
+
refresh: () => {
|
|
843
|
+
const controller = new AbortController();
|
|
844
|
+
load(true, controller.signal);
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
function BillingOverview({ loadUsage, t }) {
|
|
849
|
+
const timeZone = (0, react.useMemo)(() => Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC", []);
|
|
850
|
+
const [range, setRange] = (0, react.useState)("30d");
|
|
851
|
+
const options = (0, react.useMemo)(() => ({
|
|
852
|
+
scope: "all",
|
|
853
|
+
timeZone,
|
|
854
|
+
...range === "all" ? {} : {
|
|
855
|
+
from: range === "today" ? localDateKey(timeZone) : dateDaysAgo(timeZone, range === "7d" ? 6 : 29),
|
|
856
|
+
to: localDateKey(timeZone)
|
|
857
|
+
}
|
|
858
|
+
}), [range, timeZone]);
|
|
859
|
+
const { result, loading, refresh } = useUsageResult(loadUsage, options, JSON.stringify(options));
|
|
860
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
861
|
+
className: "dsh-billing-section",
|
|
862
|
+
"aria-labelledby": "dsh-billing-title",
|
|
863
|
+
children: [
|
|
864
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
865
|
+
className: "dsh-balance-summary",
|
|
866
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
867
|
+
id: "dsh-billing-title",
|
|
868
|
+
className: "dsh-balance-heading",
|
|
869
|
+
children: t("billing.title")
|
|
870
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
871
|
+
className: "dsh-balance-copy",
|
|
872
|
+
children: t("billing.copy", { timeZone })
|
|
873
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
874
|
+
className: "dsh-billing-actions",
|
|
875
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
876
|
+
"aria-label": t("billing.range"),
|
|
877
|
+
value: range,
|
|
878
|
+
onChange: (event) => setRange(event.target.value),
|
|
879
|
+
children: [
|
|
880
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
881
|
+
value: "today",
|
|
882
|
+
children: t("billing.todayRange")
|
|
883
|
+
}),
|
|
884
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
885
|
+
value: "7d",
|
|
886
|
+
children: t("billing.sevenDays")
|
|
887
|
+
}),
|
|
888
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
889
|
+
value: "30d",
|
|
890
|
+
children: t("billing.thirtyDays")
|
|
891
|
+
}),
|
|
892
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
893
|
+
value: "all",
|
|
894
|
+
children: t("billing.allTime")
|
|
895
|
+
})
|
|
896
|
+
]
|
|
897
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
898
|
+
className: "dsh-balance-refresh",
|
|
899
|
+
type: "button",
|
|
900
|
+
disabled: loading,
|
|
901
|
+
onClick: refresh,
|
|
902
|
+
children: loading ? t("action.loading") : t("billing.refresh")
|
|
903
|
+
})]
|
|
904
|
+
})]
|
|
905
|
+
}),
|
|
906
|
+
loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
907
|
+
className: "dsh-balance-status",
|
|
908
|
+
role: "status",
|
|
909
|
+
children: t("billing.loading")
|
|
910
|
+
}) : null,
|
|
911
|
+
result !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorMessage, {
|
|
912
|
+
result,
|
|
913
|
+
t
|
|
914
|
+
}) : null,
|
|
915
|
+
result?.ok === true && result.scope === "all" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
916
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SummaryCards, {
|
|
917
|
+
summary: result.summary,
|
|
918
|
+
t
|
|
919
|
+
}),
|
|
920
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageTables, {
|
|
921
|
+
summary: result.summary,
|
|
922
|
+
t
|
|
923
|
+
}),
|
|
924
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
925
|
+
className: "dsh-balance-meta",
|
|
926
|
+
children: [t("meta.updated", { time: new Date(result.fetchedAt).toLocaleString(t("locale.tag")) }), result.source === "cache" ? t("meta.cached") : ""]
|
|
927
|
+
})
|
|
928
|
+
] }) : null
|
|
929
|
+
]
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
function BillingView({ loadUsage, sessionId, useSession, t }) {
|
|
933
|
+
const timeZone = (0, react.useMemo)(() => Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC", []);
|
|
934
|
+
const lastAssistant = useSession((snapshot) => {
|
|
935
|
+
for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
|
|
936
|
+
const node = snapshot.nodes[index];
|
|
937
|
+
if (node?.kind === "assistant") return `${node.seq}:${node.time}`;
|
|
938
|
+
}
|
|
939
|
+
return "empty";
|
|
940
|
+
});
|
|
941
|
+
const { result, loading, refresh } = useUsageResult(loadUsage, (0, react.useMemo)(() => ({
|
|
942
|
+
scope: "session",
|
|
943
|
+
sessionId,
|
|
944
|
+
timeZone
|
|
945
|
+
}), [sessionId, timeZone]), `${sessionId}:${lastAssistant}`);
|
|
946
|
+
const sessionResult = result?.ok === true && result.scope === "session" ? result : void 0;
|
|
947
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
948
|
+
className: "dsh-billing-view",
|
|
949
|
+
"aria-labelledby": "dsh-billing-view-title",
|
|
950
|
+
children: [
|
|
951
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
952
|
+
className: "dsh-balance-summary",
|
|
953
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
954
|
+
id: "dsh-billing-view-title",
|
|
955
|
+
className: "dsh-balance-heading",
|
|
956
|
+
children: t("billing.sessionTitle")
|
|
957
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
958
|
+
className: "dsh-balance-copy",
|
|
959
|
+
children: t("billing.sessionCopy")
|
|
960
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
961
|
+
className: "dsh-balance-refresh",
|
|
962
|
+
type: "button",
|
|
963
|
+
disabled: loading,
|
|
964
|
+
onClick: refresh,
|
|
965
|
+
children: loading ? t("action.loading") : t("billing.refresh")
|
|
966
|
+
})]
|
|
967
|
+
}),
|
|
968
|
+
loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
969
|
+
className: "dsh-balance-status",
|
|
970
|
+
role: "status",
|
|
971
|
+
children: t("billing.loading")
|
|
972
|
+
}) : null,
|
|
973
|
+
result !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorMessage, {
|
|
974
|
+
result,
|
|
975
|
+
t
|
|
976
|
+
}) : null,
|
|
977
|
+
sessionResult !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
978
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SummaryCards, {
|
|
979
|
+
summary: sessionResult.summary,
|
|
980
|
+
t
|
|
981
|
+
}),
|
|
982
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
983
|
+
className: "dsh-billing-list-section",
|
|
984
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.byModel") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelRows, {
|
|
985
|
+
summary: sessionResult.summary,
|
|
986
|
+
t
|
|
987
|
+
})]
|
|
988
|
+
}),
|
|
989
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
990
|
+
className: "dsh-billing-session-breakdown",
|
|
991
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.requestDetails") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RequestRows, {
|
|
992
|
+
requests: sessionResult.requests,
|
|
993
|
+
t
|
|
994
|
+
})]
|
|
995
|
+
}),
|
|
996
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
997
|
+
className: "dsh-balance-meta",
|
|
998
|
+
children: [t("meta.updated", { time: new Date(sessionResult.fetchedAt).toLocaleString(t("locale.tag")) }), sessionResult.source === "cache" ? t("meta.cached") : ""]
|
|
999
|
+
})
|
|
1000
|
+
] }) : null
|
|
1001
|
+
]
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
//#endregion
|
|
388
1005
|
//#region src/client/DeepSeekPanel.tsx
|
|
389
1006
|
/** Standalone DeepSeek settings page, placed immediately after Agent presets. */
|
|
390
|
-
function DeepSeekPanel({ loadBalance, loadModels, t }) {
|
|
1007
|
+
function DeepSeekPanel({ loadBalance, loadModels, loadUsage, t }) {
|
|
391
1008
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
392
1009
|
className: "dsh-deepseek-panel",
|
|
393
1010
|
children: [
|
|
@@ -402,6 +1019,14 @@ window.__ModuleLoader__.load({
|
|
|
402
1019
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelsSection, {
|
|
403
1020
|
loadModels,
|
|
404
1021
|
t
|
|
1022
|
+
}),
|
|
1023
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1024
|
+
className: "dsh-deepseek-divider",
|
|
1025
|
+
"aria-hidden": "true"
|
|
1026
|
+
}),
|
|
1027
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BillingOverview, {
|
|
1028
|
+
loadUsage,
|
|
1029
|
+
t
|
|
405
1030
|
})
|
|
406
1031
|
]
|
|
407
1032
|
});
|
|
@@ -413,11 +1038,13 @@ window.__ModuleLoader__.load({
|
|
|
413
1038
|
display: flex;
|
|
414
1039
|
flex-direction: column;
|
|
415
1040
|
gap: 28px;
|
|
416
|
-
max-width:
|
|
1041
|
+
max-width: 1040px;
|
|
417
1042
|
color: var(--dsw-alias-label-primary);
|
|
418
1043
|
}
|
|
419
1044
|
.dsh-balance-section,
|
|
420
|
-
.dsh-models-section
|
|
1045
|
+
.dsh-models-section,
|
|
1046
|
+
.dsh-billing-section,
|
|
1047
|
+
.dsh-billing-view {
|
|
421
1048
|
display: flex;
|
|
422
1049
|
flex-direction: column;
|
|
423
1050
|
gap: 14px;
|
|
@@ -479,6 +1106,82 @@ window.__ModuleLoader__.load({
|
|
|
479
1106
|
.dsh-balance-breakdown dt { color: var(--dsw-alias-label-tertiary); }
|
|
480
1107
|
.dsh-balance-breakdown dd { margin: 0; color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
|
|
481
1108
|
.dsh-balance-meta { margin: 0; color: var(--dsw-alias-label-tertiary); font-size: 12px; }
|
|
1109
|
+
.dsh-billing-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
|
|
1110
|
+
.dsh-billing-actions select {
|
|
1111
|
+
min-height: 32px;
|
|
1112
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
1113
|
+
border-radius: 16px;
|
|
1114
|
+
padding: 0 12px;
|
|
1115
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
1116
|
+
color: var(--dsw-alias-label-primary);
|
|
1117
|
+
font: inherit;
|
|
1118
|
+
font-size: 13px;
|
|
1119
|
+
}
|
|
1120
|
+
.dsh-billing-card-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
|
|
1121
|
+
.dsh-billing-card {
|
|
1122
|
+
display: flex;
|
|
1123
|
+
flex-direction: column;
|
|
1124
|
+
gap: 8px;
|
|
1125
|
+
min-height: 104px;
|
|
1126
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
1127
|
+
border-radius: 12px;
|
|
1128
|
+
padding: 16px;
|
|
1129
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
1130
|
+
}
|
|
1131
|
+
.dsh-billing-card > span,
|
|
1132
|
+
.dsh-billing-card > small { color: var(--dsw-alias-label-tertiary); font-size: 12px; }
|
|
1133
|
+
.dsh-billing-card > small { margin-top: auto; line-height: 1.45; }
|
|
1134
|
+
.dsh-billing-card-primary { border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 35%, var(--dsw-alias-border-l2)); }
|
|
1135
|
+
.dsh-billing-card[data-warning='true'] { border-color: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 45%, var(--dsw-alias-border-l2)); }
|
|
1136
|
+
.dsh-billing-card > strong { font-size: 22px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
|
|
1137
|
+
.dsh-billing-cost-value { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
|
|
1138
|
+
.dsh-billing-cost-value strong { font-size: 20px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
|
|
1139
|
+
.dsh-billing-cost-value span { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 1.35; }
|
|
1140
|
+
.dsh-billing-table-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
|
|
1141
|
+
.dsh-billing-list-section {
|
|
1142
|
+
min-width: 0;
|
|
1143
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
1144
|
+
border-radius: 12px;
|
|
1145
|
+
padding: 16px;
|
|
1146
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
1147
|
+
}
|
|
1148
|
+
.dsh-billing-list-section h3,
|
|
1149
|
+
.dsh-billing-session-breakdown h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
|
|
1150
|
+
.dsh-billing-list-wide { grid-column: 1 / -1; }
|
|
1151
|
+
.dsh-billing-list { display: flex; flex-direction: column; gap: 2px; }
|
|
1152
|
+
.dsh-billing-list-row {
|
|
1153
|
+
display: flex;
|
|
1154
|
+
align-items: center;
|
|
1155
|
+
justify-content: space-between;
|
|
1156
|
+
gap: 16px;
|
|
1157
|
+
min-height: 54px;
|
|
1158
|
+
border-bottom: 1px solid var(--dsw-alias-border-l2);
|
|
1159
|
+
padding: 9px 0;
|
|
1160
|
+
}
|
|
1161
|
+
.dsh-billing-list-row:last-child { border-bottom: 0; }
|
|
1162
|
+
.dsh-billing-list-row > div:first-child { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
1163
|
+
.dsh-billing-list-row code { color: var(--dsw-alias-label-primary); font-size: 12px; overflow-wrap: anywhere; }
|
|
1164
|
+
.dsh-billing-secondary { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 1.35; }
|
|
1165
|
+
.dsh-billing-list-value { display: flex; flex: none; flex-direction: column; align-items: flex-end; gap: 3px; text-align: right; }
|
|
1166
|
+
.dsh-billing-list-value > small { color: var(--dsw-alias-label-tertiary); font-size: 11px; }
|
|
1167
|
+
.dsh-billing-session-title { overflow: hidden; color: var(--dsw-alias-label-primary); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
|
|
1168
|
+
.dsh-billing-session-breakdown { border: 1px solid var(--dsw-alias-border-l2); border-radius: 12px; padding: 16px; background: var(--dsw-alias-bg-layer-3); }
|
|
1169
|
+
.dsh-billing-request-list { display: flex; flex-direction: column; }
|
|
1170
|
+
.dsh-billing-request-row {
|
|
1171
|
+
display: flex;
|
|
1172
|
+
align-items: center;
|
|
1173
|
+
justify-content: space-between;
|
|
1174
|
+
gap: 16px;
|
|
1175
|
+
border-bottom: 1px solid var(--dsw-alias-border-l2);
|
|
1176
|
+
padding: 11px 0;
|
|
1177
|
+
font-size: 12px;
|
|
1178
|
+
}
|
|
1179
|
+
.dsh-billing-request-row:last-child { border-bottom: 0; }
|
|
1180
|
+
.dsh-billing-request-row > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
1181
|
+
.dsh-billing-request-row > div:last-child { align-items: flex-end; text-align: right; }
|
|
1182
|
+
.dsh-billing-request-row span { color: var(--dsw-alias-label-tertiary); }
|
|
1183
|
+
.dsh-billing-request-row code { color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }
|
|
1184
|
+
.dsh-billing-request-row strong { font-variant-numeric: tabular-nums; }
|
|
482
1185
|
.dsh-model-count { display: flex; align-items: center; gap: 8px; font-size: 13px; }
|
|
483
1186
|
.dsh-model-count .dsh-balance-dot { background: var(--dsw-alias-state-success-primary); }
|
|
484
1187
|
.dsh-model-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
|
|
@@ -524,6 +1227,7 @@ window.__ModuleLoader__.load({
|
|
|
524
1227
|
vertical-align: 1px;
|
|
525
1228
|
}
|
|
526
1229
|
.dsh-balance-dock-dot[data-state='available'] { background: var(--dsw-alias-state-success-primary); }
|
|
1230
|
+
.dsh-balance-dock-dot[data-state='available'][data-peak='true'] { background: var(--dsw-alias-state-warn-primary); }
|
|
527
1231
|
.dsh-balance-dock-dot[data-state='empty'],
|
|
528
1232
|
.dsh-balance-dock-dot[data-state='error'] { background: var(--dsw-alias-state-error-primary); }
|
|
529
1233
|
.dsh-balance-dock-separator {
|
|
@@ -537,7 +1241,13 @@ window.__ModuleLoader__.load({
|
|
|
537
1241
|
@media (max-width: 640px) {
|
|
538
1242
|
.dsh-balance-summary { align-items: flex-start; }
|
|
539
1243
|
.dsh-balance-grid,
|
|
540
|
-
.dsh-model-grid
|
|
1244
|
+
.dsh-model-grid,
|
|
1245
|
+
.dsh-billing-card-grid,
|
|
1246
|
+
.dsh-billing-table-grid { grid-template-columns: 1fr; }
|
|
1247
|
+
.dsh-billing-list-wide { grid-column: auto; }
|
|
1248
|
+
.dsh-billing-actions { justify-content: flex-start; }
|
|
1249
|
+
.dsh-billing-request-row { align-items: flex-start; flex-direction: column; }
|
|
1250
|
+
.dsh-billing-request-row > div:last-child { align-items: flex-start; text-align: left; }
|
|
541
1251
|
}
|
|
542
1252
|
`;
|
|
543
1253
|
//#endregion
|
|
@@ -563,6 +1273,24 @@ window.__ModuleLoader__.load({
|
|
|
563
1273
|
if (typeof value !== "object" || value === null || !("ok" in value) || typeof value.ok !== "boolean") throw new Error("模型插件收到了无法识别的 Host 响应");
|
|
564
1274
|
return value;
|
|
565
1275
|
}
|
|
1276
|
+
async function loadUsage(options, signal) {
|
|
1277
|
+
const params = new URLSearchParams({
|
|
1278
|
+
scope: options.scope,
|
|
1279
|
+
timeZone: options.timeZone
|
|
1280
|
+
});
|
|
1281
|
+
if (options.sessionId !== void 0) params.set("sessionId", options.sessionId);
|
|
1282
|
+
if (options.from !== void 0) params.set("from", options.from);
|
|
1283
|
+
if (options.to !== void 0) params.set("to", options.to);
|
|
1284
|
+
if (options.forceRefresh === true) params.set("refresh", "1");
|
|
1285
|
+
const value = await (await fetch(`${USAGE_ROUTE}?${params.toString()}`, {
|
|
1286
|
+
method: "GET",
|
|
1287
|
+
headers: { accept: "application/json" },
|
|
1288
|
+
cache: "no-store",
|
|
1289
|
+
signal
|
|
1290
|
+
})).json();
|
|
1291
|
+
if (typeof value !== "object" || value === null || !("ok" in value) || typeof value.ok !== "boolean") throw new Error("消费统计插件收到了无法识别的 Host 响应");
|
|
1292
|
+
return value;
|
|
1293
|
+
}
|
|
566
1294
|
/** Register a standalone Settings page and an ambient composer balance readout. */
|
|
567
1295
|
function apply(ctx) {
|
|
568
1296
|
ctx.effect(() => ctx.locale.register(LOCALE_NS, {
|
|
@@ -588,9 +1316,18 @@ window.__ModuleLoader__.load({
|
|
|
588
1316
|
locale: LOCALE_NS,
|
|
589
1317
|
inject: () => ({
|
|
590
1318
|
loadBalance,
|
|
591
|
-
loadModels
|
|
1319
|
+
loadModels,
|
|
1320
|
+
loadUsage
|
|
592
1321
|
})
|
|
593
1322
|
}, DeepSeekPanel));
|
|
1323
|
+
ctx.slots.inject("conversation.view", () => ctx.slots.register({
|
|
1324
|
+
name: "conversation.view",
|
|
1325
|
+
id: "deepseek-billing",
|
|
1326
|
+
order: 30,
|
|
1327
|
+
label: () => t("billing.tab"),
|
|
1328
|
+
locale: LOCALE_NS,
|
|
1329
|
+
inject: () => ({ loadUsage })
|
|
1330
|
+
}, BillingView));
|
|
594
1331
|
ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
|
|
595
1332
|
name: "conversation.composer.dock",
|
|
596
1333
|
id: "deepseek-balance",
|