KIDLi1412/dsh-session-cost 预览 preview

KIDLi1412/dsh-session-cost

DSH网页插件:会话状态栏,包含按会话估算的令牌成本(按模型人民币计价)和实时DeepSeek API余额;显示模式可配置(独立状态栏或合并到统计信息行中)。

Project Overview项目介绍

This is a DSH-native web plugin that adds two key pieces of information to the built-in stats bar below the input box of DSH Web: current session token cost estimation and your DeepSeek API account balance. It extracts token usage data (input, output, cache hits) for each model from the session event log, then calculates total cost based on an included CNY pricing table that matches DeepSeek’s official rates. It also pulls real-time balance data from DeepSeek’s official API, with a 2-minute in-memory cache and debounce to avoid excessive API requests.

The plugin displays cost and balance as a clickable pill that matches the styling of DSH’s native stats items. Clicking the pill opens a details panel that breaks down cost per model, shows the split of your balance between recharge and gift credit, and lets you edit the low balance threshold directly in the panel. It is specifically adapted for DSH 0.1.5 and above, fixing common edge cases like delayed stats bar loading, disappearing components after switching sessions, and layout mismatches. Users report no layout conflicts with DSH’s native interface elements.

The plugin is released under the open-source MIT license, and it is free to use and modify. To install, run the DSH plugin command: dsh plugin --profile web add @kidli1412/dsh-session-cost for npm install, or replace the end with the GitHub repo path to install from source. After installation, you will need to restart dsh web and hard refresh your browser to see the plugin take effect. All cost values are estimates based on token usage from session logs, so they should be used for reference only and are not a substitute for official billing data.

这是一款原生 DSH Web 插件,用于在输入框下方的自带统计栏中展示本次会话的 Token 费用估算以及 DeepSeek API 账户余额。它会从会话事件日志中提取每个模型的输入、输出、缓存命中 Token 用量,再按照人民币单价表逐条计算费用,即使是混合多模型的会话也能给出精确估算,还通过官方接口查询余额并做了缓存优化。

插件将费用和余额显示为可点击的统计项,与自带统计栏样式保持一致,点击后可展开明细面板查看各模型费用拆分、余额构成,还能直接在面板内修改低余额阈值。插件适配了 DSH 0.1.5 及以上版本的统计栏布局,解决了统计栏加载延迟、会话切换后组件消失等问题,交互体验和原生功能保持一致。

插件遵循 MIT 许可协议免费使用,默认定价表取自 DeepSeek 官方公开定价,支持用户自定义覆盖单模型定价。安装可通过 DSH 插件命令从 npm 或 GitHub 拉取,安装后需重启 DSH Web 并硬刷新浏览器。费用为估算值,基于会话日志中的 Token 用量计算,仅供参考。

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 @kidli1412/dsh-session-cost

把 KIDLi1412/dsh-session-cost 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-session-cost

DSH(DeepSeek Harness)Web 插件:把本次会话的 Token 费用估算与 DeepSeek API 余额并入输入框下方的自带统计栏。

  • 费用估算:服务端按模型逐条计价——从会话事件日志折叠出每个模型的输入/输出/缓存命中 token(语义与 dsh-token-meter 的 tokenUsage 投影一致),再按 CNY 单价表(lib/cost.js)计算费用,混合多模型的会话也精确。
  • 余额查询:复用官方余额接口 GET {baseURL}/user/balance(参考插件 dsh-usage-stats 的余额方案),凭据经 DSH 的 credentials 缝解析,2 分钟内存缓存 + 单飞防抖;?refresh=1 可强制绕过缓存(状态栏的 ⟳ 手动刷新即用此参数)。
  • 每 30 秒刷新费用、每 5 分钟刷新余额;token 用量变化后自动触发费用刷新;点击统计栏里的费用 pill 展开分模型明细与余额构成(充值/赠送),面板内 ⟳ 手动刷新(强制查询上游,成功后短暂显示"已更新 HH:MM"),面板最后一行直接改低余额阈值。

界面

费用/余额是一个与自带统计项同款的可点击 pill,追加在自带统计栏同一行;若该会话自带统计栏整行都不存在(全新会话,或冷会话加载的头一秒),pill 会先独立显示在输入框上方(同一套字号/内边距/圆角),统计栏一出现就自动并回那一行:

自带统计栏里的费用 pill(第三个)与点击展开的明细面板

  • 点击 pill 在统计栏上方展开明细面板,用的是自带两个 pill 点击展开时的同一套皮肤(圆角 12、--dsw-specific-menu 背景、标题 + 分隔线 + dt/dd 网格、12/18 字号):标题行左侧「费用」、右侧总额;网格里每个模型一行(输入/输出 tokens 与费用,跨峰谷时附 高峰/空闲 拆分),然后是余额与充值/赠送构成——读数网格只有数字;再往下是「更新于 HH:MM + ⟳ 手动刷新」一行,其下一行就是低余额阈值输入框(低余额阈值 [ 10 ] 元,见下);最底是计价说明。点击面板外或按 Esc 关闭。
  • 面板以 position:fixed 挂到 document.body 并做视口夹取(与原生 stat dialog 相同的 measure→place 流程、同样的 8px 间距 / 12px 边距),所以不会被任何祖先容器的 overflow 裁掉;数据更新走原地 patch(不重建节点),因此面板开着时刷新数值不会闪断、也不会丢焦点。
  • DSH 0.1.5 起自带统计栏改为 StatsPills:居中的 flex 行、由带图标的 pill 组成(data-composer-stats 标记),取代了此前单行省略号文本的 StatsLine。本插件的 pill 因此按同一套 13/20 字号层级、同一 1px 8px 内边距与 24px 圆角、同一 hover / aria-expanded 背景渲染,自带 ¥ 图标,视觉上与自带 pill 齐平。
  • 自带统计栏会"迟到":StatsPills 在会话有步骤或 token 之前返回 null(整行都不存在),所以插件必须能在统计栏之后挂载的情况下仍然接上去——见下文「兼容性」。
  • 数据也会迟到:刚重启 host 时首次费用/余额响应还在路上,组件却已经挂载(费用等第一次 summary、余额等上游查询或缓存)。所以观察器无条件安装:曾经在"暂时没东西可画"时干脆不装,结果没有任何人在等统计栏出现,费用段要等页面刷新(数据已被预热)才显示——这就是「每次重启后打开界面都要刷新一次」的原因。现在首个 payload 到达前 sync() 只是不画东西,观察器始终在岗。
  • 切换会话时整个输入区会被拆掉重建:打开一个没有客户端缓存的会话要等约 1 秒,这一秒里锚点处于已脱离文档的子树中。观察器过去只在"宿主仍然连在文档里"时才重新挂载自己——一次这样的回调就让它永久失效,费用段再也回不来,只能刷新页面(刷新等于重新挂载、装上新的观察器)。现在重新挂载是无条件的(脱离文档的节点依然会派发子树变更),另有一个 1 秒看门狗兜底:只要该显示的 pill 不在位(节点被 React 抹掉、统计栏被整体换掉、锚点换了父节点)就重新接回去。
  • 自带统计栏的布局一律不改:0.1.5 的统计栏是居中 flex 行(width:100%、max-width:748px、gap:12px,且不做 overflow 裁剪),追加的费用段只是这一组里的第三项,宽度本来就够——插件不写统计栏的任何行内样式。0.1.x 早期版本曾需要把统计行放宽才能显示追加段(≤ 0.1.4 的 StatsLine 有 748px 上限 + 省略号截断),那个补丁已在 0.2.3 删除。

Showing the opening section of the README — the full document lives in the repository以上为 README 开头摘要,完整文档在仓库内 · View the full README on GitHub →在 GitHub 查看完整 README →

← 上一个 Prev dsh-cae-agent 下一个 Next dsh-settings-drawer →