@linxin666/dsh-usage 0.3.7 → 0.3.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.i18n.yaml +4 -3
- package/README.md +10 -4
- package/README.zh.md +10 -4
- package/lib/client.js +655 -49
- package/lib/client.js.map +1 -1
- package/lib/index.js +560 -368
- package/lib/types/client/locales.d.ts +5 -0
- package/lib/types/core/adapters.d.ts +10 -1
- package/lib/types/core/ledger.d.ts +15 -2
- package/lib/types/core/pricing.d.ts +30 -0
- package/lib/types/core/types.d.ts +34 -1
- package/lib/types/host/usage-service.d.ts +72 -11
- package/lib/types/index.d.ts +2 -1
- package/package.json +15 -15
- package/src/client/UsageSectionCard.tsx +139 -56
- package/src/client/index.ts +11 -2
- package/src/client/locales.ts +10 -0
- package/src/client/usage.module.css +71 -12
- package/src/core/adapters.ts +84 -3
- package/src/core/ledger.ts +65 -3
- package/src/core/pricing.ts +109 -0
- package/src/core/types.ts +37 -2
- package/src/host/usage-service.ts +300 -131
- package/src/index.ts +30 -17
package/README.i18n.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# Bilingual-pair consistency record (docs/i18n.md): the git blob hash of each
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
|
-
# after editing either side, bring the other along and re-record with
|
|
4
|
-
|
|
5
|
-
README.
|
|
3
|
+
# after editing either side, bring the other along and re-record with:
|
|
4
|
+
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
+
README.md: 1a719cb72c95039ff27f0c54f11beacde523773c
|
|
6
|
+
README.zh.md: ab3c925eb31290df2140d9870c2f9ae4abc5f6a4
|
package/README.md
CHANGED
|
@@ -8,15 +8,21 @@ Usage statistics plugin for the dsh web GUI: per-provider balance and coding-pla
|
|
|
8
8
|
|
|
9
9
|
The plugin runs a host-side service and a first-level settings section (使用统计, directly below the Workshop entry):
|
|
10
10
|
|
|
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,
|
|
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).
|
|
13
|
-
- **Pet linkage**: the pet renders a dedicated announcement bubble (own glass style, tone accent, mini quota meter)
|
|
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
|
+
- **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
|
+
- **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. `bubbleMode` controls it: always (refreshed every poll with a poll-cadence TTL, so the bubble stays visible) / on change / off.
|
|
14
14
|
- 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
15
|
|
|
16
|
-
Supported balance endpoints: DeepSeek, Moonshot (CN/international), OpenRouter, SiliconFlow (CN/international), ZenMux. Supported plan endpoints: Kimi For Coding, GLM Coding Plan (CN via open.bigmodel.cn, international via api.z.ai), OpenCode Go, MiniMax. Providers without a programmatic endpoint (Qwen token plans, OpenCode Zen PAYG, Anthropic, OpenAI) are listed without facts.
|
|
16
|
+
Supported balance endpoints: DeepSeek (the official live route `deepseek-official` and the catalog alias `deepseek` both resolve), Moonshot (CN/international), OpenRouter, SiliconFlow (CN/international), ZenMux. Supported plan endpoints: Kimi For Coding, GLM Coding Plan (CN via open.bigmodel.cn, international via api.z.ai), OpenCode Go, MiniMax, Codex / ChatGPT subscription (OAuth access token from the pi-ai grant; a stale token shows an error until the harness next refreshes it). Providers without a programmatic endpoint (Qwen token plans, OpenCode Zen PAYG, Anthropic, OpenAI) are listed without facts.
|
|
17
|
+
|
|
18
|
+
### Spend estimate scope
|
|
19
|
+
|
|
20
|
+
Today's spend is an estimate priced at fold time from the published DeepSeek V4 peak/off-peak price book (CNY per million tokens; peak = the windows above, off-peak half of peak). 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.
|
|
17
21
|
|
|
18
22
|
## Install
|
|
19
23
|
|
|
24
|
+
Requires DSH 0.1.2-alpha.2 or later: the plugin is developed against the 0.1.2-alpha.2 DSH cohort and its `@deepseek-ai/*` runtime imports are provided by the host itself.
|
|
25
|
+
|
|
20
26
|
In your profile (e.g. `~/.dsh/profiles/web`):
|
|
21
27
|
|
|
22
28
|
```bash
|
package/README.zh.md
CHANGED
|
@@ -8,15 +8,21 @@ dsh Web GUI 的使用统计插件:多 provider 余额与编程套餐用量检
|
|
|
8
8
|
|
|
9
9
|
插件由宿主侧服务与设置页一级分区(使用统计,位于创意工坊下方)组成:
|
|
10
10
|
|
|
11
|
-
- **用量页签**:今日 token 分桶合计(输入 / 输出 / 缓存读 / 缓存写,按 provider 上报口径互不相加),分 provider
|
|
12
|
-
- **个人套餐页签**:每个已配置且暴露套餐端点的 provider 的配额窗口——已用百分比与重置时间(Kimi For Coding 5 小时/每周、GLM 编程计划 5 小时/每周、OpenCode Go 滚动/每周/每月、MiniMax 5
|
|
13
|
-
-
|
|
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
|
+
- **个人套餐页签**:每个已配置且暴露套餐端点的 provider 的配额窗口——已用百分比与重置时间(Kimi For Coding 5 小时/每周、GLM 编程计划 5 小时/每周、OpenCode Go 滚动/每周/每月、MiniMax 5 小时/每周、Codex / ChatGPT 订阅 5 小时/每周)。没有真实套餐/订阅体系的厂商(DeepSeek、ZenMux、Moonshot、OpenRouter、SiliconFlow)不出现在此页签,其余额显示在用量页签。
|
|
13
|
+
- **宠物联动**:宠物渲染一只专用公告气泡(独立玻璃样式、色调描边、微型配额计量条),跟随当前会话提供方。套餐类 provider(Kimi、GLM、Codex 订阅等)展示最紧的百分比窗口;DeepSeek 官方路由展示今日消费估算、当前峰谷时段与账户余额。`bubbleMode` 控制行为:常驻(每次轮询即刷新,TTL 随轮询周期走,气泡保持可见)/ 仅变化时 / 关闭。
|
|
14
14
|
- 探测完全在宿主侧按轮询周期执行(默认 60 秒,可手动刷新);API key 经宿主凭据缝解析(`llm-pi-ai` 记录、`apiKeyEnv` 引用),永不进入浏览器。
|
|
15
15
|
|
|
16
|
-
支持的余额端点:DeepSeek
|
|
16
|
+
支持的余额端点:DeepSeek(官方运行时路由 `deepseek-official` 与目录别名 `deepseek` 均可解析)、Moonshot(国内/国际)、OpenRouter、SiliconFlow(国内/国际)、ZenMux。支持的套餐端点:Kimi For Coding、GLM 编程计划(国内 open.bigmodel.cn、国际 api.z.ai)、OpenCode Go、MiniMax、Codex / ChatGPT 订阅(OAuth access token 取自 pi-ai grant;token 过期时显示错误行,宿主下次跑 Codex 请求自动刷新后恢复)。没有程序化端点的 provider(Qwen token 套餐、OpenCode Zen 按量、Anthropic、OpenAI)仅列出,不展示数据。
|
|
17
|
+
|
|
18
|
+
### 消费估算口径
|
|
19
|
+
|
|
20
|
+
今日消费是折叠时刻按 DeepSeek V4 公布的峰谷价目表(CNY / 百万 tokens;高峰即上表时段,空闲为高峰一半)做出的估算,仅覆盖 DeepSeek 官方路由——其他渠道转发的流量(ZenMux、SiliconFlow 等)不计价;未识别的 DeepSeek 模型 id 按 flash 档估算。价目表调整前记录的桶保留旧价,因此调价从发布时点起生效,不追溯历史数据。
|
|
17
21
|
|
|
18
22
|
## 安装
|
|
19
23
|
|
|
24
|
+
要求 DSH 0.1.2-alpha.2 或更高:插件基于 0.1.2-alpha.2 DSH cohort 开发,其 `@deepseek-ai/*` 运行时导入由宿主本体提供。
|
|
25
|
+
|
|
20
26
|
在 profile(如 `~/.dsh/profiles/web`)中:
|
|
21
27
|
|
|
22
28
|
```bash
|