dsh-tokenlens 1.1.0 → 1.2.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/CHANGELOG.md +15 -0
- package/PROTOCOL.md +25 -7
- package/README.en.md +5 -5
- package/README.md +6 -6
- package/client.js +568 -126
- package/index.js +10 -1
- package/lib/provider-store.mjs +7 -0
- package/lib/usage-jsonl.mjs +9 -6
- package/lib/usage-opencode.mjs +10 -4
- package/lib/usage-stats.mjs +108 -25
- package/lib/usage-zcode.mjs +23 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
本项目遵循 [Semantic Versioning](https://semver.org/):修复 = PATCH,新功能 = MINOR,不兼容变更 = MAJOR。发布时同步更新 `package.json` 的 `version`、`index.js` 的 `PLUGIN_VERSION` 与本文件(`node scripts/bump-version.mjs <version> "<note>"`);已发布的条目保持原样。
|
|
4
4
|
|
|
5
|
+
## 1.2.1 — 2026-10-31
|
|
6
|
+
|
|
7
|
+
- feat(settings): 图表模式「明细」环形图的窗口选择(今日 / 最近7天 / 最近X天(或最近30天)/ 总计)持久化到插件设置:点击 pill 立即保存,重开弹窗、切换供应商或重启 DSH 后仍保留上次选择;当前供应商没有该窗口时自动回落到总计
|
|
8
|
+
- feat(wire): `providers` 载荷与 `settingsUpdate` 增加 `settings.detailsWindow`(`today|last7Days|second|total`),旧 Host 会忽略未知字段、旧 client 读取时回落 `total`,双向兼容
|
|
9
|
+
- 修复:请求进行中连续点击窗口时只保留最后一个选择(单定时器 200ms 重试);「恢复默认设置」同时把窗口重置为总计
|
|
10
|
+
- 测试:255 个自动化用例(新增 5 个持久化回归,更新 8 个既有设置/窗口用例)
|
|
11
|
+
|
|
12
|
+
## 1.2.0 — 2026-10-31
|
|
13
|
+
|
|
14
|
+
- feat(chart): 图表模式点击某一天的柱子可下钻查看**当天 24 小时**的 Token 消耗棒状图(横轴 00:00–23:00,悬浮显示小时与占比,回车/空格同样可操作,返回或再次点击回到日趋势)
|
|
15
|
+
- feat(chart): 小时数据覆盖全部 5 个本机 harness(DSH、ZCode、OpenCode CLI、WorkBuddy、Qoder);无小时数据的旧日期不可下钻,不伪造全零序列
|
|
16
|
+
- feat(chart): 图表模式「明细」的三张环形图(按 Harness / 按供应商 / Top 模型)新增 **今日 / 最近7天 / 最近X天(或最近30天)/ 总计** 窗口切换,默认总计;切换 scope 或数据/图表视图时保持,缺失窗口自动隐藏
|
|
17
|
+
- feat(wire): `stats.daily[]` 新增可选 `hours`(24 个本地小时 Token 整数)与 `providers[pid].hours`(v1.2.0 协议,已在 PROTOCOL 中写明)
|
|
18
|
+
- 测试:250 个自动化用例(新增 13 个:小时聚合、外部 harness 小时分组、下钻交互与窗口切换的前后端回归)
|
|
19
|
+
|
|
5
20
|
## 1.1.0 — 2026-10-30
|
|
6
21
|
|
|
7
22
|
- feat(providers): 接入 Open Design(OpenDesign)只读额度查询——Design Plan 的 5 小时 / 7 天窗口已用百分比与重置时间,以及独立的钱包 USD 余额
|
package/PROTOCOL.md
CHANGED
|
@@ -180,9 +180,19 @@ with `[path]`.
|
|
|
180
180
|
{ "key": "opencode-go/deepseek-v4.1-flash", "providerId": "opencode-go",
|
|
181
181
|
"modelId": "deepseek-v4.1-flash",
|
|
182
182
|
"today": { "total": …, "messages": … },
|
|
183
|
+
"last7Days": { "total": …, "messages": … },
|
|
183
184
|
"last30Days": { "total": …, "messages": … },
|
|
184
185
|
"allTime": { "total": …, "messages": … } }
|
|
185
186
|
],
|
|
187
|
+
"daily": [ // <=120 days, ascending; chart series
|
|
188
|
+
{ "day": "2026-10-25",
|
|
189
|
+
"total": { "total": 123456, "messages": 42 },
|
|
190
|
+
"hours": [0, 0, 0, 1234, 5678, …], // 24 integers: local-hour token totals
|
|
191
|
+
"providers": {
|
|
192
|
+
"opencode-go": { "total": 1234, "messages": 5,
|
|
193
|
+
"hours": [0, 0, 0, 500, 734, …] }
|
|
194
|
+
} }
|
|
195
|
+
],
|
|
186
196
|
"zcode": { // extra-harness detail
|
|
187
197
|
"dbPath": "C:\\Users\\…\\.zcode\\cli\\db\\db.sqlite",
|
|
188
198
|
"available": true, "error": null, "rows": 65, "cached": false,
|
|
@@ -263,6 +273,12 @@ with `[path]`.
|
|
|
263
273
|
breakdown and top models are labeled DSH-only.
|
|
264
274
|
- An unavailable/disabled statistics service answers
|
|
265
275
|
`{ ok: false, error: { code: "stats-unavailable" } }`.
|
|
276
|
+
- **Hourly drill-down (v1.2.0)**: `daily[].hours` and
|
|
277
|
+
`daily[].providers[id].hours` are 24-element arrays of local-hour token totals
|
|
278
|
+
(`[0..23]`, rounded integers) used by the chart mode. Every bundled harness
|
|
279
|
+
contributes when it exposes event timestamps; a day without the field is not
|
|
280
|
+
drillable and the client must not invent an all-zero hour series. DST fall-back
|
|
281
|
+
hours collapse into one local hour slot.
|
|
266
282
|
|
|
267
283
|
## Error shape
|
|
268
284
|
|
|
@@ -302,7 +318,7 @@ needs no provider catalog of its own.
|
|
|
302
318
|
|
|
303
319
|
The dialog 「供应商管理」 page talks to three additional actions:
|
|
304
320
|
|
|
305
|
-
- `{action:"providers"}` → `{ok:true, providers:[{providerId,label,shortLabel,kind,enabled,hasKey,keySource,apiKeyRef,baseURL,consoleUrl,builtin,dshManaged,dshProviderId}], dshProviders:[{providerId,label,supported,usageProviderId}], settings:{labelStyle
|
|
321
|
+
- `{action:"providers"}` → `{ok:true, providers:[{providerId,label,shortLabel,kind,enabled,hasKey,keySource,apiKeyRef,baseURL,consoleUrl,builtin,dshManaged,dshProviderId}], dshProviders:[{providerId,label,supported,usageProviderId}], settings:{labelStyle,defaultView,defaultScope,detailsExpanded,detailsWindow}, storeFile, storeFileDisplay}`. `storeFile` is the real path (local tooling); `storeFileDisplay` replaces the user's home directory with `~` and is what the management page renders.
|
|
306
322
|
- `{action:"providerUpdate", providerId, update:{enabled?,apiKey?,apiKeyRef?,baseURL?,consoleUrl?,label?,shortLabel?}}` → same list payload;
|
|
307
323
|
empty strings clear a stored value (falling back to the profile/default). `label` (全名, ≤40 chars) and
|
|
308
324
|
`shortLabel` (短标签, ≤12 chars) let the management page rename a provider. The shipped management page no
|
|
@@ -310,9 +326,7 @@ The dialog 「供应商管理」 page talks to three additional actions:
|
|
|
310
326
|
saves enabled/consoleUrl/label/shortLabel. Overrides are persisted atomically to
|
|
311
327
|
`$DSH_HOME/dsh-tokenlens/providers.json` (plugin-owned, not the profile patch); the same file also
|
|
312
328
|
- `{action:"providerTest", providerId}` → the normal snapshot envelope (`{ok,snapshot}` or `{ok:false,error}`), forcing one upstream read.
|
|
313
|
-
- `{action:"settingsUpdate", settings:{labelStyle
|
|
314
|
-
persisted in the store (`settings.labelStyle`) and controls whether the composer chip shows each
|
|
315
|
-
provider's `shortLabel` or full `label`. Invalid values answer `unsupported-provider`.
|
|
329
|
+
- `{action:"settingsUpdate", settings:{labelStyle?:"short"|"full", defaultView?:"chart"|"data", defaultScope?:"provider"|"all", detailsExpanded?:"auto"|"expanded"|"collapsed", detailsWindow?:"today"|"last7Days"|"second"|"total"}}` → the same providers payload; every field is optional and persisted in the store (`settings.*`). `labelStyle` controls whether the composer chip shows each provider's `shortLabel` or full `label`; `defaultView` / `defaultScope` / `detailsExpanded` are the usage-dialog defaults; `detailsWindow` (v1.2.1) is the remembered 明细 donut window (falls back visually to `total` when that window is unavailable on the current provider/host). Invalid values answer `unsupported-provider`.
|
|
316
330
|
|
|
317
331
|
`dshProviders` lists every route registered in DSH model settings (in order) with a `supported` flag (whether a usage adapter exists); the shipped management page renders those routes as the primary list and keeps unconfigured preset adapters in a collapsed secondary section. `dshManaged`/`dshProviderId` tell the management page that the route already exists in DSH model settings
|
|
318
332
|
(opencode-go / commandcode / deepseek), so the page can inherit the key and base URL instead of asking for them
|
|
@@ -416,9 +430,13 @@ configure the `opencode-go` provider.
|
|
|
416
430
|
or a balance card; Command Code also shows remaining/granted credits;
|
|
417
431
|
- **token statistics**: tabs 「当前供应商 · 全部 Harness」 (default; cards = that
|
|
418
432
|
provider's tokens across DSH + ZCode) / 「全部 Harness」 (all providers);
|
|
419
|
-
cards show 今日 / 最近30天 / 总计 (total tokens,
|
|
420
|
-
count); a 「按 Harness」breakdown for the active
|
|
421
|
-
breakdown and DSH top models; an unmapped-ZCode note when
|
|
433
|
+
cards show 今日 / 最近7天 / 最近X天(或最近30天) / 总计 (total tokens,
|
|
434
|
+
input/output/cache, request count); a 「按 Harness」breakdown for the active
|
|
435
|
+
scope; DSH provider breakdown and DSH top models; an unmapped-ZCode note when
|
|
436
|
+
present;
|
|
437
|
+
- **chart mode**: the daily bar chart, a click on a day bar drills into that
|
|
438
|
+
day's 24 local-hour bars (when the Host delivers `daily[].hours`), and the
|
|
439
|
+
明细 donuts switch between 今日 / 最近7天 / 最近X天 / 总计;
|
|
422
440
|
- refresh (usage + stats), last-updated/stale line, error banners, console link.
|
|
423
441
|
3. Everything client-side must work with only the shell's seeded modules
|
|
424
442
|
(`react`, `react-dom`, `@deepseek-ai/dsh-client-ui-primitives`) — no build step.
|
package/README.en.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
> One glance at your usage: plan capacity for the selected provider plus local token statistics across harnesses, right below the DSH composer.
|
|
11
11
|
|
|
12
|
-
**dsh-TokenLens** is a usage plugin for DSH (DeepSeek Harness), version v1.1.
|
|
12
|
+
**dsh-TokenLens** is a usage plugin for DSH (DeepSeek Harness), version v1.2.1. It keeps two kinds of numbers separate:
|
|
13
13
|
|
|
14
14
|
- **Plan capacity** — the provider's authoritative server-side values (percentage windows, used / cap, balance or remaining credit);
|
|
15
15
|
- **Local token stats** — tokens consumed on this machine across every connected harness, for the selected provider or for all providers combined.
|
|
@@ -20,8 +20,8 @@ Everything is computed locally: zero runtime dependencies, no external database,
|
|
|
20
20
|
|
|
21
21
|
- **Usage chip below the composer** — follows the selected model provider and shows its plan capacity; providers without an adapter or credentials stay hidden.
|
|
22
22
|
- **Details dialog** — plan capacity windows with reset times (plus an optional "consumed · estimated consumable" hint) and local token stats for today / last 7 days / last 30 days / all-time, scoped to the current provider or all harnesses.
|
|
23
|
-
- **Data and chart modes** — tables, a daily trend chart and ring charts
|
|
24
|
-
- **Provider management page** — enabled / built-in / all filters, enable switches, credential status, console links, label editing, connection tests, subscription badges and plugin settings.
|
|
23
|
+
- **Data and chart modes** — tables, a daily trend chart and ring charts with breakdowns by harness, provider, top model and unmapped providers. In chart mode, clicking a day's bar drills into that day's 24 hourly bars; the 明细 rings switch between today / last 7 days / last X days (or last 30 days) / all time.
|
|
24
|
+
- **Provider management page** — enabled / built-in / all filters, enable switches, credential status, console links, label editing, connection tests, subscription badges and plugin settings (label style, default view/scope, details expansion, default 明细 donut window).
|
|
25
25
|
- **Auto-discovery and agent tool** — providers configured in DSH Settings → Model Services are detected by route id or base-URL host and reuse their DSH credentials; `tokenlens_usage` lets the model query snapshots, local stats and diagnostics.
|
|
26
26
|
- **Local-only** — 5 harnesses (DSH, ZCode, OpenCode CLI, WorkBuddy / CodeBuddy CLI, Qoder CN CLI), 25 built-in providers (16 with plan / balance adapters), read-only local data, no telemetry.
|
|
27
27
|
|
|
@@ -66,7 +66,7 @@ dsh plugin --profile <profile> add dsh-tokenlens
|
|
|
66
66
|
Then make sure `dsh.profile.bundles` in `$DSH_HOME/profiles/<profile>/package.json` contains `"dsh-tokenlens"`:
|
|
67
67
|
|
|
68
68
|
```jsonc
|
|
69
|
-
{ "dependencies": { "dsh-tokenlens": "^1.1
|
|
69
|
+
{ "dependencies": { "dsh-tokenlens": "^1.2.1" },
|
|
70
70
|
"dsh": { "profile": { "bundles": ["…", "dsh-tokenlens"] } } }
|
|
71
71
|
```
|
|
72
72
|
|
|
@@ -134,7 +134,7 @@ Host bridge route: `/api/tokenlens`; agent tool: `tokenlens_usage`.
|
|
|
134
134
|
|
|
135
135
|
## Development
|
|
136
136
|
|
|
137
|
-
Node.js ≥ 24, zero runtime dependencies: `node --test` runs the
|
|
137
|
+
Node.js ≥ 24, zero runtime dependencies: `node --test` runs the 255 tests.
|
|
138
138
|
|
|
139
139
|
Release: `node scripts/bump-version.mjs <version> "<note>"` updates `package.json`, `PLUGIN_VERSION` and `CHANGELOG.md`; see [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
|
|
140
140
|
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
> **一眼看清你的用量**:在 DSH 输入框下方显示当前供应商的套餐容量,并汇总本机跨 Harness 的 Token 消耗。
|
|
11
11
|
|
|
12
|
-
**dsh-TokenLens(词元透镜)** 是 DSH(DeepSeek Harness)的用量插件(v1.1
|
|
12
|
+
**dsh-TokenLens(词元透镜)** 是 DSH(DeepSeek Harness)的用量插件(v1.2.1,公开版本)。它把两类数字**按不同口径**分开呈现:
|
|
13
13
|
|
|
14
14
|
- **套餐容量**(供应商服务端权威值):百分比窗口、`已用 / 上限`、账户余额或剩余额度;
|
|
15
15
|
- **本机 Token 统计**(本机记录):当前供应商在本机所有已接入 Harness 上的合计用量,也可切到「全部 Harness」看总账。
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
- **详情弹窗**(点击 chip 打开):
|
|
40
40
|
- **套餐容量**:5 小时 / 本周 / 本月等原生窗口的已用百分比、重置时间与绝对重置日期;余额类供应商显示余额。每个窗口附带一行 `已消耗 · 预计可消耗` 估算(由本机 Token 记录 ÷ 套餐百分比推算,仅供参考)。
|
|
41
41
|
- **本机 Token 统计**:今日 / 最近 7 天 / 最近 30 天 / 总计(订阅类供应商显示「最近 X 天」生效窗口),可按「当前供应商 · 全部 Harness」与「全部 Harness」两个视角查看。
|
|
42
|
-
- **明细与图表**:按 Harness、按供应商、Top
|
|
42
|
+
- **明细与图表**:按 Harness、按供应商、Top 模型、未映射供应商分组;支持「数据」(表格)与「图表」两种模式切换。图表模式里点击某一天的柱子可下钻查看**当天 24 小时**的 Token 消耗,底部「明细」环形图支持 **今日 / 最近 7 天 / 最近 X 天(或最近 30 天)/ 总计** 窗口切换。
|
|
43
43
|
- **工作区徽标**(实验性):左侧工作区列表的名称旁显示该工作区的本机 Token 合计,悬浮卡片显示今日 / 7 天 / 30 天 / 总计;纯展示,找不到对应 UI 时自动降级。
|
|
44
|
-
- **供应商管理页**:「已配置 / 内置 /
|
|
44
|
+
- **供应商管理页**:「已配置 / 内置 / 全部」筛选、启用开关、凭据状态、控制台链接、短标签与全名编辑、测试连接、已订阅徽章;另有「插件设置」可配置标签样式、默认展示模式、默认统计范围、明细展开状态与图表「明细」环形图的默认窗口(今日 / 最近 7 天 / 最近 X 天 / 总计,记住上次选择)。
|
|
45
45
|
- **自动识别**:在 DSH「设置 → 模型服务」中配置过的供应商会自动出现在管理页,并按路由 id 或 baseURL 主机匹配内置用量适配器,自动继承 DSH 中的凭据,无需重复填写。
|
|
46
46
|
- **Agent 工具**:注册 `tokenlens_usage`,模型可以自行查询套餐容量与本机用量。
|
|
47
47
|
|
|
@@ -106,7 +106,7 @@ dsh plugin --profile <profile> add dsh-tokenlens
|
|
|
106
106
|
```jsonc
|
|
107
107
|
{
|
|
108
108
|
"dependencies": {
|
|
109
|
-
"dsh-tokenlens": "^1.1
|
|
109
|
+
"dsh-tokenlens": "^1.2.1"
|
|
110
110
|
},
|
|
111
111
|
"dsh": {
|
|
112
112
|
"profile": {
|
|
@@ -389,7 +389,7 @@ Host 半注册 `tokenlens_usage`,参数 `action`(默认 `snapshot`)与可
|
|
|
389
389
|
|
|
390
390
|
## 验证
|
|
391
391
|
|
|
392
|
-
- `node --test`:**
|
|
392
|
+
- `node --test`:**255 个自动化用例**,覆盖 Host 数据层、供应商适配器、统计折叠、各 harness 读取、插件集成与浏览器端渲染 / 交互。
|
|
393
393
|
- 在真实环境中验证过 **5 个 harness** 的数据源;本机统计与独立的 SQLite 查询、独立的日志解析逐项对账(差额为 0),跨 harness 合并与供应商映射算术自洽。
|
|
394
394
|
- 供应商接口按各官方文档与参考客户端行为验证;未配置凭据时 chip 静默隐藏,接口异常时按可重试错误降级。
|
|
395
395
|
|
|
@@ -400,7 +400,7 @@ Host 半注册 `tokenlens_usage`,参数 `action`(默认 `snapshot`)与可
|
|
|
400
400
|
```powershell
|
|
401
401
|
git clone https://github.com/daigahou/dsh-tokenlens.git
|
|
402
402
|
cd dsh-tokenlens
|
|
403
|
-
node --test #
|
|
403
|
+
node --test # 255 个用例
|
|
404
404
|
```
|
|
405
405
|
|
|
406
406
|
本地联调安装方式见[方式 C](#方式-c本地开发从源码-link)。
|