Skip to main content
B

dsh-plugin-usage

bennett-dsh/dsh-plugin-usage

A usage and reference-cost panel for DeepSeek Harness with today, 7-day, 30-day, all-time and custom ranges aggregated by hour or day; a model filter and a per-model breakdown of requests, input and output tokens, cache, reference cost and share; a model-share card showing the top four models by total tokens with the rest grouped as others; a configurable per-million-token price table seeded with DeepSeek's prices, with reference cost switchable between ¥ and $ at a fixed 1 USD = 7 CNY; and a yearly heatmap drawn only with theme variables, with no third-party chart library.

Install

dsh plugin --profile web add github:bennett-dsh/dsh-plugin-usage

README

dsh-plugin-usage

DeepSeek Harness 的 Token 用量统计插件:按天 / 自定义范围查看 Token、调用次数与成本,支持模型筛选、定价配置和年度热力图。

Token usage statistics for DeepSeek Harness.

用量统计 明细与热力图

功能

  • 今日 / 近 7 天 / 近 30 天 / 全部 / 自定义范围(不限跨度),按小时·天聚合
  • 模型筛选、按模型明细(请求数、输入/输出、缓存、成本、占比)
  • KPI 网格里的「模型占比」卡:按总 Token 显示前 4 个模型与「其它」
  • 参考成本可在 ¥ / $ 之间切换(固定汇率 1 USD = 7 CNY,宿主侧折算)
  • 可配置的每百万 Token 价格表(内置 DeepSeek 常见模型默认价)
  • 年度热力图;深/浅色自适应,只用 DSH 主题变量,无第三方图表库
  • 输入区成本 pill:composer 旁显示「今日 ¥x.xx」(今日无调用时不占位),title 带调用次数与 Token;币种跟随设置页的 ¥/$ 选择

安装

插件已发布到 npm:dsh-plugin-usage。

  • DSH Desktop:设置 → 插件 → 添加插件,输入 dsh-plugin-usage
  • Web / CLI profile:dsh plugin --profile <name> add dsh-plugin-usage,重启生效

升级同理(桌面端在插件页点更新,CLI 用 update)。

desktop profile 由 Electron 应用独占,不能用 dsh plugin --profile desktop 操作。

配置

设置 → 插件 → dsh-plugin-usage 可改 currency 和 prices(每百万 Token 价格),写入 profile patch,重启保留。 currency 是默认显示币种;仪表盘上参考成本卡里的 ¥ / $ 切换只影响当前界面(同浏览器记住选择)。

价格优先匹配 provider/model,其次裸 model;未配置的模型标为「未定价」,成本记 0。

数据来源与口径

输入区 pill 与设置页共用同一条 usage/query 通道,口径一致(今日 00:00 → 现在,按记录里的 provider/model 逐条计价)。它不看官方 tokenUsage 投影:那个投影只有会话内合计、不带模型归因,用来算钱会把不同单价混成一个数。口径是「今日」而不是「本会话」——宿主渲染 conversation.composer.dock 时不传 props,dock 条目拿不到会话标识。

折叠 DSH 会话日志中已持久化的用量事件,不自己记日志:

  • 读取走官方接口:活跃会话 snapshotEvents(),历史会话 sessionPersistence.open/read,按 revision 跳过未变日志
  • 计费对齐官方 tokenUsage 投影:同一 (turn, step) 替换;llm/retry-started 后的重试累加;assistant/attempt 的 stream 用量也计入
  • fork 会话按 inheritedEventCount 跳过父会话前缀,不重复计费
  • 费用 = Σ(各 Token 分桶 × 对应单价) / 1e6
  • 价目表以美元 / 百万 Token 为基准(与 DeepSeek 官方价一致);显示 ¥ 时按固定 7:1 折算,价目表本身不改写

兼容性

  • DSH >=0.2.0-rc.2 <0.3.0(engines.dsh),Node ≥ 22
  • 更早的宿主保留 Session.events / readFrom 回退路径

开发

npm install
npm run build   # tsc → lib/,再生成 lib/client/index.js
npm test        # node --test

CI 跑 install → build → test → bundle id 契约 → tarball 内容检查;推 v* tag 会校验版本、构建测试并创建 GitHub Release。

src/host/    宿主:scan / fold / query / settings / aggregate / rpc
src/client/  设置页「用量统计」仪表盘(纯 JS,样式内联)
scripts/     构建客户端 bundle 入口

开发期也可用 --patch 从源码加载:dsh web --patch cordis.yml(路径见 cordis.yml)。

License

MIT

Related plugins