@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/CHANGELOG.md +17 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +40 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -15
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +40 -15
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +40 -15
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.js
CHANGED
|
@@ -85,12 +85,25 @@ var anthropicProviderOptions = import_v42.z.object({
|
|
|
85
85
|
thinking: import_v42.z.object({
|
|
86
86
|
type: import_v42.z.union([import_v42.z.literal("enabled"), import_v42.z.literal("disabled")]),
|
|
87
87
|
budgetTokens: import_v42.z.number().optional()
|
|
88
|
-
}).optional()
|
|
88
|
+
}).optional(),
|
|
89
|
+
/**
|
|
90
|
+
* Whether to disable parallel function calling during tool use. Default is false.
|
|
91
|
+
* When set to true, Claude will use at most one tool per response.
|
|
92
|
+
*/
|
|
93
|
+
disableParallelToolUse: import_v42.z.boolean().optional()
|
|
89
94
|
});
|
|
90
95
|
|
|
91
96
|
// src/anthropic-prepare-tools.ts
|
|
92
97
|
var import_provider = require("@ai-sdk/provider");
|
|
93
98
|
|
|
99
|
+
// src/get-cache-control.ts
|
|
100
|
+
function getCacheControl(providerMetadata) {
|
|
101
|
+
var _a;
|
|
102
|
+
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
103
|
+
const cacheControlValue = (_a = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a : anthropic == null ? void 0 : anthropic.cache_control;
|
|
104
|
+
return cacheControlValue;
|
|
105
|
+
}
|
|
106
|
+
|
|
94
107
|
// src/tool/web-search_20250305.ts
|
|
95
108
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
96
109
|
var import_v43 = require("zod/v4");
|
|
@@ -145,7 +158,8 @@ function isWebSearchTool(tool) {
|
|
|
145
158
|
}
|
|
146
159
|
function prepareTools({
|
|
147
160
|
tools,
|
|
148
|
-
toolChoice
|
|
161
|
+
toolChoice,
|
|
162
|
+
disableParallelToolUse
|
|
149
163
|
}) {
|
|
150
164
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
151
165
|
const toolWarnings = [];
|
|
@@ -161,10 +175,12 @@ function prepareTools({
|
|
|
161
175
|
}
|
|
162
176
|
switch (tool.type) {
|
|
163
177
|
case "function":
|
|
178
|
+
const cacheControl = getCacheControl(tool.providerOptions);
|
|
164
179
|
anthropicTools2.push({
|
|
165
180
|
name: tool.name,
|
|
166
181
|
description: tool.description,
|
|
167
|
-
input_schema: tool.inputSchema
|
|
182
|
+
input_schema: tool.inputSchema,
|
|
183
|
+
cache_control: cacheControl
|
|
168
184
|
});
|
|
169
185
|
break;
|
|
170
186
|
case "provider-defined":
|
|
@@ -249,7 +265,7 @@ function prepareTools({
|
|
|
249
265
|
if (toolChoice == null) {
|
|
250
266
|
return {
|
|
251
267
|
tools: anthropicTools2,
|
|
252
|
-
toolChoice: void 0,
|
|
268
|
+
toolChoice: disableParallelToolUse ? { type: "auto", disable_parallel_tool_use: disableParallelToolUse } : void 0,
|
|
253
269
|
toolWarnings,
|
|
254
270
|
betas
|
|
255
271
|
};
|
|
@@ -259,14 +275,20 @@ function prepareTools({
|
|
|
259
275
|
case "auto":
|
|
260
276
|
return {
|
|
261
277
|
tools: anthropicTools2,
|
|
262
|
-
toolChoice: {
|
|
278
|
+
toolChoice: {
|
|
279
|
+
type: "auto",
|
|
280
|
+
disable_parallel_tool_use: disableParallelToolUse
|
|
281
|
+
},
|
|
263
282
|
toolWarnings,
|
|
264
283
|
betas
|
|
265
284
|
};
|
|
266
285
|
case "required":
|
|
267
286
|
return {
|
|
268
287
|
tools: anthropicTools2,
|
|
269
|
-
toolChoice: {
|
|
288
|
+
toolChoice: {
|
|
289
|
+
type: "any",
|
|
290
|
+
disable_parallel_tool_use: disableParallelToolUse
|
|
291
|
+
},
|
|
270
292
|
toolWarnings,
|
|
271
293
|
betas
|
|
272
294
|
};
|
|
@@ -275,7 +297,11 @@ function prepareTools({
|
|
|
275
297
|
case "tool":
|
|
276
298
|
return {
|
|
277
299
|
tools: anthropicTools2,
|
|
278
|
-
toolChoice: {
|
|
300
|
+
toolChoice: {
|
|
301
|
+
type: "tool",
|
|
302
|
+
name: toolChoice.toolName,
|
|
303
|
+
disable_parallel_tool_use: disableParallelToolUse
|
|
304
|
+
},
|
|
279
305
|
toolWarnings,
|
|
280
306
|
betas
|
|
281
307
|
};
|
|
@@ -317,12 +343,6 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
317
343
|
const blocks = groupIntoBlocks(prompt);
|
|
318
344
|
let system = void 0;
|
|
319
345
|
const messages = [];
|
|
320
|
-
function getCacheControl(providerMetadata) {
|
|
321
|
-
var _a2;
|
|
322
|
-
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
323
|
-
const cacheControlValue = (_a2 = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a2 : anthropic == null ? void 0 : anthropic.cache_control;
|
|
324
|
-
return cacheControlValue;
|
|
325
|
-
}
|
|
326
346
|
async function shouldEnableCitations(providerMetadata) {
|
|
327
347
|
var _a2, _b2;
|
|
328
348
|
const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
@@ -944,8 +964,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
944
964
|
} = prepareTools(
|
|
945
965
|
jsonResponseTool != null ? {
|
|
946
966
|
tools: [jsonResponseTool],
|
|
947
|
-
toolChoice: { type: "tool", toolName: jsonResponseTool.name }
|
|
948
|
-
|
|
967
|
+
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
968
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
969
|
+
} : {
|
|
970
|
+
tools: tools != null ? tools : [],
|
|
971
|
+
toolChoice,
|
|
972
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
973
|
+
}
|
|
949
974
|
);
|
|
950
975
|
return {
|
|
951
976
|
args: {
|