dsh-token-gauge 0.1.1 → 0.1.3
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.en.md +15 -2
- package/README.md +22 -2
- package/build.mjs +26 -5
- package/lib/client.mjs +15 -1907
- package/package.json +3 -2
package/README.en.md
CHANGED
|
@@ -19,9 +19,12 @@ popup to switch style, palette, displayed metrics, usage scope, limits (global/d
|
|
|
19
19
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
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**:
|
|
22
25
|
```bash
|
|
23
|
-
# From marketplace
|
|
24
|
-
dsh plugin --profile web add dsh-token-gauge
|
|
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
|
|
25
28
|
dsh web
|
|
26
29
|
|
|
27
30
|
# From source
|
|
@@ -30,6 +33,16 @@ node build.mjs
|
|
|
30
33
|
dsh plugin --profile web add .
|
|
31
34
|
```
|
|
32
35
|
|
|
36
|
+
### Migrating from legacy 0.1.0
|
|
37
|
+
|
|
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
|
+
```bash
|
|
41
|
+
dsh plugin --profile web remove dsh-token-gauge
|
|
42
|
+
dsh plugin --profile web add dsh-token-gauge@0.1.1
|
|
43
|
+
```
|
|
44
|
+
After reconcile, `token-gauge` is added as a bundle layer automatically; restart `dsh web` to see the **Token Gauge** tab.
|
|
45
|
+
|
|
33
46
|
## Data & pricing
|
|
34
47
|
|
|
35
48
|
- **Source**: Host subscribes to `assistant/message.usage` in the DSH session event stream and aggregates it.
|
package/README.md
CHANGED
|
@@ -22,10 +22,22 @@ DeepSeek Harness(DSH)Web 侧边栏插件:以「机车风格仪表盘」实
|
|
|
22
22
|
> 侧边栏 Tab 通过 **`dsh-better-sidebar`** 注册,请确保你的 web profile 已安装并启用该插件(本机默认已随其它插件一并安装;若缺失,`dsh plugin --profile web add dsh-better-sidebar` 即可)。
|
|
23
23
|
|
|
24
24
|
### 方式一:从市场安装(推荐)
|
|
25
|
+
|
|
26
|
+
> **强烈建议钉版本安装**:`dsh plugin add` 底层是 pnpm,受你本地 `.npmrc` 指向的镜像(如 npmmirror)同步延迟影响,裸 `add dsh-token-gauge` 在 `^0.1.0` 范围内可能解析到尚未带 `dsh.bundle` 的旧版 `0.1.0`(装上去只会是普通依赖、不进 bundle 层、侧边栏不出现)。**显式钉 `0.1.1` 可彻底规避这一坑**:
|
|
25
27
|
```bash
|
|
26
|
-
dsh plugin --profile web add dsh-token-gauge
|
|
28
|
+
dsh plugin --profile web add dsh-token-gauge@0.1.1
|
|
27
29
|
dsh web
|
|
28
30
|
```
|
|
31
|
+
> 若想装最新版,可先 `dsh plugin --profile web update dsh-token-gauge` 升级,再确认 `node_modules/dsh-token-gauge/package.json` 的 `dsh.bundle.patch` 字段存在。
|
|
32
|
+
|
|
33
|
+
### 从旧版 0.1.0 迁移
|
|
34
|
+
|
|
35
|
+
若此前已误装 `0.1.0`(表现为 `dsh.profile.bundles` 未新增 `token-gauge` 层,并出现 `declares no dsh.bundle — installed as a plain dependency` 警告),按下面两步切换即可,无需手动改 bundles:
|
|
36
|
+
```bash
|
|
37
|
+
dsh plugin --profile web remove dsh-token-gauge
|
|
38
|
+
dsh plugin --profile web add dsh-token-gauge@0.1.1 # 钉版本,避免又解析回 0.1.0
|
|
39
|
+
```
|
|
40
|
+
装完后 `dsh.profile.bundles` 在 reconcile 时自动把 `token-gauge` 加为第 13 层,重启 `dsh web` 侧边栏即出现「Token 仪表盘」。
|
|
29
41
|
|
|
30
42
|
### 方式二:本地源码安装
|
|
31
43
|
```bash
|
|
@@ -44,6 +56,14 @@ dsh web --patch ./cordis.patch.yml
|
|
|
44
56
|
|
|
45
57
|
安装后重启/硬刷新 DSH Web,侧边栏出现「Token 仪表盘」Tab。开始对话产生 Token 后,仪表盘即实时更新。
|
|
46
58
|
|
|
59
|
+
### 排查:侧边栏 Tab 不出现
|
|
60
|
+
|
|
61
|
+
DSH 把插件拆成 host(Node 端)与 client(浏览器端)两半,走不同机制。若装好却看不到 Tab,可分别验证:
|
|
62
|
+
|
|
63
|
+
- **host 半边是否正常**:浏览器访问 `http://<dsh-host>/plugins/dsh-token-gauge/state` 应返回 200 + 状态 JSON,且 `~/.dsh-token-gauge/` 目录已生成。host 不工作通常是 bundle 层没挂上(`dsh.profile.bundles` 缺 `token-gauge`)。
|
|
64
|
+
- **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+**。
|
|
65
|
+
- 改动后务必**完整重启 `dsh web`**(进程内 client 缓存只在重启时清空),仅硬刷新不够。
|
|
66
|
+
|
|
47
67
|
## 数据来源与费用口径
|
|
48
68
|
|
|
49
69
|
- **数据源**:Host 半边订阅 DSH 会话事件流中的 `assistant/message.usage`(含输入/输出/缓存命中/缓存写入 token),自行累计,不依赖其他插件。
|
|
@@ -69,7 +89,7 @@ dsh web --patch ./cordis.patch.yml
|
|
|
69
89
|
|
|
70
90
|
```
|
|
71
91
|
dsh-token-gauge/
|
|
72
|
-
├── package.json # dsh 字段声明
|
|
92
|
+
├── package.json # dsh 字段声明 bundle.patch 契约 + client.inject(稳定版 0.1.1-rc.x 兼容)
|
|
73
93
|
├── tsconfig.json
|
|
74
94
|
├── build.mjs # esbuild 构建脚本
|
|
75
95
|
├── cordis.patch.yml # 本地 overlay
|
package/build.mjs
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
// DSH 插件构建脚本:用 esbuild 产出 Host(Node) 与 Client(浏览器) 两个半边。
|
|
2
2
|
// Host: 监听会话用量事件、累计与计费(Node 环境)
|
|
3
|
-
// Client: 侧边栏仪表盘 UI
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// Client: 侧边栏仪表盘 UI(浏览器环境)。
|
|
4
|
+
//
|
|
5
|
+
// 关键契约(稳定版 DSH 0.1.1-rc.x 的 client 加载器 @deepseek-ai/dsh-client-modules):
|
|
6
|
+
// 加载器把 client bundle 作为脚本注入,要求 bundle 在加载时主动调用
|
|
7
|
+
// window.__ModuleLoader__.load({ id: '<包名>', factory: (require) => <module.exports> })
|
|
8
|
+
// 自注册(参考 dsh-better-sidebar 等所有正常插件都是此格式)。factory 内用
|
|
9
|
+
// 运行时提供的 require 取依赖(如 react),从而与运行时 React 共享同一实例。
|
|
10
|
+
// 早期误用 ESM + export 导致「loaded without registering」错误,现已修正为
|
|
11
|
+
// __ModuleLoader__.load 包裹的 CJS。
|
|
12
|
+
//
|
|
13
|
+
// 输出到 lib/index.mjs / lib/client.mjs(未跟踪的新文件名,避免覆盖受版本库
|
|
14
|
+
// 只读覆盖层保护的旧 lib/index.js / lib/client.js)。
|
|
6
15
|
import { build } from 'esbuild'
|
|
7
16
|
import { copyFileSync } from 'node:fs'
|
|
8
17
|
|
|
18
|
+
const PLUGIN_ID = 'dsh-token-gauge'
|
|
19
|
+
|
|
9
20
|
const common = {
|
|
10
21
|
bundle: true,
|
|
11
22
|
sourcemap: false,
|
|
12
23
|
logLevel: 'info',
|
|
13
24
|
}
|
|
14
25
|
|
|
26
|
+
// Host 半边:Node 环境,ESM 即可(webServer 路由)
|
|
15
27
|
await build({
|
|
16
28
|
...common,
|
|
17
29
|
entryPoints: ['src/host.ts'],
|
|
@@ -21,13 +33,22 @@ await build({
|
|
|
21
33
|
target: 'node20',
|
|
22
34
|
})
|
|
23
35
|
|
|
36
|
+
// Client 半边:DSH client-modules 加载器契约 = window.__ModuleLoader__.load 包裹的 CJS
|
|
37
|
+
// react 标为 external,由运行时 require("react") 提供(共享单实例,规避双 React 冲突)。
|
|
24
38
|
await build({
|
|
25
39
|
...common,
|
|
26
40
|
entryPoints: ['src/client.ts'],
|
|
27
41
|
outfile: 'lib/client.mjs',
|
|
28
42
|
platform: 'browser',
|
|
29
|
-
format: '
|
|
43
|
+
format: 'cjs',
|
|
30
44
|
target: 'es2020',
|
|
45
|
+
external: ['react', 'react-dom', 'react/jsx-runtime'],
|
|
46
|
+
banner: {
|
|
47
|
+
js: `window.__ModuleLoader__.load({ id: "${PLUGIN_ID}", factory: function(require){ var module = { exports: {} }; var exports = module.exports;`,
|
|
48
|
+
},
|
|
49
|
+
footer: {
|
|
50
|
+
js: `; return module.exports; } });`,
|
|
51
|
+
},
|
|
31
52
|
})
|
|
32
53
|
|
|
33
54
|
// 同步市场元数据文件
|
|
@@ -37,4 +58,4 @@ try {
|
|
|
37
58
|
/* 非必需 */
|
|
38
59
|
}
|
|
39
60
|
|
|
40
|
-
console.log('[dsh-token-gauge] build done -> lib/index.mjs (host), lib/client.mjs (client)')
|
|
61
|
+
console.log('[dsh-token-gauge] build done -> lib/index.mjs (host), lib/client.mjs (client, __ModuleLoader__.load format)')
|