Skip to main content
X

dsh-deepseek-balance

xuezhining/dsh-deepseek-balance

Shows the DeepSeek API account balance and live round-trip latency to the configured inference provider in one sidebar widget, with a configurable low-balance alert threshold. The balance needs DEEPSEEK_API_KEY configured in DSH credentials, otherwise the widget shows a missing-key notice.

Install

dsh plugin --profile web add github:xuezhining/dsh-deepseek-balance

README

余额 + 延迟挂件 · @local/deepseek-balance

在 DeepSeek Harness Web UI 侧边栏底部常驻一个小挂件,同时显示 账户可用余额 和 到模型服务商的实时网络延迟。

● ¥19.21 · 178ms

它做什么

Host 半(index.js),两条同源路由,Key 与探测都留在 Host 进程:

路由内容缓存
GET /deepseek-balanceDEEPSEEK_API_KEY 账户余额(api.deepseek.com/user/balance)10s
GET /deepseek-balance/ping对各服务商 origin 的 HEAD 往返耗时2s

两条路由都接受 ?refresh=1 绕过缓存。延迟探测的目标自动从当前 provider 配置发现: 先读 llm-deepseek 的 baseURL,再读 llm-pi-ai 的 providers.*.baseURL,都没有就退回 https://api.deepseek.com。可用环境变量覆盖:

DSH_BALANCE_PING_URLS=https://a.example,https://b.example

Client 半(client.js)注册到 sidebar.footer.action:

  • 余额每 30 秒轮询,延迟每 5 秒轮询;页面重新可见时立即刷新
  • 点击挂件 = 强制刷新两者
  • 延迟颜色:≤400ms 常规、>400ms 警告、>900ms 或不可达 报错红
  • 悬停可见:总余额 / 充值 / 赠金 / 各目标 host 的延迟 / 更新时间
  • 延迟路由尚未就绪时(例如 Host 还没重启),挂件自动只显示余额,不显示红杠

显示规则

情况挂件
正常● ¥19.21 · 178ms
余额读取中● ··· · 178ms(黄点)
缺少 API Key● 未配置 DEEPSEEK_API_KEY · 178ms(红点)
余额失败 / Key 无效● — · 178ms(红点)
服务商不可达● ¥19.21 · —(延迟变红)
侧边栏收起只显示 ¥19.21(56px 窄栏放不下延迟)

前置条件

余额显示需要 DEEPSEEK_API_KEY。 插件会通过 Host 的 credentials 服务解析这个环境变量名; 没有配置时挂件不会报错崩溃,而是显示 未配置 DEEPSEEK_API_KEY 并保留延迟显示。

延迟部分不依赖任何密钥,装好后立即可用。

配置位置(任选其一):

  • DSH 凭据库:~/.ds-harness-desktop/dsh-home/.credentials.yaml 的 refs 下
  • 系统环境变量 DEEPSEEK_API_KEY

Key 只在 Host 进程内用于请求 api.deepseek.com/user/balance,不会发往浏览器或任何其他地址。 每次查询都会重新解析,换 Key 不需要重启。

插件内配置

挂件本身没有必填配置,但有一个可调项:

设置 → 通用 → 余额告警阈值 — 默认 5,单位与余额币种一致(CNY 与 USD 各自独立比较)。 余额 ≤ 阈值时挂件变红并呼吸闪烁。设置持久化在插件目录的 balance-settings.json。

延迟的两个阈值也可以运行时覆盖,默认为 400ms(变黄)和 900ms(变红):

window.__DSB_LATENCY_TONE__ = { slow: 400, bad: 900 }

安装

从 npm 安装(推荐):

dsh plugin --profile web add @xuzhining/dsh-deepseek-balance

从 GitHub 源码安装:

dsh plugin --profile web add github:xuezhining/dsh-deepseek-balance

本地开发目录安装:

plugin_manager install_bundle  target=<本目录绝对路径>

安装后插件行 id 为 deepseek-balance,可在「设置 → 插件」中启用/停用。

回归测试

test-host.mjs 用一个替身 ctx 真跑一遍 apply(),验证两条路由、余额、延迟探测和缓存:

$env:TEST_KEY = "<DEEPSEEK_API_KEY>"
node test-host.mjs

Related plugins