dsh-simple-usage-info
其他 活跃维护

dsh-simple-usage-info

MarJose123/dsh-simple-usage-info

在消息输入框下方实时显示API账户余额,并标出当前处于高峰还是低谷计费时段,让用户无需切换页面即可掌握调用成本,合理规划使用节奏,避免意外超支。

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

dsh-simple-usage-info

npm
license

A DeepSeek Harness plugin that puts your
DeepSeek API balance, the current billing window, and the session estimated cost in the
composer dock — the ambient row directly below the message input, after the context meter.

Click the bar for the full breakdown:

The pill reads Off-peak (green) or Peak (red). The balance is read with the same
DEEPSEEK_API_KEY credential the deepseek-official model route resolves — no extra setup. The
billing window is computed in your browser's timezone and drawn from the published rule: off-peak is
half price, peak is 01:00–04:00 and 06:00–10:00 UTC, Monday–Friday, excluding Chinese public
holidays. The holiday list is fetched from
NateScarlet/holiday-cn, which scrapes the State Council
announcements daily, so it keeps itself current.

The Estimated cost section shows the running session cost in both USD and CNY, calculated from
the token usage (cached input, uncached input, and output) using the published peak and off-peak
rates of the model selected for the session. Supported models are deepseek-flash
(DeepSeek-V41-Flash) and deepseek-v4-pro (DeepSeek-V4-Pro-0813). The section appears only when
the session has non-zero token usage.

Requirements

  • DeepSeek Harness 0.2.0-rc.2 or later
  • Node 20+
  • A DEEPSEEK_API_KEY credential (the Models page writes one, or export it before launching)

Install

Recommended — the DSH plugin manager

The plugin manager forwards to pnpm, so install that first if it is missing:

bun add -g pnpm        # or: corepack enable pnpm / npm i -g pnpm
dsh plugin --profile web add dsh-simple-usage-info

This installs the package, records it in the profile's dependencies, and appends it to
dsh.profile.bundles. Because the package declares dsh.bundle.patch, its own cordis.patch.yml
then supplies the loader row — there is nothing else to edit.

Restart the web server (dsh web) when it finishes.

Manual — a cordis.patch.yml row

Use this when the package is already somewhere the profile can resolve (a local checkout, a
workspace link, a private registry). Append to $DSH_HOME/profiles/web/cordis.patch.yml:

- insert:
    - id: usage-info
      name: dsh-simple-usage-info

Restart the web server. Use either this row or the bundles entry from the recommended
path, never both, or the plugin loads twice.

Manual without pnpm — add the dependency yourself

dsh plugin only knows how to shell out to pnpm. Without it, do the two halves by hand.

1. Make the package resolvable from the profile. Either install it with any package manager:

cd "$DSH_HOME/profiles/web"
bun add dsh-simple-usage-info     # or: npm install dsh-simple-usage-info

…or link a local checkout:

mkdir -p "$DSH_HOME/profiles/web/node_modules"
ln -sfn /absolute/path/to/dsh-simple-usage-info \
        "$DSH_HOME/profiles/web/node_modules/dsh-simple-usage-info"

and declare it in $DSH_HOME/profiles/web/package.json, because DSH treats a name as profile-local
only when the manifest lists it:

{
  "name": "dsh-profile-web",
  "private": true,
  "dependencies": {
    "dsh-simple-usage-info": "link:/absolute/path/to/dsh-simple-usage-info"
  },
  "dsh": {
    "profile": {
      "bundles": [
         ////
      ]
    }
  }
}

2. Activate it with the cordis.patch.yml row above, or by adding "dsh-simple-usage-info" to
the dsh.profile.bundles array.

Restart the web server.

Configure

Set these under the usage-info row, in the profile's cordis.patch.yml:

Key Default Meaning
refreshMs 60000 how long one balance answer stays fresh
timeoutMs 15000 upstream request timeout
baseURL https://api.deepseek.com API origin
apiKeyEnv DEEPSEEK_API_KEY credential name holding the key
peakWindows ['01:00-04:00', '06:00-10:00'] peak windows, HH:MM-HH:MM UTC
peakDays [1, 2, 3, 4, 5] peak weekdays, 0 = Sunday
holidayURL holiday-cn {year}.json maintained holiday source; '' goes offline
holidayRefreshMs 43200000 how long a fetched holiday snapshot stays fresh
useBundledHolidays true keep the bundled table as an offline fallback
holidays [] extra YYYY-MM-DD dates, added on top of the fetched list
makeupWorkdaysArePeak false treat 调休 makeup workdays as peak days
makeupWorkdays [] extra YYYY-MM-DD makeup workdays
offPeakDiscountPercent 50 reported as pricing.discountPercent

For example:

- id: usage-info
  config:
    peakWindows:
      - '01:00-04:00'
      - '06:00-10:00'
    holidays:
      - 2027-01-01

A malformed schedule (a bad clock, a window wrapping past midnight, a day outside 0–6) fails at
plugin load, so the row is skipped with a clear error instead of answering requests with a broken
window.

Verify

# the route, once the server is running:
curl -s -H 'Host: 127.0.0.1:3080' http://127.0.0.1:3080/usage/balance

# the plugin really composes into a profile (throwaway home, your profile untouched):
bun run verify:compose

pricing.holidayData in the response tells you where the holidays came from — remote (fetched),
bundled (offline fallback), or none.

Development

bun install
bun run preflight          # host, pricing, holidays, client — 200+ assertions, no network
bun run preflight:live     # real balance + holiday fetch; prints the masked key only
bun run preview:panel      # prints the popover markup and stylesheet, no browser needed

There is no build step: lib/index.js is plain ESM, and lib/client.js is hand-authored in the web
client's module-loader bundle format. Neither half needs a bundler.

License

MIT