balance-dsh 2.2.5 → 2.2.6
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 +122 -64
- package/lib/index.js +72 -28
- 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
|
@@ -1520,6 +1520,10 @@ window.__ModuleLoader__.load({
|
|
|
1520
1520
|
.balance-settings__diag-btns{display:flex;align-items:center;gap:6px;flex:none}
|
|
1521
1521
|
.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
1522
|
.balance-settings__diag--error{color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
1523
|
+
.balance-settings__diag-bad{color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
1524
|
+
.balance-settings__diag-warn{color:var(--dsw-alias-state-warn-primary,#d97706)}
|
|
1525
|
+
.balance-settings__diag-ok{color:var(--dsw-alias-state-success-primary,#3fb950)}
|
|
1526
|
+
.balance-settings__diag-head{font-weight:600}
|
|
1523
1527
|
.balance-settings__diag-fix{margin:8px 0 0;font-size:12px;line-height:17px}
|
|
1524
1528
|
.balance-settings__diag-fix--ok{color:var(--dsw-alias-state-success-primary,#3fb950)}
|
|
1525
1529
|
.balance-settings__diag-fix--warn{color:var(--dsw-alias-state-warn-primary,#d97706)}
|
|
@@ -2623,7 +2627,7 @@ const CN_CALENDAR_SOURCES = [
|
|
|
2623
2627
|
["usageLoadingStyle", "2.0.9"], // 消耗行加载动效:样式1(光团开窗)/ 样式2(计算中),含行内实时预览
|
|
2624
2628
|
["todaySessionLimit", "2.1.0"], // 今日消耗扫描上限:多开对话 / 多跑子代理时把今日汇总算全
|
|
2625
2629
|
["showUsagePill", "2.1.6"], // 2.1.6:消耗行搬成对话界面右下角小浮窗(两行:本会话估算 / 金额)
|
|
2626
|
-
["diag", "2.2.
|
|
2630
|
+
["diag", "2.2.6"], // 2.2.6:设置页「数据诊断」—— 一键出结论 + 复制 + 查出问题给「修复」
|
|
2627
2631
|
]);
|
|
2628
2632
|
|
|
2629
2633
|
/** NEW_TAGS 的 key → 设置项中文名。横幅要写「本版新增:消耗行加载动效」,
|
|
@@ -3182,11 +3186,14 @@ const CN_CALENDAR_SOURCES = [
|
|
|
3182
3186
|
}
|
|
3183
3187
|
/** 这一拍的 0 是不是「不可信」(列不出会话 / 筛不出会话 / 有会话被让路跳过)。 */
|
|
3184
3188
|
function todayZeroIsSuspect(value) {
|
|
3185
|
-
|
|
3186
|
-
if (
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3189
|
+
const cost = Number(value?.cost ?? 0);
|
|
3190
|
+
if (cost !== 0) return false;
|
|
3191
|
+
// ⚠️ 2026-11-11(用户:「我今日本来就没消耗 为什么说数据异常」):
|
|
3192
|
+
// 当天还没花钱时,候选会话天然为空,suspiciousEmpty 必然为 true —— 那是**正常状态**。
|
|
3193
|
+
// 把它当「可疑」会让插件白重试一整天。只有「确实漏读」或「列表根本没列出来」才值得重试:
|
|
3194
|
+
// · skipped > 0 —— 有会话被跳过,总额偏低
|
|
3195
|
+
// · emptyListing=true —— 连列表都没列出来,很可能是冷启动索引没好
|
|
3196
|
+
return Number(value?.skipped ?? 0) > 0 || value?.emptyListing === true;
|
|
3190
3197
|
}
|
|
3191
3198
|
const todayListeners = new Set();
|
|
3192
3199
|
function notifyToday() {
|
|
@@ -7718,10 +7725,10 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7718
7725
|
if (d.balance == null) {
|
|
7719
7726
|
issues.push({
|
|
7720
7727
|
level: "error",
|
|
7721
|
-
text: d.balanceError ?
|
|
7728
|
+
text: d.balanceError ? `余额不可用:${d.balanceError}` : "余额不可用:未登录或网络失败",
|
|
7722
7729
|
});
|
|
7723
7730
|
} else if (d.balanceError) {
|
|
7724
|
-
issues.push({ level: "error", text:
|
|
7731
|
+
issues.push({ level: "error", text: `余额读取失败:${d.balanceError}` });
|
|
7725
7732
|
}
|
|
7726
7733
|
|
|
7727
7734
|
// 今日
|
|
@@ -7731,49 +7738,54 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7731
7738
|
if (today == null || typeof today !== "object") {
|
|
7732
7739
|
issues.push({
|
|
7733
7740
|
level: "warn",
|
|
7734
|
-
text:
|
|
7741
|
+
text: `今日未返回(todayPartial=${d.todayPartial === true}),客户端处于等待态`,
|
|
7735
7742
|
});
|
|
7736
7743
|
} else {
|
|
7737
7744
|
const cost = Number(today.cost ?? 0);
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7745
|
+
// ⚠️ 2026-11-11 用户(截图:今日 ¥0.0000 / sessions=0 / suspiciousEmpty=true):
|
|
7746
|
+
// 「我今日本来就没消耗 为什么说数据异常」。
|
|
7747
|
+
// 当天还没产生消耗时,今天的候选会话天然为空 → suspiciousEmpty 必然为 true,
|
|
7748
|
+
// **那是正常状态,不是假 0**。服务端也是这个口径:suspiciousEmpty 只负责「不落盘」,
|
|
7749
|
+
// 不改变发给客户端的值。所以只有「确实漏算了」才算异常:
|
|
7750
|
+
// · skipped > 0 —— 有会话被让路跳过没读,总额必然偏低 → error
|
|
7751
|
+
// · emptyListing=true —— 连会话列表都没列出来,可能还没索引好 → warn(也可能真没会话)
|
|
7752
|
+
// · cost=0 && 还在算 —— 提示一下就行
|
|
7753
|
+
// 其余情况(今天就是没花钱)**一个字都不报**。
|
|
7754
|
+
let skipped = 0;
|
|
7755
|
+
for (const s of [today, snap]) {
|
|
7756
|
+
if (s == null || typeof s !== "object") continue;
|
|
7757
|
+
skipped = Math.max(skipped, Number(s.skipped ?? 0) || 0);
|
|
7751
7758
|
}
|
|
7759
|
+
const emptyListing = today.emptyListing === true || snap?.emptyListing === true;
|
|
7752
7760
|
const pending = td != null && (td.cacheProvisional === true || td.recomputing === true);
|
|
7753
|
-
if (cost === 0 &&
|
|
7761
|
+
if (cost === 0 && skipped > 0) {
|
|
7754
7762
|
issues.push({
|
|
7755
7763
|
level: "error",
|
|
7756
|
-
text: `今日 ¥0.0000
|
|
7764
|
+
text: `今日 ¥0.0000 偏低:${skipped} 个会话读取被跳过,已排入退避重试`,
|
|
7765
|
+
});
|
|
7766
|
+
} else if (cost === 0 && emptyListing) {
|
|
7767
|
+
issues.push({
|
|
7768
|
+
level: "warn",
|
|
7769
|
+
text: "今日会话列表为空(DSH 索引未就绪);存在消耗时将于重算后更新",
|
|
7757
7770
|
});
|
|
7758
7771
|
} else if (cost === 0 && pending) {
|
|
7759
|
-
issues.push({ level: "warn", text: "
|
|
7760
|
-
}
|
|
7761
|
-
if (d.todayPartial === true) {
|
|
7762
|
-
issues.push({ level: "warn", text: "今日是部分结果(刚冷启动或刚跨天),客户端会自动补拉" });
|
|
7772
|
+
issues.push({ level: "warn", text: "今日重算中,当前 0 为占位值" });
|
|
7763
7773
|
}
|
|
7764
7774
|
}
|
|
7765
7775
|
|
|
7766
7776
|
// 本会话 / 会话服务
|
|
7767
7777
|
if (d.diag != null && typeof d.diag === "object") {
|
|
7768
7778
|
if (d.diag.sessionsUsable === false) {
|
|
7769
|
-
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false
|
|
7779
|
+
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false),本会话消耗回退磁盘读取,耗时增加" });
|
|
7770
7780
|
}
|
|
7771
7781
|
}
|
|
7772
|
-
|
|
7773
|
-
|
|
7782
|
+
// 设置页点诊断时请求不带 session,usage 必然是 null —— 那不是故障,
|
|
7783
|
+
// 报告里「本会话」段已经写明「未参与统计」,这里再报一条只会让人以为坏了。
|
|
7784
|
+
if (d.usage == null && d.loading !== true && d.diag?.sessionRequested === true) {
|
|
7785
|
+
issues.push({ level: "warn", text: "本会话 usage 缺失(会话未载入内存或事件为空),金额显示为 ¥—" });
|
|
7774
7786
|
}
|
|
7775
7787
|
if (d.loading === true) {
|
|
7776
|
-
issues.push({ level: "warn", text: "DSH
|
|
7788
|
+
issues.push({ level: "warn", text: "DSH 正在装载本会话,插件让路(正常状态,数秒后恢复)" });
|
|
7777
7789
|
}
|
|
7778
7790
|
|
|
7779
7791
|
// 浮窗定位
|
|
@@ -7784,37 +7796,51 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7784
7796
|
if (selfX !== null && left !== null && Math.abs(selfX - left) > 2) {
|
|
7785
7797
|
issues.push({
|
|
7786
7798
|
level: "error",
|
|
7787
|
-
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px
|
|
7799
|
+
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px(实际 x=${selfX},期望 x=${left})`,
|
|
7788
7800
|
});
|
|
7789
7801
|
}
|
|
7790
7802
|
}
|
|
7791
7803
|
|
|
7792
7804
|
// 设置自检:这几项填成 0 会让数字永远不对,但界面上完全看不出来
|
|
7793
7805
|
if (Number(s.todaySessionLimit ?? 1) <= 0) {
|
|
7794
|
-
issues.push({ level: "error", text: "
|
|
7806
|
+
issues.push({ level: "error", text: "设置项「今日扫描上限」= 0,今日金额将恒为 0" });
|
|
7795
7807
|
}
|
|
7796
7808
|
if (Number(s.statsSessionLimit ?? 1) <= 0) {
|
|
7797
|
-
issues.push({ level: "error", text: "
|
|
7809
|
+
issues.push({ level: "error", text: "设置项「统计扫描上限」= 0,统计面板将恒为 0" });
|
|
7798
7810
|
}
|
|
7799
7811
|
if (Number(s.peakMultiplier ?? 1) <= 0) {
|
|
7800
|
-
issues.push({ level: "error", text: "
|
|
7812
|
+
issues.push({ level: "error", text: "设置项「高峰倍率」= 0,高峰时段金额将被计为 0" });
|
|
7801
7813
|
}
|
|
7802
7814
|
return issues;
|
|
7803
7815
|
}
|
|
7804
7816
|
|
|
7817
|
+
/** 单行着色(2026-11-11 用户:「这个诊断日志太乱了 怎么全红 就给错误信息标红就行了」)。
|
|
7818
|
+
* 整块变红会让人以为满屏都是故障,实际上只有结论和那几条问题需要红。
|
|
7819
|
+
* 返回的 class 只挂在那几行上,其余保持正文色。 */
|
|
7820
|
+
function diagLineClass(line) {
|
|
7821
|
+
const t = typeof line === "string" ? line : "";
|
|
7822
|
+
if (t.startsWith("诊断结论")) {
|
|
7823
|
+
if (t.includes("FAIL")) return "balance-settings__diag-bad balance-settings__diag-head";
|
|
7824
|
+
if (t.includes("WARN")) return "balance-settings__diag-warn balance-settings__diag-head";
|
|
7825
|
+
return "balance-settings__diag-ok balance-settings__diag-head";
|
|
7826
|
+
}
|
|
7827
|
+
if (t.startsWith(" ✗")) return "balance-settings__diag-bad";
|
|
7828
|
+
if (t.startsWith(" !")) return "balance-settings__diag-warn";
|
|
7829
|
+
return "";
|
|
7830
|
+
}
|
|
7805
7831
|
/** 结论段:报告最上面那几行。 */
|
|
7806
7832
|
function formatDiagVerdict(issues) {
|
|
7807
7833
|
const bad = issues.filter((x) => x.level === "error");
|
|
7808
7834
|
const warn = issues.filter((x) => x.level === "warn");
|
|
7809
7835
|
const out = [];
|
|
7810
7836
|
if (bad.length === 0 && warn.length === 0) {
|
|
7811
|
-
out.push("诊断结论
|
|
7837
|
+
out.push("诊断结论 PASS 5 项检查通过:余额 / 今日 / 本会话 / 浮窗 / 设置");
|
|
7812
7838
|
return out;
|
|
7813
7839
|
}
|
|
7814
7840
|
const head = [];
|
|
7815
|
-
if (bad.length !== 0) head.push(
|
|
7816
|
-
if (warn.length !== 0) head.push(
|
|
7817
|
-
out.push(`诊断结论 ${head.join("
|
|
7841
|
+
if (bad.length !== 0) head.push(`FAIL ${bad.length} 项`);
|
|
7842
|
+
if (warn.length !== 0) head.push(`WARN ${warn.length} 项`);
|
|
7843
|
+
out.push(`诊断结论 ${head.join(" · ")}`);
|
|
7818
7844
|
for (const item of bad) out.push(` ✗ ${item.text}`);
|
|
7819
7845
|
for (const item of warn) out.push(` ! ${item.text}`);
|
|
7820
7846
|
return out;
|
|
@@ -7829,9 +7855,18 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7829
7855
|
const d = data != null && typeof data === "object" ? data : {};
|
|
7830
7856
|
const s = settings != null && typeof settings === "object" ? settings : {};
|
|
7831
7857
|
const lines = [];
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7858
|
+
// ⚠️ 2026-11-11:桌面版页面的 hostname 是 `app`、port 为空,原来拼出来是「app:?」,
|
|
7859
|
+
// 看着像故障。直接取 location.host(有端口才带端口),空的就写个破折号。
|
|
7860
|
+
const where = (() => {
|
|
7861
|
+
if (typeof location !== "object" || location === null) return "—";
|
|
7862
|
+
// 浏览器一定有 host(hostname + 非空才带 :port);测试夹具只给 hostname/port,
|
|
7863
|
+
// 所以这里自己拼一遍,别指望 location.host 一定存在。
|
|
7864
|
+
if (typeof location.host === "string" && location.host !== "") return location.host;
|
|
7865
|
+
const host = String(location.hostname || "");
|
|
7866
|
+
const port = String(location.port || "");
|
|
7867
|
+
if (host === "") return "—";
|
|
7868
|
+
return port === "" ? host : host + ":" + port;
|
|
7869
|
+
})();
|
|
7835
7870
|
lines.push(`balance-dsh ${version || "—"} · ${where} · ${formatDiagTime(Date.now())}`);
|
|
7836
7871
|
const issues = collectDiagIssues(d, s);
|
|
7837
7872
|
lines.push("");
|
|
@@ -7858,32 +7893,45 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7858
7893
|
const today = d.today;
|
|
7859
7894
|
const td = d.todayDiag != null && typeof d.todayDiag === "object" ? d.todayDiag : null;
|
|
7860
7895
|
const snap = td != null && td.snapshot != null && typeof td.snapshot === "object" ? td.snapshot : null;
|
|
7896
|
+
// ⚠️ 2026-11-11(用户:「我今日本来就没消耗 为什么说数据异常」):
|
|
7897
|
+
// `suspiciousEmpty` **不算**「不可信」。它的含义是「今天的候选会话为空」——
|
|
7898
|
+
// 当天还没产生消耗时它必然为 true,那是正常状态,不是假 0。
|
|
7899
|
+
// 服务端那边保留它只为了「这种 0 先别落盘」(保守,防止假 0 固化),
|
|
7900
|
+
// 但给用户看的时候只有「确实漏读」或「列表根本没列出来」才叫不可信。
|
|
7861
7901
|
const anySuspect =
|
|
7862
|
-
today?.suspiciousEmpty === true ||
|
|
7863
|
-
today?.emptyListing === true ||
|
|
7864
7902
|
Number(today?.skipped ?? 0) > 0 ||
|
|
7865
|
-
|
|
7866
|
-
snap?.
|
|
7867
|
-
|
|
7903
|
+
today?.emptyListing === true ||
|
|
7904
|
+
Number(snap?.skipped ?? 0) > 0 ||
|
|
7905
|
+
snap?.emptyListing === true;
|
|
7868
7906
|
lines.push("");
|
|
7869
7907
|
lines.push("── 今日 ──");
|
|
7870
7908
|
if (today == null || typeof today !== "object") {
|
|
7871
|
-
lines.push(
|
|
7909
|
+
lines.push(`— 未返回(todayPartial=${d.todayPartial === true})`);
|
|
7872
7910
|
} else {
|
|
7873
7911
|
lines.push(
|
|
7874
7912
|
`金额 ${formatDiagMoney(today.cost)} date=${today.date ?? "—"} ` +
|
|
7875
7913
|
`sessions=${today.sessions ?? 0} tokens=${today.totalTokens ?? 0}`,
|
|
7876
7914
|
);
|
|
7915
|
+
// 2026-11-11(用户:「今日消耗为什么还是异常为0 明明都消耗了token了」):
|
|
7916
|
+
// 冷启动那一拍服务端可能先发一个「还在算」的占位(sessions=0 / tokens=0 / partial=true),
|
|
7917
|
+
// 真值要等后台算完再补。光看上面那行会以为「今天真的没花钱」,所以直接把状态写出来。
|
|
7918
|
+
if (d.todayPartial === true) {
|
|
7919
|
+
lines.push(
|
|
7920
|
+
Number(today.cost ?? 0) === 0
|
|
7921
|
+
? "状态 partial=true 尚无结果,当前 0 为占位值,重算完成后替换"
|
|
7922
|
+
: "状态 partial=true 后台重算中,当前为增量结果",
|
|
7923
|
+
);
|
|
7924
|
+
}
|
|
7877
7925
|
// 三态:光看 today 是分不出「真 0」和「还在算」的
|
|
7878
7926
|
const zeroCost = Number(today.cost ?? 0) === 0;
|
|
7879
7927
|
const pending = td != null && (td.cacheProvisional === true || td.recomputing === true);
|
|
7880
7928
|
const verdict = !zeroCost
|
|
7881
|
-
? "
|
|
7929
|
+
? "是"
|
|
7882
7930
|
: anySuspect
|
|
7883
|
-
? "
|
|
7931
|
+
? "否(可疑零值,已排入退避重试)"
|
|
7884
7932
|
: pending
|
|
7885
|
-
? "
|
|
7886
|
-
: "
|
|
7933
|
+
? "待定(provisional 或重算中)"
|
|
7934
|
+
: "是";
|
|
7887
7935
|
lines.push(
|
|
7888
7936
|
`可信 ${verdict} suspiciousEmpty=${today.suspiciousEmpty === true} ` +
|
|
7889
7937
|
`emptyListing=${today.emptyListing === true} skipped=${today.skipped ?? 0} ` +
|
|
@@ -7893,11 +7941,11 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7893
7941
|
if (td != null) {
|
|
7894
7942
|
lines.push(
|
|
7895
7943
|
`缓存 cost=${td.cacheCost == null ? "—" : Number(td.cacheCost).toFixed(4)} ` +
|
|
7896
|
-
|
|
7897
|
-
`provisional=${td.cacheProvisional === true}
|
|
7944
|
+
`TTL=${Math.round(Number(td.cacheExpiresInMs ?? 0) / 1000)}s ` +
|
|
7945
|
+
`provisional=${td.cacheProvisional === true} recomputing=${td.recomputing === true}`,
|
|
7898
7946
|
);
|
|
7899
7947
|
if (snap == null) {
|
|
7900
|
-
lines.push("快照
|
|
7948
|
+
lines.push("快照 — 不存在(可疑结果不落盘,或今日尚未计算)");
|
|
7901
7949
|
} else {
|
|
7902
7950
|
lines.push(
|
|
7903
7951
|
`快照 ${formatDiagMoney(snap.cost)} date=${snap.date ?? "—"} v=${snap.v ?? "—"} ` +
|
|
@@ -7924,7 +7972,7 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7924
7972
|
if (usage.webToolCost != null) extra.push(`网页工具 ${formatDiagMoney(usage.webToolCost)}`);
|
|
7925
7973
|
if (extra.length) lines.push(`拆分 ${extra.join(" ")}`);
|
|
7926
7974
|
} else {
|
|
7927
|
-
lines.push("
|
|
7975
|
+
lines.push("— 请求未带 session,不参与本次统计(本会话明细用 /balance-dsh-diag)");
|
|
7928
7976
|
}
|
|
7929
7977
|
const team = d.team;
|
|
7930
7978
|
if (team != null && typeof team === "object" && Number(team.count ?? 0) > 0) {
|
|
@@ -7953,7 +8001,7 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7953
8001
|
lines.push("── 浮窗 ──");
|
|
7954
8002
|
const g = d.floatGeom;
|
|
7955
8003
|
if (g == null || typeof g !== "object") {
|
|
7956
|
-
lines.push("
|
|
8004
|
+
lines.push("— 无测量数据(浮窗未渲染或页面刚加载)");
|
|
7957
8005
|
} else {
|
|
7958
8006
|
const selfX = g.self != null && Number.isFinite(Number(g.self.x)) ? Number(g.self.x) : null;
|
|
7959
8007
|
const left = Number.isFinite(Number(g.left)) ? Number(g.left) : null;
|
|
@@ -7979,9 +8027,9 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7979
8027
|
`sessionUndefined=${diag.sessionUndefined === true} hasGet=${diag.hasGet === true}`,
|
|
7980
8028
|
);
|
|
7981
8029
|
if (diag.persistedError) lines.push(`persistedError=${diag.persistedError}`);
|
|
7982
|
-
if (d.loading === true) lines.push("loading=true
|
|
8030
|
+
if (d.loading === true) lines.push("loading=true 会话装载中,插件让路");
|
|
7983
8031
|
} else {
|
|
7984
|
-
lines.push("
|
|
8032
|
+
lines.push("— 请求未带 session,服务端未计算");
|
|
7985
8033
|
}
|
|
7986
8034
|
|
|
7987
8035
|
// ── 原始响应:没被上面提到的东西全在这里,出问题时能对到具体字段 ──
|
|
@@ -8988,10 +9036,20 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
8988
9036
|
: null,
|
|
8989
9037
|
diagReport.text
|
|
8990
9038
|
? jsx.jsx("pre", {
|
|
8991
|
-
|
|
8992
|
-
|
|
8993
|
-
|
|
8994
|
-
children: diagReport.
|
|
9039
|
+
// 只给「结论 + ✗ / ! 那几行」上色,其余走正文色。
|
|
9040
|
+
// 整块变红(旧的 --error)会让人以为满屏都是故障。
|
|
9041
|
+
className: "balance-settings__diag",
|
|
9042
|
+
children: diagReport.kind === "error"
|
|
9043
|
+
? diagReport.text
|
|
9044
|
+
: diagReport.text.split("\n").map((line, i, all) => {
|
|
9045
|
+
const cls = diagLineClass(line);
|
|
9046
|
+
return [
|
|
9047
|
+
cls === ""
|
|
9048
|
+
? line
|
|
9049
|
+
: jsx.jsx("span", { className: cls, children: line }),
|
|
9050
|
+
i === all.length - 1 ? "" : "\n",
|
|
9051
|
+
];
|
|
9052
|
+
}),
|
|
8995
9053
|
})
|
|
8996
9054
|
: null,
|
|
8997
9055
|
]),
|
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.6";
|
|
1081
1081
|
|
|
1082
1082
|
/** 斜杠命令名(2026-10-31 定案:用带作者后缀的全名,避免和别的余额插件撞车,也不设备用名)。
|
|
1083
1083
|
* ⚠️ DSH 的 COMMAND_NAME = /^[a-z][a-z0-9_-]*$/u —— **只允许小写**。
|
|
@@ -2275,8 +2275,16 @@ function withSettings(config, settings) {
|
|
|
2275
2275
|
peakMultiplier: s.peakMultiplier,
|
|
2276
2276
|
priceByModel,
|
|
2277
2277
|
statsSessionLimit: s.statsSessionLimit,
|
|
2278
|
-
|
|
2278
|
+
todaySessionLimit: s.todaySessionLimit,
|
|
2279
2279
|
statsCacheMs: s.statsCacheSec * 1000,
|
|
2280
|
+
// ⚠️ 这四个原来只存在于 settingsState 里,没进 effectiveConfig —— 于是
|
|
2281
|
+
// `effectiveConfig.refreshIntervalSec` 之类全是 undefined,诊断报告的「设置」段
|
|
2282
|
+
// 印成「轮询 undefined 统计缓存 undefined 低余额阈值 undefined 高峰 undefined × 2」
|
|
2283
|
+
// (2026-11-11 用户截图)。业务函数拿到的必须是完整口径,一律在这里补齐。
|
|
2284
|
+
refreshIntervalSec: s.refreshIntervalSec,
|
|
2285
|
+
lowBalanceThreshold: s.lowBalanceThreshold,
|
|
2286
|
+
statsCacheSec: s.statsCacheSec,
|
|
2287
|
+
peakWindowsText: s.peakWindowsText,
|
|
2280
2288
|
};
|
|
2281
2289
|
}
|
|
2282
2290
|
|
|
@@ -2507,6 +2515,14 @@ async function readTodaySnapshot(file) {
|
|
|
2507
2515
|
sessions: Number.isFinite(Number(parsed.sessions)) ? Number(parsed.sessions) : 0,
|
|
2508
2516
|
at: Number.isFinite(Number(parsed.at)) ? Number(parsed.at) : 0,
|
|
2509
2517
|
bySession,
|
|
2518
|
+
// ⚠️ 这四个标记必须一起还原(2026-11-11 用户:「怎么今日不一样」)。
|
|
2519
|
+
// 原来只还原前六项,于是读出来的快照永远带着 suspiciousEmpty=false / emptyListing=false /
|
|
2520
|
+
// skipped=0 —— 诊断里印「v=— skipped=0」看着一切正常,实际可能被让路跳过过;
|
|
2521
|
+
// mergeTodayMax 合并出来的对象也不带这些标记,客户端那三处判定全部失效。
|
|
2522
|
+
v: TODAY_SNAPSHOT_VERSION,
|
|
2523
|
+
suspiciousEmpty: parsed.suspiciousEmpty === true,
|
|
2524
|
+
emptyListing: parsed.emptyListing === true,
|
|
2525
|
+
skipped: Number.isFinite(Number(parsed.skipped)) && Number(parsed.skipped) >= 0 ? Number(parsed.skipped) : 0,
|
|
2510
2526
|
};
|
|
2511
2527
|
} catch {
|
|
2512
2528
|
return null;
|
|
@@ -4154,8 +4170,22 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4154
4170
|
// 今日
|
|
4155
4171
|
let today = null;
|
|
4156
4172
|
let todayPartial = false;
|
|
4173
|
+
// ⚠️ 必须带 reuse 走「和界面同一条路」(2026-11-11 用户:「怎么今日不一样」——
|
|
4174
|
+
// 界面 ¥0.69 / 报告 ¥0.6145)。`?session=` 每次都把当前会话的事件当 reuse 传进去,
|
|
4175
|
+
// 能看见「已发生但还没落盘」的那一截;报告原来走 `?today=1` 那条(只认持久化文件),
|
|
4176
|
+
// 天然比界面少一截,而且不重算、直接命中旧内存缓存 → 两个数必然对不上。
|
|
4177
|
+
// 报告是用户主动触发的低频操作,多读一次磁盘换来口径一致,值。
|
|
4178
|
+
const reportReuse = (() => {
|
|
4179
|
+
if (sessionId === "" || session == null) return null;
|
|
4180
|
+
try {
|
|
4181
|
+
const own = ownEventsOf(session?.header ?? null, sessionEvents(session));
|
|
4182
|
+
return Array.isArray(own) && own.length > 0 ? { sessionId, events: own, meta: session?.header ?? null } : null;
|
|
4183
|
+
} catch {
|
|
4184
|
+
return null;
|
|
4185
|
+
}
|
|
4186
|
+
})();
|
|
4157
4187
|
try {
|
|
4158
|
-
const got = await resolveTodayCost(ctx, config, todayState);
|
|
4188
|
+
const got = await resolveTodayCost(ctx, config, todayState, reportReuse);
|
|
4159
4189
|
today = got?.value ?? null;
|
|
4160
4190
|
todayPartial = got?.partial === true;
|
|
4161
4191
|
} catch (error) {
|
|
@@ -4163,26 +4193,30 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4163
4193
|
}
|
|
4164
4194
|
if (today != null) {
|
|
4165
4195
|
lines.push(`**今日** ${money(today.cost)} date=${today.date ?? "—"} sessions=${today.sessions ?? 0} tokens=${today.totalTokens ?? 0}`);
|
|
4196
|
+
// ⚠️ 2026-11-11(用户:「我今日本来就没消耗 为什么说数据异常」):
|
|
4197
|
+
// 当天还没产生消耗时,候选会话天然为空 → suspiciousEmpty 必然为 true,那是**正常状态**。
|
|
4198
|
+
// 只有「确实漏读」或「列表根本没列出来」才值得说:
|
|
4166
4199
|
const unreliable = todayValueUnreliable(today);
|
|
4167
4200
|
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} 个会话被让路跳过`);
|
|
4201
|
+
const skippedCount = Number(today.skipped ?? 0) || 0;
|
|
4202
|
+
if (cost === 0 && skippedCount > 0) {
|
|
4173
4203
|
issues.push({
|
|
4174
4204
|
level: "error",
|
|
4175
|
-
text: `今日 ¥0.0000
|
|
4205
|
+
text: `今日 ¥0.0000 偏低:${skippedCount} 个会话读取被跳过,已排入退避重试`,
|
|
4206
|
+
});
|
|
4207
|
+
} else if (cost === 0 && today.emptyListing === true) {
|
|
4208
|
+
issues.push({
|
|
4209
|
+
level: "warn",
|
|
4210
|
+
text: "今日会话列表为空(DSH 索引未就绪);存在消耗时将于重算后更新",
|
|
4176
4211
|
});
|
|
4177
4212
|
}
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
}
|
|
4181
|
-
lines.push(` 可信=${unreliable ? "不可信(假 0 / 少算,客户端会自动退避重试)" : "可信"} ` +
|
|
4213
|
+
void unreliable;
|
|
4214
|
+
lines.push(` 可信=${unreliable ? "否(可疑零值,客户端自动退避重试)" : "是"} ` +
|
|
4182
4215
|
`suspiciousEmpty=${today.suspiciousEmpty === true} emptyListing=${today.emptyListing === true} ` +
|
|
4183
4216
|
`skipped=${today.skipped ?? 0} partial=${todayPartial}`);
|
|
4184
|
-
lines.push(` 缓存
|
|
4185
|
-
`
|
|
4217
|
+
lines.push(` 缓存 TTL=${Math.max(0, Math.round((todayState.cache.expiresAt - Date.now()) / 1000))}s ` +
|
|
4218
|
+
`cost=${todayState.cache.value?.cost == null ? "—" : Number(todayState.cache.value.cost).toFixed(4)} ` +
|
|
4219
|
+
`provisional=${todayState.cache.value?.provisional === true} recomputing=${todayState.recompute != null}`);
|
|
4186
4220
|
}
|
|
4187
4221
|
let snap = null;
|
|
4188
4222
|
try {
|
|
@@ -4191,7 +4225,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4191
4225
|
snap = null;
|
|
4192
4226
|
}
|
|
4193
4227
|
if (snap == null) {
|
|
4194
|
-
lines.push(" 落盘快照
|
|
4228
|
+
lines.push(" 落盘快照 — 不存在(可疑结果不落盘,或今日尚未计算)");
|
|
4195
4229
|
} else {
|
|
4196
4230
|
lines.push(` 落盘快照 ${money(snap.cost)} v=${snap.v ?? "—"} sessions=${snap.sessions ?? 0} at=${when(snap.at)}`);
|
|
4197
4231
|
}
|
|
@@ -4208,13 +4242,19 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4208
4242
|
if (usage == null) {
|
|
4209
4243
|
issues.push({
|
|
4210
4244
|
level: "warn",
|
|
4211
|
-
text: "本会话 usage
|
|
4245
|
+
text: "本会话 usage 缺失(会话未载入内存或事件为空),金额显示为 ¥—",
|
|
4212
4246
|
});
|
|
4213
|
-
lines.push("**本会话**
|
|
4247
|
+
lines.push("**本会话** — 无 usage(会话未载入内存或事件为空,见下方会话读取)");
|
|
4214
4248
|
} else {
|
|
4215
4249
|
const tokens = (Number(usage.inputTokens ?? 0) + Number(usage.outputTokens ?? 0) +
|
|
4216
4250
|
Number(usage.cacheCreationTokens ?? 0) + Number(usage.cacheReadTokens ?? 0));
|
|
4217
|
-
|
|
4251
|
+
// ⚠️ sumEventsUsage 的返回值**没有顶层 cost**(金额在 byModel[i].cost 和 peak/offpeak 里),
|
|
4252
|
+
// 原来直接取 usage.cost 永远是 undefined → 报告印「**本会话** ¥—」,而界面明明有金额
|
|
4253
|
+
// (2026-11-11 用户截图:报告 ¥—、浮窗 ¥38.64)。口径统一走 usageCostOf + 网页工具费,
|
|
4254
|
+
// 与 formatUsage / 客户端 computeSplitCost 完全一致。
|
|
4255
|
+
const ownCost = usageCostOf(usage, catalogPricing(config, model), peakMultiplierOf(config)) +
|
|
4256
|
+
Number(usage.webToolCost ?? 0);
|
|
4257
|
+
lines.push(`**本会话** ${money(ownCost)} model=${model || "—"} tokens=${tokens}`);
|
|
4218
4258
|
const parts = [];
|
|
4219
4259
|
if (Number(usage.inputTokens ?? 0) !== 0) parts.push("输入 " + usage.inputTokens);
|
|
4220
4260
|
if (Number(usage.outputTokens ?? 0) !== 0) parts.push("输出 " + usage.outputTokens);
|
|
@@ -4236,7 +4276,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4236
4276
|
lines.push(` 子代理 ${money(subUsage.cost)} sessions=${subUsage.sessions ?? 0}`);
|
|
4237
4277
|
}
|
|
4238
4278
|
} catch {
|
|
4239
|
-
lines.push(" 子代理
|
|
4279
|
+
lines.push(" 子代理 — 枚举失败");
|
|
4240
4280
|
}
|
|
4241
4281
|
}
|
|
4242
4282
|
|
|
@@ -4249,7 +4289,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4249
4289
|
// 浮窗
|
|
4250
4290
|
lines.push("");
|
|
4251
4291
|
if (floatGeom == null) {
|
|
4252
|
-
lines.push("**浮窗**
|
|
4292
|
+
lines.push("**浮窗** — 无测量数据(浮窗未渲染或页面刚加载)");
|
|
4253
4293
|
} else {
|
|
4254
4294
|
const selfX = floatGeom.self != null && Number.isFinite(Number(floatGeom.self.x)) ? Number(floatGeom.self.x) : null;
|
|
4255
4295
|
const left = Number.isFinite(Number(floatGeom.left)) ? Number(floatGeom.left) : null;
|
|
@@ -4257,7 +4297,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4257
4297
|
if (!aligned && selfX !== null && left !== null) {
|
|
4258
4298
|
issues.push({
|
|
4259
4299
|
level: "error",
|
|
4260
|
-
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px
|
|
4300
|
+
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px(实际 x=${selfX},期望 x=${left})`,
|
|
4261
4301
|
});
|
|
4262
4302
|
}
|
|
4263
4303
|
lines.push(`**浮窗** ${aligned ? "✓ 对齐" : "✗ 偏移"} left=${left} self.x=${selfX} styleLeft=${floatGeom.styleLeft}` +
|
|
@@ -4269,7 +4309,7 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4269
4309
|
// 会话读取
|
|
4270
4310
|
const sessions = typeof ctx.get === "function" ? ctx.get("sessions") : null;
|
|
4271
4311
|
if (!(sessions != null && typeof sessions.get === "function")) {
|
|
4272
|
-
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false
|
|
4312
|
+
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false),本会话消耗回退磁盘读取,耗时增加" });
|
|
4273
4313
|
}
|
|
4274
4314
|
lines.push("");
|
|
4275
4315
|
lines.push(`**会话读取** sessionsUsable=${sessions != null && typeof sessions.get === "function"} ` +
|
|
@@ -4280,12 +4320,12 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4280
4320
|
const warn = issues.filter((x) => x.level === "warn");
|
|
4281
4321
|
const verdict = [];
|
|
4282
4322
|
if (bad.length === 0 && warn.length === 0) {
|
|
4283
|
-
verdict.push("**诊断结论
|
|
4323
|
+
verdict.push("**诊断结论 PASS** 4 项检查通过:余额 / 今日 / 本会话 / 浮窗");
|
|
4284
4324
|
} else {
|
|
4285
4325
|
const head = [];
|
|
4286
|
-
if (bad.length !== 0) head.push(
|
|
4287
|
-
if (warn.length !== 0) head.push(
|
|
4288
|
-
verdict.push(`**诊断结论 ${head.join("
|
|
4326
|
+
if (bad.length !== 0) head.push(`FAIL ${bad.length} 项`);
|
|
4327
|
+
if (warn.length !== 0) head.push(`WARN ${warn.length} 项`);
|
|
4328
|
+
verdict.push(`**诊断结论 ${head.join(" · ")}**`);
|
|
4289
4329
|
for (const item of bad) verdict.push(`- ✗ ${item.text}`);
|
|
4290
4330
|
for (const item of warn) verdict.push(`- ! ${item.text}`);
|
|
4291
4331
|
}
|
|
@@ -4778,7 +4818,10 @@ let statsInFlight = null;
|
|
|
4778
4818
|
let sessionYielded = false;
|
|
4779
4819
|
// 临时诊断:`?diag=1` 时随响应带回,用来查「为什么 usage 恒为 null」。
|
|
4780
4820
|
// 只带类型和布尔,不带 token 内容,开销为零。
|
|
4781
|
-
|
|
4821
|
+
// 2026-11-11:先记下「这次带没带 session」。设置页点「数据诊断」不带 session,
|
|
4822
|
+
// usage 必然为 null —— 客户端要能区分「根本没带会话」和「带了但读不出来」,
|
|
4823
|
+
// 前者不是故障,不该报。所以没带时也给一个最小对象(下面那个分支只在带了时进入)。
|
|
4824
|
+
let sessionDiag = wantDiag && sessionParam === "" ? { sessionRequested: false } : null;
|
|
4782
4825
|
// 诊断计时(只有 `?diag=1` 才算,正常路径零开销):
|
|
4783
4826
|
// 用来回答「会话消耗加载慢到底慢在哪一段」—— live 取数 / 持久化 / 子代理 / 团队。
|
|
4784
4827
|
const diagMs = wantDiag ? {} : null;
|
|
@@ -4809,6 +4852,7 @@ let statsInFlight = null;
|
|
|
4809
4852
|
sessionLoading = sessionsUsable && session === void 0;
|
|
4810
4853
|
if (wantDiag) {
|
|
4811
4854
|
sessionDiag = {
|
|
4855
|
+
sessionRequested: true,
|
|
4812
4856
|
sessionsType: typeof sessions,
|
|
4813
4857
|
sessionsIsNull: sessions === null,
|
|
4814
4858
|
hasGet: typeof sessions?.get === "function",
|