@ai-sdk/anthropic 3.0.0-beta.26 → 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 +15 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +212 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +212 -26
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +211 -25
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +211 -25
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.28
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 81d4308: feat(provider/anthropic): mcp connector support
|
|
8
|
+
- Updated dependencies [81d4308]
|
|
9
|
+
- @ai-sdk/provider@3.0.0-beta.7
|
|
10
|
+
- @ai-sdk/provider-utils@4.0.0-beta.18
|
|
11
|
+
|
|
12
|
+
## 3.0.0-beta.27
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 4c5a6be: feat(provider/anthropic): default and limit maxTokens based on model
|
|
17
|
+
|
|
3
18
|
## 3.0.0-beta.26
|
|
4
19
|
|
|
5
20
|
### 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.28" : "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;
|
|
@@ -1282,6 +1330,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1282
1330
|
}
|
|
1283
1331
|
case "assistant": {
|
|
1284
1332
|
const anthropicContent = [];
|
|
1333
|
+
const mcpToolUseIds = /* @__PURE__ */ new Set();
|
|
1285
1334
|
for (let j = 0; j < block.messages.length; j++) {
|
|
1286
1335
|
const message = block.messages[j];
|
|
1287
1336
|
const isLastMessage = j === block.messages.length - 1;
|
|
@@ -1347,7 +1396,29 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1347
1396
|
}
|
|
1348
1397
|
case "tool-call": {
|
|
1349
1398
|
if (part.providerExecuted) {
|
|
1350
|
-
|
|
1399
|
+
const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
|
|
1400
|
+
if (isMcpToolUse) {
|
|
1401
|
+
mcpToolUseIds.add(part.toolCallId);
|
|
1402
|
+
const serverName = (_j = (_i = part.providerOptions) == null ? void 0 : _i.anthropic) == null ? void 0 : _j.serverName;
|
|
1403
|
+
if (serverName == null || typeof serverName !== "string") {
|
|
1404
|
+
warnings.push({
|
|
1405
|
+
type: "other",
|
|
1406
|
+
message: "mcp tool use server name is required and must be a string"
|
|
1407
|
+
});
|
|
1408
|
+
break;
|
|
1409
|
+
}
|
|
1410
|
+
anthropicContent.push({
|
|
1411
|
+
type: "mcp_tool_use",
|
|
1412
|
+
id: part.toolCallId,
|
|
1413
|
+
name: part.toolName,
|
|
1414
|
+
input: part.input,
|
|
1415
|
+
server_name: serverName,
|
|
1416
|
+
cache_control: cacheControl
|
|
1417
|
+
});
|
|
1418
|
+
} else if (
|
|
1419
|
+
// code execution 20250825:
|
|
1420
|
+
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")
|
|
1421
|
+
) {
|
|
1351
1422
|
anthropicContent.push({
|
|
1352
1423
|
type: "server_tool_use",
|
|
1353
1424
|
id: part.toolCallId,
|
|
@@ -1383,7 +1454,23 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1383
1454
|
break;
|
|
1384
1455
|
}
|
|
1385
1456
|
case "tool-result": {
|
|
1386
|
-
if (part.
|
|
1457
|
+
if (mcpToolUseIds.has(part.toolCallId)) {
|
|
1458
|
+
const output = part.output;
|
|
1459
|
+
if (output.type !== "json" && output.type !== "error-json") {
|
|
1460
|
+
warnings.push({
|
|
1461
|
+
type: "other",
|
|
1462
|
+
message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
|
|
1463
|
+
});
|
|
1464
|
+
break;
|
|
1465
|
+
}
|
|
1466
|
+
anthropicContent.push({
|
|
1467
|
+
type: "mcp_tool_result",
|
|
1468
|
+
tool_use_id: part.toolCallId,
|
|
1469
|
+
is_error: output.type === "error-json",
|
|
1470
|
+
content: output.value,
|
|
1471
|
+
cache_control: cacheControl
|
|
1472
|
+
});
|
|
1473
|
+
} else if (part.toolName === "code_execution") {
|
|
1387
1474
|
const output = part.output;
|
|
1388
1475
|
if (output.type !== "json") {
|
|
1389
1476
|
warnings.push({
|
|
@@ -1639,8 +1726,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1639
1726
|
}
|
|
1640
1727
|
async getArgs({
|
|
1641
1728
|
prompt,
|
|
1642
|
-
maxOutputTokens
|
|
1643
|
-
// 4096: max model output tokens TODO update default in v5
|
|
1729
|
+
maxOutputTokens,
|
|
1644
1730
|
temperature,
|
|
1645
1731
|
topP,
|
|
1646
1732
|
topK,
|
|
@@ -1699,18 +1785,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1699
1785
|
providerOptions,
|
|
1700
1786
|
schema: anthropicProviderOptions
|
|
1701
1787
|
});
|
|
1702
|
-
const { prompt: messagesPrompt, betas
|
|
1788
|
+
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1703
1789
|
prompt,
|
|
1704
1790
|
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
1705
1791
|
warnings
|
|
1706
1792
|
});
|
|
1707
1793
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
1708
1794
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
1795
|
+
const maxOutputTokensForModel = getMaxOutputTokensForModel(this.modelId);
|
|
1796
|
+
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
1709
1797
|
const baseArgs = {
|
|
1710
1798
|
// model id:
|
|
1711
1799
|
model: this.modelId,
|
|
1712
1800
|
// standardized settings:
|
|
1713
|
-
max_tokens:
|
|
1801
|
+
max_tokens: maxTokens,
|
|
1714
1802
|
temperature,
|
|
1715
1803
|
top_k: topK,
|
|
1716
1804
|
top_p: topP,
|
|
@@ -1719,6 +1807,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1719
1807
|
...isThinking && {
|
|
1720
1808
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
1721
1809
|
},
|
|
1810
|
+
// mcp servers:
|
|
1811
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
|
|
1812
|
+
mcp_servers: anthropicOptions.mcpServers.map((server) => ({
|
|
1813
|
+
type: server.type,
|
|
1814
|
+
name: server.name,
|
|
1815
|
+
url: server.url,
|
|
1816
|
+
authorization_token: server.authorizationToken,
|
|
1817
|
+
tool_configuration: server.toolConfiguration ? {
|
|
1818
|
+
allowed_tools: server.toolConfiguration.allowedTools,
|
|
1819
|
+
enabled: server.toolConfiguration.enabled
|
|
1820
|
+
} : void 0
|
|
1821
|
+
}))
|
|
1822
|
+
},
|
|
1722
1823
|
// prompt:
|
|
1723
1824
|
system: messagesPrompt.system,
|
|
1724
1825
|
messages: messagesPrompt.messages
|
|
@@ -1753,7 +1854,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1753
1854
|
details: "topP is not supported when thinking is enabled"
|
|
1754
1855
|
});
|
|
1755
1856
|
}
|
|
1756
|
-
baseArgs.max_tokens =
|
|
1857
|
+
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
1858
|
+
}
|
|
1859
|
+
if (baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
1860
|
+
if (maxOutputTokens != null) {
|
|
1861
|
+
warnings.push({
|
|
1862
|
+
type: "unsupported-setting",
|
|
1863
|
+
setting: "maxOutputTokens",
|
|
1864
|
+
details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
baseArgs.max_tokens = maxOutputTokensForModel;
|
|
1868
|
+
}
|
|
1869
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
|
|
1870
|
+
betas.add("mcp-client-2025-04-04");
|
|
1757
1871
|
}
|
|
1758
1872
|
const {
|
|
1759
1873
|
tools: anthropicTools2,
|
|
@@ -1778,7 +1892,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1778
1892
|
tool_choice: anthropicToolChoice
|
|
1779
1893
|
},
|
|
1780
1894
|
warnings: [...warnings, ...toolWarnings],
|
|
1781
|
-
betas: /* @__PURE__ */ new Set([...
|
|
1895
|
+
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
|
|
1782
1896
|
usesJsonResponseTool: jsonResponseTool != null
|
|
1783
1897
|
};
|
|
1784
1898
|
}
|
|
@@ -1843,6 +1957,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1843
1957
|
fetch: this.config.fetch
|
|
1844
1958
|
});
|
|
1845
1959
|
const content = [];
|
|
1960
|
+
const mcpToolCalls = {};
|
|
1846
1961
|
for (const part of response.content) {
|
|
1847
1962
|
switch (part.type) {
|
|
1848
1963
|
case "text": {
|
|
@@ -1922,6 +2037,37 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1922
2037
|
}
|
|
1923
2038
|
break;
|
|
1924
2039
|
}
|
|
2040
|
+
case "mcp_tool_use": {
|
|
2041
|
+
mcpToolCalls[part.id] = {
|
|
2042
|
+
type: "tool-call",
|
|
2043
|
+
toolCallId: part.id,
|
|
2044
|
+
toolName: part.name,
|
|
2045
|
+
input: JSON.stringify(part.input),
|
|
2046
|
+
providerExecuted: true,
|
|
2047
|
+
dynamic: true,
|
|
2048
|
+
providerMetadata: {
|
|
2049
|
+
anthropic: {
|
|
2050
|
+
type: "mcp-tool-use",
|
|
2051
|
+
serverName: part.server_name
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
};
|
|
2055
|
+
content.push(mcpToolCalls[part.id]);
|
|
2056
|
+
break;
|
|
2057
|
+
}
|
|
2058
|
+
case "mcp_tool_result": {
|
|
2059
|
+
content.push({
|
|
2060
|
+
type: "tool-result",
|
|
2061
|
+
toolCallId: part.tool_use_id,
|
|
2062
|
+
toolName: mcpToolCalls[part.tool_use_id].toolName,
|
|
2063
|
+
isError: part.is_error,
|
|
2064
|
+
result: part.content,
|
|
2065
|
+
providerExecuted: true,
|
|
2066
|
+
dynamic: true,
|
|
2067
|
+
providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
|
|
2068
|
+
});
|
|
2069
|
+
break;
|
|
2070
|
+
}
|
|
1925
2071
|
case "web_fetch_tool_result": {
|
|
1926
2072
|
if (part.content.type === "web_fetch_result") {
|
|
1927
2073
|
content.push({
|
|
@@ -2102,6 +2248,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2102
2248
|
totalTokens: void 0
|
|
2103
2249
|
};
|
|
2104
2250
|
const contentBlocks = {};
|
|
2251
|
+
const mcpToolCalls = {};
|
|
2105
2252
|
let rawUsage = void 0;
|
|
2106
2253
|
let cacheCreationInputTokens = null;
|
|
2107
2254
|
let stopSequence = null;
|
|
@@ -2128,7 +2275,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2128
2275
|
return;
|
|
2129
2276
|
}
|
|
2130
2277
|
case "content_block_start": {
|
|
2131
|
-
const
|
|
2278
|
+
const part = value.content_block;
|
|
2279
|
+
const contentBlockType = part.type;
|
|
2132
2280
|
blockType = contentBlockType;
|
|
2133
2281
|
switch (contentBlockType) {
|
|
2134
2282
|
case "text": {
|
|
@@ -2154,7 +2302,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2154
2302
|
id: String(value.index),
|
|
2155
2303
|
providerMetadata: {
|
|
2156
2304
|
anthropic: {
|
|
2157
|
-
redactedData:
|
|
2305
|
+
redactedData: part.data
|
|
2158
2306
|
}
|
|
2159
2307
|
}
|
|
2160
2308
|
});
|
|
@@ -2163,16 +2311,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2163
2311
|
case "tool_use": {
|
|
2164
2312
|
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
2165
2313
|
type: "tool-call",
|
|
2166
|
-
toolCallId:
|
|
2167
|
-
toolName:
|
|
2314
|
+
toolCallId: part.id,
|
|
2315
|
+
toolName: part.name,
|
|
2168
2316
|
input: "",
|
|
2169
2317
|
firstDelta: true
|
|
2170
2318
|
};
|
|
2171
2319
|
controller.enqueue(
|
|
2172
2320
|
usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
|
|
2173
2321
|
type: "tool-input-start",
|
|
2174
|
-
id:
|
|
2175
|
-
toolName:
|
|
2322
|
+
id: part.id,
|
|
2323
|
+
toolName: part.name
|
|
2176
2324
|
}
|
|
2177
2325
|
);
|
|
2178
2326
|
return;
|
|
@@ -2187,19 +2335,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2187
2335
|
"text_editor_code_execution",
|
|
2188
2336
|
// code execution 20250825 bash:
|
|
2189
2337
|
"bash_code_execution"
|
|
2190
|
-
].includes(
|
|
2338
|
+
].includes(part.name)) {
|
|
2191
2339
|
contentBlocks[value.index] = {
|
|
2192
2340
|
type: "tool-call",
|
|
2193
|
-
toolCallId:
|
|
2194
|
-
toolName:
|
|
2341
|
+
toolCallId: part.id,
|
|
2342
|
+
toolName: part.name,
|
|
2195
2343
|
input: "",
|
|
2196
2344
|
providerExecuted: true,
|
|
2197
2345
|
firstDelta: true
|
|
2198
2346
|
};
|
|
2199
|
-
const mappedToolName =
|
|
2347
|
+
const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
|
|
2200
2348
|
controller.enqueue({
|
|
2201
2349
|
type: "tool-input-start",
|
|
2202
|
-
id:
|
|
2350
|
+
id: part.id,
|
|
2203
2351
|
toolName: mappedToolName,
|
|
2204
2352
|
providerExecuted: true
|
|
2205
2353
|
});
|
|
@@ -2207,7 +2355,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2207
2355
|
return;
|
|
2208
2356
|
}
|
|
2209
2357
|
case "web_fetch_tool_result": {
|
|
2210
|
-
const part = value.content_block;
|
|
2211
2358
|
if (part.content.type === "web_fetch_result") {
|
|
2212
2359
|
controller.enqueue({
|
|
2213
2360
|
type: "tool-result",
|
|
@@ -2245,7 +2392,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2245
2392
|
return;
|
|
2246
2393
|
}
|
|
2247
2394
|
case "web_search_tool_result": {
|
|
2248
|
-
const part = value.content_block;
|
|
2249
2395
|
if (Array.isArray(part.content)) {
|
|
2250
2396
|
controller.enqueue({
|
|
2251
2397
|
type: "tool-result",
|
|
@@ -2294,7 +2440,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2294
2440
|
}
|
|
2295
2441
|
// code execution 20250522:
|
|
2296
2442
|
case "code_execution_tool_result": {
|
|
2297
|
-
const part = value.content_block;
|
|
2298
2443
|
if (part.content.type === "code_execution_result") {
|
|
2299
2444
|
controller.enqueue({
|
|
2300
2445
|
type: "tool-result",
|
|
@@ -2326,7 +2471,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2326
2471
|
// code execution 20250825:
|
|
2327
2472
|
case "bash_code_execution_tool_result":
|
|
2328
2473
|
case "text_editor_code_execution_tool_result": {
|
|
2329
|
-
const part = value.content_block;
|
|
2330
2474
|
controller.enqueue({
|
|
2331
2475
|
type: "tool-result",
|
|
2332
2476
|
toolCallId: part.tool_use_id,
|
|
@@ -2336,6 +2480,37 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2336
2480
|
});
|
|
2337
2481
|
return;
|
|
2338
2482
|
}
|
|
2483
|
+
case "mcp_tool_use": {
|
|
2484
|
+
mcpToolCalls[part.id] = {
|
|
2485
|
+
type: "tool-call",
|
|
2486
|
+
toolCallId: part.id,
|
|
2487
|
+
toolName: part.name,
|
|
2488
|
+
input: JSON.stringify(part.input),
|
|
2489
|
+
providerExecuted: true,
|
|
2490
|
+
dynamic: true,
|
|
2491
|
+
providerMetadata: {
|
|
2492
|
+
anthropic: {
|
|
2493
|
+
type: "mcp-tool-use",
|
|
2494
|
+
serverName: part.server_name
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
};
|
|
2498
|
+
controller.enqueue(mcpToolCalls[part.id]);
|
|
2499
|
+
return;
|
|
2500
|
+
}
|
|
2501
|
+
case "mcp_tool_result": {
|
|
2502
|
+
controller.enqueue({
|
|
2503
|
+
type: "tool-result",
|
|
2504
|
+
toolCallId: part.tool_use_id,
|
|
2505
|
+
toolName: mcpToolCalls[part.tool_use_id].toolName,
|
|
2506
|
+
isError: part.is_error,
|
|
2507
|
+
result: part.content,
|
|
2508
|
+
providerExecuted: true,
|
|
2509
|
+
dynamic: true,
|
|
2510
|
+
providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
|
|
2511
|
+
});
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2339
2514
|
default: {
|
|
2340
2515
|
const _exhaustiveCheck = contentBlockType;
|
|
2341
2516
|
throw new Error(
|
|
@@ -2533,6 +2708,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2533
2708
|
};
|
|
2534
2709
|
}
|
|
2535
2710
|
};
|
|
2711
|
+
function getMaxOutputTokensForModel(modelId) {
|
|
2712
|
+
if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
|
|
2713
|
+
return 64e3;
|
|
2714
|
+
} else if (modelId.includes("claude-opus-4-")) {
|
|
2715
|
+
return 32e3;
|
|
2716
|
+
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
2717
|
+
return 8192;
|
|
2718
|
+
} else {
|
|
2719
|
+
return 4096;
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2536
2722
|
|
|
2537
2723
|
// src/tool/bash_20241022.ts
|
|
2538
2724
|
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|