Turbo-Harry
dsh-status-balance
No description
- Stars
- 0
- Language
- JavaScript
- Created
- Aug 15, 2026
- Updated
- Aug 15, 2026
Introduction
dsh-status-balance
DeepSeek Harness 的树外(out-of-tree)双面插件:在 右下角 显示 DeepSeek API 账户余额。
- host 半身(
lib/index.js):读取DEEPSEEK_API_KEY,调GET https://api.deepseek.com/user/balance,缓存结果;一方面ctx.emit("balance/updated", …)推给所有客户端,另一方面注册只读的/status-balance拉取端点。 - client 半身(
lib/client.js):往 frame 级shell.overlay槽注册一个小角标;挂载时先fetch("/status-balance")秒出首屏,再订阅balance/updated实时刷新。
架构要点(为什么是这样)
- 密钥只在 host 侧:余额接口要
Bearer密钥,浏览器绝不能碰。host 半身零 import(credentialRef运行时是恒等函数,直接用字符串"DEEPSEEK_API_KEY")。 - 推送 + 拉取双通道:实时更新走 forwarded-event(host
ctx.emit("balance/updated")→dsh-host-apiproxy转发循环 → 客户端ctx.remote.$on,需第 1 步的 allowlist);首屏秒出走只读 HTTP 端点/status-balance(host 用ctx.webServer.register注册,client 挂载时fetch一次)。 - 右下角 =
shell.overlay槽:dsh-client-ui-layout把它渲染进一个position:absolute; inset:0; z-index:20的浮层,角标用绝对定位钉在right:16px; bottom:16px。
安装(4 步)
1. 把 balance/updated 加进转发 allowlist
编辑 @deepseek-ai/dsh-api-remotes/lib/index.js,在 API_REMOTE_FORWARDED_EVENTS 数组里加一行:
const API_REMOTE_FORWARDED_EVENTS = [
"agent-preset/selected",
// ...
"settings/document-updated",
"balance/updated" // ← 新增
];
该文件位于(本机):
/Users/wuhai/.nvm/versions/node/v22.19.0/lib/node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai/dsh-api-remotes/lib/index.js
注:这是对第一方包的单点改动,重装 DSH 会被覆盖;客户端
$on无运行时 allowlist 校验,所以只改这一处 host 文件即可。
2. 把本包装进 web profile
dsh plugin --profile web add "file:/Users/wuhai/Desktop/untitled folder/dsh-status-balance"
(等价于在 ~/.dsh/profiles/web 里 pnpm add file:...。)
3. 注册到 ~/.dsh/profiles/web/cordis.patch.yml
把 [] 替换为:
- insert:
- id: status-balance
name: 'dsh-status-balance'
单行 name 决定 host 行;包内的 dsh.client 字段同时把它登记进浏览器 roster。
4. 重启 web 并刷新
dsh web # 或 dsh --profile web
打开 http://127.0.0.1:3080 刷新,右下角应出现「余额 ¥98.22」(数字按你的账户)。未配置 key 时显示「未配置 API Key」,网络失败显示「获取失败」。
验证数据层(可选,不启动 DSH)
node scripts/test-balance.mjs
只打印余额 JSON,不打印密钥。
配置
改 lib/index.js 顶部的常量:
POLL_INTERVAL_MS:轮询间隔(默认 30s)API_KEY_REF:凭证引用名(默认DEEPSEEK_API_KEY)
改 lib/client.js 顶部的常量:
LOW_BALANCE_THRESHOLD:低余额提醒阈值(默认10,单位同币种)LOW_BALANCE_CURRENCY:按哪个币种判断(默认"CNY")
当对应币种的 total_balance 低于阈值时,角标变为琥珀色并脉冲闪烁,显示「⚠ 余额不足 ¥xx」;首次跌破阈值时还会在页面顶部弹一条一次性提示。鼠标悬停角标显示「余额低于 ¥10,请及时充值」。
密钥存在 ~/.dsh/.credentials.yaml,或走 DEEPSEEK_API_KEY 环境变量(dsh-credentials-local 会继承环境)。