@laoyuehanni/dsh-token-usage 0.3.13 → 0.4.0
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.md +21 -86
- package/README.zh.md +21 -90
- package/docs/pricing.md +79 -0
- package/lib/client/StatCard.d.ts +61 -5
- package/lib/client/StatCard.d.ts.map +1 -1
- package/lib/client/StatCard.js +39 -1
- package/lib/client/StatCard.js.map +1 -1
- package/lib/client/TokenUsageCard.d.ts.map +1 -1
- package/lib/client/TokenUsageCard.js +23 -12
- package/lib/client/TokenUsageCard.js.map +1 -1
- package/lib/client/TokenUsageSection.d.ts.map +1 -1
- package/lib/client/TokenUsageSection.js +5 -5
- package/lib/client/TokenUsageSection.js.map +1 -1
- package/lib/client/TrendChart.d.ts +12 -3
- package/lib/client/TrendChart.d.ts.map +1 -1
- package/lib/client/TrendChart.js +30 -19
- package/lib/client/TrendChart.js.map +1 -1
- package/lib/client/UsageView.d.ts +6 -5
- package/lib/client/UsageView.d.ts.map +1 -1
- package/lib/client/UsageView.js +19 -14
- package/lib/client/UsageView.js.map +1 -1
- package/lib/client/format.d.ts +18 -3
- package/lib/client/format.d.ts.map +1 -1
- package/lib/client/format.js +45 -3
- package/lib/client/format.js.map +1 -1
- package/lib/client/locales.d.ts +21 -1
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/locales.js +42 -2
- package/lib/client/locales.js.map +1 -1
- package/lib/client/trend-chart/index.d.ts +1 -1
- package/lib/client/trend-chart/index.d.ts.map +1 -1
- package/lib/client/trend-chart/index.js +1 -1
- package/lib/client/trend-chart/index.js.map +1 -1
- package/lib/client/trend-chart/points.d.ts +11 -0
- package/lib/client/trend-chart/points.d.ts.map +1 -1
- package/lib/client/trend-chart/points.js +20 -0
- package/lib/client/trend-chart/points.js.map +1 -1
- package/lib/client.js +318 -50
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +14 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +117 -28
- package/lib/index.js.map +1 -1
- package/lib/log.d.ts +18 -0
- package/lib/log.d.ts.map +1 -0
- package/lib/log.js +16 -0
- package/lib/log.js.map +1 -0
- package/lib/migrate.d.ts +2 -1
- package/lib/migrate.d.ts.map +1 -1
- package/lib/migrate.js +3 -2
- package/lib/migrate.js.map +1 -1
- package/lib/pricing.d.ts +5 -2
- package/lib/pricing.d.ts.map +1 -1
- package/lib/pricing.js +15 -12
- package/lib/pricing.js.map +1 -1
- package/lib/record-cache.d.ts +11 -4
- package/lib/record-cache.d.ts.map +1 -1
- package/lib/record-cache.js +16 -9
- package/lib/record-cache.js.map +1 -1
- package/lib/rollup.d.ts +15 -8
- package/lib/rollup.d.ts.map +1 -1
- package/lib/rollup.js +14 -9
- package/lib/rollup.js.map +1 -1
- package/lib/stats-route.d.ts +3 -0
- package/lib/stats-route.d.ts.map +1 -1
- package/lib/stats-route.js +6 -4
- package/lib/stats-route.js.map +1 -1
- package/lib/stats.d.ts +8 -5
- package/lib/stats.d.ts.map +1 -1
- package/lib/stats.js +74 -26
- package/lib/stats.js.map +1 -1
- package/lib/sync-state.d.ts +2 -1
- package/lib/sync-state.d.ts.map +1 -1
- package/lib/sync-state.js +3 -2
- package/lib/sync-state.js.map +1 -1
- package/lib/sync.d.ts +24 -3
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +42 -10
- package/lib/sync.js.map +1 -1
- package/lib/usage-log.d.ts +23 -8
- package/lib/usage-log.d.ts.map +1 -1
- package/lib/usage-log.js +129 -17
- package/lib/usage-log.js.map +1 -1
- package/lib/usage-record.d.ts +88 -7
- package/lib/usage-record.d.ts.map +1 -1
- package/lib/usage-record.js +140 -4
- package/lib/usage-record.js.map +1 -1
- package/lib/wire.d.ts +19 -1
- package/lib/wire.d.ts.map +1 -1
- package/lib/wire.js.map +1 -1
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -13,53 +13,29 @@ A dsh usage plugin that displays model token usage right in the Web UI. After in
|
|
|
13
13
|
Repo: <https://github.com/LaoYueHanNi/dsh-token-usage>
|
|
14
14
|
|
|
15
15
|
> [!IMPORTANT]
|
|
16
|
-
> **
|
|
16
|
+
> **GitHub direct installs have ended** — the repository no longer carries prebuilt output. Install from npm instead:
|
|
17
17
|
>
|
|
18
18
|
> ```sh
|
|
19
|
-
> dsh plugin --profile web remove dsh-token-usage
|
|
20
19
|
> dsh plugin --profile web add @laoyuehanni/dsh-token-usage
|
|
21
20
|
> ```
|
|
22
21
|
>
|
|
23
|
-
>
|
|
22
|
+
> **Upgrading from a legacy `github:` install (≤ 0.3.7, package name `dsh-token-usage`)?** An in-place `update` fails to load — remove the old name first, then add again. Usage data under `$DSH_HOME/token-usage/` carries over untouched.
|
|
24
23
|
|
|
25
24
|
## Features
|
|
26
25
|
|
|
27
|
-
- **Live
|
|
26
|
+
- **Live recording**: every provider-billed model call is recorded as it happens — tokens, cost, model, session — context-compaction calls included.
|
|
28
27
|
- **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.
|
|
29
|
-
- **Session usage
|
|
28
|
+
- **Session usage tab**: the conversation pane gains a **Usage** view tab (beside Chat / Trajectory) with the active session's dashboard — six stat cards (successful requests with a failure pill, 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 scope switch toggles **Session / With subagents**, and the subagent table drills into each child and back. Hovering the failure pill breaks failures down per class (rate limited, server error, context exceeded, …).
|
|
30
29
|
|
|
31
30
|

|
|
32
31
|
|
|
33
|
-
- **Cost figures & model pricing**: per-request cost is computed live from per-model rates (¥ per million tokens)
|
|
34
|
-
- **Provider quota**: an input-bar button (left of the model chip) shows the selected provider's remaining quota.
|
|
35
|
-
- **History backfill**: the first startup syncs requests that happened before installation (idempotent).
|
|
32
|
+
- **Cost figures & model pricing**: per-request cost is computed live from per-model rates (¥ per million tokens); unpriced models warn and count as ¥0. Every priced model's name carries a **rates button** opening its full price table. Rates sync from the cloud feed on every startup; `pricing.json` holds manual overrides — see [Model pricing](#model-pricing).
|
|
33
|
+
- **Provider quota**: an input-bar button (left of the model chip) shows the selected provider's remaining quota. See [Provider quota](#provider-quota).
|
|
34
|
+
- **History backfill**: the first startup syncs requests that happened before installation (idempotent); unreadable session logs are skipped and counted, never fatal to the sync.
|
|
36
35
|
|
|
37
36
|
## Model pricing
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
**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. A peak slot may restrict itself to ISO weekdays via `daysOfWeek` (`1`=Monday … `7`=Sunday; omitted = every day), matched on the request's local day — e.g. DeepSeek V4 models bill weekend peak windows at the off-peak 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):
|
|
42
|
-
|
|
43
|
-
| File | Source | Notes |
|
|
44
|
-
|---|---|---|
|
|
45
|
-
| `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 |
|
|
46
|
-
| `pricing.json` | hand-edited | Overrides synced rates or adds missing models; manual tweaks survive re-syncs |
|
|
47
|
-
|
|
48
|
-
Cloud feed shape (`currency` must be `RMB`; both `modelId` and every alias become matchable keys; `timeRules` / `contextTiers` / `dailySlots` all take part in billing):
|
|
49
|
-
|
|
50
|
-
```json
|
|
51
|
-
{
|
|
52
|
-
"version": 4,
|
|
53
|
-
"updatedAt": 0,
|
|
54
|
-
"currency": "RMB",
|
|
55
|
-
"models": [
|
|
56
|
-
{ "modelId": "deepseek-chat", "inputCostPerMillion": 2, "outputCostPerMillion": 8,
|
|
57
|
-
"cacheReadCostPerMillion": 0.5, "cacheCreationCostPerMillion": 1, "aliases": ["deepseek-v3"] }
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
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):
|
|
38
|
+
Costs are billed per record at its own timestamp, and a rates update re-prices the whole history instantly. Rates come from two files merged on read — a cloud mirror auto-synced on every startup, and a hand-edited `pricing.json` whose entries always win (per model, wholesale):
|
|
63
39
|
|
|
64
40
|
```json
|
|
65
41
|
{
|
|
@@ -67,48 +43,30 @@ Flat `pricing.json` shape (keys are model ids matching the recorded `model` exac
|
|
|
67
43
|
}
|
|
68
44
|
```
|
|
69
45
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
### Changing the data directory
|
|
46
|
+
Broken files degrade the affected models to unpriced without breaking the stats page. Default location: `~/.dsh/token-usage/`. Billing rule chain, cloud feed format, and self-hosted mirror URLs: [docs/pricing.md](./docs/pricing.md).
|
|
73
47
|
|
|
74
|
-
|
|
48
|
+
## Configuration
|
|
75
49
|
|
|
76
|
-
|
|
50
|
+
### Data directory
|
|
77
51
|
|
|
78
|
-
|
|
52
|
+
Editable on the web card (**Settings → Plugins → Token Usage**): saving an absolute path takes effect immediately — history migrates automatically, no restart, no manual move. Blank keeps the default `~/.dsh/token-usage/`. A save is refused while a conversation is in progress; wait for it to end, then save again. Or set it directly:
|
|
79
53
|
|
|
80
54
|
```yml
|
|
81
|
-
# in the plugin's profile config
|
|
82
55
|
plugins:
|
|
83
56
|
token-usage:
|
|
84
57
|
path: D:/data/token-usage # default: ~/.dsh/token-usage/
|
|
85
58
|
```
|
|
86
59
|
|
|
87
|
-
###
|
|
60
|
+
### Pricing region
|
|
88
61
|
|
|
89
|
-
The
|
|
62
|
+
The pricing mirror follows your region: **Gitee** by default (fast inside mainland China) or the **GitHub mirror** of the same table — pick once on the web card's **Pricing region** dropdown or via config. The pick also drives the display currency (¥ RMB vs $ USD at the table's exchange rate).
|
|
90
63
|
|
|
91
64
|
```yml
|
|
92
|
-
# in the plugin's profile config
|
|
93
65
|
plugins:
|
|
94
66
|
token-usage:
|
|
95
67
|
pricingRegion: overseas # default: domestic
|
|
96
68
|
```
|
|
97
69
|
|
|
98
|
-
The web card exposes the data directory and the region switch; the full key set (all optional):
|
|
99
|
-
|
|
100
|
-
| Key | Default | Meaning |
|
|
101
|
-
|---|---|---|
|
|
102
|
-
| `path` | `~/.dsh/token-usage/` | Data directory (editable on the web card; saving migrates) |
|
|
103
|
-
| `pricingUrl` | — | Explicit single feed (cordis.yml only); wins over every other key below |
|
|
104
|
-
| `pricingUrlDomestic` | gitee feed | Domestic mirror override (cordis.yml only; for self-maintained forks) |
|
|
105
|
-
| `pricingUrlOverseas` | github mirror | Overseas mirror override (cordis.yml only; for self-maintained forks) |
|
|
106
|
-
| `pricingRegion` | `domestic` | `domestic` → Gitee, `overseas` → GitHub (when `pricingUrl` is unset) |
|
|
107
|
-
|
|
108
|
-
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.
|
|
109
|
-
|
|
110
|
-
**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.
|
|
111
|
-
|
|
112
70
|
## Provider quota
|
|
113
71
|
|
|
114
72
|
The input-bar button follows the currently selected provider and opens a panel with remaining quota (the same API key as inference):
|
|
@@ -126,27 +84,15 @@ The input-bar button follows the currently selected provider and opens a panel w
|
|
|
126
84
|
| DeepSeek (official) | ¥ account balance |
|
|
127
85
|
| OpenRouter | $ remaining credits |
|
|
128
86
|
|
|
129
|
-
Unsupported providers hide the button
|
|
130
|
-
|
|
131
|
-
Not supported yet: Volcengine, ZenMux, Zhipu Team plan, Claude / Codex / Gemini / Grok official subscriptions, GitHub Copilot.
|
|
87
|
+
Unsupported providers hide the button; a failed query can be retried from the panel. On by default; turn it off with `quota.enabled: false`. Not supported yet: Volcengine, ZenMux, Zhipu Team plan, Claude / Codex / Gemini / Grok official subscriptions, GitHub Copilot.
|
|
132
88
|
|
|
133
89
|
## Install
|
|
134
90
|
|
|
135
|
-
### From npm
|
|
136
|
-
|
|
137
91
|
```sh
|
|
138
92
|
dsh plugin --profile web add @laoyuehanni/dsh-token-usage
|
|
139
93
|
```
|
|
140
94
|
|
|
141
|
-
> The package declares `dsh.bundle`, so `add` wires the plugin into the profile
|
|
142
|
-
|
|
143
|
-
### From a local directory (development)
|
|
144
|
-
|
|
145
|
-
```sh
|
|
146
|
-
dsh plugin --profile web add link:D:/plugins/dsh-token-usage
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
`link:` installs a symlink: rebuild the plugin and restart `dsh web` to apply changes.
|
|
95
|
+
> The package declares `dsh.bundle`, so `add` wires the plugin into the profile automatically — installs work out of the box, and the first startup backfills pre-install history.
|
|
150
96
|
|
|
151
97
|
## Update
|
|
152
98
|
|
|
@@ -160,29 +106,18 @@ dsh plugin --profile web update @laoyuehanni/dsh-token-usage
|
|
|
160
106
|
dsh plugin --profile web remove @laoyuehanni/dsh-token-usage
|
|
161
107
|
```
|
|
162
108
|
|
|
163
|
-
|
|
109
|
+
Data files under `$DSH_HOME/token-usage/` are kept — delete them manually if you no longer need them.
|
|
164
110
|
|
|
165
111
|
## Development
|
|
166
112
|
|
|
167
|
-
Build
|
|
113
|
+
Build once, install a symlink, iterate:
|
|
168
114
|
|
|
169
115
|
```sh
|
|
170
116
|
npm install
|
|
171
117
|
npm run build && npm run build:client
|
|
118
|
+
dsh plugin --profile web add link:D:/plugins/dsh-token-usage
|
|
172
119
|
```
|
|
173
120
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
```sh
|
|
177
|
-
npm run build && npm run build:client
|
|
178
|
-
git add lib/
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
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:
|
|
182
|
-
|
|
183
|
-
```sh
|
|
184
|
-
cp cordis.example.yml cordis.yml # then edit the name path inside
|
|
185
|
-
dsh web --patch <plugin-dir>/cordis.yml
|
|
186
|
-
```
|
|
121
|
+
Rebuild and restart `dsh web` to apply changes (`npx tsdown --watch` in the plugin directory hot-reloads the client). No `prepare` script by design — `lib/` never enters the repo; `npm publish` builds it fresh into the tarball.
|
|
187
122
|
|
|
188
|
-
|
|
123
|
+
Temporary host-only mount (this launch only, no profile changes): copy `cordis.example.yml` to `cordis.yml`, point `name` at the absolute `file://` URL of your `lib/index.js`, then `dsh web --patch <plugin-dir>/cordis.yml`. Data recording works in this mode; for UI work use the `link:` install above.
|
package/README.zh.md
CHANGED
|
@@ -13,53 +13,29 @@
|
|
|
13
13
|
仓库:<https://github.com/LaoYueHanNi/dsh-token-usage>
|
|
14
14
|
|
|
15
15
|
> [!IMPORTANT]
|
|
16
|
-
>
|
|
16
|
+
> **GitHub 直装已终止**——仓库不再携带构建产物,请改从 npm 安装:
|
|
17
17
|
>
|
|
18
18
|
> ```sh
|
|
19
|
-
> dsh plugin --profile web remove dsh-token-usage
|
|
20
19
|
> dsh plugin --profile web add @laoyuehanni/dsh-token-usage
|
|
21
20
|
> ```
|
|
22
21
|
>
|
|
23
|
-
>
|
|
22
|
+
> **从旧 `github:` 安装(≤ 0.3.7,包名 `dsh-token-usage`)升级?** 原地 `update` 会导致加载失败——先移除旧包名再重新安装。`$DSH_HOME/token-usage/` 下的历史数据完整保留。
|
|
24
23
|
|
|
25
24
|
## 功能
|
|
26
25
|
|
|
27
|
-
-
|
|
26
|
+
- **实时记录**:每一次 provider 计费调用发生即记录——token、费用、模型、会话,上下文压缩调用同样计入。
|
|
28
27
|
- **Web 统计页**:过滤条(日期区间 + 模型下拉 + `1d`/`7d`/`30d` 快捷区间)、汇总卡片、按日趋势图(悬停查看当日总量)、按模型明细表。
|
|
29
|
-
- **会话用量页签**:对话面板新增「用量」视图页签(与聊天 / 轨迹并列),展示当前会话的
|
|
28
|
+
- **会话用量页签**:对话面板新增「用量」视图页签(与聊天 / 轨迹并列),展示当前会话的 dashboard —— 六张数值卡(成功请求数带失败胶囊、费用、缓存命中率、首 token 平均延迟、出字速度、总 token)+ 四项 token 明细条 + 按小时趋势图 + 按模型表。「本会话 / 含子会话」一键切换范围,子会话表逐行钻取并可逐级返回。悬停失败胶囊可看按失败类别的明细(限流 / 网络异常 / 上下文超限 等逐一计数)。
|
|
30
29
|
|
|
31
30
|

|
|
32
31
|
|
|
33
|
-
- **费用统计与模型定价**:按模型单价(¥/百万 token
|
|
34
|
-
-
|
|
35
|
-
-
|
|
32
|
+
- **费用统计与模型定价**:按模型单价(¥/百万 token)逐条实时计费,未定价模型高亮提示(费用按 ¥0 计)。定价模型的名字旁有**「定价」小按钮**,点击弹窗展示该模型的完整价格表。价格每次启动自动从云端同步,`pricing.json` 手工覆盖——详见「[模型定价](#模型定价)」。
|
|
33
|
+
- **供应商配额**:输入栏模型选择器左侧的配额按钮,跟随当前选中的供应商展示套餐余量。详见「[供应商配额](#供应商配额)」。
|
|
34
|
+
- **历史补齐**:首次启动自动同步安装前已发生的请求(幂等);无法解析的会话日志跳过并计数,绝不中断同步。
|
|
36
35
|
|
|
37
36
|
## 模型定价
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
**逐条请求精确计费**:每条记录按自身时间戳走 cc-switch-analyzer 同款规则链——时间区间规则(`timeRules`)优先,命中后用规则内上下文档位(`contextTiers`)与峰谷价(`dailySlots`);未命中走模型根的档位 → 峰谷 → 基础价。档位匹配以上下文 token 量近似(本请求 input + cacheRead + cacheWrite)。定价表更新价格后,全部历史按新价即时重算,无需重建数据。定价来自两个文件,读取时合并,`pricing.json` 的条目永远优先(整模型覆盖,含禁用其云端规则):
|
|
42
|
-
|
|
43
|
-
| 文件 | 来源 | 说明 |
|
|
44
|
-
|---|---|---|
|
|
45
|
-
| `pricing.ccsa.json` | 启动自动拉取 | 云端 model-price-table(cc-switch-analyzer 同源)的本地镜像,每次重启 dsh 自动刷新,失败时沿用旧镜像 |
|
|
46
|
-
| `pricing.json` | 手工编辑 | 覆盖同步价或补充缺失模型,手动微调不会被同步冲掉 |
|
|
47
|
-
|
|
48
|
-
云端 feed 格式(`currency` 须为 `RMB`;`modelId` 与 `aliases` 都会展开为可匹配的键;`timeRules` / `contextTiers` / `dailySlots` 全部参与计费):
|
|
49
|
-
|
|
50
|
-
```json
|
|
51
|
-
{
|
|
52
|
-
"version": 4,
|
|
53
|
-
"updatedAt": 0,
|
|
54
|
-
"currency": "RMB",
|
|
55
|
-
"models": [
|
|
56
|
-
{ "modelId": "deepseek-chat", "inputCostPerMillion": 2, "outputCostPerMillion": 8,
|
|
57
|
-
"cacheReadCostPerMillion": 0.5, "cacheCreationCostPerMillion": 1, "aliases": ["deepseek-v3"] }
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
`pricing.json` 的扁平格式(键为模型 id、与记录中的 `model` 完全一致;`inputPerMillion`、`outputPerMillion` 必填,`cacheReadPerMillion` / `cacheWritePerMillion` 可选、缺省按输入价计费):
|
|
38
|
+
每条记录按自身时间戳精确计费,价格更新后全部历史即时重算。定价来自两个文件,读取时合并——启动自动同步的云端镜像,加上手工编辑的 `pricing.json`(条目永远优先,整模型覆盖):
|
|
63
39
|
|
|
64
40
|
```json
|
|
65
41
|
{
|
|
@@ -67,51 +43,30 @@
|
|
|
67
43
|
}
|
|
68
44
|
```
|
|
69
45
|
|
|
70
|
-
|
|
46
|
+
文件损坏只影响对应模型(按未定价处理),不影响统计页。默认目录:`~/.dsh/token-usage/`。计费规则链、云端 feed 格式与自建镜像地址:[docs/pricing.md](./docs/pricing.md)。
|
|
71
47
|
|
|
72
|
-
|
|
48
|
+
## 配置
|
|
73
49
|
|
|
74
|
-
|
|
50
|
+
### 数据目录
|
|
75
51
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
迁移采用两阶段提交(先全部复制、再切换、最后清理),任何一步失败数据都只会同时存在于两份或仅留在原目录,绝不会只存于新目录。**对话进行中时无法保存目录修改**——事件只在一轮对话(turn)进行期间追加,所以只把「正在交互的对话」当作障碍,空闲开着的对话标签绝不阻止保存——卡片在保存前经 `/token-usage/dir-guard` 路由预检(判定依据是对话是否仍在交互),直接拒绝本次保存并在失败提示行显示当前进行中的对话数,设置不落盘;等待对话结束后再次保存即可完成迁移。统计缓存 `rollup.json` 是派生数据,不随迁移,切换后首次统计读取会自动重建。也可用配置项直接指定:
|
|
52
|
+
在 Web 卡片(**设置 → 插件 → Token 用量**)里修改:保存绝对路径**立即生效**——历史数据自动迁移,无需重启、无需手动搬数据。留空保持默认 `~/.dsh/token-usage/`。对话进行中时保存会被拒绝,等对话结束再保存即可。也可用配置直接指定:
|
|
79
53
|
|
|
80
54
|
```yml
|
|
81
|
-
# 插件 profile 配置里
|
|
82
55
|
plugins:
|
|
83
56
|
token-usage:
|
|
84
57
|
path: D:/data/token-usage # 缺省:~/.dsh/token-usage/
|
|
85
58
|
```
|
|
86
59
|
|
|
87
|
-
###
|
|
60
|
+
### 定价区域
|
|
88
61
|
|
|
89
|
-
|
|
62
|
+
定价镜像跟随区域:默认 **Gitee**(中国大陆内速度快),可切到同一张表的 **GitHub 镜像**——在 Web 卡片的「定价区域」下拉选一次,或用配置。该选择同时决定费用展示货币(¥ 人民币 / $ 美元,按定价表汇率换算)。
|
|
90
63
|
|
|
91
64
|
```yml
|
|
92
|
-
# 插件 profile 配置里
|
|
93
65
|
plugins:
|
|
94
66
|
token-usage:
|
|
95
67
|
pricingRegion: overseas # 默认:domestic
|
|
96
68
|
```
|
|
97
69
|
|
|
98
|
-
Web 卡片提供数据目录与地区切换两项;全部配置项(均为可选):
|
|
99
|
-
|
|
100
|
-
| 配置项 | 默认 | 含义 |
|
|
101
|
-
|---|---|---|
|
|
102
|
-
| `path` | `~/.dsh/token-usage/` | 数据目录(Web 卡片可改,保存即迁移) |
|
|
103
|
-
|
|
104
|
-
| 配置项 | 默认 | 含义 |
|
|
105
|
-
|---|---|---|
|
|
106
|
-
| `pricingUrl` | — | 显式指定单个 feed(仅 cordis.yml 可设),优先级最高,覆盖下面所有项 |
|
|
107
|
-
| `pricingUrlDomestic` | Gitee feed | 国内镜像覆盖(仅 cordis.yml 可设;自维护 fork 用) |
|
|
108
|
-
| `pricingUrlOverseas` | GitHub 镜像 | 国外镜像覆盖(仅 cordis.yml 可设;自维护 fork 用) |
|
|
109
|
-
| `pricingRegion` | `domestic` | `domestic` → Gitee,`overseas` → GitHub(`pricingUrl` 未设置时生效) |
|
|
110
|
-
|
|
111
|
-
自己维护 model-price-table fork 时,用 `pricingUrlDomestic` / `pricingUrlOverseas` 指到你的地址。保存地区切换后立即重新同步;**不自动回退**:选定的镜像拉取失败就沿用旧镜像,等待下次同步重试。
|
|
112
|
-
|
|
113
|
-
**区域联动货币展示**:地区切换同时决定统计页的费用展示货币——选「国内 / 默认(Gitee)」时费用按人民币展示(`¥` + 原表数字);选「全球(GitHub)」时按美元展示(`$` + `RMB ÷ 汇率`)。汇率取定价表最顶层的 `usdExchangeRate` 字段(人民币兑 1 美元的换算率),当前表里为 `7`;镜像尚未携带该字段时回退用内置默认值 `7`。涉及到的每处金额都会联动:汇总总费用、按模型费用列、未定价提示,以及「定价」弹窗里的入/出/缓/写 单价(美元模式下列表下方会标注换算汇率)。线协议上传输的金额始终是人民币数值,换算只在展示层进行,切换区域不用重建任何统计。
|
|
114
|
-
|
|
115
70
|
## 供应商配额
|
|
116
71
|
|
|
117
72
|
输入栏按钮跟随当前选中的供应商,点开即可查看套餐余量(与推理共用同一把 API Key):
|
|
@@ -129,28 +84,15 @@ Web 卡片提供数据目录与地区切换两项;全部配置项(均为可
|
|
|
129
84
|
| DeepSeek(官方) | ¥ 账户余额 |
|
|
130
85
|
| OpenRouter | $ 剩余额度 |
|
|
131
86
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
暂不支持:火山方舟、ZenMux、智谱团队版、Claude / Codex / Gemini / Grok 官方订阅、GitHub Copilot。
|
|
135
|
-
|
|
87
|
+
不支持的供应商不显示该按钮;查询失败可在面板内重试。默认开启,可用 `quota.enabled: false` 关闭。暂不支持:火山方舟、ZenMux、智谱团队版、Claude / Codex / Gemini / Grok 官方订阅、GitHub Copilot。
|
|
136
88
|
|
|
137
89
|
## 安装
|
|
138
90
|
|
|
139
|
-
### 从 npm 安装
|
|
140
|
-
|
|
141
91
|
```sh
|
|
142
92
|
dsh plugin --profile web add @laoyuehanni/dsh-token-usage
|
|
143
93
|
```
|
|
144
94
|
|
|
145
|
-
> 包声明了 `dsh.bundle`,`add`
|
|
146
|
-
|
|
147
|
-
### 从本地目录安装(开发调试用)
|
|
148
|
-
|
|
149
|
-
```sh
|
|
150
|
-
dsh plugin --profile web add link:D:/plugins/dsh-token-usage
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
`link:` 安装的是符号链接:重新构建插件后重启 `dsh web` 即可生效。
|
|
95
|
+
> 包声明了 `dsh.bundle`,`add` 自动把插件挂进 profile,开箱即用;首次启动自动补齐安装前的历史记录。
|
|
154
96
|
|
|
155
97
|
## 更新
|
|
156
98
|
|
|
@@ -164,29 +106,18 @@ dsh plugin --profile web update @laoyuehanni/dsh-token-usage
|
|
|
164
106
|
dsh plugin --profile web remove @laoyuehanni/dsh-token-usage
|
|
165
107
|
```
|
|
166
108
|
|
|
167
|
-
|
|
109
|
+
数据文件(`$DSH_HOME/token-usage/`)会保留,需要时手动删除。
|
|
168
110
|
|
|
169
111
|
## 开发
|
|
170
112
|
|
|
171
|
-
|
|
113
|
+
构建一次、装符号链接、迭代:
|
|
172
114
|
|
|
173
115
|
```sh
|
|
174
116
|
npm install
|
|
175
117
|
npm run build && npm run build:client
|
|
118
|
+
dsh plugin --profile web add link:D:/plugins/dsh-token-usage
|
|
176
119
|
```
|
|
177
120
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
```sh
|
|
181
|
-
npm run build && npm run build:client
|
|
182
|
-
git add lib/
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
临时挂载 —— 仅当次启动生效,不动 profile,`cordis.yml` 指向构建产物 `lib/index.js`。`cordis.yml` 是机器本地的(含你 checkout 的绝对路径),不进 git:先从模板复制一份,并把 `name` 改成你机器上 `lib/index.js` 的绝对 `file://` URL:
|
|
186
|
-
|
|
187
|
-
```sh
|
|
188
|
-
cp cordis.example.yml cordis.yml # 然后编辑其中的 name 路径
|
|
189
|
-
dsh web --patch <插件目录>/cordis.yml
|
|
190
|
-
```
|
|
121
|
+
重新构建并重启 `dsh web` 即生效(插件目录跑 `npx tsdown --watch` 可热重载客户端)。刻意不设 `prepare` 脚本——`lib/` 从不进仓库,`npm publish` 现场构建打进 tarball。
|
|
191
122
|
|
|
192
|
-
|
|
123
|
+
临时挂载(仅当次启动生效,不动 profile):复制 `cordis.example.yml` 为 `cordis.yml`,把 `name` 改成你机器上 `lib/index.js` 的绝对 `file://` URL,然后 `dsh web --patch <插件目录>/cordis.yml`。此模式数据记录照常,开发 UI 请用上面的 `link:` 安装。
|
package/docs/pricing.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# 模型定价与计费详解
|
|
2
|
+
|
|
3
|
+
README 的深度延伸:计费规则链、价格文件格式、fork 维护者的镜像配置、货币展示联动。日常使用(看统计、装插件、改数据目录)不需要本文,见 [README](../README.zh.md)。
|
|
4
|
+
|
|
5
|
+
## 计费规则链
|
|
6
|
+
|
|
7
|
+
**每条记录按自身时间戳精确计费**,与 cc-switch-analyzer 同款规则链:
|
|
8
|
+
|
|
9
|
+
1. 命中时间区间规则(`timeRules`)优先——用规则内的上下文档位(`contextTiers`)与峰谷价(`dailySlots`);
|
|
10
|
+
2. 未命中时间规则,走模型根的档位 → 峰谷 → 基础价。
|
|
11
|
+
|
|
12
|
+
细节:
|
|
13
|
+
|
|
14
|
+
- `dailySlots` 可用 `daysOfWeek` 把峰谷限制在 ISO 星期(`1`=周一 … `7`=周日;缺省=每天),按请求的本地日匹配——例如 DeepSeek V4 的周末峰时按峰谷价之外的价格计。
|
|
15
|
+
- 档位匹配以上下文 token 量近似:本请求 `input + cacheRead + cacheWrite`。
|
|
16
|
+
- 定价表更新价格后,全部历史按新价即时重算,无需重建数据。
|
|
17
|
+
|
|
18
|
+
## 价格来源:两个文件,读取时合并
|
|
19
|
+
|
|
20
|
+
| 文件 | 来源 | 说明 |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `pricing.ccsa.json` | 启动自动拉取 | 云端 model-price-table(cc-switch-analyzer 同源)的本地镜像,每次重启 dsh 自动刷新,失败时沿用旧镜像 |
|
|
23
|
+
| `pricing.json` | 手工编辑 | 覆盖同步价或补充缺失模型,手动微调不会被同步冲掉 |
|
|
24
|
+
|
|
25
|
+
`pricing.json` 的条目永远优先,**整模型覆盖**(该模型不再使用云端规则,可借此禁用其云端定价)。文件损坏或条目非法时对应模型按未定价处理,不影响统计页;保存后刷新页面即可生效。默认数据目录:`~/.dsh/token-usage/`(配置了 `path` 时以该目录为准)。
|
|
26
|
+
|
|
27
|
+
### 云端 feed 格式
|
|
28
|
+
|
|
29
|
+
`currency` 须为 `RMB`;`modelId` 与 `aliases` 都会展开为可匹配的键;`timeRules` / `contextTiers` / `dailySlots` 全部参与计费:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"version": 4,
|
|
34
|
+
"updatedAt": 0,
|
|
35
|
+
"currency": "RMB",
|
|
36
|
+
"usdExchangeRate": 7,
|
|
37
|
+
"models": [
|
|
38
|
+
{ "modelId": "deepseek-chat", "inputCostPerMillion": 2, "outputCostPerMillion": 8,
|
|
39
|
+
"cacheReadCostPerMillion": 0.5, "cacheCreationCostPerMillion": 1, "aliases": ["deepseek-v3"] }
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### pricing.json 扁平格式
|
|
45
|
+
|
|
46
|
+
键为模型 id、与记录中的 `model` 完全一致;`inputPerMillion`、`outputPerMillion` 必填,`cacheReadPerMillion` / `cacheWritePerMillion` 可选、缺省按输入价计费:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"deepseek-chat": { "inputPerMillion": 2, "outputPerMillion": 8, "cacheReadPerMillion": 0.5 }
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 镜像与区域配置(fork 维护者)
|
|
55
|
+
|
|
56
|
+
启动同步默认拉 **Gitee**(中国大陆内速度快),`pricingRegion: overseas` 切到同一张表的 **GitHub 镜像**(Web 设置里的「定价区域」下拉等效)。不做 IP 探测,部署时手动选一次。保存地区切换后立即重新同步;**不自动回退**:选定的镜像拉取失败就沿用旧镜像,等待下次同步重试。
|
|
57
|
+
|
|
58
|
+
| 配置项 | 默认 | 含义 |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| `pricingRegion` | `domestic` | `domestic` → Gitee,`overseas` → GitHub(`pricingUrl` 未设置时生效) |
|
|
61
|
+
| `pricingUrl` | — | 显式指定单个 feed(仅 cordis.yml 可设),优先级最高,覆盖下面两项 |
|
|
62
|
+
| `pricingUrlDomestic` | Gitee feed | 国内镜像覆盖(仅 cordis.yml 可设;自维护 fork 用) |
|
|
63
|
+
| `pricingUrlOverseas` | GitHub 镜像 | 国外镜像覆盖(仅 cordis.yml 可设;自维护 fork 用) |
|
|
64
|
+
|
|
65
|
+
自己维护 model-price-table fork 时,用 `pricingUrlDomestic` / `pricingUrlOverseas` 指到你的地址。
|
|
66
|
+
|
|
67
|
+
## 货币展示联动
|
|
68
|
+
|
|
69
|
+
地区切换同时决定统计页的费用展示货币:
|
|
70
|
+
|
|
71
|
+
- **国内 / 默认(Gitee)**:人民币展示(`¥` + 原表数字);
|
|
72
|
+
- **全球(GitHub)**:美元展示(`$` + `RMB ÷ 汇率`)。
|
|
73
|
+
|
|
74
|
+
汇率取定价表最顶层的 `usdExchangeRate` 字段(人民币兑 1 美元),镜像尚未携带该字段时回退内置默认值 `7`。联动覆盖每处金额:汇总总费用、按模型费用列、未定价提示,以及「定价」弹窗里的入/出/缓/写单价(美元模式下列表下方标注换算汇率)。线协议上传输的金额始终是人民币数值,换算只在展示层进行,切换区域不用重建任何统计。
|
|
75
|
+
|
|
76
|
+
## 相关决策记录
|
|
77
|
+
|
|
78
|
+
- [峰谷 daysOfWeek 语义](./decisions/implemented/2026-08-29-daily-slots-days-of-week.md)
|
|
79
|
+
- [上下文压缩请求计费](./decisions/implemented/2026-09-02-compaction-billing.md)
|
package/lib/client/StatCard.d.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared "stat card" primitive: label on top, value underneath. Used by the
|
|
3
|
-
* settings section (
|
|
4
|
-
*
|
|
5
|
-
* TTFT / token speed). Centralising the markup + styling means
|
|
6
|
-
* surfaces read as one family without each one carrying its own
|
|
7
|
-
* label-on-top / value-below rule.
|
|
3
|
+
* settings section (primary cards + four token-bucket cards) and the Usage
|
|
4
|
+
* view tab (six cards: requests-with-failure-pill / cost / total tokens /
|
|
5
|
+
* hit rate / TTFT / token speed). Centralising the markup + styling means
|
|
6
|
+
* the two surfaces read as one family without each one carrying its own
|
|
7
|
+
* copy of the label-on-top / value-below rule.
|
|
8
|
+
*
|
|
9
|
+
* {@link FailurePill} is the compact failed-count chip the requests card
|
|
10
|
+
* uses. Per-model tables use {@link RequestsCell} (`A/B`, B in the error
|
|
11
|
+
* color) instead — a pill is too much chrome for a numeric column.
|
|
8
12
|
*
|
|
9
13
|
* @module token-usage/client/StatCard
|
|
10
14
|
*/
|
|
11
15
|
import type { ReactNode } from 'react';
|
|
16
|
+
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots';
|
|
12
17
|
/** One labelled figure inside a card. */
|
|
13
18
|
export interface StatCardProps {
|
|
14
19
|
/** The small secondary line ("token cost", "hit rate", "总 token"). */
|
|
@@ -23,4 +28,55 @@ export interface StatCardProps {
|
|
|
23
28
|
* The label clamps to one line and ellipsizes if the column is squeezed.
|
|
24
29
|
*/
|
|
25
30
|
export declare function StatCard({ label, value }: StatCardProps): ReactNode;
|
|
31
|
+
/** Props for the shared failure-count pill. */
|
|
32
|
+
export interface FailurePillProps {
|
|
33
|
+
/** Failed provider attempts; 0 renders nothing. */
|
|
34
|
+
failures: number;
|
|
35
|
+
/** Per-code breakdown driving the tooltip. */
|
|
36
|
+
failuresByCode: Record<string, number> | undefined;
|
|
37
|
+
/** Locale function (`stat.failuresPill` / `fail.*`). */
|
|
38
|
+
t: TranslateNS<'token-usage'>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Compact "失败 n" chip for the requests **card** only. Hovering or focusing
|
|
42
|
+
* it lists `限流 ×count` per class. Zero failures render nothing. Per-model
|
|
43
|
+
* tables do not use this — they print `A/B` via {@link RequestsCell}.
|
|
44
|
+
*/
|
|
45
|
+
export declare function FailurePill({ failures, failuresByCode, t, }: FailurePillProps): ReactNode;
|
|
46
|
+
/** Props for the shared successful-requests card with a failure pill. */
|
|
47
|
+
export interface RequestsStatCardProps {
|
|
48
|
+
/** Successful (billed) request count. */
|
|
49
|
+
requests: number;
|
|
50
|
+
/** Failed provider attempts. */
|
|
51
|
+
failures: number;
|
|
52
|
+
/** Per-code breakdown driving the pill tooltip. */
|
|
53
|
+
failuresByCode: Record<string, number> | undefined;
|
|
54
|
+
/** Locale function (zh/en `stat.requests` / `stat.failuresPill`). */
|
|
55
|
+
t: TranslateNS<'token-usage'>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The requests tile both dashboards share: hero figure is the successful
|
|
59
|
+
* count; a compact pill to its right carries the failure count.
|
|
60
|
+
*/
|
|
61
|
+
export declare function RequestsStatCard({ requests, failures, failuresByCode, t, }: RequestsStatCardProps): ReactNode;
|
|
62
|
+
/** Props for the per-model requests cell: `success/fail` as `A/B`.
|
|
63
|
+
* Tables pass the row's own totals so a session-scoped or date-filtered
|
|
64
|
+
* summary cannot leak another row's failures into this cell. */
|
|
65
|
+
export interface RequestsCellProps {
|
|
66
|
+
requests: number;
|
|
67
|
+
failures: number;
|
|
68
|
+
failuresByCode: Record<string, number> | undefined;
|
|
69
|
+
t: TranslateNS<'token-usage'>;
|
|
70
|
+
}
|
|
71
|
+
/** Column header for the per-model success/fail split: same 3-track
|
|
72
|
+
* grid as {@link RequestsCell} so the slash sits on the column midline. */
|
|
73
|
+
export declare function RequestsSplitHead({ t }: {
|
|
74
|
+
t: TranslateNS<'token-usage'>;
|
|
75
|
+
}): ReactNode;
|
|
76
|
+
/** One table cell: successful count, and when failures > 0 a slash on
|
|
77
|
+
* the column midline plus the failure count in the error color.
|
|
78
|
+
* Zero failures print only A (same left track, so the figure still
|
|
79
|
+
* lines up with rows that have a B). Hovering B lists the per-code
|
|
80
|
+
* breakdown. */
|
|
81
|
+
export declare function RequestsCell({ requests, failures, failuresByCode, t, }: RequestsCellProps): ReactNode;
|
|
26
82
|
//# sourceMappingURL=StatCard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatCard.d.ts","sourceRoot":"","sources":["../../src/client/StatCard.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"StatCard.d.ts","sourceRoot":"","sources":["../../src/client/StatCard.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAInE,yCAAyC;AACzC,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;IACb;;2EAEuE;IACvE,KAAK,EAAE,SAAS,CAAA;CACjB;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,aAAa,GAAG,SAAS,CAOnE;AAED,+CAA+C;AAC/C,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAA;IAChB,8CAA8C;IAC9C,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;IAClD,wDAAwD;IACxD,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAA;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,cAAc,EACd,CAAC,GACF,EAAE,gBAAgB,GAAG,SAAS,CAe9B;AAED,yEAAyE;AACzE,MAAM,WAAW,qBAAqB;IACpC,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAA;IAChB,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,mDAAmD;IACnD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;IAClD,qEAAqE;IACrE,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAA;CAC9B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,CAAC,GACF,EAAE,qBAAqB,GAAG,SAAS,CAYnC;AAED;;gEAEgE;AAChE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;IAClD,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAA;CAC9B;AAED;2EAC2E;AAC3E,wBAAgB,iBAAiB,CAAC,EAAE,CAAC,EAAE,EAAE;IAAE,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAA;CAAE,GAAG,SAAS,CAQrF;AAED;;;;gBAIgB;AAChB,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,CAAC,GACF,EAAE,iBAAiB,GAAG,SAAS,CA4B/B"}
|
package/lib/client/StatCard.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Tooltip } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
3
|
+
import { failuresTooltip } from "./format.js";
|
|
2
4
|
import styles from './StatCard.module.css';
|
|
3
5
|
/**
|
|
4
6
|
* Render one stat card. The value uses the standard label-primary color.
|
|
@@ -7,4 +9,40 @@ import styles from './StatCard.module.css';
|
|
|
7
9
|
export function StatCard({ label, value }) {
|
|
8
10
|
return (_jsxs("div", { className: styles['card'], children: [_jsx("span", { className: styles['cardLabel'], children: label }), _jsx("span", { className: styles['cardValue'], children: value })] }));
|
|
9
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Compact "失败 n" chip for the requests **card** only. Hovering or focusing
|
|
14
|
+
* it lists `限流 ×count` per class. Zero failures render nothing. Per-model
|
|
15
|
+
* tables do not use this — they print `A/B` via {@link RequestsCell}.
|
|
16
|
+
*/
|
|
17
|
+
export function FailurePill({ failures, failuresByCode, t, }) {
|
|
18
|
+
if (failures === 0)
|
|
19
|
+
return null;
|
|
20
|
+
return (_jsx("span", { className: styles['pillWrap'], children: _jsx(Tooltip, { label: failuresTooltip(failuresByCode, t), side: "bottom", delayMs: 200, children: _jsx("span", { className: styles['pill'], tabIndex: 0, children: t('stat.failuresPill', { count: failures.toLocaleString() }) }) }) }));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The requests tile both dashboards share: hero figure is the successful
|
|
24
|
+
* count; a compact pill to its right carries the failure count.
|
|
25
|
+
*/
|
|
26
|
+
export function RequestsStatCard({ requests, failures, failuresByCode, t, }) {
|
|
27
|
+
return (_jsx(StatCard, { label: t('stat.requests'), value: (_jsxs(_Fragment, { children: [_jsx("span", { className: styles['cardValueMain'], children: requests.toLocaleString() }), _jsx(FailurePill, { failures: failures, failuresByCode: failuresByCode, t: t })] })) }));
|
|
28
|
+
}
|
|
29
|
+
/** Column header for the per-model success/fail split: same 3-track
|
|
30
|
+
* grid as {@link RequestsCell} so the slash sits on the column midline. */
|
|
31
|
+
export function RequestsSplitHead({ t }) {
|
|
32
|
+
return (_jsxs("span", { className: styles['split'], children: [_jsx("span", { className: styles['splitOk'], children: t('stat.ok') }), _jsx("span", { className: styles['splitSep'], "aria-hidden": true, children: "/" }), _jsx("span", { className: styles['splitFailHead'], children: t('stat.fail') })] }));
|
|
33
|
+
}
|
|
34
|
+
/** One table cell: successful count, and when failures > 0 a slash on
|
|
35
|
+
* the column midline plus the failure count in the error color.
|
|
36
|
+
* Zero failures print only A (same left track, so the figure still
|
|
37
|
+
* lines up with rows that have a B). Hovering B lists the per-code
|
|
38
|
+
* breakdown. */
|
|
39
|
+
export function RequestsCell({ requests, failures, failuresByCode, t, }) {
|
|
40
|
+
const ok = requests.toLocaleString();
|
|
41
|
+
const okFigure = _jsx("span", { className: styles['splitOk'], children: ok });
|
|
42
|
+
if (failures === 0) {
|
|
43
|
+
return _jsx("span", { className: styles['split'], children: okFigure });
|
|
44
|
+
}
|
|
45
|
+
const fail = failures.toLocaleString();
|
|
46
|
+
return (_jsxs("span", { className: styles['split'], children: [okFigure, _jsx("span", { className: styles['splitSep'], "aria-hidden": true, children: "/" }), _jsx("span", { className: styles['pillWrap'], children: _jsx(Tooltip, { label: failuresTooltip(failuresByCode, t), side: "bottom", delayMs: 200, children: _jsx("span", { className: styles['splitFail'], tabIndex: 0, "aria-label": t('stat.failuresPill', { count: fail }), children: fail }) }) })] }));
|
|
47
|
+
}
|
|
10
48
|
//# sourceMappingURL=StatCard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatCard.js","sourceRoot":"","sources":["../../src/client/StatCard.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"StatCard.js","sourceRoot":"","sources":["../../src/client/StatCard.tsx"],"names":[],"mappings":"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"}
|