@warlock.js/ai-anthropic 5.43.0 → 5.45.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/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ 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.45.0 - 2026-11-05
8
+
9
+ ### Added
10
+
11
+ - The agent-level `contextEditing.clearToolResults.clearAtLeast` is mapped to `clear_at_least` on the native `clear_tool_uses` edit, next to the resolved `trigger`, `keep` and `exclude_tools`.
12
+ - Image parts in a tool result are sent as `image` blocks inside the `tool_result`; the model reports `capabilities.toolResultImages: true`.
13
+ - `capabilities.contextWindow` is reported for every known Claude release: 1M for Opus 4.6 to 5.5, Sonnet 4.6 to 5.5, Haiku 5.5, Fable and Mythos, and 200K for Opus 4 to 4.5, Sonnet 4 to 4.5, Haiku 4.5 and the Claude 3 line. `contextWindow` in the model config still wins.
14
+
15
+ ## 5.44.0 - 2026-11-05
16
+
17
+ ### Added
18
+
19
+ - `anthropic.model({ name, contextWindow })` sets `capabilities.contextWindow`; without it the window comes from a table of 200K Claude models, and unknown models stay unset so window-relative `compaction.afterTokens` triggers do not fire.
20
+
7
21
  ## 5.40.0 - 2026-10-29
8
22
 
9
23
  ### Added
package/cjs/index.cjs CHANGED
@@ -405,6 +405,51 @@ function inferPreservedThinking(modelName) {
405
405
  return true;
406
406
  }
407
407
 
408
+ //#endregion
409
+ //#region ../../packages/ai-anthropic/src/known-context-windows.ts
410
+ const RELEASE_CONTEXT_WINDOWS = [
411
+ ["claude-fable-5-1", 1e6],
412
+ ["claude-fable-5", 1e6],
413
+ ["claude-mythos-5-1", 1e6],
414
+ ["claude-mythos-5", 1e6],
415
+ ["claude-opus-5-5", 1e6],
416
+ ["claude-opus-5", 1e6],
417
+ ["claude-opus-4-8", 1e6],
418
+ ["claude-opus-4-7", 1e6],
419
+ ["claude-opus-4-6", 1e6],
420
+ ["claude-opus-4-5", 2e5],
421
+ ["claude-opus-4-1", 2e5],
422
+ ["claude-opus-4", 2e5],
423
+ ["claude-sonnet-5-5", 1e6],
424
+ ["claude-sonnet-5", 1e6],
425
+ ["claude-sonnet-4-6", 1e6],
426
+ ["claude-sonnet-4-5", 2e5],
427
+ ["claude-sonnet-4", 2e5],
428
+ ["claude-haiku-5-5", 1e6],
429
+ ["claude-haiku-4-5", 2e5],
430
+ ["claude-3-7-sonnet", 2e5],
431
+ ["claude-3-5-sonnet", 2e5],
432
+ ["claude-3-5-haiku", 2e5],
433
+ ["claude-3-opus", 2e5],
434
+ ["claude-3-haiku", 2e5]
435
+ ];
436
+ /**
437
+ * The known context window of a Claude model, or `undefined` for an id that
438
+ * is not in the table. Platform prefixes before `claude-` and dated or `@`
439
+ * snapshot suffixes are accepted.
440
+ *
441
+ * @example
442
+ * inferContextWindow("claude-haiku-4-5-20251001"); // → 200000
443
+ * inferContextWindow("my-gateway/model"); // → undefined
444
+ */
445
+ function inferContextWindow(modelName) {
446
+ const lowered = modelName.toLowerCase();
447
+ const start = lowered.indexOf("claude-");
448
+ if (start === -1) return;
449
+ const normalized = lowered.slice(start);
450
+ for (const [root, window] of RELEASE_CONTEXT_WINDOWS) if (matchesReleaseRoot(normalized, root)) return window;
451
+ }
452
+
408
453
  //#endregion
409
454
  //#region ../../packages/ai-anthropic/src/known-output-limits.ts
410
455
  /** Family prefixes whose every release has a 128K output limit. */
@@ -746,7 +791,7 @@ function toAnthropicMessages(messages, options = {}) {
746
791
  const toolResult = {
747
792
  type: "tool_result",
748
793
  tool_use_id: message.toolCallId ?? "",
749
- content: stringifyContent(message.content)
794
+ content: toToolResultContent(message.content)
750
795
  };
751
796
  const previous = mapped[mapped.length - 1];
752
797
  if (previous && previous.role === "user" && isToolResultTurn(previous)) previous.content.push(toolResult);
@@ -854,6 +899,33 @@ function stringifyContent(content) {
854
899
  return content.filter((part) => part.type === "text").map((part) => part.text).join("");
855
900
  }
856
901
  /**
902
+ * A tool result's `content`: the plain string, or text and `image` blocks
903
+ * when the tool returned content parts. A `url` image cannot appear here
904
+ * (tool images are inline base64) but degrades to the placeholder text.
905
+ */
906
+ function toToolResultContent(content) {
907
+ if (typeof content === "string") return content;
908
+ if (!content.some((part) => part.type === "image")) return stringifyContent(content);
909
+ const blocks = [];
910
+ for (const part of content) if (part.type === "text") blocks.push({
911
+ type: "text",
912
+ text: part.text
913
+ });
914
+ else if (part.type === "image" && "base64" in part.source) blocks.push({
915
+ type: "image",
916
+ source: {
917
+ type: "base64",
918
+ media_type: part.source.mediaType,
919
+ data: part.source.base64
920
+ }
921
+ });
922
+ else blocks.push({
923
+ type: "text",
924
+ text: _warlock_js_ai.TOOL_RESULT_IMAGE_PLACEHOLDER
925
+ });
926
+ return blocks;
927
+ }
928
+ /**
857
929
  * Map a single resolved `ContentPart` to an Anthropic content block.
858
930
  * Text passes straight through; images become an `image` block with a
859
931
  * `url` source (remote) or a `base64` source (inlined bytes). The
@@ -1216,7 +1288,9 @@ var AnthropicModel = class {
1216
1288
  this.capabilities = {
1217
1289
  structuredOutput: config.structuredOutput ?? true,
1218
1290
  vision: config.vision ?? inferVisionCapability(config.name),
1291
+ toolResultImages: true,
1219
1292
  reasoning: config.reasoning ?? true,
1293
+ ...windowCapability(config.contextWindow ?? inferContextWindow(config.name)),
1220
1294
  promptCaching: true,
1221
1295
  nativeContextEditing: true,
1222
1296
  pdf: true
@@ -1962,7 +2036,8 @@ function neutralClearToolUses(neutral) {
1962
2036
  return {
1963
2037
  ...rule.afterTokens !== void 0 ? { trigger: { inputTokens: rule.afterTokens } } : {},
1964
2038
  ...rule.keep !== void 0 ? { keep: rule.keep } : {},
1965
- ...rule.exclude?.length ? { excludeTools: rule.exclude } : {}
2039
+ ...rule.exclude?.length ? { excludeTools: rule.exclude } : {},
2040
+ ...rule.clearAtLeast !== void 0 ? { clearAtLeast: rule.clearAtLeast } : {}
1966
2041
  };
1967
2042
  }
1968
2043
  function clearThinkingEdit(options) {
@@ -2051,6 +2126,9 @@ function resolveAnthropicOptions(options) {
2051
2126
  const raw = options?.providerOptions?.anthropic;
2052
2127
  return typeof raw === "object" && raw !== null ? raw : {};
2053
2128
  }
2129
+ function windowCapability(window) {
2130
+ return window === void 0 ? {} : { contextWindow: window };
2131
+ }
2054
2132
 
2055
2133
  //#endregion
2056
2134
  //#region ../../packages/ai-anthropic/src/sdk.ts