cloudaxe-opencode/packages
Kit Langton b9451175a6 refactor(llm): make LLM.Usage a fully-additive contract
Defines a single invariant for `LLM.Usage`: every field is non-negative
and every meaningful aggregate is a *sum*, never a difference. Total
billable input = inputTokens + cacheReadInputTokens + cacheWriteInputTokens.
Total billable output = outputTokens + reasoningTokens. Adding two
non-negatives cannot underflow, so consumers can no longer reproduce the
underflow-then-clamp bug class fixed by #26620.

Each protocol mapper now enforces the contract at the provider boundary
via `ProviderShared.subtractTokens`, which clamps with `Math.max(0, …)`
for defense against provider bugs:

- OpenAI Chat / Responses: pull `cached_tokens` out of `prompt_tokens` /
  `input_tokens`; pull `reasoning_tokens` out of `completion_tokens` /
  `output_tokens`. The provider's `total_tokens` is preserved verbatim.
- Gemini: pull `cachedContentTokenCount` out of `promptTokenCount`.
  Gemini already split visible candidates from thoughts.
- Bedrock: pull `cacheReadInputTokens` and `cacheWriteInputTokens` out of
  `inputTokens`, matching AWS prompt-caching docs.
- Anthropic: already non-overlapping per the Messages API; pass through.

Adds `Usage.totalInput` / `Usage.totalOutput` helpers for callers that
want the merged view, and a regression test covering the clamp behavior.

The reasoning underflow fixed in #26620 was the most visible symptom of
a broader semantic inconsistency in this package: providers also disagreed
on whether `inputTokens` includes cache reads (Anthropic excluded;
OpenAI/Gemini/Bedrock included), which would silently double-subtract
the moment v2 wired LLM.Usage into Session.getUsage. Normalizing now,
pre-integration, closes both holes in one move.
2026-05-10 13:07:58 -04:00
..
app sync release versions for v1.14.46 2026-05-10 02:34:36 +00:00
console zen: fix usage css on mobile 2026-05-10 12:14:11 -04:00
containers chore: bump Bun to 1.3.13 (#23791) 2026-04-23 00:25:36 -04:00
core sync release versions for v1.14.46 2026-05-10 02:34:36 +00:00
desktop sync release versions for v1.14.46 2026-05-10 02:34:36 +00:00
docs
enterprise sync release versions for v1.14.46 2026-05-10 02:34:36 +00:00
extensions/zed sync release versions for v1.14.46 2026-05-10 02:34:36 +00:00
function sync release versions for v1.14.46 2026-05-10 02:34:36 +00:00
http-recorder chore: generate 2026-05-10 16:44:40 +00:00
identity
llm refactor(llm): make LLM.Usage a fully-additive contract 2026-05-10 13:07:58 -04:00
opencode Use Effect timeout in compaction test (#26728) 2026-05-10 12:45:54 -04:00
plugin sync release versions for v1.14.46 2026-05-10 02:34:36 +00:00
script
sdk chore: generate 2026-05-10 16:22:29 +00:00
slack sync release versions for v1.14.46 2026-05-10 02:34:36 +00:00
storybook feat(prompt): add shell mode UI with cancel button, custom icon, and example placeholder (#24105) 2026-04-24 14:04:55 +08:00
ui sync release versions for v1.14.46 2026-05-10 02:34:36 +00:00
web Zen: add Ring 2.6 1T 2026-05-10 03:51:34 -04:00