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:

  1. Token usage statistics
    It listens for assistant/message events in session/event, persistently stores and deduplicates TokenUsage, buckets usage by session, and calculates global totals. The plugin uses llm/stream to provide in-flight call views and active sessions, and estimates current context pressure via tokenMeter.measure().

  2. 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.

  3. 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

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:

  1. Get usage data
   GET /api/token-monitor/usage
   # 返回 JSON: sessions, total, activeSessionId, lastCall, live, context
  1. Get account balance
   GET /api/token-monitor/balance
   # 参数 ?force=1 强制刷新余额

Requirements and Notes

  1. Dependency environment: pnpm must be available in PATH, and node must be installed locally.
  2. Credential setup: Balance queries require DEEPSEEK_API_KEY to be configured in the credentials.
  3. 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.
  4. Security note: The two routes have no authentication, but the Web service is bound to 127.0.0.1 by 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