dsh-balance-sidebar
DeepSeek Harness 插件:实时显示 DeepSeek API 账户余额。
- 侧边栏"设置"上方一行:
● DeepSeek ¥x.xx + 更新时间 + ↻ 立即刷新(收起侧边栏时显示数值,点击即刷新)
- 设置 → 插件 → 可配置插件:余额明细卡片(总余额 / 充值 / 赠金 / 可用 / 更新时间)
- 每 25 秒自动刷新(Host 另有 20 秒缓存)
- API Key 不出本机:复用 Harness 已配置的凭据(
llm-deepseek 设置 → DEEPSEEK_API_KEY 凭据库),浏览器只访问同源路由 /dsh-balance
安装
从 npm(发布后)
dsh plugin --profile web add dsh-balance-sidebar
从源码 / 本地目录
dsh plugin --profile web add ./dsh-balance # 相对路径以调用目录为锚点
# 或 file: 形式
dsh plugin --profile web add "file:D:/path/to/dsh-balance"
安装后重启 dsh web 即生效(dsh.bundle.patch 声明会自动把本插件的 cordis.patch.yml 并入 profile 层栈)。
卸载
dsh plugin --profile web remove dsh-balance-sidebar
依赖要求
| 依赖 | 说明 |
|---|
| DeepSeek Harness | >= 0.1.0-rc.5(Web profile) |
| 凭据 | ~/.dsh/.credentials.yaml 中的 DEEPSEEK_API_KEY,或 llm-deepseek 设置里配置的 Key / apiKeyEnv |
| Windows | 查询走 pwsh(Invoke-WebRequest,自动使用系统代理) |
| ui-sidebar 补丁(可选) | 侧边栏"余额独占一行"依赖新插槽 sidebar.footer.extra。当前上游 ui-sidebar 没有该插槽,需要应用仓库内的 ui-sidebar-extra-slot.patch: |
# 在 deepseek-harness checkout 根目录
git apply /path/to/dsh-balance/ui-sidebar-extra-slot.patch
pnpm --filter @deepseek-ai/dsh-client-ui-sidebar run bundle
不打补丁也不影响使用:设置 → 插件 里的余额卡片(settings.plugin.item)在任何版本都可用;只是侧边栏那行不会出现(slots.inject 会安静等待插槽声明)。
工作原理
浏览器 (client 半区) Node 进程 (host 半区)
┌─────────────────────┐ fetch ┌──────────────────────────────┐
│ 侧边栏行 + 设置卡片 │ ──────────▶ │ GET /dsh-balance?force=1 │
│ 每 25s 轮询 │ ◀────────── │ 凭据(settings+credentials) │
└─────────────────────┘ JSON │ → pwsh Invoke-WebRequest │
│ → api.deepseek.com/user/balance│
│ 20s 缓存 │
└──────────────────────────────┘
为什么不用 dsh 的 shell(沙箱)通道:Windows ACL 受限令牌下 Windows 安全包无法完成 TLS 握手(SEC_E_NO_CREDENTIALS),沙箱内 HTTPS 请求必然失败。因此直接使用无沙箱的 subprocess 通道,这不会降低安全性——API Key 仍在 Host 侧,浏览器不可见。
开发
npm install # 安装 tsdown
npm run bundle # 产出 lib/index.js(host)+ lib/client.js(client)
发布
# 1. 建 GitHub 仓库,并给仓库添加 dsh-plugin 话题(方便在
# https://github.com/topics/dsh-plugin 被发现)
# 2. 把 package.json 里的 repository / author 填好
npm publish # prepublishOnly 会自动执行 bundle
发布后用户即可 dsh plugin --profile web add dsh-balance-sidebar。
License
MIT