DSH HUB
HomePlugin StorePlugin PacksCommunityRankingsResourcesPublish Guide
Plugin source
Back to catalog

YuGaN525 /

YuGaN525/DSH-token-admin

Verified

DSH plugin: show per-turn token usage, estimated cost, and DeepSeek balance under every completed turn.

★ 0 Stars0 Forks0 IssuesN/A Community rating0 Confirmed installs
View on GitHub
READMESource: main@6b0b8287

DSH Token Admin

dsh-turn-cost — 在 DSH 每条已完成的对话下方显示 本轮 token 用量、估算费用、当前余额。

每轮页脚示例

1.23M tok · 输入 45.6k 输出 12.3k 缓存 98% · 本轮 ≈¥0.087 · 余额 ¥42.00

仓库名为 DSH-token-admin;插件包名与加载名仍为 dsh-turn-cost,安装命令和配置项都使用后者。

GitHub: https://github.com/YuGaN525/DSH-token-admin

鼠标悬停可看到完整明细:未缓存输入、缓存读取/写入、输出(含推理)、缓存命中率、模型、峰/谷计价、单价、余额更新时间。

功能

  • 每轮独立:利用 ui-chat 已经写入 Turn 数据的 turn-tail.tokenUsage,按轮显示,不改动、不重算官方用量。
  • 费用估算:按 token 桶 × DeepSeek 官方价目计算;自动识别峰时/谷时、周末与法定节假日。
  • 余额:优先走 DSH 账号服务 deepseekAccount.getBalance(充值钱包 + 赠金钱包),没有账号服务时回退 DEEPSEEK_API_KEY 调用 /user/balance。密钥不落日志、不下发浏览器。
  • 历史轮次:已完成的历史对话同样显示每轮 token 与费用。余额是最近一次查询结果,不是历史快照。
  • 失败开放:余额读取失败只显示 余额 —,费用照常;价目或路由不可用时显示 本轮 —,不会影响 Chat 本身。
  • 主题适配:使用 DSH 主题变量,深浅色自动跟随;无动画、无额外依赖。

数据从哪来

数据 来源
每轮 token ui-chat turn-tail 数据中的精确 tokenUsage(未缓存输入 / 缓存读取 / 缓存写入 / 输出 / 推理 / 合计 / 路由)
费用 浏览器半边用 host 下发的价目表计算
余额 DSH deepseekAccount.getBalance,或 DEEPSEEK_API_KEY → https://api.deepseek.com/user/balance
价目 内置 DeepSeek 官方 CNY 价目(2026-09-10 起),可通过配置覆盖

安装

方式 A:DSH 插件管理器

让 DSH 会话执行:

plugin_manager(action: "install_bundle", target: "<本目录绝对路径>")

方式 B:desktop profile 手动安装(本机当前方式)

pwsh -File install.ps1

脚本会备份 profile 的 package.json、添加 link: 依赖、把 dsh-turn-cost 加入 dsh.profile.bundles,并在 profile 的 node_modules 下建 junction。

之后 完全退出并重新打开 DSH Desktop 才会加载新的 bundle。卸载:

pwsh -File install.ps1 -Uninstall

配置

配置写在 cordis.patch.yml 的 config:,或安装后的 profile patch 里(按 id dsh-turn-cost 覆盖)。

键 默认 说明
refreshSeconds 30 余额缓存时间(秒),也是浏览器刷新余额的 TTL
balanceSource auto auto = 先账号后 API key;account / apikey 强制单路
pricing.currency CNY 费用显示币种;余额按接口返回币种单独显示
pricing.peakMultiplier 2 峰时价格倍率
pricing.peakWindows [[540,720],[840,1080]] 峰时窗口(当地分钟数,09:00–12:00、14:00–18:00)
pricing.weekendValley true 周末按谷时计价
pricing.holidays 2026 法定节假日 节假日全天谷时;每年安排公布后补下一年的日期
pricing.timeZone Asia/Shanghai 判断峰谷用的 IANA 时区
pricing.defaultModel flash 未匹配到模型时使用的价位
pricing.models flash / pro 两档 每档 cacheHit、cacheMiss、output,单位为 元/百万 token

覆盖示例:

- id: dsh-turn-cost
  config:
    refreshSeconds: 60
    pricing:
      models:
        flash:
          cacheHit: 0.02
          cacheMiss: 1
          output: 4
        pro:
          cacheHit: 0.15
          cacheMiss: 4.5
          output: 13.5

只写一个字段也会与默认值合并,例如只改 flash.cacheHit 不会把 cacheMiss / output 清零。

计费口径

费用 = (未缓存输入 × cacheMiss + 缓存读取 × cacheHit + 缓存写入 × cacheMiss + 输出 × output) / 1,000,000 × 峰时倍率
  • reasoningTokens 已包含在 outputTokens 中,不重复计费。
  • 一次 Turn 内有多个模型路由时,按首个模型价格估算,并在 tooltip 标注“多模型路由”。
  • 费用是估算值,实际账单以 DeepSeek 账单为准;余额是最近一次查询结果。

限制

  • 余额是当前值:历史轮次也显示最近一次查询余额,不是该轮结束时的余额。若需要严格的逐轮余额快照,可再扩展宿主侧记账。
  • 只在 Web/Desktop 客户端显示:插件通过 conversation.chat.turnTail 插槽渲染;TUI/headless 不加载客户端半边。
  • 需要精确用量:ui-chat 只有在已加载窗口包含 turn/start 且每次模型尝试都报告完整用量时才提供 tokenUsage;不完整时页脚自动隐藏。
  • 价目需要维护:DeepSeek 调整价格或发布下一年节假日安排后,更新 pricing 配置或 lib/index.js 的 DEFAULT_PRICING。
  • 余额接口:只支持 DSH DeepSeek 账号与 DeepSeek API key;使用其他提供方时 token/费用仍可显示,但余额可能为 —。

开发与测试

node test/host.test.mjs
node test/client.test.mjs

测试使用 Node 内置模块与一个极简 React 桩,不需要安装依赖。

文件

  • lib/index.js — 宿主:余额、价目、/dsh-turn-cost/state.json 路由、同源/连接栅栏。
  • lib/client.js — 浏览器:conversation.chat.turnTail 页脚、费用计算、状态缓存。
  • cordis.patch.yml — bundle 挂载声明。
  • install.ps1 / install.cmd — desktop profile 安装器。

License

MIT

—/ 5

No ratings yet

Verified DSH bundle

Commit 6b0b8287c5f3

Community comments

No comments yet. Be the first to write one.

DSH HUB

A community index for DSH plugins. Not an official GitHub or DeepSeek AI product.

CommunityResourcesAPIAbout