outprintHelloLi/dsh-balance-lite0

dsh-balance-lite

DSH web plugin: show the official DeepSeek API account balance (queried on page load and after each conversation turn, no cache).

包名
dsh-balance-lite
版本
1.0.0
许可证
MIT
最近更新
2026年8月25日

安装

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:outprintHelloLi/dsh-balance-lite

dsh-balance-lite

DeepSeek Harness (DSH) Web 插件:在对话输入框下方显示 DeepSeek 官方账户余额

  • 数据来源:DeepSeek 官方接口 GET https://api.deepseek.com/user/balance(唯一官方余额接口)。
  • 查询时机:页面首次打开时查一次;每次对话回合结束(turn/end)再查一次。
  • 无缓存:每次调用都实时请求官方接口,不设有效期缓存。
  • 显示内容is_available + balance_infoscurrency / total_balance / granted_balance / topped_up_balance)。

说明:DeepSeek 开放平台 没有 公开 API 提供「当日 token 用量 / 费用 / 账单」查询(这些只在网页控制台里看)。因此本插件只展示官方余额,不做本地用量累计或费用估算。

安装

方式一:本地 file: 依赖(推荐,开发用)

把本目录放到你的 web profile 插件目录,例如 ~/.dsh/profiles/web/plugins/dsh-balance-lite,然后改 ~/.dsh/profiles/web/package.json

{
  "dependencies": {
    "dsh-balance-lite": "file:./plugins/dsh-balance-lite"
  },
  "dsh": {
    "profile": {
      "bundles": ["@deepseek-ai/dsh-base", "@deepseek-ai/dsh-web-app", "dsh-balance-lite"]
    }
  }
}

然后安装:

cd ~/.dsh/profiles/web
pnpm install

重启 dsh web 并硬刷新页面(Ctrl+Shift+R)。

方式二:npm / GitHub 安装

发布到 npm 后执行:dsh plugin --profile web add dsh-balance-lite,或用 GitHub 依赖:

"dsh-balance-lite": "github:你的账号/dsh-balance-lite"

前置条件

  • ~/.dsh/.credentials.yaml 中存在 DEEPSEEK_API_KEY
  • Node.js ≥ 20,pnpm 可用。
  • DSH 已初始化 web profile(~/.dsh/profiles/web)。

结构

文件作用
lib/index.jshost 端:注册 /dsh-balance-lite/status 路由;监听 session/eventturn/end 在每次对话结束后查询余额。
lib/client.jsclient 端:挂载到 conversation.composer.dock,展示余额;首次加载/切换/聚焦/点击时刷新。
cordis.patch.yml把插件行插入 DSH host 组合。

设计说明

  • 不写 token 台账、不做费用估算(官方无对应接口)。
  • 客户端无轮询(不像之前插件那样每 2 秒 setInterval),避免页面卡死;只在挂载、切换会话、标签页获得焦点/可见、手动点击时拉取一次。
  • host 端 HTTP 路由仅允许 loopback 同源访问,拒绝跨域请求。

License

MIT