@ai-sdk/anthropic 3.0.0-beta.27 → 3.0.0-beta.28
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 +9 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +187 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +187 -23
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +186 -22
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +186 -22
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "@ai-sdk/provider-utils";
|
|
11
11
|
|
|
12
12
|
// src/version.ts
|
|
13
|
-
var VERSION = true ? "3.0.0-beta.
|
|
13
|
+
var VERSION = true ? "3.0.0-beta.28" : "0.0.0-test";
|
|
14
14
|
|
|
15
15
|
// src/anthropic-messages-language-model.ts
|
|
16
16
|
import {
|
|
@@ -112,6 +112,24 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
112
112
|
name: z2.string(),
|
|
113
113
|
input: z2.record(z2.string(), z2.unknown()).nullish()
|
|
114
114
|
}),
|
|
115
|
+
z2.object({
|
|
116
|
+
type: z2.literal("mcp_tool_use"),
|
|
117
|
+
id: z2.string(),
|
|
118
|
+
name: z2.string(),
|
|
119
|
+
input: z2.unknown(),
|
|
120
|
+
server_name: z2.string()
|
|
121
|
+
}),
|
|
122
|
+
z2.object({
|
|
123
|
+
type: z2.literal("mcp_tool_result"),
|
|
124
|
+
tool_use_id: z2.string(),
|
|
125
|
+
is_error: z2.boolean(),
|
|
126
|
+
content: z2.array(
|
|
127
|
+
z2.union([
|
|
128
|
+
z2.string(),
|
|
129
|
+
z2.object({ type: z2.literal("text"), text: z2.string() })
|
|
130
|
+
])
|
|
131
|
+
)
|
|
132
|
+
}),
|
|
115
133
|
z2.object({
|
|
116
134
|
type: z2.literal("web_fetch_tool_result"),
|
|
117
135
|
tool_use_id: z2.string(),
|
|
@@ -284,6 +302,24 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
284
302
|
name: z2.string(),
|
|
285
303
|
input: z2.record(z2.string(), z2.unknown()).nullish()
|
|
286
304
|
}),
|
|
305
|
+
z2.object({
|
|
306
|
+
type: z2.literal("mcp_tool_use"),
|
|
307
|
+
id: z2.string(),
|
|
308
|
+
name: z2.string(),
|
|
309
|
+
input: z2.unknown(),
|
|
310
|
+
server_name: z2.string()
|
|
311
|
+
}),
|
|
312
|
+
z2.object({
|
|
313
|
+
type: z2.literal("mcp_tool_result"),
|
|
314
|
+
tool_use_id: z2.string(),
|
|
315
|
+
is_error: z2.boolean(),
|
|
316
|
+
content: z2.array(
|
|
317
|
+
z2.union([
|
|
318
|
+
z2.string(),
|
|
319
|
+
z2.object({ type: z2.literal("text"), text: z2.string() })
|
|
320
|
+
])
|
|
321
|
+
)
|
|
322
|
+
}),
|
|
287
323
|
z2.object({
|
|
288
324
|
type: z2.literal("web_fetch_tool_result"),
|
|
289
325
|
tool_use_id: z2.string(),
|
|
@@ -536,7 +572,19 @@ var anthropicProviderOptions = z3.object({
|
|
|
536
572
|
cacheControl: z3.object({
|
|
537
573
|
type: z3.literal("ephemeral"),
|
|
538
574
|
ttl: z3.union([z3.literal("5m"), z3.literal("1h")]).optional()
|
|
539
|
-
}).optional()
|
|
575
|
+
}).optional(),
|
|
576
|
+
mcpServers: z3.array(
|
|
577
|
+
z3.object({
|
|
578
|
+
type: z3.literal("url"),
|
|
579
|
+
name: z3.string(),
|
|
580
|
+
url: z3.string(),
|
|
581
|
+
authorizationToken: z3.string().nullish(),
|
|
582
|
+
toolConfiguration: z3.object({
|
|
583
|
+
enabled: z3.boolean().nullish(),
|
|
584
|
+
allowedTools: z3.array(z3.string()).nullish()
|
|
585
|
+
}).nullish()
|
|
586
|
+
})
|
|
587
|
+
).optional()
|
|
540
588
|
});
|
|
541
589
|
|
|
542
590
|
// src/anthropic-prepare-tools.ts
|
|
@@ -1081,7 +1129,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1081
1129
|
sendReasoning,
|
|
1082
1130
|
warnings
|
|
1083
1131
|
}) {
|
|
1084
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1132
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1085
1133
|
const betas = /* @__PURE__ */ new Set();
|
|
1086
1134
|
const blocks = groupIntoBlocks(prompt);
|
|
1087
1135
|
let system = void 0;
|
|
@@ -1299,6 +1347,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1299
1347
|
}
|
|
1300
1348
|
case "assistant": {
|
|
1301
1349
|
const anthropicContent = [];
|
|
1350
|
+
const mcpToolUseIds = /* @__PURE__ */ new Set();
|
|
1302
1351
|
for (let j = 0; j < block.messages.length; j++) {
|
|
1303
1352
|
const message = block.messages[j];
|
|
1304
1353
|
const isLastMessage = j === block.messages.length - 1;
|
|
@@ -1364,7 +1413,29 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1364
1413
|
}
|
|
1365
1414
|
case "tool-call": {
|
|
1366
1415
|
if (part.providerExecuted) {
|
|
1367
|
-
|
|
1416
|
+
const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
|
|
1417
|
+
if (isMcpToolUse) {
|
|
1418
|
+
mcpToolUseIds.add(part.toolCallId);
|
|
1419
|
+
const serverName = (_j = (_i = part.providerOptions) == null ? void 0 : _i.anthropic) == null ? void 0 : _j.serverName;
|
|
1420
|
+
if (serverName == null || typeof serverName !== "string") {
|
|
1421
|
+
warnings.push({
|
|
1422
|
+
type: "other",
|
|
1423
|
+
message: "mcp tool use server name is required and must be a string"
|
|
1424
|
+
});
|
|
1425
|
+
break;
|
|
1426
|
+
}
|
|
1427
|
+
anthropicContent.push({
|
|
1428
|
+
type: "mcp_tool_use",
|
|
1429
|
+
id: part.toolCallId,
|
|
1430
|
+
name: part.toolName,
|
|
1431
|
+
input: part.input,
|
|
1432
|
+
server_name: serverName,
|
|
1433
|
+
cache_control: cacheControl
|
|
1434
|
+
});
|
|
1435
|
+
} else if (
|
|
1436
|
+
// code execution 20250825:
|
|
1437
|
+
part.toolName === "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")
|
|
1438
|
+
) {
|
|
1368
1439
|
anthropicContent.push({
|
|
1369
1440
|
type: "server_tool_use",
|
|
1370
1441
|
id: part.toolCallId,
|
|
@@ -1400,7 +1471,23 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1400
1471
|
break;
|
|
1401
1472
|
}
|
|
1402
1473
|
case "tool-result": {
|
|
1403
|
-
if (part.
|
|
1474
|
+
if (mcpToolUseIds.has(part.toolCallId)) {
|
|
1475
|
+
const output = part.output;
|
|
1476
|
+
if (output.type !== "json" && output.type !== "error-json") {
|
|
1477
|
+
warnings.push({
|
|
1478
|
+
type: "other",
|
|
1479
|
+
message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
|
|
1480
|
+
});
|
|
1481
|
+
break;
|
|
1482
|
+
}
|
|
1483
|
+
anthropicContent.push({
|
|
1484
|
+
type: "mcp_tool_result",
|
|
1485
|
+
tool_use_id: part.toolCallId,
|
|
1486
|
+
is_error: output.type === "error-json",
|
|
1487
|
+
content: output.value,
|
|
1488
|
+
cache_control: cacheControl
|
|
1489
|
+
});
|
|
1490
|
+
} else if (part.toolName === "code_execution") {
|
|
1404
1491
|
const output = part.output;
|
|
1405
1492
|
if (output.type !== "json") {
|
|
1406
1493
|
warnings.push({
|
|
@@ -1715,7 +1802,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1715
1802
|
providerOptions,
|
|
1716
1803
|
schema: anthropicProviderOptions
|
|
1717
1804
|
});
|
|
1718
|
-
const { prompt: messagesPrompt, betas
|
|
1805
|
+
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1719
1806
|
prompt,
|
|
1720
1807
|
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
1721
1808
|
warnings
|
|
@@ -1737,6 +1824,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1737
1824
|
...isThinking && {
|
|
1738
1825
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
1739
1826
|
},
|
|
1827
|
+
// mcp servers:
|
|
1828
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
|
|
1829
|
+
mcp_servers: anthropicOptions.mcpServers.map((server) => ({
|
|
1830
|
+
type: server.type,
|
|
1831
|
+
name: server.name,
|
|
1832
|
+
url: server.url,
|
|
1833
|
+
authorization_token: server.authorizationToken,
|
|
1834
|
+
tool_configuration: server.toolConfiguration ? {
|
|
1835
|
+
allowed_tools: server.toolConfiguration.allowedTools,
|
|
1836
|
+
enabled: server.toolConfiguration.enabled
|
|
1837
|
+
} : void 0
|
|
1838
|
+
}))
|
|
1839
|
+
},
|
|
1740
1840
|
// prompt:
|
|
1741
1841
|
system: messagesPrompt.system,
|
|
1742
1842
|
messages: messagesPrompt.messages
|
|
@@ -1778,11 +1878,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1778
1878
|
warnings.push({
|
|
1779
1879
|
type: "unsupported-setting",
|
|
1780
1880
|
setting: "maxOutputTokens",
|
|
1781
|
-
details: `${
|
|
1881
|
+
details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
|
|
1782
1882
|
});
|
|
1783
1883
|
}
|
|
1784
1884
|
baseArgs.max_tokens = maxOutputTokensForModel;
|
|
1785
1885
|
}
|
|
1886
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
|
|
1887
|
+
betas.add("mcp-client-2025-04-04");
|
|
1888
|
+
}
|
|
1786
1889
|
const {
|
|
1787
1890
|
tools: anthropicTools2,
|
|
1788
1891
|
toolChoice: anthropicToolChoice,
|
|
@@ -1806,7 +1909,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1806
1909
|
tool_choice: anthropicToolChoice
|
|
1807
1910
|
},
|
|
1808
1911
|
warnings: [...warnings, ...toolWarnings],
|
|
1809
|
-
betas: /* @__PURE__ */ new Set([...
|
|
1912
|
+
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
|
|
1810
1913
|
usesJsonResponseTool: jsonResponseTool != null
|
|
1811
1914
|
};
|
|
1812
1915
|
}
|
|
@@ -1871,6 +1974,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1871
1974
|
fetch: this.config.fetch
|
|
1872
1975
|
});
|
|
1873
1976
|
const content = [];
|
|
1977
|
+
const mcpToolCalls = {};
|
|
1874
1978
|
for (const part of response.content) {
|
|
1875
1979
|
switch (part.type) {
|
|
1876
1980
|
case "text": {
|
|
@@ -1950,6 +2054,37 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1950
2054
|
}
|
|
1951
2055
|
break;
|
|
1952
2056
|
}
|
|
2057
|
+
case "mcp_tool_use": {
|
|
2058
|
+
mcpToolCalls[part.id] = {
|
|
2059
|
+
type: "tool-call",
|
|
2060
|
+
toolCallId: part.id,
|
|
2061
|
+
toolName: part.name,
|
|
2062
|
+
input: JSON.stringify(part.input),
|
|
2063
|
+
providerExecuted: true,
|
|
2064
|
+
dynamic: true,
|
|
2065
|
+
providerMetadata: {
|
|
2066
|
+
anthropic: {
|
|
2067
|
+
type: "mcp-tool-use",
|
|
2068
|
+
serverName: part.server_name
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
};
|
|
2072
|
+
content.push(mcpToolCalls[part.id]);
|
|
2073
|
+
break;
|
|
2074
|
+
}
|
|
2075
|
+
case "mcp_tool_result": {
|
|
2076
|
+
content.push({
|
|
2077
|
+
type: "tool-result",
|
|
2078
|
+
toolCallId: part.tool_use_id,
|
|
2079
|
+
toolName: mcpToolCalls[part.tool_use_id].toolName,
|
|
2080
|
+
isError: part.is_error,
|
|
2081
|
+
result: part.content,
|
|
2082
|
+
providerExecuted: true,
|
|
2083
|
+
dynamic: true,
|
|
2084
|
+
providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
|
|
2085
|
+
});
|
|
2086
|
+
break;
|
|
2087
|
+
}
|
|
1953
2088
|
case "web_fetch_tool_result": {
|
|
1954
2089
|
if (part.content.type === "web_fetch_result") {
|
|
1955
2090
|
content.push({
|
|
@@ -2130,6 +2265,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2130
2265
|
totalTokens: void 0
|
|
2131
2266
|
};
|
|
2132
2267
|
const contentBlocks = {};
|
|
2268
|
+
const mcpToolCalls = {};
|
|
2133
2269
|
let rawUsage = void 0;
|
|
2134
2270
|
let cacheCreationInputTokens = null;
|
|
2135
2271
|
let stopSequence = null;
|
|
@@ -2156,7 +2292,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2156
2292
|
return;
|
|
2157
2293
|
}
|
|
2158
2294
|
case "content_block_start": {
|
|
2159
|
-
const
|
|
2295
|
+
const part = value.content_block;
|
|
2296
|
+
const contentBlockType = part.type;
|
|
2160
2297
|
blockType = contentBlockType;
|
|
2161
2298
|
switch (contentBlockType) {
|
|
2162
2299
|
case "text": {
|
|
@@ -2182,7 +2319,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2182
2319
|
id: String(value.index),
|
|
2183
2320
|
providerMetadata: {
|
|
2184
2321
|
anthropic: {
|
|
2185
|
-
redactedData:
|
|
2322
|
+
redactedData: part.data
|
|
2186
2323
|
}
|
|
2187
2324
|
}
|
|
2188
2325
|
});
|
|
@@ -2191,16 +2328,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2191
2328
|
case "tool_use": {
|
|
2192
2329
|
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
2193
2330
|
type: "tool-call",
|
|
2194
|
-
toolCallId:
|
|
2195
|
-
toolName:
|
|
2331
|
+
toolCallId: part.id,
|
|
2332
|
+
toolName: part.name,
|
|
2196
2333
|
input: "",
|
|
2197
2334
|
firstDelta: true
|
|
2198
2335
|
};
|
|
2199
2336
|
controller.enqueue(
|
|
2200
2337
|
usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
|
|
2201
2338
|
type: "tool-input-start",
|
|
2202
|
-
id:
|
|
2203
|
-
toolName:
|
|
2339
|
+
id: part.id,
|
|
2340
|
+
toolName: part.name
|
|
2204
2341
|
}
|
|
2205
2342
|
);
|
|
2206
2343
|
return;
|
|
@@ -2215,19 +2352,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2215
2352
|
"text_editor_code_execution",
|
|
2216
2353
|
// code execution 20250825 bash:
|
|
2217
2354
|
"bash_code_execution"
|
|
2218
|
-
].includes(
|
|
2355
|
+
].includes(part.name)) {
|
|
2219
2356
|
contentBlocks[value.index] = {
|
|
2220
2357
|
type: "tool-call",
|
|
2221
|
-
toolCallId:
|
|
2222
|
-
toolName:
|
|
2358
|
+
toolCallId: part.id,
|
|
2359
|
+
toolName: part.name,
|
|
2223
2360
|
input: "",
|
|
2224
2361
|
providerExecuted: true,
|
|
2225
2362
|
firstDelta: true
|
|
2226
2363
|
};
|
|
2227
|
-
const mappedToolName =
|
|
2364
|
+
const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
|
|
2228
2365
|
controller.enqueue({
|
|
2229
2366
|
type: "tool-input-start",
|
|
2230
|
-
id:
|
|
2367
|
+
id: part.id,
|
|
2231
2368
|
toolName: mappedToolName,
|
|
2232
2369
|
providerExecuted: true
|
|
2233
2370
|
});
|
|
@@ -2235,7 +2372,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2235
2372
|
return;
|
|
2236
2373
|
}
|
|
2237
2374
|
case "web_fetch_tool_result": {
|
|
2238
|
-
const part = value.content_block;
|
|
2239
2375
|
if (part.content.type === "web_fetch_result") {
|
|
2240
2376
|
controller.enqueue({
|
|
2241
2377
|
type: "tool-result",
|
|
@@ -2273,7 +2409,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2273
2409
|
return;
|
|
2274
2410
|
}
|
|
2275
2411
|
case "web_search_tool_result": {
|
|
2276
|
-
const part = value.content_block;
|
|
2277
2412
|
if (Array.isArray(part.content)) {
|
|
2278
2413
|
controller.enqueue({
|
|
2279
2414
|
type: "tool-result",
|
|
@@ -2322,7 +2457,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2322
2457
|
}
|
|
2323
2458
|
// code execution 20250522:
|
|
2324
2459
|
case "code_execution_tool_result": {
|
|
2325
|
-
const part = value.content_block;
|
|
2326
2460
|
if (part.content.type === "code_execution_result") {
|
|
2327
2461
|
controller.enqueue({
|
|
2328
2462
|
type: "tool-result",
|
|
@@ -2354,7 +2488,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2354
2488
|
// code execution 20250825:
|
|
2355
2489
|
case "bash_code_execution_tool_result":
|
|
2356
2490
|
case "text_editor_code_execution_tool_result": {
|
|
2357
|
-
const part = value.content_block;
|
|
2358
2491
|
controller.enqueue({
|
|
2359
2492
|
type: "tool-result",
|
|
2360
2493
|
toolCallId: part.tool_use_id,
|
|
@@ -2364,6 +2497,37 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2364
2497
|
});
|
|
2365
2498
|
return;
|
|
2366
2499
|
}
|
|
2500
|
+
case "mcp_tool_use": {
|
|
2501
|
+
mcpToolCalls[part.id] = {
|
|
2502
|
+
type: "tool-call",
|
|
2503
|
+
toolCallId: part.id,
|
|
2504
|
+
toolName: part.name,
|
|
2505
|
+
input: JSON.stringify(part.input),
|
|
2506
|
+
providerExecuted: true,
|
|
2507
|
+
dynamic: true,
|
|
2508
|
+
providerMetadata: {
|
|
2509
|
+
anthropic: {
|
|
2510
|
+
type: "mcp-tool-use",
|
|
2511
|
+
serverName: part.server_name
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
};
|
|
2515
|
+
controller.enqueue(mcpToolCalls[part.id]);
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
case "mcp_tool_result": {
|
|
2519
|
+
controller.enqueue({
|
|
2520
|
+
type: "tool-result",
|
|
2521
|
+
toolCallId: part.tool_use_id,
|
|
2522
|
+
toolName: mcpToolCalls[part.tool_use_id].toolName,
|
|
2523
|
+
isError: part.is_error,
|
|
2524
|
+
result: part.content,
|
|
2525
|
+
providerExecuted: true,
|
|
2526
|
+
dynamic: true,
|
|
2527
|
+
providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
|
|
2528
|
+
});
|
|
2529
|
+
return;
|
|
2530
|
+
}
|
|
2367
2531
|
default: {
|
|
2368
2532
|
const _exhaustiveCheck = contentBlockType;
|
|
2369
2533
|
throw new Error(
|