@ai-sdk/anthropic 3.0.0-beta.92 → 3.0.0-beta.94

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/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.92" : "0.0.0-test";
14
+ var VERSION = true ? "3.0.0-beta.94" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
@@ -51,29 +51,6 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
51
51
  errorToMessage: (data) => data.error.message
52
52
  });
53
53
 
54
- // src/convert-anthropic-messages-usage.ts
55
- function convertAnthropicMessagesUsage(usage) {
56
- var _a, _b;
57
- const inputTokens = usage.input_tokens;
58
- const outputTokens = usage.output_tokens;
59
- const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
60
- const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
61
- return {
62
- inputTokens: {
63
- total: inputTokens + cacheCreationTokens + cacheReadTokens,
64
- noCache: inputTokens,
65
- cacheRead: cacheReadTokens,
66
- cacheWrite: cacheCreationTokens
67
- },
68
- outputTokens: {
69
- total: outputTokens,
70
- text: void 0,
71
- reasoning: void 0
72
- },
73
- raw: usage
74
- };
75
- }
76
-
77
54
  // src/anthropic-messages-api.ts
78
55
  import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
79
56
  import { z as z2 } from "zod/v4";
@@ -129,7 +106,17 @@ var anthropicMessagesResponseSchema = lazySchema2(
129
106
  type: z2.literal("tool_use"),
130
107
  id: z2.string(),
131
108
  name: z2.string(),
132
- input: z2.unknown()
109
+ input: z2.unknown(),
110
+ // Programmatic tool calling: caller info when triggered from code execution
111
+ caller: z2.union([
112
+ z2.object({
113
+ type: z2.literal("code_execution_20250825"),
114
+ tool_id: z2.string()
115
+ }),
116
+ z2.object({
117
+ type: z2.literal("direct")
118
+ })
119
+ ]).optional()
133
120
  }),
134
121
  z2.object({
135
122
  type: z2.literal("server_tool_use"),
@@ -215,7 +202,13 @@ var anthropicMessagesResponseSchema = lazySchema2(
215
202
  type: z2.literal("code_execution_result"),
216
203
  stdout: z2.string(),
217
204
  stderr: z2.string(),
218
- return_code: z2.number()
205
+ return_code: z2.number(),
206
+ content: z2.array(
207
+ z2.object({
208
+ type: z2.literal("code_execution_output"),
209
+ file_id: z2.string()
210
+ })
211
+ ).optional().default([])
219
212
  }),
220
213
  z2.object({
221
214
  type: z2.literal("code_execution_tool_result_error"),
@@ -347,11 +340,37 @@ var anthropicMessagesChunkSchema = lazySchema2(
347
340
  message: z2.object({
348
341
  id: z2.string().nullish(),
349
342
  model: z2.string().nullish(),
343
+ role: z2.string().nullish(),
350
344
  usage: z2.looseObject({
351
345
  input_tokens: z2.number(),
352
346
  cache_creation_input_tokens: z2.number().nullish(),
353
347
  cache_read_input_tokens: z2.number().nullish()
354
- })
348
+ }),
349
+ // Programmatic tool calling: content may be pre-populated for deferred tool calls
350
+ content: z2.array(
351
+ z2.discriminatedUnion("type", [
352
+ z2.object({
353
+ type: z2.literal("tool_use"),
354
+ id: z2.string(),
355
+ name: z2.string(),
356
+ input: z2.unknown(),
357
+ caller: z2.union([
358
+ z2.object({
359
+ type: z2.literal("code_execution_20250825"),
360
+ tool_id: z2.string()
361
+ }),
362
+ z2.object({
363
+ type: z2.literal("direct")
364
+ })
365
+ ]).optional()
366
+ })
367
+ ])
368
+ ).nullish(),
369
+ stop_reason: z2.string().nullish(),
370
+ container: z2.object({
371
+ expires_at: z2.string(),
372
+ id: z2.string()
373
+ }).nullish()
355
374
  })
356
375
  }),
357
376
  z2.object({
@@ -369,7 +388,19 @@ var anthropicMessagesChunkSchema = lazySchema2(
369
388
  z2.object({
370
389
  type: z2.literal("tool_use"),
371
390
  id: z2.string(),
372
- name: z2.string()
391
+ name: z2.string(),
392
+ // Programmatic tool calling: input may be present directly for deferred tool calls
393
+ input: z2.record(z2.string(), z2.unknown()).optional(),
394
+ // Programmatic tool calling: caller info when triggered from code execution
395
+ caller: z2.union([
396
+ z2.object({
397
+ type: z2.literal("code_execution_20250825"),
398
+ tool_id: z2.string()
399
+ }),
400
+ z2.object({
401
+ type: z2.literal("direct")
402
+ })
403
+ ]).optional()
373
404
  }),
374
405
  z2.object({
375
406
  type: z2.literal("redacted_thinking"),
@@ -459,7 +490,13 @@ var anthropicMessagesChunkSchema = lazySchema2(
459
490
  type: z2.literal("code_execution_result"),
460
491
  stdout: z2.string(),
461
492
  stderr: z2.string(),
462
- return_code: z2.number()
493
+ return_code: z2.number(),
494
+ content: z2.array(
495
+ z2.object({
496
+ type: z2.literal("code_execution_output"),
497
+ file_id: z2.string()
498
+ })
499
+ ).optional().default([])
463
500
  }),
464
501
  z2.object({
465
502
  type: z2.literal("code_execution_tool_result_error"),
@@ -1030,6 +1067,7 @@ async function prepareTools({
1030
1067
  });
1031
1068
  const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
1032
1069
  const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1070
+ const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1033
1071
  anthropicTools2.push({
1034
1072
  name: tool.name,
1035
1073
  description: tool.description,
@@ -1037,6 +1075,7 @@ async function prepareTools({
1037
1075
  cache_control: cacheControl,
1038
1076
  ...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {},
1039
1077
  ...deferLoading != null ? { defer_loading: deferLoading } : {},
1078
+ ...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
1040
1079
  ...tool.inputExamples != null ? {
1041
1080
  input_examples: tool.inputExamples.map(
1042
1081
  (example) => example.input
@@ -1046,7 +1085,7 @@ async function prepareTools({
1046
1085
  if (supportsStructuredOutput === true) {
1047
1086
  betas.add("structured-outputs-2025-11-13");
1048
1087
  }
1049
- if (tool.inputExamples != null) {
1088
+ if (tool.inputExamples != null || allowedCallers != null) {
1050
1089
  betas.add("advanced-tool-use-2025-11-20");
1051
1090
  }
1052
1091
  break;
@@ -1281,6 +1320,29 @@ async function prepareTools({
1281
1320
  }
1282
1321
  }
1283
1322
 
1323
+ // src/convert-anthropic-messages-usage.ts
1324
+ function convertAnthropicMessagesUsage(usage) {
1325
+ var _a, _b;
1326
+ const inputTokens = usage.input_tokens;
1327
+ const outputTokens = usage.output_tokens;
1328
+ const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
1329
+ const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
1330
+ return {
1331
+ inputTokens: {
1332
+ total: inputTokens + cacheCreationTokens + cacheReadTokens,
1333
+ noCache: inputTokens,
1334
+ cacheRead: cacheReadTokens,
1335
+ cacheWrite: cacheCreationTokens
1336
+ },
1337
+ outputTokens: {
1338
+ total: outputTokens,
1339
+ text: void 0,
1340
+ reasoning: void 0
1341
+ },
1342
+ raw: usage
1343
+ };
1344
+ }
1345
+
1284
1346
  // src/convert-to-anthropic-messages-prompt.ts
1285
1347
  import {
1286
1348
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
@@ -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
- anthropicContent.push(
1955
- codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error" ? {
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, _g;
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 with agent skills:
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
- id: anthropicOptions.container.id,
2344
- skills: (_f = anthropicOptions.container.skills) == null ? void 0 : _f.map((skill) => ({
2345
- type: skill.type,
2346
- skill_id: skill.skillId,
2347
- version: skill.version
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 && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true)) {
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(part.input),
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: (_b = response.id) != null ? _b : void 0,
2862
- modelId: (_c = response.model) != null ? _c : void 0,
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: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null,
2871
- stopSequence: (_e = response.stop_sequence) != null ? _e : null,
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: (_g = (_f = response.container.skills) == null ? void 0 : _f.map((skill) => ({
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 ? _g : null
3056
+ }))) != null ? _h : null
2880
3057
  } : null,
2881
- contextManagement: (_h = mapAnthropicResponseContextManagement(
3058
+ contextManagement: (_i = mapAnthropicResponseContextManagement(
2882
3059
  response.context_management
2883
- )) != null ? _h : 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: true
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: contentBlock.input === "" ? "{}" : contentBlock.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 = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : 0;
3378
- usage.cache_creation_input_tokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : 0;
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 = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : null;
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: (_e = value.message.id) != null ? _e : void 0,
3386
- modelId: (_f = value.message.model) != null ? _f : void 0
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 = (_g = value.delta.stop_sequence) != null ? _g : null;
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: (_i = (_h = value.delta.container.skills) == null ? void 0 : _h.map((skill) => ({
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 ? _i : 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