bowenliang123/dsh-context
bowenliang123/dsh-contextDSH 上下文洞察面板:Context 仪表盘 + /context命令 + Context 浏览器,查看 Context的分类组成、内容详情、演进趋势、压缩/注入事件、统计等一站式 Context 全生命周期管理。
DSH Token 用量统计插件 - 今日 Token 用量按模型分桶、缓存命中率、7 日趋势图、可选顶栏徽标、持久化存储自动清理。
DSH Token Usage Statistics Plugin — Real-time tracking of today's and last 7 days' token consumption, bucketed by model with cache hit rate analysis and trend charts.
DSH 0.1.7 compatible (
>=0.1.7-rc.1): settings namespace adapted to the 0.1.7 mechanism (host exportsConfig+ volatile fields).
New "Today's Token Usage" section in settings page showing:
cacheRead / (uncachedInput + cacheRead) × 100%~/.dsh/storages/dsh-token-usage-xc/<YYYY-MM-DD>.json| Source | Description |
|---|---|
| session/event | Listen to assistant/message event's usage field |
| Model Attribution | Read event's message.source.model directly |
| Session Watermark | Dedupe by seq to avoid double counting |
Why not parse session.jsonl.zstd directly?
The file is multi-zstd-frame concatenated, requiring frame boundary scanning like the persistence backend. Plugins usesessionQueryto avoid reimplementing this complex logic.
# Using DSH CLI
dsh plugin --profile web add dsh-token-usage-xc
# Or using npm
npm install dsh-token-usage-xc
Restart DSH after installation. You'll see a new "Today's Token Usage" section in settings.
| Option | Default | Description |
|---|---|---|
| enabled | true | Enable statistics |
| refreshIntervalSec | 60 | Frontend refresh interval (10-3600s) |
| backfill | true | Backfill today's usage on startup |
| headerBadge | false | Show total token badge in conversation header |
RPC endpoints for other plugins:
// rpc.call("/api", "dsh-token-usage-xc/today", {}) -> physical route: POST /api/dsh-token-usage-xc/today
// (preferred since 0.2.24; legacy rpc.call("/dsh-token-usage-xc","today") still served on dsh <0.1.5 or patched hosts)
{
available: boolean;
date: string; // 'YYYY-MM-DD'
totalTokens: number;
requests: number;
models: {
model: string;
modelName: string | null;
provider: string;
uncachedInputTokens: number;
outputTokens: number;
cacheReadTokens: number;
cacheWriteTokens: number;
totalTokens: number;
requests: number;
}[];
}
// rpc.call("/api", "dsh-token-usage-xc/last7days", {})
// Returns last 7 days' aggregated data