@kenz1117/dsh-ui-usage-billing 0.9.17 → 0.9.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +63 -30
- package/README.md +62 -31
- package/lib/client.js +544 -364
- package/lib/index.js +577 -37
- package/lib/types/aggregate.d.ts +39 -0
- package/lib/types/client/UsageBilling.d.ts +13 -2
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/declarative.d.ts +55 -0
- package/lib/types/index.d.ts +13 -1
- package/lib/types/pricing-shared.d.ts +84 -0
- package/lib/types/reconcile.d.ts +60 -0
- package/lib/types/relay.d.ts +6 -0
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
# dsh-ui-usage-billing
|
|
4
4
|
|
|
5
|
-
<p align="center">
|
|
5
|
+
<p align="center">See every cent of your model spend — at a glance.</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/
|
|
9
|
-
<a href="https://
|
|
10
|
-
<a href="https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing"><img alt="npm
|
|
11
|
-
<a href="https://
|
|
12
|
-
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/
|
|
8
|
+
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/kenz1117/dsh-ui-usage-billing?logo=github"></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing"><img alt="npm version" src="https://img.shields.io/npm/v/@kenz1117/dsh-ui-usage-billing?logo=npm"></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@kenz1117/dsh-ui-usage-billing?logo=npm"></a>
|
|
11
|
+
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/blob/main/LICENSE"><img alt="License MIT" src="https://img.shields.io/github/license/kenz1117/dsh-ui-usage-billing"></a>
|
|
12
|
+
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/pulls"><img alt="PRs welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen"></a>
|
|
13
|
+
<a href="https://github.com/kenz1117/dsh-ui-usage-billing"><img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/kenz1117/dsh-ui-usage-billing?logo=github"></a>
|
|
13
14
|
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/graphs/contributors"><img alt="GitHub contributors" src="https://img.shields.io/github/contributors/kenz1117/dsh-ui-usage-billing"></a>
|
|
14
15
|
<a href="https://awesome-dsh-plugin.com"><img alt="Awesome DSH Plugin" src="https://awesome-dsh-plugin.com/badge.svg"></a>
|
|
15
16
|
</p>
|
|
@@ -22,41 +23,71 @@
|
|
|
22
23
|
|
|
23
24
|
> **Peak/off-peak pricing update (from 2026-08-23 (Sun) 00:00 Beijing)**: DeepSeek models follow the new official rule — **weekdays (Mon–Fri)** keep the original peak/off-peak split (peak 09:00–12:00 / 14:00–18:00, ×2); **weekends (Sat/Sun)** are no longer split and are billed at the **off-peak price** all day. The plugin's billing engine, rate table and per-turn peak/off-peak bands all reflect this.
|
|
24
25
|
|
|
26
|
+
<div align="center">
|
|
27
|
+
<img src="screenshots/demo.png" alt="dsh-ui-usage-billing — billing dashboard overview" width="80%">
|
|
28
|
+
</div>
|
|
29
|
+
|
|
25
30
|
### Demo GIF
|
|
26
31
|
|
|
27
32
|

|
|
28
33
|
|
|
29
|
-
##
|
|
34
|
+
## ✨ Highlights
|
|
35
|
+
|
|
36
|
+
- **Real usage, no fabricated samples** — the server aggregates from persisted session logs and estimates against live multi-provider official prices; it shows an empty snapshot until real data arrives.
|
|
37
|
+
- **Everything on one screen** — a sidebar trigger card plus a full dashboard (Overview / Trends / Providers / Stats / Rates / Settings) across six tabs: month / today / projection / heatmap / trend.
|
|
38
|
+
- **Subscriptions · balance · quota · reconcile** — plan quota, multi-provider balance, relay-station quota, declared endpoints and balance-delta reconciliation form a cross-verifiable billing loop.
|
|
39
|
+
- **Peak/off-peak pricing + switch alerts** — weekday peak split and weekend all-day off-peak, with a popover / system notification before a tier switch, configurable lead time.
|
|
40
|
+
- **Offline & self-contained** — no chart library, no external CDN, pure design tokens; lightweight and ready to use.
|
|
41
|
+
- **Multi-language + dual currency** — Chinese / English, ¥/$ toggle that only affects this plugin.
|
|
42
|
+
|
|
43
|
+
## 📊 Dashboard
|
|
30
44
|
|
|
31
45
|
- **Sidebar entry**: a dashboard-style trigger card above the Settings button — month cost as the headline number (monospace) with a 7-day sparkline mini-trend, second line "Today / This week"; collapses to an icon button; hover reveals a quick-look card.
|
|
32
|
-
- **Billing dashboard (tabbed)**: Overview / Trends / Providers / Stats / Rates / Settings — hero figures + YoY/DoD + month projection + KPI×4 + heatmap; 7/30-day trend; provider billing & subscriptions; export / cost breakdown / workspaces / session detail; model rate table; budget & peak alerts. Restrained tones, `--dsw-*` tokens, dark/light adaptive.
|
|
46
|
+
- **Billing dashboard (tabbed)**: Overview / Trends / Providers / Stats / Rates / Settings — hero figures + YoY/DoD + month projection + KPI×4 + heatmap; 7/30-day trend (switches between Cost / Tokens); provider billing & subscriptions; export / cost breakdown / workspaces / session detail; model rate table; budget & peak alerts. Restrained tones, `--dsw-*` tokens, dark/light adaptive.
|
|
33
47
|
|
|
34
48
|

|
|
35
49
|
- **Live cost bar**: below the composer, persistent "This turn ¥x · Session ¥y" plus the peak/off-peak tier & switch countdown and subscription low-quota chips (≤20% appear, ≤10% red).
|
|
36
50
|
- **Peak/off-peak switch alert**: a popover before a tier switch plus an optional system notification (lead time / position / mode / preview configurable), distinguishing "About to enter peak ×2 — can wait" / "About to enter off-peak, price halves".
|
|
51
|
+
- **Plugin info card**: a persistent "About" card in the Settings tab — name, description, author (jump to GitHub), source repo, npm, MIT license, version (read server-side from the package's `package.json`, single source of truth, correct on publish).
|
|
52
|
+
|
|
53
|
+
## 💰 Billing engine
|
|
54
|
+
|
|
37
55
|
- **Live-priced rate table**: models.dev fetched pricing + live-model alignment — the models actually configured are all included; peak/off-peak split (weekdays 9-12 / 14-18 peak ×2, weekends off-peak all day) plus a live USD→CNY rate, refreshed every 6 hours.
|
|
38
56
|
|
|
39
57
|

|
|
40
58
|
- **Official vs third-party buckets**: the detail cost column is split by official DeepSeek direct / third-party relay ("official x / third y" when mixed); the Stats tab has an official/third-party summary card.
|
|
41
|
-
- **
|
|
42
|
-
- **
|
|
43
|
-
|
|
59
|
+
- **Monthly budget + tier alerts**: a budget bar (on/off / amount / progress, ≥80% amber, over red pulse); notifies once per tier crossing 50/80/100%.
|
|
60
|
+
- **Cost-spike attribution**: per-turn cost bars (last 40 turns, amount at bar top, peak/off-peak background bands, >2× spike flagged with attribution).
|
|
61
|
+
|
|
62
|
+
## 🔌 Subscriptions & balance
|
|
63
|
+
|
|
64
|
+
- **Subscription quota**: detects subscription providers in `llm-pi-ai` (Kimi / Z.ai / OpenCode Go / MiniMax / OpenRouter / Xiaomi / Volcano…); those with a quota API show remaining % and reset time live, exhausted in red, no API shown as "not wired"; subscription-channel model cost is 0. **MiniMax note**: use the `minimax-token-plan-cn` provider id for `https://api.minimaxi.com`; the international route keeps `minimax` / `minimax-token-plan` against `https://www.minimaxi.com`. Override `baseUrl` per provider for proxies or staging.
|
|
65
|
+
- **Multi-provider balance**: DeepSeek / Kimi / StepFun / SiliconFlow / xAI / Zhipu GLM (Z.ai CN region) built-in official balances, and the balance column estimates "≈N days" from the 7-day daily burn.
|
|
66
|
+
- **Custom provider balance**: configure any HTTP endpoint for balance (`extract` supports constant / dot-path / add-subtract / divide, header `{{ENV}}` via the credentials seam).
|
|
67
|
+
- **Declared endpoints + balance reconcile**: **declared endpoints** (`declaredEndpoints`) let you self-declare balance/quota interfaces for vendors absent from the built-in table — you write only dot-paths ("where the number is"), no expressions; the request URL is built from the matched same-origin provider's `origin`, and safety bounds (single-slash absolute path, GET only, reject cross-origin redirects, response-size/timeout caps, credentials only from the matched provider's own `apiKeyEnv`) are enforced by `src/declarative.ts`; a wrong path is shown in the UI as `declared` with a `reason`. **Balance reconcile** (`reconcilePath`) cross-checks the official (DeepSeek-direct only) balance change against the local ledger's official-channel cost for the day, and flags a drift above the threshold (0.3 CNY and >15%) so you can double-check the price table or recent bills; top-ups / grants / currency changes reset the baseline instead of alerting, and a flat balance (subscription spend) stays silent.
|
|
68
|
+
- **Relay-site attribution & quota**: usage is grouped by a provider's `baseURL` origin — multiple keys on the same relay station merge into one row, named by its domain. Routes with a `baseURL` are auto-detected as New API (`/api/status`) or Sub2API (`/v1/usage`) to read their **balance and rolling quota windows**, labeled "no quota" when unreadable, <20% remaining in red; station recognition is cached for 5 minutes (multiple keys on one station fuse-break independently), and the `relay-quotas` endpoint attaches `diagnostics` for "why is my relay not showing". Project attribution prefers the workspace title for naming. **Unpriced models** (out-of-catalog / no price) count as 0 cost, with a "N models not priced" hint under the hero.
|
|
44
69
|
|
|
45
70
|

|
|
46
|
-
- **Custom provider balance**: configure any HTTP endpoint for balance (`extract` supports constant / dot-path / add-subtract / divide, header `{{ENV}}` via the credentials seam); DeepSeek / Kimi / StepFun / SiliconFlow have built-in official balances, and the balance column estimates "≈N days" from the 7-day daily burn.
|
|
47
|
-
- **Real usage aggregation**: the server aggregates from session logs on demand (incremental cache recomputes only written sessions), with per-session corruption tolerance and snapshot fallback; an optional `usage_stats` tool lets the model query today / month / current session / cumulative spend, plus `bySite` (relay-attributed) and `relay` (relay-only) summaries (**off by default** — toggle it in the Settings tab; takes effect after a reload).
|
|
48
|
-
- **Multi-language + dual currency**: the ¥/$ switch is bilingual (USD→English, CNY→Chinese, this plugin only); the rate table converts to the selected currency.
|
|
49
|
-
- **Model health + uncatalogued annotation**: provider connection dots (green / red / grey); a model id not in the catalog is marked "uncatalogued" priced at the fallback, with provider inferred (e.g. `mi-mimo-2.5` → Xiaomi); estimated-price models are marked "estimated".
|
|
50
|
-
- **Session detail + cost spikes + heatmap**: sessions sorted by cost (title / project / calls / cost / last active); per-turn cost bars (last 40 turns, amount at bar top, peak/off-peak background bands, >2× spike flagged with attribution); a monthly calendar heatmap (5-color scale, hover detail).
|
|
51
71
|
|
|
52
|
-
|
|
72
|
+
## 📈 Usage visualizations
|
|
53
73
|
|
|
74
|
+
- **Session detail + cost spikes + heatmap**: sessions sorted by cost (title / project / calls / cost / last active); per-turn cost bars (peak/off-peak background bands, >2× spike flagged with attribution); month / year calendar heatmap (5-color scale, hover detail; the year view is ~52 weeks, GitHub-style), with active-day and streak counts on top.
|
|
75
|
+
- **Performance metrics**: per-model first-token latency (TTFT) mean / P50 / P90, generation speed (tokens/s), total-latency mean, plus per-hour TTFT and speed curves aggregating by Beijing hour; rendered in the Stats tab as a per-model performance table and per-hour TTFT/speed dual line charts.
|
|
76
|
+
- **Token insights**: a dedicated "Tokens" tab — daily token stacks colored by "input (cache miss) / input (cache hit) / output" (including reasoning), per-model totals and share, structural KPIs (cache-hit rate / reasoning share / input-output ratio / peak day); per-day token CSV and JSON export.
|
|
77
|
+
|
|
78
|
+

|
|
54
79
|
- **Export + offline self-contained**: the Stats tab exports daily / per-session / per-site CSV and full JSON; cost breakdown / workspaces / session-detail sections are drillable (click a project row to expand its sessions); no chart library, no external CDN, pure design tokens.
|
|
55
|
-
- **Stability & reliability**: official-interface shape drift degrades with an explicit `invalid` status (distinct from network-unreachable); balance / subscription / pricing upstreams share a unified timeout budget, exponential-backoff retry and per-platform circuit-breaker cooldown; the stats snapshot is written with a `.bak` backup and auto-recovers from corruption; session-log reads re-check freshness to avoid half-line misreads; auth failures warn per provider with cooldown; the per-session fold cache is bounded by LRU to keep long-running memory stable.
|
|
56
80
|
|
|
57
81
|

|
|
58
82
|
|
|
59
|
-
##
|
|
83
|
+
## 🛡️ Robustness & privacy
|
|
84
|
+
|
|
85
|
+
- **Real usage aggregation**: the server aggregates from session logs on demand (incremental cache recomputes only written sessions), with per-session corruption tolerance and snapshot fallback; an optional `usage_stats` tool lets the model query today / month / current session / cumulative spend, plus `bySite` (relay-attributed) and `relay` (relay-only) summaries (toggle it in Settings; takes effect after a reload).
|
|
86
|
+
- **Model health + uncatalogued annotation**: provider connection dots (green / red / grey); a model id not in the catalog is marked "uncatalogued" priced at the fallback, with provider inferred (e.g. `mi-mimo-2.5` → Xiaomi); estimated-price models are marked "estimated".
|
|
87
|
+
- **Multi-language + dual currency**: the ¥/$ switch is bilingual (USD→English, CNY→Chinese, this plugin only); the rate table converts to the selected currency.
|
|
88
|
+
- **Privacy baseline**: a pure UI surface — registers no tools, injects no system prompt, writes no model-visible events; it only aggregates from existing session logs, whose content is owned by other packages.
|
|
89
|
+
|
|
90
|
+
## 🚀 Quick start
|
|
60
91
|
|
|
61
92
|
Add to the host `cordis.patch.yml`:
|
|
62
93
|
|
|
@@ -74,7 +105,7 @@ npm install @kenz1117/dsh-ui-usage-billing
|
|
|
74
105
|
|
|
75
106
|
After the host starts, the billing entry appears above the sidebar Settings. No extra configuration is needed; when `sessionPersistence` is available it aggregates real usage automatically.
|
|
76
107
|
|
|
77
|
-
## How it works
|
|
108
|
+
## ⚙️ How it works
|
|
78
109
|
|
|
79
110
|
The plugin has a server side and a browser side:
|
|
80
111
|
|
|
@@ -94,11 +125,11 @@ Browser Server (Node)
|
|
|
94
125
|
- **Server** (`src/index.ts`): injects `webServer`, `sessionPersistence` and `credentials`, and registers `GET /api/billing/usage-stats`, `/api/billing/pricing`, `/api/billing/balance`, `/api/billing/subscriptions`, `/api/billing/relay-quotas`. The aggregator caches folded results per session: each LLM call is attributed to the model of its preceding `request/header`, tokens split into cache-hit / cache-miss buckets, dates bucketed by the local timezone; a log file with unchanged mtime+size reuses its cached fold, only written sessions are re-folded, and the whole document has a 5s TTL to coalesce heavy polling. Every successfully folded session is also atomically written to an independent durable usage ledger, so permanently deleting a session no longer removes its historical cost or tokens. Aggregation logic lives in `src/aggregate.ts`.
|
|
95
126
|
- **Browser** (`src/client/`): requests the endpoints above to render the dashboard and probes each provider connection via `llm.models`. Until real data arrives it shows an all-zero empty snapshot, never fabricated samples.
|
|
96
127
|
|
|
97
|
-
## Theme collaboration
|
|
128
|
+
## 🧩 Theme collaboration
|
|
98
129
|
|
|
99
130
|
This plugin **depends on no theme package** and runs standalone. The dashboard modal declares a `billing.dashboard.decor` decoration slot (head / hero / trend / models / footer anchors) and registers a real-time cost summary as the `ctx.billingMetrics` service: theme plugins (e.g. acid-zine) inject their own decoration visuals (MacDots, tape, torn notes…) and subscription-cost data into their sticker layer. Plugin and theme load/unload independently — with no theme the default visuals apply; without billing the theme still runs.
|
|
100
131
|
|
|
101
|
-
## Billing
|
|
132
|
+
## 💡 Billing details
|
|
102
133
|
|
|
103
134
|
The rate table (`src/client/pricing.ts`) stores each model in its **native currency**: domestic providers enter CNY directly, overseas providers enter USD. Cost is computed and displayed in CNY uniformly — USD models convert via the **live rate**, domestic models never pass through a rate. At startup the server fetches the live rate and model prices (`src/pricing-fetch.ts`): USD→CNY prefers the Tencent Finance quote (keyless, reachable in China), falling back to open.er-api then the built-in default; it then refreshes every 6 hours, and the rate-table modal shows a "today's rate" marker plus live / built-in badge. The **display currency follows the user**: switching ¥ / $ converts each per-1M-token unit price via `convertUnitPrice` at the live rate (falling back to the native currency when the rate is unavailable).
|
|
104
135
|
|
|
@@ -137,11 +168,11 @@ cost (CNY) = (missInput × p_input + cacheHit × p_cacheHit + output × p_output
|
|
|
137
168
|
|
|
138
169
|
To add a model: append an entry to `MODEL_CATALOG` and map its real id in `MODEL_KEY_ALIASES` in `src/client/pricing.ts` (shared by the aggregation layer and the client renderer).
|
|
139
170
|
|
|
140
|
-
## HTTP API
|
|
171
|
+
## 🔌 HTTP API
|
|
141
172
|
|
|
142
173
|
The public HTTP endpoints and field definitions are documented in source: `GET /api/billing/pricing`, `/api/billing/balance`, `/api/billing/usage-stats`, `/api/billing/subscriptions`, `/api/billing/relay-quotas` (see `src/index.ts`, `src/aggregate.ts`, `src/relay.ts`). The `usage-stats` payload carries `bySite` (relay-attributed usage distribution: `site:<origin>` / `direct:<provider>` / `unknown`) and `unpricedModels` (ids of models with no price); `relay-quotas` returns `quotas` plus `diagnostics` (per-route origin / kind classification, for "why is my relay not showing"). All endpoints accept loopback requests only (peer socket address + Host header verified).
|
|
143
174
|
|
|
144
|
-
## Configuration
|
|
175
|
+
## ⚙️ Configuration
|
|
145
176
|
|
|
146
177
|
| Field | Default | Description |
|
|
147
178
|
| ----------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -152,8 +183,10 @@ The public HTTP endpoints and field definitions are documented in source: `GET /
|
|
|
152
183
|
| `monthlyBudget` | unset | Default monthly budget (CNY); sent with usage-stats as the budget bar's initial amount (user UI settings take precedence and persist locally) |
|
|
153
184
|
| `lowBalanceThreshold` | `50` | Low-balance alert threshold (CNY); sent with usage-stats, alerts once a day when any provider's CNY balance is below it |
|
|
154
185
|
| `subscriptionPlans` | auto-detect | Subscription quota adapter whitelist (`{ provider, baseUrl?, region? }`); when unset, auto-detects all subscription providers from `llm-pi-ai` (queries those with a quota API, marks the rest) |
|
|
186
|
+
| `declaredEndpoints` | unset | Declared endpoints (`{ displayName, origin, path, fields?, windows?, raw? }`): self-declare balance/quota interfaces for providers absent from the built-in table, writing only dot-paths ("where the number is") with no expressions; the request URL is built from the matched same-origin provider's `origin` and safety bounds (single-slash absolute path, GET only, reject cross-origin redirects, response-size/timeout caps, credentials only from the matched provider's own `apiKeyEnv`) are enforced by `src/declarative.ts` |
|
|
187
|
+
| `reconcilePath` | `~/.dsh/.dsh-usage-reconcile.json` | Balance-delta reconcile baseline path; cross-checks the official (DeepSeek-direct only) balance change against the local ledger's official-channel cost for the day, and flags a drift above the threshold (0.3 CNY and >15%); top-ups / grants / currency changes reset the baseline instead of alerting |
|
|
155
188
|
|
|
156
|
-
## Development
|
|
189
|
+
## 🛠 Development
|
|
157
190
|
|
|
158
191
|
Requirements: Node.js ^22.19 || >=24, pnpm.
|
|
159
192
|
|
|
@@ -163,7 +196,7 @@ pnpm --filter @kenz1117/dsh-ui-usage-billing bundle # builds lib/index.js and
|
|
|
163
196
|
npx vitest run packages/client/ui-usage-billing/tests # unit tests
|
|
164
197
|
```
|
|
165
198
|
|
|
166
|
-
## Release
|
|
199
|
+
## 📦 Release
|
|
167
200
|
|
|
168
201
|
This package is a standalone npm package that other DeepSeek Harness hosts can install once published.
|
|
169
202
|
|
|
@@ -173,11 +206,11 @@ npm publish --access public
|
|
|
173
206
|
|
|
174
207
|
The host discovers the browser side automatically via the `dsh.client` declaration (`platform: web`) and the `exports["./client"]` bundle in `package.json` — no registry registration needed.
|
|
175
208
|
|
|
176
|
-
## Model Experience
|
|
209
|
+
## 🤖 Model Experience
|
|
177
210
|
|
|
178
211
|
None. This plugin is a pure UI surface: it registers no tools, injects no system prompt, writes no model-visible events to the session log, and touches no session KV cache; usage statistics are aggregated by the server from existing session logs, whose content is owned by other packages.
|
|
179
212
|
|
|
180
|
-
## Known Limitations and Deferred Work
|
|
213
|
+
## ⚠️ Known Limitations and Deferred Work
|
|
181
214
|
|
|
182
215
|
- **Balance queries cover DeepSeek / Moonshot (Kimi) / StepFun / SiliconFlow / xAI / Zhipu GLM (Z.ai CN region)**: these use a standard Bearer API key. Other providers expose no public balance API or need non-Bearer auth (Xiaomi MiMo via console Cookie, SenseTime via AccessKey signing, MiniMax/Doubao via quota or AK/SK), so they currently show "not configured"; the extension point is `src/balance.ts` (add a querier per provider balance API).
|
|
183
216
|
- **Relay quota depends on upstream private schemas**: New API / Sub2API interface fields are not public, so an unreadable station is labeled "no quota" rather than fabricating an amount; if a station's response fields differ, extend the parsers in `src/relay.ts`. An "unknown route" means that route no longer exists in the current provider config (renamed / deleted); historical call data is not lost — re-adding the same-named route restores attribution automatically.
|
|
@@ -186,11 +219,11 @@ None. This plugin is a pure UI surface: it registers no tools, injects no system
|
|
|
186
219
|
- **Cost is a catalog estimate**: models without published per-token pricing (iFlytek, SenseTime, Xiaomi) use estimates (feature-list footnote ¹); official billing is authoritative.
|
|
187
220
|
- **The ledger starts at its first successful aggregation**: sessions permanently deleted before the upgrade and absent from the old snapshot cannot be recovered. Manually deleting `.dsh-usage-ledger.json` and its `.bak` clears independently retained history. Only calls successfully observed by this plugin are retained.
|
|
188
221
|
|
|
189
|
-
## Contributors
|
|
222
|
+
## ❤️ Contributors
|
|
190
223
|
|
|
191
224
|
- [@ciphoo](https://github.com/ciphoo) — MiniMax CN Token Plan quota support (PR #5)
|
|
192
225
|
- [@fabulousyuann-tech](https://github.com/fabulousyuann-tech) — durable ledger that retains usage after session deletion (PR #8)
|
|
193
226
|
|
|
194
|
-
## License
|
|
227
|
+
## 📄 License
|
|
195
228
|
|
|
196
229
|
[MIT](LICENSE) © 2026 KenZ (kenz1117)
|
package/README.md
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
# dsh-ui-usage-billing
|
|
4
4
|
|
|
5
|
-
<p align="center"
|
|
5
|
+
<p align="center">把每一分模型开销,看得清清楚楚。</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/
|
|
9
|
-
<a href="https://
|
|
10
|
-
<a href="https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing"><img alt="npm
|
|
11
|
-
<a href="https://
|
|
12
|
-
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/
|
|
8
|
+
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/kenz1117/dsh-ui-usage-billing?logo=github"></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing"><img alt="npm version" src="https://img.shields.io/npm/v/@kenz1117/dsh-ui-usage-billing?logo=npm"></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@kenz1117/dsh-ui-usage-billing?logo=npm"></a>
|
|
11
|
+
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/blob/main/LICENSE"><img alt="License MIT" src="https://img.shields.io/github/license/kenz1117/dsh-ui-usage-billing"></a>
|
|
12
|
+
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/pulls"><img alt="PRs welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen"></a>
|
|
13
|
+
<a href="https://github.com/kenz1117/dsh-ui-usage-billing"><img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/kenz1117/dsh-ui-usage-billing?logo=github"></a>
|
|
13
14
|
<a href="https://github.com/kenz1117/dsh-ui-usage-billing/graphs/contributors"><img alt="GitHub contributors" src="https://img.shields.io/github/contributors/kenz1117/dsh-ui-usage-billing"></a>
|
|
14
15
|
<a href="https://awesome-dsh-plugin.com"><img alt="Awesome DSH Plugin" src="https://awesome-dsh-plugin.com/badge.svg"></a>
|
|
15
16
|
</p>
|
|
@@ -22,43 +23,71 @@
|
|
|
22
23
|
|
|
23
24
|
> **峰谷计费规则更新(自 2026-08-23(周日)00:00 起)**:DeepSeek 模型按官方新规计费——**工作日(周一至周五)** 继续执行原峰谷分段计费(高峰 09:00–12:00 / 14:00–18:00,×2);**周末(周六、周日)** 全天不再区分峰谷时段,统一按**低谷价**计费。插件计费引擎、费率表与每轮费用峰谷分带均已同步生效。
|
|
24
25
|
|
|
26
|
+
<div align="center">
|
|
27
|
+
<img src="screenshots/demo.png" alt="dsh-ui-usage-billing — 计费仪表盘总览" width="80%">
|
|
28
|
+
</div>
|
|
29
|
+
|
|
25
30
|
### 演示动图
|
|
26
31
|
|
|
27
32
|

|
|
28
33
|
|
|
29
|
-
##
|
|
34
|
+
## ✨ 核心亮点
|
|
35
|
+
|
|
36
|
+
- **真实用量,不伪造样本** — 服务端从持久化会话日志实时聚合,按实时多厂商官方价估算;数据到达前显示空快照,绝不展示假数据。
|
|
37
|
+
- **一屏看懂一切** — 侧边栏触发卡 + 全屏仪表盘(概览 / 趋势 / 明细 / 统计 / 费率 / 设置)六区,本月/今日/预计/热力图/趋势全在。
|
|
38
|
+
- **订阅 · 余额 · 额度 · 对账** — 订阅套餐额度、多厂商余额、中转站额度、声明端点、余额差对账,形成可交叉验证的计费闭环。
|
|
39
|
+
- **峰谷计价 + 切换提醒** — 工作日峰谷分时、周末全天低谷,切档前弹窗/系统通知,提前量可配。
|
|
40
|
+
- **离线自包含** — 无图表库、无外部 CDN、纯设计令牌;依赖极轻,随装随用。
|
|
41
|
+
- **多语种 + 双币种** — 中文/English、¥/≈$ 切换,只对本插件生效。
|
|
42
|
+
|
|
43
|
+
## 📊 仪表盘
|
|
30
44
|
|
|
31
45
|
- **侧边栏入口**:设置按钮上方的仪表盘式触发卡——本月费用主数字(等宽字体)+ 近 7 天 sparkline 迷你趋势,副行「今日 / 本周」;折叠栏自动切为图标钮;悬停浮现速览卡。
|
|
32
|
-
- **计费仪表盘(分区 Tab)**:概览 / 趋势 / 明细 / 统计 / 费率 / 设置 六区——Hero 大数字 + 本年/今日环比 + 本月预计 + KPI×4 + 热力图;趋势图 7/30
|
|
46
|
+
- **计费仪表盘(分区 Tab)**:概览 / 趋势 / 明细 / 统计 / 费率 / 设置 六区——Hero 大数字 + 本年/今日环比 + 本月预计 + KPI×4 + 热力图;趋势图 7/30 天(可切费用 / Token);厂商计费与订阅;导出 / 费用构成 / 工作区 / 会话明细;模型单价表;预算与峰谷提醒。克制冷调、`--dsw-*` 令牌、深浅主题自适应。
|
|
33
47
|
|
|
34
48
|

|
|
35
49
|
- **即时代费用条**:输入框下方常驻「本轮 ¥x · 会话 ¥y」+ 峰谷档位与切换倒计时 + 订阅额度预警 chips(≤20% 浮现、≤10% 红)。
|
|
36
50
|
- **峰/谷切换提醒**:切档前弹窗 + 可选系统通知(提前量 / 位置 / 模式 / 预览可配),区分「即将进峰时 ×2 可稍等」/「即将进平价 价格减半」。
|
|
51
|
+
- **插件信息卡**:设置 Tab 常驻「关于」卡——插件名、描述、作者(可跳 GitHub)、源码仓库、npm、许可证 MIT、版本号(服务端读自包 `package.json`,单一来源,发布自动正确)。
|
|
52
|
+
|
|
53
|
+
## 💰 计费引擎
|
|
54
|
+
|
|
37
55
|
- **实时定价费率表**:models.dev 抓价 + 探活模型对标——系统实际配置模型全纳入;峰谷分时(工作日 9-12 / 14-18 高峰 ×2,周末全天低谷)+ 实时汇率(USD→CNY),每 6 小时刷新。
|
|
38
56
|
|
|
39
57
|

|
|
40
58
|
- **官方 vs 三方分桶**:明细费用列按官方 DeepSeek 直连 / 第三方中转分解(混合时「官 x / 三 y」),统计 Tab 有「官方/三方」汇总卡。
|
|
41
|
-
- **中转站归组与额度**:按 provider 的 `baseURL` 归一化 origin 归组——同一中转站的多把 key 合并成一行,站名即域名;明细 Tab 新增「中转站分布」卡(中转站 / 直连 / 未知路由三态,未知路由 = 配置里已删 / 改名的路由,诚实标注「读不到」而非误归直连)。对配了 `baseURL` 的路由自动识别 New API 系(`/api/status`)与 Sub2API(`/v1/usage`)的**余额与滚动额度窗口**,读不出标「未读出额度」,剩余 <20% 标红;中转站识别结果有 5 分钟指纹缓存(同站多把 key 独立熔断),`relay-quotas` 端点附 `diagnostics` 供「我的中转站为什么不显示」自查。智谱 GLM / Z.ai 国内域钱包余额已接入(与订阅套餐双读)。项目归属优先用工作区标题命名。**未计价的模型**(目录外/无价)费用按 0 计,Hero 下会提示「N 个模型未收录计价」。
|
|
42
59
|
- **月度预算 + 分档提醒**:预算条(开关 / 金额 / 进度,≥80% 琥珀、超支红脉);跨 50 / 80 / 100% 各提醒一次;余额折算 CNY 低于阈值每天提醒一次。
|
|
43
|
-
-
|
|
60
|
+
- **成本突增归因**:每轮费用柱状图(最近 40 轮、金额贴柱顶、峰谷背景分带、超 2 倍红标归因)。
|
|
61
|
+
|
|
62
|
+
## 🔌 订阅与余额
|
|
63
|
+
|
|
64
|
+
- **订阅套餐额度**:识别 `llm-pi-ai` 里的订阅类 provider(Kimi / Z.ai / OpenCode Go / MiniMax / OpenRouter / 小米 / 火山…),有额度 API 的实时显示剩余%与重置时间、用尽标红,无 API 标「未接入」;订阅通道模型费用记 0。档位月费与周期额度口径由内置知识库自动识别(如 OpenCode Go $10/月 + 周 $30 额度)。**MiniMax 用户注意**:国内开发者环境请用 `minimax-token-plan-cn`(自动对接 `https://api.minimaxi.com`);国际保留 `minimax` / `minimax-token-plan`(默认 `https://www.minimaxi.com`);需要自配中转或 staging 时可在该 provider 设置里覆盖 `baseUrl`。
|
|
65
|
+
- **多厂商余额**:DeepSeek / Kimi / 阶跃星辰 / 硅基流动 / xAI / 智谱 GLM(Z.ai 国内域)内置官方余额,余额列按近 7 天日均折算「约可撑 N 天」。
|
|
66
|
+
- **自定义 Provider 余额**:配置任意 HTTP 端点查余额(`extract` 支持常量 / 点路径 / add-subtract / divide,请求头 `{{ENV}}` 经凭据 seam)。
|
|
67
|
+
- **声明端点 + 余额对账**:**声明端点**(`declaredEndpoints`)为内置表没有的供应商自声明余额/额度接口——只写「数字在哪里」的点路径、无表达式;请求由匹配到同源 provider 的 origin 构造,安全边界(单斜杠绝对路径、仅 GET、拒跨源重定向、响应体/超时上限、凭据只取匹配 provider 自有 `apiKeyEnv`)由 `src/declarative.ts` 强制执行,取错路径在界面标注 `declared` 与 reason。**余额差对账**(`reconcilePath`)用官方(仅 DeepSeek 官方方向)余额当日变动与本地账本当日的官方渠道费用交叉校验,偏差超阈值(0.3 元且 >15%)时提示核对价格表或近期账单;充值 / 授信 / 币种变化重置基准而非告警、余额未减少(走订阅扣费)静默。
|
|
68
|
+
- **中转站归组与额度**:按 provider 的 `baseURL` 归一化 origin 归组——同一中转站的多把 key 合并成一行,站名即域名;对配了 `baseURL` 的路由自动识别 New API 系(`/api/status`)与 Sub2API(`/v1/usage`)的**余额与滚动额度窗口**,读不出标「未读出额度」,剩余 <20% 标红;识别结果有 5 分钟指纹缓存(同站多把 key 独立熔断),`relay-quotas` 端点附 `diagnostics` 供「我的中转站为什么不显示」自查。项目归属优先用工作区标题命名。**未计价的模型**(目录外/无价)费用按 0 计,Hero 下会提示「N 个模型未收录计价」。
|
|
44
69
|
|
|
45
70
|

|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
- **性能指标**:每个模型首字延时(TTFT)均值 / P50 / P90、生成速度(tokens/s)、总延迟均值,另按北京时间小时聚合 TTFT 与速度曲线;请求从头到首个内容 chunk 测 TTFT,工具续写步骤无独立请求头时以 step/start 估算并标 estimated。统计 Tab 渲染为按模型性能表 + 按小时 TTFT/速度双折线。
|
|
71
|
+
|
|
72
|
+
## 📈 用量可视化
|
|
73
|
+
|
|
74
|
+
- **会话明细 + 成本突增 + 热力图**:按会话费用倒序(标题 / 项目 / 调用 / 费用 / 最后活跃);每轮费用柱状图(峰谷背景分带、超 2 倍红标归因);月 / 年日历热力图(5 档色阶、悬停明细;年视图近 52 周、GitHub 风格),头部显示活跃天数 / 连续使用天数。
|
|
75
|
+
- **性能指标**:每个模型首字延时(TTFT)均值 / P50 / P90、生成速度(tokens/s)、总延迟均值,另按北京时间小时聚合 TTFT 与速度曲线;统计 Tab 渲染为按模型性能表 + 按小时 TTFT/速度双折线。
|
|
52
76
|
- **Token 统计洞察**:独立「Token」分区——每日 token 堆叠按「输入(缓存未命中)/ 输入(缓存命中)/ 输出」三桶分色(含 reasoning 思考),模型 token 总量与占比,结构 KPI(缓存命中率 / 思考占比 / 输入输出比 / 峰值日);按日 token CSV 与 JSON 导出。
|
|
53
77
|
|
|
54
78
|

|
|
55
|
-
|
|
56
79
|
- **数据导出 + 离线自包含**:统计 Tab 导出按日 / 按会话 / 按站点 CSV 与全量 JSON;费用构成 / 工作区 / 会话明细分区可下钻(点项目行展开该项目的会话);无图表库、无外部 CDN、纯设计令牌。
|
|
57
|
-
- **插件信息卡**:设置 Tab 常驻「关于」卡——插件名、描述、作者(可跳 GitHub)、源码仓库、npm、许可证 MIT、版本号(服务端读自包 `package.json`,单一来源,发布自动正确)。
|
|
58
80
|
|
|
59
81
|

|
|
60
82
|
|
|
61
|
-
##
|
|
83
|
+
## 🛡️ 健壮性与隐私
|
|
84
|
+
|
|
85
|
+
- **真实用量聚合**:服务端从会话日志实时聚合(增量缓存只重算写过的会话),单会话损坏容错、快照落盘回退;`usage_stats` 工具让模型自查今天 / 本月 / 当前会话 / 累计费用,还可查 `bySite`(按站点归组)与 `relay`(只看中转站)的汇总。
|
|
86
|
+
- **模型健康 + 未收录标注**:厂商接入状态圆点(绿 / 红 / 灰);模型 id 不在目录时标「未收录」按兜底价估算、厂商自动推断(如 `mi-mimo-2.5` → 小米);估算价模型标注「估算价」。
|
|
87
|
+
- **多语种 + 双币种**:¥ / $ 切换随币种双语(USD→英文、CNY→中文,仅本插件生效);费率表按所选币种换算。
|
|
88
|
+
- **隐私底线**:纯 UI surface,不注册工具、不注入系统提示、不向会话日志写入模型可见事件;仅从既有会话日志聚合,日志内容由其他包负责。
|
|
89
|
+
|
|
90
|
+
## 🚀 快速开始
|
|
62
91
|
|
|
63
92
|
在宿主 `cordis.patch.yml` 中加入:
|
|
64
93
|
|
|
@@ -76,7 +105,7 @@ npm install @kenz1117/dsh-ui-usage-billing
|
|
|
76
105
|
|
|
77
106
|
启动宿主后,侧边栏设置上方即出现计费入口。无需额外配置;`sessionPersistence` 可用时自动聚合真实用量。
|
|
78
107
|
|
|
79
|
-
## 工作原理
|
|
108
|
+
## ⚙️ 工作原理
|
|
80
109
|
|
|
81
110
|
插件由服务端与浏览器端两部分组成:
|
|
82
111
|
|
|
@@ -93,14 +122,14 @@ npm install @kenz1117/dsh-ui-usage-billing
|
|
|
93
122
|
└─ 渲染仪表盘
|
|
94
123
|
```
|
|
95
124
|
|
|
96
|
-
- **服务端**(`src/index.ts`):注入 `webServer`、`sessionPersistence` 与 `credentials`,注册 `GET /api/billing/usage-stats`、`/api/billing/pricing`、`/api/billing/balance`、`/api/billing/subscriptions`、`/api/billing/relay-quotas`。聚合器按会话缓存折叠结果:一次 LLM 调用归属到其前置 `request/header` 记录的模型,token 拆分到缓存命中 / 未命中桶,日期按本机时区归天;日志文件 mtime+size 不变则直接复用缓存,只有写过的会话重新折叠,整份文档另有 5 秒 TTL 合并密集轮询。每个成功折叠的会话同时原子写入独立的持久用量账本,永久删除会话后历史费用与 token
|
|
125
|
+
- **服务端**(`src/index.ts`):注入 `webServer`、`sessionPersistence` 与 `credentials`,注册 `GET /api/billing/usage-stats`、`/api/billing/pricing`、`/api/billing/balance`、`/api/billing/subscriptions`、`/api/billing/relay-quotas`。聚合器按会话缓存折叠结果:一次 LLM 调用归属到其前置 `request/header` 记录的模型,token 拆分到缓存命中 / 未命中桶,日期按本机时区归天;日志文件 mtime+size 不变则直接复用缓存,只有写过的会话重新折叠,整份文档另有 5 秒 TTL 合并密集轮询。每个成功折叠的会话同时原子写入独立的持久用量账本,永久删除会话后历史费用与 token 仍保留。
|
|
97
126
|
- **浏览器端**(`src/client/`):请求上述接口渲染仪表盘,通过 `llm.models` 探测各厂商连接状态。真实数据到达前显示全零空快照,不展示伪造样本。
|
|
98
127
|
|
|
99
|
-
## 主题协作
|
|
128
|
+
## 🧩 主题协作
|
|
100
129
|
|
|
101
130
|
本插件**不依赖任何主题包**,可独立安装运行。仪表盘弹窗声明 `billing.dashboard.decor` 装饰孔位(head / hero / trend / models / footer 锚点),并将实时费用摘要注册为 `ctx.billingMetrics` 服务:主题插件(如 acid-zine)主动注入 MacDots / 胶带 / 撕角便签等装饰视觉、订阅费用数据渲染自己的贴纸层。插件与主题各自独立装卸——主题不存在时走默认视觉,billing 不存在时主题照常运行。
|
|
102
131
|
|
|
103
|
-
##
|
|
132
|
+
## 💡 计费细节
|
|
104
133
|
|
|
105
134
|
单价表(`src/client/pricing.ts`)采用**原生币种**存储:国内厂商直接录入人民币价格,国外厂商录入美元价格。费用统一以人民币计算与展示——美元模型按**实时汇率**折算,国内模型全程不经过汇率换算。启动时服务端拉取实时汇率与模型价(`src/pricing-fetch.ts`):USD→CNY 优先腾讯财经行情(免 key、国内可达),失败依次降级 open.er-api 与内置默认值;之后每 6 小时后台刷新,单价表弹窗标注「今日汇率」与实时 / 内置徽标。金额与费率表的**展示币种跟随用户所选**:切 ¥ / $ 时把每条每百万 token 单价经 `convertUnitPrice` 按实时汇率换算到目标币种再显示(汇率缺失时回退原生币种)。
|
|
106
135
|
|
|
@@ -139,11 +168,11 @@ cost(CNY)= (missInput × p_input + cacheHit × p_cacheHit + output × p_outp
|
|
|
139
168
|
|
|
140
169
|
新增模型:在 `MODEL_CATALOG` 追加条目,并在 `src/client/pricing.ts` 的 `MODEL_KEY_ALIASES` 中映射真实模型 id(聚合层与客户端渲染共用同一张表)。
|
|
141
170
|
|
|
142
|
-
## HTTP API
|
|
171
|
+
## 🔌 HTTP API
|
|
143
172
|
|
|
144
173
|
对外 HTTP 接口与字段定义详见源码:`GET /api/billing/pricing`、`/api/billing/balance`、`/api/billing/usage-stats`、`/api/billing/subscriptions`、`/api/billing/relay-quotas`(见 `src/index.ts`、`src/aggregate.ts`、`src/relay.ts`)。其中 `usage-stats` 返回的 `bySite` 字段为按中转站归组后的用量分布(`site:<origin>` / `direct:<provider>` / `unknown`),`unpricedModels` 为未计价模型的 id 列表;`relay-quotas` 返回 `quotas`(各中转站额度)与 `diagnostics`(每条路由的 origin / kind 归类,供「为什么不显示」自查)。全部端点仅接受回环请求(peer socket 地址 + Host 头校验)。
|
|
145
174
|
|
|
146
|
-
## 配置
|
|
175
|
+
## ⚙️ 配置
|
|
147
176
|
|
|
148
177
|
| 字段 | 默认 | 说明 |
|
|
149
178
|
| ----------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
|
|
@@ -154,8 +183,10 @@ cost(CNY)= (missInput × p_input + cacheHit × p_cacheHit + output × p_outp
|
|
|
154
183
|
| `monthlyBudget` | 未设置 | 月度预算默认金额(人民币元);随 usage-stats 下发,作为仪表盘预算条的初始金额(用户在界面上的设置优先并本地持久化) |
|
|
155
184
|
| `lowBalanceThreshold` | `50` | 余额不足告警阈值(人民币元);随 usage-stats 下发,任一厂商余额折算人民币低于此值时每天提醒一次 |
|
|
156
185
|
| `subscriptionPlans` | 自动识别 | 订阅额度适配器白名单(`{ provider, baseUrl?, region? }`);缺省时自动从 `llm-pi-ai` 设置识别所有订阅类 provider(有额度 API 的查额度,无 API 的仅标识) |
|
|
186
|
+
| `declaredEndpoints` | 未设置 | 声明端点(`{ displayName, origin, path, fields?, windows?, raw? }`):为内置表没有的供应商自声明余额/额度接口,只写「数字在哪里」的点路径、无表达式;请求由匹配到同源 provider 的 origin 构造,安全边界(单斜杠绝对路径、仅 GET、拒绝跨源重定向、响应体/超时上限、凭据只取匹配 provider 自有的 apiKeyEnv)由 `src/declarative.ts` 强制执行 |
|
|
187
|
+
| `reconcilePath` | `~/.dsh/.dsh-usage-reconcile.json` | 余额差对账基准的绝对路径;用官方(仅 DeepSeek 官方方向)余额当日变动与本地账本当日的官方渠道费用做交叉校验,偏差超阈值(0.3 元且 >15%)时提示核对;充值/授信/币种变化重置基准而非告警 |
|
|
157
188
|
|
|
158
|
-
## 开发
|
|
189
|
+
## 🛠 开发
|
|
159
190
|
|
|
160
191
|
环境要求:Node.js ^22.19 || >=24,pnpm。
|
|
161
192
|
|
|
@@ -165,7 +196,7 @@ pnpm --filter @kenz1117/dsh-ui-usage-billing bundle # 构建 lib/index.js 与
|
|
|
165
196
|
npx vitest run packages/client/ui-usage-billing/tests # 单元测试
|
|
166
197
|
```
|
|
167
198
|
|
|
168
|
-
## 发布
|
|
199
|
+
## 📦 发布
|
|
169
200
|
|
|
170
201
|
本包为独立 npm 包,发布后即可被其他 DeepSeek Harness 宿主安装。
|
|
171
202
|
|
|
@@ -175,11 +206,11 @@ npm publish --access public
|
|
|
175
206
|
|
|
176
207
|
宿主通过 `package.json` 的 `dsh.client` 声明(`platform: web`)与 `exports["./client"]` bundle 自动发现浏览器端,无需注册中心登记。
|
|
177
208
|
|
|
178
|
-
## Model Experience
|
|
209
|
+
## 🤖 Model Experience
|
|
179
210
|
|
|
180
211
|
无。本插件是纯 UI surface:不注册工具、不注入系统提示、不向会话日志写入模型可见事件,也不触及会话 KV 缓存;用量统计由服务端从既有会话日志聚合,日志内容由其他包各自负责。
|
|
181
212
|
|
|
182
|
-
## Known Limitations and Deferred Work
|
|
213
|
+
## ⚠️ Known Limitations and Deferred Work
|
|
183
214
|
|
|
184
215
|
- **余额查询已接入 DeepSeek / 月之暗面(Kimi)/ 阶跃星辰(StepFun)/ 硅基流动 / xAI / 智谱 GLM(Z.ai 国内域)**:这些用标准 Bearer API key 即可查询。其余厂商因无公开余额接口或需非 Bearer 鉴权(小米 MiMo 走控制台 Cookie、商汤走 AccessKey 签名、MiniMax/字节豆包走额度制或 AK/SK),暂显示「未配置」;扩展点在 `src/balance.ts`(按厂商余额 API 增加查询器)。
|
|
185
216
|
- **中转站额度依赖上游私有 schema**:New API / Sub2API 的接口字段未公开,读不出时标「未读出额度」而非臆造金额;若某中转站响应字段不同,需按 `src/relay.ts` 的解析器扩展。未知路由表示该路由在当前 provider 配置里已不存在(改过名 / 删除过),历史调用数据未丢,重新配置同名路由即可自动归位。
|
|
@@ -188,11 +219,11 @@ npm publish --access public
|
|
|
188
219
|
- **费用为目录价估算**:讯飞 / 商汤 / 小米等未公布按量单价的模型使用估算价(特性表脚注 ¹),正式定价以厂商账单为准。
|
|
189
220
|
- **账本从首次成功聚合开始生效**:升级前已经永久删除且不在旧快照中的会话无法恢复;手动删除 `.dsh-usage-ledger.json` 及其 `.bak` 会清空独立保留的历史。账本只保留本插件已经成功观测过的调用。
|
|
190
221
|
|
|
191
|
-
## Contributors
|
|
222
|
+
## ❤️ Contributors
|
|
192
223
|
|
|
193
224
|
- [@ciphoo](https://github.com/ciphoo) — MiniMax 国内域 Token Plan 订阅额度支持(PR #5)
|
|
194
225
|
- [@fabulousyuann-tech](https://github.com/fabulousyuann-tech) — 会话删除后用量保留的持久 ledger 功能(PR #8)
|
|
195
226
|
|
|
196
|
-
## 许可证
|
|
227
|
+
## 📄 许可证
|
|
197
228
|
|
|
198
229
|
[MIT](LICENSE) © 2026 KenZ (kenz1117)
|