@kenz1117/dsh-ui-usage-billing 0.9.9 → 0.9.10

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
@@ -38,20 +38,20 @@
38
38
 
39
39
  ![Rates: model rate table (peak/off-peak split and live rate)](screenshots/5.png)
40
40
  - **Official vs third-party buckets**: the detail cost column is split by official DeepSeek direct / third-party relay ("official x / third y" when mixed); the Stats tab has an official/third-party summary card.
41
- - **Relay-site attribution & quota**: usage is grouped by a provider's `baseURL` origin — multiple keys on the same relay station merge into one row, named by its domain. The Providers tab adds a "Relay sites" card (relay / direct / unknown-route states — an unknown route is one deleted or renamed in the current provider config, honestly labeled "cannot read" rather than mis-attributed as direct). Routes with a `baseURL` are auto-detected as New API (`/api/status`) or Sub2API (`/v1/usage`) to read their **balance and rolling quota windows**, labeled "no quota" when unreadable; the Zhipu GLM / Z.ai (CN region) wallet balance is now supported (read alongside the subscription plan). Project attribution prefers the workspace title for naming.
41
+ - **Relay-site attribution & quota**: usage is grouped by a provider's `baseURL` origin — multiple keys on the same relay station merge into one row, named by its domain. The Providers tab adds a "Relay sites" card (relay / direct / unknown-route states — an unknown route is one deleted or renamed in the current provider config, honestly labeled "cannot read" rather than mis-attributed as direct). Routes with a `baseURL` are auto-detected as New API (`/api/status`) or Sub2API (`/v1/usage`) to read their **balance and rolling quota windows**, labeled "no quota" when unreadable, <20% remaining in red; station recognition is cached for 5 minutes (multiple keys on one station fuse-break independently), and the `relay-quotas` endpoint attaches `diagnostics` for "why is my relay not showing". The Zhipu GLM / Z.ai (CN region) wallet balance is now supported (read alongside the subscription plan). Project attribution prefers the workspace title for naming. **Unpriced models** (out-of-catalog / no price) count as 0 cost, with a "N models not priced" hint under the hero.
42
42
  - **Monthly budget + tier alerts**: a budget bar (on/off / amount / progress, ≥80% amber, over red pulse); notifies once per tier crossing 50/80/100%; a balance below the threshold (in CNY) alerts once a day.
43
43
  - **Subscription quota**: detects subscription providers in `llm-pi-ai` (Kimi / Z.ai / OpenCode Go / MiniMax / OpenRouter / Xiaomi / Volcano…); those with a quota API show remaining % and reset time live, exhausted in red, no API shown as "not wired"; subscription-channel model cost is 0. **MiniMax note**: use the `minimax-token-plan-cn` provider id in MiniMax API for region `https://api.minimaxi.com`; the international route keeps `minimax` / `minimax-token-plan` against `https://www.minimaxi.com`. Override `baseUrl` per provider for proxies or staging.
44
44
 
45
45
  ![Providers: provider billing & subscriptions (balance, plan quota, model usage)](screenshots/3.png)
46
46
  - **Custom provider balance**: configure any HTTP endpoint for balance (`extract` supports constant / dot-path / add-subtract / divide, header `{{ENV}}` via the credentials seam); DeepSeek / Kimi / StepFun / SiliconFlow have built-in official balances, and the balance column estimates "≈N days" from the 7-day daily burn.
47
- - **Real usage aggregation**: the server aggregates from session logs on demand (incremental cache recomputes only written sessions), with per-session corruption tolerance and snapshot fallback; an optional `usage_stats` tool lets the model query today / month spend (**off by default** — toggle it in the Settings tab; takes effect after a reload).
47
+ - **Real usage aggregation**: the server aggregates from session logs on demand (incremental cache recomputes only written sessions), with per-session corruption tolerance and snapshot fallback; an optional `usage_stats` tool lets the model query today / month / current session / cumulative spend, plus `bySite` (relay-attributed) and `relay` (relay-only) summaries (**off by default** — toggle it in the Settings tab; takes effect after a reload).
48
48
  - **Multi-language + dual currency**: the ¥/$ switch is bilingual (USD→English, CNY→Chinese, this plugin only); the rate table converts to the selected currency.
49
49
  - **Model health + uncatalogued annotation**: provider connection dots (green / red / grey); a model id not in the catalog is marked "uncatalogued" priced at the fallback, with provider inferred (e.g. `mi-mimo-2.5` → Xiaomi); estimated-price models are marked "estimated".
50
50
  - **Session detail + cost spikes + heatmap**: sessions sorted by cost (title / project / calls / cost / last active); per-turn cost bars (last 40 turns, amount at bar top, peak/off-peak background bands, >2× spike flagged with attribution); a monthly calendar heatmap (5-color scale, hover detail).
51
51
 
52
52
  ![Trends: daily cost trend, per-turn costs and peak/off-peak share](screenshots/2.png)
53
53
 
54
- - **Export + offline self-contained**: the Stats tab exports daily / per-session CSV and full JSON; no chart library, no external CDN, pure design tokens.
54
+ - **Export + offline self-contained**: the Stats tab exports daily / per-session / per-site CSV and full JSON; cost breakdown / workspaces / session-detail sections are drillable (click a project row to expand its sessions); no chart library, no external CDN, pure design tokens.
55
55
  - **Stability & reliability**: official-interface shape drift degrades with an explicit `invalid` status (distinct from network-unreachable); balance / subscription / pricing upstreams share a unified timeout budget, exponential-backoff retry and per-platform circuit-breaker cooldown; the stats snapshot is written with a `.bak` backup and auto-recovers from corruption; session-log reads re-check freshness to avoid half-line misreads; auth failures warn per provider with cooldown; the per-session fold cache is bounded by LRU to keep long-running memory stable.
56
56
 
57
57
  ![Stats: export, cost breakdown, workspaces and session detail](screenshots/4.png)
@@ -139,7 +139,7 @@ To add a model: append an entry to `MODEL_CATALOG` and map its real id in `MODEL
139
139
 
140
140
  ## HTTP API
141
141
 
142
- The public HTTP endpoints and field definitions are documented in source: `GET /api/billing/pricing`, `/api/billing/balance`, `/api/billing/usage-stats`, `/api/billing/subscriptions`, `/api/billing/relay-quotas` (see `src/index.ts`, `src/aggregate.ts`, `src/relay.ts`). The `usage-stats` payload's `bySite` field is the relay-attributed usage distribution (`site:<origin>` / `direct:<provider>` / `unknown`).
142
+ The public HTTP endpoints and field definitions are documented in source: `GET /api/billing/pricing`, `/api/billing/balance`, `/api/billing/usage-stats`, `/api/billing/subscriptions`, `/api/billing/relay-quotas` (see `src/index.ts`, `src/aggregate.ts`, `src/relay.ts`). The `usage-stats` payload carries `bySite` (relay-attributed usage distribution: `site:<origin>` / `direct:<provider>` / `unknown`) and `unpricedModels` (ids of models with no price); `relay-quotas` returns `quotas` plus `diagnostics` (per-route origin / kind classification, for "why is my relay not showing"). All endpoints accept loopback requests only (peer socket address + Host header verified).
143
143
 
144
144
  ## Configuration
145
145
 
@@ -185,6 +185,10 @@ None. This plugin is a pure UI surface: it registers no tools, injects no system
185
185
  - **Cost is a catalog estimate**: models without published per-token pricing (iFlytek, SenseTime, Xiaomi) use estimates (feature-list footnote ¹); official billing is authoritative.
186
186
  - **The 30-day trend is bounded by log retention**: dates outside the persisted log retention window are shown as zeros in the window, not backfilled.
187
187
 
188
+ ## Contributors
189
+
190
+ - [@ciphoo](https://github.com/ciphoo) — MiniMax CN Token Plan quota support (PR #5)
191
+
188
192
  ## License
189
193
 
190
194
  [MIT](LICENSE) © 2026 KenZ (kenz1117)
package/README.md CHANGED
@@ -38,22 +38,22 @@
38
38
 
39
39
  ![费率:模型单价表(峰谷分时与实时汇率)](screenshots/5.png)
40
40
  - **官方 vs 三方分桶**:明细费用列按官方 DeepSeek 直连 / 第三方中转分解(混合时「官 x / 三 y」),统计 Tab 有「官方/三方」汇总卡。
41
- - **中转站归组与额度**:按 provider 的 `baseURL` 归一化 origin 归组——同一中转站的多把 key 合并成一行,站名即域名;明细 Tab 新增「中转站分布」卡(中转站 / 直连 / 未知路由三态,未知路由 = 配置里已删 / 改名的路由,诚实标注「读不到」而非误归直连)。对配了 `baseURL` 的路由自动识别 New API 系(`/api/status`)与 Sub2API(`/v1/usage`)的**余额与滚动额度窗口**,读不出标「未读出额度」;智谱 GLM / Z.ai 国内域钱包余额已接入(与订阅套餐双读)。项目归属优先用工作区标题命名。
41
+ - **中转站归组与额度**:按 provider 的 `baseURL` 归一化 origin 归组——同一中转站的多把 key 合并成一行,站名即域名;明细 Tab 新增「中转站分布」卡(中转站 / 直连 / 未知路由三态,未知路由 = 配置里已删 / 改名的路由,诚实标注「读不到」而非误归直连)。对配了 `baseURL` 的路由自动识别 New API 系(`/api/status`)与 Sub2API(`/v1/usage`)的**余额与滚动额度窗口**,读不出标「未读出额度」,剩余 <20% 标红;中转站识别结果有 5 分钟指纹缓存(同站多把 key 独立熔断),`relay-quotas` 端点附 `diagnostics` 供「我的中转站为什么不显示」自查。智谱 GLM / Z.ai 国内域钱包余额已接入(与订阅套餐双读)。项目归属优先用工作区标题命名。**未计价的模型**(目录外/无价)费用按 0 计,Hero 下会提示「N 个模型未收录计价」。
42
42
  - **月度预算 + 分档提醒**:预算条(开关 / 金额 / 进度,≥80% 琥珀、超支红脉);跨 50 / 80 / 100% 各提醒一次;余额折算 CNY 低于阈值每天提醒一次。
43
43
  - **订阅套餐额度**:识别 `llm-pi-ai` 里的订阅类 provider(Kimi / Z.ai / OpenCode Go / MiniMax / OpenRouter / 小米 / 火山…),有额度 API 的实时显示剩余%与重置时间、用尽标红,无 API 标「未接入」;订阅通道模型费用记 0。档位月费与周期额度口径由内置知识库自动识别(如 OpenCode Go $10/月 + 周 $30 额度),有档位知识的标「自动识别」。**MiniMax 用户注意**:在国内开发者环境请使用 `minimax-token-plan-cn` provider id,自动对接 `https://api.minimaxi.com`;国际保留 `minimax` / `minimax-token-plan`,默认 `https://www.minimaxi.com`。需要自配中转或 staging 时可在该 provider 设置里覆盖 `baseUrl`。
44
44
 
45
45
  ![明细:厂商计费与订阅(余额、套餐额度、模型用量)](screenshots/3.png)
46
46
  - **自定义 Provider 余额**:配置任意 HTTP 端点查余额(`extract` 支持常量 / 点路径 / add-subtract / divide,请求头 `{{ENV}}` 经凭据 seam);DeepSeek / Kimi / 阶跃星辰 / 硅基流动内置官方余额,余额列按近 7 天日均折算「约可撑 N 天」。
47
- - **真实用量聚合**:服务端从会话日志实时聚合(增量缓存只重算写过的会话),单会话损坏容错、快照落盘回退;`usage_stats` 工具让模型自查今天 / 本月花费。
47
+ - **真实用量聚合**:服务端从会话日志实时聚合(增量缓存只重算写过的会话),单会话损坏容错、快照落盘回退;`usage_stats` 工具让模型自查今天 / 本月 / 当前会话 / 累计费用,还可查 `bySite`(按站点归组)与 `relay`(只看中转站)的汇总。
48
48
  - **多语种 + 双币种**:¥ / $ 切换随币种双语(USD→英文、CNY→中文,仅本插件生效);费率表按所选币种换算。
49
49
  - **模型健康 + 未收录标注**:厂商接入状态圆点(绿 / 红 / 灰);模型 id 不在目录时标「未收录」按兜底价估算、厂商自动推断(如 `mi-mimo-2.5` → 小米);估算价模型标注「估算价」。
50
50
  - **会话明细 + 成本突增 + 热力图**:按会话费用倒序(标题 / 项目 / 调用 / 费用 / 最后活跃);每轮费用柱状图(最近 40 轮、金额贴柱顶、峰谷背景分带、超 2 倍红标归因);月 / 年日历热力图(5 档色阶、悬停明细;年视图近 52 周、GitHub 风格),头部显示活跃天数 / 连续使用天数。
51
51
  - **性能指标**:每个模型首字延时(TTFT)均值 / P50 / P90、生成速度(tokens/s)、总延迟均值,另按北京时间小时聚合 TTFT 与速度曲线;请求从头到首个内容 chunk 测 TTFT,工具续写步骤无独立请求头时以 step/start 估算并标 estimated。统计 Tab 渲染为按模型性能表 + 按小时 TTFT/速度双折线。
52
- - **Token 统计洞察**:独立「Token」分区——每日 token 堆叠(未命中输入 / 缓存命中 / 输出,含 reasoning 思考),模型 token 总量与占比,结构 KPI(缓存命中率 / 思考占比 / 输入输出比 / 峰值日);按日 token CSV 与 JSON 导出。
52
+ - **Token 统计洞察**:独立「Token」分区——每日 token 堆叠按「输入(缓存未命中)/ 输入(缓存命中)/ 输出」三桶分色(含 reasoning 思考),模型 token 总量与占比,结构 KPI(缓存命中率 / 思考占比 / 输入输出比 / 峰值日);按日 token CSV 与 JSON 导出。
53
53
 
54
54
  ![趋势:每日费用趋势、每轮费用与峰谷时段占比](screenshots/2.png)
55
55
 
56
- - **数据导出 + 离线自包含**:统计 Tab 导出按日 / 按会话 CSV 与全量 JSON;无图表库、无外部 CDN、纯设计令牌。
56
+ - **数据导出 + 离线自包含**:统计 Tab 导出按日 / 按会话 / 按站点 CSV 与全量 JSON;费用构成 / 工作区 / 会话明细分区可下钻(点项目行展开该项目的会话);无图表库、无外部 CDN、纯设计令牌。
57
57
  - **插件信息卡**:设置 Tab 常驻「关于」卡——插件名、描述、作者(可跳 GitHub)、源码仓库、npm、许可证 MIT、版本号(服务端读自包 `package.json`,单一来源,发布自动正确)。
58
58
 
59
59
  ![统计:导出、费用构成、工作区与会话明细](screenshots/4.png)
@@ -141,7 +141,7 @@ cost(CNY)= (missInput × p_input + cacheHit × p_cacheHit + output × p_outp
141
141
 
142
142
  ## HTTP API
143
143
 
144
- 对外 HTTP 接口与字段定义详见源码:`GET /api/billing/pricing`、`/api/billing/balance`、`/api/billing/usage-stats`、`/api/billing/subscriptions`、`/api/billing/relay-quotas`(见 `src/index.ts`、`src/aggregate.ts`、`src/relay.ts`)。其中 `usage-stats` 返回的 `bySite` 字段为按中转站归组后的用量分布(`site:<origin>` / `direct:<provider>` / `unknown`)。
144
+ 对外 HTTP 接口与字段定义详见源码:`GET /api/billing/pricing`、`/api/billing/balance`、`/api/billing/usage-stats`、`/api/billing/subscriptions`、`/api/billing/relay-quotas`(见 `src/index.ts`、`src/aggregate.ts`、`src/relay.ts`)。其中 `usage-stats` 返回的 `bySite` 字段为按中转站归组后的用量分布(`site:<origin>` / `direct:<provider>` / `unknown`),`unpricedModels` 为未计价模型的 id 列表;`relay-quotas` 返回 `quotas`(各中转站额度)与 `diagnostics`(每条路由的 origin / kind 归类,供「为什么不显示」自查)。全部端点仅接受回环请求(peer socket 地址 + Host 头校验)。
145
145
 
146
146
  ## 配置
147
147
 
@@ -187,6 +187,10 @@ npm publish --access public
187
187
  - **费用为目录价估算**:讯飞 / 商汤 / 小米等未公布按量单价的模型使用估算价(特性表脚注 ¹),正式定价以厂商账单为准。
188
188
  - **30 天趋势受日志保留范围约束**:超出持久化日志保留期的日期在窗口内补零显示,不回溯历史。
189
189
 
190
+ ## Contributors
191
+
192
+ - [@ciphoo](https://github.com/ciphoo) — MiniMax 国内域 Token Plan 订阅额度支持(PR #5)
193
+
190
194
  ## 许可证
191
195
 
192
196
  [MIT](LICENSE) © 2026 KenZ (kenz1117)