dsh-plugin-api-balance
中文简介
在 DSH 侧栏底部放一枚实时账户额度小卡:读取 DeepSeek 账户的充值余额与赠送余额,按币种求和后显示总额度(多币种用 + 连接),悬停展开每个钱包的明细与更新时间,点击刷新。
额度旁边并排一枚计价时段时钟:显示北京时间,并按 DeepSeek 峰谷定价(北京时间工作日 09:00–12:00、14:00–18:00,法定节假日除外)显示「高峰」(醒目红色 + 脉冲圆点)或「空闲」(绿色),悬停可看完整窗口、下次切换时间与倒计时。
-
数据复用官方 account/getBalance,不新增凭证或网络路径;
-
默认每 15 秒轮询,页面重新可见和点击时也会刷新;
-
未登录 / 读取失败 / 无余额分别显示对应状态,不臆造 0;
-
配置项 refreshIntervalMs(默认 15000,低于 5000 回退默认值)。
-
image
Live DeepSeek account credit chip for the DSH Web client sidebar.
What it does
The plugin mounts one component into the sidebar's sidebar.footer.action seat
and keeps it current:
- reads the account's remaining credit through the existing
account/getBalance
Remote (@deepseek-ai/dsh-api-account-controller) — the same call the
Settings → Account page uses, so no new host code, credentials, or network
path exists;
- polls every
refreshIntervalMs (default 15 s), re-reads whenever the browser
tab becomes visible again, and re-reads on click;
- shows the total credit: every wallet (topped-up and granted) is summed
per currency, so the chip reports what the account can actually spend. A
multi-currency account shows one total per currency joined with
+
(¥1.00 + $2.00); amounts use the Platform Web client's currency format
(two decimals, digit grouping, <0.01 for positive sub-cent amounts);
- opens the shipped
HoverCard primitive on hover or keyboard focus: a heading,
the 总额度 / Total credit row, a divider, one label / amount line per
wallet, and a footer with the freshness stamp and the refresh hint. The
primitive owns the card's surface,
portal, placement, viewport clamping, and pointer grace, so the card cannot be
clipped by the layout frame and the pointer may rest on it;
- renders
未登录 / 不可用 when the account is signed out or the read fails,
instead of inventing a zero balance. The card explains the same state;
- sits a peak-tariff clock beside the credit chip: the current Beijing time
with a
高峰 / 空闲 tag, the countdown to the next switch in the tooltip,
and a red warning pill with a pulsing dot while DeepSeek's peak price window
is active.
Configuration
| Field | Default | Meaning |
|---|
refreshIntervalMs | 15000 | Poll interval in milliseconds; values below 5000 fall back to the default. |
Peak-tariff clock
DeepSeek publishes a peak/idle tariff in Beijing time (UTC+8): calls are
peak Monday to Friday 09:00–12:00 and 14:00–18:00, excluding Chinese
statutory holidays; every other period — weekends and holidays included — is
idle, at half the peak price.
The clock beside the chip shows the current Beijing time and the active period.
During peak the pill turns warning red (red text, red ring, red 高峰 tag, and
a pulsing dot); the native tooltip carries the full windows and the countdown
to the next switch. In the collapsed rail the clock is hidden, like the chip's
label and amount.
The holiday dates live in lib/client.js as STATUTORY_HOLIDAYS, copied from the
State Council's annual arrangement notice (currently 2026, 国办发明电〔2025〕7号).
When the next year's notice is published, append its holiday dates there; a year
without an entry falls back to the weekday + time rules only.
Installing as a profile bundle
The package is meant to live in a durable home outside the session workspace
(for example ~/.dsh/plugins/dsh-plugin-api-balance):
- add it to the profile's
dependencies as link:<that path>;
- append
dsh-plugin-api-balance to dsh.profile.bundles in the profile's
package.json;
- let the package manager create the
node_modules link, then restart DSH.
dsh.bundle.patch points at this package's cordis.patch.yml, which inserts the
api-balance row. That is why the row shows up in the sidebar's Plugins page
as a manageable bundle row (per-row enable/disable, whole-bundle enable, uninstall)
instead of being an untracked file:/// row in the user's patch layer.
The row config lives in the bundle layer; a user-patch override with the same id
still wins, so refreshIntervalMs can be tuned per installation without touching
the package.
Layout
| Path | Role |
|---|
lib/index.js | Node half. Empty apply; the row exists so the Loader mounts the package. |
lib/client.js | Browser half: the hand-written window.__ModuleLoader__.load bundle (dictionaries, snapshot store, chip component, hover-card content, peak-tariff clock, plugin body). |
cordis.patch.yml | Bundle patch inserting the api-balance row. |
The browser half only requests baseline modules (react, react/jsx-runtime,
and @deepseek-ai/dsh-client-ui-primitives for its HoverCard), so it needs no
build step and no dsh.client.external entries. Editing lib/client.js is
picked up live: client-hmr stat-polls every row's bundle and republishes it
through /plugins/events; the browser reloads that row's module graph in
place, so a rewritten bundle shows up without a manual page refresh.