@ai-sdk/anthropic 2.0.105 → 2.0.107

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/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  } from "@ai-sdk/provider-utils";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = true ? "2.0.105" : "0.0.0-test";
14
+ var VERSION = true ? "2.0.107" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
@@ -676,9 +676,10 @@ var anthropicSystemMessageProviderOptions = z3.object({
676
676
  */
677
677
  clearAt: z3.literal("next_user_message").optional(),
678
678
  /**
679
- * Overrides the effort for the turn following this mid-conversation system
680
- * message. The required `mid-conversation-output-config-2026-07-01` beta is added
681
- * automatically.
679
+ * Sets the model effort from the next user turn until a later message
680
+ * changes it. An effort-only system message with empty content can appear
681
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
682
+ * added automatically.
682
683
  */
683
684
  effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
684
685
  /**
@@ -728,7 +729,7 @@ var anthropicProviderOptions = z3.object({
728
729
  *
729
730
  * - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
730
731
  * - `jsonTool`: Use a special JSON response tool to specify the structured output format (default for most models).
731
- * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Opus 5.5 and Fable 5.1).
732
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Sonnet 5.5, Opus 5.5, and Fable 5.1).
732
733
  */
733
734
  structuredOutputMode: z3.enum(["outputFormat", "jsonTool", "auto"]).optional(),
734
735
  /**
@@ -741,6 +742,9 @@ var anthropicProviderOptions = z3.object({
741
742
  * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
742
743
  * provider drops the unsupported setting, emits a warning, and sends an
743
744
  * adaptive thinking request. Use `effort` to control how much they think.
745
+ *
746
+ * `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
747
+ * and the provider uses it in place of `disabled` for that model.
744
748
  */
745
749
  thinking: z3.union([
746
750
  z3.object({
@@ -772,6 +776,14 @@ var anthropicProviderOptions = z3.object({
772
776
  z3.object({
773
777
  type: z3.literal("disabled")
774
778
  }),
779
+ z3.object({
780
+ /**
781
+ * for `claude-sonnet-5-5`: no upfront thinking, but progress notes
782
+ * between tool calls are returned as summarized thinking blocks.
783
+ * Only supported at `low`, `medium`, and `high` effort.
784
+ */
785
+ type: z3.literal("between_tools")
786
+ }),
775
787
  z3.object({
776
788
  /**
777
789
  * Configure prefix mismatch handling without changing the model's
@@ -1674,7 +1686,7 @@ async function convertToAnthropicMessagesPrompt({
1674
1686
  cacheControlValidator,
1675
1687
  toolsetNames = {}
1676
1688
  }) {
1677
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1689
+ var _a, _b, _c, _d, _e, _f, _g;
1678
1690
  const betas = /* @__PURE__ */ new Set();
1679
1691
  const blocks = groupIntoBlocks(prompt);
1680
1692
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1706,10 +1718,9 @@ async function convertToAnthropicMessagesPrompt({
1706
1718
  const type = block.type;
1707
1719
  switch (type) {
1708
1720
  case "system": {
1709
- const content = [];
1721
+ const systemMessages = [];
1710
1722
  let toolChangeCount = 0;
1711
- let clearAt = void 0;
1712
- let effort = void 0;
1723
+ let hasMidConversationOptions = false;
1713
1724
  for (const { content: text, providerOptions } of block.messages) {
1714
1725
  const systemMessageOptions = await parseProviderOptions({
1715
1726
  provider: "anthropic",
@@ -1717,8 +1728,9 @@ async function convertToAnthropicMessagesPrompt({
1717
1728
  schema: anthropicSystemMessageProviderOptions
1718
1729
  });
1719
1730
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1720
- clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1721
- effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1731
+ const clearAt = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt;
1732
+ const effort = systemMessageOptions == null ? void 0 : systemMessageOptions.effort;
1733
+ const content = [];
1722
1734
  if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1723
1735
  content.push({
1724
1736
  type: "text",
@@ -1739,33 +1751,47 @@ async function convertToAnthropicMessagesPrompt({
1739
1751
  }
1740
1752
  });
1741
1753
  }
1754
+ hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
1755
+ systemMessages.push({
1756
+ role: "system",
1757
+ content,
1758
+ ...clearAt != null && { clear_at: clearAt },
1759
+ ...effort != null && { output_config: { effort } }
1760
+ });
1742
1761
  }
1743
- const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1744
- if (i === 0 || system == null && !hasMidConversationOptions) {
1745
- if (hasMidConversationOptions) {
1762
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
1763
+ if (toolChangeCount > 0) {
1746
1764
  warnings.push({
1747
1765
  type: "other",
1748
- message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1766
+ message: "tool changes on the initial system message are not supported by Anthropic. Configure the initial tool set via the tools option instead. The tool changes have been ignored."
1749
1767
  });
1750
1768
  }
1751
- system = content.filter(
1752
- (part) => part.type === "text"
1769
+ for (const message of systemMessages) {
1770
+ if (message.content.length === 0 && message.clear_at == null && message.output_config != null) {
1771
+ messages.push(message);
1772
+ betas.add("mid-conversation-output-config-2026-07-01");
1773
+ } else if (message.clear_at != null || message.output_config != null) {
1774
+ warnings.push({
1775
+ type: "other",
1776
+ message: "clearAt and effort on this initial system message are not supported by Anthropic. Use a separate effort-only system message with empty content to set effort. These options have been ignored."
1777
+ });
1778
+ }
1779
+ }
1780
+ system = systemMessages.flatMap(
1781
+ (message) => message.content.filter(
1782
+ (part) => part.type === "text"
1783
+ )
1753
1784
  );
1754
1785
  } else {
1755
- messages.push({
1756
- role: "system",
1757
- content,
1758
- ...clearAt != null && { clear_at: clearAt },
1759
- ...effort != null && { output_config: { effort } }
1760
- });
1786
+ messages.push(...systemMessages);
1761
1787
  betas.add("mid-conversation-system-2026-04-07");
1762
1788
  if (toolChangeCount > 0) {
1763
1789
  betas.add("mid-conversation-tool-changes-2026-07-01");
1764
1790
  }
1765
- if (clearAt != null) {
1791
+ if (systemMessages.some((message) => message.clear_at != null)) {
1766
1792
  betas.add("mid-conversation-system-clear-at-2026-08-21");
1767
1793
  }
1768
- if (effort != null) {
1794
+ if (systemMessages.some((message) => message.output_config != null)) {
1769
1795
  betas.add("mid-conversation-output-config-2026-07-01");
1770
1796
  }
1771
1797
  }
@@ -1780,10 +1806,10 @@ async function convertToAnthropicMessagesPrompt({
1780
1806
  for (let j = 0; j < content.length; j++) {
1781
1807
  const part = content[j];
1782
1808
  const isLastPart = j === content.length - 1;
1783
- const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1809
+ const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1784
1810
  type: "user message part",
1785
1811
  canCache: true
1786
- })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1812
+ })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1787
1813
  type: "user message",
1788
1814
  canCache: true
1789
1815
  }) : void 0;
@@ -1828,7 +1854,7 @@ async function convertToAnthropicMessagesPrompt({
1828
1854
  media_type: "application/pdf",
1829
1855
  data: convertToBase64(part.data)
1830
1856
  },
1831
- title: (_e = metadata.title) != null ? _e : part.filename,
1857
+ title: (_c = metadata.title) != null ? _c : part.filename,
1832
1858
  ...metadata.context && { context: metadata.context },
1833
1859
  ...enableCitations && {
1834
1860
  citations: { enabled: true }
@@ -1852,7 +1878,7 @@ async function convertToAnthropicMessagesPrompt({
1852
1878
  media_type: "text/plain",
1853
1879
  data: convertToString(part.data)
1854
1880
  },
1855
- title: (_f = metadata.title) != null ? _f : part.filename,
1881
+ title: (_d = metadata.title) != null ? _d : part.filename,
1856
1882
  ...metadata.context && { context: metadata.context },
1857
1883
  ...enableCitations && {
1858
1884
  citations: { enabled: true }
@@ -1874,10 +1900,10 @@ async function convertToAnthropicMessagesPrompt({
1874
1900
  for (let i2 = 0; i2 < content.length; i2++) {
1875
1901
  const part = content[i2];
1876
1902
  const isLastPart = i2 === content.length - 1;
1877
- const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1903
+ const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1878
1904
  type: "tool result part",
1879
1905
  canCache: true
1880
- })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1906
+ })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1881
1907
  type: "tool result message",
1882
1908
  canCache: true
1883
1909
  }) : void 0;
@@ -1965,16 +1991,16 @@ async function convertToAnthropicMessagesPrompt({
1965
1991
  for (let k = 0; k < content.length; k++) {
1966
1992
  const part = content[k];
1967
1993
  const isLastContentPart = k === content.length - 1;
1968
- const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1994
+ const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1969
1995
  type: "assistant message part",
1970
1996
  canCache: true
1971
- })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1997
+ })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1972
1998
  type: "assistant message",
1973
1999
  canCache: true
1974
2000
  }) : void 0;
1975
2001
  switch (part.type) {
1976
2002
  case "text": {
1977
- const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
2003
+ const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1978
2004
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1979
2005
  anthropicContent.push({
1980
2006
  type: "compaction",
@@ -2654,6 +2680,7 @@ var AnthropicMessagesLanguageModel = class {
2654
2680
  rejectsThinkingDisabledAboveHighEffort,
2655
2681
  rejectsThinkingDisabled,
2656
2682
  rejectsForcedToolUse,
2683
+ supportsBetweenToolsThinking,
2657
2684
  isKnownModel
2658
2685
  } = getModelCapabilities(this.modelId);
2659
2686
  if (!isKnownModel && maxOutputTokens == null) {
@@ -2689,7 +2716,7 @@ var AnthropicMessagesLanguageModel = class {
2689
2716
  }
2690
2717
  }
2691
2718
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
2692
- const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") || this.modelId.includes("claude-opus-5-5") ? "auto" : "jsonTool";
2719
+ const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") || this.modelId.includes("claude-opus-5-5") || this.modelId.includes("claude-sonnet-5-5") ? "auto" : "jsonTool";
2693
2720
  let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2694
2721
  if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
2695
2722
  warnings.push({
@@ -2724,7 +2751,14 @@ var AnthropicMessagesLanguageModel = class {
2724
2751
  });
2725
2752
  if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
2726
2753
  const thinking = anthropicOptions.thinking;
2727
- if ("type" in thinking && thinking.type === "disabled") {
2754
+ if ("type" in thinking && thinking.type === "disabled" && supportsBetweenToolsThinking) {
2755
+ warnings.push({
2756
+ type: "unsupported-setting",
2757
+ setting: "providerOptions.anthropic.thinking",
2758
+ details: `thinking cannot be disabled for ${this.modelId}. Using 'between_tools' thinking, the lowest thinking setting, instead.`
2759
+ });
2760
+ anthropicOptions.thinking = { type: "between_tools" };
2761
+ } else if ("type" in thinking && thinking.type === "disabled") {
2728
2762
  warnings.push({
2729
2763
  type: "unsupported-setting",
2730
2764
  setting: "providerOptions.anthropic.thinking",
@@ -2755,7 +2789,15 @@ var AnthropicMessagesLanguageModel = class {
2755
2789
  });
2756
2790
  anthropicOptions.effort = "high";
2757
2791
  }
2758
- const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2792
+ if (thinkingType === "between_tools" && anthropicOptions != null && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2793
+ warnings.push({
2794
+ type: "unsupported-setting",
2795
+ setting: "providerOptions.anthropic.effort",
2796
+ details: `effort '${anthropicOptions.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`
2797
+ });
2798
+ anthropicOptions.effort = "high";
2799
+ }
2800
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive" || thinkingType === "between_tools";
2759
2801
  let thinkingBudget = thinkingOptions != null && "budgetTokens" in thinkingOptions ? thinkingOptions.budgetTokens : void 0;
2760
2802
  const thinkingDisplay = thinkingOptions != null && "display" in thinkingOptions ? thinkingOptions.display : void 0;
2761
2803
  const thinkingBlockBinding = thinkingOptions != null && "blockBinding" in thinkingOptions ? thinkingOptions.blockBinding : void 0;
@@ -4120,7 +4162,18 @@ var AnthropicMessagesLanguageModel = class {
4120
4162
  }
4121
4163
  };
4122
4164
  function getModelCapabilities(modelId) {
4123
- if (modelId.includes("claude-opus-5-5")) {
4165
+ if (modelId.includes("claude-sonnet-5-5")) {
4166
+ return {
4167
+ maxOutputTokens: 128e3,
4168
+ supportsStructuredOutput: true,
4169
+ rejectsSamplingParameters: true,
4170
+ rejectsThinkingDisabledAboveHighEffort: true,
4171
+ rejectsThinkingDisabled: true,
4172
+ rejectsForcedToolUse: true,
4173
+ supportsBetweenToolsThinking: true,
4174
+ isKnownModel: true
4175
+ };
4176
+ } else if (modelId.includes("claude-opus-5-5")) {
4124
4177
  return {
4125
4178
  maxOutputTokens: 128e3,
4126
4179
  supportsStructuredOutput: true,
@@ -4128,6 +4181,7 @@ function getModelCapabilities(modelId) {
4128
4181
  rejectsThinkingDisabledAboveHighEffort: true,
4129
4182
  rejectsThinkingDisabled: true,
4130
4183
  rejectsForcedToolUse: true,
4184
+ supportsBetweenToolsThinking: false,
4131
4185
  isKnownModel: true
4132
4186
  };
4133
4187
  } else if (modelId.includes("claude-opus-5")) {
@@ -4138,6 +4192,7 @@ function getModelCapabilities(modelId) {
4138
4192
  rejectsThinkingDisabledAboveHighEffort: true,
4139
4193
  rejectsThinkingDisabled: false,
4140
4194
  rejectsForcedToolUse: false,
4195
+ supportsBetweenToolsThinking: false,
4141
4196
  isKnownModel: true
4142
4197
  };
4143
4198
  } else if (modelId.includes("claude-fable-5-1")) {
@@ -4148,6 +4203,7 @@ function getModelCapabilities(modelId) {
4148
4203
  rejectsThinkingDisabledAboveHighEffort: false,
4149
4204
  rejectsThinkingDisabled: true,
4150
4205
  rejectsForcedToolUse: true,
4206
+ supportsBetweenToolsThinking: false,
4151
4207
  isKnownModel: true
4152
4208
  };
4153
4209
  } else if (modelId.includes("claude-fable-5")) {
@@ -4158,6 +4214,7 @@ function getModelCapabilities(modelId) {
4158
4214
  rejectsThinkingDisabledAboveHighEffort: false,
4159
4215
  rejectsThinkingDisabled: true,
4160
4216
  rejectsForcedToolUse: false,
4217
+ supportsBetweenToolsThinking: false,
4161
4218
  isKnownModel: true
4162
4219
  };
4163
4220
  } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-sonnet-5")) {
@@ -4168,6 +4225,7 @@ function getModelCapabilities(modelId) {
4168
4225
  rejectsThinkingDisabledAboveHighEffort: false,
4169
4226
  rejectsThinkingDisabled: false,
4170
4227
  rejectsForcedToolUse: false,
4228
+ supportsBetweenToolsThinking: false,
4171
4229
  isKnownModel: true
4172
4230
  };
4173
4231
  } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
@@ -4178,6 +4236,7 @@ function getModelCapabilities(modelId) {
4178
4236
  rejectsThinkingDisabledAboveHighEffort: false,
4179
4237
  rejectsThinkingDisabled: false,
4180
4238
  rejectsForcedToolUse: false,
4239
+ supportsBetweenToolsThinking: false,
4181
4240
  isKnownModel: true
4182
4241
  };
4183
4242
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
@@ -4188,6 +4247,7 @@ function getModelCapabilities(modelId) {
4188
4247
  rejectsThinkingDisabledAboveHighEffort: false,
4189
4248
  rejectsThinkingDisabled: false,
4190
4249
  rejectsForcedToolUse: false,
4250
+ supportsBetweenToolsThinking: false,
4191
4251
  isKnownModel: true
4192
4252
  };
4193
4253
  } else if (modelId.includes("claude-opus-4-1")) {
@@ -4198,6 +4258,7 @@ function getModelCapabilities(modelId) {
4198
4258
  rejectsThinkingDisabledAboveHighEffort: false,
4199
4259
  rejectsThinkingDisabled: false,
4200
4260
  rejectsForcedToolUse: false,
4261
+ supportsBetweenToolsThinking: false,
4201
4262
  isKnownModel: true
4202
4263
  };
4203
4264
  } else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet")) {
@@ -4208,6 +4269,7 @@ function getModelCapabilities(modelId) {
4208
4269
  rejectsThinkingDisabledAboveHighEffort: false,
4209
4270
  rejectsThinkingDisabled: false,
4210
4271
  rejectsForcedToolUse: false,
4272
+ supportsBetweenToolsThinking: false,
4211
4273
  isKnownModel: true
4212
4274
  };
4213
4275
  } else if (modelId.includes("claude-opus-4-")) {
@@ -4218,6 +4280,7 @@ function getModelCapabilities(modelId) {
4218
4280
  rejectsThinkingDisabledAboveHighEffort: false,
4219
4281
  rejectsThinkingDisabled: false,
4220
4282
  rejectsForcedToolUse: false,
4283
+ supportsBetweenToolsThinking: false,
4221
4284
  isKnownModel: true
4222
4285
  };
4223
4286
  } else if (modelId.includes("claude-3-haiku")) {
@@ -4228,6 +4291,7 @@ function getModelCapabilities(modelId) {
4228
4291
  rejectsThinkingDisabledAboveHighEffort: false,
4229
4292
  rejectsThinkingDisabled: false,
4230
4293
  rejectsForcedToolUse: false,
4294
+ supportsBetweenToolsThinking: false,
4231
4295
  isKnownModel: true
4232
4296
  };
4233
4297
  } else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
@@ -4238,6 +4302,7 @@ function getModelCapabilities(modelId) {
4238
4302
  rejectsThinkingDisabledAboveHighEffort: false,
4239
4303
  rejectsThinkingDisabled: false,
4240
4304
  rejectsForcedToolUse: false,
4305
+ supportsBetweenToolsThinking: false,
4241
4306
  isKnownModel: false
4242
4307
  };
4243
4308
  } else if (modelId.includes("claude-")) {
@@ -4248,6 +4313,7 @@ function getModelCapabilities(modelId) {
4248
4313
  rejectsThinkingDisabledAboveHighEffort: true,
4249
4314
  rejectsThinkingDisabled: false,
4250
4315
  rejectsForcedToolUse: false,
4316
+ supportsBetweenToolsThinking: false,
4251
4317
  isKnownModel: false
4252
4318
  };
4253
4319
  } else {
@@ -4258,6 +4324,7 @@ function getModelCapabilities(modelId) {
4258
4324
  rejectsThinkingDisabledAboveHighEffort: false,
4259
4325
  rejectsThinkingDisabled: false,
4260
4326
  rejectsForcedToolUse: false,
4327
+ supportsBetweenToolsThinking: false,
4261
4328
  isKnownModel: false
4262
4329
  };
4263
4330
  }