DSH’s interface usually displays token statistics (such as “71 steps · 257 tok/s”), but lacks a “cost” item. dsh-turn-cost registers a read-only session projection, reads usage events, converts them to RMB using a price table, and displays the amount below the input box and at the end of each response.

What Is This

This is a DSH client plugin. It does not modify DSH’s source code or styles. By injecting a turnCost session projection, it extracts token consumption from the event stream and calculates the amount using price configuration.

Core Features

  1. Statistics pill below the input box
    Adds one to DSH’s existing statistics pills, displaying the cumulative cost.
    The text is formatted like: 本轮 ¥0.42 · 本对话 ¥3.17.
    Hover to view detailed data for the four token buckets.

  2. Per-turn cost badge at the end of each response
    Displays the cost for that turn in the action bar (on the same row as the copy and like buttons).
    The text is formatted like: 本轮 ¥0.42.

  3. Peak/off-peak pricing support
    Reads fields such as peakEnabled and peakWindows from the ledger configuration to support peak/off-peak pricing by UTC time windows.

  4. Built-in fallback pricing table
    When the dsh-cost-meter ledger cannot be read, it uses the DeepSeek deepseek-flash tier hardcoded in the code as a fallback.

Installation and Enablement

Prerequisites: Node.js ≥ 18 and DSH installed locally.

  1. Clone the repository
    git clone https://github.com/CHIP-PHILO-GH/dsh-turn-cost
    cd dsh-turn-cost
  1. Place the plugin
    Place this directory as a plugin in DSH’s profile plugin directory, for example:
    $env:DSH_HOME\profiles\node_modules\dsh-turn-cost
    (Default to ~/.dsh when DSH_HOME is not set)

  2. Load and restart
    The plugin automatically registers the loader through cordis.patch.yml. After installation, restart dsh web for it to take effect.

    After restart, the host side prints a self-check log line:

    [dsh-turn-cost] 已加载,计价:¥ 小数 4 位,汇率 7.2

Configuration

The plugin has no standalone configuration file. It reads DSH’s dsh-cost-meter ledger configuration.

Configuration path:
<DSH_HOME>\storages\cost-meter\ledger.json

Fields that are read (others are ignored):

Key Type Default Description
symbol string ¥ Amount prefix
decimals number 4 Decimal places to display
exchangeRate number 7.2 Exchange rate from USD to RMB
peakEnabled boolean false Peak/off-peak pricing toggle (must be exactly equal to true to take effect)
peakEffectiveAt string None Effective time for peak/off-peak pricing; parsed by Date.parse
peakWindows array [] Peak-hour windows, in UTC hours
prices.models object {} Model ID → unit price record
prices.default object Fallback unit price Used when a model is not registered

Fields in a unit price record:
- cacheHit: Price for cache hits (used for both cache reads and writes)
- cacheMiss: Price for input tokens on cache miss
- output: Price for output tokens
- offPeak / peak: Optional off-peak/peak tier prices

Note: The configuration is read once when the plugin loads. After modifying the ledger, you must restart dsh web for changes to take effect.

Pricing Basis

Formula (units: USD / 1M tokens):

美元成本 = (未缓存输入 × cacheMiss + 输出 × output + (缓存读取 + 缓存写入) × cacheHit) / 1,000,000
人民币   = 美元成本 × exchangeRate

When ledger.json does not exist, cannot be read, or has an incorrect format, the plugin does not throw an error; instead, it uses the built-in fallback table (corresponding to the official DeepSeek deepseek-flash tier):
- Cache hit (including reads and writes): 0.0028
- Cache-miss input: 0.14
- Output: 0.28

Use Cases and Notes

  • Estimate, not billing: The displayed value is an estimate. Pricing depends on the ledger. If the ledger prices differ from actual contract prices, the displayed value may be inconsistent.
  • Four buckets only: It counts only the four token buckets in usage; other billing items are not included.
  • Cache writes priced as hits: Consistent with dsh-cost-meter; cache writes use the cacheHit price.
  • Plugin permissions: The plugin runs with the permissions of the current DSH process. It is recommended to review the source code and license before installation.

Summary

dsh-turn-cost uses a simple projection and DOM injection to solve the pain point of DSH lacking cost statistics. It supports peak/off-peak pricing and includes a built-in fallback, making it suitable for DSH users who need fine-grained control over single-turn conversation costs.