dsh-plugin-session-spend
开发工具 活跃维护

dsh-plugin-session-spend

dtxovo/dsh-plugin-session-spend

轻量级插件,自动跟踪当前会话消耗,按DeepSeek高峰与低谷费率窗口分别计价,清晰展示各时段费用明细,方便开发者掌控单次会话成本。

1
Stars 标星
0
Forks 分支
1
Watchers 关注
0
Open Issues
JavaScript
主要语言
MIT
开源协议
89 KB
仓库大小
1 个月前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:dtxovo/dsh-plugin-session-spend
git clone https://github.com/dtxovo/dsh-plugin-session-spend.git
git clone git@github.com:dtxovo/dsh-plugin-session-spend.git
README.md main

dsh-plugin-session-spend

A DeepSeek Harness plugin that shows what the current
session has cost so far, split by DeepSeek's peak and off-peak rate windows.

The cost pill and its breakdown panel

English | 中文

What it shows

A pill in the composer dock, beside the shipped token-usage pill:

   [shipped] 11 turns 191 steps · 226 tok/s   51.5M tok · 99.5% cached        (¥) ¥2.75

Click it for the breakdown. A session that stayed inside one window shows a single block:

(¥) Cost                                          ¥1.09
───────────────────────────────────────────────────────
Off-peak · 110 requests
Uncached input                          187K tok · ¥0.187
Cache read                            20.77M tok · ¥0.415
Output                                  121K tok · ¥0.482

A session spanning both windows splits into two blocks, each with its own subtotal:

(¥) Cost                                          ¥3.30
───────────────────────────────────────────────────────
Peak · 3 requests
Uncached input                         1.00M tok · ¥2.00
Output                                  100K tok · ¥0.800
Subtotal                                          ¥2.80
Off-peak · 7 requests
Cache read                             5.00M tok · ¥0.100
Output                                  100K tok · ¥0.400
Subtotal                                          ¥0.500

The figure is the whole session, not the loaded window: paging, compaction, and
resuming a session do not change it, and a retried model request is not billed twice.

Install

git clone https://github.com/dtxovo/dsh-plugin-session-spend
cd dsh-plugin-session-spend
powershell -NoProfile -ExecutionPolicy Bypass -File .\install.ps1

The script does two things: copies the package to <profile>\plugins\session-cost\, and
appends the mount entry to <profile>\cordis.patch.yml (skipped when it is already there).
Then refresh the DSH page (Ctrl+R).

The profile directory is resolved in this order: the -ProfileDir argument, then
$env:DSH_PROFILE_DIR, then ~\.dsh\profiles\desktop.

-ExecutionPolicy Bypass is needed because Windows blocks unsigned .ps1 files by
default. On a machine whose execution policy already allows local scripts, .\install.ps1
works as-is. On macOS or Linux, do the same two steps by hand under PowerShell 7.

Upgrading an existing install

Re-running install.ps1 overwrites the files in place, which is enough for a normal version
bump. A release that renames the package is the exception: DSH caches a plugin's resolved
package name at load time, while the client bundle registers under the new one, so the browser
half fails to load even though every file on disk is correct. The script detects that case and
warns — restart DSH, then run it again. Reloading the page is not enough, because the stale
name lives in the host process.

Configure

Edit the profile's cordis.patch.yml and save — the patch layer is watched, so no restart
is needed. Refresh the page afterwards so the browser picks up the new rates.

- insert:
    - id: session-cost-v2
      name: ./plugins/session-cost/host.js
      config:
        currency: "¥"     # display symbol
        per: 1000000      # the four rates below are per this many tokens
        input: 1          # uncached input     <- off-peak rate
        cacheRead: 0.02   # cache read         <- off-peak rate
        cacheWrite: 0     # cache write (DeepSeek does not bill this separately)
        output: 4         # output             <- off-peak rate
        holidays: []      # Beijing dates, e.g. ["2026-10-01", "2026-10-02"]
        # peak:           # omit to default to off-peak x 2
        #   input: 2
        #   cacheRead: 0.04
        #   cacheWrite: 0
        #   output: 8

The built-in defaults are DeepSeek deepseek-flash off-peak list prices in CNY per
million tokens, taken from the official pricing page on 2026-10-15:

Off-peak Peak
Input (cache hit) ¥0.02 ¥0.04
Input (cache miss) ¥1 ¥2
Output ¥4 ¥8

Check them against your own bill. A third-party gateway does not bill these numbers,
and this table covers only deepseek-flash.

Limitations

  • Holidays are yours to fill in. holidays defaults to empty. China's public holidays
    are announced yearly and cannot be derived, so top the list up each year. Weekends that
    are worked as make-up days stay off-peak: the published rule only looks at Monday-Friday
    plus the holiday list.
  • One rate table, not one per model. Switching models mid-session is not detected; every
    token is priced with the same rates.
  • Reasoning tokens are not added on top. reasoningTokens is a subset of what output is
    billed for, so adding it would double-count.
  • An estimate, not an invoice. Token cost only — no minimum spend, tiered pricing,
    currency conversion, or granted credit.
  • The peak window is fixed at Beijing time Monday-Friday 09:00-12:00 and 14:00-18:00.

The design behind the numbers, and the DSH internals this plugin had to work around, are in
docs/IMPLEMENTATION.md.

Development

node .\check.mjs         # 44 assertions on the client half, against ./client.js
node .\check-host.mjs "<profile>\plugins\session-cost\host.js"   # 33 assertions on the host half

check.mjs needs nothing but Node: it renders the client half through a small React
stand-in that covers exactly the API surface the component uses.

check-host.mjs imports the host half, which resolves @deepseek-ai/schemastery and zod
from its own location — both are supplied by DeepSeek Harness. Point it at an installed copy
(the normal case), or install those two packages first. Run it with no argument and it says
so instead of failing silently.

Releasing

Publishing happens in CI, never from a laptop: .github/workflows/publish.yml
publishes on a v* tag through npm Trusted Publishing (OIDC), so this repository holds no
NPM_TOKEN and no long-lived write credential — nothing to leak and nothing to rotate.
Provenance attestations are attached automatically for a public package in a public repository.

  1. Bump version in package.json and commit.
  2. git tag v0.1.0 && git push origin v0.1.0.

The tag-driven run needs a Trusted Publisher configured once on npmjs.com: the package's
Settings → Trusted Publisher → GitHub Actions, with user dtxovo, repository
dsh-plugin-session-spend, and workflow publish.yml.

License

MIT © 2026 dtxovo