deepseek-harness
deepseek-ai
DeepSeek Harness: Everything is a Plugin.
PROJECT TOPICS
PROJECT README
English | 中文
A DeepSeek Harness plugin that shows real-time DeepSeek API usage.
/user/balance endpoint (default every 30s): total / granted / topped-up balance and availability, with multi-key aggregation (apiKeys)llm/stream waterfall, in three windows: total / today / last-60s, with the cache-hit rate~/.dsh/deepseek-usage/usage.json), powering the trend charts and CSV exportsdeepseek-chat / deepseek-reasoner table, overridable via config), computed per window, with peak/off-peak pricing (offPeakHours / offPeakDiscount)conversation.composer.dock), auto-refresh + manual refreshblockOnLowBalance)settings.section seat: balance card + per-key accounts, three-window usage, in-panel config editor (writes back through the host), history heatmap & 30-day bars, per-model pricing table, per-session usage table, and CSV exportsdeepseek_usage, so the agent can query balance and usage on demanddsh plugin --profile web add github:yyb16yyb-hub/dsh-deepseek-usage
⚠️ First install requires build authorization: pnpm ≥ 10 refuses to run prepare scripts of git-hosted dependencies (the plugin builds lib/ from source at install time). The first add fails with a hint — copy the exact package key pnpm prints into that profile's pnpm-workspace.yaml, then re-run:
allowBuilds:
dsh-deepseek-usage: true
Pin a commit for reproducible installs: dsh plugin --profile web add github:yyb16yyb-hub/dsh-deepseek-usage#<sha>.
dsh plugin --profile web add /path/to/dsh-deepseek-usage # local dir (pre-built lib/)
dsh plugin --profile web add ./dsh-deepseek-usage-0.1.0.tgz # pnpm pack output
Restart dsh web after installing — the client module table is scanned at boot.
Uninstall:
dsh plugin --profile web remove dsh-deepseek-usage
The API key is resolved in this order (re-resolved on every poll, so changes take effect immediately):
apiKeyctx.credentials): process env → ~/.dsh/.credentials.yaml → project .env → user .env. A DeepSeek key entered on the Web Settings → Models page lands in ~/.dsh/.credentials.yaml, which this plugin picks up automatically — no extra config neededapiKey in the registered llm-deepseek settings section (if any)Override the plugin row in the profile's cordis.patch.yml to configure:
- id: deepseek-usage
config:
apiKeyEnv: DEEPSEEK_API_KEY
apiKeys: [] # extra API keys whose balances are aggregated
pollIntervalMs: 60000 # balance poll interval (ms, min 5000)
balanceTimeoutMs: 10000 # balance fetch timeout (ms)
showBalance: true
showTokens: true
showCost: true
alertThreshold: 20 # low-balance alert threshold (account currency; 0 = off)
blockOnLowBalance: false # block LLM requests while balance < alertThreshold
maxSessions: 200 # max sessions kept in the per-session drill-down
offPeakHours: [0,1,2,3,4,5,6,7] # local hours priced as off-peak
offPeakDiscount: 0.5 # cache-miss price multiplier in off-peak hours
pricing:
deepseek-chat:
input: 2 # ¥ / 1M tokens
output: 3
cacheRead: 0.5
deepseek-reasoner:
input: 4
output: 16
cacheRead: 1
Cost is an estimate: the built-in pricing table reflects common public pricing — always check the latest official DeepSeek prices, and override via
pricingor the settings-panel editor. Off-peak pricing applies the discount to cache-miss input/output prices only (matching DeepSeek's policy), priced at the current hour.
Settings-panel edits (threshold, poll interval, display toggles, block toggle, off-peak window, pricing) are validated host-side and persisted — they override matching
cordis.ymlvalues until reset. Secrets (apiKey/apiKeys) are never accepted through the editor or persisted.
pollIntervalMs), with a manual refresh button.alertThreshold the dock turns amber with a ⚠ mark, below threshold/5 it turns red; crossing the threshold fires one browser notification (only when Notification.permission === 'granted' — the plugin never prompts for permission). With blockOnLowBalance enabled, LLM requests fail with a clear message while the balance is below the threshold.Data comes from the same-origin endpoints GET /dsh-deepseek-usage (?refresh=1 forces a balance re-poll) and POST /dsh-deepseek-usage/config (editor writes). API keys stay on the host side and never reach the browser. Daily history is persisted to ~/.dsh/deepseek-usage/usage.json.
The agent can call deepseek_usage:
scope: total / today / rolling to pick a windowpnpm install
pnpm typecheck # tsc --noEmit
pnpm test # vitest unit tests (stats + cost)
pnpm build # esbuild → lib/index.js (host half) + lib/client.js (browser half)
src/
├── index.ts # host half: apply(), llm/stream hook, block gate, tool, HTTP routes
├── balance.ts # DeepSeek /user/balance client + multi-key poller
├── stats.ts # usage tracking (total/today/rolling windows, per-model, per-session, restore/export)
├── cost.ts # pure pricing/cost logic (peak/off-peak) — unit tested
├── persist.ts # JSON persistence (atomic writes, $DSH_HOME/deepseek-usage/usage.json)
├── config.ts # schemastery config schema
└── client/
├── index.ts # browser half: locale + composer.dock / settings.section registration
├── api.ts # shared: payload types, fetch, config save, CSV export, formatters
├── UsageDock.tsx # composer dock (with low-balance alert)
├── UsageSettingsSection.tsx # settings panel (balance/accounts/usage/history/editor/sessions)
└── locales.ts # zh/en dictionaries
@deepseek-ai/* external so they resolve from the profile's node_modules (single cordis runtime identity)packages/client/web/src/platform.ts (react, cordis, slots, …); everything else is inlined, and the artifact is wrapped in window.__ModuleLoader__.load({ id, factory }) for the web shell's module loaderBalance polling uses the same API key as LLM requests; keys are never sent to the browser and never persisted by the plugin (only non-secret config overrides are). As with any third-party plugin, review the source before installing.
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: 无有效分类标签。