Adachi-Hougetsu
dsh-api-tools
dsh API usage metering and one-click refresh plugins for DeepSeek Harness
- Stars
- 0
- Language
- JavaScript
- Created
- Aug 15, 2026
- Updated
- Aug 15, 2026
Introduction
dsh-api-tools
为 DeepSeek Harness(dsh)Web 界面打造的两个实用插件:
- API 用量统计(dsh-api-meter + dsh-ui-api-meter)——按模型、按对话统计 token 用量
- 一键刷新(dsh-refresh + dsh-ui-refresh)——设置面板里的灰色刷新按钮,重启 dsh web
截图提示:可自行将面板截图放入
docs/api-meter.png后显示在这里。
功能
API 用量统计
- 侧边栏底部入口,点击打开大窗口
- 顶部四项总量:总 Tokens、缓存命中率、调用次数、推理 Tokens
- 每日堆叠柱状图(x 轴日期):未命中输入(蓝)/ 输出(深蓝)/ 缓存命中(浅蓝),可切换 7 / 14 / 30 天 / 全部
- 按模型分类、按对话(会话)明细(点击展开该会话的模型用量)
- 数据每 5 秒自动刷新
一键刷新
- 设置面板内容列头部(关闭按钮旁)的小圆形刷新按钮
- 点击确认后自动重启 dsh web(约 30 秒),无需手动操作终端
安装
git clone https://github.com/Adachi-Hougetsu/dsh-api-tools.git
cd dsh-api-tools
# 逐个安装四个插件包(顺序:先 host 再 UI)
dsh plugin --profile web add ./dsh-api-meter
dsh plugin --profile web add ./dsh-ui-api-meter
dsh plugin --profile web add ./dsh-refresh
dsh plugin --profile web add ./dsh-ui-refresh
--profile web换成你实际使用的 profile 名;没有指定过 profile 时,默认 web 界面使用web。
使用
安装后重启 dsh web:
- 侧边栏底部出现「API 用量」图标 → 点击打开用量面板
- 打开「设置」→ 内容列头部(右上角)出现灰色圆形刷新按钮 → 点击刷新
历史数据自动回算
插件升级前(旧版本没有按会话统计)的调用记录,会在首次启动时自动回算:
-
自动读取
~/.dsh/sessions下的会话日志,重建按会话的用量明细 -
无需任何手动操作,日志里会显示
backfilled N historical calls -
如果你希望强制重建,可以手动运行:
node dsh-api-meter/scripts/backfill-sessions.mjs(需 dsh web 处于停止状态;脚本会先备份现有
usage.json)
配置
插件数据保存在 ~/.dsh/storages/api-meter/usage.json,可在 profile 的 cordis.patch.yml 中覆盖:
- id: api-meter
config:
persistIntervalMs: 30000 # 快照保存间隔(毫秒),0 关闭定时保存
persistPath: 'C:\path\to\usage.json' # 快照文件路径
sessionsRoot: 'C:\path\to\sessions' # 会话日志目录(回算用)
- id: refresh
config:
dshCmd: 'C:\path\to\dsh.cmd' # dsh CLI 路径(重启用)
killDelayMs: 800 # 响应后退出延迟
卸载
dsh plugin --profile web remove dsh-ui-refresh
dsh plugin --profile web remove dsh-refresh
dsh plugin --profile web remove dsh-ui-api-meter
dsh plugin --profile web remove dsh-api-meter
常见问题
重启后历史会话数据没出现? 确认 dsh web 完整重启过一次(首次启动时自动回算),并检查日志中是否有 api-meter: backfilled 字样。
总量与会话明细数字不一致? 总量按 provider/model 统计,会话明细按对话统计;同一调用会计入两者,但旧版本无会话信息的调用只计入总量。
刷新按钮点击后页面没反应? 确认 dsh-refresh 已安装且 dshCmd 指向正确的 dsh CLI 路径(见配置)。