@linxin666/dsh-usage 0.3.22 → 0.3.24
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 -8
- package/README.zh.md +6 -8
- package/lib/client.js +749 -78
- package/lib/client.js.map +1 -1
- package/lib/index.js +171 -201
- package/lib/types/client/UsageSectionCard.d.ts +0 -1
- package/lib/types/client/UsageSidebarPanel.d.ts +34 -0
- package/lib/types/client/body-mutations.d.ts +45 -0
- package/lib/types/client/locales.d.ts +9 -4
- package/lib/types/client/sidebar-entry-core.d.ts +87 -0
- package/lib/types/client/sidebar-entry.d.ts +35 -0
- package/lib/types/client/sidebar-panel-mount.d.ts +40 -0
- package/lib/types/client/voucher.d.ts +2 -2
- package/lib/types/core/provider-routes.d.ts +26 -0
- package/lib/types/core/types.d.ts +14 -1
- package/lib/types/host/access.d.ts +17 -0
- package/lib/types/host/pair-access.d.ts +34 -0
- package/lib/types/host/routes.d.ts +16 -7
- package/lib/types/host/usage-service.d.ts +28 -73
- package/lib/types/index.d.ts +0 -2
- package/package.json +4 -3
- package/src/client/UsageSectionCard.tsx +1 -15
- package/src/client/UsageSidebarPanel.tsx +196 -0
- package/src/client/body-mutations.ts +133 -0
- package/src/client/index.ts +22 -1
- package/src/client/locales.ts +20 -10
- package/src/client/sidebar-entry-core.ts +321 -0
- package/src/client/sidebar-entry.ts +101 -0
- package/src/client/sidebar-panel-mount.tsx +113 -0
- package/src/client/usage.module.css +252 -0
- package/src/client/voucher.ts +2 -2
- package/src/core/adapters.ts +40 -6
- package/src/core/provider-routes.ts +37 -0
- package/src/core/types.ts +14 -1
- package/src/host/access.ts +21 -0
- package/src/host/pair-access.ts +49 -0
- package/src/host/routes.ts +19 -10
- package/src/host/usage-service.ts +65 -214
- package/src/index.ts +1 -6
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: 1ec6e9c8d8f8f95a45777162471f3e1ee9a2768a
|
|
6
|
+
README.zh.md: 6623cf55cbb4f3a72d90352af8ba52581057ee85
|
package/README.md
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
English | [中文](README.zh.md)
|
|
4
4
|
|
|
5
|
-
Usage statistics plugin for the dsh web GUI: per-provider balance and coding-plan quota detection plus a live token usage ledger, with
|
|
5
|
+
Usage statistics plugin for the dsh web GUI: per-provider balance and coding-plan quota detection plus a live token usage ledger, with the current session provider's today usage on the sidebar entry.
|
|
6
6
|
|
|
7
7
|
## What it does
|
|
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, 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
|
-
- **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.
|
|
14
|
-
- **
|
|
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 (one row per adapter family: a dormant catalog alias shadowed by the family's live route no longer renders its own balance row). 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/month, 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,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.
|
|
14
|
+
- **Sidebar panel**: a usage entry in the sidebar (directly below the family plugin entries) expands into a collapsible panel showing the same overview document — plan providers with their quota windows and tightest percent, balance-only providers with their remaining amount. The entry row carries the panel's controls (a refresh button with a short cooldown and a collapse chevron). Collapsed, a one-line strip under the row shows the current session provider's today usage (tokens, calls, and the priced cost when the family is priced); with no session provider or no usage today the strip stays silent. The collapsed state is remembered in `localStorage` (`dsh-usage.sidebar.collapsed`). Polling runs at 10 s while expanded and 30 s while collapsed, and pauses whenever the page is hidden. The panel reads `/api/dsh-usage/overview` through the same family trust fence as the settings section: loopback always passes, and a browser on a paired LAN device passes when `dsh-remote-web-ui` is loaded — an unpaired LAN request still gets 403.
|
|
15
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.
|
|
16
16
|
|
|
17
|
-
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
|
+
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 — the `zai` route the pi-ai catalog registers, plus the `zai-coding` / `zai-coding-cn` aliases; 5-hour, weekly and monthly windows, token-metered and credit-metered plans), 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.
|
|
18
18
|
|
|
19
19
|
### Spend estimate scope
|
|
20
20
|
|
|
@@ -48,7 +48,6 @@ Restart `dsh web` for the host half; the client half applies on refresh. The sec
|
|
|
48
48
|
| --- | --- | --- |
|
|
49
49
|
| `enabled` | `true` | Master switch; off = no listeners, no probes, no routes |
|
|
50
50
|
| `pollIntervalSec` | `60` | Provider probe cycle (30-3600 s, hot-swappable) |
|
|
51
|
-
| `bubbleMode` | `always` | Pet announcement bubble: `always` (fresh every poll) / `change` (only when the value changes) / `off` |
|
|
52
51
|
| `retainDays` | `180` | Ledger retention in local days (7-730) |
|
|
53
52
|
|
|
54
53
|
## Known limitations
|
|
@@ -58,4 +57,3 @@ Restart `dsh web` for the host half; the client half applies on refresh. The sec
|
|
|
58
57
|
- A failed probe keeps the previous fact visible and reports the error line; providers may rate-limit aggressive polling.
|
|
59
58
|
- 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
59
|
- 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).
|
|
61
|
-
- The pet bubble requires the dsh-pet plugin; without it the section works unchanged.
|
package/README.zh.md
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.md) | 中文
|
|
4
4
|
|
|
5
|
-
dsh Web GUI 的使用统计插件:多 provider 余额与编程套餐用量检测,外加实时 token
|
|
5
|
+
dsh Web GUI 的使用统计插件:多 provider 余额与编程套餐用量检测,外加实时 token 用量台账,并在侧栏入口展示当前会话提供方的今日用量。
|
|
6
6
|
|
|
7
7
|
## 功能
|
|
8
8
|
|
|
9
9
|
插件由宿主侧服务与设置页一级分区(使用统计,位于创意工坊下方)组成:
|
|
10
10
|
|
|
11
|
-
- **用量页签**:今日 token 分桶合计(输入 / 输出 / 缓存读 / 缓存写,按 provider 上报口径互不相加),分 provider 与模型细分,近 30 天以「提供方-模型」水平条形图展示,以及所有已配置 provider
|
|
12
|
-
- **个人套餐页签**:每个已配置且暴露套餐端点的 provider 的配额窗口——已用百分比与重置时间(Kimi For Coding 5 小时/每周、GLM 编程计划 5
|
|
13
|
-
- **Token 银行页签**:以 DeepSeek 官方家族的台账用量铸造「鲸元券」,汇率按
|
|
14
|
-
-
|
|
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
|
+
- **Token 银行页签**:以 DeepSeek 官方家族的台账用量铸造「鲸元券」,汇率按 100 万 tokens 兑 1 鲸元(防膨胀)。页签把该家族保留台账内的 token 总量(`deepseek` 目录别名与运行时路由 `deepseek-official` 合并计算)折算成票面面额印在钞票图上,附带走票窗口的序列号行,并提供保存图片按钮与(浏览器支持文件分享时的)系统分享按钮。消费行优先展示从官方余额观测到的真实累计花费——余额下降即计为消费,充值上涨不计——首次观测到下降之前回落为折叠时刻估算。铸造总量优先取宿主的全台账聚合,旧宿主回落为近 30 天;无官方用量时展示空状态。票面文字与语言无关(数字、拉丁小字、ISO 日期),导出图在浏览器本地渲染。
|
|
14
|
+
- **侧栏面板**:侧栏在家族插件入口下方提供「用量」入口,展开为可折叠面板,读取与设置分区相同的 overview 文档——套餐类 provider 展示配额窗口与最紧百分比,仅余额类 provider 展示剩余额度。入口行本身承载面板控件(带短冷却的刷新按钮与折叠箭头)。折叠态下,入口行下方的一行摘要条展示当前会话提供方的今日用量(tokens、调用次数,计价家族附带费用);无会话提供方或今日无用量时摘要条保持沉默。折叠状态记在 `localStorage`(`dsh-usage.sidebar.collapsed`)。轮询节奏为展开 10 秒、折叠 30 秒,页面隐藏时一律暂停。面板经与设置分区相同的家族信任围栏读取 `/api/dsh-usage/overview`:回环地址始终放行,已配对的局域网设备在装有 `dsh-remote-web-ui` 时放行,未配对的局域网请求仍返回 403。
|
|
15
15
|
- 探测完全在宿主侧按轮询周期执行(默认 60 秒,可手动刷新);API key 经宿主凭据缝解析(`llm-pi-ai` 记录、`apiKeyEnv` 引用),永不进入浏览器。
|
|
16
16
|
|
|
17
|
-
支持的余额端点:DeepSeek(官方运行时路由 `deepseek-official` 与目录别名 `deepseek` 均可解析)、Moonshot(国内/国际)、OpenRouter、SiliconFlow(国内/国际)、ZenMux。支持的套餐端点:Kimi For Coding、GLM 编程计划(国内 open.bigmodel.cn、国际 api.z.ai
|
|
17
|
+
支持的余额端点:DeepSeek(官方运行时路由 `deepseek-official` 与目录别名 `deepseek` 均可解析)、Moonshot(国内/国际)、OpenRouter、SiliconFlow(国内/国际)、ZenMux。支持的套餐端点:Kimi For Coding、GLM 编程计划(国内 open.bigmodel.cn、国际 api.z.ai——即 pi-ai 目录注册的 `zai` 路由,另兼容 `zai-coding` / `zai-coding-cn` 别名;覆盖 5 小时 / 每周 / 每月窗口与 token 制、积分制套餐)、OpenCode Go、MiniMax、Codex / ChatGPT 订阅(OAuth access token 取自 pi-ai grant;token 过期时显示错误行,宿主下次跑 Codex 请求自动刷新后恢复)。没有程序化端点的 provider(Qwen token 套餐、OpenCode Zen 按量、Anthropic、OpenAI)仅列出,不展示数据。
|
|
18
18
|
|
|
19
19
|
### 消费估算口径
|
|
20
20
|
|
|
@@ -48,7 +48,6 @@ pnpm add @linxin666/dsh-usage
|
|
|
48
48
|
| --- | --- | --- |
|
|
49
49
|
| `enabled` | `true` | 总开关;关闭后不监听、不探测、不注册路由 |
|
|
50
50
|
| `pollIntervalSec` | `60` | provider 探测周期(30-3600 秒,热切换) |
|
|
51
|
-
| `bubbleMode` | `always` | 宠物公告气泡:`always`(每次轮询即刷新)/ `change`(仅数值变化时)/ `off` |
|
|
52
51
|
| `retainDays` | `180` | 台账按本地日保留天数(7-730) |
|
|
53
52
|
|
|
54
53
|
## 已知限制
|
|
@@ -58,4 +57,3 @@ pnpm add @linxin666/dsh-usage
|
|
|
58
57
|
- 探测失败时保留上一次数据并展示错误行;过于频繁的轮询可能触发 provider 限流。
|
|
59
58
|
- 鲸元券面额只覆盖台账保留窗口(`retainDays`)内的用量:被清理的天同时退出趋势图与票面。
|
|
60
59
|
- 真实花费观测从第一次官方余额观测开始:更早的消费不回补,且只有观测到的余额下降才累计(余额上涨是充值,永不计费)。
|
|
61
|
-
- 宠物气泡需要 dsh-pet 插件;未安装时分区功能不受影响。
|