@linxin666/dsh-usage 0.3.20 → 0.3.22
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.i18n.yaml +2 -2
- package/README.md +6 -1
- package/README.zh.md +6 -1
- package/lib/client.js +347 -34
- package/lib/client.js.map +1 -1
- package/lib/index.js +70 -15
- package/lib/types/client/UsageSectionCard.d.ts +4 -3
- package/lib/types/client/locales.d.ts +12 -0
- package/lib/types/client/voucher-art.generated.d.ts +9 -0
- package/lib/types/client/voucher.d.ts +56 -0
- package/lib/types/core/pricing.d.ts +14 -8
- package/lib/types/core/types.d.ts +28 -6
- package/lib/types/host/usage-service.d.ts +26 -0
- package/package.json +2 -2
- package/src/client/UsageSectionCard.tsx +141 -15
- package/src/client/index.ts +7 -4
- package/src/client/locales.ts +24 -0
- package/src/client/usage.module.css +13 -0
- package/src/client/voucher-art.generated.ts +10 -0
- package/src/client/voucher.ts +144 -0
- package/src/core/pricing.ts +31 -17
- package/src/core/types.ts +30 -6
- package/src/host/usage-service.ts +76 -4
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 2fe59d1c5b7e56aa1ec4a771334f6733d0e513c5
|
|
6
|
+
README.zh.md: d0da2bc20e50639ac0d6133757b3bef7fd6536ec
|
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ The plugin runs a host-side service and a first-level settings section (使用
|
|
|
10
10
|
|
|
11
11
|
- **Usage tab (用量)**: today's token totals per bucket (input / output / cache read / cache write, disjoint as the provider reports them) with per-provider and per-model breakdown, the last 30 days as a horizontal provider/model bar chart, and the balance of every configured provider. For the official DeepSeek family the tab also shows the current peak/off-peak pricing period (Beijing weekdays 09:00-12:00 and 14:00-18:00 are peak, billed at double) and today's estimated spend in CNY. The ledger folds live `session/event` streams (`request/header` route attribution plus `assistant/message` usage) into `$DSH_HOME/dsh-usage/usage-ledger.json` with day-based retention; counting starts when the plugin is first enabled.
|
|
12
12
|
- **Plans tab (个人套餐)**: coding-plan quota windows for every configured provider that exposes one — used percent and reset time per window (Kimi For Coding 5h/week, GLM Coding Plan 5h/week, OpenCode Go rolling/weekly/monthly, MiniMax 5h/week, Codex / ChatGPT subscription 5h/week). Providers without a real plan or subscription (DeepSeek, ZenMux, Moonshot, OpenRouter, SiliconFlow) never appear on this tab; their balance shows on the usage tab instead.
|
|
13
|
+
- **Token Bank tab (Token 银行)**: the whale-yuan voucher (鲸元券) minted from the official DeepSeek family's ledger at an anti-inflation exchange rate of 1,000 tokens per whale yuan. The tab sums the family's retained-ledger tokens (the `deepseek` catalog alias and the live `deepseek-official` route combined), stamps the minted face value onto the banknote artwork with a serial line carrying the minting window, and offers a save-image button plus a native share button when the browser supports sharing files. The spend line shows the real CNY total observed from the official balance once available — balance decreases accrue as spend, top-ups never count — and falls back to the fold-time estimate before the first observation. The minted total prefers the host's whole-ledger aggregate and falls back to the last 30 days on an older host; with no official DeepSeek usage the tab shows its empty state. The on-note text is locale-neutral (digits, latin captions, ISO dates) and the export is rendered locally in the browser.
|
|
13
14
|
- **Pet linkage**: the pet renders a dedicated announcement bubble (own glass style, tone accent, mini quota meter) following the current session provider. Plan providers (Kimi, GLM, Codex subscription, ...) show their tightest percent window; the official DeepSeek family shows today's estimated spend with the current peak/off-peak period and the account balance. When the session provider has no announceable probe fact (a relay station or local runtime without an adapter, failing probes, percent-less windows), the bubble falls back to that provider's live usage today (tokens and call count); with neither fact nor usage it stays silent. `bubbleMode` controls it: always (refreshed every poll with a poll-cadence TTL, so the bubble stays visible) / on change / off.
|
|
14
15
|
- Probes run entirely host-side on a poll cycle (default 60 s, manual refresh button); API keys are resolved through the harness credential seam (`llm-pi-ai` records, `apiKeyEnv` references) and never reach the browser.
|
|
15
16
|
|
|
@@ -17,7 +18,9 @@ Supported balance endpoints: DeepSeek (the official live route `deepseek-officia
|
|
|
17
18
|
|
|
18
19
|
### Spend estimate scope
|
|
19
20
|
|
|
20
|
-
Today's spend is an estimate priced at fold time from the published DeepSeek
|
|
21
|
+
Today's spend is an estimate priced at fold time from the published DeepSeek peak/off-peak price book (CNY per million tokens; peak = the windows above, off-peak half of peak). The rows in force are `deepseek-flash` (DeepSeek-V4.1-Flash) and `deepseek-v4-pro`: the retired flash ids (`deepseek-v4-flash`, `deepseek-v4-flash-vision-exp`) bill the flash row, and `deepseek-v4-pro` moves to that row once DeepSeek routes the id to V4.1-Flash on 2026-09-14 12:00 Beijing.
|
|
22
|
+
|
|
23
|
+
It covers the official DeepSeek routes only — relay traffic billed elsewhere (ZenMux, SiliconFlow, ...) stays unpriced — and unknown DeepSeek model ids take the flash-class row. Buckets recorded before a price change keep the old pricing, so a price-book update is reflected from the moment it ships, not retroactively.
|
|
21
24
|
|
|
22
25
|
## Install
|
|
23
26
|
|
|
@@ -53,4 +56,6 @@ Restart `dsh web` for the host half; the client half applies on refresh. The sec
|
|
|
53
56
|
- Usage counting starts when the plugin is first enabled; historical sessions are not backfilled.
|
|
54
57
|
- OAuth-based routes (for example qwen OAuth grants) are detected as such but not probed; the plugin does not spend third-party OAuth budgets.
|
|
55
58
|
- A failed probe keeps the previous fact visible and reports the error line; providers may rate-limit aggressive polling.
|
|
59
|
+
- The voucher's face value covers the ledger's retention window (`retainDays`): pruned days drop out of both the trend chart and the note.
|
|
60
|
+
- The real-spend watch starts at the first official balance observation: earlier consumption is not backfilled, and only observed balance decreases accrue (a balance rise is a top-up and never counts).
|
|
56
61
|
- The pet bubble requires the dsh-pet plugin; without it the section works unchanged.
|
package/README.zh.md
CHANGED
|
@@ -10,6 +10,7 @@ dsh Web GUI 的使用统计插件:多 provider 余额与编程套餐用量检
|
|
|
10
10
|
|
|
11
11
|
- **用量页签**:今日 token 分桶合计(输入 / 输出 / 缓存读 / 缓存写,按 provider 上报口径互不相加),分 provider 与模型细分,近 30 天以「提供方-模型」水平条形图展示,以及所有已配置 provider 的余额。对 DeepSeek 官方路由,页签还展示当前峰谷计价时段(北京时间工作日 09:00-12:00、14:00-18:00 为高峰,按双倍计费)与今日消费估算(CNY)。台账从 `session/event` 实时流折叠(`request/header` 归因路由 + `assistant/message` 用量),持久化到 `$DSH_HOME/dsh-usage/usage-ledger.json`,按本地日保留;统计自插件首次启用起计。
|
|
12
12
|
- **个人套餐页签**:每个已配置且暴露套餐端点的 provider 的配额窗口——已用百分比与重置时间(Kimi For Coding 5 小时/每周、GLM 编程计划 5 小时/每周、OpenCode Go 滚动/每周/每月、MiniMax 5 小时/每周、Codex / ChatGPT 订阅 5 小时/每周)。没有真实套餐/订阅体系的厂商(DeepSeek、ZenMux、Moonshot、OpenRouter、SiliconFlow)不出现在此页签,其余额显示在用量页签。
|
|
13
|
+
- **Token 银行页签**:以 DeepSeek 官方家族的台账用量铸造「鲸元券」,汇率按 1000 tokens 兑 1 鲸元(防膨胀)。页签把该家族保留台账内的 token 总量(`deepseek` 目录别名与运行时路由 `deepseek-official` 合并计算)折算成票面面额印在钞票图上,附带走票窗口的序列号行,并提供保存图片按钮与(浏览器支持文件分享时的)系统分享按钮。消费行优先展示从官方余额观测到的真实累计花费——余额下降即计为消费,充值上涨不计——首次观测到下降之前回落为折叠时刻估算。铸造总量优先取宿主的全台账聚合,旧宿主回落为近 30 天;无官方用量时展示空状态。票面文字与语言无关(数字、拉丁小字、ISO 日期),导出图在浏览器本地渲染。
|
|
13
14
|
- **宠物联动**:宠物渲染一只专用公告气泡(独立玻璃样式、色调描边、微型配额计量条),跟随当前会话提供方。套餐类 provider(Kimi、GLM、Codex 订阅等)展示最紧的百分比窗口;DeepSeek 官方路由展示今日消费估算、当前峰谷时段与账户余额。会话提供方没有可公告的探测事实时(无适配器的中转站或本地运行时、探测失败、无百分比窗口),气泡回落为该提供方今日的实时用量(tokens 与调用次数);事实与用量皆无时保持沉默。`bubbleMode` 控制行为:常驻(每次轮询即刷新,TTL 随轮询周期走,气泡保持可见)/ 仅变化时 / 关闭。
|
|
14
15
|
- 探测完全在宿主侧按轮询周期执行(默认 60 秒,可手动刷新);API key 经宿主凭据缝解析(`llm-pi-ai` 记录、`apiKeyEnv` 引用),永不进入浏览器。
|
|
15
16
|
|
|
@@ -17,7 +18,9 @@ dsh Web GUI 的使用统计插件:多 provider 余额与编程套餐用量检
|
|
|
17
18
|
|
|
18
19
|
### 消费估算口径
|
|
19
20
|
|
|
20
|
-
今日消费是折叠时刻按 DeepSeek
|
|
21
|
+
今日消费是折叠时刻按 DeepSeek 公布的峰谷价目表(CNY / 百万 tokens;高峰即上表时段,空闲为高峰一半)做出的估算。当前生效的是 `deepseek-flash`(DeepSeek-V4.1-Flash)与 `deepseek-v4-pro` 两档:已下线的 flash 系列 id(`deepseek-v4-flash`、`deepseek-v4-flash-vision-exp`)按 flash 档计价,`deepseek-v4-pro` 在北京时间 2026-09-14 12:00 被 DeepSeek 路由到 V4.1-Flash 后同样按该档计价。
|
|
22
|
+
|
|
23
|
+
估算仅覆盖 DeepSeek 官方路由——其他渠道转发的流量(ZenMux、SiliconFlow 等)不计价;未识别的 DeepSeek 模型 id 按 flash 档估算。价目表调整前记录的桶保留旧价,因此调价从发布时点起生效,不追溯历史数据。
|
|
21
24
|
|
|
22
25
|
## 安装
|
|
23
26
|
|
|
@@ -53,4 +56,6 @@ pnpm add @linxin666/dsh-usage
|
|
|
53
56
|
- 用量统计自插件首次启用起计,不回填历史会话。
|
|
54
57
|
- OAuth 类路由(如 qwen OAuth 授权)仅识别类型,不做探测;插件不消耗第三方 OAuth 额度。
|
|
55
58
|
- 探测失败时保留上一次数据并展示错误行;过于频繁的轮询可能触发 provider 限流。
|
|
59
|
+
- 鲸元券面额只覆盖台账保留窗口(`retainDays`)内的用量:被清理的天同时退出趋势图与票面。
|
|
60
|
+
- 真实花费观测从第一次官方余额观测开始:更早的消费不回补,且只有观测到的余额下降才累计(余额上涨是充值,永不计费)。
|
|
56
61
|
- 宠物气泡需要 dsh-pet 插件;未安装时分区功能不受影响。
|