npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@duke-dsh-plugins/dsh-token-stats

v1.4.0

Published

Token usage statistics for DeepSeek Harness (7/30-day per-model charts + yearly heatmap) plus an inline coding-plan balance/quota readout in the composer (minimax/deepseek/kimi/openrouter/zhipu).

Readme


DeepSeek Harness(DSH) Web UI 打造的 Token 消耗统计插件:在设置面板里一目了然每个模型每天、每个统计区间的 token 用量。

功能

| 功能 | 说明 | |---|---| | 📊 两个 Tab | 近 7 天 / 近 30 天,两个区间都包含今天 | | 📈 堆叠柱状图 | 统计区间内每个模型每天的消耗(悬停查看具体数字) | | 🥧 饼图 | 统计区间内每个模型的总消耗占比 + 图例(精确值 + 百分比) | | 🔥 GitHub 风格热力图 | 「近一年」每日活跃;天数随容器宽度自适应,最多显示 365 天(一年) | | 🗂 汇总卡片 | 区间总 Tokens / 输入(含缓存) / 输出 | | 💾 本地持久化 | 聚合结果落盘 <DSH_HOME>/data/dsh-token-stats/stats.json,冷启动只扫描新会话、秒开;删除该文件可强制全量重扫 | | ⏱ 自动刷新 | 页面打开期间每 30s 刷新;历史回填期间每 2s 轮询进度 | | 💰 套餐余额 | 输入框工具行(model 选择器左侧)内联显示当前 provider 的余额/套餐用量,跟随当前模型自动切换;支持 minimax / deepseek / kimi / openrouter / zhipu;60s 轮询,点击立即刷新 | | 🌗 主题适配 | 全部使用 DSH 设计 token,明暗主题自动跟随 |

套餐余额功能参考自 dsh-musage(MIT),API Key 直接复用 DSH 模型设置里已配置的凭据(credentials 服务),无需重复配置。

安装

标准安装(推荐)

本插件是标准 DSH bundlepackage.json 声明 dsh.bundle.patch,包内自带 cordis.patch.yml,用官方 dsh plugin 命令安装:

# 本地开发:pnpm 软链到本仓库,改代码即生效(无需重新复制)
dsh plugin --profile web add /path/to/dsh-token-stats

# 正式发布:从 GitHub Release tarball 安装
dsh plugin --profile web add https://github.com/MoonlitDropOfBlood/dsh-token-stats/releases/download/v1.4.0/dsh-token-stats-1.4.0.tgz

重启 DSH 后,打开 DSH Web UI 的设置(侧栏底部),左侧导航会出现 Token 统计 页。

dsh plugin add 把插件装成 profile 的 npm 依赖并追加到 dsh.profile.bundles,启动时 DSH 自动应用包内的 cordis.patch.yml 挂载插件。卸载:dsh plugin --profile web remove dsh-token-stats

使用

  1. 打开 设置Token 统计
  2. 近 7 天 / 近 30 天 两个 Tab 间切换:
    • 柱状图展示区间内每天、每个模型的消耗(堆叠)。
    • 饼图展示区间内每个模型的总消耗占比。
    • 顶部卡片给出区间总 Tokens / 输入 / 输出。
  3. 下方 每日活跃 热力图展示更长时间范围:格子越多 = 容器越宽,最多覆盖近一年。
  4. 会话输入框工具行(model 选择器左侧)内联显示当前 provider 的套餐余额:
    • DeepSeek / OpenRouter 显示余额(如 ¥43.97 / $12.50);
    • MiniMax / Kimi / 智谱 显示 5h X% | 7d Y%(5 小时 / 7 天窗口已用百分比,悬停查看重置时间);
    • 切换模型时自动切换 provider;每 60s 自动刷新,点击读数立即强制刷新
    • 未配置对应 API Key 或拉取失败时显示 (悬停查看原因);当前 provider 不在支持列表时不占位。

工作原理

DSH 会话日志(唯一权威数据源)
  ├─ LIVE   : session/event  → assistant/message(usage)   [插件启动后实时累计]
  ├─ HISTORY: sessionQuery.readSession() → 回填历史        [仅扫描从未回填过的会话]
  ├─ DEDUP  : 按 session+seq 水位线去重,绝不重复计数
  └─ PERSIST: 聚合 + 水位线落盘 stats.json(防抖写盘 + 停止时 flush)
        │
        ▼
TokenStatsService.getStats()   ← ctx.remote.tokenStats.getStats()(Client 调用)
TokenStatsService.getQuota()   ← ctx.remote.tokenStats.getQuota(provider, force)
        │
        ├─ getStats → 设置面板「Token 统计」页(柱状图 / 饼图 / 热力图)
        └─ getQuota → composer 工具行内联读数(conversation.input.right,
                      紧贴 model select 左侧;跟随当前会话模型自动切 provider)
  • 数据按本地日历天 × 模型provider::model)聚合;total = input + output + cacheRead + cacheWrite
  • 历史回填只统计插件启动前发生的调用,实时监听只统计启动后的,两者通过每个会话的事件序号水位线合并,不会重复。
  • 模型/模型来自 assistant/messagemessage.source(kind = 'model'),无需自行解析请求头。
  • 套餐余额:Host 半经 credentials 服务解析用户在模型设置里已配置的 API Key(引用命名遵循 <ROUTE>_API_KEY 约定),GET provider 官方端点(宿主全局 fetch 优先,无 fetch 时回退 subprocess curl);30s 缓存 + 失败指数退避(5s→30min),不落盘。

目录结构

dsh-token-stats/
├── index.js            # Host 半:TokenStatsService(Remote 服务,采集 + 回填)
├── client.js           # Client 半:设置页「Token 统计」UI bundle
├── typert.host.js      # Typert Host manifest(tokenStats/getStats 描述)
├── cordis.patch.yml    # dsh bundle patch(挂载行)
├── .github/workflows/  # GitHub Actions 发布
├── AGENTS.md           # 面向 AI agent 的开发指南(含踩坑)
└── LICENSE             # MIT

开发

npm run check           # node --check index.js client.js typert.host.js
dsh plugin --profile web add /path/to/dsh-token-stats   # 安装/重装到本机 DSH profile

详见 AGENTS.md——记录了 DSH 正式插件(Host/Client/Typert 三件套)的完整机制和踩坑。

License

本项目遵循 MIT License

本项目是基于 DeepSeek Harness 构建的社区插件,并非 DeepSeek 官方产品。