@ai-sdk/anthropic 3.0.35 → 3.0.37

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,17 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.37
4
+
5
+ ### Patch Changes
6
+
7
+ - e288302: feat(anthropic): add support for Opus 4.6
8
+
9
+ ## 3.0.36
10
+
11
+ ### Patch Changes
12
+
13
+ - 1652320: feat(anthropic): support custom tool-reference content for deferred tool loading
14
+
3
15
  ## 3.0.35
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -94,7 +94,7 @@ interface AnthropicMessageMetadata {
94
94
  } | null;
95
95
  }
96
96
 
97
- type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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' | (string & {});
97
+ type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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-opus-4-6' | (string & {});
98
98
  declare const anthropicProviderOptions: z.ZodObject<{
99
99
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
100
100
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -102,10 +102,14 @@ declare const anthropicProviderOptions: z.ZodObject<{
102
102
  jsonTool: "jsonTool";
103
103
  auto: "auto";
104
104
  }>>;
105
- thinking: z.ZodOptional<z.ZodObject<{
106
- type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
105
+ thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
106
+ type: z.ZodLiteral<"adaptive">;
107
+ }, z.core.$strip>, z.ZodObject<{
108
+ type: z.ZodLiteral<"enabled">;
107
109
  budgetTokens: z.ZodOptional<z.ZodNumber>;
108
- }, z.core.$strip>>;
110
+ }, z.core.$strip>, z.ZodObject<{
111
+ type: z.ZodLiteral<"disabled">;
112
+ }, z.core.$strip>]>>;
109
113
  disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
110
114
  cacheControl: z.ZodOptional<z.ZodObject<{
111
115
  type: z.ZodLiteral<"ephemeral">;
@@ -134,6 +138,7 @@ declare const anthropicProviderOptions: z.ZodObject<{
134
138
  low: "low";
135
139
  medium: "medium";
136
140
  high: "high";
141
+ max: "max";
137
142
  }>>;
138
143
  contextManagement: z.ZodOptional<z.ZodObject<{
139
144
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
package/dist/index.d.ts CHANGED
@@ -94,7 +94,7 @@ interface AnthropicMessageMetadata {
94
94
  } | null;
95
95
  }
96
96
 
97
- type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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' | (string & {});
97
+ type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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-opus-4-6' | (string & {});
98
98
  declare const anthropicProviderOptions: z.ZodObject<{
99
99
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
100
100
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -102,10 +102,14 @@ declare const anthropicProviderOptions: z.ZodObject<{
102
102
  jsonTool: "jsonTool";
103
103
  auto: "auto";
104
104
  }>>;
105
- thinking: z.ZodOptional<z.ZodObject<{
106
- type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
105
+ thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
106
+ type: z.ZodLiteral<"adaptive">;
107
+ }, z.core.$strip>, z.ZodObject<{
108
+ type: z.ZodLiteral<"enabled">;
107
109
  budgetTokens: z.ZodOptional<z.ZodNumber>;
108
- }, z.core.$strip>>;
110
+ }, z.core.$strip>, z.ZodObject<{
111
+ type: z.ZodLiteral<"disabled">;
112
+ }, z.core.$strip>]>>;
109
113
  disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
110
114
  cacheControl: z.ZodOptional<z.ZodObject<{
111
115
  type: z.ZodLiteral<"ephemeral">;
@@ -134,6 +138,7 @@ declare const anthropicProviderOptions: z.ZodObject<{
134
138
  low: "low";
135
139
  medium: "medium";
136
140
  high: "high";
141
+ max: "max";
137
142
  }>>;
138
143
  contextManagement: z.ZodOptional<z.ZodObject<{
139
144
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils23 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.35" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.37" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -756,10 +756,20 @@ var anthropicProviderOptions = import_v43.z.object({
756
756
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
757
757
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
758
758
  */
759
- thinking: import_v43.z.object({
760
- type: import_v43.z.union([import_v43.z.literal("enabled"), import_v43.z.literal("disabled")]),
761
- budgetTokens: import_v43.z.number().optional()
762
- }).optional(),
759
+ thinking: import_v43.z.discriminatedUnion("type", [
760
+ import_v43.z.object({
761
+ /** for Opus 4.6 and newer models */
762
+ type: import_v43.z.literal("adaptive")
763
+ }),
764
+ import_v43.z.object({
765
+ /** for models before Opus 4.6 */
766
+ type: import_v43.z.literal("enabled"),
767
+ budgetTokens: import_v43.z.number().optional()
768
+ }),
769
+ import_v43.z.object({
770
+ type: import_v43.z.literal("disabled")
771
+ })
772
+ ]).optional(),
763
773
  /**
764
774
  * Whether to disable parallel function calling during tool use. Default is false.
765
775
  * When set to true, Claude will use at most one tool per response.
@@ -815,7 +825,7 @@ var anthropicProviderOptions = import_v43.z.object({
815
825
  /**
816
826
  * @default 'high'
817
827
  */
818
- effort: import_v43.z.enum(["low", "medium", "high"]).optional(),
828
+ effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional(),
819
829
  contextManagement: import_v43.z.object({
820
830
  edits: import_v43.z.array(
821
831
  import_v43.z.discriminatedUnion("type", [
@@ -1747,6 +1757,7 @@ async function convertToAnthropicMessagesPrompt({
1747
1757
  switch (output.type) {
1748
1758
  case "content":
1749
1759
  contentValue = output.value.map((contentPart) => {
1760
+ var _a2;
1750
1761
  switch (contentPart.type) {
1751
1762
  case "text":
1752
1763
  return {
@@ -1799,6 +1810,20 @@ async function convertToAnthropicMessagesPrompt({
1799
1810
  });
1800
1811
  return void 0;
1801
1812
  }
1813
+ case "custom": {
1814
+ const anthropicOptions = (_a2 = contentPart.providerOptions) == null ? void 0 : _a2.anthropic;
1815
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.type) === "tool-reference") {
1816
+ return {
1817
+ type: "tool_reference",
1818
+ tool_name: anthropicOptions.toolName
1819
+ };
1820
+ }
1821
+ warnings.push({
1822
+ type: "other",
1823
+ message: `unsupported custom tool content part`
1824
+ });
1825
+ return void 0;
1826
+ }
1802
1827
  default: {
1803
1828
  warnings.push({
1804
1829
  type: "other",
@@ -2523,8 +2548,9 @@ var AnthropicMessagesLanguageModel = class {
2523
2548
  cacheControlValidator,
2524
2549
  toolNameMapping
2525
2550
  });
2526
- const isThinking = ((_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type) === "enabled";
2527
- let thinkingBudget = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.budgetTokens;
2551
+ const thinkingType = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type;
2552
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2553
+ let thinkingBudget = thinkingType === "enabled" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.budgetTokens : void 0;
2528
2554
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2529
2555
  const baseArgs = {
2530
2556
  // model id:
@@ -2537,7 +2563,10 @@ var AnthropicMessagesLanguageModel = class {
2537
2563
  stop_sequences: stopSequences,
2538
2564
  // provider specific settings:
2539
2565
  ...isThinking && {
2540
- thinking: { type: "enabled", budget_tokens: thinkingBudget }
2566
+ thinking: {
2567
+ type: thinkingType,
2568
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget }
2569
+ }
2541
2570
  },
2542
2571
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
2543
2572
  output_config: { effort: anthropicOptions.effort }
@@ -2621,7 +2650,7 @@ var AnthropicMessagesLanguageModel = class {
2621
2650
  }
2622
2651
  };
2623
2652
  if (isThinking) {
2624
- if (thinkingBudget == null) {
2653
+ if (thinkingType === "enabled" && thinkingBudget == null) {
2625
2654
  warnings.push({
2626
2655
  type: "compatibility",
2627
2656
  feature: "extended thinking",
@@ -3907,7 +3936,13 @@ var AnthropicMessagesLanguageModel = class {
3907
3936
  }
3908
3937
  };
3909
3938
  function getModelCapabilities(modelId) {
3910
- if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
3939
+ if (modelId.includes("claude-opus-4-6")) {
3940
+ return {
3941
+ maxOutputTokens: 128e3,
3942
+ supportsStructuredOutput: true,
3943
+ isKnownModel: true
3944
+ };
3945
+ } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
3911
3946
  return {
3912
3947
  maxOutputTokens: 64e3,
3913
3948
  supportsStructuredOutput: true,