DeepSeek Harness 插件

gdy01/dsh-token-cost

Star 数 ★ 0 分类 用量与计费 收录于 2026-08-19

在 DSH Web 侧边栏按项目展示 LLM Token 用量与人民币花费,分别统计输入(未命中)、命中与输出,并按模型标准价格自动计价。

安装

# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)

dsh plugin --profile web add github:gdy01/dsh-token-cost

装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本。请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。

README

一个 DSH 插件:按项目展示 LLM Token 用量,并按模型标准价格自动换算成人民币花费,分为:

  • 输入(未命中) —— 未命中缓存的输入 token
  • 命中 —— 缓存命中的输入 token(cacheReadTokens
  • 输出 —— 输出 token

未知模型会照常列出 token 数,但费用显示为「—」,方便你直接补充价格,无需改代码。

功能

  • 读取本地 DSH 会话日志(~/.dsh/sessions$DSH_HOME/sessions)。
  • 项目(会话 cwd)和模型聚合统计。
  • 在 DSH Web 侧边栏底部增加 💰 按钮;面板展示项目汇总和可展开的模型明细。
  • 零运行时 npm 依赖:使用 Node 自带的 node:zlib Zstandard 解码。
  • HTTP API 仅允许回环访问(/dsh-token-cost/*)。

安装

请安装子目录 dsh-token-cost,不要安装上一级的 dsh plugin 目录。上一级目录没有 package.json,装错不会出现侧边栏按钮。

推荐使用绝对路径(路径里有空格,必须加引号):

dsh plugin --profile web add "file:/Users/dg/Documents/dsh plugin/dsh-token-cost"

或在该目录内执行:

cd /Users/dg/Documents/dsh plugin/dsh-token-cost
dsh plugin --profile web add "file:$PWD"

如果之前装错了 dsh plugin 目录,先卸载再重装:

dsh plugin --profile web remove "dsh plugin"
dsh plugin --profile web add "file:/Users/dg/Documents/dsh plugin/dsh-token-cost"

安装后重启 dsh web 并刷新页面,侧边栏底部会出现 💰 按钮。

也可以直接运行仓库里的安装脚本:

./scripts/install.sh

原理

宿主插件扫描 DSH sessions 目录下的每个 session.jsonl.zstd / session.jsonl,重放:

  • session.cwd → 项目
  • request/header → 当前模型
  • assistant/chunk { type: 'usage' }assistant/message.usage → 输入 / 命中 / 输出 token

同一 (turn, step) 的用量会去重(后面的 assistant/message 会替换之前的 usage chunk),与 DSH 自身 token-meter 的口径一致。

价格表

内置 DeepSeek 官方人民币价格(元 / 百万 tokens):

模型 输入(未命中) 命中 输出
deepseek-chat / deepseek-v4-flash 2 0.5 8
deepseek-reasoner / deepseek-v4-pro 4 1 16

可在 profile 的 cordis.patch.yml 中覆盖(patch 行会替换整个 config,所以需要保留的价格都要写全):

- id: token-cost
  config:
    prices:
      deepseek-chat:
        input: 2
        hit: 0.5
        output: 8
      deepseek-reasoner:
        input: 4
        hit: 1
        output: 16
      deepseek-v4-flash:
        input: 2
        hit: 0.5
        output: 8
      deepseek-v4-pro:
        input: 4
        hit: 1
        output: 16

API

  • GET /dsh-token-cost/api/stats —— 完整的按项目/按模型 JSON
  • GET /dsh-token-cost/api/prices —— 当前价格表
  • GET /dsh-token-cost/healthz —— 存活检查

License

MIT

内容来自项目 README(GitHub)↗

链接

同类插件

查看整个分类 →