前言¶
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。sessionCostprojection 通過和tokenUsage/sessionStats相同的 seam 提供,會出現在 projection carriers 中,例如 history tail page 和session/projectionpush frames。- 社區目錄是獨立站點,與 DeepSeek / 幻方無官方從屬關係。
鏈接¶
- 目錄頁:https://www.skillhub.cn/plugins/Sttrevens/dsh-cost-meter
- GitHub:https://github.com/Sttrevens/dsh-cost-meter