Repository navigation
新增历史用量回填与侧边栏余额,修复 Token 统计及持久化 - #14
Closed
zhiqiangme wants to merge 7 commits into
Closed
zhiqiangme wants to merge 7 commits into
zhiqiangme wants to merge 7 commits into
Conversation
新增 lib/scan.js:从本地会话日志回填插件未运行期间的历史用量。 支持增量扫描(缓存游标)、深扫(连探针已覆盖的会话一起扫)、 按 (sessionId, turn, step) 折叠重复结算。 后端 provider 增加 scanHistory / scanStatus 动作;面板加「扫描历史」按钮。 新增 test/scan.test.js。
上游 npm 已到 1.16.5(GitHub 停在 1.14.1),以其为基线并入本地的 事后扫描与 tab 改名,保留 1.15/1.16 的预算、Hero 卡片、趋势/环形图、 会话排行、搜索与帮助抽屉等功能。 顶部 tab 改名为「用量」「余额」(原「用量与消耗」「剩余余额查询」)。
修复切入用量/余额页后切换会话,再切回仍停在插件页的问题: 仅写 localStorage 无效(store 只在挂载时读一次,之后每次变更都会 把内存值写回),改为在会话变更时通过宿主注入的 openView 复位。 面板上的宽度调整线改为对句柄元素 visibility/pointerEvents 隐藏, 不改布局、不加祖先类名。 对齐概览页卡片间距;「帮助与说明」移到子页签栏右侧。新增 test/view-reset.test.js。
侧边栏底部(设置上方)新增入口:按余额页标签顺序串行探测, 显示第一个查到余额的服务商;标签固定为「余额」,双击跳转余额页。 跳转走宿主注入的 openView 句柄并做会话归属校验,不会切走别的会话。 余额页新增「侧边栏设置」,可固定显示某个服务商,选择即刻生效。 新增 test/sidebar.test.js。
「本轮 token」此前显示成整场对话的量:窗口误用 timing.stepStartTime (那是一步的起点,长会话里会横跨很多轮),改用宿主 turn 的 location.turn.start/end;且必须用 useChat 读节点(会话快照没有 chat.nodes),用错 hook 会让窗口永远取不到。 累计量改用宿主紧凑计数写法(149M / 12.2K),弹窗配色改走主题变量 --dsw-alias-* 以适配夜间模式。新增 turn-usage / turn-window / client-integrity 测试。
总 token 双计未命中:记录时把 DeepSeek 系不上报的 cacheWriteTokens 兜底成 inputTokens,四桶合计因此多算一笔。改为记录层只存真实上报值, 兜底移到展示层;历史记录经 normalizeRecord 迁移清零。 消息面板直接读会话日志并按宿主 tokenUsage 规则折叠(同一步替换、 llm/retry-started 后另计),不再依赖可能漏记的插件记录。 新增 lib/storage.js(原子写 + 损坏保护,解析失败不静默清空)、 lib/records.js(复合身份去重,同毫秒不同请求不再互相覆盖)、 lib/conversation-usage.js。新增对应测试。
package.json 版本更新到 1.16.5-local.22,CHANGELOG 补充本地构建记录。
zhiqiangme
marked this pull request as ready for review
September 17, 2026 07:24
Owner
|
感谢 @zhiqiangme 这份 PR,工作量很大,我逐项读过了。 先说评审口径:以 结论不做整包合并,但按条目移植了其中的确定性修复,已在 1.18.0(commit 为什么不整包合并
已采纳并合入 1.18.0
想单独立项、暂未合并
其他
再次感谢。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
本地实时探针可能漏记部分请求,历史回填又可能将同一步重试覆盖,导致消息 Token 面板与宿主累计不一致。本 PR 将对话面板改为按宿主持久化日志折叠用量,并补充历史回填、持久化保护及相关界面功能。
代码来源与审阅范围
本 PR 的差异包含两部分:同步上游 npm 已发布代码,以及在此基础上的本次修复与功能修改。
main与v1.16.5标签均指向bf612da3982de7363435534f608b6f6999540d8e,其中package.json仍为1.14.1;npm@feiyang666/[email protected]的实际发布内容与该提交不同,包括lib/index.js、lib/client.js和文档。🐛 修复 BUG
🎨 UI 修改
✨ 新增功能
版本号与更新日志整理提交:b70aba4。同一提交可能同时包含 BUG 修复与 UI 修改,以上按实际改动分别引用。
验证
node --test test/*.test.js:110 项通过。node scripts/check-package.js:通过。git diff --check upstream/main...upstream-features:通过。其他
1.16.5-local.22,发布版本号与本地构建更新日志需要维护者确认。