@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.0-beta.70
4
+
5
+ ### Patch Changes
6
+
7
+ - f13958c: chore(antropic): allow custom names for provider-defined tools
8
+
9
+ ## 3.0.0-beta.69
10
+
11
+ ### Patch Changes
12
+
13
+ - 589a4ee: fix(anthropic): simplify pulling first chunk
14
+
3
15
  ## 3.0.0-beta.68
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "3.0.0-beta.68" : "0.0.0-test";
34
+ var VERSION = true ? "3.0.0-beta.70" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -1237,7 +1237,8 @@ async function convertToAnthropicMessagesPrompt({
1237
1237
  prompt,
1238
1238
  sendReasoning,
1239
1239
  warnings,
1240
- cacheControlValidator
1240
+ cacheControlValidator,
1241
+ toolNameMapping
1241
1242
  }) {
1242
1243
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1243
1244
  const betas = /* @__PURE__ */ new Set();
@@ -1575,6 +1576,9 @@ async function convertToAnthropicMessagesPrompt({
1575
1576
  }
1576
1577
  case "tool-call": {
1577
1578
  if (part.providerExecuted) {
1579
+ const providerToolName = toolNameMapping.toProviderToolName(
1580
+ part.toolName
1581
+ );
1578
1582
  const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
1579
1583
  if (isMcpToolUse) {
1580
1584
  mcpToolUseIds.add(part.toolCallId);
@@ -1596,7 +1600,7 @@ async function convertToAnthropicMessagesPrompt({
1596
1600
  });
1597
1601
  } else if (
1598
1602
  // code execution 20250825:
1599
- 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")
1603
+ 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")
1600
1604
  ) {
1601
1605
  anthropicContent.push({
1602
1606
  type: "server_tool_use",
@@ -1606,20 +1610,22 @@ async function convertToAnthropicMessagesPrompt({
1606
1610
  input: part.input,
1607
1611
  cache_control: cacheControl
1608
1612
  });
1609
- } else if (part.toolName === "code_execution" || // code execution 20250522
1610
- part.toolName === "web_fetch" || part.toolName === "web_search") {
1611
- anthropicContent.push({
1612
- type: "server_tool_use",
1613
- id: part.toolCallId,
1614
- name: part.toolName,
1615
- input: part.input,
1616
- cache_control: cacheControl
1617
- });
1618
1613
  } else {
1619
- warnings.push({
1620
- type: "other",
1621
- message: `provider executed tool call for tool ${part.toolName} is not supported`
1622
- });
1614
+ if (providerToolName === "code_execution" || // code execution 20250522
1615
+ providerToolName === "web_fetch" || providerToolName === "web_search") {
1616
+ anthropicContent.push({
1617
+ type: "server_tool_use",
1618
+ id: part.toolCallId,
1619
+ name: providerToolName,
1620
+ input: part.input,
1621
+ cache_control: cacheControl
1622
+ });
1623
+ } else {
1624
+ warnings.push({
1625
+ type: "other",
1626
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
1627
+ });
1628
+ }
1623
1629
  }
1624
1630
  break;
1625
1631
  }
@@ -1633,6 +1639,9 @@ async function convertToAnthropicMessagesPrompt({
1633
1639
  break;
1634
1640
  }
1635
1641
  case "tool-result": {
1642
+ const providerToolName = toolNameMapping.toProviderToolName(
1643
+ part.toolName
1644
+ );
1636
1645
  if (mcpToolUseIds.has(part.toolCallId)) {
1637
1646
  const output = part.output;
1638
1647
  if (output.type !== "json" && output.type !== "error-json") {
@@ -1649,7 +1658,7 @@ async function convertToAnthropicMessagesPrompt({
1649
1658
  content: output.value,
1650
1659
  cache_control: cacheControl
1651
1660
  });
1652
- } else if (part.toolName === "code_execution") {
1661
+ } else if (providerToolName === "code_execution") {
1653
1662
  const output = part.output;
1654
1663
  if (output.type !== "json") {
1655
1664
  warnings.push({
@@ -1702,7 +1711,7 @@ async function convertToAnthropicMessagesPrompt({
1702
1711
  }
1703
1712
  break;
1704
1713
  }
1705
- if (part.toolName === "web_fetch") {
1714
+ if (providerToolName === "web_fetch") {
1706
1715
  const output = part.output;
1707
1716
  if (output.type !== "json") {
1708
1717
  warnings.push({
@@ -1737,7 +1746,7 @@ async function convertToAnthropicMessagesPrompt({
1737
1746
  });
1738
1747
  break;
1739
1748
  }
1740
- if (part.toolName === "web_search") {
1749
+ if (providerToolName === "web_search") {
1741
1750
  const output = part.output;
1742
1751
  if (output.type !== "json") {
1743
1752
  warnings.push({
@@ -1974,11 +1983,30 @@ var AnthropicMessagesLanguageModel = class {
1974
1983
  inputSchema: responseFormat.schema
1975
1984
  } : void 0;
1976
1985
  const cacheControlValidator = new CacheControlValidator();
1986
+ const toolNameMapping = (0, import_provider_utils11.createToolNameMapping)({
1987
+ tools,
1988
+ providerToolNames: {
1989
+ "anthropic.code_execution_20250522": "code_execution",
1990
+ "anthropic.code_execution_20250825": "code_execution",
1991
+ "anthropic.computer_20241022": "computer",
1992
+ "anthropic.computer_20250124": "computer",
1993
+ "anthropic.text_editor_20241022": "str_replace_editor",
1994
+ "anthropic.text_editor_20250124": "str_replace_editor",
1995
+ "anthropic.text_editor_20250429": "str_replace_based_edit_tool",
1996
+ "anthropic.text_editor_20250728": "str_replace_based_edit_tool",
1997
+ "anthropic.bash_20241022": "bash",
1998
+ "anthropic.bash_20250124": "bash",
1999
+ "anthropic.memory_20250818": "memory",
2000
+ "anthropic.web_search_20250305": "web_search",
2001
+ "anthropic.web_fetch_20250910": "web_fetch"
2002
+ }
2003
+ });
1977
2004
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1978
2005
  prompt,
1979
2006
  sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
1980
2007
  warnings,
1981
- cacheControlValidator
2008
+ cacheControlValidator,
2009
+ toolNameMapping
1982
2010
  });
1983
2011
  const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1984
2012
  const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
@@ -2130,7 +2158,8 @@ var AnthropicMessagesLanguageModel = class {
2130
2158
  },
2131
2159
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2132
2160
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2133
- usesJsonResponseTool: jsonResponseTool != null
2161
+ usesJsonResponseTool: jsonResponseTool != null,
2162
+ toolNameMapping
2134
2163
  };
2135
2164
  }
2136
2165
  async getHeaders({
@@ -2188,7 +2217,7 @@ var AnthropicMessagesLanguageModel = class {
2188
2217
  }
2189
2218
  async doGenerate(options) {
2190
2219
  var _a, _b, _c, _d, _e, _f, _g, _h;
2191
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2220
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2192
2221
  ...options,
2193
2222
  stream: false,
2194
2223
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2279,7 +2308,7 @@ var AnthropicMessagesLanguageModel = class {
2279
2308
  content.push({
2280
2309
  type: "tool-call",
2281
2310
  toolCallId: part.id,
2282
- toolName: "code_execution",
2311
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2283
2312
  input: JSON.stringify({ type: part.name, ...part.input }),
2284
2313
  providerExecuted: true
2285
2314
  });
@@ -2287,7 +2316,7 @@ var AnthropicMessagesLanguageModel = class {
2287
2316
  content.push({
2288
2317
  type: "tool-call",
2289
2318
  toolCallId: part.id,
2290
- toolName: part.name,
2319
+ toolName: toolNameMapping.toCustomToolName(part.name),
2291
2320
  input: JSON.stringify(part.input),
2292
2321
  providerExecuted: true
2293
2322
  });
@@ -2329,7 +2358,7 @@ var AnthropicMessagesLanguageModel = class {
2329
2358
  content.push({
2330
2359
  type: "tool-result",
2331
2360
  toolCallId: part.tool_use_id,
2332
- toolName: "web_fetch",
2361
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2333
2362
  result: {
2334
2363
  type: "web_fetch_result",
2335
2364
  url: part.content.url,
@@ -2350,7 +2379,7 @@ var AnthropicMessagesLanguageModel = class {
2350
2379
  content.push({
2351
2380
  type: "tool-result",
2352
2381
  toolCallId: part.tool_use_id,
2353
- toolName: "web_fetch",
2382
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2354
2383
  isError: true,
2355
2384
  result: {
2356
2385
  type: "web_fetch_tool_result_error",
@@ -2365,7 +2394,7 @@ var AnthropicMessagesLanguageModel = class {
2365
2394
  content.push({
2366
2395
  type: "tool-result",
2367
2396
  toolCallId: part.tool_use_id,
2368
- toolName: "web_search",
2397
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2369
2398
  result: part.content.map((result) => {
2370
2399
  var _a2;
2371
2400
  return {
@@ -2395,7 +2424,7 @@ var AnthropicMessagesLanguageModel = class {
2395
2424
  content.push({
2396
2425
  type: "tool-result",
2397
2426
  toolCallId: part.tool_use_id,
2398
- toolName: "web_search",
2427
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2399
2428
  isError: true,
2400
2429
  result: {
2401
2430
  type: "web_search_tool_result_error",
@@ -2411,7 +2440,7 @@ var AnthropicMessagesLanguageModel = class {
2411
2440
  content.push({
2412
2441
  type: "tool-result",
2413
2442
  toolCallId: part.tool_use_id,
2414
- toolName: "code_execution",
2443
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2415
2444
  result: {
2416
2445
  type: part.content.type,
2417
2446
  stdout: part.content.stdout,
@@ -2423,7 +2452,7 @@ var AnthropicMessagesLanguageModel = class {
2423
2452
  content.push({
2424
2453
  type: "tool-result",
2425
2454
  toolCallId: part.tool_use_id,
2426
- toolName: "code_execution",
2455
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2427
2456
  isError: true,
2428
2457
  result: {
2429
2458
  type: "code_execution_tool_result_error",
@@ -2439,7 +2468,7 @@ var AnthropicMessagesLanguageModel = class {
2439
2468
  content.push({
2440
2469
  type: "tool-result",
2441
2470
  toolCallId: part.tool_use_id,
2442
- toolName: "code_execution",
2471
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2443
2472
  result: part.content
2444
2473
  });
2445
2474
  break;
@@ -2485,11 +2514,13 @@ var AnthropicMessagesLanguageModel = class {
2485
2514
  };
2486
2515
  }
2487
2516
  async doStream(options) {
2517
+ var _a, _b;
2488
2518
  const {
2489
2519
  args: body,
2490
2520
  warnings,
2491
2521
  betas,
2492
- usesJsonResponseTool
2522
+ usesJsonResponseTool,
2523
+ toolNameMapping
2493
2524
  } = await this.getArgs({
2494
2525
  ...options,
2495
2526
  stream: true,
@@ -2523,25 +2554,13 @@ var AnthropicMessagesLanguageModel = class {
2523
2554
  let isJsonResponseFromTool = false;
2524
2555
  let blockType = void 0;
2525
2556
  const generateId3 = this.generateId;
2526
- let isFirstChunk = true;
2527
- let stream = void 0;
2528
- const returnPromise = new import_provider_utils11.DelayedPromise();
2529
2557
  const transformedStream = response.pipeThrough(
2530
2558
  new TransformStream({
2531
2559
  start(controller) {
2532
2560
  controller.enqueue({ type: "stream-start", warnings });
2533
2561
  },
2534
- async flush() {
2535
- if (returnPromise.isPending()) {
2536
- returnPromise.resolve({
2537
- stream,
2538
- request: { body },
2539
- response: { headers: responseHeaders }
2540
- });
2541
- }
2542
- },
2543
2562
  transform(chunk, controller) {
2544
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2563
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
2545
2564
  if (options.includeRawChunks) {
2546
2565
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2547
2566
  }
@@ -2549,29 +2568,6 @@ var AnthropicMessagesLanguageModel = class {
2549
2568
  controller.enqueue({ type: "error", error: chunk.error });
2550
2569
  return;
2551
2570
  }
2552
- if (isFirstChunk) {
2553
- if (chunk.value.type === "error") {
2554
- returnPromise.reject(
2555
- new import_provider3.APICallError({
2556
- message: chunk.value.error.message,
2557
- url,
2558
- requestBodyValues: body,
2559
- statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
2560
- responseHeaders,
2561
- responseBody: JSON.stringify(chunk.value.error),
2562
- isRetryable: chunk.value.error.type === "overloaded_error"
2563
- })
2564
- );
2565
- controller.terminate();
2566
- return;
2567
- }
2568
- isFirstChunk = false;
2569
- returnPromise.resolve({
2570
- stream,
2571
- request: { body },
2572
- response: { headers: responseHeaders }
2573
- });
2574
- }
2575
2571
  const value = chunk.value;
2576
2572
  switch (value.type) {
2577
2573
  case "ping": {
@@ -2650,19 +2646,21 @@ var AnthropicMessagesLanguageModel = class {
2650
2646
  // code execution 20250825 bash:
2651
2647
  "bash_code_execution"
2652
2648
  ].includes(part.name)) {
2649
+ const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2650
+ const customToolName = toolNameMapping.toCustomToolName(providerToolName);
2653
2651
  contentBlocks[value.index] = {
2654
2652
  type: "tool-call",
2655
2653
  toolCallId: part.id,
2656
- toolName: part.name,
2654
+ toolName: customToolName,
2657
2655
  input: "",
2658
2656
  providerExecuted: true,
2659
- firstDelta: true
2657
+ firstDelta: true,
2658
+ providerToolName: part.name
2660
2659
  };
2661
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2662
2660
  controller.enqueue({
2663
2661
  type: "tool-input-start",
2664
2662
  id: part.id,
2665
- toolName: mappedToolName,
2663
+ toolName: customToolName,
2666
2664
  providerExecuted: true
2667
2665
  });
2668
2666
  }
@@ -2673,7 +2671,7 @@ var AnthropicMessagesLanguageModel = class {
2673
2671
  controller.enqueue({
2674
2672
  type: "tool-result",
2675
2673
  toolCallId: part.tool_use_id,
2676
- toolName: "web_fetch",
2674
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2677
2675
  result: {
2678
2676
  type: "web_fetch_result",
2679
2677
  url: part.content.url,
@@ -2694,7 +2692,7 @@ var AnthropicMessagesLanguageModel = class {
2694
2692
  controller.enqueue({
2695
2693
  type: "tool-result",
2696
2694
  toolCallId: part.tool_use_id,
2697
- toolName: "web_fetch",
2695
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2698
2696
  isError: true,
2699
2697
  result: {
2700
2698
  type: "web_fetch_tool_result_error",
@@ -2709,13 +2707,13 @@ var AnthropicMessagesLanguageModel = class {
2709
2707
  controller.enqueue({
2710
2708
  type: "tool-result",
2711
2709
  toolCallId: part.tool_use_id,
2712
- toolName: "web_search",
2710
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2713
2711
  result: part.content.map((result) => {
2714
- var _a2;
2712
+ var _a3;
2715
2713
  return {
2716
2714
  url: result.url,
2717
2715
  title: result.title,
2718
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2716
+ pageAge: (_a3 = result.page_age) != null ? _a3 : null,
2719
2717
  encryptedContent: result.encrypted_content,
2720
2718
  type: result.type
2721
2719
  };
@@ -2730,7 +2728,7 @@ var AnthropicMessagesLanguageModel = class {
2730
2728
  title: result.title,
2731
2729
  providerMetadata: {
2732
2730
  anthropic: {
2733
- pageAge: (_a = result.page_age) != null ? _a : null
2731
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null
2734
2732
  }
2735
2733
  }
2736
2734
  });
@@ -2739,7 +2737,7 @@ var AnthropicMessagesLanguageModel = class {
2739
2737
  controller.enqueue({
2740
2738
  type: "tool-result",
2741
2739
  toolCallId: part.tool_use_id,
2742
- toolName: "web_search",
2740
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2743
2741
  isError: true,
2744
2742
  result: {
2745
2743
  type: "web_search_tool_result_error",
@@ -2755,7 +2753,7 @@ var AnthropicMessagesLanguageModel = class {
2755
2753
  controller.enqueue({
2756
2754
  type: "tool-result",
2757
2755
  toolCallId: part.tool_use_id,
2758
- toolName: "code_execution",
2756
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2759
2757
  result: {
2760
2758
  type: part.content.type,
2761
2759
  stdout: part.content.stdout,
@@ -2767,7 +2765,7 @@ var AnthropicMessagesLanguageModel = class {
2767
2765
  controller.enqueue({
2768
2766
  type: "tool-result",
2769
2767
  toolCallId: part.tool_use_id,
2770
- toolName: "code_execution",
2768
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2771
2769
  isError: true,
2772
2770
  result: {
2773
2771
  type: "code_execution_tool_result_error",
@@ -2783,7 +2781,7 @@ var AnthropicMessagesLanguageModel = class {
2783
2781
  controller.enqueue({
2784
2782
  type: "tool-result",
2785
2783
  toolCallId: part.tool_use_id,
2786
- toolName: "code_execution",
2784
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2787
2785
  result: part.content
2788
2786
  });
2789
2787
  return;
@@ -2851,11 +2849,10 @@ var AnthropicMessagesLanguageModel = class {
2851
2849
  type: "tool-input-end",
2852
2850
  id: contentBlock.toolCallId
2853
2851
  });
2854
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2855
2852
  controller.enqueue({
2856
2853
  type: "tool-call",
2857
2854
  toolCallId: contentBlock.toolCallId,
2858
- toolName,
2855
+ toolName: contentBlock.toolName,
2859
2856
  input: contentBlock.input === "" ? "{}" : contentBlock.input,
2860
2857
  providerExecuted: contentBlock.providerExecuted
2861
2858
  });
@@ -2923,8 +2920,8 @@ var AnthropicMessagesLanguageModel = class {
2923
2920
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2924
2921
  return;
2925
2922
  }
2926
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2927
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2923
+ if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
2924
+ delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
2928
2925
  }
2929
2926
  controller.enqueue({
2930
2927
  type: "tool-input-delta",
@@ -2958,7 +2955,7 @@ var AnthropicMessagesLanguageModel = class {
2958
2955
  }
2959
2956
  case "message_start": {
2960
2957
  usage.inputTokens = value.message.usage.input_tokens;
2961
- usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2958
+ usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
2962
2959
  rawUsage = {
2963
2960
  ...value.message.usage
2964
2961
  };
@@ -3022,22 +3019,35 @@ var AnthropicMessagesLanguageModel = class {
3022
3019
  })
3023
3020
  );
3024
3021
  const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
3025
- stream = streamForConsumer;
3026
3022
  const firstChunkReader = streamForFirstChunk.getReader();
3027
3023
  try {
3028
- const { done } = await firstChunkReader.read();
3029
- if (!done) {
3030
- firstChunkReader.cancel();
3024
+ await firstChunkReader.read();
3025
+ let result = await firstChunkReader.read();
3026
+ if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
3027
+ result = await firstChunkReader.read();
3031
3028
  }
3032
- } catch (error) {
3033
- try {
3034
- firstChunkReader.cancel();
3035
- } catch (e) {
3029
+ if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
3030
+ const error = result.value.error;
3031
+ throw new import_provider3.APICallError({
3032
+ message: error.message,
3033
+ url,
3034
+ requestBodyValues: body,
3035
+ statusCode: error.type === "overloaded_error" ? 529 : 500,
3036
+ responseHeaders,
3037
+ responseBody: JSON.stringify(error),
3038
+ isRetryable: error.type === "overloaded_error"
3039
+ });
3036
3040
  }
3037
3041
  } finally {
3042
+ firstChunkReader.cancel().catch(() => {
3043
+ });
3038
3044
  firstChunkReader.releaseLock();
3039
3045
  }
3040
- return returnPromise.promise;
3046
+ return {
3047
+ stream: streamForConsumer,
3048
+ request: { body },
3049
+ response: { headers: responseHeaders }
3050
+ };
3041
3051
  }
3042
3052
  };
3043
3053
  function getModelCapabilities(modelId) {