@ai-sdk/anthropic 3.0.123 → 3.0.125

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
@@ -1,5 +1,25 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.125
4
+
5
+ ### Patch Changes
6
+
7
+ - 358683e: feat(anthropic): add Claude Sonnet 5.5 support
8
+
9
+ - add the `claude-sonnet-5-5` model ID to `@ai-sdk/anthropic` and `@ai-sdk/google-vertex`, `anthropic.claude-sonnet-5-5` and `us.anthropic.claude-sonnet-5-5` to `@ai-sdk/amazon-bedrock`, and `anthropic/claude-sonnet-5.5` to `@ai-sdk/gateway`
10
+ - add the `between_tools` thinking type (`thinking: { type: 'between_tools' }`), the lowest thinking setting on `claude-sonnet-5-5`; `xhigh` and `max` effort are lowered to `high` with a warning because the API rejects them with `between_tools`
11
+ - `claude-sonnet-5-5` rejects disabled thinking: `thinking: { type: 'disabled' }` is replaced with `between_tools` thinking (with a warning), and budget-based thinking is converted to adaptive thinking
12
+ - `claude-sonnet-5-5` rejects forced tool use: `required` and named tool choices fall back to `auto`, and `structuredOutputMode: 'jsonTool'` falls back to native structured outputs, each with a warning
13
+
14
+ - eeabdce: Normalize dangling programmatic tool caller references in conversation history after pruning. Before a subsequent user message, omit caller metadata whose source code execution call is missing and emit a warning, preserving the retained tool calls and results. Keep caller metadata unchanged for active tool continuations.
15
+
16
+ ## 3.0.124
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [29dc427]
21
+ - @ai-sdk/provider-utils@4.0.56
22
+
3
23
  ## 3.0.123
4
24
 
5
25
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -195,7 +195,7 @@ interface AnthropicMessageMetadata {
195
195
  } | null;
196
196
  }
197
197
 
198
- type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
198
+ type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
199
199
  /**
200
200
  * Anthropic provider options for system messages.
201
201
  */
@@ -242,6 +242,8 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
242
242
  budgetTokens: z.ZodOptional<z.ZodNumber>;
243
243
  }, z.core.$strip>, z.ZodObject<{
244
244
  type: z.ZodLiteral<"disabled">;
245
+ }, z.core.$strip>, z.ZodObject<{
246
+ type: z.ZodLiteral<"between_tools">;
245
247
  }, z.core.$strip>]>, z.ZodObject<{
246
248
  blockBinding: z.ZodObject<{
247
249
  prefixMismatchBehavior: z.ZodEnum<{
package/dist/index.d.ts CHANGED
@@ -195,7 +195,7 @@ interface AnthropicMessageMetadata {
195
195
  } | null;
196
196
  }
197
197
 
198
- type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
198
+ type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
199
199
  /**
200
200
  * Anthropic provider options for system messages.
201
201
  */
@@ -242,6 +242,8 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
242
242
  budgetTokens: z.ZodOptional<z.ZodNumber>;
243
243
  }, z.core.$strip>, z.ZodObject<{
244
244
  type: z.ZodLiteral<"disabled">;
245
+ }, z.core.$strip>, z.ZodObject<{
246
+ type: z.ZodLiteral<"between_tools">;
245
247
  }, z.core.$strip>]>, z.ZodObject<{
246
248
  blockBinding: z.ZodObject<{
247
249
  prefixMismatchBehavior: z.ZodEnum<{
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils27 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.123" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.125" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -948,6 +948,9 @@ var anthropicLanguageModelOptions = import_v43.z.object({
948
948
  * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
949
949
  * provider drops the unsupported setting, emits a warning, and sends an
950
950
  * adaptive thinking request. Use `effort` to control how much they think.
951
+ *
952
+ * `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
953
+ * and the provider uses it in place of `disabled` for that model.
951
954
  */
952
955
  thinking: import_v43.z.union([
953
956
  import_v43.z.discriminatedUnion("type", [
@@ -976,6 +979,14 @@ var anthropicLanguageModelOptions = import_v43.z.object({
976
979
  }),
977
980
  import_v43.z.object({
978
981
  type: import_v43.z.literal("disabled")
982
+ }),
983
+ import_v43.z.object({
984
+ /**
985
+ * for `claude-sonnet-5-5`: no upfront thinking, but progress notes
986
+ * between tool calls are returned as summarized thinking blocks.
987
+ * Only supported at `low`, `medium`, and `high` effort.
988
+ */
989
+ type: import_v43.z.literal("between_tools")
979
990
  })
980
991
  ]),
981
992
  /**
@@ -2402,6 +2413,7 @@ async function convertToAnthropicMessagesPrompt({
2402
2413
  const validator = cacheControlValidator || new CacheControlValidator();
2403
2414
  let system = void 0;
2404
2415
  const messages = [];
2416
+ let lastUserMessageIndex = -1;
2405
2417
  async function shouldEnableCitations(providerMetadata) {
2406
2418
  var _a2, _b2;
2407
2419
  const anthropicOptions = await (0, import_provider_utils15.parseProviderOptions)({
@@ -2513,6 +2525,9 @@ async function convertToAnthropicMessagesPrompt({
2513
2525
  const { role, content } = message;
2514
2526
  switch (role) {
2515
2527
  case "user": {
2528
+ if (content.length > 0) {
2529
+ lastUserMessageIndex = messages.length;
2530
+ }
2516
2531
  for (let j = 0; j < content.length; j++) {
2517
2532
  const part = content[j];
2518
2533
  const isLastPart = j === content.length - 1;
@@ -3297,6 +3312,42 @@ async function convertToAnthropicMessagesPrompt({
3297
3312
  }
3298
3313
  }
3299
3314
  }
3315
+ const codeExecutionToolCallIds = /* @__PURE__ */ new Set();
3316
+ for (const message of messages) {
3317
+ if (message.role !== "assistant") {
3318
+ continue;
3319
+ }
3320
+ for (const part of message.content) {
3321
+ if (part.type === "server_tool_use" && part.name === "code_execution") {
3322
+ codeExecutionToolCallIds.add(part.id);
3323
+ }
3324
+ }
3325
+ }
3326
+ const warnedToolCallIds = /* @__PURE__ */ new Set();
3327
+ for (let i = 0; i < lastUserMessageIndex; i++) {
3328
+ const message = messages[i];
3329
+ if (message.role !== "assistant") {
3330
+ continue;
3331
+ }
3332
+ for (const part of message.content) {
3333
+ if (!("caller" in part)) {
3334
+ continue;
3335
+ }
3336
+ const caller = part.caller;
3337
+ if (caller == null || caller.type === "direct" || codeExecutionToolCallIds.has(caller.tool_id)) {
3338
+ continue;
3339
+ }
3340
+ const toolCallId = "id" in part ? part.id : part.tool_use_id;
3341
+ delete part.caller;
3342
+ if (!warnedToolCallIds.has(toolCallId)) {
3343
+ warnedToolCallIds.add(toolCallId);
3344
+ warnings.push({
3345
+ type: "other",
3346
+ message: `Omitted caller metadata for tool ${toolCallId} because source code execution tool ${caller.tool_id} is missing from the conversation history.`
3347
+ });
3348
+ }
3349
+ }
3350
+ }
3300
3351
  return {
3301
3352
  prompt: { system, messages },
3302
3353
  betas
@@ -3740,6 +3791,7 @@ var AnthropicMessagesLanguageModel = class {
3740
3791
  rejectsThinkingDisabledAboveHighEffort,
3741
3792
  rejectsThinkingDisabled,
3742
3793
  rejectsForcedToolUse,
3794
+ supportsBetweenToolsThinking,
3743
3795
  isKnownModel
3744
3796
  } = getModelCapabilities(this.modelId);
3745
3797
  if (!isKnownModel && maxOutputTokens == null) {
@@ -3841,7 +3893,14 @@ var AnthropicMessagesLanguageModel = class {
3841
3893
  if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
3842
3894
  const requestedThinking = anthropicOptions.thinking;
3843
3895
  const requestedType = "type" in requestedThinking ? requestedThinking.type : void 0;
3844
- if (requestedType === "disabled") {
3896
+ if (requestedType === "disabled" && supportsBetweenToolsThinking) {
3897
+ warnings.push({
3898
+ type: "unsupported",
3899
+ feature: "providerOptions.anthropic.thinking",
3900
+ details: `thinking cannot be disabled for ${this.modelId}. Using 'between_tools' thinking, the lowest thinking setting, instead.`
3901
+ });
3902
+ anthropicOptions.thinking = { type: "between_tools" };
3903
+ } else if (requestedType === "disabled") {
3845
3904
  warnings.push({
3846
3905
  type: "unsupported",
3847
3906
  feature: "providerOptions.anthropic.thinking",
@@ -3867,7 +3926,15 @@ var AnthropicMessagesLanguageModel = class {
3867
3926
  });
3868
3927
  anthropicOptions.effort = "high";
3869
3928
  }
3870
- const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3929
+ if (thinkingType === "between_tools" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
3930
+ warnings.push({
3931
+ type: "unsupported",
3932
+ feature: "providerOptions.anthropic.effort",
3933
+ details: `effort '${anthropicOptions.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`
3934
+ });
3935
+ anthropicOptions.effort = "high";
3936
+ }
3937
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive" || thinkingType === "between_tools";
3871
3938
  const sendThinking = isThinking || thinkingType === "disabled";
3872
3939
  let thinkingBudget = thinkingType === "enabled" && thinking != null && "budgetTokens" in thinking ? thinking.budgetTokens : void 0;
3873
3940
  const thinkingDisplay = thinkingType === "adaptive" && thinking != null && "display" in thinking ? thinking.display : void 0;
@@ -5703,7 +5770,18 @@ var AnthropicMessagesLanguageModel = class {
5703
5770
  }
5704
5771
  };
5705
5772
  function getModelCapabilities(modelId) {
5706
- if (modelId.includes("claude-opus-5-5")) {
5773
+ if (modelId.includes("claude-sonnet-5-5")) {
5774
+ return {
5775
+ maxOutputTokens: 128e3,
5776
+ supportsStructuredOutput: true,
5777
+ rejectsSamplingParameters: true,
5778
+ rejectsThinkingDisabledAboveHighEffort: true,
5779
+ rejectsThinkingDisabled: true,
5780
+ rejectsForcedToolUse: true,
5781
+ supportsBetweenToolsThinking: true,
5782
+ isKnownModel: true
5783
+ };
5784
+ } else if (modelId.includes("claude-opus-5-5")) {
5707
5785
  return {
5708
5786
  maxOutputTokens: 128e3,
5709
5787
  supportsStructuredOutput: true,
@@ -5711,6 +5789,7 @@ function getModelCapabilities(modelId) {
5711
5789
  rejectsThinkingDisabledAboveHighEffort: true,
5712
5790
  rejectsThinkingDisabled: true,
5713
5791
  rejectsForcedToolUse: true,
5792
+ supportsBetweenToolsThinking: false,
5714
5793
  isKnownModel: true
5715
5794
  };
5716
5795
  } else if (modelId.includes("claude-opus-5")) {
@@ -5721,6 +5800,7 @@ function getModelCapabilities(modelId) {
5721
5800
  rejectsThinkingDisabledAboveHighEffort: true,
5722
5801
  rejectsThinkingDisabled: false,
5723
5802
  rejectsForcedToolUse: false,
5803
+ supportsBetweenToolsThinking: false,
5724
5804
  isKnownModel: true
5725
5805
  };
5726
5806
  } else if (modelId.includes("claude-fable-5-1")) {
@@ -5731,6 +5811,7 @@ function getModelCapabilities(modelId) {
5731
5811
  rejectsThinkingDisabledAboveHighEffort: false,
5732
5812
  rejectsThinkingDisabled: true,
5733
5813
  rejectsForcedToolUse: true,
5814
+ supportsBetweenToolsThinking: false,
5734
5815
  isKnownModel: true
5735
5816
  };
5736
5817
  } else if (modelId.includes("claude-fable-5")) {
@@ -5741,6 +5822,7 @@ function getModelCapabilities(modelId) {
5741
5822
  rejectsThinkingDisabledAboveHighEffort: false,
5742
5823
  rejectsThinkingDisabled: true,
5743
5824
  rejectsForcedToolUse: false,
5825
+ supportsBetweenToolsThinking: false,
5744
5826
  isKnownModel: true
5745
5827
  };
5746
5828
  } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-sonnet-5")) {
@@ -5751,6 +5833,7 @@ function getModelCapabilities(modelId) {
5751
5833
  rejectsThinkingDisabledAboveHighEffort: false,
5752
5834
  rejectsThinkingDisabled: false,
5753
5835
  rejectsForcedToolUse: false,
5836
+ supportsBetweenToolsThinking: false,
5754
5837
  isKnownModel: true
5755
5838
  };
5756
5839
  } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
@@ -5761,6 +5844,7 @@ function getModelCapabilities(modelId) {
5761
5844
  rejectsThinkingDisabledAboveHighEffort: false,
5762
5845
  rejectsThinkingDisabled: false,
5763
5846
  rejectsForcedToolUse: false,
5847
+ supportsBetweenToolsThinking: false,
5764
5848
  isKnownModel: true
5765
5849
  };
5766
5850
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
@@ -5771,6 +5855,7 @@ function getModelCapabilities(modelId) {
5771
5855
  rejectsThinkingDisabledAboveHighEffort: false,
5772
5856
  rejectsThinkingDisabled: false,
5773
5857
  rejectsForcedToolUse: false,
5858
+ supportsBetweenToolsThinking: false,
5774
5859
  isKnownModel: true
5775
5860
  };
5776
5861
  } else if (modelId.includes("claude-opus-4-1")) {
@@ -5781,6 +5866,7 @@ function getModelCapabilities(modelId) {
5781
5866
  rejectsThinkingDisabledAboveHighEffort: false,
5782
5867
  rejectsThinkingDisabled: false,
5783
5868
  rejectsForcedToolUse: false,
5869
+ supportsBetweenToolsThinking: false,
5784
5870
  isKnownModel: true
5785
5871
  };
5786
5872
  } else if (modelId.includes("claude-sonnet-4-")) {
@@ -5791,6 +5877,7 @@ function getModelCapabilities(modelId) {
5791
5877
  rejectsThinkingDisabledAboveHighEffort: false,
5792
5878
  rejectsThinkingDisabled: false,
5793
5879
  rejectsForcedToolUse: false,
5880
+ supportsBetweenToolsThinking: false,
5794
5881
  isKnownModel: true
5795
5882
  };
5796
5883
  } else if (modelId.includes("claude-opus-4-")) {
@@ -5801,6 +5888,7 @@ function getModelCapabilities(modelId) {
5801
5888
  rejectsThinkingDisabledAboveHighEffort: false,
5802
5889
  rejectsThinkingDisabled: false,
5803
5890
  rejectsForcedToolUse: false,
5891
+ supportsBetweenToolsThinking: false,
5804
5892
  isKnownModel: true
5805
5893
  };
5806
5894
  } else if (modelId.includes("claude-3-haiku")) {
@@ -5811,6 +5899,7 @@ function getModelCapabilities(modelId) {
5811
5899
  rejectsThinkingDisabledAboveHighEffort: false,
5812
5900
  rejectsThinkingDisabled: false,
5813
5901
  rejectsForcedToolUse: false,
5902
+ supportsBetweenToolsThinking: false,
5814
5903
  isKnownModel: true
5815
5904
  };
5816
5905
  } else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
@@ -5821,6 +5910,7 @@ function getModelCapabilities(modelId) {
5821
5910
  rejectsThinkingDisabledAboveHighEffort: false,
5822
5911
  rejectsThinkingDisabled: false,
5823
5912
  rejectsForcedToolUse: false,
5913
+ supportsBetweenToolsThinking: false,
5824
5914
  isKnownModel: false
5825
5915
  };
5826
5916
  } else if (modelId.includes("claude-")) {
@@ -5831,6 +5921,7 @@ function getModelCapabilities(modelId) {
5831
5921
  rejectsThinkingDisabledAboveHighEffort: true,
5832
5922
  rejectsThinkingDisabled: false,
5833
5923
  rejectsForcedToolUse: false,
5924
+ supportsBetweenToolsThinking: false,
5834
5925
  isKnownModel: false
5835
5926
  };
5836
5927
  } else {
@@ -5841,6 +5932,7 @@ function getModelCapabilities(modelId) {
5841
5932
  rejectsThinkingDisabledAboveHighEffort: false,
5842
5933
  rejectsThinkingDisabled: false,
5843
5934
  rejectsForcedToolUse: false,
5935
+ supportsBetweenToolsThinking: false,
5844
5936
  isKnownModel: false
5845
5937
  };
5846
5938
  }