@cassius0924/dsh-usage-dashboard 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -135,7 +135,7 @@ dsh plugin --profile web add ./path/to/dsh-usage-dashboard
135
135
 
136
136
  前提:
137
137
 
138
- - 已配置 `DEEPSEEK_API_KEY`(「设置 → 模型」里填,或放在 `$DSH_HOME/.credentials.yaml`)——余额接口要用。
138
+ - 余额优先走 DSH 的**账号登录**(浏览器授权,不需要 API Key);未登录账号时才回退到 `DEEPSEEK_API_KEY`(「设置 → 模型」里填,或放在 `$DSH_HOME/.credentials.yaml`)。
139
139
  - 本机有 pnpm(`dsh plugin` 是 pnpm 的转发器)。
140
140
 
141
141
  装好后打开 GUI,**进入任意一个会话**(「额度」tab 挂在 `conversation.view` 上,New Session 首页没有 tab 栏),顶部就能看到 `Chat / Trajectory / 额度`。
package/lib/client.js CHANGED
@@ -467,6 +467,7 @@ var zh = {
467
467
  "error.credentialsUnavailable": "\u51ED\u8BC1\u670D\u52A1\u4E0D\u53EF\u7528",
468
468
  "error.credentialRead": "\u8BFB\u53D6 API Key \u5931\u8D25\uFF1A{detail}",
469
469
  "error.noApiKey": "\u672A\u914D\u7F6E DEEPSEEK_API_KEY\uFF08\u53EF\u5728\u300C\u8BBE\u7F6E \u2192 \u6A21\u578B\u300D\u4E2D\u586B\u5199\uFF09",
470
+ "error.accountBalanceUnavailable": "\u8D26\u53F7\u4F59\u989D\u63A5\u53E3\u4E0D\u53EF\u7528\uFF0C\u4E14\u672A\u914D\u7F6E DEEPSEEK_API_KEY",
470
471
  "error.balanceRequest": "\u8BF7\u6C42\u4F59\u989D\u63A5\u53E3\u5931\u8D25\uFF1A{detail}",
471
472
  "error.balanceHttp": "\u4F59\u989D\u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF\uFF08HTTP {status}\uFF09",
472
473
  "error.balanceParse": "\u89E3\u6790\u4F59\u989D\u54CD\u5E94\u5931\u8D25",
@@ -488,7 +489,7 @@ var zh = {
488
489
  "balance.overYear": "> 365 \u5929",
489
490
  "balance.noRunway": "\u8FD1 {days} \u5929\u6CA1\u6709\u7528\u91CF\uFF0C\u65E0\u6CD5\u4F30\u7B97",
490
491
  "balance.runwayTitle": "\u6309\u8FD1 {days} \u5929\u65E5\u5747 \xA5{cost} \u4F30\u7B97\uFF08\u542B\u65E0\u7528\u91CF\u7684\u65E5\u5B50\uFF1B\u4ECA\u5929\u5C1A\u672A\u8FC7\u5B8C\uFF09",
491
- "balance.empty": "\u8BFB\u4E0D\u5230\u4F59\u989D\u3002\u8BF7\u786E\u8BA4\u300C\u8BBE\u7F6E \u2192 \u6A21\u578B\u300D\u91CC\u5DF2\u586B DEEPSEEK_API_KEY\uFF0C\u7136\u540E\u70B9\u53F3\u4E0A\u89D2\u5237\u65B0\u3002",
492
+ "balance.empty": "\u8BFB\u4E0D\u5230\u4F59\u989D\u3002\u8BF7\u786E\u8BA4\u8D26\u53F7\u5DF2\u767B\u5F55\uFF0C\u6216\u5728\u300C\u8BBE\u7F6E \u2192 \u6A21\u578B\u300D\u4E2D\u586B\u5199 DEEPSEEK_API_KEY\uFF0C\u7136\u540E\u70B9\u53F3\u4E0A\u89D2\u5237\u65B0\u3002",
492
493
  "sessionUsage.title": "\u5F53\u524D\u4F1A\u8BDD\u6D88\u8017\uFF08\u8D39\u7528\u4E3A\u4F30\u7B97\uFF09",
493
494
  "sessionUsage.cost": "\u672C\u4F1A\u8BDD\u8D39\u7528",
494
495
  "sessionUsage.tokens": "\u672C\u4F1A\u8BDD tokens",
@@ -725,6 +726,7 @@ var en = {
725
726
  "error.credentialsUnavailable": "Credential service is unavailable",
726
727
  "error.credentialRead": "Could not read the API key: {detail}",
727
728
  "error.noApiKey": "DEEPSEEK_API_KEY is not configured (add it under Settings \u2192 Models)",
729
+ "error.accountBalanceUnavailable": "The account balance endpoint is unavailable and DEEPSEEK_API_KEY is not configured",
728
730
  "error.balanceRequest": "Balance request failed: {detail}",
729
731
  "error.balanceHttp": "Balance endpoint returned HTTP {status}",
730
732
  "error.balanceParse": "Could not parse the balance response",
@@ -746,7 +748,7 @@ var en = {
746
748
  "balance.overYear": "> 365 days",
747
749
  "balance.noRunway": "No usage in the last {days} days, so runway cannot be estimated",
748
750
  "balance.runwayTitle": "Based on \xA5{cost} average daily spend over the last {days} days (including idle days; today is incomplete)",
749
- "balance.empty": "Balance is unavailable. Add DEEPSEEK_API_KEY under Settings \u2192 Models, then refresh.",
751
+ "balance.empty": "Balance is unavailable. Sign in to your account or add DEEPSEEK_API_KEY under Settings \u2192 Models, then refresh.",
750
752
  "sessionUsage.title": "Current session spend (estimated)",
751
753
  "sessionUsage.cost": "This session",
752
754
  "sessionUsage.tokens": "Session tokens",
@@ -830,6 +832,7 @@ function localizeApiError(message, t, fallback) {
830
832
  if (message === "\u4F59\u989D\u52A0\u8F7D\u5931\u8D25") return t("error.balanceLoad");
831
833
  if (message === "\u7528\u91CF\u52A0\u8F7D\u5931\u8D25") return t("error.usageLoad");
832
834
  if (message === "\u672A\u914D\u7F6E DEEPSEEK_API_KEY\uFF08\u53EF\u5728\u300C\u8BBE\u7F6E \u2192 \u6A21\u578B\u300D\u4E2D\u586B\u5199\uFF09") return t("error.noApiKey");
835
+ if (message === "\u8D26\u53F7\u4F59\u989D\u63A5\u53E3\u4E0D\u53EF\u7528\uFF0C\u4E14\u672A\u914D\u7F6E DEEPSEEK_API_KEY") return t("error.accountBalanceUnavailable");
833
836
  if (message === "\u89E3\u6790\u4F59\u989D\u54CD\u5E94\u5931\u8D25") return t("error.balanceParse");
834
837
  if (message === "\u4F1A\u8BDD\u6301\u4E45\u5316\u670D\u52A1\u4E0D\u53EF\u7528") return t("error.persistenceUnavailable");
835
838
  if (message === "\u7F3A\u5C11\u4F1A\u8BDD id") return t("error.missingSessionId");
@@ -2704,7 +2707,7 @@ function BalanceDashboard(props) {
2704
2707
  ] })
2705
2708
  ] })
2706
2709
  ] }),
2707
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "dq-footer", children: "@cassius0924/dsh-usage-dashboard v0.6.0" })
2710
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "dq-footer", children: "@cassius0924/dsh-usage-dashboard v0.6.1" })
2708
2711
  ] });
2709
2712
  }
2710
2713
 
@@ -3167,6 +3170,14 @@ p.dq-session-sub{margin:8px 0}
3167
3170
 
3168
3171
  // src/client/widget.tsx
3169
3172
  var import_react6 = require("react");
3173
+
3174
+ // src/client/sessions.ts
3175
+ function currentSessionIdOf(state) {
3176
+ const retained = Object.values(state.byId ?? {}).find((row) => (row?.retainedBy?.mainView ?? 0) > 0);
3177
+ return retained?.id ?? state.current;
3178
+ }
3179
+
3180
+ // src/client/widget.tsx
3170
3181
  var import_jsx_runtime6 = require("react/jsx-runtime");
3171
3182
  var MARGIN = 16;
3172
3183
  var CORNER_KEY = "widget.corner";
@@ -3217,7 +3228,7 @@ function cornerPos(corner, node, bounds) {
3217
3228
  }
3218
3229
  function QuotaWidget(props) {
3219
3230
  const { t } = useI18n();
3220
- const sessionId = props.useSessions((state) => state.current);
3231
+ const sessionId = props.useSessions(currentSessionIdOf);
3221
3232
  const [visible, setVisible] = (0, import_react6.useState)(widgetVisibleStore.get());
3222
3233
  (0, import_react6.useEffect)(() => widgetVisibleStore.subscribe(() => setVisible(widgetVisibleStore.get())), []);
3223
3234
  const [quotaViewActive2, setQuotaViewActive] = (0, import_react6.useState)(quotaViewActiveStore.get());