@ai-sdk/anthropic 2.0.0-beta.7 → 2.0.0-beta.9

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
@@ -68,7 +68,12 @@ var anthropicProviderOptions = z2.object({
68
68
  thinking: z2.object({
69
69
  type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
70
70
  budgetTokens: z2.number().optional()
71
- }).optional()
71
+ }).optional(),
72
+ /**
73
+ * Whether to disable parallel function calling during tool use. Default is false.
74
+ * When set to true, Claude will use at most one tool per response.
75
+ */
76
+ disableParallelToolUse: z2.boolean().optional()
72
77
  });
73
78
 
74
79
  // src/anthropic-prepare-tools.ts
@@ -76,6 +81,14 @@ import {
76
81
  UnsupportedFunctionalityError
77
82
  } from "@ai-sdk/provider";
78
83
 
84
+ // src/get-cache-control.ts
85
+ function getCacheControl(providerMetadata) {
86
+ var _a;
87
+ const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
88
+ const cacheControlValue = (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a : anthropic2 == null ? void 0 : anthropic2.cache_control;
89
+ return cacheControlValue;
90
+ }
91
+
79
92
  // src/tool/web-search_20250305.ts
80
93
  import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
81
94
  import { z as z3 } from "zod/v4";
@@ -130,7 +143,8 @@ function isWebSearchTool(tool) {
130
143
  }
131
144
  function prepareTools({
132
145
  tools,
133
- toolChoice
146
+ toolChoice,
147
+ disableParallelToolUse
134
148
  }) {
135
149
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
136
150
  const toolWarnings = [];
@@ -146,10 +160,12 @@ function prepareTools({
146
160
  }
147
161
  switch (tool.type) {
148
162
  case "function":
163
+ const cacheControl = getCacheControl(tool.providerOptions);
149
164
  anthropicTools2.push({
150
165
  name: tool.name,
151
166
  description: tool.description,
152
- input_schema: tool.inputSchema
167
+ input_schema: tool.inputSchema,
168
+ cache_control: cacheControl
153
169
  });
154
170
  break;
155
171
  case "provider-defined":
@@ -234,7 +250,7 @@ function prepareTools({
234
250
  if (toolChoice == null) {
235
251
  return {
236
252
  tools: anthropicTools2,
237
- toolChoice: void 0,
253
+ toolChoice: disableParallelToolUse ? { type: "auto", disable_parallel_tool_use: disableParallelToolUse } : void 0,
238
254
  toolWarnings,
239
255
  betas
240
256
  };
@@ -244,14 +260,20 @@ function prepareTools({
244
260
  case "auto":
245
261
  return {
246
262
  tools: anthropicTools2,
247
- toolChoice: { type: "auto" },
263
+ toolChoice: {
264
+ type: "auto",
265
+ disable_parallel_tool_use: disableParallelToolUse
266
+ },
248
267
  toolWarnings,
249
268
  betas
250
269
  };
251
270
  case "required":
252
271
  return {
253
272
  tools: anthropicTools2,
254
- toolChoice: { type: "any" },
273
+ toolChoice: {
274
+ type: "any",
275
+ disable_parallel_tool_use: disableParallelToolUse
276
+ },
255
277
  toolWarnings,
256
278
  betas
257
279
  };
@@ -260,7 +282,11 @@ function prepareTools({
260
282
  case "tool":
261
283
  return {
262
284
  tools: anthropicTools2,
263
- toolChoice: { type: "tool", name: toolChoice.toolName },
285
+ toolChoice: {
286
+ type: "tool",
287
+ name: toolChoice.toolName,
288
+ disable_parallel_tool_use: disableParallelToolUse
289
+ },
264
290
  toolWarnings,
265
291
  betas
266
292
  };
@@ -304,12 +330,6 @@ async function convertToAnthropicMessagesPrompt({
304
330
  const blocks = groupIntoBlocks(prompt);
305
331
  let system = void 0;
306
332
  const messages = [];
307
- function getCacheControl(providerMetadata) {
308
- var _a2;
309
- const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
310
- const cacheControlValue = (_a2 = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a2 : anthropic2 == null ? void 0 : anthropic2.cache_control;
311
- return cacheControlValue;
312
- }
313
333
  async function shouldEnableCitations(providerMetadata) {
314
334
  var _a2, _b2;
315
335
  const anthropicOptions = await parseProviderOptions({
@@ -931,8 +951,13 @@ var AnthropicMessagesLanguageModel = class {
931
951
  } = prepareTools(
932
952
  jsonResponseTool != null ? {
933
953
  tools: [jsonResponseTool],
934
- toolChoice: { type: "tool", toolName: jsonResponseTool.name }
935
- } : { tools: tools != null ? tools : [], toolChoice }
954
+ toolChoice: { type: "tool", toolName: jsonResponseTool.name },
955
+ disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
956
+ } : {
957
+ tools: tools != null ? tools : [],
958
+ toolChoice,
959
+ disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
960
+ }
936
961
  );
937
962
  return {
938
963
  args: {