@laoyuehanni/dsh-token-usage 0.3.7
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/LICENSE +21 -0
- package/README.md +178 -0
- package/README.zh.md +182 -0
- package/cordis.patch.yml +7 -0
- package/lib/client/CostDeltaFlyLabel.d.ts +8 -0
- package/lib/client/CostDeltaFlyLabel.d.ts.map +1 -0
- package/lib/client/CostDeltaFlyLabel.js +24 -0
- package/lib/client/CostDeltaFlyLabel.js.map +1 -0
- package/lib/client/HitRateText.d.ts +21 -0
- package/lib/client/HitRateText.d.ts.map +1 -0
- package/lib/client/HitRateText.js +16 -0
- package/lib/client/HitRateText.js.map +1 -0
- package/lib/client/QuotaButton.d.ts +70 -0
- package/lib/client/QuotaButton.d.ts.map +1 -0
- package/lib/client/QuotaButton.js +346 -0
- package/lib/client/QuotaButton.js.map +1 -0
- package/lib/client/SessionStatsChip.d.ts +47 -0
- package/lib/client/SessionStatsChip.d.ts.map +1 -0
- package/lib/client/SessionStatsChip.js +141 -0
- package/lib/client/SessionStatsChip.js.map +1 -0
- package/lib/client/StatCard.d.ts +26 -0
- package/lib/client/StatCard.d.ts.map +1 -0
- package/lib/client/StatCard.js +10 -0
- package/lib/client/StatCard.js.map +1 -0
- package/lib/client/TokenUsageCard.d.ts +41 -0
- package/lib/client/TokenUsageCard.d.ts.map +1 -0
- package/lib/client/TokenUsageCard.js +164 -0
- package/lib/client/TokenUsageCard.js.map +1 -0
- package/lib/client/TokenUsageSection.d.ts +32 -0
- package/lib/client/TokenUsageSection.d.ts.map +1 -0
- package/lib/client/TokenUsageSection.js +266 -0
- package/lib/client/TokenUsageSection.js.map +1 -0
- package/lib/client/TrendChart.d.ts +53 -0
- package/lib/client/TrendChart.d.ts.map +1 -0
- package/lib/client/TrendChart.js +141 -0
- package/lib/client/TrendChart.js.map +1 -0
- package/lib/client/UsageView.d.ts +42 -0
- package/lib/client/UsageView.d.ts.map +1 -0
- package/lib/client/UsageView.js +158 -0
- package/lib/client/UsageView.js.map +1 -0
- package/lib/client/async-resource.d.ts +54 -0
- package/lib/client/async-resource.d.ts.map +1 -0
- package/lib/client/async-resource.js +90 -0
- package/lib/client/async-resource.js.map +1 -0
- package/lib/client/card-form.d.ts +171 -0
- package/lib/client/card-form.d.ts.map +1 -0
- package/lib/client/card-form.js +300 -0
- package/lib/client/card-form.js.map +1 -0
- package/lib/client/cost-inflate-motion.d.ts +17 -0
- package/lib/client/cost-inflate-motion.d.ts.map +1 -0
- package/lib/client/cost-inflate-motion.js +61 -0
- package/lib/client/cost-inflate-motion.js.map +1 -0
- package/lib/client/cost-inflate.d.ts +28 -0
- package/lib/client/cost-inflate.d.ts.map +1 -0
- package/lib/client/cost-inflate.js +49 -0
- package/lib/client/cost-inflate.js.map +1 -0
- package/lib/client/day.d.ts +49 -0
- package/lib/client/day.d.ts.map +1 -0
- package/lib/client/day.js +84 -0
- package/lib/client/day.js.map +1 -0
- package/lib/client/format.d.ts +120 -0
- package/lib/client/format.d.ts.map +1 -0
- package/lib/client/format.js +163 -0
- package/lib/client/format.js.map +1 -0
- package/lib/client/index.d.ts +26 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +131 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/locales.d.ts +131 -0
- package/lib/client/locales.d.ts.map +1 -0
- package/lib/client/locales.js +230 -0
- package/lib/client/locales.js.map +1 -0
- package/lib/client/quota-format.d.ts +69 -0
- package/lib/client/quota-format.d.ts.map +1 -0
- package/lib/client/quota-format.js +147 -0
- package/lib/client/quota-format.js.map +1 -0
- package/lib/client/session-stats.d.ts +105 -0
- package/lib/client/session-stats.d.ts.map +1 -0
- package/lib/client/session-stats.js +142 -0
- package/lib/client/session-stats.js.map +1 -0
- package/lib/client/trend-chart/axis.d.ts +21 -0
- package/lib/client/trend-chart/axis.d.ts.map +1 -0
- package/lib/client/trend-chart/axis.js +33 -0
- package/lib/client/trend-chart/axis.js.map +1 -0
- package/lib/client/trend-chart/bucket.d.ts +24 -0
- package/lib/client/trend-chart/bucket.d.ts.map +1 -0
- package/lib/client/trend-chart/bucket.js +28 -0
- package/lib/client/trend-chart/bucket.js.map +1 -0
- package/lib/client/trend-chart/index.d.ts +12 -0
- package/lib/client/trend-chart/index.d.ts.map +1 -0
- package/lib/client/trend-chart/index.js +9 -0
- package/lib/client/trend-chart/index.js.map +1 -0
- package/lib/client/trend-chart/points.d.ts +46 -0
- package/lib/client/trend-chart/points.d.ts.map +1 -0
- package/lib/client/trend-chart/points.js +82 -0
- package/lib/client/trend-chart/points.js.map +1 -0
- package/lib/client/trend-chart/scale.d.ts +47 -0
- package/lib/client/trend-chart/scale.d.ts.map +1 -0
- package/lib/client/trend-chart/scale.js +75 -0
- package/lib/client/trend-chart/scale.js.map +1 -0
- package/lib/client/use-color-scheme.d.ts +18 -0
- package/lib/client/use-color-scheme.d.ts.map +1 -0
- package/lib/client/use-color-scheme.js +37 -0
- package/lib/client/use-color-scheme.js.map +1 -0
- package/lib/client/use-cost-inflate.d.ts +33 -0
- package/lib/client/use-cost-inflate.d.ts.map +1 -0
- package/lib/client/use-cost-inflate.js +108 -0
- package/lib/client/use-cost-inflate.js.map +1 -0
- package/lib/client.js +3892 -0
- package/lib/client.js.map +1 -0
- package/lib/index.d.ts +132 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +599 -0
- package/lib/index.js.map +1 -0
- package/lib/migrate.d.ts +60 -0
- package/lib/migrate.d.ts.map +1 -0
- package/lib/migrate.js +126 -0
- package/lib/migrate.js.map +1 -0
- package/lib/pricing.d.ts +212 -0
- package/lib/pricing.d.ts.map +1 -0
- package/lib/pricing.js +492 -0
- package/lib/pricing.js.map +1 -0
- package/lib/quota/adapters/deepseek-balance.d.ts +18 -0
- package/lib/quota/adapters/deepseek-balance.d.ts.map +1 -0
- package/lib/quota/adapters/deepseek-balance.js +76 -0
- package/lib/quota/adapters/deepseek-balance.js.map +1 -0
- package/lib/quota/adapters/kimi.d.ts +26 -0
- package/lib/quota/adapters/kimi.d.ts.map +1 -0
- package/lib/quota/adapters/kimi.js +91 -0
- package/lib/quota/adapters/kimi.js.map +1 -0
- package/lib/quota/adapters/minimax.d.ts +24 -0
- package/lib/quota/adapters/minimax.d.ts.map +1 -0
- package/lib/quota/adapters/minimax.js +136 -0
- package/lib/quota/adapters/minimax.js.map +1 -0
- package/lib/quota/adapters/opencode-go.d.ts +25 -0
- package/lib/quota/adapters/opencode-go.d.ts.map +1 -0
- package/lib/quota/adapters/opencode-go.js +105 -0
- package/lib/quota/adapters/opencode-go.js.map +1 -0
- package/lib/quota/adapters/openrouter.d.ts +15 -0
- package/lib/quota/adapters/openrouter.d.ts.map +1 -0
- package/lib/quota/adapters/openrouter.js +54 -0
- package/lib/quota/adapters/openrouter.js.map +1 -0
- package/lib/quota/adapters/zhipu.d.ts +38 -0
- package/lib/quota/adapters/zhipu.d.ts.map +1 -0
- package/lib/quota/adapters/zhipu.js +246 -0
- package/lib/quota/adapters/zhipu.js.map +1 -0
- package/lib/quota/credentials.d.ts +79 -0
- package/lib/quota/credentials.d.ts.map +1 -0
- package/lib/quota/credentials.js +130 -0
- package/lib/quota/credentials.js.map +1 -0
- package/lib/quota/http.d.ts +49 -0
- package/lib/quota/http.d.ts.map +1 -0
- package/lib/quota/http.js +114 -0
- package/lib/quota/http.js.map +1 -0
- package/lib/quota/provider-tracking.d.ts +45 -0
- package/lib/quota/provider-tracking.d.ts.map +1 -0
- package/lib/quota/provider-tracking.js +52 -0
- package/lib/quota/provider-tracking.js.map +1 -0
- package/lib/quota/quota-route.d.ts +22 -0
- package/lib/quota/quota-route.d.ts.map +1 -0
- package/lib/quota/quota-route.js +57 -0
- package/lib/quota/quota-route.js.map +1 -0
- package/lib/quota/quota-service.d.ts +54 -0
- package/lib/quota/quota-service.d.ts.map +1 -0
- package/lib/quota/quota-service.js +171 -0
- package/lib/quota/quota-service.js.map +1 -0
- package/lib/quota/registry.d.ts +24 -0
- package/lib/quota/registry.d.ts.map +1 -0
- package/lib/quota/registry.js +38 -0
- package/lib/quota/registry.js.map +1 -0
- package/lib/quota/types.d.ts +79 -0
- package/lib/quota/types.d.ts.map +1 -0
- package/lib/quota/types.js +24 -0
- package/lib/quota/types.js.map +1 -0
- package/lib/record-cache.d.ts +38 -0
- package/lib/record-cache.d.ts.map +1 -0
- package/lib/record-cache.js +143 -0
- package/lib/record-cache.js.map +1 -0
- package/lib/rollup.d.ts +52 -0
- package/lib/rollup.d.ts.map +1 -0
- package/lib/rollup.js +117 -0
- package/lib/rollup.js.map +1 -0
- package/lib/stats-route.d.ts +88 -0
- package/lib/stats-route.d.ts.map +1 -0
- package/lib/stats-route.js +313 -0
- package/lib/stats-route.js.map +1 -0
- package/lib/stats.d.ts +158 -0
- package/lib/stats.d.ts.map +1 -0
- package/lib/stats.js +426 -0
- package/lib/stats.js.map +1 -0
- package/lib/sync-state.d.ts +27 -0
- package/lib/sync-state.d.ts.map +1 -0
- package/lib/sync-state.js +56 -0
- package/lib/sync-state.js.map +1 -0
- package/lib/sync.d.ts +74 -0
- package/lib/sync.d.ts.map +1 -0
- package/lib/sync.js +64 -0
- package/lib/sync.js.map +1 -0
- package/lib/trend-bucket.d.ts +48 -0
- package/lib/trend-bucket.d.ts.map +1 -0
- package/lib/trend-bucket.js +87 -0
- package/lib/trend-bucket.js.map +1 -0
- package/lib/usage-log.d.ts +64 -0
- package/lib/usage-log.d.ts.map +1 -0
- package/lib/usage-log.js +144 -0
- package/lib/usage-log.js.map +1 -0
- package/lib/usage-record.d.ts +59 -0
- package/lib/usage-record.d.ts.map +1 -0
- package/lib/usage-record.js +115 -0
- package/lib/usage-record.js.map +1 -0
- package/lib/wire.d.ts +452 -0
- package/lib/wire.d.ts.map +1 -0
- package/lib/wire.js +144 -0
- package/lib/wire.js.map +1 -0
- package/package.json +100 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LaoYueHanNi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# dsh-token-usage
|
|
2
|
+
|
|
3
|
+
[](https://awesome-dsh-plugin.com)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
[简体中文](./README.zh.md) | English
|
|
8
|
+
|
|
9
|
+
A dsh usage plugin that displays model token usage right in the Web UI. After installation, open **Settings** (the gear icon in the sidebar) and you'll find the **Token Usage** page — summary cards (with cost), a daily total-token line chart, a per-model breakdown, and per-model pricing dialogs, all filterable by date range and model, exactly as shown in the screenshot above.
|
|
10
|
+
|
|
11
|
+
[dsh]: https://github.com/cordiverse/dsh
|
|
12
|
+
|
|
13
|
+
Repo: <https://github.com/LaoYueHanNi/dsh-token-usage>
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **Live hook**: every successful model request is appended to per-day JSONL files (request id, model, input / output / cache-read / cache-write tokens, time, session id).
|
|
18
|
+
- **Web stats page**: filters (date range + model + `1d`/`7d`/`30d` shortcuts), summary cards, daily trend chart (hover a day for its total), per-model table.
|
|
19
|
+
- **Session usage view tab**: the conversation pane gains a **Usage** view tab (beside Chat / Trajectory) showing the active session's token & cost dashboard — six stat cards (requests, cost, cache hit rate, average time-to-first-token, generation throughput, total tokens), a 4-bucket token strip, an hourly trend chart, and a per-model table. A **Session / With subagents** scope switch aggregates the whole subagent subtree in one request, and the subagent table lists each child (requests, total tokens, cost, hit rate, TTFT, throughput) with drill-in navigation back to the parent. Token/cost figures come from the plugin's own billing chain (post-install records); TTFT and throughput come from DSH's `sessionStats` session projection (covers pre-install history). Sessions without records degrade to a placeholder, never an error.
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
- **Cost figures & model pricing**: per-request cost is computed live from per-model rates (¥ per million tokens) — a highlighted total-cost card, a cost column in the per-model table, and a warning strip for unpriced models (their cost counts as ¥0). Every priced model's name carries a small **rates button** that opens a dialog with that model's full price table: **each row is one billing condition** (default rates, context tiers like `≥ 512K`, peak windows like `09:00-12:00`, grouped under time rules' date windows), with the in/out/cache/write rates as aligned columns — mirroring exactly what the per-record resolver bills. Rates merge from two files: every startup mirrors the cloud model-price-table feed (the same source cc-switch-analyzer pulls) automatically, and `pricing.json` holds manual overrides.
|
|
24
|
+
- **Provider quota**: an input-bar button (left of the model chip) shows the selected provider's remaining quota. Coding plans (Zhipu GLM / Kimi / MiniMax / OpenCode Go) get time-window progress; DeepSeek / OpenRouter get the account balance. See [Provider quota](#provider-quota).
|
|
25
|
+
- **History backfill**: the first startup syncs requests that happened before installation (idempotent).
|
|
26
|
+
|
|
27
|
+
## Model pricing
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
**Every record is priced individually**: each one resolves through the analyzer's rule chain at its own timestamp — the covering time rule first (its context tiers, its peak slots), else the model root's tiers → peak slots → base rates. Tier matching approximates the context size by the request's input-side tokens (input + cacheRead + cacheWrite). A price update re-prices the whole history instantly, with no data rebuild. Rates come from two files merged on read — `pricing.json` entries always win (a manual entry replaces that model's cloud rules wholesale):
|
|
32
|
+
|
|
33
|
+
| File | Source | Notes |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `pricing.ccsa.json` | startup auto-fetch | Verbatim mirror of the cloud model-price-table feed (the analyzer's source); refreshed on every dsh restart, falling back to the previous mirror on failure |
|
|
36
|
+
| `pricing.json` | hand-edited | Overrides synced rates or adds missing models; manual tweaks survive re-syncs |
|
|
37
|
+
|
|
38
|
+
Cloud feed shape (`currency` must be `RMB`; both `modelId` and every alias become matchable keys; `timeRules` / `contextTiers` / `dailySlots` all take part in billing):
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"version": 4,
|
|
43
|
+
"updatedAt": 0,
|
|
44
|
+
"currency": "RMB",
|
|
45
|
+
"models": [
|
|
46
|
+
{ "modelId": "deepseek-chat", "inputCostPerMillion": 2, "outputCostPerMillion": 8,
|
|
47
|
+
"cacheReadCostPerMillion": 0.5, "cacheCreationCostPerMillion": 1, "aliases": ["deepseek-v3"] }
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Flat `pricing.json` shape (keys are model ids matching the recorded `model` exactly; `inputPerMillion` and `outputPerMillion` required, `cacheReadPerMillion` / `cacheWritePerMillion` optional and falling back to the input rate):
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"deepseek-chat": { "inputPerMillion": 2, "outputPerMillion": 8, "cacheReadPerMillion": 0.5 }
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
A broken file or invalid entries leave the affected models unpriced without breaking the stats page; save and refresh the page to apply changes. Default location: `~/.dsh/token-usage/` (wherever `path` points when configured).
|
|
61
|
+
|
|
62
|
+
### Changing the data directory
|
|
63
|
+
|
|
64
|
+
The data directory is editable from the web settings: on **Settings → Plugins**, inside the collapsed **Token Usage** card, the **Data directory** input leaves the location at its default (`~/.dsh/token-usage/`) when blank; saving an absolute path **takes effect immediately** — the historical data migrates into the new directory (verbatim file copy, then the switch and the source cleanup) with no restart and no manual data move.
|
|
65
|
+
|
|
66
|
+
The **Browse…** button next to the input opens the directory picker — the dsh framework's own directory-picking capability (the same chooser the workspace flows use, driven through `ctx.workspaces.pickDirectory()`): a native OS dialog on a local desktop, switching to an in-app browser for remote or headless clients. A picked path only stages the draft — you still press save to commit it.
|
|
67
|
+
|
|
68
|
+
The migration is a two-phase commit (copy everything → flip the running directory → clean the source): at any failure point the data exists in both places or only in the source — never only in the target. **A directory change cannot be saved while a conversation is in progress** — events only append while a turn is open, so only an actively conversing session counts and an idle open tab never blocks a save — the card pre-checks through the `/token-usage/dir-guard` route before anything writes (the verdict is whether a conversation is still interacting), refusing the save up front and naming the in-progress conversation count on the failure line; nothing persists. Wait for the conversation to end, then save again and the move proceeds. The stats cache `rollup.json` is derived state: it does not travel, and the first stats read after the switch rebuilds it. The directory can also be set directly:
|
|
69
|
+
|
|
70
|
+
```yml
|
|
71
|
+
# in the plugin's profile config
|
|
72
|
+
plugins:
|
|
73
|
+
token-usage:
|
|
74
|
+
path: D:/data/token-usage # default: ~/.dsh/token-usage/
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Choosing the pricing mirror
|
|
78
|
+
|
|
79
|
+
The startup sync pulls from **Gitee** by default (fast inside mainland China). Installations outside mainland China can point the sync at the **GitHub mirror** of the same table — either from the web settings (the **Pricing region** dropdown in the same **Token Usage** card, editable live) or with a single config line. No IP sniffing: you just pick once.
|
|
80
|
+
|
|
81
|
+
```yml
|
|
82
|
+
# in the plugin's profile config
|
|
83
|
+
plugins:
|
|
84
|
+
token-usage:
|
|
85
|
+
pricingRegion: overseas # default: domestic
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The web card exposes the data directory and the region switch; the full key set (all optional):
|
|
89
|
+
|
|
90
|
+
| Key | Default | Meaning |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `path` | `~/.dsh/token-usage/` | Data directory (editable on the web card; saving migrates) |
|
|
93
|
+
| `pricingUrl` | — | Explicit single feed (cordis.yml only); wins over every other key below |
|
|
94
|
+
| `pricingUrlDomestic` | gitee feed | Domestic mirror override (cordis.yml only; for self-maintained forks) |
|
|
95
|
+
| `pricingUrlOverseas` | github mirror | Overseas mirror override (cordis.yml only; for self-maintained forks) |
|
|
96
|
+
| `pricingRegion` | `domestic` | `domestic` → Gitee, `overseas` → GitHub (when `pricingUrl` is unset) |
|
|
97
|
+
|
|
98
|
+
A saved region change re-syncs the mirror immediately; there is no automatic failover — the chosen mirror fails, the previous mirror stays until a later sync succeeds.
|
|
99
|
+
|
|
100
|
+
**Region drives the display currency.** The region pick also decides how the stats page shows money: *Default / CN (Gitee)* keeps costs in RMB (`¥` + the table's own numbers); *Global (GitHub)* shows them in USD (`$` + `RMB ÷ rate`). The rate comes from the `usdExchangeRate` field at the very top of the pricing table (RMB per 1 USD; currently `7`), and falls back to a built-in `7` when the mirror does not carry it yet. Every money display follows along: the total-cost card, the per-model cost column, the unpriced warning, and the in/out/cache/write rates in the pricing dialog (whose USD view annotates the conversion rate under the table). Amounts on the wire always stay RMB — conversion happens only at render time, so switching regions never rebuilds any stats.
|
|
101
|
+
|
|
102
|
+
## Provider quota
|
|
103
|
+
|
|
104
|
+
The input-bar button follows the currently selected provider and opens a panel with remaining quota (the same API key as inference):
|
|
105
|
+
|
|
106
|
+
<img src="docs/images/zhipu-plan-usage.png" width="520" alt="Zhipu GLM quota panel">
|
|
107
|
+
|
|
108
|
+
<img src="docs/images/opencode-go-plan-usage.png" width="520" alt="OpenCode Go quota panel">
|
|
109
|
+
|
|
110
|
+
| Provider | Shows |
|
|
111
|
+
|---|---|
|
|
112
|
+
| Zhipu GLM Coding Plan (CN / international) | 5-hour, weekly (some plans also monthly) |
|
|
113
|
+
| Kimi For Coding | 5-hour, weekly |
|
|
114
|
+
| MiniMax Coding Plan (CN / international) | 5-hour, weekly |
|
|
115
|
+
| OpenCode Go | 5-hour, weekly, monthly |
|
|
116
|
+
| DeepSeek (official) | ¥ account balance |
|
|
117
|
+
| OpenRouter | $ remaining credits |
|
|
118
|
+
|
|
119
|
+
Unsupported providers hide the button. A failed query can be retried from the panel. On by default; set `quota.enabled: false` to turn it off.
|
|
120
|
+
|
|
121
|
+
Not supported yet: Volcengine, ZenMux, Zhipu Team plan, Claude / Codex / Gemini / Grok official subscriptions, GitHub Copilot.
|
|
122
|
+
|
|
123
|
+
## Install
|
|
124
|
+
|
|
125
|
+
### From GitHub (recommended)
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
dsh plugin --profile web add github:LaoYueHanNi/dsh-token-usage
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
> The package declares `dsh.bundle`, so `add` wires the plugin into the profile's layer stack automatically — no config editing needed. The built `lib/` ships in the repo (there is no `prepare` script), so git installs work out of the box without any build allowlist. The first startup runs one history backfill, afterwards it records in real time.
|
|
132
|
+
|
|
133
|
+
### From a local directory (development)
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
dsh plugin --profile web add link:D:/plugins/dsh-token-usage
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`link:` installs a symlink: rebuild the plugin and restart `dsh web` to apply changes.
|
|
140
|
+
|
|
141
|
+
## Update
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
dsh plugin --profile web update dsh-token-usage
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Remove
|
|
148
|
+
|
|
149
|
+
```sh
|
|
150
|
+
dsh plugin --profile web remove dsh-token-usage
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The plugin is removed from the profile and stops loading. Data files under `$DSH_HOME/token-usage/` are kept — delete them manually if you no longer need them.
|
|
154
|
+
|
|
155
|
+
## Development
|
|
156
|
+
|
|
157
|
+
Build the plugin once:
|
|
158
|
+
|
|
159
|
+
```sh
|
|
160
|
+
npm install
|
|
161
|
+
npm run build && npm run build:client
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
> **No `prepare` script — by design.** The compiled `lib/` output is committed to the repo. pnpm ≥ 10 refuses to run build scripts of git-hosted dependencies unless they are allowlisted (`ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`), so a `prepare` script would break the zero-config `github:` install for every user. Shipping prebuilt output instead keeps `dsh plugin add github:LaoYueHanNi/dsh-token-usage` working out of the box. **After changing anything under `src/`, always rebuild and commit the updated `lib/`**, or installs will get stale output:
|
|
165
|
+
|
|
166
|
+
```sh
|
|
167
|
+
npm run build && npm run build:client
|
|
168
|
+
git add lib/
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Temporary mount — effective for this launch only, no profile changes. `cordis.yml` points at the built `lib/index.js`. That file is machine-local (it embeds the absolute path of YOUR checkout) and not tracked by git: copy it from the template first and edit `name` to the absolute `file://` URL of `lib/index.js` on your machine:
|
|
172
|
+
|
|
173
|
+
```sh
|
|
174
|
+
cp cordis.example.yml cordis.yml # then edit the name path inside
|
|
175
|
+
dsh web --patch <plugin-dir>/cordis.yml
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
This mode only mounts the host half (data recording keeps working); the stats page needs the client bundle resolved by package name, so for UI development use the `link:` install above instead: run `npm run build && npm run build:client` (or `npx tsdown --watch` in the plugin directory), restart `dsh web`, and the browser plugin hot-reloads automatically.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# dsh-token-usage
|
|
2
|
+
|
|
3
|
+
[](https://awesome-dsh-plugin.com)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
简体中文 | [English](./README.md)
|
|
8
|
+
|
|
9
|
+
一个 [dsh] 用量插件:在 Web 界面直接展示模型 token 用量。安装后打开**设置**(侧栏底部齿轮),即可看到「Token 用量」页 —— 汇总卡片(含费用)、按日总 token 折线图、按模型明细表与定价弹窗,支持按日期区间和模型筛选,效果见上图。
|
|
10
|
+
|
|
11
|
+
[dsh]: https://github.com/cordiverse/dsh
|
|
12
|
+
|
|
13
|
+
仓库:<https://github.com/LaoYueHanNi/dsh-token-usage>
|
|
14
|
+
|
|
15
|
+
## 功能
|
|
16
|
+
|
|
17
|
+
- **实时记录**:每次成功的模型请求追加一行到按天分片的 JSONL 文件(请求 id、模型、输入 / 输出 / 缓存读 / 缓存写 token、时间、会话 id)。
|
|
18
|
+
- **Web 统计页**:过滤条(日期区间 + 模型下拉 + `1d`/`7d`/`30d` 快捷区间)、汇总卡片、按日趋势图(悬停查看当日总量)、按模型明细表。
|
|
19
|
+
- **会话用量页签**:对话面板新增「用量」视图页签(与聊天 / 轨迹并列),展示当前会话的 token 与费用 dashboard —— 六张数值卡(请求数、费用、缓存命中率、首 token 平均延迟、出字速度、总 token)+ 四项 token 明细条 + 按小时趋势图 + 按模型表;支持「本会话 / 含子会话」范围切换(子会话子树聚合到一次请求),子会话表逐行展示(请求数、总 token、费用、命中率、首 token、速度),点击行钻取到该子会话并可逐级返回。token 与费用走插件自己的计费链(安装后记录),首 token 与出字速度读 DSH 的 `sessionStats` 会话投影(含安装前历史);会话无记录时优雅降级为占位文案。
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
- **费用统计与模型定价**:按模型单价(¥/百万 token)实时计算费用 —— 汇总卡醒目展示总费用,按模型表每行带费用列,未定价模型高亮提示(费用按 ¥0 计)。定价模型的名字旁有**「定价」小按钮**,点击弹窗展示该模型的完整价格表:**每行一个计费条件**(默认价、上下文档位 `≥ 512K`、峰谷时段 `09:00-12:00`、限时规则的日期窗口分组),条件对应的入/出/缓/写四价各自成列,与逐条计费的解析规则一一对应。定价由云端镜像与手工文件合并而来:启动时自动从 model-price-table(cc-switch-analyzer 同源)拉取镜像,`pricing.json` 手工覆盖/补充。
|
|
24
|
+
- **供应商配额**:输入栏模型选择器左侧有配额按钮,跟随当前选中的供应商展示套餐余量。智谱 GLM / Kimi / MiniMax / OpenCode Go 显示时间窗口进度,DeepSeek / OpenRouter 显示账户余额。详见「[供应商配额](#供应商配额)」。
|
|
25
|
+
- **历史补齐**:首次启动自动同步安装前已发生的请求(幂等)。
|
|
26
|
+
|
|
27
|
+
## 模型定价
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
**逐条请求精确计费**:每条记录按自身时间戳走 cc-switch-analyzer 同款规则链——时间区间规则(`timeRules`)优先,命中后用规则内上下文档位(`contextTiers`)与峰谷价(`dailySlots`);未命中走模型根的档位 → 峰谷 → 基础价。档位匹配以上下文 token 量近似(本请求 input + cacheRead + cacheWrite)。定价表更新价格后,全部历史按新价即时重算,无需重建数据。定价来自两个文件,读取时合并,`pricing.json` 的条目永远优先(整模型覆盖,含禁用其云端规则):
|
|
32
|
+
|
|
33
|
+
| 文件 | 来源 | 说明 |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `pricing.ccsa.json` | 启动自动拉取 | 云端 model-price-table(cc-switch-analyzer 同源)的本地镜像,每次重启 dsh 自动刷新,失败时沿用旧镜像 |
|
|
36
|
+
| `pricing.json` | 手工编辑 | 覆盖同步价或补充缺失模型,手动微调不会被同步冲掉 |
|
|
37
|
+
|
|
38
|
+
云端 feed 格式(`currency` 须为 `RMB`;`modelId` 与 `aliases` 都会展开为可匹配的键;`timeRules` / `contextTiers` / `dailySlots` 全部参与计费):
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"version": 4,
|
|
43
|
+
"updatedAt": 0,
|
|
44
|
+
"currency": "RMB",
|
|
45
|
+
"models": [
|
|
46
|
+
{ "modelId": "deepseek-chat", "inputCostPerMillion": 2, "outputCostPerMillion": 8,
|
|
47
|
+
"cacheReadCostPerMillion": 0.5, "cacheCreationCostPerMillion": 1, "aliases": ["deepseek-v3"] }
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`pricing.json` 的扁平格式(键为模型 id、与记录中的 `model` 完全一致;`inputPerMillion`、`outputPerMillion` 必填,`cacheReadPerMillion` / `cacheWritePerMillion` 可选、缺省按输入价计费):
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"deepseek-chat": { "inputPerMillion": 2, "outputPerMillion": 8, "cacheReadPerMillion": 0.5 }
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
文件损坏或条目非法时对应模型按未定价处理,不影响统计页;保存后刷新页面即可生效。默认数据目录:`~/.dsh/token-usage/`(配置了 `path` 时以该目录为准)。
|
|
61
|
+
|
|
62
|
+
### 修改数据目录
|
|
63
|
+
|
|
64
|
+
数据目录可在 Web 设置里直接修改:**设置 → 插件**页签下折叠的 **Token 用量** 卡片内,「数据目录」输入框留空表示默认位置(`~/.dsh/token-usage/`),填入绝对路径并保存后**立即生效**——历史数据自动迁移到新目录(按文件原样复制,完成后自动切换并清理旧目录),无需重启,也无需手动搬数据。
|
|
65
|
+
|
|
66
|
+
输入框旁的「**浏览…**」按钮打开目录选择器——复用 dsh 框架自带的目录选择能力(与工作区流程同一个选择器,经 `ctx.workspaces.pickDirectory()` 驱动):本机桌面走系统原生对话框,远程/无桌面环境自动切换为应用内浏览。选中的路径只填入暂存草稿,仍需点「保存」才提交。
|
|
67
|
+
|
|
68
|
+
迁移采用两阶段提交(先全部复制、再切换、最后清理),任何一步失败数据都只会同时存在于两份或仅留在原目录,绝不会只存于新目录。**对话进行中时无法保存目录修改**——事件只在一轮对话(turn)进行期间追加,所以只把「正在交互的对话」当作障碍,空闲开着的对话标签绝不阻止保存——卡片在保存前经 `/token-usage/dir-guard` 路由预检(判定依据是对话是否仍在交互),直接拒绝本次保存并在失败提示行显示当前进行中的对话数,设置不落盘;等待对话结束后再次保存即可完成迁移。统计缓存 `rollup.json` 是派生数据,不随迁移,切换后首次统计读取会自动重建。也可用配置项直接指定:
|
|
69
|
+
|
|
70
|
+
```yml
|
|
71
|
+
# 插件 profile 配置里
|
|
72
|
+
plugins:
|
|
73
|
+
token-usage:
|
|
74
|
+
path: D:/data/token-usage # 缺省:~/.dsh/token-usage/
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 选择定价镜像
|
|
78
|
+
|
|
79
|
+
启动同步默认拉 **Gitee**(中国大陆内速度快)。中国大陆以外的安装可把同步切到同一张表的 **GitHub 镜像** —— 既可在 Web 设置里改(同一张 **Token 用量** 卡片内的「定价区域」下拉,保存后立即生效),也可用一行配置。不做 IP 探测,部署者装的时候手动选一次即可:
|
|
80
|
+
|
|
81
|
+
```yml
|
|
82
|
+
# 插件 profile 配置里
|
|
83
|
+
plugins:
|
|
84
|
+
token-usage:
|
|
85
|
+
pricingRegion: overseas # 默认:domestic
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Web 卡片提供数据目录与地区切换两项;全部配置项(均为可选):
|
|
89
|
+
|
|
90
|
+
| 配置项 | 默认 | 含义 |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `path` | `~/.dsh/token-usage/` | 数据目录(Web 卡片可改,保存即迁移) |
|
|
93
|
+
|
|
94
|
+
| 配置项 | 默认 | 含义 |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| `pricingUrl` | — | 显式指定单个 feed(仅 cordis.yml 可设),优先级最高,覆盖下面所有项 |
|
|
97
|
+
| `pricingUrlDomestic` | Gitee feed | 国内镜像覆盖(仅 cordis.yml 可设;自维护 fork 用) |
|
|
98
|
+
| `pricingUrlOverseas` | GitHub 镜像 | 国外镜像覆盖(仅 cordis.yml 可设;自维护 fork 用) |
|
|
99
|
+
| `pricingRegion` | `domestic` | `domestic` → Gitee,`overseas` → GitHub(`pricingUrl` 未设置时生效) |
|
|
100
|
+
|
|
101
|
+
自己维护 model-price-table fork 时,用 `pricingUrlDomestic` / `pricingUrlOverseas` 指到你的地址。保存地区切换后立即重新同步;**不自动回退**:选定的镜像拉取失败就沿用旧镜像,等待下次同步重试。
|
|
102
|
+
|
|
103
|
+
**区域联动货币展示**:地区切换同时决定统计页的费用展示货币——选「国内 / 默认(Gitee)」时费用按人民币展示(`¥` + 原表数字);选「全球(GitHub)」时按美元展示(`$` + `RMB ÷ 汇率`)。汇率取定价表最顶层的 `usdExchangeRate` 字段(人民币兑 1 美元的换算率),当前表里为 `7`;镜像尚未携带该字段时回退用内置默认值 `7`。涉及到的每处金额都会联动:汇总总费用、按模型费用列、未定价提示,以及「定价」弹窗里的入/出/缓/写 单价(美元模式下列表下方会标注换算汇率)。线协议上传输的金额始终是人民币数值,换算只在展示层进行,切换区域不用重建任何统计。
|
|
104
|
+
|
|
105
|
+
## 供应商配额
|
|
106
|
+
|
|
107
|
+
输入栏按钮跟随当前选中的供应商,点开即可查看套餐余量(与推理共用同一把 API Key):
|
|
108
|
+
|
|
109
|
+
<img src="docs/images/zhipu-plan-usage_zh.png" width="520" alt="智谱 GLM 配额面板">
|
|
110
|
+
|
|
111
|
+
<img src="docs/images/opencode-go-plan-usage_zh.png" width="520" alt="OpenCode Go 配额面板">
|
|
112
|
+
|
|
113
|
+
| 供应商 | 展示 |
|
|
114
|
+
|---|---|
|
|
115
|
+
| 智谱 GLM Coding Plan(国内 / 国际) | 5 小时、每周(部分套餐另有每月) |
|
|
116
|
+
| Kimi For Coding | 5 小时、每周 |
|
|
117
|
+
| MiniMax Coding Plan(国内 / 国际) | 5 小时、每周 |
|
|
118
|
+
| OpenCode Go | 5 小时、每周、每月 |
|
|
119
|
+
| DeepSeek(官方) | ¥ 账户余额 |
|
|
120
|
+
| OpenRouter | $ 剩余额度 |
|
|
121
|
+
|
|
122
|
+
不支持的供应商不显示该按钮。查询失败时可在面板内重试。默认开启,可用 `quota.enabled: false` 关闭。
|
|
123
|
+
|
|
124
|
+
暂不支持:火山方舟、ZenMux、智谱团队版、Claude / Codex / Gemini / Grok 官方订阅、GitHub Copilot。
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
## 安装
|
|
128
|
+
|
|
129
|
+
### 从 GitHub 安装(推荐)
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
dsh plugin --profile web add github:LaoYueHanNi/dsh-token-usage
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
> 包声明了 `dsh.bundle`,`add` 会自动把插件挂进 profile 的层栈,无需手动改配置。构建产物 `lib/` 随仓库提交(没有 `prepare` 脚本),git 安装开箱即用,无需任何构建白名单配置。首次启动自动补齐一次历史记录,之后纯实时记录。
|
|
136
|
+
|
|
137
|
+
### 从本地目录安装(开发调试用)
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
dsh plugin --profile web add link:D:/plugins/dsh-token-usage
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`link:` 安装的是符号链接:重新构建插件后重启 `dsh web` 即可生效。
|
|
144
|
+
|
|
145
|
+
## 更新
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
dsh plugin --profile web update dsh-token-usage
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 移除
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
dsh plugin --profile web remove dsh-token-usage
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
插件会从 profile 移除并停止加载。数据文件(`$DSH_HOME/token-usage/`)会保留,需要时手动删除。
|
|
158
|
+
|
|
159
|
+
## 开发
|
|
160
|
+
|
|
161
|
+
先构建一次插件:
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
npm install
|
|
165
|
+
npm run build && npm run build:client
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
> **刻意不设 `prepare` 脚本。** 编译产物 `lib/` 已提交进仓库。pnpm ≥ 10 默认拒绝执行 git-hosted 依赖的构建脚本,除非加入白名单(报错 `ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`),因此若保留 `prepare`,每个用户用 `github:` 安装都会失败。改为随仓库分发预构建产物后,`dsh plugin add github:LaoYueHanNi/dsh-token-usage` 才能零配置开箱即用。**改动 `src/` 下的任何文件后,务必重新构建并提交更新后的 `lib/`**,否则别人安装到的是旧产物:
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
npm run build && npm run build:client
|
|
172
|
+
git add lib/
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
临时挂载 —— 仅当次启动生效,不动 profile,`cordis.yml` 指向构建产物 `lib/index.js`。`cordis.yml` 是机器本地的(含你 checkout 的绝对路径),不进 git:先从模板复制一份,并把 `name` 改成你机器上 `lib/index.js` 的绝对 `file://` URL:
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
cp cordis.example.yml cordis.yml # 然后编辑其中的 name 路径
|
|
179
|
+
dsh web --patch <插件目录>/cordis.yml
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
此模式只挂载 host 半边(数据记录照常工作);统计页依赖按包名解析的客户端 bundle,因此开发 UI 请用上面的 `link:` 安装方式:执行 `npm run build && npm run build:client`(或在插件目录跑 `npx tsdown --watch`)并重启 `dsh web` 后,浏览器端插件会自动热重载。
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Bundle patch layer of the token-usage plugin. Applied automatically when
|
|
2
|
+
# the package is installed into a profile via `dsh plugin --profile <name> add`
|
|
3
|
+
# (a package declaring `dsh.bundle` joins the profile's bundle stack, so no
|
|
4
|
+
# manual profile editing is needed). The row references the package by name.
|
|
5
|
+
- insert:
|
|
6
|
+
- id: token-usage
|
|
7
|
+
name: 'dsh-token-usage'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { CostInflateVars } from './cost-inflate.ts';
|
|
3
|
+
/** One +Δ fly label; animation starts on mount via WAAPI. */
|
|
4
|
+
export declare function CostDeltaFlyLabel({ text, vars }: {
|
|
5
|
+
text: string;
|
|
6
|
+
vars: CostInflateVars;
|
|
7
|
+
}): ReactNode;
|
|
8
|
+
//# sourceMappingURL=CostDeltaFlyLabel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CostDeltaFlyLabel.d.ts","sourceRoot":"","sources":["../../src/client/CostDeltaFlyLabel.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGxD,6DAA6D;AAC7D,wBAAgB,iBAAiB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,eAAe,CAAA;CAAE,GAAG,SAAS,CAsBpG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useRef } from 'react';
|
|
3
|
+
import { runDeltaFly } from "./cost-inflate-motion.js";
|
|
4
|
+
import styles from './SessionStatsChip.module.css';
|
|
5
|
+
/** One +Δ fly label; animation starts on mount via WAAPI. */
|
|
6
|
+
export function CostDeltaFlyLabel({ text, vars }) {
|
|
7
|
+
const ref = useRef(null);
|
|
8
|
+
useLayoutEffect(() => {
|
|
9
|
+
const el = ref.current;
|
|
10
|
+
if (el === null)
|
|
11
|
+
return;
|
|
12
|
+
const anim = runDeltaFly(el, vars);
|
|
13
|
+
if (anim === null) {
|
|
14
|
+
// Motion is allowed but this host has no WAAPI: without the animation
|
|
15
|
+
// the label would sit statically for the whole inflate window — hide
|
|
16
|
+
// it and let the number update be the only signal.
|
|
17
|
+
el.style.visibility = 'hidden';
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
return () => { anim.cancel(); };
|
|
21
|
+
}, [vars]);
|
|
22
|
+
return (_jsx("span", { ref: ref, className: styles['deltaFly'], children: text }));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=CostDeltaFlyLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CostDeltaFlyLabel.js","sourceRoot":"","sources":["../../src/client/CostDeltaFlyLabel.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD,OAAO,MAAM,MAAM,+BAA+B,CAAA;AAElD,6DAA6D;AAC7D,MAAM,UAAU,iBAAiB,CAAC,EAAE,IAAI,EAAE,IAAI,EAA2C;IACvF,MAAM,GAAG,GAAG,MAAM,CAAkB,IAAI,CAAC,CAAA;IAEzC,eAAe,CAAC,GAAG,EAAE;QACnB,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAA;QACtB,IAAI,EAAE,KAAK,IAAI;YAAE,OAAM;QACvB,MAAM,IAAI,GAAG,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;QAClC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,sEAAsE;YACtE,qEAAqE;YACrE,mDAAmD;YACnD,EAAE,CAAC,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAA;YAC9B,OAAM;QACR,CAAC;QACD,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA,CAAC,CAAC,CAAA;IAChC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;IAEV,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,YAC1C,IAAI,GACA,CACR,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coloured cache-hit-rate figure: the same four-bucket mapping the
|
|
3
|
+
* session-header chip uses (`format.hitRateDisplay`), so every surface
|
|
4
|
+
* that shows a hit rate — the chip, the Usage-tab / settings stat
|
|
5
|
+
* cards, the per-model and subagent tables — paints one gradient.
|
|
6
|
+
*
|
|
7
|
+
* @module token-usage/client/HitRateText
|
|
8
|
+
*/
|
|
9
|
+
import type { ReactNode } from 'react';
|
|
10
|
+
import type { UsageTotals } from '../wire.ts';
|
|
11
|
+
import { type HitRateBand } from './format.ts';
|
|
12
|
+
/** CSS-module class for one hit-rate colour bucket. */
|
|
13
|
+
export declare function bandClassOf(band: HitRateBand): string;
|
|
14
|
+
/**
|
|
15
|
+
* Render a hit-rate percentage (or `—`) in its threshold colour.
|
|
16
|
+
* @param totals - the aggregated token buckets the rate is computed from.
|
|
17
|
+
*/
|
|
18
|
+
export declare function HitRateText({ totals }: {
|
|
19
|
+
totals: UsageTotals;
|
|
20
|
+
}): ReactNode;
|
|
21
|
+
//# sourceMappingURL=HitRateText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HitRateText.d.ts","sourceRoot":"","sources":["../../src/client/HitRateText.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAG9D,uDAAuD;AACvD,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAErD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CAG1E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { hitRateDisplay } from "./format.js";
|
|
3
|
+
import bands from './hit-rate-band.module.css';
|
|
4
|
+
/** CSS-module class for one hit-rate colour bucket. */
|
|
5
|
+
export function bandClassOf(band) {
|
|
6
|
+
return bands[`band_${band}`] ?? '';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Render a hit-rate percentage (or `—`) in its threshold colour.
|
|
10
|
+
* @param totals - the aggregated token buckets the rate is computed from.
|
|
11
|
+
*/
|
|
12
|
+
export function HitRateText({ totals }) {
|
|
13
|
+
const { text, band } = hitRateDisplay(totals);
|
|
14
|
+
return _jsx("span", { className: bandClassOf(band), children: text });
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=HitRateText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HitRateText.js","sourceRoot":"","sources":["../../src/client/HitRateText.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAA;AAC9D,OAAO,KAAK,MAAM,4BAA4B,CAAA;AAE9C,uDAAuD;AACvD,MAAM,UAAU,WAAW,CAAC,IAAiB;IAC3C,OAAO,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,IAAI,EAAE,CAAA;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,MAAM,EAA2B;IAC7D,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC,CAAA;IAC7C,OAAO,eAAM,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,YAAG,IAAI,GAAQ,CAAA;AAC1D,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input-bar quota button (browser half): a 28×28 round trigger registered
|
|
3
|
+
* into the `conversation.input.right` slot (it renders left of the model
|
|
4
|
+
* chip — the host's fixed tool-row order). The glyph is a remaining-share
|
|
5
|
+
* ring (ContextMeter family) colored by the finest window. Clicking opens a
|
|
6
|
+
* width-tiered popup (amount-only 200px / one progress bar 232px / two
|
|
7
|
+
* bars 320px) centered on the button with the current provider's quota
|
|
8
|
+
* windows: progress columns (5 小时 / 每周) for coding-plan providers, an
|
|
9
|
+
* amount row for balance providers.
|
|
10
|
+
*
|
|
11
|
+
* The provider follows the model CHIP's live selection (the shell's
|
|
12
|
+
* model-selection service reports the host's next selection before any
|
|
13
|
+
* request is sent); without that service the host falls back to the last
|
|
14
|
+
* request's provider, else the default selection.
|
|
15
|
+
*
|
|
16
|
+
* The button SELF-GATES: it renders nothing while the host cannot
|
|
17
|
+
* determine a provider (`no-provider`), the provider has no quota adapter
|
|
18
|
+
* (`unsupported`), or the feature is off (`disabled`) — switching
|
|
19
|
+
* providers makes it appear again. A supported provider whose query fails
|
|
20
|
+
* KEEPS the button and shows the error with a retry inside the panel.
|
|
21
|
+
*
|
|
22
|
+
* The hover tooltip reads provider name + the finest window's exact
|
|
23
|
+
* remaining figure (percent, or the amount when no ratio exists).
|
|
24
|
+
*
|
|
25
|
+
* The interaction copies ContextMeter verbatim (click toggles, document
|
|
26
|
+
* pointerdown outside closes, Escape closes); mutual exclusion with the
|
|
27
|
+
* ContextMeter panel falls out of both components' outside-close
|
|
28
|
+
* handlers — opening one closes the other on its next pointerdown.
|
|
29
|
+
*
|
|
30
|
+
* @module token-usage/client/QuotaButton
|
|
31
|
+
*/
|
|
32
|
+
import type { ReactNode } from 'react';
|
|
33
|
+
import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
|
|
34
|
+
/**
|
|
35
|
+
* Structural view of the shell's model-selection service
|
|
36
|
+
* (`ctx.modelDirectories`, owned by ui-model-selection) — the same shared
|
|
37
|
+
* per-session directory the model chip renders from. Structural on
|
|
38
|
+
* purpose: no value import across plugins, and no compile-time tie to a
|
|
39
|
+
* package version the shell may or may not carry.
|
|
40
|
+
*/
|
|
41
|
+
export interface ModelSelectionSource {
|
|
42
|
+
/** The session's shared directory (throws when the session resolves no scope). */
|
|
43
|
+
directoryFor(sessionId: string): {
|
|
44
|
+
/** The host-reported selection for the NEXT assembled step; null before the first load. */
|
|
45
|
+
store: {
|
|
46
|
+
getSnapshot(): {
|
|
47
|
+
current: {
|
|
48
|
+
provider: string;
|
|
49
|
+
} | null;
|
|
50
|
+
};
|
|
51
|
+
subscribe(fn: () => void): () => void;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Stable holder the registration injects; the service attaches late (optional inject). */
|
|
56
|
+
export interface ModelDirectoryHandle {
|
|
57
|
+
readonly service: ModelSelectionSource | undefined;
|
|
58
|
+
}
|
|
59
|
+
/** Props the quota button binds for the conversation input-right slot. */
|
|
60
|
+
export type QuotaButtonProps = PropsRuntime<'conversation.input.right'> & PropsLocale<'token-usage'> & {
|
|
61
|
+
modelDirectory?: ModelDirectoryHandle;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Render the input-bar quota button for the active session's provider.
|
|
65
|
+
* @param props - the framework session id, the locale seat, and the
|
|
66
|
+
* optional model-directory holder (the chip's live selection).
|
|
67
|
+
* @returns the trigger + panel, or null while hidden (see the module note).
|
|
68
|
+
*/
|
|
69
|
+
export declare function QuotaButton({ sessionId, t, modelDirectory }: QuotaButtonProps): ReactNode | null;
|
|
70
|
+
//# sourceMappingURL=QuotaButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuotaButton.d.ts","sourceRoot":"","sources":["../../src/client/QuotaButton.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAqCjF;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,kFAAkF;IAClF,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG;QAC/B,2FAA2F;QAC3F,KAAK,EAAE;YACL,WAAW,IAAI;gBAAE,OAAO,EAAE;oBAAE,QAAQ,EAAE,MAAM,CAAA;iBAAE,GAAG,IAAI,CAAA;aAAE,CAAA;YACvD,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;SACtC,CAAA;KACF,CAAA;CACF;AAED,2FAA2F;AAC3F,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAAA;CACnD;AAED,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAC1B,YAAY,CAAC,0BAA0B,CAAC,GACtC,WAAW,CAAC,aAAa,CAAC,GAC1B;IAAE,cAAc,CAAC,EAAE,oBAAoB,CAAA;CAAE,CAAA;AAE7C;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAiNhG"}
|