@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.
@@ -114,7 +114,17 @@ var anthropicMessagesResponseSchema = lazySchema2(
114
114
  type: z2.literal("tool_use"),
115
115
  id: z2.string(),
116
116
  name: z2.string(),
117
- input: z2.unknown()
117
+ input: z2.unknown(),
118
+ // Programmatic tool calling: caller info when triggered from code execution
119
+ caller: z2.union([
120
+ z2.object({
121
+ type: z2.literal("code_execution_20250825"),
122
+ tool_id: z2.string()
123
+ }),
124
+ z2.object({
125
+ type: z2.literal("direct")
126
+ })
127
+ ]).optional()
118
128
  }),
119
129
  z2.object({
120
130
  type: z2.literal("server_tool_use"),
@@ -200,7 +210,13 @@ var anthropicMessagesResponseSchema = lazySchema2(
200
210
  type: z2.literal("code_execution_result"),
201
211
  stdout: z2.string(),
202
212
  stderr: z2.string(),
203
- return_code: z2.number()
213
+ return_code: z2.number(),
214
+ content: z2.array(
215
+ z2.object({
216
+ type: z2.literal("code_execution_output"),
217
+ file_id: z2.string()
218
+ })
219
+ ).optional().default([])
204
220
  }),
205
221
  z2.object({
206
222
  type: z2.literal("code_execution_tool_result_error"),
@@ -332,11 +348,37 @@ var anthropicMessagesChunkSchema = lazySchema2(
332
348
  message: z2.object({
333
349
  id: z2.string().nullish(),
334
350
  model: z2.string().nullish(),
351
+ role: z2.string().nullish(),
335
352
  usage: z2.looseObject({
336
353
  input_tokens: z2.number(),
337
354
  cache_creation_input_tokens: z2.number().nullish(),
338
355
  cache_read_input_tokens: z2.number().nullish()
339
- })
356
+ }),
357
+ // Programmatic tool calling: content may be pre-populated for deferred tool calls
358
+ content: z2.array(
359
+ z2.discriminatedUnion("type", [
360
+ z2.object({
361
+ type: z2.literal("tool_use"),
362
+ id: z2.string(),
363
+ name: z2.string(),
364
+ input: z2.unknown(),
365
+ caller: z2.union([
366
+ z2.object({
367
+ type: z2.literal("code_execution_20250825"),
368
+ tool_id: z2.string()
369
+ }),
370
+ z2.object({
371
+ type: z2.literal("direct")
372
+ })
373
+ ]).optional()
374
+ })
375
+ ])
376
+ ).nullish(),
377
+ stop_reason: z2.string().nullish(),
378
+ container: z2.object({
379
+ expires_at: z2.string(),
380
+ id: z2.string()
381
+ }).nullish()
340
382
  })
341
383
  }),
342
384
  z2.object({
@@ -354,7 +396,19 @@ var anthropicMessagesChunkSchema = lazySchema2(
354
396
  z2.object({
355
397
  type: z2.literal("tool_use"),
356
398
  id: z2.string(),
357
- name: z2.string()
399
+ name: z2.string(),
400
+ // Programmatic tool calling: input may be present directly for deferred tool calls
401
+ input: z2.record(z2.string(), z2.unknown()).optional(),
402
+ // Programmatic tool calling: caller info when triggered from code execution
403
+ caller: z2.union([
404
+ z2.object({
405
+ type: z2.literal("code_execution_20250825"),
406
+ tool_id: z2.string()
407
+ }),
408
+ z2.object({
409
+ type: z2.literal("direct")
410
+ })
411
+ ]).optional()
358
412
  }),
359
413
  z2.object({
360
414
  type: z2.literal("redacted_thinking"),
@@ -444,7 +498,13 @@ var anthropicMessagesChunkSchema = lazySchema2(
444
498
  type: z2.literal("code_execution_result"),
445
499
  stdout: z2.string(),
446
500
  stderr: z2.string(),
447
- return_code: z2.number()
501
+ return_code: z2.number(),
502
+ content: z2.array(
503
+ z2.object({
504
+ type: z2.literal("code_execution_output"),
505
+ file_id: z2.string()
506
+ })
507
+ ).optional().default([])
448
508
  }),
449
509
  z2.object({
450
510
  type: z2.literal("code_execution_tool_result_error"),
@@ -1015,6 +1075,7 @@ async function prepareTools({
1015
1075
  });
1016
1076
  const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
1017
1077
  const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1078
+ const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1018
1079
  anthropicTools2.push({
1019
1080
  name: tool.name,
1020
1081
  description: tool.description,
@@ -1022,6 +1083,7 @@ async function prepareTools({
1022
1083
  cache_control: cacheControl,
1023
1084
  ...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {},
1024
1085
  ...deferLoading != null ? { defer_loading: deferLoading } : {},
1086
+ ...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
1025
1087
  ...tool.inputExamples != null ? {
1026
1088
  input_examples: tool.inputExamples.map(
1027
1089
  (example) => example.input
@@ -1031,7 +1093,7 @@ async function prepareTools({
1031
1093
  if (supportsStructuredOutput === true) {
1032
1094
  betas.add("structured-outputs-2025-11-13");
1033
1095
  }
1034
- if (tool.inputExamples != null) {
1096
+ if (tool.inputExamples != null || allowedCallers != null) {
1035
1097
  betas.add("advanced-tool-use-2025-11-20");
1036
1098
  }
1037
1099
  break;
@@ -1290,7 +1352,13 @@ var codeExecution_20250522OutputSchema = lazySchema6(
1290
1352
  type: z7.literal("code_execution_result"),
1291
1353
  stdout: z7.string(),
1292
1354
  stderr: z7.string(),
1293
- return_code: z7.number()
1355
+ return_code: z7.number(),
1356
+ content: z7.array(
1357
+ z7.object({
1358
+ type: z7.literal("code_execution_output"),
1359
+ file_id: z7.string()
1360
+ })
1361
+ ).optional().default([])
1294
1362
  })
1295
1363
  )
1296
1364
  );
@@ -1320,6 +1388,18 @@ import { z as z8 } from "zod/v4";
1320
1388
  var codeExecution_20250825OutputSchema = lazySchema7(
1321
1389
  () => zodSchema7(
1322
1390
  z8.discriminatedUnion("type", [
1391
+ z8.object({
1392
+ type: z8.literal("code_execution_result"),
1393
+ stdout: z8.string(),
1394
+ stderr: z8.string(),
1395
+ return_code: z8.number(),
1396
+ content: z8.array(
1397
+ z8.object({
1398
+ type: z8.literal("code_execution_output"),
1399
+ file_id: z8.string()
1400
+ })
1401
+ ).optional().default([])
1402
+ }),
1323
1403
  z8.object({
1324
1404
  type: z8.literal("bash_code_execution_result"),
1325
1405
  content: z8.array(
@@ -1366,6 +1446,11 @@ var codeExecution_20250825OutputSchema = lazySchema7(
1366
1446
  var codeExecution_20250825InputSchema = lazySchema7(
1367
1447
  () => zodSchema7(
1368
1448
  z8.discriminatedUnion("type", [
1449
+ // Programmatic tool calling format (mapped from { code } by AI SDK)
1450
+ z8.object({
1451
+ type: z8.literal("programmatic-tool-call"),
1452
+ code: z8.string()
1453
+ }),
1369
1454
  z8.object({
1370
1455
  type: z8.literal("bash_code_execution"),
1371
1456
  command: z8.string()
@@ -1396,7 +1481,11 @@ var codeExecution_20250825InputSchema = lazySchema7(
1396
1481
  var factory5 = createProviderToolFactoryWithOutputSchema4({
1397
1482
  id: "anthropic.code_execution_20250825",
1398
1483
  inputSchema: codeExecution_20250825InputSchema,
1399
- outputSchema: codeExecution_20250825OutputSchema
1484
+ outputSchema: codeExecution_20250825OutputSchema,
1485
+ // Programmatic tool calling: tool results may be deferred to a later turn
1486
+ // when code execution triggers a client-executed tool that needs to be
1487
+ // resolved before the code execution result can be returned.
1488
+ supportsDeferredResults: true
1400
1489
  });
1401
1490
  var codeExecution_20250825 = (args = {}) => {
1402
1491
  return factory5(args);
@@ -1473,7 +1562,7 @@ async function convertToAnthropicMessagesPrompt({
1473
1562
  cacheControlValidator,
1474
1563
  toolNameMapping
1475
1564
  }) {
1476
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1565
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1477
1566
  const betas = /* @__PURE__ */ new Set();
1478
1567
  const blocks = groupIntoBlocks(prompt);
1479
1568
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1843,6 +1932,19 @@ async function convertToAnthropicMessagesPrompt({
1843
1932
  input: part.input,
1844
1933
  cache_control: cacheControl
1845
1934
  });
1935
+ } else if (
1936
+ // code execution 20250825 programmatic tool calling:
1937
+ // Strip the fake 'programmatic-tool-call' type before sending to Anthropic
1938
+ providerToolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && part.input.type === "programmatic-tool-call"
1939
+ ) {
1940
+ const { type: _, ...inputWithoutType } = part.input;
1941
+ anthropicContent.push({
1942
+ type: "server_tool_use",
1943
+ id: part.toolCallId,
1944
+ name: "code_execution",
1945
+ input: inputWithoutType,
1946
+ cache_control: cacheControl
1947
+ });
1846
1948
  } else {
1847
1949
  if (providerToolName === "code_execution" || // code execution 20250522
1848
1950
  providerToolName === "web_fetch" || providerToolName === "web_search") {
@@ -1870,11 +1972,17 @@ async function convertToAnthropicMessagesPrompt({
1870
1972
  }
1871
1973
  break;
1872
1974
  }
1975
+ const callerOptions = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
1976
+ const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? callerOptions.caller.type === "code_execution_20250825" && callerOptions.caller.toolId ? {
1977
+ type: "code_execution_20250825",
1978
+ tool_id: callerOptions.caller.toolId
1979
+ } : callerOptions.caller.type === "direct" ? { type: "direct" } : void 0 : void 0;
1873
1980
  anthropicContent.push({
1874
1981
  type: "tool_use",
1875
1982
  id: part.toolCallId,
1876
1983
  name: part.toolName,
1877
1984
  input: part.input,
1985
+ ...caller && { caller },
1878
1986
  cache_control: cacheControl
1879
1987
  });
1880
1988
  break;
@@ -1901,6 +2009,39 @@ async function convertToAnthropicMessagesPrompt({
1901
2009
  });
1902
2010
  } else if (providerToolName === "code_execution") {
1903
2011
  const output = part.output;
2012
+ if (output.type === "error-text" || output.type === "error-json") {
2013
+ let errorInfo = {};
2014
+ try {
2015
+ if (typeof output.value === "string") {
2016
+ errorInfo = JSON.parse(output.value);
2017
+ } else if (typeof output.value === "object" && output.value !== null) {
2018
+ errorInfo = output.value;
2019
+ }
2020
+ } catch (e) {
2021
+ }
2022
+ if (errorInfo.type === "code_execution_tool_result_error") {
2023
+ anthropicContent.push({
2024
+ type: "code_execution_tool_result",
2025
+ tool_use_id: part.toolCallId,
2026
+ content: {
2027
+ type: "code_execution_tool_result_error",
2028
+ error_code: (_l = errorInfo.errorCode) != null ? _l : "unknown"
2029
+ },
2030
+ cache_control: cacheControl
2031
+ });
2032
+ } else {
2033
+ anthropicContent.push({
2034
+ type: "bash_code_execution_tool_result",
2035
+ tool_use_id: part.toolCallId,
2036
+ cache_control: cacheControl,
2037
+ content: {
2038
+ type: "bash_code_execution_tool_result_error",
2039
+ error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
2040
+ }
2041
+ });
2042
+ }
2043
+ break;
2044
+ }
1904
2045
  if (output.type !== "json") {
1905
2046
  warnings.push({
1906
2047
  type: "other",
@@ -1927,7 +2068,8 @@ async function convertToAnthropicMessagesPrompt({
1927
2068
  type: codeExecutionOutput.type,
1928
2069
  stdout: codeExecutionOutput.stdout,
1929
2070
  stderr: codeExecutionOutput.stderr,
1930
- return_code: codeExecutionOutput.return_code
2071
+ return_code: codeExecutionOutput.return_code,
2072
+ content: (_n = codeExecutionOutput.content) != null ? _n : []
1931
2073
  },
1932
2074
  cache_control: cacheControl
1933
2075
  });
@@ -1936,19 +2078,34 @@ async function convertToAnthropicMessagesPrompt({
1936
2078
  value: output.value,
1937
2079
  schema: codeExecution_20250825OutputSchema
1938
2080
  });
1939
- anthropicContent.push(
1940
- codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error" ? {
2081
+ if (codeExecutionOutput.type === "code_execution_result") {
2082
+ anthropicContent.push({
2083
+ type: "code_execution_tool_result",
2084
+ tool_use_id: part.toolCallId,
2085
+ content: {
2086
+ type: codeExecutionOutput.type,
2087
+ stdout: codeExecutionOutput.stdout,
2088
+ stderr: codeExecutionOutput.stderr,
2089
+ return_code: codeExecutionOutput.return_code,
2090
+ content: (_o = codeExecutionOutput.content) != null ? _o : []
2091
+ },
2092
+ cache_control: cacheControl
2093
+ });
2094
+ } else if (codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error") {
2095
+ anthropicContent.push({
1941
2096
  type: "bash_code_execution_tool_result",
1942
2097
  tool_use_id: part.toolCallId,
1943
2098
  cache_control: cacheControl,
1944
2099
  content: codeExecutionOutput
1945
- } : {
2100
+ });
2101
+ } else {
2102
+ anthropicContent.push({
1946
2103
  type: "text_editor_code_execution_tool_result",
1947
2104
  tool_use_id: part.toolCallId,
1948
2105
  cache_control: cacheControl,
1949
2106
  content: codeExecutionOutput
1950
- }
1951
- );
2107
+ });
2108
+ }
1952
2109
  }
1953
2110
  break;
1954
2111
  }
@@ -2200,7 +2357,7 @@ var AnthropicMessagesLanguageModel = class {
2200
2357
  providerOptions,
2201
2358
  stream
2202
2359
  }) {
2203
- var _a, _b, _c, _d, _e, _f, _g;
2360
+ var _a, _b, _c, _d, _e, _f;
2204
2361
  const warnings = [];
2205
2362
  if (frequencyPenalty != null) {
2206
2363
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2322,16 +2479,22 @@ var AnthropicMessagesLanguageModel = class {
2322
2479
  } : void 0
2323
2480
  }))
2324
2481
  },
2325
- // container with agent skills:
2482
+ // container: For programmatic tool calling (just an ID string) or agent skills (object with id and skills)
2326
2483
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2327
- container: {
2328
- id: anthropicOptions.container.id,
2329
- skills: (_f = anthropicOptions.container.skills) == null ? void 0 : _f.map((skill) => ({
2330
- type: skill.type,
2331
- skill_id: skill.skillId,
2332
- version: skill.version
2333
- }))
2334
- }
2484
+ container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? (
2485
+ // Object format when skills are provided (agent skills feature)
2486
+ {
2487
+ id: anthropicOptions.container.id,
2488
+ skills: anthropicOptions.container.skills.map((skill) => ({
2489
+ type: skill.type,
2490
+ skill_id: skill.skillId,
2491
+ version: skill.version
2492
+ }))
2493
+ }
2494
+ ) : (
2495
+ // String format for container ID only (programmatic tool calling)
2496
+ anthropicOptions.container.id
2497
+ )
2335
2498
  },
2336
2499
  // prompt:
2337
2500
  system: messagesPrompt.system,
@@ -2445,7 +2608,7 @@ var AnthropicMessagesLanguageModel = class {
2445
2608
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2446
2609
  betas.add("effort-2025-11-24");
2447
2610
  }
2448
- if (stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true)) {
2611
+ if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
2449
2612
  betas.add("fine-grained-tool-streaming-2025-05-14");
2450
2613
  }
2451
2614
  const usingNativeOutputFormat = useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
@@ -2541,7 +2704,7 @@ var AnthropicMessagesLanguageModel = class {
2541
2704
  });
2542
2705
  }
2543
2706
  async doGenerate(options) {
2544
- var _a, _b, _c, _d, _e, _f, _g, _h;
2707
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2545
2708
  const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2546
2709
  ...options,
2547
2710
  stream: false,
@@ -2619,11 +2782,23 @@ var AnthropicMessagesLanguageModel = class {
2619
2782
  text: JSON.stringify(part.input)
2620
2783
  });
2621
2784
  } else {
2785
+ const caller = part.caller;
2786
+ const callerInfo = caller ? {
2787
+ type: caller.type,
2788
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
2789
+ } : void 0;
2622
2790
  content.push({
2623
2791
  type: "tool-call",
2624
2792
  toolCallId: part.id,
2625
2793
  toolName: part.name,
2626
- input: JSON.stringify(part.input)
2794
+ input: JSON.stringify(part.input),
2795
+ ...callerInfo && {
2796
+ providerMetadata: {
2797
+ anthropic: {
2798
+ caller: callerInfo
2799
+ }
2800
+ }
2801
+ }
2627
2802
  });
2628
2803
  }
2629
2804
  break;
@@ -2638,11 +2813,12 @@ var AnthropicMessagesLanguageModel = class {
2638
2813
  providerExecuted: true
2639
2814
  });
2640
2815
  } else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
2816
+ 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;
2641
2817
  content.push({
2642
2818
  type: "tool-call",
2643
2819
  toolCallId: part.id,
2644
2820
  toolName: toolNameMapping.toCustomToolName(part.name),
2645
- input: JSON.stringify(part.input),
2821
+ input: JSON.stringify(inputToSerialize),
2646
2822
  providerExecuted: true
2647
2823
  });
2648
2824
  } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
@@ -2778,7 +2954,8 @@ var AnthropicMessagesLanguageModel = class {
2778
2954
  type: part.content.type,
2779
2955
  stdout: part.content.stdout,
2780
2956
  stderr: part.content.stderr,
2781
- return_code: part.content.return_code
2957
+ return_code: part.content.return_code,
2958
+ content: (_b = part.content.content) != null ? _b : []
2782
2959
  }
2783
2960
  });
2784
2961
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -2843,8 +3020,8 @@ var AnthropicMessagesLanguageModel = class {
2843
3020
  usage: convertAnthropicMessagesUsage(response.usage),
2844
3021
  request: { body: args },
2845
3022
  response: {
2846
- id: (_b = response.id) != null ? _b : void 0,
2847
- modelId: (_c = response.model) != null ? _c : void 0,
3023
+ id: (_c = response.id) != null ? _c : void 0,
3024
+ modelId: (_d = response.model) != null ? _d : void 0,
2848
3025
  headers: responseHeaders,
2849
3026
  body: rawResponse
2850
3027
  },
@@ -2852,20 +3029,20 @@ var AnthropicMessagesLanguageModel = class {
2852
3029
  providerMetadata: {
2853
3030
  anthropic: {
2854
3031
  usage: response.usage,
2855
- cacheCreationInputTokens: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null,
2856
- stopSequence: (_e = response.stop_sequence) != null ? _e : null,
3032
+ cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
3033
+ stopSequence: (_f = response.stop_sequence) != null ? _f : null,
2857
3034
  container: response.container ? {
2858
3035
  expiresAt: response.container.expires_at,
2859
3036
  id: response.container.id,
2860
- skills: (_g = (_f = response.container.skills) == null ? void 0 : _f.map((skill) => ({
3037
+ skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
2861
3038
  type: skill.type,
2862
3039
  skillId: skill.skill_id,
2863
3040
  version: skill.version
2864
- }))) != null ? _g : null
3041
+ }))) != null ? _h : null
2865
3042
  } : null,
2866
- contextManagement: (_h = mapAnthropicResponseContextManagement(
3043
+ contextManagement: (_i = mapAnthropicResponseContextManagement(
2867
3044
  response.context_management
2868
- )) != null ? _h : null
3045
+ )) != null ? _i : null
2869
3046
  }
2870
3047
  }
2871
3048
  };
@@ -2919,7 +3096,7 @@ var AnthropicMessagesLanguageModel = class {
2919
3096
  controller.enqueue({ type: "stream-start", warnings });
2920
3097
  },
2921
3098
  transform(chunk, controller) {
2922
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
3099
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2923
3100
  if (options.includeRawChunks) {
2924
3101
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2925
3102
  }
@@ -2979,12 +3156,20 @@ var AnthropicMessagesLanguageModel = class {
2979
3156
  id: String(value.index)
2980
3157
  });
2981
3158
  } else {
3159
+ const caller = part.caller;
3160
+ const callerInfo = caller ? {
3161
+ type: caller.type,
3162
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
3163
+ } : void 0;
3164
+ const hasNonEmptyInput = part.input && Object.keys(part.input).length > 0;
3165
+ const initialInput = hasNonEmptyInput ? JSON.stringify(part.input) : "";
2982
3166
  contentBlocks[value.index] = {
2983
3167
  type: "tool-call",
2984
3168
  toolCallId: part.id,
2985
3169
  toolName: part.name,
2986
- input: "",
2987
- firstDelta: true
3170
+ input: initialInput,
3171
+ firstDelta: initialInput.length === 0,
3172
+ ...callerInfo && { caller: callerInfo }
2988
3173
  };
2989
3174
  controller.enqueue({
2990
3175
  type: "tool-input-start",
@@ -3136,7 +3321,8 @@ var AnthropicMessagesLanguageModel = class {
3136
3321
  type: part.content.type,
3137
3322
  stdout: part.content.stdout,
3138
3323
  stderr: part.content.stderr,
3139
- return_code: part.content.return_code
3324
+ return_code: part.content.return_code,
3325
+ content: (_b2 = part.content.content) != null ? _b2 : []
3140
3326
  }
3141
3327
  });
3142
3328
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -3253,12 +3439,32 @@ var AnthropicMessagesLanguageModel = class {
3253
3439
  type: "tool-input-end",
3254
3440
  id: contentBlock.toolCallId
3255
3441
  });
3442
+ let finalInput = contentBlock.input === "" ? "{}" : contentBlock.input;
3443
+ if (contentBlock.providerToolName === "code_execution") {
3444
+ try {
3445
+ const parsed = JSON.parse(finalInput);
3446
+ if (parsed != null && typeof parsed === "object" && "code" in parsed && !("type" in parsed)) {
3447
+ finalInput = JSON.stringify({
3448
+ type: "programmatic-tool-call",
3449
+ ...parsed
3450
+ });
3451
+ }
3452
+ } catch (e) {
3453
+ }
3454
+ }
3256
3455
  controller.enqueue({
3257
3456
  type: "tool-call",
3258
3457
  toolCallId: contentBlock.toolCallId,
3259
3458
  toolName: contentBlock.toolName,
3260
- input: contentBlock.input === "" ? "{}" : contentBlock.input,
3261
- providerExecuted: contentBlock.providerExecuted
3459
+ input: finalInput,
3460
+ providerExecuted: contentBlock.providerExecuted,
3461
+ ...contentBlock.caller && {
3462
+ providerMetadata: {
3463
+ anthropic: {
3464
+ caller: contentBlock.caller
3465
+ }
3466
+ }
3467
+ }
3262
3468
  });
3263
3469
  }
3264
3470
  break;
@@ -3359,17 +3565,70 @@ var AnthropicMessagesLanguageModel = class {
3359
3565
  }
3360
3566
  case "message_start": {
3361
3567
  usage.input_tokens = value.message.usage.input_tokens;
3362
- usage.cache_read_input_tokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : 0;
3363
- usage.cache_creation_input_tokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : 0;
3568
+ usage.cache_read_input_tokens = (_c = value.message.usage.cache_read_input_tokens) != null ? _c : 0;
3569
+ usage.cache_creation_input_tokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : 0;
3364
3570
  rawUsage = {
3365
3571
  ...value.message.usage
3366
3572
  };
3367
- cacheCreationInputTokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : null;
3573
+ cacheCreationInputTokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : null;
3574
+ if (value.message.container != null) {
3575
+ container = {
3576
+ expiresAt: value.message.container.expires_at,
3577
+ id: value.message.container.id,
3578
+ skills: null
3579
+ };
3580
+ }
3581
+ if (value.message.stop_reason != null) {
3582
+ finishReason = mapAnthropicStopReason({
3583
+ finishReason: value.message.stop_reason,
3584
+ isJsonResponseFromTool
3585
+ });
3586
+ }
3368
3587
  controller.enqueue({
3369
3588
  type: "response-metadata",
3370
- id: (_e = value.message.id) != null ? _e : void 0,
3371
- modelId: (_f = value.message.model) != null ? _f : void 0
3589
+ id: (_f = value.message.id) != null ? _f : void 0,
3590
+ modelId: (_g = value.message.model) != null ? _g : void 0
3372
3591
  });
3592
+ if (value.message.content != null) {
3593
+ for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
3594
+ const part = value.message.content[contentIndex];
3595
+ if (part.type === "tool_use") {
3596
+ const caller = part.caller;
3597
+ const callerInfo = caller ? {
3598
+ type: caller.type,
3599
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
3600
+ } : void 0;
3601
+ controller.enqueue({
3602
+ type: "tool-input-start",
3603
+ id: part.id,
3604
+ toolName: part.name
3605
+ });
3606
+ const inputStr = JSON.stringify((_h = part.input) != null ? _h : {});
3607
+ controller.enqueue({
3608
+ type: "tool-input-delta",
3609
+ id: part.id,
3610
+ delta: inputStr
3611
+ });
3612
+ controller.enqueue({
3613
+ type: "tool-input-end",
3614
+ id: part.id
3615
+ });
3616
+ controller.enqueue({
3617
+ type: "tool-call",
3618
+ toolCallId: part.id,
3619
+ toolName: part.name,
3620
+ input: inputStr,
3621
+ ...callerInfo && {
3622
+ providerMetadata: {
3623
+ anthropic: {
3624
+ caller: callerInfo
3625
+ }
3626
+ }
3627
+ }
3628
+ });
3629
+ }
3630
+ }
3631
+ }
3373
3632
  return;
3374
3633
  }
3375
3634
  case "message_delta": {
@@ -3378,15 +3637,15 @@ var AnthropicMessagesLanguageModel = class {
3378
3637
  finishReason: value.delta.stop_reason,
3379
3638
  isJsonResponseFromTool
3380
3639
  });
3381
- stopSequence = (_g = value.delta.stop_sequence) != null ? _g : null;
3640
+ stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
3382
3641
  container = value.delta.container != null ? {
3383
3642
  expiresAt: value.delta.container.expires_at,
3384
3643
  id: value.delta.container.id,
3385
- skills: (_i = (_h = value.delta.container.skills) == null ? void 0 : _h.map((skill) => ({
3644
+ skills: (_k = (_j = value.delta.container.skills) == null ? void 0 : _j.map((skill) => ({
3386
3645
  type: skill.type,
3387
3646
  skillId: skill.skill_id,
3388
3647
  version: skill.version
3389
- }))) != null ? _i : null
3648
+ }))) != null ? _k : null
3390
3649
  } : null;
3391
3650
  if (value.delta.context_management) {
3392
3651
  contextManagement = mapAnthropicResponseContextManagement(