@angelyeye/dsh-cost-tracker 1.9.2 → 1.9.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,137 @@
2
2
 
3
3
  本文件用中文记录 dsh-cost-tracker 的版本变更。
4
4
 
5
+ ## v1.9.4(2026-09-24)
6
+
7
+ **修复「配额查询不可用:火山方舟配额响应不是合法 JSON(GetCodingPlanUsage)」—— 宿主全局 fetch 被 undici 包污染后不解压 gzip,插件改为自带解压兜底**
8
+
9
+ ### 一、根因(已在本机复现并定位到机制)
10
+
11
+ DSH 宿主进程里只要有插件 `import` 了 **npm 的 `undici` 包**,Node **内置 `fetch`** 就不再解压
12
+ gzip:响应**既没有 `content-encoding`,正文也是原始压缩字节**。本机引入方:`dshmarket/lib/net.js`
13
+ (静态 import)、`dsh-http-proxy` 与 `dsh-web-fetch-http`(动态 import)。
14
+
15
+ 矩阵实测(同一进程、同一凭据、真实接口):
16
+
17
+ | 阶段 | npmjs `/latest` | 火山 `GetCodingPlanUsage` |
18
+ | --- | --- | --- |
19
+ | 纯 Node(未 import undici) | 200 · `ce=gzip` · 3055B · JSON OK | 200 · `ce=gzip` · 560B · 解析 OK(三档窗口) |
20
+ | `await import('undici')` 之后(不装 dispatcher 也一样) | 200 · `ce=null` · 1506B · **原始 gzip(`1f8b`)· FAIL** | 200 · `ce=null` · 326B · **原始 gzip · FAIL** |
21
+
22
+ 两条现场症状同源:
23
+ - 本插件配额面板:`safeFetch` → 全局 fetch → 拿到压缩字节 → `JSON.parse` 失败 → 面板报
24
+ 「配额查询不可用:火山方舟配额响应不是合法 JSON(GetCodingPlanUsage)」;
25
+ - 插件市场把所有包的新版本读成 `null`(它的 `marketFetch` 在无代理时回退的也是全局 fetch,
26
+ 日志里的 `… is not valid JSON` 就是同一形态的乱码)。
27
+
28
+ 补充对照:`web_fetch` 工具一直正常,因为它用的是 undici 包自己的 `fetch`(解压正常);
29
+ `content-encoding: gzip` 存在时同样会中招 —— 关键在「谁解压」,不在响应长什么样。
30
+
31
+ ### 二、修法(两层,都在 `credstore.js` 的出站封套里,对调用方透明)
32
+
33
+ 1. **请求侧**:`safeFetch` 默认补 `accept-encoding: identity`,从源头要未压缩正文
34
+ (调用方显式指定过就尊重调用方);
35
+ 2. **响应侧**:新增 `decodeCompressedBody()` + `withDecodedBody()`,按**字节**判断(gzip `1f8b`、
36
+ zlib `78xx`、响应头明说的 `br`/`deflate`)自行解压,绝不只看响应头 —— 服务端忽略 `identity`
37
+ 时同样能正确解析;解压异常一律**原样返回**,不因为猜测丢内容。
38
+ `withDecodedBody()` 只实现调用方真正用到的成员(`status`/`ok`/`url`/`redirected`/`headers`/
39
+ `text`/`json`/`arrayBuffer`),正文只读取一次并缓存,且对「只有 `text()` 的 fetch 替身」保持兼容。
40
+
41
+ 影响面:插件全部出站请求都走 `safeFetch`(火山配额、Kimi 配额、云端同步与读取、官方定价页抓取),
42
+ 因此这一处修复同时给这些路径兜住了同一个坑。
43
+
44
+ ### 三、验证
45
+
46
+ - 真机端到端(先 `import('undici')` 污染进程,再走 `index.js` 的真实接线):
47
+ - 旧行为(裸全局 fetch)→ 报出与用户完全一致的错误;
48
+ - 修复后(`safeFetch` + 白名单)→ `action=GetCodingPlanUsage`,三档窗口
49
+ `fiveHour / weekly / monthly` 全部解析(实测 100% / 27.08% / 14.77%);
50
+ - `test/credstore.test.js` 新增 [5]:坏宿主(无 `content-encoding` 的 gzip 正文)可解析、
51
+ 健康宿主(头写 gzip 但正文已解压)不二次解压、deflate 兜底、纯文本替身兼容、
52
+ 非压缩内容原样返回、`accept-encoding` 默认值与调用方覆盖;
53
+ - `test/volcengine-host.test.js` 新增 [6]:端到端 —— 宿主返回未解压 gzip 时配额路由仍 `ok:true`、
54
+ 三档窗口齐全、百分比不被放大、请求确带 `accept-encoding: identity`;
55
+ - 全量 18 个测试文件通过。
56
+
57
+ ### 四、说明
58
+
59
+ - 这是**环境韧性**修复,不改变任何计费/同步口径:HTTP 面、配置键、落盘路径、云端契约零改动;
60
+ - 需要重启 `dsh web` 才生效(改动在宿主半端 `index.js`/`credstore.js`);
61
+ - 插件市场那条不属于本插件可控范围(其自身回退路径同样依赖全局 fetch),
62
+ 可在 `dshmarket` 侧改为始终使用 undici 包的 fetch 或自行解压;本插件侧的同类风险已消除。
63
+
64
+ ## v1.9.3(2026-09-24)
65
+
66
+ **适配 DSH 0.1.7-alpha.2:配置入口内迁到「花费统计」页头齿轮(带返回键),旧插件配置卡片入口保留兼容**
67
+
68
+ ### 一、背景:新宿主上原配置入口已经消失
69
+
70
+ - DSH `0.1.7-alpha.2` **删除了 `settings.plugin.item` 插槽**(在 0.1.7-alpha.2 全部宿主包的 JS 里该字符串零命中),
71
+ 原「设置 → 插件 → 插件配置」页由 `dsh-client-ui-settings-plugins` 承担,现在该分区只托管
72
+ `settings.plugins.tab`,唯一贡献者是**只读清单** `dsh-client-ui-settings-plugin-inventory`
73
+ (只显示完整名称 / 配置状态 / 启用于),**没有任何表单**;
74
+ - 同时 `dsh-settings` 的 `installSection` 也已下线(grep 零命中),即 `index.js` 的
75
+ `installSettingsSection()` 现在只会静默返回 false;配置值实际只来自
76
+ `~/.dsh/storages/cost-tracker-config.json` + 插件自己的 `/api/cost-tracker/*` —— 所以修复完全落在客户端;
77
+ - 结论:v1.9.2 及更早版本在新宿主上「设置 → 插件 → 插件配置」里**再也看不到本插件的配置卡片**,
78
+ 而插件的配置又只在那张卡片里 —— 用户实际上失去了全部设置入口(本次修复的动机)。
79
+
80
+ ### 二、改法:配置 UI 内迁到本插件自己的设置分区
81
+
82
+ - 新增 `CostSection`(`settings.section` 的渲染函数):持有 `view`(`dashboard` / `config`)与 `ui` 快照
83
+ (`peak` 轮询 + `UI_EVENT` 监听,从原 `DashGate` 上移,看板与配置页共用同一快照);
84
+ - `Dashboard` 页头 `.cost-h1` 右侧新增**齿轮按钮** `button.cost-gear`(自绘齿轮图标、`aria-label="花费统计设置"`、
85
+ `title` 同文案,不带可见文字);点击进入配置页;
86
+ - 配置页 = `ConfigPanel({ mode: "page" })`:根节点 `div.cost-wrap.cost-cfg-page`,
87
+ 页头为 **返回键** `button.cost-back`(‹ 图标 + 「返回」+ `aria-label="返回花费统计看板"`)
88
+ + 标题「花费统计 · 设置」+ 兼容说明;正文**常驻展开**(无外层折叠),
89
+ 顶部状态条与七个折叠分组(多机汇总 / 峰谷计价与提示 / 订阅套餐与配额 / 计价与价格目录 /
90
+ 历史导入 / 数据与界面 / 安全与凭据)与各分组动作**逐项不变**;
91
+ - **为什么是分区内子视图而不是第二个左侧导航项**:宿主设置外壳渲染分区时只传入 `close`
92
+ (`dsh-client-ui-settings-general` 的 `renderSlot('settings.section', { close }, { only: active })`),
93
+ 分区没有任何程序化切换导航的能力;`settings.section` 的 label 与 order 也只能在注册时决定;
94
+ - **关闭看板不再可能成为死亡入口**:`uiDashboardEnabled=false` 时仍渲染页头 + 齿轮,
95
+ 只把统计内容换成「点右上角齿轮 → 数据与界面 → 打开」的指引(原卡片入口在新宿主上已不存在,
96
+ 这条护栏是必须的)。
97
+
98
+ ### 三、兼容:`settings.plugin.item` 卡片入口保留
99
+
100
+ - 注册**原样保留**(`slots.inject(pluginItemKey, ...)` 无条件注入,未声明该插槽时回调不触发 ⇒ 零成本);
101
+ 仍声明它的旧宿主(`dsh < 0.1.7-alpha.2`)照旧显示卡片;
102
+ - 两个入口**共用同一个 `ConfigPanel`**(`mode: "card"` 折叠卡片外壳 / `mode: "page"` 配置页外壳),
103
+ 正文同一段渲染 ⇒ 字段、字典、校验、写接口不可能漂移;两处的未保存草稿各自独立;
104
+ - 卡片外壳(`li.cost-pcard` > `button.cost-pcard-head` > 折叠 body、默认收起、`aria-expanded`)
105
+ 与 `.cost-pcard*` 样式**逐字未改**,原有卡片测试原样通过(`client-render` 的 [3] 组断言未动)。
106
+
107
+ ### 四、文案路径统一
108
+
109
+ - 插件内与 HTTP/Agent 错误里的路径统一为「设置 → 花费统计 → 右上角齿轮 → 分组名」:
110
+ `client.js`(峰谷只读面板、云端同步只读卡、看板关闭提示、云端未配置提示、令牌失效提示)、
111
+ `index.js`(`NOT_CONFIGURED`、共享引导令牌失效)、`sync.js`(`TOKEN_INVALID` message);
112
+ - 注释同步更新(`config.js`、`pricing.js`、`vendor-catalog.js`、`index.js`、`schema.js` 相关段),
113
+ 旧宿主兼容路径只在配置页页脚与 README 里说明。
114
+
115
+ ### 五、测试
116
+
117
+ - `test/client-render.test.js`:新增 **[3b] 齿轮入口**(齿轮存在 / 可访问名 / 图标 / 挂在页头操作位 /
118
+ 点击进入配置页 / 页头有返回键 / 七个分组齐 / 两视图互斥 / 点返回回到看板)与
119
+ **[3c] 两入口一致性**(配置页与兼容卡片的分组标题、状态摘要、关键字段集合必须相同);
120
+ [8] 组新增「关闭态仍渲染齿轮 → 点击进入配置页 → 能重新打开看板」的完整闭环;
121
+ 原 [3] 卡片外壳断言保持不变(兼容入口的护栏);
122
+ - `test/ui-display.test.js`:关闭提示断言改为指向齿轮,新增「分区内配置入口不受三个界面开关控制」
123
+ 「齿轮挂在页头操作位」两条;[5] 改为断言四个插槽无条件注册(含兼容卡片);
124
+ - `test/client-registration.test.js`:[6] 组扩充为「两种外壳来自同一个 ConfigPanel」
125
+ 「齿轮与返回键都在(图标 + 可访问名)」「settings.section 渲染的是 CostSection 而不是直接渲染看板」;
126
+ - 全量 18 个测试文件通过。
127
+
128
+ ### 六、行为差异与注意
129
+
130
+ - **从配置页点「返回」会丢弃未点保存的草稿**(每个分组仍是「改草稿 → 点该组保存」;
131
+ 折叠分组之间的切换不丢草稿,与卡片折叠语义一致);
132
+ - 切换左侧设置分区 / 关闭设置面板时组件卸载,下次进入回到看板视图(宿主只挂载当前分区);
133
+ - 本次为**纯客户端 UI 重组**:HTTP 面、配置键、落盘路径、云端契约(`dsh-cost-cloud`)、
134
+ 计费/定价/导入/同步逻辑**零改动**,老配置零迁移。
135
+
5
136
  ## v1.9.2(2026-09-20)
6
137
 
7
138
  **定价口径修正:V4-Pro 不再路由到 Flash(官方撤销下线计划)+ 新增「法定节假日全天闲时」**
package/README.en.md CHANGED
@@ -206,7 +206,7 @@ cp .env.example .env # fill SESSION_SECRET and ADMIN_PASSWORD_HASH (node sc
206
206
  docker compose up -d # open http://<server>:8787 and generate a shared bootstrap token under Settings
207
207
  ```
208
208
 
209
- **Configure each device**: open **Settings → Plugins → Plugin configuration → Cost Tracker** and fill in:
209
+ **Configure each device**: open **Settings → Cost Tracker → gear icon (top right)** → "Multi-machine aggregation (cloud sync)" and fill in:
210
210
 
211
211
  | Field | Meaning |
212
212
  | --- | --- |
@@ -235,22 +235,34 @@ The dimension selector adds per-device / per-agent / per-model breakdowns and a
235
235
 
236
236
  ### Interface visibility (v1.8.12, optional)
237
237
 
238
- Don't want the plugin in your face? **Settings → Plugins → Plugin configuration → Cost Tracker → Interface visibility** has three independent switches that apply **the moment you tick them** (no Save, no `dsh` restart):
238
+ Don't want the plugin in your face? **Settings → Cost Tracker → gear icon (top right) → Data & interface → Interface visibility** has three independent switches that apply **the moment you tick them** (no Save, no `dsh` restart):
239
239
 
240
240
  | Switch | What turning it off does |
241
241
  | --- | --- |
242
242
  | Composer cost pill | the per-session cost / model breakdown above the chat input disappears |
243
243
  | Sidebar peak bar | the phase / countdown strip at the bottom of the sidebar disappears (the peak-switch popup and web notifications go with it; if you only want the reminder without the strip, use the notice switch under "Peak/off-peak pricing & notices" instead) |
244
- | Settings dashboard | the "Cost Tracker" entry disappears from the Settings nav (accounting and cloud sync keep running; the page then shows a one-line hint on how to bring it back) |
244
+ | Settings dashboard | the Settings nav entry keeps a one-line hint on how to bring the dashboard back (accounting and cloud sync keep running) |
245
245
 
246
246
  - **Display only**: accounting, persistence, cloud sync and the agent tools (`cost_stats` etc.) are unaffected;
247
- - **The plugin configuration card itself is never hidden by these switches** — otherwise you would have no way to turn them back on;
247
+ - **The configuration entry itself is never hidden by these switches** — the header gear always stays (old hosts also keep the plugin configuration card), otherwise you would have no way to turn them back on;
248
248
  - Truth value is "hidden only on an explicit `false`", so a missing key means visible: **an existing config file looks exactly the same after upgrading**;
249
249
  - All three keys live in the same `~/.dsh/storages/cost-tracker-config.json` (`uiDockEnabled` / `uiPeakEnabled` / `uiDashboardEnabled`) and never overwrite the peak/cloud fields.
250
250
 
251
- ### Plugin configuration card (v1.9.0 redesign: the single place for every setting)
251
+ ### Settings entry (v1.9.3: the gear in the Cost Tracker header; the only entry on new hosts)
252
252
 
253
- **Settings → Plugins → Plugin configuration → Cost Tracker** now carries **all** settings, laid out as collapsible groups under a status strip (cloud sync / records stored / pending / last sync / pricing era / history import / amount basis):
253
+ **Settings → Cost Tracker → gear icon at the top right** (icon button, tooltip "花费统计设置") opens the configuration page; the **back** control at its top-left returns to the dashboard.
254
+
255
+ | Entry | Host versions | Shape |
256
+ | --- | --- | --- |
257
+ | **Header gear → configuration page** (v1.9.3, recommended) | all versions | Settings → Cost Tracker → gear; the page is fully expanded, back control at the top left |
258
+ | **Plugin configuration card** (v1.9.0, kept for compatibility) | only hosts that still declare `settings.plugin.item` (`dsh < 0.1.7-alpha.2`) | Settings → Plugins → Plugin configuration → Cost Tracker; collapsed by default, click the header to expand |
259
+
260
+ > DSH `0.1.7-alpha.2` removed the `settings.plugin.item` slot (the Built-in plugins section became a read-only inventory),
261
+ > so the card no longer shows on new hosts. The registration is **kept** (an undeclared slot simply never fires, so it costs
262
+ > nothing) and old hosts keep working. Both entries share **one configuration component**, so fields, validation and write
263
+ > paths are identical — only the shell differs; unsaved drafts are independent, just edit wherever you are.
264
+
265
+ The configuration page carries **all** settings, laid out as collapsible groups under a status strip (cloud sync / records stored / pending / last sync / pricing era / history import / amount basis):
254
266
 
255
267
  | Group | Contents |
256
268
  | --- | --- |
@@ -328,6 +340,46 @@ Example: `curl -X POST http://127.0.0.1:3080/api/cost-tracker/summary -d '{}'`
328
340
 
329
341
  > Highlights only — the full version-by-version history lives in [`CHANGELOG.md`](./CHANGELOG.md) (Chinese).
330
342
 
343
+ ### v1.9.4 (2026-09-24)
344
+
345
+ **Fix "Volcengine Ark quota response is not valid JSON": the host's global fetch stops decompressing gzip once the `undici` package is loaded, so the plugin now decodes bodies itself**
346
+
347
+ - **Root cause (reproduced locally)**: as soon as any plugin in the host process imports the npm `undici`
348
+ package (`dshmarket` does it statically here; `dsh-http-proxy` / `dsh-web-fetch-http` dynamically), Node's
349
+ **built-in** `fetch` no longer decompresses gzip — the response has no `content-encoding` and the body is
350
+ raw compressed bytes (measured: 560 B of plain JSON without the import, 326 B starting with `1f 8b` with it).
351
+ `JSON.parse(await res.text())` therefore always fails, which is exactly the quota-panel error; **the plugin
352
+ market reading every package's latest version as `null` shares the same root cause** (its no-proxy fallback
353
+ also uses the global fetch);
354
+ - **Fix (two layers, transparent to callers)**: `safeFetch` now sends `accept-encoding: identity` to ask for
355
+ uncompressed bodies, and after receiving the body it decompresses by **bytes** (gzip `1f8b` / zlib `78xx` /
356
+ `br`, `deflate` when the header says so); any decompression failure returns the original bytes untouched.
357
+ Every plugin egress (Volcengine/Kimi quota, cloud sync and reads, official pricing-page fetch) goes through
358
+ this wrapper, so all of them are covered;
359
+ - **Verification**: live end-to-end — with the process polluted by `import('undici')` the old path reproduces
360
+ the exact error, while the fixed path returns the three real windows (100% / 27.08% / 14.77%); new
361
+ `credstore` [5] and `volcengine-host` [6] regressions; all 18 test files pass;
362
+ - **Takes effect** after a `dsh web` restart (host-half change).
363
+
364
+ ### v1.9.3 (2026-09-24)
365
+
366
+ **DSH 0.1.7-alpha.2 support: the configuration entry moved into the Cost Tracker page (gear icon + back control); the old card entry is kept for compatibility**
367
+
368
+ - **Why**: DSH `0.1.7-alpha.2` removed the `settings.plugin.item` slot (the old Settings → Plugins → Plugin configuration page);
369
+ the Built-in plugins section is now a read-only inventory, and `dsh-settings` no longer exposes `installSection` — so the
370
+ plugin's configuration card could never render on the new host;
371
+ - **What**: the configuration UI now lives inside the plugin's own settings section —
372
+ **Settings → Cost Tracker → gear icon (top right)** opens the configuration page, whose **back** control returns to the
373
+ dashboard. The seven collapsible groups, the status strip and every per-group action (Save / Test / Sync now / price sync /
374
+ history import …) are unchanged;
375
+ - **Why an in-page switch instead of a second nav entry**: the host settings shell renders a section with `close` only
376
+ (`renderSlot('settings.section', { close }, { only: active })`), so a section has no way to navigate the shell;
377
+ - **Compatibility**: the `settings.plugin.item` registration is **kept** — on 0.1.7+ the slot does not exist, so the callback
378
+ never fires (zero cost), while older hosts keep showing the card. Both entries share one `ConfigPanel` (only the shell
379
+ differs), so fields, validation and write paths are identical; unsaved drafts stay independent;
380
+ - **No more dead end**: when the dashboard is turned off, the header and gear remain, with a one-line hint pointing to
381
+ "Data & interface → Settings dashboard" (the old card entry no longer exists on new hosts, so this guard is required).
382
+
331
383
  ### v1.9.2 (2026-09-20)
332
384
 
333
385
  **Pricing correction: V4-Pro is no longer routed to Flash (official retirement plan revoked) + statutory holidays are now off-peak**
@@ -570,6 +622,15 @@ Example: `curl -X POST http://127.0.0.1:3080/api/cost-tracker/summary -d '{}'`
570
622
 
571
623
  ## FAQ
572
624
 
625
+ **Q: The quota panel says "Volcengine Ark quota response is not valid JSON (GetCodingPlanUsage)" — what now?**
626
+ Upgrade to **v1.9.4 or later** and restart `dsh web`. The cause is neither Volcengine nor your credentials:
627
+ once any plugin in the host process does `import('undici')` (on this machine `dshmarket` does), Node's
628
+ **built-in `fetch`** stops decompressing gzip — the response carries no `content-encoding` and the body is
629
+ raw compressed bytes, so `JSON.parse` always fails. From v1.9.4 the plugin decompresses bodies itself
630
+ inside its outbound wrapper and asks for `accept-encoding: identity` by default, so it is immune.
631
+ Related: **the plugin market showing no updates (every package "up to date") has the same root cause**, but
632
+ that path is owned by `dshmarket` itself and needs a fix there.
633
+
573
634
  **Q: Where is my data? Is it safe?**
574
635
  Everything stays on your machine in `~/.dsh/storages/cost-tracker-records.json`; nothing is uploaded. The API binds to loopback but has no authentication — **do not expose the DSH port to the public internet**.
575
636
 
@@ -592,7 +653,7 @@ Quota is read from the Ark **control-plane** OpenAPI (`open.volcengineapi.com`,
592
653
  1. Volcengine console → **IAM → Users → Keys**, create an AccessKeyID / SecretAccessKey pair;
593
654
  2. Grant that sub-user **`ArkReadOnlyAccess`** and **`BillingCenterReadOnlyAccess`** (read-only is enough to query usage);
594
655
  3. Let the plugin obtain the pair (any one of these, in priority order):
595
- - fill in **Volcengine AccessKeyID / SecretAccessKey** under **Settings → Plugins → Plugin config → Cost Tracker** (the secret is never echoed back); or
656
+ - fill in **Volcengine AccessKeyID / SecretAccessKey** under **Settings → Cost Tracker → gear icon → Subscriptions & quota** (the secret is never echoed back); or
596
657
  - put them in the `refs:` section of `~/.dsh/.credentials.yaml` under `VOLC_ACCESSKEY` / `VOLC_SECRETKEY` (variants such as `VOLCENGINE_ACCESS_KEY_ID` and `ARK_ACCESS_KEY_ID` also work); or
597
658
  - export them as environment variables with the same names.
598
659
 
package/README.md CHANGED
@@ -29,8 +29,8 @@
29
29
  | | 功能 | 说明 |
30
30
  | --- | --- | --- |
31
31
  | 💰 | **花费统计** | 每一次 API 调用自动记账:输入 / 输出 / 缓存命中 / 缓存写入 Tokens 与费用(缓存写入按缓存命中价计),按天、按模型聚合 |
32
- | ⏰ | **峰谷定价** | 内置单价表,高峰时段(北京时间周一至周五 9:00–12:00、14:00–18:00,**不含中国法定节假日**)与闲时半价自动区分,**周末与法定节假日全天计为闲时**(节假日表 2026 全年 33 天,可在配置卡覆盖/停用;调休补班的周六周日不计高峰),本地模型(ollama 等)计 0;**单价表按「计费时代」分版**(`legacy` / `v41`),北京时间 2026-09-10 12:00 起自动切换为 V4.1 Flash 新价(2.0 / 0.04 / 8.0 高峰),并按官方脚注把旧 V4-Flash 系请求路由到 V4.1 Flash 计费;**`deepseek-v4-pro` 维持自有牌价 9.0 / 27.0 / 0.30 不做路由**(官方 2026-09-14 撤销了下线计划) |
33
- | 🔔 | **峰谷计价提示** | **设置 → 插件 → 插件配置 → 花费统计 → 峰谷计价与提示**(v1.9.0 起设置集中在此,改完即可预览):当前档位/距下次切换倒计时时段条、样式切换(**简洁单行·按24h比例** / **环形表盘·相位色点**)、简洁样式可选**双行紧凑**(上下布局,条上文下/文上条下)、「显示时间」开关、峰/谷切换前弹窗提醒与浏览器系统通知、提前提醒分钟、弹窗位置(右下角/屏幕中心)、提醒类型;侧边栏底部常驻显示时段条(窄栏/展开自适应)。看板上的同名面板改为只读回显 |
32
+ | ⏰ | **峰谷定价** | 内置单价表,高峰时段(北京时间周一至周五 9:00–12:00、14:00–18:00,**不含中国法定节假日**)与闲时半价自动区分,**周末与法定节假日全天计为闲时**(节假日表 2026 全年 33 天,可在配置页覆盖/停用;调休补班的周六周日不计高峰),本地模型(ollama 等)计 0;**单价表按「计费时代」分版**(`legacy` / `v41`),北京时间 2026-09-10 12:00 起自动切换为 V4.1 Flash 新价(2.0 / 0.04 / 8.0 高峰),并按官方脚注把旧 V4-Flash 系请求路由到 V4.1 Flash 计费;**`deepseek-v4-pro` 维持自有牌价 9.0 / 27.0 / 0.30 不做路由**(官方 2026-09-14 撤销了下线计划) |
33
+ | 🔔 | **峰谷计价提示** | **设置 → 花费统计 → 右上角齿轮 → 峰谷计价与提示**(v1.9.0 起设置集中在此,改完即可预览;DSH 0.1.7-alpha.2 起入口在「花费统计」页头的齿轮,v1.9.3):当前档位/距下次切换倒计时时段条、样式切换(**简洁单行·按24h比例** / **环形表盘·相位色点**)、简洁样式可选**双行紧凑**(上下布局,条上文下/文上条下)、「显示时间」开关、峰/谷切换前弹窗提醒与浏览器系统通知、提前提醒分钟、弹窗位置(右下角/屏幕中心)、提醒类型;侧边栏底部常驻显示时段条(窄栏/展开自适应)。看板上的同名面板改为只读回显 |
34
34
  | 📌 | **六组概览卡** | 设置页顶部六张卡:今日费用 / 本月费用 / 总花费 / API 请求次数 / Tokens / **总余额**。前三个金额卡**不含订阅会员等效费用**,订阅以附注展示 |
35
35
  | 👁️ | **视觉模型** | 支持 `deepseek-v4-flash-vision-exp`:legacy 时代单价与 flash 一致,2026-09-10 12:00 起随 V4.1 Flash 新价计费(该旧名已下线,请求由 V4.1 Flash 提供);图片按官方规则换算 token(每张上限 384 个,以接口用量计费) |
36
36
  | 🏷️ | **官方模型名对齐** | 计费支持**官方现役名 `deepseek-flash`**(价格卡脚注 (1):「模型名请使用 `deepseek-flash`」),旧写法 `deepseek-v4.1-flash` 等归一化后命中同一档价,避免因官方改名而落入兜底估算 |
@@ -41,7 +41,7 @@
41
41
  | 💳 | **余额查询** | 一键查询 DeepSeek 官方账户余额(总余额 / 充值 / 赠送 / 状态) |
42
42
  | 🤖 | **Agent 工具** | 直接在对话里问:"我现在花了多少钱?"——Agent 会调用 `cost_stats` / `cost_prices` 等工具回答 |
43
43
  | 🔻 | **状态栏** | 聊天输入框下方实时显示:**本会话花费**(胶囊分段:本会话 / 订阅套餐 / 分模型),按会话实际用到的模型与订阅拆分,**多模型默认折叠只显示 top2,点击展开全部明细**;订阅显示具体套餐名,不再展示配额与调用次数 |
44
- | 👁️ | **界面显示开关** | 输入框上方的花费胶囊、侧边栏峰谷时段条、设置页「花费统计」看板**三个落点各自可关**(设置 → 插件 → 插件配置 → 花费统计 → 界面显示),勾选即刻生效;**只影响显示**,记账、云端同步与 Agent 工具照常,配置卡片本身不受开关控制 |
44
+ | 👁️ | **界面显示开关** | 输入框上方的花费胶囊、侧边栏峰谷时段条、设置页「花费统计」看板**三个落点各自可关**(设置 → 花费统计 → 右上角齿轮 → 数据与界面 → 界面显示),勾选即刻生效;**只影响显示**,记账、云端同步与 Agent 工具照常,配置入口(齿轮页)本身不受开关控制 |
45
45
  | 💾 | **本地持久化** | 数据存本机 `~/.dsh/storages/cost-tracker-records.json`,重启不丢、不上传;**明细保留最近 180 天,更早自动压缩为永久日汇总,全时段统计永远精确且内存/磁盘有界** |
46
46
  | 🕰️ | **历史导入(v1.9.0)** | 回放宿主会话日志,**把装插件之前的对话调用补录进账本**(按各自时间戳的旧价计费);只补插件不可能记到的部分(安装前 / 停机缺口),幂等可重复执行,导入记录标记 `source=import` 以便区分 |
47
47
  | 🔄 | **官方价格同步(v1.9.0)** | 一键抓取官方定价页、解析各模型峰价并对比差异,应用后构建**新的计费时代**(只影响之后,历史口径不回改);每日可自动核对(只提示、不自动应用),页面改版时宁可不同步也绝不写错价 |
@@ -64,7 +64,7 @@
64
64
 
65
65
  ![单个模型的请求次数面积图与 Tokens 堆叠图,悬停提示显示完整日期与分段数值](docs/screenshots/model-detail.png)
66
66
 
67
- > 📸 截图取自 v1.8.x 的看板;v1.9.0 起工具栏多了「含 Plan 总额」开关、插件配置卡片改为七个折叠分组(见「插件配置卡片」一节),概览卡与图表本身不变。
67
+ > 📸 截图取自 v1.8.x 的看板;v1.9.0 起工具栏多了「含 Plan 总额」开关、配置面板改为七个折叠分组(见「设置入口」一节),v1.9.3 起配置页由「花费统计」页头右上角齿轮进入(带返回键),概览卡与图表本身不变。
68
68
 
69
69
  ---
70
70
 
@@ -180,7 +180,7 @@ rm -rf ~/.dsh/profiles/node_modules/dsh-cost-tracker
180
180
  - **配色切换**:「按模型」视图下,消费金额标题旁有三套装色款条(橙→黄 / 蓝→紫 / 蓝→浅蓝)可切换;模型按总消费降序排名取色(第 1 名最深夜底、逐级变浅,不循环不撞色),选择保存在浏览器本地;
181
181
  - **分模型区块**:每个模型一张请求次数图 + 一张 Tokens 构成图(输入/缓存写入/输出/缓存命中);
182
182
  - **Token 用量统计热力图**:类 Codex 的 26 周每日用量方格,颜色深浅按当日 token 相对最大值分档;悬停任一格看该日明细(输入 / 缓存 / 输出 / 费用),今天高亮描边;**口径跟随三态开关**:「本机」只统计本机,「本机+云端」把云端按天用量并入(与上方卡片同一并集口径、不重复计数),「仅云端」只看云端,标题右侧标注当前口径。云端按天明细需要 `dsh-cost-cloud ≥ v1.3.2`,旧云端下自动退回本机口径;
183
- - **峰谷计价与提示**:时段条样式可选(**简洁单行·按 24h 比例**(白色实时进度线) / **环形表盘·相位色点**),简洁样式可选**双行紧凑**(条上文下 / 文上条下),可开关「显示时间」刻度(00:00–21:00),设置峰/谷切换前的弹窗提醒提前量(1–30 分钟)、提醒类型(两者 / 进入高峰 / 进入闲时)、弹窗位置(右下角 / 屏幕中心)与浏览器系统通知。**v1.9.0 起这些设置统一在「设置 → 插件 → 插件配置 → 花费统计 → 峰谷计价与提示」里改**(看板上的同名面板改为只读回显,只保留弹窗预览);侧边栏底部常驻时段条显示当前档位与下次切换倒计时;
183
+ - **峰谷计价与提示**:时段条样式可选(**简洁单行·按 24h 比例**(白色实时进度线) / **环形表盘·相位色点**),简洁样式可选**双行紧凑**(条上文下 / 文上条下),可开关「显示时间」刻度(00:00–21:00),设置峰/谷切换前的弹窗提醒提前量(1–30 分钟)、提醒类型(两者 / 进入高峰 / 进入闲时)、弹窗位置(右下角 / 屏幕中心)与浏览器系统通知。**v1.9.0 起这些设置统一在「设置 → 花费统计 → 右上角齿轮 → 峰谷计价与提示」里改**(v1.9.3 起入口为页头齿轮;看板上的同名面板改为只读回显,只保留弹窗预览);侧边栏底部常驻时段条显示当前档位与下次切换倒计时;
184
184
  - **含 Plan 总额开关(v1.9.0)**:工具栏右侧一个开关,决定金额卡与图表的口径 —— 关闭(默认)只算按量真金白银、订阅以附注展示;打开则金额 = 按量 + 订阅等值,图表按天并入「订阅等值」一段。选择存浏览器本地并回写服务端配置(跨设备一致);
185
185
  - **导出 CSV**:导出明细记录(近 180 天)+ 日汇总行(`purpose=rollup`)。
186
186
 
@@ -208,7 +208,7 @@ cp .env.example .env # 填 SESSION_SECRET 与 ADMIN_PASSWORD_HASH(node sc
208
208
  docker compose up -d # 打开 http://<服务器>:8787 ,在「设置」页生成共享引导令牌
209
209
  ```
210
210
 
211
- **在每台设备上配置**:打开 **设置 → 插件 → 插件配置 → 花费统计**,填写:
211
+ **在每台设备上配置**:打开 **设置 → 花费统计 → 右上角齿轮** → 「多机汇总(云端同步)」,填写:
212
212
 
213
213
  | 字段 | 说明 |
214
214
  | --- | --- |
@@ -233,26 +233,37 @@ docker compose up -d # 打开 http://<服务器>:8787 ,在「设置」页
233
233
  **其它 agent 也能接入**:云端的上报协议是开放的,任何 agent 的统计插件按 `dsh-cost-cloud` 仓库的 `docs/INGEST-API.md` 实现即可接入,云端无需改动,看板会自动出现新的 Agent 列。
234
234
  **关键约定**:同一台机器上的所有 agent 必须共用同一个 `machineId`(共享文件 `~/.dsh-cost/device.json`),否则会被统计成多台设备。
235
235
 
236
- **隐私**:只上报 token 数量、费用、时间戳与标识符(不涉及 prompt / 回复 / 文件内容);可在配置卡开启「会话脱敏」(`sessionId` 上报前替换为不可逆哈希)与「不含 purpose」。
236
+ **隐私**:只上报 token 数量、费用、时间戳与标识符(不涉及 prompt / 回复 / 文件内容);可在配置页开启「会话脱敏」(`sessionId` 上报前替换为不可逆哈希)与「不含 purpose」。
237
237
 
238
238
  ### 界面显示(v1.8.12,可选)
239
239
 
240
- 不想在界面上看到插件?**设置 → 插件 → 插件配置 → 花费统计 → 界面显示**里三个开关**各自独立**、**勾选即刻生效**(无需点「保存」,也无需重启 dsh):
240
+ 不想在界面上看到插件?**设置 → 花费统计 → 右上角齿轮 → 数据与界面 → 界面显示**里三个开关**各自独立**、**勾选即刻生效**(无需点「保存」,也无需重启 dsh):
241
241
 
242
242
  | 开关 | 关掉之后 |
243
243
  | --- | --- |
244
244
  | 输入框上方的花费胶囊 | 会话输入区不再显示本会话花费与模型明细 |
245
245
  | 侧边栏峰谷时段条 | 侧边栏底部的档位 / 倒计时消失(峰谷切换弹窗与系统通知一并停用;只想留提醒不想要时段条,请改用「峰谷计价与提示」里的提示开关) |
246
- | 设置页「花费统计」看板 | 设置页左侧不再出现该入口(记账与云端同步照常;关掉后该页只留一句重新打开的指引) |
246
+ | 设置页「花费统计」看板 | 设置页左侧的该入口只留一句重新打开的指引(记账与云端同步照常) |
247
247
 
248
248
  - **只影响显示**:记账、落盘、云端同步与 Agent 工具(`cost_stats` 等)全部照常工作;
249
- - **插件配置卡片本身不受这三个开关控制** —— 否则关掉之后就没有入口能再打开了;
249
+ - **配置入口本身不受这三个开关控制** —— 页头齿轮始终在(旧宿主还有插件配置卡片),否则关掉之后就没有入口能再打开了;
250
250
  - 取值为「只有显式 `false` 才隐藏」,缺省即显示。老配置文件里没有这几个键,**升级后界面与升级前一致**;
251
251
  - 落盘在同一份 `~/.dsh/storages/cost-tracker-config.json`(键名 `uiDockEnabled` / `uiPeakEnabled` / `uiDashboardEnabled`),与峰谷、云端字段互不覆盖。
252
252
 
253
- ### 插件配置卡片(v1.9.0 重设计:全部设置的唯一入口)
253
+ ### 设置入口(v1.9.3:花费统计页头齿轮;新宿主上的唯一入口)
254
254
 
255
- **设置 → 插件 → 插件配置 → 花费统计** 现在承载**全部**设置,按折叠分组排列,顶部一条状态摘要(云端同步 / 已记账条数 / 待上报 / 上次同步 / 计价时代 / 历史导入 / 金额口径):
255
+ **设置 → 花费统计 → 页头右上角齿轮**(图标按钮,悬浮提示「花费统计设置」)→ 配置页,左上角**返回键**回到看板。
256
+
257
+ | 入口 | 适用宿主 | 形态 |
258
+ | --- | --- | --- |
259
+ | **页头齿轮 → 配置页**(v1.9.3 起,推荐) | 全部版本 | 设置 → 花费统计 → 齿轮;配置页整页常驻展开,左上角返回键 |
260
+ | **插件配置卡片**(v1.9.0,兼容保留) | 仅仍声明 `settings.plugin.item` 的旧宿主(`dsh < 0.1.7-alpha.2`) | 设置 → 插件 → 插件配置 → 花费统计;卡片默认收起,点标题展开 |
261
+
262
+ > DSH `0.1.7-alpha.2` 删除了 `settings.plugin.item` 插槽(「内置插件」分区改为只读清单),卡片在新宿主上不显示;
263
+ > 插件侧的注册**保留**(插槽不存在时回调不触发,零成本),旧宿主照旧可用。两个入口**共用同一个配置组件**,
264
+ > 字段、校验、写接口完全一致,只是外壳不同;未保存草稿各自独立,就近改一处即可。
265
+
266
+ 配置页承载**全部**设置,按折叠分组排列,顶部一条状态摘要(云端同步 / 已记账条数 / 待上报 / 上次同步 / 计价时代 / 历史导入 / 金额口径):
256
267
 
257
268
  | 分组 | 内容 |
258
269
  | --- | --- |
@@ -264,13 +275,13 @@ docker compose up -d # 打开 http://<服务器>:8787 ,在「设置」页
264
275
  | **数据与界面** | 界面显示三开关(勾选即刻生效)、导出 CSV、重算费用(试算 / 写回)、清空数据(两步确认) |
265
276
  | **安全与凭据** | 云端令牌 / 火山 SK 的「是否已配置 + 存储位置」徽章、旧版明文迁移状态、清除按钮与出站防护说明 |
266
277
 
267
- 约定:**只有「界面显示」三开关是勾选即刻生效**(要立刻看到显隐结果),其余分组都是「改草稿 → 点该组保存」,避免误触即写盘;分组折叠只切显隐、不卸载内容,展开任一分组都不会重新取数或丢草稿。
278
+ 约定:**只有「界面显示」三开关是勾选即刻生效**(要立刻看到显隐结果),其余分组都是「改草稿 → 点该组保存」,避免误触即写盘;分组折叠只切显隐、不卸载内容,展开任一分组都不会重新取数或丢草稿。**从配置页点「返回」会丢弃未点保存的草稿**(点该组「保存」即落盘),各组之间互不影响。
268
279
 
269
280
  ### 历史导入(v1.9.0)
270
281
 
271
282
  装上插件之前的对话也能补进账本:插件回放宿主会话日志(`$DSH_HOME/sessions/<项目>/<会话>/session.v3.jsonl.zstd`,多 zstd frame 逐帧解压、逐帧切片),把其中的模型调用按**当时时间戳**的计费口径入账。
272
283
 
273
- - 默认**开机自动导入**(延迟 8 秒,不阻塞启动),也可在配置卡点「立即导入」或关掉自动(`autoImport`);
284
+ - 默认**开机自动导入**(延迟 8 秒,不阻塞启动),也可在配置页点「立即导入」或关掉自动(`autoImport`);
274
285
  - **只补「插件不可能记到」的调用**:早于本机最早一条实时记录,或所在日完全没有实时覆盖(停机缺口);
275
286
  - 跨安装点的会话按切割线截断:安装前那段补录,安装后那段以实时记录为准;
276
287
  - **幂等三保险**:清单按文件 mtime + size 快跳、逐调用键 `(sessionId, 时间戳, 五桶 tokens)` 去重、已被实时覆盖的日子宁可不导入也不重复计数;
@@ -278,7 +289,7 @@ docker compose up -d # 打开 http://<服务器>:8787 ,在「设置」页
278
289
 
279
290
  ### 官方价格同步与多厂商目录(v1.9.0)
280
291
 
281
- - **官方价格同步**:配置卡里点「核对官方价」抓取官方定价页(中文页直接给出人民币价),解析出各模型峰价并与当前生效价对比;点「应用新价」把结果构建为**新的计费时代** —— 只对生效时刻**之后**的记录生效,历史记录按各自时间戳选版,口径不回改。每日可自动核对(默认开,只提示差异,**绝不自动应用**)。解析器对页面改版 / 数字缺失 / 「空闲价 ≠ 高峰一半」一律抛错,宁可不同步也绝不写错价;
292
+ - **官方价格同步**:配置页里点「核对官方价」抓取官方定价页(中文页直接给出人民币价),解析出各模型峰价并与当前生效价对比;点「应用新价」把结果构建为**新的计费时代** —— 只对生效时刻**之后**的记录生效,历史记录按各自时间戳选版,口径不回改。每日可自动核对(默认开,只提示差异,**绝不自动应用**)。解析器对页面改版 / 数字缺失 / 「空闲价 ≠ 高峰一半」一律抛错,宁可不同步也绝不写错价;
282
293
  - **多厂商模型价格目录**:内置 14 家厂商 / 90 个模型条目(OpenAI / Anthropic / Google / Moonshot / z-ai / xAI / Alibaba / MiniMax / Tencent / Xiaomi / Upstage / NVIDIA / Mistral / OpenCode;数据改编自 `dsh-cost-meter` 的已核对官方目录,MIT),按 USD→CNY 汇率(默认 7.2,可改)折算。内置表之外的模型命中目录即记**精确价**(不再标「估算」);匹配模式可选宽松(归一化包含)或严格(名称全等);
283
294
  - **手动覆盖价**:`provider/model` → 输入 / 输出 / 缓存价,优先级最高,用于自建端点或议价套餐;
284
295
  - **计费优先级**:手动覆盖价 > 订阅归类(Plan)> 内置 / 同步时代精确价 > 多厂商目录 > provider 兜底 > 通用兜底。`cost_prices` 工具与 `/api/cost-tracker/prices` 会一并回显当前时代、同步时代、目录指纹与覆盖价;
@@ -318,7 +329,7 @@ POST /api/cost-tracker/prices-config 价格同步设置(定价页地址 / 每日
318
329
  POST /api/cost-tracker/import-status 历史导入状态
319
330
  POST /api/cost-tracker/import-run 执行一轮历史导入(幂等)
320
331
  POST /api/cost-tracker/import-config 历史导入设置(开机自动开关)
321
- POST /api/cost-tracker/reset 清空全部记录(配置卡两步确认后调用)
332
+ POST /api/cost-tracker/reset 清空全部记录(配置页两步确认后调用)
322
333
  POST /api/cost-tracker/export 导出 CSV
323
334
  ```
324
335
 
@@ -330,6 +341,45 @@ POST /api/cost-tracker/export 导出 CSV
330
341
 
331
342
  > 这里只列重要版本;逐版完整记录见 [`CHANGELOG.md`](./CHANGELOG.md)。
332
343
 
344
+ ### v1.9.4(2026-09-24)
345
+
346
+ **修复「火山方舟配额响应不是合法 JSON」:宿主全局 fetch 被 undici 包污染后不解压 gzip,插件改为自带解压兜底**
347
+
348
+ - **根因(本机复现)**:宿主进程里只要有插件 `import` 了 npm 的 `undici` 包(本机是
349
+ `dshmarket` 静态引入,另有 `dsh-http-proxy` / `dsh-web-fetch-http`),Node **内置** `fetch`
350
+ 就不再解压 gzip —— 响应既没有 `content-encoding`,正文也是原始压缩字节
351
+ (实测:未 import 时 560B 明文 JSON;import 后 326B 且以 `1f 8b` 开头)。于是
352
+ `JSON.parse(await res.text())` 必然失败,面板报「配额查询不可用:火山方舟配额响应不是合法 JSON」;
353
+ **插件市场把所有包的新版本读成 `null` 也是同一个根因**(它无代理时回退用的同样是全局 fetch);
354
+ - **修法(两层,对调用方透明)**:`safeFetch` 默认补 `accept-encoding: identity` 从源头要未压缩正文;
355
+ 收到正文后按**字节**判断(gzip `1f8b` / zlib `78xx` / 响应头明说的 `br`、`deflate`)自行解压,
356
+ 解压异常一律原样返回。插件所有出站请求(火山/Kimi 配额、云端同步与读取、官方定价页抓取)
357
+ 都走这里,因此一并兜住;
358
+ - **验证**:真机端到端 —— 先 `import('undici')` 污染进程,旧路径复现同一条错误,
359
+ 修复后 `GetCodingPlanUsage` 正常返回三档窗口(实测 100% / 27.08% / 14.77%);
360
+ 新增 `credstore` [5] 与 `volcengine-host` [6] 两组回归,全量 18 个测试文件通过;
361
+ - **生效条件**:改动在宿主半端,需重启 `dsh web`。
362
+
363
+ ### v1.9.3(2026-09-24)
364
+
365
+ **适配 DSH 0.1.7-alpha.2:配置入口内迁到「花费统计」页头齿轮(旧卡片入口保留兼容)**
366
+
367
+ - **背景**:DSH `0.1.7-alpha.2` 删除了 `settings.plugin.item` 插槽(原来的「设置 → 插件 → 插件配置」),
368
+ 「内置插件」分区改成**只读清单**(只显示完整名称 / 配置状态 / 启用于),`dsh-settings` 的
369
+ `installSection` 也一并下线 —— 本插件原先挂在那里的配置卡片在新宿主上**永远不会显示**;
370
+ - **改法**:配置 UI 内迁到本插件自己的设置分区 —— **设置 → 花费统计 → 页头右上角齿轮**(齿轮为图标按钮,
371
+ 带 `花费统计设置` 可访问名)→ 配置页,左上角**返回键**回到看板。七个折叠分组、顶部状态摘要、
372
+ 各分组的保存 / 测试连接 / 立即同步 / 用价同步 / 历史导入等动作**逐项不变**;
373
+ - **为什么是「页内跳转」而不是第二个左侧导航项**:宿主设置外壳渲染分区时只传入 `close`
374
+ (`renderSlot('settings.section', { close }, { only: active })`),分区没有任何程序化切换导航的能力;
375
+ - **兼容**:`settings.plugin.item` 注册**保留**。0.1.7+ 上该插槽不存在 → 回调不触发即自动失效(零成本);
376
+ 仍声明它的旧宿主照旧显示卡片。两种入口**共用同一个 `ConfigPanel`**(只有外壳不同),字段、校验、
377
+ 写接口完全一致 —— 就近改一处即可,两处的未保存草稿互相独立;
378
+ - **不再可能关掉后打不开**:看板被关掉时页头与齿轮仍在,只有统计内容换成一句「点右上角齿轮 →
379
+ 数据与界面 → 打开」的指引(原「插件配置」入口在新宿主上已经不存在,这条护栏是必须的);
380
+ - **文案**:插件内所有指引(峰谷只读面板、云端同步只读卡、令牌失效提示、云端未配置提示)与
381
+ Agent 工具 / HTTP 错误里的路径统一改为「设置 → 花费统计 → 右上角齿轮 → 分组名」。
382
+
333
383
  ### v1.9.2(2026-09-20)
334
384
 
335
385
  **定价口径修正:V4-Pro 不再路由到 Flash(官方撤销下线计划)+ 新增「法定节假日全天闲时」**
@@ -569,6 +619,13 @@ POST /api/cost-tracker/export 导出 CSV
569
619
 
570
620
  ## 常见问题
571
621
 
622
+ **Q:配额面板提示「火山方舟配额响应不是合法 JSON(GetCodingPlanUsage)」怎么办?**
623
+ 先升级到 **v1.9.4 或更高**并重启 `dsh web`。根因不在火山侧,也不在凭据:宿主进程里只要有插件
624
+ `import` 了 npm 的 `undici` 包(本机是 `dshmarket`),Node **内置 `fetch`** 就不再解压 gzip ——
625
+ 响应没有 `content-encoding`、正文是原始压缩字节,`JSON.parse` 必然失败。v1.9.4 起插件在出站封套里
626
+ 自带解压(并默认请求 `accept-encoding: identity`),因此不再受影响。附带说明:**插件市场看不到新版本
627
+ (所有包都显示已是最新)是同一个根因**,但那条路径由 `dshmarket` 自己发起,需在其侧修复。
628
+
572
629
  **Q:数据存在哪里?安全吗?**
573
630
  全部数据只存在你本机的 `~/.dsh/storages/cost-tracker-records.json`,不会上传到任何服务器。API 只监听本机回环地址,但无鉴权——**不要把 DSH 端口暴露到公网**。
574
631
 
@@ -591,7 +648,7 @@ POST /api/cost-tracker/export 导出 CSV
591
648
  1. 火山引擎控制台 → **IAM → 用户 → 密钥**,创建 AccessKeyID / SecretAccessKey;
592
649
  2. 给该子用户授予 **`ArkReadOnlyAccess`** 与 **`BillingCenterReadOnlyAccess`**(只读,足够查询用量);
593
650
  3. 让插件拿到这对密钥(任选其一,按优先级):
594
- - **设置 → 插件 → 插件配置 → 花费统计** 里填 `火山引擎 AccessKeyID` / `SecretAccessKey`(密钥不回显);或
651
+ - **设置 → 花费统计 → 右上角齿轮 → 订阅套餐与配额** 里填 `火山引擎 AccessKeyID` / `SecretAccessKey`(密钥不回显);或
595
652
  - 写进 `~/.dsh/.credentials.yaml` 的 `refs:` 段,键名 `VOLC_ACCESSKEY` / `VOLC_SECRETKEY`(也兼容 `VOLCENGINE_ACCESS_KEY_ID`、`ARK_ACCESS_KEY_ID` 等写法);或
596
653
  - 设为同名环境变量。
597
654
 
@@ -625,7 +682,7 @@ POST /api/cost-tracker/export 导出 CSV
625
682
  ├── config.js 配置层:峰谷计价提示 + 云端同步 + 界面显示 + 火山凭据的默认值与规范化(纯逻辑,可独立测试)
626
683
  ├── volcengine.js 火山方舟配额查询:HMAC-SHA256 签名、响应解析、凭据归一(纯逻辑,可独立测试)
627
684
  ├── sync.js 云端同步引擎:设备身份、增量水位、幂等批次、退避重试
628
- ├── schema.js 宿主设置空间的 schema(插件配置卡片字段)
685
+ ├── schema.js 宿主设置空间的 schema(配置面板字段;旧宿主兼容)
629
686
  ├── view.js 三态视图合并:本机 / 本机+云端 / 仅云端的口径归一化(浏览器与测试共用)
630
687
  ├── client.js Client 半端:设置页仪表盘、状态栏与峰谷提示 UI
631
688
  ├── package.json 插件清单:声明 dsh.bundle(插件可被安装的关键)与 dsh.client(前端 UI)
package/client.js CHANGED
@@ -244,6 +244,19 @@ window.__ModuleLoader__.load({
244
244
  .cost-pcard-chevron { color: var(--dsw-alias-label-tertiary, #8b93a1); flex: none; transition: transform .16s; }
245
245
  .cost-pcard-chevron.is-open { transform: rotate(180deg); }
246
246
  .cost-pcard-body { border-top: .5px solid var(--dsw-alias-border-l2, #e5e7eb); margin: 0 16px; padding: 12px 0 10px; }
247
+ /* ---------- 设置入口 v1.9.3:页头齿轮 + 分区内配置页(宿主 0.1.7 起插件配置插槽下线) ---------- */
248
+ /* 页头右侧的操作位:把齿轮推到行尾,不影响既有的标题与图标 */
249
+ .cost-h1-actions { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }
250
+ .cost-gear { appearance: none; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 0; border: .5px solid var(--dsw-alias-border-l2, #d1d5db); border-radius: 8px; background: var(--dsw-alias-bg-layer-1, #fff); color: var(--dsw-alias-label-secondary, #5b6472); cursor: pointer; transition: background .16s, border-color .16s, color .16s; }
251
+ .cost-gear:hover { background: var(--dsw-alias-bg-layer-2, #f3f4f6); color: var(--dsw-alias-label-primary, #171a1f); }
252
+ .cost-gear:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary, #2563eb); outline-offset: 2px; }
253
+ .cost-gear-icon { display: block; }
254
+ .cost-cfg-page { padding-top: 2px; }
255
+ .cost-cfg-page-head { display: flex; align-items: center; gap: 10px; margin: 2px 0 10px; }
256
+ .cost-back { appearance: none; display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; font: inherit; font-size: 12px; border-radius: 6px; border: .5px solid var(--dsw-alias-border-l2, #d1d5db); background: var(--dsw-alias-bg-layer-1, #fff); color: var(--dsw-alias-label-primary, #171a1f); cursor: pointer; }
257
+ .cost-back:hover { background: var(--dsw-alias-bg-layer-2, #f3f4f6); }
258
+ .cost-back:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary, #2563eb); outline-offset: 2px; }
259
+ .cost-cfg-page-title { display: inline-flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; }
247
260
  /* ---------- 插件配置卡片 v1.9.0:顶部状态条 + 折叠分组 ---------- */
248
261
  .cost-cfg-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 2px 0 10px; }
249
262
  .cost-cfg-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; line-height: 1.6; padding: 2px 9px; border-radius: 999px; border: .5px solid var(--dsw-alias-border-l2, #e5e7eb); background: var(--dsw-alias-bg-layer-3, transparent); color: var(--dsw-alias-label-secondary, #5b6472); white-space: nowrap; }
@@ -292,6 +305,42 @@ window.__ModuleLoader__.load({
292
305
  e("path", { d: "M10.9 9.5 L13.7 9.5" })));
293
306
  }
294
307
 
308
+ /**
309
+ * 设置齿轮(v1.9.3):自绘 —— 外环 + 内孔 + 8 根径向齿。
310
+ * 不用第三方图标字体/路径,避免额外许可负担;齿由极坐标循环生成,
311
+ * 15px 下仍能看清是「齿轮」而不是圆点。
312
+ */
313
+ function gearIcon(size) {
314
+ const s = size || 15;
315
+ const teeth = [];
316
+ for (let i = 0; i < 8; i++) {
317
+ const a = (Math.PI / 4) * i;
318
+ teeth.push(e("line", {
319
+ key: "gt" + i,
320
+ x1: (8 + 4.6 * Math.cos(a)).toFixed(2), y1: (8 + 4.6 * Math.sin(a)).toFixed(2),
321
+ x2: (8 + 6.4 * Math.cos(a)).toFixed(2), y2: (8 + 6.4 * Math.sin(a)).toFixed(2),
322
+ stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round",
323
+ }));
324
+ }
325
+ return e("svg", {
326
+ className: "cost-gear-icon", width: s, height: s, viewBox: "0 0 16 16",
327
+ fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true",
328
+ },
329
+ e("circle", { cx: 8, cy: 8, r: 4.6, stroke: "currentColor", strokeWidth: 1.3 }),
330
+ e("circle", { cx: 8, cy: 8, r: 1.7, stroke: "currentColor", strokeWidth: 1.3 }),
331
+ e("g", null, teeth));
332
+ }
333
+
334
+ /** 返回箭头(配置页左上角),与本插件其它内联 SVG 同款线宽与端点 */
335
+ function backIcon(size) {
336
+ const s = size || 13;
337
+ return e("svg", {
338
+ className: "cost-back-icon", width: s, height: s, viewBox: "0 0 14 14",
339
+ fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true",
340
+ },
341
+ e("path", { d: "M8.75 3.5 5.25 7l3.5 3.5", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" }));
342
+ }
343
+
295
344
  function fmtInt(n) { return String(Math.round(Number(n) || 0)).replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
296
345
  function fmtMoney(n) {
297
346
  const x = Number(n) || 0;
@@ -1519,7 +1568,8 @@ window.__ModuleLoader__.load({
1519
1568
  // 设置面板:峰谷计价与提示
1520
1569
  /**
1521
1570
  * 「峰谷计价与提示」看板面板(v1.9.0 起**只读**)。
1522
- * 设置入口统一到「设置 → 插件 → 插件配置 → 花费统计 → 峰谷计价与提示」,
1571
+ * 设置入口统一到「设置 → 花费统计 → 右上角齿轮 → 峰谷计价与提示」
1572
+ * (旧宿主也可在「设置 → 插件 → 插件配置 → 花费统计」卡片里改,同一份配置),
1523
1573
  * 这里只回显当前档位与生效配置,避免两处都能改造成口径不一致。
1524
1574
  * 预览按钮保留:它只是本地弹窗预览,不改任何持久化状态。
1525
1575
  */
@@ -1567,8 +1617,8 @@ window.__ModuleLoader__.load({
1567
1617
 
1568
1618
  // ============================================================
1569
1619
  // 云端同步(只读回显)—— 花费统计设置页
1570
- // 编辑入口在「设置 → 插件 → 插件配置 → 花费统计」卡片,这里只回显当前状态,
1571
- // 避免两处都能改造成口径不一致。
1620
+ // 编辑入口在「设置 → 花费统计 → 右上角齿轮」(旧宿主:插件配置卡片里的同一份设置),
1621
+ // 这里只回显当前状态,避免两处都能改造成口径不一致。
1572
1622
  // ============================================================
1573
1623
  function SyncReadonlyCard(props) {
1574
1624
  const [st, setSt] = useState(props && props.sync ? props.sync : null);
@@ -1597,15 +1647,25 @@ window.__ModuleLoader__.load({
1597
1647
  line("上报项目", st.includePurpose ? "含 purpose" : "不含 purpose")),
1598
1648
  st.lastError ? e("div", { className: "cost-err", style: { marginTop: "6px" } }, "最近错误:" + st.lastError) : null,
1599
1649
  e("div", { className: "cost-hint", style: { marginTop: "8px" } },
1600
- "编辑入口:设置 → 插件 → 插件配置 → 花费统计" + (st.dataDir ? "(身份文件:" + st.identityFile + ")" : "")));
1650
+ "编辑入口:设置 → 花费统计 → 右上角齿轮(设置)" + (st.dataDir ? "(身份文件:" + st.identityFile + ")" : "")));
1601
1651
  }
1602
1652
 
1603
1653
  // ============================================================
1604
- // 插件配置卡(设置 → 插件 → 插件配置)
1605
- // 卡片自绘内部结构、表单走本插件自己的 host API(/api/cost-tracker/sync-*),
1654
+ // 配置面板(一份实现,两种外壳)
1655
+ // · mode 'card'(默认):宿主「插件配置」列表里的可点开卡片
1656
+ // (settings.plugin.item,key = cost-tracker)。**兼容保留** ——
1657
+ // DSH 0.1.7-alpha.2 起宿主已不再声明该插槽,回调不触发即自动失效,
1658
+ // 零成本;仍声明该插槽的旧宿主照旧有卡片。
1659
+ // · mode 'page':本插件「设置 → 花费统计」分区内的配置页,由页头齿轮进入、
1660
+ // 左上角返回键退出(宿主设置外壳没有分区间跳转能力,见 apply 处注释)。
1661
+ // 两种外壳共用同一段正文(顶部状态条 + 七个折叠分组),因此不可能出现
1662
+ // 「两处字段/口径不一致」——只有外壳不同。
1663
+ // 表单走本插件自己的 host API(/api/cost-tracker/*),
1606
1664
  // 不硬依赖 settings UI 包的内部实现,避免版本耦合。
1607
1665
  // ============================================================
1608
- function PluginConfigCard() {
1666
+ function ConfigPanel(props) {
1667
+ const mode = props && props.mode === "page" ? "page" : "card";
1668
+ const onBack = props && props.onBack;
1609
1669
  const [st, setSt] = useState(null);
1610
1670
  const [prices, setPrices] = useState(null);
1611
1671
  const [imp, setImp] = useState(null);
@@ -2186,13 +2246,7 @@ window.__ModuleLoader__.load({
2186
2246
  e("div", { className: "cost-hint", style: { marginTop: "6px" } },
2187
2247
  "提示:AccessKeyID 属非敏感标识(控制台可见),会随看板回显以便预填;SecretAccessKey 与令牌在任何响应里都只有布尔标记。"));
2188
2248
 
2189
- // 卡片外壳对齐宿主 PluginCard:li.cost-pcard > button.cost-pcard-head(标题+副标题+箭头)> body
2190
- const head = e("button", { type: "button", className: "cost-pcard-head", "aria-expanded": open, onClick: () => setOpen(v => !v) },
2191
- e("span", { className: "cost-pcard-headtext" },
2192
- e("span", { className: "cost-pcard-name" }, "花费统计" + (st && st.enabled ? " · 云端同步已开启" : "")),
2193
- e("span", { className: "cost-pcard-desc" }, "全部设置集中于此:云端同步(多机汇总)、峰谷计价与提示、订阅套餐与配额、计价与价格目录、历史导入、数据与界面、安全与凭据。")),
2194
- e("svg", { className: "cost-pcard-chevron" + (open ? " is-open" : ""), width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true" },
2195
- e("path", { d: "M3.5 5.25 7 8.75l3.5-3.5", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round", strokeLinejoin: "round" })));
2249
+ // 正文(两种外壳共用):顶部状态条 + 七个折叠分组。外壳只决定包在外面的 chrome。
2196
2250
  const body = e("div", null,
2197
2251
  topStrip,
2198
2252
  !st ? e("div", { className: "cost-hint", style: { margin: "4px 0 8px" } }, "加载状态…") : null,
@@ -2203,6 +2257,31 @@ window.__ModuleLoader__.load({
2203
2257
  cfgSection(Object.assign({ key: "s5" }, secProps("imp", "历史导入", (impDraft.autoImport !== false ? "开机自动" : "手动") + " · 已导入 " + fmtInt((imp && imp.totalImported) || 0) + " 条")), impBody),
2204
2258
  cfgSection(Object.assign({ key: "s6" }, secProps("data", "数据与界面", "保留 180 天明细 · 界面落点 " + UI_SURFACES.filter(s => uiDraft[s.key] !== false).length + "/3")), dataBody),
2205
2259
  cfgSection(Object.assign({ key: "s7" }, secProps("sec", "安全与凭据", "密钥零落盘 · 出站白名单")), secBody));
2260
+
2261
+ // ---------- 外壳①:分区内配置页(齿轮进入 / 返回键退出) ----------
2262
+ // 页头自己画,因为宿主设置外壳只负责导航与内容列(见 apply 处注释)。
2263
+ if (mode === "page") {
2264
+ return e("div", { className: "cost-wrap cost-cfg-page" },
2265
+ e("div", { className: "cost-cfg-page-head" },
2266
+ e("button", {
2267
+ type: "button", className: "cost-back", onClick: onBack,
2268
+ "aria-label": "返回花费统计看板", title: "返回花费统计看板",
2269
+ }, backIcon(13), e("span", null, "返回")),
2270
+ e("span", { className: "cost-cfg-page-title" }, pluginIcon(18), "花费统计 · 设置")),
2271
+ e("div", { className: "cost-hint", style: { margin: "0 0 8px" } },
2272
+ "全部设置集中于此页:云端同步(多机汇总)、峰谷计价与提示、订阅套餐与配额、计价与价格目录、历史导入、数据与界面、安全与凭据。"
2273
+ + "旧版宿主(设置里仍显示「插件 → 插件配置」卡片)在那张卡片里打开的是同一份设置,就近改一处即可。"),
2274
+ body);
2275
+ }
2276
+
2277
+ // ---------- 外壳②:宿主「插件配置」列表里的卡片(兼容旧宿主) ----------
2278
+ // 卡片外壳对齐宿主 PluginCard:li.cost-pcard > button.cost-pcard-head(标题+副标题+箭头)> body
2279
+ const head = e("button", { type: "button", className: "cost-pcard-head", "aria-expanded": open, onClick: () => setOpen(v => !v) },
2280
+ e("span", { className: "cost-pcard-headtext" },
2281
+ e("span", { className: "cost-pcard-name" }, "花费统计" + (st && st.enabled ? " · 云端同步已开启" : "")),
2282
+ e("span", { className: "cost-pcard-desc" }, "全部设置集中于此:云端同步(多机汇总)、峰谷计价与提示、订阅套餐与配额、计价与价格目录、历史导入、数据与界面、安全与凭据。")),
2283
+ e("svg", { className: "cost-pcard-chevron" + (open ? " is-open" : ""), width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true" },
2284
+ e("path", { d: "M3.5 5.25 7 8.75l3.5-3.5", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round", strokeLinejoin: "round" })));
2206
2285
  return e("li", { className: "cost-pcard" + (open ? " is-open" : "") },
2207
2286
  head,
2208
2287
  open ? e("div", { className: "cost-pcard-body" }, body) : null);
@@ -2330,12 +2409,21 @@ window.__ModuleLoader__.load({
2330
2409
  }
2331
2410
 
2332
2411
  /**
2333
- * 「花费统计」看板的插槽门卫。
2334
- * 关掉界面显示时**不能注册成空渲染**(会留下一个点不开的空白导航项),
2335
- * 所以这里保留设置项但只渲染一句说明 —— 用户随时能在插件配置卡片里改回来。
2336
- * 宿主不重启插件、插槽注册也无法撤销,因此显隐必须在渲染期判定。
2412
+ * 「花费统计」设置分区的路由壳(v1.9.3)。
2413
+ *
2414
+ * 宿主 0.1.7-alpha.2 起,「内置插件」分区改成只读清单、`settings.plugin.item`
2415
+ * 插槽被删除(0.1.6 及更早的宿主仍声明它,插件侧保留注册做兼容),
2416
+ * 所以配置入口随页面内迁:看板页头右上角齿轮 → 本分区内的配置页 → 左上角返回键。
2417
+ * 之所以做成「分区内子视图」而不是第二个左侧导航项:宿主设置外壳渲染分区时
2418
+ * 只传入 close(见 dsh-client-ui-settings-general 的
2419
+ * renderSlot('settings.section', { close }, { only: active })),
2420
+ * 分区没有任何程序化切换导航的能力。
2421
+ *
2422
+ * ui 快照(peak 轮询 + UI_EVENT 广播)放在这一层:看板与配置页共用同一个快照,
2423
+ * 因此配置页里改完「界面显示」开关后,返回看板立刻生效。
2337
2424
  */
2338
- function DashGate() {
2425
+ function CostSection() {
2426
+ const [view, setView] = useState("dashboard");
2339
2427
  const [ui, setUi] = useState(null);
2340
2428
  useEffect(() => {
2341
2429
  let alive = true;
@@ -2347,17 +2435,44 @@ window.__ModuleLoader__.load({
2347
2435
  window.addEventListener(UI_EVENT, load);
2348
2436
  return () => { alive = false; clearInterval(id); window.removeEventListener(UI_EVENT, load); };
2349
2437
  }, []);
2438
+ if (view === "config") {
2439
+ return e(ConfigPanel, { mode: "page", onBack: () => setView("dashboard") });
2440
+ }
2441
+ return e(DashboardGate, { ui, onOpenConfig: () => setView("config") });
2442
+ }
2443
+
2444
+ /**
2445
+ * 看板门卫 + 看板关闭态。
2446
+ * 关掉界面显示时**不能注册成空渲染**(会留下一个点不开的空白导航项),
2447
+ * 也不能把齿轮一起藏起来(否则关掉后再没有入口能打开):
2448
+ * 所以这里保留页头 + 齿轮,只把统计内容换成一句说明。
2449
+ * 宿主不重启插件、插槽注册也无法撤销,因此显隐必须在渲染期判定。
2450
+ */
2451
+ function DashboardGate(props) {
2452
+ const ui = props ? props.ui : null;
2453
+ const openConfig = props && props.onOpenConfig;
2350
2454
  if (!uiOn(ui, "uiDashboardEnabled")) {
2351
2455
  return e("div", { className: "cost-wrap" },
2352
- e("div", { className: "cost-h1" }, pluginIcon(18), "花费统计"),
2456
+ e("div", { className: "cost-h1" }, pluginIcon(18), "花费统计",
2457
+ e("span", { className: "cost-h1-actions" }, e(GearButton, { onClick: openConfig }))),
2353
2458
  e("div", { className: "cost-hint", style: { marginTop: "8px" } },
2354
2459
  "花费统计看板已在设置里关闭显示。记账与云端同步不受影响;要重新打开:" +
2355
- "设置 → 插件 → 插件配置 → 花费统计 → 界面显示 → 打开「设置页花费统计看板」。"));
2460
+ "点右上角齿轮 → 「数据与界面」→ 打开「设置页花费统计看板」。"));
2356
2461
  }
2357
- return e(Dashboard, {});
2462
+ return e(Dashboard, { onOpenConfig: openConfig });
2463
+ }
2464
+
2465
+ /** 看板页头右上角的设置齿轮:进入本分区的配置页 */
2466
+ function GearButton(props) {
2467
+ return e("button", {
2468
+ type: "button", className: "cost-gear",
2469
+ "aria-label": "花费统计设置", title: "花费统计设置",
2470
+ onClick: props && props.onClick,
2471
+ }, gearIcon(15));
2358
2472
  }
2359
2473
 
2360
- function Dashboard() {
2474
+ function Dashboard(props) {
2475
+ const onOpenConfig = props && props.onOpenConfig;
2361
2476
  const [days, setDays] = useState(7);
2362
2477
  const [dash, setDash] = useState(null);
2363
2478
  const [dashErr, setDashErr] = useState("");
@@ -2608,11 +2723,12 @@ window.__ModuleLoader__.load({
2608
2723
  }
2609
2724
 
2610
2725
  return e("div", { className: "cost-wrap" },
2611
- e("div", { className: "cost-h1" }, pluginIcon(18), "花费统计"),
2726
+ e("div", { className: "cost-h1" }, pluginIcon(18), "花费统计",
2727
+ e("span", { className: "cost-h1-actions" }, e(GearButton, { onClick: onOpenConfig }))),
2612
2728
  filterRow(days, setDays, onExport, onRefresh, msg, busy, dash ? dash.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末与法定节假日全天闲时)", viewCtl, openVolc, planTotal, setPlanTotal),
2613
2729
  !cloudAvailable
2614
2730
  ? e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2615
- "仅显示本机数据。在多台电脑/多个 Agent 之间汇总:到「设置 → 插件 → 插件配置 → 花费统计」填写云端服务地址与令牌。")
2731
+ "仅显示本机数据。在多台电脑/多个 Agent 之间汇总:点右上角齿轮 → 「多机汇总(云端同步)」填写云端服务地址与令牌。")
2616
2732
  : null,
2617
2733
  sync && sync.enabled && sync.pending > 0 && view !== "local"
2618
2734
  ? e("div", { className: "cost-cloudnote" },
@@ -2623,7 +2739,7 @@ window.__ModuleLoader__.load({
2623
2739
  ? e("div", { className: "cost-err", style: { marginTop: "6px" } }, "云端数据不可用(已显示本机数据):" + cloudErr)
2624
2740
  : null,
2625
2741
  sync && sync.needAuth
2626
- ? e("div", { className: "cost-err", style: { marginTop: "6px" } }, "云端令牌无效:请在「设置 → 插件 → 插件配置 → 花费统计」更新令牌。")
2742
+ ? e("div", { className: "cost-err", style: { marginTop: "6px" } }, "云端令牌无效:请在「设置 → 花费统计 → 右上角齿轮 → 多机汇总」更新令牌。")
2627
2743
  : null,
2628
2744
  dashErr ? e("div", { className: "cost-err", style: { marginTop: "8px" } }, dashErr) : null,
2629
2745
  (!viewDash && !dashErr) ? e("div", { className: "cost-hint", style: { marginTop: "12px" } }, "加载中…") : null,
@@ -2786,20 +2902,26 @@ window.__ModuleLoader__.load({
2786
2902
  applyStyles(ctx);
2787
2903
  const slots = ctx.get("slots");
2788
2904
  if (slots === undefined) return;
2905
+ // 「花费统计」设置分区:看板 + 页头齿轮进入的配置页(见 CostSection 注释)
2789
2906
  slots.inject("settings.section", () => slots.register(
2790
2907
  { name: "settings.section", id: "cost-dashboard", order: 30, label: "花费统计" },
2791
- () => e(DashGate, {}),
2908
+ () => e(CostSection, {}),
2792
2909
  ));
2793
- // 插件配置卡片(设置 → 插件 → 插件配置):以 settings 命名空间为键。
2910
+ // 插件配置卡片(设置 → 插件 → 插件配置):以 settings 命名空间为键,**兼容入口**。
2794
2911
  // 这里必须**无条件** inject,不能拿 slots.entries(key).length 当"插槽是否存在"的探测:
2795
2912
  // entries 数的是"已经注册进该槽的条目",而条目正是由各插件在插槽声明后才注册的,
2796
2913
  // 所以在插件 apply 阶段它恒为空 —— 用探测就会把卡片永远挡在门外(1.8.0 的缺陷)。
2797
2914
  // 宿主的官方卡片(dsh-client-ui-settings-plugins)与 dsh-context 都是无条件 inject:
2798
2915
  // 插槽未声明时回调不触发、声明时自动触发,既不会误判也不需要重试。
2916
+ //
2917
+ // v1.9.3:DSH 0.1.7-alpha.2 起宿主已删除该插槽(「内置插件」分区改为只读清单),
2918
+ // 回调自然不触发 ⇒ 保留注册在 0.1.7+ 上是零成本的空操作;
2919
+ // 仍声明该插槽的旧宿主照旧显示这张卡片,且它与分区内配置页共用 ConfigPanel,
2920
+ // 字段、校验、写接口完全一致(只是外壳不同)。
2799
2921
  const pluginItemKey = "settings.plugin.item";
2800
2922
  slots.inject(pluginItemKey, () => slots.register(
2801
2923
  { name: pluginItemKey, key: "cost-tracker" },
2802
- () => e(PluginConfigCard, {}),
2924
+ () => e(ConfigPanel, { mode: "card" }),
2803
2925
  ));
2804
2926
  slots.inject("conversation.composer.dock", () => slots.register(
2805
2927
  { name: "conversation.composer.dock", id: "cost", order: 1 },
package/config.js CHANGED
@@ -47,8 +47,8 @@
47
47
  // uiDashboardEnabled 设置页左侧的「花费统计」看板入口(settings.section)
48
48
  //
49
49
  // 三者**互相独立**,且都只影响前端渲染,不影响记账、云端同步与 Agent 工具。
50
- // 插件配置卡片(settings.plugin.item)不受这三个开关控制 —— 它必须始终可点,
51
- // 否则关掉之后用户就没有入口再打开了。
50
+ // 承载这些开关的配置面板本身不受开关控制 —— 它必须始终可达(页头齿轮,
51
+ // 以及旧宿主「设置 → 插件 → 插件配置」里的卡片),否则关掉之后用户就没有入口再打开了。
52
52
  //
53
53
  // 真值语义与 peakEnabled 相反:null/undefined → true(显隐是从 v1.8.12 才有的新
54
54
  // 能力,老配置文件里没有这几个键,必须保持默认全部可见),只有显式 false 才隐藏。
@@ -128,7 +128,7 @@ export function defaultCloudConfig() {
128
128
  export const BOARD_VIEWS = ['local', 'local+cloud', 'cloud']
129
129
 
130
130
  /**
131
- * 前端显隐开关(设置 → 插件 → 插件配置 → 花费统计 → 界面显示)。
131
+ * 前端显隐开关(设置 → 花费统计 → 右上角齿轮 → 数据与界面 → 界面显示)。
132
132
  * 每项声明:配置键、文案、说明,以及它在 DSH 里对应的插槽(便于对照宿主与测试)。
133
133
  * 新增可控落点时只改这张表:服务端 normalize 与前端卡片都从它派生。
134
134
  */
package/credstore.js CHANGED
@@ -16,7 +16,18 @@
16
16
  // redirect:'manual' + 自管跳转(最多 3 跳):**携带凭据的请求不跨主机跟随**
17
17
  // (防重定向把凭据带去别处),不带凭据的请求可在白名单内跟随
18
18
  // (官方定价页 `/pricing` → `/pricing/` 这种同站加斜杠的 302 必须放行)。
19
+ // 4. 响应体自解压(v1.9.4):**不依赖宿主 fetch 的解压**。宿主进程里只要有任何
20
+ // 插件 `import` 了 npm 的 `undici` 包(本机实测:`dshmarket/lib/net.js` 静态引入,
21
+ // `dsh-http-proxy` / `dsh-web-fetch-http` 动态引入),Node 内置 `fetch` 就不再
22
+ // 解压 gzip —— 响应既不带 `content-encoding`,body 也是原始压缩字节,于是
23
+ // `JSON.parse(await res.text())` 必然失败。真实故障:火山方舟配额面板报
24
+ // 「配额响应不是合法 JSON(GetCodingPlanUsage)」,插件市场把所有包的新版本
25
+ // 读成 null(它回退用的也是全局 fetch)。修法有两层:
26
+ // · 请求默认带 `accept-encoding: identity`,从源头要未压缩正文;
27
+ // · 收到正文后按**字节**(gzip 1f8b / zlib 78xx / brotli 头)自行解压,
28
+ // 绝不只看响应头 —— 服务端忽略 identity 时同样能正确解析。
19
29
  // ============================================================
30
+ import * as zlib from 'node:zlib'
20
31
 
21
32
  /** 本插件占用的凭据引用名(POSIX shell 标识符风格,宿主凭据库通用) */
22
33
  export const CRED_REFS = {
@@ -28,6 +39,95 @@ function isLoopbackHost(host) {
28
39
  return /^(localhost|127\.0\.0\.1|\[::1?\]|::1)$/i.test(String(host || ''))
29
40
  }
30
41
 
42
+ /** gzip 魔数(1f 8b)—— 压缩流的第一、二字节 */
43
+ function looksGzip(buf) {
44
+ return buf.length > 2 && buf[0] === 0x1f && buf[1] === 0x8b
45
+ }
46
+ /** zlib 魔数(78 01 / 78 9c / 78 da)—— 即 `deflate` 头 */
47
+ function looksZlib(buf) {
48
+ return buf.length > 2 && buf[0] === 0x78 && (buf[1] === 0x01 || buf[1] === 0x9c || buf[1] === 0xda)
49
+ }
50
+
51
+ /**
52
+ * 响应体字节 → 明文 Buffer(v1.9.4)。
53
+ *
54
+ * 判定顺序刻意「先看字节、再看响应头」:宿主全局 fetch 被 undici 包污染后,
55
+ * 响应头里的 `content-encoding` 会消失而正文仍是压缩流,只看头会漏掉;
56
+ * 反过来服务端若已按 `identity` 返回明文,字节判定也不会误伤。
57
+ * 任何解压异常都**原样返回**原始字节 —— 宁可让上层报「不是合法 JSON」,
58
+ * 也不能因为这里的猜测把可读内容弄丢。
59
+ *
60
+ * @param {Buffer} buf - 原始响应体
61
+ * @param {string} contentEncoding - 响应头里声明的编码(可能为空)
62
+ * @returns {Buffer}
63
+ */
64
+ export function decodeCompressedBody(buf, contentEncoding) {
65
+ if (!Buffer.isBuffer(buf) || buf.length === 0) return buf
66
+ const ce = String(contentEncoding || '').trim().toLowerCase()
67
+ try {
68
+ if (looksGzip(buf)) return zlib.gunzipSync(buf)
69
+ if (looksZlib(buf)) return zlib.inflateSync(buf)
70
+ // brotli / 其它编码没有稳定魔数:只在响应头明说、且确实是压缩流时才尝试
71
+ if (ce === 'br' || ce === 'brotli') return zlib.brotliDecompressSync(buf)
72
+ if (ce === 'deflate') return zlib.inflateSync(buf)
73
+ if (ce === 'gzip' || ce === 'x-gzip') return zlib.gunzipSync(buf)
74
+ } catch (e) {
75
+ return buf // 已经解压过 / 截断 / 不是压缩流:交回原样
76
+ }
77
+ return buf
78
+ }
79
+
80
+ /**
81
+ * 把 Response 包成「自带解压」的等价物(v1.9.4)。
82
+ *
83
+ * 只实现调用方真正用到的成员(status / ok / url / redirected / headers /
84
+ * text / json / arrayBuffer),因此对既有接线是透明的;正文只读取一次并缓存,
85
+ * `text()` 与 `json()` 复用同一份解码结果。
86
+ * @param {Response|object} res
87
+ * @returns {object}
88
+ */
89
+ export function withDecodedBody(res) {
90
+ let cached = null
91
+ const bytes = () => {
92
+ if (cached === null) {
93
+ cached = (async () => {
94
+ let raw = Buffer.alloc(0)
95
+ try {
96
+ if (typeof res.arrayBuffer === 'function') {
97
+ raw = Buffer.from(await res.arrayBuffer())
98
+ } else if (typeof res.text === 'function') {
99
+ raw = Buffer.from(String(await res.text()), 'utf8')
100
+ }
101
+ } catch (e) {
102
+ raw = Buffer.alloc(0)
103
+ }
104
+ const ce = res && res.headers && typeof res.headers.get === 'function' ? res.headers.get('content-encoding') : ''
105
+ return decodeCompressedBody(raw, ce)
106
+ })()
107
+ }
108
+ return cached
109
+ }
110
+ return {
111
+ status: res.status,
112
+ ok: res.ok,
113
+ statusText: res.statusText,
114
+ url: res.url,
115
+ redirected: res.redirected,
116
+ headers: res.headers,
117
+ text: async () => (await bytes()).toString('utf8'),
118
+ json: async () => JSON.parse((await bytes()).toString('utf8')),
119
+ arrayBuffer: async () => {
120
+ const b = await bytes()
121
+ return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength)
122
+ },
123
+ }
124
+ }
125
+
126
+ /** 判断请求头里是否已经指定了 accept-encoding(大小写不敏感) */
127
+ function hasAcceptEncoding(headers) {
128
+ return Object.keys(headers || {}).some((k) => k.toLowerCase() === 'accept-encoding')
129
+ }
130
+
31
131
  /** 从 URL 提取 hostname(不含端口);非法 URL 返回 '' */
32
132
  export function hostnameOf(url) {
33
133
  try {
@@ -95,6 +195,9 @@ export async function safeFetch(url, opts) {
95
195
  }
96
196
  // init.headers 在前、opts.headers 在后:调用方经 init 传的签名头不被覆盖
97
197
  const headers = Object.assign({}, init.headers || {}, o.headers || {})
198
+ // v1.9.4:从源头要未压缩正文(宿主全局 fetch 可能已不解压,见文件头「响应体自解压」)。
199
+ // 调用方显式指定过 accept-encoding 时尊重调用方。
200
+ if (!hasAcceptEncoding(headers)) headers['accept-encoding'] = 'identity'
98
201
  const credentialHeader = Object.keys(headers).find((k) => /^(authorization|proxy-authorization|x-api-key|api-key)$/i.test(k))
99
202
  let current = String(url)
100
203
  let method = init.method
@@ -111,9 +214,9 @@ export async function safeFetch(url, opts) {
111
214
  } finally {
112
215
  clearTimeout(timer)
113
216
  }
114
- if (!(res.status >= 300 && res.status < 400)) return res
217
+ if (!(res.status >= 300 && res.status < 400)) return withDecodedBody(res)
115
218
  const loc = typeof res.headers.get === 'function' ? (res.headers.get('location') || '') : ''
116
- if (!loc) return res // 3xx 但没给 Location:交给调用方按状态自行判断
219
+ if (!loc) return withDecodedBody(res) // 3xx 但没给 Location:交给调用方按状态自行判断
117
220
  let target
118
221
  try {
119
222
  target = new URL(loc, current).toString()
package/index.js CHANGED
@@ -33,12 +33,14 @@ import { createCredSeam, migrateLegacySecrets, safeFetch, CRED_REFS, hostnameOf
33
33
  import { listSessionLogs, planAndBuildImports, loadManifest, IMPORT_SOURCE } from './import.js'
34
34
 
35
35
  /** 插件版本(写入上报信封,便于云端排查版本差异) */
36
- const PLUGIN_VERSION = '1.9.2'
36
+ const PLUGIN_VERSION = '1.9.4'
37
37
  setPluginVersion(PLUGIN_VERSION)
38
38
 
39
- /** 「设置 → 插件 → 插件配置」里的卡片字段(与 settings 命名空间一致)。
40
- * v1.9.0 起配置卡承载**全部**设置(峰谷/订阅/计费/目录/导入/同步/界面显示),
41
- * 这里声明的是卡片可写的字段全集;密钥类字段 role('secret') 只进凭据库。 */
39
+ /** 配置面板可写的字段(与 settings 命名空间一致)。
40
+ * v1.9.0 起配置面板承载**全部**设置(峰谷/订阅/计费/目录/导入/同步/界面显示);
41
+ * v1.9.3 起入口内迁到「设置 → 花费统计 → 右上角齿轮」(旧宿主仍可用
42
+ * 「设置 → 插件 → 插件配置」卡片,两处同一组件),这里声明的是字段全集;
43
+ * 密钥类字段 role('secret') 只进凭据库。 */
42
44
  const SyncSchema = Schema.object({
43
45
  deviceName: Schema.string().default(undefined).description('本机在看板上显示的名字'),
44
46
  cloudEnabled: Schema.boolean().default(undefined).description('启用云端同步'),
@@ -272,8 +274,8 @@ export default {
272
274
  // ---------- plugin config(峰谷计价 + 云端同步) ----------
273
275
  // 与记录分开存储:$DSH_HOME/storages/cost-tracker-config.json。
274
276
  // 提供读写与校验(默认值见 config.js),写失败不阻断(下次改设置重试)。
275
- // 若部署里存在 @deepseek-ai/dsh-settings(本机 DSH 自带),另外注册一个
276
- // `cost-tracker` 命名空间:用户在「设置 → 插件 → 插件配置」里改的字段
277
+ // 若部署里存在 @deepseek-ai/dsh-settings(旧宿主;0.1.7 起该服务已无 installSection),
278
+ // 另外注册一个 `cost-tracker` 命名空间:旧宿主设置面里改的字段
277
279
  // 通过 settings/updated 回灌到本文件,保证两个入口读写同一份配置。
278
280
  const CONFIG_FILE = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'storages', 'cost-tracker-config.json')
279
281
  /** 官方价格同步产物(同步时代 + 最近核对结果),与配置/账本分开存 */
@@ -1798,7 +1800,7 @@ export default {
1798
1800
  // 令牌在凭据库(v1.9.0 起配置文件不落明文);此处只做「有没有配置」的快速判定,
1799
1801
  // 真正取值在下方 resolveCloudToken()(异步,凭据服务可能晚于本插件注册)
1800
1802
  if (!cloudConfig.cloudEnabled || !cloudConfig.cloudUrl) {
1801
- return { ok: false, error: '云端同步未配置(在「设置 → 插件 → 插件配置 → 花费统计」填写服务地址与令牌)', code: 'NOT_CONFIGURED' }
1803
+ return { ok: false, error: '云端同步未配置(在「设置 → 花费统计 → 右上角齿轮 → 多机汇总」填写服务地址与令牌)', code: 'NOT_CONFIGURED' }
1802
1804
  }
1803
1805
  const key = JSON.stringify(query)
1804
1806
  const hit = cloudCache.get(key)
@@ -2257,7 +2259,7 @@ export default {
2257
2259
  '待上报:' + st.pending + ' 条 · 已上报水位 seq=' + st.watermark + ' · 日汇总已同步 ' + st.rollupsSent + ' 项',
2258
2260
  ]
2259
2261
  if (st.lastError) lines.push('最近错误:' + st.lastError + (st.backoffMs ? '(退避 ' + Math.round(st.backoffMs / 1000) + 's)' : ''))
2260
- if (st.needAuth) lines.push('⚠ 令牌无效:请在「设置 → 插件 → 插件配置 → 花费统计」更新共享引导令牌')
2262
+ if (st.needAuth) lines.push('⚠ 令牌无效:请在「设置 → 花费统计 → 右上角齿轮 → 多机汇总」更新共享引导令牌')
2261
2263
  if (v.action === 'now' && v.result) {
2262
2264
  lines.push('本次同步:新增 ' + (v.result.accepted || 0) + ' 条 · 去重 ' + (v.result.duplicates || 0) + ' 条 · 日汇总 ' + (v.result.rollups || 0) + ' 项' + (v.result.error ? ' · 失败:' + v.result.error : ''))
2263
2265
  }
@@ -2320,7 +2322,9 @@ export default {
2320
2322
  if (!settingsOk) {
2321
2323
  // settings 是可选服务(宿主未组合时不报错、不阻断启动),但不能像 1.8.0 那样只探一次:
2322
2324
  // 它晚于本插件就绪时,那一次 ctx.get('settings') 必然落空 → 命名空间永不注册 →
2323
- // 「设置 → 插件 → 插件配置」里永远没有本插件的卡片。
2325
+ // 旧宿主的「设置 → 插件 → 插件配置」里永远没有本插件的卡片。
2326
+ // (0.1.7-alpha.2 起宿主已移除 settings.installSection 与插件配置插槽,本路径自然 inert;
2327
+ // 配置入口改由客户端「设置 → 花费统计 → 右上角齿轮」承担,见 client.js 的 CostSection。)
2324
2328
  // 与 dsh-context 的 installSettings 同款写法:ctx.inject 等它就绪后再装,始终缺席则自然 inert。
2325
2329
  try {
2326
2330
  ctx.inject(['settings'], (sctx) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angelyeye/dsh-cost-tracker",
3
- "version": "1.9.2",
3
+ "version": "1.9.4",
4
4
  "description": "DeepSeek Harness (DSH) plugin: LLM token usage & cost tracking with a settings dashboard, agent tools, HTTP API, persistent storage, multi-device cloud sync, session-log history import, official price sync and a multi-vendor price catalog.",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/pricing.js CHANGED
@@ -171,7 +171,7 @@ export function setSyncedEras(eras) {
171
171
  /** 当前注入的同步时代(只读副本,供状态回显) */
172
172
  export function getSyncedEras() { return SYNCED_ERAS.slice() }
173
173
 
174
- // ---------- 手动覆盖价(v1.9.0,插件配置卡维护) ----------
174
+ // ---------- 手动覆盖价(v1.9.0,配置面板维护) ----------
175
175
  let PRICE_OVERRIDES = new Map()
176
176
  function overrideKey(np, model) {
177
177
  return normalizeModelName(np) + '/' + normalizeModelName(model)
@@ -407,7 +407,7 @@ export const VISION_IMAGE_MAX_TOKENS = 384
407
407
  // · 2026 年:国办发明电〔2025〕7 号(2025-11-04 发布)
408
408
  // https://www.gov.cn/zhengce/zhengceku/202511/content_7047091.htm
409
409
  // 调休补班的周六/周日**不计高峰**:定价规则只看「周一至周五」,调休不改变这一点。
410
- // 新一年度的安排通常在上一年 11 月公布,届时更新本表并随版本发布;也可在插件配置卡
410
+ // 新一年度的安排通常在上一年 11 月公布,届时更新本表并随版本发布;也可在配置面板
411
411
  // 用 `peakHolidays` 覆盖(见 setPeakHolidays)。
412
412
  // ------------------------------------------------------------
413
413
  export const CN_HOLIDAYS = [
@@ -455,7 +455,7 @@ let PEAK_HOLIDAY_LIST = null
455
455
  let PEAK_HOLIDAY_SET = null // Set<string>(null 时按需从 CN_HOLIDAYS 构建)
456
456
 
457
457
  /**
458
- * 覆盖法定节假日列表(插件配置卡的「峰谷计价与提示」)。语义防呆:
458
+ * 覆盖法定节假日列表(配置面板的「峰谷计价与提示」)。语义防呆:
459
459
  * · 传 null / undefined / '' → 恢复内置表(默认);config 里存空串即走这条;
460
460
  * · 传 'none' / 'off' / '0' → 显式停用(不排除任何节假日,等价于按「仅周末」计);
461
461
  * · 传数组或分隔字符串 → 用该列表**整体替换**内置表(不追加);
package/sync.js CHANGED
@@ -240,7 +240,7 @@ function classifyStatus(status, body) {
240
240
  if (status === 200 && body && body.ok) return { ok: true }
241
241
  const code = (body && body.code) || ''
242
242
  if (status === 401 || code === 'TOKEN_INVALID' || code === 'TOKEN_MISSING') {
243
- return { ok: false, code: 'TOKEN_INVALID', needAuth: true, message: '云端令牌无效,请在插件配置里更新' }
243
+ return { ok: false, code: 'TOKEN_INVALID', needAuth: true, message: '云端令牌无效,请在「设置 → 花费统计 → 右上角齿轮 → 多机汇总」更新' }
244
244
  }
245
245
  if (status === 403) {
246
246
  return { ok: false, code, needAuth: false, message: (body && body.error) || '云端拒绝:设备被禁用或未开启自注册' }
package/vendor-catalog.js CHANGED
@@ -6,7 +6,7 @@
6
6
  // sourceUrl / checkedAt 以便溯源;条目单价为 **USD / 1M tokens**。
7
7
  //
8
8
  // 本插件账本恒以人民币(CNY)入账,因此目录价在计费时按 `catalogFxRate`
9
- // (默认 7.2,可在插件配置卡修改)折算为 CNY。缓存写入价沿用目录约定:
9
+ // (默认 7.2,可在配置面板修改)折算为 CNY。缓存写入价沿用目录约定:
10
10
  // 与缓存命中价(cachedInput)同价。
11
11
  //
12
12
  // 匹配规则(catalogEntryFor):