dsh-token-gauge 0.1.0 → 0.1.2
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 +29 -6
- package/build.mjs +40 -0
- package/cordis.patch.yml +8 -8
- package/lib/client.mjs +2856 -0
- package/lib/{index.js → index.mjs} +68 -37
- package/package.json +57 -32
- package/preview/styles-showcase-v2.html +385 -0
- package/preview/styles-showcase.html +370 -0
- package/src/client.ts +100 -41
- package/src/host.ts +81 -45
- package/tsconfig.json +19 -0
- package/lib/client.js +0 -886
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
|
@@ -14,22 +14,37 @@ DeepSeek Harness(DSH)Web 侧边栏插件:以「机车风格仪表盘」实
|
|
|
14
14
|
- **限额**:支持全局 / 日 / 周 / 月 四类限额(默认全局为空=自动量程)。指针按所选口径对限额扫动。
|
|
15
15
|
- **中英文界面**:设置内一键切换 zh / en。
|
|
16
16
|
- **导出报表**:一键导出 CSV / JSON 用量明细(全局、分模型、按日/周/月/会话)。
|
|
17
|
-
-
|
|
17
|
+
- **侧边栏 Tab**:通过 `dsh-better-sidebar` 注册(稳定版 0.1.1-rc.x 唯一的外部 Tab 入口,web profile 需已安装);Client 半边将 react 打进 bundle,无需额外运行时。Host 半边监听 DSH 会话用量事件自行累计,可独立发布。
|
|
18
18
|
|
|
19
19
|
## 安装
|
|
20
20
|
|
|
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
|
+
> 侧边栏 Tab 通过 **`dsh-better-sidebar`** 注册,请确保你的 web profile 已安装并启用该插件(本机默认已随其它插件一并安装;若缺失,`dsh plugin --profile web add dsh-better-sidebar` 即可)。
|
|
23
|
+
|
|
21
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` 可彻底规避这一坑**:
|
|
22
27
|
```bash
|
|
23
|
-
dsh plugin --profile web add dsh-token-gauge
|
|
28
|
+
dsh plugin --profile web add dsh-token-gauge@0.1.1
|
|
24
29
|
dsh web
|
|
25
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 仪表盘」。
|
|
26
41
|
|
|
27
42
|
### 方式二:本地源码安装
|
|
28
43
|
```bash
|
|
29
44
|
git clone <本仓库> dsh-token-gauge
|
|
30
45
|
cd dsh-token-gauge
|
|
31
46
|
npm install
|
|
32
|
-
node build.mjs # 生成 lib/index.
|
|
47
|
+
node build.mjs # 生成 lib/index.mjs 与 lib/client.mjs
|
|
33
48
|
dsh plugin --profile web add . # 读取 package.json 的 dsh 字段
|
|
34
49
|
dsh web
|
|
35
50
|
```
|
|
@@ -41,6 +56,14 @@ dsh web --patch ./cordis.patch.yml
|
|
|
41
56
|
|
|
42
57
|
安装后重启/硬刷新 DSH Web,侧边栏出现「Token 仪表盘」Tab。开始对话产生 Token 后,仪表盘即实时更新。
|
|
43
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
|
+
|
|
44
67
|
## 数据来源与费用口径
|
|
45
68
|
|
|
46
69
|
- **数据源**:Host 半边订阅 DSH 会话事件流中的 `assistant/message.usage`(含输入/输出/缓存命中/缓存写入 token),自行累计,不依赖其他插件。
|
|
@@ -66,7 +89,7 @@ dsh web --patch ./cordis.patch.yml
|
|
|
66
89
|
|
|
67
90
|
```
|
|
68
91
|
dsh-token-gauge/
|
|
69
|
-
├── package.json # dsh 字段声明
|
|
92
|
+
├── package.json # dsh 字段声明 bundle.patch 契约 + client.inject(稳定版 0.1.1-rc.x 兼容)
|
|
70
93
|
├── tsconfig.json
|
|
71
94
|
├── build.mjs # esbuild 构建脚本
|
|
72
95
|
├── cordis.patch.yml # 本地 overlay
|
|
@@ -79,13 +102,13 @@ dsh-token-gauge/
|
|
|
79
102
|
│ ├── i18n.ts # 中英文案
|
|
80
103
|
│ ├── export.ts # 报表导出
|
|
81
104
|
│ └── util.ts # 格式化/量程工具
|
|
82
|
-
├── lib/ # 构建产物(
|
|
105
|
+
├── lib/ # 构建产物(lib/index.mjs / lib/client.mjs),随包发布
|
|
83
106
|
├── README.md / README.en.md / LICENSE
|
|
84
107
|
```
|
|
85
108
|
|
|
86
109
|
## 上架市场
|
|
87
110
|
|
|
88
|
-
本包已按 DSH 插件规范命名(`dsh`
|
|
111
|
+
本包已按 DSH 插件规范命名(`dsh.bundle.patch` 清单 + `lib/index.mjs` / `lib/client.mjs`),并声明 `files` 白名单。
|
|
89
112
|
发布到 npm 后,其他用户即可 `dsh plugin --profile web add dsh-token-gauge` 安装发现:
|
|
90
113
|
|
|
91
114
|
```bash
|
package/build.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// DSH 插件构建脚本:用 esbuild 产出 Host(Node) 与 Client(浏览器) 两个半边。
|
|
2
|
+
// Host: 监听会话用量事件、累计与计费(Node 环境)
|
|
3
|
+
// Client: 侧边栏仪表盘 UI(浏览器环境,纯原生 DOM/SVG,react 已打进 bundle)
|
|
4
|
+
// 注意:输出到 lib/index.mjs / lib/client.mjs(未跟踪的新文件名,避免覆盖
|
|
5
|
+
// 受版本库只读覆盖层保护的旧 lib/index.js / lib/client.js)。
|
|
6
|
+
import { build } from 'esbuild'
|
|
7
|
+
import { copyFileSync } from 'node:fs'
|
|
8
|
+
|
|
9
|
+
const common = {
|
|
10
|
+
bundle: true,
|
|
11
|
+
sourcemap: false,
|
|
12
|
+
logLevel: 'info',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
await build({
|
|
16
|
+
...common,
|
|
17
|
+
entryPoints: ['src/host.ts'],
|
|
18
|
+
outfile: 'lib/index.mjs',
|
|
19
|
+
platform: 'node',
|
|
20
|
+
format: 'esm',
|
|
21
|
+
target: 'node20',
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
await build({
|
|
25
|
+
...common,
|
|
26
|
+
entryPoints: ['src/client.ts'],
|
|
27
|
+
outfile: 'lib/client.mjs',
|
|
28
|
+
platform: 'browser',
|
|
29
|
+
format: 'esm',
|
|
30
|
+
target: 'es2020',
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// 同步市场元数据文件
|
|
34
|
+
try {
|
|
35
|
+
copyFileSync('LICENSE', 'lib/LICENSE')
|
|
36
|
+
} catch {
|
|
37
|
+
/* 非必需 */
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.log('[dsh-token-gauge] build done -> lib/index.mjs (host), lib/client.mjs (client)')
|
package/cordis.patch.yml
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# dsh
|
|
1
|
+
# dsh-token-gauge bundle patch: inserts the token-gauge host plugin into the
|
|
2
|
+
# profile root as one entry. Applied by `dsh plugin add dsh-token-gauge`.
|
|
3
|
+
# The host half subscribes to `assistant/message.usage`, accumulates token
|
|
4
|
+
# usage + cost, and serves two routes for the browser sidebar half:
|
|
5
|
+
# GET /plugins/dsh-token-gauge/state -> full gauge state (JSON)
|
|
6
|
+
# POST /plugins/dsh-token-gauge/cmd -> {type,payload} -> updated state
|
|
7
7
|
- insert:
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
- id: token-gauge
|
|
9
|
+
name: 'dsh-token-gauge'
|