@angelyeye/dsh-cost-tracker 1.9.5 → 1.10.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 +103 -0
- package/README.en.md +58 -3
- package/README.md +56 -6
- package/account.js +222 -0
- package/client.js +72 -12
- package/docs/THIRD-PARTY-NOTICES.md +1 -1
- package/docs/provider-pricing.json +585 -91
- package/import.js +42 -6
- package/index.js +128 -43
- package/package.json +4 -2
- package/pricing.js +47 -9
- package/settings.js +95 -0
- package/vendor-catalog.js +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,109 @@
|
|
|
2
2
|
|
|
3
3
|
本文件用中文记录 dsh-cost-tracker 的版本变更。
|
|
4
4
|
|
|
5
|
+
## v1.10.0(2026-10-25)
|
|
6
|
+
|
|
7
|
+
**模型目录刷新到 2026-10-25 官方口径:15 家厂商 / 141 个条目(新增 51、改价 10、口径修正 25);火山方舟 Coding Plan 白名单按官方现行 13 个 Model Name 复核,并给「泛 volcengine」分支补上日期后缀容忍**
|
|
8
|
+
|
|
9
|
+
### 一、多厂商目录:新增了哪些新模型
|
|
10
|
+
|
|
11
|
+
目录上次刷新是 2026-08-18(`generatedAt` 可查),两个多月里各家的新旗舰与降价款都没进来。本次逐家复核,`providers` 从 14 家 90 条扩到 **15 家 141 条**(新增 51,改价 10,其余为来源/口径修正 25;删除 0 条,下线模型一律保留并打 `notes` 标记,便于历史记录核对)。
|
|
12
|
+
|
|
13
|
+
| 厂商 | 本次新增(部分) | 变化要点 |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| OpenAI | `gpt-6-astra` / `gpt-6-sol` / `gpt-6.1-sol` / `gpt-6-luna` | `gpt-5.6-sol` **降价 $5/$30 → $4/$20** |
|
|
16
|
+
| Anthropic | `claude-fable-5-1`、`claude-mythos-5-1`、`claude-opus-5-5`、`claude-sonnet-5-5`、`claude-haiku-5-5` | `claude-sonnet-5` 早鸟价 `$2/$10` 经官方 2026-08-10 公告**永久化**,notes 修正 |
|
|
17
|
+
| Google | `gemini-4-argon`(5 折至 2026-11-30)、`gemini-3.8-flash` | 3.7/3.8 Flash 促销口径两源冲突,notes 标「未核实」 |
|
|
18
|
+
| Moonshot | `kimi-k3.1-pro`、`kimi-k3.1-pro-highspeed` | `kimi-k2.5` 官方 2026-08-31 下线(保留 + notes) |
|
|
19
|
+
| 智谱 z-ai | `glm-5.3-flash`、`glm-5.3-flashx`;`glm-5.3` **由 unpriced 恢复精确价** `$1.40/$4.40` | 官方已公布单价,原「不编造价格」占位作废 |
|
|
20
|
+
| xAI | `grok-4.7`、`grok-4.20-0309-reasoning` / `-non-reasoning` / `multi-agent-0309` | `grok-4.3` 补 `cachedInput 0.20`;各档补 >200K 分档说明 |
|
|
21
|
+
| Alibaba | `qwen3.8-flash` | `qwen3.8-max` / `qwen3.7-max` 缓存读价按官方 10% 修正为 `0.20` / `0.25` |
|
|
22
|
+
| MiniMax | `minimax-m3.1-flash`(¥1/¥0.10/¥4,按 7.2 折算) | `minimax-m3` 补 >512K 档与 priority ×1.5 说明 |
|
|
23
|
+
| 腾讯混元 | `hy4-preview`(¥6/¥0.30/¥18 折算) | `hunyuan-a13b` 原值实为**人民币刊例价**,改为美元口径 `0.069/0.278`;`hy3` 升为 official |
|
|
24
|
+
| 小米 MiMo | `mimo-v2.6-pro` / `mimo-v2.6-flash` / `mimo-v2.6-pro-ultraspeed` | `mimo-v2.5` 系 2026-10-21 10:00 下线(保留 + notes) |
|
|
25
|
+
| Upstage | `solar-mini-4` | `solar-pro4` 2026-10-20 起 5 折;`solar-pro3` 2026-10-30 停服(notes) |
|
|
26
|
+
| NVIDIA | `nemotron-3.5-lightning-30b-a3b`、`nemotron-3.5-super-vl-120b-a12b` | 官方仍未公布 token 单价,保持 `unpriced` |
|
|
27
|
+
| Mistral | `mistral-large-4`(Public Preview)、`mistral-small-2603`(原 `mistral-small-4.0` 更名)、`ministral-14b/8b/3b-2512` | 官方价表未列缓存价,缓存值 notes 标「未核实」 |
|
|
28
|
+
| **Meta(新厂商)** | `muse-wonder-1.0`、`muse-spark-1.3`、`muse-spark-1.2` | 新增 provider 别名 `meta` / `meta-ai` / `muse` |
|
|
29
|
+
| OpenCode Go 档 | 补 17 条:`grok-4.7`、`glm-5.3`(原 unpriced → `$1.40/$4.40`)、`kimi-k3.1-pro`、`gpt-6-luna`、`gemini-4-argon`、`hy4-preview`、`deepseek-v4.1-flash` / `v4-pro` 等 | 订阅档按「固定月费 + 每模型月度美元额度」计量,token 单价与按量档一致 |
|
|
30
|
+
|
|
31
|
+
**未收录的模型与原因**(不编造价格):
|
|
32
|
+
- `Big Pickle` / `Beam` / `Flint 40B` / `LongCat 2.5 Preview`:仅以网关限时免费档存在,或厂商主体未披露,无公开 token 价 → 不落表(`LongCat-2.0` 有网关价,已收录在 OpenCode Go 档);
|
|
33
|
+
- 智谱国内 `bigmodel.cn` 人民币价、Kimi K2.7 / K2.6 官方 API 单价、MiniMax 国际站美元价:官方页本机抓不到正文 → 沿用网关值并在 `notes` 明确标注出处;
|
|
34
|
+
- OpenAI / Google 官方定价页本机返回 403 / DNS 不可达 → 这两家的值取自 OpenCode Console 网关价,`sourceUrl` 如实写网关地址,并用 OpenRouter 端点做交叉核对(一致 / 冲突都在 `notes` 写明)。
|
|
35
|
+
|
|
36
|
+
### 二、火山方舟 Coding Plan 白名单(`pricing.js`)
|
|
37
|
+
|
|
38
|
+
- 白名单从 14 个扩到 **24 个 id**:按官方 2026-10「Coding Plan 个人版快速开始」复核,补入 `kimi-k3`、`kimi-k3.1-pro`、`kimi-k2.8-preview`、`deepseek-v4.1-flash-economy`、`deepseek-v4-flash`、`glm-5.3`、`glm-latest`、`doubao-seed-2.1-lite`、`doubao-seed-2.0-mini`、`doubao-seed-evolving`;`glm-5.2` 列入(2026-08-31 起官方由 `glm-5.3` 承接)。
|
|
39
|
+
- 旧白名单里 9 个「4 月还在、10 月官方清单不列」的 id **不删**:下线公告页本机取不到正文,删错会把仍在售的套餐内模型误标成按量;保留的代价只是极端情况下少算按量花费(方向更安全,符合本项目「宁可漏配也不能错配」的门卫原则)。
|
|
40
|
+
- **新增日期后缀容忍**:方舟模型 id 普遍带 6 位日期后缀(`glm-5-3-flash-260828`、`deepseek-v4-1-flash-260910`、`doubao-seed-2-1-pro-260915`),而 `normalizeModelName` 只去分隔符。专属 coding 端点因「整档订阅」提前 return 不受影响,但**泛 `volcengine` 分支**下这些 id 会漏配 → 被标成「按量 · 估算」。现新增 `stripVolcDateSuffix()`:先剥尾部 `\d{6}` 再查白名单与前缀,`ep-20260413045435-2shmq` 这类接入点 id 仍不会被误判。
|
|
41
|
+
- Kimi 订阅侧无需改动(`SUBSCRIPTION_MODELS` 为 `null` = 整档订阅),`6.5/27.0/1.1/1.1` 仍是估算值——官方明确不公开套餐内 token 等效价。
|
|
42
|
+
|
|
43
|
+
### 三、数据纪律
|
|
44
|
+
|
|
45
|
+
- 每条新增/改动都带 `sourceUrl` + `checkedAt: 2026-10-25`;官方页优先,网关兜底时在 `notes` 写明「取自网关 / 未核实 / 两源冲突」,与仓库既有的「不编造价格」约定一致。
|
|
46
|
+
- `CATALOG_META.generatedAt` 同步为 `2026-10-25`(设置页「数据日期」与云端 `/api/v1/protocol` 都会回显)。
|
|
47
|
+
- 计费优先级不变:手动覆盖价 > 订阅归类 > 内置/同步时代精确价 > 目录 > provider 兜底 > 通用兜底。
|
|
48
|
+
|
|
49
|
+
### 四、测试
|
|
50
|
+
|
|
51
|
+
- `test/vendor-catalog.test.js` 新增断言:`meta` 厂商在列、`glm-5.3` / `gpt-6-astra` / `kimi-k3.1-pro` 可命中(防止「只加 JSON 不加别名」或「占位未清」回归)。
|
|
52
|
+
- `test/pricing.test.js` 更新火山门卫断言到 2026-10 官方白名单(含 `glm-latest` 别名),并新增「泛 volcengine 带日期后缀仍计为订阅」与「接入点 id 仍不误判」两侧断言。
|
|
53
|
+
- 全仓 22 个测试文件逐文件运行全绿,`npm test` 全绿。
|
|
54
|
+
|
|
55
|
+
## v1.9.6(2026-10-17)
|
|
56
|
+
|
|
57
|
+
**新增:余额查询兼容 DSH「DeepSeek 账号登录」——账号态改走宿主 `deepseekAccount.getBalance()`,读取 Platform 钱包(充值 / 赠金);API Key 路径原样保留**
|
|
58
|
+
|
|
59
|
+
### 一、问题:账号登录用户查不到余额
|
|
60
|
+
|
|
61
|
+
DSH 的浏览器 PKCE 账号登录(`@deepseek-ai/dsh-deepseek-account` + `dsh-deepseek-account-platform`,0.1.7-alpha.1 起引入)把授权写进 credentials 的 **record** `deepseek-account-platform/default`(`{version, token, issuer}`),**从不写 ref**。而 `credentials.resolve()` 只查 refs 半区 —— 所以:
|
|
62
|
+
|
|
63
|
+
- 账号 token 没有 ref 名,`resolve('DEEPSEEK_API_KEY')` 取不到它;
|
|
64
|
+
- 账号态推理用 `x-dsh-auth-token` 走 Platform 网关,运行时 `dsh-llm-deepseek-account` 与 `dsh-llm-deepseek` 的 README 都写明「**不会回退到 API key**」,两条路由互斥;
|
|
65
|
+
- 全 asar 扫描中 `api.deepseek.com/user/balance`、`total_balance`、`granted_balance`、`topped_up_balance` 命中数均为 0 —— 说明「登录后拿 key 去查 api.deepseek.com」这条路在 0.2.x 里根本不存在。
|
|
66
|
+
|
|
67
|
+
结论:只认 `DEEPSEEK_API_KEY` 的旧实现,在纯账号态下必然报「未找到 DeepSeek API Key」,不是配置问题。
|
|
68
|
+
|
|
69
|
+
### 二、改法:新增账号余额来源,优先级三级
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
面板手填 API Key > 账号登录态(宿主服务) > 配置/环境里的 API Key
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- **账号登录态**:`ctx.get('deepseekAccount').getBalance(client)`,数据源为 Platform 的 `GET /api/v0/users/get_user_summary`,返回 `null`(未登录/凭据失效换代)| `{status:'failed'}`(网络/超时/协议)| `{status:'ready', value:[充值钱包], bonusWallets:[赠金钱包]}`。
|
|
76
|
+
- **client 元数据三字段必填**:`version` / `locale` / `timezoneOffsetSeconds` 会被运行时直接拼进 `x-client-*` 请求头,缺一个就抛 `TypeError`(实测:无参 → `reading 'version'`,`{}` → `reading 'toLowerCase'`)。宿主侧一律补齐,浏览器半端再把 `navigator.language` 与本机时区传上来覆盖。
|
|
77
|
+
- **手填 Key 仍最高优先**:那是用户显式动作,意图最强。
|
|
78
|
+
- **账号态失败不回退 API Key**:账号已登录时回退会显示**另一个账户**的数字,比报错更误导;失败信息里直接给出出路(手动填 Key)。
|
|
79
|
+
- **旧宿主零影响**:没有 `deepseekAccount` 服务的 DSH 自动走原路径,文案与 v1.9.5 逐字一致,不做版本号判断。
|
|
80
|
+
|
|
81
|
+
### 三、口径与字段
|
|
82
|
+
|
|
83
|
+
- 账号态「总余额」= 同币种充值钱包合计 + 同币种赠金合计,用 **BigInt 精确十进制加法**(不经 `Number`,`0.1+0.2` 不出现 `0.30000000000000004`;Platform 返回的 `0E-16` 这类零值统一显示为 `0`)。
|
|
84
|
+
- 账号态 `available` 返回 **null**(Platform 摘要没有 `is_available`,不把「未知」渲染成「不可用」);API Key 态仍为布尔。
|
|
85
|
+
- 多币种:卡片按 `CNY > USD > 其它` 选主币种,符号与标题跟随币种(USD 不再一律显示 `¥`),完整钱包列表放在 `wallets` / `currencies` 里。
|
|
86
|
+
- **展示精度**:Platform 钱包金额实测是 **16 位小数**(形如 `1234.5600000000000000`)。界面按 DSH 官方「账号与余额」页口径**截断到分**(不四舍五入)、正的不足一分显示 `<0.01`、零显示 `0.00`、负数保留符号;同时兼容 `0E-16` 这类指数写法(指数 > 30 时不硬展开)。**接口返回值保持原始精度不截断**,展示与数据分离。
|
|
87
|
+
- 响应新增 `source: 'account' | 'apikey' | 'none'`;`total` / `granted` / `toppedUp` / `currency` / `keySource` 等旧字段全部保留(`keySource` 账号态为 `account`)。
|
|
88
|
+
|
|
89
|
+
### 四、顺带修复(同一轮 0.2.x 兼容审计发现)
|
|
90
|
+
|
|
91
|
+
- **历史导入对 v4 会话静默失效**:0.2.x 起宿主把新会话写成 `session.v4.jsonl.zstd`,而 `import.js` 只枚举 `session.v3.jsonl.zstd` / `session.v3.jsonl` / `session.jsonl.zstd` / `session.jsonl` 四个硬编码名字 —— v4 及以后的新会话被**静默跳过**(导入清单里 0 个 v4、无任何报错,只表现为「历史导入不再补录新会话」)。本机实测:`.dsh\sessions` 下 68 个 v4 + 20 个 v3 + 10 个 legacy,修复前 `listSessionLogs()` 只返回 29 个。**内容层本来是兼容的**(抽样实测 v4 日志能正常回放出调用(Lead 样本 1160 事件 → 132 调用;verifier 另证与同目录 v3 的调用集合一致),`usage` / `message.source` 形状未变),断点只在文件名。现改为按 `session[.vN].jsonl[.zstd]` 正则识别,**版本号高者优先、同版本 zstd 优先**,宿主将来升 v5/v6 不需要再改枚举;新增 `test/session-log-v4.test.js`(含 v5 前瞻与真实目录交叉核对)。
|
|
92
|
+
- **账号态 provider 的兜底价**:账号登录的推理 provider 名是 `deepseek-account`,原先不在 `PROVIDER_RATES` 里。现役模型能命中 provider 无关的精确价表(实测 100% 命中、`estimated:false`),但**表外的新模型**会落到 `GENERIC_RATES`(缓存价 0.5 而非 0.04、且无峰谷半价)→ 费用被静默高估。现把 `deepseek-account` 登记为与 `deepseek` 共用同一份兜底价(`pricing.js`)。
|
|
93
|
+
- **`settings` 读取迁移到 0.2.x 的 `describe()`(原为静默降级)**:0.2.x 的 `SettingsForms` 已无 `get()`(只剩 `configure/describe/update/replace/mutate/write/prepareDocument`),插件原来的 `deepseekKeyEnv()` / `kimiKeyEnv()` / 火山 AK 候选链会抛 TypeError 并被各自 try/catch 吞掉 → **恒走硬编码默认名**。默认名与官方一致,标准部署看不出问题;但**自定义 `apiKeyEnv`** 的部署会去查一个不存在的 Key 名(表现为「明明配了 Key 却报未找到」)。0.2.x 的正确读法是 `settings.describe()` —— 它返回全部条目的表单描述,`row.value` 即该条目 volatile 字段的**生效值**(`apiKeyEnv` 正是 `.volatile()` 字段)。新增 `settings.js` 做「describe() 优先、get() 兜底」的双 API 兼容读,并按 settings 实例做 10s 短缓存(describe 是全量投影,余额/Kimi/火山三个入口一次刷新会各调一次)。旧宿主行为完全不变;新增 `test/settings-compat.test.js`(两套 API、优先级、缓存、边界,以及「0.2.x 自定义 ref 真的被用来查 Key」的端到端断言)。
|
|
94
|
+
- **修掉既有测试腐化**:`test/import.test.js` 的「看板读到导入记录的总花费」用 `dashboard {days:30}`(相对当前时间)去断言固定日期 fixture(2026-09-15 起),2026-10-15 之后必然假失败 —— 它断言的是**口径**(导入记录要进看板)而非时间窗口,改为足够宽的窗口覆盖 fixture。这是 `npm test` 在 CI 上变红、进而挡住发布的根因。
|
|
95
|
+
|
|
96
|
+
### 五、新增测试
|
|
97
|
+
|
|
98
|
+
`test/balance-account.test.js`:用真实文件 + 真实 HTTP 处理器跑,不打模块内桩:账号 ready 投影、未登录回退 Key、手填 Key 优先(且不调用账号服务)、账号失败不静默回退、`getBalance` 返回 `undefined` 按契约外失败处理(**不**当作未登录回退,否则会显示另一个账户的余额)、旧宿主文案不变、`client` 三字段必填、精确十进制加法、客户端来源判定与币种显示、展示格式化(从 bundle 源码取函数在 VM 里求值)、账号态 provider 兜底价、settings 双 API 端到端。
|
|
99
|
+
|
|
100
|
+
`test/session-log-v4.test.js`:`session[.vN].jsonl[.zstd]` 全版本枚举(v3/v4/v5/无版本/plain/zstd/空目录/非会话文件),并对照本机真实 `.dsh\sessions` 校验「磁盘上的 v4 全部被枚举到」。
|
|
101
|
+
|
|
102
|
+
`test/settings-compat.test.js`:`readSettingsSection()` 的双 API 兼容读(旧宿主 `get()` / 0.2.x `describe()` / 两者都在时 describe 优先 / 都不可用 / 抛错 / 非数组 / 非对象 / ns 非法)、10s 缓存与显式失效、不同 settings 实例互不串味。
|
|
103
|
+
|
|
104
|
+
> 测试口径:全仓 **22 个测试文件逐文件运行全绿**,`npm test`(CI 用的 `&&` 链)同样全绿 —— 发布工作流的 "Run tests" 关卡因此恢复可用。
|
|
105
|
+
|
|
106
|
+
> 说明:账号登录**不会**下发 API Key,因此「用账号登录直接请求 api.deepseek.com/user/balance」不可行;能查的是 **Platform 钱包**(与 DSH 官方「设置 → 账号与余额」同源),两者是同一 DeepSeek 账号的不同接口口径。
|
|
107
|
+
|
|
5
108
|
## v1.9.5(2026-10-07)
|
|
6
109
|
|
|
7
110
|
**修复「桌面端(Electron 外壳)花费统计整块看板变成无样式原生控件」—— 自建 `<style>` 缺 `data-plugin` 归属标记,被 DSH 客户端模块系统认领给别的模块后在 HMR 清理时连带删除**
|
package/README.en.md
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
| 📊 | **Visual dashboard** | A new "Cost Statistics" page in Settings: overview cards, cost bar charts (by peak period / by model), per-model request & token charts — **all with hover tooltips** |
|
|
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
|
-
| 💳 | **Balance lookup** | One-click DeepSeek account balance (total / topped-up / granted / status) |
|
|
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
41
|
| 🤖 | **Agent tools** | Ask in any chat: "how much have I spent today?" — the agent answers via `cost_stats` / `cost_prices` |
|
|
42
42
|
| 🔻 | **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
43
|
| 🔥 | **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 |
|
|
@@ -278,7 +278,7 @@ Only the three interface switches apply instantly; every other group is "edit dr
|
|
|
278
278
|
|
|
279
279
|
### History import (v1.9.0)
|
|
280
280
|
|
|
281
|
-
Conversations from **before you installed the plugin** can be backfilled: the plugin replays the host session logs (`$DSH_HOME/sessions/<project>/<session>/session.
|
|
281
|
+
Conversations from **before you installed the plugin** can be backfilled: the plugin replays the host session logs (`$DSH_HOME/sessions/<project>/<session>/session[.vN].jsonl[.zstd]`, decompressed frame by frame — the host appends one zstd frame per batch; since v1.9.6 the `vN` version is detected automatically, so v4/v5 need no code change) and books each model call at the price era of **its own timestamp**.
|
|
282
282
|
|
|
283
283
|
- **Auto-import on startup** by default (8 s delay, never blocks the boot), with an "Import now" button and an `autoImport` switch;
|
|
284
284
|
- **Only calls the plugin could not have recorded**: earlier than this machine's first live record, or on a day with no live coverage at all (downtime gaps);
|
|
@@ -300,6 +300,27 @@ Conversations from **before you installed the plugin** can be backfilled: the pl
|
|
|
300
300
|
- **No response ever echoes a secret**: status endpoints return only booleans plus the storage location (credential store / process memory). `AccessKeyID` is a non-sensitive identifier and is echoed so the form can be pre-filled;
|
|
301
301
|
- **Egress protection**: any request carrying credentials must match the host allowlist (DeepSeek / Kimi / Volcengine control plane / your configured cloud URL / the pricing page host), non-loopback hosts must use https, and `redirect: 'manual'` is forced — any 3xx is treated as a failure so a redirect can never carry the `Authorization` header elsewhere.
|
|
302
302
|
|
|
303
|
+
### Balance sources & account login (v1.9.6)
|
|
304
|
+
|
|
305
|
+
The lookup picks a source in this priority order — **account login neither needs nor accepts an API key**:
|
|
306
|
+
|
|
307
|
+
1. **API key typed into the panel** (highest priority, explicit user action) → `https://api.deepseek.com/user/balance`;
|
|
308
|
+
2. **DSH account login** → the host service `deepseekAccount.getBalance()`, which reads the Platform
|
|
309
|
+
wallets (`normal_wallets` = topped-up, `bonus_wallets` = granted; CNY / USD) — the same data source
|
|
310
|
+
as the official Settings → Account page;
|
|
311
|
+
3. **API key from settings / environment** (`DEEPSEEK_API_KEY`) → same as 1.
|
|
312
|
+
|
|
313
|
+
Why two sources: DSH's account login stores its PKCE grant as a credentials **record**
|
|
314
|
+
(`deepseek-account-platform/default`) and **never issues an API key**; account inference uses
|
|
315
|
+
`x-dsh-auth-token` against the Platform gateway while API-key inference uses `x-api-key`, and the
|
|
316
|
+
runtime documents that the two routes **never fall back to each other**. "Log in, then query
|
|
317
|
+
api.deepseek.com with the token" is simply not a thing on 0.2.x.
|
|
318
|
+
|
|
319
|
+
Semantics: the account path reports **Platform wallets** (top-up and bonus listed separately,
|
|
320
|
+
total = the same-currency sum, added with exact decimal arithmetic); the API-key path keeps
|
|
321
|
+
`total_balance` / `granted_balance` / `topped_up_balance` and `is_available`. Hosts without a
|
|
322
|
+
`deepseekAccount` service fall back to the old path with v1.9.5 behaviour.
|
|
323
|
+
|
|
303
324
|
### HTTP API (for other tools)
|
|
304
325
|
|
|
305
326
|
All endpoints are `POST` + JSON and listen on the loopback address:
|
|
@@ -319,7 +340,7 @@ POST /api/cost-tracker/cloud Read-only cloud aggregation (route/days/excl
|
|
|
319
340
|
POST /api/cost-tracker/kimi-usage Kimi subscription quota
|
|
320
341
|
POST /api/cost-tracker/volcengine-usage Volcengine Ark Coding Plan quota (5-hour / weekly / monthly windows)
|
|
321
342
|
POST /api/cost-tracker/volcengine-config Save Volcengine AK/SK (reports only whether keys are configured, never the keys)
|
|
322
|
-
POST /api/cost-tracker/balance Account balance
|
|
343
|
+
POST /api/cost-tracker/balance Account balance (account login first; pass {"apiKey":"sk-..."} to override)
|
|
323
344
|
POST /api/cost-tracker/prices Price table (by pricing era + synced eras + multi-vendor catalog + overrides)
|
|
324
345
|
POST /api/cost-tracker/recompute Re-price stored records by era (dry-run unless {"apply":true})
|
|
325
346
|
POST /api/cost-tracker/billing-config Billing basis & catalog config (amount basis / plan overrides / match & fx / price overrides)
|
|
@@ -340,6 +361,40 @@ Example: `curl -X POST http://127.0.0.1:3080/api/cost-tracker/summary -d '{}'`
|
|
|
340
361
|
|
|
341
362
|
> Highlights only — the full version-by-version history lives in [`CHANGELOG.md`](./CHANGELOG.md) (Chinese).
|
|
342
363
|
|
|
364
|
+
### v1.9.6 (2026-10-17)
|
|
365
|
+
|
|
366
|
+
**Balance lookup now works with DSH "DeepSeek account login": under an account the plugin calls the host service `deepseekAccount.getBalance()` and reads the Platform wallets (top-up / bonus); the API-key path is unchanged**
|
|
367
|
+
|
|
368
|
+
- **Why it used to fail**: since 0.1.7 DSH supports browser PKCE account login, whose grant is stored
|
|
369
|
+
as a credentials **record** (`deepseek-account-platform/default` — `{version, token, issuer}`) and
|
|
370
|
+
**never as a ref**, while `credentials.resolve()` only reads the refs half. Account inference also
|
|
371
|
+
uses `x-dsh-auth-token` versus `x-api-key` for API keys, the runtime documents that the two routes
|
|
372
|
+
**never fall back to each other**, and `api.deepseek.com/user/balance` appears nowhere in the
|
|
373
|
+
runtime. An implementation that only knew `DEEPSEEK_API_KEY` therefore always reported
|
|
374
|
+
"DeepSeek API key not found" under a pure account login;
|
|
375
|
+
- **New priority**: API key typed in the panel > account login > configured/environment API key.
|
|
376
|
+
A failed account read does **not** fall back to an API key (that would show a different account's
|
|
377
|
+
numbers); the error tells the user to type a key instead;
|
|
378
|
+
- **Required contract**: the `client` argument's three fields (`version` / `locale` /
|
|
379
|
+
`timezoneOffsetSeconds`) are spliced into `x-client-*` headers by the runtime and a missing field
|
|
380
|
+
throws `TypeError`; the host always fills them in and the browser half overrides locale/time zone;
|
|
381
|
+
- **Semantics**: account "total" = same-currency top-up + bonus, added with exact decimal arithmetic;
|
|
382
|
+
`available` is `null` under an account (the Platform summary has no `is_available`, so "unknown" is
|
|
383
|
+
never rendered as "unavailable"); multi-currency picks CNY > USD and the symbol/title follow it;
|
|
384
|
+
- **No regression**: hosts without a `deepseekAccount` service take the old path with v1.9.5 wording;
|
|
385
|
+
- **Also fixed (same compatibility audit)**: (1) history import now recognises `session[.vN].jsonl[.zstd]`
|
|
386
|
+
— 0.2.x writes `session.v4.jsonl.zstd`, while the old code only enumerated v3/legacy names, so new
|
|
387
|
+
sessions were silently skipped (68 v4 sessions on this machine were missed; the content itself is
|
|
388
|
+
compatible); (2) the account provider `deepseek-account` now has a DeepSeek fallback price, so models
|
|
389
|
+
outside the exact table no longer fall to generic cache pricing (0.5 → 0.04) and keep peak/off-peak;
|
|
390
|
+
(3) settings reads migrated to 0.2.x's `settings.describe()` (`get()` was removed): the new
|
|
391
|
+
`settings.js` does "describe first, get as fallback", so **deployments with a custom `apiKeyEnv` no
|
|
392
|
+
longer resolve the wrong key name**;
|
|
393
|
+
- **Tests**: new `test/balance-account.test.js`, `test/session-log-v4.test.js` and
|
|
394
|
+
`test/settings-compat.test.js`; all **22 test files pass**, and `npm test` (the `&&` chain CI runs) is
|
|
395
|
+
green as well — this also fixes the pre-existing fake failure in `test/import.test.js` (fixed-date
|
|
396
|
+
fixture vs a relative `days` window), which was the reason CI's test gate went red.
|
|
397
|
+
|
|
343
398
|
### v1.9.5 (2026-10-07)
|
|
344
399
|
|
|
345
400
|
**Fix "the whole Cost dashboard renders as unstyled native controls in the Desktop (Electron) app": the plugin's own `<style>` lacked a `data-plugin` ownership tag, so another module claimed it and HMR cleanup deleted it along with its own styles**
|
package/README.md
CHANGED
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
| 🧭 | **多机汇总(云端同步)** | 可对接**自建云端服务**(独立仓库 `dsh-cost-cloud`,零运行时依赖):多台电脑的用量汇总到一处,看板顶部出现 **本机 / 本机+云端 / 仅云端** 三态开关,并支持**设备 × Agent 矩阵**(行合计 = 列合计 = 总计);上报内容仅 token 数、费用、时间戳与标识符,可选会话脱敏 |
|
|
39
39
|
| 🔥 | **用量热力图** | 设置页新增「Token 用量统计」:类 Codex 的 **26 周日用量方格热图**,按天着色(输入 / 缓存 / 输出 / 费用),悬停看当日明细、今天高亮描边,顶部显示全时段累计;**跟随三态视图**——「本机+云端 / 仅云端」下自动并入云端按天用量(卡片标题右侧标注当前口径) |
|
|
40
40
|
| 📈 | **订阅配额监控** | Kimi Coding Plan、**火山方舟 Coding Plan** 等订阅套餐:配额进度条、重置倒计时、等效按量费用参考。火山方舟走管控面 OpenAPI(HMAC 签名),需 AccessKeyID + SecretAccessKey |
|
|
41
|
-
| 💳 | **余额查询** | 一键查询 DeepSeek 官方账户余额(总余额 / 充值 / 赠送 / 状态) |
|
|
41
|
+
| 💳 | **余额查询** | 一键查询 DeepSeek 官方账户余额(总余额 / 充值 / 赠送 / 状态);**已登录 DSH 账号时直接读 Platform 钱包(充值 / 赠金),不再需要 API Key(v1.9.6)** |
|
|
42
42
|
| 🤖 | **Agent 工具** | 直接在对话里问:"我现在花了多少钱?"——Agent 会调用 `cost_stats` / `cost_prices` 等工具回答 |
|
|
43
43
|
| 🔻 | **状态栏** | 聊天输入框下方实时显示:**本会话花费**(胶囊分段:本会话 / 订阅套餐 / 分模型),按会话实际用到的模型与订阅拆分,**多模型默认折叠只显示 top2,点击展开全部明细**;订阅显示具体套餐名,不再展示配额与调用次数 |
|
|
44
44
|
| 👁️ | **界面显示开关** | 输入框上方的花费胶囊、侧边栏峰谷时段条、设置页「花费统计」看板**三个落点各自可关**(设置 → 花费统计 → 右上角齿轮 → 数据与界面 → 界面显示),勾选即刻生效;**只影响显示**,记账、云端同步与 Agent 工具照常,配置入口(齿轮页)本身不受开关控制 |
|
|
45
45
|
| 💾 | **本地持久化** | 数据存本机 `~/.dsh/storages/cost-tracker-records.json`,重启不丢、不上传;**明细保留最近 180 天,更早自动压缩为永久日汇总,全时段统计永远精确且内存/磁盘有界** |
|
|
46
46
|
| 🕰️ | **历史导入(v1.9.0)** | 回放宿主会话日志,**把装插件之前的对话调用补录进账本**(按各自时间戳的旧价计费);只补插件不可能记到的部分(安装前 / 停机缺口),幂等可重复执行,导入记录标记 `source=import` 以便区分 |
|
|
47
47
|
| 🔄 | **官方价格同步(v1.9.0)** | 一键抓取官方定价页、解析各模型峰价并对比差异,应用后构建**新的计费时代**(只影响之后,历史口径不回改);每日可自动核对(只提示、不自动应用),页面改版时宁可不同步也绝不写错价 |
|
|
48
|
-
| 🌐 | **多厂商价格目录(v1.9.0)** | 内置
|
|
48
|
+
| 🌐 | **多厂商价格目录(v1.9.0)** | 内置 15 家厂商 / 141 个模型条目(USD→CNY 按可配汇率折算),OpenAI / Anthropic / Gemini / Qwen 等内置表之外的模型也能按**精确价**入账;支持宽松/严格匹配与**手动覆盖价** |
|
|
49
49
|
| ⚖️ | **Plan 与按量双轨(v1.9.0)** | 工具栏「含 Plan 总额」开关一键切换口径:关闭只算按量真金白银、订阅以附注展示;打开则金额 = 按量 + 订阅等值,图表按天并入「订阅等值」段 |
|
|
50
50
|
| 🔐 | **凭据零落盘(v1.9.0)** | 云端令牌与火山 SecretAccessKey 只写 DSH 凭据库(配置文件零明文,旧版明文启动时自动迁移);任何响应只回显布尔;出站请求白名单 + 强制 https + 拒绝跟随重定向(防凭据外带) |
|
|
51
51
|
| 📤 | **CSV 导出** | 一键导出明细 + 日汇总(purpose=rollup),方便用 Excel / Numbers 做进一步分析 |
|
|
@@ -279,7 +279,7 @@ docker compose up -d # 打开 http://<服务器>:8787 ,在「设置」页
|
|
|
279
279
|
|
|
280
280
|
### 历史导入(v1.9.0)
|
|
281
281
|
|
|
282
|
-
装上插件之前的对话也能补进账本:插件回放宿主会话日志(`$DSH_HOME/sessions/<项目>/<会话>/session.
|
|
282
|
+
装上插件之前的对话也能补进账本:插件回放宿主会话日志(`$DSH_HOME/sessions/<项目>/<会话>/session[.vN].jsonl[.zstd]`,多 zstd frame 逐帧解压、逐帧切片;v1.9.6 起按 `vN` 自动识别版本,v4/v5 无需改代码),把其中的模型调用按**当时时间戳**的计费口径入账。
|
|
283
283
|
|
|
284
284
|
- 默认**开机自动导入**(延迟 8 秒,不阻塞启动),也可在配置页点「立即导入」或关掉自动(`autoImport`);
|
|
285
285
|
- **只补「插件不可能记到」的调用**:早于本机最早一条实时记录,或所在日完全没有实时覆盖(停机缺口);
|
|
@@ -290,7 +290,7 @@ docker compose up -d # 打开 http://<服务器>:8787 ,在「设置」页
|
|
|
290
290
|
### 官方价格同步与多厂商目录(v1.9.0)
|
|
291
291
|
|
|
292
292
|
- **官方价格同步**:配置页里点「核对官方价」抓取官方定价页(中文页直接给出人民币价),解析出各模型峰价并与当前生效价对比;点「应用新价」把结果构建为**新的计费时代** —— 只对生效时刻**之后**的记录生效,历史记录按各自时间戳选版,口径不回改。每日可自动核对(默认开,只提示差异,**绝不自动应用**)。解析器对页面改版 / 数字缺失 / 「空闲价 ≠ 高峰一半」一律抛错,宁可不同步也绝不写错价;
|
|
293
|
-
- **多厂商模型价格目录**:内置
|
|
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,可改)折算。内置表之外的模型命中目录即记**精确价**(不再标「估算」);匹配模式可选宽松(归一化包含)或严格(名称全等);
|
|
294
294
|
- **手动覆盖价**:`provider/model` → 输入 / 输出 / 缓存价,优先级最高,用于自建端点或议价套餐;
|
|
295
295
|
- **计费优先级**:手动覆盖价 > 订阅归类(Plan)> 内置 / 同步时代精确价 > 多厂商目录 > provider 兜底 > 通用兜底。`cost_prices` 工具与 `/api/cost-tracker/prices` 会一并回显当前时代、同步时代、目录指纹与覆盖价;
|
|
296
296
|
- 云端(`dsh-cost-cloud ≥ v1.4.0`)有同源实现与对应的管理端点,两边口径可对照(`/api/v1/protocol` 回显云端实际使用的价格版本与目录指纹)。
|
|
@@ -301,6 +301,26 @@ docker compose up -d # 打开 http://<服务器>:8787 ,在「设置」页
|
|
|
301
301
|
- **任何响应都不回显密钥**:状态接口只给布尔与「存储位置」(凭据库 / 进程内存),`AccessKeyID` 属非敏感标识才会回显以便预填;
|
|
302
302
|
- **出站防护**:携带凭据的请求必须命中主机白名单(DeepSeek / Kimi / 火山管控面 / 配置的云端地址 / 定价页主机),非本机地址强制 https,`redirect: 'manual'` —— 3xx 一律按失败处理,防止重定向把 `Authorization` 头带去别处。
|
|
303
303
|
|
|
304
|
+
### 余额来源与账号登录(v1.9.6)
|
|
305
|
+
|
|
306
|
+
余额查询按以下优先级选来源,**账号登录不需要也不接受 API Key**:
|
|
307
|
+
|
|
308
|
+
1. **面板手填 API Key**(最高优先,用户显式动作)→ 请求 `https://api.deepseek.com/user/balance`;
|
|
309
|
+
2. **DSH 账号登录态** → 调宿主服务 `deepseekAccount.getBalance()`,读 Platform 钱包
|
|
310
|
+
(`normal_wallets` = 充值钱包、`bonus_wallets` = 赠金钱包,币种 CNY / USD),
|
|
311
|
+
与官方「设置 → 账号与余额」同源;
|
|
312
|
+
3. **配置 / 环境里的 API Key**(`DEEPSEEK_API_KEY`)→ 同 1。
|
|
313
|
+
|
|
314
|
+
为什么必须分两条:DSH 的账号登录用 PKCE 授权把 token 写进凭据库的 **record**
|
|
315
|
+
(`deepseek-account-platform/default`),**不会下发 API Key**;账号态推理用
|
|
316
|
+
`x-dsh-auth-token` 走 Platform 网关、API Key 态用 `x-api-key`,运行时文档明确两条路由
|
|
317
|
+
**互不回退**。因此「登录后拿 key 去查 api.deepseek.com」这条路在 0.2.x 里不存在。
|
|
318
|
+
|
|
319
|
+
口径差异:账号态展示的是 **Platform 钱包**(充值 / 赠金分开列示,总额 = 同币种两者之和,
|
|
320
|
+
精确十进制相加);API Key 态沿用 `total_balance` / `granted_balance` /
|
|
321
|
+
`topped_up_balance` 与 `is_available`。没有 `deepseekAccount` 服务的旧宿主自动走原路径,
|
|
322
|
+
行为与 v1.9.5 一致。
|
|
323
|
+
|
|
304
324
|
### HTTP API(供其他工具调用)
|
|
305
325
|
|
|
306
326
|
全部为 `POST` + JSON,监听本机地址:
|
|
@@ -320,7 +340,7 @@ POST /api/cost-tracker/cloud 云端只读聚合(route/days/excludeSelf/de
|
|
|
320
340
|
POST /api/cost-tracker/kimi-usage Kimi 订阅配额
|
|
321
341
|
POST /api/cost-tracker/volcengine-usage 火山方舟 Coding Plan 配额(5 小时/周/月窗口)
|
|
322
342
|
POST /api/cost-tracker/volcengine-config 保存火山方舟 AK/SK(只回显「是否已配置」,不回显密钥)
|
|
323
|
-
POST /api/cost-tracker/balance 账户余额
|
|
343
|
+
POST /api/cost-tracker/balance 账户余额(账号登录态优先;传 {"apiKey":"sk-…"} 可手填覆盖)
|
|
324
344
|
POST /api/cost-tracker/prices 单价表(按计费时代分版 + 同步时代 + 多厂商目录 + 覆盖价)
|
|
325
345
|
POST /api/cost-tracker/recompute 按计费时代重算已入库记录(默认只试算,传 {"apply":true} 落盘)
|
|
326
346
|
POST /api/cost-tracker/billing-config 双轨计费与目录配置(金额口径/订阅归类/匹配与汇率/覆盖价)
|
|
@@ -341,6 +361,36 @@ POST /api/cost-tracker/export 导出 CSV
|
|
|
341
361
|
|
|
342
362
|
> 这里只列重要版本;逐版完整记录见 [`CHANGELOG.md`](./CHANGELOG.md)。
|
|
343
363
|
|
|
364
|
+
### v1.9.6(2026-10-17)
|
|
365
|
+
|
|
366
|
+
**新增:余额查询兼容 DSH「DeepSeek 账号登录」—— 账号态改走宿主 `deepseekAccount.getBalance()` 读 Platform 钱包(充值 / 赠金),API Key 路径原样保留**
|
|
367
|
+
|
|
368
|
+
- **为什么之前查不到**:0.1.7 起 DSH 支持浏览器 PKCE 账号登录,授权只写进凭据库的 **record**
|
|
369
|
+
`deepseek-account-platform/default`(`{version, token, issuer}`),**从不写 ref**,而
|
|
370
|
+
`credentials.resolve()` 只查 refs 半区 —— 账号 token 没有 ref 名;同时账号态推理用
|
|
371
|
+
`x-dsh-auth-token`、API Key 态用 `x-api-key`,运行时文档明确两者「互不回退」,且整个运行时里
|
|
372
|
+
`api.deepseek.com/user/balance` 零命中。于是只认 `DEEPSEEK_API_KEY` 的旧实现,在纯账号态下
|
|
373
|
+
必然报「未找到 DeepSeek API Key」;
|
|
374
|
+
- **新优先级**:面板手填 Key > 账号登录态 > 配置/环境 API Key。账号态**失败不回退** API Key
|
|
375
|
+
(回退会显示另一个账户的数字),错误信息直接给出「手动填 Key」的出路;
|
|
376
|
+
- **必填契约**:`getBalance(client)` 的 `client` 三字段(`version` / `locale` /
|
|
377
|
+
`timezoneOffsetSeconds`)会被运行时直接拼进 `x-client-*` 头,缺一个就抛 `TypeError`;
|
|
378
|
+
宿主侧一律补齐,浏览器半端再用 `navigator.language` 与本机时区覆盖;
|
|
379
|
+
- **口径**:账号钱包「总余额 = 同币种充值 + 同币种赠金」,用 BigInt 精确十进制相加;
|
|
380
|
+
账号态 `available` 为 `null`(Platform 摘要没有 `is_available`,不把未知渲染成不可用);
|
|
381
|
+
多币种按 CNY > USD 选主币种,符号与标题跟随币种;
|
|
382
|
+
- **零影响**:没有 `deepseekAccount` 服务的旧宿主自动走原路径,文案与 v1.9.5 逐字一致;
|
|
383
|
+
- **顺带修复(同一轮 0.2.x 兼容审计)**:① 历史导入现在识别 `session[.vN].jsonl[.zstd]` ——
|
|
384
|
+
0.2.x 起新会话写成 `session.v4.jsonl.zstd`,旧实现只认 v3/legacy 名字,导致新会话被**静默跳过**
|
|
385
|
+
(本机 68 个 v4 会话全部漏掉;内容层其实兼容);② 账号态 provider `deepseek-account` 补上
|
|
386
|
+
DeepSeek 兜底价,精确价表之外的新模型不再落到 generic 缓存价(0.5 → 0.04)且保留峰谷半价;
|
|
387
|
+
③ 设置读取迁移到 0.2.x 的 `settings.describe()`(`get()` 已被移除):新增 `settings.js` 做
|
|
388
|
+
「describe 优先、get 兜底」的兼容读,**自定义 `apiKeyEnv` 的部署不再取错 Key 名**;
|
|
389
|
+
- **测试**:新增 `test/balance-account.test.js`、`test/session-log-v4.test.js`、
|
|
390
|
+
`test/settings-compat.test.js`;全仓 **22 个测试文件逐文件运行全绿**,`npm test`(CI 用的 `&&` 链)
|
|
391
|
+
同样全绿(同时修掉了 `test/import.test.js` 里因固定日期 fixture 造成的既有假失败 —— 它正是
|
|
392
|
+
`npm test` 变红、挡住发布的根因)。
|
|
393
|
+
|
|
344
394
|
### v1.9.5(2026-10-07)
|
|
345
395
|
|
|
346
396
|
**修复「桌面端(Electron 外壳)花费统计整块看板变成无样式原生控件」:自建 `<style>` 缺 `data-plugin` 归属标记,被别的模块认领后在 HMR 清理时连带删除**
|
|
@@ -435,7 +485,7 @@ POST /api/cost-tracker/export 导出 CSV
|
|
|
435
485
|
- **历史导入**:回放宿主会话日志(多 zstd frame 逐帧解压),补录「装插件之前」的调用。幂等三保险(清单快跳 + 逐调用键去重 + 覆盖判定),跨安装点会话按切割线截断,导入记录标记 `source=import`。默认开机自动执行(延迟 8 秒,不阻塞启动),新 Agent 工具 `cost_import`;
|
|
436
486
|
- **凭据外带防护**:令牌与火山 SK 只写 DSH 凭据库(配置文件零明文),启动时自动迁移旧版明文;所有出站请求走白名单 + 强制 https + `redirect:'manual'`(拒绝跟随 3xx,防重定向把 `Authorization` 带走);任何响应只回显布尔与存储位置;
|
|
437
487
|
- **价格同步**:解析官方定价页(转置价格表:列 = 模型、行 = 指标 × 时段)→ 构建新计费时代,只影响生效时刻之后的记录,历史口径不回改;页面改版 / 数字不齐 / 空闲价非半价一律抛错。每日自动核对只提示差异,应用需手动确认;
|
|
438
|
-
- **多厂商模型价格目录**:
|
|
488
|
+
- **多厂商模型价格目录**:15 家厂商 / 141 个模型条目(USD/1M tokens → 按汇率折 CNY),内置表之外的模型命中即记精确价;匹配模式宽松 / 严格可选;另有手动覆盖价表;
|
|
439
489
|
- **Plan 与按量双轨 + 「含 Plan 总额」开关**:金额卡与图表口径一键切换(关闭只算按量、订阅以附注展示;打开则按量 + 订阅等值并入,图表出现「订阅等值」段),选择存浏览器并回写服务端;
|
|
440
490
|
- **设置集中 + 卡片重设计**:`设置 → 插件 → 插件配置 → 花费统计` 成为唯一设置入口,按「多机汇总 / 峰谷计价与提示 / 订阅套餐与配额 / 计价与价格目录 / 历史导入 / 数据与界面 / 安全与凭据」七个折叠分组排列,顶部状态摘要条;看板上的峰谷面板改为只读回显;
|
|
441
491
|
- **测试**:新增 `test/import.test.js`(合成多帧 zstd 会话日志,37 条断言)、`test/price-sync.test.js`(含真实页面回归)、`test/vendor-catalog.test.js`、`test/credstore.test.js`,`client-render` 增加金额口径开关与卡片分组断言 —— 共 17 个测试文件全绿。
|
package/account.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// DSH 0.2.1-rc.2+「DeepSeek 账号登录」余额适配 —— 纯投影层
|
|
3
|
+
//
|
|
4
|
+
// 为什么需要这一层(背景,来自 0.2.1-rc.2 运行时源码,见 README 的「账号登录」节):
|
|
5
|
+
// · 0.2.1-rc.2 起 DSH 支持浏览器 PKCE 账号登录。账号态推理用
|
|
6
|
+
// `x-dsh-auth-token` 走 Platform 网关(@deepseek-ai/dsh-llm-deepseek-account),
|
|
7
|
+
// README 原文:「不会回退到 API key」——**登录不会下发 API Key**。
|
|
8
|
+
// · 插件旧版余额只认 `DEEPSEEK_API_KEY` 去请求
|
|
9
|
+
// https://api.deepseek.com/user/balance,于是账号态下永远「未找到 DeepSeek API Key」。
|
|
10
|
+
// · 账号余额的正规取法:宿主服务 `deepseekAccount.getBalance(client)`,
|
|
11
|
+
// 内部请求 Platform Web 的 GET /api/v0/users/get_user_summary。
|
|
12
|
+
//
|
|
13
|
+
// 契约(逐字核对过 0.2.1-rc.2 的 lib/types/*.js):
|
|
14
|
+
// getBalance(client) → null
|
|
15
|
+
// | { status: 'failed' }
|
|
16
|
+
// | { status: 'ready', value: Wallet[], bonusWallets: Wallet[] }
|
|
17
|
+
// Wallet = { currency: 'CNY' | 'USD', balance: '<十进制字符串>' }
|
|
18
|
+
// · value = 充值钱包(normal_wallets)
|
|
19
|
+
// · bonusWallets = 赠金钱包(bonus_wallets)
|
|
20
|
+
// · null = 没有已存授权(未登录),或查询期间凭据被清除
|
|
21
|
+
// · 'failed' = 网络/超时/协议类失败(**不会**被伪造成 0 余额)
|
|
22
|
+
// client 参数**必填**:platformClientHeaders 直接读
|
|
23
|
+
// client.version / client.locale / client.timezoneOffsetSeconds,
|
|
24
|
+
// 少一个就抛 TypeError —— 所以本模块必须把三个字段补齐再调用。
|
|
25
|
+
//
|
|
26
|
+
// 本模块只做「纯投影」:不碰 ctx、不发网络请求,便于在无 DSH 运行时的环境下
|
|
27
|
+
// 直接单测(见 test/balance-account.test.js)。宿主侧调用见 index.js 的 balance()。
|
|
28
|
+
// ============================================================
|
|
29
|
+
|
|
30
|
+
/** 余额/钱包金额的十进制文法:与 0.2.1-rc.2 运行时 zod 校验器逐字一致。 */
|
|
31
|
+
const DECIMAL_RE = /^([+-]?)(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/
|
|
32
|
+
|
|
33
|
+
/** 币种偏好:与旧版 API Key 路径「优先取 CNY」保持一致。 */
|
|
34
|
+
const CURRENCY_PREFERENCE = ['CNY', 'USD']
|
|
35
|
+
|
|
36
|
+
/** 数字字面量的符号(视图层用)。 */
|
|
37
|
+
export function currencySymbol(currency) {
|
|
38
|
+
return String(currency || '').toUpperCase() === 'USD' ? '$' : '¥'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 解析十进制字符串为「BigInt 系数 + 小数位数」。
|
|
43
|
+
* @param {string} value - 形如 "12.34" / "-0.5" / "0E-16" / "1e+3"
|
|
44
|
+
* @returns {{coef:bigint, scale:number}|null} 不合法返回 null
|
|
45
|
+
*/
|
|
46
|
+
function decParse(value) {
|
|
47
|
+
const text = String(value === null || value === undefined ? '' : value).trim()
|
|
48
|
+
const m = DECIMAL_RE.exec(text)
|
|
49
|
+
if (!m) return null
|
|
50
|
+
const intPart = m[2] || ''
|
|
51
|
+
const fracPart = m[3] || ''
|
|
52
|
+
// "1." / ".5" / "0" 都合法;"." 单独一个不合法
|
|
53
|
+
if (!intPart && !fracPart) return null
|
|
54
|
+
const exp = m[4] ? parseInt(m[4], 10) : 0
|
|
55
|
+
if (!Number.isFinite(exp) || Math.abs(exp) > 200) return null
|
|
56
|
+
const sign = m[1] === '-' ? -1n : 1n
|
|
57
|
+
const digits = (intPart + fracPart).replace(/^0+(?=\d)/, '') || '0'
|
|
58
|
+
let coef = BigInt(digits) * sign
|
|
59
|
+
let scale = fracPart.length - exp
|
|
60
|
+
if (scale < 0) {
|
|
61
|
+
coef *= 10n ** BigInt(-scale)
|
|
62
|
+
scale = 0
|
|
63
|
+
}
|
|
64
|
+
return { coef, scale }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 把「系数 + 小数位数」格式化成十进制字符串(不丢精度、不做四舍五入)。 */
|
|
68
|
+
function decFormat(coef, scale) {
|
|
69
|
+
// 零统一输出 "0":Platform 会返回 0E-16 这类「零但带巨大尾数」的值,
|
|
70
|
+
// 若原样展开会变成 0.0000000000000000,界面上毫无意义。
|
|
71
|
+
if (coef === 0n) return '0'
|
|
72
|
+
const negative = coef < 0n
|
|
73
|
+
let abs = negative ? -coef : coef
|
|
74
|
+
let text = abs.toString()
|
|
75
|
+
if (scale > 0) {
|
|
76
|
+
while (text.length <= scale) text = '0' + text
|
|
77
|
+
text = text.slice(0, text.length - scale) + '.' + text.slice(text.length - scale)
|
|
78
|
+
}
|
|
79
|
+
return (negative ? '-' : '') + text
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 精确十进制加法(字符串进、字符串出,不经过 Number,避免 0.1+0.2 类误差)。
|
|
84
|
+
* 非法输入按 0 处理 —— 钱包原始字符串另存在结果里,不会丢证据。
|
|
85
|
+
* @param {string} a
|
|
86
|
+
* @param {string} b
|
|
87
|
+
* @returns {string}
|
|
88
|
+
*/
|
|
89
|
+
export function decAdd(a, b) {
|
|
90
|
+
const x = decParse(a)
|
|
91
|
+
const y = decParse(b)
|
|
92
|
+
const left = x || { coef: 0n, scale: 0 }
|
|
93
|
+
const right = y || { coef: 0n, scale: 0 }
|
|
94
|
+
const scale = Math.max(left.scale, right.scale)
|
|
95
|
+
const lc = left.coef * 10n ** BigInt(scale - left.scale)
|
|
96
|
+
const rc = right.coef * 10n ** BigInt(scale - right.scale)
|
|
97
|
+
return decFormat(lc + rc, scale)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 多个十进制字符串求和。 */
|
|
101
|
+
export function decSum(list) {
|
|
102
|
+
let total = '0'
|
|
103
|
+
for (const v of list || []) total = decAdd(total, v)
|
|
104
|
+
return total
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 构造 getBalance(client) 的 client 元数据。
|
|
109
|
+
*
|
|
110
|
+
* 三个字段都必填:缺 version 时用插件自身版本,缺 locale 时按宿主运行环境的
|
|
111
|
+
* 默认语言(Node 自带完整 ICU),缺时区偏移时用本机时区。浏览器半端会把
|
|
112
|
+
* navigator.language 与本机时区一起传上来(见 client.js 的 balanceClientMeta)。
|
|
113
|
+
*
|
|
114
|
+
* @param {object} [input] - 来自 HTTP 参数 { version, locale, timezoneOffsetSeconds }
|
|
115
|
+
* @param {string} [fallbackVersion] - 缺省版本号(插件版本)
|
|
116
|
+
* @returns {{version:string, locale:string, timezoneOffsetSeconds:number}}
|
|
117
|
+
*/
|
|
118
|
+
export function accountClientMeta(input, fallbackVersion) {
|
|
119
|
+
const src = input && typeof input === 'object' ? input : {}
|
|
120
|
+
let version = typeof src.version === 'string' && src.version.trim() ? src.version.trim() : ''
|
|
121
|
+
if (!version) version = typeof fallbackVersion === 'string' && fallbackVersion.trim() ? fallbackVersion.trim() : '0.0.0'
|
|
122
|
+
let locale = typeof src.locale === 'string' && src.locale.trim() ? src.locale.trim() : ''
|
|
123
|
+
if (!locale) {
|
|
124
|
+
try { locale = String(Intl.DateTimeFormat().resolvedOptions().locale || '') } catch (e) { locale = '' }
|
|
125
|
+
}
|
|
126
|
+
if (!locale) locale = 'zh-CN'
|
|
127
|
+
let tz = Number(src.timezoneOffsetSeconds)
|
|
128
|
+
if (!Number.isFinite(tz)) tz = -new Date().getTimezoneOffset() * 60
|
|
129
|
+
return { version, locale, timezoneOffsetSeconds: Math.round(tz) }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 钱包数组归一化:只留币种与金额都合法的项,保留原始金额字符串。 */
|
|
133
|
+
function normalizeWallets(list, kind) {
|
|
134
|
+
const out = []
|
|
135
|
+
if (!Array.isArray(list)) return out
|
|
136
|
+
for (const w of list) {
|
|
137
|
+
if (!w || typeof w !== 'object') continue
|
|
138
|
+
const currency = typeof w.currency === 'string' ? w.currency.toUpperCase() : ''
|
|
139
|
+
if (!currency) continue
|
|
140
|
+
const balance = w.balance === null || w.balance === undefined ? '' : String(w.balance)
|
|
141
|
+
if (!decParse(balance)) continue
|
|
142
|
+
out.push({ currency, balance, kind })
|
|
143
|
+
}
|
|
144
|
+
return out
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 取某币种的合计(无该币种钱包时返回 '0')。 */
|
|
148
|
+
function sumCurrency(wallets, currency) {
|
|
149
|
+
const amounts = []
|
|
150
|
+
for (const w of wallets) if (w.currency === currency) amounts.push(w.balance)
|
|
151
|
+
return amounts.length ? decSum(amounts) : '0'
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 把 `deepseekAccount.getBalance()` 的 ready 结果投影成本插件既有的 balance 形状。
|
|
156
|
+
*
|
|
157
|
+
* 兼容性:`total` / `granted` / `toppedUp` / `currency` / `keySource` 全部沿用旧字段,
|
|
158
|
+
* 新增 `source: 'account'`、`available: null`(账号态无法判断官方 is_available)与
|
|
159
|
+
* `wallets` / `currencies`(多币种时视图层可逐个展示)。
|
|
160
|
+
*
|
|
161
|
+
* 口径说明:Platform 的充值钱包与赠金钱包是**两个**钱包,
|
|
162
|
+
* 「总余额」= 同币种充值合计 + 同币种赠金合计(官方 Web 也是分开列示)。
|
|
163
|
+
*
|
|
164
|
+
* @param {object} details - getBalance 的返回值
|
|
165
|
+
* @returns {object|null} ready 时返回插件形状;非 ready(含 null)返回 null
|
|
166
|
+
*/
|
|
167
|
+
export function mapAccountBalance(details) {
|
|
168
|
+
if (!details || typeof details !== 'object' || details.status !== 'ready') return null
|
|
169
|
+
// 运行时契约里两个数组永远存在;缺失说明服务形状变了 —— 这时宁可失败,
|
|
170
|
+
// 也不能把「不知道」渲染成「0 余额」(0.2.1-rc.2 自己的实现同样坚持这一点)。
|
|
171
|
+
if (!Array.isArray(details.value) || !Array.isArray(details.bonusWallets)) return null
|
|
172
|
+
const recharge = normalizeWallets(details.value, 'recharge')
|
|
173
|
+
const bonus = normalizeWallets(details.bonusWallets, 'bonus')
|
|
174
|
+
// 有元素但全被校验挡掉 = 载荷损坏 → 失败,而不是静默归零
|
|
175
|
+
if ((details.value.length && !recharge.length) || (details.bonusWallets.length && !bonus.length)) return null
|
|
176
|
+
const currencies = []
|
|
177
|
+
for (const w of recharge) if (currencies.indexOf(w.currency) < 0) currencies.push(w.currency)
|
|
178
|
+
for (const w of bonus) if (currencies.indexOf(w.currency) < 0) currencies.push(w.currency)
|
|
179
|
+
let currency = ''
|
|
180
|
+
for (const c of CURRENCY_PREFERENCE) {
|
|
181
|
+
if (currencies.indexOf(c) >= 0) { currency = c; break }
|
|
182
|
+
}
|
|
183
|
+
if (!currency) currency = currencies[0] || 'CNY'
|
|
184
|
+
const toppedUp = sumCurrency(recharge, currency)
|
|
185
|
+
const granted = sumCurrency(bonus, currency)
|
|
186
|
+
return {
|
|
187
|
+
ok: true,
|
|
188
|
+
error: '',
|
|
189
|
+
// 账号态没有 is_available 这一说(余额不足是请求失败时由宿主提示);
|
|
190
|
+
// 用 null 而不是 false,避免把「未知」显示成「不可用」。
|
|
191
|
+
available: null,
|
|
192
|
+
source: 'account',
|
|
193
|
+
keySource: 'account',
|
|
194
|
+
currency,
|
|
195
|
+
total: decAdd(toppedUp, granted),
|
|
196
|
+
toppedUp,
|
|
197
|
+
granted,
|
|
198
|
+
currencies,
|
|
199
|
+
wallets: recharge.concat(bonus),
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 账号余额查询失败的统一形状(保持旧字段齐全,视图层无需特判空值)。
|
|
205
|
+
* @param {string} error - 面向用户的中文错误说明
|
|
206
|
+
* @returns {object}
|
|
207
|
+
*/
|
|
208
|
+
export function accountBalanceFailure(error) {
|
|
209
|
+
return {
|
|
210
|
+
ok: false,
|
|
211
|
+
error: String(error || '账号余额查询失败'),
|
|
212
|
+
available: null,
|
|
213
|
+
source: 'account',
|
|
214
|
+
keySource: 'account',
|
|
215
|
+
currency: 'CNY',
|
|
216
|
+
total: '',
|
|
217
|
+
toppedUp: '',
|
|
218
|
+
granted: '',
|
|
219
|
+
currencies: [],
|
|
220
|
+
wallets: [],
|
|
221
|
+
}
|
|
222
|
+
}
|