balance-dsh 2.2.4 → 2.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.
- package/README.md +23 -1
- package/lib/client.js +229 -2
- package/lib/index.js +74 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -114,7 +114,29 @@ token 数用官方文档站「图片 Token 计算器」的同一套算法估算
|
|
|
114
114
|
- **会话里**:输入 `/balance-dsh-diag` —— 带着当前会话,所以本会话明细、子代理、团队都算得全;
|
|
115
115
|
- **设置页**:插件 → `balance-dsh` → 最下面「数据诊断」→ 点「数据诊断」。这里拿不到会话 id,那几项会标注为不参与统计。
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
两边内容同源,**开头第一行就是结论**——不用自己看懂字段,它会直接告诉你有没有查出问题:
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
诊断结论 ✗ 3 处异常、! 2 处提醒
|
|
121
|
+
✗ 余额取不到:未登录
|
|
122
|
+
✗ 今日 ¥0.0000 不可信:列得出会话但今天一个都没筛中;连会话列表都没列出来(DSH 索引还没就绪)。插件正在自动退避重试,拿到真值会自己更新,不用手动刷新
|
|
123
|
+
✗ 浮窗定位偏移 6px(卡片在 x=1156,应该在 x=1150)
|
|
124
|
+
! 今日是部分结果(刚冷启动或刚跨天),客户端会自动补拉
|
|
125
|
+
! 本会话 usage 读不到(会话没进内存或事件被切空),本会话金额会显示 ≈ ¥—
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
一切正常时就是一行 `诊断结论 ✓ 一切正常(余额、今日、本会话、浮窗、设置都没查出问题)`。查出**异常**时设置页那块报告会整体变成警告色,不用逐行读也知道出事了。
|
|
129
|
+
|
|
130
|
+
它查的是这几类:余额取不到 / 今日是假 0(含「为什么」)/ 今日还是部分结果 / 本会话读不到 usage / DSH 会话服务不可用 / 浮窗定位偏掉 / 设置里被填成 0 的扫描上限或倍率。后面跟着完整现场:余额、今日可信度、今日缓存与落盘快照、本会话(金额、模型、token 分项、高峰空闲拆分)、子代理与团队、当前设置口径、浮窗定位、会话读取状态,**最后附一段原始响应 JSON**(最多 6000 字)——没被正文明说的异常都能从那里对到具体字段,不用再开控制台。设置页那边有「复制」,整段贴出来即可。
|
|
131
|
+
|
|
132
|
+
查出问题时按钮旁边会多一个**「修复」**,点它会清掉能自己恢复的那几样再重算:
|
|
133
|
+
|
|
134
|
+
- 今日的内存缓存、重试次数和「已定值」标记(假 0 就是被这几个钉住的);
|
|
135
|
+
- 余额立刻重拉一次;
|
|
136
|
+
- 让浮窗重新量一次位置;
|
|
137
|
+
- 服务端那边同步清一次今日缓存,并中止进行中的重算。
|
|
138
|
+
|
|
139
|
+
它**不改你的设置**(那是有意配的值,不是故障),**也不删落盘快照**(可疑的 0 本来就落不了盘,「只增不减」保护着可信的那份)。修完会立刻重新诊断一遍并如实说还剩什么:「已恢复」或者在下面继续列异常——不会因为点过按钮就假装修好了。
|
|
118
140
|
|
|
119
141
|
只读动作,不会改任何设置,也不会写任何文件。字段含义和判据见下面「常见问题」里的「今日一直显示 ¥0.00 不动」。
|
|
120
142
|
|
package/lib/client.js
CHANGED
|
@@ -1520,6 +1520,9 @@ 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-fix{margin:8px 0 0;font-size:12px;line-height:17px}
|
|
1524
|
+
.balance-settings__diag-fix--ok{color:var(--dsw-alias-state-success-primary,#3fb950)}
|
|
1525
|
+
.balance-settings__diag-fix--warn{color:var(--dsw-alias-state-warn-primary,#d97706)}
|
|
1523
1526
|
.balance-settings__status{flex:1;min-width:0;font-size:12px;line-height:17px;color:var(--dsw-alias-label-tertiary)}
|
|
1524
1527
|
.balance-settings__status--error{color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
1525
1528
|
.balance-settings__status--ok{color:var(--dsw-alias-state-success-primary,#22c55e)}
|
|
@@ -1867,6 +1870,10 @@ window.__ModuleLoader__.load({
|
|
|
1867
1870
|
* `/balance-api?geom=1`,然后 `GET /balance-api?diag=1` 的 `floatGeom` 就能看到。
|
|
1868
1871
|
* 节流是必须的:measure 每 400ms 跑一次,无脑发会把还要算余额/今日的接口刷满。 */
|
|
1869
1872
|
let floatGeomSentAt = 0;
|
|
1873
|
+
// 「让浮窗立刻重新量一次」的钩子(2026-11-09,配诊断里的「修复」按钮)。
|
|
1874
|
+
// measure 定义在浮窗组件的 effect 里,设置卡片根本够不着,只能这样接一根线。
|
|
1875
|
+
// 没挂上时(浮窗没渲染 / 不在对话页)调它就是空操作,不报错。
|
|
1876
|
+
let floatRemeasureHook = null;
|
|
1870
1877
|
let floatGeomKey = "";
|
|
1871
1878
|
function reportFloatGeom(payload) {
|
|
1872
1879
|
try {
|
|
@@ -2616,6 +2623,7 @@ const CN_CALENDAR_SOURCES = [
|
|
|
2616
2623
|
["usageLoadingStyle", "2.0.9"], // 消耗行加载动效:样式1(光团开窗)/ 样式2(计算中),含行内实时预览
|
|
2617
2624
|
["todaySessionLimit", "2.1.0"], // 今日消耗扫描上限:多开对话 / 多跑子代理时把今日汇总算全
|
|
2618
2625
|
["showUsagePill", "2.1.6"], // 2.1.6:消耗行搬成对话界面右下角小浮窗(两行:本会话估算 / 金额)
|
|
2626
|
+
["diag", "2.2.5"], // 2.2.5:设置页「数据诊断」—— 一键出结论 + 复制 + 查出问题给「修复」
|
|
2619
2627
|
]);
|
|
2620
2628
|
|
|
2621
2629
|
/** NEW_TAGS 的 key → 设置项中文名。横幅要写「本版新增:消耗行加载动效」,
|
|
@@ -2627,6 +2635,7 @@ const CN_CALENDAR_SOURCES = [
|
|
|
2627
2635
|
usageLoadingStyle: "消耗行加载动效",
|
|
2628
2636
|
todaySessionLimit: "今日消耗扫描上限",
|
|
2629
2637
|
showUsagePill: "对话右下角消耗浮窗",
|
|
2638
|
+
diag: "数据诊断",
|
|
2630
2639
|
};
|
|
2631
2640
|
|
|
2632
2641
|
/** 模板串里取一张表的三个 NEW 相关字段,缺省一律安全兜底。 */
|
|
@@ -6179,6 +6188,8 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
6179
6188
|
};
|
|
6180
6189
|
syncObservers();
|
|
6181
6190
|
measureCtl.sync = syncObservers;
|
|
6191
|
+
// 把这次的 measure 挂出去:诊断里的「修复」按钮靠它把位置重算一遍。
|
|
6192
|
+
floatRemeasureHook = measure;
|
|
6182
6193
|
const onResize = () => {
|
|
6183
6194
|
measure();
|
|
6184
6195
|
scheduleSettle();
|
|
@@ -6194,6 +6205,8 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
6194
6205
|
return () => {
|
|
6195
6206
|
disposed = true;
|
|
6196
6207
|
clearInterval(timer);
|
|
6208
|
+
// 只拆自己挂的那个,别把后来者的钩子清掉
|
|
6209
|
+
if (floatRemeasureHook === measure) floatRemeasureHook = null;
|
|
6197
6210
|
clearSettle();
|
|
6198
6211
|
if (slideHold !== null) {
|
|
6199
6212
|
clearTimeout(slideHold);
|
|
@@ -7690,6 +7703,123 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7690
7703
|
}
|
|
7691
7704
|
return { sum, text: parts.length ? parts.join(" ") : "全 0" };
|
|
7692
7705
|
}
|
|
7706
|
+
/** 点「数据诊断」时**直接告诉用户有没有问题**(2026-11-09:「如果数据异常会提醒用户吗」)。
|
|
7707
|
+
* 只列字段等于让用户自己判,多数人看不懂 `suspiciousEmpty=false` 是什么意思。
|
|
7708
|
+
* 所以先跑一遍能查的检查,把结论摆在报告最上面:
|
|
7709
|
+
* error = 这个数现在就是错的(假 0、取不到、定位偏掉)
|
|
7710
|
+
* warn = 数值可能不准,但插件已经在自动纠正,或者纯粹是「正在算」
|
|
7711
|
+
* 没抓到任何一条 = 一切正常。 */
|
|
7712
|
+
function collectDiagIssues(data, settings) {
|
|
7713
|
+
const d = data != null && typeof data === "object" ? data : {};
|
|
7714
|
+
const s = settings != null && typeof settings === "object" ? settings : {};
|
|
7715
|
+
const issues = [];
|
|
7716
|
+
|
|
7717
|
+
// 余额
|
|
7718
|
+
if (d.balance == null) {
|
|
7719
|
+
issues.push({
|
|
7720
|
+
level: "error",
|
|
7721
|
+
text: d.balanceError ? `余额取不到:${d.balanceError}` : "余额取不到(未登录或网络失败)",
|
|
7722
|
+
});
|
|
7723
|
+
} else if (d.balanceError) {
|
|
7724
|
+
issues.push({ level: "error", text: `余额读取报错:${d.balanceError}` });
|
|
7725
|
+
}
|
|
7726
|
+
|
|
7727
|
+
// 今日
|
|
7728
|
+
const today = d.today;
|
|
7729
|
+
const td = d.todayDiag != null && typeof d.todayDiag === "object" ? d.todayDiag : null;
|
|
7730
|
+
const snap = td != null && td.snapshot != null && typeof td.snapshot === "object" ? td.snapshot : null;
|
|
7731
|
+
if (today == null || typeof today !== "object") {
|
|
7732
|
+
issues.push({
|
|
7733
|
+
level: "warn",
|
|
7734
|
+
text: `今日服务端暂未给出(todayPartial=${d.todayPartial === true}),界面会走等待态并自动补拉`,
|
|
7735
|
+
});
|
|
7736
|
+
} else {
|
|
7737
|
+
const cost = Number(today.cost ?? 0);
|
|
7738
|
+
const why = [];
|
|
7739
|
+
const seen = new Set();
|
|
7740
|
+
const add = (flag, reason) => {
|
|
7741
|
+
if (flag !== true || seen.has(reason)) return;
|
|
7742
|
+
seen.add(reason);
|
|
7743
|
+
why.push(reason);
|
|
7744
|
+
};
|
|
7745
|
+
for (const src of [today, snap]) {
|
|
7746
|
+
if (src == null || typeof src !== "object") continue;
|
|
7747
|
+
add(src.suspiciousEmpty === true, "列得出会话但今天一个都没筛中");
|
|
7748
|
+
add(src.emptyListing === true, "连会话列表都没列出来(DSH 索引还没就绪)");
|
|
7749
|
+
const skipped = Number(src.skipped ?? 0);
|
|
7750
|
+
if (skipped > 0) add(true, `${skipped} 个会话被让路跳过`);
|
|
7751
|
+
}
|
|
7752
|
+
const pending = td != null && (td.cacheProvisional === true || td.recomputing === true);
|
|
7753
|
+
if (cost === 0 && why.length !== 0) {
|
|
7754
|
+
issues.push({
|
|
7755
|
+
level: "error",
|
|
7756
|
+
text: `今日 ¥0.0000 不可信:${why.join(";")}。插件正在自动退避重试,拿到真值会自己更新,不用手动刷新`,
|
|
7757
|
+
});
|
|
7758
|
+
} else if (cost === 0 && pending) {
|
|
7759
|
+
issues.push({ level: "warn", text: "今日的 0 还在算(缓存 provisional 或正在重算),这一拍不是最终值" });
|
|
7760
|
+
}
|
|
7761
|
+
if (d.todayPartial === true) {
|
|
7762
|
+
issues.push({ level: "warn", text: "今日是部分结果(刚冷启动或刚跨天),客户端会自动补拉" });
|
|
7763
|
+
}
|
|
7764
|
+
}
|
|
7765
|
+
|
|
7766
|
+
// 本会话 / 会话服务
|
|
7767
|
+
if (d.diag != null && typeof d.diag === "object") {
|
|
7768
|
+
if (d.diag.sessionsUsable === false) {
|
|
7769
|
+
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false),本会话消耗只能退回读磁盘,会慢" });
|
|
7770
|
+
}
|
|
7771
|
+
}
|
|
7772
|
+
if (d.usage == null && d.loading !== true) {
|
|
7773
|
+
issues.push({ level: "warn", text: "本会话 usage 读不到(会话没进内存或事件被切空),本会话金额会显示 ≈ ¥—" });
|
|
7774
|
+
}
|
|
7775
|
+
if (d.loading === true) {
|
|
7776
|
+
issues.push({ level: "warn", text: "DSH 正在装载本会话,插件主动让路 —— 这不是故障,几秒后自己会好" });
|
|
7777
|
+
}
|
|
7778
|
+
|
|
7779
|
+
// 浮窗定位
|
|
7780
|
+
const g = d.floatGeom;
|
|
7781
|
+
if (g != null && typeof g === "object") {
|
|
7782
|
+
const selfX = g.self != null && Number.isFinite(Number(g.self.x)) ? Number(g.self.x) : null;
|
|
7783
|
+
const left = Number.isFinite(Number(g.left)) ? Number(g.left) : null;
|
|
7784
|
+
if (selfX !== null && left !== null && Math.abs(selfX - left) > 2) {
|
|
7785
|
+
issues.push({
|
|
7786
|
+
level: "error",
|
|
7787
|
+
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px(卡片在 x=${selfX},应该在 x=${left})`,
|
|
7788
|
+
});
|
|
7789
|
+
}
|
|
7790
|
+
}
|
|
7791
|
+
|
|
7792
|
+
// 设置自检:这几项填成 0 会让数字永远不对,但界面上完全看不出来
|
|
7793
|
+
if (Number(s.todaySessionLimit ?? 1) <= 0) {
|
|
7794
|
+
issues.push({ level: "error", text: "设置里的「今日扫描上限」是 0,今日金额会永远是 0" });
|
|
7795
|
+
}
|
|
7796
|
+
if (Number(s.statsSessionLimit ?? 1) <= 0) {
|
|
7797
|
+
issues.push({ level: "error", text: "设置里的「统计扫描上限」是 0,统计面板会永远是 0" });
|
|
7798
|
+
}
|
|
7799
|
+
if (Number(s.peakMultiplier ?? 1) <= 0) {
|
|
7800
|
+
issues.push({ level: "error", text: "设置里的「高峰倍率」是 0,高峰时段金额会被算成 0" });
|
|
7801
|
+
}
|
|
7802
|
+
return issues;
|
|
7803
|
+
}
|
|
7804
|
+
|
|
7805
|
+
/** 结论段:报告最上面那几行。 */
|
|
7806
|
+
function formatDiagVerdict(issues) {
|
|
7807
|
+
const bad = issues.filter((x) => x.level === "error");
|
|
7808
|
+
const warn = issues.filter((x) => x.level === "warn");
|
|
7809
|
+
const out = [];
|
|
7810
|
+
if (bad.length === 0 && warn.length === 0) {
|
|
7811
|
+
out.push("诊断结论 ✓ 一切正常(余额、今日、本会话、浮窗、设置都没查出问题)");
|
|
7812
|
+
return out;
|
|
7813
|
+
}
|
|
7814
|
+
const head = [];
|
|
7815
|
+
if (bad.length !== 0) head.push(`✗ ${bad.length} 处异常`);
|
|
7816
|
+
if (warn.length !== 0) head.push(`! ${warn.length} 处提醒`);
|
|
7817
|
+
out.push(`诊断结论 ${head.join("、")}`);
|
|
7818
|
+
for (const item of bad) out.push(` ✗ ${item.text}`);
|
|
7819
|
+
for (const item of warn) out.push(` ! ${item.text}`);
|
|
7820
|
+
return out;
|
|
7821
|
+
}
|
|
7822
|
+
|
|
7693
7823
|
/** 一份「出问题时能把整条链路对出来」的诊断文本。
|
|
7694
7824
|
* ⚠️ 2026-11-09 第二轮(用户:「诊断出来的信息是不是太少了 如果用户遇到别的数据异常
|
|
7695
7825
|
* 这东西复制过来好像也不知道哪里有问题」):所以正文按环节分段把**能拿到的都列出来**,
|
|
@@ -7703,6 +7833,9 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7703
7833
|
? `${location.hostname || "127.0.0.1"}:${location.port || "?"}`
|
|
7704
7834
|
: "?";
|
|
7705
7835
|
lines.push(`balance-dsh ${version || "—"} · ${where} · ${formatDiagTime(Date.now())}`);
|
|
7836
|
+
const issues = collectDiagIssues(d, s);
|
|
7837
|
+
lines.push("");
|
|
7838
|
+
for (const line of formatDiagVerdict(issues)) lines.push(line);
|
|
7706
7839
|
|
|
7707
7840
|
// ── 余额 ──
|
|
7708
7841
|
const bal = d.balance;
|
|
@@ -7882,6 +8015,9 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7882
8015
|
// idle/loading/ok/error 四态 + 一份已经拼好的纯文本。只读,不写任何设置。
|
|
7883
8016
|
const [diagReport, setDiagReport] = react.useState({ kind: "idle", text: "" });
|
|
7884
8017
|
const [diagCopied, setDiagCopied] = react.useState(false);
|
|
8018
|
+
// 「修复」按钮(2026-11-09 用户:「如果异常能不能添加一个修复按钮」)。
|
|
8019
|
+
// kind: idle / running / done(全好了)/ partial(修完还剩问题)/ failed
|
|
8020
|
+
const [diagFix, setDiagFix] = react.useState({ kind: "idle", note: "" });
|
|
7885
8021
|
|
|
7886
8022
|
// 拿到设置后灌一次草稿;draft 已有内容就不再覆盖,避免打断正在输入的用户。
|
|
7887
8023
|
// ⚠️ 必须等 `loaded === true` 再灌(2026-10-31 审查):
|
|
@@ -8054,7 +8190,14 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
8054
8190
|
const response = await fetch("/balance-api?diag=1&today=1", { headers: { accept: "application/json" } });
|
|
8055
8191
|
if (!response.ok) throw new Error("HTTP " + response.status);
|
|
8056
8192
|
const data = await response.json();
|
|
8057
|
-
|
|
8193
|
+
// 查出 error 级问题就把整块换成警告色 —— 用户点这个按钮就是想确认「是不是出事了」,
|
|
8194
|
+
// 一份平淡的等宽文本会让人误以为一切正常。
|
|
8195
|
+
const issues = collectDiagIssues(data, settingsCache.value);
|
|
8196
|
+
const bad = issues.some((x) => x.level === "error");
|
|
8197
|
+
setDiagReport({
|
|
8198
|
+
kind: bad ? "warn" : "ok",
|
|
8199
|
+
text: formatDiagnostics(data, settingsCache.version, settingsCache.value),
|
|
8200
|
+
});
|
|
8058
8201
|
} catch (error) {
|
|
8059
8202
|
setDiagReport({
|
|
8060
8203
|
kind: "error",
|
|
@@ -8063,6 +8206,69 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
8063
8206
|
}
|
|
8064
8207
|
})();
|
|
8065
8208
|
};
|
|
8209
|
+
/** 「修复」:把能自己恢复的那几样清掉再重算一遍。
|
|
8210
|
+
* ⚠️ 刻意**不碰用户的设置**(那是有意配的值,不是故障),也不删落盘快照
|
|
8211
|
+
* (可疑的 0 本来就落不了盘,「只增不减」保护着可信那份,删了只会让下次冷启动更慢)。
|
|
8212
|
+
* 修完立刻重新诊断一次,剩多少问题如实显示 —— 不假装修好了。 */
|
|
8213
|
+
const onFixDiag = () => {
|
|
8214
|
+
if (diagFix.kind === "running") return;
|
|
8215
|
+
setDiagCopied(false);
|
|
8216
|
+
setDiagFix({ kind: "running", note: "" });
|
|
8217
|
+
const notes = [];
|
|
8218
|
+
void (async () => {
|
|
8219
|
+
// ① 今日:清内存缓存与重试状态。可疑的 0 是被「已 settled」和缓存 TTL 钉住的,
|
|
8220
|
+
// 不清这两个,重新请求也只会拿到同一个值。
|
|
8221
|
+
todayCache.at = 0;
|
|
8222
|
+
todayCache.tried = false;
|
|
8223
|
+
todayCache.settled = false;
|
|
8224
|
+
todayCache.suspect = false;
|
|
8225
|
+
todayCache.retries = 0;
|
|
8226
|
+
clearTodaySuspectRetry();
|
|
8227
|
+
notes.push("今日缓存已清");
|
|
8228
|
+
// ② 余额:本来就是实时请求,这里只是强制立刻重拉一次
|
|
8229
|
+
void fetchBalanceOnce(true);
|
|
8230
|
+
notes.push("余额重拉");
|
|
8231
|
+
// ③ 浮窗:让浮窗自己重新量一次(拿不到钩子就跳过后面的提示)
|
|
8232
|
+
if (typeof floatRemeasureHook === "function") {
|
|
8233
|
+
try {
|
|
8234
|
+
floatRemeasureHook();
|
|
8235
|
+
notes.push("浮窗已重新定位");
|
|
8236
|
+
} catch {
|
|
8237
|
+
/* 量不到就当没有这一步 */
|
|
8238
|
+
}
|
|
8239
|
+
}
|
|
8240
|
+
// ④ 让服务端也清一次今日缓存(进行中的重算会继续喂旧值),再拿最新数据重出报告
|
|
8241
|
+
try {
|
|
8242
|
+
const response = await fetch("/balance-api?diag=1&today=1&fix=1", {
|
|
8243
|
+
headers: { accept: "application/json" },
|
|
8244
|
+
});
|
|
8245
|
+
if (!response.ok) throw new Error("HTTP " + response.status);
|
|
8246
|
+
const data = await response.json();
|
|
8247
|
+
if (data.fix != null && typeof data.fix === "object") {
|
|
8248
|
+
if (data.fix.clearedTodayCache === true) notes.push("服务端缓存已清");
|
|
8249
|
+
if (data.fix.cancelledRecompute === true) notes.push("已中止进行中的重算");
|
|
8250
|
+
}
|
|
8251
|
+
const issues = collectDiagIssues(data, settingsCache.value);
|
|
8252
|
+
const bad = issues.some((x) => x.level === "error");
|
|
8253
|
+
setDiagReport({
|
|
8254
|
+
kind: bad ? "warn" : "ok",
|
|
8255
|
+
text: formatDiagnostics(data, settingsCache.version, settingsCache.value),
|
|
8256
|
+
});
|
|
8257
|
+
setDiagFix({
|
|
8258
|
+
kind: bad ? "partial" : "done",
|
|
8259
|
+
note: notes.join(";") + (bad ? ";还剩问题,见下方结论" : ";已恢复"),
|
|
8260
|
+
});
|
|
8261
|
+
// 服务端算完之后,客户端再跟一次,让界面数字也换成新的
|
|
8262
|
+
void fetchTodayOnce(true);
|
|
8263
|
+
} catch (error) {
|
|
8264
|
+
setDiagFix({
|
|
8265
|
+
kind: "failed",
|
|
8266
|
+
note: "修复请求失败:" + (error instanceof Error ? error.message : String(error)),
|
|
8267
|
+
});
|
|
8268
|
+
}
|
|
8269
|
+
})();
|
|
8270
|
+
};
|
|
8271
|
+
|
|
8066
8272
|
const onCopyDiag = () => {
|
|
8067
8273
|
const text = diagReport.text;
|
|
8068
8274
|
if (!text) return;
|
|
@@ -8748,6 +8954,16 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
8748
8954
|
? "数据诊断"
|
|
8749
8955
|
: "重新诊断",
|
|
8750
8956
|
}),
|
|
8957
|
+
// 只有查出问题时才出现「修复」—— 一切正常时多一个按钮只会让人以为还有事没做
|
|
8958
|
+
diagReport.kind === "warn"
|
|
8959
|
+
? jsx.jsx("button", {
|
|
8960
|
+
type: "button",
|
|
8961
|
+
className: "balance-settings__btn",
|
|
8962
|
+
onClick: onFixDiag,
|
|
8963
|
+
disabled: diagFix.kind === "running",
|
|
8964
|
+
children: diagFix.kind === "running" ? "修复中…" : "修复",
|
|
8965
|
+
})
|
|
8966
|
+
: null,
|
|
8751
8967
|
diagReport.text
|
|
8752
8968
|
? jsx.jsx("button", {
|
|
8753
8969
|
type: "button",
|
|
@@ -8759,11 +8975,22 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
8759
8975
|
],
|
|
8760
8976
|
}),
|
|
8761
8977
|
),
|
|
8978
|
+
// 修完说清楚做了什么、还剩什么 —— 只报「成功」而不提剩余问题等于骗人
|
|
8979
|
+
diagFix.note
|
|
8980
|
+
? jsx.jsx("div", {
|
|
8981
|
+
className:
|
|
8982
|
+
"balance-settings__diag-fix" +
|
|
8983
|
+
(diagFix.kind === "failed" || diagFix.kind === "partial"
|
|
8984
|
+
? " balance-settings__diag-fix--warn"
|
|
8985
|
+
: " balance-settings__diag-fix--ok"),
|
|
8986
|
+
children: diagFix.note,
|
|
8987
|
+
})
|
|
8988
|
+
: null,
|
|
8762
8989
|
diagReport.text
|
|
8763
8990
|
? jsx.jsx("pre", {
|
|
8764
8991
|
className:
|
|
8765
8992
|
"balance-settings__diag" +
|
|
8766
|
-
(diagReport.kind === "error" ? " balance-settings__diag--error" : ""),
|
|
8993
|
+
(diagReport.kind === "error" || diagReport.kind === "warn" ? " balance-settings__diag--error" : ""),
|
|
8767
8994
|
children: diagReport.text,
|
|
8768
8995
|
})
|
|
8769
8996
|
: null,
|
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.5";
|
|
1081
1081
|
|
|
1082
1082
|
/** 斜杠命令名(2026-10-31 定案:用带作者后缀的全名,避免和别的余额插件撞车,也不设备用名)。
|
|
1083
1083
|
* ⚠️ DSH 的 COMMAND_NAME = /^[a-z][a-z0-9_-]*$/u —— **只允许小写**。
|
|
@@ -4115,6 +4115,9 @@ function runQuietly(label, fn) {
|
|
|
4115
4115
|
* 2026-11-09 用户两句:「怎么在会话调出诊断信息」「诊断出来的信息是不是太少了」。 */
|
|
4116
4116
|
async function buildDiagReport({ ctx, config, todayState, session, sessionId, signal, floatGeom }) {
|
|
4117
4117
|
const lines = [];
|
|
4118
|
+
// 结论收集(2026-11-09「如果数据异常会提醒用户吗」):命令和设置页那个按钮同口径,
|
|
4119
|
+
// 都把「查出来的问题」摆在最前面,而不是甩一堆字段让人自己判。
|
|
4120
|
+
const issues = [];
|
|
4118
4121
|
const money = (v) => (Number.isFinite(Number(v)) && v !== null && v !== undefined ? "¥" + Number(v).toFixed(4) : "¥—");
|
|
4119
4122
|
const when = (ms) => {
|
|
4120
4123
|
const n = Number(ms);
|
|
@@ -4139,6 +4142,11 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4139
4142
|
} catch (error) {
|
|
4140
4143
|
balanceError = error instanceof Error ? error.message : String(error);
|
|
4141
4144
|
}
|
|
4145
|
+
if (balance === null) {
|
|
4146
|
+
issues.push({ level: "error", text: balanceError ? `余额取不到:${balanceError}` : "余额取不到(未登录或网络失败)" });
|
|
4147
|
+
} else if (balanceError) {
|
|
4148
|
+
issues.push({ level: "error", text: `余额读取报错:${balanceError}` });
|
|
4149
|
+
}
|
|
4142
4150
|
lines.push("**余额** " + (balance === null ? "¥—(未登录或取不到)" : money(balance.total_balance) +
|
|
4143
4151
|
(balance.granted_balance == null ? "" : ` 赠送 ${money(balance.granted_balance)}`)));
|
|
4144
4152
|
if (balanceError) lines.push(` balanceError:${balanceError}`);
|
|
@@ -4156,6 +4164,20 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4156
4164
|
if (today != null) {
|
|
4157
4165
|
lines.push(`**今日** ${money(today.cost)} date=${today.date ?? "—"} sessions=${today.sessions ?? 0} tokens=${today.totalTokens ?? 0}`);
|
|
4158
4166
|
const unreliable = todayValueUnreliable(today);
|
|
4167
|
+
const cost = Number(today.cost ?? 0);
|
|
4168
|
+
if (cost === 0 && unreliable) {
|
|
4169
|
+
const why = [];
|
|
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} 个会话被让路跳过`);
|
|
4173
|
+
issues.push({
|
|
4174
|
+
level: "error",
|
|
4175
|
+
text: `今日 ¥0.0000 不可信:${why.join(";") || "服务端标记为可疑"}。插件会自动退避重试`,
|
|
4176
|
+
});
|
|
4177
|
+
}
|
|
4178
|
+
if (todayPartial) {
|
|
4179
|
+
issues.push({ level: "warn", text: "今日是部分结果(刚冷启动或刚跨天),客户端会自动补拉" });
|
|
4180
|
+
}
|
|
4159
4181
|
lines.push(` 可信=${unreliable ? "不可信(假 0 / 少算,客户端会自动退避重试)" : "可信"} ` +
|
|
4160
4182
|
`suspiciousEmpty=${today.suspiciousEmpty === true} emptyListing=${today.emptyListing === true} ` +
|
|
4161
4183
|
`skipped=${today.skipped ?? 0} partial=${todayPartial}`);
|
|
@@ -4184,6 +4206,10 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4184
4206
|
const model = session == null ? "" : detectModel(session);
|
|
4185
4207
|
lines.push("");
|
|
4186
4208
|
if (usage == null) {
|
|
4209
|
+
issues.push({
|
|
4210
|
+
level: "warn",
|
|
4211
|
+
text: "本会话 usage 读不到(会话没进内存或事件被切空),本会话金额会显示 ≈ ¥—",
|
|
4212
|
+
});
|
|
4187
4213
|
lines.push("**本会话** —(拿不到 usage:会话没进内存或事件切空了,见下面的会话读取)");
|
|
4188
4214
|
} else {
|
|
4189
4215
|
const tokens = (Number(usage.inputTokens ?? 0) + Number(usage.outputTokens ?? 0) +
|
|
@@ -4228,6 +4254,12 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4228
4254
|
const selfX = floatGeom.self != null && Number.isFinite(Number(floatGeom.self.x)) ? Number(floatGeom.self.x) : null;
|
|
4229
4255
|
const left = Number.isFinite(Number(floatGeom.left)) ? Number(floatGeom.left) : null;
|
|
4230
4256
|
const aligned = selfX !== null && left !== null && Math.abs(selfX - left) <= 2;
|
|
4257
|
+
if (!aligned && selfX !== null && left !== null) {
|
|
4258
|
+
issues.push({
|
|
4259
|
+
level: "error",
|
|
4260
|
+
text: `浮窗定位偏移 ${Math.abs(selfX - left)}px(卡片在 x=${selfX},应该在 x=${left})`,
|
|
4261
|
+
});
|
|
4262
|
+
}
|
|
4231
4263
|
lines.push(`**浮窗** ${aligned ? "✓ 对齐" : "✗ 偏移"} left=${left} self.x=${selfX} styleLeft=${floatGeom.styleLeft}` +
|
|
4232
4264
|
` 视口=${floatGeom.vw}×${floatGeom.vh}`);
|
|
4233
4265
|
lines.push(` card ${rect(floatGeom.card)} dock ${rect(floatGeom.dock)} ` +
|
|
@@ -4236,9 +4268,29 @@ async function buildDiagReport({ ctx, config, todayState, session, sessionId, si
|
|
|
4236
4268
|
|
|
4237
4269
|
// 会话读取
|
|
4238
4270
|
const sessions = typeof ctx.get === "function" ? ctx.get("sessions") : null;
|
|
4271
|
+
if (!(sessions != null && typeof sessions.get === "function")) {
|
|
4272
|
+
issues.push({ level: "warn", text: "DSH 会话服务不可用(sessionsUsable=false),本会话消耗只能退回读磁盘,会慢" });
|
|
4273
|
+
}
|
|
4239
4274
|
lines.push("");
|
|
4240
4275
|
lines.push(`**会话读取** sessionsUsable=${sessions != null && typeof sessions.get === "function"} ` +
|
|
4241
4276
|
`sessionUndefined=${session === undefined || session === null} sessionId=${sessionId || "—"}`);
|
|
4277
|
+
|
|
4278
|
+
// 结论插到标题下面(lines[0] 是标题、lines[1] 是空行)
|
|
4279
|
+
const bad = issues.filter((x) => x.level === "error");
|
|
4280
|
+
const warn = issues.filter((x) => x.level === "warn");
|
|
4281
|
+
const verdict = [];
|
|
4282
|
+
if (bad.length === 0 && warn.length === 0) {
|
|
4283
|
+
verdict.push("**诊断结论 ✓ 一切正常**(余额、今日、本会话、浮窗都没查出问题)");
|
|
4284
|
+
} else {
|
|
4285
|
+
const head = [];
|
|
4286
|
+
if (bad.length !== 0) head.push(`✗ ${bad.length} 处异常`);
|
|
4287
|
+
if (warn.length !== 0) head.push(`! ${warn.length} 处提醒`);
|
|
4288
|
+
verdict.push(`**诊断结论 ${head.join("、")}**`);
|
|
4289
|
+
for (const item of bad) verdict.push(`- ✗ ${item.text}`);
|
|
4290
|
+
for (const item of warn) verdict.push(`- ! ${item.text}`);
|
|
4291
|
+
}
|
|
4292
|
+
verdict.push("");
|
|
4293
|
+
lines.splice(2, 0, ...verdict);
|
|
4242
4294
|
return lines.join("\n");
|
|
4243
4295
|
}
|
|
4244
4296
|
export function apply(ctx, config = {}) {
|
|
@@ -4623,6 +4675,11 @@ let statsInFlight = null;
|
|
|
4623
4675
|
let wantStats = false;
|
|
4624
4676
|
let wantToday = false;
|
|
4625
4677
|
let wantDiag = false;
|
|
4678
|
+
// `?fix=1`(配 diag 用):把「能自己修的那部分」修掉再算。
|
|
4679
|
+
// 2026-11-09 用户:「如果异常能不能添加一个修复按钮」。
|
|
4680
|
+
// 目前只对今日有意义 —— 假 0 是内存缓存/进行中的重算把值钉住了,清掉即可重新算;
|
|
4681
|
+
// 余额本来就是每次实时请求,usage 由客户端自己重取,都不需要服务端额外动作。
|
|
4682
|
+
let wantFix = false;
|
|
4626
4683
|
// `?lite=1`:只算「本会话 usage + 子代理 + 团队」,**不查余额、不碰今日**。
|
|
4627
4684
|
// 智能体团队的 15 秒补拉走这条 —— 补拉只为了更新团队那点数字,
|
|
4628
4685
|
// 却原来连带一次官方余额网络请求(实测 419ms)和一次今日增量,
|
|
@@ -4635,6 +4692,7 @@ let statsInFlight = null;
|
|
|
4635
4692
|
wantStats = search.get("stats") === "1";
|
|
4636
4693
|
wantToday = search.get("today") === "1";
|
|
4637
4694
|
wantDiag = search.get("diag") === "1";
|
|
4695
|
+
wantFix = wantDiag && search.get("fix") === "1";
|
|
4638
4696
|
wantLite = search.get("lite") === "1";
|
|
4639
4697
|
} catch {
|
|
4640
4698
|
model = "";
|
|
@@ -4642,8 +4700,22 @@ let statsInFlight = null;
|
|
|
4642
4700
|
wantStats = false;
|
|
4643
4701
|
wantToday = false;
|
|
4644
4702
|
wantDiag = false;
|
|
4703
|
+
wantFix = false;
|
|
4645
4704
|
wantLite = false;
|
|
4646
4705
|
}
|
|
4706
|
+
// 修复(`?fix=1`,配诊断用):清掉今日的内存缓存与「进行中的重算」句柄,
|
|
4707
|
+
// 让后面这次真的重新算一遍。2026-11-09 用户:「如果异常能不能添加一个修复按钮」。
|
|
4708
|
+
// ⚠️ **不动落盘快照**:可疑的 0 本来就落不了盘(todayValueUnreliable 会拦),
|
|
4709
|
+
// 而「只增不减」的规则保护着已经可信的那份 —— 删文件只会让下次冷启动更慢。
|
|
4710
|
+
const fixResult = { clearedTodayCache: false, cancelledRecompute: false };
|
|
4711
|
+
if (wantFix) {
|
|
4712
|
+
if (todayState.cache.value !== null || todayState.cache.expiresAt !== 0) {
|
|
4713
|
+
fixResult.clearedTodayCache = true;
|
|
4714
|
+
}
|
|
4715
|
+
if (todayState.recompute != null) fixResult.cancelledRecompute = true;
|
|
4716
|
+
todayState.cache = { value: null, expiresAt: 0 };
|
|
4717
|
+
todayState.recompute = null;
|
|
4718
|
+
}
|
|
4647
4719
|
let stats = null;
|
|
4648
4720
|
let statsError = "";
|
|
4649
4721
|
if (wantStats) {
|
|
@@ -5075,6 +5147,7 @@ let statsInFlight = null;
|
|
|
5075
5147
|
// 不返回它的话,客户端会按「空结果」走 400ms 的快重试,又把解压撞回去。
|
|
5076
5148
|
...(sessionYielded ? { loading: true } : {}),
|
|
5077
5149
|
...(wantDiag ? { diag: sessionDiag, floatGeom: lastFloatGeom, todayDiag } : {}),
|
|
5150
|
+
...(wantFix ? { fix: fixResult } : {}),
|
|
5078
5151
|
});
|
|
5079
5152
|
} catch (error) {
|
|
5080
5153
|
// headersSent 之后不能再写头,只能放弃这一次响应
|