dsh-account-pool 0.2.3 → 0.2.5

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.
Files changed (2) hide show
  1. package/lib/client.js +37 -11
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -334,12 +334,23 @@ window.__ModuleLoader__.load({ id: "dsh-account-pool", factory: (require) => {
334
334
  * 大数字紧凑显示:1234567 → 1.23M。
335
335
  * 指标卡上空间有限,完整千分位会撑破布局;完整值放到 title 里。
336
336
  */
337
+ /**
338
+ * 大数缩写:1000 → K,1e6 → M,1e9 → B。
339
+ *
340
+ * 精度随量级放宽(1.55B 比 2B 有用),但**整数结果不带多余的 .0**:
341
+ * 800.0M 读起来像精度声明,其实 800M 就够——去掉尾零更干净。
342
+ *
343
+ * 缩写会丢精度,所以表格里用它时必须把精确值放到悬停。
344
+ */
337
345
  function formatCompact(n) {
338
346
  const v = Number(n) || 0;
339
347
  if (v < 1000) return String(v);
340
- if (v < 1e6) return (v / 1e3).toFixed(v < 1e4 ? 1 : 0) + "K";
341
- if (v < 1e9) return (v / 1e6).toFixed(v < 1e7 ? 2 : 1) + "M";
342
- return (v / 1e9).toFixed(2) + "B";
348
+ const scaled = v < 1e6 ? v / 1e3 : v < 1e9 ? v / 1e6 : v / 1e9;
349
+ const unit = v < 1e6 ? "K" : v < 1e9 ? "M" : "B";
350
+ const digits = v < 1e4 ? 1 : v < 1e7 ? 2 : 2;
351
+ // 去掉尾部多余的零:800.00M → 800M,1.50B → 1.5B,1.00K → 1K
352
+ // (先删结尾的 0,再删可能留下的小数点)
353
+ return scaled.toFixed(digits).replace(/0+$/, "").replace(/\.$/, "") + unit;
343
354
  }
344
355
 
345
356
  /** 等宽数字:表格里数字列对齐才读得下去。 */
@@ -1008,11 +1019,21 @@ window.__ModuleLoader__.load({ id: "dsh-account-pool", factory: (require) => {
1008
1019
  }));
1009
1020
 
1010
1021
  // 表格列宽:数字列右对齐、等宽,读起来才顺
1011
- const numCell = (value, color) => h("td", {
1022
+ /**
1023
+ * 数字单元格。
1024
+ *
1025
+ * @param {string} value 显示文本(可能是缩写的 1.69B)
1026
+ * @param {string} [color] 文字色
1027
+ * @param {string} [exact] 精确值,有则在悬停时显示——
1028
+ * 缩写会丢精度(1.69B 到底是 1,690,000,000 还是 1,689,999,999
1029
+ * 看不出来),能对账的数字要能查到原值。
1030
+ */
1031
+ const numCell = (value, color, exact) => h("td", {
1012
1032
  style: Object.assign({}, TD_STYLE, NUM_STYLE, {
1013
1033
  textAlign: "right",
1014
1034
  color: color ?? "var(--dsw-alias-label-primary)",
1015
1035
  }),
1036
+ ...(exact === undefined ? {} : { title: exact }),
1016
1037
  }, value);
1017
1038
 
1018
1039
  return h("div", { style: CARD_STYLE },
@@ -1042,15 +1063,17 @@ window.__ModuleLoader__.load({ id: "dsh-account-pool", factory: (require) => {
1042
1063
  }, busy ? "刷新中…" : "刷新"),
1043
1064
  ),
1044
1065
 
1045
- // ---- 核心指标:强制 4 列一行 ----
1046
- // 用 grid 而不是 flex-wrap:wrap 在窄面板里会把第 4 块挤到下一行,
1066
+ // ---- 核心指标:一行铺满 ----
1067
+ // 用 grid 而不是 flex-wrap:wrap 在窄面板里会把最后一块挤到下一行,
1047
1068
  // grid 的 1fr 会按可用宽度均分,永远保持一行。
1069
+ //
1070
+ // 列数必须跟着**实际指标数**走。之前只换类名、内联仍是 4 列,
1071
+ // 去掉积分后 Trae 就变成「3 个块占 4 列」——右边空一格,很难看。
1048
1072
  h("div", {
1049
- // 少一个指标时用 3 列网格,避免留下一个空位
1050
1073
  className: reportsCredits ? "wb-kpi-grid-4" : "wb-kpi-grid-3",
1051
1074
  style: {
1052
1075
  display: "grid",
1053
- gridTemplateColumns: "repeat(4, minmax(0, 1fr))",
1076
+ gridTemplateColumns: "repeat(" + (reportsCredits ? 4 : 3) + ", minmax(0, 1fr))",
1054
1077
  gap: "8px",
1055
1078
  marginBottom: "8px",
1056
1079
  },
@@ -1145,9 +1168,12 @@ window.__ModuleLoader__.load({ id: "dsh-account-pool", factory: (require) => {
1145
1168
  h("td", { style: Object.assign({}, TD_STYLE, { whiteSpace: "nowrap" }) }, m.key),
1146
1169
  numCell(formatNumber(m.requests)),
1147
1170
  numCell(formatNumber(m.errors), m.errors > 0 ? "var(--dsw-alias-state-error-primary)" : "var(--dsw-alias-label-secondary)"),
1148
- numCell(formatNumber(m.promptTokens)),
1149
- numCell(formatNumber(m.completionTokens)),
1150
- numCell(formatNumber(m.totalTokens)),
1171
+ // token 用 K/M/B 缩写:纯数字能到十位(如 1,690,000,000),
1172
+ // 把表格撑得很宽。精确值放悬停里,需要对账时够用。
1173
+ numCell(formatCompact(m.promptTokens), undefined, formatNumber(m.promptTokens) + " tokens"),
1174
+ numCell(formatCompact(m.completionTokens), undefined, formatNumber(m.completionTokens) + " tokens"),
1175
+ numCell(formatCompact(m.totalTokens), undefined, formatNumber(m.totalTokens) + " tokens"),
1176
+ // 积分保持整数:它是要对账的数字,缩写反而看不清
1151
1177
  numCell(formatNumber(m.credits)),
1152
1178
  )
1153
1179
  )),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-account-pool",
3
3
  "displayName": "Account Pool",
4
- "version": "0.2.3",
4
+ "version": "0.2.5",
5
5
  "description": "把多个 WorkBuddy / Trae 账号汇成账号池接入 DeepSeek Harness:自动切换、限流熔断退避、凭证安全落盘",
6
6
  "type": "module",
7
7
  "license": "MIT",