dsh-cost-meter 1.8.25 → 1.8.26

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.md CHANGED
@@ -2,15 +2,17 @@
2
2
 
3
3
  **English** | [简体中文](README.zh-CN.md)
4
4
 
5
+ Community and feedback: [Join the WeChat group →](#community). The WeChat group is open. You're welcome to join.
6
+
5
7
  <div align="center">
6
8
 
7
9
  **Session cost tracking plugin for the DeepSeek Harness web GUI (bilingual UI)**
8
10
 
9
11
  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; weekends and Chinese public holidays are off-peak all day, with separate labels) · 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 170+ model-ID catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / Volcano Ark / Qwen / Xiaomi MiMo / Factory Droid) plan/API dual-track billing (subscription quota vs pay-as-you-go money separated, per-1% & full-window token/equivalent-cost estimates with daily/weekly/monthly curves) · · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
10
12
 
11
- [![version](https://img.shields.io/badge/version-1.8.25-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
13
+ [![version](https://img.shields.io/badge/version-1.8.26-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
12
14
 
13
- **v1.8.25** adds Factory (Droid) subscription quota windows: 5-hour, weekly and monthly, with separate Standard/Core pools, optional organization ID, secure credential storage and the existing quota strip. See the [Factory guide](docs/factory-quota.md#english).
15
+ **v1.8.26** fixes custom-provider plan matching with manual plan assignment, explicit name-based detection and recovery of fully covered recent usage. See the [plan assignment guide](docs/token-plan-stats.md#assigning-custom-providers-to-a-plan).
14
16
 
15
17
  Desktop users: follow the [Desktop installation instructions](docs/install-troubleshooting.md#desktop-安装与更新) for the application's own CLI and `desktop` Profile.
16
18
 
@@ -90,7 +92,7 @@ For Qianwen / Alibaba Cloud fund accounts, use **Add Qianwen / Alibaba Cloud bal
90
92
 
91
93
  Qwen Token Plan can use the [official CLI subscription quota](docs/qwen-cli-quota.md#english). Install the CLI on the DSH host and run `qianwen auth login` as the same OS user. Local estimates remain the default; CLI mode shows current account credits without changing the local ledger.
92
94
 
93
- Local Qwen Token Plan credits include only the subscription providers `qwen`, `qwen-tokenplan`, `qianwen-tokenplan`, `qwen-token-plan` and `qianwen-token-plan` (case-insensitive, optional `llm-` prefix). Explicit API classifications are excluded. The `qianwen` pay-as-you-go provider does not consume estimated plan credits even when its model ID is identical. Use one of the supported subscription provider names; models outside the credits table need all three rates configured.
95
+ Local Qwen Token Plan credits include Plan calls assigned to Qwen. Existing subscription aliases such as `qwen` and `qwen-tokenplan` remain supported; custom providers can select Qwen under Model statistics → Billing class, or use an explicit vendor name and plan marker for auto detection. Explicit API calls are excluded. The pay-as-you-go `qianwen` provider is not assigned merely because its model ID is identical. Models outside the credits table need all three rates configured.
94
96
 
95
97
  Xiaomi MiMo Token Plan quotas are queried with the **MiMo console cookie**, not an API key: log in at `platform.xiaomimimo.com`, press F12 → Network → find the `balanceAlertConfig` request and paste the full `cookie` request header into the MiMo card in Settings → Cost → Quotas (it must include `serviceToken` and `userId`; the DSH credential store keeps it as `MIMO_COOKIE`). The card shows the plan/compensation credit windows with the period-end reset (Beijing time) plus a balance row. Copy a fresh console cookie when the card reports an expired login. Token Plan inference keys (`tp-*` / `ttp-*`) are not accepted by this console adapter. Local plan statistics use the calendar month; compensation and balance are displayed without estimates because local calls cannot be attributed to those pools.
96
98
 
@@ -323,22 +325,22 @@ On Node.js 20, use `npm install -g pnpm@10` instead. See [pnpm installation and
323
325
  dsh plugin --profile web add dsh-cost-meter
324
326
  ```
325
327
 
326
- **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.8.25`** — review the script before running):
328
+ **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.8.26`** — review the script before running):
327
329
 
328
330
  ```powershell
329
- irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.25/install.ps1 | iex
331
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.26/install.ps1 | iex
330
332
  ```
331
333
 
332
334
  **Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
333
335
 
334
336
  ```sh
335
- dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.25
337
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.26
336
338
  ```
337
339
 
338
340
  Without git, use the GitHub tag archive:
339
341
 
340
342
  ```sh
341
- dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.25.tar.gz
343
+ dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.26.tar.gz
342
344
  ```
343
345
 
344
346
  After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
@@ -509,6 +511,15 @@ Check and clear the host search before changing stored data.
509
511
  - Plan/API classification is inferred from channel and config; mixed subscription/PAYG usage of one vendor (e.g. Kimi) can be overridden per provider:model in settings.
510
512
  - A restart of `dsh web` is required after installing/updating the plugin.
511
513
 
514
+ ## Community
515
+
516
+ Join the WeChat group to discuss the plugin, share feedback, and suggest features.
517
+
518
+ <p align="center">
519
+ <a href="docs/community-wechat.jpg"><img src="docs/community-wechat.jpg" alt="dsh-cost-meter WeChat community QR code" width="320" /></a><br />
520
+ <a href="docs/community-wechat.jpg">View full-size QR code</a>
521
+ </p>
522
+
512
523
  ## Update history
513
524
 
514
525
  A per-version overview and the community-issue resolution log live in [docs/UPDATE-HISTORY.md](docs/UPDATE-HISTORY.md) (中文); the itemized changelog is [CHANGELOG.md](CHANGELOG.md).
package/README.zh-CN.md CHANGED
@@ -2,15 +2,17 @@
2
2
 
3
3
  [English](README.md) | **简体中文**
4
4
 
5
+ 交流与反馈:[加入微信交流群 →](#交流与反馈) · 微信交流群已开放,欢迎您加入。
6
+
5
7
  <div align="center">
6
8
 
7
9
  **DeepSeek Harness 会话费用统计插件(界面中英双语)**
8
10
 
9
11
  本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段;周末与中国法定假日全天按谷价,分别标注) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 170+ 模型 ID 价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / 火山方舟 / 千问 / 小米 MiMo 十一家,含 Volcano Ark AK/SK 签名与 MiMo 控制台 Cookie 查询) · Plan/API 双轨计费(订阅额度与按量金额分离统计,每 1% 额度与满窗的 token/等值金额估算及日/周/月曲线) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
10
12
 
11
- [![version](https://img.shields.io/badge/version-1.8.25-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
13
+ [![version](https://img.shields.io/badge/version-1.8.26-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
12
14
 
13
- **v1.8.25** 新增 Factory(Droid)订阅额度:5 小时、每周、每月,支持 Standard/Core 分开显示、可选组织 ID、DSH 凭据库及现有额度横条。详见 [Factory 使用说明](docs/factory-quota.md)。
15
+ **v1.8.26** 修复自定义渠道的套餐匹配,支持手动选择套餐和按名称特征自动归属,并恢复能完整核对的近期用量。详见 [套餐归属说明](docs/token-plan-stats.md#自定义渠道如何关联套餐)。
14
16
 
15
17
  桌面端用户请按 [Desktop 安装说明](docs/install-troubleshooting.md#desktop-安装与更新),使用应用自带的 CLI 和 `desktop` Profile。
16
18
 
@@ -89,7 +91,7 @@
89
91
 
90
92
  千问 Token Plan 可在卡片内选择[官方 CLI 订阅额度](docs/qwen-cli-quota.md),需在 DSH 主机以同一系统账号安装 CLI 并运行 `qianwen auth login`。默认保留本地估算;CLI 模式显示账号当前 Credits,不修改本地账本。
91
93
 
92
- 千问 Token Plan 的本地 Credits 仅统计 `qwen`、`qwen-tokenplan`、`qianwen-tokenplan`、`qwen-token-plan`、`qianwen-token-plan` 订阅 provider(大小写不敏感,可带 `llm-` 前缀);显式归类为 API 的调用不计。`qianwen` 按量 provider 即使使用相同模型名也不会计入订阅额度。自定义渠道名需使用上述订阅名称之一,模型不在抵扣表中时需补充三项费率。
94
+ 千问 Token Plan 的本地 Credits 统计归属千问套餐的 Plan 调用。保留 `qwen`、`qwen-tokenplan` 等订阅别名,自定义渠道也可在「按模型统计 → 计费方式」选择千问套餐,或使用明确的厂商名与套餐特征自动识别。显式 API 调用不计;`qianwen` 按量渠道不会仅因同名模型自动归入。模型不在抵扣表中时需补充三项费率。
93
95
 
94
96
  小米 MiMo Token Plan 的额度查询使用**控制台 Cookie**(而非 API Key):登录 `platform.xiaomimimo.com` 后按 F12 →「网络」→ 找到 `balanceAlertConfig` 请求,把请求头 `cookie` 整段粘贴进「设置 → 费用 → 额度」的 MiMo 卡片(需含 `serviceToken` 与 `userId`,DSH 凭据库以 `MIMO_COOKIE` 托管)。卡片显示套餐/补偿积分窗口与周期截止重置(北京时间)及余额行。控制台 Cookie 过期后,按卡片提示重新复制。此控制台查询不接受 Token Plan 推理专用 Key(`tp-*` / `ttp-*`)。本地套餐统计按自然月汇总;补偿积分和余额只展示查询结果,不用无法区分归属的本地调用估算。
95
97
 
@@ -323,22 +325,22 @@ Node.js 20 请改用 `npm install -g pnpm@10`。版本要求见 [pnpm 官方安
323
325
  dsh plugin --profile web add dsh-cost-meter
324
326
  ```
325
327
 
326
- **PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.25`**,建议先下载审阅再运行):
328
+ **PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.26`**,建议先下载审阅再运行):
327
329
 
328
330
  ```powershell
329
- irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.25/install.ps1 | iex
331
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.26/install.ps1 | iex
330
332
  ```
331
333
 
332
334
  **或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
333
335
 
334
336
  ```sh
335
- dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.25
337
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.26
336
338
  ```
337
339
 
338
340
  没有 git 时可用 GitHub tag 打包直链:
339
341
 
340
342
  ```sh
341
- dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.25.tar.gz
343
+ dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.26.tar.gz
342
344
  ```
343
345
 
344
346
  安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
@@ -513,6 +515,15 @@ dsh --profile web --port 3099 # 真机启动(观察启
513
515
  - Plan/API 双轨分类基于渠道与配置推断,混合订阅/按量使用同一厂商 Key 的场景(如 Kimi 订阅 + PAYG 混用)可在设置中按 provider:model 手动覆盖。
514
516
  - 安装/更新插件后需重启 `dsh web` 生效。
515
517
 
518
+ ## 交流与反馈
519
+
520
+ 使用交流、问题反馈和功能建议,欢迎加入微信交流群。
521
+
522
+ <p align="center">
523
+ <a href="docs/community-wechat.jpg"><img src="docs/community-wechat.jpg" alt="dsh-cost-meter 微信交流群二维码" width="320" /></a><br />
524
+ <a href="docs/community-wechat.jpg">查看二维码大图</a>
525
+ </p>
526
+
516
527
  ## 更新历史
517
528
 
518
529
  各版本更新总览与社区 issue 处理记录见 [docs/UPDATE-HISTORY.md](docs/UPDATE-HISTORY.md);逐条开发记录见 [CHANGELOG.md](CHANGELOG.md)。
package/lib/backfill.js CHANGED
@@ -14,7 +14,7 @@ import { open } from 'node:fs/promises'
14
14
  import * as zlib from 'node:zlib'
15
15
  import { costOf, providerPriceEntryFor, usdFromCost, isWrapperProviderId, wrapperUpstreamProvider } from './pricing.js'
16
16
  import { localDayKey, zeroDay, splitLedgerApiCost } from './store.js'
17
- import { billingClassOf, enabledPlanSetOf } from './plan-billing.js'
17
+ import { billingClassOf, enabledPlanSetOf, planProviderIdOf, isRoutedThirdPartyCall, appendHourBucket, planUsageFingerprint, HOUR_BUCKET_RETENTION_MS, localMidnightMs } from './plan-billing.js'
18
18
  import { USAGE_DEDUP_WINDOW_MS, usageFingerprint } from './usage-dedup.js'
19
19
  import { isNativeSearchUsageEvent } from './native-search-events.js'
20
20
  import { listSessionLogFiles } from './session-log-files.js'
@@ -279,6 +279,51 @@ async function* sessionBillingRecords(ledger, sessionsRoot, onlySessionIds = nul
279
279
  }
280
280
  }
281
281
 
282
+ /** Recover only recent, fully covered days. Neither calls nor recorded costs change. */
283
+ export async function repairPlanHourBuckets(ledger, sessionsRoot, { nowMs = Date.now(), isActive = () => true } = {}) {
284
+ const config = structuredClone(ledger.config), fingerprint = planUsageFingerprint(config)
285
+ const historyReset = structuredClone(ledger.historyReset ?? null)
286
+ const from = nowMs - HOUR_BUCKET_RETENTION_MS
287
+ const sessionIds = new Set(), dates = new Set()
288
+ for (const [date, day] of Object.entries(ledger.days ?? {})) {
289
+ if (date < localDayKey(from) || date > localDayKey(nowMs)) continue
290
+ dates.add(date)
291
+ for (const session of day.sessions ?? []) if (typeof session.id === 'string') sessionIds.add(session.id)
292
+ }
293
+ if (!sessionIds.size || !isActive() || ledger.closed) return { days: 0 }
294
+ const byDay = new Map(), enabled = enabledPlanSetOf(config)
295
+ for await (const records of sessionBillingRecords(ledger, sessionsRoot, sessionIds)) {
296
+ if (!isActive() || ledger.closed || planUsageFingerprint(ledger.config) !== fingerprint) return { days: 0 }
297
+ if (!records) continue
298
+ const replay = replaySessionRecords(records, config, dates, true)
299
+ for (const [date, models] of Object.entries(replay.days)) {
300
+ if (!dates.has(date)) continue
301
+ const entry = byDay.get(date) ?? { expected: zeroDay(date), buckets: {} }
302
+ mergeBucketsInto(entry.expected.byProviderModel, models)
303
+ for (const values of Object.values(models))
304
+ for (const key of ['input', 'output', 'cacheRead', 'cacheWrite', 'reasoning', 'calls', 'cost']) entry.expected[key] += Number(values[key]) || 0
305
+ byDay.set(date, entry)
306
+ }
307
+ for (const call of replay.samples ?? []) {
308
+ if (call.seed || call.atMs < from || call.atMs > nowMs || !dates.has(call.date)
309
+ || billingClassOf(call.provider, call.model, config.planBilling, enabled, config.prices) !== 'plan') continue
310
+ const id = planProviderIdOf(call.provider, config.planBilling, call.model)
311
+ ?? (isRoutedThirdPartyCall(call.provider, call.model, config.prices) ? 'go' : null)
312
+ const entry = byDay.get(call.date)
313
+ if (id && entry) entry.buckets = appendHourBucket(entry.buckets, id, call.atMs,
314
+ ['input', 'output', 'cacheRead', 'cacheWrite', 'reasoning'].reduce((sum, key) => sum + (Number(call.buckets[key]) || 0), 0), call.cost)
315
+ }
316
+ }
317
+ if (!isActive() || ledger.closed) return { days: 0 }
318
+ const repairs = [...byDay].map(([date, entry]) => {
319
+ const start = localMidnightMs(Date.parse(date + 'T12:00:00'))
320
+ const end = new Date(new Date(start).getFullYear(), new Date(start).getMonth(), new Date(start).getDate() + 1).getTime()
321
+ return { date, start, end, ...entry, fingerprint, historyReset }
322
+ })
323
+ ledger.repairPlanHours(repairs)
324
+ return { days: repairs.length }
325
+ }
326
+
282
327
  /**
283
328
  * 回放单个会话的事件流,重建逐次用量。与 costUsage 投影同规则:
284
329
  * request/header 切换当前 provider/model;usage 块按 (turn, step) 去重,
@@ -0,0 +1 @@
1
+ window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.community.js",factory:d=>{const y=d("react"),{createElement:e,useState:p,useEffect:f}=y,a="dsh-cost-meter:community-notice-seen",r=new Set;let i=!1;function b(){if(i)return!0;try{return window.localStorage.getItem(a)==="1"}catch{return!1}}function w({locale:s,footer:t=!1}){const[m,c]=p(b),n=s==="en",h="https://github.com/Han-1413141/dsh-cost-meter/blob/master/"+(n?"README.md#community":"README.zh-CN.md#交流与反馈"),g=()=>{i=!0;try{window.localStorage.setItem(a,"1")}catch{}c(!0);for(const o of r)o(!0)};f(()=>{r.add(c);const o=u=>{if(u.key===a&&u.newValue==="1"){i=!0;for(const v of r)v(!0)}};return window.addEventListener("storage",o),()=>{r.delete(c),window.removeEventListener("storage",o)}},[]);const l={href:h,target:"_blank",rel:"noopener noreferrer"};return t?m?e("footer",{className:"cm-community-entry"},e("a",l,n?"Community & feedback ↗":"交流与反馈 ↗")):null:m?null:e("aside",{className:"cm-community-notice",role:"status"},e("span",null,n?"The plugin WeChat group is open":"插件交流群已开放"),e("a",l,n?"View QR code ↗":"查看二维码 ↗"),e("button",{type:"button",className:"cm-btn small","aria-label":n?"Dismiss community notice":"关闭交流群提示",onClick:g},"×"))}function x(s){const t=document.createElement("style");return t.textContent=".cm-community-notice{display:flex;align-items:center;gap:12px;flex-wrap:wrap;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);font-size:12px;color:var(--dsw-alias-label-secondary)}.cm-community-notice button{margin-left:auto;flex:none;min-width:28px;min-height:28px}.cm-community-notice a,.cm-community-entry a{color:var(--dsw-alias-state-business-primary,var(--dsw-alias-brand-primary,#4d6bfe));text-decoration:none}.cm-community-notice a:hover,.cm-community-entry a:hover{text-decoration:underline}.cm-community-entry{display:flex;border-top:1px solid var(--dsw-alias-border-l1);padding-top:12px;font-size:12px}.cm-community-notice :focus-visible,.cm-community-entry a:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe);outline-offset:3px;border-radius:4px}",document.head.appendChild(t),s.effect(()=>()=>t.remove(),"cost-meter: community styles"),w}return{mount:x}}});