@chenlongapps/opencode-token-usage 0.4.28 → 0.5.1
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 +13 -9
- package/README.zh-CN.md +13 -9
- package/dist/aliases.d.ts +7 -5
- package/dist/aliases.js +32 -24
- package/dist/overrides.d.ts +7 -8
- package/dist/overrides.js +20 -49
- package/dist/performance.d.ts +3 -1
- package/dist/performance.js +158 -50
- package/dist/price-identity.d.ts +38 -0
- package/dist/price-identity.js +75 -0
- package/dist/prices.generated.d.ts +2 -3912
- package/dist/prices.generated.js +1401 -306
- package/dist/pricing.d.ts +3 -23
- package/dist/pricing.js +4 -97
- package/dist/tui.js +35 -25
- package/dist/usage.d.ts +5 -5
- package/dist/usage.js +34 -12
- package/docs/pricing.md +27 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Use it to see how many tokens a session and its subagents consume, how full the
|
|
|
27
27
|
|
|
28
28
|
- **Session-tree totals:** Track input, output, reasoning and cache tokens across the session tree, including unopened subagents, without double-counting inherited fork history.
|
|
29
29
|
- **Context visibility:** See the viewed session's context usage, latest reported request and estimated prompt composition.
|
|
30
|
-
- **Estimated cost by model:** Price recorded calls using their actual models, with
|
|
30
|
+
- **Estimated cost by model:** Price recorded calls using their actual models, with one built-in official or reference price per model/SKU as a fallback. Estimates are not provider bills.
|
|
31
31
|
- **Performance at a glance:** Monitor tokens per second (TPS), time to first token (TTFT) and the viewed session's own elapsed response time. Live TPS and elapsed-time estimates are marked with `~`.
|
|
32
32
|
- **Native terminal UI:** Keep a sidebar panel in the main session and a single-line summary in subagent views; open details only when needed.
|
|
33
33
|
- **On-demand details:** Use `/token-usage` for compact or detailed statistics, including per-model usage and rates, without sending a prompt to the model.
|
|
@@ -39,7 +39,7 @@ Use it to see how many tokens a session and its subagents consume, how full the
|
|
|
39
39
|
Requires **OpenCode 2** and **Node.js 22+**. See [Compatibility](#compatibility) for verified host versions and the OpenTUI engine caveat.
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
opencode plugin add @chenlongapps/opencode-token-usage
|
|
42
|
+
opencode plugin add @chenlongapps/opencode-token-usage@latest
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
Restart OpenCode after installation.
|
|
@@ -61,7 +61,9 @@ Instead of the command above, add the package to your project's `opencode.json`
|
|
|
61
61
|
```json
|
|
62
62
|
{
|
|
63
63
|
"$schema": "https://opencode.ai/config.json",
|
|
64
|
-
"plugins": [
|
|
64
|
+
"plugins": [
|
|
65
|
+
"@chenlongapps/opencode-token-usage@latest"
|
|
66
|
+
]
|
|
65
67
|
}
|
|
66
68
|
```
|
|
67
69
|
|
|
@@ -114,7 +116,7 @@ Costs follow the sidebar's pricing and `partial`/unavailable/free conventions. I
|
|
|
114
116
|
| `Steps` | Assistant message count across the session tree, including subagents; follows OpenCode's own stats definition, so compaction and user messages are not steps |
|
|
115
117
|
| `Est. Cost` | Estimated cost across the tree, pricing each assistant and compaction call with its actual model |
|
|
116
118
|
| `Run Time` | The viewed session's cumulative native per-turn response duration; while running, includes a display-only estimate of the current turn's elapsed time marked with `~`; never adds child-session durations |
|
|
117
|
-
| `TPS` | Provider-reported average throughput for `Output + Reasoning` across the tree. While streaming, a valid
|
|
119
|
+
| `TPS` | Provider-reported average throughput for `Output + Reasoning` across the tree. While streaming, a valid estimate from delivered text, reasoning summaries and tool input (UTF-8 bytes / 4) takes precedence and is marked with `~`. A fast window is preferred, with a longer fallback for sparse delivery. Completion restores historical throughput without `~` |
|
|
118
120
|
| `TTFT` | Average time to first token across measurable assistant steps in the tree, preferring OpenCode's native first-token timestamp |
|
|
119
121
|
|
|
120
122
|
#### Behavior
|
|
@@ -129,10 +131,12 @@ Costs follow the sidebar's pricing and `partial`/unavailable/free conventions. I
|
|
|
129
131
|
- `Run Time` / `Time` shows the duration and its estimate/freshness markers, without running-status text or animation. An idle parent's time never advances just because a child is active. Closing or switching views cleans up their estimates, and the shared elapsed-time ticker stops when no view needs it. Unavailable/stale timing keeps its own marker.
|
|
130
132
|
- A confirmed zero `Run Time` / `Time` is hidden in the sidebar, subagent summary/dialog and both `/token-usage` modes, without leaving an empty row or field. A nonzero live estimate makes the first turn visible even before any response has completed. Nonzero millisecond durations, unavailable values and stale timing remain visible.
|
|
131
133
|
- Runtime follows retained history: agent/model switches and compaction preserve past turns; fork copies never contribute to the fork's own time. A staged revert does not remove turns, but a committed revert deleting messages also removes their durations. Deleted historical timing cannot be reconstructed.
|
|
132
|
-
- `Est. Cost` prices
|
|
133
|
-
- The
|
|
134
|
+
- `Est. Cost` prices each message with its recorded model. Complete non-zero OpenCode prices take precedence. A verified Free SKU contributes the estimate at its paid counterpart's rate when that rate covers the call; By Model labels this `Free usage reference`, not a charge. Otherwise keep valid zero rates (except reviewed billing exceptions). Fallbacks replace the whole schedule without mixing rates or filling in missing categories.
|
|
135
|
+
- The offline snapshot is generated from [models.dev](https://models.dev/catalog.json) using verified LAB/model identities. It keeps one schedule per model or billing SKU: official non-zero prices first, then OpenRouter, Vercel AI Gateway, Amazon Bedrock and LLM Gateway in order, then the lowest other non-zero base Input + Output rate, and finally explicit zero prices. Reviewed overrides replace entire schedules. Free references are exact SKU links to existing rates, not duplicated quotes or guesses based on a suffix. No prices are downloaded or compared across providers at runtime.
|
|
134
136
|
- Confirmed free usage displays `$0.00`; positive estimates below `$0.001` display `<$0.001`, estimates through and including `$0.01` use three decimal places, and larger estimates use two. Unavailable prices display `—`; known subtotals with unpriced messages are marked `partial`. The snapshot excludes gateway markups, regional premiums, unlisted discounts, non-text billing, tool fees, and taxes, so Est. Cost is not a provider bill. See [price sources and limitations](docs/pricing.md).
|
|
135
|
-
- Live `TPS`
|
|
137
|
+
- Live `TPS` merges deliveries within 100 ms and samples each response independently. The fast path keeps the 2s window, requires at least 80 UTF-8 bytes over the response and at least three batches spanning 500 ms in the window, and smooths by elapsed time. The first batch counts toward readiness but only sets the baseline; its bytes do not enter the speed calculation.
|
|
138
|
+
- When the fast estimate is unavailable, the sparse fallback averages a contiguous span of up to 30s. It needs at least 12 UTF-8 bytes in that span (including the baseline) and at least three batches spanning 3s. The two most recent batch intervals must be at least 500 ms and within a factor of three of each other. A single batch of at least 80 bytes that contributes more than 75% of the measured bytes becomes a new baseline instead of producing a spike. Fast output takes priority again as soon as it qualifies, without inheriting the slow average.
|
|
139
|
+
- A fast estimate expires after 2s of silence. Sparse estimates expire after three times the lower median of up to five recent qualifying intervals, bounded to 6–30s. A shared in-memory timeout uses a local monotonic clock for expiry and never reads history. Short fast expiry does not discard sparse candidates; expired slow samples and tool or retry boundaries require a fresh baseline without resetting response-wide byte counts or ending the step. Without a valid estimate the display uses historical TPS or hides it if unavailable. Positive estimates below `0.1` display as `~<0.1 tok/s`.
|
|
136
140
|
- Reconnection resets live TPS windows and reconciles all tracked sessions, including offscreen sessions, with the server's active-session set. Quiet unfinished streams get a shared activity check after 60s, without reading message history. Confirmed inactive streams and their TTFT observations expire after a further 60s. Running tools, retries and pre-first-token waits have no hard lifetime; failed activity reads retain state and retry. Provider `streamed` metadata alone never means that tools have finished. Checks stop when no unfinished streams remain.
|
|
137
141
|
- Live TPS measures observable delivery, not the model's internal token-generation clock. Responses summary bursts, done-only content and transport buffering can still affect estimates; complete hidden reasoning cannot be reconstructed. Without `~`, TPS is `Σ(Output + Reasoning) ÷ Σ(time.streamed − (time.firstToken ?? time.created))` in seconds across valid assistant samples in the tree. Valid native first-token timing excludes pre-first-token waiting, matching the host's per-step denominator; older hosts/history without it retain the full request-duration fallback. This is a tree-wide weighted average, not just the current turn or recent delivery window. No model-specific multipliers, hard TPS caps or hidden-reasoning guesses are applied.
|
|
138
142
|
- `TTFT` prefers native `time.firstToken − time.created` in history and `session.step.first-token` during streaming. A buffered delta cannot overwrite native timing. Older hosts fall back to the first nonempty text/reasoning/tool-input delta, or historical reasoning/tool creation times when measurable; text-only history without a native first-token timestamp has no recoverable TTFT. Native timing survives reopening and live-observation expiry. Retries reusing a message ID replace the previous attempt's sample. TTFT remains the average across measurable steps in the whole tree, whereas OpenCode's footer uses the first measurable step in the current turn, so multi-step/subagent values need not match.
|
|
@@ -155,9 +159,9 @@ For native TTFT/TPS checks on a host with `time.firstToken`, run `npm run test:s
|
|
|
155
159
|
|
|
156
160
|
The OpenCode SDK packages are pinned to `2.3.0`, with OpenTUI `0.8.4` and Solid/compiler `1.9.16`. OpenTUI declares Node.js `>=26.4.0` for its native Node runtime, so npm reports `EBADENGINE` on Node 22; `engine-strict` installations require a Node version meeting that dependency's engine requirement. The plugin's TUI runs inside OpenCode, not as a standalone Node 22 renderer. The project's Node.js 22+ minimum is unchanged; see the [verification record](docs/verification.md) for checks of this dependency set.
|
|
157
161
|
|
|
158
|
-
The [price update workflow](.github/workflows/update-prices.yml) checks models.dev every 4 hours (or on demand via **Run workflow** on `main`). No snapshot diff means no release.
|
|
162
|
+
The [price update workflow](.github/workflows/update-prices.yml) checks models.dev every 4 hours (or on demand via **Run workflow** on `main`). No snapshot diff means no release. A change to selected prices or lookup data must pass lint, typecheck, tests, build, and pack validation before the workflow bumps the patch version (for example, `0.4.4` → `0.4.5`), commits only `src/prices.generated.ts`, `package.json`, and `package-lock.json`, and atomically pushes `main` and its version tag. The workflow creates a GitHub Release and explicitly dispatches [`publish.yml`](.github/workflows/publish.yml) on that tag to publish via npm Trusted Publishing/OIDC; no long-lived npm token is needed. GitHub Actions must be allowed to push to `main` and create tags, and npm must trust `publish.yml` with permission to run `npm publish`.
|
|
159
163
|
|
|
160
|
-
Failed validation never bumps the version. An unfinished tagged price release is retried with the same version before checking new prices; registry outages are not treated as missing versions. Publishing skips versions already on npm, prevents moving `latest` backwards, and polls registry visibility for up to 10 minutes after publication, logging progress. A verification timeout is not proof that `npm publish` failed: check the registry and retry the same tag without bumping the version; already-published versions are not republished.
|
|
164
|
+
Failed validation never bumps the version. An unfinished tagged price release is retried with the same version before checking new prices; registry outages are not treated as missing versions. Publishing skips versions already on npm, prevents moving `latest` backwards, and polls registry visibility for up to 10 minutes after publication, logging progress. A verification timeout is not proof that `npm publish` failed: check the registry and retry the same tag without bumping the version; already-published versions are not republished. Exceptional LAB-to-Provider links, exact aliases and manual price overrides require review; ordinary new models no longer need allowlist entries. See the [release guide](docs/releasing.md) for setup, verification timing, and retries.
|
|
161
165
|
|
|
162
166
|
For a manual refresh, run `npm run prices:update` in a networked environment, review the generated diff and exceptions, then run the checks above. Builds and plugin refreshes do not contact models.dev.
|
|
163
167
|
|
package/README.zh-CN.md
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
- **会话树用量汇总:** 统计整棵会话树的输入、输出、推理和缓存 token,包含未打开的子代理,避免重复计算分叉继承历史。
|
|
29
29
|
- **上下文可见:** 查看当前会话的上下文占用、最近一次已上报请求及提示词构成估算。
|
|
30
|
-
- **按模型估算费用:**
|
|
30
|
+
- **按模型估算费用:** 按每次调用实际使用的模型计价,回退到每个模型或计费 SKU 唯一的内置官方价或参考价。估算费用不等于提供商账单。
|
|
31
31
|
- **性能一目了然:** 查看每秒 token 数(TPS)、首 token 时间(TTFT)及当前会话自身的对话耗时。实时 TPS 与已耗时估算以 `~` 标记。
|
|
32
32
|
- **原生终端界面:** 主会话使用侧边栏,子代理视图保留单行摘要,按需打开完整面板。
|
|
33
33
|
- **按需查看详情:** 通过 `/token-usage` 切换紧凑/详细统计,查看各模型的用量与费率,不向模型发送提示词。
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
需要 **OpenCode 2** 和 **Node.js 22+**。已验证宿主版本及 OpenTUI 引擎限制见[兼容性](#兼容性)。
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
opencode plugin add @chenlongapps/opencode-token-usage
|
|
42
|
+
opencode plugin add @chenlongapps/opencode-token-usage@latest
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
安装后重启 OpenCode。
|
|
@@ -61,7 +61,9 @@ opencode plugin add @chenlongapps/opencode-token-usage
|
|
|
61
61
|
```json
|
|
62
62
|
{
|
|
63
63
|
"$schema": "https://opencode.ai/config.json",
|
|
64
|
-
"plugins": [
|
|
64
|
+
"plugins": [
|
|
65
|
+
"@chenlongapps/opencode-token-usage@latest"
|
|
66
|
+
]
|
|
65
67
|
}
|
|
66
68
|
```
|
|
67
69
|
|
|
@@ -114,7 +116,7 @@ OpenCode **2.3.0 现已通过完整检查**,包含插件详情与原生 `/usag
|
|
|
114
116
|
| `Steps` | 全树(含子代理)的 assistant 消息数,口径与 OpenCode 自带统计一致,compaction 与用户消息不计为 step |
|
|
115
117
|
| `Est. Cost` | 按每条 assistant 与 compaction 消息实际模型估算的全树费用 |
|
|
116
118
|
| `Run Time` | 被查看会话自身的累计原生对话耗时;运行中包含仅用于显示的当前轮已耗时估算,以 `~` 标记;不额外叠加子会话耗时 |
|
|
117
|
-
| `TPS` | 服务端已上报的全树 `Output + Reasoning`
|
|
119
|
+
| `TPS` | 服务端已上报的全树 `Output + Reasoning` 平均吞吐。流式进行中时,优先显示已交付文本、推理摘要和工具输入的有效估算(UTF-8 字节数 / 4),以 `~` 标记。优先使用快速窗口,稀疏交付时可回退到较长窗口。完成后恢复不带 `~` 的历史吞吐 |
|
|
118
120
|
| `TTFT` | 全树中可测 assistant step 的平均首 token 时间,优先使用 OpenCode 原生首 token 时间戳 |
|
|
119
121
|
|
|
120
122
|
#### 行为
|
|
@@ -129,10 +131,12 @@ OpenCode **2.3.0 现已通过完整检查**,包含插件详情与原生 `/usag
|
|
|
129
131
|
- `Run Time`/`Time` 仅显示耗时及估算/未更新标记,不附加运行状态文本或动画。已空闲父会话的耗时不会因子代理活跃而增长。关闭视图或切换会话时清理相应估算,无视图需要估算时停止共享耗时 ticker。不可用/未更新的耗时仍保留各自标记。
|
|
130
132
|
- 正常状态下确认累计值为零时,侧边栏、子代理摘要/浮窗及 `/token-usage` 紧凑/详细模式均隐藏整个 `Run Time`/`Time` 项,不留空行或空字段。当前轮实时估算非零时,首轮回答尚未完成也会显示时间。非零毫秒耗时、不可用值和未更新的耗时仍保留显示。
|
|
131
133
|
- 耗时随保留历史变化:切换 agent/模型与压缩保留过去轮次;分叉继承副本不计入分叉自身耗时。暂存回退不会删除轮次,但已提交回退删除消息后,也会移除这些消息对应的耗时;已删除的历史计时无法恢复。
|
|
132
|
-
- `Est. Cost` 按每条消息记录的实际模型分别计算。OpenCode
|
|
133
|
-
-
|
|
134
|
+
- `Est. Cost` 按每条消息记录的实际模型分别计算。OpenCode 的完整非零价格优先。已确认对应付费型号的 Free SKU,按该参考价计入总额,并在 By Model 标注 `Free usage reference`,不代表实际扣费。没有完整参考价时保留有效零价(已核实的计费例外除外)。费率整条回退,不混用,也不填补缺失类别。
|
|
135
|
+
- 离线快照用 [models.dev](https://models.dev/catalog.json) 的 LAB/标准模型身份生成。每个模型或计费 SKU 只保留一套费率:原厂非零价优先,再依次查找 OpenRouter、Vercel AI Gateway、Amazon Bedrock、LLM Gateway,其次是其他 Provider 中基础 Input + Output 最低的非零价,最后才是明确的零价。人工例外整条替换。免费参考价只通过精确 SKU 关联已有费率,不复制报价,也不靠删后缀猜价。运行时不下载价格,也不在供应商之间重新选价。
|
|
134
136
|
- 确认免费时显示 `$0.00`;正费用低于 `$0.001` 时显示 `<$0.001`,不超过 `$0.01` 的费用保留三位小数,更高费用保留两位。价格不可用时显示 `—`;只有部分消息可计算时在已知小计后标注 `partial`。快照不含网关加价、区域溢价、未列明的折扣、非文本计费、工具费和税费;Est. Cost 是估算而非账单。覆盖范围、来源和限制见[价格来源与限制](docs/pricing.md)。
|
|
135
|
-
- 实时 `TPS`
|
|
137
|
+
- 实时 `TPS` 合并 100ms 内的增量,每个响应独立采样。快速路径保留 2 秒窗口,要求响应累计至少 80 个 UTF-8 字节、窗口内至少 3 批且跨度至少 500ms,按经过时间平滑。首批计入门槛,但只作测速基线,其字节不进入速度分子。
|
|
138
|
+
- 快速估算不可用时,低速回退在不超过 30 秒的连续稀疏区间取平均。区间内至少有 12 个 UTF-8 字节(含基线)、至少 3 批且跨度至少 3 秒;最近两个批次间隔均须至少 500ms,且较长者不超过较短者的 3 倍。若单批至少有 80 字节且占测速字节超过 75%,则将其作为新基线,不显示速度尖峰。快速输出重新满足门槛即优先显示,不沿用低速平均。
|
|
139
|
+
- 快速估算静默 2 秒后过期;低速估算取最近最多 5 个有效间隔的下中位数乘以 3,限制在 6–30 秒。共享内存超时用本地单调时钟判断过期,不读取历史。快速估算过期不清空稀疏候选样本;低速窗口过期、工具执行或重试边界则重新建立基线,不清零同一响应累计字节,也不结束 step。没有有效估算时,回退历史 TPS,无历史值则隐藏。正估算值低于 `0.1` 时显示 `~<0.1 tok/s`。
|
|
136
140
|
- 重连时重置实时 TPS 窗口,并通过服务端活动会话列表对账全部已跟踪会话,包括离屏会话。未结束的流静默 60 秒后进行共享活动检查,不读取消息历史;确认会话已停止后,再保留 60 秒并回收流及其 TTFT 观察。仍在运行的工具、重试及首 token 前等待没有硬性寿命上限;活动查询失败时保留状态并重试。仅有提供商的 `streamed` 元数据不代表工具已结束。没有未结束流时停止检查。
|
|
137
141
|
- 实时 TPS 测量可观察的内容交付,而非模型内部生成 token 的时钟。Responses 摘要突发、仅在 done 中返回的内容和传输缓冲仍可能影响估算,不能还原完整隐藏推理。不带 `~` 时,TPS 为全树有效 assistant 样本的 `Σ(Output + Reasoning) ÷ Σ(time.streamed − (time.firstToken ?? time.created))`(换算为秒)。有效原生首 token 时间会排除首 token 前等待,与宿主的单步分母一致;旧宿主/历史缺少该时间时保留完整请求时长回退。它是全树加权平均,不是仅取当前轮或近期交付窗口。不做模型专属倍率、TPS 硬上限或隐藏 reasoning token 猜测。
|
|
138
142
|
- `TTFT` 在历史中优先使用原生 `time.firstToken − time.created`,流式过程中使用 `session.step.first-token`;缓冲后的 delta 不会覆盖原生时间。旧宿主回退到首个非空文本/推理/工具输入 delta,或可测的历史 reasoning/tool 创建时间;没有原生首 token 时间的纯文本历史无法恢复 TTFT。原生时间可在重新打开会话和实时观察过期后恢复。重试复用消息 ID 时替换上次尝试的样本。TTFT 仍是整棵树可测 step 的平均值,而 OpenCode 页脚取当前轮首个可测 step,多步/子代理场景不保证数值相同。
|
|
@@ -155,9 +159,9 @@ lint 使用 ESLint 10 Flat Config 及 JavaScript/TypeScript 推荐规则,不
|
|
|
155
159
|
|
|
156
160
|
OpenCode SDK 包精确锁定为 `2.3.0`,OpenTUI 为 `0.8.4`,Solid 与编译器为 `1.9.16`。OpenTUI 为其原生 Node 运行时声明 Node.js `>=26.4.0`,因此 Node 22 安装时 npm 会输出 `EBADENGINE`;启用 `engine-strict` 时须使用满足该依赖引擎要求的 Node 版本。插件的 TUI 在 OpenCode 内运行,并非独立的 Node 22 渲染器。项目 Node.js 22+ 的最低要求不变;该依赖组合的检查见[验证记录](docs/verification.md)。
|
|
157
161
|
|
|
158
|
-
[价格更新工作流](.github/workflows/update-prices.yml) 每 4 小时检查 models.dev,也可在 `main` 上通过 **Run workflow**
|
|
162
|
+
[价格更新工作流](.github/workflows/update-prices.yml) 每 4 小时检查 models.dev,也可在 `main` 上通过 **Run workflow** 手动触发。快照无变化就不发布。选定费率或查询数据发生变化时,先通过 lint、类型检查、测试、构建和打包检查,再自动升级 patch 版本(例如 `0.4.4` → `0.4.5`),只提交 `src/prices.generated.ts`、`package.json` 和 `package-lock.json`,并原子推送 `main` 与版本标签。工作流创建 GitHub Release,显式触发该标签上的 [`publish.yml`](.github/workflows/publish.yml),通过 npm Trusted Publishing/OIDC 发布,无需长期 npm token。仓库必须允许 GitHub Actions 推送 `main` 和创建标签;npm 必须信任 `publish.yml` 并允许执行 `npm publish`。
|
|
159
163
|
|
|
160
|
-
验证失败不会升版本。已打标签但未完成的自动价格发布会优先重试同一版本,再检查新价格;registry 故障不会被当作版本不存在。发布时跳过 npm 已有版本、防止 `latest` 倒退,并在发布后最多轮询 10 分钟核验 registry 可见性,输出进度。校验超时不代表 `npm publish` 失败:先检查 registry
|
|
164
|
+
验证失败不会升版本。已打标签但未完成的自动价格发布会优先重试同一版本,再检查新价格;registry 故障不会被当作版本不存在。发布时跳过 npm 已有版本、防止 `latest` 倒退,并在发布后最多轮询 10 分钟核验 registry 可见性,输出进度。校验超时不代表 `npm publish` 失败:先检查 registry,再重试原标签,不另升版本;已发布版本不会重复发布。特殊的 LAB 与 Provider 关联、精确别名、人工价格例外仍需审核,普通新模型无需更新白名单。配置、校验时限和重试方法见[发布说明](docs/releasing.md)。
|
|
161
165
|
|
|
162
166
|
手动更新时,在联网的维护环境运行 `npm run prices:update`,审阅生成文件及例外差异,再执行上述检查。构建和插件刷新不会请求 models.dev。
|
|
163
167
|
|
package/dist/aliases.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/** Reviewed ownership when the API's Provider ID differs from its LAB ID.
|
|
2
|
+
* These do not grant ownership of any other LAB's models hosted there. */
|
|
3
|
+
export declare const PROVIDER_LABS: ReadonlyMap<string, string>;
|
|
4
|
+
/** Exact namespacing aliases for caller-supplied model IDs, not ownership. */
|
|
5
|
+
export declare const LAB_ALIASES: ReadonlyMap<string, string>;
|
|
6
|
+
/** Reviewed compatibility spellings, only when no real SKU takes precedence.
|
|
7
|
+
* Dated/versioned SKUs with separate upstream identities are not aliases. */
|
|
6
8
|
export declare const MODEL_ALIASES: Readonly<Record<string, string>>;
|
package/dist/aliases.js
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
/** Reviewed ownership when the API's Provider ID differs from its LAB ID.
|
|
2
|
+
* These do not grant ownership of any other LAB's models hosted there. */
|
|
3
|
+
export const PROVIDER_LABS = new Map([
|
|
4
|
+
["alibaba-cn", "alibaba"],
|
|
5
|
+
["amazon-bedrock", "amazon"], // AWS develops Nova and serves it through Bedrock.
|
|
6
|
+
["arcee", "arcee-ai"],
|
|
7
|
+
["byteplus", "bytedance-seed"], // International ModelArk.
|
|
8
|
+
["google-vertex", "google"], // Vertex also relays unrelated LABs.
|
|
9
|
+
["longcat", "meituan"],
|
|
10
|
+
["minimax-cn", "minimax"],
|
|
11
|
+
["moonshotai-cn", "moonshotai"],
|
|
12
|
+
["stepfun-ai", "stepfun"],
|
|
13
|
+
["tencent-tokenhub", "tencent"],
|
|
14
|
+
["volcengine", "bytedance-seed"],
|
|
15
|
+
["zai", "zhipuai"],
|
|
16
|
+
]);
|
|
17
|
+
/** Exact namespacing aliases for caller-supplied model IDs, not ownership. */
|
|
18
|
+
export const LAB_ALIASES = new Map([
|
|
19
|
+
...PROVIDER_LABS,
|
|
20
|
+
["mistralai", "mistral"],
|
|
21
|
+
["qwen", "alibaba"],
|
|
22
|
+
["x-ai", "xai"],
|
|
23
|
+
["z-ai", "zhipuai"],
|
|
24
|
+
]);
|
|
25
|
+
/** Reviewed compatibility spellings, only when no real SKU takes precedence.
|
|
26
|
+
* Dated/versioned SKUs with separate upstream identities are not aliases. */
|
|
16
27
|
export const MODEL_ALIASES = {
|
|
17
28
|
"alibaba/qwen3.5-plus-20260420": "alibaba/qwen3.5-plus-2026-04-20",
|
|
18
29
|
"alibaba/qwen3.8-max-0902": "alibaba/qwen3.8-max",
|
|
19
|
-
"
|
|
20
|
-
"deepseek/deepseek-v4-flash": "deepseek/deepseek-v4.1-flash",
|
|
21
|
-
"deepseek/deepseek-v4-flash-0731": "deepseek/deepseek-v4.1-flash",
|
|
22
|
-
"deepseek/deepseek-v4-flash-vision-exp": "deepseek/deepseek-v4.1-flash",
|
|
23
|
-
"deepseek/deepseek-v4-pro": "deepseek/deepseek-v4-pro-0813",
|
|
30
|
+
"anthropic/claude-opus-4.7": "anthropic/claude-opus-4-7",
|
|
24
31
|
"mistral/mistral-medium-3-5": "mistral/mistral-medium-2604",
|
|
25
32
|
"mistral/mistral-medium-3-5-26-04": "mistral/mistral-medium-2604",
|
|
26
33
|
"openai/gpt-chat-latest": "openai/chat-latest",
|
|
27
|
-
"sakana/fugu-max": "sakana/fugu-max
|
|
28
|
-
"sakana/fugu-ultra-v2": "sakana/fugu-ultra-v2
|
|
34
|
+
"sakana/fugu-max-v1.0": "sakana/fugu-max",
|
|
35
|
+
"sakana/fugu-ultra-v2.0": "sakana/fugu-ultra-v2",
|
|
29
36
|
"upstage/solar-pro4-260806": "upstage/solar-pro4",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
37
|
+
"bytedance-seed/seed-2-1-turbo": "bytedance-seed/seed-2.1-turbo",
|
|
38
|
+
"bytedance-seed/dola-seed-2-1-turbo": "bytedance-seed/seed-2.1-turbo",
|
|
39
|
+
"bytedance-seed/dola-seed-2-1-turbo-260628": "bytedance-seed/seed-2.1-turbo",
|
|
32
40
|
};
|
package/dist/overrides.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { Price } from "./usage.js";
|
|
2
|
-
/** models.dev has no manufacturer-of-model field. Only these first-party
|
|
3
|
-
* catalogs and model families can supply fallback prices. A manufacturer
|
|
4
|
-
* listing somebody else's model (e.g. Alibaba's Kimi) is not its origin. */
|
|
5
|
-
export declare const ORIGINAL_PROVIDERS: Readonly<Record<string, RegExp>>;
|
|
6
2
|
export interface PriceOverride {
|
|
3
|
+
/** Provider selling this tariff; id is its exact SKU or the lab model ID. */
|
|
7
4
|
providerID: string;
|
|
8
5
|
id: string;
|
|
6
|
+
canonicalID?: string;
|
|
9
7
|
prices: readonly Price[];
|
|
10
8
|
source: string;
|
|
11
9
|
reason: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
/** Only bind this tariff to exact provider SKUs, not generic aliases. */
|
|
11
|
+
scoped?: true;
|
|
12
|
+
/** Exact OpenCode provider/SKU whose zero is a verified non-tariff. */
|
|
13
|
+
zeroException?: string;
|
|
15
14
|
}
|
|
16
15
|
/** Rates absent from the first-party models.dev listing or contradicted by a
|
|
17
16
|
* specifically verified manufacturer tariff. Never use a reseller's quote. */
|
|
@@ -19,4 +18,4 @@ export declare const OVERRIDES_VERIFIED = "2026-09-23";
|
|
|
19
18
|
export declare const PRICE_OVERRIDES: readonly PriceOverride[];
|
|
20
19
|
/** A catalog zero may mean an unmetered subscription, or that cache storage is
|
|
21
20
|
* billed by time rather than per write token. Do not invent a free write rate. */
|
|
22
|
-
export declare function
|
|
21
|
+
export declare function adjustCatalogPrice(providerID: string, price: Price): Price;
|
package/dist/overrides.js
CHANGED
|
@@ -1,40 +1,9 @@
|
|
|
1
|
-
/** models.dev has no manufacturer-of-model field. Only these first-party
|
|
2
|
-
* catalogs and model families can supply fallback prices. A manufacturer
|
|
3
|
-
* listing somebody else's model (e.g. Alibaba's Kimi) is not its origin. */
|
|
4
|
-
export const ORIGINAL_PROVIDERS = {
|
|
5
|
-
ai21: /^jamba-/i,
|
|
6
|
-
alibaba: /^(?:qwen|qwq|qvq)/i,
|
|
7
|
-
anthropic: /^claude-/i,
|
|
8
|
-
arcee: /^trinity-/i,
|
|
9
|
-
cohere: /^(?:command-|north-)/i,
|
|
10
|
-
deepseek: /^deepseek-/i,
|
|
11
|
-
google: /^(?:gemini-|gemma-|deep-research-)/i,
|
|
12
|
-
inception: /^mercury-/i,
|
|
13
|
-
longcat: /^longcat-/i,
|
|
14
|
-
meta: /^muse-/i,
|
|
15
|
-
minimax: /^minimax-/i,
|
|
16
|
-
mistral: /^(?:open-mistral-|open-mixtral-|mistral-|ministral-|magistral-|codestral-|devstral-|labs-devstral-|pixtral-|voxtral-)/i,
|
|
17
|
-
moonshotai: /^kimi-/i,
|
|
18
|
-
nvidia: /^nvidia\/(?:nemotron-|llama-[\w.-]*nemotron-)/i,
|
|
19
|
-
openai: /^(?:gpt-|o\d|chat-latest$)/i,
|
|
20
|
-
perplexity: /^sonar(?:-|$)/i,
|
|
21
|
-
sakana: /^(?:fugu|sakana-namazu)/i,
|
|
22
|
-
"stepfun-ai": /^step-/i,
|
|
23
|
-
// TokenHub's hy3 zero is a subscription-plan quote, not a token tariff;
|
|
24
|
-
// hy3 pay-as-you-go is a reviewed exception below.
|
|
25
|
-
"tencent-tokenhub": /^hy4-preview$/i,
|
|
26
|
-
upstage: /^solar-/i,
|
|
27
|
-
volcengine: /^doubao-seed-/i,
|
|
28
|
-
xai: /^grok-/i,
|
|
29
|
-
xiaomi: /^mimo-/i,
|
|
30
|
-
zai: /^glm-/i,
|
|
31
|
-
};
|
|
32
1
|
/** Rates absent from the first-party models.dev listing or contradicted by a
|
|
33
2
|
* specifically verified manufacturer tariff. Never use a reseller's quote. */
|
|
34
3
|
export const OVERRIDES_VERIFIED = "2026-09-23";
|
|
35
4
|
export const PRICE_OVERRIDES = [
|
|
36
5
|
{
|
|
37
|
-
providerID: "openai", id: "chat-latest",
|
|
6
|
+
providerID: "openai", id: "chat-latest",
|
|
38
7
|
source: "https://developers.openai.com/api/docs/pricing", reason: "Official ChatGPT API SKU missing from the first-party catalog",
|
|
39
8
|
prices: [{ input: 5, output: 30, cache: { read: 0.5 } }],
|
|
40
9
|
},
|
|
@@ -49,7 +18,9 @@ export const PRICE_OVERRIDES = [
|
|
|
49
18
|
["gpt-6-sol", 4, 20, 0.4, 5, 8, 30, 0.8, 10],
|
|
50
19
|
["gpt-6-luna", 0.2, 1, 0.02, 0.25, 0.4, 1.5, 0.04, 0.5],
|
|
51
20
|
].map(([id, input, output, read, write, longInput, longOutput, longRead, longWrite]) => ({
|
|
52
|
-
providerID: "openai", id: `${id}-fast`,
|
|
21
|
+
providerID: "openai", id: `${id}-fast`,
|
|
22
|
+
canonicalID: id === "gpt-6-astra" ? `openai/${id}-fast` : `openai/${id}:fast`,
|
|
23
|
+
...(id === "gpt-6-astra" ? {} : { scoped: true }),
|
|
53
24
|
source: "https://developers.openai.com/api/docs/pricing",
|
|
54
25
|
reason: "Published first-party Fast rate and long-context boundary (not in mode.cost)",
|
|
55
26
|
prices: [
|
|
@@ -59,13 +30,13 @@ export const PRICE_OVERRIDES = [
|
|
|
59
30
|
],
|
|
60
31
|
})),
|
|
61
32
|
{
|
|
62
|
-
providerID: "deepseek", id: "deepseek-v4.1-flash",
|
|
33
|
+
providerID: "deepseek", id: "deepseek-v4.1-flash",
|
|
63
34
|
source: "https://api-docs.deepseek.com/quick_start/pricing",
|
|
64
35
|
reason: "Peak synchronous price; the hourly billing tier is not recorded in historical messages",
|
|
65
36
|
prices: [{ input: 0.3, output: 1.2, cache: { read: 0.006 } }],
|
|
66
37
|
},
|
|
67
38
|
{
|
|
68
|
-
providerID: "deepseek", id: "deepseek-v4-pro-0813",
|
|
39
|
+
providerID: "deepseek", id: "deepseek-v4-pro-0813",
|
|
69
40
|
source: "https://api-docs.deepseek.com/quick_start/pricing",
|
|
70
41
|
reason: "Peak synchronous price; the hourly billing tier is not recorded in historical messages",
|
|
71
42
|
prices: [{ input: 1.32, output: 3.96, cache: { read: 0.044 } }],
|
|
@@ -83,7 +54,7 @@ export const PRICE_OVERRIDES = [
|
|
|
83
54
|
prices: [{ input: 1, output: 2.7, cache: { read: 0.05, write: 1 } }],
|
|
84
55
|
},
|
|
85
56
|
{
|
|
86
|
-
providerID: "tencent-tokenhub", id: "hy3",
|
|
57
|
+
providerID: "tencent-tokenhub", id: "hy3", zeroException: "tencent-tokenhub/hy3",
|
|
87
58
|
source: "https://intl.cloud.tencent.com/document/product/1300/78937",
|
|
88
59
|
reason: "Published pay-as-you-go tariff, rather than the catalog's subscription-plan zero",
|
|
89
60
|
prices: [{ input: 0.132, output: 0.528, cache: { read: 0.033 } }],
|
|
@@ -101,9 +72,9 @@ export const PRICE_OVERRIDES = [
|
|
|
101
72
|
prices: [{ input: 1.5, output: 7.5, cache: { read: 0.15 } }],
|
|
102
73
|
},
|
|
103
74
|
{
|
|
104
|
-
providerID: "alibaba", id: "qwen3.7-flash",
|
|
75
|
+
providerID: "alibaba", id: "qwen3.7-flash",
|
|
105
76
|
source: "https://www.alibabacloud.com/help/en/model-studio/model-pricing",
|
|
106
|
-
reason: "
|
|
77
|
+
reason: "Published international pay-as-you-go schedule; aggregate cache writes cannot select implicit versus explicit pricing",
|
|
107
78
|
prices: [
|
|
108
79
|
{ input: 0.03, output: 0.13, cache: { read: 0.006 } },
|
|
109
80
|
{ tier: { type: "context", size: 32_000 }, input: 0.1, output: 0.4, cache: { read: 0.02 } },
|
|
@@ -111,19 +82,19 @@ export const PRICE_OVERRIDES = [
|
|
|
111
82
|
],
|
|
112
83
|
},
|
|
113
84
|
{
|
|
114
|
-
providerID: "alibaba", id: "qwen3.8-2.4t-a95b",
|
|
85
|
+
providerID: "alibaba", id: "qwen3.8-2.4t-a95b",
|
|
115
86
|
source: "https://www.alibabacloud.com/help/en/model-studio/model-pricing",
|
|
116
87
|
reason: "Manufacturer's international tariff; this SKU is absent from the international catalog",
|
|
117
88
|
prices: [{ input: 2, output: 6 }],
|
|
118
89
|
},
|
|
119
90
|
{
|
|
120
|
-
providerID: "alibaba", id: "qwen3.8-27b",
|
|
91
|
+
providerID: "alibaba", id: "qwen3.8-27b",
|
|
121
92
|
source: "https://www.alibabacloud.com/help/en/model-studio/model-pricing",
|
|
122
93
|
reason: "Manufacturer's international tariff; this SKU is absent from the international catalog",
|
|
123
94
|
prices: [{ input: 0.5, output: 3, cache: { read: 0.1 } }],
|
|
124
95
|
},
|
|
125
96
|
{
|
|
126
|
-
providerID: "alibaba", id: "qwen3.5-plus-2026-04-20",
|
|
97
|
+
providerID: "alibaba", id: "qwen3.5-plus-2026-04-20",
|
|
127
98
|
source: "https://www.alibabacloud.com/help/en/model-studio/model-pricing",
|
|
128
99
|
reason: "Manufacturer's international tariff; this SKU is absent from the international catalog",
|
|
129
100
|
prices: [
|
|
@@ -132,13 +103,13 @@ export const PRICE_OVERRIDES = [
|
|
|
132
103
|
],
|
|
133
104
|
},
|
|
134
105
|
{
|
|
135
|
-
providerID: "
|
|
106
|
+
providerID: "byteplus", id: "dola-seed-2-1-turbo", canonicalID: "bytedance-seed/seed-2.1-turbo",
|
|
136
107
|
source: "https://docs.byteplus.com/en/docs/ModelArk/1099320",
|
|
137
108
|
reason: "BytePlus manufacturer SKU uses a different ID from the regional Volcengine catalog",
|
|
138
109
|
prices: [{ input: 0.5, output: 2.5, cache: { read: 0.1 } }],
|
|
139
110
|
},
|
|
140
111
|
{
|
|
141
|
-
providerID: "sakana", id: "fugu-ultra-v2.0",
|
|
112
|
+
providerID: "sakana", id: "fugu-ultra-v2.0", canonicalID: "sakana/fugu-ultra-v2",
|
|
142
113
|
source: "https://console.sakana.ai/pricing",
|
|
143
114
|
reason: "Manufacturer versioned SKU not present under this ID; higher tier starts at 272K",
|
|
144
115
|
prices: [
|
|
@@ -147,16 +118,16 @@ export const PRICE_OVERRIDES = [
|
|
|
147
118
|
],
|
|
148
119
|
},
|
|
149
120
|
{
|
|
150
|
-
providerID: "sakana", id: "fugu-max-v1.0",
|
|
121
|
+
providerID: "sakana", id: "fugu-max-v1.0", canonicalID: "sakana/fugu-max",
|
|
151
122
|
source: "https://console.sakana.ai/pricing",
|
|
152
123
|
reason: "Manufacturer versioned SKU absent from models.dev",
|
|
153
124
|
prices: [{ input: 2, output: 6, cache: { read: 0.25 } }],
|
|
154
125
|
},
|
|
155
126
|
...[
|
|
156
|
-
["aion-3.0",
|
|
157
|
-
["aion-3.0-mini",
|
|
158
|
-
].map(([id,
|
|
159
|
-
providerID: "aion-labs", id,
|
|
127
|
+
["aion-3.0", 3, 6, 0.75],
|
|
128
|
+
["aion-3.0-mini", 0.7, 1.4, 0.18],
|
|
129
|
+
].map(([id, input, output, read]) => ({
|
|
130
|
+
providerID: "aion-labs", id,
|
|
160
131
|
source: "https://www.aionlabs.ai/docs/models",
|
|
161
132
|
reason: "First-party hosted API price; models.dev has no Aion manufacturer provider",
|
|
162
133
|
prices: [{ input, output, cache: { read } }],
|
|
@@ -164,7 +135,7 @@ export const PRICE_OVERRIDES = [
|
|
|
164
135
|
];
|
|
165
136
|
/** A catalog zero may mean an unmetered subscription, or that cache storage is
|
|
166
137
|
* billed by time rather than per write token. Do not invent a free write rate. */
|
|
167
|
-
export function
|
|
138
|
+
export function adjustCatalogPrice(providerID, price) {
|
|
168
139
|
const ambiguousWrite = (providerID === "zai" && price.cache?.write === 0)
|
|
169
140
|
|| (providerID === "alibaba" && price.cache?.write !== undefined);
|
|
170
141
|
if (ambiguousWrite && price.cache) {
|
package/dist/performance.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface PerformanceOptions {
|
|
|
37
37
|
active?: ReadActiveSessions | undefined;
|
|
38
38
|
}
|
|
39
39
|
/** Requires three merged batches; the first is a baseline, not newly generated bytes. */
|
|
40
|
-
export declare function estimatedLiveTps(samples: readonly StreamSample[]): number | undefined;
|
|
40
|
+
export declare function estimatedLiveTps(samples: readonly StreamSample[], start?: number): number | undefined;
|
|
41
41
|
/** Time-based EWMA: elapsed time determines the weight, never delta count. */
|
|
42
42
|
export declare function smoothLiveTps(previous: number | undefined, raw: number, elapsed?: number): number;
|
|
43
43
|
export interface PreparedPerformance {
|
|
@@ -75,6 +75,8 @@ export declare class PerformanceMonitor {
|
|
|
75
75
|
private publish;
|
|
76
76
|
private deleteSession;
|
|
77
77
|
private resetLive;
|
|
78
|
+
private breakDelivery;
|
|
79
|
+
private recordDelta;
|
|
78
80
|
private touch;
|
|
79
81
|
private finish;
|
|
80
82
|
/** One shared, history-free read covers offscreen sessions too. Failures are not idle. */
|