dsh-cost-meter 1.5.30 → 1.5.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00) · pre-switch popup & system-notification alerts for peak/off-peak changes (position / lead time / alert type configurable) · one-click price sync from the official docs · Codex-style token usage heat grid · multi-vendor model pricing (built-in 90+ model price catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet) · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
8
8
 
9
- [![version](https://img.shields.io/badge/version-1.5.30-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
9
+ [![version](https://img.shields.io/badge/version-1.5.31-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
10
10
  [![npm](https://img.shields.io/npm/v/dsh-cost-meter?label=npm)](https://www.npmjs.com/package/dsh-cost-meter)
11
11
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
12
12
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-dsh--plugin-4176E6)](https://github.com/deepseek-ai/deepseek-harness)
@@ -26,7 +26,7 @@ English | [中文](README.md)
26
26
  | Feature | Location | Description |
27
27
  |---|---|---|
28
28
  | Per-conversation cost | Below the composer / session title bar | Live accumulated cost + input/cache/output tokens; position configurable |
29
- | Official balance | Sidebar top / Settings page (configurable) | Total / granted / topped-up balance, auto-refresh + manual refresh; optional three-segment progress bar (blue/orange/gray) |
29
+ | Official balance | Sidebar top / Settings page (configurable) | Total / granted / topped-up balance, auto-refresh + manual refresh; optional three-segment progress bar (blue/orange/gray), whose today segment only counts official-channel spend (coding plans / custom providers excluded) |
30
30
  | Custom provider balance | Sidebar / Settings page (configurable) | Configurable HTTP balance lookup (e.g. LiteLLM); bilingual labels, currency, extract rules (dot path / number / add / subtract / divide — use divide for NewApi-style quota endpoints, see [example](#custom-provider-balance-example-newapi-template)); collapsible panel alongside Coding Plan quotas |
31
31
  | OpenCode Go quota | Sidebar / Settings / bottom-right dock (configurable) | Rolling-5h / weekly / monthly usage percent and reset times, each window toggleable independently, budget used % can show alongside; key auto-discovered (DSH credential store OPENCODE_GO_API_KEY / env / opencode login) or entered manually |
32
32
  | Coding plan quotas | Sidebar / Settings page (per vendor) | Multi-vendor coding-plan quota queries (Anthropic Claude Pro/Max, Z.ai / Zhipu GLM Coding Plan, MiniMax Token Plan, Kimi/Moonshot balance, OpenRouter credits, SiliconFlow balance, CommandCode 5h/weekly windows + monthly credits balance); per-vendor enable switch, key, display position and refresh interval (sidebar card in the same box style as the Go quota; the collapsed rail shows percentages), credentials only sent to official endpoints; neutral hints when no credentials/subscription; SCNet Token Plan has no quota API — monthly usage is estimated from the local ledger via the official credits deduction table (no credentials needed) |
@@ -227,22 +227,22 @@ Real captures from an actual DSH sidebar of the period strip and collapsed verti
227
227
  dsh plugin --profile web add dsh-cost-meter
228
228
  ```
229
229
 
230
- **PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.5.30`** — review the script before running):
230
+ **PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.5.31`** — review the script before running):
231
231
 
232
232
  ```powershell
233
- irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.30/install.ps1 | iex
233
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.31/install.ps1 | iex
234
234
  ```
235
235
 
236
236
  **Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
237
237
 
238
238
  ```sh
239
- dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.30
239
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.31
240
240
  ```
241
241
 
242
242
  Without git, use the GitHub tag archive:
243
243
 
244
244
  ```sh
245
- dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.30.tar.gz
245
+ dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.31.tar.gz
246
246
  ```
247
247
 
248
248
  After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 90+ 模型价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet 八家) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
8
8
 
9
- [![version](https://img.shields.io/badge/version-1.5.30-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
9
+ [![version](https://img.shields.io/badge/version-1.5.31-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
10
10
  [![npm](https://img.shields.io/npm/v/dsh-cost-meter?label=npm)](https://www.npmjs.com/package/dsh-cost-meter)
11
11
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
12
12
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-dsh--plugin-4176E6)](https://github.com/deepseek-ai/deepseek-harness)
@@ -26,7 +26,7 @@
26
26
  | 功能 | 位置 | 说明 |
27
27
  |---|---|---|
28
28
  | 本会话费用 | 输入区下方 / 会话标题栏 | 实时累计费用 + 输入/缓存/输出 token,位置可配 |
29
- | 官方余额 | 侧边栏顶部 / 设置页(可配) | 总余额 / 赠送 / 充值,自动刷新 + 手动刷新;可选三段进度条(蓝/橙/灰) |
29
+ | 官方余额 | 侧边栏顶部 / 设置页(可配) | 总余额 / 赠送 / 充值,自动刷新 + 手动刷新;可选三段进度条(蓝/橙/灰),当日段只统计官方渠道费用(不含 Coding Plan / 自定义 Provider) |
30
30
  | 自定义 Provider 余额 | 侧边栏 / 设置页(可配) | 可配置 HTTP 查询任意 Provider 余额(LiteLLM 等);中/英名称、币种、extract 规则(点路径 / 数字常量 / add / subtract / divide,divide 适配 NewApi 等 quota 端点,见下方[示例](#自定义-provider-余额配置示例newapi-模板));与 Coding Plan 同区可折叠配置 |
31
31
  | OpenCode Go 额度 | 侧边栏 / 设置页 / 右下角(dock,可配) | 滚动 5 小时 / 本周 / 本月用量百分比与重置时间,三档可分别开关,可同时显示预算已用%;Key 自动发现(DSH 凭据库 OPENCODE_GO_API_KEY / 环境变量 / opencode 登录态)或手动填写 |
32
32
  | Coding Plan 额度 | 侧边栏 / 设置页(每家可配) | 多厂商 coding plan 订阅额度查询(Anthropic Claude Pro/Max、Z.ai/智谱 GLM、MiniMax Token Plan、Kimi/Moonshot 余额、OpenRouter credits、SiliconFlow 余额、CommandCode 5h/周窗口与月度 Credits 余额),各家独立启用开关、Key、显示位置与刷新间隔(侧边栏卡片与 Go 额度同款,收起窄栏显示百分比),凭据只发往官方端点;无凭据/无订阅为中性提示;SCNet 超算互联网 Token Plan 无 API 额度端点,按官方 Credits 抵扣表由本地账本估算月度用量(无需凭据) |
@@ -229,22 +229,22 @@
229
229
  dsh plugin --profile web add dsh-cost-meter
230
230
  ```
231
231
 
232
- **PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.5.30`**,建议先下载审阅再运行):
232
+ **PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.5.31`**,建议先下载审阅再运行):
233
233
 
234
234
  ```powershell
235
- irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.30/install.ps1 | iex
235
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.31/install.ps1 | iex
236
236
  ```
237
237
 
238
238
  **或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
239
239
 
240
240
  ```sh
241
- dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.30
241
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.31
242
242
  ```
243
243
 
244
244
  没有 git 时可用 GitHub tag 打包直链:
245
245
 
246
246
  ```sh
247
- dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.30.tar.gz
247
+ dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.31.tar.gz
248
248
  ```
249
249
 
250
250
  安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
package/lib/client.js CHANGED
@@ -1757,8 +1757,26 @@ window.__ModuleLoader__.load({
1757
1757
  return null
1758
1758
  }
1759
1759
 
1760
+ // issue #36:官方余额进度条的「当日已用」只统计会扣 DeepSeek 开放平台余额的调用
1761
+ // (byProviderModel 中 provider 前缀为 deepseek 的条目,含未标注 provider 的历史调用);
1762
+ // Coding Plan / 自定义 Provider 等渠道的费用只体现在各自的额度条/余额条上。
1763
+ // 账本无按渠道拆分的旧数据(byProviderModel 缺失/为空)退回全量,保持升级前行为。
1764
+ function todayOfficialUsd(state) {
1765
+ const today = state.today
1766
+ const by = today?.byProviderModel
1767
+ if (by === null || typeof by !== 'object' || Object.keys(by).length === 0) return Number(today?.cost) || 0
1768
+ let sum = 0
1769
+ for (const [key, value] of Object.entries(by)) {
1770
+ const idx = key.indexOf(':')
1771
+ if ((idx >= 0 ? key.slice(0, idx) : key) !== 'deepseek') continue
1772
+ sum += Number(value?.cost) || 0
1773
+ }
1774
+ return sum
1775
+ }
1776
+
1760
1777
  function todayUsedInBalanceCurrency(state, config, mode, custom) {
1761
- const usd = Number(state.today?.cost) || 0
1778
+ // 官方模式只取 deepseek 渠道费用;自定义 Provider 余额无渠道映射,维持全量(与既有行为一致)
1779
+ const usd = mode === 'official' ? todayOfficialUsd(state) : Number(state.today?.cost) || 0
1762
1780
  if (mode === 'custom') {
1763
1781
  const unit = customBalanceUnitOf(config, custom)
1764
1782
  if (unit === 'USD') return usd
package/lib/index.js CHANGED
@@ -42,7 +42,7 @@ const SERVER_MESSAGES = {
42
42
  balanceDisplayOff: '余额显示已关闭,请先在 显示设置 中开启',
43
43
  balanceRefreshed: '余额已刷新',
44
44
  balanceQueryFailed: '余额查询失败:{message}',
45
- reconcileWarn: '对账提示:本地账本今日合计 {cost} 与官方余额当日变动 {delta} 偏差较大,请核对价格表或近期账单',
45
+ reconcileWarn: '对账提示:本地账本今日官方渠道费用 {cost} 与官方余额当日变动 {delta} 偏差较大,请核对价格表或近期账单',
46
46
  goQuotaKeyMissing: '未找到 OpenCode Go API Key。有 Go 订阅的话:运行 opencode login、导出 OPENCODE_GO_API_KEY 环境变量,或在显示设置中填写 Key;没有订阅可关闭上方「启用」开关。',
47
47
  goQuotaHttp: 'OpenCode Go 额度接口 HTTP {code}',
48
48
  goQuotaNoSub: '没有检测到生效的 OpenCode Go 订阅(接口返回 {code}),或 API Key 无效。没有订阅可关闭上方「启用」开关。',
@@ -82,7 +82,7 @@ const SERVER_MESSAGES = {
82
82
  balanceDisplayOff: 'Balance display is off; enable it in Display settings first',
83
83
  balanceRefreshed: 'Balance refreshed',
84
84
  balanceQueryFailed: 'Balance query failed: {message}',
85
- reconcileWarn: 'Reconciliation notice: today\'s local ledger cost ({cost}) deviates significantly from the official balance change ({delta}); please check the price table or recent bills',
85
+ reconcileWarn: 'Reconciliation notice: today\'s local official-channel cost ({cost}) deviates significantly from the official balance change ({delta}); please check the price table or recent bills',
86
86
  goQuotaKeyMissing: 'OpenCode Go API key not found. If you have a Go subscription: run opencode login, export OPENCODE_GO_API_KEY, or set the key in Display settings; otherwise turn off the Enable switch above.',
87
87
  goQuotaHttp: 'OpenCode Go quota API returned HTTP {code}',
88
88
  goQuotaNoSub: 'No active OpenCode Go subscription detected (API returned {code}), or the API key is invalid. Turn off the Enable switch above if you have no subscription.',
@@ -605,11 +605,12 @@ function createService(ctx, ledger) {
605
605
  }
606
606
  const task = queryBalance(ctx, localeOf(ledger.config)).then(result => {
607
607
  balanceCache = { fetchedAt: Date.now(), value: { status: 'ok', message: '', fetchedAt: Date.now(), ...result } }
608
- // 余额差交叉校验(issue #18):官方余额当日变动 vs 本地账本今日合计,偏差超阈提示。
608
+ // 余额差交叉校验(issue #18):官方余额当日变动 vs 本地账本今日官方渠道费用,偏差超阈提示。
609
+ // issue #36:Coding Plan / 自定义 Provider 的费用不动官方余额,对账只统计 deepseek 渠道,否则订阅用户会恒报 drift。
609
610
  if ((ledger.config?.balance?.reconcile ?? true) === true && balanceCache.value.status === 'ok') {
610
611
  const nowMs = Date.now()
611
612
  const usd = v => '$' + Number(v).toFixed(4)
612
- const { ref, event } = reconcileBalanceDelta(ledger.balanceRef, balanceCache.value, ledger.today().cost, localDayKey(nowMs), nowMs)
613
+ const { ref, event } = reconcileBalanceDelta(ledger.balanceRef, balanceCache.value, ledger.todayOfficialCost(), localDayKey(nowMs), nowMs)
613
614
  if (ref !== ledger.balanceRef) {
614
615
  ledger.balanceRef = ref
615
616
  ledger.scheduleWrite()
package/lib/store.js CHANGED
@@ -153,6 +153,26 @@ export function zeroDay(date) {
153
153
  return { date, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0, calls: 0, cost: 0, byProviderModel: {}, sessions: [] }
154
154
  }
155
155
 
156
+ /**
157
+ * 聚合某日账本中归属 DeepSeek 官方渠道的费用(USD;issue #36)。
158
+ * 只累加 byProviderModel 里 provider 前缀为 deepseek 的条目(账本记账时未标注
159
+ * provider 的调用同样归入 deepseek);Coding Plan / 自定义 Provider 等渠道不计入。
160
+ * 无按渠道拆分的旧数据(byProviderModel 缺失/为空)退回全量 cost,保持升级前行为。
161
+ * @param day - 单日账本记录(可能为 undefined)。
162
+ */
163
+ export function officialCostOfDay(day) {
164
+ if (day === undefined || day === null || typeof day !== 'object') return 0
165
+ const by = day.byProviderModel
166
+ if (by === null || typeof by !== 'object' || Object.keys(by).length === 0) return Number(day.cost) || 0
167
+ let sum = 0
168
+ for (const [key, value] of Object.entries(by)) {
169
+ const idx = key.indexOf(':')
170
+ if ((idx >= 0 ? key.slice(0, idx) : key) !== 'deepseek') continue
171
+ sum += Number(value?.cost) || 0
172
+ }
173
+ return sum
174
+ }
175
+
156
176
  function zeroSession(id) {
157
177
  return { id, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0, calls: 0, cost: 0, byProviderModel: {} }
158
178
  }
@@ -1039,6 +1059,15 @@ export class Ledger {
1039
1059
  return day === undefined ? zeroDay(date) : this.copyDay(day)
1040
1060
  }
1041
1061
 
1062
+ /**
1063
+ * 今日账本中归属 DeepSeek 官方渠道的费用(USD,issue #36)。
1064
+ * 官方余额进度条「当日已用」与余额差对账只关心会扣 DeepSeek 开放平台余额的调用;
1065
+ * Coding Plan、自定义 Provider 等渠道的费用不计入(各自额度条/余额条自行体现)。
1066
+ */
1067
+ todayOfficialCost() {
1068
+ return officialCostOfDay(this.days[localDayKey(Date.now())])
1069
+ }
1070
+
1042
1071
  /** 历史列表(降序,轻量副本,不含会话明细)。 */
1043
1072
  history(limit = 60) {
1044
1073
  return Object.keys(this.days)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cost-meter",
3
- "version": "1.5.30",
3
+ "version": "1.5.31",
4
4
  "description": "DeepSeek Harness 会话费用统计插件:本会话成本、当日费用、历史记录与官方价格同步,支持多厂商多模型价格计费(内置 90+ 模型价格目录与自动匹配)、主流 Coding Plan 订阅额度查询与显示(7 家,含 SCNet Token Plan 本地 Credits 计量)、自定义 Provider 余额查询(可配任意 HTTP 端点)与余额进度条、峰谷计价时段显示与切换前弹窗/系统通知提醒(位置/提前量/类型可配),界面中英双语。Session cost tracking plugin for DeepSeek Harness: per-conversation cost, daily totals, history and official price sync, with multi-vendor model pricing (built-in 90+ model catalog with auto-matching), Coding Plan quota queries & display for 7 vendors (incl. local credits metering for the SCNet Token Plan), custom provider balance lookup (configurable HTTP endpoint) and balance progress bar, plus peak/off-peak pricing display with pre-switch popup & system-notification alerts (position / lead time / type configurable), in a bilingual (Chinese/English) UI.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",