@angelyeye/dsh-cost-tracker 1.10.0 → 1.11.0

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,159 @@
2
2
 
3
3
  本文件用中文记录 dsh-cost-tracker 的版本变更。
4
4
 
5
+ ## v1.11.0(2026-11-13)
6
+
7
+ **Token 数量改中文单位(万/亿)· GPT Fast 档单独计价 · 目录汇率 6.67 · 新模型与价格表刷新**
8
+
9
+ ### 一、Token 数量统一为中文单位(万 / 亿)
10
+
11
+ **问题**:界面与工具里 token 一直显示成 `1.5M` / `314K`(英文单位),中英混排、量级不直观。
12
+
13
+ **改法**:新增纯函数模块 `token-format.js`,规则统一为
14
+
15
+ | 范围 | 显示 | 示例 |
16
+ |---|---|---|
17
+ | < 1 万 | 千分位整数 | `9,300` |
18
+ | ≥ 1 万 < 1 亿 | `X.X万`(≥100 万取整) | `31.4万` / `150万` / `3138万` |
19
+ | ≥ 1 亿 | `X.XX亿`(≥10 亿 1 位) | `1.5亿` / `327.7亿` |
20
+
21
+ 落点(全量):
22
+ - 前端 `client.js`:概览卡副行、Tokens 主值、订阅面板、设备×Agent 矩阵、热力图顶部与 tooltip、图表刻度(`fmtTokens` / `fmtCompact` / `fmtInt` 的 token 用途全部收敛到一处);
23
+ - 宿主 `index.js`:`cost_stats` 工具输出;
24
+ - 云端看板 `web/state.js` 的 `fmtTokens` 与 `web/app.js`、`web/views.js` 的展示文案。
25
+
26
+ 同时新增 `fmtTokensExact` 保留完整千分位数值(tooltip / 明细 / CSV 口径不受影响);工具 JSON 与 CSV 的**数值字段不变**,只改展示文本。
27
+
28
+ **UI 兼容**:中文单位让数字变宽,补了 `font-variant-numeric: tabular-nums` 防抖动,Fast 价格行与矩阵列改为「等宽数字 + 单行省略」,避免窄容器换行错位或单位被截断。
29
+
30
+ ### 二、GPT Fast 档(`service_tier: fast` / `priority`)单独计价
31
+
32
+ **背景**:OpenAI 于 2026-07-30 把 Priority processing 更名为 Fast mode,请求可用 `service_tier: "fast"` 或 `"priority"`;同一模型的 Fast 档价格与标准价不同(多数 2 倍)。此前插件只按模型名匹配单价,Fast 请求被按标准价记账,金额系统性偏低。
33
+
34
+ **宿主现状**:当前运行时不给插件层提供档位(`GenerateOptions` / `TokenUsage` / stream 事件都没有该字段),因此插件自己取档位:
35
+
36
+ 1. 请求参数 `options.serviceTier`(未来宿主支持时优先);
37
+ 2. 会话在 **`dsh-fast-tier`** 插件里的档位选择(该插件把选择写进会话日志的 `steered` 事件,`source.kind = 'fast-tier'`);
38
+ 3. 都拿不到 → 标准档。
39
+
40
+ 新增 `fast-tier.js`(纯逻辑):`billableTierOf` / `tierOfSteeredEvent` / `tierFromEvents` / `createTierResolver` / `resolveTier`。解析器**只读**(读会话对象与已注册投影,不注册同名投影、不写会话),`sessions` / `sessionProjections` 声明为**可选依赖**,任一环节缺失或抛错都降级 `standard`,绝不影响记账主流程。
41
+
42
+ **价格来源**:只认目录里**显式登记**的 `serviceTiers.fast`,绝不按「×2」推算。已登记 6 个模型(官方 Fast 页 + 交叉核对):
43
+
44
+ | 模型 | 标准(USD 输入/缓存读/输出) | Fast | 来源 |
45
+ |---|---|---|---|
46
+ | gpt-6-astra | 10 / 1 / 50 | 20 / 2 / 100 | 官方 |
47
+ | gpt-6.1-sol | 2 / 0.1 / 10 | 4 / 0.2 / 20 | 官方 |
48
+ | gpt-6.1-terra | 1 / 0.05 / 5 | 2 / 0.1 / 10 | 官方 |
49
+ | gpt-6-sol | 2 / 0.2 / 10 | 4 / 0.4 / 20 | 官方 |
50
+ | gpt-5.6-sol | 4 / 0.4 / 20 | 8 / 0.8 / 40 | 官方 |
51
+ | gpt-6-luna | 0.1 / 0.01 / 0.5 | 0.2 / 0.02 / 1 | 交叉核对 |
52
+
53
+ 无 Fast 档价的模型(5.4 / 5.6 Luna 等)按标准价计并标 `standard-only`;`ultrafast` 按 Fast 价计并标注「实际倍率更高、金额偏低」。
54
+
55
+ ### 三、长上下文分档与独立缓存写价
56
+
57
+ - 目录条目新增 `longContext`(`inputTokensAbove` + 长档价):请求**输入侧** token 超过阈值(OpenAI 272K)时按整请求长档价计。阈值判定只看输入,输出不计入。
58
+ - 目录条目新增 `cacheWriteInput`:OpenAI / Anthropic 的缓存写价与读价不同(如 gpt-6.1-sol 读 $0.1、写 $2.5),此前被强行按读价计。`computeCost` 改为读写分别计价;未提供写价时沿用读价,DeepSeek 等读写同价模型结果完全不变。
59
+
60
+ ### 四、目录汇率 7.2 → 6.67
61
+
62
+ - `vendor-catalog.js`:`CATALOG_FX_DEFAULT = 6.67`,新增 `CATALOG_FX_LEGACY_DEFAULT = 7.2`;
63
+ - `config.js`:默认值改 6.67,`migrateCatalogFxRate` 把「仍是旧默认 7.2」的配置迁移到 6.67,**用户显式设置的其他值保留**;
64
+ - 云端 `catalog.js`:库内 `catalog_fx_rate` 残留 7.2 时迁移并写回;
65
+ - 前端 `client.js`:三处硬编码 7.2 改为常量 `DEFAULT_FX`。
66
+
67
+ > 这是全局汇率:所有 USD 计价模型(OpenAI / Anthropic / Gemini / xAI / Mistral 等)随之变化,账本仍以人民币入账,历史记录不回改。
68
+
69
+ ### 五、新模型与价格表刷新(2026-11-13)
70
+
71
+ 目录从 15 家 / 141 条扩到 **15 家 / 154 条**。
72
+
73
+ 新增:`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`)。
74
+
75
+ 改价校正:`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)等。
76
+
77
+ 口径说明写进 `notes`:官方优先、交叉核对其次、单源标注;促销到期日(`gemini-4-carbon` 12-01 翻倍、`hy4` 12-31 恢复目录价、`gpt-5.5-cyber-preview` 2027-02-01 下线、MiniMax M2.5/M2.7 11-18 下线)一并记录。
78
+
79
+ ### 五之二、中转站 / 聚合网关按模型名识别厂商(真实流量阻塞修复)
80
+
81
+ **问题(实测发现)**:本机 GPT 流量走的是中转站 `zhouhy-relay`,而目录只认厂商名(`openai`/`anthropic`/…),查不到 `zhouhy-relay` 就直接落到**通用兜底价 2 / 8 / 0.5 CNY**。后果有两层:
82
+
83
+ 1. 真实 GPT 调用长期被**低估约 6 倍**(`gpt-6.1-sol` 实际 ¥13.34/1M 输入,兜底只算 ¥2);
84
+ 2. 兜底路径没有档位概念,**Fast 价永远不生效** —— 这个缺口会直接让本次 Fast 功能在真实环境里空转。
85
+
86
+ **改法**:`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)。
87
+
88
+ **安全边界**:推断只决定「查哪家目录」,推断后仍要**真正命中该厂商的条目**才计精确价;推断不出厂商(或厂商目录里没有该模型)依旧返回 `null`,落回 provider / 通用兜底。`deepseek` 系不映射到目录厂商,仍走内置时代价。命中的条目 `via` 带 `+model-inferred` 标记,便于排查。
89
+
90
+ **实测(用户真实会话)**:`zhouhy-relay` + `gpt-6.1-sol`,档位 `priority`:
91
+
92
+ | | 标准价 | Fast 价 |
93
+ |---|---|---|
94
+ | 11 次真实 GPT 调用合计 | ¥44.86 | ¥89.72(+¥44.86,正好 2 倍) |
95
+
96
+ 同一批调用在旧口径(通用兜底)下只有约 ¥4.93 —— 修正后约为其 9 倍,这是**纠偏**而非涨价。
97
+
98
+ ### 五之三、带发布批次号的 DeepSeek 模型名(真实账本纠偏)
99
+
100
+ **问题(实测发现)**:真实流量里的模型 id 带批次后缀,例如 `deepseek-v4.1-flash-1017`、`deepseek-v4-1-flash-261017`。价表只登记了基础名,归一化后仍带数字尾巴 → 错过精确价 → 落到通用兜底,**缓存读按 ¥0.5 计而官方是 ¥0.04**(缓存部分贵 12.5 倍)。本机受影响约 2171 条记录(`tencentmaas` / `gongsi`)。
101
+
102
+ **改法**:`resolveModelInEra()` 增加一次「剥离尾部版本号后重试」,支持 `-1017`(MMDD)、`-261017`(YYMMDD)、`-2026-09`(YYYY-MM)三种写法。
103
+
104
+ **边界**:剥离只对 `deepseek` 开头的模型生效 —— 这些是同一模型的不同批次,价格一致;其它厂商的尾号可能代表不同档位(如 `gpt-5.4-mini`),不能一概剥离。
105
+
106
+ ### 六、云端(dsh-cost-cloud)配套
107
+
108
+ - `pricing.js` / `vendor-catalog.js` / `price-sync.js` / `docs/provider-pricing.json` 逐字节同源,`PRICING_SOURCE_HASH` 重算;
109
+ - `computeCostAt` 支持 `serviceTier` / `tokens`,并把 tokens 自动带入目录回调(长上下文分档与插件同口径);
110
+ - `ingest.js` 新增 `tierOfMeta`:按记录 `meta.serviceTier` 决定重算档位,**上报优先、重算留痕**的既有设计不变;
111
+ - `catalogInfo` 回显 `fastTierModelCount`;看板 token 改中文单位;
112
+ - 版本 1.5.0 → 1.6.0,`syncVer` 仍为 1,协议向后兼容(`meta` 为可选字段,未知 meta 被忽略)。
113
+
114
+ ### 七、测试
115
+
116
+ 新增 `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)。
117
+
118
+ 本仓 24 个测试文件、云端 18 个测试文件全部通过,`check-pricing-sync.js` 全绿。
119
+
120
+ ### 八、已知边界
121
+
122
+ - Fast 判定依赖 `dsh-fast-tier` 的会话选择;该插件被卸载/禁用后,历史 Fast 请求无法事后识别,按标准价计并标注「档位未知」。
123
+ - 网关私有倍率(sub2api 可能对 Fast 另计)不模拟;必要时用现有手动覆盖价处理。
124
+ - Ultrafast / Flex / Batch / 区域加价 / ChatGPT 订阅额度口径不在本期。
125
+ - 官方 Fast 页只列 4 个模型,`gpt-6-luna`、`gpt-5.6-sol` 的 Fast 价来自模型页 / LiteLLM / Pi 交叉核对,条目标注 `cross-checked`。
126
+
127
+ ## v1.10.1(2026-10-25)
128
+
129
+ **安全加固:本地状态文件在 POSIX 上收紧为 owner-only(目录 0700 / 文件 0600);新增 PR CI 门禁(`pull_request` 跑 `npm test`)**
130
+
131
+ > 这两项改进来自外部贡献者 [@shaunpalmer](https://github.com/shaunpalmer) 的 PR #1([Project studios/english hardening](https://github.com/Angelyeye/dsh-cost-tracker/pull/1))。该 PR 整体未合并(包名改为 `@shaunpalmer/…`、版本回退、客户端砍掉约 90% 的界面、屏蔽配置入口、并移除了两个 UI 回归测试),但其中「文件权限收紧」与「PR 跑测试」两处是真实缺口,本次按当前代码结构重写后落地。
132
+
133
+ ### 一、本地状态文件权限收紧(`store.js` / `sync.js` / `index.js`)
134
+
135
+ **问题**:`~/.dsh/storages` 下的文件走默认 umask(常见 022)创建,POSIX 上同机其他用户可读。而这里存的是**完整用量明细**(会话、模型、token、花费;未开启脱敏时还有 sessionId)、设备身份与同步游标、云端同步地址等。
136
+
137
+ **改法**:
138
+
139
+ - `store.js` 导出 `PRIVATE_DIR_MODE = 0o700` / `PRIVATE_FILE_MODE = 0o600`:记录文件与实例锁的**目录创建**带 0700、**文件写入**带 0600;
140
+ - `sync.js` 的 `device.json`、`cost-tracker-sync.json` 同样走「目录 0700 + 文件 0600」,并把两处重复的「写临时文件 → rename」收成 `writePrivateJson()`;
141
+ - `index.js` 的配置文件、官方价格状态、历史导入清单也补上同样的模式;
142
+ - **只影响新建**:不 chmod 已有文件,避免动到用户既有部署的权限策略;Windows 忽略 mode,行为完全不变;CSV 导出(用户主动选择落地位置的产物)保持默认权限,方便分享。
143
+
144
+ **测试**:`test/storage.test.js` 用注入的 fs 断言 `mkdirSync(…,{mode:0o700})` / `writeFileSync(…,{mode:0o600})` 真的传进去了(跨平台可断言),并在 POSIX 上额外核对真实文件权限 0600;`test/sync.test.js` 在 POSIX 上核对身份目录/文件与同步目录/游标的实权限,同时验证私有权限路径不影响读写(游标可读回、不留 `.tmp`)。
145
+
146
+ ### 二、新增 PR CI 门禁(`.github/workflows/ci.yml`)
147
+
148
+ 此前仓库只有手动触发的 `publish-npm.yml`,**PR 上没有任何检查**(评审外部 PR 时只能本地 checkout 分支跑测试)。新增 `CI` 工作流:`pull_request` 与 `push: main` 触发,`permissions: contents: read`(无凭据、fork PR 也能安全跑),Node 24(与发布工作流同版本),执行与发布关卡同一条 `npm test`;另加 concurrency 取消同分支旧运行。不使用 npm cache —— 本包零 npm 依赖、无 lockfile,缓存只会多一次报错。
149
+
150
+ ### 三、未采纳部分(保留在作者自己的 fork)
151
+
152
+ 包名/版本/入口变更、`index.safe.js` 用 Proxy 屏蔽 `settings` 服务并临时篡改 `process.argv[1]`、英文重写全部模块并替换 README/CHANGELOG(会丢失发布历史,而仓库已有 `README.en.md`)、NZD 展示(浏览器直连第三方汇率 API,且写死单一币种)。隐私默认值(`maskSessionId` / `includePurpose`)方向合理但会改变现有云端归因口径,保持当前默认,后续以显式选项讨论。
153
+
154
+ ### 四、测试
155
+
156
+ `npm test` 全绿(22 个测试文件);`storage` 85 项、`sync` 126 项断言通过。
157
+
5
158
  ## v1.10.0(2026-10-25)
6
159
 
7
160
  **模型目录刷新到 2026-10-25 官方口径:15 家厂商 / 141 个条目(新增 51、改价 10、口径修正 25);火山方舟 Coding Plan 白名单按官方现行 13 个 Model Name 复核,并给「泛 volcengine」分支补上日期后缀容忍**
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 签名、响应解析、凭据归一(纯逻辑,可独立测试)
package/client.js CHANGED
@@ -282,6 +282,14 @@ window.__ModuleLoader__.load({
282
282
  .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; }
283
283
  .cost-cfg-chip b { color: var(--dsw-alias-label-primary, #171a1f); font-weight: 600; font-variant-numeric: tabular-nums; }
284
284
  .cost-cfg-chip.is-on { border-color: var(--dsw-alias-brand-primary, #2563eb); color: var(--dsw-alias-brand-primary, #2563eb); }
285
+ /* v1.11.0:GPT Fast 档价格行(token 走「万/亿」后数字变宽,用等宽数字 + 单行省略兜底) */
286
+ .cost-fast-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; padding: 2px 0; font-size: 12px; font-variant-numeric: tabular-nums; }
287
+ .cost-fast-name { flex: 0 0 auto; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-primary, #171a1f); font-weight: 500; }
288
+ .cost-fast-pair { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-secondary, #5b6472); }
289
+ .cost-fast-sep { opacity: .45; }
290
+ .cost-fast-tag { flex: 0 0 auto; font-size: 11px; padding: 0 6px; border-radius: 999px; border: .5px solid var(--dsw-alias-border-l2, #e5e7eb); color: var(--dsw-alias-label-secondary, #5b6472); white-space: nowrap; }
291
+ /* token 数字统一等宽,避免 万/亿 切换时宽度跳动 */
292
+ .cost-matrix-num, .cost-ug-tip-val, .cost-stat-sub { font-variant-numeric: tabular-nums; }
285
293
  .cost-sec { border: 1px solid var(--dsw-alias-border-l1, #e5e7eb); border-radius: 10px; margin-top: 10px; overflow: hidden; }
286
294
  .cost-sec-head { appearance: none; width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; background: none; border: 0; display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
287
295
  .cost-sec-head:hover { background: var(--dsw-alias-bg-layer-2, transparent); }
@@ -366,6 +374,9 @@ window.__ModuleLoader__.load({
366
374
  e("path", { d: "M8.75 3.5 5.25 7l3.5 3.5", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" }));
367
375
  }
368
376
 
377
+ /** 目录价 USD→CNY 缺省汇率(与后端 vendor-catalog.CATALOG_FX_DEFAULT 一致;真实值由后端回显) */
378
+ const DEFAULT_FX = 6.67;
379
+
369
380
  function fmtInt(n) { return String(Math.round(Number(n) || 0)).replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
370
381
  function fmtMoney(n) {
371
382
  const x = Number(n) || 0;
@@ -380,14 +391,29 @@ window.__ModuleLoader__.load({
380
391
  if (n >= 1000) return (n / 1000).toFixed(1) + "K";
381
392
  return String(Math.round(n));
382
393
  }
383
- // 热力图 token 显示:<1000 原样;≥1000 用 K(≥100 时取整),≥1000000 用 M(≥100 时取整)
394
+ // v1.11.0:token 数量统一中文口径(与 token-format.js 同一规则,双端一致)
395
+ // <1万 → 千分位整数;≥1万 → X.X万(≥100万取整);≥1亿 → X.XX亿(≥10亿 1 位)
396
+ // 保留 fmtTokens 这个函数名(调用点最多),但语义已换成中文单位,
397
+ // 这样 Windows 大小写不敏感的文件系统上不会出现两个只差大小写的同名函数。
384
398
  function fmtTokens(n) {
385
- const v = Math.max(0, Number(n) || 0);
386
- const scaled = (x) => (x >= 100 ? String(Math.round(x)) : String(Math.round(x * 10) / 10));
387
- if (v < 1000) return String(Math.round(v));
388
- if (v < 1000000) return scaled(v / 1000) + "K";
389
- return scaled(v / 1000000) + "M";
390
- }
399
+ const raw = Number(n);
400
+ const v = Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 0;
401
+ const trim = (s) => (s.indexOf(".") >= 0 ? s.replace(/\.?0+$/, "") : s);
402
+ if (v < 10000) return String(v).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
403
+ if (v < 100000000) {
404
+ const w = v / 10000;
405
+ return (w >= 100 ? String(Math.round(w)) : trim(w.toFixed(1))) + "万";
406
+ }
407
+ const y = v / 100000000;
408
+ return (y >= 10 ? trim(y.toFixed(1)) : trim(y.toFixed(2))) + "亿";
409
+ }
410
+ /** token 精确显示(tooltip / 明细用,完整千分位不换算单位) */
411
+ function fmtTokensExact(n) {
412
+ const raw = Number(n);
413
+ const v = Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 0;
414
+ return String(v).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
415
+ }
416
+ // 热力图 token 显示:统一走上面的 fmtTokens(v1.11.0 起为中文单位 万/亿)
391
417
  function fmtAxisMoney(v) {
392
418
  if (v <= 0) return "0";
393
419
  if (v >= 1000) return (v / 1000).toFixed(1) + "k";
@@ -975,7 +1001,7 @@ window.__ModuleLoader__.load({
975
1001
  // on :主值 = 按量 + 订阅等值(Plan 总额);副行说明拆分,避免看数不明口径
976
1002
  const money = (t) => planTotal ? (Number(t.real) || 0) + (Number(t.sub) || 0) : (Number(t.real) || 0);
977
1003
  const moneySub = (t) => {
978
- const base = "调用 " + fmtInt(t.calls) + " 次 · Tokens " + fmtCompact(t.tokens);
1004
+ const base = "调用 " + fmtInt(t.calls) + " 次 · Token " + fmtTokens(t.tokens);
979
1005
  if (planTotal) {
980
1006
  return base + " · 含订阅 ¥" + fmtMoney(t.sub) + (t.subCalls ? "(" + fmtInt(t.subCalls) + " 次)" : "");
981
1007
  }
@@ -1011,11 +1037,11 @@ window.__ModuleLoader__.load({
1011
1037
  return e("div", { className: "cost-cards" },
1012
1038
  statCard("今日费用(CNY)" + planBadge + "[" + tag() + "]", "¥" + fmtMoney(money(today)), moneySub(today)),
1013
1039
  statCard("本月费用(CNY)" + planBadge, "¥" + fmtMoney(money(month)), moneySub(month)),
1014
- statCard("总花费(CNY)" + planBadge, "¥" + fmtMoney(money(all)), "调用 " + fmtInt(all.calls) + " 次 · Tokens " + fmtCompact(all.tokens) + (all.sub > 0 ? (planTotal ? " · 含订阅 ¥" + fmtMoney(all.sub) : " · 订阅 ¥" + fmtMoney(all.sub)) : "")),
1040
+ statCard("总花费(CNY)" + planBadge, "¥" + fmtMoney(money(all)), "调用 " + fmtInt(all.calls) + " 次 · Token " + fmtTokens(all.tokens) + (all.sub > 0 ? (planTotal ? " · 含订阅 ¥" + fmtMoney(all.sub) : " · 订阅 ¥" + fmtMoney(all.sub)) : "")),
1015
1041
  statCard("API 请求次数", fmtInt(all.calls + all.subCalls),
1016
1042
  "按量 " + fmtInt(all.calls) + " · 订阅 " + fmtInt(all.subCalls)),
1017
- statCard("Tokens", fmtInt(all.tokens + all.subTokens),
1018
- "按量 " + fmtCompact(all.tokens) + " · 订阅 " + fmtCompact(all.subTokens)),
1043
+ statCard("Token", fmtTokens(all.tokens + all.subTokens),
1044
+ "按量 " + fmtTokens(all.tokens) + " · 订阅 " + fmtTokens(all.subTokens)),
1019
1045
  statCard(balTitle, balValue, balSub));
1020
1046
  }
1021
1047
 
@@ -1103,7 +1129,7 @@ window.__ModuleLoader__.load({
1103
1129
  body = e("div", null, bars);
1104
1130
  }
1105
1131
  const stats = dash
1106
- ? "累计请求 " + fmtInt(dash.subCalls) + " 次 · Tokens " + fmtInt(dash.subTokens) + " · 等效按量费用 ¥" + fmtMoney(dash.subEquivalent)
1132
+ ? "累计请求 " + fmtInt(dash.subCalls) + " 次 · Token " + fmtTokens(dash.subTokens) + " · 等效按量费用 ¥" + fmtMoney(dash.subEquivalent)
1107
1133
  : "加载中…";
1108
1134
  return e("div", { className: "cost-panel" },
1109
1135
  e("div", { className: "cost-row" },
@@ -1187,7 +1213,7 @@ window.__ModuleLoader__.load({
1187
1213
  }
1188
1214
  }
1189
1215
  const stats = dash
1190
- ? "累计请求 " + fmtInt(dash.subCalls) + " 次 · Tokens " + fmtInt(dash.subTokens) + " · 等效按量费用 ¥" + fmtMoney(dash.subEquivalent)
1216
+ ? "累计请求 " + fmtInt(dash.subCalls) + " 次 · Token " + fmtTokens(dash.subTokens) + " · 等效按量费用 ¥" + fmtMoney(dash.subEquivalent)
1191
1217
  : "加载中…";
1192
1218
  return e("div", { className: "cost-panel" },
1193
1219
  e("div", { className: "cost-row" },
@@ -1381,7 +1407,7 @@ window.__ModuleLoader__.load({
1381
1407
  className: "cost-ug-tip",
1382
1408
  style: { left: left + "px", top: top + "px", transform: transform },
1383
1409
  },
1384
- e("div", { className: "cost-ug-tip-total" }, day.date + " · " + fmtTokens(tokens) + " tokens" + (day.calls ? " · " + fmtInt(day.calls) + " 次调用" : "")),
1410
+ e("div", { className: "cost-ug-tip-total" }, day.date + " · " + "Token " + fmtTokens(tokens) + (day.calls ? " · " + fmtInt(day.calls) + " 次调用" : "")),
1385
1411
  e("div", { className: "cost-ug-tip-row" }, e("span", { className: "cost-ug-tip-name" }, "输入"), e("span", { className: "cost-ug-tip-val" }, fmtTokens(day.input))),
1386
1412
  e("div", { className: "cost-ug-tip-row" }, e("span", { className: "cost-ug-tip-name" }, "缓存"), e("span", { className: "cost-ug-tip-val" }, fmtTokens((day.cacheRead || 0) + (day.cacheWrite || 0)))),
1387
1413
  e("div", { className: "cost-ug-tip-row" }, e("span", { className: "cost-ug-tip-name" }, "输出"), e("span", { className: "cost-ug-tip-val" }, fmtTokens(day.output))),
@@ -1390,7 +1416,7 @@ window.__ModuleLoader__.load({
1390
1416
 
1391
1417
  return e("div", { className: "cost-ug" },
1392
1418
  e("div", { className: "cost-ug-total" },
1393
- "累计 " + fmtTokens(t.tokens) + " tokens · 输入 " + fmtTokens(t.input) + " · 缓存 " + fmtTokens(t.cache) + " · 输出 " + fmtTokens(t.output) + " · " + fmtInt(t.calls) + " 次调用"),
1419
+ "累计 " + fmtTokens(t.tokens) + " · 输入 " + fmtTokens(t.input) + " · 缓存 " + fmtTokens(t.cache) + " · 输出 " + fmtTokens(t.output) + " · " + fmtInt(t.calls) + " 次调用"),
1394
1420
  e("div", { className: "cost-ug-host", ref: hostRef },
1395
1421
  e("div", { className: "cost-ug-grid", style: { gridTemplateColumns: "repeat(" + WEEKS + ", 1fr)" } }, cells),
1396
1422
  tipEl),
@@ -1750,7 +1776,7 @@ window.__ModuleLoader__.load({
1750
1776
  const [draft, setDraft] = useState({});
1751
1777
  // 分组草稿(各自独立保存;互不覆盖)
1752
1778
  const [peakDraft, setPeakDraft] = useState({});
1753
- const [bill, setBill] = useState({ showTotalWithPlan: false, priceMatch: "fuzzy", catalogFxRate: 7.2, planRows: [], priceRows: [] });
1779
+ const [bill, setBill] = useState({ showTotalWithPlan: false, priceMatch: "fuzzy", catalogFxRate: DEFAULT_FX, planRows: [], priceRows: [] });
1754
1780
  const [psDraft, setPsDraft] = useState({ priceSyncUrl: "", priceSyncAutoCheck: true });
1755
1781
  const [impDraft, setImpDraft] = useState({ autoImport: true });
1756
1782
  const [volcId, setVolcId] = useState("");
@@ -1811,7 +1837,7 @@ window.__ModuleLoader__.load({
1811
1837
  setBill({
1812
1838
  showTotalWithPlan: v.showTotalWithPlan === true,
1813
1839
  priceMatch: v.priceMatch === "exact" ? "exact" : "fuzzy",
1814
- catalogFxRate: typeof v.catalogFxRate === "number" ? v.catalogFxRate : 7.2,
1840
+ catalogFxRate: typeof v.catalogFxRate === "number" ? v.catalogFxRate : DEFAULT_FX,
1815
1841
  planRows: planOverridesToRows(v.planOverrides),
1816
1842
  priceRows: priceOverridesToRows(v.priceOverrides),
1817
1843
  });
@@ -1887,7 +1913,7 @@ window.__ModuleLoader__.load({
1887
1913
  apiCall("billing-config", {
1888
1914
  showTotalWithPlan: !!bill.showTotalWithPlan,
1889
1915
  priceMatch: bill.priceMatch === "exact" ? "exact" : "fuzzy",
1890
- catalogFxRate: Number(bill.catalogFxRate) || 7.2,
1916
+ catalogFxRate: Number(bill.catalogFxRate) || DEFAULT_FX,
1891
1917
  planOverrides: planRowsToObj(bill.planRows),
1892
1918
  priceOverrides: priceRowsToObj(bill.priceRows),
1893
1919
  }).then(v => {
@@ -2201,7 +2227,7 @@ window.__ModuleLoader__.load({
2201
2227
  e("div", { className: "cost-row", style: { gap: "8px" } },
2202
2228
  e("input", {
2203
2229
  className: "cost-input", style: { width: "90px" }, type: "number", step: "0.1", min: "0.1", max: "100",
2204
- value: String(bill.catalogFxRate == null ? 7.2 : bill.catalogFxRate),
2230
+ value: String(bill.catalogFxRate == null ? DEFAULT_FX : bill.catalogFxRate),
2205
2231
  onChange: ev => setBillField("catalogFxRate", Number(ev.target.value)),
2206
2232
  }),
2207
2233
  e("span", { className: "cost-hint" }, "目录单价为 USD/1M tokens,按此汇率折算为人民币入账"))),
@@ -2242,7 +2268,26 @@ window.__ModuleLoader__.load({
2242
2268
  cat ? e("div", { className: "cost-cfg-top", style: { marginTop: "6px" } },
2243
2269
  (cat.providers || []).map(p => e("span", { key: "cp" + p.id, className: "cost-cfg-chip" }, p.id, " ", e("b", null, p.count)))) : null,
2244
2270
  e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2245
- "命中目录 = 精确价(不计入「估算」);内置时代价优先于目录,手动覆盖价优先于两者;目录读取失败不影响计费,自动回落 provider 兜底。")));
2271
+ "命中目录 = 精确价(不计入「估算」);内置时代价优先于目录,手动覆盖价优先于两者;目录读取失败不影响计费,自动回落 provider 兜底。"),
2272
+ // v1.11.0: GPT Fast tier price comparison (service_tier fast / priority)
2273
+ cat && cat.fast && (cat.fast.models || []).length > 0
2274
+ ? e("div", { className: "cost-subblock", style: { marginTop: "10px" } },
2275
+ e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "GPT Fast 档价格(USD → CNY @" + cat.fast.fxRate + ")"),
2276
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2277
+ "共 " + cat.fast.models.length + " 个模型登记了 Fast 档价 · 核实 " + (cat.fast.checkedAt || "—")
2278
+ + "。判定来源:请求参数优先,其次读本会话在 dsh-fast-tier 里的档位选择;识别不到时按标准价计,绝不按倍率推算。"),
2279
+ e("div", { className: "cost-list", style: { marginTop: "6px" } },
2280
+ cat.fast.models.map(m => e("div", { key: "ft" + m.provider + m.model, className: "cost-fast-row" },
2281
+ e("span", { className: "cost-fast-name", title: m.model + " · " + (m.sourceUrl || "") }, m.model),
2282
+ e("span", { className: "cost-fast-pair", title: "CNY / 1M tokens:标准 → Fast" },
2283
+ "输入 ¥" + m.standardCny.input + "→¥" + m.fastCny.input,
2284
+ e("span", { className: "cost-fast-sep" }, " · "),
2285
+ "输出 ¥" + m.standardCny.output + "→¥" + m.fastCny.output),
2286
+ e("span", { className: "cost-fast-tag" }, m.confidence === "official" ? "官方" : "交叉核对")))))
2287
+ : null,
2288
+ cat && cat.fast && (cat.fast.models || []).length === 0
2289
+ ? e("div", { className: "cost-hint", style: { marginTop: "6px" } }, "目录中暂无登记 Fast 档价的模型。")
2290
+ : null));
2246
2291
 
2247
2292
  // ---------- ⑤ 历史导入 ----------
2248
2293
  const impBody = e("div", null,
@@ -2884,7 +2929,7 @@ window.__ModuleLoader__.load({
2884
2929
  e("span", { className: "cost-matrix-key", title: r.key }, r.key),
2885
2930
  e("span", { className: "cost-matrix-num" }, "¥" + fmtMoney(r.cost)),
2886
2931
  e("span", { className: "cost-matrix-num" }, fmtInt(r.calls)),
2887
- e("span", { className: "cost-matrix-num" }, fmtCompact(r.tokens)),
2932
+ e("span", { className: "cost-matrix-num" }, fmtTokens(r.tokens)),
2888
2933
  e("span", { className: "cost-matrix-note" }, r.tag || "")))),
2889
2934
  matrix && matrix.rows && e("div", { style: { marginTop: "10px" } },
2890
2935
  e("div", { className: "cost-hint" }, "设备 × Agent 矩阵(行=设备,列=Agent,点击云端「设备 × Agent」页可下钻到记录)"),
package/config.js CHANGED
@@ -275,10 +275,27 @@ export function defaultBillingConfig() {
275
275
  // 多厂商目录匹配模式:fuzzy(归一化包含匹配,默认)/ exact(全等)
276
276
  priceMatch: 'fuzzy',
277
277
  // 目录价 USD→CNY 汇率(目录数据为 USD / 1M tokens,账本为 CNY)
278
- catalogFxRate: 7.2,
278
+ // v1.11.0:默认由 7.2 调整为 6.67(见 CATALOG_FX_DEFAULT)
279
+ catalogFxRate: 6.67,
279
280
  }
280
281
  }
281
282
 
283
+ /**
284
+ * 汇率迁移:老配置里存着「旧默认 7.2」说明用户从未改过,升级后跟随新默认;
285
+ * 用户显式设置的其它合法值(如 6.9)保持不变。
286
+ * @param {number} fx - 配置里的原始汇率
287
+ * @param {number} def - 当前默认汇率
288
+ * @returns {number}
289
+ */
290
+ export function migrateCatalogFxRate(fx, def) {
291
+ const base = Number.isFinite(Number(def)) && Number(def) > 0 ? Number(def) : 6.67
292
+ const v = Number(fx)
293
+ if (!Number.isFinite(v) || v < 0.1 || v > 100) return base
294
+ // 旧默认值(7.2)与其等价写法(7.20 / "7.2")一并视为「未改过」
295
+ if (Math.abs(v - 7.2) < 1e-9 && Math.abs(base - 7.2) >= 1e-9) return base
296
+ return v
297
+ }
298
+
282
299
  /**
283
300
  * 规范化双轨计费与价格目录配置。
284
301
  * planOverrides 键统一为小写(provider 与 model 各自归一化拼 '/'),
@@ -305,7 +322,8 @@ export function normalizeBillingConfig(raw) {
305
322
  showTotalWithPlan: raw.showTotalWithPlan === true,
306
323
  planOverrides,
307
324
  priceMatch: raw.priceMatch === 'exact' ? 'exact' : 'fuzzy',
308
- catalogFxRate: Number.isFinite(fx) && fx >= 0.1 && fx <= 100 ? fx : def.catalogFxRate,
325
+ // 旧默认 7.2 → 新默认 6.67:仅当配置值仍是旧默认时才迁移,用户自定义值保留
326
+ catalogFxRate: migrateCatalogFxRate(fx, def.catalogFxRate),
309
327
  }
310
328
  }
311
329