@ai-sdk/anthropic 2.0.58 → 2.0.59

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.
@@ -2,7 +2,7 @@ import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2
2
2
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
3
  import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
- 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 & {});
5
+ 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 & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -2,7 +2,7 @@ import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2
2
2
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
3
  import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
- 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 & {});
5
+ 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 & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -575,10 +575,20 @@ var anthropicProviderOptions = import_v43.z.object({
575
575
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
576
576
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
577
577
  */
578
- thinking: import_v43.z.object({
579
- type: import_v43.z.union([import_v43.z.literal("enabled"), import_v43.z.literal("disabled")]),
580
- budgetTokens: import_v43.z.number().optional()
581
- }).optional(),
578
+ thinking: import_v43.z.discriminatedUnion("type", [
579
+ import_v43.z.object({
580
+ /** for Opus 4.6 and newer models */
581
+ type: import_v43.z.literal("adaptive")
582
+ }),
583
+ import_v43.z.object({
584
+ /** for models before Opus 4.6 */
585
+ type: import_v43.z.literal("enabled"),
586
+ budgetTokens: import_v43.z.number().optional()
587
+ }),
588
+ import_v43.z.object({
589
+ type: import_v43.z.literal("disabled")
590
+ })
591
+ ]).optional(),
582
592
  /**
583
593
  * Whether to disable parallel function calling during tool use. Default is false.
584
594
  * When set to true, Claude will use at most one tool per response.
@@ -610,7 +620,7 @@ var anthropicProviderOptions = import_v43.z.object({
610
620
  /**
611
621
  * @default 'high'
612
622
  */
613
- effort: import_v43.z.enum(["low", "medium", "high"]).optional()
623
+ effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional()
614
624
  });
615
625
 
616
626
  // src/anthropic-prepare-tools.ts
@@ -1868,8 +1878,9 @@ var AnthropicMessagesLanguageModel = class {
1868
1878
  warnings,
1869
1879
  cacheControlValidator
1870
1880
  });
1871
- const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1872
- const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
1881
+ const thinkingType = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type;
1882
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
1883
+ let thinkingBudget = thinkingType === "enabled" ? (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens : void 0;
1873
1884
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
1874
1885
  const baseArgs = {
1875
1886
  // model id:
@@ -1882,7 +1893,10 @@ var AnthropicMessagesLanguageModel = class {
1882
1893
  stop_sequences: stopSequences,
1883
1894
  // provider specific settings:
1884
1895
  ...isThinking && {
1885
- thinking: { type: "enabled", budget_tokens: thinkingBudget }
1896
+ thinking: {
1897
+ type: thinkingType,
1898
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget }
1899
+ }
1886
1900
  },
1887
1901
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
1888
1902
  output_config: { effort: anthropicOptions.effort }
@@ -1910,7 +1924,7 @@ var AnthropicMessagesLanguageModel = class {
1910
1924
  messages: messagesPrompt.messages
1911
1925
  };
1912
1926
  if (isThinking) {
1913
- if (thinkingBudget == null) {
1927
+ if (thinkingType === "enabled" && thinkingBudget == null) {
1914
1928
  throw new import_provider3.UnsupportedFunctionalityError({
1915
1929
  functionality: "thinking requires a budget"
1916
1930
  });
@@ -1939,7 +1953,7 @@ var AnthropicMessagesLanguageModel = class {
1939
1953
  details: "topP is not supported when thinking is enabled"
1940
1954
  });
1941
1955
  }
1942
- baseArgs.max_tokens = maxTokens + thinkingBudget;
1956
+ baseArgs.max_tokens = maxTokens + (thinkingBudget != null ? thinkingBudget : 0);
1943
1957
  }
1944
1958
  if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
1945
1959
  if (maxOutputTokens != null) {
@@ -2828,7 +2842,13 @@ var AnthropicMessagesLanguageModel = class {
2828
2842
  }
2829
2843
  };
2830
2844
  function getModelCapabilities(modelId) {
2831
- if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
2845
+ if (modelId.includes("claude-opus-4-6")) {
2846
+ return {
2847
+ maxOutputTokens: 128e3,
2848
+ supportsStructuredOutput: true,
2849
+ isKnownModel: true
2850
+ };
2851
+ } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
2832
2852
  return {
2833
2853
  maxOutputTokens: 64e3,
2834
2854
  supportsStructuredOutput: true,