@steven-wu/dsh-cost-meter:在 DSH Web UI 中显示实时美元成本角标

前言

DSH 的扩展方式是「一切皆插件」。社区目录是独立站点,与 DeepSeek / 幻方无官方从属关系。对使用 DSH Web UI 的开发者来说,provider 通常返回 token usage,但不会直接给出当前会话和单轮请求的美元成本。@steven-wu/dsh-cost-meter 解决的是这个映射问题:把 provider-reported usage 按可配置价格表累计,并在 Web UI 的会话中显示实时成本角标。

这是什么

@steven-wu/dsh-cost-meter 是一个 DSH 插件,用于在当前打开的 Web UI 会话中显示实时 USD 成本角标。它根据 provider token usage 和可配置价格表计算成本,支持整个会话总额和按 turn 的成本。插件声明 dsh.bundle 清单和 dsh.client 包,许可证为 MIT。

核心功能

成本累计

插件在 session-projection seam 上注册 sessionCost projection。它会从 request/header 事件跟踪当前 provider/model,并累计 provider 报告的 usage buckets:uncached input、output、cache-read、cache-write。

它沿用 token-meter 的规则:对同一个 (turn, step) 样本做替换,而不是重复计数。最终输出 whole-session totals,以及以 turn number 为键的 byTurn map。

UI 展示

插件在 conversation.chat.assistant-actions slot 中注册 badge。这个 slot 位于每条 assistant 消息末尾的动作行。每个 badge 显示该 turn 的成本;hover 时打开 tooltip,展示按 usage bucket 的 breakdown,以及 session total。

价格配置

价格表使用 USD per million tokens,key 为 provider/model。插件支持通过以下位置配置:

~/.dsh/cost-pricing.json
DSH_COST_PRICING
row's config.pricingPath

如果某个模型没有 models entry,会 fallback 到 default;如果不存在 default,成本按 0 计。

安装与启用

安装到 web profile:

dsh plugin --profile web add @steven-wu/dsh-cost-meter

安装后重启 web profile,然后刷新页面。

开发时使用本地 checkout:

dsh plugin --profile web add file:/path/to/dsh-cost-meter

Settings 中的 Plugins 面板是只读的,用于 inventory + config cards;安装仍然通过 dsh plugin --profile … add 完成。

另外,purely-cordis mounting 也可以通过 cordis.patch.yml insert row 完成;插件自带的 cordis.patch.yml 中保存了该行。

典型用法

1、首次运行时,插件在 boot 阶段读取 ~/.dsh/cost-pricing.json,并会把默认价格表写到该路径。

2、编辑该价格表,按 provider/model 维护 USD per million tokens 价格,然后重启 dsh web 使配置生效。

3、如需覆盖默认路径,可以使用环境变量:

DSH_COST_PRICING=/path/to/cost-pricing.json

也可以在 row 的 config.pricingPath 中指定路径。

4、在 Web UI 中打开会话,assistant 消息末尾会出现成本 badge;hover badge 可查看该 turn 的 breakdown 和 session total。

适用场景与注意

适合使用 DSH Web UI,并希望把 provider token usage 转成 USD 成本的人。典型需求包括:查看当前会话的累计成本、查看单个 assistant turn 的成本、按 provider/model 自定义价格表。

安装前请注意:

  • 插件以当前 dsh 进程权限运行,安装前应检查源码、依赖和许可证。
  • @deepseek-ai/dsh-* 应作为 peerDependencies 从 harness 解析,而不是作为 dependencies 装入 profile;否则可能 shadow harness copy,并可能拉取 stale dist-tag。
  • sessionCost projection 通过和 tokenUsage / sessionStats 相同的 seam 提供,会出现在 projection carriers 中,例如 history tail page 和 session/projection push frames。
  • 社区目录是独立站点,与 DeepSeek / 幻方无官方从属关系。

链接

  • 目录页:https://www.skillhub.cn/plugins/Sttrevens/dsh-cost-meter
  • GitHub:https://github.com/Sttrevens/dsh-cost-meter
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye