dsh-token-gauge 1.1.0 → 1.1.1

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 liumiaozhi
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 liumiaozhi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md CHANGED
@@ -1,95 +1,102 @@
1
- # dsh-token-gauge · Token Gauge Dashboard
2
-
3
- <p align="center">
4
- <img src="screenshots/single-classical.png" alt="Single gauge · Vintage skin" width="48%">
5
- <img src="screenshots/dual-starfield.png" alt="Dual gauge · Starfield skin" width="48%">
6
- </p>
7
-
8
- <p align="center">
9
- <img src="screenshots/styles.png" alt="Vintage / Macaron / Minimal / Starfield skins" width="78%">
10
- </p>
11
-
12
- <p align="center">
13
- <a href="https://github.com/liumiaozhi/dsh-token-gauge/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/liumiaozhi/dsh-token-gauge?style=flat-square"></a>
14
- <a href="LICENSE"><img alt="License MIT" src="https://img.shields.io/github/license/liumiaozhi/dsh-token-gauge?style=flat-square"></a>
15
- <img alt="DeepSeek Harness" src="https://img.shields.io/badge/DeepSeek%20Harness-Web%20Plugin-4f46e5?style=flat-square">
16
- </p>
17
-
18
- A sidebar Token gauge for **DeepSeek Harness (DSH)**. Four skins — Vintage, Macaron, Minimal and Starfield — turn token speed, session/today usage and spend, and cache hit rate into a quick car-dashboard read.
19
-
20
- > Preview images use sample data. Real values are aggregated from local DSH session logs; nothing is fabricated.
21
-
22
- ## Features
23
-
24
- - **Two structures**
25
- - **Single**: token-speed gauge on the left, current-session / today tokens and spend on the right, cache-hit progress bar at the bottom.
26
- - **Dual**: token-speed gauge and cache-hit gauge side by side on top; current-session and today tokens / spend below.
27
- - **Four skins**: Vintage (warm amber), Macaron, Minimal, Starfield. Structure and skin combine freely — eight presentations.
28
- - **Live speed**: reads streaming output deltas from the current session and moves the needle smoothly across 0–500 tokens/s.
29
- - **Cache gauge**: 70–100% range with 70 / 75 / 100 ticks; below 70% the needle parks at 70% while the readout keeps the real value.
30
- - **Token formatting**: always in **k (thousand tokens)**, two decimals and thousands separators, e.g. `15,098.77k`.
31
- - **Settings**: the slider icon at the card's top-right opens structure/skin choices; selections persist in `localStorage`.
32
- - **Theme-aware** and dependency-free: no billing plugin, no chart library, no external CDN. The Host half aggregates DSH session logs itself.
33
-
34
- ## Install
35
-
36
- The plugin ships its own Host half: it reads DSH's `sessionPersistence` logs and aggregates usage locally. **No billing plugin is required.**
37
-
38
- ```bash
39
- dsh plugin --profile web add dsh-token-gauge
40
- ```
41
-
42
- From source (current repository version):
43
-
44
- ```bash
45
- git clone https://github.com/liumiaozhi/dsh-token-gauge.git
46
- dsh plugin --profile web add "link:<absolute-path-to-repo>"
47
- ```
48
-
49
- > If npm still serves an older `dsh-token-gauge`, install from source until 1.1.0 is published.
50
-
51
- Restart or hard-refresh DSH Web. The card replaces the original billing trigger at the same sidebar-footer slot without needing that plugin.
52
-
53
- ## Usage
54
-
55
- 1. Click the slider icon at the **top-right** of the card.
56
- 2. Choose **Single / Dual** under Layout.
57
- 3. Pick one of **Vintage / Macaron / Minimal / Starfield**.
58
- 4. Start a conversation; speed follows streaming output and usage refreshes every 1.5s.
59
-
60
- <p align="center">
61
- <img src="screenshots/settings.png" alt="Settings: layout and four skins" width="62%">
62
- </p>
63
-
64
- ## Data
65
-
66
- | Metric | Source |
67
- | --- | --- |
68
- | Token speed | Streaming text / reasoning / tool-call deltas of the current session, estimated over a 0–500 tokens/s scale |
69
- | Current-session tokens | `input + output` over all turns of the current session |
70
- | Today tokens | Today's `input + output` from the plugin's own `byDay` aggregate |
71
- | Current-session spend | Estimated from successful model calls in the current session |
72
- | Today spend | Estimated from DeepSeek Flash / Pro list prices with peak/off-peak bands |
73
- | Cache hit rate | Today's `cacheHit / (cacheHit + cacheMiss)`, gauge range 70–100% |
74
-
75
- The Host half reads `assistant/message.usage` from DSH `sessionPersistence`, adds 0.02 CNY per web-search call, and prices DeepSeek Flash (2 / 0.04 / 8 CNY per million tokens) and Pro (9 / 0.3 / 27). Peak hours are weekdays 09–12 and 14–18; weekends and off-peak are half price. Unknown models fall back to Flash rates. Amounts are estimates, not an official invoice.
76
-
77
- ## Development
78
-
79
- ```bash
80
- git clone https://github.com/liumiaozhi/dsh-token-gauge.git
81
- cd dsh-token-gauge
82
- dsh plugin --profile web add "link:$PWD"
83
- ```
84
-
85
- `client.js` is a hand-written Client bundle; no build step. DSH Client HMR reloads it after edits; refresh the page if HMR is unavailable.
86
-
87
- ## Compatibility
88
-
89
- - DSH Web (`platform: web`), requiring `@deepseek-ai/dsh-client-ui-sidebar` and `@deepseek-ai/dsh-client-ui-session`.
90
- - Host half uses DSH's built-in `sessionPersistence` and `webServer`; no billing plugin.
91
- - Preview images are generated from the actual component styles with sample data.
92
-
93
- ## License
94
-
95
- [MIT](LICENSE) © 2026 liumiaozhi
1
+ # dsh-token-gauge · Token Gauge Dashboard
2
+
3
+ <p align="center">
4
+ <img src="screenshots/single-classical.png" alt="Single gauge · Vintage skin" width="48%">
5
+ <img src="screenshots/dual-starfield.png" alt="Dual gauge · Starfield skin" width="48%">
6
+ </p>
7
+
8
+ <p align="center">
9
+ <img src="screenshots/styles.png" alt="Vintage / Macaron / Minimal / Starfield skins" width="78%">
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://github.com/liumiaozhi/dsh-token-gauge/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/liumiaozhi/dsh-token-gauge?style=flat-square"></a>
14
+ <a href="LICENSE"><img alt="License MIT" src="https://img.shields.io/github/license/liumiaozhi/dsh-token-gauge?style=flat-square"></a>
15
+ <img alt="DeepSeek Harness" src="https://img.shields.io/badge/DeepSeek%20Harness-Web%20Plugin-4f46e5?style=flat-square">
16
+ </p>
17
+
18
+ A sidebar Token gauge for **DeepSeek Harness (DSH)**. Four skins — Vintage, Macaron, Minimal and Starfield — turn token speed, session/today usage and spend, and cache hit rate into a quick car-dashboard read.
19
+
20
+ > Preview images use sample data. Real values come from local DSH sessions through the billing plugin; nothing is fabricated.
21
+
22
+ ## Features
23
+
24
+ - **Two structures**
25
+ - **Single**: token-speed gauge on the left, current-session / today tokens and spend on the right, cache-hit progress bar at the bottom.
26
+ - **Dual**: token-speed gauge and cache-hit gauge side by side on top; current-session and today tokens / spend below.
27
+ - **Four skins**: Vintage (warm amber), Macaron, Minimal, Starfield. Structure and skin combine freely — eight presentations.
28
+ - **Live speed**: reads streaming output deltas from the current session and moves the needle smoothly across 0–500 tokens/s.
29
+ - **Cache gauge**: 70–100% range with 70 / 75 / 100 ticks; below 70% the needle parks at 70% while the readout keeps the real value.
30
+ - **Token formatting**: always in **k (thousand tokens)**, two decimals and thousands separators, e.g. `15,098.77k`.
31
+ - **Settings**: the slider icon at the card's top-right opens structure/skin choices; selections persist in `localStorage`.
32
+ - **Theme-aware** and dependency-free: no billing plugin, no chart library, no external CDN. The Host half aggregates DSH session logs itself.
33
+
34
+ ## Install
35
+
36
+ The plugin ships its own Host half: it reads DSH's `sessionPersistence` logs and aggregates usage locally. **No billing plugin is required.**
37
+
38
+ ```bash
39
+ dsh plugin --profile web add dsh-token-gauge
40
+ ```
41
+
42
+ From source (current repository version):
43
+
44
+ ```bash
45
+ git clone https://github.com/liumiaozhi/dsh-token-gauge.git
46
+ dsh plugin --profile web add "link:<absolute-path-to-repo>"
47
+ ```
48
+
49
+ > If npm still serves an older `dsh-token-gauge`, install from source until 1.1.0 is published.
50
+
51
+ Restart or hard-refresh DSH Web. The card replaces the original billing trigger at the same sidebar-footer slot without needing that plugin.
52
+
53
+ ## Usage
54
+
55
+ 1. Click the slider icon at the **top-right** of the card.
56
+ 2. Choose **Single / Dual** under Layout.
57
+ 3. Pick one of **Vintage / Macaron / Minimal / Starfield**.
58
+ 4. Start a conversation; speed follows streaming output and usage refreshes every 1.5s.
59
+
60
+ <p align="center">
61
+ <img src="screenshots/settings.png" alt="Settings: layout and four skins" width="62%">
62
+ </p>
63
+
64
+ ## Data
65
+
66
+ | Metric | Source |
67
+ | --- | --- |
68
+ | Token speed | Streaming text / reasoning / tool-call deltas of the current session, estimated over a 0–500 tokens/s scale |
69
+ | Current-session tokens | `input + output` over all turns of the current session |
70
+ | Today tokens | Today's `input + output` from the plugin's own `byDay` aggregate |
71
+ | Current-session spend | Estimated from successful model calls in the current session |
72
+ | Today spend | Estimated from DeepSeek Flash / Pro list prices with peak/off-peak bands |
73
+ | Cache hit rate | Today's `cacheHit / (cacheHit + cacheMiss)`, gauge range 70–100% |
74
+
75
+ The Host half reads `assistant/message.usage` from DSH `sessionPersistence`, adds 0.02 CNY per web-search call, and prices DeepSeek Flash (2 / 0.04 / 8 CNY per million tokens) and Pro (9 / 0.3 / 27). Peak hours are weekdays 09–12 and 14–18; weekends and off-peak are half price. Unknown models fall back to Flash rates. Amounts are estimates, not an official invoice.
76
+
77
+ ## Development
78
+
79
+ ```bash
80
+ git clone https://github.com/liumiaozhi/dsh-token-gauge.git
81
+ cd dsh-token-gauge
82
+ dsh plugin --profile web add "link:$PWD"
83
+ ```
84
+
85
+ `client.js` is a hand-written Client bundle; no build step. DSH Client HMR reloads it after edits; refresh the page if HMR is unavailable.
86
+
87
+ ## Compatibility
88
+
89
+ - DSH Web (`platform: web`), requiring `@deepseek-ai/dsh-client-ui-sidebar` and `@deepseek-ai/dsh-client-ui-session`.
90
+ - Host half uses DSH's built-in `sessionPersistence` and `webServer`; no billing plugin.
91
+ - Preview images are generated from the actual component styles with sample data.
92
+
93
+ ## Changelog
94
+
95
+ ### 1.1.1
96
+
97
+ - Fix a startup failure on DSH 0.2.x: the Client bundle now registers under its package name `dsh-token-gauge` instead of `dsh-cost-dashboard`. The loader matches module factories by package name, so the old id left the row unregistered, the bundle was re-requested and executed twice, and the second registration threw `duplicate factory registration` — surfacing as `web boot: 1 entry did not activate` / `dsh-token-gauge: import failed`.
98
+ - Declare `engines.dsh` and `dsh.compatibility` for DSH `>=0.2.0-rc.1 <0.3.0-0`, so an incompatible runtime is rejected at install time with a clear message instead of surfacing as a boot failure.
99
+
100
+ ## License
101
+
102
+ [MIT](LICENSE) © 2026 liumiaozhi
package/README.md CHANGED
@@ -1,115 +1,122 @@
1
- # dsh-token-gauge · 费用仪表盘
2
-
3
- <p align="center">
4
- <img src="screenshots/single-classical.png" alt="单表 · 古典风格" width="48%">
5
- <img src="screenshots/dual-starfield.png" alt="双表 · 星空风格" width="48%">
6
- </p>
7
-
8
- <p align="center">
9
- <img src="screenshots/styles.png" alt="古典 / 马卡龙 / 极简 / 星空四种皮肤" width="78%">
10
- </p>
11
-
12
- <p align="center">
13
- <a href="https://github.com/liumiaozhi/dsh-token-gauge/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/liumiaozhi/dsh-token-gauge?style=flat-square"></a>
14
- <a href="LICENSE"><img alt="License MIT" src="https://img.shields.io/github/license/liumiaozhi/dsh-token-gauge?style=flat-square"></a>
15
- <img alt="DeepSeek Harness" src="https://img.shields.io/badge/DeepSeek%20Harness-Web%20Plugin-4f46e5?style=flat-square">
16
- <img alt="Token Gauge" src="https://img.shields.io/badge/UI-Token%20Gauge-0ea5e9?style=flat-square">
17
- </p>
18
-
19
- 一个给 **DeepSeek Harness(DSH)** 用的侧边栏 Token 费用仪表盘。用老式车机 / 马卡龙 / 极简 / 星空四种皮肤,把 Token 输出速度、当前会话与今日消耗、缓存命中率做成一眼能读懂的仪表。
20
-
21
- > 界面预览使用示例数据;实际数据来自 DSH 本地会话日志聚合,不伪造样本。
22
-
23
- ## 特性
24
-
25
- - **两种结构**
26
- - **单表**:左侧 Token 速度仪表盘,右侧当前会话 / 今日 Token 与金额,底部缓存命中率进度条。
27
- - **双表**:上方左侧 Token 速度、右侧缓存命中率两个仪表盘;下方并列展示当前会话与今日的 Token 量、金额。
28
- - **四种皮肤**:古典(老式车机琥珀色)、马卡龙、极简、星空。结构 × 皮肤可自由组合,共 8 种呈现。
29
- - **实时 Token 速度**:读取当前会话的流式输出增量,指针在 0–500 token/秒之间平滑摆动。
30
- - **缓存命中率表盘**:量程 70–100%,刻度 70 / 85 / 100;低于 70% 时指针停在 70%,中央数字仍显示真实值。
31
- - **Token 口径**:统一以 **k(千 token)** 显示,保留两位小数并带千分位,例如 `15,098.77k`。
32
- - **设置入口**:卡片右上角滑杆图标;选择结构与皮肤后立即生效,并写入 `localStorage`,刷新后保留。
33
- - **主题自适应**:颜色来自 DSH 主题令牌,深浅色模式均可读;不引入图表库、不请求外部 CDN。
34
-
35
- ## 安装
36
-
37
- 本插件自带 Host 半边,直接从 DSH 的 `sessionPersistence` 读取本地会话日志并聚合用量,**不依赖任何计费插件**。
38
-
39
- ```bash
40
- dsh plugin --profile web add dsh-token-gauge
41
- ```
42
-
43
- 从源码安装(本仓库当前版本):
44
-
45
- ```bash
46
- git clone https://github.com/liumiaozhi/dsh-token-gauge.git
47
- dsh plugin --profile web add "link:<本仓库绝对路径>"
48
- ```
49
-
50
- > npm 上的 `dsh-token-gauge` 若仍为旧版,请先用源码安装;发布 1.1.0 后可直接按名称安装。
51
-
52
- 安装后重启或硬刷新 DSH Web,侧边栏底部会出现「费用仪表盘」。插件以 slot 优先级覆盖原计费卡片,但不需要计费插件本身。
53
-
54
- ## 使用
55
-
56
- 1. 点击卡片**右上角**的滑杆图标打开设置。
57
- 2. 在「结构」中选择 **单表 / 双表**。
58
- 3. 在下方四种皮肤中选择 **古典 / 马卡龙 / 极简 / 星空**。
59
- 4. 开始对话,Token 速度表会随流式输出更新;会话与今日数据每 1.5 秒刷新。
60
-
61
- <p align="center">
62
- <img src="screenshots/settings.png" alt="设置面板:结构 + 四种皮肤" width="62%">
63
- </p>
64
-
65
- ## 数据与口径
66
-
67
- | 指标 | 来源 / 口径 |
68
- | --- | --- |
69
- | Token 速度 | 当前会话 `assistant/live-chunk` 文本 / reasoning / tool-call 增量估算,0–500 token/秒 |
70
- | 当前会话 Token | 当前会话所有轮次的 `input + output` |
71
- | 今日 Token | 本插件 `byDay` 中今天的 `input + output` |
72
- | 当前会话金额 | 当前会话所有成功模型调用按单价估算 |
73
- | 今日金额 | 本插件按 DeepSeek Flash / Pro 列表价与峰谷时段估算的今日费用 |
74
- | 缓存命中率 | 今日 `cacheHit / (cacheHit + cacheMiss)`,仪表盘量程 70–100% |
75
-
76
- Host 半边读取 DSH 的 `sessionPersistence` 会话日志,按 `assistant/message.usage` 聚合;搜索调用按 0.02 元/次估算。DeepSeek Flash(2 / 0.04 / 8 元每百万 token)与 Pro(9 / 0.3 / 27)使用官方列表价,工作日高峰外与周末按半价;其他模型回退到 Flash 价格估算。金额是参考值,不是官方账单。
77
-
78
- ## 目录结构
79
-
80
- ```text
81
- dsh-token-gauge/
82
- ├── package.json # DSH bundle + Client 声明
83
- ├── cordis.patch.yml # 插入 token-gauge 行
84
- ├── index.js # Host 半边:注册 /api/token-gauge/usage-stats
85
- ├── usage-server.js # 会话日志聚合 + DeepSeek 峰谷计价
86
- ├── client.js # Client 半边:仪表盘 / 设置 / 样式
87
- ├── locale/
88
- │ ├── zh.json # 插件市场中文标题与描述
89
- │ └── en.json
90
- ├── icon.svg # 插件图标
91
- ├── screenshots/ # README 预览图
92
- └── README.md / README.en.md / LICENSE
93
- ```
94
-
95
- ## 开发
96
-
97
- ```bash
98
- git clone https://github.com/liumiaozhi/dsh-token-gauge.git
99
- cd dsh-token-gauge
100
- # 本插件是手写 Client bundle,无构建步骤
101
- dsh plugin --profile web add "link:$PWD"
102
- ```
103
-
104
- 修改 `client.js` 后,DSH 的 Client HMR 会在文件变化后重新加载模块;没有热更新时刷新页面即可。
105
-
106
- ## 兼容与限制
107
-
108
- - 面向 DSH Web(`platform: web`),需要 `@deepseek-ai/dsh-client-ui-sidebar` 与 `@deepseek-ai/dsh-client-ui-session`。
109
- - Host 半边依赖 DSH 自带的 `sessionPersistence` 与 `webServer` 服务;不需要计费插件。
110
- - 缓存命中率低于 70% 时指针停在 70% 刻度,中央数字保留真实值,避免表盘外推。
111
- - README 图片为按实际组件样式生成的示例预览,数据为演示值。
112
-
113
- ## 许可
114
-
115
- [MIT](LICENSE) © 2026 liumiaozhi
1
+ # dsh-token-gauge · 费用仪表盘
2
+
3
+ <p align="center">
4
+ <img src="screenshots/single-classical.png" alt="单表 · 古典风格" width="48%">
5
+ <img src="screenshots/dual-starfield.png" alt="双表 · 星空风格" width="48%">
6
+ </p>
7
+
8
+ <p align="center">
9
+ <img src="screenshots/styles.png" alt="古典 / 马卡龙 / 极简 / 星空四种皮肤" width="78%">
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://github.com/liumiaozhi/dsh-token-gauge/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/liumiaozhi/dsh-token-gauge?style=flat-square"></a>
14
+ <a href="LICENSE"><img alt="License MIT" src="https://img.shields.io/github/license/liumiaozhi/dsh-token-gauge?style=flat-square"></a>
15
+ <img alt="DeepSeek Harness" src="https://img.shields.io/badge/DeepSeek%20Harness-Web%20Plugin-4f46e5?style=flat-square">
16
+ <img alt="Token Gauge" src="https://img.shields.io/badge/UI-Token%20Gauge-0ea5e9?style=flat-square">
17
+ </p>
18
+
19
+ 一个给 **DeepSeek Harness(DSH)** 用的侧边栏 Token 费用仪表盘。用老式车机 / 马卡龙 / 极简 / 星空四种皮肤,把 Token 输出速度、当前会话与今日消耗、缓存命中率做成一眼能读懂的仪表。
20
+
21
+ > 界面预览使用示例数据;实际数据来自 DSH 本地会话与计费插件聚合,不伪造样本。
22
+
23
+ ## 特性
24
+
25
+ - **两种结构**
26
+ - **单表**:左侧 Token 速度仪表盘,右侧当前会话 / 今日 Token 与金额,底部缓存命中率进度条。
27
+ - **双表**:上方左侧 Token 速度、右侧缓存命中率两个仪表盘;下方并列展示当前会话与今日的 Token 量、金额。
28
+ - **四种皮肤**:古典(老式车机琥珀色)、马卡龙、极简、星空。结构 × 皮肤可自由组合,共 8 种呈现。
29
+ - **实时 Token 速度**:读取当前会话的流式输出增量,指针在 0–500 token/秒之间平滑摆动。
30
+ - **缓存命中率表盘**:量程 70–100%,刻度 70 / 85 / 100;低于 70% 时指针停在 70%,中央数字仍显示真实值。
31
+ - **Token 口径**:统一以 **k(千 token)** 显示,保留两位小数并带千分位,例如 `15,098.77k`。
32
+ - **设置入口**:卡片右上角滑杆图标;选择结构与皮肤后立即生效,并写入 `localStorage`,刷新后保留。
33
+ - **主题自适应**:颜色来自 DSH 主题令牌,深浅色模式均可读;不引入图表库、不请求外部 CDN。
34
+
35
+ ## 安装
36
+
37
+ 本插件自带 Host 半边,直接从 DSH 的 `sessionPersistence` 读取本地会话日志并聚合用量,**不依赖任何计费插件**。
38
+
39
+ ```bash
40
+ dsh plugin --profile web add dsh-token-gauge
41
+ ```
42
+
43
+ 从源码安装(本仓库当前版本):
44
+
45
+ ```bash
46
+ git clone https://github.com/liumiaozhi/dsh-token-gauge.git
47
+ dsh plugin --profile web add "link:<本仓库绝对路径>"
48
+ ```
49
+
50
+ > npm 上的 `dsh-token-gauge` 若仍为旧版,请先用源码安装;发布 1.1.0 后可直接按名称安装。
51
+
52
+ 安装后重启或硬刷新 DSH Web,侧边栏底部会出现「费用仪表盘」。插件以 slot 优先级覆盖原计费卡片,但不需要计费插件本身。
53
+
54
+ ## 使用
55
+
56
+ 1. 点击卡片**右上角**的滑杆图标打开设置。
57
+ 2. 在「结构」中选择 **单表 / 双表**。
58
+ 3. 在下方四种皮肤中选择 **古典 / 马卡龙 / 极简 / 星空**。
59
+ 4. 开始对话,Token 速度表会随流式输出更新;会话与今日数据每 1.5 秒刷新。
60
+
61
+ <p align="center">
62
+ <img src="screenshots/settings.png" alt="设置面板:结构 + 四种皮肤" width="62%">
63
+ </p>
64
+
65
+ ## 数据与口径
66
+
67
+ | 指标 | 来源 / 口径 |
68
+ | --- | --- |
69
+ | Token 速度 | 当前会话 `assistant/live-chunk` 文本 / reasoning / tool-call 增量估算,0–500 token/秒 |
70
+ | 当前会话 Token | 当前会话所有轮次的 `input + output` |
71
+ | 今日 Token | 本插件 `byDay` 中今天的 `input + output` |
72
+ | 当前会话金额 | 当前会话所有成功模型调用按单价估算 |
73
+ | 今日金额 | 本插件按 DeepSeek Flash / Pro 列表价与峰谷时段估算的今日费用 |
74
+ | 缓存命中率 | 今日 `cacheHit / (cacheHit + cacheMiss)`,仪表盘量程 70–100% |
75
+
76
+ Host 半边读取 DSH 的 `sessionPersistence` 会话日志,按 `assistant/message.usage` 聚合;搜索调用按 0.02 元/次估算。DeepSeek Flash(2 / 0.04 / 8 元每百万 token)与 Pro(9 / 0.3 / 27)使用官方列表价,工作日高峰外与周末按半价;其他模型回退到 Flash 价格估算。金额是参考值,不是官方账单。
77
+
78
+ ## 目录结构
79
+
80
+ ```text
81
+ dsh-token-gauge/
82
+ ├── package.json # DSH bundle + Client 声明
83
+ ├── cordis.patch.yml # 插入 token-gauge 行
84
+ ├── index.js # Host 半边:注册 /api/token-gauge/usage-stats
85
+ ├── usage-server.js # 会话日志聚合 + DeepSeek 峰谷计价
86
+ ├── client.js # Client 半边:仪表盘 / 设置 / 样式
87
+ ├── locale/
88
+ │ ├── zh.json # 插件市场中文标题与描述
89
+ │ └── en.json
90
+ ├── icon.svg # 插件图标
91
+ ├── screenshots/ # README 预览图
92
+ └── README.md / README.en.md / LICENSE
93
+ ```
94
+
95
+ ## 开发
96
+
97
+ ```bash
98
+ git clone https://github.com/liumiaozhi/dsh-token-gauge.git
99
+ cd dsh-token-gauge
100
+ # 本插件是手写 Client bundle,无构建步骤
101
+ dsh plugin --profile web add "link:$PWD"
102
+ ```
103
+
104
+ 修改 `client.js` 后,DSH 的 Client HMR 会在文件变化后重新加载模块;没有热更新时刷新页面即可。
105
+
106
+ ## 兼容与限制
107
+
108
+ - 面向 DSH Web(`platform: web`),需要 `@deepseek-ai/dsh-client-ui-sidebar` 与 `@deepseek-ai/dsh-client-ui-session`。
109
+ - Host 半边依赖 DSH 自带的 `sessionPersistence` 与 `webServer` 服务;不需要计费插件。
110
+ - 缓存命中率低于 70% 时指针停在 70% 刻度,中央数字保留真实值,避免表盘外推。
111
+ - README 图片为按实际组件样式生成的示例预览,数据为演示值。
112
+
113
+ ## 更新日志
114
+
115
+ ### 1.1.1
116
+
117
+ - 修复在 DSH 0.2.x 上无法启动:Client bundle 的注册 id 由 `dsh-cost-dashboard` 改为包名 `dsh-token-gauge`。加载器按包名匹配模块工厂,旧 id 不被识别,该行会被判定缺失并重新拉取 bundle,导致同一个 bundle 执行两次并抛出 `duplicate factory registration`,最终表现为 `web boot: 1 entry did not activate` / `dsh-token-gauge: import failed`。
118
+ - 新增 `engines.dsh` 与 `dsh.compatibility` 声明,限定 DSH `>=0.2.0-rc.1 <0.3.0-0`。不兼容的运行时会在安装阶段被 DSH 拦下并给出明确提示,而不是等到启动失败才暴露。
119
+
120
+ ## 许可
121
+
122
+ [MIT](LICENSE) © 2026 liumiaozhi