@ai-sdk/anthropic 3.0.59 → 3.0.61

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.
@@ -17,6 +17,11 @@ type AnthropicMessagesConfig = {
17
17
  * When false, the model will use JSON tool fallback for structured outputs.
18
18
  */
19
19
  supportsNativeStructuredOutput?: boolean;
20
+ /**
21
+ * When false, `strict` on tool definitions will be ignored and a warning emitted.
22
+ * Defaults to true.
23
+ */
24
+ supportsStrictTools?: boolean;
20
25
  };
21
26
  declare class AnthropicMessagesLanguageModel implements LanguageModelV3 {
22
27
  readonly specificationVersion = "v3";
@@ -941,15 +946,19 @@ declare class CacheControlValidator {
941
946
  getWarnings(): SharedV3Warning[];
942
947
  }
943
948
 
944
- declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, }: {
949
+ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, }: {
945
950
  tools: LanguageModelV3CallOptions['tools'];
946
951
  toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
947
952
  disableParallelToolUse?: boolean;
948
953
  cacheControlValidator?: CacheControlValidator;
949
954
  /**
950
- * Whether the model supports structured output.
955
+ * Whether the model supports native structured output response format.
951
956
  */
952
957
  supportsStructuredOutput: boolean;
958
+ /**
959
+ * Whether the model supports strict mode on tool definitions.
960
+ */
961
+ supportsStrictTools: boolean;
953
962
  }): Promise<{
954
963
  tools: Array<AnthropicTool> | undefined;
955
964
  toolChoice: AnthropicToolChoice | undefined;
@@ -17,6 +17,11 @@ type AnthropicMessagesConfig = {
17
17
  * When false, the model will use JSON tool fallback for structured outputs.
18
18
  */
19
19
  supportsNativeStructuredOutput?: boolean;
20
+ /**
21
+ * When false, `strict` on tool definitions will be ignored and a warning emitted.
22
+ * Defaults to true.
23
+ */
24
+ supportsStrictTools?: boolean;
20
25
  };
21
26
  declare class AnthropicMessagesLanguageModel implements LanguageModelV3 {
22
27
  readonly specificationVersion = "v3";
@@ -941,15 +946,19 @@ declare class CacheControlValidator {
941
946
  getWarnings(): SharedV3Warning[];
942
947
  }
943
948
 
944
- declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, }: {
949
+ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, }: {
945
950
  tools: LanguageModelV3CallOptions['tools'];
946
951
  toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
947
952
  disableParallelToolUse?: boolean;
948
953
  cacheControlValidator?: CacheControlValidator;
949
954
  /**
950
- * Whether the model supports structured output.
955
+ * Whether the model supports native structured output response format.
951
956
  */
952
957
  supportsStructuredOutput: boolean;
958
+ /**
959
+ * Whether the model supports strict mode on tool definitions.
960
+ */
961
+ supportsStrictTools: boolean;
953
962
  }): Promise<{
954
963
  tools: Array<AnthropicTool> | undefined;
955
964
  toolChoice: AnthropicToolChoice | undefined;
@@ -18,13 +18,13 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/internal/index.ts
21
- var internal_exports = {};
22
- __export(internal_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  AnthropicMessagesLanguageModel: () => AnthropicMessagesLanguageModel,
24
24
  anthropicTools: () => anthropicTools,
25
25
  prepareTools: () => prepareTools
26
26
  });
27
- module.exports = __toCommonJS(internal_exports);
27
+ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/anthropic-messages-language-model.ts
30
30
  var import_provider3 = require("@ai-sdk/provider");
@@ -1261,7 +1261,8 @@ async function prepareTools({
1261
1261
  toolChoice,
1262
1262
  disableParallelToolUse,
1263
1263
  cacheControlValidator,
1264
- supportsStructuredOutput
1264
+ supportsStructuredOutput,
1265
+ supportsStrictTools
1265
1266
  }) {
1266
1267
  var _a;
1267
1268
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
@@ -1283,13 +1284,20 @@ async function prepareTools({
1283
1284
  const eagerInputStreaming = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming;
1284
1285
  const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1285
1286
  const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1287
+ if (!supportsStrictTools && tool.strict != null) {
1288
+ toolWarnings.push({
1289
+ type: "unsupported",
1290
+ feature: "strict",
1291
+ details: `Tool '${tool.name}' has strict: ${tool.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`
1292
+ });
1293
+ }
1286
1294
  anthropicTools2.push({
1287
1295
  name: tool.name,
1288
1296
  description: tool.description,
1289
1297
  input_schema: tool.inputSchema,
1290
1298
  cache_control: cacheControl,
1291
1299
  ...eagerInputStreaming ? { eager_input_streaming: true } : {},
1292
- ...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {},
1300
+ ...supportsStrictTools === true && tool.strict != null ? { strict: tool.strict } : {},
1293
1301
  ...deferLoading != null ? { defer_loading: deferLoading } : {},
1294
1302
  ...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
1295
1303
  ...tool.inputExamples != null ? {
@@ -2579,7 +2587,7 @@ async function convertToAnthropicMessagesPrompt({
2579
2587
  } catch (e) {
2580
2588
  const extractedErrorCode = (_r = output.value) == null ? void 0 : _r.errorCode;
2581
2589
  errorValue = {
2582
- errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unknown"
2590
+ errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
2583
2591
  };
2584
2592
  }
2585
2593
  anthropicContent.push({
@@ -2587,7 +2595,7 @@ async function convertToAnthropicMessagesPrompt({
2587
2595
  tool_use_id: part.toolCallId,
2588
2596
  content: {
2589
2597
  type: "web_fetch_tool_result_error",
2590
- error_code: (_s = errorValue.errorCode) != null ? _s : "unknown"
2598
+ error_code: (_s = errorValue.errorCode) != null ? _s : "unavailable"
2591
2599
  },
2592
2600
  cache_control: cacheControl
2593
2601
  });
@@ -2864,7 +2872,7 @@ var AnthropicMessagesLanguageModel = class {
2864
2872
  providerOptions,
2865
2873
  stream
2866
2874
  }) {
2867
- var _a, _b, _c, _d, _e, _f, _g;
2875
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2868
2876
  const warnings = [];
2869
2877
  if (frequencyPenalty != null) {
2870
2878
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2922,7 +2930,8 @@ var AnthropicMessagesLanguageModel = class {
2922
2930
  isKnownModel
2923
2931
  } = getModelCapabilities(this.modelId);
2924
2932
  const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
2925
- const structureOutputMode = (_b = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _b : "auto";
2933
+ const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
2934
+ const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
2926
2935
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2927
2936
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
2928
2937
  type: "function",
@@ -2957,14 +2966,14 @@ var AnthropicMessagesLanguageModel = class {
2957
2966
  });
2958
2967
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
2959
2968
  prompt,
2960
- sendReasoning: (_c = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _c : true,
2969
+ sendReasoning: (_d = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _d : true,
2961
2970
  warnings,
2962
2971
  cacheControlValidator,
2963
2972
  toolNameMapping
2964
2973
  });
2965
- const thinkingType = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type;
2974
+ const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
2966
2975
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2967
- let thinkingBudget = thinkingType === "enabled" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.budgetTokens : void 0;
2976
+ let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
2968
2977
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2969
2978
  const baseArgs = {
2970
2979
  // model id:
@@ -3171,7 +3180,7 @@ var AnthropicMessagesLanguageModel = class {
3171
3180
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3172
3181
  betas.add("fast-mode-2026-02-01");
3173
3182
  }
3174
- if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
3183
+ if (stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true)) {
3175
3184
  betas.add("fine-grained-tool-streaming-2025-05-14");
3176
3185
  }
3177
3186
  const {
@@ -3185,13 +3194,15 @@ var AnthropicMessagesLanguageModel = class {
3185
3194
  toolChoice: { type: "required" },
3186
3195
  disableParallelToolUse: true,
3187
3196
  cacheControlValidator,
3188
- supportsStructuredOutput: false
3197
+ supportsStructuredOutput: false,
3198
+ supportsStrictTools
3189
3199
  } : {
3190
3200
  tools: tools != null ? tools : [],
3191
3201
  toolChoice,
3192
3202
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
3193
3203
  cacheControlValidator,
3194
- supportsStructuredOutput
3204
+ supportsStructuredOutput,
3205
+ supportsStrictTools
3195
3206
  }
3196
3207
  );
3197
3208
  const cacheWarnings = cacheControlValidator.getWarnings();
@@ -3208,7 +3219,7 @@ var AnthropicMessagesLanguageModel = class {
3208
3219
  ...betas,
3209
3220
  ...toolsBetas,
3210
3221
  ...userSuppliedBetas,
3211
- ...(_g = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _g : []
3222
+ ...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
3212
3223
  ]),
3213
3224
  usesJsonResponseTool: jsonResponseTool != null,
3214
3225
  toolNameMapping,