@ai-sdk/anthropic 3.0.0-beta.56 → 3.0.0-beta.58

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 ? "3.0.0-beta.56" : "0.0.0-test";
14
+ var VERSION = true ? "3.0.0-beta.58" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
@@ -587,6 +587,14 @@ var anthropicProviderOptions = z3.object({
587
587
  * This allows you to deactivate reasoning inputs for models that do not support them.
588
588
  */
589
589
  sendReasoning: z3.boolean().optional(),
590
+ /**
591
+ * Determines how structured outputs are generated.
592
+ *
593
+ * - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
594
+ * - `jsonTool`: Use a special 'json' tool to specify the structured output format.
595
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default).
596
+ */
597
+ structuredOutputMode: z3.enum(["outputFormat", "jsonTool", "auto"]).optional(),
590
598
  /**
591
599
  * Configuration for enabling Claude's extended thinking.
592
600
  *
@@ -648,7 +656,11 @@ var anthropicProviderOptions = z3.object({
648
656
  *
649
657
  * @default true
650
658
  */
651
- toolStreaming: z3.boolean().optional()
659
+ toolStreaming: z3.boolean().optional(),
660
+ /**
661
+ * @default 'high'
662
+ */
663
+ effort: z3.enum(["low", "medium", "high"]).optional()
652
664
  });
653
665
 
654
666
  // src/anthropic-prepare-tools.ts
@@ -1925,7 +1937,7 @@ var AnthropicMessagesLanguageModel = class {
1925
1937
  providerOptions,
1926
1938
  stream
1927
1939
  }) {
1928
- var _a, _b, _c, _d, _e;
1940
+ var _a, _b, _c, _d, _e, _f;
1929
1941
  const warnings = [];
1930
1942
  if (frequencyPenalty != null) {
1931
1943
  warnings.push({
@@ -1969,27 +1981,33 @@ var AnthropicMessagesLanguageModel = class {
1969
1981
  });
1970
1982
  }
1971
1983
  }
1972
- const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
1973
- type: "function",
1974
- name: "json",
1975
- description: "Respond with a JSON object.",
1976
- inputSchema: responseFormat.schema
1977
- } : void 0;
1978
1984
  const anthropicOptions = await parseProviderOptions2({
1979
1985
  provider: "anthropic",
1980
1986
  providerOptions,
1981
1987
  schema: anthropicProviderOptions
1982
1988
  });
1989
+ const {
1990
+ maxOutputTokens: maxOutputTokensForModel,
1991
+ supportsStructuredOutput,
1992
+ isKnownModel
1993
+ } = getModelCapabilities(this.modelId);
1994
+ const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "auto";
1995
+ const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
1996
+ const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
1997
+ type: "function",
1998
+ name: "json",
1999
+ description: "Respond with a JSON object.",
2000
+ inputSchema: responseFormat.schema
2001
+ } : void 0;
1983
2002
  const cacheControlValidator = new CacheControlValidator();
1984
2003
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1985
2004
  prompt,
1986
- sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
2005
+ sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
1987
2006
  warnings,
1988
2007
  cacheControlValidator
1989
2008
  });
1990
- const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
1991
- const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
1992
- const { maxOutputTokens: maxOutputTokensForModel, knownModel } = getMaxOutputTokensForModel(this.modelId);
2009
+ const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
2010
+ const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
1993
2011
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
1994
2012
  const baseArgs = {
1995
2013
  // model id:
@@ -2004,6 +2022,16 @@ var AnthropicMessagesLanguageModel = class {
2004
2022
  ...isThinking && {
2005
2023
  thinking: { type: "enabled", budget_tokens: thinkingBudget }
2006
2024
  },
2025
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
2026
+ output_config: { effort: anthropicOptions.effort }
2027
+ },
2028
+ // structured output:
2029
+ ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
2030
+ output_format: {
2031
+ type: "json_schema",
2032
+ schema: responseFormat.schema
2033
+ }
2034
+ },
2007
2035
  // mcp servers:
2008
2036
  ...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
2009
2037
  mcp_servers: anthropicOptions.mcpServers.map((server) => ({
@@ -2021,7 +2049,7 @@ var AnthropicMessagesLanguageModel = class {
2021
2049
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2022
2050
  container: {
2023
2051
  id: anthropicOptions.container.id,
2024
- skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
2052
+ skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
2025
2053
  type: skill.type,
2026
2054
  skill_id: skill.skillId,
2027
2055
  version: skill.version
@@ -2064,7 +2092,7 @@ var AnthropicMessagesLanguageModel = class {
2064
2092
  }
2065
2093
  baseArgs.max_tokens = maxTokens + thinkingBudget;
2066
2094
  }
2067
- if (knownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
2095
+ if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
2068
2096
  if (maxOutputTokens != null) {
2069
2097
  warnings.push({
2070
2098
  type: "unsupported-setting",
@@ -2090,9 +2118,15 @@ var AnthropicMessagesLanguageModel = class {
2090
2118
  });
2091
2119
  }
2092
2120
  }
2093
- if (stream && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _e : true)) {
2121
+ if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2122
+ betas.add("effort-2025-11-24");
2123
+ }
2124
+ if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
2094
2125
  betas.add("fine-grained-tool-streaming-2025-05-14");
2095
2126
  }
2127
+ if (useStructuredOutput) {
2128
+ betas.add("structured-outputs-2025-11-13");
2129
+ }
2096
2130
  const {
2097
2131
  tools: anthropicTools2,
2098
2132
  toolChoice: anthropicToolChoice,
@@ -2969,17 +3003,49 @@ var AnthropicMessagesLanguageModel = class {
2969
3003
  };
2970
3004
  }
2971
3005
  };
2972
- function getMaxOutputTokensForModel(modelId) {
2973
- if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
2974
- return { maxOutputTokens: 64e3, knownModel: true };
3006
+ function getModelCapabilities(modelId) {
3007
+ if (modelId.includes("claude-sonnet-4-5")) {
3008
+ return {
3009
+ maxOutputTokens: 64e3,
3010
+ supportsStructuredOutput: true,
3011
+ isKnownModel: true
3012
+ };
3013
+ } else if (modelId.includes("claude-opus-4-1") || modelId.includes("claude-opus-4-5")) {
3014
+ return {
3015
+ maxOutputTokens: 32e3,
3016
+ supportsStructuredOutput: true,
3017
+ isKnownModel: true
3018
+ };
3019
+ } else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
3020
+ return {
3021
+ maxOutputTokens: 64e3,
3022
+ supportsStructuredOutput: false,
3023
+ isKnownModel: true
3024
+ };
2975
3025
  } else if (modelId.includes("claude-opus-4-")) {
2976
- return { maxOutputTokens: 32e3, knownModel: true };
3026
+ return {
3027
+ maxOutputTokens: 32e3,
3028
+ supportsStructuredOutput: false,
3029
+ isKnownModel: true
3030
+ };
2977
3031
  } else if (modelId.includes("claude-3-5-haiku")) {
2978
- return { maxOutputTokens: 8192, knownModel: true };
3032
+ return {
3033
+ maxOutputTokens: 8192,
3034
+ supportsStructuredOutput: false,
3035
+ isKnownModel: true
3036
+ };
2979
3037
  } else if (modelId.includes("claude-3-haiku")) {
2980
- return { maxOutputTokens: 4096, knownModel: true };
3038
+ return {
3039
+ maxOutputTokens: 4096,
3040
+ supportsStructuredOutput: false,
3041
+ isKnownModel: true
3042
+ };
2981
3043
  } else {
2982
- return { maxOutputTokens: 4096, knownModel: false };
3044
+ return {
3045
+ maxOutputTokens: 4096,
3046
+ supportsStructuredOutput: false,
3047
+ isKnownModel: false
3048
+ };
2983
3049
  }
2984
3050
  }
2985
3051