@kenz1117/dsh-ui-usage-billing 1.8.11 → 1.8.12
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 +17 -3
- package/README.md +15 -3
- package/lib/client.js +5 -5
- package/lib/index.js +1402 -379
- package/lib/types/aggregate.d.ts +22 -13
- package/lib/types/balance.d.ts +4 -2
- package/lib/types/client/PeakScheduleEditor.d.ts +9 -0
- package/lib/types/client/api/balance.d.ts +1 -1
- package/lib/types/client/domain/floating-model.d.ts +31 -0
- package/lib/types/client/domain/types.d.ts +10 -1
- package/lib/types/client/live-cost.d.ts +10 -3
- package/lib/types/client/locales.d.ts +2 -1
- package/lib/types/client/peak-alert.d.ts +2 -1
- package/lib/types/client/peak-schedule-locales.d.ts +48 -0
- package/lib/types/client/price-drafts.d.ts +19 -0
- package/lib/types/client/price-picker.d.ts +17 -0
- package/lib/types/client/pricing.d.ts +8 -9
- package/lib/types/client/round-chart.d.ts +1 -0
- package/lib/types/client/scheduled-band.d.ts +23 -0
- package/lib/types/config.d.ts +2 -0
- package/lib/types/peak-ledger.d.ts +21 -0
- package/lib/types/peak-schedule-history.d.ts +7 -0
- package/lib/types/peak-schedule-models.d.ts +21 -0
- package/lib/types/peak-schedule-store.d.ts +10 -0
- package/lib/types/peak-schedule.d.ts +67 -0
- package/lib/types/pricing-shared.d.ts +61 -1
- package/lib/types/reconcile.d.ts +11 -2
- package/lib/types/routes/balance.d.ts +6 -3
- package/lib/types/routes/peak-schedule.d.ts +12 -0
- package/lib/types/routes/pricing-models.d.ts +11 -0
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -61,7 +61,7 @@ Most billing plugins stop at "token count × unit price". dsh-ui-usage-billing t
|
|
|
61
61
|
|
|
62
62
|
### Sidebar and live feedback
|
|
63
63
|
|
|
64
|
-
- **Trigger card**: today / week / month headline, 7-day trend and daily gauge; choose a full card, compact icon or hidden entry, with a quick look on hover.
|
|
64
|
+
- **Trigger card**: today / week / month headline, 7-day trend and daily gauge; choose a full card, compact icon or hidden entry, with a quick look on hover. The hover card ranks pay-as-you-go and subscription models over the selected period, which defaults to today (previously fixed to the current month). Metered models rank by dashboard cost, including custom prices. Subscription models rank by call count. Multiple channels or usage of unknown origin leave the wallet balance unconfirmed. If only one subscription channel can be identified, the card shows its quota and flags any remaining usage of unknown origin.
|
|
65
65
|
- **Cost bar and alerts**: live turn / Session cost, model-aware peak and quota warnings, plus optional system notifications for tier switches and Session completion.
|
|
66
66
|
- **Shortcut**: bind "Open usage billing dashboard" in the host's Settings → Shortcuts — `⌘⇧D` by default (`Ctrl+Shift+D` on Windows / Linux), rebindable or clearable — so the dashboard stays one keystroke away even with the sidebar entry hidden.
|
|
67
67
|
|
|
@@ -82,11 +82,21 @@ Overview / Queue / Billing / Usage / Trends / Agents / Rates / Settings. The her
|
|
|
82
82
|
|
|
83
83
|
</details>
|
|
84
84
|
|
|
85
|
+
### Independent peak schedules
|
|
86
|
+
|
|
87
|
+
In Settings, choose a configured source and DeepSeek time-priced model. Set peak windows, a fixed UTC offset, weekend treatment or off-peak dates. The start of a window is inclusive and its end is exclusive. Empty windows mean all-day off-peak. Both relays and official sources inherit the 09:00–12:00 and 14:00–18:00 weekday windows in UTC+8 with weekends off-peak. Only official sources inherit the built-in holiday calendar. DeepSeek Account and its aliases keep native pricing even on an origin shared with an API key. The task queue uses the official calendar.
|
|
88
|
+
|
|
89
|
+
Changes and clears apply from the effective time shown in the editor. Replay looks up the revision active at each call. A batch save reports each rule separately and keeps rejected drafts for retry. New revisions identify the local API as their source. The caller's identity is unknown. Only consecutive identical settings for a key can be compacted. Reversions and clears keep their historical intervals.
|
|
90
|
+
|
|
91
|
+
When a session log is gone, billed amounts are preserved. For newly catalogued models, the ledger weights each source's own tokens at two Beijing-time probes (10:00 and 20:00 within the ledger's local day), looking up each probe's schedule revision independently. New records distinguish API-key, protected-account and exempt usage. Older records use an override only where historical routing data rules out shared account traffic. A missing source breakdown uses the native estimate. Known subscriptions, unknown channels and inseparable subscription mixtures incur no backfill charge. The daily blend remains an estimate.
|
|
92
|
+
|
|
93
|
+
Settings are stored in `DSH_HOME/.dsh-usage-peak-schedule.json`, configurable via `peakSchedulePath`. Untimed legacy rules do not affect billing. Invalid revisions or rules are skipped individually. On replacement, the original legacy or damaged file is preserved alongside the settings as `.recovery-<SHA-256>`. The `.bak` file holds the previous saved contents and can be restored while the plugin is stopped.
|
|
94
|
+
|
|
85
95
|
## 💰 Billing engine
|
|
86
96
|
|
|
87
97
|
- **Channel attribution**: official, direct, relay and unknown routes stay separate; route and model aliases repair historical attribution.
|
|
88
98
|
- **Time-based pricing**: live models.dev data, 247 built-in models across 25 vendors, segmented peak pricing and live FX; later changes never rewrite history.
|
|
89
|
-
- **Real-cost overrides**: set relay-specific prices for the same model and fill gaps for uncatalogued models.
|
|
99
|
+
- **Real-cost overrides**: set relay-specific prices for the same model and fill gaps for uncatalogued models. For each day and model, an existing site grid (even an empty one) leaves unattributed usage and mixed paid/subscription buckets at the host cost. A missing grid uses the model default or, if absent, the sole source price. The dashboard labels these source estimates because the source is unknown. The picker includes configured, used and catalog models. Save applies complete, unique rows and keeps the last saved price for rows with invalid drafts. Enter `0` explicitly for a free rate.
|
|
90
100
|
- **Budget controls**: global and per-model budgets, 50 / 80 / 100% alerts, balance warnings and last-40-turn spike attribution.
|
|
91
101
|
|
|
92
102
|

|
|
@@ -94,7 +104,9 @@ Overview / Queue / Billing / Usage / Trends / Agents / Rates / Settings. The her
|
|
|
94
104
|
## 🔌 Subscriptions & balance
|
|
95
105
|
|
|
96
106
|
- **Subscription quotas**: detect Kimi, Z.ai, OpenCode Go, MiniMax, Claude, CommandCode and more, with remaining quota and reset times; subscription-channel model cost is 0.
|
|
97
|
-
- **Official balances
|
|
107
|
+
- **Official balances** cover DeepSeek, Kimi, StepFun, SiliconFlow, xAI, Zhipu GLM and Tencent Cloud TokenHub. The dashboard estimates days remaining from the last seven days of spending for single-currency balances.
|
|
108
|
+
- **DeepSeek wallets** appear on separate rows. The Platform wallet uses the API key. The sign-in wallet requires the optional `deepseekAccount` host service and the UI’s host version, language and time zone. If the service or metadata is missing (for example, the host omits its optional `release` field), the sign-in row explains why. The sign-in integration has been tested with a simulated service; host `0.2.3-alpha.3` now provides that service — a signed-out account shows the reason on that row instead of 0. Reading the balance of a really signed-in account is still pending on-device verification.
|
|
109
|
+
- **DeepSeek reconciliation** compares the CNY Platform wallet’s balance change with spending attributable to that wallet since the same baseline. When both wallets are active, the plugin can still reconcile traffic to the official API site if the API-key route owns that site exclusively and there are no ambiguous direct calls. A source change, an unavailable wallet or ambiguous spending resets the baseline.
|
|
98
110
|
- **Relays and reconciliation**: merge keys by site, read New API / Sub2API rolling quotas, and cross-check custom endpoints or official balance deltas against the ledger.
|
|
99
111
|
|
|
100
112
|

|
|
@@ -226,6 +238,8 @@ To add a model: append an entry to `BUILTIN_MODEL_CATALOG` in `src/builtin-catal
|
|
|
226
238
|
|
|
227
239
|
## 🔌 HTTP API
|
|
228
240
|
|
|
241
|
+
`GET /api/billing/peak-schedule` returns available source/model pairs, current rules, the latest revision's effective time and notices. `POST /api/billing/peak-schedule` accepts `{ "version": 3, "changes": { … } }`. Each key is a JSON-stringified source/model pair. Its value is a rule or `null` to clear it. The response includes `results` with `accepted`, `invalidRule` or `unavailableModel` per key. A malformed envelope returns 400 and a clock conflict returns 409. Both methods require a local request.
|
|
242
|
+
|
|
229
243
|
The public HTTP endpoints and field definitions are documented in source, including usage, pricing, balances, subscriptions, relay quotas, `GET/POST /api/billing/task-queue` and `GET /api/billing/task-queue-summary` (see `src/index.ts`, `src/aggregate.ts`, `src/relay.ts`, `src/routes/task-queue.ts`). The queue returns host capability, workspaces, official models and durable tasks; mutations are `enqueue` / `enqueueMany`, remove-not-started and clear-finished. The summary returns only the price-band state and queued count, never Prompts. All endpoints accept loopback requests only; queue writes additionally require a loopback Origin, JSON Content-Type and a body no larger than 10 MiB.
|
|
230
244
|
|
|
231
245
|
## ⚙️ Configuration
|
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
|
|
62
62
|
### 侧栏与即时反馈
|
|
63
63
|
|
|
64
|
-
- **触发卡**:今日 / 本周 / 本月主数字、近 7
|
|
64
|
+
- **触发卡**:今日 / 本周 / 本月主数字、近 7 天趋势与当日水位;支持完整卡片、紧凑图标、完全隐藏,悬停可看速览。速览中的按量模型与订阅模型跟随触发卡的统计范围,默认看今天(此前固定看本月)。按量模型按仪表盘显示的费用排名,包含自定义单价;订阅模型按调用数排名。多个通道或部分用量来源不明时,卡片不推测余额。若只能确认一个订阅通道,会显示该通道的额度,并标注仍有用量来源不明。
|
|
65
65
|
- **与其它插件共存**:侧栏底部入口被多个插件同时占用时,触发卡自动收成 36×36 图标钮(不占满整行、不挤走邻居),悬停仍出速览、点击照常打开仪表盘;邻居卸载后自动还原成完整卡片。
|
|
66
66
|
- **费用条与提醒**:常驻本轮 / 会话费用,按当前模型显示峰谷和订阅额度预警;切档与会话完成可发系统通知。
|
|
67
67
|
- **快捷键**:宿主「设置 → 快捷键」可绑定「打开用量计费仪表盘」,默认 `⌘⇧D`(Windows / Linux `Ctrl+Shift+D`),可改绑或清空;侧栏隐藏后也能一键打开面板。
|
|
@@ -83,6 +83,16 @@
|
|
|
83
83
|
|
|
84
84
|
</details>
|
|
85
85
|
|
|
86
|
+
### 独立峰谷时段
|
|
87
|
+
|
|
88
|
+
在「设置」中选一个已配置的来源与 DeepSeek 分时价模型,填写高峰窗口、固定 UTC 偏移、周末和指定低谷日期后保存。窗口开始分钟计入高峰,结束分钟不计入;空窗口表示全天低谷。规则只修改该来源与模型的判档,不修改模型单价或官方历史调价节点。没有规则时保留原有计价;DeepSeek 账号通道及其别名始终走原规则,即使与 API Key 共用站点也是如此。低谷任务队列仍按官方时段调度。
|
|
89
|
+
|
|
90
|
+
中转与官方来源均继承 09:00–12:00、14:00–18:00 的工作日峰窗,周末全天低谷,默认时区 UTC+8。只有官方来源自动继承内置节假日。每个更改或清除自面板显示的生效时间起作用,历史日志按调用时刻查修订。批量保存会逐条返回结果,修正失败的草稿即可重试。新修订记录本机 API 来源,调用者身份未知。持久化只合并同一键连续重复的设置,保留改动、恢复和清除的历史区间。
|
|
91
|
+
|
|
92
|
+
仅剩账本时,已计费用原样保留。新收录模型按各来源的实际 token 桶,在账本自然日内取北京时间 10:00 和 20:00 两个探针,分别使用探针时刻生效的规则,再按既定比例混合估价。新账本区分 API Key、账号和豁免用量;旧账本只有在历史路由信息能排除账号共用时才套用该来源规则。缺少来源明细的部分沿用内置估价;已知订阅或未知通道,以及无法拆分的订阅混合桶,不补收费用。日级估价仍有别于逐请求实算。
|
|
93
|
+
|
|
94
|
+
配置默认保存在 `DSH_HOME/.dsh-usage-peak-schedule.json`,可用 `peakSchedulePath` 指定其他位置。没有生效时间的旧版规则不参与计价。损坏的修订或规则会单独跳过,其他有效历史保留。首次替换旧版或损坏文件时,原始字节保存在同目录 `.recovery-<SHA-256>` 文件中。`.bak` 文件保留上一次保存内容,可停用插件后从备份恢复。
|
|
95
|
+
|
|
86
96
|
## 💰 计费引擎
|
|
87
97
|
|
|
88
98
|
- **按通道归账**:官方、直连、中转与未知路由分开统计;路由别名和模型别名可修复历史归属。
|
|
@@ -95,7 +105,7 @@
|
|
|
95
105
|
## 🔌 订阅与余额
|
|
96
106
|
|
|
97
107
|
- **订阅额度**:自动识别 Kimi、Z.ai、OpenCode Go、MiniMax、Claude、CommandCode 等通道,展示剩余额度与重置时间;订阅模型费用记 0。
|
|
98
|
-
- **官方余额**:覆盖 DeepSeek、Kimi、阶跃星辰、硅基流动、xAI、智谱 GLM、腾讯云 TokenHub,并按近 7 天消耗估算可用天数。
|
|
108
|
+
- **官方余额**:覆盖 DeepSeek、Kimi、阶跃星辰、硅基流动、xAI、智谱 GLM、腾讯云 TokenHub,并按近 7 天消耗估算可用天数。DeepSeek 开放平台余额通过 API Key 查询。登录钱包是可选服务适配:仅当宿主注入 `deepseekAccount` 且界面提供版本、语言与时区时才查询,与 API Key 钱包分别展示。宿主启动信息可省略 `release`;缺少元数据或服务时会显示原因。此路径经桩服务验证;宿主 `0.2.3-alpha.3` 已提供该服务——未登录时该行显示「未登录」而不是 0,真实登录账号的余额读取仍待实机验收。余额差对账仅比较同一开放平台人民币钱包、同一基准之后可归属的费用;同时登录时,仅当官方 API 站点由该路由独占且没有无法区分的直连费用时才对账。来源切换、钱包不可用或费用混合无法分辨时重置基准。
|
|
99
109
|
- **中转与对账**:同站多 key 合并,识别 New API / Sub2API 滚动额度;自定义端点与官方余额差可和本地账本交叉验证。
|
|
100
110
|
|
|
101
111
|

|
|
@@ -198,7 +208,7 @@ cost(CNY)= (missInput × p_input + cacheWrite × p_cacheWrite + cacheHit ×
|
|
|
198
208
|
|
|
199
209
|
**「本月预计」的口径**:本月已发生 + 近 7 个自然日节奏 × 本月剩余天数。只外推还没发生的天数,近期没花钱就不虚增——早期版本拿「本月有记录的天数」当分母求日均再乘整月天数,稀疏使用的月份会被放大数倍(实测 4 天记录、其余 19 天没用的月份被外推成实际值的 4 倍)。
|
|
200
210
|
|
|
201
|
-
**自定义单价(设置 Tab,issue #16)**:结构化条目表(模型 + 可选来源 + 输入/缓存命中/输出 + 币种),不再手编 JSON。来源(中转站域名)留空 = 该模型默认价;填入中转站域名(如 `https://api.my-relay.com`)= 仅该来源的同名模型用此价(同名模型可同时存在默认价与多个来源价,互不覆盖)。显示层按「模型 ×
|
|
211
|
+
**自定义单价(设置 Tab,issue #16)**:结构化条目表(模型 + 可选来源 + 输入/缓存命中/输出 + 币种),不再手编 JSON。来源(中转站域名)留空 = 该模型默认价;填入中转站域名(如 `https://api.my-relay.com`)= 仅该来源的同名模型用此价(同名模型可同时存在默认价与多个来源价,互不覆盖)。显示层按「模型 × 来源」精确匹配重算,已归属的用量没有对应来源价时回落该模型默认价。按日期和模型逐格判断:已有站点格(包括空格)时,未归属的剩余用量与无法拆分订阅 token 的混合格保留宿主计价。该格缺少站点信息时优先用模型默认价,否则仅在该模型恰有一个来源价时使用其估算费用。仪表盘会标注按唯一来源价估算的模型,因为实际来源无法验证。下拉可选已配置、已用和目录模型。保存时逐行校验,完整且无重复的行可保存,草稿有误的行沿用上次保存的价格。免费价请显式输入 `0`。
|
|
202
212
|
|
|
203
213
|
**未收录模型的补价入口(issue #125)**:概览顶部的「N 个模型未收录计价」提示条现在**直接列出未收录的模型 id**,并带「去补价」按钮(跳到设置页的自定义单价分区);这些 id 同时进入自定义单价的候选列表(下拉直接选),不必回会话日志手抄——中转站的 id 常带路由前缀与全角冒号,抄错就是「自定义价没效果」。
|
|
204
214
|
|
|
@@ -247,6 +257,8 @@ cost(CNY)= (missInput × p_input + cacheWrite × p_cacheWrite + cacheHit ×
|
|
|
247
257
|
|
|
248
258
|
## 🔌 HTTP API
|
|
249
259
|
|
|
260
|
+
`GET /api/billing/peak-schedule` 返回可选来源/模型、当前规则、最近修订生效时间和读取提示。`POST /api/billing/peak-schedule` 接收 `{ "version": 3, "changes": { … } }`(键为来源/模型 JSON 数组字符串,值为规则或表示清除的 `null`)。响应的 `results` 逐键返回 `accepted`、`invalidRule` 或 `unavailableModel`。请求整体格式错误返回 400,宿主时钟冲突返回 409。端点限本机访问。
|
|
261
|
+
|
|
250
262
|
对外 HTTP 接口与字段定义详见源码:`GET /api/billing/pricing`、`/api/billing/balance`、`/api/billing/usage-stats`、`/api/billing/subscriptions`、`/api/billing/relay-quotas`、`GET/POST /api/billing/task-queue`、`GET /api/billing/task-queue-summary` 等(见 `src/index.ts`、`src/aggregate.ts`、`src/relay.ts`、`src/routes/task-queue.ts`)。其中 `usage-stats` 返回的 `bySite` 字段为按中转站归组后的用量分布,`relay-quotas` 返回额度与路由诊断;`task-queue` 返回能力、工作区、官方模型和持久任务快照,写操作为 `enqueue` / `enqueueMany`、移除未启动任务与清理已结束历史;`task-queue-summary` 只返回峰谷状态与待执行数量,不返回 Prompt。全部端点仅接受回环请求;队列写操作另校验回环 Origin、JSON Content-Type 与 10 MiB body 上限。
|
|
251
263
|
|
|
252
264
|
## ⚙️ 配置
|