freespace8/dsh-plugins--plugins-dsh-deepseek-balance ↗★ 0
dsh-deepseek-balance
DeepSeek 官方余额胶囊:会话使用官方 DeepSeek 模型时,在 Web GUI 会话头部显示官方 API 余额,支持点击刷新与定时刷新。
安装
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:freespace8/dsh-plugins#0c78441f1ff5002ffd06fd0ba9328a3ff00d8fb2&path:plugins/dsh-deepseek-balance说明文档
阅读完整 README ↗dsh-deepseek-balance
DeepSeek 官方 API 余额胶囊插件。在 DSH Web GUI 的会话头部(Session log 左侧)显示官方 DeepSeek API 余额:
- 仅当会话当前模型是官方 DeepSeek(provider 为
deepseek-official,即api.deepseek.com)时显示;使用 Packy 等第三方中转模型时自动隐藏; - 显示
¥xx.xx(无货币后缀),鼠标悬停显示赠送/充值明细与上次刷新耗时; - 胶囊内的刷新按钮点击立即刷新(图标旋转动画),并每 5 分钟自动刷新一次;
- 无缓存:每次刷新都真实请求官方接口;失败时保留上次余额并红点提示。
安装
dsh plugin --profile web add file:/Users/taylor/working/github.com/freespace8/dsh-extensions/plugins/deepseek-balance
安装后重启 web profile(dsh plugin add 只改 manifest 与依赖,运行中的实例不热加载新 bundle)。
前置条件:~/.dsh/.credentials.yaml 里有 DEEPSEEK_API_KEY(或已配置同名环境变量)。
配置
profile 的 cordis.patch.yml 里按 id 覆盖(整段替换 config):
- id: deepseek-balance
config:
apiKeyEnv: DEEPSEEK_API_KEY # 余额请求使用的凭据名
refreshIntervalMs: 300000 # 自动刷新间隔(毫秒)
order: -1 # 会话头部胶囊的排列序(越小越靠前)
shellTimeoutMs: 8000 # 拉取余额的 shell 总超时(毫秒)
工作原理
- host 半体(
src/index.js):经ctx.credentials解析 API Key,用ctx.shell执行curl https://api.deepseek.com/user/balance,注册 HTTP 路由/plugins/dsh-deepseek-balance/balance把结果(含刷新间隔配置)发给浏览器; - client 半体(
lib/client.js):注册conversation.session.header.utilitiesslot 条目; 用ctx.modelDirectories读会话当前模型做显示判定;fetch余额路由渲染胶囊。
余额数据始终来自官方 DeepSeek 接口(用存储的官方 Key),与模型流量走哪个供应商无关; 显示与否只看会话当前模型是否官方 DeepSeek。
验证
npm run check # 产物门检查(语法、导出形状、exports/files、patch 行、client id)
真实生效验证(装进 profile 后):重启 web profile → 打开一个已建会话 → 头部出现余额胶囊; 把模型切到第三方(如 Packy)→ 胶囊消失;切回官方 DeepSeek → 胶囊恢复。