@ai-sdk/anthropic 3.0.0-beta.27 → 3.0.0-beta.29
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 +18 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +213 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +215 -41
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +212 -39
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +214 -40
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.29
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3794514: feat: flexible tool output content support
|
|
8
|
+
- Updated dependencies [3794514]
|
|
9
|
+
- @ai-sdk/provider-utils@4.0.0-beta.19
|
|
10
|
+
- @ai-sdk/provider@3.0.0-beta.8
|
|
11
|
+
|
|
12
|
+
## 3.0.0-beta.28
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 81d4308: feat(provider/anthropic): mcp connector support
|
|
17
|
+
- Updated dependencies [81d4308]
|
|
18
|
+
- @ai-sdk/provider@3.0.0-beta.7
|
|
19
|
+
- @ai-sdk/provider-utils@4.0.0-beta.18
|
|
20
|
+
|
|
3
21
|
## 3.0.0-beta.27
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -15,6 +15,16 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
15
15
|
type: z.ZodLiteral<"ephemeral">;
|
|
16
16
|
ttl: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
17
17
|
}, z.core.$strip>>;
|
|
18
|
+
mcpServers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
19
|
+
type: z.ZodLiteral<"url">;
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
url: z.ZodString;
|
|
22
|
+
authorizationToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
toolConfiguration: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
24
|
+
enabled: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
25
|
+
allowedTools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
26
|
+
}, z.core.$strip>>>;
|
|
27
|
+
}, z.core.$strip>>>;
|
|
18
28
|
}, z.core.$strip>;
|
|
19
29
|
type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
|
|
20
30
|
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,16 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
15
15
|
type: z.ZodLiteral<"ephemeral">;
|
|
16
16
|
ttl: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
17
17
|
}, z.core.$strip>>;
|
|
18
|
+
mcpServers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
19
|
+
type: z.ZodLiteral<"url">;
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
url: z.ZodString;
|
|
22
|
+
authorizationToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
toolConfiguration: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
24
|
+
enabled: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
25
|
+
allowedTools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
26
|
+
}, z.core.$strip>>>;
|
|
27
|
+
}, z.core.$strip>>>;
|
|
18
28
|
}, z.core.$strip>;
|
|
19
29
|
type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
|
|
20
30
|
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
31
31
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/version.ts
|
|
34
|
-
var VERSION = true ? "3.0.0-beta.
|
|
34
|
+
var VERSION = true ? "3.0.0-beta.29" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -119,6 +119,24 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
119
119
|
name: import_v42.z.string(),
|
|
120
120
|
input: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).nullish()
|
|
121
121
|
}),
|
|
122
|
+
import_v42.z.object({
|
|
123
|
+
type: import_v42.z.literal("mcp_tool_use"),
|
|
124
|
+
id: import_v42.z.string(),
|
|
125
|
+
name: import_v42.z.string(),
|
|
126
|
+
input: import_v42.z.unknown(),
|
|
127
|
+
server_name: import_v42.z.string()
|
|
128
|
+
}),
|
|
129
|
+
import_v42.z.object({
|
|
130
|
+
type: import_v42.z.literal("mcp_tool_result"),
|
|
131
|
+
tool_use_id: import_v42.z.string(),
|
|
132
|
+
is_error: import_v42.z.boolean(),
|
|
133
|
+
content: import_v42.z.array(
|
|
134
|
+
import_v42.z.union([
|
|
135
|
+
import_v42.z.string(),
|
|
136
|
+
import_v42.z.object({ type: import_v42.z.literal("text"), text: import_v42.z.string() })
|
|
137
|
+
])
|
|
138
|
+
)
|
|
139
|
+
}),
|
|
122
140
|
import_v42.z.object({
|
|
123
141
|
type: import_v42.z.literal("web_fetch_tool_result"),
|
|
124
142
|
tool_use_id: import_v42.z.string(),
|
|
@@ -291,6 +309,24 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
291
309
|
name: import_v42.z.string(),
|
|
292
310
|
input: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).nullish()
|
|
293
311
|
}),
|
|
312
|
+
import_v42.z.object({
|
|
313
|
+
type: import_v42.z.literal("mcp_tool_use"),
|
|
314
|
+
id: import_v42.z.string(),
|
|
315
|
+
name: import_v42.z.string(),
|
|
316
|
+
input: import_v42.z.unknown(),
|
|
317
|
+
server_name: import_v42.z.string()
|
|
318
|
+
}),
|
|
319
|
+
import_v42.z.object({
|
|
320
|
+
type: import_v42.z.literal("mcp_tool_result"),
|
|
321
|
+
tool_use_id: import_v42.z.string(),
|
|
322
|
+
is_error: import_v42.z.boolean(),
|
|
323
|
+
content: import_v42.z.array(
|
|
324
|
+
import_v42.z.union([
|
|
325
|
+
import_v42.z.string(),
|
|
326
|
+
import_v42.z.object({ type: import_v42.z.literal("text"), text: import_v42.z.string() })
|
|
327
|
+
])
|
|
328
|
+
)
|
|
329
|
+
}),
|
|
294
330
|
import_v42.z.object({
|
|
295
331
|
type: import_v42.z.literal("web_fetch_tool_result"),
|
|
296
332
|
tool_use_id: import_v42.z.string(),
|
|
@@ -543,7 +579,19 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
543
579
|
cacheControl: import_v43.z.object({
|
|
544
580
|
type: import_v43.z.literal("ephemeral"),
|
|
545
581
|
ttl: import_v43.z.union([import_v43.z.literal("5m"), import_v43.z.literal("1h")]).optional()
|
|
546
|
-
}).optional()
|
|
582
|
+
}).optional(),
|
|
583
|
+
mcpServers: import_v43.z.array(
|
|
584
|
+
import_v43.z.object({
|
|
585
|
+
type: import_v43.z.literal("url"),
|
|
586
|
+
name: import_v43.z.string(),
|
|
587
|
+
url: import_v43.z.string(),
|
|
588
|
+
authorizationToken: import_v43.z.string().nullish(),
|
|
589
|
+
toolConfiguration: import_v43.z.object({
|
|
590
|
+
enabled: import_v43.z.boolean().nullish(),
|
|
591
|
+
allowedTools: import_v43.z.array(import_v43.z.string()).nullish()
|
|
592
|
+
}).nullish()
|
|
593
|
+
})
|
|
594
|
+
).optional()
|
|
547
595
|
});
|
|
548
596
|
|
|
549
597
|
// src/anthropic-prepare-tools.ts
|
|
@@ -1064,7 +1112,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1064
1112
|
sendReasoning,
|
|
1065
1113
|
warnings
|
|
1066
1114
|
}) {
|
|
1067
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1115
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1068
1116
|
const betas = /* @__PURE__ */ new Set();
|
|
1069
1117
|
const blocks = groupIntoBlocks(prompt);
|
|
1070
1118
|
let system = void 0;
|
|
@@ -1215,20 +1263,20 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1215
1263
|
return {
|
|
1216
1264
|
type: "text",
|
|
1217
1265
|
text: contentPart.text,
|
|
1218
|
-
cache_control:
|
|
1266
|
+
cache_control: cacheControl
|
|
1219
1267
|
};
|
|
1220
|
-
case "
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1268
|
+
case "image-data": {
|
|
1269
|
+
return {
|
|
1270
|
+
type: "image",
|
|
1271
|
+
source: {
|
|
1272
|
+
type: "base64",
|
|
1273
|
+
media_type: contentPart.mediaType,
|
|
1274
|
+
data: contentPart.data
|
|
1275
|
+
},
|
|
1276
|
+
cache_control: cacheControl
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
case "file-data": {
|
|
1232
1280
|
if (contentPart.mediaType === "application/pdf") {
|
|
1233
1281
|
betas.add("pdfs-2024-09-25");
|
|
1234
1282
|
return {
|
|
@@ -1238,15 +1286,24 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1238
1286
|
media_type: contentPart.mediaType,
|
|
1239
1287
|
data: contentPart.data
|
|
1240
1288
|
},
|
|
1241
|
-
cache_control:
|
|
1289
|
+
cache_control: cacheControl
|
|
1242
1290
|
};
|
|
1243
1291
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1292
|
+
warnings.push({
|
|
1293
|
+
type: "other",
|
|
1294
|
+
message: `unsupported tool content part type: ${contentPart.type} with media type: ${contentPart.mediaType}`
|
|
1246
1295
|
});
|
|
1296
|
+
return void 0;
|
|
1297
|
+
}
|
|
1298
|
+
default: {
|
|
1299
|
+
warnings.push({
|
|
1300
|
+
type: "other",
|
|
1301
|
+
message: `unsupported tool content part type: ${contentPart.type}`
|
|
1302
|
+
});
|
|
1303
|
+
return void 0;
|
|
1247
1304
|
}
|
|
1248
1305
|
}
|
|
1249
|
-
});
|
|
1306
|
+
}).filter(import_provider_utils10.isNonNullable);
|
|
1250
1307
|
break;
|
|
1251
1308
|
case "text":
|
|
1252
1309
|
case "error-text":
|
|
@@ -1282,6 +1339,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1282
1339
|
}
|
|
1283
1340
|
case "assistant": {
|
|
1284
1341
|
const anthropicContent = [];
|
|
1342
|
+
const mcpToolUseIds = /* @__PURE__ */ new Set();
|
|
1285
1343
|
for (let j = 0; j < block.messages.length; j++) {
|
|
1286
1344
|
const message = block.messages[j];
|
|
1287
1345
|
const isLastMessage = j === block.messages.length - 1;
|
|
@@ -1347,7 +1405,29 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1347
1405
|
}
|
|
1348
1406
|
case "tool-call": {
|
|
1349
1407
|
if (part.providerExecuted) {
|
|
1350
|
-
|
|
1408
|
+
const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
|
|
1409
|
+
if (isMcpToolUse) {
|
|
1410
|
+
mcpToolUseIds.add(part.toolCallId);
|
|
1411
|
+
const serverName = (_j = (_i = part.providerOptions) == null ? void 0 : _i.anthropic) == null ? void 0 : _j.serverName;
|
|
1412
|
+
if (serverName == null || typeof serverName !== "string") {
|
|
1413
|
+
warnings.push({
|
|
1414
|
+
type: "other",
|
|
1415
|
+
message: "mcp tool use server name is required and must be a string"
|
|
1416
|
+
});
|
|
1417
|
+
break;
|
|
1418
|
+
}
|
|
1419
|
+
anthropicContent.push({
|
|
1420
|
+
type: "mcp_tool_use",
|
|
1421
|
+
id: part.toolCallId,
|
|
1422
|
+
name: part.toolName,
|
|
1423
|
+
input: part.input,
|
|
1424
|
+
server_name: serverName,
|
|
1425
|
+
cache_control: cacheControl
|
|
1426
|
+
});
|
|
1427
|
+
} else if (
|
|
1428
|
+
// code execution 20250825:
|
|
1429
|
+
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")
|
|
1430
|
+
) {
|
|
1351
1431
|
anthropicContent.push({
|
|
1352
1432
|
type: "server_tool_use",
|
|
1353
1433
|
id: part.toolCallId,
|
|
@@ -1383,7 +1463,23 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1383
1463
|
break;
|
|
1384
1464
|
}
|
|
1385
1465
|
case "tool-result": {
|
|
1386
|
-
if (part.
|
|
1466
|
+
if (mcpToolUseIds.has(part.toolCallId)) {
|
|
1467
|
+
const output = part.output;
|
|
1468
|
+
if (output.type !== "json" && output.type !== "error-json") {
|
|
1469
|
+
warnings.push({
|
|
1470
|
+
type: "other",
|
|
1471
|
+
message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
|
|
1472
|
+
});
|
|
1473
|
+
break;
|
|
1474
|
+
}
|
|
1475
|
+
anthropicContent.push({
|
|
1476
|
+
type: "mcp_tool_result",
|
|
1477
|
+
tool_use_id: part.toolCallId,
|
|
1478
|
+
is_error: output.type === "error-json",
|
|
1479
|
+
content: output.value,
|
|
1480
|
+
cache_control: cacheControl
|
|
1481
|
+
});
|
|
1482
|
+
} else if (part.toolName === "code_execution") {
|
|
1387
1483
|
const output = part.output;
|
|
1388
1484
|
if (output.type !== "json") {
|
|
1389
1485
|
warnings.push({
|
|
@@ -1698,7 +1794,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1698
1794
|
providerOptions,
|
|
1699
1795
|
schema: anthropicProviderOptions
|
|
1700
1796
|
});
|
|
1701
|
-
const { prompt: messagesPrompt, betas
|
|
1797
|
+
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1702
1798
|
prompt,
|
|
1703
1799
|
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
1704
1800
|
warnings
|
|
@@ -1720,6 +1816,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1720
1816
|
...isThinking && {
|
|
1721
1817
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
1722
1818
|
},
|
|
1819
|
+
// mcp servers:
|
|
1820
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
|
|
1821
|
+
mcp_servers: anthropicOptions.mcpServers.map((server) => ({
|
|
1822
|
+
type: server.type,
|
|
1823
|
+
name: server.name,
|
|
1824
|
+
url: server.url,
|
|
1825
|
+
authorization_token: server.authorizationToken,
|
|
1826
|
+
tool_configuration: server.toolConfiguration ? {
|
|
1827
|
+
allowed_tools: server.toolConfiguration.allowedTools,
|
|
1828
|
+
enabled: server.toolConfiguration.enabled
|
|
1829
|
+
} : void 0
|
|
1830
|
+
}))
|
|
1831
|
+
},
|
|
1723
1832
|
// prompt:
|
|
1724
1833
|
system: messagesPrompt.system,
|
|
1725
1834
|
messages: messagesPrompt.messages
|
|
@@ -1761,11 +1870,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1761
1870
|
warnings.push({
|
|
1762
1871
|
type: "unsupported-setting",
|
|
1763
1872
|
setting: "maxOutputTokens",
|
|
1764
|
-
details: `${
|
|
1873
|
+
details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
|
|
1765
1874
|
});
|
|
1766
1875
|
}
|
|
1767
1876
|
baseArgs.max_tokens = maxOutputTokensForModel;
|
|
1768
1877
|
}
|
|
1878
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
|
|
1879
|
+
betas.add("mcp-client-2025-04-04");
|
|
1880
|
+
}
|
|
1769
1881
|
const {
|
|
1770
1882
|
tools: anthropicTools2,
|
|
1771
1883
|
toolChoice: anthropicToolChoice,
|
|
@@ -1789,7 +1901,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1789
1901
|
tool_choice: anthropicToolChoice
|
|
1790
1902
|
},
|
|
1791
1903
|
warnings: [...warnings, ...toolWarnings],
|
|
1792
|
-
betas: /* @__PURE__ */ new Set([...
|
|
1904
|
+
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
|
|
1793
1905
|
usesJsonResponseTool: jsonResponseTool != null
|
|
1794
1906
|
};
|
|
1795
1907
|
}
|
|
@@ -1854,6 +1966,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1854
1966
|
fetch: this.config.fetch
|
|
1855
1967
|
});
|
|
1856
1968
|
const content = [];
|
|
1969
|
+
const mcpToolCalls = {};
|
|
1857
1970
|
for (const part of response.content) {
|
|
1858
1971
|
switch (part.type) {
|
|
1859
1972
|
case "text": {
|
|
@@ -1933,6 +2046,37 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1933
2046
|
}
|
|
1934
2047
|
break;
|
|
1935
2048
|
}
|
|
2049
|
+
case "mcp_tool_use": {
|
|
2050
|
+
mcpToolCalls[part.id] = {
|
|
2051
|
+
type: "tool-call",
|
|
2052
|
+
toolCallId: part.id,
|
|
2053
|
+
toolName: part.name,
|
|
2054
|
+
input: JSON.stringify(part.input),
|
|
2055
|
+
providerExecuted: true,
|
|
2056
|
+
dynamic: true,
|
|
2057
|
+
providerMetadata: {
|
|
2058
|
+
anthropic: {
|
|
2059
|
+
type: "mcp-tool-use",
|
|
2060
|
+
serverName: part.server_name
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2064
|
+
content.push(mcpToolCalls[part.id]);
|
|
2065
|
+
break;
|
|
2066
|
+
}
|
|
2067
|
+
case "mcp_tool_result": {
|
|
2068
|
+
content.push({
|
|
2069
|
+
type: "tool-result",
|
|
2070
|
+
toolCallId: part.tool_use_id,
|
|
2071
|
+
toolName: mcpToolCalls[part.tool_use_id].toolName,
|
|
2072
|
+
isError: part.is_error,
|
|
2073
|
+
result: part.content,
|
|
2074
|
+
providerExecuted: true,
|
|
2075
|
+
dynamic: true,
|
|
2076
|
+
providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
|
|
2077
|
+
});
|
|
2078
|
+
break;
|
|
2079
|
+
}
|
|
1936
2080
|
case "web_fetch_tool_result": {
|
|
1937
2081
|
if (part.content.type === "web_fetch_result") {
|
|
1938
2082
|
content.push({
|
|
@@ -2113,6 +2257,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2113
2257
|
totalTokens: void 0
|
|
2114
2258
|
};
|
|
2115
2259
|
const contentBlocks = {};
|
|
2260
|
+
const mcpToolCalls = {};
|
|
2116
2261
|
let rawUsage = void 0;
|
|
2117
2262
|
let cacheCreationInputTokens = null;
|
|
2118
2263
|
let stopSequence = null;
|
|
@@ -2139,7 +2284,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2139
2284
|
return;
|
|
2140
2285
|
}
|
|
2141
2286
|
case "content_block_start": {
|
|
2142
|
-
const
|
|
2287
|
+
const part = value.content_block;
|
|
2288
|
+
const contentBlockType = part.type;
|
|
2143
2289
|
blockType = contentBlockType;
|
|
2144
2290
|
switch (contentBlockType) {
|
|
2145
2291
|
case "text": {
|
|
@@ -2165,7 +2311,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2165
2311
|
id: String(value.index),
|
|
2166
2312
|
providerMetadata: {
|
|
2167
2313
|
anthropic: {
|
|
2168
|
-
redactedData:
|
|
2314
|
+
redactedData: part.data
|
|
2169
2315
|
}
|
|
2170
2316
|
}
|
|
2171
2317
|
});
|
|
@@ -2174,16 +2320,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2174
2320
|
case "tool_use": {
|
|
2175
2321
|
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
2176
2322
|
type: "tool-call",
|
|
2177
|
-
toolCallId:
|
|
2178
|
-
toolName:
|
|
2323
|
+
toolCallId: part.id,
|
|
2324
|
+
toolName: part.name,
|
|
2179
2325
|
input: "",
|
|
2180
2326
|
firstDelta: true
|
|
2181
2327
|
};
|
|
2182
2328
|
controller.enqueue(
|
|
2183
2329
|
usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
|
|
2184
2330
|
type: "tool-input-start",
|
|
2185
|
-
id:
|
|
2186
|
-
toolName:
|
|
2331
|
+
id: part.id,
|
|
2332
|
+
toolName: part.name
|
|
2187
2333
|
}
|
|
2188
2334
|
);
|
|
2189
2335
|
return;
|
|
@@ -2198,19 +2344,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2198
2344
|
"text_editor_code_execution",
|
|
2199
2345
|
// code execution 20250825 bash:
|
|
2200
2346
|
"bash_code_execution"
|
|
2201
|
-
].includes(
|
|
2347
|
+
].includes(part.name)) {
|
|
2202
2348
|
contentBlocks[value.index] = {
|
|
2203
2349
|
type: "tool-call",
|
|
2204
|
-
toolCallId:
|
|
2205
|
-
toolName:
|
|
2350
|
+
toolCallId: part.id,
|
|
2351
|
+
toolName: part.name,
|
|
2206
2352
|
input: "",
|
|
2207
2353
|
providerExecuted: true,
|
|
2208
2354
|
firstDelta: true
|
|
2209
2355
|
};
|
|
2210
|
-
const mappedToolName =
|
|
2356
|
+
const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
|
|
2211
2357
|
controller.enqueue({
|
|
2212
2358
|
type: "tool-input-start",
|
|
2213
|
-
id:
|
|
2359
|
+
id: part.id,
|
|
2214
2360
|
toolName: mappedToolName,
|
|
2215
2361
|
providerExecuted: true
|
|
2216
2362
|
});
|
|
@@ -2218,7 +2364,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2218
2364
|
return;
|
|
2219
2365
|
}
|
|
2220
2366
|
case "web_fetch_tool_result": {
|
|
2221
|
-
const part = value.content_block;
|
|
2222
2367
|
if (part.content.type === "web_fetch_result") {
|
|
2223
2368
|
controller.enqueue({
|
|
2224
2369
|
type: "tool-result",
|
|
@@ -2256,7 +2401,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2256
2401
|
return;
|
|
2257
2402
|
}
|
|
2258
2403
|
case "web_search_tool_result": {
|
|
2259
|
-
const part = value.content_block;
|
|
2260
2404
|
if (Array.isArray(part.content)) {
|
|
2261
2405
|
controller.enqueue({
|
|
2262
2406
|
type: "tool-result",
|
|
@@ -2305,7 +2449,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2305
2449
|
}
|
|
2306
2450
|
// code execution 20250522:
|
|
2307
2451
|
case "code_execution_tool_result": {
|
|
2308
|
-
const part = value.content_block;
|
|
2309
2452
|
if (part.content.type === "code_execution_result") {
|
|
2310
2453
|
controller.enqueue({
|
|
2311
2454
|
type: "tool-result",
|
|
@@ -2337,7 +2480,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2337
2480
|
// code execution 20250825:
|
|
2338
2481
|
case "bash_code_execution_tool_result":
|
|
2339
2482
|
case "text_editor_code_execution_tool_result": {
|
|
2340
|
-
const part = value.content_block;
|
|
2341
2483
|
controller.enqueue({
|
|
2342
2484
|
type: "tool-result",
|
|
2343
2485
|
toolCallId: part.tool_use_id,
|
|
@@ -2347,6 +2489,37 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2347
2489
|
});
|
|
2348
2490
|
return;
|
|
2349
2491
|
}
|
|
2492
|
+
case "mcp_tool_use": {
|
|
2493
|
+
mcpToolCalls[part.id] = {
|
|
2494
|
+
type: "tool-call",
|
|
2495
|
+
toolCallId: part.id,
|
|
2496
|
+
toolName: part.name,
|
|
2497
|
+
input: JSON.stringify(part.input),
|
|
2498
|
+
providerExecuted: true,
|
|
2499
|
+
dynamic: true,
|
|
2500
|
+
providerMetadata: {
|
|
2501
|
+
anthropic: {
|
|
2502
|
+
type: "mcp-tool-use",
|
|
2503
|
+
serverName: part.server_name
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
};
|
|
2507
|
+
controller.enqueue(mcpToolCalls[part.id]);
|
|
2508
|
+
return;
|
|
2509
|
+
}
|
|
2510
|
+
case "mcp_tool_result": {
|
|
2511
|
+
controller.enqueue({
|
|
2512
|
+
type: "tool-result",
|
|
2513
|
+
toolCallId: part.tool_use_id,
|
|
2514
|
+
toolName: mcpToolCalls[part.tool_use_id].toolName,
|
|
2515
|
+
isError: part.is_error,
|
|
2516
|
+
result: part.content,
|
|
2517
|
+
providerExecuted: true,
|
|
2518
|
+
dynamic: true,
|
|
2519
|
+
providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
|
|
2520
|
+
});
|
|
2521
|
+
return;
|
|
2522
|
+
}
|
|
2350
2523
|
default: {
|
|
2351
2524
|
const _exhaustiveCheck = contentBlockType;
|
|
2352
2525
|
throw new Error(
|