dsh-token-gauge 0.1.10 → 1.1.0

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,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 dsh-token-gauge contributors
3
+ Copyright (c) 2026 liumiaozhi
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.en.md CHANGED
@@ -1,67 +1,95 @@
1
1
  # dsh-token-gauge · Token Gauge Dashboard
2
2
 
3
- A DeepSeek Harness (DSH) Web sidebar plugin that shows Token usage and cost on a **motorcycle-style dashboard**.
4
- The needle rotates smoothly as usage grows; usage and cost figures sit below the needle. Click ⚙ to open a settings
5
- popup to switch style, palette, displayed metrics, usage scope, limits (global/daily/weekly/monthly), language, and export reports.
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>
6
7
 
7
- > Default style: **Modern EV Tech** · Default palette: **Neon Blue** · Default metric: **global cumulative**.
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.
8
21
 
9
22
  ## Features
10
23
 
11
- - **Live gauge**: SVG arc gauge; needle rotates with `usage / limit`; turns red when over limit.
12
- - **6 styles**: Modern EV Tech (default), Raw Motorcycle, Luxury Sports, Cute Car, Cyberpunk, Retro Dial.
13
- - **8 palettes**: Amber Gold, Neon Blue, Track Red, Aurora Green, Sakura Pink, Night Purple, Titanium Silver, Volcano Orange (freely combinable with styles).
14
- - **Usage & cost**: total tokens, cost (¥), plus optional cards (input/output, cache hit, sessions, today, quota progress).
15
- - **Limits**: global / daily / weekly / monthly (default global = empty → auto scale).
16
- - **i18n**: one-click zh / en.
17
- - **Export**: one-click CSV / JSON usage reports (global, per-model, per day/week/month/session).
18
- - **Zero runtime deps**: Client is pure DOM/SVG (no React); Host listens to DSH usage events and aggregates on its own.
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.
19
33
 
20
34
  ## Install
21
35
 
22
- > **Pin the version**: `dsh plugin add` is backed by pnpm and can be affected by mirror sync lag (e.g. npmmirror).
23
- > A bare `add dsh-token-gauge` may resolve `0.1.0` under `^0.1.0` — that old build lacks `dsh.bundle`, so it installs
24
- > as a plain dependency (no bundle layer, no sidebar tab). **Pin `0.1.1` to avoid this**:
36
+ The plugin ships its own Host half: it reads DSH's `sessionPersistence` logs and aggregates usage locally. **No billing plugin is required.**
37
+
25
38
  ```bash
26
- # From marketplace (recommended — pin to avoid resolving to the legacy 0.1.0)
27
- dsh plugin --profile web add dsh-token-gauge@0.1.1
28
- dsh web
29
-
30
- # From source
31
- npm install
32
- node build.mjs
33
- dsh plugin --profile web add .
39
+ dsh plugin --profile web add dsh-token-gauge
34
40
  ```
35
41
 
36
- ### Migrating from legacy 0.1.0
42
+ From source (current repository version):
37
43
 
38
- If you already installed `0.1.0` (no `token-gauge` layer in `dsh.profile.bundles`, warning `declares no dsh.bundle —
39
- installed as a plain dependency`), switch with:
40
44
  ```bash
41
- dsh plugin --profile web remove dsh-token-gauge
42
- dsh plugin --profile web add dsh-token-gauge@0.1.1
45
+ git clone https://github.com/liumiaozhi/dsh-token-gauge.git
46
+ dsh plugin --profile web add "link:<absolute-path-to-repo>"
43
47
  ```
44
- After reconcile, `token-gauge` is added as a bundle layer automatically; restart `dsh web` to see the **Token Gauge** tab.
45
48
 
46
- ## Data & pricing
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
47
54
 
48
- - **Source**: Host subscribes to `assistant/message.usage` in the DSH session event stream and aggregates it.
49
- - **Views**: global / daily / weekly / monthly / session / model.
50
- - **Cost**: `(missInput×inMiss + cacheHit×inHit + cacheWrite×write + output×out) / 1,000,000` (¥/M tokens).
51
- Ships DeepSeek official CNY presets, editable per model in settings (advanced · pricing).
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.
52
59
 
53
- ## Settings (⚙ popup)
60
+ <p align="center">
61
+ <img src="screenshots/settings.png" alt="Settings: layout and four skins" width="62%">
62
+ </p>
54
63
 
55
- Language · Style · Palette · Metric (global/session/today/daily/weekly/monthly) · Display toggles ·
56
- Limits (global/daily/weekly/monthly) · Advanced pricing · Export CSV/JSON · Clear / Reset.
64
+ ## Data
57
65
 
58
- ## Publish
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
59
78
 
60
79
  ```bash
61
- npm version patch
62
- npm publish --registry=https://registry.npmjs.org
80
+ git clone https://github.com/liumiaozhi/dsh-token-gauge.git
81
+ cd dsh-token-gauge
82
+ dsh plugin --profile web add "link:$PWD"
63
83
  ```
64
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
+
65
93
  ## License
66
94
 
67
- MIT
95
+ [MIT](LICENSE) © 2026 liumiaozhi
package/README.md CHANGED
@@ -1,129 +1,115 @@
1
- # dsh-token-gauge · Token 机车仪表盘
1
+ # dsh-token-gauge · 费用仪表盘
2
2
 
3
- DeepSeek Harness(DSH)Web 侧边栏插件:以「机车风格仪表盘」实时展示 Token 用量与费用。
4
- 指针随用量增长平滑转动,下方显示用量与费用数字;点击 ⚙ 打开设置弹窗,可切换风格、配色、显示内容、用量口径、限额(全局/日/周/月)、语言并导出用量报表。
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>
5
7
 
6
- > 默认风格:**现代电车科技**;默认配色:**霓虹蓝**;默认用量口径:**全局累计**。
8
+ <p align="center">
9
+ <img src="screenshots/styles.png" alt="古典 / 马卡龙 / 极简 / 星空四种皮肤" width="78%">
10
+ </p>
7
11
 
8
- ## 特性
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>
9
18
 
10
- - **实时仪表盘**:SVG 弧形表盘,指针随 `用量 / 限额` 比值转动;超限进入红色危险区并提示。
11
- - **多风格(6 种)**:现代电车科技(默认)、原始机车、豪华跑车、可爱小车、赛博朋克、复古机械表盘。
12
- - **多配色(8 种)**:琥珀金、霓虹蓝、赛道红、极光绿、樱粉、暗夜紫、钛银、火山橙。风格与配色可自由组合。
13
- - **用量与费用**:显示总 Token、费用(¥),并可开启输入/输出、缓存命中、会话数、今日用量、限额进度等副卡片。
14
- - **限额**:支持全局 / 日 / 周 / 月 四类限额(默认全局为空=自动量程)。指针按所选口径对限额扫动。
15
- - **中英文界面**:设置内一键切换 zh / en。
16
- - **导出报表**:一键导出 CSV / JSON 用量明细(全局、分模型、按日/周/月/会话)。
17
- - **侧边栏 Tab**:通过 `dsh-better-sidebar` 注册(稳定版 0.1.1-rc.x 唯一的外部 Tab 入口,web profile 需已安装);Client 半边将 react 打进 bundle,无需额外运行时。Host 半边监听 DSH 会话用量事件自行累计,可独立发布。
19
+ 一个给 **DeepSeek Harness(DSH)** 用的侧边栏 Token 费用仪表盘。用老式车机 / 马卡龙 / 极简 / 星空四种皮肤,把 Token 输出速度、当前会话与今日消耗、缓存命中率做成一眼能读懂的仪表。
18
20
 
19
- ## 安装
21
+ > 界面预览使用示例数据;实际数据来自 DSH 本地会话日志聚合,不伪造样本。
20
22
 
21
- > **兼容性**:本插件面向 **DSH 0.1.1-rc.1 / 0.1.1-rc.2(稳定版)**。采用 `dsh.bundle.patch` 清单 + `cordis.patch.yml` 注册,符合稳定版的插件机制(不兼容新版 0.1.2-alpha 的 `dsh.host/client` 清单)。
22
- > **前置依赖 `dsh-better-sidebar`**:本插件的 Tab 通过 `ctx.betterSidebar.registerTab` 注册到它的**右侧工作台**,所以它必须是 **profile 的直接依赖、且已挂进 `dsh.profile.bundles`**:
23
- >
24
- > `dsh plugin --profile web add dsh-better-sidebar`
25
- >
26
- > ⚠️ **陷阱(很常见)**:它若只是本插件的**传递依赖**,只会被装进 `node_modules` 而**不会**被挂成 bundle 层 —— 加载树里没有条目、`betterSidebar` 服务不会被 provide,表现就是本插件「已启用 / 已挂载」却没有任何侧边栏 Tab,**而且全程零报错**(0.1.7 起会在浏览器控制台打出明确指引)。同理请确认 `cordis.patch.yml` 与 `.dsh-market/state.json` 没有把它列为 `disabled`。
27
- >
28
- > 另注:Tab 注册后会出现在侧边栏 **「+ 新建 Tab」菜单**里(这是 better-sidebar 的设计:注册的是 tab *类型*,需你点开一次才会出现在标签栏),详见下方「排查」。
23
+ ## 特性
29
24
 
30
- ### 方式一:从市场安装(推荐)
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。
31
34
 
32
- > **强烈建议钉版本安装**:`dsh plugin add` 底层是 pnpm,受你本地 `.npmrc` 指向的镜像(如 npmmirror)同步延迟影响,裸 `add dsh-token-gauge` 在 `^0.1.0` 范围内可能解析到尚未带 `dsh.bundle` 的旧版 `0.1.0`(装上去只会是普通依赖、不进 bundle 层、侧边栏不出现)。**显式钉 `0.1.7` 可彻底规避这一坑**:
33
- ```bash
34
- dsh plugin --profile web add dsh-token-gauge@0.1.7
35
- dsh web
36
- ```
37
- > 若想装最新版,可先 `dsh plugin --profile web update dsh-token-gauge` 升级,再确认 `node_modules/dsh-token-gauge/package.json` 的 `dsh.bundle.patch` 字段存在。
35
+ ## 安装
38
36
 
39
- ### 从旧版 0.1.0 迁移
37
+ 本插件自带 Host 半边,直接从 DSH 的 `sessionPersistence` 读取本地会话日志并聚合用量,**不依赖任何计费插件**。
40
38
 
41
- 若此前已误装 `0.1.0`(表现为 `dsh.profile.bundles` 未新增 `token-gauge` 层,并出现 `declares no dsh.bundle — installed as a plain dependency` 警告),按下面两步切换即可,无需手动改 bundles:
42
39
  ```bash
43
- dsh plugin --profile web remove dsh-token-gauge
44
- dsh plugin --profile web add dsh-token-gauge@0.1.7 # 钉版本,避免又解析回 0.1.0
40
+ dsh plugin --profile web add dsh-token-gauge
45
41
  ```
46
- 装完后 `dsh.profile.bundles` 在 reconcile 时自动把 `token-gauge` 加为最后一层,重启 `dsh web` 后,在侧边栏 **「+ 新建 Tab」菜单**里选「Token 仪表盘」即可打开。
47
42
 
48
- ### 方式二:本地源码安装
49
- ```bash
50
- git clone <本仓库> dsh-token-gauge
51
- cd dsh-token-gauge
52
- npm install
53
- node build.mjs # 生成 lib/index.mjs 与 lib/client.mjs
54
- dsh plugin --profile web add . # 读取 package.json 的 dsh 字段
55
- dsh web
56
- ```
57
- 或在已运行 DSH 的情况下以本地 overlay 调试:
43
+ 从源码安装(本仓库当前版本):
44
+
58
45
  ```bash
59
- node build.mjs
60
- dsh web --patch ./cordis.patch.yml
46
+ git clone https://github.com/liumiaozhi/dsh-token-gauge.git
47
+ dsh plugin --profile web add "link:<本仓库绝对路径>"
61
48
  ```
62
49
 
63
- 安装后**完整重启** DSH Web(进程内 client 缓存只在重启时清空,硬刷新不够),然后在侧边栏点 **「+ 新建 Tab」→「Token 仪表盘」** 打开它。开始对话产生 Token 后,仪表盘即实时更新。
50
+ > npm 上的 `dsh-token-gauge` 若仍为旧版,请先用源码安装;发布 1.1.0 后可直接按名称安装。
64
51
 
65
- ### 排查:侧边栏 Tab 不出现
52
+ 安装后重启或硬刷新 DSH Web,侧边栏底部会出现「费用仪表盘」。插件以 slot 优先级覆盖原计费卡片,但不需要计费插件本身。
66
53
 
67
- DSH 把插件拆成 host(Node 端)与 client(浏览器端)两半,走不同机制。若装好却看不到 Tab,可分别验证:
54
+ ## 使用
68
55
 
69
- - **host 半边是否正常**:浏览器访问 `http://<dsh-host>/plugins/dsh-token-gauge/state` 应返回 200 + 状态 JSON,且 `~/.dsh-token-gauge/` 目录已生成。host 不工作通常是 bundle 层没挂上(`dsh.profile.bundles` 缺 `token-gauge`)。
70
- - **client 半边是否正常**:访问 `/plugins/dsh-token-gauge/client.js` 应返回 200(打包后的客户端脚本);首页 `window.__DSH_BOOT__` 里应包含该 client。若此处 404,常见原因是 `package.json` 的 `exports` 未导出 `./package.json`——DSH 的 client 加载器用 `require.resolve('<包名>/package.json')` 定位 client 包,缺少该子路径导出会被静默判为「非 client 包」且(进程内)缓存。**本包已显式导出 `"./package.json"`,如遇此问题请确认装的是 0.1.2+**。
71
- - **`dsh-better-sidebar` 是否真的挂载了**(「已启用/已挂载却无 Tab」的头号原因):Tab 挂在它的右侧工作台上。检查 `~/.dsh/profiles/web/package.json` 的 `dsh.profile.bundles` **和** `dependencies` 里是否**都**有 `dsh-better-sidebar` —— **只存在于 `node_modules` 不算**:作为传递依赖装进来的包不会被挂成 bundle 层,服务不会被 provide,于是本插件完全静默(0.1.7 起浏览器控制台会打出指引)。同时确认 `cordis.patch.yml` 与 `.dsh-market/state.json` 未把它标为 `disabled`。
72
- - **类型已注册,但标签栏里看不到**:`registerTab` 注册的是 tab **类型**,不会自动出现在标签栏 —— 需到侧边栏 **「+ 新建 Tab」菜单**点选「Token 仪表盘」打开一次。若菜单里也找不到,去看侧边栏**设置面板的 Tab 列表**:列表里有 = 注册成功只是没打开;列表里也没有 = 服务没拿到(回到上一条)。
73
- - 改动后务必**完整重启 `dsh web`**(进程内 client 缓存只在重启时清空),仅硬刷新不够。
56
+ 1. 点击卡片**右上角**的滑杆图标打开设置。
57
+ 2. 在「结构」中选择 **单表 / 双表**。
58
+ 3. 在下方四种皮肤中选择 **古典 / 马卡龙 / 极简 / 星空**。
59
+ 4. 开始对话,Token 速度表会随流式输出更新;会话与今日数据每 1.5 秒刷新。
74
60
 
75
- ## 数据来源与费用口径
61
+ <p align="center">
62
+ <img src="screenshots/settings.png" alt="设置面板:结构 + 四种皮肤" width="62%">
63
+ </p>
76
64
 
77
- - **数据源**:Host 半边订阅 DSH 会话事件流中的 `assistant/message.usage`(含输入/输出/缓存命中/缓存写入 token),自行累计,不依赖其他插件。
78
- - **累计视图**:全局 / 当日 / 当周 / 当月 / 会话 / 模型 六套。
79
- - **费用**:`费用 = (未命中输入×输入未命中单价 + 缓存命中×输入命中单价 + 缓存写入×写入单价 + 输出×输出单价) / 1,000,000`。
80
- 内置 DeepSeek 官方 ¥ 预设(如 deepseek-chat:输入缓存命中 0.5 / 未命中 2、输出 8;deepseek-reasoner:1 / 4 / 16),可在设置「高级·定价」中按模型自定义(¥/百万 token)。
65
+ ## 数据与口径
81
66
 
82
- ## 设置项(⚙ 弹窗)
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% |
83
75
 
84
- | 分组 | 说明 |
85
- |---|---|
86
- | 语言 | 中文 / English |
87
- | 风格 | 6 种机车风格 |
88
- | 配色 | 8 种调色板 |
89
- | 用量口径 | 全局累计 / 当前会话 / 今日 / 每日 / 每周 / 每月 |
90
- | 显示内容 | 用量、费用、输入/输出、缓存节省、会话数、今日用量、限额进度(可独立开关) |
91
- | 限额 | 全局 / 日 / 周 / 月(留空为不限,仪表盘自动量程) |
92
- | 高级·定价 | 按模型编辑输入命中/未命中、输出、缓存写入 单价(¥/百万 token) |
93
- | 导出报表 | CSV / JSON |
94
- | 其他 | 清空用量、恢复默认 |
76
+ Host 半边读取 DSH 的 `sessionPersistence` 会话日志,按 `assistant/message.usage` 聚合;搜索调用按 0.02 元/次估算。DeepSeek Flash(2 / 0.04 / 8 元每百万 token)与 Pro(9 / 0.3 / 27)使用官方列表价,工作日高峰外与周末按半价;其他模型回退到 Flash 价格估算。金额是参考值,不是官方账单。
95
77
 
96
78
  ## 目录结构
97
79
 
98
- ```
80
+ ```text
99
81
  dsh-token-gauge/
100
- ├── package.json # dsh 字段声明 bundle.patch 契约 + client.inject(稳定版 0.1.1-rc.x 兼容)
101
- ├── tsconfig.json
102
- ├── build.mjs # esbuild 构建脚本
103
- ├── cordis.patch.yml # 本地 overlay
104
- ├── src/
105
- │ ├── host.ts # Host 半边:用量监听/累计/计费/持久化
106
- │ ├── client.ts # Client 半边:注册侧边栏 Tab + 装配
107
- │ ├── gauge.ts # SVG 仪表盘(指针/读数)
108
- │ ├── styles.ts # 风格+配色定义与全局 CSS
109
- │ ├── settings.ts # 设置弹窗
110
- │ ├── i18n.ts # 中英文案
111
- │ ├── export.ts # 报表导出
112
- │ └── util.ts # 格式化/量程工具
113
- ├── lib/ # 构建产物(lib/index.mjs / lib/client.mjs),随包发布
114
- ├── README.md / README.en.md / LICENSE
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
115
93
  ```
116
94
 
117
- ## 上架市场
118
-
119
- 本包已按 DSH 插件规范命名(`dsh.bundle.patch` 清单 + `lib/index.mjs` / `lib/client.mjs`),并声明 `files` 白名单。
120
- 发布到 npm 后,其他用户即可 `dsh plugin --profile web add dsh-token-gauge` 安装发现:
95
+ ## 开发
121
96
 
122
97
  ```bash
123
- npm version patch # 或 minor/major
124
- npm publish # 须使用官方源 registry.npmjs.org
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"
125
102
  ```
126
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
+
127
113
  ## 许可
128
114
 
129
- MIT
115
+ [MIT](LICENSE) © 2026 liumiaozhi