@chenlongapps/opencode-token-usage 0.3.2 → 0.3.3

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 CHANGED
@@ -60,8 +60,8 @@ For remote sessions, add the package name to `plugins` in your local `~/.config/
60
60
  - A fork is a separate session tree. Inherited message copies are attributed only to their original source to prevent double counting.
61
61
  - `Context` only searches messages after the most recent compaction with `status === "completed"` and is hidden when reliable usage or a model context limit is unavailable.
62
62
  - `Steps` counts every assistant message in the tree, whether or not it reported usage, and reuses the fork-copy de-duplication so inherited history is never counted twice.
63
- - `Cost` prices every message with its recorded model. A complete applicable price resolved by OpenCode takes precedence; when OpenCode has no usable price, the plugin falls back to a packaged snapshot of manufacturer prices.
64
- - Gateway models can use manufacturer fallback prices through exact model IDs and documented aliases. The fallback does not include gateway markups, regional premiums, discounts, tool fees, or taxes, so Cost is an estimate rather than a provider bill.
63
+ - `Cost` prices every message with its recorded model. A complete non-zero price resolved by OpenCode takes precedence. If OpenCode reports a complete zero price, a complete official snapshot price overrides it; incomplete prices fall back for the whole message without mixing rates.
64
+ - Gateway models can use fallback prices through exact model IDs, documented aliases, and known wrappers. A terminal `-free` or `:free` is removed only for an exact base ID lookup; other suffixes are not stripped. The fallback excludes gateway markups, regional premiums, unlisted discounts, tool fees, and taxes, so Cost is an estimate rather than a provider bill.
65
65
  - Confirmed free usage displays `$0.00`; unavailable prices display `—`; known subtotals with unpriced messages are marked `partial`. See the [built-in price snapshot](docs/pricing.md) for coverage, sources, and limitations.
66
66
  - Initial read failures display `Unavailable`. Later failures retain the last complete snapshot, display `Not updated`, and retry automatically.
67
67
 
package/README.zh-CN.md CHANGED
@@ -60,8 +60,8 @@ opencode plugin add @chenlongapps/opencode-token-usage
60
60
  - 分叉会话是独立会话树。继承消息副本只归原始来源,避免重复计费。
61
61
  - `Context` 仅搜索最后一次 `status === "completed"` 的 compaction 之后;没有可靠用量或模型上限时隐藏。
62
62
  - `Steps` 统计树中全部 assistant 消息,无论是否已上报用量;复用分叉副本去重,继承历史不会重复计数。
63
- - `Cost` 按每条消息记录的实际模型分别计算。OpenCode 当前解析出的完整适用价格优先;OpenCode 没有可用价格时,回退到插件内置的厂商官方价格快照。
64
- - 网关模型可通过精确模型 ID 和已记录别名使用厂商价格,但不包含网关加价、区域溢价、折扣、工具费和税费,因此 Cost 是估算而非提供商账单。
63
+ - `Cost` 按每条消息记录的实际模型分别计算。OpenCode 当前解析出的完整非零价格优先;若 OpenCode 给出完整零价,且内置价格快照可以完整计价,则采用快照价格。价格不完整时整条消息回退,不混用两套费率。
64
+ - 网关模型通过精确模型 ID、明确别名和已知包装格式匹配;也会尝试移除终尾 `-free` 或 `:free` 后精确查找基础 ID,其他后缀不会剥离。快照不包含网关加价、区域溢价、未列明的折扣、工具费和税费,因此 Cost 是估算而非提供商账单。
65
65
  - 确认免费时显示 `$0.00`;价格不可用时显示 `—`;只有部分消息可计算时在已知小计后标注 `partial`。覆盖范围、来源和限制见[内置官方价格快照](docs/pricing.md)。
66
66
  - 首次读取失败显示 `Unavailable`;后续失败保留上次完整快照、标注 `Not updated` 并自动重试。
67
67
 
package/dist/pricing.js CHANGED
@@ -175,9 +175,7 @@ export const OFFICIAL_PRICE_SNAPSHOT = {
175
175
  source: "https://cohere.com/pricing",
176
176
  prices: [{ input: 2.5, output: 10 }],
177
177
  },
178
- // Meta Model API standard-tier rates. The contributor tier is a separate
179
- // discounted program that permits training on prompts and completions, so
180
- // it is intentionally not part of the standard snapshot.
178
+ // Meta Model API standard-tier rates.
181
179
  {
182
180
  id: "muse-spark-1.1", released: "2026-07-09", source: "https://ai.developer.meta.com/docs/pricing-rate-limits",
183
181
  prices: [{ input: 1.25, output: 4.25, cache: { read: 0.15 } }],
@@ -190,6 +188,17 @@ export const OFFICIAL_PRICE_SNAPSHOT = {
190
188
  id: "muse-spark-1.3", released: "2026-09-02", source: "https://ai.developer.meta.com/docs/pricing-rate-limits",
191
189
  prices: [{ input: 1.25, output: 4.25, cache: { read: 0.15 } }],
192
190
  },
191
+ // Meta Contributor rates are conditional on allowing Meta to use prompts
192
+ // and completions for training. OpenCode's contributor-free model IDs
193
+ // resolve here after removing their terminal -free suffix.
194
+ {
195
+ id: "muse-spark-1.2-contributor", released: "2026-08-05", source: "https://ai.developer.meta.com/docs/pricing-rate-limits",
196
+ prices: [{ input: 0.1, output: 0.2, cache: { read: 0.002 } }],
197
+ },
198
+ {
199
+ id: "muse-spark-1.3-contributor", released: "2026-09-02", source: "https://ai.developer.meta.com/docs/pricing-rate-limits",
200
+ prices: [{ input: 0.1, output: 0.2, cache: { read: 0.002 } }],
201
+ },
193
202
  // Inception's current Mercury 2.5 API page shows an 80% launch discount;
194
203
  // the snapshot records the billed standard-platform rates on verification
195
204
  // day rather than the crossed-out list prices. No cache-write token rate is
@@ -498,5 +507,14 @@ export function officialPrice(model) {
498
507
  if (entry)
499
508
  return entry;
500
509
  }
510
+ for (const candidate of candidates) {
511
+ for (const suffix of ["-free", ":free"]) {
512
+ if (!candidate.endsWith(suffix))
513
+ continue;
514
+ const entry = index.get(candidate.slice(0, -suffix.length));
515
+ if (entry)
516
+ return entry;
517
+ }
518
+ }
501
519
  return undefined;
502
520
  }
package/dist/usage.d.ts CHANGED
@@ -83,8 +83,9 @@ export declare function estimate(tokens: Tokens, prices?: readonly Price[]): {
83
83
  defaultPrice: boolean;
84
84
  };
85
85
  export type CostStatus = "empty" | "complete" | "partial" | "unavailable";
86
- /** Prices every call with its recorded model. OpenCode's resolved price wins;
87
- * the built-in manufacturer snapshot is used only when that price is incomplete. */
86
+ /** Prices every call with its recorded model. A complete non-zero OpenCode
87
+ * price wins; a complete snapshot price can replace a complete OpenCode zero.
88
+ * Incomplete OpenCode prices fall back to the snapshot as a whole. */
88
89
  export declare function summarize(messages: Iterable<UsageMessage>, catalog?: PriceCatalog): {
89
90
  tokens: Tokens;
90
91
  total: number;
package/dist/usage.js CHANGED
@@ -22,8 +22,9 @@ export function estimate(tokens, prices = []) {
22
22
  && (rate === undefined || !Number.isFinite(rate) || rate < 0))),
23
23
  };
24
24
  }
25
- /** Prices every call with its recorded model. OpenCode's resolved price wins;
26
- * the built-in manufacturer snapshot is used only when that price is incomplete. */
25
+ /** Prices every call with its recorded model. A complete non-zero OpenCode
26
+ * price wins; a complete snapshot price can replace a complete OpenCode zero.
27
+ * Incomplete OpenCode prices fall back to the snapshot as a whole. */
27
28
  export function summarize(messages, catalog = new Map()) {
28
29
  const tokens = normalize();
29
30
  let cost = 0;
@@ -50,8 +51,11 @@ export function summarize(messages, catalog = new Map()) {
50
51
  continue;
51
52
  }
52
53
  let value = estimate(t, catalog.get(modelKey(message.model)));
53
- if (value.defaultPrice)
54
- value = estimate(t, officialPrice(message.model)?.prices);
54
+ if (value.defaultPrice || value.cost === 0) {
55
+ const snapshot = estimate(t, officialPrice(message.model)?.prices);
56
+ if (!snapshot.defaultPrice)
57
+ value = snapshot;
58
+ }
55
59
  if (value.defaultPrice)
56
60
  missingCosts++;
57
61
  else {
package/docs/pricing.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # 内置官方价格快照
2
2
 
3
- 插件自 v0.3.0 起,在 OpenCode 当前模型目录没有可用于某条消息的完整价格时,使用本页所列的厂商官方标准价补全。v0.3.2 快照核验于 **2026-09-23**,共收录 74 个模型,金额均为美元 / 100 万 token。
3
+ 插件自 v0.3.0 起,在 OpenCode 当前模型目录没有可用于某条消息的完整价格时,使用本页所列的公开 API 价格补全。若 OpenCode 给出完整零价,而快照能完整计价,则使用快照价格。快照核验于 **2026-09-23**,共收录 79 个模型,金额均为美元 / 100 万 token。
4
4
 
5
5
  ## 规则
6
6
 
7
7
  - 每条 assistant 与 compaction 消息按自身记录的 `providerID`、模型 ID 和 token 用量分别计算。
8
- - OpenCode 当前解析出的完整适用价格优先;仅当适用档位或本次实际使用的 token 类别缺价时,整条消息回退到内置价格,不混用两套费率。
9
- - 网关模型只通过精确厂商 ID、精确别名及已知包装格式匹配,例如 `openai/gpt-5.6-luna`、`us.anthropic.claude-opus-5` 和 `claude-opus-5@default`。不按相似名称猜测。
10
- - 目录首版只新增 2026-03-22 至 2026-09-22 发布、具有明确标准 token 价格的模型。后续版本只限制新增窗口,已经收录的模型不会因超过半年而自动删除。
11
- - 采用标准同步 API 的公开价,不含 Batch、Flex、Fast/Priority、区域溢价、网关加价、免费额度、企业折扣、工具费和税费,因此 Cost 仍是估算,不代表账单。
8
+ - OpenCode 当前解析出的完整适用非零价格优先。若完整适用价格为零,则尝试使用内置价格;只有快照能完整覆盖该消息实际使用的 token 类别时才覆盖零价,否则保留 OpenCode 的零价。OpenCode 价格不完整时,整条消息回退到内置价格,不混用两套费率。
9
+ - 网关模型只通过精确厂商 ID、精确别名及已知包装格式匹配,例如 `openai/gpt-5.6-luna`、`us.anthropic.claude-opus-5` 和 `claude-opus-5@default`。匹配这些现有形式后,也会尝试仅移除模型 ID 的末尾 `-free` 或 `:free` 再精确匹配基础 ID,例如 `mimo-v2.6-flash-free`、`meta/muse-spark-1.3:free` 和 `muse-spark-1.3-contributor-free`;`-pro`、`-fast`、`-free-preview` 等其他后缀不会剥离。不按相似名称猜测。
10
+ - 目录首版只新增 2026-03-22 至 2026-09-22 发布、具有明确 token 费率的模型。后续版本只限制新增窗口,已经收录的条目不会因超过半年而自动删除。
11
+ - 采用标准同步 API 的公开价;Meta Contributor 条件价按单独标注的来源记录。不含 Batch、Flex、Fast/Priority、区域溢价、网关加价、企业折扣、工具费和税费,因此 Cost 仍是估算,不代表账单。
12
12
  - 任一有用量消息仍无法定价时,已知小计标记 `partial`;全部无法定价时显示 `—`。明确零价才显示 `$0.00`。
13
13
  - 促销价按核验日官网显示的费率收录(如 `gpt-5.6-sol`、MiniMax-M3 的"长期 5 折"标价),不用划线原价。
14
14
 
@@ -199,7 +199,14 @@ Step 5 Preview 官方明确说明 cache-miss Input 包含首次缓存写入,
199
199
  | `muse-spark-1.2` | 2026-08-05 | 1.25 | 4.25 | 0.15 |
200
200
  | `muse-spark-1.3` | 2026-09-02 | 1.25 | 4.25 | 0.15 |
201
201
 
202
- 这里只收录 Standard tier。Contributor tier 虽然也是官方 API,但以允许 Meta 使用提示词和回答训练为条件的折扣方案,不属于标准价;官方没有 cache write token 价。
202
+ Contributor tier 以允许 Meta 使用提示词和回答进行训练为条件,按独立 tier 记录。官方没有公布 cache write token 价。
203
+
204
+ | Contributor 模型 | 发布日期 | Input | Output | Cache Read | Cache Write |
205
+ | --- | --- | ---: | ---: | ---: | ---: |
206
+ | `muse-spark-1.2-contributor` | 2026-08-05 | 0.10 | 0.20 | 0.002 | — |
207
+ | `muse-spark-1.3-contributor` | 2026-09-02 | 0.10 | 0.20 | 0.002 | — |
208
+
209
+ OpenCode Zen 的 `muse-spark-1.2-contributor-free` 和 `muse-spark-1.3-contributor-free` 会精确匹配各自 Contributor 条目;Cost 因此按 Meta Contributor 费率估算。
203
210
 
204
211
  ## Inception
205
212
 
@@ -278,7 +285,7 @@ Fugu Ultra 的编排 token 已包含在 API 返回的 input/output 用量中,
278
285
  - Realtime、音频、图片、视频、embedding、按页、按分钟和按工具调用收费的模型无法仅由当前五类 token 用量准确计算。
279
286
  - `grok-4.20`、`grok-4.20-multi-agent` 发布于 2026-03-09,早于目录收录窗口起点 2026-03-22。
280
287
  - Fast/Priority 等加速档(`claude-opus-*-fast`、`gpt-5.6-*-pro`、`gpt-6-astra-pro`、MiniMax priority 档)不是标准同步价。
281
- - 免费模型(Gemma 系列、`cohere/north-mini-code` 等开源或网关零价款)不设价格条目。
282
- - 无法从厂商官方页面确认标准 token 价格的模型不猜价,包括 OpenRouter stealth/alpha 匿名模型、`z-ai/glm-5v-turbo`、`qwen3.6-plus-preview`、腾讯 `hy3-preview` 与 `hy-mt2-*`、`kwaipilot/kat-coder-pro-v2.5` 及其 Air 版本、`inclusionai/ling-3.0-*`、`bytedance-seed/seed-2.0-code` 等。这些模型目前只能查到 OpenRouter、AtlasCloud、DeepInfra 等网关或第三方报价,不能据此推断厂商标准价。
288
+ - 其他免费模型(Gemma 系列、`cohere/north-mini-code` 等开源或网关零价款)不设价格条目。
289
+ - 无法从厂商官方页面确认标准 token 价格的模型不猜价,包括 OpenRouter stealth/alpha 匿名模型、`z-ai/glm-5v-turbo`、`qwen3.6-plus-preview`、腾讯 `hy3-preview` 与 `hy-mt2-*`、`kwaipilot/kat-coder-pro-v2.5` 及其 Air 版本、除上表 OpenCode Zen SKU 外的 `inclusionai/ling-3.0-*`、`bytedance-seed/seed-2.0-code` 等。这些模型目前只能查到 OpenRouter、AtlasCloud、DeepInfra 等网关或第三方报价,不能据此推断厂商标准价。
283
290
  - 浮动别名(`-latest` 指针与 OpenRouter `~` 前缀条目)随底层模型漂移,不收录固定价。
284
291
  - 只有询价、托管部署价或无法从厂商官方页面确认标准 token 价格的模型不猜价。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenlongapps/opencode-token-usage",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Session-tree token usage, live performance, context window and estimated cost for OpenCode 2",
5
5
  "keywords": [
6
6
  "opencode",