balance-dsh 2.3.3 → 2.3.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 +36 -21
- package/lib/client.js +507 -55
- package/lib/index.js +100 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,13 +16,17 @@ DeepSeek Harness 插件:在 Web UI 中直接显示 DeepSeek 账户余额和当
|
|
|
16
16
|
- **新版(默认)**:上方一行文字信息 + 下方一条扁刻度条。
|
|
17
17
|
- 文字分两段:`今日 ¥21.42`(今天累计消耗)和 `空闲 剩 3h57m`(当前时段 + 距切换还剩多久,高峰为红色、空闲为绿色)。
|
|
18
18
|
- 刻度条整条代表**一整天**:彩色分段标出这一天里哪些时段是高峰、哪些是空闲,一个指针标出「此刻走在今天的哪个位置」,每分钟前进一格。换日或同步到新的节假日安排时,颜色分布会交叉淡入。
|
|
19
|
+
- **侧栏拖窄、一行放不下时自动切成三行**:`今日 ¥21.42` / `空闲 剩 3h57m` / 刻度条,整体居中。不会挤成省略号,也不会把设置齿轮顶歪。
|
|
20
|
+
- 「今日」的金额、以及「空闲 / 高峰」那一段都是**滑过去**的,不是瞬间跳位:`剩 10h55m` 变成 `剩 10h54m` 时能看出它在走。
|
|
19
21
|
- **旧版**:钱包图标 + `余额` + 金额(带货币单位)的纯文字行,右侧可带时段标签。
|
|
20
22
|
|
|
21
|
-
金额按余额状态变色:充足为主题绿、低于阈值(默认 10
|
|
23
|
+
金额按余额状态变色:充足为主题绿、低于阈值(默认 10 元)为琥珀黄、余额用完时金额胶囊整个换成红色 **「充值」** 按钮(点一下直达充值页)。金额变化时按位滚动切换(只滚变化的数位),不会整块闪一下。
|
|
22
24
|
|
|
23
25
|
### 收起态圆钮
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
侧边栏收起时,余额显示为左下角的**圆形**悬浮按钮(liquid glass 质感,圆内显示 `¥金额`,余额耗尽时显示「充值」)。直径与距左缘距离均可调。
|
|
28
|
+
|
|
29
|
+
位置固定在**左下角,底边和左边的留白一样宽**,**不跟聊天框对齐**——窗口怎么缩放、输入框上面多一行少一行,它都待在原地不动。
|
|
26
30
|
|
|
27
31
|
### 刷新
|
|
28
32
|
|
|
@@ -49,20 +53,30 @@ DeepSeek Harness 插件:在 Web UI 中直接显示 DeepSeek 账户余额和当
|
|
|
49
53
|
- 节假日与调休安排从国务院公告(公开数据源)自动同步,内置当年表作离线兜底,**无需每年手动维护**;配置界面里能看到上次同步时间,也能手动触发立即同步。
|
|
50
54
|
- 消耗金额**跨时段精确计费**:高峰时段的 token 按高峰价、空闲时段按目录价,按每条消息的**事件时间**分桶计算,不会用「当前时段」笼统估算整个会话。
|
|
51
55
|
|
|
52
|
-
###
|
|
56
|
+
### 会话消耗浮窗
|
|
57
|
+
|
|
58
|
+
对话界面**右下角**一张小卡片,竖排两行:上行 `本会话消耗估算`,下行金额。没有图标,也不放 `≈`——标签本身就说清了是估算。
|
|
59
|
+
|
|
60
|
+
- **贴着输入框**:待在输入框的右下角。窗口放大到 4K 全屏时它跟着输入框走,不会被甩到屏幕最右边。
|
|
61
|
+
- **从输入框里升出来**:整页只出现一次,之后切对话不再重播。
|
|
62
|
+
- **加载**:一层毛玻璃迷雾盖住金额,数据到手那一刻一道白光扫过、数字跟着光显现。**同一会话只出现一次**,之后的实时刷新只滚数字、不重播动画。
|
|
63
|
+
- **历史过长时**:卡片上方会浮起一颗「历史过长,稍候」的小气泡,并且至少停留 1 秒才消失。所以加载 1.05 秒也不会闪一下就没。
|
|
64
|
+
- **数字按位滚动**,只滚变化的数位。
|
|
53
65
|
|
|
54
|
-
|
|
66
|
+
**点击**展开明细浮层:Token 用量、缓存命中率、模型、高峰 / 空闲拆分、子代理消耗、网页搜索 / 抓取次数与费用、图片张数与估算 token。
|
|
67
|
+
|
|
68
|
+
### 窗口太窄时
|
|
69
|
+
|
|
70
|
+
窗口宽度收窄到 **860px** 以下,左下圆钮和右下消耗浮窗会**淡出隐藏**——缩到最小附近时这两张卡都不挡字。拉回 860px 以上自动恢复。
|
|
55
71
|
|
|
56
72
|
### 智能体团队(Agent Teams)
|
|
57
73
|
|
|
58
74
|
会话里开了团队(Lead + teammate)时:
|
|
59
75
|
|
|
60
|
-
-
|
|
76
|
+
- 浮窗里多一颗 `团队 N` 小圆片,说明这颗金额是**本会话 + N 个队友**的合计(队友的钱本来就按子会话算进去了)。
|
|
61
77
|
- 明细浮层多一块「智能体团队」,按人头列出每个队友的 `名字 · 状态` 与 `≈ ¥金额`,右上角是团队合计。
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
|
|
65
|
-
roster 直接读会话里的 `team/member` 事件,不依赖 `agentTeams` 服务或 `agentTeam` 投影 —— 团队功能没启用时这些事件不存在,上面这些都不出现。
|
|
78
|
+
- 队友干活时团队金额会自动刷新,不会停在旧值。
|
|
79
|
+
- 从父会话 fork 出来的队友,插件只算它自己产生的消耗,不会把父会话的钱重复算一遍。
|
|
66
80
|
|
|
67
81
|
### 网页搜索 / 抓取按次计费
|
|
68
82
|
|
|
@@ -76,7 +90,7 @@ roster 直接读会话里的 `team/member` 事件,不依赖 `agentTeams` 服
|
|
|
76
90
|
图片 12 张 · 约 4,300 tok · 已计入输入
|
|
77
91
|
```
|
|
78
92
|
|
|
79
|
-
token
|
|
93
|
+
token 数按官方文档站「图片 Token 计算器」的同一套算法估算,所以和官网算出来的数字一致。同一张图只算一次,不会因为同时出现在两处事件里被重复统计。
|
|
80
94
|
|
|
81
95
|
要注意的是:**图一旦进入上下文,后面每一轮请求都会再把它计一遍输入**(多数能命中缓存,单价便宜很多)。所以「图片 N 张 · 约 X tok」说的是这些图本身的体积,不是它们累计产生的费用。
|
|
82
96
|
|
|
@@ -147,13 +161,13 @@ token 数用官方文档站「图片 Token 计算器」的同一套算法估算
|
|
|
147
161
|
|
|
148
162
|
**插件显示的所有金额都是本地估算,不是 DeepSeek 官方账单。** 想要准确数字请用「查看官方用量」打开官方页面。
|
|
149
163
|
|
|
150
|
-
- 热力图按北京时间聚合最近 90
|
|
151
|
-
- 费用按每条消息的**实际模型**和**峰谷时段**估算:高峰时段的 token
|
|
152
|
-
-
|
|
153
|
-
- 其他已知误差来源:本地 token
|
|
164
|
+
- 热力图按北京时间聚合最近 90 天的会话 Token 用量。
|
|
165
|
+
- 费用按每条消息的**实际模型**和**峰谷时段**估算:高峰时段的 token 按高峰价、空闲时段按目录价。
|
|
166
|
+
- **峰谷归属按「请求发起时刻」判定**(拿不到时回退消息完成时刻)。**官方并未公开跨时段请求到底按发起还是按完成计费**,所以这是一个合理猜测而非官方口径;如果官方实际按响应生成时间逐段计费,一次横跨边界的请求真实费用会介于「全高峰」和「全空闲」之间,本插件两种口径都算不出这个中间值。(实测影响很小:请求平均耗时约 6 秒,长请求也只到分钟级,撞上窗口边界的概率极低。)
|
|
167
|
+
- 其他已知误差来源:本地 token 数与官方计费口径可能不同(系统提示、工具调用的内部算法未公开);缓存有没有命中,官方口径可能不同;官方调价后需等插件更新价表;模型靠会话里的切换点推断,同名不同版本分不清。
|
|
154
168
|
- 峰值倍率只乘一次:高峰桶乘以倍率,空闲桶原价,网页工具费不参与峰谷倍数。
|
|
155
169
|
- **图片 token 已包含在输入里**,插件不会再为它算一次钱(那会让金额翻倍)。明细里的「图片约 X tok」是各张图本身的体积之和,按官方计算器算法估算;图留在上下文里每轮都会重新计一遍输入,这部分体现在「缓存读取」中。
|
|
156
|
-
- 为避免历史会话过多拖慢 DeepSeek Harness
|
|
170
|
+
- 为避免历史会话过多拖慢 DeepSeek Harness,统计面板默认最多回看最近 **80** 个会话,今日消耗默认扫 **200** 个(今日要宽、历史要快,两个上限分别可调);统计结果缓存 5 分钟,重复打开面板不会重复请求。**这两个上限、以及刷新间隔、各类显示开关,都能在配置界面里改。**
|
|
157
171
|
- 账户余额优先读取 **DeepSeek Harness 官方账号**(登录后即可用,无需 API Key);未登录时回退到 API Key。两者都不可用时仍可查看本地 Token 与费用统计,只是余额会显示为不可用。
|
|
158
172
|
|
|
159
173
|
## 安装
|
|
@@ -214,11 +228,12 @@ dsh plugin --profile desktop add github:Rannist/balance-dsh
|
|
|
214
228
|
|---|---|
|
|
215
229
|
| 版本与更新 | 当前版本、检查更新、就地更新 |
|
|
216
230
|
| 节假日数据 | 同步状态、立即同步 |
|
|
217
|
-
| 余额 |
|
|
218
|
-
| 界面显示 | 侧边栏余额行开关、余额行样式(新版 /
|
|
219
|
-
| 收起态圆钮 |
|
|
220
|
-
| 用量统计 |
|
|
221
|
-
| 计费 |
|
|
231
|
+
| 余额 | 余额刷新间隔、低余额警示阈值、API Key |
|
|
232
|
+
| 界面显示 | 侧边栏余额行开关、余额行样式(新版 / 旧版)、侧边栏入口开关、右键刷新浪潮、会话消耗行开关、消耗行加载动效(样式1 白光擦出 / 样式2 计算中)、(仅旧版)高峰空闲标签开关 |
|
|
233
|
+
| 收起态圆钮 | 显示圆钮、直径、距左缘(同时就是距底边) |
|
|
234
|
+
| 用量统计 | 今日消耗扫描上限、扫描会话数上限、统计缓存时长、聚合缓存条数上限 |
|
|
235
|
+
| 计费 | 高峰时段(可编辑,格式 `9-12, 14-18`)、高峰时段倍率 |
|
|
236
|
+
| 数据诊断 | 生成诊断报告、修复(查出问题时才出现)、复制 |
|
|
222
237
|
|
|
223
238
|
卡片最顶部是一条固定的范围声明:「计费仅支持 DeepSeek Harness 内的 DeepSeek 官方模型与账号;其他大模型不计入金额。」
|
|
224
239
|
|
|
@@ -260,7 +275,7 @@ pnpm remove balance-dsh
|
|
|
260
275
|
- 检查更新只请求 `registry.npmjs.org` 上本包的版本号,不发送任何账户信息;就地更新只下载本插件自己的发布包。
|
|
261
276
|
- 节假日数据来自公开的国务院公告镜像(`cdn.jsdelivr.net` 上的 holiday-cn),只读取、不上报。
|
|
262
277
|
- 插件不收集、不上传任何会话内容到第三方。
|
|
263
|
-
-
|
|
278
|
+
- 消费统计完全基于本地会话数据计算,不向 DeepSeek 之外的服务发送数据。
|
|
264
279
|
|
|
265
280
|
## 价格表(空闲时段价,元/百万 tokens)
|
|
266
281
|
|
package/lib/client.js
CHANGED
|
@@ -171,13 +171,34 @@ window.__ModuleLoader__.load({
|
|
|
171
171
|
padding 0 10px 0 8px、gap 8px、font 14px/22px、color label-primary;
|
|
172
172
|
左缘与设置按钮严格对齐,高度/颜色一致(金额 600 加粗)。
|
|
173
173
|
布局:[meta + 刻度条(竖排,居中)] [金额(最右)] */
|
|
174
|
-
.balance-footer{position:relative;isolation:isolate;box-sizing:border-box;display:flex;align-items:center;justify-content:flex-start;gap:
|
|
174
|
+
.balance-footer{position:relative;isolation:isolate;box-sizing:border-box;display:flex;align-items:center;justify-content:flex-start;gap:6px;flex:1 1 auto;min-width:0;margin:0;height:42px;margin-top:0;margin-bottom:0;margin-right:0;padding:0 0 0 8px;color:var(--dsw-alias-label-primary);font-size:14px;line-height:22px;text-decoration:none;cursor:pointer;white-space:nowrap;overflow:visible;-webkit-user-select:none;user-select:none}
|
|
175
|
+
/* ⚠️ 这里没有 width:100%(2026-11-24,issue #3),用 flex:1 1 auto:吃满可用宽度,但 basis 是
|
|
176
|
+
内容宽,不会像 flex:1 1 100% 那样在 flex-wrap 容器里独占一行(那会把「移动访问」挤到第二行,
|
|
177
|
+
两行各自居中之后看着就是「胶囊偏上」)。
|
|
178
|
+
⚠️ grow 必须保留:classic 的胶囊靠 .balance-footer__value 的 margin-left:auto 推到右缘,
|
|
179
|
+
行本身不占满整宽时 auto 外边距没有空间可推,胶囊就紧贴在「余额」二字后面(用户 2026-11-24:
|
|
180
|
+
「太靠左了」)。 */
|
|
175
181
|
/* 带 meta 行时整块变高:42px 装不下「一行 11px 文字 + 13px 轨道」,改成自适应。 */
|
|
176
182
|
.balance-footer--stacked{height:auto;min-height:42px;padding-top:5px;padding-bottom:5px}
|
|
177
183
|
/* 整行都是热区(单击统计面板 / 双击用量页 / 右键刷新;交互挂在 .balance-stats-anchor、捕获阶段)。
|
|
178
184
|
不给整行画 hover / active 底色——那圈圆角高亮框在侧边栏里太显眼,
|
|
179
185
|
且余白区也被涂上颜色很怪(2026-10-30 反馈「我不要高亮显示」)。
|
|
180
186
|
可点指示只靠右端胶囊自己的 hover 缩放。 */
|
|
187
|
+
/* ── 精简态(同排还有别的入口时自动收缩,2026-11-24)────────────────────────
|
|
188
|
+
侧栏底部那一排由宿主 footerActions 提供,是 display:flex / 不换行 —— 我们改不动它
|
|
189
|
+
(改了就是改宿主容器)。所以放不下时只能**自己变窄**:
|
|
190
|
+
收起图标、「余额」二字、时段标签,只留金额胶囊。
|
|
191
|
+
实测 ¥ 4.63 约 60px,加另一个插件入口(移动访问 ~90px)在 256px 里绰绰有余。
|
|
192
|
+
判定见 useFooterCompact():同排可见入口 > 1 就收缩,恢复成 1 个就展开。 */
|
|
193
|
+
/* ⚠️ 选择器不能带直接子级符号:sep / period-inline 是 value 胶囊的**子节点**,不是行的直接子级。
|
|
194
|
+
只写直接子级会一个都收不起来,金额胶囊仍然那么宽、照样挤。 */
|
|
195
|
+
.balance-footer--compact{flex:0 1 auto;gap:0;padding:0 2px}
|
|
196
|
+
.balance-footer--compact .balance-footer__icon,
|
|
197
|
+
.balance-footer--compact .balance-footer__label,
|
|
198
|
+
.balance-footer--compact .balance-footer__sep,
|
|
199
|
+
.balance-footer--compact .balance-footer__period-inline,
|
|
200
|
+
.balance-footer--compact .balance-footer__spacer{display:none}
|
|
201
|
+
|
|
181
202
|
.balance-footer__spacer{flex:1 1 0;min-width:0}
|
|
182
203
|
/* 右键刷新的「抹除」效果:白条从左划到右,白条**左边**的数字已经"显影"(新值),
|
|
183
204
|
右边仍被一层暗罩压着(旧值)。所以视觉上就是「只有被白条经过的地方才更新」。
|
|
@@ -204,7 +225,17 @@ window.__ModuleLoader__.load({
|
|
|
204
225
|
滚完再收(--roll-done 那条带 160ms 过渡)。宽度变化只发生在没有任何滚动的那一帧之后,
|
|
205
226
|
既不会横向互挤,也不会丢动画。
|
|
206
227
|
影子格保持 from 字符:这一格在滚动期间要维持原来的宽度。 */
|
|
207
|
-
|
|
228
|
+
/* ⚠️ 这条**不能带 animation:none**(2026-11-24 用户:「余额胶囊内如果出现小数的消失或显现时
|
|
229
|
+
动画不要消失」)。--gone 的语义是"这一格新值是空位"——余额 ≥1000 取整后小数位没了、
|
|
230
|
+
或者 999 → 1000 小数点滚走,都属于这种。它该做的事是:滚动期间保持旧字符的宽度、
|
|
231
|
+
照常走 balance-roll-out 把旧字符滚上去,滚完之后由 --roll-done 那条再把宽度收到 0。
|
|
232
|
+
原来这里写了 animation:none,等于把该格的滚动整个跳过 —— 同一个胶囊里其他格子还在滚,
|
|
233
|
+
它却"啪"一下没了,看着就是动画断了一半。
|
|
234
|
+
max-width:2ch 的职责只是**滚完之前不把邻格挤走**(宽度变化必须推迟到滚完之后,
|
|
235
|
+
否则邻格被横向推着走、新旧两串数字会叠住,这是 2026-10-31 的老坑)。
|
|
236
|
+
注意:下面 .balance-footer__timeline-meta-item--today 那条带 --today 前缀的 max-width:0
|
|
237
|
+
是「今日」金额专用的(为了让「今日」二字不要在 600ms 后二次滑动),跟余额胶囊无关,别混。 */
|
|
238
|
+
.balance-footer__dcell--gone{max-width:2ch}
|
|
208
239
|
/* ─── 滚动播完后的「定格态」(2026-10-31 方案 3 补充)─────────────────────────
|
|
209
240
|
为什么需要它:滚动动画不是 JS 触发的,而是 .balance-footer__dout / __din 上
|
|
210
241
|
常驻的 animation 声明。只要这两个节点还在、类名还在、animation 声明还在,
|
|
@@ -218,6 +249,7 @@ window.__ModuleLoader__.load({
|
|
|
218
249
|
(没有 transform = top:0),正好就是关键帧 100% 的位置。 */
|
|
219
250
|
.balance-footer__dcell--roll-done .balance-footer__dout{animation:none;display:none}
|
|
220
251
|
.balance-footer__dcell--roll-done .balance-footer__din{animation:none;transform:none}
|
|
252
|
+
|
|
221
253
|
/* 滚完之后才收宽度(滚动期间由上面的 --gone 保持原宽度)。
|
|
222
254
|
160ms 过渡:此时全串都已经静止,收窄只会让右边的格子整体平移,不存在两串数字互挤。 */
|
|
223
255
|
.balance-footer__dcell--roll-done.balance-footer__dcell--gone{animation:none;max-width:0;transition:max-width .16s linear}
|
|
@@ -504,6 +536,8 @@ window.__ModuleLoader__.load({
|
|
|
504
536
|
.balance-footer__label{flex:none;color:var(--dsw-alias-label-primary)}
|
|
505
537
|
.balance-footer__value{box-sizing:border-box;position:relative;z-index:0;isolation:isolate;display:inline-flex;align-items:center;justify-content:center;font-variant-numeric:tabular-nums;font-weight:500;font-synthesis:none;font-size:16px;line-height:1;white-space:nowrap;padding:7px 14px;border-radius:999px;corner-shape:round;margin-left:auto;margin-right:4px;text-decoration:none;cursor:pointer;transition:transform .15s var(--ds-ease-in-out,.2s),box-shadow .18s var(--ds-ease-in-out,.2s),color .42s var(--ds-ease-in-out,.2s),background .42s var(--ds-ease-in-out,.2s);flex:none;/* 宽度恒定 121px:靠「固定 px + 位数多就缩字号」两条一起实现。
|
|
506
538
|
⚠️ 开头的 box-sizing:border-box 是前提,不能省:min-width 默认算的是「内容盒」,
|
|
539
|
+
|
|
540
|
+
|
|
507
541
|
少了它 121px 会变成 121 + 左右 padding 28px = 149px 总宽,胶囊凭空胖一圈
|
|
508
542
|
(用户反馈「我的余额胶囊为什么这么长」,真实客户端实测正是 149px)。DSH 页面上
|
|
509
543
|
没有全局 border-box,刻度条 / 去充值 / FAB 都各自显式写了,只有这一处漏过。
|
|
@@ -517,6 +551,66 @@ window.__ModuleLoader__.load({
|
|
|
517
551
|
宽度照样跳。也别按「¥14.34 • 空闲」这种臆想格式去量 —— timeline 胶囊里只有
|
|
518
552
|
金额+货币码,先前按假格式算出 6.6em 恰好等于 0.00 CNY 的天然宽度,对任何值都不生效(踩过)。
|
|
519
553
|
justify-content:flex-end 让内容靠右,位数少时留白落在左边。 */min-width:112px}
|
|
554
|
+
/* ── 精简态 + timeline 形态:改成竖排,时段条挪到金额下方(2026-11-24 用户要求)──────
|
|
555
|
+
不收缩宽度的话 timeline 那块(今日 / 空闲 / 刻度条 竖排成一列)会把金额挤出去被裁
|
|
556
|
+
(用户截图:左边「今日 ¥0.7 / 空闲 剩」被裁掉一半)。
|
|
557
|
+
收缩宽度又会把「今日」「空闲」裁字,所以改成上下排:金额一行,那段时段信息整体落到下面。
|
|
558
|
+
不用拆 periodNode —— 它(.balance-footer__timeline)本来就是 meta + 刻度条 的竖排容器,
|
|
559
|
+
整块 order 到金额后面即可。行高由 --stacked 的 height:auto 自适应。
|
|
560
|
+
⚠️ 选择器末尾留一个空格(.balance-footer__timeline {):selftest 的 cssRule() 用
|
|
561
|
+
indexOf(sel + "{") 做子串匹配,紧贴会把它顶成第一条、抢掉基础规则,一串断言跟着红。 */
|
|
562
|
+
/* ── 精简竖排 = 原版的等比缩小(2026-11-24 用户:「就跟原版一样 等比例缩小」)──────
|
|
563
|
+
比例 0.8,每一项都按同一个系数走,形状和各元素之间的比例关系与原版一致:
|
|
564
|
+
胶囊 字号 16→13 内边距 7/14 → 6/11 最小宽 112→90 圆角 999px 不变
|
|
565
|
+
meta 行 字号 11→9 间距 6→5
|
|
566
|
+
时段条 高 15→12 宽 = 可用宽 × 0.8(跟着侧栏缩放,宽屏下不会拉成一根横线)
|
|
567
|
+
块间距 4→3
|
|
568
|
+
要整体再大/再小,只改这五组数、保持同一系数即可,别单独调某一项(那就不等比了)。 */
|
|
569
|
+
/* 两列:**左边**今日消耗 + 时段剩余(含刻度条),**右边**余额胶囊(用户 2026-11-24:
|
|
570
|
+
「左边显示今日消耗和时段剩余 右边显示余额胶囊」)。
|
|
571
|
+
所以回到 row,左侧 .balance-footer__timeline 吃满剩余宽(flex:1 1 auto + min-width:0),
|
|
572
|
+
胶囊固定按内容宽(flex:0 0 auto)贴在右端。
|
|
573
|
+
⚠️ .balance-footer__timeline 的 align-items 必须显式写 flex-start —— 基础规则是 center,
|
|
574
|
+
只在外层写 align-self 管不到它内部,meta 和刻度条会各自居中、跟左侧边缘错开。 */
|
|
575
|
+
.balance-footer--compact.balance-footer--stacked{flex:1 1 100%;flex-direction:row;align-items:center;justify-content:space-between;gap:6px;padding:2px 0}
|
|
576
|
+
/* 胶囊再收一档,把宽度让给左边(用户 2026-11-24:「胶囊再小一点点就行 现在就是时段表的 m
|
|
577
|
+
显示不全」——左侧 .balance-footer__timeline 是 flex:1 1 auto,右边胶囊越宽它就压得越窄,
|
|
578
|
+
「空闲 剩 11h40m」的尾巴就被裁掉了)。
|
|
579
|
+
90→76 / 6-11→5-9 / 13→12 大约省 18px,正好够那个 m。
|
|
580
|
+
⚠️ 别再往下压字号:12px 是这套 0.8 比例里的可见下限,再小数字会糊。 */
|
|
581
|
+
.balance-footer--compact.balance-footer--stacked .balance-footer__value {order:2;flex:0 0 auto;min-width:76px;margin-left:0;margin-right:0;padding:5px 9px;font-size:12px;align-self:center}
|
|
582
|
+
/* ⚠️ 位数降档必须跟着进来(2026-11-24「现在这个胶囊能显示到万单位的吗」)。
|
|
583
|
+
基础规则按整数位数给胶囊挂 --dense / --dense2 来收宽度,但那两条只有 1 个类,
|
|
584
|
+
压不过上面那条 5 个类的 compact 规则 —— 不补的话「位数多就缩字号」在这层整个失效,
|
|
585
|
+
金额一大就把胶囊撑宽、反过来挤压左侧时段文字。补上后每一档都比基础版小 0.5px。 */
|
|
586
|
+
.balance-footer--compact.balance-footer--stacked .balance-footer__value--dense {font-size:11.5px}
|
|
587
|
+
.balance-footer--compact.balance-footer--stacked .balance-footer__value--dense2 {font-size:10.5px}/* ⚠️ 这里必须是**居中**(2026-11-24 用户第二轮定案:「今日的移动确实需要滑动效果,
|
|
588
|
+
因为今日消耗的宽度 但刚刚是bug 有异常的滑动」)。
|
|
589
|
+
滑动本身的语义没错:今日金额从 ¥2.07 变 ¥123.45 时整块居中重排,「今日」二字要被平滑推开,
|
|
590
|
+
靠的是下面 usePrePaintEffect 那 460ms 的 translateX。所以对齐必须是 center ——
|
|
591
|
+
改成 flex-start 之后金额再怎么变「今日」都钉死在缩进点,滑动就没了。
|
|
592
|
+
上一版之所以出现"异常滑动",根因是 --today 被改成了 flex:0 1 auto(和「空闲 剩」同一行):
|
|
593
|
+
那样 meta 宽度会跟着「空闲 剩 11h33m」的字数一起变,居中重排时「今日」的 left 也跟着漂,
|
|
594
|
+
而 effect 只在 todayText 变化时才跑、prev 记的位置早已过期 → 下次一跑 shift 巨大 → 猛滑一下。
|
|
595
|
+
现在恢复 --today 独占一整行(flex:0 0 100%),它的 left 只由「自己这一行居中 + 金额宽度」
|
|
596
|
+
决定,「空闲 剩」的字数变化只影响下一行、推不动它 —— 真滑动保留,假滑动消失。 */
|
|
597
|
+
.balance-footer--compact.balance-footer--stacked .balance-footer__timeline {order:1;flex:1 1 auto;min-width:0;align-self:center;align-items:center;gap:3px}
|
|
598
|
+
/* 「今日」独占一整行、内部居中 —— 这是滑动效果的前提(left 只由自己的金额宽度决定)。
|
|
599
|
+
曾经收成 flex:0 1 auto 让它和「空闲 剩」同行,结果 meta 宽度跟着「空闲」的字数变,
|
|
600
|
+
居中重排把「今日」也带着漂,才出现"不该滑的时候滑"。别再收。 */
|
|
601
|
+
.balance-footer--compact.balance-footer--stacked .balance-footer__timeline-meta-item--today {flex:0 0 100%;justify-content:center;text-align:center}
|
|
602
|
+
.balance-footer--compact.balance-footer--stacked .balance-footer__timeline-meta {
|
|
603
|
+
justify-content:center;
|
|
604
|
+
/* 两行之间用 row-gap,别再用一条 gap 同时管两个方向:
|
|
605
|
+
写 gap:5px 时 row-gap 也被抬到 5px,比下面「空闲 → 色带」那 3px 还松,
|
|
606
|
+
9px 字号下等于半个行高,看着就是一块空档(2026-11-24 用户对着截图问
|
|
607
|
+
「是不是空隙有点大了」)。实测「今日↔空闲」5.00px、「空闲↔色带」3.00px。
|
|
608
|
+
现在行距对齐成 3px,和色带那一档一致。 */
|
|
609
|
+
column-gap:5px;
|
|
610
|
+
row-gap:3px;
|
|
611
|
+
font-size:9px;
|
|
612
|
+
text-align:center}
|
|
613
|
+
.balance-footer--compact.balance-footer--stacked .balance-footer__timeline-track {height:12px;width:100%;max-width:110px;margin-left:auto;margin-right:auto}
|
|
520
614
|
/* 余额位数多时降档,配合上面的固定宽度,让长金额也收在 121px 内 */
|
|
521
615
|
.balance-footer__value--dense{font-size:13px}
|
|
522
616
|
.balance-footer__value--dense2{font-size:11.5px}
|
|
@@ -544,7 +638,15 @@ window.__ModuleLoader__.load({
|
|
|
544
638
|
.balance-footer__value--low:hover{background:rgba(217,119,6,.22)}
|
|
545
639
|
/* 旧版布局:胶囊靠右 —— 这是备份 v1.3.1 里的原始写法(margin-left:auto)。
|
|
546
640
|
不能放到基础规则上,新版 timeline 用 margin:0 auto 居中,会和它打架。 */
|
|
547
|
-
|
|
641
|
+
/* 旧版样式的胶囊比旁边「移动访问」的文字基线高 1~2px(用户 2026-11-24 两次反馈「有点偏上」
|
|
642
|
+
→「还是有一点」→「怎么感觉还是偏上」)。那个按钮是 dsh-mobile 的,尺寸与内边距不归我们管,只能在自己的行上补。
|
|
643
|
+
⚠️ 这是按截图目测的补偿值,不是布局修正:真正的垂直基准由 footerActions 的 align-items:center
|
|
644
|
+
决定,两边都居中了,差的是「胶囊有背景块、按钮只有文字」带来的视觉基线错觉。 */
|
|
645
|
+
.balance-footer--classic{top:4px}
|
|
646
|
+
/* 胶囊不要贴死右端,往左挪一点(用户 2026-11-24:「能不能往左边的中间一点」)。
|
|
647
|
+
margin-left:auto 负责把它从「余额」二字后面推到右边,margin-right 再从右端让出一段,
|
|
648
|
+
落点就在右侧偏左的位置。这个数值就是让出的距离,想再靠左就加大、想贴回去就写 0。 */
|
|
649
|
+
.balance-footer--classic .balance-footer__value{margin-left:auto;margin-right:14px}
|
|
548
650
|
.balance-footer__value--healthy{color:var(--dsw-alias-state-success-primary);background:rgba(34,197,94,.15)}
|
|
549
651
|
/* 余额耗尽时只把金额胶囊换成充值按钮(2026-11-13 用户:「余额用完 只替换余额处为充值按钮」)。
|
|
550
652
|
盒子完全沿用 .balance-footer__value(min-width / padding / 圆角 / 居中),只换配色与文字,
|
|
@@ -1035,6 +1137,27 @@ window.__ModuleLoader__.load({
|
|
|
1035
1137
|
dghost + dout + din 三件套的滚格子),只要它们量出来差 1px,卡片就长高 1px、上移 1px。
|
|
1036
1138
|
钉死这一行之后,里面换成什么都不会影响卡片总高(多出来的部分被行高裁掉/居中吸收)。 */
|
|
1037
1139
|
.balance-float__value-row{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-width:0;height:1lh;transition:opacity .2s linear}
|
|
1140
|
+
/* 慢加载提示 —— **独立的一颗小气泡**,贴在主卡片正上方(2026-11-24 用户:
|
|
1141
|
+
「可以单独显示一个小浮窗」)。
|
|
1142
|
+
为什么不塞进卡片:卡片是 bottom 钉在输入卡片底边上的,内部多一行会让它整体长高、
|
|
1143
|
+
上面两行跟着上跳;而且那是"内容变多",不是"另给一个提示"。
|
|
1144
|
+
放在正上方而不是下方 —— 下方就是输入框,压上去比往上飘更难受。
|
|
1145
|
+
定位靠 .balance-float 自己(position:fixed 即包含块)的 bottom:100% + 6px,
|
|
1146
|
+
完全跟随主卡片的移动,不需要再算一遍坐标。
|
|
1147
|
+
⚠️ 外层铺满卡片宽度只为了居中,真正的胶囊在内层 <b> 上(宽度按文字自适应,
|
|
1148
|
+
提示才 73.5px,比卡片窄,看着才像"另一个小浮窗")。
|
|
1149
|
+
⚠️ 绝不用 transform 做居中/位移:小字号走 GPU 纹理会发虚(2026-10-31 的教训)。 */
|
|
1150
|
+
/* 进出场:淡入 + 从下往上浮 5px(消失时反向沉下去)。
|
|
1151
|
+
2026-11-24 用户:「提示消失没有动画了 并且添加消失和显现来明示用户」。
|
|
1152
|
+
⚠️ 消失本来是有过渡的,坏在文字被一起清空了 —— opacity 刚开始降、字已经没了,
|
|
1153
|
+
看着就是硬切。所以文字必须**常驻**,只靠这个类开关透明度。
|
|
1154
|
+
⚠️ 静止态刻意写 transform:none 而不是 translateY(0):translateY(0) 也算 transform,
|
|
1155
|
+
会让这块独立成合成层,10.5px 中文在 GPU 纹理里会发虚(2026-10-31 的老坑)。
|
|
1156
|
+
none ↔ translateY 之间浏览器按 identity 插值,过渡照样成立。
|
|
1157
|
+
⚠️ 水平居中靠 flex(justify-content:center),不许用 translateX 硬拽。 */
|
|
1158
|
+
.balance-float__slow-tip{position:absolute;bottom:100%;left:0;right:0;margin-bottom:6px;display:flex;justify-content:center;opacity:0;transform:translateY(5px);pointer-events:none;transition:opacity .2s ease,transform .24s cubic-bezier(.22,.72,.28,1)}
|
|
1159
|
+
.balance-float--slow .balance-float__slow-tip{opacity:1;transform:none}
|
|
1160
|
+
.balance-float__slow-tip>b{display:block;padding:3px 9px;border-radius:999px;font-size:10.5px;line-height:13px;font-weight:400;color:var(--dsw-alias-label-tertiary);white-space:nowrap;background:var(--dsw-specific-sidebar-fill,rgba(27,27,28,.92));box-shadow:0 4px 12px rgba(0,0,0,.34),inset 0 0 0 1px rgba(255,255,255,.05)}
|
|
1038
1161
|
/* 金额那一格:预留 **9ch** 兜住等待态那颗加载胶囊(2026-11-02 用户:「是不是可以让加载胶囊长一点了」)。
|
|
1039
1162
|
实测 14px 字下 1ch ≈ 8.21px → 6.4ch 只有 52.5px,在 101px 宽的卡片里显得又短又胖;
|
|
1040
1163
|
9ch ≈ 73.9px,正好和上面那行「本会话消耗估算」(77px)等宽对齐 ——
|
|
@@ -1374,7 +1497,26 @@ window.__ModuleLoader__.load({
|
|
|
1374
1497
|
.balance-stats-close{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:0;border-radius:8px;color:var(--dsw-alias-label-secondary);background:transparent;font-size:22px;line-height:1;cursor:pointer}
|
|
1375
1498
|
.balance-stats-close:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}
|
|
1376
1499
|
.balance-stats-error{padding:12px;border-radius:10px;color:var(--dsw-alias-state-error-primary,#e5484d);background:rgba(229,72,77,.10)}
|
|
1377
|
-
|
|
1500
|
+
/* 加载态:一条**实时推进**的进度条 + 已用时(2026-11-24 用户:「加载时添加一个实时的加载条」)。
|
|
1501
|
+
统计面板打开时要扫上百个会话的 zstd,几秒内只有一行「正在汇总会话记录…」,没有任何
|
|
1502
|
+
"还在动"的证据 —— 用户分不清是卡住还是真在算。这里两层反馈:
|
|
1503
|
+
① 轨道上一条**不确定态**的跑马灯(服务端一次请求返回、拿不到百分比,所以不能用真实进度);
|
|
1504
|
+
用两段亮块交错推进,比单块更有"在持续干活"的观感。
|
|
1505
|
+
② 下方按秒累加的耗时数字,只要它还在涨,就说明这一拍没死。
|
|
1506
|
+
动画跟其它动效一样**不受 prefers-reduced-motion 影响**(它是可读状态而不是装饰),
|
|
1507
|
+
但幅度压得很小(横向平移 + 透明度),不会有明显闪烁。 */
|
|
1508
|
+
/* 圆形转圈(2026-11-24 用户:「说错了 是进度条 可以用圆形的」)。
|
|
1509
|
+
底环是暗的完整圆,上面一段亮弧自己转,同时弧长从 20 → 62 → 20 呼吸,
|
|
1510
|
+
看起来是"一圈在跑"而不是"一个缺口在转"。
|
|
1511
|
+
r = 13 ⇒ 周长 2πr ≈ 81.68,stroke-dasharray 用 20 62 正好把整圈铺满。 */
|
|
1512
|
+
.balance-stats-progress{display:flex;flex-direction:column;align-items:center;gap:12px;padding:40px 12px 44px;color:var(--dsw-alias-label-secondary)}
|
|
1513
|
+
.balance-stats-spinner{display:block;width:30px;height:30px;animation:balance-stats-spin .95s linear infinite}
|
|
1514
|
+
.balance-stats-spinner__track{fill:none;stroke:var(--dsw-alias-border-l2,rgba(127,127,127,.22));stroke-width:2.5}
|
|
1515
|
+
.balance-stats-spinner__arc{fill:none;stroke:#4d6bfe;stroke-width:2.5;stroke-linecap:round;animation:balance-stats-arc 1.9s ease-in-out infinite}
|
|
1516
|
+
@keyframes balance-stats-spin{to{transform:rotate(360deg)}}
|
|
1517
|
+
@keyframes balance-stats-arc{0%{stroke-dasharray:20 62}50%{stroke-dasharray:62 20}100%{stroke-dasharray:20 62}}
|
|
1518
|
+
.balance-stats-progress__text{font-size:12px;line-height:1;font-variant-numeric:tabular-nums}
|
|
1519
|
+
.balance-stats-progress__elapsed{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));font-size:11px;line-height:1}
|
|
1378
1520
|
.balance-stats-top{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;margin-bottom:8px}
|
|
1379
1521
|
.balance-stats-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-bottom:8px}
|
|
1380
1522
|
/* 分组数为奇数时(「按模型」「时段拆分」条件渲染可能缺席),最后一个横跨整行,避免半空行 */
|
|
@@ -1428,13 +1570,21 @@ window.__ModuleLoader__.load({
|
|
|
1428
1570
|
/* ── 展开态底部一行:[设置齿轮][余额胶囊],余额在设置右边 ──
|
|
1429
1571
|
全部使用稳定锚点,不依赖 CSS Modules hash 类名(DSH 升级后仍有效):
|
|
1430
1572
|
- wide 态特征:底部存在 .balance-footer / .balance-topup(收起态渲染 position:fixed 的 .balance-fab,不影响)
|
|
1431
|
-
- footArea 改 row
|
|
1432
|
-
- [data-slot] = slot 出口契约(display:contents)
|
|
1573
|
+
- footArea 改 row(宿主默认是 column,上下两行);footerActions 按内容宽靠右排列
|
|
1574
|
+
- [data-slot] = slot 出口契约(display:contents)
|
|
1575
|
+
⚠️ 2026-11-24(issue #3):**绝不许再改宿主自己的控件**。
|
|
1576
|
+
这里只改 footArea 的排列方向这一条容器属性 —— 不改 sidebar.settings 的 order、
|
|
1577
|
+
尺寸、圆角,也不隐藏它的文字。老实现那三条(order:-1 / 32×32 圆形 / span 隐藏)
|
|
1578
|
+
对**所有**装了本插件的用户生效,是明确的反模式;入口排不下的问题改由
|
|
1579
|
+
排不下的问题交给 footerActions 的 flex-wrap + .balance-footer 的 flex:1 1 100%:
|
|
1580
|
+
自己占满一整行,别的入口被挤到下一行,两边都不裁字。 */
|
|
1433
1581
|
:has(> :has(> [data-slot="sidebar.footer.action"])):has(.balance-footer, .balance-topup){flex-direction:row;align-items:center;gap:4px}
|
|
1434
|
-
:has(> :has(> [data-slot="sidebar.footer.action"])):has(.balance-footer, .balance-topup) > :has(> [data-slot="sidebar.footer.action"]){flex:1 1
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1582
|
+
:has(> :has(> [data-slot="sidebar.footer.action"])):has(.balance-footer, .balance-topup) > :has(> [data-slot="sidebar.footer.action"]){order:1;flex:1 1 auto;min-width:0;display:flex;flex-direction:row;flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:4px}
|
|
1583
|
+
/* settingsArea 宿主自带 flex:none + width:100%(那是 column 布局下的写法)。footArea 改成 row 之后
|
|
1584
|
+
它会独占整行、把 footerActions 挤成 0,所以这里必须把它收成「按内容宽」。
|
|
1585
|
+
⚠️ 只动**容器**的伸缩与宽度,按钮的尺寸 / 圆角 / 是否显示文字一律不碰(issue #3 的核心诉求)。
|
|
1586
|
+
顺序由上面 footerActions 的 order:1 解决:设置区默认 order 0 排在前,余额落在它的右边。 */
|
|
1587
|
+
:has(> :has(> [data-slot="sidebar.footer.action"])):has(.balance-footer, .balance-topup) > :has(> [data-slot="sidebar.settings"]){flex:0 0 auto;width:auto;min-width:0}
|
|
1438
1588
|
/* ── 插件配置卡片:DSH「插件」页 → balance-dsh 详情页(slot plugins.bundle.config) ──
|
|
1439
1589
|
用插件自己的稳定类名(不依赖 DSH 的 CSS Modules hash);主题变量一律带回退值,
|
|
1440
1590
|
变量缺失时仍然可读,不会变成透明文字。开关/按钮的真圆角要显式 corner-shape:round,
|
|
@@ -2382,6 +2532,14 @@ let floatRemeasureHook = null;
|
|
|
2382
2532
|
* ⚠️ 只按「会话切换」起算,流式刷新绝不重播(那样很割裂,2026-10-31 定过)。
|
|
2383
2533
|
* 300ms 是下限不是固定等待:请求更慢时雾跟着更久,跟以前一样。 */
|
|
2384
2534
|
const COST_FOG_FLOOR_MS = 420;
|
|
2535
|
+
/** 「加载超过 1 秒就给个说法」(2026-11-24 用户:「当对话估算加载超过1秒 就在下方显示
|
|
2536
|
+
* 提示对话历史过长需要时间 给用户」)。大会话冷启动要解压几十 MB 的 zstd,
|
|
2537
|
+
* 光看那团雾分不出「还在算」和「卡住了」。1 秒以下不打扰 —— 正常会话都在这个区间。 */
|
|
2538
|
+
const COST_SLOW_HINT_MS = 1000;
|
|
2539
|
+
/** 气泡一旦亮起,**至少留这么久**才允许收(2026-11-24 用户:「有的对话可能刚好1秒多一点
|
|
2540
|
+
* 导致提示就闪了一下 所以添加提示显示保底1秒」)。1.05 秒的加载会让气泡只存在 50ms,
|
|
2541
|
+
* 加上 200ms 的淡出还没走完就没了,看着像闪了一下故障。 */
|
|
2542
|
+
const COST_SLOW_HINT_MIN_MS = 1000;
|
|
2385
2543
|
// 滚动播完后给 roll 打 done 标记(2026-10-31 方案 3 补充)。
|
|
2386
2544
|
// 为什么必须做:`dout`/`din` 上的 animation 是常驻声明,只要它还在,
|
|
2387
2545
|
// 元素经历 display:none → 有盒子时浏览器会取消并重建动画,从 0 秒重播。
|
|
@@ -2664,7 +2822,16 @@ const CN_CALENDAR_SOURCES = [
|
|
|
2664
2822
|
// 跨多版升上来的会看到中间所有新功能,只升一版的老功能一条都不亮。
|
|
2665
2823
|
if (recV !== "" && recV === intro) {
|
|
2666
2824
|
const baseline = String(fallbackFrom || "");
|
|
2667
|
-
|
|
2825
|
+
// ⚠️ `t` 是「这一项被记下来时的升级时刻」,不许伪造;但它可能来自**上一次**升级 ——
|
|
2826
|
+
// 本版新加的功能在用户还没升级时就被 markNewTagsEntered 贴上了旧 t
|
|
2827
|
+
// (锚点用的是当时的 newTagSince),于是窗口一天都没走就先判了过期。
|
|
2828
|
+
// 2026-11-26 用户报「我这边怎么没有 newtag 标签」就是这个:aggCacheMax 的
|
|
2829
|
+
// t = 11/24,而本次升级是 11/26,差 45.5 小时 → within() 恒 false。
|
|
2830
|
+
// 窗口起点取两者较晚的那个:既不动 t,也不会让老功能重新计时
|
|
2831
|
+
// (reallyFresh 仍然卡着 compareVersion(intro, baseline) > 0)。
|
|
2832
|
+
const recSince = Number.isFinite(recT) && recT > 0 ? recT : 0;
|
|
2833
|
+
const upSince = Number(fallbackSince) > 0 ? Number(fallbackSince) : 0;
|
|
2834
|
+
const since = Math.max(recSince, upSince);
|
|
2668
2835
|
const reallyFresh = baseline === "" || compareVersion(intro, baseline) > 0 || isCurrentIntro(since);
|
|
2669
2836
|
const entered = rec !== null && rec.d === true;
|
|
2670
2837
|
return {
|
|
@@ -2710,6 +2877,7 @@ const CN_CALENDAR_SOURCES = [
|
|
|
2710
2877
|
["todaySessionLimit", "2.1.0"], // 今日消耗扫描上限:多开对话 / 多跑子代理时把今日汇总算全
|
|
2711
2878
|
["showUsagePill", "2.1.6"], // 2.1.6:消耗行搬成对话界面右下角小浮窗(两行:本会话估算 / 金额)
|
|
2712
2879
|
["diag", "2.2.6"], // 2.2.6:设置页「数据诊断」—— 一键出结论 + 复制 + 查出问题给「修复」
|
|
2880
|
+
["aggCacheMax", "2.3.5"], // 2.3.5:聚合缓存条数上限(原来写死 320,会话多的人装不下)
|
|
2713
2881
|
]);
|
|
2714
2882
|
|
|
2715
2883
|
/** NEW_TAGS 的 key → 设置项中文名。横幅要写「本版新增:消耗行加载动效」,
|
|
@@ -2722,6 +2890,7 @@ const CN_CALENDAR_SOURCES = [
|
|
|
2722
2890
|
todaySessionLimit: "今日消耗扫描上限",
|
|
2723
2891
|
showUsagePill: "对话右下角消耗浮窗",
|
|
2724
2892
|
diag: "数据诊断",
|
|
2893
|
+
aggCacheMax: "聚合缓存条数上限",
|
|
2725
2894
|
};
|
|
2726
2895
|
|
|
2727
2896
|
/** 模板串里取一张表的三个 NEW 相关字段,缺省一律安全兜底。 */
|
|
@@ -2883,6 +3052,31 @@ const CN_CALENDAR_SOURCES = [
|
|
|
2883
3052
|
if (intPart.length >= 3) return " balance-footer__value--dense";
|
|
2884
3053
|
return "";
|
|
2885
3054
|
}
|
|
3055
|
+
// 余额的**显示**文本(2026-11-24 用户:「当余额超过 1000 时 就不要显示小数了」)。
|
|
3056
|
+
// ≥1000 取整、<1000 保持服务端给的两们小数。只影响显示:计费、阈值判断、
|
|
3057
|
+
// 低余额告警一律仍用原始 total_balance,所以 999.99 → 1000 那一刻不会因为四舍五入
|
|
3058
|
+
// 反过来影响「是否低于阈值」的判定。
|
|
3059
|
+
// 顺便让 `amountDensity` 吃的是取整后的串 —— 位数变少,降档也跟着更准。
|
|
3060
|
+
function formatTotalDisplay(raw) {
|
|
3061
|
+
const text = String(raw ?? "");
|
|
3062
|
+
const n = Number.parseFloat(text);
|
|
3063
|
+
if (Number.isFinite(n) && Math.abs(n) >= 1000) return String(Math.round(n));
|
|
3064
|
+
return text;
|
|
3065
|
+
}
|
|
3066
|
+
// ⚠️⚠️ **临时预览值**(2026-11-24 用户「帮我给余额先暂时改成 99999 给我看一下」)。
|
|
3067
|
+
// 测完把 return 那句改回 `return null;`。返回值是 null 时一切走真实余额,零影响。
|
|
3068
|
+
// 提成模块级函数是因为「滚动 effect」也要看到它:预览值从 3 位跳到 5 位时,
|
|
3069
|
+
// 逐位滚动会把旧值和新值叠在同一格上(buildRollCells 已按位数补齐,但动画没跑完时两串都在),
|
|
3070
|
+
// 屏幕上就是 `99999.00CNY` 和 `12.98CNY` 糊成一坨 —— 预览只为了量宽度,不要动画。
|
|
3071
|
+
function balancePreviewValue() {
|
|
3072
|
+
try {
|
|
3073
|
+
const q = new URLSearchParams(window.location.search).get("mock");
|
|
3074
|
+
if (q !== null && /^\d+(?:\.\d+)?$/.test(q)) return Number(q).toFixed(2);
|
|
3075
|
+
} catch {
|
|
3076
|
+
/* 拿不到 location 就落到下面的默认值 */
|
|
3077
|
+
}
|
|
3078
|
+
return null;
|
|
3079
|
+
}
|
|
2886
3080
|
// ─── 时段刻度条:色带固定 = 一整天,指针随时刻从左走到右 ────────────────
|
|
2887
3081
|
// 轨道铺满当天 00:00 → 次日 00:00 的时段色带(不滚动),指针位置 = 现在时刻在当天的比例。
|
|
2888
3082
|
// 指针每秒前进一次(pointerNow 独立节拍),CSS transition:left 1s linear 补成连续滑动;
|
|
@@ -2996,6 +3190,7 @@ const CN_CALENDAR_SOURCES = [
|
|
|
2996
3190
|
// 今日消耗单独一个上限,默认比统计宽(服务端 TODAY_MAX_SESSIONS 同值)
|
|
2997
3191
|
todaySessionLimit: 200,
|
|
2998
3192
|
statsCacheSec: 300,
|
|
3193
|
+
aggCacheMax: 320,
|
|
2999
3194
|
peakWindowsText: "9-12, 14-18",
|
|
3000
3195
|
peakMultiplier: 2,
|
|
3001
3196
|
priceFlash: null,
|
|
@@ -4000,12 +4195,30 @@ const CN_CALENDAR_SOURCES = [
|
|
|
4000
4195
|
function UsageStatsPanel({ onClose, panelRef, closing }) {
|
|
4001
4196
|
const liveBalance = useBalance();
|
|
4002
4197
|
const [heatmapTooltip, setHeatmapTooltip] = react.useState(null);
|
|
4198
|
+
// 加载进度条的「已用 X.Xs」—— 服务端一次返回、给不出百分比,但一个还在涨的数字
|
|
4199
|
+
// 就是"它没卡住"的直接证据(用户 2026-11-24:「加载时添加一个实时的加载条」)。
|
|
4200
|
+
const [statsElapsedMs, setStatsElapsedMs] = react.useState(0);
|
|
4003
4201
|
const [state, setState] = react.useState(() => {
|
|
4004
4202
|
const cached = getCachedUsageStats();
|
|
4005
4203
|
return cached
|
|
4006
4204
|
? { loading: false, data: cached, error: "" }
|
|
4007
4205
|
: { loading: true, data: null, error: "" };
|
|
4008
4206
|
});
|
|
4207
|
+
const statsLoading = state.loading;
|
|
4208
|
+
react.useEffect(() => {
|
|
4209
|
+
if (!statsLoading) return undefined;
|
|
4210
|
+
const startedAt = Date.now();
|
|
4211
|
+
setStatsElapsedMs(0);
|
|
4212
|
+
// 100ms 一拍:数字"在跳"的感觉比每秒一次明显,代价可忽略(只是 setState 一个数值)。
|
|
4213
|
+
// 用 setTimeout 递归而不是 rAF —— DSH 渲染进程里 rAF 会被窗口可见性挂起。
|
|
4214
|
+
let timer = 0;
|
|
4215
|
+
const tick = () => {
|
|
4216
|
+
setStatsElapsedMs(Date.now() - startedAt);
|
|
4217
|
+
timer = setTimeout(tick, 100);
|
|
4218
|
+
};
|
|
4219
|
+
timer = setTimeout(tick, 100);
|
|
4220
|
+
return () => clearTimeout(timer);
|
|
4221
|
+
}, [statsLoading]);
|
|
4009
4222
|
react.useEffect(() => {
|
|
4010
4223
|
let disposed = false;
|
|
4011
4224
|
fetchUsageStats().then(
|
|
@@ -4139,7 +4352,25 @@ const CN_CALENDAR_SOURCES = [
|
|
|
4139
4352
|
const rangeDays = Number(stats && stats.rangeDays) || 90;
|
|
4140
4353
|
|
|
4141
4354
|
const body = state.loading
|
|
4142
|
-
? jsx.
|
|
4355
|
+
? jsx.jsxs("div", {
|
|
4356
|
+
className: "balance-stats-progress",
|
|
4357
|
+
children: [
|
|
4358
|
+
// 圆形转圈:底环 + 亮弧,亮弧自己转、弧长呼吸(见 CSS 那两条 keyframes)
|
|
4359
|
+
jsx.jsx("svg", {
|
|
4360
|
+
className: "balance-stats-spinner",
|
|
4361
|
+
viewBox: "0 0 32 32",
|
|
4362
|
+
"aria-hidden": "true",
|
|
4363
|
+
children: [
|
|
4364
|
+
jsx.jsx("circle", { className: "balance-stats-spinner__track", cx: 16, cy: 16, r: 13 }),
|
|
4365
|
+
jsx.jsx("circle", { className: "balance-stats-spinner__arc", cx: 16, cy: 16, r: 13 }),
|
|
4366
|
+
],
|
|
4367
|
+
}),
|
|
4368
|
+
jsx.jsx("div", { className: "balance-stats-progress__text", children: "正在汇总会话记录…" }),
|
|
4369
|
+
statsElapsedMs > 0
|
|
4370
|
+
? jsx.jsx("div", { className: "balance-stats-progress__elapsed", children: "已用 " + (statsElapsedMs / 1000).toFixed(1) + "s" })
|
|
4371
|
+
: null,
|
|
4372
|
+
],
|
|
4373
|
+
})
|
|
4143
4374
|
: state.error
|
|
4144
4375
|
? jsx.jsx("div", { className: "balance-stats-error", children: state.error })
|
|
4145
4376
|
: jsx.jsxs(jsx.Fragment, {
|
|
@@ -4570,7 +4801,87 @@ function makeTodayFlowStyle() {
|
|
|
4570
4801
|
};
|
|
4571
4802
|
}
|
|
4572
4803
|
|
|
4804
|
+
// ── 侧栏底部同排入口数(2026-11-24)────────────────────────────────────────
|
|
4805
|
+
//
|
|
4806
|
+
// 宿主把那一条放在 footerActions 里(display:flex、row、不换行)。我们只读、不改它:
|
|
4807
|
+
// 数一下同一排有几个可见入口,超过 1 个就把自己收缩成「只留金额」的精简态。
|
|
4808
|
+
//
|
|
4809
|
+
// ⚠️ 测量纪律(AGENTS 记过一整版的坑):
|
|
4810
|
+
// [data-slot="sidebar.footer.action"] 是 SlotOutlet 的出口容器,display:contents
|
|
4811
|
+
// —— 不生成盒子,getBoundingClientRect() 全 0。所以数的是它的**子元素**(真元素),
|
|
4812
|
+
// 而且每个注册项各有一个 outlet,必须遍历 row 下**所有** outlet 才数得全
|
|
4813
|
+
// (只 querySelector 一个会漏掉 dsh-mobile 的「移动访问」)。
|
|
4814
|
+
function measureFooterCrowd() {
|
|
4815
|
+
try {
|
|
4816
|
+
if (typeof document === "undefined") return 1;
|
|
4817
|
+
const outlet = document.querySelector('[data-slot="sidebar.footer.action"]');
|
|
4818
|
+
const row = outlet?.parentElement ?? null;
|
|
4819
|
+
if (row === null) return 1;
|
|
4820
|
+
const shown = (n) => n !== null && n !== void 0
|
|
4821
|
+
&& typeof n.getClientRects === "function" && n.getClientRects().length > 0;
|
|
4822
|
+
let count = 0;
|
|
4823
|
+
for (const node of Array.from(row.children)) {
|
|
4824
|
+
if (node?.getAttribute?.("data-slot") === "sidebar.footer.action") {
|
|
4825
|
+
for (const inner of Array.from(node.children)) if (shown(inner)) count += 1;
|
|
4826
|
+
} else if (shown(node)) {
|
|
4827
|
+
count += 1;
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
4830
|
+
return count;
|
|
4831
|
+
} catch {
|
|
4832
|
+
return 1;
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4835
|
+
/** 同排是否还有别的入口(有就收缩成只留金额)。 */
|
|
4836
|
+
function useFooterCompact() {
|
|
4837
|
+
const [crowded, setCrowded] = react.useState(false);
|
|
4838
|
+
react.useEffect(() => {
|
|
4839
|
+
let disposed = false;
|
|
4840
|
+
const sync = () => {
|
|
4841
|
+
if (disposed) return;
|
|
4842
|
+
const next = measureFooterCrowd() > 1;
|
|
4843
|
+
setCrowded((prev) => (prev === next ? prev : next));
|
|
4844
|
+
};
|
|
4845
|
+
sync();
|
|
4846
|
+
const onResize = () => sync();
|
|
4847
|
+
if (typeof window !== "undefined") window.addEventListener("resize", onResize);
|
|
4848
|
+
let ro = null;
|
|
4849
|
+
let mo = null;
|
|
4850
|
+
try {
|
|
4851
|
+
const outlet = document.querySelector('[data-slot="sidebar.footer.action"]');
|
|
4852
|
+
const row = outlet?.parentElement ?? null;
|
|
4853
|
+
const footArea = row?.parentElement ?? null;
|
|
4854
|
+
if (typeof ResizeObserver === "function") {
|
|
4855
|
+
ro = new ResizeObserver(sync);
|
|
4856
|
+
if (footArea !== null) ro.observe(footArea);
|
|
4857
|
+
if (row !== null) ro.observe(row);
|
|
4858
|
+
}
|
|
4859
|
+
// 别的插件挂载/卸载发生在**别的** outlet 上,所以要盯整棵子树
|
|
4860
|
+
if (typeof MutationObserver === "function" && row !== null) {
|
|
4861
|
+
mo = new MutationObserver(sync);
|
|
4862
|
+
mo.observe(row, { childList: true, subtree: true });
|
|
4863
|
+
}
|
|
4864
|
+
} catch {
|
|
4865
|
+
// 观察器不可用就只靠 resize
|
|
4866
|
+
}
|
|
4867
|
+
const t1 = setTimeout(sync, 60);
|
|
4868
|
+
const t2 = setTimeout(sync, 260);
|
|
4869
|
+
return () => {
|
|
4870
|
+
disposed = true;
|
|
4871
|
+
clearTimeout(t1);
|
|
4872
|
+
clearTimeout(t2);
|
|
4873
|
+
if (typeof window !== "undefined") window.removeEventListener("resize", onResize);
|
|
4874
|
+
if (ro !== null) ro.disconnect();
|
|
4875
|
+
if (mo !== null) mo.disconnect();
|
|
4876
|
+
};
|
|
4877
|
+
}, []);
|
|
4878
|
+
return crowded;
|
|
4879
|
+
}
|
|
4880
|
+
|
|
4573
4881
|
function BalanceFooter({ wide }) {
|
|
4882
|
+
// 同排还有别的入口时收缩成「只留金额」(见 useFooterCompact 那段注释)
|
|
4883
|
+
const crowded = useFooterCompact();
|
|
4884
|
+
const crowdClass = crowded ? ' balance-footer--compact' : '';
|
|
4574
4885
|
const state = useBalance();
|
|
4575
4886
|
const settings = useSettings();
|
|
4576
4887
|
const today = useToday();
|
|
@@ -4828,6 +5139,15 @@ function makeTodayFlowStyle() {
|
|
|
4828
5139
|
// 「手动更新时擦除样式的 然后滚动就不要了 分清楚了」)。
|
|
4829
5140
|
// 这条判据精确到请求,不再有"时间窗猜错"的可能。
|
|
4830
5141
|
const manual = state.manual === true;
|
|
5142
|
+
// ⚠️ 预览值生效时**一律不滚**,直接把 roll 定成静态(2026-11-24)。
|
|
5143
|
+
// 预览是从真实余额一步跳到 99999.00,整数位从 2 位变 5 位:buildRollCells 会把旧值
|
|
5144
|
+
// 左侧补空位对齐,可动画只有 420ms,两串数字在中途同框;预览页刷新频率高、动画还没走完
|
|
5145
|
+
// 就重渲染,屏幕上就成了 `99999.00CNY` 压着 `12.98CNY` 的乱码。
|
|
5146
|
+
// 预览本来只为量宽度,不要动画。
|
|
5147
|
+
if (balancePreviewValue() !== null) {
|
|
5148
|
+
setRoll(null);
|
|
5149
|
+
return;
|
|
5150
|
+
}
|
|
4831
5151
|
if (rollText === null || prev === null || prev === rollText) return;
|
|
4832
5152
|
if (manual) {
|
|
4833
5153
|
// 手动刷新期间不滚(擦除已经给足反馈),但**必须把 roll 同步到当前值**。
|
|
@@ -4935,62 +5255,92 @@ function makeTodayFlowStyle() {
|
|
|
4935
5255
|
// 上一段到点把 transform 清成 "",正好把新一段的过渡打断在半路 —— 滑到一半定住。
|
|
4936
5256
|
// 现在改成:**先清 transform 再量**(永远拿到布局位置,与动画无关),两个定时器都
|
|
4937
5257
|
// 进 ref 且新一段开始前全部取消;正在滑的时候从「当前视觉位置」接着走,不瞬移。
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
5258
|
+
// ⚠️ 这段位移平滑现在由**三处共用**:「今日」二字、时段词「空闲」、时段词「高峰」。
|
|
5259
|
+
// 三者的 left 都是 flex 居中推出来的(居中 = (行宽 − 内容宽)/2),
|
|
5260
|
+
// 任何一处内容宽度一变,位置就跳,而纯 CSS 过渡不了一个由布局算出来的位置。
|
|
5261
|
+
// 2026-11-24 用户:「忘记给当前时段添加左右滑动的效果了 因为如果从剩10h到
|
|
5262
|
+
// 剩9h59m的话 当前空闲或高峰二字会直接瞬移」—— 就是这一处漏掉了时段词。
|
|
5263
|
+
// 连「剩」前缀一起存:滚动要对齐补的是数字段,前缀是非数字段、保持不动。
|
|
5264
|
+
const remainText = spanNow === null ? null : "剩 " + formatRemain(spanNow.remainMs);
|
|
5265
|
+
const glideLeft = react.useRef(Object.create(null)); // key → 上一次布局 left
|
|
5266
|
+
const glideTimers = react.useRef(Object.create(null)); // key → 进行中的定时器
|
|
5267
|
+
const clearGlideTimers = () => {
|
|
5268
|
+
for (const key of Object.keys(glideTimers.current)) {
|
|
5269
|
+
for (const timer of glideTimers.current[key] ?? []) clearTimeout(timer);
|
|
5270
|
+
glideTimers.current[key] = [];
|
|
5271
|
+
}
|
|
4943
5272
|
};
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
5273
|
+
// 把 el 从「旧位置」平滑推到现在的位置。逻辑与原先只服务「今日」那版完全一致。
|
|
5274
|
+
const glideTo = (el, key) => {
|
|
5275
|
+
// ⚠️ 元素不在场(换时段后另一个词根本不存在)就把它记的位置**作废**。
|
|
5276
|
+
// 否则下次它出现时 prev 还是几小时前的坐标,shift 几十像素,一进场就猛滑一下
|
|
5277
|
+
// —— 正是 AGENTS 里记的「prev 过期 → shift 巨大」那个坑。
|
|
5278
|
+
if (!el) {
|
|
5279
|
+
glideLeft.current[key] = null;
|
|
5280
|
+
return;
|
|
5281
|
+
}
|
|
5282
|
+
// ⚠️ 元素没有盒子时(切到设置页,DSH 会给祖先挂 display:none)rect 全是 0。
|
|
5283
|
+
// 这时量出来的「位置」是假的,记下来就污染了基准,切回来那一刻 shift 足有 50px、
|
|
5284
|
+
// 整块猛滑一下。getClientRects() 对 display:none 返回空列表,是唯一可靠的判断
|
|
5285
|
+
// (用 rect.width/left 判 0 会误伤真的贴在左边缘的元素;visibility:hidden 仍返回 rect,
|
|
5286
|
+
// 那时位置是对的,照常处理)。
|
|
5287
|
+
if (el.getClientRects().length === 0) {
|
|
5288
|
+
glideLeft.current[key] = null;
|
|
5289
|
+
el.style.transition = "";
|
|
5290
|
+
return;
|
|
5291
|
+
}
|
|
5292
|
+
const prev = glideLeft.current[key] ?? null;
|
|
4949
5293
|
// 正在滑的时候先记下当前视觉位置:新的一段要接着这里走,否则会瞬移回布局位置。
|
|
4950
|
-
const gliding =
|
|
4951
|
-
const visualNow = gliding ?
|
|
4952
|
-
clearTodayTimers();
|
|
5294
|
+
const gliding = el.style.transform !== "";
|
|
5295
|
+
const visualNow = gliding ? el.getBoundingClientRect().left : 0;
|
|
4953
5296
|
// ⚠️ 必须先清 transform 再量 —— 否则量到的是「布局位置 + 上一段残留位移」。
|
|
4954
5297
|
// 这一步在 paint 之前,而且紧接着就把 translateX 补回去,所以不会闪。
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
const left =
|
|
4958
|
-
|
|
5298
|
+
el.style.transition = "none";
|
|
5299
|
+
el.style.transform = "";
|
|
5300
|
+
const left = el.getBoundingClientRect().left;
|
|
5301
|
+
glideLeft.current[key] = left;
|
|
4959
5302
|
// 首次挂载没有参照,只记位置不滑动。
|
|
4960
5303
|
if (prev === null) {
|
|
4961
|
-
|
|
5304
|
+
el.style.transition = "";
|
|
4962
5305
|
return;
|
|
4963
5306
|
}
|
|
4964
5307
|
// 静止时:新位置比旧位置左了多少,就先右移多少回到旧位置,再过渡回 0。
|
|
4965
5308
|
// 正在滑时:从当前视觉位置接着走(不再叠「上一段本该补的距离」,否则会越补越歪)。
|
|
4966
5309
|
const shift = gliding ? visualNow - left : prev - left;
|
|
4967
5310
|
if (Math.abs(shift) < 0.5) {
|
|
4968
|
-
|
|
5311
|
+
el.style.transition = "";
|
|
4969
5312
|
return;
|
|
4970
5313
|
}
|
|
4971
|
-
|
|
5314
|
+
el.style.transform = "translateX(" + shift.toFixed(2) + "px)";
|
|
4972
5315
|
// 下一帧才放开过渡。这里用 setTimeout 而不是 rAF —— DSH 渲染进程里
|
|
4973
5316
|
// rAF 会被窗口可见性挂起,回调可能永远不来(见 AGENTS「UI 易错点」)。
|
|
4974
5317
|
const id = setTimeout(() => {
|
|
4975
5318
|
// 460ms 不是随手写的:启动那一刻的位移只有 2.2px,320ms 滑完肉眼看不出在动、
|
|
4976
5319
|
// 只觉得"顿了一下";拉到 460ms 才读得出是平滑挪过去的(2026-10-31 反馈)。
|
|
4977
|
-
|
|
4978
|
-
|
|
5320
|
+
el.style.transition = "transform .46s cubic-bezier(.22,.72,.28,1)";
|
|
5321
|
+
el.style.transform = "translateX(0px)";
|
|
4979
5322
|
const done = setTimeout(() => {
|
|
4980
5323
|
// 清干净:transition 留着会影响后续任何位移,
|
|
4981
5324
|
// transform 留着更糟 —— 残留的 translateX(0px) 会让这块独立成合成层,
|
|
4982
5325
|
// 小字号中文在 GPU 纹理里渲染直接发虚(用户 2026-10-31:「数字变糊了」)。
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
5326
|
+
el.style.transition = "";
|
|
5327
|
+
el.style.transform = "";
|
|
5328
|
+
glideTimers.current[key] = [];
|
|
4986
5329
|
}, 500);
|
|
4987
|
-
|
|
5330
|
+
glideTimers.current[key] = [done];
|
|
4988
5331
|
}, 16);
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
5332
|
+
glideTimers.current[key] = [id];
|
|
5333
|
+
};
|
|
5334
|
+
usePrePaintEffect(() => {
|
|
5335
|
+
if (typeof document === "undefined" || typeof document.querySelector !== "function") return;
|
|
5336
|
+
clearGlideTimers();
|
|
5337
|
+
glideTo(document.querySelector(".balance-footer__timeline-meta-item--today .balance-footer__today-label"), "today");
|
|
5338
|
+
// 时段词两种形态各查一次:同一时刻只有一个在 DOM 里,
|
|
5339
|
+
// 另一个拿到 null 直接跳过(换时段时会从空闲切到高峰,位置同样要滑过去)。
|
|
5340
|
+
glideTo(document.querySelector(".balance-footer__timeline-meta-item--peak"), "peak");
|
|
5341
|
+
glideTo(document.querySelector(".balance-footer__timeline-meta-item--offpeak"), "offpeak");
|
|
5342
|
+
return clearGlideTimers;
|
|
5343
|
+
}, [todayText, remainText]);
|
|
4994
5344
|
const remainPrevRef = react.useRef(null);
|
|
4995
5345
|
const [remainRoll, setRemainRoll] = react.useState(null);
|
|
4996
5346
|
usePrePaintEffect(() => {
|
|
@@ -5378,7 +5728,8 @@ function makeTodayFlowStyle() {
|
|
|
5378
5728
|
// (2026-10-31 实测截图)。币种在收起态没有横向空间,展开态才显示。
|
|
5379
5729
|
// 滚动起点同样要把 `roll.from` 里的币种剥掉,否则 from 含 CNY、to 不含,
|
|
5380
5730
|
// 逐位比对会整串错位。
|
|
5381
|
-
|
|
5731
|
+
// ≥1000 取整(与侧栏胶囊同一口径,见 formatTotalDisplay)
|
|
5732
|
+
const rectNum = formatTotalDisplay(b.total_balance);
|
|
5382
5733
|
const stripCurrency = (s) => String(s == null ? "" : s).replace(/\s*[A-Z]{3}\s*$/, "");
|
|
5383
5734
|
const rectRoll = roll === null ? null : { from: stripCurrency(roll.from), at: roll.at, done: roll.done };
|
|
5384
5735
|
// ⚠️ 余额耗尽时整卡的跳转目标换成充值页(2026-11-13):卡片里那一行「充值」
|
|
@@ -5557,7 +5908,7 @@ function makeTodayFlowStyle() {
|
|
|
5557
5908
|
|
|
5558
5909
|
if (state.status === "error") {
|
|
5559
5910
|
return withPanel(jsx.jsxs("div", {
|
|
5560
|
-
className: "balance-footer" + footerEnterClass, id: "balance-footer-root",
|
|
5911
|
+
className: "balance-footer" + footerEnterClass + crowdClass, id: "balance-footer-root",
|
|
5561
5912
|
...interactions,
|
|
5562
5913
|
children: [
|
|
5563
5914
|
// 失败原因统一走主题化浮层,避免把长错误塞进 42px 的余额行
|
|
@@ -5581,7 +5932,15 @@ function makeTodayFlowStyle() {
|
|
|
5581
5932
|
}
|
|
5582
5933
|
|
|
5583
5934
|
const b = state.balance;
|
|
5584
|
-
|
|
5935
|
+
// ⚠️ 临时预览开关(2026-11-24 用户:「帮我给余额先暂时改成 99999 给我看一下」):
|
|
5936
|
+
// 地址栏加 `?mock=99999` 就能把主数字换成指定值,用来在真实的侧栏宽度下看
|
|
5937
|
+
// 万位金额会不会撑破胶囊 / 挤掉左边的时段文字。不加这个参数时**一个字节都不影响**,
|
|
5938
|
+
// 完全走真实余额。要用的时候重新加载页面并带上参数即可,不用改代码。
|
|
5939
|
+
const totalsPreview = balancePreviewValue();
|
|
5940
|
+
const totalRaw = totalsPreview ?? b.total_balance;
|
|
5941
|
+
// 显示用(≥1000 取整),计算与阈值判断仍用原值。
|
|
5942
|
+
const totalText0 = formatTotalDisplay(totalRaw);
|
|
5943
|
+
const total = Number.parseFloat(totalRaw ?? "0");
|
|
5585
5944
|
// 「余额不足」必须听服务端的 is_available,**不能**用 total <= 0 推断
|
|
5586
5945
|
// (2026-10-31 审查):`total_balance` 只是**充值余额**,赠送钱包单列在 granted_balance 里
|
|
5587
5946
|
// (见 AGENTS「主数字只等于充值余额」)。所以「充值花光但赠送还有」时 total 是 0、
|
|
@@ -5591,11 +5950,11 @@ function makeTodayFlowStyle() {
|
|
|
5591
5950
|
? b.is_available === false
|
|
5592
5951
|
: (!Number.isFinite(total) || total <= 0);
|
|
5593
5952
|
const currency = b.currency || "CNY";
|
|
5594
|
-
const totalText =
|
|
5953
|
+
const totalText = totalText0 + " " + currency;
|
|
5595
5954
|
// 位数多就降字号:一旦整数位到 4 位,16px 的胶囊会宽过 121px 的固定宽度
|
|
5596
5955
|
// (1234.56 CNY 131.3px / 12345.67 CNY 141.1px),把自己撑出容器右缘。
|
|
5597
5956
|
// 降一档字号就能收回来,宽度重新恒定 —— 配合 .balance-footer__value 的 min-width。
|
|
5598
|
-
const valueDensity = amountDensity(
|
|
5957
|
+
const valueDensity = amountDensity(totalText0);
|
|
5599
5958
|
// ⚠️ 余额耗尽**不再整行早退**(2026-11-13 用户:「在新版样式情况下 余额用完
|
|
5600
5959
|
// 只替换余额处为充值按钮」)。原来这里直接 return 一个「spacer + 去充值」,于是
|
|
5601
5960
|
// 新版样式底下「今日消耗 / 时段词 / 剩余时间 / 色带指针」**整块消失** ——
|
|
@@ -5848,7 +6207,7 @@ function makeTodayFlowStyle() {
|
|
|
5848
6207
|
children: period === "peak" ? "高峰" : "空闲",
|
|
5849
6208
|
});
|
|
5850
6209
|
return withPanel(jsx.jsxs("div", {
|
|
5851
|
-
className: "balance-footer balance-footer--classic" + footerEnterClass, id: "balance-footer-root",
|
|
6210
|
+
className: "balance-footer balance-footer--classic" + footerEnterClass + crowdClass, id: "balance-footer-root",
|
|
5852
6211
|
children: [
|
|
5853
6212
|
jsx.jsx("span", { className: "balance-footer__icon", children: jsx.jsx(WalletIcon, {}) }),
|
|
5854
6213
|
jsx.jsx("span", { className: "balance-footer__label", children: "余额" }),
|
|
@@ -5866,7 +6225,7 @@ function makeTodayFlowStyle() {
|
|
|
5866
6225
|
}), undefined, undefined, rowInteractions);
|
|
5867
6226
|
}
|
|
5868
6227
|
return withPanel(jsx.jsxs("div", {
|
|
5869
|
-
className: "balance-footer balance-footer--stacked" + footerEnterClass, id: "balance-footer-root",
|
|
6228
|
+
className: "balance-footer balance-footer--stacked" + footerEnterClass + crowdClass, id: "balance-footer-root",
|
|
5870
6229
|
children: [
|
|
5871
6230
|
// 抹除层覆盖整块显示区(today 行 + meta 行 + 时段条):白条经过哪里,哪里才显影
|
|
5872
6231
|
waveNode,
|
|
@@ -5890,9 +6249,15 @@ function makeTodayFlowStyle() {
|
|
|
5890
6249
|
key: "reveal-" + revealSeq,
|
|
5891
6250
|
children: [
|
|
5892
6251
|
// 底层(常显):光条没扫到的区域就是它,所以内容不会先消失再长出来。
|
|
6252
|
+
// ⚠️ 预览值生效时**底层直接写新值**(2026-11-24):ref 是上一轮渲染留下的旧值,
|
|
6253
|
+
// 而上面 sweep 层拿的是新值,没挂 --animate(revealSeq 为 0)时 clip-path 是 none、
|
|
6254
|
+
// 两层都画出来 → `99999.00CNY` 压着 `12.98CNY`。正常刷新两层内容相同,看不出来;
|
|
6255
|
+
// 预览一步从 3 位跳到 5 位才暴露。预览只要宽度,底层跟新值就好。
|
|
5893
6256
|
jsx.jsx("span", {
|
|
5894
6257
|
className: "balance-footer__reveal-base",
|
|
5895
|
-
children:
|
|
6258
|
+
children: totalsPreview !== null
|
|
6259
|
+
? totalText
|
|
6260
|
+
: (revealBaseRef.current !== null ? revealBaseRef.current : totalText),
|
|
5896
6261
|
}, "base"),
|
|
5897
6262
|
// 上层:被 clip-path 从左边擦开的那一层,光条走到哪,哪才盖住底层。
|
|
5898
6263
|
jsx.jsx("span", {
|
|
@@ -5994,6 +6359,13 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
5994
6359
|
usePrePaintEffect(() => {
|
|
5995
6360
|
if (typeof document === "undefined" || typeof document.querySelector !== "function") return undefined;
|
|
5996
6361
|
let disposed = false;
|
|
6362
|
+
// ⚠️ 重挂载(切会话 / 切视图)后的**第一拍测量**不许挂滑动过渡(2026-11-24:
|
|
6363
|
+
// 「切换对话时 对话消耗浮窗会有从左往右的动画」)。
|
|
6364
|
+
// 原因:floatBoxMemo 里存的是**上一个会话**的位置,新会话的输入卡片宽度不同 →
|
|
6365
|
+
// cardRect.right 不同 → 锚左缘算出来的 left 不同 → 首拍 movedPx 轻松过 12px →
|
|
6366
|
+
// 被判成「内部布局在动」而 slideOn(),屏幕上看就是卡片从旧位置滑到新位置。
|
|
6367
|
+
// 那不是布局在动,是换了内容。首拍直接落位,之后的真实位移照旧走过渡。
|
|
6368
|
+
let firstMeasure = floatBoxMemo !== null; // 冷启动 memo 是 null,本来就没过渡可挂
|
|
5997
6369
|
// ⚠️ 前置两个占位(measure 里要用,而它们真正定义在 measure 之后 —— 用 const 直接引用
|
|
5998
6370
|
// 会在首次 measure() 时撞上 TDZ)。
|
|
5999
6371
|
// · sync:把观察者补挂到**当前**这棵 DOM 上。收起/展开侧边栏时 DSH 会重建 composer 子树,
|
|
@@ -6259,7 +6631,9 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
6259
6631
|
: Math.max(Math.abs(floatBoxMemo.left - styleLeft), Math.abs(floatBoxMemo.bottom - styleBottom));
|
|
6260
6632
|
// 大跳变 + 视口没变 → 内部布局在动(收起/展开侧边栏),挂滑动过渡并保持一段;
|
|
6261
6633
|
// 视口变了 → 用户在拖窗口边缘,立刻摘掉过渡,卡片必须紧跟窗口(否则像被橡皮筋拽着)。
|
|
6262
|
-
|
|
6634
|
+
const isFirst = firstMeasure;
|
|
6635
|
+
firstMeasure = false;
|
|
6636
|
+
if (isFirst || vwChanged || cbMoved) measureCtl.slideOff();
|
|
6263
6637
|
else if (movedPx >= FLOAT_SLIDE_MIN_PX) measureCtl.slideOn();
|
|
6264
6638
|
// 布局还在动(侧边栏展开/收起带动输入卡片变宽)→ 顺手把观察者补挂到当前 DOM 上,
|
|
6265
6639
|
// 并再跟几拍。少了这两句,元素一被重建就退回「等兜底轮询」的老路 = 位置刷新慢半拍。
|
|
@@ -6267,7 +6641,8 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
6267
6641
|
// ⚠️ 包含块自己在动时(侧栏展开/收起的 width 过渡)**不排补拍**:
|
|
6268
6642
|
// 那段里 ResizeObserver 每帧都会回调 measure,本来就不缺触发源;
|
|
6269
6643
|
// 每帧再排 8 个定时器(0/16/40/…/400ms)纯属自己给自己加戏,是掉帧的一半来源。
|
|
6270
|
-
|
|
6644
|
+
// 首拍同样不排补拍:刚重挂载时位置已经用 memo 落对了,排八拍纯属白烧
|
|
6645
|
+
if (!isFirst && movedPx > FLOAT_JITTER_PX && !cbMoved) measureCtl.settle();
|
|
6271
6646
|
// 写 state 的同时记进模块级 memo:下一帧/下一次重挂载的首帧都用这个值,
|
|
6272
6647
|
// 不再等测量(否则切会话会闪一帧 CSS 兜底的 16/16)。
|
|
6273
6648
|
setFloatBox((prev) => {
|
|
@@ -7052,6 +7427,53 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7052
7427
|
// 只是靠请求慢才看得见雾)。它只按「换会话 / 入场完成」起算,流式刷新期间不会重播。
|
|
7053
7428
|
const showCostLoading = (staleUsage || costPending || costFogFloor || !costResolved)
|
|
7054
7429
|
&& floatEntered && (!sessionReady || costFogFloor) && !costStuck;
|
|
7430
|
+
// 「这次加载已经超过 1 秒了」(2026-11-24 用户:「当对话估算加载超过1秒
|
|
7431
|
+
// 就在下方显示 提示对话历史过长需要时间 给用户」→ 又改成「可以单独显示一个小浮窗」)。
|
|
7432
|
+
// 两个方向都要有下限:
|
|
7433
|
+
// 亮 —— 连续加载满 COST_SLOW_HINT_MS 才亮(1 秒以下不打扰,正常会话都在这个区间);
|
|
7434
|
+
// 收 —— 亮了之后至少留 COST_SLOW_HINT_MIN_MS 才允许收(2026-11-24 用户:
|
|
7435
|
+
// 「有的对话可能刚好1秒多一点 导致提示就闪了一下 所以添加提示显示保底1秒」)。
|
|
7436
|
+
// 只加亮的下限的话,1.05 秒的加载会让气泡只活 50ms,连 200ms 的淡出都走不完。
|
|
7437
|
+
// ⚠️ 依赖里必须有 costSlowHint:收的那一支要靠它判断「这次是真亮过还是没亮过」。
|
|
7438
|
+
// 亮了以后 effect 会再跑一遍,但第一支的 `if (costSlowHint) return` 会挡住重排,
|
|
7439
|
+
// 不会自己重启定时器,也不会死循环。
|
|
7440
|
+
// ⚠️ 记「亮起时刻」用 ref 不用 state:它不参与渲染,写它不该触发重渲染。
|
|
7441
|
+
// ⚠️ 显示的判据是 costSlowHint **自己**,绝不能再串一个 showCostLoading ——
|
|
7442
|
+
// showCostLoading 在「加载结束」那一帧就变 false,串上它等于保底时长作废:
|
|
7443
|
+
// 1.05 秒的加载依旧只亮 50ms(2026-11-24 自查出来的 bug,用户本来就是在报这个「闪一下」)。
|
|
7444
|
+
// costSlowHint 只在 showCostLoading 期间才被置 true,收起有保底,本身就是完整判据。
|
|
7445
|
+
const [costSlowHint, setCostSlowHint] = react.useState(false);
|
|
7446
|
+
const slowHintShowAt = react.useRef(0);
|
|
7447
|
+
const slowHintSession = react.useRef(sessionId);
|
|
7448
|
+
react.useEffect(() => {
|
|
7449
|
+
// 换会话 = 全新一轮:上一个会话的亮起状态不许带过来,
|
|
7450
|
+
// 否则切到一个慢会话时会「刚进来就显示历史过长」,其实它还没加载满 1 秒。
|
|
7451
|
+
let hintOn = costSlowHint;
|
|
7452
|
+
if (slowHintSession.current !== sessionId) {
|
|
7453
|
+
slowHintSession.current = sessionId;
|
|
7454
|
+
slowHintShowAt.current = 0;
|
|
7455
|
+
hintOn = false;
|
|
7456
|
+
if (costSlowHint) setCostSlowHint(false);
|
|
7457
|
+
}
|
|
7458
|
+
if (showCostLoading) {
|
|
7459
|
+
if (hintOn) return undefined; // 已经亮着,别重排
|
|
7460
|
+
const id = setTimeout(() => {
|
|
7461
|
+
slowHintShowAt.current = Date.now();
|
|
7462
|
+
setCostSlowHint(true);
|
|
7463
|
+
}, COST_SLOW_HINT_MS);
|
|
7464
|
+
return () => clearTimeout(id);
|
|
7465
|
+
}
|
|
7466
|
+
// 加载结束了:没亮过就什么都不用做(大多数情况)
|
|
7467
|
+
if (!hintOn) return undefined;
|
|
7468
|
+
// 亮过就补足保底时长,剩余多少等多少
|
|
7469
|
+
const left = COST_SLOW_HINT_MIN_MS - (Date.now() - slowHintShowAt.current);
|
|
7470
|
+
if (left <= 0) {
|
|
7471
|
+
setCostSlowHint(false);
|
|
7472
|
+
return undefined;
|
|
7473
|
+
}
|
|
7474
|
+
const id = setTimeout(() => setCostSlowHint(false), left);
|
|
7475
|
+
return () => clearTimeout(id);
|
|
7476
|
+
}, [showCostLoading, costSlowHint, sessionId]);
|
|
7055
7477
|
// 等待兜底:4 秒还没等到(请求一直不返回 / 服务端卡住),停止等、退回缓存值。
|
|
7056
7478
|
// ⚠️ 依赖只留这三个(2026-10-31 第二十二轮审计):早先 `showCostLoading` 也在依赖里,
|
|
7057
7479
|
// 而它含 staleUsage / costPending,流式期间每变一次就 cleanup 重排 → 计时器被无限顺延,
|
|
@@ -7648,7 +8070,8 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7648
8070
|
// (订阅/离场判定都在用 document.querySelector 找它),`.balance-float` 才是浮窗外观。
|
|
7649
8071
|
className: "balance-usage-line balance-float"
|
|
7650
8072
|
+ (floatEnter ? " balance-float--enter" : "")
|
|
7651
|
-
+ (floatSlide ? " balance-float--slide" : "")
|
|
8073
|
+
+ (floatSlide ? " balance-float--slide" : "")
|
|
8074
|
+
+ (costSlowHint ? " balance-float--slow" : ""),
|
|
7652
8075
|
"aria-haspopup": "dialog",
|
|
7653
8076
|
"aria-expanded": detailsOpen,
|
|
7654
8077
|
"aria-label": "本会话消耗明细",
|
|
@@ -7670,7 +8093,25 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
7670
8093
|
// 2026-11-02 第十一轮:用户「只显示本会话的消耗 不要今日消耗 然后调小一点 太大了
|
|
7671
8094
|
// 我要的是第一列显示本会话消耗估算的字样 第二列显示消耗数字 保留动画」——
|
|
7672
8095
|
// 所以今日那一整行(连带它的雾/擦出/滚 & 图标)都撤掉了,卡片回到 20px 高。
|
|
7673
|
-
|
|
8096
|
+
// 两行常驻内容 + 卡片外那颗慢加载气泡,用展开写法拼成一个数组
|
|
8097
|
+
// (原来是对象简写 `children,`,加第三个节点必须改成展开,否则语法不成立)。
|
|
8098
|
+
children: [
|
|
8099
|
+
...children,
|
|
8100
|
+
// 慢加载气泡(2026-11-24 用户:「当对话估算加载超过1秒 就在下方显示
|
|
8101
|
+
// 提示对话历史过长需要时间 给用户」→ 又改口「可以单独显示一个小浮窗」)。
|
|
8102
|
+
// 挂在卡片底部之外、靠 bottom:100% 定位到正上方,所以**不影响卡片高度**
|
|
8103
|
+
// (卡片始终 42px,不再有"长高 13px"的抖动)。
|
|
8104
|
+
// 常驻节点 + 只切 opacity:条件渲染没有过渡,会出现/消失得很硬。
|
|
8105
|
+
jsx.jsx("span", {
|
|
8106
|
+
key: "slow",
|
|
8107
|
+
className: "balance-float__slow-tip",
|
|
8108
|
+
"aria-hidden": costSlowHint ? void 0 : "true",
|
|
8109
|
+
// ⚠️ 文字**不许**跟着 costSlowHint 一起清空:一清空,opacity 的淡出
|
|
8110
|
+
// 就没有内容可看,视觉上是硬切(2026-11-24 用户:「提示消失没有动画了」)。
|
|
8111
|
+
// 常驻 + 只切 aria-hidden/透明度,进出场才都看得见。
|
|
8112
|
+
children: jsx.jsx("b", { children: "历史过长,稍候" }),
|
|
8113
|
+
}),
|
|
8114
|
+
],
|
|
7674
8115
|
}),
|
|
7675
8116
|
detailsOpen
|
|
7676
8117
|
? createPortal(
|
|
@@ -8162,6 +8603,7 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
8162
8603
|
lines.push(
|
|
8163
8604
|
`轮询 ${s.refreshIntervalSec ?? "—"}s · 今日扫描上限 ${s.todaySessionLimit ?? "—"} · ` +
|
|
8164
8605
|
`统计上限 ${s.statsSessionLimit ?? "—"} · 统计缓存 ${s.statsCacheSec ?? "—"}s · ` +
|
|
8606
|
+
`聚合缓存 ${s.aggCacheMax ?? "—"} 条 · ` +
|
|
8165
8607
|
`低余额阈值 ${s.lowBalanceThreshold ?? "—"}`,
|
|
8166
8608
|
);
|
|
8167
8609
|
lines.push(
|
|
@@ -9138,6 +9580,14 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
9138
9580
|
numberRow("todaySessionLimit", "今日消耗扫描上限", "启动时最多统计今天动过的多少个会话(多开对话、多跑子代理时调大,越大越全也可能越慢)。", 10, 2000, "个"),
|
|
9139
9581
|
numberRow("statsSessionLimit", "扫描会话数上限", "统计面板最多回看多少个历史会话(越大越慢)。", 10, 2000, "个"),
|
|
9140
9582
|
numberRow("statsCacheSec", "统计缓存时长", "统计结果缓存多久;0 = 每次重新扫描。", 0, 3600, "秒"),
|
|
9583
|
+
numberRow(
|
|
9584
|
+
"aggCacheMax",
|
|
9585
|
+
"聚合缓存条数上限",
|
|
9586
|
+
"最多记住多少个会话算过的结果。超过就从最旧的开始丢 —— 丢掉的不会丢数据,只是下次打开那个会话要重算一遍。会话多、把上面两个上限调大的人可以调高。",
|
|
9587
|
+
100,
|
|
9588
|
+
5000,
|
|
9589
|
+
"条",
|
|
9590
|
+
),
|
|
9141
9591
|
]),
|
|
9142
9592
|
|
|
9143
9593
|
group("billing", "计费", [
|
|
@@ -9281,6 +9731,8 @@ function UsageCostLine({ useProjection, sessionId }) {
|
|
|
9281
9731
|
// ctx.get() 不会因未声明注入而抛错,服务不存在时返回 undefined。
|
|
9282
9732
|
sessionsFace = typeof ctx.get === "function" ? ctx.get("sessions") : void 0;
|
|
9283
9733
|
// 余额显示:展开态底部胶囊(order 20 排在市场 10 之后、紧挨设置);收起态悬浮 FAB
|
|
9734
|
+
// 布局:footerActions 开了 flex-wrap,.balance-footer 占满一整行(flex:1 1 100%),
|
|
9735
|
+
// 所以别的插件也占这一行时会被挤到下一行,两边都不裁字(见 .balance-footer 那段注释)。
|
|
9284
9736
|
ctx.slots.inject("sidebar.footer.action", () =>
|
|
9285
9737
|
ctx.slots.register(
|
|
9286
9738
|
{
|
package/lib/index.js
CHANGED
|
@@ -80,13 +80,30 @@ const SESSION_STAMP_TTL_MS = 5 * 1000; // 指纹来源(会话列表)
|
|
|
80
80
|
// 指纹必然每次都变;不节流就是「每个 chunk 一轮 800 ms 同步解压」。
|
|
81
81
|
// 4 秒的滞后在这个场景里感知不到(余额轮询本身 60 秒一轮)。
|
|
82
82
|
const SESSION_REREAD_MIN_MS = 4 * 1000;
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
//
|
|
89
|
-
|
|
83
|
+
// 自适应冷却的上下限(2026-11-24):按「这个会话上一次真读盘花了多久」现算。
|
|
84
|
+
// 会话大小差好几个数量级 —— 新开的会话解压 20 ms,这个 27 MB / 85 MB 解压后的会话要 560 ms。
|
|
85
|
+
// 写死一个数必然两头不讨好:小会话被拖慢、大会话还是卡。
|
|
86
|
+
// 目标:让「真读盘」始终只占约 1/12 的墙钟时间,剩下 11/12 留给 DSH 自己。
|
|
87
|
+
const SESSION_REREAD_MAX_MS = 15 * 1000;
|
|
88
|
+
// 每个会话上一次**真正解压**的耗时(ms)。只由成功路径写,失败不参与(失败本来就没解出东西)。
|
|
89
|
+
// ⚠️ 必须 capSessionMap 限长,否则跨月累积上千个会话 id 永不回收。
|
|
90
|
+
const sessionReadCost = new Map();
|
|
91
|
+
|
|
92
|
+
/** 这个会话该冷却多久才允许再读盘。测过就按耗时现算,没测过用默认值。 */
|
|
93
|
+
function sessionRereadMinMs(sessionId) {
|
|
94
|
+
const measured = sessionReadCost.get(sessionId);
|
|
95
|
+
if (typeof measured !== "number" || !Number.isFinite(measured) || measured <= 0) {
|
|
96
|
+
return SESSION_REREAD_MIN_MS;
|
|
97
|
+
}
|
|
98
|
+
// ×12 = 「读盘占 1/12」。夹在 [MIN, MAX] 之间:
|
|
99
|
+
// 小会话被抬到 4 秒下限(再快也没意义,客户端本来就 600ms 问一次);
|
|
100
|
+
// 大会话最高 15 秒封顶(再长用户会觉得金额卡死了)。
|
|
101
|
+
return Math.min(SESSION_REREAD_MAX_MS, Math.max(SESSION_REREAD_MIN_MS, Math.round(measured * 12)));
|
|
102
|
+
}
|
|
103
|
+
// 子会话的重读间隔已并入 sessionRereadMinMs(2026-11-24):原来写死 15 秒,
|
|
104
|
+
// 但 fork 队友的日志是父会话全量副本、体量从小到几百 MB 都有,写死一样两头不讨好。
|
|
105
|
+
// 现在和父会话走同一套「按上次解压耗时现算 + [4s, 15s] 夹值」。
|
|
106
|
+
// 注意子会话数字只是**补充信息**(团队补拉本来就 15 秒一轮),所以上限 15 秒对它是够的。
|
|
90
107
|
// 子代理整体结果的短期备忘(同 rootKey + 配置)。`?session=` 一次请求里
|
|
91
108
|
// 会连着问好几处(消耗行 / 团队补拉 / 今日增量),1.5 秒内复用同一份,
|
|
92
109
|
// 端到端把这段从 36~97 ms 压到 0。子会话本身有 15 秒节流,这里不会让数字更旧。
|
|
@@ -324,12 +341,46 @@ function eventsSignature(events) {
|
|
|
324
341
|
return `${n}\u0000${stamp}`;
|
|
325
342
|
}
|
|
326
343
|
|
|
327
|
-
|
|
344
|
+
// 配置签名的格式版本。改了取值范围就 +1:旧条目在载入时被直接丢弃,
|
|
345
|
+
// 否则它们永远不可能命中,却白占 AGG_CACHE_MAX 的额度。
|
|
346
|
+
// v3(2026-11-26):补上 peakWeekdays(peakRuleOf 会读它,漏了就等于改周几不失效)。
|
|
347
|
+
const AGG_SIG_VERSION = "v3";
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* 配置签名:**只有真正影响计费的字段**才进来。
|
|
351
|
+
*
|
|
352
|
+
* ⚠️ 曾经是 `JSON.stringify(整份 config)`(只 delete 掉 apiKey),代价实测过:
|
|
353
|
+
* 用户改「余额刷新间隔」「低余额阈值」「扫描会话数上限」「余额行样式」这些
|
|
354
|
+
* 与钱毫无关系的设置,也会让**全部会话**的聚合缓存一起作废、下次全部重新解压。
|
|
355
|
+
* 2026-11-26 拆 balance-session-usage.json:66 条里 34 条(51.5%)是这么浪费的,
|
|
356
|
+
* 表现为同一个会话、同一个文件指纹却存了好几份,差异只在 statsSessionLimit 之类。
|
|
357
|
+
*
|
|
358
|
+
* 计费真正依赖的,一处都不能漏:
|
|
359
|
+
* ① config 里的:peakWindows / peakWeekdays / peakMultiplier / peak(旧布尔,等价 ×2)/
|
|
360
|
+
* priceByModel / price(旧的兜底价对象)
|
|
361
|
+
* ② config 外的:内置价表 MODEL_PRICING + LEGACY_MODEL_PRICING + FLASH_REPRICED_AT +
|
|
362
|
+
* WEB_TOOL_BILLING_START / WEB_TOOL_PRICE_PER_CALL + 节假日日历 CN_CALENDAR
|
|
363
|
+
* ② 全都在代码里,升级版本才可能变 —— 所以直接把 PLUGIN_VERSION 拼进签名:
|
|
364
|
+
* 版本一变旧缓存自动作废,不用维护第二个人工版本号,也不可能忘。
|
|
365
|
+
* 取不到就退化成随机串(等于不缓存),宁可慢也不能算错。
|
|
366
|
+
*/
|
|
328
367
|
function configSignature(config) {
|
|
329
368
|
try {
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
369
|
+
const c = config ?? {};
|
|
370
|
+
return (
|
|
371
|
+
AGG_SIG_VERSION +
|
|
372
|
+
"|" +
|
|
373
|
+
PLUGIN_VERSION +
|
|
374
|
+
"|" +
|
|
375
|
+
JSON.stringify({
|
|
376
|
+
peakWindows: c.peakWindows ?? null,
|
|
377
|
+
peakWeekdays: c.peakWeekdays ?? null,
|
|
378
|
+
peakMultiplier: c.peakMultiplier ?? null,
|
|
379
|
+
peak: c.peak ?? null,
|
|
380
|
+
priceByModel: c.priceByModel ?? null,
|
|
381
|
+
price: c.price ?? null,
|
|
382
|
+
})
|
|
383
|
+
);
|
|
333
384
|
} catch {
|
|
334
385
|
return `?${Math.random()}`;
|
|
335
386
|
}
|
|
@@ -370,7 +421,11 @@ function memoSessionUsage(key, compute) {
|
|
|
370
421
|
// * 存的是 ownEventsOf() 切过前缀的聚合(fork 会话不会把父会话历史算两遍);
|
|
371
422
|
// * 同时存按日桶(byDay),今日增量就不必再为了「今天这一桶」去解压整份会话。
|
|
372
423
|
const AGG_CACHE_FILENAME = "balance-session-usage.json";
|
|
424
|
+
// 默认条数上限。用户可在设置页「聚合缓存条数上限」里改(见 aggCacheLimit)。
|
|
373
425
|
const AGG_CACHE_MAX = 320;
|
|
426
|
+
// 设置页能调到的硬上限。载入旧文件时按它裁 —— 那一刻还没有 config,
|
|
427
|
+
// 若按默认 320 裁,用户设成 960 的那部分会被白白截掉。
|
|
428
|
+
const AGG_CACHE_HARD_MAX = 5000;
|
|
374
429
|
// 孤儿临时文件的清扫门槛:`writeJsonAtomic` 正常路径是「写 → rename」,毫秒级;
|
|
375
430
|
// 只有进程被打断才会留下。给 10 分钟,绝不会扫掉正在写的那个。
|
|
376
431
|
const TEMP_SWEEP_MIN_AGE_MS = 10 * 60 * 1000;
|
|
@@ -391,8 +446,15 @@ function aggCacheKey(sessionId, stamp, config) {
|
|
|
391
446
|
return `${sessionIdKey(String(sessionId ?? ""))}\u0000${stamp}\u0000${configSignature(config)}`;
|
|
392
447
|
}
|
|
393
448
|
|
|
394
|
-
|
|
395
|
-
|
|
449
|
+
/** 用户设置里的缓存条数上限;没设 / 非法就退回默认 320。 */
|
|
450
|
+
function aggCacheLimit(config) {
|
|
451
|
+
const n = Number(config?.aggCacheMax);
|
|
452
|
+
if (!Number.isFinite(n)) return AGG_CACHE_MAX;
|
|
453
|
+
return Math.min(AGG_CACHE_HARD_MAX, Math.max(100, Math.round(n)));
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function trimAggCache(max = AGG_CACHE_MAX) {
|
|
457
|
+
while (aggCache.size > max) {
|
|
396
458
|
const oldest = aggCache.keys().next();
|
|
397
459
|
if (oldest.done) return;
|
|
398
460
|
aggCache.delete(oldest.value);
|
|
@@ -412,13 +474,18 @@ async function ensureAggCacheLoaded(ctx) {
|
|
|
412
474
|
if (e == null || typeof e !== "object") continue;
|
|
413
475
|
if (typeof e.k !== "string" || e.k === "") continue;
|
|
414
476
|
if (e.u == null || typeof e.u !== "object") continue;
|
|
477
|
+
// 只收当前签名格式的条目。旧格式(键里没有 "v2|")永远不可能命中新签名,
|
|
478
|
+
// 留着只会挤占 AGG_CACHE_MAX 的额度,把能命中的会话顶出去。
|
|
479
|
+
const sigPart = String(e.k.split("\u0000")[2] ?? "");
|
|
480
|
+
if (!sigPart.startsWith(AGG_SIG_VERSION + "|")) continue;
|
|
415
481
|
aggCache.set(e.k, {
|
|
416
482
|
usage: e.u,
|
|
417
483
|
model: typeof e.m === "string" ? e.m : "",
|
|
418
484
|
byDay: e.d != null && typeof e.d === "object" ? e.d : null,
|
|
419
485
|
});
|
|
420
486
|
}
|
|
421
|
-
|
|
487
|
+
// 载入这一刻还拿不到用户设置,按硬上限裁即可;真正的上限在 putAggCache 里按 config 生效。
|
|
488
|
+
trimAggCache(AGG_CACHE_HARD_MAX);
|
|
422
489
|
} catch {
|
|
423
490
|
// 文件不存在 / 读坏 → 当空缓存,全部走解压路径(慢一点,但数字对)
|
|
424
491
|
}
|
|
@@ -437,7 +504,7 @@ function putAggCache(ctx, sessionId, stamp, config, value) {
|
|
|
437
504
|
model: value.model ?? "",
|
|
438
505
|
byDay: value.byDay ?? null,
|
|
439
506
|
});
|
|
440
|
-
trimAggCache();
|
|
507
|
+
trimAggCache(aggCacheLimit(config));
|
|
441
508
|
scheduleAggFlush(ctx);
|
|
442
509
|
}
|
|
443
510
|
|
|
@@ -542,7 +609,12 @@ async function inspectPersistedCached(ctx, sessionId, minIntervalMs = 0, opts =
|
|
|
542
609
|
|
|
543
610
|
const task = (async () => {
|
|
544
611
|
try {
|
|
612
|
+
const readStartedAt = Date.now();
|
|
545
613
|
const value = await inspectPersistedSession(ctx, sessionId);
|
|
614
|
+
// 记这次解压花了多久 —— 下一拍 sessionRereadMinMs() 靠它决定冷却时长。
|
|
615
|
+
// 放在 value 拿到之后:抛异常说明没解出东西,不能拿半截耗时去缩短/拉长节流。
|
|
616
|
+
sessionReadCost.set(sessionId, Date.now() - readStartedAt);
|
|
617
|
+
capSessionMap(sessionReadCost);
|
|
546
618
|
// 覆盖同一会话时先把旧那份的字节数扣掉,否则总量只增不减。
|
|
547
619
|
if (persistCache.has(sessionId)) dropEntry(sessionId);
|
|
548
620
|
const size = estimateBytes(value);
|
|
@@ -1140,7 +1212,7 @@ function formatBalance(balance) {
|
|
|
1140
1212
|
// | { status:"failed" } (网络失败;官方明确“失败绝不变成 0 余额”)
|
|
1141
1213
|
// client 是 AccountClientMetadata(version / locale / timezoneOffsetSeconds),
|
|
1142
1214
|
// 缺字段会在平台侧组装请求头时抛错,所以三个字段都要给。
|
|
1143
|
-
const PLUGIN_VERSION = "2.3.
|
|
1215
|
+
const PLUGIN_VERSION = "2.3.5";
|
|
1144
1216
|
|
|
1145
1217
|
/** 斜杠命令名(2026-10-31 定案:用带作者后缀的全名,避免和别的余额插件撞车,也不设备用名)。
|
|
1146
1218
|
* ⚠️ DSH 的 COMMAND_NAME = /^[a-z][a-z0-9_-]*$/u —— **只允许小写**。
|
|
@@ -2235,6 +2307,9 @@ const DEFAULT_SETTINGS = {
|
|
|
2235
2307
|
// 默认放得比统计宽(用户 2026-10-31 要求「过多可以计算久一点」)。
|
|
2236
2308
|
todaySessionLimit: TODAY_MAX_SESSIONS,
|
|
2237
2309
|
statsCacheSec: 300, // 统计结果缓存秒数
|
|
2310
|
+
// 聚合缓存(balance-session-usage.json)最多存多少条。会话多 / 扫描上限调得大时调高,
|
|
2311
|
+
// 代价只是那个 JSON 变大(每条约 2.3 KB)。见 aggCacheLimit。
|
|
2312
|
+
aggCacheMax: AGG_CACHE_MAX,
|
|
2238
2313
|
// 计费
|
|
2239
2314
|
// 高峰时段窗口。官方当前是「工作日北京 9-12、14-18」,但这条也是会变的
|
|
2240
2315
|
// (改了时段就等于改了哪几个小时翻倍)。写成文本而不是数组:输入框直接对应,
|
|
@@ -2369,6 +2444,7 @@ function normalizeSettings(raw) {
|
|
|
2369
2444
|
statsSessionLimit: clampNumber(src.statsSessionLimit, 10, 2000, d.statsSessionLimit),
|
|
2370
2445
|
todaySessionLimit: clampNumber(src.todaySessionLimit, 10, 2000, d.todaySessionLimit),
|
|
2371
2446
|
statsCacheSec: clampNumber(src.statsCacheSec, 0, 3600, d.statsCacheSec),
|
|
2447
|
+
aggCacheMax: clampNumber(src.aggCacheMax, 100, AGG_CACHE_HARD_MAX, d.aggCacheMax),
|
|
2372
2448
|
peakWindowsText: normalizePeakWindowsText(src.peakWindowsText, d.peakWindowsText),
|
|
2373
2449
|
peakMultiplier: clampNumber(src.peakMultiplier, 1, 10, d.peakMultiplier),
|
|
2374
2450
|
priceFlash: normalizePriceOverride(src.priceFlash),
|
|
@@ -2393,6 +2469,7 @@ function withSettings(config, settings) {
|
|
|
2393
2469
|
statsSessionLimit: s.statsSessionLimit,
|
|
2394
2470
|
todaySessionLimit: s.todaySessionLimit,
|
|
2395
2471
|
statsCacheMs: s.statsCacheSec * 1000,
|
|
2472
|
+
aggCacheMax: s.aggCacheMax,
|
|
2396
2473
|
// ⚠️ 这四个原来只存在于 settingsState 里,没进 effectiveConfig —— 于是
|
|
2397
2474
|
// `effectiveConfig.refreshIntervalSec` 之类全是 undefined,诊断报告的「设置」段
|
|
2398
2475
|
// 印成「轮询 undefined 统计缓存 undefined 低余额阈值 undefined 高峰 undefined × 2」
|
|
@@ -3308,7 +3385,7 @@ async function buildTodayCost(ctx, config, reuse = null, dayStartOverride = null
|
|
|
3308
3385
|
// 替刚离开的那个大会话重新解压 65 MB 纯属白烧 CPU,还会把用户正看的那个对话拖住。
|
|
3309
3386
|
// ⚠️ 跳过得记账(`skipped += 1`),否则这个会话的今日贡献会变成「0 且看起来正常」——
|
|
3310
3387
|
// 那正是 2.1.9 修过的假 0,`suspiciousEmpty` / 不落盘全靠这个计数兜住。
|
|
3311
|
-
const inspected = await inspectPersistedCached(ctx, sessionId,
|
|
3388
|
+
const inspected = await inspectPersistedCached(ctx, sessionId, sessionRereadMinMs(sessionId), {
|
|
3312
3389
|
yieldWhenStale: true,
|
|
3313
3390
|
});
|
|
3314
3391
|
if (inspected === PERSIST_STALE_SKIPPED) {
|
|
@@ -4040,7 +4117,9 @@ async function sumSubagentUsageUncached(ctx, sessionId, config) {
|
|
|
4040
4117
|
const stamp = String(childStamps.get(id) ?? childStamps.get(`session-${id}`) ?? "");
|
|
4041
4118
|
let u = (getAggCache(id, stamp, config) ?? null)?.usage ?? null;
|
|
4042
4119
|
if (u === null) {
|
|
4043
|
-
|
|
4120
|
+
// 子会话(队友 / 子代理)同样按体量自适应:fork 出来的队友日志就是父会话全量副本,
|
|
4121
|
+
// 常常比父会话还大。用同一个 sessionRereadMinMs 走同一套上下限。
|
|
4122
|
+
const inspected = await inspectPersistedCached(ctx, id, sessionRereadMinMs(id));
|
|
4044
4123
|
const events = Array.isArray(inspected?.events) ? inspected.events : [];
|
|
4045
4124
|
// ⚠️ fork 出来的子会话(智能体团队的 context:"fork" 队友、subagent_fork)**整段继承
|
|
4046
4125
|
// 了父会话的事件前缀**(buildForkSeed 直接把源事件 slice 复制进新日志),
|
|
@@ -5192,6 +5271,7 @@ let statsInFlight = null;
|
|
|
5192
5271
|
if (sessionDiag !== null) {
|
|
5193
5272
|
sessionDiag.aggCache = aggHit !== null ? "hit" : "miss";
|
|
5194
5273
|
sessionDiag.aggEntries = aggCache.size;
|
|
5274
|
+
sessionDiag.aggLimit = aggCacheLimit(effectiveConfig);
|
|
5195
5275
|
sessionDiag.stamp = stamp;
|
|
5196
5276
|
}
|
|
5197
5277
|
if (aggHit !== null) {
|
|
@@ -5213,9 +5293,9 @@ let statsInFlight = null;
|
|
|
5213
5293
|
throw SESSION_FOCUS_DROPPED;
|
|
5214
5294
|
}
|
|
5215
5295
|
if (sessionDiag !== null) sessionDiag.focusDropped = false;
|
|
5216
|
-
let persisted = await inspectPersistedCached(ctx, persistedId,
|
|
5296
|
+
let persisted = await inspectPersistedCached(ctx, persistedId, sessionRereadMinMs(persistedId));
|
|
5217
5297
|
if ((persisted == null || !Array.isArray(persisted.events) || persisted.events.length === 0) && persistedId !== sessionParam) {
|
|
5218
|
-
persisted = await inspectPersistedCached(ctx, sessionParam,
|
|
5298
|
+
persisted = await inspectPersistedCached(ctx, sessionParam, sessionRereadMinMs(sessionParam));
|
|
5219
5299
|
}
|
|
5220
5300
|
if (sessionDiag !== null) {
|
|
5221
5301
|
sessionDiag.persisted = {
|