Saltar al contenido principal
C

dsh-plugin-token-stat

chenllsu/dsh-plugin-token-stat

DSH plugin: append each answer's token usage to the conversation

Instalar

dsh plugin --profile web add github:chenllsu/dsh-plugin-token-stat

README

dsh-plugin-token-stat

DeepSeek Harness 插件:在每一条 AI 回答上显示本次对话消耗的 token 数。

Show the provider-reported token usage of every assistant answer inside DeepSeek Harness's web UI.

功能 / Features

  • 每条 assistant 回答的操作区显示:⚡ in 12.2K · out 456(含缓存 token 时显示 cache 1.1K
  • 数据来自 LLM 提供方上报的 usage 字段(DeepSeek 等适配器支持时自动生效)
  • 服务端监听 session/eventassistant/message 事件,维护每会话 token 统计
  • 客户端在 conversation.chat.assistant-actions 插槽渲染,不修改消息内容,不影响模型上下文

安装 / Install

dsh plugin --profile web add @choate/dsh-plugin-token-stat

或从源码 link 安装:

dsh plugin --profile web add "dsh-plugin-token-stat@link:/absolute/path/to/dsh-plugin-token-stat"

安装后重启 dsh web,然后随便发一条消息,回答右下角即显示 token 统计。

原理 / How it works

DSH 的事件溯源会话日志中,assistant/message 事件携带 usage: TokenUsageinputTokens / outputTokens / cacheReadTokens)。本插件:

  • 服务端src/index.ts):监听 session/event,捕获每条 assistant/message 的 usage 并做会话级汇总(附 totals() 自省接口)。
  • 客户端client/index.tsx):注册 conversation.chat.assistant-actions 插槽条目,从会话快照的 assistant 节点读取 usage,渲染 token 标注。

开发 / Development

npm install
npm run build     # tsc 编译服务端 + tsdown 打包客户端
npm run typecheck

产物:

  • lib/index.js — 服务端插件(cordis patch 加载)
  • client/client.js — 客户端插件(web ModuleLoader 格式)

发布 / Publish

# 发布到 npm
npm publish

# 提交到 awesome-dsh-plugin 上架插件市场
# https://github.com/awesome-dsh-plugin/awesome-dsh-plugin

许可 / License

MIT

Plugins relacionados