@pinkbanana/dsh-balance 0.5.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/lib/client.js CHANGED
@@ -9,9 +9,37 @@ window.__ModuleLoader__.load({
9
9
  //#region src/types.ts
10
10
  /** The same-origin endpoint exposed by the plugin's Host half. */
11
11
  const BALANCE_ROUTE = "/dsh-balance/api/balance";
12
- /** The same-origin endpoint that proxies DeepSeek's `/models` API. */
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
- }, [result, t]);
153
- const state = result === void 0 ? "loading" : result.ok && result.isAvailable ? "available" : result.ok ? "empty" : "error";
154
- const accessibleState = result?.ok === true ? t(result.isAvailable ? "balance.available" : "balance.unavailable") : void 0;
155
- const pricingActive = now.getTime() >= PEAK_EFFECTIVE_FROM;
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": `${t("dock.label")}: ${summary}${accessibleState === void 0 ? "" : `. ${accessibleState}`}${periodLabel === void 0 ? "" : `. ${periodLabel}`}`,
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: t("dock.label") }),
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",
@@ -188,31 +245,53 @@ window.__ModuleLoader__.load({
188
245
  /** Simplified Chinese dictionary and source of truth for the namespace key set. */
189
246
  const zh = {
190
247
  "locale.tag": "zh-CN",
191
- "nav.balance": "DeepSeek 余额",
248
+ "panel.ledger": "账户总览",
249
+ "panel.private": "密钥仅存本机",
250
+ "panel.title": "账户余额",
251
+ "panel.copy": "查看各提供方的账户余额与 API 消费。",
252
+ "panel.providers": "选择提供方",
253
+ "panel.models": "可用模型",
254
+ "panel.activity": "消费记录",
255
+ "panel.allProviders": "全部提供方",
256
+ "panel.account": "账户余额",
257
+ "balance.availableAmount": "当前可用余额",
258
+ "balance.totalCash": "总充值金额",
259
+ "balance.totalVoucher": "总赠送金额",
260
+ "balance.prepaid": "预付费账户",
261
+ "balance.postpaid": "后付费账户",
262
+ "balance.totalsNote": "总充值与总赠送金额为账户累计金额,不代表当前剩余余额;账户类型不表示服务可用状态。",
263
+ "balance.setupTokener": "在 Tokener 账户设置创建个人访问令牌(PAT),配置为 TOKENER_MANAGEMENT_TOKEN;模型列表使用独立的 TOKENER_API_KEY。自定义凭据请配置 balanceApiKeyRef 与 apiKeyRef。",
264
+ "balance.setupDeepSeek": "在“设置 → 模型”保存 DeepSeek API 密钥,或配置 {ref} 环境变量。",
265
+ "balance.setup": "在“设置 → 模型”添加自定义提供方,Provider ID 填写 {provider}(大小写不限),并保存 API 密钥。默认凭据为 {ref};自定义凭据请检查插件配置。",
266
+ "error.UNSUPPORTED_PROVIDER": "暂不支持此提供方的余额查询",
267
+ "nav.balance": "模型余额",
192
268
  "action.loading": "查询中…",
193
- "balance.title": "DeepSeek API 余额",
269
+ "balance.title": "{provider} 账户",
194
270
  "balance.copy": "余额由本机 Host 使用已保存的 API 密钥查询,密钥不会发送到浏览器。",
195
271
  "balance.refresh": "刷新余额",
196
- "balance.loading": "正在查询 DeepSeek 账户余额…",
272
+ "balance.loading": "正在查询账户余额…",
197
273
  "balance.available": "当前账户有可用余额",
198
274
  "balance.unavailable": "当前账户没有可用余额",
199
- "balance.empty": "DeepSeek 未返回任何币种余额。",
275
+ "balance.empty": "提供方未返回任何币种余额。",
200
276
  "balance.toppedUp": "充值余额",
201
277
  "balance.granted": "赠送余额",
202
- "dock.label": "DeepSeek 余额",
278
+ "dock.label": "{provider} 余额",
279
+ "dock.noSelection": "尚未获取当前模型",
203
280
  "dock.loading": "查询中…",
204
281
  "dock.unavailable": "暂时无法获取",
205
282
  "dock.empty": "暂无余额信息",
206
- "models.title": "DeepSeek 可用模型",
207
- "models.copy": "从 DeepSeek 官方 /models 接口读取当前 API Key 可访问的模型。",
283
+ "models.title": "{provider} 可用模型",
284
+ "models.copy": "查看 {provider} 返回的可用模型。",
208
285
  "models.refresh": "刷新模型",
209
- "models.loading": "正在查询 DeepSeek 模型列表…",
286
+ "models.loading": "正在查询模型列表…",
210
287
  "models.count": "当前可用 {count} 个模型",
211
- "models.empty": "DeepSeek 未返回任何可用模型。",
288
+ "models.empty": "提供方未返回任何可用模型。",
212
289
  "models.owner": "由 {owner} 提供",
290
+ "models.created": "创建于 {date}",
213
291
  "billing.tab": "消费",
214
292
  "billing.title": "API 消费统计",
215
293
  "billing.copy": "按会话、模型和日期统计实际 provider usage;日期按 {timeZone} 分组。",
294
+ "billing.provider": "统计提供方",
216
295
  "billing.range": "统计范围",
217
296
  "billing.todayRange": "今日",
218
297
  "billing.sevenDays": "最近 7 天",
@@ -241,6 +320,7 @@ window.__ModuleLoader__.load({
241
320
  "billing.unknownModel": "未知模型",
242
321
  "billing.inputOutput": "输入 {input} · 输出 {output}",
243
322
  "billing.notPriced": "未计费",
323
+ "billing.partial": "仅包含已知价格的请求",
244
324
  "billing.reason.missing-usage": "缺少 provider usage",
245
325
  "billing.reason.unknown-provider": "未知 provider",
246
326
  "billing.reason.unknown-model": "未知模型价格",
@@ -257,43 +337,65 @@ window.__ModuleLoader__.load({
257
337
  "meta.updated": "更新于 {time}",
258
338
  "meta.cached": " · 缓存",
259
339
  "error.FORBIDDEN": "此查询仅允许从本机访问",
260
- "error.INVALID_API_KEY": "DeepSeek API 密钥无效或没有查询权限",
261
- "error.INVALID_RESPONSE": "DeepSeek 返回了无法识别的响应",
340
+ "error.INVALID_API_KEY": "API 密钥无效或没有查询权限",
341
+ "error.INVALID_RESPONSE": "返回了无法识别的响应",
262
342
  "error.METHOD_NOT_ALLOWED": "请求方法不受支持",
263
- "error.MISSING_API_KEY": "未配置 DeepSeek API 密钥,请先在“模型”设置中保存",
264
- "error.RATE_LIMITED": "DeepSeek API 请求过于频繁,请稍后重试",
265
- "error.UPSTREAM_ERROR": "DeepSeek API 返回了错误",
266
- "error.UPSTREAM_TIMEOUT": "查询 DeepSeek API 超时",
267
- "error.UPSTREAM_UNAVAILABLE": "无法连接到 DeepSeek API"
343
+ "error.MISSING_API_KEY": "未配置查询凭据",
344
+ "error.RATE_LIMITED": "API 请求过于频繁,请稍后重试",
345
+ "error.UPSTREAM_ERROR": "API 返回了错误",
346
+ "error.UPSTREAM_TIMEOUT": "查询 API 超时",
347
+ "error.UPSTREAM_UNAVAILABLE": "无法连接到 API"
268
348
  };
269
349
  /** English dictionary, checked complete against the Chinese key set. */
270
350
  const en = {
271
351
  "locale.tag": "en-US",
272
- "nav.balance": "DeepSeek Balance",
352
+ "panel.ledger": "ACCOUNT LEDGER",
353
+ "panel.private": "Keys stay local",
354
+ "panel.title": "Account balances",
355
+ "panel.copy": "View account balances and API usage by provider.",
356
+ "panel.providers": "Select provider",
357
+ "panel.models": "AVAILABLE MODELS",
358
+ "panel.activity": "USAGE ACTIVITY",
359
+ "panel.allProviders": "All providers",
360
+ "panel.account": "ACCOUNT BALANCE",
361
+ "balance.availableAmount": "Available balance",
362
+ "balance.totalCash": "Total cash credited",
363
+ "balance.totalVoucher": "Total vouchers granted",
364
+ "balance.prepaid": "Prepaid account",
365
+ "balance.postpaid": "Postpaid account",
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.",
368
+ "balance.setupDeepSeek": "Save your DeepSeek API key in Settings → Models, or set the {ref} environment variable.",
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.",
370
+ "error.UNSUPPORTED_PROVIDER": "Balance queries are not supported for this provider",
371
+ "nav.balance": "Model Balances",
273
372
  "action.loading": "Loading…",
274
- "balance.title": "DeepSeek API Balance",
373
+ "balance.title": "{provider} account",
275
374
  "balance.copy": "The local Host queries your balance with the saved API key. The key is never sent to the browser.",
276
375
  "balance.refresh": "Refresh balance",
277
- "balance.loading": "Loading your DeepSeek API balance…",
376
+ "balance.loading": "Loading your account balance…",
278
377
  "balance.available": "This account has available balance",
279
378
  "balance.unavailable": "This account has no available balance",
280
- "balance.empty": "DeepSeek returned no currency balances.",
379
+ "balance.empty": "The provider returned no currency balances.",
281
380
  "balance.toppedUp": "Topped-up balance",
282
381
  "balance.granted": "Granted balance",
283
- "dock.label": "DeepSeek Balance",
382
+ "dock.label": "{provider} Balance",
383
+ "dock.noSelection": "Current model not available yet",
284
384
  "dock.loading": "Loading…",
285
385
  "dock.unavailable": "Temporarily unavailable",
286
386
  "dock.empty": "No balance information",
287
- "models.title": "Available DeepSeek Models",
288
- "models.copy": "Lists the models available to the current API key using the official DeepSeek /models endpoint.",
387
+ "models.title": "Available {provider} models",
388
+ "models.copy": "Models available from {provider}.",
289
389
  "models.refresh": "Refresh models",
290
- "models.loading": "Loading the DeepSeek model list…",
390
+ "models.loading": "Loading the model list…",
291
391
  "models.count": "{count} models available",
292
- "models.empty": "DeepSeek returned no available models.",
392
+ "models.empty": "The provider returned no available models.",
293
393
  "models.owner": "Provided by {owner}",
394
+ "models.created": "Created {date}",
294
395
  "billing.tab": "Usage",
295
396
  "billing.title": "API Usage",
296
397
  "billing.copy": "Actual provider usage grouped by session, model, and date; dates use {timeZone}.",
398
+ "billing.provider": "Usage provider",
297
399
  "billing.range": "Usage range",
298
400
  "billing.todayRange": "Today",
299
401
  "billing.sevenDays": "Last 7 days",
@@ -322,6 +424,7 @@ window.__ModuleLoader__.load({
322
424
  "billing.unknownModel": "Unknown model",
323
425
  "billing.inputOutput": "Input {input} · Output {output}",
324
426
  "billing.notPriced": "Unpriced",
427
+ "billing.partial": "Requests with known pricing only",
325
428
  "billing.reason.missing-usage": "Provider usage is missing",
326
429
  "billing.reason.unknown-provider": "Unknown provider",
327
430
  "billing.reason.unknown-model": "Unknown model pricing",
@@ -338,14 +441,14 @@ window.__ModuleLoader__.load({
338
441
  "meta.updated": "Updated {time}",
339
442
  "meta.cached": " · Cached",
340
443
  "error.FORBIDDEN": "This query is available only from the local machine",
341
- "error.INVALID_API_KEY": "The DeepSeek API key is invalid or lacks permission",
342
- "error.INVALID_RESPONSE": "DeepSeek returned an unrecognized response",
444
+ "error.INVALID_API_KEY": "The API key is invalid or lacks permission",
445
+ "error.INVALID_RESPONSE": "The provider returned an unrecognized response",
343
446
  "error.METHOD_NOT_ALLOWED": "This request method is not supported",
344
- "error.MISSING_API_KEY": "No DeepSeek API key is configured. Save one in Models settings first.",
345
- "error.RATE_LIMITED": "Too many DeepSeek API requests. Try again later.",
346
- "error.UPSTREAM_ERROR": "The DeepSeek API returned an error",
347
- "error.UPSTREAM_TIMEOUT": "The DeepSeek API request timed out",
348
- "error.UPSTREAM_UNAVAILABLE": "Could not connect to the DeepSeek API"
447
+ "error.MISSING_API_KEY": "Query credentials are not configured.",
448
+ "error.RATE_LIMITED": "Too many API requests. Try again later.",
449
+ "error.UPSTREAM_ERROR": "The API returned an error",
450
+ "error.UPSTREAM_TIMEOUT": "The API request timed out",
451
+ "error.UPSTREAM_UNAVAILABLE": "Could not connect to the API"
349
452
  };
350
453
  function errorLocaleKey(code) {
351
454
  return `error.${code}`;
@@ -353,91 +456,116 @@ window.__ModuleLoader__.load({
353
456
  //#endregion
354
457
  //#region src/client/BalanceTab.tsx
355
458
  function BalanceCard({ info, t }) {
459
+ const details = [
460
+ ["balance.toppedUp", info.toppedUpBalance],
461
+ ["balance.granted", info.grantedBalance],
462
+ ["balance.totalCash", info.totalCashBalance],
463
+ ["balance.totalVoucher", info.totalVoucherBalance]
464
+ ];
356
465
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
357
466
  className: "dsh-balance-card",
358
467
  children: [
359
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
468
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
360
469
  className: "dsh-balance-card-head",
361
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
470
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("balance.availableAmount") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
362
471
  className: "dsh-balance-currency",
363
472
  children: info.currency
364
- })
473
+ })]
365
474
  }),
366
475
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
367
476
  className: "dsh-balance-total",
368
477
  children: displayAmount(info.totalBalance, info.currency, t("locale.tag"))
369
478
  }),
370
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("dl", {
479
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dl", {
371
480
  className: "dsh-balance-breakdown",
372
- children: [
373
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t("balance.toppedUp") }),
374
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: displayAmount(info.toppedUpBalance, info.currency, t("locale.tag")) }),
375
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t("balance.granted") }),
376
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: displayAmount(info.grantedBalance, info.currency, t("locale.tag")) })
377
- ]
481
+ children: details.filter(([, value]) => value !== void 0).map(([label, value]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t(label) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: displayAmount(value, info.currency, t("locale.tag")) })] }, label))
378
482
  })
379
483
  ]
380
484
  });
381
485
  }
382
- function BalanceSection({ loadBalance, t }) {
486
+ function BalanceSection({ loadBalance, t, provider = "deepseek" }) {
383
487
  const [result, setResult] = (0, react.useState)();
384
488
  const [loading, setLoading] = (0, react.useState)(true);
385
- const load = (0, react.useCallback)(async (forceRefresh, signal) => {
489
+ const active = (0, react.useRef)();
490
+ const providerName = findBalanceProvider(provider).name;
491
+ const load = (0, react.useCallback)(async (forceRefresh) => {
492
+ active.current?.abort();
493
+ const controller = new AbortController();
494
+ active.current = controller;
495
+ const { signal } = controller;
386
496
  setLoading(true);
387
497
  try {
388
- setResult(await loadBalance(forceRefresh, signal));
389
- } catch (error) {
390
- if (signal.aborted) return;
391
- setResult({
498
+ const value = await loadBalance(forceRefresh, signal, provider);
499
+ if (!signal.aborted) setResult(value);
500
+ } catch {
501
+ if (!signal.aborted) setResult({
392
502
  ok: false,
393
503
  code: "UPSTREAM_UNAVAILABLE",
394
- message: error instanceof Error ? error.message : ""
504
+ message: ""
395
505
  });
396
506
  } finally {
397
507
  if (!signal.aborted) setLoading(false);
398
508
  }
399
- }, [loadBalance]);
509
+ }, [loadBalance, provider]);
400
510
  (0, react.useEffect)(() => {
401
- const controller = new AbortController();
402
- load(false, controller.signal);
511
+ setResult(void 0);
512
+ load(false);
403
513
  return () => {
404
- controller.abort();
514
+ active.current?.abort();
405
515
  };
406
516
  }, [load]);
407
- const refresh = () => {
408
- const controller = new AbortController();
409
- load(true, controller.signal);
410
- };
411
517
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
412
518
  className: "dsh-balance-section",
413
519
  "aria-labelledby": "dsh-balance-title",
520
+ "aria-busy": loading,
521
+ "data-provider": provider,
414
522
  children: [
415
523
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
416
524
  className: "dsh-balance-summary",
417
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
525
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
526
+ className: "dsh-ledger-kicker",
527
+ children: ["01 / ", t("panel.account")]
528
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
418
529
  id: "dsh-balance-title",
419
530
  className: "dsh-balance-heading",
420
- children: t("balance.title")
421
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
422
- className: "dsh-balance-copy",
423
- children: t("balance.copy")
424
- })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
531
+ children: t("balance.title", { provider: providerName })
532
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
425
533
  className: "dsh-balance-refresh",
426
534
  type: "button",
427
535
  disabled: loading,
428
- onClick: refresh,
429
- children: loading ? t("action.loading") : t("balance.refresh")
536
+ onClick: () => {
537
+ load(true);
538
+ },
539
+ children: [
540
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
541
+ "aria-hidden": "true",
542
+ children: "↻"
543
+ }),
544
+ " ",
545
+ loading ? t("action.loading") : t("balance.refresh")
546
+ ]
430
547
  })]
431
548
  }),
432
- loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
433
- className: "dsh-balance-status",
549
+ loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
550
+ className: "dsh-balance-skeleton",
434
551
  role: "status",
435
- children: t("balance.loading")
552
+ children: [
553
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("balance.loading") }),
554
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
555
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {})
556
+ ]
436
557
  }) : null,
437
- result?.ok === false ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
558
+ result?.ok === false ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
438
559
  className: "dsh-balance-error",
439
560
  role: "alert",
440
- children: t(errorLocaleKey(result.code))
561
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("strong", { children: [
562
+ providerName,
563
+ " / ",
564
+ t(errorLocaleKey(result.code))
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", {
566
+ provider: providerName,
567
+ ref: findBalanceProvider(provider).apiKeyRef
568
+ }) }) : null]
441
569
  }) : null,
442
570
  result?.ok === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
443
571
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -446,7 +574,7 @@ window.__ModuleLoader__.load({
446
574
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
447
575
  className: "dsh-balance-dot",
448
576
  "aria-hidden": "true"
449
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(result.isAvailable ? "balance.available" : "balance.unavailable") })]
577
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: result.accountType !== void 0 ? t(`balance.${result.accountType}`) : t(result.isAvailable ? "balance.available" : "balance.unavailable") })]
450
578
  }),
451
579
  result.balanceInfos.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
452
580
  className: "dsh-balance-grid",
@@ -458,9 +586,16 @@ window.__ModuleLoader__.load({
458
586
  className: "dsh-balance-status",
459
587
  children: t("balance.empty")
460
588
  }),
461
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
462
- className: "dsh-balance-meta",
463
- children: [t("meta.updated", { time: new Date(result.fetchedAt).toLocaleString(t("locale.tag")) }), result.source === "cache" ? t("meta.cached") : ""]
589
+ result.accountType !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
590
+ className: "dsh-balance-copy",
591
+ children: t("balance.totalsNote")
592
+ }) : null,
593
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
594
+ className: "dsh-balance-footer",
595
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
596
+ className: "dsh-balance-meta",
597
+ children: [t("meta.updated", { time: new Date(result.fetchedAt).toLocaleString(t("locale.tag")) }), result.source === "cache" ? t("meta.cached") : ""]
598
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("panel.private") })]
464
599
  })
465
600
  ] }) : null
466
601
  ]
@@ -471,62 +606,74 @@ window.__ModuleLoader__.load({
471
606
  function ModelCard({ model, t }) {
472
607
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
473
608
  className: "dsh-model-card",
474
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
475
- className: "dsh-model-id",
476
- children: model.id
477
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
478
- className: "dsh-model-owner",
479
- children: t("models.owner", { owner: model.ownedBy })
480
- })]
609
+ children: [
610
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
611
+ className: "dsh-model-id",
612
+ children: model.id
613
+ }),
614
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
615
+ className: "dsh-model-owner",
616
+ children: t("models.owner", { owner: model.ownedBy })
617
+ }),
618
+ model.created === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
619
+ className: "dsh-model-owner",
620
+ children: t("models.created", { date: (/* @__PURE__ */ new Date(model.created * 1e3)).toLocaleDateString(t("locale.tag")) })
621
+ })
622
+ ]
481
623
  });
482
624
  }
483
- function ModelsSection({ loadModels, t }) {
625
+ function ModelsSection({ loadModels, t, provider = "deepseek" }) {
484
626
  const [result, setResult] = (0, react.useState)();
485
627
  const [loading, setLoading] = (0, react.useState)(true);
486
- const load = (0, react.useCallback)(async (forceRefresh, signal) => {
628
+ const active = (0, react.useRef)();
629
+ const providerName = findBalanceProvider(provider).name;
630
+ const load = (0, react.useCallback)(async (forceRefresh) => {
631
+ active.current?.abort();
632
+ const controller = new AbortController();
633
+ active.current = controller;
634
+ const { signal } = controller;
487
635
  setLoading(true);
488
636
  try {
489
- setResult(await loadModels(forceRefresh, signal));
490
- } catch (error) {
491
- if (signal.aborted) return;
492
- setResult({
637
+ const value = await loadModels(forceRefresh, signal, provider);
638
+ if (!signal.aborted) setResult(value);
639
+ } catch {
640
+ if (!signal.aborted) setResult({
493
641
  ok: false,
494
642
  code: "UPSTREAM_UNAVAILABLE",
495
- message: error instanceof Error ? error.message : ""
643
+ message: ""
496
644
  });
497
645
  } finally {
498
646
  if (!signal.aborted) setLoading(false);
499
647
  }
500
- }, [loadModels]);
648
+ }, [loadModels, provider]);
501
649
  (0, react.useEffect)(() => {
502
- const controller = new AbortController();
503
- load(false, controller.signal);
650
+ setResult(void 0);
651
+ load(false);
504
652
  return () => {
505
- controller.abort();
653
+ active.current?.abort();
506
654
  };
507
655
  }, [load]);
508
- const refresh = () => {
509
- const controller = new AbortController();
510
- load(true, controller.signal);
511
- };
512
656
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
513
657
  className: "dsh-models-section",
514
658
  "aria-labelledby": "dsh-models-title",
659
+ "aria-busy": loading,
515
660
  children: [
516
661
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
517
662
  className: "dsh-balance-summary",
518
663
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
519
664
  id: "dsh-models-title",
520
665
  className: "dsh-balance-heading",
521
- children: t("models.title")
666
+ children: t("models.title", { provider: providerName })
522
667
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
523
668
  className: "dsh-balance-copy",
524
- children: t("models.copy")
669
+ children: t("models.copy", { provider: providerName })
525
670
  })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
526
671
  className: "dsh-balance-refresh",
527
672
  type: "button",
528
673
  disabled: loading,
529
- onClick: refresh,
674
+ onClick: () => {
675
+ load(true);
676
+ },
530
677
  children: loading ? t("action.loading") : t("models.refresh")
531
678
  })]
532
679
  }),
@@ -585,9 +732,9 @@ window.__ModuleLoader__.load({
585
732
  return `${values.year ?? "0000"}-${values.month ?? "00"}-${values.day ?? "00"}`;
586
733
  }
587
734
  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);
735
+ const local = /* @__PURE__ */ new Date(`${localDateKey(timeZone)}T12:00:00Z`);
736
+ local.setUTCDate(local.getUTCDate() - days);
737
+ return local.toISOString().slice(0, 10);
591
738
  }
592
739
  function totalForDay(summary, date) {
593
740
  return summary.byDay.find((item) => item.date === date) ?? {
@@ -613,13 +760,18 @@ window.__ModuleLoader__.load({
613
760
  }
614
761
  function CostLabel({ totals, t }) {
615
762
  const locale = t("locale.tag");
763
+ const unpriced = totals.requests > 0 && totals.pricedRequests === 0;
616
764
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
617
765
  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]
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
+ ]
623
775
  });
624
776
  }
625
777
  function SummaryCards({ summary, t }) {
@@ -653,7 +805,7 @@ window.__ModuleLoader__.load({
653
805
  className: "dsh-billing-card",
654
806
  children: [
655
807
  /* @__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) }),
808
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: formatTokens(summary.totals.inputTokens + summary.totals.outputTokens + summary.totals.cacheReadTokens + summary.totals.cacheWriteTokens) }),
657
809
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
658
810
  totals: summary.totals,
659
811
  t
@@ -704,13 +856,9 @@ window.__ModuleLoader__.load({
704
856
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
705
857
  totals: item,
706
858
  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
- ] })]
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)}%` })}` : ""] })]
712
860
  })]
713
- }, `${item.provider}/${item.model}`))
861
+ }, JSON.stringify([item.provider, item.model])))
714
862
  });
715
863
  }
716
864
  function UsageTables({ summary, t }) {
@@ -785,7 +933,11 @@ window.__ModuleLoader__.load({
785
933
  className: "dsh-billing-request-row",
786
934
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
787
935
  /* @__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") }),
936
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("code", { children: [
937
+ request.provider ?? "?",
938
+ " / ",
939
+ request.model ?? t("billing.unknownModel")
940
+ ] }),
789
941
  request.unknownReason !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
790
942
  className: "dsh-billing-secondary",
791
943
  children: t(`billing.reason.${request.unknownReason}`)
@@ -810,52 +962,69 @@ window.__ModuleLoader__.load({
810
962
  });
811
963
  }
812
964
  function useUsageResult(loadUsage, options, revision) {
813
- const [result, setResult] = (0, react.useState)();
965
+ const [state, setState] = (0, react.useState)();
814
966
  const [loading, setLoading] = (0, react.useState)(true);
815
- const load = (0, react.useCallback)(async (forceRefresh, signal) => {
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;
816
973
  setLoading(true);
817
974
  try {
818
- setResult(await loadUsage({
975
+ const result = await loadUsage({
819
976
  ...options,
820
977
  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 : ""
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
+ }
827
991
  });
828
992
  } finally {
829
993
  if (!signal.aborted) setLoading(false);
830
994
  }
831
995
  }, [loadUsage, options]);
832
996
  (0, react.useEffect)(() => {
833
- const controller = new AbortController();
834
- load(false, controller.signal);
997
+ load(false);
835
998
  return () => {
836
- controller.abort();
999
+ active.current?.abort();
837
1000
  };
838
1001
  }, [load, revision]);
839
1002
  return {
840
- result,
1003
+ result: state?.options === options ? state.result : void 0,
841
1004
  loading,
842
1005
  refresh: () => {
843
- const controller = new AbortController();
844
- load(true, controller.signal);
1006
+ load(true);
845
1007
  }
846
1008
  };
847
1009
  }
848
- 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;
849
1013
  const timeZone = (0, react.useMemo)(() => Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC", []);
850
1014
  const [range, setRange] = (0, react.useState)("30d");
851
1015
  const options = (0, react.useMemo)(() => ({
852
1016
  scope: "all",
1017
+ ...selectedProvider === void 0 ? {} : { provider: selectedProvider },
853
1018
  timeZone,
854
1019
  ...range === "all" ? {} : {
855
1020
  from: range === "today" ? localDateKey(timeZone) : dateDaysAgo(timeZone, range === "7d" ? 6 : 29),
856
1021
  to: localDateKey(timeZone)
857
1022
  }
858
- }), [range, timeZone]);
1023
+ }), [
1024
+ range,
1025
+ timeZone,
1026
+ selectedProvider
1027
+ ]);
859
1028
  const { result, loading, refresh } = useUsageResult(loadUsage, options, JSON.stringify(options));
860
1029
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
861
1030
  className: "dsh-billing-section",
@@ -872,35 +1041,50 @@ window.__ModuleLoader__.load({
872
1041
  children: t("billing.copy", { timeZone })
873
1042
  })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
874
1043
  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", {
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", {
893
1053
  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
- })]
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
+ ]
904
1088
  })]
905
1089
  }),
906
1090
  loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
@@ -1003,28 +1187,73 @@ window.__ModuleLoader__.load({
1003
1187
  }
1004
1188
  //#endregion
1005
1189
  //#region src/client/DeepSeekPanel.tsx
1006
- /** Standalone DeepSeek settings page, placed immediately after Agent presets. */
1190
+ /** Provider-neutral settings workspace. The exported name preserves existing integrations. */
1007
1191
  function DeepSeekPanel({ loadBalance, loadModels, loadUsage, t }) {
1192
+ const [provider, setProvider] = (0, react.useState)("deepseek");
1008
1193
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1009
1194
  className: "dsh-deepseek-panel",
1010
1195
  children: [
1196
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
1197
+ className: "dsh-ledger-header",
1198
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1199
+ className: "dsh-ledger-eyebrow",
1200
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["DSH / ", t("panel.ledger")] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("panel.private") })]
1201
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1202
+ className: "dsh-ledger-intro",
1203
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", { children: t("panel.title") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("panel.copy") })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1204
+ className: "dsh-ledger-orbit",
1205
+ "aria-hidden": "true",
1206
+ children: [
1207
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
1208
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
1209
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
1210
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "↗" })
1211
+ ]
1212
+ })]
1213
+ })]
1214
+ }),
1215
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1216
+ className: "dsh-provider-switch",
1217
+ role: "group",
1218
+ "aria-label": t("panel.providers"),
1219
+ children: BALANCE_PROVIDERS.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1220
+ type: "button",
1221
+ "aria-pressed": provider === item.id,
1222
+ onClick: () => setProvider(item.id),
1223
+ children: [
1224
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1225
+ className: "dsh-provider-index",
1226
+ children: ["0", index + 1]
1227
+ }),
1228
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: item.name }),
1229
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1230
+ className: "dsh-provider-arrow",
1231
+ "aria-hidden": "true",
1232
+ children: "↗"
1233
+ })
1234
+ ]
1235
+ }, item.id))
1236
+ }),
1011
1237
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BalanceSection, {
1238
+ provider,
1012
1239
  loadBalance,
1013
1240
  t
1014
- }),
1015
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1016
- className: "dsh-deepseek-divider",
1017
- "aria-hidden": "true"
1241
+ }, `balance-${provider}`),
1242
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1243
+ className: "dsh-ledger-section-label",
1244
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["02 / ", t("panel.models")] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: findBalanceProvider(provider).name })]
1018
1245
  }),
1019
1246
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelsSection, {
1247
+ provider,
1020
1248
  loadModels,
1021
1249
  t
1022
- }),
1250
+ }, `models-${provider}`),
1023
1251
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1024
- className: "dsh-deepseek-divider",
1025
- "aria-hidden": "true"
1252
+ className: "dsh-ledger-section-label",
1253
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["03 / ", t("panel.activity")] })
1026
1254
  }),
1027
1255
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BillingOverview, {
1256
+ provider,
1028
1257
  loadUsage,
1029
1258
  t
1030
1259
  })
@@ -1035,77 +1264,96 @@ window.__ModuleLoader__.load({
1035
1264
  //#region src/client/styles.ts
1036
1265
  const balanceStyles = `
1037
1266
  .dsh-deepseek-panel {
1267
+ --ledger-ink: var(--dsw-alias-label-primary, #202421);
1268
+ --ledger-muted: var(--dsw-alias-label-secondary, #60665f);
1269
+ --ledger-line: var(--dsw-alias-border-l2, #d7dbd3);
1270
+ --ledger-paper: var(--dsw-alias-bg-layer-3, #f5f6f0);
1038
1271
  display: flex;
1039
1272
  flex-direction: column;
1040
- gap: 28px;
1273
+ gap: 24px;
1041
1274
  max-width: 1040px;
1042
- color: var(--dsw-alias-label-primary);
1275
+ min-width: 0;
1276
+ color: var(--ledger-ink);
1277
+ container-type: inline-size;
1043
1278
  }
1279
+ .dsh-deepseek-panel *, .dsh-deepseek-panel *::before, .dsh-deepseek-panel *::after { box-sizing: border-box; }
1280
+ .dsh-ledger-header { border-top: 2px solid var(--ledger-ink); padding-top: 14px; }
1281
+ .dsh-ledger-eyebrow, .dsh-ledger-section-label, .dsh-ledger-kicker {
1282
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1283
+ font-size: 11px;
1284
+ letter-spacing: .08em;
1285
+ line-height: 1.6;
1286
+ color: var(--ledger-muted);
1287
+ }
1288
+ .dsh-ledger-eyebrow, .dsh-ledger-section-label { display: flex; justify-content: space-between; gap: 16px; }
1289
+ .dsh-ledger-intro { display: grid; grid-template-columns: 1fr 150px; align-items: center; gap: 24px; padding: 32px 0 20px; }
1290
+ .dsh-ledger-intro h1 { max-width: 650px; margin: 0; font-size: 24px; font-weight: 500; line-height: 1.4; }
1291
+ .dsh-ledger-intro p { margin: 18px 0 0; color: var(--ledger-muted); font-size: 13px; line-height: 1.7; }
1292
+ .dsh-ledger-orbit { position: relative; display: grid; place-items: center; width: 148px; height: 148px; }
1293
+ .dsh-ledger-orbit i { position: absolute; width: 112px; height: 112px; border: 1px solid var(--ledger-muted); border-radius: 50%; transform: rotate(-35deg) scaleX(.5); }
1294
+ .dsh-ledger-orbit i:nth-child(2) { transform: rotate(25deg) scaleX(.5); }
1295
+ .dsh-ledger-orbit i:nth-child(3) { transform: rotate(85deg) scaleX(.5); }
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; }
1297
+ .dsh-ledger-header:hover .dsh-ledger-orbit span { transform: rotate(45deg); }
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; }
1300
+ .dsh-provider-switch button:hover { background: var(--ledger-paper); transform: translateY(-2px); }
1301
+ .dsh-provider-switch button[aria-pressed='true'] { color: #e5f6bd; background: #25352e; border-color: #25352e; }
1302
+ .dsh-provider-index { font-family: ui-monospace, monospace; font-size: 10px; opacity: .7; }
1303
+ .dsh-provider-arrow { margin-left: auto; transition: transform .2s; }
1304
+ .dsh-provider-switch button[aria-pressed='true'] .dsh-provider-arrow { transform: rotate(45deg); }
1305
+ .dsh-ledger-kicker { margin: 0 0 8px; }
1306
+ .dsh-ledger-section-label { border-top: 1px solid var(--ledger-line); padding-top: 18px; margin-top: 12px; }
1044
1307
  .dsh-balance-section,
1045
1308
  .dsh-models-section,
1046
1309
  .dsh-billing-section,
1047
- .dsh-billing-view {
1048
- display: flex;
1049
- flex-direction: column;
1050
- gap: 14px;
1051
- }
1052
- .dsh-deepseek-divider {
1053
- height: 1px;
1054
- background: var(--dsw-alias-border-l2);
1055
- }
1056
- .dsh-balance-summary {
1057
- display: flex;
1058
- align-items: center;
1059
- justify-content: space-between;
1060
- gap: 16px;
1061
- }
1062
- .dsh-balance-heading { margin: 0; font-size: 18px; font-weight: 600; line-height: 24px; }
1063
- .dsh-balance-copy { margin: 4px 0 0; color: var(--dsw-alias-label-tertiary); font-size: 13px; line-height: 1.5; }
1064
- .dsh-balance-refresh {
1065
- flex: none;
1066
- appearance: none;
1067
- border: 1px solid var(--dsw-alias-border-l2);
1068
- border-radius: 16px;
1069
- min-height: 32px;
1070
- padding: 0 14px;
1071
- background: transparent;
1072
- color: var(--dsw-alias-label-primary);
1073
- font: inherit;
1074
- font-size: 13px;
1075
- cursor: pointer;
1076
- }
1077
- .dsh-balance-refresh:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
1078
- .dsh-balance-refresh:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }
1310
+ .dsh-billing-view { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
1311
+ .dsh-balance-section { animation: dsh-ledger-reveal .3s ease-out; }
1312
+ .dsh-balance-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
1313
+ .dsh-balance-heading { margin: 0; font-size: 20px; font-weight: 550; line-height: 1.4; letter-spacing: -.025em; }
1314
+ .dsh-balance-copy { margin: 4px 0 0; color: var(--dsw-alias-label-secondary, #60665f); font-size: 12px; line-height: 1.7; }
1315
+ .dsh-balance-refresh { flex: none; appearance: none; border: 1px solid var(--dsw-alias-border-l2, #d7dbd3); border-radius: 4px; min-height: 36px; padding: 0 14px; background: transparent; color: var(--dsw-alias-label-primary, #202421); font: inherit; font-size: 12px; cursor: pointer; transition: background .2s; }
1316
+ .dsh-balance-refresh:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, #e9edde); }
1317
+ .dsh-balance-refresh:focus-visible, .dsh-provider-switch button:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary, #628537); outline-offset: 3px; }
1079
1318
  .dsh-balance-refresh:disabled { cursor: default; opacity: .55; }
1080
- .dsh-balance-status,
1081
- .dsh-balance-error {
1082
- margin: 0;
1083
- border: 1px solid var(--dsw-alias-border-l2);
1084
- border-radius: 12px;
1085
- padding: 18px;
1086
- background: var(--dsw-alias-bg-layer-3);
1087
- color: var(--dsw-alias-label-secondary);
1088
- font-size: 13px;
1089
- line-height: 1.6;
1319
+ .dsh-balance-status, .dsh-balance-error { margin: 0; border: 1px solid var(--dsw-alias-border-l2, #d7dbd3); border-radius: 4px; padding: 24px; background: var(--dsw-alias-bg-layer-3, #f5f6f0); color: var(--dsw-alias-label-secondary, #60665f); font-size: 13px; line-height: 1.7; }
1320
+ .dsh-balance-error { border-left: 3px solid var(--dsw-alias-state-error-primary, #b04734); }
1321
+ .dsh-balance-error strong { color: var(--dsw-alias-state-error-primary, #b04734); }
1322
+ .dsh-balance-error p { margin: 10px 0 0; }
1323
+ .dsh-balance-availability { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ledger-muted); }
1324
+ .dsh-balance-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--dsw-alias-state-error-primary, #b04734); }
1325
+ .dsh-balance-availability[data-available='true'] .dsh-balance-dot { background: var(--dsw-alias-state-success-primary, #568434); }
1326
+ .dsh-balance-availability[data-available='null'] .dsh-balance-dot { background: var(--ledger-muted); }
1327
+ .dsh-balance-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; }
1328
+ .dsh-balance-card { position: relative; min-width: 0; overflow: hidden; border: 1px solid var(--ledger-line); border-radius: 4px; padding: 26px; background: var(--ledger-paper); }
1329
+ .dsh-balance-card:first-child { background: #25352e; border-color: #25352e; color: #f2f5eb; }
1330
+ .dsh-balance-card::before { content: ''; position: absolute; top: 0; right: 22px; height: 9px; width: 30px; border-left: 1px solid currentColor; border-right: 1px solid currentColor; opacity: .4; }
1331
+ .dsh-balance-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; }
1332
+ .dsh-balance-currency { font-family: ui-monospace, monospace; font-size: 11px; letter-spacing: .1em; padding: 4px 7px; border: 1px solid currentColor; border-radius: 3px; }
1333
+ .dsh-balance-total { margin: 24px 0 32px; font-size: clamp(32px, 6cqi, 64px); font-weight: 450; letter-spacing: -.045em; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
1334
+ .dsh-balance-card:first-child .dsh-balance-total { color: #d7ed9d; }
1335
+ .dsh-balance-breakdown { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 0; padding-top: 18px; border-top: 1px solid color-mix(in srgb, currentColor 20%, transparent); }
1336
+ .dsh-balance-breakdown dt { font-size: 11px; opacity: .75; line-height: 1.5; }
1337
+ .dsh-balance-breakdown dd { margin: 8px 0 0; font-size: 17px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
1338
+ .dsh-balance-meta { margin: 0; color: var(--dsw-alias-label-secondary, #60665f); font-size: 11px; line-height: 1.6; }
1339
+ .dsh-balance-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; color: var(--ledger-muted); font-size: 11px; }
1340
+ .dsh-balance-skeleton { min-height: 245px; display: flex; flex-direction: column; align-items: flex-start; gap: 28px; padding: 26px; border: 1px solid var(--ledger-line); background: var(--ledger-paper); font-size: 12px; color: var(--ledger-muted); }
1341
+ .dsh-balance-skeleton i { width: 60%; height: 42px; background: var(--ledger-line); animation: dsh-ledger-pulse 1.4s ease-in-out infinite alternate; }
1342
+ .dsh-balance-skeleton i:last-child { width: 35%; height: 16px; }
1343
+ @keyframes dsh-ledger-reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
1344
+ @keyframes dsh-ledger-pulse { to { opacity: .4; } }
1345
+ @container (max-width: 540px) {
1346
+ .dsh-ledger-intro { grid-template-columns: 1fr; padding-top: 24px; }
1347
+ .dsh-ledger-orbit { display: none; }
1348
+ .dsh-provider-switch button { padding: 12px; gap: 10px; }
1349
+ .dsh-balance-grid, .dsh-deepseek-panel .dsh-model-grid, .dsh-deepseek-panel .dsh-billing-card-grid, .dsh-deepseek-panel .dsh-billing-table-grid { grid-template-columns: 1fr; }
1350
+ .dsh-balance-card { padding: 20px; }
1351
+ .dsh-deepseek-panel .dsh-balance-summary { flex-wrap: wrap; }
1090
1352
  }
1091
- .dsh-balance-error { color: var(--dsw-alias-state-error-primary); }
1092
- .dsh-balance-availability { display: flex; align-items: center; gap: 8px; font-size: 13px; }
1093
- .dsh-balance-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--dsw-alias-state-error-primary); }
1094
- .dsh-balance-availability[data-available='true'] .dsh-balance-dot { background: var(--dsw-alias-state-success-primary); }
1095
- .dsh-balance-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
1096
- .dsh-balance-card {
1097
- border: 1px solid var(--dsw-alias-border-l2);
1098
- border-radius: 12px;
1099
- padding: 16px;
1100
- background: var(--dsw-alias-bg-layer-3);
1353
+ @media (prefers-reduced-motion: reduce) {
1354
+ .dsh-deepseek-panel *, .dsh-deepseek-panel *::before, .dsh-deepseek-panel *::after { animation: none !important; transition: none !important; }
1101
1355
  }
1102
- .dsh-balance-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
1103
- .dsh-balance-currency { color: var(--dsw-alias-label-tertiary); font-size: 12px; font-weight: 600; letter-spacing: .04em; }
1104
- .dsh-balance-total { margin: 12px 0 16px; font-size: 28px; font-weight: 650; line-height: 1.15; }
1105
- .dsh-balance-breakdown { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; margin: 0; font-size: 12px; }
1106
- .dsh-balance-breakdown dt { color: var(--dsw-alias-label-tertiary); }
1107
- .dsh-balance-breakdown dd { margin: 0; color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
1108
- .dsh-balance-meta { margin: 0; color: var(--dsw-alias-label-tertiary); font-size: 12px; }
1356
+ .dsh-deepseek-panel .dsh-model-card, .dsh-deepseek-panel .dsh-billing-card, .dsh-deepseek-panel .dsh-billing-list-section { border-radius: 4px; }
1109
1357
  .dsh-billing-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
1110
1358
  .dsh-billing-actions select {
1111
1359
  min-height: 32px;
@@ -1208,7 +1456,7 @@ window.__ModuleLoader__.load({
1208
1456
  width: 100%;
1209
1457
  max-width: var(--dsh-chat-content-width);
1210
1458
  margin: 0 auto;
1211
- padding: 4px calc(var(--dsh-composer-side-clearance) + 16px) 0;
1459
+ padding: 4px calc(var(--dsh-composer-side-clearance, 0px) + 16px) 0;
1212
1460
  color: var(--dsw-alias-label-tertiary);
1213
1461
  font-size: 12px;
1214
1462
  line-height: 20px;
@@ -1217,6 +1465,7 @@ window.__ModuleLoader__.load({
1217
1465
  overflow: hidden;
1218
1466
  text-overflow: ellipsis;
1219
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; }
1220
1469
  .dsh-balance-dock-dot {
1221
1470
  display: inline-block;
1222
1471
  width: 6px;
@@ -1235,10 +1484,12 @@ window.__ModuleLoader__.load({
1235
1484
  color: var(--dsw-alias-separator-primary);
1236
1485
  }
1237
1486
  .dsh-balance-dock-value {
1487
+ display: inline-block;
1238
1488
  color: var(--dsw-alias-label-secondary);
1239
1489
  font-variant-numeric: tabular-nums;
1240
1490
  }
1241
1491
  @media (max-width: 640px) {
1492
+ .dsh-balance-dock { white-space: normal; }
1242
1493
  .dsh-balance-summary { align-items: flex-start; }
1243
1494
  .dsh-balance-grid,
1244
1495
  .dsh-model-grid,
@@ -1252,9 +1503,16 @@ window.__ModuleLoader__.load({
1252
1503
  `;
1253
1504
  //#endregion
1254
1505
  //#region src/client/index.tsx
1255
- const inject = ["slots", "locale"];
1256
- async function loadBalance(forceRefresh, signal) {
1257
- const value = await (await fetch(forceRefresh ? `${BALANCE_ROUTE}?refresh=1` : BALANCE_ROUTE, {
1506
+ const inject = [
1507
+ "slots",
1508
+ "locale",
1509
+ "modelDirectories"
1510
+ ];
1511
+ async function loadBalance(forceRefresh, signal, provider = "deepseek") {
1512
+ const params = new URLSearchParams({ provider });
1513
+ if (forceRefresh) params.set("refresh", "1");
1514
+ const url = `${BALANCE_ROUTE}?${params}`;
1515
+ const value = await (await fetch(url, {
1258
1516
  method: "GET",
1259
1517
  headers: { accept: "application/json" },
1260
1518
  cache: "no-store",
@@ -1263,8 +1521,11 @@ window.__ModuleLoader__.load({
1263
1521
  if (typeof value !== "object" || value === null || !("ok" in value) || typeof value.ok !== "boolean") throw new Error("余额插件收到了无法识别的 Host 响应");
1264
1522
  return value;
1265
1523
  }
1266
- async function loadModels(forceRefresh, signal) {
1267
- const value = await (await fetch(forceRefresh ? `${MODELS_ROUTE}?refresh=1` : MODELS_ROUTE, {
1524
+ async function loadModels(forceRefresh, signal, provider = "deepseek") {
1525
+ const params = new URLSearchParams({ provider });
1526
+ if (forceRefresh) params.set("refresh", "1");
1527
+ const url = `${MODELS_ROUTE}?${params}`;
1528
+ const value = await (await fetch(url, {
1268
1529
  method: "GET",
1269
1530
  headers: { accept: "application/json" },
1270
1531
  cache: "no-store",
@@ -1278,6 +1539,7 @@ window.__ModuleLoader__.load({
1278
1539
  scope: options.scope,
1279
1540
  timeZone: options.timeZone
1280
1541
  });
1542
+ if (options.provider !== void 0) params.set("provider", options.provider);
1281
1543
  if (options.sessionId !== void 0) params.set("sessionId", options.sessionId);
1282
1544
  if (options.from !== void 0) params.set("from", options.from);
1283
1545
  if (options.to !== void 0) params.set("to", options.to);
@@ -1333,7 +1595,10 @@ window.__ModuleLoader__.load({
1333
1595
  id: "deepseek-balance",
1334
1596
  order: 10,
1335
1597
  locale: LOCALE_NS,
1336
- inject: () => ({ loadBalance })
1598
+ inject: (sessionId) => ({
1599
+ loadBalance,
1600
+ selection: ctx.modelDirectories.directoryFor(sessionId)
1601
+ })
1337
1602
  }, BalanceDock));
1338
1603
  }
1339
1604
  //#endregion