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-token-usage-counter

v0.2.1

Published

Self-contained token usage statistics and provider-aware reasoning effort controls for DeepSeek Harness.

Readme

Token 用量统计插件

English | 中文

token-usage-counter 是一个用于 DeepSeek Harness 的 Token 用量统计插件。 它会持久化 provider 上报的用量,支持全局、按会话、按 Provider / 模型查看, 并避免把失败请求或重试请求重复算入总量。

它解决了什么问题

| 能力 | 说明 | | --- | --- | | 精确分桶 | 输入(未命中)、输入(命中)、缓存写入、输出保持独立。 | | 持久化累计 | 数据写入 Harness 的 usage-stats settings 命名空间,重启不会归零。 | | 多维查看 | 支持全局、单个会话、Provider / 模型三个维度。 | | 每日活跃度 | 为 Web 设置页的累计统计和本地日历热力图提供数据。 | | 自带设置页 | Bundle 同时提供统计服务和 Web 设置页面,不依赖 Harness 内置用量页面。 | | 推理强度 | 为自定义 Provider / 模型补充可配置的推理等级。 | | 安全提交 | 只有匹配的成功消息确认后,usage-only chunk 才会计入。 | | 交互式命令 | 挂载 commands 服务时提供 /tokens,随时查看当前摘要。 |

统计仪表盘

配套的 Web 设置视图强调“先看懂,再核对”:

  • 三行累计卡片:总 Token、输入(未命中)、输入(命中)、输出 Token、总调用次数;
  • 独立的今日数据卡片;
  • 根据容器宽度动态适配的 12–52 周热力图;
  • 鼠标悬停或键盘聚焦查看当日精确总 Token 和调用次数;
  • 快照包含模型明细时,显示 Provider / 模型维度的统计。

作为 DSH 插件安装

推荐使用已发布的 npm Bundle:

dsh plugin --profile web add -w --config.auto-install-peers=false dsh-token-usage-counter

然后启动或刷新 Web profile:

dsh web

包内声明了 dsh.bundledsh.client manifest。CLI 会自动应用 cordis.patch.yml 配置层,同时加载宿主端统计服务和浏览器端设置页面,不需要修改 Harness 源码。安装或更新后请重启已经运行的 dsh web,页面会自动加入设置导航。

配置模型推理强度

在自己的 cordis.yml 或最后应用的 patch 中,为同一个插件条目补充 Provider 配置:

- id: token-usage-counter
  name: dsh-token-usage-counter
  config:
    providers:
      cliproxyapi:
        api: openai-responses
        reasoning: high
        efforts:
          low: low
          medium: medium
          high: high
          xhigh: xhigh
          max: max
      jyld:
        api: openai-completions
        models:
          deepseek-v4-flash-0731:
            efforts:
              low: low
              medium: medium
              high: high
              xhigh: xhigh
              max: max

插件只为已经存在于 @deepseek-ai/dsh-llm-pi-ai 设置中的 Provider / 模型补齐 缺失的 reasoningEfforts,不会覆盖手写值;efforts 可用于适配网关自定义的 wire 字符串,disabled: true 可关闭单个模型的推理能力。

本地开发 overlay

发布前直接运行 checkout 时,可以使用本目录提供的 overlay:

dsh web --patch token-usage-counter/cordis.yml

或者在自己的 cordis.yml 中加入:

- name: './src/index.ts'

插件依赖 sessionssettings 服务;当 commands 服务存在时,才会启用 /tokens 命令。

从源码构建

仓库会提交生成后的 lib/index.js,因此从 GitHub 安装时不需要额外的安装时构建 授权。修改源码后,在仓库根目录执行:

pnpm install --config.auto-install-peers=false
pnpm build

随附的 Bundle patch 会先禁用内置的 usage-statsui-usage-stats,再挂载 本插件,因为统计服务使用同一个 settings 命名空间,且设置页由本插件自带。手动 挂载时,请不要同时启用 @deepseek-ai/dsh-usage-stats@deepseek-ai/dsh-client-ui-usage-stats

API

插件提供 ctx.tokenUsageCounter

ctx.tokenUsageCounter.getSummary()
ctx.tokenUsageCounter.getSession(sessionId)
ctx.tokenUsageCounter.getModel(provider, model)
ctx.tokenUsageCounter.formatSummary()

摘要包含全局、Provider / 模型、会话三个层级的统计。每个计数器都保留四个互不 重叠的 provider 用量分桶,以及 totalTokenscalls

计数规则

插件监听持久化的 session/event 事件流,并在加载时接管已经存在的会话。只有 成功完成的锚点才会提交用量:

  • assistant/message.usage 只计入一次;
  • compaction/summary.usage 也会作为一次 provider 调用计入;
  • 单独的 assistant/chunk 会等待匹配的 assistant/message 到达;
  • 同一个 (turn, step) 同时出现 chunk 和最终消息时,以最终值替换早期样本;
  • 失败请求、重试请求和 fork 会话的种子历史不会重复计入。

这样得到的是“已完成的 provider 工作量”,而不是原始流事件数量。

搜索关键词

DeepSeek Harness 插件 · Token 用量统计 · LLM Token 分析 · AI 用量统计 · Prompt Cache 追踪 · 模型用量仪表盘 · 每日 Token 热力图 · 模型推理强度 · reasoning effort · 自定义 Provider · TypeScript Cordis 插件 · 本地优先可观测性 · Provider Token 计费

许可证

MIT