@ai-sdk/anthropic 3.0.0-beta.68 → 3.0.0-beta.70

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.
@@ -556,7 +556,7 @@ declare class CacheControlValidator {
556
556
 
557
557
  declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
558
558
  tools: LanguageModelV3CallOptions['tools'];
559
- toolChoice?: LanguageModelV3CallOptions['toolChoice'];
559
+ toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
560
560
  disableParallelToolUse?: boolean;
561
561
  cacheControlValidator?: CacheControlValidator;
562
562
  }): Promise<{
@@ -556,7 +556,7 @@ declare class CacheControlValidator {
556
556
 
557
557
  declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
558
558
  tools: LanguageModelV3CallOptions['tools'];
559
- toolChoice?: LanguageModelV3CallOptions['toolChoice'];
559
+ toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
560
560
  disableParallelToolUse?: boolean;
561
561
  cacheControlValidator?: CacheControlValidator;
562
562
  }): Promise<{
@@ -1230,7 +1230,8 @@ async function convertToAnthropicMessagesPrompt({
1230
1230
  prompt,
1231
1231
  sendReasoning,
1232
1232
  warnings,
1233
- cacheControlValidator
1233
+ cacheControlValidator,
1234
+ toolNameMapping
1234
1235
  }) {
1235
1236
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1236
1237
  const betas = /* @__PURE__ */ new Set();
@@ -1568,6 +1569,9 @@ async function convertToAnthropicMessagesPrompt({
1568
1569
  }
1569
1570
  case "tool-call": {
1570
1571
  if (part.providerExecuted) {
1572
+ const providerToolName = toolNameMapping.toProviderToolName(
1573
+ part.toolName
1574
+ );
1571
1575
  const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
1572
1576
  if (isMcpToolUse) {
1573
1577
  mcpToolUseIds.add(part.toolCallId);
@@ -1589,7 +1593,7 @@ async function convertToAnthropicMessagesPrompt({
1589
1593
  });
1590
1594
  } else if (
1591
1595
  // code execution 20250825:
1592
- 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")
1596
+ providerToolName === "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")
1593
1597
  ) {
1594
1598
  anthropicContent.push({
1595
1599
  type: "server_tool_use",
@@ -1599,20 +1603,22 @@ async function convertToAnthropicMessagesPrompt({
1599
1603
  input: part.input,
1600
1604
  cache_control: cacheControl
1601
1605
  });
1602
- } else if (part.toolName === "code_execution" || // code execution 20250522
1603
- part.toolName === "web_fetch" || part.toolName === "web_search") {
1604
- anthropicContent.push({
1605
- type: "server_tool_use",
1606
- id: part.toolCallId,
1607
- name: part.toolName,
1608
- input: part.input,
1609
- cache_control: cacheControl
1610
- });
1611
1606
  } else {
1612
- warnings.push({
1613
- type: "other",
1614
- message: `provider executed tool call for tool ${part.toolName} is not supported`
1615
- });
1607
+ if (providerToolName === "code_execution" || // code execution 20250522
1608
+ providerToolName === "web_fetch" || providerToolName === "web_search") {
1609
+ anthropicContent.push({
1610
+ type: "server_tool_use",
1611
+ id: part.toolCallId,
1612
+ name: providerToolName,
1613
+ input: part.input,
1614
+ cache_control: cacheControl
1615
+ });
1616
+ } else {
1617
+ warnings.push({
1618
+ type: "other",
1619
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
1620
+ });
1621
+ }
1616
1622
  }
1617
1623
  break;
1618
1624
  }
@@ -1626,6 +1632,9 @@ async function convertToAnthropicMessagesPrompt({
1626
1632
  break;
1627
1633
  }
1628
1634
  case "tool-result": {
1635
+ const providerToolName = toolNameMapping.toProviderToolName(
1636
+ part.toolName
1637
+ );
1629
1638
  if (mcpToolUseIds.has(part.toolCallId)) {
1630
1639
  const output = part.output;
1631
1640
  if (output.type !== "json" && output.type !== "error-json") {
@@ -1642,7 +1651,7 @@ async function convertToAnthropicMessagesPrompt({
1642
1651
  content: output.value,
1643
1652
  cache_control: cacheControl
1644
1653
  });
1645
- } else if (part.toolName === "code_execution") {
1654
+ } else if (providerToolName === "code_execution") {
1646
1655
  const output = part.output;
1647
1656
  if (output.type !== "json") {
1648
1657
  warnings.push({
@@ -1695,7 +1704,7 @@ async function convertToAnthropicMessagesPrompt({
1695
1704
  }
1696
1705
  break;
1697
1706
  }
1698
- if (part.toolName === "web_fetch") {
1707
+ if (providerToolName === "web_fetch") {
1699
1708
  const output = part.output;
1700
1709
  if (output.type !== "json") {
1701
1710
  warnings.push({
@@ -1730,7 +1739,7 @@ async function convertToAnthropicMessagesPrompt({
1730
1739
  });
1731
1740
  break;
1732
1741
  }
1733
- if (part.toolName === "web_search") {
1742
+ if (providerToolName === "web_search") {
1734
1743
  const output = part.output;
1735
1744
  if (output.type !== "json") {
1736
1745
  warnings.push({
@@ -1967,11 +1976,30 @@ var AnthropicMessagesLanguageModel = class {
1967
1976
  inputSchema: responseFormat.schema
1968
1977
  } : void 0;
1969
1978
  const cacheControlValidator = new CacheControlValidator();
1979
+ const toolNameMapping = (0, import_provider_utils11.createToolNameMapping)({
1980
+ tools,
1981
+ providerToolNames: {
1982
+ "anthropic.code_execution_20250522": "code_execution",
1983
+ "anthropic.code_execution_20250825": "code_execution",
1984
+ "anthropic.computer_20241022": "computer",
1985
+ "anthropic.computer_20250124": "computer",
1986
+ "anthropic.text_editor_20241022": "str_replace_editor",
1987
+ "anthropic.text_editor_20250124": "str_replace_editor",
1988
+ "anthropic.text_editor_20250429": "str_replace_based_edit_tool",
1989
+ "anthropic.text_editor_20250728": "str_replace_based_edit_tool",
1990
+ "anthropic.bash_20241022": "bash",
1991
+ "anthropic.bash_20250124": "bash",
1992
+ "anthropic.memory_20250818": "memory",
1993
+ "anthropic.web_search_20250305": "web_search",
1994
+ "anthropic.web_fetch_20250910": "web_fetch"
1995
+ }
1996
+ });
1970
1997
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1971
1998
  prompt,
1972
1999
  sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
1973
2000
  warnings,
1974
- cacheControlValidator
2001
+ cacheControlValidator,
2002
+ toolNameMapping
1975
2003
  });
1976
2004
  const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1977
2005
  const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
@@ -2123,7 +2151,8 @@ var AnthropicMessagesLanguageModel = class {
2123
2151
  },
2124
2152
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2125
2153
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2126
- usesJsonResponseTool: jsonResponseTool != null
2154
+ usesJsonResponseTool: jsonResponseTool != null,
2155
+ toolNameMapping
2127
2156
  };
2128
2157
  }
2129
2158
  async getHeaders({
@@ -2181,7 +2210,7 @@ var AnthropicMessagesLanguageModel = class {
2181
2210
  }
2182
2211
  async doGenerate(options) {
2183
2212
  var _a, _b, _c, _d, _e, _f, _g, _h;
2184
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2213
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2185
2214
  ...options,
2186
2215
  stream: false,
2187
2216
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2272,7 +2301,7 @@ var AnthropicMessagesLanguageModel = class {
2272
2301
  content.push({
2273
2302
  type: "tool-call",
2274
2303
  toolCallId: part.id,
2275
- toolName: "code_execution",
2304
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2276
2305
  input: JSON.stringify({ type: part.name, ...part.input }),
2277
2306
  providerExecuted: true
2278
2307
  });
@@ -2280,7 +2309,7 @@ var AnthropicMessagesLanguageModel = class {
2280
2309
  content.push({
2281
2310
  type: "tool-call",
2282
2311
  toolCallId: part.id,
2283
- toolName: part.name,
2312
+ toolName: toolNameMapping.toCustomToolName(part.name),
2284
2313
  input: JSON.stringify(part.input),
2285
2314
  providerExecuted: true
2286
2315
  });
@@ -2322,7 +2351,7 @@ var AnthropicMessagesLanguageModel = class {
2322
2351
  content.push({
2323
2352
  type: "tool-result",
2324
2353
  toolCallId: part.tool_use_id,
2325
- toolName: "web_fetch",
2354
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2326
2355
  result: {
2327
2356
  type: "web_fetch_result",
2328
2357
  url: part.content.url,
@@ -2343,7 +2372,7 @@ var AnthropicMessagesLanguageModel = class {
2343
2372
  content.push({
2344
2373
  type: "tool-result",
2345
2374
  toolCallId: part.tool_use_id,
2346
- toolName: "web_fetch",
2375
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2347
2376
  isError: true,
2348
2377
  result: {
2349
2378
  type: "web_fetch_tool_result_error",
@@ -2358,7 +2387,7 @@ var AnthropicMessagesLanguageModel = class {
2358
2387
  content.push({
2359
2388
  type: "tool-result",
2360
2389
  toolCallId: part.tool_use_id,
2361
- toolName: "web_search",
2390
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2362
2391
  result: part.content.map((result) => {
2363
2392
  var _a2;
2364
2393
  return {
@@ -2388,7 +2417,7 @@ var AnthropicMessagesLanguageModel = class {
2388
2417
  content.push({
2389
2418
  type: "tool-result",
2390
2419
  toolCallId: part.tool_use_id,
2391
- toolName: "web_search",
2420
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2392
2421
  isError: true,
2393
2422
  result: {
2394
2423
  type: "web_search_tool_result_error",
@@ -2404,7 +2433,7 @@ var AnthropicMessagesLanguageModel = class {
2404
2433
  content.push({
2405
2434
  type: "tool-result",
2406
2435
  toolCallId: part.tool_use_id,
2407
- toolName: "code_execution",
2436
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2408
2437
  result: {
2409
2438
  type: part.content.type,
2410
2439
  stdout: part.content.stdout,
@@ -2416,7 +2445,7 @@ var AnthropicMessagesLanguageModel = class {
2416
2445
  content.push({
2417
2446
  type: "tool-result",
2418
2447
  toolCallId: part.tool_use_id,
2419
- toolName: "code_execution",
2448
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2420
2449
  isError: true,
2421
2450
  result: {
2422
2451
  type: "code_execution_tool_result_error",
@@ -2432,7 +2461,7 @@ var AnthropicMessagesLanguageModel = class {
2432
2461
  content.push({
2433
2462
  type: "tool-result",
2434
2463
  toolCallId: part.tool_use_id,
2435
- toolName: "code_execution",
2464
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2436
2465
  result: part.content
2437
2466
  });
2438
2467
  break;
@@ -2478,11 +2507,13 @@ var AnthropicMessagesLanguageModel = class {
2478
2507
  };
2479
2508
  }
2480
2509
  async doStream(options) {
2510
+ var _a, _b;
2481
2511
  const {
2482
2512
  args: body,
2483
2513
  warnings,
2484
2514
  betas,
2485
- usesJsonResponseTool
2515
+ usesJsonResponseTool,
2516
+ toolNameMapping
2486
2517
  } = await this.getArgs({
2487
2518
  ...options,
2488
2519
  stream: true,
@@ -2516,25 +2547,13 @@ var AnthropicMessagesLanguageModel = class {
2516
2547
  let isJsonResponseFromTool = false;
2517
2548
  let blockType = void 0;
2518
2549
  const generateId2 = this.generateId;
2519
- let isFirstChunk = true;
2520
- let stream = void 0;
2521
- const returnPromise = new import_provider_utils11.DelayedPromise();
2522
2550
  const transformedStream = response.pipeThrough(
2523
2551
  new TransformStream({
2524
2552
  start(controller) {
2525
2553
  controller.enqueue({ type: "stream-start", warnings });
2526
2554
  },
2527
- async flush() {
2528
- if (returnPromise.isPending()) {
2529
- returnPromise.resolve({
2530
- stream,
2531
- request: { body },
2532
- response: { headers: responseHeaders }
2533
- });
2534
- }
2535
- },
2536
2555
  transform(chunk, controller) {
2537
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2556
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
2538
2557
  if (options.includeRawChunks) {
2539
2558
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2540
2559
  }
@@ -2542,29 +2561,6 @@ var AnthropicMessagesLanguageModel = class {
2542
2561
  controller.enqueue({ type: "error", error: chunk.error });
2543
2562
  return;
2544
2563
  }
2545
- if (isFirstChunk) {
2546
- if (chunk.value.type === "error") {
2547
- returnPromise.reject(
2548
- new import_provider3.APICallError({
2549
- message: chunk.value.error.message,
2550
- url,
2551
- requestBodyValues: body,
2552
- statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
2553
- responseHeaders,
2554
- responseBody: JSON.stringify(chunk.value.error),
2555
- isRetryable: chunk.value.error.type === "overloaded_error"
2556
- })
2557
- );
2558
- controller.terminate();
2559
- return;
2560
- }
2561
- isFirstChunk = false;
2562
- returnPromise.resolve({
2563
- stream,
2564
- request: { body },
2565
- response: { headers: responseHeaders }
2566
- });
2567
- }
2568
2564
  const value = chunk.value;
2569
2565
  switch (value.type) {
2570
2566
  case "ping": {
@@ -2643,19 +2639,21 @@ var AnthropicMessagesLanguageModel = class {
2643
2639
  // code execution 20250825 bash:
2644
2640
  "bash_code_execution"
2645
2641
  ].includes(part.name)) {
2642
+ const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2643
+ const customToolName = toolNameMapping.toCustomToolName(providerToolName);
2646
2644
  contentBlocks[value.index] = {
2647
2645
  type: "tool-call",
2648
2646
  toolCallId: part.id,
2649
- toolName: part.name,
2647
+ toolName: customToolName,
2650
2648
  input: "",
2651
2649
  providerExecuted: true,
2652
- firstDelta: true
2650
+ firstDelta: true,
2651
+ providerToolName: part.name
2653
2652
  };
2654
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2655
2653
  controller.enqueue({
2656
2654
  type: "tool-input-start",
2657
2655
  id: part.id,
2658
- toolName: mappedToolName,
2656
+ toolName: customToolName,
2659
2657
  providerExecuted: true
2660
2658
  });
2661
2659
  }
@@ -2666,7 +2664,7 @@ var AnthropicMessagesLanguageModel = class {
2666
2664
  controller.enqueue({
2667
2665
  type: "tool-result",
2668
2666
  toolCallId: part.tool_use_id,
2669
- toolName: "web_fetch",
2667
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2670
2668
  result: {
2671
2669
  type: "web_fetch_result",
2672
2670
  url: part.content.url,
@@ -2687,7 +2685,7 @@ var AnthropicMessagesLanguageModel = class {
2687
2685
  controller.enqueue({
2688
2686
  type: "tool-result",
2689
2687
  toolCallId: part.tool_use_id,
2690
- toolName: "web_fetch",
2688
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2691
2689
  isError: true,
2692
2690
  result: {
2693
2691
  type: "web_fetch_tool_result_error",
@@ -2702,13 +2700,13 @@ var AnthropicMessagesLanguageModel = class {
2702
2700
  controller.enqueue({
2703
2701
  type: "tool-result",
2704
2702
  toolCallId: part.tool_use_id,
2705
- toolName: "web_search",
2703
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2706
2704
  result: part.content.map((result) => {
2707
- var _a2;
2705
+ var _a3;
2708
2706
  return {
2709
2707
  url: result.url,
2710
2708
  title: result.title,
2711
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2709
+ pageAge: (_a3 = result.page_age) != null ? _a3 : null,
2712
2710
  encryptedContent: result.encrypted_content,
2713
2711
  type: result.type
2714
2712
  };
@@ -2723,7 +2721,7 @@ var AnthropicMessagesLanguageModel = class {
2723
2721
  title: result.title,
2724
2722
  providerMetadata: {
2725
2723
  anthropic: {
2726
- pageAge: (_a = result.page_age) != null ? _a : null
2724
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null
2727
2725
  }
2728
2726
  }
2729
2727
  });
@@ -2732,7 +2730,7 @@ var AnthropicMessagesLanguageModel = class {
2732
2730
  controller.enqueue({
2733
2731
  type: "tool-result",
2734
2732
  toolCallId: part.tool_use_id,
2735
- toolName: "web_search",
2733
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2736
2734
  isError: true,
2737
2735
  result: {
2738
2736
  type: "web_search_tool_result_error",
@@ -2748,7 +2746,7 @@ var AnthropicMessagesLanguageModel = class {
2748
2746
  controller.enqueue({
2749
2747
  type: "tool-result",
2750
2748
  toolCallId: part.tool_use_id,
2751
- toolName: "code_execution",
2749
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2752
2750
  result: {
2753
2751
  type: part.content.type,
2754
2752
  stdout: part.content.stdout,
@@ -2760,7 +2758,7 @@ var AnthropicMessagesLanguageModel = class {
2760
2758
  controller.enqueue({
2761
2759
  type: "tool-result",
2762
2760
  toolCallId: part.tool_use_id,
2763
- toolName: "code_execution",
2761
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2764
2762
  isError: true,
2765
2763
  result: {
2766
2764
  type: "code_execution_tool_result_error",
@@ -2776,7 +2774,7 @@ var AnthropicMessagesLanguageModel = class {
2776
2774
  controller.enqueue({
2777
2775
  type: "tool-result",
2778
2776
  toolCallId: part.tool_use_id,
2779
- toolName: "code_execution",
2777
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2780
2778
  result: part.content
2781
2779
  });
2782
2780
  return;
@@ -2844,11 +2842,10 @@ var AnthropicMessagesLanguageModel = class {
2844
2842
  type: "tool-input-end",
2845
2843
  id: contentBlock.toolCallId
2846
2844
  });
2847
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2848
2845
  controller.enqueue({
2849
2846
  type: "tool-call",
2850
2847
  toolCallId: contentBlock.toolCallId,
2851
- toolName,
2848
+ toolName: contentBlock.toolName,
2852
2849
  input: contentBlock.input === "" ? "{}" : contentBlock.input,
2853
2850
  providerExecuted: contentBlock.providerExecuted
2854
2851
  });
@@ -2916,8 +2913,8 @@ var AnthropicMessagesLanguageModel = class {
2916
2913
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2917
2914
  return;
2918
2915
  }
2919
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2920
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2916
+ if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
2917
+ delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
2921
2918
  }
2922
2919
  controller.enqueue({
2923
2920
  type: "tool-input-delta",
@@ -2951,7 +2948,7 @@ var AnthropicMessagesLanguageModel = class {
2951
2948
  }
2952
2949
  case "message_start": {
2953
2950
  usage.inputTokens = value.message.usage.input_tokens;
2954
- usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2951
+ usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
2955
2952
  rawUsage = {
2956
2953
  ...value.message.usage
2957
2954
  };
@@ -3015,22 +3012,35 @@ var AnthropicMessagesLanguageModel = class {
3015
3012
  })
3016
3013
  );
3017
3014
  const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
3018
- stream = streamForConsumer;
3019
3015
  const firstChunkReader = streamForFirstChunk.getReader();
3020
3016
  try {
3021
- const { done } = await firstChunkReader.read();
3022
- if (!done) {
3023
- firstChunkReader.cancel();
3017
+ await firstChunkReader.read();
3018
+ let result = await firstChunkReader.read();
3019
+ if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
3020
+ result = await firstChunkReader.read();
3024
3021
  }
3025
- } catch (error) {
3026
- try {
3027
- firstChunkReader.cancel();
3028
- } catch (e) {
3022
+ if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
3023
+ const error = result.value.error;
3024
+ throw new import_provider3.APICallError({
3025
+ message: error.message,
3026
+ url,
3027
+ requestBodyValues: body,
3028
+ statusCode: error.type === "overloaded_error" ? 529 : 500,
3029
+ responseHeaders,
3030
+ responseBody: JSON.stringify(error),
3031
+ isRetryable: error.type === "overloaded_error"
3032
+ });
3029
3033
  }
3030
3034
  } finally {
3035
+ firstChunkReader.cancel().catch(() => {
3036
+ });
3031
3037
  firstChunkReader.releaseLock();
3032
3038
  }
3033
- return returnPromise.promise;
3039
+ return {
3040
+ stream: streamForConsumer,
3041
+ request: { body },
3042
+ response: { headers: responseHeaders }
3043
+ };
3034
3044
  }
3035
3045
  };
3036
3046
  function getModelCapabilities(modelId) {