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

@wang291010/dsh-usage-stats

v0.1.0-yourworkbench.2

Published

DSH API 用量统计(YourWorkbench 本地维护,基于上游 @abcdefu_cja/dsh-usage-stats 0.1.0 修改):token、请求、轮次、缓存命中、费用估算与多提供商余额/配额。

Readme

@wang291010/dsh-usage-stats

YourWorkbench 本地维护发行版:基于上游 @abcdefu_cja/[email protected] (BSD-3-Clause)修改。后续改动以本仓库为准,上游仅作来源标注。 归属与更新上游见 docs/ownership-boundary.md

DSH Web 的 API 用量统计插件:精确统计 token、请求、完成轮次、活跃天数、缓存命中率、费用估算,并同时拉取 OpenCode 订阅配额与 DeepSeek 官方余额。以独立插件形态挂载(不属于 dsh-web-ui 家族),在设置页左侧导航提供专属「用量统计」Tab。

与启发式估算不同,本插件的 token 计数是精确的:直接来自每个请求的 provider usage 报告(inputTokens/outputTokenscacheReadTokens/cacheWriteTokens),并采用 DSH 自身的 (turn, step) 替换语义,最终消息会替换其先前的用量块而不是重复累计。

功能

  • 用量概览 Tab
    • 常驻 KPI 区:Token 总量(含费用)、请求数、完成轮次、活跃天数、平均缓存命中率、提供商动态卡(OpenCode 周配额 / DeepSeek 余额)
    • Token 四分色拆分条(输入 / 缓存读 / 缓存写 / 输出)
    • 堆叠柱状趋势图:按模型分段着色,Y 轴中文单位刻度(万/亿),悬停柱子显示当日明细 tooltip(总用量 / 费用 / 分模型 Top5+其他 / 缓存命中率)
    • 模型明细表(请求数 / token / 费用)
  • 模型与缓存 Tab:模型占比 Donut 图 + 缓存效率诊断(命中率、节省 token、节省比例)
  • 余额与配额 Tab:OpenCode 订阅配额三窗口进度条(滚动 / 每周 / 每月 + 重置倒计时);DeepSeek 官方余额(金额 / 预计可用天数 / 充值链接跳转官方充值页 / 手动刷新)
  • 会话用量面板:会话页按钮展开当前会话用量(累计 / 最近请求 / 进行中轮次实时消耗)
  • 7 / 14 / 30 / 90 天与自定义范围切换;展开时 30s 轮询

架构

  • 宿主端:订阅 session/event(全局、所有会话),把每次请求折入 UsageStatsMeter(token / 请求 / 轮次 / 费用 / 最近请求元数据)。按日(本地时区 YYYY-MM-DD)与分模型桶聚合,优先落盘到 $DSH_HOME/dsh-usage-stats.json(未设置时回退 ~/.dsh/dsh-usage-stats.json;30s 防抖写盘 + flush/dispose 即时写,原子 tmp + rename,损坏文件转 .bak 重建)。只读路由 /api/dsh-usage-stats/* 带 loopback 围栏。余额客户端并行拉取全部已检测 provider 的快照(OpenCode /v1/usage 配额 + DeepSeek /user/balance 金额),各自失败互不影响。
  • 浏览器端:注册设置页左侧导航独立 Tab(官方 settings.section 槽,id usage-stats;不属于任何家族分组)。也注册会话页用量按钮(conversation.session.header.utilities 槽)。

安装

独立插件,与 dsh-web-ui 家族及其聚合包无关。

方式一:npm(发布后)

npm i @wang291010/dsh-usage-stats
dsh plugin --profile web add @wang291010/dsh-usage-stats

方式二:本地 link(开发)

dsh plugin --profile web add link:/path/to/dsh-usage-stats

安装后重启 dsh web。也可写入个人 DSH 覆盖层 ~/.dsh/config.yaml(保存即热加载):

- insert:
    - id: usage-stats
      name: '@wang291010/dsh-usage-stats'
      config:
        enabled: true
        currency: CNY
        balance:
          mode: auto
          refreshMs: 600000

所有配置项均可选(默认值见下表)。

配置

| Key | 类型 | 默认 | 含义 | |---|---|---|---| | enabled | boolean | true | 总开关;关闭后停止事件订阅、落盘与计量 | | prices | Record<string, ModelPrice> | 内置价格表 | 每百万 token 单价,按模型键(input / cacheRead / cacheWrite / output,可选 peak 高峰价);用户项覆盖内置表 | | defaultPrice | ModelPrice | 无 | 未在 prices 中的模型的兜底单价;缺省时未知模型按 0 计价 | | currency | string | CNY | 费用与余额的显示货币(CNY 显示 ¥,USD 显示 $) | | peakHours | Array<[number, number]> | [[9,10],[14,15]] | 高峰时段(北京时间小时,左闭右开);落在高峰时段且模型配置了 peak 价时按高峰价计费 | | balance.mode | 'auto' \| 'manual' \| 'off' | auto | auto 自动检测全部已知 provider(OpenCode 配额 + DeepSeek 余额);manual 使用固定 baseUrloff 关闭余额拉取 | | balance.baseUrl | string | 无 | 余额端点基址(manual 模式必填) | | balance.path | string | /user/balance | 追加到 baseUrl 的余额路径 | | balance.apiKeyEnv | string | DEEPSEEK_API_KEY | 存放 provider API key 的环境变量名(优先进程环境变量,其次 ~/.dsh/.credentials.yaml) | | balance.refreshMs | number | 600000 | 余额刷新间隔(毫秒,最小 1000) |

ModelPrice{ input, cacheRead, cacheWrite, output, peak? },非负数。内置 DeepSeek 价目(每百万 token,CNY):deepseek-chat { input: 2, cacheRead: 0.5, cacheWrite: 2, output: 8 }deepseek-reasoner { input: 4, cacheRead: 1, cacheWrite: 4, output: 16 }

DeepSeek-V4 系列(2026-08-17 0 时起官方峰谷定价,CNY)

| 模型 | 空闲 input / cacheRead / output | 高峰 input / cacheRead / output | |---|---|---| | deepseek-v4-flash | 1.5 / 0.05 / 4.5 | 3.0 / 0.1 / 9.0 | | deepseek-v4-pro | 4.5 / 0.15 / 13.5 | 9.0 / 0.3 / 27.0 |

高峰时段按北京时区判断,默认每日 9:00、14:00 起各一小时(peakHours 可调整);高峰价为空闲价的 2 倍。其他内置模型(OpenCode Zen Go 等)为 USD 价目且无峰谷区分。

余额自动检测

auto 模式同时检测以下 provider(内置端点表,profile 无 baseURL 也可推断):

| provider | 端点 | 展示 | |---|---|---| | OpenCode Go(opencode-go) | GET https://opencode.ai/zen/go/v1/usage,key 环境变量 OPENCODE_GO_API_KEY | 订阅配额三窗口(滚动 / 每周 / 每月) | | DeepSeek(deepseek) | GET https://api.deepseek.com/user/balance,key 环境变量 DEEPSEEK_API_KEY | 金额余额 + 预计可用天数 |

导出形态

函数/命名空间插件:inject / Config / apply,无默认导出。宿主端还导出 USAGE_STATS_METER_KEY(宿主挂到上下文、路由与余额任务读取的 symbol)与 USAGE_STATS_SETTINGS_NAMESPACE。计量、计价、存储、查询与 provider 检测模块均为纯函数并有单元测试。

模型体验

提示词与工具面

无。插件不注入任何提示片段、不注册任何工具:只消费持久化的 session/event 流并暴露只读 HTTP 路由;浏览器卡片经官方 settings.section 槽渲染。

Token 影响

每请求零额外 token。

KV 缓存影响

无系统提示词贡献,无缓存稳定性影响。

已知限制与后续工作

  • 费用是估算:按内置或用户价目表 × provider 上报用量计算,非账单方发票;请以实际账单为准。
  • 余额取决于 provider 端点:DeepSeek 官方余额接口要求有效官方 key(OpenCode 的 key 不被接受);OpenCode 配额接口可能受 Cloudflare 对非浏览器 UA 的延迟惩罚(已用浏览器 UA + 25s 超时缓解)。
  • 历史自启用时起算:日聚合只记录插件启用后观察到的事件,之前的使用不回填。
  • 留存byDay 保留最近 730 天,sessions 保留最近 500 个;更早数据在保存时裁剪。

许可

BSD-3-Clause,见 LICENSE