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

dsh-usage-statistics-panel

v0.2.2

Published

DSH web plugin: a usage statistics panel with per-day token trend, GitHub-style activity heatmap, cache hit-rate curve and per-model / per-provider breakdowns, replicating the reasonix usage stats feature.

Readme

DSH Usage Statistics Panel

English | 中文

npm version npm downloads License TypeScript dsh-plugin Awesome DSH Plugin Commit activity Last commit

DSH web 插件的用量统计面板:按天 Token 趋势、GitHub 风格活跃热力图、缓存命中率曲线、按模型与按供应商两种用量拆分(堆叠柱状图 + 明细列表),在设置页新增一个"使用统计"页面。

所有图表均为手绘 SVG,不依赖图表库;配色使用 GitHub Primer 的 data-viz 双套色板(模型前 10 名、供应商前 5 名各取一个等级色,其余归入灰色 "Other" 桶),并随 DSH 主题自适应。

预览

功能

  • 时间范围:最近 7 / 14 / 30 / 90 天,或自定义起止日期
  • 汇总卡片:Token 用量、会话数量(完成的 turn)、请求数量、活跃天数、平均缓存命中率、最常用模型
  • 26 周活跃热力图:每日 token 用量的 GitHub 风格色阶,悬停查看当天明细
  • 按天 Token 趋势:堆叠柱状图叠加平滑的缓存命中率曲线(Catmull-Rom 样条),悬停查看各模型拆分
  • 模型用量:堆叠柱状图 + 明细列表,前 10 名模型分色,其余折叠为可展开的 "Other" 明细;柱状图滚入视野时自基部升起
  • 供应商用量:同一结构上移一层——前 5 名供应商分色(独立色板),其余归入灰色 "Other";悬停任一侧联动另一侧,柱状图悬停显示该供应商的全部模型用量;每行可展开该供应商的模型明细,"Other" 展开被折叠的供应商、其下再展开各自的模型(展开不影响柱状图高度)
  • 底部信息栏增强:设置页可开启"精确缓存命中率"(会话底部信息栏的缓存命中率以两位小数显示,如 85.25%)、"会话 Token 明细"(底部信息栏显示总 Token、输入、输入(命中缓存)、输入(未命中缓存)与输出 Token,替代默认的"输入/输出"两项)与"流式吞吐速度"(输出过程中速度读数随每个增量实时刷新为估算值,某一步结束后回到会话累计的精确值;估算以 DeepSeek 公布的字符密度为先验,再用本会话已结算步骤的实测字符/Token 比率校准,读数取最近 2 秒内实际观测到的 Token 增量并做平滑(单帧抖动不会传导到显示),UI 迟发的积压不会被计入,一步中途静默时保持最后一次读数而不是回落到会话平均值);开关位于"使用统计"面板底部,与"侧边栏快捷入口"同款样式,切换即时生效
  • 历史回扫:首次启用时枚举并回放既有会话日志;对挂载后才首次观测到的活跃会话,其挂载前的历史会在下一次启动时按事件序号边界回放补全,从安装日起尽量还原历史用量
  • 本地持久化:数据写入 $DSH_HOME/storages/usage_history.json(storage-domain),纯本地、无外部依赖

安装

dsh plugin --profile <name> add dsh-usage-statistics-panel@latest

装完硬刷新浏览器(Cmd/Ctrl+Shift+R):client 半的改动 DSH 会热加载,无需重启;仅 host 半(采集/存储/路由)更新时需要重启 DSH。

插件挂载后,在 Web UI 的设置页左侧导航会出现"使用统计"页面。

兼容性:本插件支持 DeepSeek Harness >= 0.1.2-rc.1,历史回扫双路径:0.1.2-rc.1list+inspect0.1.3-alpha.* 及以后版本走 list+open+分页 read+closeinspect 在新版宿主已移除)。开发依赖与核验目标对齐宿主 0.1.6-alpha.1,已在 0.1.2-rc.10.1.5-rc.20.1.6-alpha.1 上核验,V3 日志兼容由单测覆盖。

peer 依赖中的 @deepseek-ai/* 只表达能力下界(>=0.1.2-rc.1 是插件用到的最早接口面),并全部标记为 optional:semver 的范围匹配不到未来的预发布宿主(>=0.1.2-rc.10.1.5-rc.20.1.6-alpha.1 均判不满足),所以实际支持的宿主版本以本段说明为准,不依赖 npm 的 peer 校验。

旧版本用户:使用 DeepSeek Harness 0.1.1-rc.20.1.2-alpha.* 的用户,请安装本插件的旧版本(0.1.9 及之前)。0.1.10 仅支持 >= 0.1.2-rc.1;自 0.1.11 起同一版本双路径支持 0.1.2-rc.10.1.3-alpha.*

数据来源

面板的数据采集是观测式的:插件订阅会话事件流(session/event)中的 assistant/messageassistant/chunk,提取 provider 上报的 token 用量(输入 / 输出 / 缓存读 / 缓存写),在单个会话内(turn, step) 去重(同一调用只计一次、保留先到的样本——两个官方适配器对流式采样与最终上报的数值完全一致;并发会话各自独立计数、互不吞样本)。模型归因优先取消息自带的 source(每次调用各自标注),缺失时回退到会话的路由折叠(request/context 事件或会话的 requestContext()),宿主重启后也不会落入 "(unknown)" 桶。首次启用时还会回扫既有会话日志补齐历史。

提示:Token 用量从插件启用(含回扫)之日起累计;更早的会话日志若无 provider 上报的用量数据,则无法回溯。

子代理会话:子代理是独立会话,其 token、请求与完成的轮次与顶层会话一并统计(实时采集覆盖全部会话事件流,重启后回扫同样覆盖子代理会话日志);父会话仅收到子代理结果摘要,不会重复计入。子代理会话早期的请求标记(step/start)先于其路由事件写入日志,首个请求可能统计在 "(unknown)" 桶——请求总数不受影响。

Token 口径:汇总卡片与趋势图的 Token 总量为服务商总口径——未缓存输入 + 输出 + 缓存读 + 缓存写,与服务商账单面板一致(DeepSeek 会把 prompt 拆成输入/缓存读两个不相交的桶,简单相加会漏掉占大头的缓存部分)。平均缓存命中率以输入侧(命中 + 未命中)为分母,其中未命中 = 未缓存输入 + 缓存写入——与会话底部信息栏(官方 StatsLine 口径)完全一致,两处读数不会出现分歧;命中率卡片下方同时展示缓存命中的绝对 token 量。

重建统计POST /usage/api/reset(与面板同源信任围栏保护)清空本地统计并按当前归因规则全量重放会话日志——用于历史数据损坏或归因规则升级后的重建。仍在进行中的会话以其重置时刻的日志长度为界:界内由重放重建、界外继续由实时采集,恰好各计一次。

开发

pnpm install
pnpm typecheck   # tsc --noEmit
pnpm test        # vitest
pnpm build       # tsc declarations + tsdown (host ESM + 双通道 client bundle)

设计与实现

  • Host 半src/):collector(事件订阅 + 回扫折叠)、storeusage_history storage-domain)、query(范围聚合,翻译自 reasonix 的 query.go)、routes/usage/api fenced JSON 路由,信任围栏与 /api 网关一致)
  • Client 半src/client/):UsageStatsPanel.tsx(手绘 SVG 图表,移植自 reasonix 面板 + Primer 配色)、locales(en / zh / zh-TW)、api/usage/api fetch 封装)
  • 双通道打包lib/client.js(官方 profile 通道,bundle id = 包名)与 lib/client-registry.js(插件注册表通道,bundle id = manifest id)。harness 0.1.x 官方加载链只消费前者;后者为外部 registry 通道预留,当前无消费者
  • 详细设计见 docs/design.md

致谢

本面板是对 reasonix 用量统计功能的复刻移植:作者曾为 DeepSeek-Reasonix 实现并贡献了该功能(PR #7238#7503),本插件按 DSH 的插件规范将其移植到 DeepSeek Harness,前端图表大比例复用原实现,数据层则基于 DSH 的会话日志与 storage-domain 重新实现。

Activity

HaoyueQin/dsh-usage-statistics-panel GitStock K-Line Chart

License

MIT