@ai-sdk/anthropic 3.0.0-beta.91 → 3.0.0-beta.93
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 +16 -0
- package/dist/index.d.mts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +336 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +334 -54
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +40 -0
- package/dist/internal/index.d.ts +40 -0
- package/dist/internal/index.js +311 -52
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +311 -52
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "3.0.0-beta.
|
|
14
|
+
var VERSION = true ? "3.0.0-beta.93" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -129,7 +129,17 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
129
129
|
type: z2.literal("tool_use"),
|
|
130
130
|
id: z2.string(),
|
|
131
131
|
name: z2.string(),
|
|
132
|
-
input: z2.unknown()
|
|
132
|
+
input: z2.unknown(),
|
|
133
|
+
// Programmatic tool calling: caller info when triggered from code execution
|
|
134
|
+
caller: z2.union([
|
|
135
|
+
z2.object({
|
|
136
|
+
type: z2.literal("code_execution_20250825"),
|
|
137
|
+
tool_id: z2.string()
|
|
138
|
+
}),
|
|
139
|
+
z2.object({
|
|
140
|
+
type: z2.literal("direct")
|
|
141
|
+
})
|
|
142
|
+
]).optional()
|
|
133
143
|
}),
|
|
134
144
|
z2.object({
|
|
135
145
|
type: z2.literal("server_tool_use"),
|
|
@@ -215,7 +225,13 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
215
225
|
type: z2.literal("code_execution_result"),
|
|
216
226
|
stdout: z2.string(),
|
|
217
227
|
stderr: z2.string(),
|
|
218
|
-
return_code: z2.number()
|
|
228
|
+
return_code: z2.number(),
|
|
229
|
+
content: z2.array(
|
|
230
|
+
z2.object({
|
|
231
|
+
type: z2.literal("code_execution_output"),
|
|
232
|
+
file_id: z2.string()
|
|
233
|
+
})
|
|
234
|
+
).optional().default([])
|
|
219
235
|
}),
|
|
220
236
|
z2.object({
|
|
221
237
|
type: z2.literal("code_execution_tool_result_error"),
|
|
@@ -347,11 +363,37 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
347
363
|
message: z2.object({
|
|
348
364
|
id: z2.string().nullish(),
|
|
349
365
|
model: z2.string().nullish(),
|
|
366
|
+
role: z2.string().nullish(),
|
|
350
367
|
usage: z2.looseObject({
|
|
351
368
|
input_tokens: z2.number(),
|
|
352
369
|
cache_creation_input_tokens: z2.number().nullish(),
|
|
353
370
|
cache_read_input_tokens: z2.number().nullish()
|
|
354
|
-
})
|
|
371
|
+
}),
|
|
372
|
+
// Programmatic tool calling: content may be pre-populated for deferred tool calls
|
|
373
|
+
content: z2.array(
|
|
374
|
+
z2.discriminatedUnion("type", [
|
|
375
|
+
z2.object({
|
|
376
|
+
type: z2.literal("tool_use"),
|
|
377
|
+
id: z2.string(),
|
|
378
|
+
name: z2.string(),
|
|
379
|
+
input: z2.unknown(),
|
|
380
|
+
caller: z2.union([
|
|
381
|
+
z2.object({
|
|
382
|
+
type: z2.literal("code_execution_20250825"),
|
|
383
|
+
tool_id: z2.string()
|
|
384
|
+
}),
|
|
385
|
+
z2.object({
|
|
386
|
+
type: z2.literal("direct")
|
|
387
|
+
})
|
|
388
|
+
]).optional()
|
|
389
|
+
})
|
|
390
|
+
])
|
|
391
|
+
).nullish(),
|
|
392
|
+
stop_reason: z2.string().nullish(),
|
|
393
|
+
container: z2.object({
|
|
394
|
+
expires_at: z2.string(),
|
|
395
|
+
id: z2.string()
|
|
396
|
+
}).nullish()
|
|
355
397
|
})
|
|
356
398
|
}),
|
|
357
399
|
z2.object({
|
|
@@ -369,7 +411,19 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
369
411
|
z2.object({
|
|
370
412
|
type: z2.literal("tool_use"),
|
|
371
413
|
id: z2.string(),
|
|
372
|
-
name: z2.string()
|
|
414
|
+
name: z2.string(),
|
|
415
|
+
// Programmatic tool calling: input may be present directly for deferred tool calls
|
|
416
|
+
input: z2.record(z2.string(), z2.unknown()).optional(),
|
|
417
|
+
// Programmatic tool calling: caller info when triggered from code execution
|
|
418
|
+
caller: z2.union([
|
|
419
|
+
z2.object({
|
|
420
|
+
type: z2.literal("code_execution_20250825"),
|
|
421
|
+
tool_id: z2.string()
|
|
422
|
+
}),
|
|
423
|
+
z2.object({
|
|
424
|
+
type: z2.literal("direct")
|
|
425
|
+
})
|
|
426
|
+
]).optional()
|
|
373
427
|
}),
|
|
374
428
|
z2.object({
|
|
375
429
|
type: z2.literal("redacted_thinking"),
|
|
@@ -459,7 +513,13 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
459
513
|
type: z2.literal("code_execution_result"),
|
|
460
514
|
stdout: z2.string(),
|
|
461
515
|
stderr: z2.string(),
|
|
462
|
-
return_code: z2.number()
|
|
516
|
+
return_code: z2.number(),
|
|
517
|
+
content: z2.array(
|
|
518
|
+
z2.object({
|
|
519
|
+
type: z2.literal("code_execution_output"),
|
|
520
|
+
file_id: z2.string()
|
|
521
|
+
})
|
|
522
|
+
).optional().default([])
|
|
463
523
|
}),
|
|
464
524
|
z2.object({
|
|
465
525
|
type: z2.literal("code_execution_tool_result_error"),
|
|
@@ -1030,6 +1090,7 @@ async function prepareTools({
|
|
|
1030
1090
|
});
|
|
1031
1091
|
const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
|
|
1032
1092
|
const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
|
|
1093
|
+
const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
|
|
1033
1094
|
anthropicTools2.push({
|
|
1034
1095
|
name: tool.name,
|
|
1035
1096
|
description: tool.description,
|
|
@@ -1037,6 +1098,7 @@ async function prepareTools({
|
|
|
1037
1098
|
cache_control: cacheControl,
|
|
1038
1099
|
...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {},
|
|
1039
1100
|
...deferLoading != null ? { defer_loading: deferLoading } : {},
|
|
1101
|
+
...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
|
|
1040
1102
|
...tool.inputExamples != null ? {
|
|
1041
1103
|
input_examples: tool.inputExamples.map(
|
|
1042
1104
|
(example) => example.input
|
|
@@ -1046,7 +1108,7 @@ async function prepareTools({
|
|
|
1046
1108
|
if (supportsStructuredOutput === true) {
|
|
1047
1109
|
betas.add("structured-outputs-2025-11-13");
|
|
1048
1110
|
}
|
|
1049
|
-
if (tool.inputExamples != null) {
|
|
1111
|
+
if (tool.inputExamples != null || allowedCallers != null) {
|
|
1050
1112
|
betas.add("advanced-tool-use-2025-11-20");
|
|
1051
1113
|
}
|
|
1052
1114
|
break;
|
|
@@ -1305,7 +1367,13 @@ var codeExecution_20250522OutputSchema = lazySchema6(
|
|
|
1305
1367
|
type: z7.literal("code_execution_result"),
|
|
1306
1368
|
stdout: z7.string(),
|
|
1307
1369
|
stderr: z7.string(),
|
|
1308
|
-
return_code: z7.number()
|
|
1370
|
+
return_code: z7.number(),
|
|
1371
|
+
content: z7.array(
|
|
1372
|
+
z7.object({
|
|
1373
|
+
type: z7.literal("code_execution_output"),
|
|
1374
|
+
file_id: z7.string()
|
|
1375
|
+
})
|
|
1376
|
+
).optional().default([])
|
|
1309
1377
|
})
|
|
1310
1378
|
)
|
|
1311
1379
|
);
|
|
@@ -1335,6 +1403,18 @@ import { z as z8 } from "zod/v4";
|
|
|
1335
1403
|
var codeExecution_20250825OutputSchema = lazySchema7(
|
|
1336
1404
|
() => zodSchema7(
|
|
1337
1405
|
z8.discriminatedUnion("type", [
|
|
1406
|
+
z8.object({
|
|
1407
|
+
type: z8.literal("code_execution_result"),
|
|
1408
|
+
stdout: z8.string(),
|
|
1409
|
+
stderr: z8.string(),
|
|
1410
|
+
return_code: z8.number(),
|
|
1411
|
+
content: z8.array(
|
|
1412
|
+
z8.object({
|
|
1413
|
+
type: z8.literal("code_execution_output"),
|
|
1414
|
+
file_id: z8.string()
|
|
1415
|
+
})
|
|
1416
|
+
).optional().default([])
|
|
1417
|
+
}),
|
|
1338
1418
|
z8.object({
|
|
1339
1419
|
type: z8.literal("bash_code_execution_result"),
|
|
1340
1420
|
content: z8.array(
|
|
@@ -1381,6 +1461,11 @@ var codeExecution_20250825OutputSchema = lazySchema7(
|
|
|
1381
1461
|
var codeExecution_20250825InputSchema = lazySchema7(
|
|
1382
1462
|
() => zodSchema7(
|
|
1383
1463
|
z8.discriminatedUnion("type", [
|
|
1464
|
+
// Programmatic tool calling format (mapped from { code } by AI SDK)
|
|
1465
|
+
z8.object({
|
|
1466
|
+
type: z8.literal("programmatic-tool-call"),
|
|
1467
|
+
code: z8.string()
|
|
1468
|
+
}),
|
|
1384
1469
|
z8.object({
|
|
1385
1470
|
type: z8.literal("bash_code_execution"),
|
|
1386
1471
|
command: z8.string()
|
|
@@ -1411,7 +1496,11 @@ var codeExecution_20250825InputSchema = lazySchema7(
|
|
|
1411
1496
|
var factory5 = createProviderToolFactoryWithOutputSchema4({
|
|
1412
1497
|
id: "anthropic.code_execution_20250825",
|
|
1413
1498
|
inputSchema: codeExecution_20250825InputSchema,
|
|
1414
|
-
outputSchema: codeExecution_20250825OutputSchema
|
|
1499
|
+
outputSchema: codeExecution_20250825OutputSchema,
|
|
1500
|
+
// Programmatic tool calling: tool results may be deferred to a later turn
|
|
1501
|
+
// when code execution triggers a client-executed tool that needs to be
|
|
1502
|
+
// resolved before the code execution result can be returned.
|
|
1503
|
+
supportsDeferredResults: true
|
|
1415
1504
|
});
|
|
1416
1505
|
var codeExecution_20250825 = (args = {}) => {
|
|
1417
1506
|
return factory5(args);
|
|
@@ -1488,7 +1577,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1488
1577
|
cacheControlValidator,
|
|
1489
1578
|
toolNameMapping
|
|
1490
1579
|
}) {
|
|
1491
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1580
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1492
1581
|
const betas = /* @__PURE__ */ new Set();
|
|
1493
1582
|
const blocks = groupIntoBlocks(prompt);
|
|
1494
1583
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -1858,6 +1947,19 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1858
1947
|
input: part.input,
|
|
1859
1948
|
cache_control: cacheControl
|
|
1860
1949
|
});
|
|
1950
|
+
} else if (
|
|
1951
|
+
// code execution 20250825 programmatic tool calling:
|
|
1952
|
+
// Strip the fake 'programmatic-tool-call' type before sending to Anthropic
|
|
1953
|
+
providerToolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && part.input.type === "programmatic-tool-call"
|
|
1954
|
+
) {
|
|
1955
|
+
const { type: _, ...inputWithoutType } = part.input;
|
|
1956
|
+
anthropicContent.push({
|
|
1957
|
+
type: "server_tool_use",
|
|
1958
|
+
id: part.toolCallId,
|
|
1959
|
+
name: "code_execution",
|
|
1960
|
+
input: inputWithoutType,
|
|
1961
|
+
cache_control: cacheControl
|
|
1962
|
+
});
|
|
1861
1963
|
} else {
|
|
1862
1964
|
if (providerToolName === "code_execution" || // code execution 20250522
|
|
1863
1965
|
providerToolName === "web_fetch" || providerToolName === "web_search") {
|
|
@@ -1885,11 +1987,17 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1885
1987
|
}
|
|
1886
1988
|
break;
|
|
1887
1989
|
}
|
|
1990
|
+
const callerOptions = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
|
|
1991
|
+
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? callerOptions.caller.type === "code_execution_20250825" && callerOptions.caller.toolId ? {
|
|
1992
|
+
type: "code_execution_20250825",
|
|
1993
|
+
tool_id: callerOptions.caller.toolId
|
|
1994
|
+
} : callerOptions.caller.type === "direct" ? { type: "direct" } : void 0 : void 0;
|
|
1888
1995
|
anthropicContent.push({
|
|
1889
1996
|
type: "tool_use",
|
|
1890
1997
|
id: part.toolCallId,
|
|
1891
1998
|
name: part.toolName,
|
|
1892
1999
|
input: part.input,
|
|
2000
|
+
...caller && { caller },
|
|
1893
2001
|
cache_control: cacheControl
|
|
1894
2002
|
});
|
|
1895
2003
|
break;
|
|
@@ -1916,6 +2024,39 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1916
2024
|
});
|
|
1917
2025
|
} else if (providerToolName === "code_execution") {
|
|
1918
2026
|
const output = part.output;
|
|
2027
|
+
if (output.type === "error-text" || output.type === "error-json") {
|
|
2028
|
+
let errorInfo = {};
|
|
2029
|
+
try {
|
|
2030
|
+
if (typeof output.value === "string") {
|
|
2031
|
+
errorInfo = JSON.parse(output.value);
|
|
2032
|
+
} else if (typeof output.value === "object" && output.value !== null) {
|
|
2033
|
+
errorInfo = output.value;
|
|
2034
|
+
}
|
|
2035
|
+
} catch (e) {
|
|
2036
|
+
}
|
|
2037
|
+
if (errorInfo.type === "code_execution_tool_result_error") {
|
|
2038
|
+
anthropicContent.push({
|
|
2039
|
+
type: "code_execution_tool_result",
|
|
2040
|
+
tool_use_id: part.toolCallId,
|
|
2041
|
+
content: {
|
|
2042
|
+
type: "code_execution_tool_result_error",
|
|
2043
|
+
error_code: (_l = errorInfo.errorCode) != null ? _l : "unknown"
|
|
2044
|
+
},
|
|
2045
|
+
cache_control: cacheControl
|
|
2046
|
+
});
|
|
2047
|
+
} else {
|
|
2048
|
+
anthropicContent.push({
|
|
2049
|
+
type: "bash_code_execution_tool_result",
|
|
2050
|
+
tool_use_id: part.toolCallId,
|
|
2051
|
+
cache_control: cacheControl,
|
|
2052
|
+
content: {
|
|
2053
|
+
type: "bash_code_execution_tool_result_error",
|
|
2054
|
+
error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
break;
|
|
2059
|
+
}
|
|
1919
2060
|
if (output.type !== "json") {
|
|
1920
2061
|
warnings.push({
|
|
1921
2062
|
type: "other",
|
|
@@ -1942,7 +2083,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1942
2083
|
type: codeExecutionOutput.type,
|
|
1943
2084
|
stdout: codeExecutionOutput.stdout,
|
|
1944
2085
|
stderr: codeExecutionOutput.stderr,
|
|
1945
|
-
return_code: codeExecutionOutput.return_code
|
|
2086
|
+
return_code: codeExecutionOutput.return_code,
|
|
2087
|
+
content: (_n = codeExecutionOutput.content) != null ? _n : []
|
|
1946
2088
|
},
|
|
1947
2089
|
cache_control: cacheControl
|
|
1948
2090
|
});
|
|
@@ -1951,19 +2093,34 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1951
2093
|
value: output.value,
|
|
1952
2094
|
schema: codeExecution_20250825OutputSchema
|
|
1953
2095
|
});
|
|
1954
|
-
|
|
1955
|
-
|
|
2096
|
+
if (codeExecutionOutput.type === "code_execution_result") {
|
|
2097
|
+
anthropicContent.push({
|
|
2098
|
+
type: "code_execution_tool_result",
|
|
2099
|
+
tool_use_id: part.toolCallId,
|
|
2100
|
+
content: {
|
|
2101
|
+
type: codeExecutionOutput.type,
|
|
2102
|
+
stdout: codeExecutionOutput.stdout,
|
|
2103
|
+
stderr: codeExecutionOutput.stderr,
|
|
2104
|
+
return_code: codeExecutionOutput.return_code,
|
|
2105
|
+
content: (_o = codeExecutionOutput.content) != null ? _o : []
|
|
2106
|
+
},
|
|
2107
|
+
cache_control: cacheControl
|
|
2108
|
+
});
|
|
2109
|
+
} else if (codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error") {
|
|
2110
|
+
anthropicContent.push({
|
|
1956
2111
|
type: "bash_code_execution_tool_result",
|
|
1957
2112
|
tool_use_id: part.toolCallId,
|
|
1958
2113
|
cache_control: cacheControl,
|
|
1959
2114
|
content: codeExecutionOutput
|
|
1960
|
-
}
|
|
2115
|
+
});
|
|
2116
|
+
} else {
|
|
2117
|
+
anthropicContent.push({
|
|
1961
2118
|
type: "text_editor_code_execution_tool_result",
|
|
1962
2119
|
tool_use_id: part.toolCallId,
|
|
1963
2120
|
cache_control: cacheControl,
|
|
1964
2121
|
content: codeExecutionOutput
|
|
1965
|
-
}
|
|
1966
|
-
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
1967
2124
|
}
|
|
1968
2125
|
break;
|
|
1969
2126
|
}
|
|
@@ -2215,7 +2372,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2215
2372
|
providerOptions,
|
|
2216
2373
|
stream
|
|
2217
2374
|
}) {
|
|
2218
|
-
var _a, _b, _c, _d, _e, _f
|
|
2375
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2219
2376
|
const warnings = [];
|
|
2220
2377
|
if (frequencyPenalty != null) {
|
|
2221
2378
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -2337,16 +2494,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2337
2494
|
} : void 0
|
|
2338
2495
|
}))
|
|
2339
2496
|
},
|
|
2340
|
-
// container
|
|
2497
|
+
// container: For programmatic tool calling (just an ID string) or agent skills (object with id and skills)
|
|
2341
2498
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2342
|
-
container:
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2499
|
+
container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? (
|
|
2500
|
+
// Object format when skills are provided (agent skills feature)
|
|
2501
|
+
{
|
|
2502
|
+
id: anthropicOptions.container.id,
|
|
2503
|
+
skills: anthropicOptions.container.skills.map((skill) => ({
|
|
2504
|
+
type: skill.type,
|
|
2505
|
+
skill_id: skill.skillId,
|
|
2506
|
+
version: skill.version
|
|
2507
|
+
}))
|
|
2508
|
+
}
|
|
2509
|
+
) : (
|
|
2510
|
+
// String format for container ID only (programmatic tool calling)
|
|
2511
|
+
anthropicOptions.container.id
|
|
2512
|
+
)
|
|
2350
2513
|
},
|
|
2351
2514
|
// prompt:
|
|
2352
2515
|
system: messagesPrompt.system,
|
|
@@ -2460,7 +2623,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2460
2623
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
2461
2624
|
betas.add("effort-2025-11-24");
|
|
2462
2625
|
}
|
|
2463
|
-
if (stream && ((
|
|
2626
|
+
if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
|
|
2464
2627
|
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
2465
2628
|
}
|
|
2466
2629
|
const usingNativeOutputFormat = useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
@@ -2556,7 +2719,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2556
2719
|
});
|
|
2557
2720
|
}
|
|
2558
2721
|
async doGenerate(options) {
|
|
2559
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2722
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2560
2723
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2561
2724
|
...options,
|
|
2562
2725
|
stream: false,
|
|
@@ -2634,11 +2797,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2634
2797
|
text: JSON.stringify(part.input)
|
|
2635
2798
|
});
|
|
2636
2799
|
} else {
|
|
2800
|
+
const caller = part.caller;
|
|
2801
|
+
const callerInfo = caller ? {
|
|
2802
|
+
type: caller.type,
|
|
2803
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
2804
|
+
} : void 0;
|
|
2637
2805
|
content.push({
|
|
2638
2806
|
type: "tool-call",
|
|
2639
2807
|
toolCallId: part.id,
|
|
2640
2808
|
toolName: part.name,
|
|
2641
|
-
input: JSON.stringify(part.input)
|
|
2809
|
+
input: JSON.stringify(part.input),
|
|
2810
|
+
...callerInfo && {
|
|
2811
|
+
providerMetadata: {
|
|
2812
|
+
anthropic: {
|
|
2813
|
+
caller: callerInfo
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2642
2817
|
});
|
|
2643
2818
|
}
|
|
2644
2819
|
break;
|
|
@@ -2653,11 +2828,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2653
2828
|
providerExecuted: true
|
|
2654
2829
|
});
|
|
2655
2830
|
} else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
|
|
2831
|
+
const inputToSerialize = part.name === "code_execution" && part.input != null && typeof part.input === "object" && "code" in part.input && !("type" in part.input) ? { type: "programmatic-tool-call", ...part.input } : part.input;
|
|
2656
2832
|
content.push({
|
|
2657
2833
|
type: "tool-call",
|
|
2658
2834
|
toolCallId: part.id,
|
|
2659
2835
|
toolName: toolNameMapping.toCustomToolName(part.name),
|
|
2660
|
-
input: JSON.stringify(
|
|
2836
|
+
input: JSON.stringify(inputToSerialize),
|
|
2661
2837
|
providerExecuted: true
|
|
2662
2838
|
});
|
|
2663
2839
|
} else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
|
|
@@ -2793,7 +2969,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2793
2969
|
type: part.content.type,
|
|
2794
2970
|
stdout: part.content.stdout,
|
|
2795
2971
|
stderr: part.content.stderr,
|
|
2796
|
-
return_code: part.content.return_code
|
|
2972
|
+
return_code: part.content.return_code,
|
|
2973
|
+
content: (_b = part.content.content) != null ? _b : []
|
|
2797
2974
|
}
|
|
2798
2975
|
});
|
|
2799
2976
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -2858,8 +3035,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2858
3035
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
2859
3036
|
request: { body: args },
|
|
2860
3037
|
response: {
|
|
2861
|
-
id: (
|
|
2862
|
-
modelId: (
|
|
3038
|
+
id: (_c = response.id) != null ? _c : void 0,
|
|
3039
|
+
modelId: (_d = response.model) != null ? _d : void 0,
|
|
2863
3040
|
headers: responseHeaders,
|
|
2864
3041
|
body: rawResponse
|
|
2865
3042
|
},
|
|
@@ -2867,20 +3044,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2867
3044
|
providerMetadata: {
|
|
2868
3045
|
anthropic: {
|
|
2869
3046
|
usage: response.usage,
|
|
2870
|
-
cacheCreationInputTokens: (
|
|
2871
|
-
stopSequence: (
|
|
3047
|
+
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
|
|
3048
|
+
stopSequence: (_f = response.stop_sequence) != null ? _f : null,
|
|
2872
3049
|
container: response.container ? {
|
|
2873
3050
|
expiresAt: response.container.expires_at,
|
|
2874
3051
|
id: response.container.id,
|
|
2875
|
-
skills: (
|
|
3052
|
+
skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
|
|
2876
3053
|
type: skill.type,
|
|
2877
3054
|
skillId: skill.skill_id,
|
|
2878
3055
|
version: skill.version
|
|
2879
|
-
}))) != null ?
|
|
3056
|
+
}))) != null ? _h : null
|
|
2880
3057
|
} : null,
|
|
2881
|
-
contextManagement: (
|
|
3058
|
+
contextManagement: (_i = mapAnthropicResponseContextManagement(
|
|
2882
3059
|
response.context_management
|
|
2883
|
-
)) != null ?
|
|
3060
|
+
)) != null ? _i : null
|
|
2884
3061
|
}
|
|
2885
3062
|
}
|
|
2886
3063
|
};
|
|
@@ -2934,7 +3111,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2934
3111
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2935
3112
|
},
|
|
2936
3113
|
transform(chunk, controller) {
|
|
2937
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
3114
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2938
3115
|
if (options.includeRawChunks) {
|
|
2939
3116
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2940
3117
|
}
|
|
@@ -2994,12 +3171,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2994
3171
|
id: String(value.index)
|
|
2995
3172
|
});
|
|
2996
3173
|
} else {
|
|
3174
|
+
const caller = part.caller;
|
|
3175
|
+
const callerInfo = caller ? {
|
|
3176
|
+
type: caller.type,
|
|
3177
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
3178
|
+
} : void 0;
|
|
3179
|
+
const hasNonEmptyInput = part.input && Object.keys(part.input).length > 0;
|
|
3180
|
+
const initialInput = hasNonEmptyInput ? JSON.stringify(part.input) : "";
|
|
2997
3181
|
contentBlocks[value.index] = {
|
|
2998
3182
|
type: "tool-call",
|
|
2999
3183
|
toolCallId: part.id,
|
|
3000
3184
|
toolName: part.name,
|
|
3001
|
-
input:
|
|
3002
|
-
firstDelta:
|
|
3185
|
+
input: initialInput,
|
|
3186
|
+
firstDelta: initialInput.length === 0,
|
|
3187
|
+
...callerInfo && { caller: callerInfo }
|
|
3003
3188
|
};
|
|
3004
3189
|
controller.enqueue({
|
|
3005
3190
|
type: "tool-input-start",
|
|
@@ -3151,7 +3336,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3151
3336
|
type: part.content.type,
|
|
3152
3337
|
stdout: part.content.stdout,
|
|
3153
3338
|
stderr: part.content.stderr,
|
|
3154
|
-
return_code: part.content.return_code
|
|
3339
|
+
return_code: part.content.return_code,
|
|
3340
|
+
content: (_b2 = part.content.content) != null ? _b2 : []
|
|
3155
3341
|
}
|
|
3156
3342
|
});
|
|
3157
3343
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -3268,12 +3454,32 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3268
3454
|
type: "tool-input-end",
|
|
3269
3455
|
id: contentBlock.toolCallId
|
|
3270
3456
|
});
|
|
3457
|
+
let finalInput = contentBlock.input === "" ? "{}" : contentBlock.input;
|
|
3458
|
+
if (contentBlock.providerToolName === "code_execution") {
|
|
3459
|
+
try {
|
|
3460
|
+
const parsed = JSON.parse(finalInput);
|
|
3461
|
+
if (parsed != null && typeof parsed === "object" && "code" in parsed && !("type" in parsed)) {
|
|
3462
|
+
finalInput = JSON.stringify({
|
|
3463
|
+
type: "programmatic-tool-call",
|
|
3464
|
+
...parsed
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
} catch (e) {
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3271
3470
|
controller.enqueue({
|
|
3272
3471
|
type: "tool-call",
|
|
3273
3472
|
toolCallId: contentBlock.toolCallId,
|
|
3274
3473
|
toolName: contentBlock.toolName,
|
|
3275
|
-
input:
|
|
3276
|
-
providerExecuted: contentBlock.providerExecuted
|
|
3474
|
+
input: finalInput,
|
|
3475
|
+
providerExecuted: contentBlock.providerExecuted,
|
|
3476
|
+
...contentBlock.caller && {
|
|
3477
|
+
providerMetadata: {
|
|
3478
|
+
anthropic: {
|
|
3479
|
+
caller: contentBlock.caller
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3277
3483
|
});
|
|
3278
3484
|
}
|
|
3279
3485
|
break;
|
|
@@ -3374,17 +3580,70 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3374
3580
|
}
|
|
3375
3581
|
case "message_start": {
|
|
3376
3582
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3377
|
-
usage.cache_read_input_tokens = (
|
|
3378
|
-
usage.cache_creation_input_tokens = (
|
|
3583
|
+
usage.cache_read_input_tokens = (_c = value.message.usage.cache_read_input_tokens) != null ? _c : 0;
|
|
3584
|
+
usage.cache_creation_input_tokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : 0;
|
|
3379
3585
|
rawUsage = {
|
|
3380
3586
|
...value.message.usage
|
|
3381
3587
|
};
|
|
3382
|
-
cacheCreationInputTokens = (
|
|
3588
|
+
cacheCreationInputTokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : null;
|
|
3589
|
+
if (value.message.container != null) {
|
|
3590
|
+
container = {
|
|
3591
|
+
expiresAt: value.message.container.expires_at,
|
|
3592
|
+
id: value.message.container.id,
|
|
3593
|
+
skills: null
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
if (value.message.stop_reason != null) {
|
|
3597
|
+
finishReason = mapAnthropicStopReason({
|
|
3598
|
+
finishReason: value.message.stop_reason,
|
|
3599
|
+
isJsonResponseFromTool
|
|
3600
|
+
});
|
|
3601
|
+
}
|
|
3383
3602
|
controller.enqueue({
|
|
3384
3603
|
type: "response-metadata",
|
|
3385
|
-
id: (
|
|
3386
|
-
modelId: (
|
|
3604
|
+
id: (_f = value.message.id) != null ? _f : void 0,
|
|
3605
|
+
modelId: (_g = value.message.model) != null ? _g : void 0
|
|
3387
3606
|
});
|
|
3607
|
+
if (value.message.content != null) {
|
|
3608
|
+
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
3609
|
+
const part = value.message.content[contentIndex];
|
|
3610
|
+
if (part.type === "tool_use") {
|
|
3611
|
+
const caller = part.caller;
|
|
3612
|
+
const callerInfo = caller ? {
|
|
3613
|
+
type: caller.type,
|
|
3614
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
3615
|
+
} : void 0;
|
|
3616
|
+
controller.enqueue({
|
|
3617
|
+
type: "tool-input-start",
|
|
3618
|
+
id: part.id,
|
|
3619
|
+
toolName: part.name
|
|
3620
|
+
});
|
|
3621
|
+
const inputStr = JSON.stringify((_h = part.input) != null ? _h : {});
|
|
3622
|
+
controller.enqueue({
|
|
3623
|
+
type: "tool-input-delta",
|
|
3624
|
+
id: part.id,
|
|
3625
|
+
delta: inputStr
|
|
3626
|
+
});
|
|
3627
|
+
controller.enqueue({
|
|
3628
|
+
type: "tool-input-end",
|
|
3629
|
+
id: part.id
|
|
3630
|
+
});
|
|
3631
|
+
controller.enqueue({
|
|
3632
|
+
type: "tool-call",
|
|
3633
|
+
toolCallId: part.id,
|
|
3634
|
+
toolName: part.name,
|
|
3635
|
+
input: inputStr,
|
|
3636
|
+
...callerInfo && {
|
|
3637
|
+
providerMetadata: {
|
|
3638
|
+
anthropic: {
|
|
3639
|
+
caller: callerInfo
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
});
|
|
3644
|
+
}
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3388
3647
|
return;
|
|
3389
3648
|
}
|
|
3390
3649
|
case "message_delta": {
|
|
@@ -3393,15 +3652,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3393
3652
|
finishReason: value.delta.stop_reason,
|
|
3394
3653
|
isJsonResponseFromTool
|
|
3395
3654
|
});
|
|
3396
|
-
stopSequence = (
|
|
3655
|
+
stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
|
|
3397
3656
|
container = value.delta.container != null ? {
|
|
3398
3657
|
expiresAt: value.delta.container.expires_at,
|
|
3399
3658
|
id: value.delta.container.id,
|
|
3400
|
-
skills: (
|
|
3659
|
+
skills: (_k = (_j = value.delta.container.skills) == null ? void 0 : _j.map((skill) => ({
|
|
3401
3660
|
type: skill.type,
|
|
3402
3661
|
skillId: skill.skill_id,
|
|
3403
3662
|
version: skill.version
|
|
3404
|
-
}))) != null ?
|
|
3663
|
+
}))) != null ? _k : null
|
|
3405
3664
|
} : null;
|
|
3406
3665
|
if (value.delta.context_management) {
|
|
3407
3666
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -4033,9 +4292,30 @@ function createAnthropic(options = {}) {
|
|
|
4033
4292
|
return provider;
|
|
4034
4293
|
}
|
|
4035
4294
|
var anthropic = createAnthropic();
|
|
4295
|
+
|
|
4296
|
+
// src/forward-anthropic-container-id-from-last-step.ts
|
|
4297
|
+
function forwardAnthropicContainerIdFromLastStep({
|
|
4298
|
+
steps
|
|
4299
|
+
}) {
|
|
4300
|
+
var _a, _b, _c;
|
|
4301
|
+
for (let i = steps.length - 1; i >= 0; i--) {
|
|
4302
|
+
const containerId = (_c = (_b = (_a = steps[i].providerMetadata) == null ? void 0 : _a.anthropic) == null ? void 0 : _b.container) == null ? void 0 : _c.id;
|
|
4303
|
+
if (containerId) {
|
|
4304
|
+
return {
|
|
4305
|
+
providerOptions: {
|
|
4306
|
+
anthropic: {
|
|
4307
|
+
container: { id: containerId }
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
};
|
|
4311
|
+
}
|
|
4312
|
+
}
|
|
4313
|
+
return void 0;
|
|
4314
|
+
}
|
|
4036
4315
|
export {
|
|
4037
4316
|
VERSION,
|
|
4038
4317
|
anthropic,
|
|
4039
|
-
createAnthropic
|
|
4318
|
+
createAnthropic,
|
|
4319
|
+
forwardAnthropicContainerIdFromLastStep
|
|
4040
4320
|
};
|
|
4041
4321
|
//# sourceMappingURL=index.mjs.map
|