@ai-sdk/anthropic 3.0.0-beta.69 → 3.0.0-beta.70
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 +6 -0
- package/dist/index.js +78 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -47
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +77 -46
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +78 -46
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
combineHeaders,
|
|
8
8
|
createEventSourceResponseHandler,
|
|
9
9
|
createJsonResponseHandler,
|
|
10
|
+
createToolNameMapping,
|
|
10
11
|
generateId,
|
|
11
12
|
parseProviderOptions as parseProviderOptions2,
|
|
12
13
|
postJsonToApi,
|
|
@@ -1242,7 +1243,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1242
1243
|
prompt,
|
|
1243
1244
|
sendReasoning,
|
|
1244
1245
|
warnings,
|
|
1245
|
-
cacheControlValidator
|
|
1246
|
+
cacheControlValidator,
|
|
1247
|
+
toolNameMapping
|
|
1246
1248
|
}) {
|
|
1247
1249
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1248
1250
|
const betas = /* @__PURE__ */ new Set();
|
|
@@ -1580,6 +1582,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1580
1582
|
}
|
|
1581
1583
|
case "tool-call": {
|
|
1582
1584
|
if (part.providerExecuted) {
|
|
1585
|
+
const providerToolName = toolNameMapping.toProviderToolName(
|
|
1586
|
+
part.toolName
|
|
1587
|
+
);
|
|
1583
1588
|
const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
|
|
1584
1589
|
if (isMcpToolUse) {
|
|
1585
1590
|
mcpToolUseIds.add(part.toolCallId);
|
|
@@ -1601,7 +1606,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1601
1606
|
});
|
|
1602
1607
|
} else if (
|
|
1603
1608
|
// code execution 20250825:
|
|
1604
|
-
|
|
1609
|
+
providerToolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && typeof part.input.type === "string" && (part.input.type === "bash_code_execution" || part.input.type === "text_editor_code_execution")
|
|
1605
1610
|
) {
|
|
1606
1611
|
anthropicContent.push({
|
|
1607
1612
|
type: "server_tool_use",
|
|
@@ -1611,20 +1616,22 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1611
1616
|
input: part.input,
|
|
1612
1617
|
cache_control: cacheControl
|
|
1613
1618
|
});
|
|
1614
|
-
} else if (part.toolName === "code_execution" || // code execution 20250522
|
|
1615
|
-
part.toolName === "web_fetch" || part.toolName === "web_search") {
|
|
1616
|
-
anthropicContent.push({
|
|
1617
|
-
type: "server_tool_use",
|
|
1618
|
-
id: part.toolCallId,
|
|
1619
|
-
name: part.toolName,
|
|
1620
|
-
input: part.input,
|
|
1621
|
-
cache_control: cacheControl
|
|
1622
|
-
});
|
|
1623
1619
|
} else {
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1620
|
+
if (providerToolName === "code_execution" || // code execution 20250522
|
|
1621
|
+
providerToolName === "web_fetch" || providerToolName === "web_search") {
|
|
1622
|
+
anthropicContent.push({
|
|
1623
|
+
type: "server_tool_use",
|
|
1624
|
+
id: part.toolCallId,
|
|
1625
|
+
name: providerToolName,
|
|
1626
|
+
input: part.input,
|
|
1627
|
+
cache_control: cacheControl
|
|
1628
|
+
});
|
|
1629
|
+
} else {
|
|
1630
|
+
warnings.push({
|
|
1631
|
+
type: "other",
|
|
1632
|
+
message: `provider executed tool call for tool ${part.toolName} is not supported`
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1628
1635
|
}
|
|
1629
1636
|
break;
|
|
1630
1637
|
}
|
|
@@ -1638,6 +1645,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1638
1645
|
break;
|
|
1639
1646
|
}
|
|
1640
1647
|
case "tool-result": {
|
|
1648
|
+
const providerToolName = toolNameMapping.toProviderToolName(
|
|
1649
|
+
part.toolName
|
|
1650
|
+
);
|
|
1641
1651
|
if (mcpToolUseIds.has(part.toolCallId)) {
|
|
1642
1652
|
const output = part.output;
|
|
1643
1653
|
if (output.type !== "json" && output.type !== "error-json") {
|
|
@@ -1654,7 +1664,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1654
1664
|
content: output.value,
|
|
1655
1665
|
cache_control: cacheControl
|
|
1656
1666
|
});
|
|
1657
|
-
} else if (
|
|
1667
|
+
} else if (providerToolName === "code_execution") {
|
|
1658
1668
|
const output = part.output;
|
|
1659
1669
|
if (output.type !== "json") {
|
|
1660
1670
|
warnings.push({
|
|
@@ -1707,7 +1717,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1707
1717
|
}
|
|
1708
1718
|
break;
|
|
1709
1719
|
}
|
|
1710
|
-
if (
|
|
1720
|
+
if (providerToolName === "web_fetch") {
|
|
1711
1721
|
const output = part.output;
|
|
1712
1722
|
if (output.type !== "json") {
|
|
1713
1723
|
warnings.push({
|
|
@@ -1742,7 +1752,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1742
1752
|
});
|
|
1743
1753
|
break;
|
|
1744
1754
|
}
|
|
1745
|
-
if (
|
|
1755
|
+
if (providerToolName === "web_search") {
|
|
1746
1756
|
const output = part.output;
|
|
1747
1757
|
if (output.type !== "json") {
|
|
1748
1758
|
warnings.push({
|
|
@@ -1979,11 +1989,30 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1979
1989
|
inputSchema: responseFormat.schema
|
|
1980
1990
|
} : void 0;
|
|
1981
1991
|
const cacheControlValidator = new CacheControlValidator();
|
|
1992
|
+
const toolNameMapping = createToolNameMapping({
|
|
1993
|
+
tools,
|
|
1994
|
+
providerToolNames: {
|
|
1995
|
+
"anthropic.code_execution_20250522": "code_execution",
|
|
1996
|
+
"anthropic.code_execution_20250825": "code_execution",
|
|
1997
|
+
"anthropic.computer_20241022": "computer",
|
|
1998
|
+
"anthropic.computer_20250124": "computer",
|
|
1999
|
+
"anthropic.text_editor_20241022": "str_replace_editor",
|
|
2000
|
+
"anthropic.text_editor_20250124": "str_replace_editor",
|
|
2001
|
+
"anthropic.text_editor_20250429": "str_replace_based_edit_tool",
|
|
2002
|
+
"anthropic.text_editor_20250728": "str_replace_based_edit_tool",
|
|
2003
|
+
"anthropic.bash_20241022": "bash",
|
|
2004
|
+
"anthropic.bash_20250124": "bash",
|
|
2005
|
+
"anthropic.memory_20250818": "memory",
|
|
2006
|
+
"anthropic.web_search_20250305": "web_search",
|
|
2007
|
+
"anthropic.web_fetch_20250910": "web_fetch"
|
|
2008
|
+
}
|
|
2009
|
+
});
|
|
1982
2010
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1983
2011
|
prompt,
|
|
1984
2012
|
sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
|
|
1985
2013
|
warnings,
|
|
1986
|
-
cacheControlValidator
|
|
2014
|
+
cacheControlValidator,
|
|
2015
|
+
toolNameMapping
|
|
1987
2016
|
});
|
|
1988
2017
|
const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
|
|
1989
2018
|
const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
|
|
@@ -2135,7 +2164,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2135
2164
|
},
|
|
2136
2165
|
warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
|
|
2137
2166
|
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
|
|
2138
|
-
usesJsonResponseTool: jsonResponseTool != null
|
|
2167
|
+
usesJsonResponseTool: jsonResponseTool != null,
|
|
2168
|
+
toolNameMapping
|
|
2139
2169
|
};
|
|
2140
2170
|
}
|
|
2141
2171
|
async getHeaders({
|
|
@@ -2193,7 +2223,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2193
2223
|
}
|
|
2194
2224
|
async doGenerate(options) {
|
|
2195
2225
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2196
|
-
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2226
|
+
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2197
2227
|
...options,
|
|
2198
2228
|
stream: false,
|
|
2199
2229
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2284,7 +2314,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2284
2314
|
content.push({
|
|
2285
2315
|
type: "tool-call",
|
|
2286
2316
|
toolCallId: part.id,
|
|
2287
|
-
toolName: "code_execution",
|
|
2317
|
+
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2288
2318
|
input: JSON.stringify({ type: part.name, ...part.input }),
|
|
2289
2319
|
providerExecuted: true
|
|
2290
2320
|
});
|
|
@@ -2292,7 +2322,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2292
2322
|
content.push({
|
|
2293
2323
|
type: "tool-call",
|
|
2294
2324
|
toolCallId: part.id,
|
|
2295
|
-
toolName: part.name,
|
|
2325
|
+
toolName: toolNameMapping.toCustomToolName(part.name),
|
|
2296
2326
|
input: JSON.stringify(part.input),
|
|
2297
2327
|
providerExecuted: true
|
|
2298
2328
|
});
|
|
@@ -2334,7 +2364,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2334
2364
|
content.push({
|
|
2335
2365
|
type: "tool-result",
|
|
2336
2366
|
toolCallId: part.tool_use_id,
|
|
2337
|
-
toolName: "web_fetch",
|
|
2367
|
+
toolName: toolNameMapping.toCustomToolName("web_fetch"),
|
|
2338
2368
|
result: {
|
|
2339
2369
|
type: "web_fetch_result",
|
|
2340
2370
|
url: part.content.url,
|
|
@@ -2355,7 +2385,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2355
2385
|
content.push({
|
|
2356
2386
|
type: "tool-result",
|
|
2357
2387
|
toolCallId: part.tool_use_id,
|
|
2358
|
-
toolName: "web_fetch",
|
|
2388
|
+
toolName: toolNameMapping.toCustomToolName("web_fetch"),
|
|
2359
2389
|
isError: true,
|
|
2360
2390
|
result: {
|
|
2361
2391
|
type: "web_fetch_tool_result_error",
|
|
@@ -2370,7 +2400,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2370
2400
|
content.push({
|
|
2371
2401
|
type: "tool-result",
|
|
2372
2402
|
toolCallId: part.tool_use_id,
|
|
2373
|
-
toolName: "web_search",
|
|
2403
|
+
toolName: toolNameMapping.toCustomToolName("web_search"),
|
|
2374
2404
|
result: part.content.map((result) => {
|
|
2375
2405
|
var _a2;
|
|
2376
2406
|
return {
|
|
@@ -2400,7 +2430,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2400
2430
|
content.push({
|
|
2401
2431
|
type: "tool-result",
|
|
2402
2432
|
toolCallId: part.tool_use_id,
|
|
2403
|
-
toolName: "web_search",
|
|
2433
|
+
toolName: toolNameMapping.toCustomToolName("web_search"),
|
|
2404
2434
|
isError: true,
|
|
2405
2435
|
result: {
|
|
2406
2436
|
type: "web_search_tool_result_error",
|
|
@@ -2416,7 +2446,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2416
2446
|
content.push({
|
|
2417
2447
|
type: "tool-result",
|
|
2418
2448
|
toolCallId: part.tool_use_id,
|
|
2419
|
-
toolName: "code_execution",
|
|
2449
|
+
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2420
2450
|
result: {
|
|
2421
2451
|
type: part.content.type,
|
|
2422
2452
|
stdout: part.content.stdout,
|
|
@@ -2428,7 +2458,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2428
2458
|
content.push({
|
|
2429
2459
|
type: "tool-result",
|
|
2430
2460
|
toolCallId: part.tool_use_id,
|
|
2431
|
-
toolName: "code_execution",
|
|
2461
|
+
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2432
2462
|
isError: true,
|
|
2433
2463
|
result: {
|
|
2434
2464
|
type: "code_execution_tool_result_error",
|
|
@@ -2444,7 +2474,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2444
2474
|
content.push({
|
|
2445
2475
|
type: "tool-result",
|
|
2446
2476
|
toolCallId: part.tool_use_id,
|
|
2447
|
-
toolName: "code_execution",
|
|
2477
|
+
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2448
2478
|
result: part.content
|
|
2449
2479
|
});
|
|
2450
2480
|
break;
|
|
@@ -2495,7 +2525,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2495
2525
|
args: body,
|
|
2496
2526
|
warnings,
|
|
2497
2527
|
betas,
|
|
2498
|
-
usesJsonResponseTool
|
|
2528
|
+
usesJsonResponseTool,
|
|
2529
|
+
toolNameMapping
|
|
2499
2530
|
} = await this.getArgs({
|
|
2500
2531
|
...options,
|
|
2501
2532
|
stream: true,
|
|
@@ -2621,19 +2652,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2621
2652
|
// code execution 20250825 bash:
|
|
2622
2653
|
"bash_code_execution"
|
|
2623
2654
|
].includes(part.name)) {
|
|
2655
|
+
const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
|
|
2656
|
+
const customToolName = toolNameMapping.toCustomToolName(providerToolName);
|
|
2624
2657
|
contentBlocks[value.index] = {
|
|
2625
2658
|
type: "tool-call",
|
|
2626
2659
|
toolCallId: part.id,
|
|
2627
|
-
toolName:
|
|
2660
|
+
toolName: customToolName,
|
|
2628
2661
|
input: "",
|
|
2629
2662
|
providerExecuted: true,
|
|
2630
|
-
firstDelta: true
|
|
2663
|
+
firstDelta: true,
|
|
2664
|
+
providerToolName: part.name
|
|
2631
2665
|
};
|
|
2632
|
-
const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
|
|
2633
2666
|
controller.enqueue({
|
|
2634
2667
|
type: "tool-input-start",
|
|
2635
2668
|
id: part.id,
|
|
2636
|
-
toolName:
|
|
2669
|
+
toolName: customToolName,
|
|
2637
2670
|
providerExecuted: true
|
|
2638
2671
|
});
|
|
2639
2672
|
}
|
|
@@ -2644,7 +2677,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2644
2677
|
controller.enqueue({
|
|
2645
2678
|
type: "tool-result",
|
|
2646
2679
|
toolCallId: part.tool_use_id,
|
|
2647
|
-
toolName: "web_fetch",
|
|
2680
|
+
toolName: toolNameMapping.toCustomToolName("web_fetch"),
|
|
2648
2681
|
result: {
|
|
2649
2682
|
type: "web_fetch_result",
|
|
2650
2683
|
url: part.content.url,
|
|
@@ -2665,7 +2698,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2665
2698
|
controller.enqueue({
|
|
2666
2699
|
type: "tool-result",
|
|
2667
2700
|
toolCallId: part.tool_use_id,
|
|
2668
|
-
toolName: "web_fetch",
|
|
2701
|
+
toolName: toolNameMapping.toCustomToolName("web_fetch"),
|
|
2669
2702
|
isError: true,
|
|
2670
2703
|
result: {
|
|
2671
2704
|
type: "web_fetch_tool_result_error",
|
|
@@ -2680,7 +2713,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2680
2713
|
controller.enqueue({
|
|
2681
2714
|
type: "tool-result",
|
|
2682
2715
|
toolCallId: part.tool_use_id,
|
|
2683
|
-
toolName: "web_search",
|
|
2716
|
+
toolName: toolNameMapping.toCustomToolName("web_search"),
|
|
2684
2717
|
result: part.content.map((result) => {
|
|
2685
2718
|
var _a3;
|
|
2686
2719
|
return {
|
|
@@ -2710,7 +2743,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2710
2743
|
controller.enqueue({
|
|
2711
2744
|
type: "tool-result",
|
|
2712
2745
|
toolCallId: part.tool_use_id,
|
|
2713
|
-
toolName: "web_search",
|
|
2746
|
+
toolName: toolNameMapping.toCustomToolName("web_search"),
|
|
2714
2747
|
isError: true,
|
|
2715
2748
|
result: {
|
|
2716
2749
|
type: "web_search_tool_result_error",
|
|
@@ -2726,7 +2759,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2726
2759
|
controller.enqueue({
|
|
2727
2760
|
type: "tool-result",
|
|
2728
2761
|
toolCallId: part.tool_use_id,
|
|
2729
|
-
toolName: "code_execution",
|
|
2762
|
+
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2730
2763
|
result: {
|
|
2731
2764
|
type: part.content.type,
|
|
2732
2765
|
stdout: part.content.stdout,
|
|
@@ -2738,7 +2771,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2738
2771
|
controller.enqueue({
|
|
2739
2772
|
type: "tool-result",
|
|
2740
2773
|
toolCallId: part.tool_use_id,
|
|
2741
|
-
toolName: "code_execution",
|
|
2774
|
+
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2742
2775
|
isError: true,
|
|
2743
2776
|
result: {
|
|
2744
2777
|
type: "code_execution_tool_result_error",
|
|
@@ -2754,7 +2787,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2754
2787
|
controller.enqueue({
|
|
2755
2788
|
type: "tool-result",
|
|
2756
2789
|
toolCallId: part.tool_use_id,
|
|
2757
|
-
toolName: "code_execution",
|
|
2790
|
+
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2758
2791
|
result: part.content
|
|
2759
2792
|
});
|
|
2760
2793
|
return;
|
|
@@ -2822,11 +2855,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2822
2855
|
type: "tool-input-end",
|
|
2823
2856
|
id: contentBlock.toolCallId
|
|
2824
2857
|
});
|
|
2825
|
-
const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
|
|
2826
2858
|
controller.enqueue({
|
|
2827
2859
|
type: "tool-call",
|
|
2828
2860
|
toolCallId: contentBlock.toolCallId,
|
|
2829
|
-
toolName,
|
|
2861
|
+
toolName: contentBlock.toolName,
|
|
2830
2862
|
input: contentBlock.input === "" ? "{}" : contentBlock.input,
|
|
2831
2863
|
providerExecuted: contentBlock.providerExecuted
|
|
2832
2864
|
});
|
|
@@ -2894,8 +2926,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2894
2926
|
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
2895
2927
|
return;
|
|
2896
2928
|
}
|
|
2897
|
-
if (contentBlock.firstDelta && (contentBlock.
|
|
2898
|
-
delta = `{"type": "${contentBlock.
|
|
2929
|
+
if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
|
|
2930
|
+
delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
|
|
2899
2931
|
}
|
|
2900
2932
|
controller.enqueue({
|
|
2901
2933
|
type: "tool-input-delta",
|