@ai-sdk/anthropic 3.0.0-beta.63 → 3.0.0-beta.65

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,16 +11,18 @@ import {
11
11
  } from "@ai-sdk/provider-utils";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = true ? "3.0.0-beta.63" : "0.0.0-test";
14
+ var VERSION = true ? "3.0.0-beta.65" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
18
- UnsupportedFunctionalityError as UnsupportedFunctionalityError3
18
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError3,
19
+ APICallError
19
20
  } from "@ai-sdk/provider";
20
21
  import {
21
22
  combineHeaders,
22
23
  createEventSourceResponseHandler,
23
24
  createJsonResponseHandler,
25
+ DelayedPromise,
24
26
  generateId,
25
27
  parseProviderOptions as parseProviderOptions2,
26
28
  postJsonToApi,
@@ -736,7 +738,6 @@ var textEditor_20250728InputSchema = lazySchema3(
736
738
  );
737
739
  var factory = createProviderDefinedToolFactory({
738
740
  id: "anthropic.text_editor_20250728",
739
- name: "str_replace_based_edit_tool",
740
741
  inputSchema: textEditor_20250728InputSchema
741
742
  });
742
743
  var textEditor_20250728 = (args = {}) => {
@@ -788,7 +789,6 @@ var webSearch_20250305InputSchema = lazySchema4(
788
789
  );
789
790
  var factory2 = createProviderDefinedToolFactoryWithOutputSchema({
790
791
  id: "anthropic.web_search_20250305",
791
- name: "web_search",
792
792
  inputSchema: webSearch_20250305InputSchema,
793
793
  outputSchema: webSearch_20250305OutputSchema
794
794
  });
@@ -849,7 +849,6 @@ var webFetch_20250910InputSchema = lazySchema5(
849
849
  );
850
850
  var factory3 = createProviderDefinedToolFactoryWithOutputSchema2({
851
851
  id: "anthropic.web_fetch_20250910",
852
- name: "web_fetch",
853
852
  inputSchema: webFetch_20250910InputSchema,
854
853
  outputSchema: webFetch_20250910OutputSchema
855
854
  });
@@ -1139,7 +1138,6 @@ var codeExecution_20250522InputSchema = lazySchema6(
1139
1138
  );
1140
1139
  var factory4 = createProviderDefinedToolFactoryWithOutputSchema3({
1141
1140
  id: "anthropic.code_execution_20250522",
1142
- name: "code_execution",
1143
1141
  inputSchema: codeExecution_20250522InputSchema,
1144
1142
  outputSchema: codeExecution_20250522OutputSchema
1145
1143
  });
@@ -1232,7 +1230,6 @@ var codeExecution_20250825InputSchema = lazySchema7(
1232
1230
  );
1233
1231
  var factory5 = createProviderDefinedToolFactoryWithOutputSchema4({
1234
1232
  id: "anthropic.code_execution_20250825",
1235
- name: "code_execution",
1236
1233
  inputSchema: codeExecution_20250825InputSchema,
1237
1234
  outputSchema: codeExecution_20250825OutputSchema
1238
1235
  });
@@ -2520,8 +2517,9 @@ var AnthropicMessagesLanguageModel = class {
2520
2517
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2521
2518
  });
2522
2519
  const citationDocuments = this.extractCitationDocuments(options.prompt);
2520
+ const url = this.buildRequestUrl(true);
2523
2521
  const { responseHeaders, value: response } = await postJsonToApi({
2524
- url: this.buildRequestUrl(true),
2522
+ url,
2525
2523
  headers: await this.getHeaders({ betas, headers: options.headers }),
2526
2524
  body: this.transformRequestBody(body),
2527
2525
  failedResponseHandler: anthropicFailedResponseHandler,
@@ -2546,473 +2544,523 @@ var AnthropicMessagesLanguageModel = class {
2546
2544
  let isJsonResponseFromTool = false;
2547
2545
  let blockType = void 0;
2548
2546
  const generateId3 = this.generateId;
2549
- return {
2550
- stream: response.pipeThrough(
2551
- new TransformStream({
2552
- start(controller) {
2553
- controller.enqueue({ type: "stream-start", warnings });
2554
- },
2555
- transform(chunk, controller) {
2556
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2557
- if (options.includeRawChunks) {
2558
- controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2547
+ let isFirstChunk = true;
2548
+ let stream = void 0;
2549
+ const returnPromise = new DelayedPromise();
2550
+ const transformedStream = response.pipeThrough(
2551
+ new TransformStream({
2552
+ start(controller) {
2553
+ controller.enqueue({ type: "stream-start", warnings });
2554
+ },
2555
+ async flush() {
2556
+ if (returnPromise.isPending()) {
2557
+ returnPromise.resolve({
2558
+ stream,
2559
+ request: { body },
2560
+ response: { headers: responseHeaders }
2561
+ });
2562
+ }
2563
+ },
2564
+ transform(chunk, controller) {
2565
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2566
+ if (options.includeRawChunks) {
2567
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2568
+ }
2569
+ if (!chunk.success) {
2570
+ controller.enqueue({ type: "error", error: chunk.error });
2571
+ return;
2572
+ }
2573
+ if (isFirstChunk) {
2574
+ if (chunk.value.type === "error") {
2575
+ returnPromise.reject(
2576
+ new APICallError({
2577
+ message: chunk.value.error.message,
2578
+ url,
2579
+ requestBodyValues: body,
2580
+ statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
2581
+ responseHeaders,
2582
+ responseBody: JSON.stringify(chunk.value.error),
2583
+ isRetryable: chunk.value.error.type === "overloaded_error"
2584
+ })
2585
+ );
2586
+ controller.terminate();
2587
+ return;
2559
2588
  }
2560
- if (!chunk.success) {
2561
- controller.enqueue({ type: "error", error: chunk.error });
2589
+ isFirstChunk = false;
2590
+ returnPromise.resolve({
2591
+ stream,
2592
+ request: { body },
2593
+ response: { headers: responseHeaders }
2594
+ });
2595
+ }
2596
+ const value = chunk.value;
2597
+ switch (value.type) {
2598
+ case "ping": {
2562
2599
  return;
2563
2600
  }
2564
- const value = chunk.value;
2565
- switch (value.type) {
2566
- case "ping": {
2567
- return;
2568
- }
2569
- case "content_block_start": {
2570
- const part = value.content_block;
2571
- const contentBlockType = part.type;
2572
- blockType = contentBlockType;
2573
- switch (contentBlockType) {
2574
- case "text": {
2575
- if (usesJsonResponseTool) {
2576
- return;
2601
+ case "content_block_start": {
2602
+ const part = value.content_block;
2603
+ const contentBlockType = part.type;
2604
+ blockType = contentBlockType;
2605
+ switch (contentBlockType) {
2606
+ case "text": {
2607
+ if (usesJsonResponseTool) {
2608
+ return;
2609
+ }
2610
+ contentBlocks[value.index] = { type: "text" };
2611
+ controller.enqueue({
2612
+ type: "text-start",
2613
+ id: String(value.index)
2614
+ });
2615
+ return;
2616
+ }
2617
+ case "thinking": {
2618
+ contentBlocks[value.index] = { type: "reasoning" };
2619
+ controller.enqueue({
2620
+ type: "reasoning-start",
2621
+ id: String(value.index)
2622
+ });
2623
+ return;
2624
+ }
2625
+ case "redacted_thinking": {
2626
+ contentBlocks[value.index] = { type: "reasoning" };
2627
+ controller.enqueue({
2628
+ type: "reasoning-start",
2629
+ id: String(value.index),
2630
+ providerMetadata: {
2631
+ anthropic: {
2632
+ redactedData: part.data
2633
+ }
2577
2634
  }
2635
+ });
2636
+ return;
2637
+ }
2638
+ case "tool_use": {
2639
+ const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2640
+ if (isJsonResponseTool) {
2641
+ isJsonResponseFromTool = true;
2578
2642
  contentBlocks[value.index] = { type: "text" };
2579
2643
  controller.enqueue({
2580
2644
  type: "text-start",
2581
2645
  id: String(value.index)
2582
2646
  });
2583
- return;
2584
- }
2585
- case "thinking": {
2586
- contentBlocks[value.index] = { type: "reasoning" };
2647
+ } else {
2648
+ contentBlocks[value.index] = {
2649
+ type: "tool-call",
2650
+ toolCallId: part.id,
2651
+ toolName: part.name,
2652
+ input: "",
2653
+ firstDelta: true
2654
+ };
2587
2655
  controller.enqueue({
2588
- type: "reasoning-start",
2589
- id: String(value.index)
2656
+ type: "tool-input-start",
2657
+ id: part.id,
2658
+ toolName: part.name
2590
2659
  });
2591
- return;
2592
2660
  }
2593
- case "redacted_thinking": {
2594
- contentBlocks[value.index] = { type: "reasoning" };
2661
+ return;
2662
+ }
2663
+ case "server_tool_use": {
2664
+ if ([
2665
+ "web_fetch",
2666
+ "web_search",
2667
+ // code execution 20250825:
2668
+ "code_execution",
2669
+ // code execution 20250825 text editor:
2670
+ "text_editor_code_execution",
2671
+ // code execution 20250825 bash:
2672
+ "bash_code_execution"
2673
+ ].includes(part.name)) {
2674
+ contentBlocks[value.index] = {
2675
+ type: "tool-call",
2676
+ toolCallId: part.id,
2677
+ toolName: part.name,
2678
+ input: "",
2679
+ providerExecuted: true,
2680
+ firstDelta: true
2681
+ };
2682
+ const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2595
2683
  controller.enqueue({
2596
- type: "reasoning-start",
2597
- id: String(value.index),
2598
- providerMetadata: {
2599
- anthropic: {
2600
- redactedData: part.data
2601
- }
2602
- }
2684
+ type: "tool-input-start",
2685
+ id: part.id,
2686
+ toolName: mappedToolName,
2687
+ providerExecuted: true
2603
2688
  });
2604
- return;
2605
2689
  }
2606
- case "tool_use": {
2607
- const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2608
- if (isJsonResponseTool) {
2609
- isJsonResponseFromTool = true;
2610
- contentBlocks[value.index] = { type: "text" };
2611
- controller.enqueue({
2612
- type: "text-start",
2613
- id: String(value.index)
2614
- });
2615
- } else {
2616
- contentBlocks[value.index] = {
2617
- type: "tool-call",
2618
- toolCallId: part.id,
2619
- toolName: part.name,
2620
- input: "",
2621
- firstDelta: true
2622
- };
2623
- controller.enqueue({
2624
- type: "tool-input-start",
2625
- id: part.id,
2626
- toolName: part.name
2627
- });
2628
- }
2629
- return;
2630
- }
2631
- case "server_tool_use": {
2632
- if ([
2633
- "web_fetch",
2634
- "web_search",
2635
- // code execution 20250825:
2636
- "code_execution",
2637
- // code execution 20250825 text editor:
2638
- "text_editor_code_execution",
2639
- // code execution 20250825 bash:
2640
- "bash_code_execution"
2641
- ].includes(part.name)) {
2642
- contentBlocks[value.index] = {
2643
- type: "tool-call",
2644
- toolCallId: part.id,
2645
- toolName: part.name,
2646
- input: "",
2647
- providerExecuted: true,
2648
- firstDelta: true
2649
- };
2650
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2651
- controller.enqueue({
2652
- type: "tool-input-start",
2653
- id: part.id,
2654
- toolName: mappedToolName,
2655
- providerExecuted: true
2656
- });
2657
- }
2658
- return;
2659
- }
2660
- case "web_fetch_tool_result": {
2661
- if (part.content.type === "web_fetch_result") {
2662
- controller.enqueue({
2663
- type: "tool-result",
2664
- toolCallId: part.tool_use_id,
2665
- toolName: "web_fetch",
2666
- result: {
2667
- type: "web_fetch_result",
2668
- url: part.content.url,
2669
- retrievedAt: part.content.retrieved_at,
2670
- content: {
2671
- type: part.content.content.type,
2672
- title: part.content.content.title,
2673
- citations: part.content.content.citations,
2674
- source: {
2675
- type: part.content.content.source.type,
2676
- mediaType: part.content.content.source.media_type,
2677
- data: part.content.content.source.data
2678
- }
2690
+ return;
2691
+ }
2692
+ case "web_fetch_tool_result": {
2693
+ if (part.content.type === "web_fetch_result") {
2694
+ controller.enqueue({
2695
+ type: "tool-result",
2696
+ toolCallId: part.tool_use_id,
2697
+ toolName: "web_fetch",
2698
+ result: {
2699
+ type: "web_fetch_result",
2700
+ url: part.content.url,
2701
+ retrievedAt: part.content.retrieved_at,
2702
+ content: {
2703
+ type: part.content.content.type,
2704
+ title: part.content.content.title,
2705
+ citations: part.content.content.citations,
2706
+ source: {
2707
+ type: part.content.content.source.type,
2708
+ mediaType: part.content.content.source.media_type,
2709
+ data: part.content.content.source.data
2679
2710
  }
2680
2711
  }
2681
- });
2682
- } else if (part.content.type === "web_fetch_tool_result_error") {
2683
- controller.enqueue({
2684
- type: "tool-result",
2685
- toolCallId: part.tool_use_id,
2686
- toolName: "web_fetch",
2687
- isError: true,
2688
- result: {
2689
- type: "web_fetch_tool_result_error",
2690
- errorCode: part.content.error_code
2691
- }
2692
- });
2693
- }
2694
- return;
2712
+ }
2713
+ });
2714
+ } else if (part.content.type === "web_fetch_tool_result_error") {
2715
+ controller.enqueue({
2716
+ type: "tool-result",
2717
+ toolCallId: part.tool_use_id,
2718
+ toolName: "web_fetch",
2719
+ isError: true,
2720
+ result: {
2721
+ type: "web_fetch_tool_result_error",
2722
+ errorCode: part.content.error_code
2723
+ }
2724
+ });
2695
2725
  }
2696
- case "web_search_tool_result": {
2697
- if (Array.isArray(part.content)) {
2698
- controller.enqueue({
2699
- type: "tool-result",
2700
- toolCallId: part.tool_use_id,
2701
- toolName: "web_search",
2702
- result: part.content.map((result) => {
2703
- var _a2;
2704
- return {
2705
- url: result.url,
2706
- title: result.title,
2707
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2708
- encryptedContent: result.encrypted_content,
2709
- type: result.type
2710
- };
2711
- })
2712
- });
2713
- for (const result of part.content) {
2714
- controller.enqueue({
2715
- type: "source",
2716
- sourceType: "url",
2717
- id: generateId3(),
2726
+ return;
2727
+ }
2728
+ case "web_search_tool_result": {
2729
+ if (Array.isArray(part.content)) {
2730
+ controller.enqueue({
2731
+ type: "tool-result",
2732
+ toolCallId: part.tool_use_id,
2733
+ toolName: "web_search",
2734
+ result: part.content.map((result) => {
2735
+ var _a2;
2736
+ return {
2718
2737
  url: result.url,
2719
2738
  title: result.title,
2720
- providerMetadata: {
2721
- anthropic: {
2722
- pageAge: (_a = result.page_age) != null ? _a : null
2723
- }
2724
- }
2725
- });
2726
- }
2727
- } else {
2728
- controller.enqueue({
2729
- type: "tool-result",
2730
- toolCallId: part.tool_use_id,
2731
- toolName: "web_search",
2732
- isError: true,
2733
- result: {
2734
- type: "web_search_tool_result_error",
2735
- errorCode: part.content.error_code
2736
- }
2737
- });
2738
- }
2739
- return;
2740
- }
2741
- // code execution 20250522:
2742
- case "code_execution_tool_result": {
2743
- if (part.content.type === "code_execution_result") {
2744
- controller.enqueue({
2745
- type: "tool-result",
2746
- toolCallId: part.tool_use_id,
2747
- toolName: "code_execution",
2748
- result: {
2749
- type: part.content.type,
2750
- stdout: part.content.stdout,
2751
- stderr: part.content.stderr,
2752
- return_code: part.content.return_code
2753
- }
2754
- });
2755
- } else if (part.content.type === "code_execution_tool_result_error") {
2739
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2740
+ encryptedContent: result.encrypted_content,
2741
+ type: result.type
2742
+ };
2743
+ })
2744
+ });
2745
+ for (const result of part.content) {
2756
2746
  controller.enqueue({
2757
- type: "tool-result",
2758
- toolCallId: part.tool_use_id,
2759
- toolName: "code_execution",
2760
- isError: true,
2761
- result: {
2762
- type: "code_execution_tool_result_error",
2763
- errorCode: part.content.error_code
2747
+ type: "source",
2748
+ sourceType: "url",
2749
+ id: generateId3(),
2750
+ url: result.url,
2751
+ title: result.title,
2752
+ providerMetadata: {
2753
+ anthropic: {
2754
+ pageAge: (_a = result.page_age) != null ? _a : null
2755
+ }
2764
2756
  }
2765
2757
  });
2766
2758
  }
2767
- return;
2768
- }
2769
- // code execution 20250825:
2770
- case "bash_code_execution_tool_result":
2771
- case "text_editor_code_execution_tool_result": {
2759
+ } else {
2772
2760
  controller.enqueue({
2773
2761
  type: "tool-result",
2774
2762
  toolCallId: part.tool_use_id,
2775
- toolName: "code_execution",
2776
- result: part.content
2763
+ toolName: "web_search",
2764
+ isError: true,
2765
+ result: {
2766
+ type: "web_search_tool_result_error",
2767
+ errorCode: part.content.error_code
2768
+ }
2777
2769
  });
2778
- return;
2779
2770
  }
2780
- case "mcp_tool_use": {
2781
- mcpToolCalls[part.id] = {
2782
- type: "tool-call",
2783
- toolCallId: part.id,
2784
- toolName: part.name,
2785
- input: JSON.stringify(part.input),
2786
- providerExecuted: true,
2787
- dynamic: true,
2788
- providerMetadata: {
2789
- anthropic: {
2790
- type: "mcp-tool-use",
2791
- serverName: part.server_name
2792
- }
2771
+ return;
2772
+ }
2773
+ // code execution 20250522:
2774
+ case "code_execution_tool_result": {
2775
+ if (part.content.type === "code_execution_result") {
2776
+ controller.enqueue({
2777
+ type: "tool-result",
2778
+ toolCallId: part.tool_use_id,
2779
+ toolName: "code_execution",
2780
+ result: {
2781
+ type: part.content.type,
2782
+ stdout: part.content.stdout,
2783
+ stderr: part.content.stderr,
2784
+ return_code: part.content.return_code
2793
2785
  }
2794
- };
2795
- controller.enqueue(mcpToolCalls[part.id]);
2796
- return;
2797
- }
2798
- case "mcp_tool_result": {
2786
+ });
2787
+ } else if (part.content.type === "code_execution_tool_result_error") {
2799
2788
  controller.enqueue({
2800
2789
  type: "tool-result",
2801
2790
  toolCallId: part.tool_use_id,
2802
- toolName: mcpToolCalls[part.tool_use_id].toolName,
2803
- isError: part.is_error,
2804
- result: part.content,
2805
- dynamic: true,
2806
- providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
2791
+ toolName: "code_execution",
2792
+ isError: true,
2793
+ result: {
2794
+ type: "code_execution_tool_result_error",
2795
+ errorCode: part.content.error_code
2796
+ }
2807
2797
  });
2808
- return;
2809
- }
2810
- default: {
2811
- const _exhaustiveCheck = contentBlockType;
2812
- throw new Error(
2813
- `Unsupported content block type: ${_exhaustiveCheck}`
2814
- );
2815
2798
  }
2799
+ return;
2800
+ }
2801
+ // code execution 20250825:
2802
+ case "bash_code_execution_tool_result":
2803
+ case "text_editor_code_execution_tool_result": {
2804
+ controller.enqueue({
2805
+ type: "tool-result",
2806
+ toolCallId: part.tool_use_id,
2807
+ toolName: "code_execution",
2808
+ result: part.content
2809
+ });
2810
+ return;
2811
+ }
2812
+ case "mcp_tool_use": {
2813
+ mcpToolCalls[part.id] = {
2814
+ type: "tool-call",
2815
+ toolCallId: part.id,
2816
+ toolName: part.name,
2817
+ input: JSON.stringify(part.input),
2818
+ providerExecuted: true,
2819
+ dynamic: true,
2820
+ providerMetadata: {
2821
+ anthropic: {
2822
+ type: "mcp-tool-use",
2823
+ serverName: part.server_name
2824
+ }
2825
+ }
2826
+ };
2827
+ controller.enqueue(mcpToolCalls[part.id]);
2828
+ return;
2829
+ }
2830
+ case "mcp_tool_result": {
2831
+ controller.enqueue({
2832
+ type: "tool-result",
2833
+ toolCallId: part.tool_use_id,
2834
+ toolName: mcpToolCalls[part.tool_use_id].toolName,
2835
+ isError: part.is_error,
2836
+ result: part.content,
2837
+ dynamic: true,
2838
+ providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
2839
+ });
2840
+ return;
2841
+ }
2842
+ default: {
2843
+ const _exhaustiveCheck = contentBlockType;
2844
+ throw new Error(
2845
+ `Unsupported content block type: ${_exhaustiveCheck}`
2846
+ );
2816
2847
  }
2817
2848
  }
2818
- case "content_block_stop": {
2819
- if (contentBlocks[value.index] != null) {
2820
- const contentBlock = contentBlocks[value.index];
2821
- switch (contentBlock.type) {
2822
- case "text": {
2849
+ }
2850
+ case "content_block_stop": {
2851
+ if (contentBlocks[value.index] != null) {
2852
+ const contentBlock = contentBlocks[value.index];
2853
+ switch (contentBlock.type) {
2854
+ case "text": {
2855
+ controller.enqueue({
2856
+ type: "text-end",
2857
+ id: String(value.index)
2858
+ });
2859
+ break;
2860
+ }
2861
+ case "reasoning": {
2862
+ controller.enqueue({
2863
+ type: "reasoning-end",
2864
+ id: String(value.index)
2865
+ });
2866
+ break;
2867
+ }
2868
+ case "tool-call":
2869
+ const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
2870
+ if (!isJsonResponseTool) {
2823
2871
  controller.enqueue({
2824
- type: "text-end",
2825
- id: String(value.index)
2872
+ type: "tool-input-end",
2873
+ id: contentBlock.toolCallId
2826
2874
  });
2827
- break;
2828
- }
2829
- case "reasoning": {
2875
+ const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2830
2876
  controller.enqueue({
2831
- type: "reasoning-end",
2832
- id: String(value.index)
2877
+ type: "tool-call",
2878
+ toolCallId: contentBlock.toolCallId,
2879
+ toolName,
2880
+ input: contentBlock.input,
2881
+ providerExecuted: contentBlock.providerExecuted
2833
2882
  });
2834
- break;
2835
2883
  }
2836
- case "tool-call":
2837
- const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
2838
- if (!isJsonResponseTool) {
2839
- controller.enqueue({
2840
- type: "tool-input-end",
2841
- id: contentBlock.toolCallId
2842
- });
2843
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2844
- controller.enqueue({
2845
- type: "tool-call",
2846
- toolCallId: contentBlock.toolCallId,
2847
- toolName,
2848
- input: contentBlock.input,
2849
- providerExecuted: contentBlock.providerExecuted
2850
- });
2851
- }
2852
- break;
2853
- }
2854
- delete contentBlocks[value.index];
2884
+ break;
2855
2885
  }
2856
- blockType = void 0;
2857
- return;
2886
+ delete contentBlocks[value.index];
2858
2887
  }
2859
- case "content_block_delta": {
2860
- const deltaType = value.delta.type;
2861
- switch (deltaType) {
2862
- case "text_delta": {
2863
- if (usesJsonResponseTool) {
2864
- return;
2865
- }
2866
- controller.enqueue({
2867
- type: "text-delta",
2868
- id: String(value.index),
2869
- delta: value.delta.text
2870
- });
2888
+ blockType = void 0;
2889
+ return;
2890
+ }
2891
+ case "content_block_delta": {
2892
+ const deltaType = value.delta.type;
2893
+ switch (deltaType) {
2894
+ case "text_delta": {
2895
+ if (usesJsonResponseTool) {
2871
2896
  return;
2872
2897
  }
2873
- case "thinking_delta": {
2898
+ controller.enqueue({
2899
+ type: "text-delta",
2900
+ id: String(value.index),
2901
+ delta: value.delta.text
2902
+ });
2903
+ return;
2904
+ }
2905
+ case "thinking_delta": {
2906
+ controller.enqueue({
2907
+ type: "reasoning-delta",
2908
+ id: String(value.index),
2909
+ delta: value.delta.thinking
2910
+ });
2911
+ return;
2912
+ }
2913
+ case "signature_delta": {
2914
+ if (blockType === "thinking") {
2874
2915
  controller.enqueue({
2875
2916
  type: "reasoning-delta",
2876
2917
  id: String(value.index),
2877
- delta: value.delta.thinking
2918
+ delta: "",
2919
+ providerMetadata: {
2920
+ anthropic: {
2921
+ signature: value.delta.signature
2922
+ }
2923
+ }
2878
2924
  });
2879
- return;
2880
2925
  }
2881
- case "signature_delta": {
2882
- if (blockType === "thinking") {
2883
- controller.enqueue({
2884
- type: "reasoning-delta",
2885
- id: String(value.index),
2886
- delta: "",
2887
- providerMetadata: {
2888
- anthropic: {
2889
- signature: value.delta.signature
2890
- }
2891
- }
2892
- });
2893
- }
2926
+ return;
2927
+ }
2928
+ case "input_json_delta": {
2929
+ const contentBlock = contentBlocks[value.index];
2930
+ let delta = value.delta.partial_json;
2931
+ if (delta.length === 0) {
2894
2932
  return;
2895
2933
  }
2896
- case "input_json_delta": {
2897
- const contentBlock = contentBlocks[value.index];
2898
- let delta = value.delta.partial_json;
2899
- if (delta.length === 0) {
2934
+ if (isJsonResponseFromTool) {
2935
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
2900
2936
  return;
2901
2937
  }
2902
- if (isJsonResponseFromTool) {
2903
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
2904
- return;
2905
- }
2906
- controller.enqueue({
2907
- type: "text-delta",
2908
- id: String(value.index),
2909
- delta
2910
- });
2911
- } else {
2912
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2913
- return;
2914
- }
2915
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2916
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2917
- }
2918
- controller.enqueue({
2919
- type: "tool-input-delta",
2920
- id: contentBlock.toolCallId,
2921
- delta
2922
- });
2923
- contentBlock.input += delta;
2924
- contentBlock.firstDelta = false;
2938
+ controller.enqueue({
2939
+ type: "text-delta",
2940
+ id: String(value.index),
2941
+ delta
2942
+ });
2943
+ } else {
2944
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2945
+ return;
2925
2946
  }
2926
- return;
2927
- }
2928
- case "citations_delta": {
2929
- const citation = value.delta.citation;
2930
- const source = createCitationSource(
2931
- citation,
2932
- citationDocuments,
2933
- generateId3
2934
- );
2935
- if (source) {
2936
- controller.enqueue(source);
2947
+ if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2948
+ delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2937
2949
  }
2938
- return;
2950
+ controller.enqueue({
2951
+ type: "tool-input-delta",
2952
+ id: contentBlock.toolCallId,
2953
+ delta
2954
+ });
2955
+ contentBlock.input += delta;
2956
+ contentBlock.firstDelta = false;
2939
2957
  }
2940
- default: {
2941
- const _exhaustiveCheck = deltaType;
2942
- throw new Error(
2943
- `Unsupported delta type: ${_exhaustiveCheck}`
2944
- );
2958
+ return;
2959
+ }
2960
+ case "citations_delta": {
2961
+ const citation = value.delta.citation;
2962
+ const source = createCitationSource(
2963
+ citation,
2964
+ citationDocuments,
2965
+ generateId3
2966
+ );
2967
+ if (source) {
2968
+ controller.enqueue(source);
2945
2969
  }
2970
+ return;
2971
+ }
2972
+ default: {
2973
+ const _exhaustiveCheck = deltaType;
2974
+ throw new Error(
2975
+ `Unsupported delta type: ${_exhaustiveCheck}`
2976
+ );
2946
2977
  }
2947
2978
  }
2948
- case "message_start": {
2949
- usage.inputTokens = value.message.usage.input_tokens;
2950
- usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2951
- rawUsage = {
2952
- ...value.message.usage
2953
- };
2954
- cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
2955
- controller.enqueue({
2956
- type: "response-metadata",
2957
- id: (_d = value.message.id) != null ? _d : void 0,
2958
- modelId: (_e = value.message.model) != null ? _e : void 0
2959
- });
2960
- return;
2961
- }
2962
- case "message_delta": {
2963
- usage.outputTokens = value.usage.output_tokens;
2964
- usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
2965
- finishReason = mapAnthropicStopReason({
2966
- finishReason: value.delta.stop_reason,
2967
- isJsonResponseFromTool
2968
- });
2969
- stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
2970
- container = value.delta.container != null ? {
2971
- expiresAt: value.delta.container.expires_at,
2972
- id: value.delta.container.id,
2973
- skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
2974
- type: skill.type,
2975
- skillId: skill.skill_id,
2976
- version: skill.version
2977
- }))) != null ? _j : null
2978
- } : null;
2979
- rawUsage = {
2980
- ...rawUsage,
2981
- ...value.usage
2982
- };
2983
- return;
2984
- }
2985
- case "message_stop": {
2986
- controller.enqueue({
2987
- type: "finish",
2988
- finishReason,
2989
- usage,
2990
- providerMetadata: {
2991
- anthropic: {
2992
- usage: rawUsage != null ? rawUsage : null,
2993
- cacheCreationInputTokens,
2994
- stopSequence,
2995
- container
2996
- }
2979
+ }
2980
+ case "message_start": {
2981
+ usage.inputTokens = value.message.usage.input_tokens;
2982
+ usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2983
+ rawUsage = {
2984
+ ...value.message.usage
2985
+ };
2986
+ cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
2987
+ controller.enqueue({
2988
+ type: "response-metadata",
2989
+ id: (_d = value.message.id) != null ? _d : void 0,
2990
+ modelId: (_e = value.message.model) != null ? _e : void 0
2991
+ });
2992
+ return;
2993
+ }
2994
+ case "message_delta": {
2995
+ usage.outputTokens = value.usage.output_tokens;
2996
+ usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
2997
+ finishReason = mapAnthropicStopReason({
2998
+ finishReason: value.delta.stop_reason,
2999
+ isJsonResponseFromTool
3000
+ });
3001
+ stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
3002
+ container = value.delta.container != null ? {
3003
+ expiresAt: value.delta.container.expires_at,
3004
+ id: value.delta.container.id,
3005
+ skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
3006
+ type: skill.type,
3007
+ skillId: skill.skill_id,
3008
+ version: skill.version
3009
+ }))) != null ? _j : null
3010
+ } : null;
3011
+ rawUsage = {
3012
+ ...rawUsage,
3013
+ ...value.usage
3014
+ };
3015
+ return;
3016
+ }
3017
+ case "message_stop": {
3018
+ controller.enqueue({
3019
+ type: "finish",
3020
+ finishReason,
3021
+ usage,
3022
+ providerMetadata: {
3023
+ anthropic: {
3024
+ usage: rawUsage != null ? rawUsage : null,
3025
+ cacheCreationInputTokens,
3026
+ stopSequence,
3027
+ container
2997
3028
  }
2998
- });
2999
- return;
3000
- }
3001
- case "error": {
3002
- controller.enqueue({ type: "error", error: value.error });
3003
- return;
3004
- }
3005
- default: {
3006
- const _exhaustiveCheck = value;
3007
- throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
3008
- }
3029
+ }
3030
+ });
3031
+ return;
3032
+ }
3033
+ case "error": {
3034
+ controller.enqueue({ type: "error", error: value.error });
3035
+ return;
3036
+ }
3037
+ default: {
3038
+ const _exhaustiveCheck = value;
3039
+ throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
3009
3040
  }
3010
3041
  }
3011
- })
3012
- ),
3013
- request: { body },
3014
- response: { headers: responseHeaders }
3015
- };
3042
+ }
3043
+ })
3044
+ );
3045
+ const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
3046
+ stream = streamForConsumer;
3047
+ const reader = streamForFirstChunk.getReader();
3048
+ (async () => {
3049
+ try {
3050
+ const { done } = await reader.read();
3051
+ if (!done) {
3052
+ await reader.cancel();
3053
+ }
3054
+ } catch (error) {
3055
+ try {
3056
+ await reader.cancel();
3057
+ } catch (e) {
3058
+ }
3059
+ } finally {
3060
+ reader.releaseLock();
3061
+ }
3062
+ })();
3063
+ return returnPromise.promise;
3016
3064
  }
3017
3065
  };
3018
3066
  function getModelCapabilities(modelId) {
@@ -3078,7 +3126,6 @@ var bash_20241022InputSchema = lazySchema8(
3078
3126
  );
3079
3127
  var bash_20241022 = createProviderDefinedToolFactory2({
3080
3128
  id: "anthropic.bash_20241022",
3081
- name: "bash",
3082
3129
  inputSchema: bash_20241022InputSchema
3083
3130
  });
3084
3131
 
@@ -3099,7 +3146,6 @@ var bash_20250124InputSchema = lazySchema9(
3099
3146
  );
3100
3147
  var bash_20250124 = createProviderDefinedToolFactory3({
3101
3148
  id: "anthropic.bash_20250124",
3102
- name: "bash",
3103
3149
  inputSchema: bash_20250124InputSchema
3104
3150
  });
3105
3151
 
@@ -3132,7 +3178,6 @@ var computer_20241022InputSchema = lazySchema10(
3132
3178
  );
3133
3179
  var computer_20241022 = createProviderDefinedToolFactory4({
3134
3180
  id: "anthropic.computer_20241022",
3135
- name: "computer",
3136
3181
  inputSchema: computer_20241022InputSchema
3137
3182
  });
3138
3183
 
@@ -3175,7 +3220,6 @@ var computer_20250124InputSchema = lazySchema11(
3175
3220
  );
3176
3221
  var computer_20250124 = createProviderDefinedToolFactory5({
3177
3222
  id: "anthropic.computer_20250124",
3178
- name: "computer",
3179
3223
  inputSchema: computer_20250124InputSchema
3180
3224
  });
3181
3225
 
@@ -3225,7 +3269,6 @@ var memory_20250818InputSchema = lazySchema12(
3225
3269
  );
3226
3270
  var memory_20250818 = createProviderDefinedToolFactory6({
3227
3271
  id: "anthropic.memory_20250818",
3228
- name: "memory",
3229
3272
  inputSchema: memory_20250818InputSchema
3230
3273
  });
3231
3274
 
@@ -3251,7 +3294,6 @@ var textEditor_20241022InputSchema = lazySchema13(
3251
3294
  );
3252
3295
  var textEditor_20241022 = createProviderDefinedToolFactory7({
3253
3296
  id: "anthropic.text_editor_20241022",
3254
- name: "str_replace_editor",
3255
3297
  inputSchema: textEditor_20241022InputSchema
3256
3298
  });
3257
3299
 
@@ -3277,7 +3319,6 @@ var textEditor_20250124InputSchema = lazySchema14(
3277
3319
  );
3278
3320
  var textEditor_20250124 = createProviderDefinedToolFactory8({
3279
3321
  id: "anthropic.text_editor_20250124",
3280
- name: "str_replace_editor",
3281
3322
  inputSchema: textEditor_20250124InputSchema
3282
3323
  });
3283
3324
 
@@ -3303,7 +3344,6 @@ var textEditor_20250429InputSchema = lazySchema15(
3303
3344
  );
3304
3345
  var textEditor_20250429 = createProviderDefinedToolFactory9({
3305
3346
  id: "anthropic.text_editor_20250429",
3306
- name: "str_replace_based_edit_tool",
3307
3347
  inputSchema: textEditor_20250429InputSchema
3308
3348
  });
3309
3349