← 返回列表
D

dsh-token-budget

v0.1.1 · 4 天前发布

DSH plugin bundle: cumulative token usage, cache-hit rate, and per-model/per-period estimated cost, with a live session-header badge

dshdsh-plugindeepseek-harnesstokencostusage

README

dsh-token-budget — DSH 自定义插件示例

一个完整的 DSH(DeepSeek Harness)自定义插件:统计每个会话的累计 token
用量(K/M 紧凑格式)、缓存命中率、当前模型,并按模型单价估算花费。
同时作为"如何写 DSH 插件"的参考实现。

它做了什么

1. 注册一个会话投影单元 tokenCost:从会话日志的 assistant/message
事件(携带 provider 上报的 usage)折叠出全日志总量
(输入/输出/缓存读/缓存写 token + 估算金额 + 缓存命中率 + 模型)。
Web UI 通过投影通道实时读取(事件推送,无需刷新页面)。
2. 注册一个模型工具 token_cost_report:agent 自己可以调用它查询当前
会话的用量、命中率、模型与金额(从持久化日志尾部重放,无插件可变状态)。
3. 双面 UI 半区(lib/client.js:把花费徽标注册进会话头部
conversation.session.header.actions 插槽,显示如
19.2M tokens · 缓存命中 98% · ≈0.91 CNY

按模型计价

request/context 事件在模型切换时记录 provider/model;投影按事件顺序
fold,每条请求的用量增量用当时生效的模型单价计价后累加——会话中途
切换模型,后续请求自动用新价格,历史请求保持原价,与真实账单一致。

文件结构

```
dsh-token-cost/
├── package.json # 包元数据 + 依赖 + dsh.client 双面声明
├── UI-SLOTS.

版本兼容矩阵

DSH 版本状态说明
dsh@0.1.0-rc.6 ✅ 兼容 cordis patch ✅
dsh@0.1.0 ✅ 兼容 标准 patch ✅
dsh@0.2.0 ⚠️ 待验证 待实测(API 可能在变)
dsh@0.3.0+ ❓ 未知 尚未发布

💡 兼容矩阵每周末自动跑实测,欢迎 PR 修正

元数据

License
MIT
npm
dsh-token-budget
Repo
Engines
{}
Weekly DL
0
Monthly DL
0
dsh.bundle
{"bundle":{"patch":"./cordis.patch.yml"},"client":{"inject":["@deepseek-ai/dsh-client-locale","@deepseek-ai/dsh-client-runtime","@deepseek-ai/dsh-client-ui-conversation"],"platform":"web"}}