kai-GitHubaccount/dsh-usage-panel

kai-GitHubaccount/dsh-usage-panel

会话头部显示 DeepSeek 余额与本会话 Token 用量:三级余额预警、自定义阈值、一键充值入口、分段 Token 条与缓存命中率,并采用可见时才轮询的省流策略。

用量与计费deepseek-harnessdeepseek-harness-plugins

dsh-usage-panel

English | 简体中文

DeepSeek account balance and per-session token usage for the DSH (DeepSeek Harness) web GUI, rendered as a colored pill in the session header (top right).

Panel preview

Features

  • Balance from the official GET /user/balance (total / topped-up / granted).
  • Token usage from the host tokenUsage projection: uncached input, cache read, cache write, output, total, and cache-hit rate.
  • Three-level balance alert with user-editable thresholds: sufficient / warning / insufficient, recoloring the pill and the detail card.
  • Recharge entry: top-up, usage detail, sign-in, and copy-link, with three open modes (new tab / same tab / copy link).
  • Query efficiency: visibility-aware polling (paused on hidden tabs), exponential backoff on failure, a 30s host cache with single-flight, and manual refresh.
  • Version tolerant: the host prefers ctx.connection.fetch and falls back to ctx.webServer; the browser tries the session-header seats in order.

Install

Option 1 - install it as a plugin package (recommended):

dsh plugin --profile web add dsh-usage-panel

Option 2 - local installer:

node install.mjs --home ~/.dsh --profile web

Restart dsh web (or let the live patch watcher apply it) and refresh the GUI.

Configuration (host)

apply(ctx, config) reads an optional config object from the patch row:

FieldDefaultMeaning
routePath/api/usage-panel/balanceroute served by the host half
cacheMs30000upstream cache and single-flight window
apiKeyEnvDEEPSEEK_API_KEYresolved via ctx.credentials, then env
baseUrlhttps://api.deepseek.comprovider base URL
baseUrlEnvDEEPSEEK_BASE_URLenv var overriding baseUrl

Compatibility

  • Host: Node >= 18, no imports, so it loads from any path. Prefers ctx.connection.fetch.register and falls back to ctx.webServer.register. Key resolution uses ctx.credentials when present.
  • Browser: requires only the seeded React module and the slots service. Preferred seat is conversation.session.header.utilities, then conversation.session.header.corner; sidebar.footer.action is a delayed (4s) fallback, so the pill never pre-empts the header on a normal boot. Token usage needs the session-scoped useProjection hook; without it the balance still renders.
  • No platform-specific code, so it is machine independent.

Verify

node tools/verify.mjs --port 3080 --home ~/.dsh

Reports boot-graph presence, the HMR channel, and the served bundle features.

Uninstall

Remove the usage-panel insert row from the profile patch and delete <home>/plugins/dsh-usage-panel.

Author

Mysterious Mark

License

MIT