balance-dsh 2.2.6 → 2.2.8

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
@@ -471,6 +471,11 @@ window.__ModuleLoader__.load({
471
471
  不能放到基础规则上,新版 timeline 用 margin:0 auto 居中,会和它打架。 */
472
472
  .balance-footer--classic .balance-footer__value{margin-left:auto}
473
473
  .balance-footer__value--healthy{color:var(--dsw-alias-state-success-primary);background:rgba(34,197,94,.15)}
474
+ /* 余额耗尽时只把金额胶囊换成充值按钮(2026-11-13 用户:「余额用完 只替换余额处为充值按钮」)。
475
+ 盒子完全沿用 .balance-footer__value(min-width / padding / 圆角 / 居中),只换配色与文字,
476
+ 所以今日消耗、时段词、色带的位置一格都不动。配色取「低余额」那档红色,语义一致。 */
477
+ .balance-footer__value--topup{color:var(--dsw-alias-state-error-primary,#e5484d);background:rgba(229,72,77,.15)}
478
+ .balance-footer__value--topup:hover{background:rgba(229,72,77,.24)}
474
479
  /* 正在刷新:金额栏压成半透明旧值,和左侧的时段占位呼应,避免旧数字看起来像刚更新的 */
475
480
  /* 刷新中不再整体降透明度(2026-10-31:「播放手动刷新的动画时余额颜色怎么变了」)。
476
481
  原来这里 opacity:.9,和上面的 hover 变暗叠在一起,刷新那一下颜色明显发灰。
@@ -793,6 +798,8 @@ window.__ModuleLoader__.load({
793
798
  font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;
794
799
  }
795
800
  .balance-fab__value--low{color:var(--dsw-alias-state-error-primary,#d97706)}
801
+ /* 收起态矩形卡:余额那一行换成「充值」时同样只换配色,卡片结构与尺寸不变 */
802
+ .balance-fab__value--topup{color:var(--dsw-alias-state-error-primary,#e5484d);background:rgba(229,72,77,.15);border-radius:999px}
796
803
  /* 时段词 + 剩余时长:一行两段,剩余时长用弱化色;11px 是中文清晰度的下限 */
797
804
  .balance-fab__period{display:flex;align-items:baseline;justify-content:center;gap:4px;font-size:11px;line-height:13px;font-weight:600;letter-spacing:0;white-space:nowrap;opacity:.92}
798
805
  /* ⚠️ 剩余时长必须显式给 color(2026-10-31:「这个剩余怎么带颜色 展开是啥颜色就是啥颜色」)。
@@ -2774,7 +2781,13 @@ const CN_CALENDAR_SOURCES = [
2774
2781
  if (h < 24) return m === 0 ? h + "h" : h + "h" + m + "m";
2775
2782
  const d = Math.floor(h / 24);
2776
2783
  const rh = h % 24;
2777
- return rh === 0 ? d + "d" : d + "d" + rh + "h";
2784
+ // ⚠️ rh === 0 时**分钟必须单独带上**(2026-11-15 用户截图「空闲 剩 1d」)。
2785
+ // 周日上午 08:02 距周一 09:00 正好 24h57m,原来走 rh===0 分支直接 return "1d",
2786
+ // 57 分钟被整段吞掉;而 23h59m 反倒老老实实显示「23h59m」——
2787
+ // 24 小时这条边界上精度突然从分钟级掉到天级,看着就像剩余时间算错了。
2788
+ // 现在 rh 补 0 时退回分钟档:「1d57m」。比「24h57m」短、语义仍读得通。
2789
+ if (rh === 0) return m === 0 ? d + "d" : d + "d" + m + "m";
2790
+ return d + "d" + rh + "h";
2778
2791
  }
2779
2792
  /**
2780
2793
  * 余额位数多时返回降字号用的 class(空串 = 不降)。
@@ -4140,11 +4153,8 @@ const CN_CALENDAR_SOURCES = [
4140
4153
  jsx.jsxs("div", {
4141
4154
  className: "balance-stats-actions",
4142
4155
  children: [
4143
- jsx.jsx("a", {
4144
- className: "balance-stats-link",
4145
- ...externalLink(USAGE_URL, "usage"),
4146
- children: "查看官方用量",
4147
- }),
4156
+ // 2026-11-13:统计面板底下原来还挂着一个跳官网的入口,用户说多余了,已删。
4157
+ // 面板本身就在算用量,再挂一个外链只会让人以为官网那个才是准的。
4148
4158
  // 官方「去充值」走同一个原生平台视口(带平台凭据,不用网页登录)
4149
4159
  jsx.jsx("a", {
4150
4160
  className: "balance-stats-link balance-stats-link--primary",
@@ -5170,7 +5180,17 @@ function makeTodayFlowStyle() {
5170
5180
  // 后代即使 position:fixed 也完全不渲染——组件确实被调用了(wide=false),但 DOM 不可见。
5171
5181
  // portal 到 body 后 position:fixed 才真正生效(2026-09-28 用户反馈「收起侧边栏余额不显示」)。
5172
5182
  // 圆形 FAB 放不下长文本:余额显示「¥<金额>」,余额耗尽时用「充值」而不是「去充值」
5173
- const balanceText = "¥" + b.total_balance;
5183
+ // ⚠️ 符号按币种走(2026-11-13 issue #2):原来一律写死 ¥,纯 USD 账号会显示成
5184
+ // 「¥12.50」,既错又丢信息。展开态那条(totalText)本来就是「金额 + 币种代码」,
5185
+ // 这里只有 60px 的圆,用符号更省地方。
5186
+ // CNY / 空 → ¥(历史默认,绝大多数账号);USD → $;其它币种用三位代码 + 空格。
5187
+ const currencySign = (code) => {
5188
+ const c = String(code || "").toUpperCase();
5189
+ if (c === "" || c === "CNY" || c === "RMB") return "¥";
5190
+ if (c === "USD") return "$";
5191
+ return c + " ";
5192
+ };
5193
+ const balanceText = currencySign(b.currency) + b.total_balance;
5174
5194
 
5175
5195
  // ─── 新版(timeline)收起态:矩形卡片(2026-10-31) ────────────────────
5176
5196
  // 「这个同样跟随新版跟旧版的选择 当前样式是旧版 显示一个矩形 里面显示跟新版里一样的东西
@@ -5219,10 +5239,13 @@ function makeTodayFlowStyle() {
5219
5239
  const rectNum = String(b.total_balance);
5220
5240
  const stripCurrency = (s) => String(s == null ? "" : s).replace(/\s*[A-Z]{3}\s*$/, "");
5221
5241
  const rectRoll = roll === null ? null : { from: stripCurrency(roll.from), at: roll.at, done: roll.done };
5242
+ // ⚠️ 余额耗尽时整卡的跳转目标换成充值页(2026-11-13):卡片里那一行「充值」
5243
+ // 不能再嵌一个 <a>(a 套 a 是非法 HTML,浏览器会把外层拆开、点击行为也乱),
5244
+ // 所以直接把外层这颗 a 的 href 换掉 —— 点卡片任意位置都是去充值。
5222
5245
  const rectFab = withPanel(jsx.jsxs("a", {
5223
- className: "balance-fab balance-fab--rect",
5246
+ className: "balance-fab balance-fab--rect" + (depleted ? " balance-fab--rect-topup" : ""),
5224
5247
  style: rectStyle,
5225
- ...externalLink(USAGE_URL, "usage"),
5248
+ ...externalLink(depleted ? TOP_UP_URL : USAGE_URL, depleted ? "top-up" : "usage"),
5226
5249
  ...interactions,
5227
5250
  children: [
5228
5251
  // 右键水波(2026-10-31:「设计成水面波浪样式的 鼠标点击的对应区域为波浪中心 向外扩张」)。
@@ -5244,17 +5267,22 @@ function makeTodayFlowStyle() {
5244
5267
  },
5245
5268
  }),
5246
5269
  }),
5247
- // 余额
5270
+ // 余额(耗尽时这一行换成「充值」,卡片其余部分 —— 今日 / 时段 / 刻度条 —— 照常保留)
5248
5271
  jsx.jsx("span", {
5249
- className: "balance-fab__value" + (total > 0 && total < lowThreshold ? " balance-fab__value--low" : ""),
5250
- children: jsx.jsx("span", {
5251
- className: "balance-footer__roll",
5252
- children: renderRollCells(
5253
- buildRollCells(rectRoll === null ? rectNum : rectRoll.from, rectNum),
5254
- "f" + (rectRoll === null ? "" : rectRoll.at),
5255
- rectRoll !== null && rectRoll.done === true,
5256
- ),
5257
- }),
5272
+ className: "balance-fab__value"
5273
+ + (depleted
5274
+ ? " balance-fab__value--topup"
5275
+ : (total > 0 && total < lowThreshold ? " balance-fab__value--low" : "")),
5276
+ children: depleted
5277
+ ? "充值"
5278
+ : jsx.jsx("span", {
5279
+ className: "balance-footer__roll",
5280
+ children: renderRollCells(
5281
+ buildRollCells(rectRoll === null ? rectNum : rectRoll.from, rectNum),
5282
+ "f" + (rectRoll === null ? "" : rectRoll.at),
5283
+ rectRoll !== null && rectRoll.done === true,
5284
+ ),
5285
+ }),
5258
5286
  }),
5259
5287
  // 今日消费紧贴余额下方(2026-10-31 箭头标注:「今日消费显示在」这一行)。
5260
5288
  // 「今日」二字**常显、不进动画**(2026-10-31:「今日二字不算在动画里」),
@@ -5426,25 +5454,25 @@ function makeTodayFlowStyle() {
5426
5454
  // (1234.56 CNY 131.3px / 12345.67 CNY 141.1px),把自己撑出容器右缘。
5427
5455
  // 降一档字号就能收回来,宽度重新恒定 —— 配合 .balance-footer__value 的 min-width。
5428
5456
  const valueDensity = amountDensity(b.total_balance);
5429
- if (depleted) {
5430
- return withPanel(jsx.jsxs("div", {
5431
- className: "balance-footer" + footerEnterClass, id: "balance-footer-root",
5432
- ...interactions,
5433
- children: [
5434
- jsx.jsx("span", { className: "balance-footer__spacer" }),
5435
- jsx.jsx("a", {
5436
- className: "balance-footer__topup",
5437
- ...externalLink(TOP_UP_URL, "top-up", {
5438
- // 阻止冒泡:不要把"去充值"的点击误当成本行余额的单击/双击
5439
- onClick: (event) => event.stopPropagation(),
5440
- onDoubleClick: (event) => event.stopPropagation(),
5441
- onContextMenu: onBalanceContextMenu,
5442
- }),
5443
- children: "去充值",
5444
- }),
5445
- ],
5446
- }));
5447
- }
5457
+ // ⚠️ 余额耗尽**不再整行早退**(2026-11-13 用户:「在新版样式情况下 余额用完
5458
+ // 只替换余额处为充值按钮」)。原来这里直接 return 一个「spacer + 去充值」,于是
5459
+ // 新版样式底下「今日消耗 / 时段词 / 剩余时间 / 色带指针」**整块消失** ——
5460
+ // 那几项跟余额无关,账户没钱了它们照样有效,藏起来之后用户分不清是「没钱了」
5461
+ // 还是「插件坏了」(issue #2 就是被这么误判成插件坏掉的)。
5462
+ // 现在只把金额胶囊换成一颗充值按钮,其余元素的布局一格都不动。
5463
+ // 点击走 externalLink → openPlatformOrUrl → window.open,由 DSH 交给系统默认浏览器。
5464
+ const valueNode = depleted
5465
+ ? jsx.jsx("a", {
5466
+ className: "balance-footer__value balance-footer__value--topup" + valueDensity,
5467
+ ...externalLink(TOP_UP_URL, "top-up", {
5468
+ // 阻止冒泡:不要把「充值」的点击误当成本行余额的单击/双击
5469
+ onClick: (event) => event.stopPropagation(),
5470
+ onDoubleClick: (event) => event.stopPropagation(),
5471
+ onContextMenu: onBalanceContextMenu,
5472
+ }),
5473
+ children: "充值",
5474
+ })
5475
+ : null;
5448
5476
 
5449
5477
  // 与 periodSpan / buildTimeline 同源都用 timelineNow:三者必须指向同一时刻,
5450
5478
  // 否则边界那一分钟会出现“标签已是高峰、剩余时间还按空闲算”的自相矛盾。
@@ -5682,7 +5710,7 @@ function makeTodayFlowStyle() {
5682
5710
  children: [
5683
5711
  jsx.jsx("span", { className: "balance-footer__icon", children: jsx.jsx(WalletIcon, {}) }),
5684
5712
  jsx.jsx("span", { className: "balance-footer__label", children: "余额" }),
5685
- jsx.jsxs("span", {
5713
+ valueNode !== null ? valueNode : jsx.jsxs("span", {
5686
5714
  className: "balance-footer__value" + (low ? " balance-footer__value--low" : " balance-footer__value--healthy") + valueDensity,
5687
5715
  children: [
5688
5716
  totalText,
@@ -5703,7 +5731,7 @@ function makeTodayFlowStyle() {
5703
5731
  periodNode === null
5704
5732
  ? jsx.jsx("span", { className: "balance-footer__spacer" })
5705
5733
  : periodNode,
5706
- jsx.jsx("span", {
5734
+ valueNode !== null ? valueNode : jsx.jsx("span", {
5707
5735
  className: "balance-footer__value" + (low ? " balance-footer__value--low" : " balance-footer__value--healthy") + valueDensity,
5708
5736
  // key 绑定 waveSeq:只有右键手动刷新才 +1 → 重挂 → 白光把金额重新擦一遍。
5709
5737
  // 自动刷新(60s 轮询 / 对话完成触发的 fetch)不动 waveSeq,所以不会擦,
@@ -8984,8 +9012,8 @@ function UsageCostLine({ useProjection, sessionId }) {
8984
9012
  row(
8985
9013
  "diag",
8986
9014
  "生成诊断报告",
8987
- // 2026-11-09 用户:「把这段指令放在诊断按钮的说明里面」—— 命令和按钮同源,
8988
- // 说明里直接把指令写出来,用户看到这一行就知道会话里也能调。
9015
+ // 2026-11-09 用户:「把这段指令放在诊断按钮的说明里面」—— 命令和按钮同源,
9016
+ // 说明里直接把指令写出来,用户看到这一行就知道会话里也能调。
8989
9017
  "把余额、今日消耗的可信度、会话读取状态、浮窗定位原样列成一张表;数字不对劲时点一下,复制出来就能直接发给别人看。只读取,不改任何设置。会话里也可以直接发 /balance-dsh-diag,那条会带上本会话明细。",
8990
9018
  jsx.jsxs("div", {
8991
9019
  className: "balance-settings__diag-btns",
package/lib/index.js CHANGED
@@ -1077,7 +1077,7 @@ function formatBalance(balance) {
1077
1077
  // | { status:"failed" } (网络失败;官方明确“失败绝不变成 0 余额”)
1078
1078
  // client 是 AccountClientMetadata(version / locale / timezoneOffsetSeconds),
1079
1079
  // 缺字段会在平台侧组装请求头时抛错,所以三个字段都要给。
1080
- const PLUGIN_VERSION = "2.2.6";
1080
+ const PLUGIN_VERSION = "2.2.8";
1081
1081
 
1082
1082
  /** 斜杠命令名(2026-10-31 定案:用带作者后缀的全名,避免和别的余额插件撞车,也不设备用名)。
1083
1083
  * ⚠️ DSH 的 COMMAND_NAME = /^[a-z][a-z0-9_-]*$/u —— **只允许小写**。
@@ -1619,7 +1619,8 @@ function normalizeAccountBalance(result) {
1619
1619
  let found = false;
1620
1620
  for (const w of arr) {
1621
1621
  if (!w || typeof w.balance !== "string") continue;
1622
- if (w.currency !== currency) continue;
1622
+ // 币种比较不区分大小写:官方目前一律大写,但 "cny" 这种写法不该让整笔钱消失。
1623
+ if (String(w.currency).toUpperCase() !== String(currency).toUpperCase()) continue;
1623
1624
  const n = Number(w.balance);
1624
1625
  if (!Number.isFinite(n)) continue;
1625
1626
  sum += n;
@@ -1627,13 +1628,36 @@ function normalizeAccountBalance(result) {
1627
1628
  }
1628
1629
  return found ? sum : null;
1629
1630
  };
1630
- // 币种先看充值钱包,再看赠送钱包,都没有就按 CNY。
1631
- const currencyOf = (list) => {
1631
+ // ⚠️⚠️ 选币种**绝不能按「数组首项」**(2026-11-13 issue #2)。
1632
+ // 官方 getBalance() 返回的是**多币种钱包列表**,账号的 value 首项可能是一个余额为 0 的 USD 钱包
1633
+ // (bonusWallets 里通常还有一个同样为 0 的 USD,进一步坐实首项是空钱包):
1634
+ // value: [{ currency: "USD", balance: "0E-16" }, { currency: "CNY", balance: "16.1873..." }]
1635
+ // bonusWallets: [{ currency: "USD", balance: "0" }]
1636
+ // 按首项取到 USD → sumByCurrency(value, "USD") = 0 → topped_up = 0、granted = 0
1637
+ // → is_available = false → 客户端进 depleted 分支,整个余额行只剩一颗「去充值」,
1638
+ // 用户以为没钱,实际 CNY 有 16.18。同一份数据、只是数组顺序不同就换一个结果,纯属选错了。
1639
+ // 优先级:**有余额的 CNY → 有余额的任意币种 → 任意 CNY(哪怕 0)→ 第一个有效钱包 → CNY**。
1640
+ // CNY 排在最前是因为插件的计价与符号都是人民币口径;只有在完全没有 CNY 钱包时
1641
+ // (纯 USD 账号)才退到别的币种,那样至少能把金额显示出来。
1642
+ const walletsOf = (list) => {
1632
1643
  const arr = Array.isArray(list) ? list : [];
1633
- const hit = arr.find((w) => w && typeof w.currency === "string" && w.currency !== "");
1634
- return hit ? hit.currency : null;
1644
+ const out = [];
1645
+ for (const w of arr) {
1646
+ if (!w || typeof w.currency !== "string" || w.currency === "") continue;
1647
+ const n = Number(w.balance);
1648
+ out.push({ currency: w.currency, funded: Number.isFinite(n) && n > 0 });
1649
+ }
1650
+ return out;
1635
1651
  };
1636
- const currency = currencyOf(result.value) ?? currencyOf(result.bonusWallets) ?? "CNY";
1652
+ const allWallets = [...walletsOf(result.value), ...walletsOf(result.bonusWallets)];
1653
+ const isCnyWallet = (w) => w.currency.toUpperCase() === "CNY";
1654
+ const pickedWallet =
1655
+ allWallets.find((w) => w.funded && isCnyWallet(w)) ??
1656
+ allWallets.find((w) => w.funded) ??
1657
+ allWallets.find(isCnyWallet) ??
1658
+ allWallets[0] ??
1659
+ null;
1660
+ const currency = pickedWallet ? pickedWallet.currency : "CNY";
1637
1661
  const toppedSum = sumByCurrency(result.value, currency);
1638
1662
  const grantedSum = sumByCurrency(result.bonusWallets, currency);
1639
1663
  // 官方金额字符串遵循 big.js 文法(允许 0E-16 这类写法),Number() 能正确解析。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balance-dsh",
3
- "version": "2.2.6",
3
+ "version": "2.2.8",
4
4
  "description": "在 DeepSeek Harness 中显示 DeepSeek 账户余额和当前会话 token/费用消耗(含高峰/空闲峰谷计费)。仅支持 DeepSeek 官方模型与账号,暂不支持其他大模型。",
5
5
  "author": "Rannist",
6
6
  "type": "module",