@ai-sdk/anthropic 4.0.0-beta.3 → 4.0.0-beta.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "4.0.0-beta.3",
3
+ "version": "4.0.0-beta.5",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -36,8 +36,8 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@ai-sdk/provider": "4.0.0-beta.0",
40
- "@ai-sdk/provider-utils": "5.0.0-beta.1"
39
+ "@ai-sdk/provider": "4.0.0-beta.1",
40
+ "@ai-sdk/provider-utils": "5.0.0-beta.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "20.17.24",
@@ -129,6 +129,12 @@ type AnthropicMessagesConfig = {
129
129
  * When false, the model will use JSON tool fallback for structured outputs.
130
130
  */
131
131
  supportsNativeStructuredOutput?: boolean;
132
+
133
+ /**
134
+ * When false, `strict` on tool definitions will be ignored and a warning emitted.
135
+ * Defaults to true.
136
+ */
137
+ supportsStrictTools?: boolean;
132
138
  };
133
139
 
134
140
  export class AnthropicMessagesLanguageModel implements LanguageModelV4 {
@@ -270,6 +276,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV4 {
270
276
  (this.config.supportsNativeStructuredOutput ?? true) &&
271
277
  modelSupportsStructuredOutput;
272
278
 
279
+ const supportsStrictTools =
280
+ (this.config.supportsStrictTools ?? true) &&
281
+ modelSupportsStructuredOutput;
282
+
273
283
  const structureOutputMode =
274
284
  anthropicOptions?.structuredOutputMode ?? 'auto';
275
285
  const useStructuredOutput =
@@ -614,6 +624,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV4 {
614
624
  disableParallelToolUse: true,
615
625
  cacheControlValidator,
616
626
  supportsStructuredOutput: false,
627
+ supportsStrictTools,
617
628
  }
618
629
  : {
619
630
  tools: tools ?? [],
@@ -621,6 +632,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV4 {
621
632
  disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
622
633
  cacheControlValidator,
623
634
  supportsStructuredOutput,
635
+ supportsStrictTools,
624
636
  },
625
637
  );
626
638
 
@@ -26,6 +26,7 @@ export async function prepareTools({
26
26
  disableParallelToolUse,
27
27
  cacheControlValidator,
28
28
  supportsStructuredOutput,
29
+ supportsStrictTools,
29
30
  }: {
30
31
  tools: LanguageModelV4CallOptions['tools'];
31
32
  toolChoice: LanguageModelV4CallOptions['toolChoice'] | undefined;
@@ -33,9 +34,14 @@ export async function prepareTools({
33
34
  cacheControlValidator?: CacheControlValidator;
34
35
 
35
36
  /**
36
- * Whether the model supports structured output.
37
+ * Whether the model supports native structured output response format.
37
38
  */
38
39
  supportsStructuredOutput: boolean;
40
+
41
+ /**
42
+ * Whether the model supports strict mode on tool definitions.
43
+ */
44
+ supportsStrictTools: boolean;
39
45
  }): Promise<{
40
46
  tools: Array<AnthropicTool> | undefined;
41
47
  toolChoice: AnthropicToolChoice | undefined;
@@ -72,13 +78,21 @@ export async function prepareTools({
72
78
  const deferLoading = anthropicOptions?.deferLoading;
73
79
  const allowedCallers = anthropicOptions?.allowedCallers;
74
80
 
81
+ if (!supportsStrictTools && tool.strict != null) {
82
+ toolWarnings.push({
83
+ type: 'unsupported',
84
+ feature: 'strict',
85
+ details: `Tool '${tool.name}' has strict: ${tool.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`,
86
+ });
87
+ }
88
+
75
89
  anthropicTools.push({
76
90
  name: tool.name,
77
91
  description: tool.description,
78
92
  input_schema: tool.inputSchema,
79
93
  cache_control: cacheControl,
80
94
  ...(eagerInputStreaming ? { eager_input_streaming: true } : {}),
81
- ...(supportsStructuredOutput === true && tool.strict != null
95
+ ...(supportsStrictTools === true && tool.strict != null
82
96
  ? { strict: tool.strict }
83
97
  : {}),
84
98
  ...(deferLoading != null ? { defer_loading: deferLoading } : {}),