jkStars/dsh-token-usage-stats 预览 preview

jkStars/dsh-token-usage-stats

DSH Web 插件:跨会话的 Token 用量、请求次数与可选成本统计(ctx.tokenUsageStats),自带独立仪表盘页面(/token-usage-stats,JSON 数据源 /api/token-usage-stats)以及侧边栏底部入口(页内模态框打开仪表盘)。

catalog descriptioncatalog 简介 / catalog description:DSH plugin: cross-session token usage analytics with a web dashboard (ctx.tokenUsageStats)

Project Overview项目介绍

This is a native web plugin built exclusively for DeepSeek Harness (DSH), designed to track cross-session token consumption, API request counts, and calculate optional usage costs for DeepSeek API calls. It ships with a standalone statistics dashboard accessible at the /token-usage-stats endpoint, a JSON data API at /api/token-usage-stats, and adds a quick access entry at the bottom of DSH’s sidebar that opens the dashboard in an in-page modal. To install the plugin, you can run the DSH CLI command dsh plugin --profile web add dsh-token-usage-stats@latest, then restart the DSH host or refresh the GUI to activate it.

After installation, you can open the dashboard either by clicking the "Usage Stats" entry in the sidebar or navigating directly to the dashboard URL in your browser. By default, the dashboard displays hourly stats for the current day, but you can switch between five time ranges: today, last 3 days, last 7 days, last 30 days, and all time. The dashboard automatically adjusts grouping granularity based on the selected range to keep charts clear and uncluttered, and it auto-refreshes every 10 seconds to pull the latest usage data. This tool is ideal for DSH users who want to track their DeepSeek API spending and avoid unexpected charges.

Currently, the plugin only supports tracking usage and costs for DeepSeek’s official API, pulling all usage data from local DSH session logs; it does not support tracking API usage from third-party providers or other channels. Users can configure their preferred display currency and custom pricing per million tokens for any model, with built-in support for peak and off-peak pricing tiers based on Beijing time. Default pricing for DeepSeek’s official models is already included, and the plugin is open source under the permissive MIT license, free for anyone to use and modify.

这是一款专为 DeepSeek Harness 开发的原生网页插件,用于统计跨会话的 Token 用量、API 请求次数,并支持可选的成本计算。插件自带独立的统计仪表盘页面(路径 /token-usage-stats),提供 JSON 格式数据源接口(/api/token-usage-stats),还在 DSH 侧边栏底部添加了入口,点击可通过页内模态框打开仪表盘。用户可通过 DSH 自带的插件命令直接在线安装,安装后重启宿主或刷新 GUI 即可使用。

安装完成后,用户可以点击侧边栏底部的「用量统计」入口打开仪表盘,也可以直接访问对应路径打开统计页面。仪表盘默认展示当日按小时分组的统计数据,支持切换今日、近3天、近7天、近30天、全部范围五种统计区间,不同区间会自动适配合适的时间分组粒度,保证图表清晰不拥挤。这款插件适合需要监控自己 DeepSeek API 用量、控制 API 调用成本的 DSH 用户使用。

目前该插件仅支持统计 DeepSeek 官方 API 的用量和成本,数据基于本地 Harness 会话日志回放生成,不支持统计其他渠道或第三方提供商的 API 费用。用户可自行配置显示货币和各模型的百万 Token 定价,支持区分高峰闲时段不同计价,插件已内置 DeepSeek 官方模型的默认定价。该插件采用 MIT 许可开源,免费供用户使用和修改。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 1 warning1 项注意
  • Only 3 stars - very few users, little community feedback星标只有 3,几乎没人在用,遇到问题缺少社区反馈
DSH walks through these 9 checksDSH 会逐条核对这 9 项

Compatibility兼容性

  • DSH, Node, OS and profile requirementsDSH 版本 / Node 版本 / 操作系统 / profile 是否满足要求
  • External dependencies and runtimes (Electron / Python / Docker, ...)外部依赖与运行时(Electron / Python / Docker 等)是否齐备
  • Conflicts with installed plugins: command names, skill / tool names, ports, duplicate MCP registration与已装插件是否冲突:命令名、skill / tool 重名、端口占用、重复 MCP 注册

Security安全性

  • Repo matches the facts registered here; archived or abandoned?仓库是否与页面登记一致,是否归档或长期停更
  • Safety of preinstall / install / postinstall and install.sh / setup.ps1preinstall / install / postinstall 与 install.sh、setup.ps1 是否安全
  • curl|bash, download-then-execute, obfuscation, unrelated domains → stop immediatelycurl|bash、下载即执行、混淆代码、无关域名 → 立刻停止
  • Typosquatting or unmaintained packages among the new dependencies新增依赖里有没有 typosquatting 或无人维护的包
  • Requested permissions vs. what the feature actually needs申请了哪些权限、是否超出功能所需(filesystem / network / shell / clipboard)
  • Any sudo / admin requirement, plus uninstall and rollback是否要求 sudo / 管理员权限,以及卸载与回滚方式

Anything uncertain must be marked unknown with a note on how to confirm it. This site's signal screen is a static snapshot, not a security audit.拿不准的必须标「未知」并说明要我怎么确认。本站的信号筛查是静态快照,不能替代安全审计。

Or use CLI install (for developers)或使用命令行安装(适合开发者)

CLI Install命令行安装

dsh plugin --profile web add dsh-token-usage-stats@0.3.14

把 jkStars/dsh-token-usage-stats 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-token-usage-stats

简体中文 | English

DSH Web 插件:跨会话的 Token 用量、请求次数与可选成本统计(ctx.tokenUsageStats),自带独立仪表盘页面(/token-usage-stats,JSON 数据源 /api/token-usage-stats)以及侧边栏底部入口(页内模态框打开仪表盘)。

截图

侧边栏底部入口 — 点击「用量统计」打开仪表盘

使用入口

仪表盘 - 今天视图(成本堆叠、token 趋势、构成占比、按模型与 TOP 对话表)

仪表盘 - 今天

构成明细悬浮提示(悬停柱子查看分类明细)

仪表盘 - 悬浮提示

全部范围 - 按天视图

仪表盘 - 全部范围

说明:目前仅统计 DeepSeek 官方 API 的费用(token 用量、请求次数与成本基于本地 Harness 会话日志回放),不包含其它提供商/渠道的 API 费用。

安装

dsh plugin --profile web add dsh-token-usage-stats@0.3.14

插件的 cordis.patch.yml 会插入插件行;浏览器半区通过 dsh.client 清单自动加载。安装后重启宿主(或刷新 GUI)。

更新到新版本:

dsh plugin --profile web add dsh-token-usage-stats@latest

使用

从侧边栏底部入口打开仪表盘,或直接访问 http://<host>:<port>/token-usage-stats。

页面默认显示「今天」的按小时视图,可切换 今天 / 近 3 天 / 近 7 天 / 近 30 天 / 全部 范围,其中「近 7 天」、「近 30 天」和「全部」显示按天视图(「全部」在跨度较长时会自动按自然周或自然月折叠展示,确保图表清晰不拥挤)。每 10 秒自动刷新一次。仅当配置了模型定价时才显示成本金额。

配置

插入行支持 config.currency(成本显示货币)与 config.pricing(各模型每百万 token 的价格)。成本按高峰/闲时两档计价:高峰为北京时间 09:00-12:00、14:00-18:00,其余北京时段为闲时;周末(北京时间周六/周日)全天按闲时。用 peak/offpeak 两档的模型按使用时间取对应档位;只用四个平档键(uncachedInputPerMillion / cacheReadPerMillion / cacheWritePerMillion / outputPerMillion)的模型任意时段同价。默认行带 currency: CNY,以及 deepseek-flash 与 deepseek-v4-pro 的官方高峰/闲时定价(自动兼容 deepseek-v4-flash* 历史模型别名)。

在 profile 自己的 cordis.patch.yml 中覆盖示例:

- patch:
    - id: token-usage-stats
      config:
        currency: USD
        pricing:
          deepseek-flash:
            peak:
              uncachedInputPerMillion: 2.0
              cacheReadPerMillion: 0.04
              cacheWritePerMillion: 0
              outputPerMillion: 8.0
            offpeak:
              uncachedInputPerMillion: 1.0
              cacheReadPerMillion: 0.02
              cacheWritePerMillion: 0
              outputPerMillion: 4.0

开发

pnpm install   # devDependencies 通过 link: 指向本地 deepseek-harness checkout
pnpm run build # tsc -> lib/types, tsdown -> lib/index.js + lib/client.js

devDependencies 通过 link: 条目解析 @deepseek-ai/dsh-* 的类型,要求 harness checkout 位于本包上一级目录 ../deepseek-harness。运行时 peer 依赖由 dsh 宿主提供,不从 npm 安装。

发布

npm run build
npm publish    # 自动执行 prepublishOnly(npm run build)

仓库与反馈

欢迎提 Issue 或 PR。

← 上一个 Prev dsh-project-prompt 下一个 Next dsh-theme-liquid-glass →