@warlock.js/ai-anthropic 5.30.0 → 5.31.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +44 -6
  2. package/cjs/index.cjs +815 -132
  3. package/cjs/index.cjs.map +1 -1
  4. package/esm/config.type.d.mts +107 -4
  5. package/esm/config.type.d.mts.map +1 -1
  6. package/esm/index.d.mts +8 -3
  7. package/esm/index.mjs +7 -1
  8. package/esm/known-output-limits.mjs +46 -0
  9. package/esm/known-output-limits.mjs.map +1 -0
  10. package/esm/known-pricing.d.mts +58 -0
  11. package/esm/known-pricing.d.mts.map +1 -0
  12. package/esm/known-pricing.mjs +165 -0
  13. package/esm/known-pricing.mjs.map +1 -0
  14. package/esm/model.d.mts +89 -17
  15. package/esm/model.d.mts.map +1 -1
  16. package/esm/model.mjs +383 -86
  17. package/esm/model.mjs.map +1 -1
  18. package/esm/request.type.d.mts +25 -0
  19. package/esm/request.type.d.mts.map +1 -0
  20. package/esm/thinking-mode.d.mts +14 -1
  21. package/esm/thinking-mode.d.mts.map +1 -1
  22. package/esm/thinking-mode.mjs +102 -2
  23. package/esm/thinking-mode.mjs.map +1 -1
  24. package/esm/utils/cache-usage.mjs +62 -0
  25. package/esm/utils/cache-usage.mjs.map +1 -0
  26. package/esm/utils/index.d.mts +3 -0
  27. package/esm/utils/map-stop-reason.d.mts +1 -0
  28. package/esm/utils/provider-blocks.d.mts +39 -0
  29. package/esm/utils/provider-blocks.d.mts.map +1 -0
  30. package/esm/utils/to-anthropic-messages.d.mts +71 -0
  31. package/esm/utils/to-anthropic-messages.d.mts.map +1 -0
  32. package/esm/utils/to-anthropic-messages.mjs +12 -4
  33. package/esm/utils/to-anthropic-messages.mjs.map +1 -1
  34. package/esm/utils/to-anthropic-tools.d.mts +19 -0
  35. package/esm/utils/to-anthropic-tools.d.mts.map +1 -0
  36. package/esm/utils/wrap-anthropic-error.d.mts +1 -0
  37. package/esm/utils/wrap-anthropic-error.mjs +6 -1
  38. package/esm/utils/wrap-anthropic-error.mjs.map +1 -1
  39. package/llms-full.txt +214 -32
  40. package/llms.txt +1 -1
  41. package/package.json +3 -3
  42. package/skills/README.md +1 -1
  43. package/skills/setup-anthropic/SKILL.md +214 -32
package/CHANGELOG.md CHANGED
@@ -4,6 +4,44 @@ All notable changes to `@warlock.js/ai-anthropic` are documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
6
6
 
7
+ ## 5.31.0 - 2026-10-18
8
+
9
+ ### Upgrading
10
+
11
+ - Claude models are now priced by default, so `Usage.cost` appears and USD budgets enforce on them without extra configuration. Pass `pricing` to keep contract rates.
12
+ - Responses can be longer, and cost more, when `maxTokens` was never set. Set `maxTokens` on the model or per call to keep a lower cap. For a gateway or proxy id, set `maxOutputTokens` so streaming uses the real limit.
13
+
14
+ ### Added
15
+
16
+ - Built-in Claude API list prices (`ANTHROPIC_MODEL_PRICING`, `anthropicPricingFor`, `withAnthropicCacheWriteRates`), from Anthropic's pricing page as of 2026-10-17, used when neither the model nor the SDK registry is priced. Dated snapshot ids resolve to their alias. Claude Haiku 5.5 (priced by prompt length) is left unpriced.
17
+ - `complete()` and the streaming `done` chunk attach `usage.cost` when the model is priced.
18
+ - 529 / `overloaded_error` responses and mid-stream overload events throw `ProviderOverloadedError`; every wrapped error carries `status`, `billed` and `retryable`.
19
+ - An adapter contract test verifies that aborting `signal` rejects `complete()` and `stream()` on the model and cancels the HTTP request.
20
+ - `AnthropicModelConfig.maxOutputTokens` overrides the inferred model output limit that sizes the default `max_tokens`.
21
+ - With `streamChunks`, `stream()` yields `reasoning` for `thinking_delta`, `tool-args` for the `input_json_delta` of client `tool_use` blocks, and `usage` after `message_start` and each `message_delta`. `send()` takes the same `streamChunks` transport option.
22
+ - `ai.providerTool({ provider: "anthropic", definition })` entries (`web_search`, `web_fetch`, `code_execution`, `bash`, `text_editor`, `memory`, …) are sent verbatim ahead of the function tools; the prompt-cache breakpoint stays on the last function tool. Other providers' tools are skipped with a warning. The reserved `providerOptions.anthropic.body` keys are unchanged.
23
+ - Typed context management on `providerOptions.anthropic`: `contextManagement.clearToolUses` / `clearThinking` (`clear_tool_uses_20250919` / `clear_thinking_20251015`, beta `context-management-2025-06-27`) and `serverCompaction` (`compact_20260112`, beta `compact-2026-01-12`, trigger of at least 50,000 input tokens). The adapter builds the edits in the order the API requires and adds the beta headers; combining them with `body.context_management` fails with `InvalidRequestError`.
24
+ - `thinkingBlockBinding: "error" | "drop_block"` sends `thinking.block_binding.prefix_mismatch_behavior` with the `thinking-binding-controls-2026-08-01` beta.
25
+ - Preserved thinking after client-side compaction: on Claude Fable 5.1, Opus 5.5, Sonnet 5.5 and Haiku 5.5 an assistant turn marked `compaction: "retained"` is replayed without its thinking blocks, which were produced against the replaced history. `AnthropicModelConfig.preservedThinking` overrides the inference; `inferPreservedThinking(name)` and `ToAnthropicMessagesOptions` are exported.
26
+ - `AnthropicModel.buildRequest()` creates a detached request snapshot for preflight auditing; `send(request)` sends that snapshot as a completion or stream without rebuilding its body.
27
+ - Message, tool and provider-block converters and request types are exported from the package root for hosts using their own transport.
28
+
29
+ ### Changed
30
+
31
+ - `reasoning: { effort: "none" }` now turns thinking off on Claude Sonnet 5 and Claude Haiku 5.5 with `thinking: { type: "disabled" }` (sent alone, so Haiku 5.5 stays at its default effort, inside the range where `disabled` is accepted). Previously no `thinking` field was sent and both models ran adaptive thinking by default.
32
+ - `reasoning: { effort: "none" }` on Claude Opus 5 now sends adaptive thinking at `output_config.effort: "low"` instead of omitting `thinking` (which ran at the default `high`). Opus 5 is deliberately not sent `disabled`: with thinking off it can write a tool call as plain text that never runs, and leak thinking tags. Claude Opus 5.5, Sonnet 5.5 and Fable 5 / 5.1 are unchanged.
33
+ - **BREAKING** The default `max_tokens` (when no `maxTokens` is set) rose from 4096. Streaming requests use the model's documented max output — 128K for the Claude 5 family and Opus 4.6–4.8 / Sonnet 4.6, 64K for Opus / Sonnet / Haiku 4.5 — and non-streaming requests use 16384, capped by the model's max output (the Anthropic SDK requires streaming for larger non-streaming requests unless the client sets a `timeout`). Unknown ids default to 16384. With thinking on, the default still keeps room for the thinking budget plus 4096 answer tokens, within the model's limit.
34
+
35
+ ### Fixed
36
+
37
+ - Usage is marked `inputIncludesCache: false` (Anthropic's `input_tokens` excludes cache reads and writes), and 1-hour cache writes are reported in `cacheWrite1hTokens` from `cache_creation.ephemeral_1h_input_tokens` — or, when the breakdown is missing, from a request whose every cache marker asked for `ttl: "1h"`. Cost now bills reads and writes once each, at their own rates.
38
+ - Caller pricing that omits cache-write rates gets Anthropic's documented multipliers (5-minute writes 1.25x input, 1-hour writes 2x) instead of billing writes at nothing.
39
+ - Usage includes server-side compaction: the `compaction` entries of `usage.iterations`, which the top-level token counts leave out, are added to `input`, `output` and the cache counts (completions and streams).
40
+ - `complete()` always builds a non-streaming request, including when an indexed `stream` option is supplied.
41
+ - A request that fails to build in `complete()`, `stream()` or `countTokens()` (a reserved `providerOptions.anthropic.body` key, or a `body` value `structuredClone` cannot copy, such as a function) is logged like a send failure and rejects with an `AIError`; errors that are not already one become an `InvalidRequestError` carrying the original as `cause`. Before, the raw error escaped unlogged. `buildRequest()` itself still throws the raw error.
42
+ - The debug log line for a streaming request reads "Starting streaming call to messages.create" again; non-streaming requests keep "Starting call to messages.create".
43
+ - The provider docs and `setup-anthropic` skill say that `send()` passes `betas` only to the `"beta.messages"` endpoint.
44
+
7
45
  ## 5.30.0 - 2026-10-16
8
46
 
9
47
  ### Upgrading
@@ -13,16 +51,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
13
51
 
14
52
  ### Added
15
53
 
16
- - Responses with thinking, redacted-thinking, compaction, server-tool or cited-text blocks return the whole ordered turn as `ModelResponse.blocks` (and on the streaming `done` chunk); an assistant message carrying Anthropic `blocks` is replayed verbatim (WR-022).
17
- - `providerOptions.anthropic` (`AnthropicCallOptions`): `betas` routes the call through `client.beta.messages`, `body` merges extra request fields last (`context_management`, `fallbacks`, `inference_geo`, …), `thinkingDisplay` sets `thinking.display` (WR-025).
18
- - `AnthropicModel.countTokens(messages, options?)` counts input tokens through `messages.countTokens`; `AnthropicModel` is exported and `AnthropicSDK.model()` returns it (WR-025).
54
+ - Responses with thinking, redacted-thinking, compaction, server-tool or cited-text blocks return the whole ordered turn as `ModelResponse.blocks` (and on the streaming `done` chunk); an assistant message carrying Anthropic `blocks` is replayed verbatim.
55
+ - `providerOptions.anthropic` (`AnthropicCallOptions`): `betas` routes the call through `client.beta.messages`, `body` merges extra request fields last (`context_management`, `fallbacks`, `inference_geo`, …), `thinkingDisplay` sets `thinking.display`.
56
+ - `AnthropicModel.countTokens(messages, options?)` counts input tokens through `messages.countTokens`; `AnthropicModel` is exported and `AnthropicSDK.model()` returns it.
19
57
  - Per-call `cacheControl.ttl` overrides the model's `promptCacheTtl`.
20
58
 
21
59
  ### Changed
22
60
 
23
- - Consecutive tool results are sent as one `user` message with several `tool_result` blocks, as Anthropic expects for parallel tool use (WR-024).
24
- - Claude 5-family thinking rules: Opus 5.5, Sonnet 5.5 and Fable 5 / 5.1 never receive `budget_tokens` or `disabled` (WR-026).
25
- - `effort: "none"` on Claude Sonnet 5.5 sends `thinking: { type: "between_tools" }` (its only thinking-off form, sent alone with no `output_config.effort` or `display`); it used to omit `thinking`, so the model still thought at its default effort. Opus 5.5 and Fable 5 / 5.1 have no thinking-off form and keep omitting `thinking` (WR-026).
61
+ - Consecutive tool results are sent as one `user` message with several `tool_result` blocks, as Anthropic expects for parallel tool use.
62
+ - Claude 5-family thinking rules: Opus 5.5, Sonnet 5.5 and Fable 5 / 5.1 never receive `budget_tokens` or `disabled`.
63
+ - `effort: "none"` on Claude Sonnet 5.5 sends `thinking: { type: "between_tools" }` (its only thinking-off form, sent alone with no `output_config.effort` or `display`); it used to omit `thinking`, so the model still thought at its default effort. Opus 5.5 and Fable 5 / 5.1 have no thinking-off form and keep omitting `thinking`.
26
64
 
27
65
  ### Fixed
28
66