@feiyang666/dsh-usage-plugin 1.9.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/README.md ADDED
@@ -0,0 +1,272 @@
1
+ <div align="center">
2
+
3
+ # DeepSeek Harness 用量与消耗插件(dsh-usage-plugin)
4
+
5
+ [English](./README.en.md) | **简体中文**
6
+
7
+ [GitHub](https://github.com/feiyang-dev/dsh-usage-plugin) · [npm](https://www.npmjs.com/package/@feiyang666/dsh-usage-plugin) · MIT License
8
+
9
+ **由开发者制作的 DeepSeek Harness 插件** —— 记录每一次模型调用的 token 用量与消耗,支持峰谷计费、余额查询、日历热力图与 CSV / JSON / PNG 导出。
10
+
11
+ ![License](https://img.shields.io/badge/license-MIT-blue.svg)
12
+ ![Node](https://img.shields.io/badge/node-%3E%3D18-339933)
13
+ ![Platform](https://img.shields.io/badge/platform-web%20%26%20desktop-4d9fff)
14
+
15
+ </div>
16
+
17
+ ---
18
+
19
+ > ## 🔔 重要通知(2026-08-16):npm 包名已更换
20
+ >
21
+ > 本插件的 **npm 包名已由 `@feiyang666/deepseekharnessdesktop` 更名为 `@feiyang666/dsh-usage-plugin`**(与 GitHub 仓库名 `feiyang-dev/dsh-usage-plugin` 保持一致)。
22
+ >
23
+ > - 安装 / 升级请使用新包名:`dsh plugin --profile web add @feiyang666/dsh-usage-plugin`
24
+ > - 旧包名 `@feiyang666/deepseekharnessdesktop` 仍会保留一段时间,但**不再维护、不会更新**,请尽快迁移
25
+ > - 桌面端(`DeepSeek Harness 桌面版`)已兼容两种包名,旧包名安装的会自动识别并支持「一键更新」迁移到新包名
26
+
27
+ ---
28
+
29
+ ## 简介
30
+
31
+ dsh-usage-plugin 是 DeepSeek Harness 生态的**用量与消耗统计插件**(DSH plugin,Host + Client 双面一体包)。装好后在 WebUI 顶部「对话」「轨迹」之后会出现 **「用量与消耗」** 与 **「剩余余额查询」** 两个 tab:
32
+
33
+ > 支持 **Windows / macOS / Linux**:路径按当前平台处理(`node:path`),目录选择与「打开所在目录」均调用系统原生方式(macOS 用 `osascript` / `open`,Linux 用 `zenity` / `xdg-open`),余额查询与导出不依赖 Windows 专用命令。
34
+
35
+ - **用量与消耗**:记录每次模型调用的 token 用量与缓存命中(输入·未命中 / 缓存命中 / 缓存写入 / 输出 / 推理 / 结束原因),按 DeepSeek 峰谷/基础价格计算消耗(高峰时段自动按北京时间 9:00–12:00、14:00–18:00 计价)。模型名以请求参数为准如实显示(非 DeepSeek 模型不再显示为「未知模型」,无官方价格的模型消耗按 0 统计)。概览含「按模型」表与「按 API 服务商 × 模型」明细表(每个服务商一组,组内列出各模型的调用与高峰/空闲分列消耗),底部有总费用合计。
36
+ - **用量日历**:按月查看每日用量热力图(按消耗或调用数着色),悬停查看详情(含高峰 / 空闲消耗拆分)、点击某天查看当日调用明细与高峰/空闲消耗统计,附本月每日统计表(高峰消耗 / 空闲消耗 / 总消耗分列)与月度汇总。
37
+ - **缓存命中列表**:最新记录排在最前,支持 今天 / 近7天 / 近30天 / 全部 快捷筛选与自定义起止日期区间,汇总行与表尾合计区分高峰消耗 / 空闲消耗 / 总费用合计;列表分页渲染(每页 100 条),记录量大也不卡顿。
38
+ - **价格表**:**DeepSeek 官方 API 价格表**,展示基础价与峰谷价(高峰/空闲)单价表,高峰价与空闲价分列展示,支持在面板内直接编辑价格并持久化(数据目录 `pricing.json`),也可一键恢复默认。
39
+ - **剩余余额查询**:用当前配置的 `DEEPSEEK_API_KEY` 查询 DeepSeek 账户余额。
40
+ - **导出**:CSV / JSON / **PNG 长图**(按最新在前展示,最多含最近 2000 条,超出会提示;PNG 报告含高峰 / 空闲消耗分列统计),可导出到任意目录(原生目录选择器),导出后自动打开所在目录。
41
+ - **导入**:选择文件(JSON / CSV)合并导入,按时间去重。
42
+ - **持久化**:记录实时落盘到 `<会话工作区>/dsh-usage/usage-records.json`,重启自动恢复(上限 100000 条,尽量多存)。
43
+ - **界面适配**:面板字号跟随应用「显示大小」设置自动缩放(em 相对字号),面板宽度以视口封顶、宽表格在容器内横向滑动(max-content + overflow-x),任何窗口大小下所有列与合计都完整可见,不会裁掉右侧内容。
44
+
45
+ ---
46
+
47
+ ## 界面预览
48
+
49
+ ### 用量与消耗
50
+ ![用量与消耗](./docs/assets/usage-overview.png)
51
+
52
+ ### 剩余余额查询
53
+ ![剩余余额查询](./docs/assets/balance-query.png)
54
+
55
+ ## 推荐安装方式
56
+
57
+ > 两个方法任选其一,效果等价。**推荐使用桌面端**,全程图形化、无需命令行。
58
+
59
+ ### 方式一(推荐):桌面端一键安装
60
+
61
+ 安装 [DeepSeek Harness 桌面版](https://github.com/feiyang-dev/DeepSeek-Harness-Desktop),打开后点击 **「安装插件」→ 推荐插件 → 用量与消耗插件 → 一键安装**,完成后点 **「立即重启服务」** 即可生效。
62
+
63
+ ### 方式二:命令行安装
64
+
65
+ ```bash
66
+ # 前提:已安装 dsh(npm install -g @deepseek-ai/dsh)
67
+ dsh plugin --profile web add @feiyang666/dsh-usage-plugin
68
+ ```
69
+
70
+ 也可对其它 profile 安装:
71
+
72
+ ```bash
73
+ dsh plugin --profile web add @feiyang666/dsh-usage-plugin
74
+ dsh plugin --profile headless add @feiyang666/dsh-usage-plugin
75
+ ```
76
+
77
+ 装完重启 dsh web 服务即可。详细的手动安装 / 接线 / 卸载 / 排障说明见下方。
78
+
79
+ ---
80
+
81
+ ## 这个包是什么
82
+
83
+ 一个 npm 包 = **host 半**(Node 侧 Cordis 插件,负责记录、计费、余额查询、导出,见 `lib/index.js`)+ **client 半**(浏览器侧面板,见 `lib/client.js`,通过 `/usage/api` 与 host 通信)。
84
+
85
+ 包通过两处声明接入 DSH:
86
+
87
+ | 声明 | 作用 |
88
+ | --- | --- |
89
+ | `dsh.bundle.patch`(`cordis.patch.yml`) | 让 DSH 把它识别为**标准 bundle 插件包**:`dsh plugin --profile <名> add <包名>` 一条命令即可安装并自动接线,无需手改任何配置文件 |
90
+ | `dsh.client` + `exports["./client"]` | 让 web 客户端在 `/plugins/<包名>/client.js` 自动加载浏览器面板 |
91
+
92
+ 所以对使用者来说,**安装就是一条命令**,不用碰 YAML、不用手动复制文件。
93
+
94
+ ---
95
+
96
+ ## 安装(给使用者)
97
+
98
+ ### 0. 前提条件
99
+
100
+ - 已安装 DeepSeek Harness(`npm install -g @deepseek-ai/dsh` 全局安装,或使用基于它的桌面应用 / `npx @deepseek-ai/dsh web`)。
101
+ - 安装方式 A(推荐)需要 **pnpm**:`npm install -g pnpm`(或 `corepack enable`)。
102
+ - 确保 `dsh` 命令在 PATH 里(桌面应用自带环境则在其终端中执行)。
103
+
104
+ ### 1. 方法 A(推荐):一条命令安装
105
+
106
+ ```bash
107
+ dsh plugin --profile web add @feiyang666/dsh-usage-plugin
108
+ ```
109
+
110
+ 这条命令会做三件事(全部自动):
111
+
112
+ 1. 在 `~/.dsh/profiles/web` 里通过 pnpm 安装本包(首次使用会自动初始化该 profile);
113
+ 2. 检测到包的 `dsh.bundle` 声明,自动把包名写进 profile 的 `dsh.profile.bundles` 层列表;
114
+ 3. 重启后,DSH 启动时会自动读取包内的 `cordis.patch.yml`,把插件行挂进应用树——**不需要**手动编辑任何配置文件。
115
+
116
+ 其它 profile 同理,把 `web` 换成你的 profile 名即可(如 `dsh plugin --profile headless add ...`;`dsh web` 等价于 `dsh --profile web`)。
117
+
118
+ > 想用本地 tarball 测试:`dsh plugin --profile web add C:\path\to\feiyang666-deepseekharnessdesktop-1.1.0.tgz`
119
+
120
+ ### 2. 方法 B:手动安装(不使用 pnpm / 无 `dsh plugin`)
121
+
122
+ 只在没有 pnpm 或需要完全手工控制时才用。请**不要在 `~/.dsh/profiles` 根目录直接 `npm install`**(该目录没有 package.json,npm 会把整个 node_modules 当残留清掉)。
123
+
124
+ **B1. 用 pnpm 但不用 `dsh plugin`:**
125
+
126
+ ```bash
127
+ cd ~/.dsh/profiles/web
128
+ pnpm add @feiyang666/dsh-usage-plugin
129
+ # 然后手动把插件行加进 web/cordis.patch.yml(见 B3),再重启
130
+ ```
131
+
132
+ **B2. 或用 npm:** 在 profile 目录先补一个最小 package.json 再装:
133
+
134
+ ```bash
135
+ cd ~/.dsh/profiles/web
136
+ # 若该目录还没有 package.json(用 dsh plugin 初始化过才会有):
137
+ # echo '{"name":"dsh-profile-web","private":true,"dependencies":{}}' > package.json
138
+ npm install @feiyang666/dsh-usage-plugin
139
+ ```
140
+
141
+ **B3. 接线(只需做一次,幂等):** 在 `~/.dsh/profiles/web/cordis.patch.yml` 末尾追加:
142
+
143
+ ```yaml
144
+ - insert:
145
+ - id: usage-plugin
146
+ name: '@feiyang666/dsh-usage-plugin'
147
+ inject:
148
+ - fs
149
+ - webServer
150
+ - subprocess
151
+ - credentials
152
+ - sandboxPolicy
153
+ - agents
154
+ ```
155
+
156
+ 也可以直接跑包内的接线脚本(自动找 profile 并追加,幂等):
157
+
158
+ ```bash
159
+ node node_modules/@feiyang666/dsh-usage-plugin/scripts/wire.js
160
+ ```
161
+
162
+ > ⚠️ 行上的 `inject` 列表**不能省略**:它让 Cordis 等到 `fs` / `webServer` / `subprocess` / `credentials` / `sandboxPolicy` / `agents` 服务就绪后再激活插件。缺了它,`/usage/api` 路由不会注册,面板会报 `Unexpected end of JSON input`。
163
+
164
+ ### 3. 方法 C:桌面应用
165
+
166
+ 桌面版(如 [DeepSeek Harness 桌面版](https://github.com/feiyang-dev/DeepSeek-Harness-Desktop))底层就是同一个 `~/.dsh/profiles`。在任意终端执行方法 A 的命令即可,装完重启应用;应用内启动的是同一个 `dsh web`,插件自动生效。
167
+
168
+ ### 4. 重启并验证
169
+
170
+ 重启 DeepSeek Harness 的 web 应用(命令行:结束旧进程后重新运行 `dsh web`;桌面应用:完全退出后重新打开)。然后:
171
+
172
+ - 刷新 http://127.0.0.1:3080 ,顶部「对话」「轨迹」之后会出现 **「用量与消耗」** 和 **「剩余余额查询」** 两个 tab;设置里也有对应入口。
173
+ - 「用量与消耗」面板内含 **概览 / 用量日历 / 缓存命中列表 / 价格表** 四个子页签。
174
+ - 发一条消息后,「用量与消耗」面板应出现本次调用的 token / 消耗记录。
175
+
176
+ ### 5. 配置(余额查询需要)
177
+
178
+ 「剩余余额查询」使用当前配置的 `DEEPSEEK_API_KEY`:在 **设置 → 模型** 中配置 API Key(与跑对话用的同一个 key),然后打开「剩余余额查询」tab 点「查询余额」。
179
+
180
+ ---
181
+
182
+ ## 卸载
183
+
184
+ ```bash
185
+ dsh plugin --profile web remove @feiyang666/dsh-usage-plugin
186
+ ```
187
+
188
+ (等价于 pnpm remove;`dsh plugin` 会自动把包名从 `dsh.profile.bundles` 层列表里移除。)然后重启应用即可。
189
+
190
+ 手工安装的(方法 B),反向操作:删除 `cordis.patch.yml` 里的 `usage-plugin` 行,再 `pnpm remove` / `npm uninstall` 该包,重启。
191
+
192
+ > 从 1.0.x 手工接线版升级到 1.1.x 时:先删掉旧 `cordis.patch.yml` 里的 `usage-plugin` 行(或整体按卸载流程走一遍),再按方法 A 重装,避免同一插件被挂载两次。
193
+
194
+ ---
195
+
196
+ ## 数据与位置
197
+
198
+ - 数据文件:`<会话工作区>/dsh-usage/usage-records.json`
199
+ - 价格配置(面板内编辑后保存):`<会话工作区>/dsh-usage/pricing.json`
200
+ - 导出目录(默认):`<会话工作区>/dsh-usage/{csv,json,images}/`
201
+ - 自定义导出目录:在面板「导出目标目录」里填写或点「选择目录…」
202
+ - 启动诊断日志(若插件激活失败):会话工作区下的 `dsh-usage-boot.log`
203
+
204
+ ---
205
+
206
+ ## 常见问题
207
+
208
+ | 现象 | 原因 / 处理 |
209
+ | --- | --- |
210
+ | 面板报 `Unexpected end of JSON input` | 插件行缺少 `inject` 列表,路由未注册。按方法 B3 补上 inject 后重启 |
211
+ | 面板一直空白 / 顶部无 tab | 插件未激活。看会话工作区 `dsh-usage-boot.log`;确认 `cordis.patch.yml` 里的行存在且 `name` 正确 |
212
+ | 余额查询失败「未配置 DEEPSEEK_API_KEY」 | 在 设置 → 模型 里配置 API Key |
213
+ | 余额查询失败网络错误 | 确认能访问 `api.deepseek.com`(国内网络请配置代理) |
214
+ | `dsh plugin` 报 pnpm not found | 安装 pnpm:`npm install -g pnpm` |
215
+ | 安装时连不上 npm 官方源 | 配置镜像:`npm config set registry https://registry.npmmirror.com`(或对 pnpm 设 `pnpm config set registry ...`)后再执行安装命令 |
216
+ | 卸载后仍报 `Cannot find package '@feiyang666/...'` | profile 里残留了包引用。删掉 `cordis.patch.yml` 中对应行与 `dsh.profile.bundles` 里的包名,重启 |
217
+
218
+ ---
219
+
220
+ ## 发布到 npm(给维护者)
221
+
222
+ ```bash
223
+ npm login # 用你自己的 npm 账号
224
+ npm run check # 发布前自检(prepublishOnly 也会自动跑)
225
+ npm pack # 检查 tarball 内容
226
+ npm publish --access public # 作用域包必须 --access public
227
+ ```
228
+
229
+ > 发布到公共 npm 会公开源码,请确认包内无敏感信息(API Key 等只在运行时由用户配置)。
230
+ > 本机网络若连不上 `registry.npmjs.org`,发布前用 `npm config set registry https://registry.npmjs.org`(包内 `.npmrc` 已预置该 registry)。
231
+
232
+ ---
233
+
234
+ ## 相关项目
235
+
236
+ | 项目 | 说明 | 安装方式 |
237
+ | --- | --- | --- |
238
+ | [DeepSeek Harness 桌面版](https://github.com/feiyang-dev/DeepSeek-Harness-Desktop) | Windows 桌面控制台:一键安装/启动/停止/重启 dsh web 服务,内置插件管理,**推荐插件区一键安装本插件** | 下载桌面版,点几下即可 |
239
+ | [数据保险箱(dsh-vault)](https://github.com/feiyang-dev/dsh-vault) | 自动备份 / 清空检测 / 一键恢复,保护聊天记录与工作区数据 | 桌面端一键安装,或 `dsh plugin add @feiyang666/dsh-vault` |
240
+ | [DeepSeek-Harness](https://github.com/deepseek-ai/DeepSeek-Harness) | 官方 CLI / Web 服务 | 见下方「运行 DeepSeek Harness」 |
241
+
242
+ ### 运行 DeepSeek Harness
243
+
244
+ **快速安装(通过 npm)**
245
+
246
+ 安装 Node.js,然后运行:
247
+
248
+ ```bash
249
+ npx @deepseek-ai/dsh web
250
+ ```
251
+
252
+ 该命令会启动 Web UI,默认地址为 http://127.0.0.1:3080。详见 [Web UI 指南](https://github.com/deepseek-ai/DeepSeek-Harness)。
253
+
254
+ **从源码运行**
255
+
256
+ 如需从仓库源码运行:
257
+
258
+ ```bash
259
+ git clone https://github.com/deepseek-ai/deepseek-harness.git
260
+ cd deepseek-harness
261
+ pnpm install
262
+ pnpm run build
263
+ pnpm dsh web
264
+ ```
265
+
266
+ ## 致谢
267
+
268
+ - **[@liu3734](https://github.com/liu3734)**:报告并定位 macOS(POSIX)下路径处理与 spawn 的 Windows 专用问题,提出跨平台修复方案([#1](https://github.com/feiyang-dev/dsh-usage-plugin/issues/1))。
269
+
270
+ ## 许可
271
+
272
+ MIT © dsh-usage-plugin
@@ -0,0 +1,22 @@
1
+ # dsh-usage-plugin — bundle patch layer.
2
+ #
3
+ # This file is the package's `dsh.bundle.patch` layer. When the package is
4
+ # installed into a DSH profile (via `dsh plugin --profile <name> add
5
+ # @feiyang666/dsh-usage-plugin`, or manually), the loader applies this
6
+ # patch over the profile's empty root entry list, mounting the plugin row.
7
+ #
8
+ # The `inject` list is REQUIRED: it tells the Cordis loader to wait until the
9
+ # fs / webServer / subprocess / credentials / sandboxPolicy / agents services
10
+ # are ready before activating the plugin. Without it the plugin's `apply` may
11
+ # run before those services exist, the `/usage/api` route never registers, and
12
+ # the client panel fails with `Unexpected end of JSON input`.
13
+ - insert:
14
+ - id: usage-plugin
15
+ name: '@feiyang666/dsh-usage-plugin'
16
+ inject:
17
+ - fs
18
+ - webServer
19
+ - subprocess
20
+ - credentials
21
+ - sandboxPolicy
22
+ - agents