Introduction¶
When using DeepSeek Harness (DSH) Web Shell, it is common to want real-time visibility into token consumption and account balance. The dsh-token-monitor plugin is designed to address these two pain points by monitoring the event stream to track usage and querying the official DeepSeek API directly for balance information. The plugin is maintained by chencmb2077-ui, uses a pure static Host integration approach, and requires no build steps.
Core Features¶
The plugin provides the following capabilities:
-
Token usage statistics
It listens forassistant/messageevents insession/event, persistently stores and deduplicatesTokenUsage, buckets usage by session, and calculates global totals. The plugin usesllm/streamto provide in-flight call views and active sessions, and estimates current context pressure viatokenMeter.measure(). -
Balance query
It requests the official DeepSeek API (https://api.deepseek.com/user/balance) through a Node subprocess using OpenSSL TLS. The API key is passed only via environment variables to the subprocess and does not enter the browser or logs. Cache support for 60 seconds and manual refresh are provided. -
Floating window display
It generates a fixed card in the bottom-right corner of the page, polls usage every 2.5 seconds, and polls balance every 60 seconds. The card can collapse into a “pill” style, and the styling automatically adapts to light and dark themes.
Installation and Enabling¶
CLI Installation (Recommended)¶
This plugin is a DSH Bundle, and package.json declares dsh.bundle.patch. After installation, it is automatically added to the current Profile’s Bundle layer.
dsh plugin --profile web add github:chencmb2077-ui/dsh-token-monitor
dsh web
Manual Installation¶
Place the token-monitor directory under the Profile configuration directory and append the configuration in cordis.patch.yml.
- insert:
- id: token-monitor
name: ./token-monitor/index.js
Typical Usage¶
After startup, the plugin registers two JSON HTTP routes:
- Get usage data
GET /api/token-monitor/usage
# 返回 JSON: sessions, total, activeSessionId, lastCall, live, context
- Get account balance
GET /api/token-monitor/balance
# 参数 ?force=1 强制刷新余额
Requirements and Notes¶
- Dependency environment:
pnpmmust be available in PATH, andnodemust be installed locally. - Credential setup: Balance queries require
DEEPSEEK_API_KEYto be configured in the credentials. - Provider limitation: If a non-DeepSeek provider is used (such as pi-ai, OpenRouter, or local models), the balance displays “Query failed,” but usage statistics are not affected.
- Security note: The two routes have no authentication, but the Web service is bound to
127.0.0.1by default and is only accessible locally. The API key is not written to logs and is not returned to the browser.
Summary¶
dsh-token-monitor provides DSH users with comprehensive monitoring capabilities, from event stream tracking to account balance queries. Through static injection and local subprocess queries, it balances real-time performance with security.
- GitHub: https://github.com/chencmb2077-ui/dsh-token-monitor
- Directory page: https://www.skillhub.cn/plugins/chencmb2077-ui/dsh-token-monitor