Back to home

r0bert001

dsh-balance-plugin

Deepseek Harness插件,支持实时展示deepseek余额

Stars
0
Language
JavaScript
Created
Aug 15, 2026
Updated
Aug 15, 2026

Introduction

dsh-model-balance

在 DeepSeek Harness Web 界面中实时显示 DeepSeek 账户模型余额的插件。

插件在会话页头部(标题下方)显示一个余额胶囊:当前总余额、更新时间点、 状态圆点(绿 = 正常 / 黄 = 获取中 / 红 = 失败),并带一个手动刷新按钮。 把鼠标悬停在胶囊上可以看到充值 / 赠送余额的明细。

工作原理

  • 宿主端lib/index.js):每 intervalMs(默认 60 秒)用配置的凭证 调用 GET {baseURL}/user/balance,缓存快照,并通过 webServer 注册一个 exact 路由 /api/model-balance 提供给浏览器。该接口永远不会暴露 API Key
  • 浏览器端lib/client.js):每 30 秒轮询该路由(页面重新可见时立即 刷新),把快照渲染到 conversation.session.header.utilities 插槽。

凭证解析与官方 DeepSeek LLM 适配器一致:先走 credentials 服务(Web 的 「模型」设置页写入的 Key,即 $DSH_HOME/.credentials.yaml),再回退到启动 环境变量 DEEPSEEK_API_KEYDEEPSEEK_BASE_URL 可覆盖 API 地址。

安装

# 在 dsh-model-balance 目录外执行;pnpm 由 dsh plugin 转发
dsh plugin --profile web add <dsh-model-balance 的绝对路径>

安装后重启 Web 服务(dsh web)并刷新页面即可生效:

# 先停掉正在运行的 dsh web,然后
dsh web

配置

编辑 $DSH_HOME/profiles/web/cordis.patch.yml 覆盖行配置:

- id: model-balance
  config:
    intervalMs: 30000   # 宿主刷新间隔(毫秒),最小 5000
    apiKeyEnv: DEEPSEEK_API_KEY
    baseURL: https://api.deepseek.com

验证

  • 接口:curl http://127.0.0.1:3080/api/model-balance 应返回 {"state":"ok","data":{...},"fetchedAt":...}
  • 组成检查:dsh --profile web --dump-config 中应包含 model-balance 行。

说明

  • 默认绑定为 127.0.0.1,余额接口只返回余额数据;如需更严格的访问控制, 可自行在宿主端加鉴权。
  • 移除插件:dsh plugin --profile web remove dsh-model-balance,然后重启。