balance-dsh 2.2.5 → 2.2.7
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 +11 -8
- package/lib/client.js +183 -103
- package/lib/index.js +102 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -117,17 +117,20 @@ token 数用官方文档站「图片 Token 计算器」的同一套算法估算
|
|
|
117
117
|
两边内容同源,**开头第一行就是结论**——不用自己看懂字段,它会直接告诉你有没有查出问题:
|
|
118
118
|
|
|
119
119
|
```
|
|
120
|
-
诊断结论
|
|
121
|
-
✗
|
|
122
|
-
|
|
123
|
-
✗ 浮窗定位偏移 6px(卡片在 x=1156,应该在 x=1150)
|
|
124
|
-
! 今日是部分结果(刚冷启动或刚跨天),客户端会自动补拉
|
|
125
|
-
! 本会话 usage 读不到(会话没进内存或事件被切空),本会话金额会显示 ≈ ¥—
|
|
120
|
+
诊断结论 FAIL 1 项 · WARN 1 项
|
|
121
|
+
✗ 余额不可用:未登录
|
|
122
|
+
! 本会话 usage 缺失(会话未载入内存或事件为空),金额显示为 ¥—
|
|
126
123
|
```
|
|
127
124
|
|
|
128
|
-
一切正常时就是一行 `诊断结论
|
|
125
|
+
一切正常时就是一行 `诊断结论 PASS 5 项检查通过:余额 / 今日 / 本会话 / 浮窗 / 设置`。
|
|
129
126
|
|
|
130
|
-
|
|
127
|
+
**只有那几行会变颜色**:结论行按严重度取色(有异常红 / 只有提醒琥珀 / 全好绿),下面 `✗` 的行红、`!` 的行琥珀,其余正文保持普通颜色——满屏红会让人以为到处都坏了。
|
|
128
|
+
|
|
129
|
+
它查的是这几类:余额取不到 / 今日**确实漏算**了会话 / 今日会话列表没列出来 / 本会话读不到 usage / DSH 会话服务不可用 / 浮窗定位偏掉 / 设置里被填成 0 的扫描上限或倍率。
|
|
130
|
+
|
|
131
|
+
> **今日 ¥0 本身不算异常。** 当天还没产生消耗时,今天的候选会话天然为空,服务端会标一个 `suspiciousEmpty`——那只是「今天还没活动」,不是假 0。诊断只在两种情况下才说今日有问题:有会话被让路跳过没读到(`skipped > 0`,总额确实会偏少),或者连会话列表都没列出来(`emptyListing`,可能是 DSH 索引还没就绪)。今天确实没花钱,就一个字都不报。
|
|
132
|
+
|
|
133
|
+
后面跟着完整现场:余额、今日可信度、今日缓存与落盘快照、本会话(金额、模型、token 分项、高峰空闲拆分)、子代理与团队、当前设置口径、浮窗定位、会话读取状态,**最后附一段原始响应 JSON**(最多 6000 字)——没被正文明说的异常都能从那里对到具体字段,不用再开控制台。设置页那边有「复制」,整段贴出来即可。
|
|
131
134
|
|
|
132
135
|
查出问题时按钮旁边会多一个**「修复」**,点它会清掉能自己恢复的那几样再重算:
|
|
133
136
|
|
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:「这个剩余怎么带颜色 展开是啥颜色就是啥颜色」)。
|
|
@@ -1520,6 +1527,10 @@ window.__ModuleLoader__.load({
|
|
|
1520
1527
|
.balance-settings__diag-btns{display:flex;align-items:center;gap:6px;flex:none}
|
|
1521
1528
|
.balance-settings__diag{box-sizing:border-box;margin:8px 0 0;padding:10px 12px;max-height:320px;overflow:auto;border:.5px solid var(--dsw-alias-border-l2,rgba(127,127,127,.22));border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-base,rgba(0,0,0,.18));color:var(--dsw-alias-label-secondary);font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:11.5px;line-height:1.65;white-space:pre;tab-size:2;user-select:text;-webkit-user-select:text}
|
|
1522
1529
|
.balance-settings__diag--error{color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
1530
|
+
.balance-settings__diag-bad{color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
1531
|
+
.balance-settings__diag-warn{color:var(--dsw-alias-state-warn-primary,#d97706)}
|
|
1532
|
+
.balance-settings__diag-ok{color:var(--dsw-alias-state-success-primary,#3fb950)}
|
|
1533
|
+
.balance-settings__diag-head{font-weight:600}
|
|
1523
1534
|
.balance-settings__diag-fix{margin:8px 0 0;font-size:12px;line-height:17px}
|
|
1524
1535
|
.balance-settings__diag-fix--ok{color:var(--dsw-alias-state-success-primary,#3fb950)}
|
|
1525
1536
|
.balance-settings__diag-fix--warn{color:var(--dsw-alias-state-warn-primary,#d97706)}
|
|
@@ -2623,7 +2634,7 @@ const CN_CALENDAR_SOURCES = [
|
|
|
2623
2634
|
["usageLoadingStyle", "2.0.9"], // 消耗行加载动效:样式1(光团开窗)/ 样式2(计算中),含行内实时预览
|
|
2624
2635
|
["todaySessionLimit", "2.1.0"], // 今日消耗扫描上限:多开对话 / 多跑子代理时把今日汇总算全
|
|
2625
2636
|
["showUsagePill", "2.1.6"], // 2.1.6:消耗行搬成对话界面右下角小浮窗(两行:本会话估算 / 金额)
|
|
2626
|
-
["diag", "2.2.
|
|
2637
|
+
["diag", "2.2.6"], // 2.2.6:设置页「数据诊断」—— 一键出结论 + 复制 + 查出问题给「修复」
|
|
2627
2638
|
]);
|
|
2628
2639
|
|
|
2629
2640
|
/** NEW_TAGS 的 key → 设置项中文名。横幅要写「本版新增:消耗行加载动效」,
|
|
@@ -3182,11 +3193,14 @@ const CN_CALENDAR_SOURCES = [
|
|
|
3182
3193
|
}
|
|
3183
3194
|
/** 这一拍的 0 是不是「不可信」(列不出会话 / 筛不出会话 / 有会话被让路跳过)。 */
|
|
3184
3195
|
function todayZeroIsSuspect(value) {
|
|
3185
|
-
|
|
3186
|
-
if (
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3196
|
+
const cost = Number(value?.cost ?? 0);
|
|
3197
|
+
if (cost !== 0) return false;
|
|
3198
|
+
// ⚠️ 2026-11-11(用户:「我今日本来就没消耗 为什么说数据异常」):
|
|
3199
|
+
// 当天还没花钱时,候选会话天然为空,suspiciousEmpty 必然为 true —— 那是**正常状态**。
|
|
3200
|
+
// 把它当「可疑」会让插件白重试一整天。只有「确实漏读」或「列表根本没列出来」才值得重试:
|
|
3201
|
+
// · skipped > 0 —— 有会话被跳过,总额偏低
|
|
3202
|
+
// · emptyListing=true —— 连列表都没列出来,很可能是冷启动索引没好
|
|
3203
|
+
return Number(value?.skipped ?? 0) > 0 || value?.emptyListing === true;
|
|
3190
3204
|
}
|
|
3191
3205
|
const todayListeners = new Set();
|
|
3192
3206
|
function notifyToday() {
|
|
@@ -4133,11 +4147,8 @@ const CN_CALENDAR_SOURCES = [
|
|
|
4133
4147
|
jsx.jsxs("div", {
|
|
4134
4148
|
className: "balance-stats-actions",
|
|
4135
4149
|
children: [
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
...externalLink(USAGE_URL, "usage"),
|
|
4139
|
-
children: "查看官方用量",
|
|
4140
|
-
}),
|
|
4150
|
+
// 2026-11-13:统计面板底下原来还挂着一个跳官网的入口,用户说多余了,已删。
|
|
4151
|
+
// 面板本身就在算用量,再挂一个外链只会让人以为官网那个才是准的。
|
|
4141
4152
|
// 官方「去充值」走同一个原生平台视口(带平台凭据,不用网页登录)
|
|
4142
4153
|
jsx.jsx("a", {
|
|
4143
4154
|
className: "balance-stats-link balance-stats-link--primary",
|
|
@@ -5163,7 +5174,17 @@ function makeTodayFlowStyle() {
|
|
|
5163
5174
|
// 后代即使 position:fixed 也完全不渲染——组件确实被调用了(wide=false),但 DOM 不可见。
|
|
5164
5175
|
// portal 到 body 后 position:fixed 才真正生效(2026-09-28 用户反馈「收起侧边栏余额不显示」)。
|
|
5165
5176
|
// 圆形 FAB 放不下长文本:余额显示「¥<金额>」,余额耗尽时用「充值」而不是「去充值」
|
|
5166
|
-
|
|
5177
|
+
// ⚠️ 符号按币种走(2026-11-13 issue #2):原来一律写死 ¥,纯 USD 账号会显示成
|
|
5178
|
+
// 「¥12.50」,既错又丢信息。展开态那条(totalText)本来就是「金额 + 币种代码」,
|
|
5179
|
+
// 这里只有 60px 的圆,用符号更省地方。
|
|
5180
|
+
// CNY / 空 → ¥(历史默认,绝大多数账号);USD → $;其它币种用三位代码 + 空格。
|
|
5181
|
+
const currencySign = (code) => {
|
|
5182
|
+
const c = String(code || "").toUpperCase();
|
|
5183
|
+
if (c === "" || c === "CNY" || c === "RMB") return "¥";
|
|
5184
|
+
if (c === "USD") return "$";
|
|
5185
|
+
return c + " ";
|
|
5186
|
+
};
|
|
5187
|
+
const balanceText = currencySign(b.currency) + b.total_balance;
|
|
5167
5188
|
|
|
5168
5189
|
// ─── 新版(timeline)收起态:矩形卡片(2026-10-31) ────────────────────
|
|
5169
5190
|
// 「这个同样跟随新版跟旧版的选择 当前样式是旧版 显示一个矩形 里面显示跟新版里一样的东西
|
|
@@ -5212,10 +5233,13 @@ function makeTodayFlowStyle() {
|
|
|
5212
5233
|
const rectNum = String(b.total_balance);
|
|
5213
5234
|
const stripCurrency = (s) => String(s == null ? "" : s).replace(/\s*[A-Z]{3}\s*$/, "");
|
|
5214
5235
|
const rectRoll = roll === null ? null : { from: stripCurrency(roll.from), at: roll.at, done: roll.done };
|
|
5236
|
+
// ⚠️ 余额耗尽时整卡的跳转目标换成充值页(2026-11-13):卡片里那一行「充值」
|
|
5237
|
+
// 不能再嵌一个 <a>(a 套 a 是非法 HTML,浏览器会把外层拆开、点击行为也乱),
|
|
5238
|
+
// 所以直接把外层这颗 a 的 href 换掉 —— 点卡片任意位置都是去充值。
|
|
5215
5239
|
const rectFab = withPanel(jsx.jsxs("a", {
|
|
5216
|
-
className: "balance-fab balance-fab--rect",
|
|
5240
|
+
className: "balance-fab balance-fab--rect" + (depleted ? " balance-fab--rect-topup" : ""),
|
|
5217
5241
|
style: rectStyle,
|
|
5218
|
-
...externalLink(USAGE_URL, "usage"),
|
|
5242
|
+
...externalLink(depleted ? TOP_UP_URL : USAGE_URL, depleted ? "top-up" : "usage"),
|
|
5219
5243
|
...interactions,
|
|
5220
5244
|
children: [
|
|
5221
5245
|
// 右键水波(2026-10-31:「设计成水面波浪样式的 鼠标点击的对应区域为波浪中心 向外扩张」)。
|
|
@@ -5237,17 +5261,22 @@ function makeTodayFlowStyle() {
|
|
|
5237
5261
|
},
|
|
5238
5262
|
}),
|
|
5239
5263
|
}),
|
|
5240
|
-
//
|
|
5264
|
+
// 余额(耗尽时这一行换成「充值」,卡片其余部分 —— 今日 / 时段 / 刻度条 —— 照常保留)
|
|
5241
5265
|
jsx.jsx("span", {
|
|
5242
|
-
className: "balance-fab__value"
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5266
|
+
className: "balance-fab__value"
|
|
5267
|
+
+ (depleted
|
|
5268
|
+
? " balance-fab__value--topup"
|
|
5269
|
+
: (total > 0 && total < lowThreshold ? " balance-fab__value--low" : "")),
|
|
5270
|
+
children: depleted
|
|
5271
|
+
? "充值"
|
|
5272
|
+
: jsx.jsx("span", {
|
|
5273
|
+
className: "balance-footer__roll",
|
|
5274
|
+
children: renderRollCells(
|
|
5275
|
+
buildRollCells(rectRoll === null ? rectNum : rectRoll.from, rectNum),
|
|
5276
|
+
"f" + (rectRoll === null ? "" : rectRoll.at),
|
|
5277
|
+
rectRoll !== null && rectRoll.done === true,
|
|
5278
|
+
),
|
|
5279
|
+
}),
|
|
5251
5280
|
}),
|
|
5252
5281
|
// 今日消费紧贴余额下方(2026-10-31 箭头标注:「今日消费显示在」这一行)。
|
|
5253
5282
|
// 「今日」二字**常显、不进动画**(2026-10-31:「今日二字不算在动画里」),
|
|
@@ -5419,25 +5448,25 @@ function makeTodayFlowStyle() {
|
|
|
5419
5448
|
// (1234.56 CNY 131.3px / 12345.67 CNY 141.1px),把自己撑出容器右缘。
|
|
5420
5449
|
// 降一档字号就能收回来,宽度重新恒定 —— 配合 .balance-footer__value 的 min-width。
|
|
5421
5450
|
const valueDensity = amountDensity(b.total_balance);
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
})
|
|
5440
|
-
|
|
5451
|
+
// ⚠️ 余额耗尽**不再整行早退**(2026-11-13 用户:「在新版样式情况下 余额用完
|
|
5452
|
+
// 只替换余额处为充值按钮」)。原来这里直接 return 一个「spacer + 去充值」,于是
|
|
5453
|
+
// 新版样式底下「今日消耗 / 时段词 / 剩余时间 / 色带指针」**整块消失** ——
|
|
5454
|
+
// 那几项跟余额无关,账户没钱了它们照样有效,藏起来之后用户分不清是「没钱了」
|
|
5455
|
+
// 还是「插件坏了」(issue #2 就是被这么误判成插件坏掉的)。
|
|
5456
|
+
// 现在只把金额胶囊换成一颗充值按钮,其余元素的布局一格都不动。
|
|
5457
|
+
// 点击走 externalLink → openPlatformOrUrl → window.open,由 DSH 交给系统默认浏览器。
|
|
5458
|
+
const valueNode = depleted
|
|
5459
|
+
? jsx.jsx("a", {
|
|
5460
|
+
className: "balance-footer__value balance-footer__value--topup" + valueDensity,
|
|
5461
|
+
...externalLink(TOP_UP_URL, "top-up", {
|
|
5462
|
+
// 阻止冒泡:不要把「充值」的点击误当成本行余额的单击/双击
|
|
5463
|
+
onClick: (event) => event.stopPropagation(),
|
|
5464
|
+
onDoubleClick: (event) => event.stopPropagation(),
|
|
5465
|
+
onContextMenu: onBalanceContextMenu,
|
|
5466
|
+
}),
|
|
5467
|
+
children: "充值",
|
|
5468
|
+
})
|
|
5469
|
+
: null;
|
|
5441
5470
|
|
|
5442
5471
|
// 与 periodSpan / buildTimeline 同源都用 timelineNow:三者必须指向同一时刻,
|
|
5443
5472
|
// 否则边界那一分钟会出现“标签已是高峰、剩余时间还按空闲算”的自相矛盾。
|
|
@@ -5675,7 +5704,7 @@ function makeTodayFlowStyle() {
|
|
|
5675
5704
|
children: [
|
|
5676
5705
|
jsx.jsx("span", { className: "balance-footer__icon", children: jsx.jsx(WalletIcon, {}) }),
|
|
5677
5706
|
jsx.jsx("span", { className: "balance-footer__label", children: "余额" }),
|
|
5678
|
-
jsx.jsxs("span", {
|
|
5707
|
+
valueNode !== null ? valueNode : jsx.jsxs("span", {
|
|
5679
5708
|
className: "balance-footer__value" + (low ? " balance-footer__value--low" : " balance-footer__value--healthy") + valueDensity,
|
|
5680
5709
|
children: [
|
|
5681
5710
|
totalText,
|
|
@@ -5696,7 +5725,7 @@ function makeTodayFlowStyle() {
|
|
|
5696
5725
|
periodNode === null
|
|
5697
5726
|
? jsx.jsx("span", { className: "balance-footer__spacer" })
|
|
5698
5727
|
: periodNode,
|
|
5699
|
-
jsx.jsx("span", {
|
|
5728
|
+
valueNode !== null ? valueNode : jsx.jsx("span", {
|
|
5700
5729
|
className: "balance-footer__value" + (low ? " balance-footer__value--low" : " balance-footer__value--healthy") + valueDensity,
|
|
5701
5730
|
// key 绑定 waveSeq:只有右键手动刷新才 +1 → 重挂 → 白光把金额重新擦一遍。
|
|
5702
5731
|
// 自动刷新(60s 轮询 / 对话完成触发的 fetch)不动 waveSeq,所以不会擦,
|
|
@@ -7718,10 +7747,10 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7718
7747
|
if (d.balance == null) {
|
|
7719
7748
|
issues.push({
|
|
7720
7749
|
level: "error",
|
|
7721
|
-
text: d.balanceError ?
|
|
7750
|
+
text: d.balanceError ? `余额不可用:${d.balanceError}` : "余额不可用:未登录或网络失败",
|
|
7722
7751
|
});
|
|
7723
7752
|
} else if (d.balanceError) {
|
|
7724
|
-
issues.push({ level: "error", text:
|
|
7753
|
+
issues.push({ level: "error", text: `余额读取失败:${d.balanceError}` });
|
|
7725
7754
|
}
|
|
7726
7755
|
|
|
7727
7756
|
// 今日
|
|
@@ -7731,49 +7760,54 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7731
7760
|
if (today == null || typeof today !== "object") {
|
|
7732
7761
|
issues.push({
|
|
7733
7762
|
level: "warn",
|
|
7734
|
-
text:
|
|
7763
|
+
text: `今日未返回(todayPartial=${d.todayPartial === true}),客户端处于等待态`,
|
|
7735
7764
|
});
|
|
7736
7765
|
} else {
|
|
7737
7766
|
const cost = Number(today.cost ?? 0);
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7767
|
+
// ⚠️ 2026-11-11 用户(截图:今日 ¥0.0000 / sessions=0 / suspiciousEmpty=true):
|
|
7768
|
+
// 「我今日本来就没消耗 为什么说数据异常」。
|
|
7769
|
+
// 当天还没产生消耗时,今天的候选会话天然为空 → suspiciousEmpty 必然为 true,
|
|
7770
|
+
// **那是正常状态,不是假 0**。服务端也是这个口径:suspiciousEmpty 只负责「不落盘」,
|
|
7771
|
+
// 不改变发给客户端的值。所以只有「确实漏算了」才算异常:
|
|
7772
|
+
// · skipped > 0 —— 有会话被让路跳过没读,总额必然偏低 → error
|
|
7773
|
+
// · emptyListing=true —— 连会话列表都没列出来,可能还没索引好 → warn(也可能真没会话)
|
|
7774
|
+
// · cost=0 && 还在算 —— 提示一下就行
|
|
7775
|
+
// 其余情况(今天就是没花钱)**一个字都不报**。
|
|
7776
|
+
let skipped = 0;
|
|
7777
|
+
for (const s of [today, snap]) {
|
|
7778
|
+
if (s == null || typeof s !== "object") continue;
|
|
7779
|
+
skipped = Math.max(skipped, Number(s.skipped ?? 0) || 0);
|
|
7751
7780
|
}
|
|
7781
|
+
const emptyListing = today.emptyListing === true || snap?.emptyListing === true;
|
|
7752
7782
|
const pending = td != null && (td.cacheProvisional === true || td.recomputing === true);
|
|
7753
|
-
if (cost === 0 &&
|
|
7783
|
+
if (cost === 0 && skipped > 0) {
|
|
7754
7784
|
issues.push({
|
|
7755
7785
|
level: "error",
|
|
7756
|
-
text: `今日 ¥0.0000
|
|
7786
|
+
text: `今日 ¥0.0000 偏低:${skipped} 个会话读取被跳过,已排入退避重试`,
|
|
7787
|
+
});
|
|
7788
|
+
} else if (cost === 0 && emptyListing) {
|
|
7789
|
+
issues.push({
|
|
7790
|
+
level: "warn",
|
|
7791
|
+
text: "今日会话列表为空(DSH 索引未就绪);存在消耗时将于重算后更新",
|
|
7757
7792
|
});
|
|
7758
7793
|
} else if (cost === 0 && pending) {
|
|
7759
|
-
issues.push({ level: "warn", text: "
|
|
7760
|
-
}
|
|
7761
|
-
if (d.todayPartial === true) {
|
|
7762
|
-
issues.push({ level: "warn", text: "今日是部分结果(刚冷启动或刚跨天),客户端会自动补拉" });
|
|
7794
|
+
issues.push({ level: "warn", text: "今日重算中,当前 0 为占位值" });
|
|
7763
7795
|
}
|
|
7764
7796
|
}
|
|
7765
7797
|
|
|
7766
7798
|
// 本会话 / 会话服务
|
|
7767
7799
|
if (d.diag != null && typeof d.diag === "object") {
|
|
7768
7800
|
if (d.diag.sessionsUsable === false) {
|
|
7769
|
-
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false
|
|
7801
|
+
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false),本会话消耗回退磁盘读取,耗时增加" });
|
|
7770
7802
|
}
|
|
7771
7803
|
}
|
|
7772
|
-
|
|
7773
|
-
|
|
7804
|
+
// 设置页点诊断时请求不带 session,usage 必然是 null —— 那不是故障,
|
|
7805
|
+
// 报告里「本会话」段已经写明「未参与统计」,这里再报一条只会让人以为坏了。
|
|
7806
|
+
if (d.usage == null && d.loading !== true && d.diag?.sessionRequested === true) {
|
|
7807
|
+
issues.push({ level: "warn", text: "本会话 usage 缺失(会话未载入内存或事件为空),金额显示为 ¥—" });
|
|
7774
7808
|
}
|
|
7775
7809
|
if (d.loading === true) {
|
|
7776
|
-
issues.push({ level: "warn", text: "DSH
|
|
7810
|
+
issues.push({ level: "warn", text: "DSH 正在装载本会话,插件让路(正常状态,数秒后恢复)" });
|
|
7777
7811
|
}
|
|
7778
7812
|
|
|
7779
7813
|
// 浮窗定位
|
|
@@ -7784,37 +7818,51 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7784
7818
|
if (selfX !== null && left !== null && Math.abs(selfX - left) > 2) {
|
|
7785
7819
|
issues.push({
|
|
7786
7820
|
level: "error",
|
|
7787
|
-
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px
|
|
7821
|
+
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px(实际 x=${selfX},期望 x=${left})`,
|
|
7788
7822
|
});
|
|
7789
7823
|
}
|
|
7790
7824
|
}
|
|
7791
7825
|
|
|
7792
7826
|
// 设置自检:这几项填成 0 会让数字永远不对,但界面上完全看不出来
|
|
7793
7827
|
if (Number(s.todaySessionLimit ?? 1) <= 0) {
|
|
7794
|
-
issues.push({ level: "error", text: "
|
|
7828
|
+
issues.push({ level: "error", text: "设置项「今日扫描上限」= 0,今日金额将恒为 0" });
|
|
7795
7829
|
}
|
|
7796
7830
|
if (Number(s.statsSessionLimit ?? 1) <= 0) {
|
|
7797
|
-
issues.push({ level: "error", text: "
|
|
7831
|
+
issues.push({ level: "error", text: "设置项「统计扫描上限」= 0,统计面板将恒为 0" });
|
|
7798
7832
|
}
|
|
7799
7833
|
if (Number(s.peakMultiplier ?? 1) <= 0) {
|
|
7800
|
-
issues.push({ level: "error", text: "
|
|
7834
|
+
issues.push({ level: "error", text: "设置项「高峰倍率」= 0,高峰时段金额将被计为 0" });
|
|
7801
7835
|
}
|
|
7802
7836
|
return issues;
|
|
7803
7837
|
}
|
|
7804
7838
|
|
|
7839
|
+
/** 单行着色(2026-11-11 用户:「这个诊断日志太乱了 怎么全红 就给错误信息标红就行了」)。
|
|
7840
|
+
* 整块变红会让人以为满屏都是故障,实际上只有结论和那几条问题需要红。
|
|
7841
|
+
* 返回的 class 只挂在那几行上,其余保持正文色。 */
|
|
7842
|
+
function diagLineClass(line) {
|
|
7843
|
+
const t = typeof line === "string" ? line : "";
|
|
7844
|
+
if (t.startsWith("诊断结论")) {
|
|
7845
|
+
if (t.includes("FAIL")) return "balance-settings__diag-bad balance-settings__diag-head";
|
|
7846
|
+
if (t.includes("WARN")) return "balance-settings__diag-warn balance-settings__diag-head";
|
|
7847
|
+
return "balance-settings__diag-ok balance-settings__diag-head";
|
|
7848
|
+
}
|
|
7849
|
+
if (t.startsWith(" ✗")) return "balance-settings__diag-bad";
|
|
7850
|
+
if (t.startsWith(" !")) return "balance-settings__diag-warn";
|
|
7851
|
+
return "";
|
|
7852
|
+
}
|
|
7805
7853
|
/** 结论段:报告最上面那几行。 */
|
|
7806
7854
|
function formatDiagVerdict(issues) {
|
|
7807
7855
|
const bad = issues.filter((x) => x.level === "error");
|
|
7808
7856
|
const warn = issues.filter((x) => x.level === "warn");
|
|
7809
7857
|
const out = [];
|
|
7810
7858
|
if (bad.length === 0 && warn.length === 0) {
|
|
7811
|
-
out.push("诊断结论
|
|
7859
|
+
out.push("诊断结论 PASS 5 项检查通过:余额 / 今日 / 本会话 / 浮窗 / 设置");
|
|
7812
7860
|
return out;
|
|
7813
7861
|
}
|
|
7814
7862
|
const head = [];
|
|
7815
|
-
if (bad.length !== 0) head.push(
|
|
7816
|
-
if (warn.length !== 0) head.push(
|
|
7817
|
-
out.push(`诊断结论 ${head.join("
|
|
7863
|
+
if (bad.length !== 0) head.push(`FAIL ${bad.length} 项`);
|
|
7864
|
+
if (warn.length !== 0) head.push(`WARN ${warn.length} 项`);
|
|
7865
|
+
out.push(`诊断结论 ${head.join(" · ")}`);
|
|
7818
7866
|
for (const item of bad) out.push(` ✗ ${item.text}`);
|
|
7819
7867
|
for (const item of warn) out.push(` ! ${item.text}`);
|
|
7820
7868
|
return out;
|
|
@@ -7829,9 +7877,18 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7829
7877
|
const d = data != null && typeof data === "object" ? data : {};
|
|
7830
7878
|
const s = settings != null && typeof settings === "object" ? settings : {};
|
|
7831
7879
|
const lines = [];
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7880
|
+
// ⚠️ 2026-11-11:桌面版页面的 hostname 是 `app`、port 为空,原来拼出来是「app:?」,
|
|
7881
|
+
// 看着像故障。直接取 location.host(有端口才带端口),空的就写个破折号。
|
|
7882
|
+
const where = (() => {
|
|
7883
|
+
if (typeof location !== "object" || location === null) return "—";
|
|
7884
|
+
// 浏览器一定有 host(hostname + 非空才带 :port);测试夹具只给 hostname/port,
|
|
7885
|
+
// 所以这里自己拼一遍,别指望 location.host 一定存在。
|
|
7886
|
+
if (typeof location.host === "string" && location.host !== "") return location.host;
|
|
7887
|
+
const host = String(location.hostname || "");
|
|
7888
|
+
const port = String(location.port || "");
|
|
7889
|
+
if (host === "") return "—";
|
|
7890
|
+
return port === "" ? host : host + ":" + port;
|
|
7891
|
+
})();
|
|
7835
7892
|
lines.push(`balance-dsh ${version || "—"} · ${where} · ${formatDiagTime(Date.now())}`);
|
|
7836
7893
|
const issues = collectDiagIssues(d, s);
|
|
7837
7894
|
lines.push("");
|
|
@@ -7858,32 +7915,45 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7858
7915
|
const today = d.today;
|
|
7859
7916
|
const td = d.todayDiag != null && typeof d.todayDiag === "object" ? d.todayDiag : null;
|
|
7860
7917
|
const snap = td != null && td.snapshot != null && typeof td.snapshot === "object" ? td.snapshot : null;
|
|
7918
|
+
// ⚠️ 2026-11-11(用户:「我今日本来就没消耗 为什么说数据异常」):
|
|
7919
|
+
// `suspiciousEmpty` **不算**「不可信」。它的含义是「今天的候选会话为空」——
|
|
7920
|
+
// 当天还没产生消耗时它必然为 true,那是正常状态,不是假 0。
|
|
7921
|
+
// 服务端那边保留它只为了「这种 0 先别落盘」(保守,防止假 0 固化),
|
|
7922
|
+
// 但给用户看的时候只有「确实漏读」或「列表根本没列出来」才叫不可信。
|
|
7861
7923
|
const anySuspect =
|
|
7862
|
-
today?.suspiciousEmpty === true ||
|
|
7863
|
-
today?.emptyListing === true ||
|
|
7864
7924
|
Number(today?.skipped ?? 0) > 0 ||
|
|
7865
|
-
|
|
7866
|
-
snap?.
|
|
7867
|
-
|
|
7925
|
+
today?.emptyListing === true ||
|
|
7926
|
+
Number(snap?.skipped ?? 0) > 0 ||
|
|
7927
|
+
snap?.emptyListing === true;
|
|
7868
7928
|
lines.push("");
|
|
7869
7929
|
lines.push("── 今日 ──");
|
|
7870
7930
|
if (today == null || typeof today !== "object") {
|
|
7871
|
-
lines.push(
|
|
7931
|
+
lines.push(`— 未返回(todayPartial=${d.todayPartial === true})`);
|
|
7872
7932
|
} else {
|
|
7873
7933
|
lines.push(
|
|
7874
7934
|
`金额 ${formatDiagMoney(today.cost)} date=${today.date ?? "—"} ` +
|
|
7875
7935
|
`sessions=${today.sessions ?? 0} tokens=${today.totalTokens ?? 0}`,
|
|
7876
7936
|
);
|
|
7937
|
+
// 2026-11-11(用户:「今日消耗为什么还是异常为0 明明都消耗了token了」):
|
|
7938
|
+
// 冷启动那一拍服务端可能先发一个「还在算」的占位(sessions=0 / tokens=0 / partial=true),
|
|
7939
|
+
// 真值要等后台算完再补。光看上面那行会以为「今天真的没花钱」,所以直接把状态写出来。
|
|
7940
|
+
if (d.todayPartial === true) {
|
|
7941
|
+
lines.push(
|
|
7942
|
+
Number(today.cost ?? 0) === 0
|
|
7943
|
+
? "状态 partial=true 尚无结果,当前 0 为占位值,重算完成后替换"
|
|
7944
|
+
: "状态 partial=true 后台重算中,当前为增量结果",
|
|
7945
|
+
);
|
|
7946
|
+
}
|
|
7877
7947
|
// 三态:光看 today 是分不出「真 0」和「还在算」的
|
|
7878
7948
|
const zeroCost = Number(today.cost ?? 0) === 0;
|
|
7879
7949
|
const pending = td != null && (td.cacheProvisional === true || td.recomputing === true);
|
|
7880
7950
|
const verdict = !zeroCost
|
|
7881
|
-
? "
|
|
7951
|
+
? "是"
|
|
7882
7952
|
: anySuspect
|
|
7883
|
-
? "
|
|
7953
|
+
? "否(可疑零值,已排入退避重试)"
|
|
7884
7954
|
: pending
|
|
7885
|
-
? "
|
|
7886
|
-
: "
|
|
7955
|
+
? "待定(provisional 或重算中)"
|
|
7956
|
+
: "是";
|
|
7887
7957
|
lines.push(
|
|
7888
7958
|
`可信 ${verdict} suspiciousEmpty=${today.suspiciousEmpty === true} ` +
|
|
7889
7959
|
`emptyListing=${today.emptyListing === true} skipped=${today.skipped ?? 0} ` +
|
|
@@ -7893,11 +7963,11 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7893
7963
|
if (td != null) {
|
|
7894
7964
|
lines.push(
|
|
7895
7965
|
`缓存 cost=${td.cacheCost == null ? "—" : Number(td.cacheCost).toFixed(4)} ` +
|
|
7896
|
-
|
|
7897
|
-
`provisional=${td.cacheProvisional === true}
|
|
7966
|
+
`TTL=${Math.round(Number(td.cacheExpiresInMs ?? 0) / 1000)}s ` +
|
|
7967
|
+
`provisional=${td.cacheProvisional === true} recomputing=${td.recomputing === true}`,
|
|
7898
7968
|
);
|
|
7899
7969
|
if (snap == null) {
|
|
7900
|
-
lines.push("快照
|
|
7970
|
+
lines.push("快照 — 不存在(可疑结果不落盘,或今日尚未计算)");
|
|
7901
7971
|
} else {
|
|
7902
7972
|
lines.push(
|
|
7903
7973
|
`快照 ${formatDiagMoney(snap.cost)} date=${snap.date ?? "—"} v=${snap.v ?? "—"} ` +
|
|
@@ -7924,7 +7994,7 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7924
7994
|
if (usage.webToolCost != null) extra.push(`网页工具 ${formatDiagMoney(usage.webToolCost)}`);
|
|
7925
7995
|
if (extra.length) lines.push(`拆分 ${extra.join(" ")}`);
|
|
7926
7996
|
} else {
|
|
7927
|
-
lines.push("
|
|
7997
|
+
lines.push("— 请求未带 session,不参与本次统计(本会话明细用 /balance-dsh-diag)");
|
|
7928
7998
|
}
|
|
7929
7999
|
const team = d.team;
|
|
7930
8000
|
if (team != null && typeof team === "object" && Number(team.count ?? 0) > 0) {
|
|
@@ -7953,7 +8023,7 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7953
8023
|
lines.push("── 浮窗 ──");
|
|
7954
8024
|
const g = d.floatGeom;
|
|
7955
8025
|
if (g == null || typeof g !== "object") {
|
|
7956
|
-
lines.push("
|
|
8026
|
+
lines.push("— 无测量数据(浮窗未渲染或页面刚加载)");
|
|
7957
8027
|
} else {
|
|
7958
8028
|
const selfX = g.self != null && Number.isFinite(Number(g.self.x)) ? Number(g.self.x) : null;
|
|
7959
8029
|
const left = Number.isFinite(Number(g.left)) ? Number(g.left) : null;
|
|
@@ -7979,9 +8049,9 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7979
8049
|
`sessionUndefined=${diag.sessionUndefined === true} hasGet=${diag.hasGet === true}`,
|
|
7980
8050
|
);
|
|
7981
8051
|
if (diag.persistedError) lines.push(`persistedError=${diag.persistedError}`);
|
|
7982
|
-
if (d.loading === true) lines.push("loading=true
|
|
8052
|
+
if (d.loading === true) lines.push("loading=true 会话装载中,插件让路");
|
|
7983
8053
|
} else {
|
|
7984
|
-
lines.push("
|
|
8054
|
+
lines.push("— 请求未带 session,服务端未计算");
|
|
7985
8055
|
}
|
|
7986
8056
|
|
|
7987
8057
|
// ── 原始响应:没被上面提到的东西全在这里,出问题时能对到具体字段 ──
|
|
@@ -8988,10 +9058,20 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
8988
9058
|
: null,
|
|
8989
9059
|
diagReport.text
|
|
8990
9060
|
? jsx.jsx("pre", {
|
|
8991
|
-
|
|
8992
|
-
|
|
8993
|
-
|
|
8994
|
-
children: diagReport.
|
|
9061
|
+
// 只给「结论 + ✗ / ! 那几行」上色,其余走正文色。
|
|
9062
|
+
// 整块变红(旧的 --error)会让人以为满屏都是故障。
|
|
9063
|
+
className: "balance-settings__diag",
|
|
9064
|
+
children: diagReport.kind === "error"
|
|
9065
|
+
? diagReport.text
|
|
9066
|
+
: diagReport.text.split("\n").map((line, i, all) => {
|
|
9067
|
+
const cls = diagLineClass(line);
|
|
9068
|
+
return [
|
|
9069
|
+
cls === ""
|
|
9070
|
+
? line
|
|
9071
|
+
: jsx.jsx("span", { className: cls, children: line }),
|
|
9072
|
+
i === all.length - 1 ? "" : "\n",
|
|
9073
|
+
];
|
|
9074
|
+
}),
|
|
8995
9075
|
})
|
|
8996
9076
|
: null,
|
|
8997
9077
|
]),
|
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.
|
|
1080
|
+
const PLUGIN_VERSION = "2.2.7";
|
|
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
|
-
|
|
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
|
-
//
|
|
1631
|
-
|
|
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
|
|
1634
|
-
|
|
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
|
|
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() 能正确解析。
|
|
@@ -2275,8 +2299,16 @@ function withSettings(config, settings) {
|
|
|
2275
2299
|
peakMultiplier: s.peakMultiplier,
|
|
2276
2300
|
priceByModel,
|
|
2277
2301
|
statsSessionLimit: s.statsSessionLimit,
|
|
2278
|
-
|
|
2302
|
+
todaySessionLimit: s.todaySessionLimit,
|
|
2279
2303
|
statsCacheMs: s.statsCacheSec * 1000,
|
|
2304
|
+
// ⚠️ 这四个原来只存在于 settingsState 里,没进 effectiveConfig —— 于是
|
|
2305
|
+
// `effectiveConfig.refreshIntervalSec` 之类全是 undefined,诊断报告的「设置」段
|
|
2306
|
+
// 印成「轮询 undefined 统计缓存 undefined 低余额阈值 undefined 高峰 undefined × 2」
|
|
2307
|
+
// (2026-11-11 用户截图)。业务函数拿到的必须是完整口径,一律在这里补齐。
|
|
2308
|
+
refreshIntervalSec: s.refreshIntervalSec,
|
|
2309
|
+
lowBalanceThreshold: s.lowBalanceThreshold,
|
|
2310
|
+
statsCacheSec: s.statsCacheSec,
|
|
2311
|
+
peakWindowsText: s.peakWindowsText,
|
|
2280
2312
|
};
|
|
2281
2313
|
}
|
|
2282
2314
|
|
|
@@ -2507,6 +2539,14 @@ async function readTodaySnapshot(file) {
|
|
|
2507
2539
|
sessions: Number.isFinite(Number(parsed.sessions)) ? Number(parsed.sessions) : 0,
|
|
2508
2540
|
at: Number.isFinite(Number(parsed.at)) ? Number(parsed.at) : 0,
|
|
2509
2541
|
bySession,
|
|
2542
|
+
// ⚠️ 这四个标记必须一起还原(2026-11-11 用户:「怎么今日不一样」)。
|
|
2543
|
+
// 原来只还原前六项,于是读出来的快照永远带着 suspiciousEmpty=false / emptyListing=false /
|
|
2544
|
+
// skipped=0 —— 诊断里印「v=— skipped=0」看着一切正常,实际可能被让路跳过过;
|
|
2545
|
+
// mergeTodayMax 合并出来的对象也不带这些标记,客户端那三处判定全部失效。
|
|
2546
|
+
v: TODAY_SNAPSHOT_VERSION,
|
|
2547
|
+
suspiciousEmpty: parsed.suspiciousEmpty === true,
|
|
2548
|
+
emptyListing: parsed.emptyListing === true,
|
|
2549
|
+
skipped: Number.isFinite(Number(parsed.skipped)) && Number(parsed.skipped) >= 0 ? Number(parsed.skipped) : 0,
|
|
2510
2550
|
};
|
|
2511
2551
|
} catch {
|
|
2512
2552
|
return null;
|
|
@@ -4154,8 +4194,22 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4154
4194
|
// 今日
|
|
4155
4195
|
let today = null;
|
|
4156
4196
|
let todayPartial = false;
|
|
4197
|
+
// ⚠️ 必须带 reuse 走「和界面同一条路」(2026-11-11 用户:「怎么今日不一样」——
|
|
4198
|
+
// 界面 ¥0.69 / 报告 ¥0.6145)。`?session=` 每次都把当前会话的事件当 reuse 传进去,
|
|
4199
|
+
// 能看见「已发生但还没落盘」的那一截;报告原来走 `?today=1` 那条(只认持久化文件),
|
|
4200
|
+
// 天然比界面少一截,而且不重算、直接命中旧内存缓存 → 两个数必然对不上。
|
|
4201
|
+
// 报告是用户主动触发的低频操作,多读一次磁盘换来口径一致,值。
|
|
4202
|
+
const reportReuse = (() => {
|
|
4203
|
+
if (sessionId === "" || session == null) return null;
|
|
4204
|
+
try {
|
|
4205
|
+
const own = ownEventsOf(session?.header ?? null, sessionEvents(session));
|
|
4206
|
+
return Array.isArray(own) && own.length > 0 ? { sessionId, events: own, meta: session?.header ?? null } : null;
|
|
4207
|
+
} catch {
|
|
4208
|
+
return null;
|
|
4209
|
+
}
|
|
4210
|
+
})();
|
|
4157
4211
|
try {
|
|
4158
|
-
const got = await resolveTodayCost(ctx, config, todayState);
|
|
4212
|
+
const got = await resolveTodayCost(ctx, config, todayState, reportReuse);
|
|
4159
4213
|
today = got?.value ?? null;
|
|
4160
4214
|
todayPartial = got?.partial === true;
|
|
4161
4215
|
} catch (error) {
|
|
@@ -4163,26 +4217,30 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4163
4217
|
}
|
|
4164
4218
|
if (today != null) {
|
|
4165
4219
|
lines.push(`**今日** ${money(today.cost)} date=${today.date ?? "—"} sessions=${today.sessions ?? 0} tokens=${today.totalTokens ?? 0}`);
|
|
4220
|
+
// ⚠️ 2026-11-11(用户:「我今日本来就没消耗 为什么说数据异常」):
|
|
4221
|
+
// 当天还没产生消耗时,候选会话天然为空 → suspiciousEmpty 必然为 true,那是**正常状态**。
|
|
4222
|
+
// 只有「确实漏读」或「列表根本没列出来」才值得说:
|
|
4166
4223
|
const unreliable = todayValueUnreliable(today);
|
|
4167
4224
|
const cost = Number(today.cost ?? 0);
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
if (today.suspiciousEmpty === true) why.push("列得出会话但今天一个都没筛中");
|
|
4171
|
-
if (today.emptyListing === true) why.push("连会话列表都没列出来(DSH 索引还没就绪)");
|
|
4172
|
-
if (Number(today.skipped ?? 0) > 0) why.push(`${today.skipped} 个会话被让路跳过`);
|
|
4225
|
+
const skippedCount = Number(today.skipped ?? 0) || 0;
|
|
4226
|
+
if (cost === 0 && skippedCount > 0) {
|
|
4173
4227
|
issues.push({
|
|
4174
4228
|
level: "error",
|
|
4175
|
-
text: `今日 ¥0.0000
|
|
4229
|
+
text: `今日 ¥0.0000 偏低:${skippedCount} 个会话读取被跳过,已排入退避重试`,
|
|
4230
|
+
});
|
|
4231
|
+
} else if (cost === 0 && today.emptyListing === true) {
|
|
4232
|
+
issues.push({
|
|
4233
|
+
level: "warn",
|
|
4234
|
+
text: "今日会话列表为空(DSH 索引未就绪);存在消耗时将于重算后更新",
|
|
4176
4235
|
});
|
|
4177
4236
|
}
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
}
|
|
4181
|
-
lines.push(` 可信=${unreliable ? "不可信(假 0 / 少算,客户端会自动退避重试)" : "可信"} ` +
|
|
4237
|
+
void unreliable;
|
|
4238
|
+
lines.push(` 可信=${unreliable ? "否(可疑零值,客户端自动退避重试)" : "是"} ` +
|
|
4182
4239
|
`suspiciousEmpty=${today.suspiciousEmpty === true} emptyListing=${today.emptyListing === true} ` +
|
|
4183
4240
|
`skipped=${today.skipped ?? 0} partial=${todayPartial}`);
|
|
4184
|
-
lines.push(` 缓存
|
|
4185
|
-
`
|
|
4241
|
+
lines.push(` 缓存 TTL=${Math.max(0, Math.round((todayState.cache.expiresAt - Date.now()) / 1000))}s ` +
|
|
4242
|
+
`cost=${todayState.cache.value?.cost == null ? "—" : Number(todayState.cache.value.cost).toFixed(4)} ` +
|
|
4243
|
+
`provisional=${todayState.cache.value?.provisional === true} recomputing=${todayState.recompute != null}`);
|
|
4186
4244
|
}
|
|
4187
4245
|
let snap = null;
|
|
4188
4246
|
try {
|
|
@@ -4191,7 +4249,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4191
4249
|
snap = null;
|
|
4192
4250
|
}
|
|
4193
4251
|
if (snap == null) {
|
|
4194
|
-
lines.push(" 落盘快照
|
|
4252
|
+
lines.push(" 落盘快照 — 不存在(可疑结果不落盘,或今日尚未计算)");
|
|
4195
4253
|
} else {
|
|
4196
4254
|
lines.push(` 落盘快照 ${money(snap.cost)} v=${snap.v ?? "—"} sessions=${snap.sessions ?? 0} at=${when(snap.at)}`);
|
|
4197
4255
|
}
|
|
@@ -4208,13 +4266,19 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4208
4266
|
if (usage == null) {
|
|
4209
4267
|
issues.push({
|
|
4210
4268
|
level: "warn",
|
|
4211
|
-
text: "本会话 usage
|
|
4269
|
+
text: "本会话 usage 缺失(会话未载入内存或事件为空),金额显示为 ¥—",
|
|
4212
4270
|
});
|
|
4213
|
-
lines.push("**本会话**
|
|
4271
|
+
lines.push("**本会话** — 无 usage(会话未载入内存或事件为空,见下方会话读取)");
|
|
4214
4272
|
} else {
|
|
4215
4273
|
const tokens = (Number(usage.inputTokens ?? 0) + Number(usage.outputTokens ?? 0) +
|
|
4216
4274
|
Number(usage.cacheCreationTokens ?? 0) + Number(usage.cacheReadTokens ?? 0));
|
|
4217
|
-
|
|
4275
|
+
// ⚠️ sumEventsUsage 的返回值**没有顶层 cost**(金额在 byModel[i].cost 和 peak/offpeak 里),
|
|
4276
|
+
// 原来直接取 usage.cost 永远是 undefined → 报告印「**本会话** ¥—」,而界面明明有金额
|
|
4277
|
+
// (2026-11-11 用户截图:报告 ¥—、浮窗 ¥38.64)。口径统一走 usageCostOf + 网页工具费,
|
|
4278
|
+
// 与 formatUsage / 客户端 computeSplitCost 完全一致。
|
|
4279
|
+
const ownCost = usageCostOf(usage, catalogPricing(config, model), peakMultiplierOf(config)) +
|
|
4280
|
+
Number(usage.webToolCost ?? 0);
|
|
4281
|
+
lines.push(`**本会话** ${money(ownCost)} model=${model || "—"} tokens=${tokens}`);
|
|
4218
4282
|
const parts = [];
|
|
4219
4283
|
if (Number(usage.inputTokens ?? 0) !== 0) parts.push("输入 " + usage.inputTokens);
|
|
4220
4284
|
if (Number(usage.outputTokens ?? 0) !== 0) parts.push("输出 " + usage.outputTokens);
|
|
@@ -4236,7 +4300,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4236
4300
|
lines.push(` 子代理 ${money(subUsage.cost)} sessions=${subUsage.sessions ?? 0}`);
|
|
4237
4301
|
}
|
|
4238
4302
|
} catch {
|
|
4239
|
-
lines.push(" 子代理
|
|
4303
|
+
lines.push(" 子代理 — 枚举失败");
|
|
4240
4304
|
}
|
|
4241
4305
|
}
|
|
4242
4306
|
|
|
@@ -4249,7 +4313,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4249
4313
|
// 浮窗
|
|
4250
4314
|
lines.push("");
|
|
4251
4315
|
if (floatGeom == null) {
|
|
4252
|
-
lines.push("**浮窗**
|
|
4316
|
+
lines.push("**浮窗** — 无测量数据(浮窗未渲染或页面刚加载)");
|
|
4253
4317
|
} else {
|
|
4254
4318
|
const selfX = floatGeom.self != null && Number.isFinite(Number(floatGeom.self.x)) ? Number(floatGeom.self.x) : null;
|
|
4255
4319
|
const left = Number.isFinite(Number(floatGeom.left)) ? Number(floatGeom.left) : null;
|
|
@@ -4257,7 +4321,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4257
4321
|
if (!aligned && selfX !== null && left !== null) {
|
|
4258
4322
|
issues.push({
|
|
4259
4323
|
level: "error",
|
|
4260
|
-
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px
|
|
4324
|
+
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px(实际 x=${selfX},期望 x=${left})`,
|
|
4261
4325
|
});
|
|
4262
4326
|
}
|
|
4263
4327
|
lines.push(`**浮窗** ${aligned ? "✓ 对齐" : "✗ 偏移"} left=${left} self.x=${selfX} styleLeft=${floatGeom.styleLeft}` +
|
|
@@ -4269,7 +4333,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4269
4333
|
// 会话读取
|
|
4270
4334
|
const sessions = typeof ctx.get === "function" ? ctx.get("sessions") : null;
|
|
4271
4335
|
if (!(sessions != null && typeof sessions.get === "function")) {
|
|
4272
|
-
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false
|
|
4336
|
+
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false),本会话消耗回退磁盘读取,耗时增加" });
|
|
4273
4337
|
}
|
|
4274
4338
|
lines.push("");
|
|
4275
4339
|
lines.push(`**会话读取** sessionsUsable=${sessions != null && typeof sessions.get === "function"} ` +
|
|
@@ -4280,12 +4344,12 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4280
4344
|
const warn = issues.filter((x) => x.level === "warn");
|
|
4281
4345
|
const verdict = [];
|
|
4282
4346
|
if (bad.length === 0 && warn.length === 0) {
|
|
4283
|
-
verdict.push("**诊断结论
|
|
4347
|
+
verdict.push("**诊断结论 PASS** 4 项检查通过:余额 / 今日 / 本会话 / 浮窗");
|
|
4284
4348
|
} else {
|
|
4285
4349
|
const head = [];
|
|
4286
|
-
if (bad.length !== 0) head.push(
|
|
4287
|
-
if (warn.length !== 0) head.push(
|
|
4288
|
-
verdict.push(`**诊断结论 ${head.join("
|
|
4350
|
+
if (bad.length !== 0) head.push(`FAIL ${bad.length} 项`);
|
|
4351
|
+
if (warn.length !== 0) head.push(`WARN ${warn.length} 项`);
|
|
4352
|
+
verdict.push(`**诊断结论 ${head.join(" · ")}**`);
|
|
4289
4353
|
for (const item of bad) verdict.push(`- ✗ ${item.text}`);
|
|
4290
4354
|
for (const item of warn) verdict.push(`- ! ${item.text}`);
|
|
4291
4355
|
}
|
|
@@ -4778,7 +4842,10 @@ let statsInFlight = null;
|
|
|
4778
4842
|
let sessionYielded = false;
|
|
4779
4843
|
// 临时诊断:`?diag=1` 时随响应带回,用来查「为什么 usage 恒为 null」。
|
|
4780
4844
|
// 只带类型和布尔,不带 token 内容,开销为零。
|
|
4781
|
-
|
|
4845
|
+
// 2026-11-11:先记下「这次带没带 session」。设置页点「数据诊断」不带 session,
|
|
4846
|
+
// usage 必然为 null —— 客户端要能区分「根本没带会话」和「带了但读不出来」,
|
|
4847
|
+
// 前者不是故障,不该报。所以没带时也给一个最小对象(下面那个分支只在带了时进入)。
|
|
4848
|
+
let sessionDiag = wantDiag && sessionParam === "" ? { sessionRequested: false } : null;
|
|
4782
4849
|
// 诊断计时(只有 `?diag=1` 才算,正常路径零开销):
|
|
4783
4850
|
// 用来回答「会话消耗加载慢到底慢在哪一段」—— live 取数 / 持久化 / 子代理 / 团队。
|
|
4784
4851
|
const diagMs = wantDiag ? {} : null;
|
|
@@ -4809,6 +4876,7 @@ let statsInFlight = null;
|
|
|
4809
4876
|
sessionLoading = sessionsUsable && session === void 0;
|
|
4810
4877
|
if (wantDiag) {
|
|
4811
4878
|
sessionDiag = {
|
|
4879
|
+
sessionRequested: true,
|
|
4812
4880
|
sessionsType: typeof sessions,
|
|
4813
4881
|
sessionsIsNull: sessions === null,
|
|
4814
4882
|
hasGet: typeof sessions?.get === "function",
|