@angelyeye/dsh-cost-tracker 1.10.1 → 1.11.1

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,180 @@
2
2
 
3
3
  本文件用中文记录 dsh-cost-tracker 的版本变更。
4
4
 
5
+ ## v1.11.1(2026-11-16)
6
+
7
+ **时间区间口径修复:卡片主值跟随筛选 ・ 新增「今天」・ 云端区间真正生效 ・ 设备 × Agent 矩阵恢复**
8
+
9
+ 这一版修的全是**静默错值**——不报错、界面照常渲染,但数字是错的。四个问题互相缠绕,都源于「界面上的时间范围」和「实际取数的区间」不是同一件事。
10
+
11
+ ### 一、三张统计卡(花费 / API 请求次数 / Token)主值跟随时间筛选
12
+
13
+ **问题**:这三张卡直接读 `dash.all`(全时段累计),与顶部「近 N 天 / 全部」下拉完全无关。切到「近 7 天」时,图表与明细表都收窄了,卡片却依旧显示开天辟地以来的累计,同一屏内两套口径。
14
+
15
+ **改法**:主值改取窗口聚合 `dash.realCost / realCalls / realTokens / subEquivalent / subCalls / subTokens`(`buildDashboard({days})` 已按 cutoff 过滤),累计值降到副行并显式标注「累计 ¥X」,标题追加「· 近 7 天」后缀。
16
+
17
+ `今日费用`/`本月费用` 两卡保持原样——它们是固定日历口径,与滚动窗口无关是正确语义。
18
+
19
+ ### 二、新增「今天」选项(按北京日历日,不是近 24 小时)
20
+
21
+ 时间下拉新增首项「今天」。**不能简单加一个 `days=1`**:`buildDashboard` 原本的约定是 `cutoff = now - days*86400000`,`days=1` 会变成「近 24 小时」,把昨天晚间的消费算进今天,与旁边「今日费用」卡(北京日历日)对不上,屏幕上出现两个互相矛盾的「今天」。
22
+
23
+ 改法:抽出 `windowCutoff(days, now)` 作为**唯一**的区间换算入口,`days=1` 特判为北京时间当日 00:00:
24
+
25
+ | days | cutoff |
26
+ |---|---|
27
+ | 1 | 北京时间当日 00:00(今天) |
28
+ | >1 | `now - days*86400000`(滚动窗口) |
29
+ | ≤0 | 0(不限起点,全部) |
30
+
31
+ `buildDashboard` 与本版新增的云端 `fetchCloud` 共用它,确保「本机 + 云端」的两半落在同一区间。
32
+
33
+ ### 三、云端区间真正生效(此前恒定近 7 天)
34
+
35
+ **问题**:`fetchCloud()` 拼查询串时只发了 `range` 和 `days`,**从未发 `from`/`to`**;而 `cloud` 路由又把 `range` 默认值写死成 `'7d'`。结果:界面切「近 30 天 / 全部」,云端那一半纹丝不动,固定按近 7 天算。
36
+
37
+ **为什么不能靠 `range` 枚举解决**:云端 `resolveRange()` 只认 `today / 7d / 30d / 90d / month / year / all`,**其余值静默降级成 `all`**。实测传 `1d`、`14d` 会直接返回全时段累计且无任何报错——这比报错更难发现。所以凡有精确区间的地方一律走云端已支持的 `from`/`to` 自定义区间,不受枚举限制。
38
+
39
+ **改法**:
40
+ - `fetchCloud` 在 `days>0` 时用 `windowCutoff` 推导起点并写入 `from`/`to`;
41
+ - `cloud` 路由不再无条件写死 `range:'7d'`,改为 `a.range || (a.days === 0 ? 'all' : '7d')` 兜底。
42
+
43
+ **配套云端改动**(`dsh-cost-cloud` 同步发布):`readOverview` / `readPluginView` 的 union 分支透传 `from`/`to`。这两个函数此前用白名单式 `Object.assign` 转发参数,漏掉了 `from`/`to`,导致「仅云端」正常、「本机+云端」不跟随——一半对一半错。
44
+
45
+ ### 四、设备 × Agent 矩阵恢复渲染
46
+
47
+ **问题**:`loadCloudMatrix()` 请求宿主 `matrix` 路由,但宿主 `ROUTES` 里**根本没有这个路由**,稳定 404 → `setCloudMatrix(null)` → 矩阵区块永不渲染,且无任何提示。
48
+
49
+ **改法**:不再依赖不存在的路由,改由云端 `overview`/`plugin-view` 已返回的 `devices[]`(含 `sources[]`)与 `sources[]` 在客户端就地派生矩阵(`buildDeviceMatrix`),用派生值而非 state,`viewDash`/`days`/`view` 变化时自动重算。
50
+
51
+ **数据诚实性**:`devices[].sources` 只说明「该设备用过哪些 agent」,**不提供按 agent 拆分的金额**。因此单 agent 设备将整台金额记入该列;多 agent 设备无法拆分时格子**留空**并在表头注明,合计列仍为精确总额——不编造数字。
52
+
53
+ ### 测试
54
+
55
+ 新增 `test/time-range.test.js`(9 项断言):捕获真实发出的云端 URL,断言必须含 `from`/`to`、`days=1` 落在北京零点(UTC 16:00 整)、不同 `days` 必须产生不同区间(锁死「恒定 7d」回归)、`days=0` 走 `range=all` 且不带 `from`。
56
+
57
+ ## v1.11.0(2026-11-13)
58
+
59
+ **Token 数量改中文单位(万/亿)· GPT Fast 档单独计价 · 目录汇率 6.67 · 新模型与价格表刷新**
60
+
61
+ ### 一、Token 数量统一为中文单位(万 / 亿)
62
+
63
+ **问题**:界面与工具里 token 一直显示成 `1.5M` / `314K`(英文单位),中英混排、量级不直观。
64
+
65
+ **改法**:新增纯函数模块 `token-format.js`,规则统一为
66
+
67
+ | 范围 | 显示 | 示例 |
68
+ |---|---|---|
69
+ | < 1 万 | 千分位整数 | `9,300` |
70
+ | ≥ 1 万 < 1 亿 | `X.X万`(≥100 万取整) | `31.4万` / `150万` / `3138万` |
71
+ | ≥ 1 亿 | `X.XX亿`(≥10 亿 1 位) | `1.5亿` / `327.7亿` |
72
+
73
+ 落点(全量):
74
+ - 前端 `client.js`:概览卡副行、Tokens 主值、订阅面板、设备×Agent 矩阵、热力图顶部与 tooltip、图表刻度(`fmtTokens` / `fmtCompact` / `fmtInt` 的 token 用途全部收敛到一处);
75
+ - 宿主 `index.js`:`cost_stats` 工具输出;
76
+ - 云端看板 `web/state.js` 的 `fmtTokens` 与 `web/app.js`、`web/views.js` 的展示文案。
77
+
78
+ 同时新增 `fmtTokensExact` 保留完整千分位数值(tooltip / 明细 / CSV 口径不受影响);工具 JSON 与 CSV 的**数值字段不变**,只改展示文本。
79
+
80
+ **UI 兼容**:中文单位让数字变宽,补了 `font-variant-numeric: tabular-nums` 防抖动,Fast 价格行与矩阵列改为「等宽数字 + 单行省略」,避免窄容器换行错位或单位被截断。
81
+
82
+ ### 二、GPT Fast 档(`service_tier: fast` / `priority`)单独计价
83
+
84
+ **背景**:OpenAI 于 2026-07-30 把 Priority processing 更名为 Fast mode,请求可用 `service_tier: "fast"` 或 `"priority"`;同一模型的 Fast 档价格与标准价不同(多数 2 倍)。此前插件只按模型名匹配单价,Fast 请求被按标准价记账,金额系统性偏低。
85
+
86
+ **宿主现状**:当前运行时不给插件层提供档位(`GenerateOptions` / `TokenUsage` / stream 事件都没有该字段),因此插件自己取档位:
87
+
88
+ 1. 请求参数 `options.serviceTier`(未来宿主支持时优先);
89
+ 2. 会话在 **`dsh-fast-tier`** 插件里的档位选择(该插件把选择写进会话日志的 `steered` 事件,`source.kind = 'fast-tier'`);
90
+ 3. 都拿不到 → 标准档。
91
+
92
+ 新增 `fast-tier.js`(纯逻辑):`billableTierOf` / `tierOfSteeredEvent` / `tierFromEvents` / `createTierResolver` / `resolveTier`。解析器**只读**(读会话对象与已注册投影,不注册同名投影、不写会话),`sessions` / `sessionProjections` 声明为**可选依赖**,任一环节缺失或抛错都降级 `standard`,绝不影响记账主流程。
93
+
94
+ **价格来源**:只认目录里**显式登记**的 `serviceTiers.fast`,绝不按「×2」推算。已登记 6 个模型(官方 Fast 页 + 交叉核对):
95
+
96
+ | 模型 | 标准(USD 输入/缓存读/输出) | Fast | 来源 |
97
+ |---|---|---|---|
98
+ | gpt-6-astra | 10 / 1 / 50 | 20 / 2 / 100 | 官方 |
99
+ | gpt-6.1-sol | 2 / 0.1 / 10 | 4 / 0.2 / 20 | 官方 |
100
+ | gpt-6.1-terra | 1 / 0.05 / 5 | 2 / 0.1 / 10 | 官方 |
101
+ | gpt-6-sol | 2 / 0.2 / 10 | 4 / 0.4 / 20 | 官方 |
102
+ | gpt-5.6-sol | 4 / 0.4 / 20 | 8 / 0.8 / 40 | 官方 |
103
+ | gpt-6-luna | 0.1 / 0.01 / 0.5 | 0.2 / 0.02 / 1 | 交叉核对 |
104
+
105
+ 无 Fast 档价的模型(5.4 / 5.6 Luna 等)按标准价计并标 `standard-only`;`ultrafast` 按 Fast 价计并标注「实际倍率更高、金额偏低」。
106
+
107
+ ### 三、长上下文分档与独立缓存写价
108
+
109
+ - 目录条目新增 `longContext`(`inputTokensAbove` + 长档价):请求**输入侧** token 超过阈值(OpenAI 272K)时按整请求长档价计。阈值判定只看输入,输出不计入。
110
+ - 目录条目新增 `cacheWriteInput`:OpenAI / Anthropic 的缓存写价与读价不同(如 gpt-6.1-sol 读 $0.1、写 $2.5),此前被强行按读价计。`computeCost` 改为读写分别计价;未提供写价时沿用读价,DeepSeek 等读写同价模型结果完全不变。
111
+
112
+ ### 四、目录汇率 7.2 → 6.67
113
+
114
+ - `vendor-catalog.js`:`CATALOG_FX_DEFAULT = 6.67`,新增 `CATALOG_FX_LEGACY_DEFAULT = 7.2`;
115
+ - `config.js`:默认值改 6.67,`migrateCatalogFxRate` 把「仍是旧默认 7.2」的配置迁移到 6.67,**用户显式设置的其他值保留**;
116
+ - 云端 `catalog.js`:库内 `catalog_fx_rate` 残留 7.2 时迁移并写回;
117
+ - 前端 `client.js`:三处硬编码 7.2 改为常量 `DEFAULT_FX`。
118
+
119
+ > 这是全局汇率:所有 USD 计价模型(OpenAI / Anthropic / Gemini / xAI / Mistral 等)随之变化,账本仍以人民币入账,历史记录不回改。
120
+
121
+ ### 五、新模型与价格表刷新(2026-11-13)
122
+
123
+ 目录从 15 家 / 141 条扩到 **15 家 / 154 条**。
124
+
125
+ 新增:`gpt-6.1-terra`、`gpt-6-rosalind`、`gpt-6-cyber`、`gpt-5.6-cyber`、`gpt-5.5-cyber`、`gpt-5.5-cyber-preview`、`gpt-6-astra-law`、`claude-fable-5-2`、`claude-mythos-5-2`、`gemini-4-carbon`、`gemini-4-hydrogen`、`hy4`、`glm-5.3-flashx`、`qwen4-max-preview`(Token Plan 专属、无按 token 公开价,标 `unpriced`)。
126
+
127
+ 改价校正:`mistral-large-4`(0.70 / 0.07 / 2.10,旧值 1.36/4.18 来自第三方 host 非官方牌价)、`grok-4.7`(2 / 0.5 / 6,≥200K 翻倍)、`claude-opus-5-5`(4 / 0.2 / 20,缓存读 0.05x)等。
128
+
129
+ 口径说明写进 `notes`:官方优先、交叉核对其次、单源标注;促销到期日(`gemini-4-carbon` 12-01 翻倍、`hy4` 12-31 恢复目录价、`gpt-5.5-cyber-preview` 2027-02-01 下线、MiniMax M2.5/M2.7 11-18 下线)一并记录。
130
+
131
+ ### 五之二、中转站 / 聚合网关按模型名识别厂商(真实流量阻塞修复)
132
+
133
+ **问题(实测发现)**:本机 GPT 流量走的是中转站 `zhouhy-relay`,而目录只认厂商名(`openai`/`anthropic`/…),查不到 `zhouhy-relay` 就直接落到**通用兜底价 2 / 8 / 0.5 CNY**。后果有两层:
134
+
135
+ 1. 真实 GPT 调用长期被**低估约 6 倍**(`gpt-6.1-sol` 实际 ¥13.34/1M 输入,兜底只算 ¥2);
136
+ 2. 兜底路径没有档位概念,**Fast 价永远不生效** —— 这个缺口会直接让本次 Fast 功能在真实环境里空转。
137
+
138
+ **改法**:`vendor-catalog.js` 新增 `inferProviderFromModel(model)`,在 provider 名查不到时按**模型名前缀**推断厂商(`gpt-`/`o3`/`o4`/`codex` → openai,`claude` → anthropic,`gemini`/`gemma` → google,`grok` → xai,`glm` → z-ai,`qwen` → alibaba,`kimi`/`moonshot` → moonshot,`hy`/`hunyuan` → tencent,`mimo` → xiaomi,`solar` → upstage,`nemotron` → nvidia,`mistral`/`ministral`/`codestral`/`devstral`/`magistral` → mistral,`muse` → meta,`minimax` → minimax)。
139
+
140
+ **安全边界**:推断只决定「查哪家目录」,推断后仍要**真正命中该厂商的条目**才计精确价;推断不出厂商(或厂商目录里没有该模型)依旧返回 `null`,落回 provider / 通用兜底。`deepseek` 系不映射到目录厂商,仍走内置时代价。命中的条目 `via` 带 `+model-inferred` 标记,便于排查。
141
+
142
+ **实测(用户真实会话)**:`zhouhy-relay` + `gpt-6.1-sol`,档位 `priority`:
143
+
144
+ | | 标准价 | Fast 价 |
145
+ |---|---|---|
146
+ | 11 次真实 GPT 调用合计 | ¥44.86 | ¥89.72(+¥44.86,正好 2 倍) |
147
+
148
+ 同一批调用在旧口径(通用兜底)下只有约 ¥4.93 —— 修正后约为其 9 倍,这是**纠偏**而非涨价。
149
+
150
+ ### 五之三、带发布批次号的 DeepSeek 模型名(真实账本纠偏)
151
+
152
+ **问题(实测发现)**:真实流量里的模型 id 带批次后缀,例如 `deepseek-v4.1-flash-1017`、`deepseek-v4-1-flash-261017`。价表只登记了基础名,归一化后仍带数字尾巴 → 错过精确价 → 落到通用兜底,**缓存读按 ¥0.5 计而官方是 ¥0.04**(缓存部分贵 12.5 倍)。本机受影响约 2171 条记录(`tencentmaas` / `gongsi`)。
153
+
154
+ **改法**:`resolveModelInEra()` 增加一次「剥离尾部版本号后重试」,支持 `-1017`(MMDD)、`-261017`(YYMMDD)、`-2026-09`(YYYY-MM)三种写法。
155
+
156
+ **边界**:剥离只对 `deepseek` 开头的模型生效 —— 这些是同一模型的不同批次,价格一致;其它厂商的尾号可能代表不同档位(如 `gpt-5.4-mini`),不能一概剥离。
157
+
158
+ ### 六、云端(dsh-cost-cloud)配套
159
+
160
+ - `pricing.js` / `vendor-catalog.js` / `price-sync.js` / `docs/provider-pricing.json` 逐字节同源,`PRICING_SOURCE_HASH` 重算;
161
+ - `computeCostAt` 支持 `serviceTier` / `tokens`,并把 tokens 自动带入目录回调(长上下文分档与插件同口径);
162
+ - `ingest.js` 新增 `tierOfMeta`:按记录 `meta.serviceTier` 决定重算档位,**上报优先、重算留痕**的既有设计不变;
163
+ - `catalogInfo` 回显 `fastTierModelCount`;看板 token 改中文单位;
164
+ - 版本 1.5.0 → 1.6.0,`syncVer` 仍为 1,协议向后兼容(`meta` 为可选字段,未知 meta 被忽略)。
165
+
166
+ ### 七、测试
167
+
168
+ 新增 `test/token-format.test.js`(35 项)、`test/fast-tier.test.js`(45 项),并扩展 `test/client-render.test.js`(前端 `fmtTokens` 与 `token-format` 逐值一致 + 禁止英文单位回归)、`test/vendor-catalog.test.js`(汇率 6.67 / Fast 档 / 长档 / 独立写价)、`test/pricing.test.js`(Fast 计价端到端)、`test/config.test.js`(汇率迁移)、`test/recompute.test.js`(工具渲染)、`test/pricing-sync.test.js`(云端长档与 Fast)。
169
+
170
+ 本仓 24 个测试文件、云端 18 个测试文件全部通过,`check-pricing-sync.js` 全绿。
171
+
172
+ ### 八、已知边界
173
+
174
+ - Fast 判定依赖 `dsh-fast-tier` 的会话选择;该插件被卸载/禁用后,历史 Fast 请求无法事后识别,按标准价计并标注「档位未知」。
175
+ - 网关私有倍率(sub2api 可能对 Fast 另计)不模拟;必要时用现有手动覆盖价处理。
176
+ - Ultrafast / Flex / Batch / 区域加价 / ChatGPT 订阅额度口径不在本期。
177
+ - 官方 Fast 页只列 4 个模型,`gpt-6-luna`、`gpt-5.6-sol` 的 Fast 价来自模型页 / LiteLLM / Pi 交叉核对,条目标注 `cross-checked`。
178
+
5
179
  ## v1.10.1(2026-10-25)
6
180
 
7
181
  **安全加固:本地状态文件在 POSIX 上收紧为 owner-only(目录 0700 / 文件 0600);新增 PR CI 门禁(`pull_request` 跑 `npm test`)**
package/README.en.md CHANGED
@@ -38,13 +38,15 @@
38
38
  | 🧭 | **Multi-machine aggregation (cloud sync)** | Point it at your own **self-hosted cloud service** (separate `dsh-cost-cloud` repo, zero runtime dependencies) to merge usage from several computers; the dashboard then offers a **This machine / This machine + cloud / Cloud only** switcher plus a **device × Agent matrix** (row totals = column totals = grand total). Only token counts, cost, timestamps and identifiers are uploaded, with optional session-id masking |
39
39
  | 📈 | **Subscription quota** | Kimi Coding Plan and **Volcengine Ark Coding Plan**: quota progress bars, reset countdowns and pay-as-you-go-equivalent cost for reference. Volcengine is queried through the Ark **control-plane OpenAPI** (HMAC-signed), requiring an AccessKeyID + SecretAccessKey pair |
40
40
  | 💳 | **Balance lookup** | One-click DeepSeek account balance (total / topped-up / granted / status); **signed in to a DSH account it reads the Platform wallets (top-up / bonus) directly — no API key needed (v1.9.6)** |
41
+ | ⚡ | **GPT Fast tier pricing** | OpenAI Fast mode (`service_tier: fast` / `priority`) is billed apart from Standard: the 6 catalog models that **explicitly declare** a Fast price are charged at the official Fast rate (mostly 2x), with a separate long-context tier above 272K input. The tier comes from the request parameter or the session's choice in `dsh-fast-tier`; when it cannot be determined the Standard price applies — never a multiplied guess |
42
+ | 🔢 | **Chinese token units** | Token counts render in Chinese units everywhere: `9,300` / `31.4万` / `1.5亿` instead of `314K` / `1.5M`. Exact values (hover details, CSV) keep the full grouped number |
41
43
  | 🤖 | **Agent tools** | Ask in any chat: "how much have I spent today?" — the agent answers via `cost_stats` / `cost_prices` |
42
44
  | 🔻 | **Status line** | A live line under the chat input: **session cost** (segmented pills: session / subscription plan / per-model), split by the models actually used in the session; multi-model collapses to top2 by default, click to expand. Subscription shows the plan name; no quota or call-count clutter |
43
45
  | 🔥 | **Usage heatmap** | A "Token Usage" panel in Settings: a Codex-style **26-week daily-usage grid**, colored per-day by input / cache / output / cost with hover details and a today outline; all-time totals shown on top |
44
46
  | 💾 | **Local persistence** | Data lives in `~/.dsh/storages/cost-tracker-records.json`; survives restarts, never leaves your machine. **Details are kept for the last 180 days; older records are auto-compressed into permanent daily rollups, so all-time stats stay exact with bounded memory/disk** |
45
47
  | 🕰️ | **History import (v1.9.0)** | Replays host session logs to **backfill calls made before you installed the plugin** (each priced by its own timestamp); only calls the plugin could not have recorded (pre-install / downtime gaps); idempotent, and imported records are tagged `source=import` |
46
48
  | 🔄 | **Official price sync (v1.9.0)** | Fetches the official pricing page, parses each model's peak price and shows the diff; applying builds a **new pricing era** that only affects later records (history never shifts). The daily check only reports diffs and never auto-applies; a restructured page aborts instead of writing a wrong price |
47
- | 🌐 | **Multi-vendor price catalog (v1.9.0)** | 14 vendors / 90 entries (USD→CNY at a configurable rate), so models outside the built-in table (OpenAI / Anthropic / Gemini / Qwen …) get **exact** prices; fuzzy or exact matching plus manual price overrides |
49
+ | 🌐 | **Multi-vendor price catalog (v1.9.0)** | 15 vendors / 154 entries (USD→CNY at a configurable rate), so models outside the built-in table (OpenAI / Anthropic / Gemini / Qwen …) get **exact** prices; fuzzy or exact matching plus manual price overrides |
48
50
  | ⚖️ | **Plan vs metered dual basis (v1.9.0)** | One "Include Plan total" switch changes the basis: off = metered spend only, with subscriptions shown as a footnote; on = metered + subscription equivalent, merged into the charts as its own segment |
49
51
  | 🔐 | **No plaintext secrets (v1.9.0)** | The cloud token and the Volcengine secret live only in the DSH credential store (legacy plaintext migrates on startup); responses only report booleans; every outbound request goes through a host allowlist with forced https and no cross-host redirects |
50
52
  | 📤 | **CSV export** | One-click export of details + daily rollups (`purpose=rollup`) for further analysis in Excel / Numbers |
@@ -289,7 +291,7 @@ Conversations from **before you installed the plugin** can be backfilled: the pl
289
291
  ### Official price sync & multi-vendor catalog (v1.9.0)
290
292
 
291
293
  - **Official price sync**: "Check official prices" fetches the official pricing page (the Chinese page gives CNY directly), parses each model's peak price and diffs it against the currently effective table; "Apply new prices" turns the result into a **new pricing era** that only affects records at or after the apply moment — history keeps its own era, so past numbers never shift. A daily automatic check (on by default) only reports diffs and **never auto-applies**. The parser refuses to write anything on page restructures, missing numbers, or an off-peak price that is not exactly half the peak price;
292
- - **Multi-vendor price catalog**: 14 vendors / 90 model entries (OpenAI, Anthropic, Google, Moonshot, z-ai, xAI, Alibaba, MiniMax, Tencent, Xiaomi, Upstage, NVIDIA, Mistral, OpenCode; data adapted from `dsh-cost-meter`'s verified catalog, MIT), converted with a configurable USD→CNY rate (default 7.2). Models outside the built-in table are billed as **exact** prices instead of "estimated"; fuzzy (normalized containment) or exact matching;
294
+ - **Multi-vendor price catalog**: 15 vendors / 154 model entries (OpenAI, Anthropic, Google, Moonshot, z-ai, xAI, Alibaba, MiniMax, Tencent, Xiaomi, Upstage, NVIDIA, Mistral, OpenCode; data adapted from `dsh-cost-meter`'s verified catalog, MIT), converted with a configurable USD→CNY rate (default 6.67). Models outside the built-in table are billed as **exact** prices instead of "estimated"; fuzzy (normalized containment) or exact matching;
293
295
  - **Manual price overrides** per `provider/model` (input / output / cache) take the highest priority — for self-hosted endpoints or negotiated deals;
294
296
  - **Resolution order**: manual override > subscription classification > built-in / synced era > catalog > provider fallback > generic fallback. `cost_prices` and `/api/cost-tracker/prices` report the current era, synced eras, catalog fingerprint and overrides;
295
297
  - The cloud service (`dsh-cost-cloud ≥ v1.4.0`) implements the same rules with its own admin endpoints, and `/api/v1/protocol` reports which price version the cloud is actually using.
@@ -499,7 +501,7 @@ Example: `curl -X POST http://127.0.0.1:3080/api/cost-tracker/summary -d '{}'`
499
501
  - **History import** — replays the host session logs (many appended zstd frames, decompressed frame by frame) to backfill calls from **before the plugin was installed**. Idempotent three ways (manifest fast-skip, per-call dedup key, coverage rule), sessions straddling the install point are cut at the first live record, and imported records are tagged `source=import`. Auto-runs on startup (8 s delay, never blocks the boot); new agent tool `cost_import`;
500
502
  - **Credential-egress protection** — the cloud token and the Volcengine secret are written only to the DSH credential store (the config file keeps a boolean), legacy plaintext is migrated automatically on startup, and every outbound request goes through an allowlist with forced https and `redirect:'manual'` (3xx is a failure, so a redirect can never carry the `Authorization` header away). No response ever echoes a secret;
501
503
  - **Official price sync** — parses the official pricing page (a transposed table: columns are models, rows are metric × time band) into a new pricing era that only affects records at or after the apply moment, so history never shifts. Page restructures, missing numbers or an off-peak price that is not half the peak price all abort the sync instead of writing a wrong price. The daily automatic check only reports diffs;
502
- - **Multi-vendor price catalog** — 14 vendors / 90 entries (USD per 1M tokens, converted at a configurable rate), so models outside the built-in table get **exact** prices instead of "estimated"; fuzzy/exact matching plus a manual price-override table;
504
+ - **Multi-vendor price catalog** — 15 vendors / 154 entries (USD per 1M tokens, converted at a configurable rate), so models outside the built-in table get **exact** prices instead of "estimated"; fuzzy/exact matching plus a manual price-override table;
503
505
  - **Plan vs metered dual basis + "Include Plan total" switch** — one toolbar switch decides whether the money cards and charts show metered spend only (subscriptions shown as a footnote) or metered + subscription equivalent (a dedicated "subscription equivalent" chart segment). The choice is stored locally and written back to the server config;
504
506
  - **Settings unified + card redesign** — **Settings → Plugins → Plugin configuration → Cost Tracker** is now the single entry point, with seven collapsible groups (multi-machine aggregation / peak pricing & notices / subscriptions & quotas / pricing & catalog / history import / data & interface / security & credentials) under a status strip; the dashboard's peak panel became read-only;
505
507
  - **Tests** — four new files (`test/import.test.js` synthesises multi-frame zstd logs, `test/price-sync.test.js` also runs against a real fetched page, `test/vendor-catalog.test.js`, `test/credstore.test.js`), plus new client-render assertions for the amount-basis switch and the card groups: 17 test files, all green.
@@ -764,6 +766,8 @@ Either way: if only the UI (`client.js`) changed, a **hard browser refresh** (Cm
764
766
  ```
765
767
  ├── index.js Host half: usage capture, aggregation, HTTP API, agent tools
766
768
  ├── store.js Storage layer: 180-day detail retention + permanent daily rollups + atomic writes (with lock retries; pure logic, unit-testable)
769
+ token-format.js Chinese token-unit formatting (wan / yi); shared by UI and tools
770
+ ├── fast-tier.js GPT service-tier detection from the session log written by dsh-fast-tier (read-only)
767
771
  ├── pricing.js Pricing & tokens: price tables, peak/off-peak billing, vision model, peak-phase math, subscription gate (pure logic, unit-testable)
768
772
  ├── config.js Config layer: defaults & normalization for the peak-price notice, cloud sync, UI toggles and Volcengine credentials (pure logic, unit-testable)
769
773
  ├── volcengine.js Volcengine Ark quota: HMAC-SHA256 signing, response parsing, credential normalization (pure logic, unit-testable)
package/README.md CHANGED
@@ -39,13 +39,15 @@
39
39
  | 🔥 | **用量热力图** | 设置页新增「Token 用量统计」:类 Codex 的 **26 周日用量方格热图**,按天着色(输入 / 缓存 / 输出 / 费用),悬停看当日明细、今天高亮描边,顶部显示全时段累计;**跟随三态视图**——「本机+云端 / 仅云端」下自动并入云端按天用量(卡片标题右侧标注当前口径) |
40
40
  | 📈 | **订阅配额监控** | Kimi Coding Plan、**火山方舟 Coding Plan** 等订阅套餐:配额进度条、重置倒计时、等效按量费用参考。火山方舟走管控面 OpenAPI(HMAC 签名),需 AccessKeyID + SecretAccessKey |
41
41
  | 💳 | **余额查询** | 一键查询 DeepSeek 官方账户余额(总余额 / 充值 / 赠送 / 状态);**已登录 DSH 账号时直接读 Platform 钱包(充值 / 赠金),不再需要 API Key(v1.9.6)** |
42
+ | ⚡ | **GPT Fast 档计价** | OpenAI Fast mode(`service_tier: fast` / `priority`)与标准价分开计:目录里**显式登记**的 6 个模型按官方 Fast 价入账(多为 2 倍),长上下文(>272K 输入)另按长档价;档位来自请求参数或本会话在 `dsh-fast-tier` 里的选择,**识别不到就按标准价计**,绝不按倍率推算。无 Fast 报价的模型照旧按标准价 |
43
+ | 🔢 | **Token 中文单位** | 所有界面与工具里的 token 数量统一显示为中文单位:`9,300` / `31.4万` / `1.5亿`,不再出现 `314K` / `1.5M`;精确数值(悬停明细、CSV)保留完整千分位 |
42
44
  | 🤖 | **Agent 工具** | 直接在对话里问:"我现在花了多少钱?"——Agent 会调用 `cost_stats` / `cost_prices` 等工具回答 |
43
45
  | 🔻 | **状态栏** | 聊天输入框下方实时显示:**本会话花费**(胶囊分段:本会话 / 订阅套餐 / 分模型),按会话实际用到的模型与订阅拆分,**多模型默认折叠只显示 top2,点击展开全部明细**;订阅显示具体套餐名,不再展示配额与调用次数 |
44
46
  | 👁️ | **界面显示开关** | 输入框上方的花费胶囊、侧边栏峰谷时段条、设置页「花费统计」看板**三个落点各自可关**(设置 → 花费统计 → 右上角齿轮 → 数据与界面 → 界面显示),勾选即刻生效;**只影响显示**,记账、云端同步与 Agent 工具照常,配置入口(齿轮页)本身不受开关控制 |
45
47
  | 💾 | **本地持久化** | 数据存本机 `~/.dsh/storages/cost-tracker-records.json`,重启不丢、不上传;**明细保留最近 180 天,更早自动压缩为永久日汇总,全时段统计永远精确且内存/磁盘有界** |
46
48
  | 🕰️ | **历史导入(v1.9.0)** | 回放宿主会话日志,**把装插件之前的对话调用补录进账本**(按各自时间戳的旧价计费);只补插件不可能记到的部分(安装前 / 停机缺口),幂等可重复执行,导入记录标记 `source=import` 以便区分 |
47
49
  | 🔄 | **官方价格同步(v1.9.0)** | 一键抓取官方定价页、解析各模型峰价并对比差异,应用后构建**新的计费时代**(只影响之后,历史口径不回改);每日可自动核对(只提示、不自动应用),页面改版时宁可不同步也绝不写错价 |
48
- | 🌐 | **多厂商价格目录(v1.9.0)** | 内置 15 家厂商 / 141 个模型条目(USD→CNY 按可配汇率折算),OpenAI / Anthropic / Gemini / Qwen 等内置表之外的模型也能按**精确价**入账;支持宽松/严格匹配与**手动覆盖价** |
50
+ | 🌐 | **多厂商价格目录(v1.9.0)** | 内置 15 家厂商 / 154 个模型条目(USD→CNY 按可配汇率折算,默认 6.67),OpenAI / Anthropic / Gemini / Qwen 等内置表之外的模型也能按**精确价**入账;支持宽松/严格匹配与**手动覆盖价** |
49
51
  | ⚖️ | **Plan 与按量双轨(v1.9.0)** | 工具栏「含 Plan 总额」开关一键切换口径:关闭只算按量真金白银、订阅以附注展示;打开则金额 = 按量 + 订阅等值,图表按天并入「订阅等值」段 |
50
52
  | 🔐 | **凭据零落盘(v1.9.0)** | 云端令牌与火山 SecretAccessKey 只写 DSH 凭据库(配置文件零明文,旧版明文启动时自动迁移);任何响应只回显布尔;出站请求白名单 + 强制 https + 拒绝跟随重定向(防凭据外带) |
51
53
  | 📤 | **CSV 导出** | 一键导出明细 + 日汇总(purpose=rollup),方便用 Excel / Numbers 做进一步分析 |
@@ -270,7 +272,7 @@ docker compose up -d # 打开 http://<服务器>:8787 ,在「设置」页
270
272
  | **多机汇总(云端同步)** | 设备名、启用开关、服务地址、共享令牌、同步间隔、单批条数、会话脱敏、上报 purpose、上报日汇总、补传窗口、默认视图 + 保存 / 测试连接 / 立即同步 / 全量补传 + 设备 ID / 水位 / 最近错误 |
271
273
  | **峰谷计价与提示** | 峰谷开关、显著提示、时段条样式(简洁 / 环形表盘)、时间刻度 / 双行紧凑、切换提醒(提前量 / 类型 / 位置 / 系统通知)+ **改完即可预览**(时段条与弹窗预览) |
272
274
  | **订阅套餐与配额** | 火山方舟 `AccessKeyID` / `SecretAccessKey`(后者只进凭据库)、配额查询与百分比条、**订阅归类覆盖**表(`provider/*` 或 `provider/model` → 订阅 / 按量) |
273
- | **计价与价格目录** | 「含 Plan 总额」、目录匹配模式(宽松 / 严格)、USD→CNY 汇率、**手动覆盖价**表、**官方价格同步**(核对 / 应用 / 上次差异 / 当前时代 / 已同步时代)、**多厂商目录概览**(厂商与条目数、数据日期、指纹) |
275
+ | **计价与价格目录** | 「含 Plan 总额」、目录匹配模式(宽松 / 严格)、USD→CNY 汇率、**手动覆盖价**表、**官方价格同步**(核对 / 应用 / 上次差异 / 当前时代 / 已同步时代)、**多厂商目录概览**(厂商与条目数、数据日期、指纹)、**GPT Fast 档价格对照** |
274
276
  | **历史导入** | 自动导入开关、立即导入、累计导入条数与已处理日志数、三条口径说明 |
275
277
  | **数据与界面** | 界面显示三开关(勾选即刻生效)、导出 CSV、重算费用(试算 / 写回)、清空数据(两步确认) |
276
278
  | **安全与凭据** | 云端令牌 / 火山 SK 的「是否已配置 + 存储位置」徽章、旧版明文迁移状态、清除按钮与出站防护说明 |
@@ -290,7 +292,7 @@ docker compose up -d # 打开 http://<服务器>:8787 ,在「设置」页
290
292
  ### 官方价格同步与多厂商目录(v1.9.0)
291
293
 
292
294
  - **官方价格同步**:配置页里点「核对官方价」抓取官方定价页(中文页直接给出人民币价),解析出各模型峰价并与当前生效价对比;点「应用新价」把结果构建为**新的计费时代** —— 只对生效时刻**之后**的记录生效,历史记录按各自时间戳选版,口径不回改。每日可自动核对(默认开,只提示差异,**绝不自动应用**)。解析器对页面改版 / 数字缺失 / 「空闲价 ≠ 高峰一半」一律抛错,宁可不同步也绝不写错价;
293
- - **多厂商模型价格目录**:内置 15 家厂商 / 141 个模型条目(OpenAI / Anthropic / Google / Moonshot / z-ai / xAI / Alibaba / MiniMax / Tencent / Xiaomi / Upstage / NVIDIA / Mistral / Meta / OpenCode;数据改编自 `dsh-cost-meter` 的初始目录,MIT,2026-10-25 起按各厂商官方定价页逐条复核),按 USD→CNY 汇率(默认 7.2,可改)折算。内置表之外的模型命中目录即记**精确价**(不再标「估算」);匹配模式可选宽松(归一化包含)或严格(名称全等);
295
+ - **多厂商模型价格目录**:内置 15 家厂商 / 154 个模型条目(OpenAI / Anthropic / Google / Moonshot / z-ai / xAI / Alibaba / MiniMax / Tencent / Xiaomi / Upstage / NVIDIA / Mistral / Meta / OpenCode;数据改编自 `dsh-cost-meter` 的初始目录,MIT,2026-10-25 起按各厂商官方定价页逐条复核,2026-11-13 全量刷新),按 USD→CNY 汇率(默认 **6.67**,可改)折算。内置表之外的模型命中目录即记**精确价**(不再标「估算」);匹配模式可选宽松(归一化包含)或严格(名称全等);
294
296
  - **手动覆盖价**:`provider/model` → 输入 / 输出 / 缓存价,优先级最高,用于自建端点或议价套餐;
295
297
  - **计费优先级**:手动覆盖价 > 订阅归类(Plan)> 内置 / 同步时代精确价 > 多厂商目录 > provider 兜底 > 通用兜底。`cost_prices` 工具与 `/api/cost-tracker/prices` 会一并回显当前时代、同步时代、目录指纹与覆盖价;
296
298
  - 云端(`dsh-cost-cloud ≥ v1.4.0`)有同源实现与对应的管理端点,两边口径可对照(`/api/v1/protocol` 回显云端实际使用的价格版本与目录指纹)。
@@ -485,7 +487,7 @@ POST /api/cost-tracker/export 导出 CSV
485
487
  - **历史导入**:回放宿主会话日志(多 zstd frame 逐帧解压),补录「装插件之前」的调用。幂等三保险(清单快跳 + 逐调用键去重 + 覆盖判定),跨安装点会话按切割线截断,导入记录标记 `source=import`。默认开机自动执行(延迟 8 秒,不阻塞启动),新 Agent 工具 `cost_import`;
486
488
  - **凭据外带防护**:令牌与火山 SK 只写 DSH 凭据库(配置文件零明文),启动时自动迁移旧版明文;所有出站请求走白名单 + 强制 https + `redirect:'manual'`(拒绝跟随 3xx,防重定向把 `Authorization` 带走);任何响应只回显布尔与存储位置;
487
489
  - **价格同步**:解析官方定价页(转置价格表:列 = 模型、行 = 指标 × 时段)→ 构建新计费时代,只影响生效时刻之后的记录,历史口径不回改;页面改版 / 数字不齐 / 空闲价非半价一律抛错。每日自动核对只提示差异,应用需手动确认;
488
- - **多厂商模型价格目录**:15 家厂商 / 141 个模型条目(USD/1M tokens → 按汇率折 CNY),内置表之外的模型命中即记精确价;匹配模式宽松 / 严格可选;另有手动覆盖价表;
490
+ - **多厂商模型价格目录**:15 家厂商 / 154 个模型条目(USD/1M tokens → 按汇率折 CNY,默认 6.67),内置表之外的模型命中即记精确价;匹配模式宽松 / 严格可选;另有手动覆盖价表;
489
491
  - **Plan 与按量双轨 + 「含 Plan 总额」开关**:金额卡与图表口径一键切换(关闭只算按量、订阅以附注展示;打开则按量 + 订阅等值并入,图表出现「订阅等值」段),选择存浏览器并回写服务端;
490
492
  - **设置集中 + 卡片重设计**:`设置 → 插件 → 插件配置 → 花费统计` 成为唯一设置入口,按「多机汇总 / 峰谷计价与提示 / 订阅套餐与配额 / 计价与价格目录 / 历史导入 / 数据与界面 / 安全与凭据」七个折叠分组排列,顶部状态摘要条;看板上的峰谷面板改为只读回显;
491
493
  - **测试**:新增 `test/import.test.js`(合成多帧 zstd 会话日志,37 条断言)、`test/price-sync.test.js`(含真实页面回归)、`test/vendor-catalog.test.js`、`test/credstore.test.js`,`client-render` 增加金额口径开关与卡片分组断言 —— 共 17 个测试文件全绿。
@@ -750,6 +752,8 @@ POST /api/cost-tracker/export 导出 CSV
750
752
  ```
751
753
  ├── index.js Host 半端:用量采集、聚合、HTTP API、Agent 工具
752
754
  ├── store.js 存储层:明细保留 + 永久日汇总 + 原子落盘(含占用重试,纯逻辑可独立测试)
755
+ ├── token-format.js Token 数量中文单位(万/亿)格式化:纯函数,字号与工具共用同一规则
756
+ ├── fast-tier.js GPT 服务档位识别:读 dsh-fast-tier 写在会话日志里的档位选择(只读)
753
757
  ├── pricing.js 定价与 Token 层:单价表、峰谷计价、视觉模型、峰值相位、订阅门卫(纯逻辑,可独立测试)
754
758
  ├── config.js 配置层:峰谷计价提示 + 云端同步 + 界面显示 + 火山凭据的默认值与规范化(纯逻辑,可独立测试)
755
759
  ├── volcengine.js 火山方舟配额查询:HMAC-SHA256 签名、响应解析、凭据归一(纯逻辑,可独立测试)