@pinkbanana/dsh-balance 0.6.0 → 0.7.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 +33 -7
- package/README_EN.md +33 -7
- package/lib/client.js +196 -99
- package/lib/client.js.map +1 -1
- package/lib/index.js +104 -38
- package/lib/index.js.map +1 -1
- package/lib/types/balance.d.ts +1 -0
- package/lib/types/billing.d.ts +3 -2
- package/lib/types/client/BalanceDock.d.ts +9 -2
- package/lib/types/client/BillingTab.d.ts +5 -2
- package/lib/types/client/locales.d.ts +6 -2
- package/lib/types/client/styles.d.ts +1 -1
- package/lib/types/index.d.ts +4 -2
- package/lib/types/providers.d.ts +19 -0
- package/package.json +9 -3
package/lib/client.js
CHANGED
|
@@ -12,6 +12,34 @@ window.__ModuleLoader__.load({
|
|
|
12
12
|
/** The same-origin endpoint that proxies the selected provider’s `/models` API. */
|
|
13
13
|
const MODELS_ROUTE = "/dsh-balance/api/models";
|
|
14
14
|
//#endregion
|
|
15
|
+
//#region src/providers.ts
|
|
16
|
+
/** Browser-safe provider metadata. Credentials and wire parsers stay on the Host. */
|
|
17
|
+
const BALANCE_PROVIDERS = [
|
|
18
|
+
{
|
|
19
|
+
id: "deepseek",
|
|
20
|
+
name: "DeepSeek",
|
|
21
|
+
apiKeyRef: "DEEPSEEK_API_KEY",
|
|
22
|
+
baseUrl: "https://api.deepseek.com"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "stepfun",
|
|
26
|
+
name: "StepFun",
|
|
27
|
+
apiKeyRef: "STEPFUN_API_KEY",
|
|
28
|
+
baseUrl: "https://api.stepfun.com/v1"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "tokener",
|
|
32
|
+
name: "Tokener",
|
|
33
|
+
apiKeyRef: "TOKENER_API_KEY",
|
|
34
|
+
baseUrl: "https://api.tokener.ai/v1",
|
|
35
|
+
balanceApiKeyRef: "TOKENER_MANAGEMENT_TOKEN",
|
|
36
|
+
balanceBaseUrl: "https://console.tokener.ai/api/v1"
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
function findBalanceProvider(id) {
|
|
40
|
+
return BALANCE_PROVIDERS.find((provider) => provider.id === id.trim().toLowerCase());
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
15
43
|
//#region src/pricing.ts
|
|
16
44
|
/** Shared DeepSeek pricing schedule used by Host billing and the client indicator. */
|
|
17
45
|
const BEIJING_OFFSET_MS = 288e5;
|
|
@@ -112,7 +140,22 @@ window.__ModuleLoader__.load({
|
|
|
112
140
|
const REFRESH_INTERVAL_MS = 6e4;
|
|
113
141
|
const PEAK_TICK_MS = 3e4;
|
|
114
142
|
/** Compact ambient balance readout below the active-session composer card. */
|
|
115
|
-
function BalanceDock({ loadBalance, t }) {
|
|
143
|
+
function BalanceDock({ selection, loadBalance, t, sessionId }) {
|
|
144
|
+
const snapshot = (0, react.useSyncExternalStore)(selection.store.subscribe, selection.store.getSnapshot);
|
|
145
|
+
(0, react.useEffect)(() => {
|
|
146
|
+
if (selection.store.getSnapshot().status === "idle") selection.load().catch(() => {});
|
|
147
|
+
}, [selection]);
|
|
148
|
+
const current = snapshot.current;
|
|
149
|
+
const provider = current === null ? void 0 : findBalanceProvider(current.provider);
|
|
150
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProviderBalanceDock, {
|
|
151
|
+
provider: provider?.id,
|
|
152
|
+
providerName: provider?.name ?? current?.provider,
|
|
153
|
+
model: current?.model,
|
|
154
|
+
loadBalance,
|
|
155
|
+
t
|
|
156
|
+
}, `${sessionId}:${current?.provider ?? ""}`);
|
|
157
|
+
}
|
|
158
|
+
function ProviderBalanceDock({ provider, providerName, model, loadBalance, t }) {
|
|
116
159
|
const [result, setResult] = (0, react.useState)();
|
|
117
160
|
const [now, setNow] = (0, react.useState)(() => /* @__PURE__ */ new Date());
|
|
118
161
|
(0, react.useEffect)(() => {
|
|
@@ -122,12 +165,13 @@ window.__ModuleLoader__.load({
|
|
|
122
165
|
};
|
|
123
166
|
}, []);
|
|
124
167
|
(0, react.useEffect)(() => {
|
|
168
|
+
if (provider === void 0) return;
|
|
125
169
|
let controller;
|
|
126
170
|
const load = () => {
|
|
127
171
|
controller?.abort();
|
|
128
172
|
controller = new AbortController();
|
|
129
173
|
const signal = controller.signal;
|
|
130
|
-
loadBalance(false, signal).then((value) => {
|
|
174
|
+
loadBalance(false, signal, provider).then((value) => {
|
|
131
175
|
if (!signal.aborted) setResult(value);
|
|
132
176
|
}).catch(() => {
|
|
133
177
|
if (!signal.aborted) setResult({
|
|
@@ -143,16 +187,24 @@ window.__ModuleLoader__.load({
|
|
|
143
187
|
window.clearInterval(timer);
|
|
144
188
|
controller?.abort();
|
|
145
189
|
};
|
|
146
|
-
}, [loadBalance]);
|
|
190
|
+
}, [loadBalance, provider]);
|
|
147
191
|
const summary = (0, react.useMemo)(() => {
|
|
192
|
+
if (providerName === void 0) return t("dock.noSelection");
|
|
193
|
+
if (provider === void 0) return t("error.UNSUPPORTED_PROVIDER");
|
|
148
194
|
if (result === void 0) return t("dock.loading");
|
|
149
195
|
if (!result.ok) return t("dock.unavailable");
|
|
150
196
|
if (result.balanceInfos.length === 0) return t("dock.empty");
|
|
151
197
|
return result.balanceInfos.map((info) => `${info.currency} ${displayAmount(info.totalBalance, info.currency, t("locale.tag"))}`).join(" · ");
|
|
152
|
-
}, [
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
198
|
+
}, [
|
|
199
|
+
result,
|
|
200
|
+
t,
|
|
201
|
+
provider,
|
|
202
|
+
providerName
|
|
203
|
+
]);
|
|
204
|
+
const state = provider === void 0 ? "unknown" : result === void 0 ? "loading" : !result.ok ? "error" : result.isAvailable === null ? "unknown" : result.isAvailable ? "available" : "empty";
|
|
205
|
+
const accessibleState = result?.ok === true && result.isAvailable !== null ? t(result.isAvailable ? "balance.available" : "balance.unavailable") : void 0;
|
|
206
|
+
const label = providerName === void 0 ? t("nav.balance") : t("dock.label", { provider: providerName });
|
|
207
|
+
const pricingActive = provider === "deepseek" && now.getTime() >= PEAK_EFFECTIVE_FROM;
|
|
156
208
|
const isPeak = pricingActive && isPeakHour(now);
|
|
157
209
|
const periodLabel = pricingActive ? t(isPeak ? "pricing.peak" : "pricing.offPeak") : void 0;
|
|
158
210
|
const periodTitle = pricingActive ? t(isPeak ? "pricing.peakHint" : "pricing.offPeakHint", { time: formatClockTime(nextPeriodChange(now), t("locale.tag")) }) : void 0;
|
|
@@ -161,7 +213,7 @@ window.__ModuleLoader__.load({
|
|
|
161
213
|
role: "status",
|
|
162
214
|
"aria-live": "polite",
|
|
163
215
|
title: periodTitle,
|
|
164
|
-
"aria-label": `${
|
|
216
|
+
"aria-label": `${label}${model === void 0 ? "" : ` / ${model}`}: ${summary}${accessibleState === void 0 ? "" : `. ${accessibleState}`}${periodLabel === void 0 ? "" : `. ${periodLabel}`}`,
|
|
165
217
|
children: [
|
|
166
218
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
167
219
|
className: "dsh-balance-dock-dot",
|
|
@@ -169,7 +221,12 @@ window.__ModuleLoader__.load({
|
|
|
169
221
|
"data-peak": isPeak ? "true" : void 0,
|
|
170
222
|
"aria-hidden": "true"
|
|
171
223
|
}),
|
|
172
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children:
|
|
224
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label }),
|
|
225
|
+
model === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
226
|
+
className: "dsh-balance-dock-model",
|
|
227
|
+
title: model,
|
|
228
|
+
children: model
|
|
229
|
+
}),
|
|
173
230
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
174
231
|
className: "dsh-balance-dock-separator",
|
|
175
232
|
"aria-hidden": "true",
|
|
@@ -183,23 +240,6 @@ window.__ModuleLoader__.load({
|
|
|
183
240
|
});
|
|
184
241
|
}
|
|
185
242
|
//#endregion
|
|
186
|
-
//#region src/providers.ts
|
|
187
|
-
/** Browser-safe provider metadata. Credentials and wire parsers stay on the Host. */
|
|
188
|
-
const BALANCE_PROVIDERS = [{
|
|
189
|
-
id: "deepseek",
|
|
190
|
-
name: "DeepSeek",
|
|
191
|
-
apiKeyRef: "DEEPSEEK_API_KEY",
|
|
192
|
-
baseUrl: "https://api.deepseek.com"
|
|
193
|
-
}, {
|
|
194
|
-
id: "stepfun",
|
|
195
|
-
name: "StepFun",
|
|
196
|
-
apiKeyRef: "STEPFUN_API_KEY",
|
|
197
|
-
baseUrl: "https://api.stepfun.com/v1"
|
|
198
|
-
}];
|
|
199
|
-
function findBalanceProvider(id) {
|
|
200
|
-
return BALANCE_PROVIDERS.find((provider) => provider.id === id.trim().toLowerCase());
|
|
201
|
-
}
|
|
202
|
-
//#endregion
|
|
203
243
|
//#region src/client/locales.ts
|
|
204
244
|
const LOCALE_NS = "dsh-balance";
|
|
205
245
|
/** Simplified Chinese dictionary and source of truth for the namespace key set. */
|
|
@@ -220,6 +260,7 @@ window.__ModuleLoader__.load({
|
|
|
220
260
|
"balance.prepaid": "预付费账户",
|
|
221
261
|
"balance.postpaid": "后付费账户",
|
|
222
262
|
"balance.totalsNote": "总充值与总赠送金额为账户累计金额,不代表当前剩余余额;账户类型不表示服务可用状态。",
|
|
263
|
+
"balance.setupTokener": "在 Tokener 账户设置创建个人访问令牌(PAT),配置为 TOKENER_MANAGEMENT_TOKEN;模型列表使用独立的 TOKENER_API_KEY。自定义凭据请配置 balanceApiKeyRef 与 apiKeyRef。",
|
|
223
264
|
"balance.setupDeepSeek": "在“设置 → 模型”保存 DeepSeek API 密钥,或配置 {ref} 环境变量。",
|
|
224
265
|
"balance.setup": "在“设置 → 模型”添加自定义提供方,Provider ID 填写 {provider}(大小写不限),并保存 API 密钥。默认凭据为 {ref};自定义凭据请检查插件配置。",
|
|
225
266
|
"error.UNSUPPORTED_PROVIDER": "暂不支持此提供方的余额查询",
|
|
@@ -234,7 +275,8 @@ window.__ModuleLoader__.load({
|
|
|
234
275
|
"balance.empty": "提供方未返回任何币种余额。",
|
|
235
276
|
"balance.toppedUp": "充值余额",
|
|
236
277
|
"balance.granted": "赠送余额",
|
|
237
|
-
"dock.label": "
|
|
278
|
+
"dock.label": "{provider} 余额",
|
|
279
|
+
"dock.noSelection": "尚未获取当前模型",
|
|
238
280
|
"dock.loading": "查询中…",
|
|
239
281
|
"dock.unavailable": "暂时无法获取",
|
|
240
282
|
"dock.empty": "暂无余额信息",
|
|
@@ -249,6 +291,7 @@ window.__ModuleLoader__.load({
|
|
|
249
291
|
"billing.tab": "消费",
|
|
250
292
|
"billing.title": "API 消费统计",
|
|
251
293
|
"billing.copy": "按会话、模型和日期统计实际 provider usage;日期按 {timeZone} 分组。",
|
|
294
|
+
"billing.provider": "统计提供方",
|
|
252
295
|
"billing.range": "统计范围",
|
|
253
296
|
"billing.todayRange": "今日",
|
|
254
297
|
"billing.sevenDays": "最近 7 天",
|
|
@@ -277,6 +320,7 @@ window.__ModuleLoader__.load({
|
|
|
277
320
|
"billing.unknownModel": "未知模型",
|
|
278
321
|
"billing.inputOutput": "输入 {input} · 输出 {output}",
|
|
279
322
|
"billing.notPriced": "未计费",
|
|
323
|
+
"billing.partial": "仅包含已知价格的请求",
|
|
280
324
|
"billing.reason.missing-usage": "缺少 provider usage",
|
|
281
325
|
"billing.reason.unknown-provider": "未知 provider",
|
|
282
326
|
"billing.reason.unknown-model": "未知模型价格",
|
|
@@ -296,7 +340,7 @@ window.__ModuleLoader__.load({
|
|
|
296
340
|
"error.INVALID_API_KEY": "API 密钥无效或没有查询权限",
|
|
297
341
|
"error.INVALID_RESPONSE": "返回了无法识别的响应",
|
|
298
342
|
"error.METHOD_NOT_ALLOWED": "请求方法不受支持",
|
|
299
|
-
"error.MISSING_API_KEY": "
|
|
343
|
+
"error.MISSING_API_KEY": "未配置查询凭据",
|
|
300
344
|
"error.RATE_LIMITED": "API 请求过于频繁,请稍后重试",
|
|
301
345
|
"error.UPSTREAM_ERROR": "API 返回了错误",
|
|
302
346
|
"error.UPSTREAM_TIMEOUT": "查询 API 超时",
|
|
@@ -320,6 +364,7 @@ window.__ModuleLoader__.load({
|
|
|
320
364
|
"balance.prepaid": "Prepaid account",
|
|
321
365
|
"balance.postpaid": "Postpaid account",
|
|
322
366
|
"balance.totalsNote": "Cash and voucher totals are cumulative amounts, not remaining balances. Account type does not indicate service availability.",
|
|
367
|
+
"balance.setupTokener": "Create a personal access token (PAT) in Tokener account settings and configure TOKENER_MANAGEMENT_TOKEN. Models use a separate TOKENER_API_KEY. Set balanceApiKeyRef and apiKeyRef for custom credentials.",
|
|
323
368
|
"balance.setupDeepSeek": "Save your DeepSeek API key in Settings → Models, or set the {ref} environment variable.",
|
|
324
369
|
"balance.setup": "Add a custom provider in Settings → Models with Provider ID {provider} (case-insensitive), then save your API key. The default credential is {ref}; check plugin configuration for custom references.",
|
|
325
370
|
"error.UNSUPPORTED_PROVIDER": "Balance queries are not supported for this provider",
|
|
@@ -334,7 +379,8 @@ window.__ModuleLoader__.load({
|
|
|
334
379
|
"balance.empty": "The provider returned no currency balances.",
|
|
335
380
|
"balance.toppedUp": "Topped-up balance",
|
|
336
381
|
"balance.granted": "Granted balance",
|
|
337
|
-
"dock.label": "
|
|
382
|
+
"dock.label": "{provider} Balance",
|
|
383
|
+
"dock.noSelection": "Current model not available yet",
|
|
338
384
|
"dock.loading": "Loading…",
|
|
339
385
|
"dock.unavailable": "Temporarily unavailable",
|
|
340
386
|
"dock.empty": "No balance information",
|
|
@@ -349,6 +395,7 @@ window.__ModuleLoader__.load({
|
|
|
349
395
|
"billing.tab": "Usage",
|
|
350
396
|
"billing.title": "API Usage",
|
|
351
397
|
"billing.copy": "Actual provider usage grouped by session, model, and date; dates use {timeZone}.",
|
|
398
|
+
"billing.provider": "Usage provider",
|
|
352
399
|
"billing.range": "Usage range",
|
|
353
400
|
"billing.todayRange": "Today",
|
|
354
401
|
"billing.sevenDays": "Last 7 days",
|
|
@@ -377,6 +424,7 @@ window.__ModuleLoader__.load({
|
|
|
377
424
|
"billing.unknownModel": "Unknown model",
|
|
378
425
|
"billing.inputOutput": "Input {input} · Output {output}",
|
|
379
426
|
"billing.notPriced": "Unpriced",
|
|
427
|
+
"billing.partial": "Requests with known pricing only",
|
|
380
428
|
"billing.reason.missing-usage": "Provider usage is missing",
|
|
381
429
|
"billing.reason.unknown-provider": "Unknown provider",
|
|
382
430
|
"billing.reason.unknown-model": "Unknown model pricing",
|
|
@@ -396,7 +444,7 @@ window.__ModuleLoader__.load({
|
|
|
396
444
|
"error.INVALID_API_KEY": "The API key is invalid or lacks permission",
|
|
397
445
|
"error.INVALID_RESPONSE": "The provider returned an unrecognized response",
|
|
398
446
|
"error.METHOD_NOT_ALLOWED": "This request method is not supported",
|
|
399
|
-
"error.MISSING_API_KEY": "
|
|
447
|
+
"error.MISSING_API_KEY": "Query credentials are not configured.",
|
|
400
448
|
"error.RATE_LIMITED": "Too many API requests. Try again later.",
|
|
401
449
|
"error.UPSTREAM_ERROR": "The API returned an error",
|
|
402
450
|
"error.UPSTREAM_TIMEOUT": "The API request timed out",
|
|
@@ -514,7 +562,7 @@ window.__ModuleLoader__.load({
|
|
|
514
562
|
providerName,
|
|
515
563
|
" / ",
|
|
516
564
|
t(errorLocaleKey(result.code))
|
|
517
|
-
] }), result.code === "MISSING_API_KEY" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t(provider === "deepseek" ? "balance.setupDeepSeek" : "balance.setup", {
|
|
565
|
+
] }), result.code === "MISSING_API_KEY" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t(provider === "tokener" ? "balance.setupTokener" : provider === "deepseek" ? "balance.setupDeepSeek" : "balance.setup", {
|
|
518
566
|
provider: providerName,
|
|
519
567
|
ref: findBalanceProvider(provider).apiKeyRef
|
|
520
568
|
}) }) : null]
|
|
@@ -684,9 +732,9 @@ window.__ModuleLoader__.load({
|
|
|
684
732
|
return `${values.year ?? "0000"}-${values.month ?? "00"}-${values.day ?? "00"}`;
|
|
685
733
|
}
|
|
686
734
|
function dateDaysAgo(timeZone, days) {
|
|
687
|
-
const local =
|
|
688
|
-
local.
|
|
689
|
-
return
|
|
735
|
+
const local = /* @__PURE__ */ new Date(`${localDateKey(timeZone)}T12:00:00Z`);
|
|
736
|
+
local.setUTCDate(local.getUTCDate() - days);
|
|
737
|
+
return local.toISOString().slice(0, 10);
|
|
690
738
|
}
|
|
691
739
|
function totalForDay(summary, date) {
|
|
692
740
|
return summary.byDay.find((item) => item.date === date) ?? {
|
|
@@ -712,13 +760,18 @@ window.__ModuleLoader__.load({
|
|
|
712
760
|
}
|
|
713
761
|
function CostLabel({ totals, t }) {
|
|
714
762
|
const locale = t("locale.tag");
|
|
763
|
+
const unpriced = totals.requests > 0 && totals.pricedRequests === 0;
|
|
715
764
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
716
765
|
className: "dsh-billing-cost-value",
|
|
717
|
-
children: [
|
|
718
|
-
amount(totals.
|
|
719
|
-
" ",
|
|
720
|
-
|
|
721
|
-
|
|
766
|
+
children: [
|
|
767
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: unpriced ? t("billing.notPriced") : amount(totals.costUsd, "USD", locale) }),
|
|
768
|
+
totals.unpricedRequests > 0 && !unpriced ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.partial") }) : null,
|
|
769
|
+
totals.costCny !== null && !unpriced ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
|
|
770
|
+
amount(totals.costCny, "CNY", locale),
|
|
771
|
+
" ",
|
|
772
|
+
t("billing.fixedRate")
|
|
773
|
+
] }) : null
|
|
774
|
+
]
|
|
722
775
|
});
|
|
723
776
|
}
|
|
724
777
|
function SummaryCards({ summary, t }) {
|
|
@@ -752,7 +805,7 @@ window.__ModuleLoader__.load({
|
|
|
752
805
|
className: "dsh-billing-card",
|
|
753
806
|
children: [
|
|
754
807
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.tokens") }),
|
|
755
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: formatTokens(summary.totals.inputTokens + summary.totals.outputTokens) }),
|
|
808
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: formatTokens(summary.totals.inputTokens + summary.totals.outputTokens + summary.totals.cacheReadTokens + summary.totals.cacheWriteTokens) }),
|
|
756
809
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
757
810
|
totals: summary.totals,
|
|
758
811
|
t
|
|
@@ -803,13 +856,9 @@ window.__ModuleLoader__.load({
|
|
|
803
856
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
804
857
|
totals: item,
|
|
805
858
|
t
|
|
806
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", { children: [
|
|
807
|
-
t("billing.requestCount", { count: item.requests }),
|
|
808
|
-
" · ",
|
|
809
|
-
t("billing.share", { percent: `${summary.totals.costUsd === 0 ? 0 : Math.round(item.costUsd / summary.totals.costUsd * 100)}%` })
|
|
810
|
-
] })]
|
|
859
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", { children: [t("billing.requestCount", { count: item.requests }), item.pricedRequests > 0 && summary.totals.costUsd > 0 ? ` · ${t("billing.share", { percent: `${Math.round(item.costUsd / summary.totals.costUsd * 100)}%` })}` : ""] })]
|
|
811
860
|
})]
|
|
812
|
-
},
|
|
861
|
+
}, JSON.stringify([item.provider, item.model])))
|
|
813
862
|
});
|
|
814
863
|
}
|
|
815
864
|
function UsageTables({ summary, t }) {
|
|
@@ -884,7 +933,11 @@ window.__ModuleLoader__.load({
|
|
|
884
933
|
className: "dsh-billing-request-row",
|
|
885
934
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
886
935
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: new Date(request.time).toLocaleString(locale) }),
|
|
887
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
936
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("code", { children: [
|
|
937
|
+
request.provider ?? "?",
|
|
938
|
+
" / ",
|
|
939
|
+
request.model ?? t("billing.unknownModel")
|
|
940
|
+
] }),
|
|
888
941
|
request.unknownReason !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
|
|
889
942
|
className: "dsh-billing-secondary",
|
|
890
943
|
children: t(`billing.reason.${request.unknownReason}`)
|
|
@@ -909,52 +962,69 @@ window.__ModuleLoader__.load({
|
|
|
909
962
|
});
|
|
910
963
|
}
|
|
911
964
|
function useUsageResult(loadUsage, options, revision) {
|
|
912
|
-
const [
|
|
965
|
+
const [state, setState] = (0, react.useState)();
|
|
913
966
|
const [loading, setLoading] = (0, react.useState)(true);
|
|
914
|
-
const
|
|
967
|
+
const active = (0, react.useRef)();
|
|
968
|
+
const load = (0, react.useCallback)(async (forceRefresh) => {
|
|
969
|
+
active.current?.abort();
|
|
970
|
+
const controller = new AbortController();
|
|
971
|
+
active.current = controller;
|
|
972
|
+
const { signal } = controller;
|
|
915
973
|
setLoading(true);
|
|
916
974
|
try {
|
|
917
|
-
|
|
975
|
+
const result = await loadUsage({
|
|
918
976
|
...options,
|
|
919
977
|
forceRefresh
|
|
920
|
-
}, signal)
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
978
|
+
}, signal);
|
|
979
|
+
if (!signal.aborted) setState({
|
|
980
|
+
options,
|
|
981
|
+
result
|
|
982
|
+
});
|
|
983
|
+
} catch {
|
|
984
|
+
if (!signal.aborted) setState({
|
|
985
|
+
options,
|
|
986
|
+
result: {
|
|
987
|
+
ok: false,
|
|
988
|
+
code: "UPSTREAM_UNAVAILABLE",
|
|
989
|
+
message: ""
|
|
990
|
+
}
|
|
926
991
|
});
|
|
927
992
|
} finally {
|
|
928
993
|
if (!signal.aborted) setLoading(false);
|
|
929
994
|
}
|
|
930
995
|
}, [loadUsage, options]);
|
|
931
996
|
(0, react.useEffect)(() => {
|
|
932
|
-
|
|
933
|
-
load(false, controller.signal);
|
|
997
|
+
load(false);
|
|
934
998
|
return () => {
|
|
935
|
-
|
|
999
|
+
active.current?.abort();
|
|
936
1000
|
};
|
|
937
1001
|
}, [load, revision]);
|
|
938
1002
|
return {
|
|
939
|
-
result,
|
|
1003
|
+
result: state?.options === options ? state.result : void 0,
|
|
940
1004
|
loading,
|
|
941
1005
|
refresh: () => {
|
|
942
|
-
|
|
943
|
-
load(true, controller.signal);
|
|
1006
|
+
load(true);
|
|
944
1007
|
}
|
|
945
1008
|
};
|
|
946
1009
|
}
|
|
947
|
-
function BillingOverview({ loadUsage, t }) {
|
|
1010
|
+
function BillingOverview({ loadUsage, t, provider }) {
|
|
1011
|
+
const [providerScope, setProviderScope] = (0, react.useState)("selected");
|
|
1012
|
+
const selectedProvider = providerScope === "all" ? void 0 : provider;
|
|
948
1013
|
const timeZone = (0, react.useMemo)(() => Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC", []);
|
|
949
1014
|
const [range, setRange] = (0, react.useState)("30d");
|
|
950
1015
|
const options = (0, react.useMemo)(() => ({
|
|
951
1016
|
scope: "all",
|
|
1017
|
+
...selectedProvider === void 0 ? {} : { provider: selectedProvider },
|
|
952
1018
|
timeZone,
|
|
953
1019
|
...range === "all" ? {} : {
|
|
954
1020
|
from: range === "today" ? localDateKey(timeZone) : dateDaysAgo(timeZone, range === "7d" ? 6 : 29),
|
|
955
1021
|
to: localDateKey(timeZone)
|
|
956
1022
|
}
|
|
957
|
-
}), [
|
|
1023
|
+
}), [
|
|
1024
|
+
range,
|
|
1025
|
+
timeZone,
|
|
1026
|
+
selectedProvider
|
|
1027
|
+
]);
|
|
958
1028
|
const { result, loading, refresh } = useUsageResult(loadUsage, options, JSON.stringify(options));
|
|
959
1029
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
960
1030
|
className: "dsh-billing-section",
|
|
@@ -971,35 +1041,50 @@ window.__ModuleLoader__.load({
|
|
|
971
1041
|
children: t("billing.copy", { timeZone })
|
|
972
1042
|
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
973
1043
|
className: "dsh-billing-actions",
|
|
974
|
-
children: [
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
980
|
-
value: "
|
|
981
|
-
children:
|
|
982
|
-
}),
|
|
983
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
984
|
-
value: "7d",
|
|
985
|
-
children: t("billing.sevenDays")
|
|
986
|
-
}),
|
|
987
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
988
|
-
value: "30d",
|
|
989
|
-
children: t("billing.thirtyDays")
|
|
990
|
-
}),
|
|
991
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1044
|
+
children: [
|
|
1045
|
+
provider === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
1046
|
+
"aria-label": t("billing.provider"),
|
|
1047
|
+
value: providerScope,
|
|
1048
|
+
onChange: (event) => setProviderScope(event.target.value),
|
|
1049
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1050
|
+
value: "selected",
|
|
1051
|
+
children: findBalanceProvider(provider)?.name ?? provider
|
|
1052
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
992
1053
|
value: "all",
|
|
993
|
-
children: t("
|
|
994
|
-
})
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1054
|
+
children: t("panel.allProviders")
|
|
1055
|
+
})]
|
|
1056
|
+
}),
|
|
1057
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
1058
|
+
"aria-label": t("billing.range"),
|
|
1059
|
+
value: range,
|
|
1060
|
+
onChange: (event) => setRange(event.target.value),
|
|
1061
|
+
children: [
|
|
1062
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1063
|
+
value: "today",
|
|
1064
|
+
children: t("billing.todayRange")
|
|
1065
|
+
}),
|
|
1066
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1067
|
+
value: "7d",
|
|
1068
|
+
children: t("billing.sevenDays")
|
|
1069
|
+
}),
|
|
1070
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1071
|
+
value: "30d",
|
|
1072
|
+
children: t("billing.thirtyDays")
|
|
1073
|
+
}),
|
|
1074
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1075
|
+
value: "all",
|
|
1076
|
+
children: t("billing.allTime")
|
|
1077
|
+
})
|
|
1078
|
+
]
|
|
1079
|
+
}),
|
|
1080
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1081
|
+
className: "dsh-balance-refresh",
|
|
1082
|
+
type: "button",
|
|
1083
|
+
disabled: loading,
|
|
1084
|
+
onClick: refresh,
|
|
1085
|
+
children: loading ? t("action.loading") : t("billing.refresh")
|
|
1086
|
+
})
|
|
1087
|
+
]
|
|
1003
1088
|
})]
|
|
1004
1089
|
}),
|
|
1005
1090
|
loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
@@ -1163,11 +1248,12 @@ window.__ModuleLoader__.load({
|
|
|
1163
1248
|
loadModels,
|
|
1164
1249
|
t
|
|
1165
1250
|
}, `models-${provider}`),
|
|
1166
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1251
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1167
1252
|
className: "dsh-ledger-section-label",
|
|
1168
|
-
children:
|
|
1253
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["03 / ", t("panel.activity")] })
|
|
1169
1254
|
}),
|
|
1170
1255
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BillingOverview, {
|
|
1256
|
+
provider,
|
|
1171
1257
|
loadUsage,
|
|
1172
1258
|
t
|
|
1173
1259
|
})
|
|
@@ -1209,8 +1295,8 @@ window.__ModuleLoader__.load({
|
|
|
1209
1295
|
.dsh-ledger-orbit i:nth-child(3) { transform: rotate(85deg) scaleX(.5); }
|
|
1210
1296
|
.dsh-ledger-orbit span { display: grid; place-items: center; width: 40px; height: 40px; background: #d7ed9d; color: #233316; border-radius: 50%; font-size: 24px; transition: transform .4s ease; }
|
|
1211
1297
|
.dsh-ledger-header:hover .dsh-ledger-orbit span { transform: rotate(45deg); }
|
|
1212
|
-
.dsh-provider-switch { display: flex; gap: 8px; padding-bottom: 24px; border-bottom: 1px solid var(--ledger-line); }
|
|
1213
|
-
.dsh-provider-switch button { display: flex; align-items: center; gap: 14px; flex: 1;
|
|
1298
|
+
.dsh-provider-switch { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 24px; border-bottom: 1px solid var(--ledger-line); }
|
|
1299
|
+
.dsh-provider-switch button { display: flex; align-items: center; gap: 14px; flex: 1 1 140px; min-width: 0; min-height: 58px; padding: 12px 18px; border: 1px solid var(--ledger-line); border-radius: 4px; color: var(--ledger-ink); background: transparent; font: inherit; font-size: 16px; cursor: pointer; transition: background .2s, transform .2s; }
|
|
1214
1300
|
.dsh-provider-switch button:hover { background: var(--ledger-paper); transform: translateY(-2px); }
|
|
1215
1301
|
.dsh-provider-switch button[aria-pressed='true'] { color: #e5f6bd; background: #25352e; border-color: #25352e; }
|
|
1216
1302
|
.dsh-provider-index { font-family: ui-monospace, monospace; font-size: 10px; opacity: .7; }
|
|
@@ -1370,7 +1456,7 @@ window.__ModuleLoader__.load({
|
|
|
1370
1456
|
width: 100%;
|
|
1371
1457
|
max-width: var(--dsh-chat-content-width);
|
|
1372
1458
|
margin: 0 auto;
|
|
1373
|
-
padding: 4px calc(var(--dsh-composer-side-clearance) + 16px) 0;
|
|
1459
|
+
padding: 4px calc(var(--dsh-composer-side-clearance, 0px) + 16px) 0;
|
|
1374
1460
|
color: var(--dsw-alias-label-tertiary);
|
|
1375
1461
|
font-size: 12px;
|
|
1376
1462
|
line-height: 20px;
|
|
@@ -1379,6 +1465,7 @@ window.__ModuleLoader__.load({
|
|
|
1379
1465
|
overflow: hidden;
|
|
1380
1466
|
text-overflow: ellipsis;
|
|
1381
1467
|
}
|
|
1468
|
+
.dsh-balance-dock-model { display: inline-block; max-width: 40%; margin-left: 8px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
|
|
1382
1469
|
.dsh-balance-dock-dot {
|
|
1383
1470
|
display: inline-block;
|
|
1384
1471
|
width: 6px;
|
|
@@ -1397,10 +1484,12 @@ window.__ModuleLoader__.load({
|
|
|
1397
1484
|
color: var(--dsw-alias-separator-primary);
|
|
1398
1485
|
}
|
|
1399
1486
|
.dsh-balance-dock-value {
|
|
1487
|
+
display: inline-block;
|
|
1400
1488
|
color: var(--dsw-alias-label-secondary);
|
|
1401
1489
|
font-variant-numeric: tabular-nums;
|
|
1402
1490
|
}
|
|
1403
1491
|
@media (max-width: 640px) {
|
|
1492
|
+
.dsh-balance-dock { white-space: normal; }
|
|
1404
1493
|
.dsh-balance-summary { align-items: flex-start; }
|
|
1405
1494
|
.dsh-balance-grid,
|
|
1406
1495
|
.dsh-model-grid,
|
|
@@ -1414,7 +1503,11 @@ window.__ModuleLoader__.load({
|
|
|
1414
1503
|
`;
|
|
1415
1504
|
//#endregion
|
|
1416
1505
|
//#region src/client/index.tsx
|
|
1417
|
-
const inject = [
|
|
1506
|
+
const inject = [
|
|
1507
|
+
"slots",
|
|
1508
|
+
"locale",
|
|
1509
|
+
"modelDirectories"
|
|
1510
|
+
];
|
|
1418
1511
|
async function loadBalance(forceRefresh, signal, provider = "deepseek") {
|
|
1419
1512
|
const params = new URLSearchParams({ provider });
|
|
1420
1513
|
if (forceRefresh) params.set("refresh", "1");
|
|
@@ -1446,6 +1539,7 @@ window.__ModuleLoader__.load({
|
|
|
1446
1539
|
scope: options.scope,
|
|
1447
1540
|
timeZone: options.timeZone
|
|
1448
1541
|
});
|
|
1542
|
+
if (options.provider !== void 0) params.set("provider", options.provider);
|
|
1449
1543
|
if (options.sessionId !== void 0) params.set("sessionId", options.sessionId);
|
|
1450
1544
|
if (options.from !== void 0) params.set("from", options.from);
|
|
1451
1545
|
if (options.to !== void 0) params.set("to", options.to);
|
|
@@ -1501,7 +1595,10 @@ window.__ModuleLoader__.load({
|
|
|
1501
1595
|
id: "deepseek-balance",
|
|
1502
1596
|
order: 10,
|
|
1503
1597
|
locale: LOCALE_NS,
|
|
1504
|
-
inject: () => ({
|
|
1598
|
+
inject: (sessionId) => ({
|
|
1599
|
+
loadBalance,
|
|
1600
|
+
selection: ctx.modelDirectories.directoryFor(sessionId)
|
|
1601
|
+
})
|
|
1505
1602
|
}, BalanceDock));
|
|
1506
1603
|
}
|
|
1507
1604
|
//#endregion
|