@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.
@@ -733,7 +733,6 @@ var textEditor_20250728InputSchema = (0, import_provider_utils4.lazySchema)(
733
733
  );
734
734
  var factory = (0, import_provider_utils3.createProviderDefinedToolFactory)({
735
735
  id: "anthropic.text_editor_20250728",
736
- name: "str_replace_based_edit_tool",
737
736
  inputSchema: textEditor_20250728InputSchema
738
737
  });
739
738
  var textEditor_20250728 = (args = {}) => {
@@ -781,7 +780,6 @@ var webSearch_20250305InputSchema = (0, import_provider_utils5.lazySchema)(
781
780
  );
782
781
  var factory2 = (0, import_provider_utils5.createProviderDefinedToolFactoryWithOutputSchema)({
783
782
  id: "anthropic.web_search_20250305",
784
- name: "web_search",
785
783
  inputSchema: webSearch_20250305InputSchema,
786
784
  outputSchema: webSearch_20250305OutputSchema
787
785
  });
@@ -838,7 +836,6 @@ var webFetch_20250910InputSchema = (0, import_provider_utils6.lazySchema)(
838
836
  );
839
837
  var factory3 = (0, import_provider_utils6.createProviderDefinedToolFactoryWithOutputSchema)({
840
838
  id: "anthropic.web_fetch_20250910",
841
- name: "web_fetch",
842
839
  inputSchema: webFetch_20250910InputSchema,
843
840
  outputSchema: webFetch_20250910OutputSchema
844
841
  });
@@ -1117,7 +1114,6 @@ var codeExecution_20250522InputSchema = (0, import_provider_utils8.lazySchema)(
1117
1114
  );
1118
1115
  var factory4 = (0, import_provider_utils8.createProviderDefinedToolFactoryWithOutputSchema)({
1119
1116
  id: "anthropic.code_execution_20250522",
1120
- name: "code_execution",
1121
1117
  inputSchema: codeExecution_20250522InputSchema,
1122
1118
  outputSchema: codeExecution_20250522OutputSchema
1123
1119
  });
@@ -1206,7 +1202,6 @@ var codeExecution_20250825InputSchema = (0, import_provider_utils9.lazySchema)(
1206
1202
  );
1207
1203
  var factory5 = (0, import_provider_utils9.createProviderDefinedToolFactoryWithOutputSchema)({
1208
1204
  id: "anthropic.code_execution_20250825",
1209
- name: "code_execution",
1210
1205
  inputSchema: codeExecution_20250825InputSchema,
1211
1206
  outputSchema: codeExecution_20250825OutputSchema
1212
1207
  });
@@ -2494,8 +2489,9 @@ var AnthropicMessagesLanguageModel = class {
2494
2489
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2495
2490
  });
2496
2491
  const citationDocuments = this.extractCitationDocuments(options.prompt);
2492
+ const url = this.buildRequestUrl(true);
2497
2493
  const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
2498
- url: this.buildRequestUrl(true),
2494
+ url,
2499
2495
  headers: await this.getHeaders({ betas, headers: options.headers }),
2500
2496
  body: this.transformRequestBody(body),
2501
2497
  failedResponseHandler: anthropicFailedResponseHandler,
@@ -2520,473 +2516,523 @@ var AnthropicMessagesLanguageModel = class {
2520
2516
  let isJsonResponseFromTool = false;
2521
2517
  let blockType = void 0;
2522
2518
  const generateId2 = this.generateId;
2523
- return {
2524
- stream: response.pipeThrough(
2525
- new TransformStream({
2526
- start(controller) {
2527
- controller.enqueue({ type: "stream-start", warnings });
2528
- },
2529
- transform(chunk, controller) {
2530
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2531
- if (options.includeRawChunks) {
2532
- controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2519
+ let isFirstChunk = true;
2520
+ let stream = void 0;
2521
+ const returnPromise = new import_provider_utils11.DelayedPromise();
2522
+ const transformedStream = response.pipeThrough(
2523
+ new TransformStream({
2524
+ start(controller) {
2525
+ controller.enqueue({ type: "stream-start", warnings });
2526
+ },
2527
+ async flush() {
2528
+ if (returnPromise.isPending()) {
2529
+ returnPromise.resolve({
2530
+ stream,
2531
+ request: { body },
2532
+ response: { headers: responseHeaders }
2533
+ });
2534
+ }
2535
+ },
2536
+ transform(chunk, controller) {
2537
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2538
+ if (options.includeRawChunks) {
2539
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2540
+ }
2541
+ if (!chunk.success) {
2542
+ controller.enqueue({ type: "error", error: chunk.error });
2543
+ return;
2544
+ }
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;
2533
2560
  }
2534
- if (!chunk.success) {
2535
- controller.enqueue({ type: "error", error: chunk.error });
2561
+ isFirstChunk = false;
2562
+ returnPromise.resolve({
2563
+ stream,
2564
+ request: { body },
2565
+ response: { headers: responseHeaders }
2566
+ });
2567
+ }
2568
+ const value = chunk.value;
2569
+ switch (value.type) {
2570
+ case "ping": {
2536
2571
  return;
2537
2572
  }
2538
- const value = chunk.value;
2539
- switch (value.type) {
2540
- case "ping": {
2541
- return;
2542
- }
2543
- case "content_block_start": {
2544
- const part = value.content_block;
2545
- const contentBlockType = part.type;
2546
- blockType = contentBlockType;
2547
- switch (contentBlockType) {
2548
- case "text": {
2549
- if (usesJsonResponseTool) {
2550
- return;
2573
+ case "content_block_start": {
2574
+ const part = value.content_block;
2575
+ const contentBlockType = part.type;
2576
+ blockType = contentBlockType;
2577
+ switch (contentBlockType) {
2578
+ case "text": {
2579
+ if (usesJsonResponseTool) {
2580
+ return;
2581
+ }
2582
+ contentBlocks[value.index] = { type: "text" };
2583
+ controller.enqueue({
2584
+ type: "text-start",
2585
+ id: String(value.index)
2586
+ });
2587
+ return;
2588
+ }
2589
+ case "thinking": {
2590
+ contentBlocks[value.index] = { type: "reasoning" };
2591
+ controller.enqueue({
2592
+ type: "reasoning-start",
2593
+ id: String(value.index)
2594
+ });
2595
+ return;
2596
+ }
2597
+ case "redacted_thinking": {
2598
+ contentBlocks[value.index] = { type: "reasoning" };
2599
+ controller.enqueue({
2600
+ type: "reasoning-start",
2601
+ id: String(value.index),
2602
+ providerMetadata: {
2603
+ anthropic: {
2604
+ redactedData: part.data
2605
+ }
2551
2606
  }
2607
+ });
2608
+ return;
2609
+ }
2610
+ case "tool_use": {
2611
+ const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2612
+ if (isJsonResponseTool) {
2613
+ isJsonResponseFromTool = true;
2552
2614
  contentBlocks[value.index] = { type: "text" };
2553
2615
  controller.enqueue({
2554
2616
  type: "text-start",
2555
2617
  id: String(value.index)
2556
2618
  });
2557
- return;
2558
- }
2559
- case "thinking": {
2560
- contentBlocks[value.index] = { type: "reasoning" };
2619
+ } else {
2620
+ contentBlocks[value.index] = {
2621
+ type: "tool-call",
2622
+ toolCallId: part.id,
2623
+ toolName: part.name,
2624
+ input: "",
2625
+ firstDelta: true
2626
+ };
2561
2627
  controller.enqueue({
2562
- type: "reasoning-start",
2563
- id: String(value.index)
2628
+ type: "tool-input-start",
2629
+ id: part.id,
2630
+ toolName: part.name
2564
2631
  });
2565
- return;
2566
2632
  }
2567
- case "redacted_thinking": {
2568
- contentBlocks[value.index] = { type: "reasoning" };
2633
+ return;
2634
+ }
2635
+ case "server_tool_use": {
2636
+ if ([
2637
+ "web_fetch",
2638
+ "web_search",
2639
+ // code execution 20250825:
2640
+ "code_execution",
2641
+ // code execution 20250825 text editor:
2642
+ "text_editor_code_execution",
2643
+ // code execution 20250825 bash:
2644
+ "bash_code_execution"
2645
+ ].includes(part.name)) {
2646
+ contentBlocks[value.index] = {
2647
+ type: "tool-call",
2648
+ toolCallId: part.id,
2649
+ toolName: part.name,
2650
+ input: "",
2651
+ providerExecuted: true,
2652
+ firstDelta: true
2653
+ };
2654
+ const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2569
2655
  controller.enqueue({
2570
- type: "reasoning-start",
2571
- id: String(value.index),
2572
- providerMetadata: {
2573
- anthropic: {
2574
- redactedData: part.data
2575
- }
2576
- }
2656
+ type: "tool-input-start",
2657
+ id: part.id,
2658
+ toolName: mappedToolName,
2659
+ providerExecuted: true
2577
2660
  });
2578
- return;
2579
2661
  }
2580
- case "tool_use": {
2581
- const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2582
- if (isJsonResponseTool) {
2583
- isJsonResponseFromTool = true;
2584
- contentBlocks[value.index] = { type: "text" };
2585
- controller.enqueue({
2586
- type: "text-start",
2587
- id: String(value.index)
2588
- });
2589
- } else {
2590
- contentBlocks[value.index] = {
2591
- type: "tool-call",
2592
- toolCallId: part.id,
2593
- toolName: part.name,
2594
- input: "",
2595
- firstDelta: true
2596
- };
2597
- controller.enqueue({
2598
- type: "tool-input-start",
2599
- id: part.id,
2600
- toolName: part.name
2601
- });
2602
- }
2603
- return;
2604
- }
2605
- case "server_tool_use": {
2606
- if ([
2607
- "web_fetch",
2608
- "web_search",
2609
- // code execution 20250825:
2610
- "code_execution",
2611
- // code execution 20250825 text editor:
2612
- "text_editor_code_execution",
2613
- // code execution 20250825 bash:
2614
- "bash_code_execution"
2615
- ].includes(part.name)) {
2616
- contentBlocks[value.index] = {
2617
- type: "tool-call",
2618
- toolCallId: part.id,
2619
- toolName: part.name,
2620
- input: "",
2621
- providerExecuted: true,
2622
- firstDelta: true
2623
- };
2624
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2625
- controller.enqueue({
2626
- type: "tool-input-start",
2627
- id: part.id,
2628
- toolName: mappedToolName,
2629
- providerExecuted: true
2630
- });
2631
- }
2632
- return;
2633
- }
2634
- case "web_fetch_tool_result": {
2635
- if (part.content.type === "web_fetch_result") {
2636
- controller.enqueue({
2637
- type: "tool-result",
2638
- toolCallId: part.tool_use_id,
2639
- toolName: "web_fetch",
2640
- result: {
2641
- type: "web_fetch_result",
2642
- url: part.content.url,
2643
- retrievedAt: part.content.retrieved_at,
2644
- content: {
2645
- type: part.content.content.type,
2646
- title: part.content.content.title,
2647
- citations: part.content.content.citations,
2648
- source: {
2649
- type: part.content.content.source.type,
2650
- mediaType: part.content.content.source.media_type,
2651
- data: part.content.content.source.data
2652
- }
2662
+ return;
2663
+ }
2664
+ case "web_fetch_tool_result": {
2665
+ if (part.content.type === "web_fetch_result") {
2666
+ controller.enqueue({
2667
+ type: "tool-result",
2668
+ toolCallId: part.tool_use_id,
2669
+ toolName: "web_fetch",
2670
+ result: {
2671
+ type: "web_fetch_result",
2672
+ url: part.content.url,
2673
+ retrievedAt: part.content.retrieved_at,
2674
+ content: {
2675
+ type: part.content.content.type,
2676
+ title: part.content.content.title,
2677
+ citations: part.content.content.citations,
2678
+ source: {
2679
+ type: part.content.content.source.type,
2680
+ mediaType: part.content.content.source.media_type,
2681
+ data: part.content.content.source.data
2653
2682
  }
2654
2683
  }
2655
- });
2656
- } else if (part.content.type === "web_fetch_tool_result_error") {
2657
- controller.enqueue({
2658
- type: "tool-result",
2659
- toolCallId: part.tool_use_id,
2660
- toolName: "web_fetch",
2661
- isError: true,
2662
- result: {
2663
- type: "web_fetch_tool_result_error",
2664
- errorCode: part.content.error_code
2665
- }
2666
- });
2667
- }
2668
- return;
2684
+ }
2685
+ });
2686
+ } else if (part.content.type === "web_fetch_tool_result_error") {
2687
+ controller.enqueue({
2688
+ type: "tool-result",
2689
+ toolCallId: part.tool_use_id,
2690
+ toolName: "web_fetch",
2691
+ isError: true,
2692
+ result: {
2693
+ type: "web_fetch_tool_result_error",
2694
+ errorCode: part.content.error_code
2695
+ }
2696
+ });
2669
2697
  }
2670
- case "web_search_tool_result": {
2671
- if (Array.isArray(part.content)) {
2672
- controller.enqueue({
2673
- type: "tool-result",
2674
- toolCallId: part.tool_use_id,
2675
- toolName: "web_search",
2676
- result: part.content.map((result) => {
2677
- var _a2;
2678
- return {
2679
- url: result.url,
2680
- title: result.title,
2681
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2682
- encryptedContent: result.encrypted_content,
2683
- type: result.type
2684
- };
2685
- })
2686
- });
2687
- for (const result of part.content) {
2688
- controller.enqueue({
2689
- type: "source",
2690
- sourceType: "url",
2691
- id: generateId2(),
2698
+ return;
2699
+ }
2700
+ case "web_search_tool_result": {
2701
+ if (Array.isArray(part.content)) {
2702
+ controller.enqueue({
2703
+ type: "tool-result",
2704
+ toolCallId: part.tool_use_id,
2705
+ toolName: "web_search",
2706
+ result: part.content.map((result) => {
2707
+ var _a2;
2708
+ return {
2692
2709
  url: result.url,
2693
2710
  title: result.title,
2694
- providerMetadata: {
2695
- anthropic: {
2696
- pageAge: (_a = result.page_age) != null ? _a : null
2697
- }
2698
- }
2699
- });
2700
- }
2701
- } else {
2702
- controller.enqueue({
2703
- type: "tool-result",
2704
- toolCallId: part.tool_use_id,
2705
- toolName: "web_search",
2706
- isError: true,
2707
- result: {
2708
- type: "web_search_tool_result_error",
2709
- errorCode: part.content.error_code
2710
- }
2711
- });
2712
- }
2713
- return;
2714
- }
2715
- // code execution 20250522:
2716
- case "code_execution_tool_result": {
2717
- if (part.content.type === "code_execution_result") {
2718
- controller.enqueue({
2719
- type: "tool-result",
2720
- toolCallId: part.tool_use_id,
2721
- toolName: "code_execution",
2722
- result: {
2723
- type: part.content.type,
2724
- stdout: part.content.stdout,
2725
- stderr: part.content.stderr,
2726
- return_code: part.content.return_code
2727
- }
2728
- });
2729
- } else if (part.content.type === "code_execution_tool_result_error") {
2711
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2712
+ encryptedContent: result.encrypted_content,
2713
+ type: result.type
2714
+ };
2715
+ })
2716
+ });
2717
+ for (const result of part.content) {
2730
2718
  controller.enqueue({
2731
- type: "tool-result",
2732
- toolCallId: part.tool_use_id,
2733
- toolName: "code_execution",
2734
- isError: true,
2735
- result: {
2736
- type: "code_execution_tool_result_error",
2737
- errorCode: part.content.error_code
2719
+ type: "source",
2720
+ sourceType: "url",
2721
+ id: generateId2(),
2722
+ url: result.url,
2723
+ title: result.title,
2724
+ providerMetadata: {
2725
+ anthropic: {
2726
+ pageAge: (_a = result.page_age) != null ? _a : null
2727
+ }
2738
2728
  }
2739
2729
  });
2740
2730
  }
2741
- return;
2742
- }
2743
- // code execution 20250825:
2744
- case "bash_code_execution_tool_result":
2745
- case "text_editor_code_execution_tool_result": {
2731
+ } else {
2746
2732
  controller.enqueue({
2747
2733
  type: "tool-result",
2748
2734
  toolCallId: part.tool_use_id,
2749
- toolName: "code_execution",
2750
- result: part.content
2735
+ toolName: "web_search",
2736
+ isError: true,
2737
+ result: {
2738
+ type: "web_search_tool_result_error",
2739
+ errorCode: part.content.error_code
2740
+ }
2751
2741
  });
2752
- return;
2753
2742
  }
2754
- case "mcp_tool_use": {
2755
- mcpToolCalls[part.id] = {
2756
- type: "tool-call",
2757
- toolCallId: part.id,
2758
- toolName: part.name,
2759
- input: JSON.stringify(part.input),
2760
- providerExecuted: true,
2761
- dynamic: true,
2762
- providerMetadata: {
2763
- anthropic: {
2764
- type: "mcp-tool-use",
2765
- serverName: part.server_name
2766
- }
2743
+ return;
2744
+ }
2745
+ // code execution 20250522:
2746
+ case "code_execution_tool_result": {
2747
+ if (part.content.type === "code_execution_result") {
2748
+ controller.enqueue({
2749
+ type: "tool-result",
2750
+ toolCallId: part.tool_use_id,
2751
+ toolName: "code_execution",
2752
+ result: {
2753
+ type: part.content.type,
2754
+ stdout: part.content.stdout,
2755
+ stderr: part.content.stderr,
2756
+ return_code: part.content.return_code
2767
2757
  }
2768
- };
2769
- controller.enqueue(mcpToolCalls[part.id]);
2770
- return;
2771
- }
2772
- case "mcp_tool_result": {
2758
+ });
2759
+ } else if (part.content.type === "code_execution_tool_result_error") {
2773
2760
  controller.enqueue({
2774
2761
  type: "tool-result",
2775
2762
  toolCallId: part.tool_use_id,
2776
- toolName: mcpToolCalls[part.tool_use_id].toolName,
2777
- isError: part.is_error,
2778
- result: part.content,
2779
- dynamic: true,
2780
- providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
2763
+ toolName: "code_execution",
2764
+ isError: true,
2765
+ result: {
2766
+ type: "code_execution_tool_result_error",
2767
+ errorCode: part.content.error_code
2768
+ }
2781
2769
  });
2782
- return;
2783
- }
2784
- default: {
2785
- const _exhaustiveCheck = contentBlockType;
2786
- throw new Error(
2787
- `Unsupported content block type: ${_exhaustiveCheck}`
2788
- );
2789
2770
  }
2771
+ return;
2772
+ }
2773
+ // code execution 20250825:
2774
+ case "bash_code_execution_tool_result":
2775
+ case "text_editor_code_execution_tool_result": {
2776
+ controller.enqueue({
2777
+ type: "tool-result",
2778
+ toolCallId: part.tool_use_id,
2779
+ toolName: "code_execution",
2780
+ result: part.content
2781
+ });
2782
+ return;
2783
+ }
2784
+ case "mcp_tool_use": {
2785
+ mcpToolCalls[part.id] = {
2786
+ type: "tool-call",
2787
+ toolCallId: part.id,
2788
+ toolName: part.name,
2789
+ input: JSON.stringify(part.input),
2790
+ providerExecuted: true,
2791
+ dynamic: true,
2792
+ providerMetadata: {
2793
+ anthropic: {
2794
+ type: "mcp-tool-use",
2795
+ serverName: part.server_name
2796
+ }
2797
+ }
2798
+ };
2799
+ controller.enqueue(mcpToolCalls[part.id]);
2800
+ return;
2801
+ }
2802
+ case "mcp_tool_result": {
2803
+ controller.enqueue({
2804
+ type: "tool-result",
2805
+ toolCallId: part.tool_use_id,
2806
+ toolName: mcpToolCalls[part.tool_use_id].toolName,
2807
+ isError: part.is_error,
2808
+ result: part.content,
2809
+ dynamic: true,
2810
+ providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
2811
+ });
2812
+ return;
2813
+ }
2814
+ default: {
2815
+ const _exhaustiveCheck = contentBlockType;
2816
+ throw new Error(
2817
+ `Unsupported content block type: ${_exhaustiveCheck}`
2818
+ );
2790
2819
  }
2791
2820
  }
2792
- case "content_block_stop": {
2793
- if (contentBlocks[value.index] != null) {
2794
- const contentBlock = contentBlocks[value.index];
2795
- switch (contentBlock.type) {
2796
- case "text": {
2821
+ }
2822
+ case "content_block_stop": {
2823
+ if (contentBlocks[value.index] != null) {
2824
+ const contentBlock = contentBlocks[value.index];
2825
+ switch (contentBlock.type) {
2826
+ case "text": {
2827
+ controller.enqueue({
2828
+ type: "text-end",
2829
+ id: String(value.index)
2830
+ });
2831
+ break;
2832
+ }
2833
+ case "reasoning": {
2834
+ controller.enqueue({
2835
+ type: "reasoning-end",
2836
+ id: String(value.index)
2837
+ });
2838
+ break;
2839
+ }
2840
+ case "tool-call":
2841
+ const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
2842
+ if (!isJsonResponseTool) {
2797
2843
  controller.enqueue({
2798
- type: "text-end",
2799
- id: String(value.index)
2844
+ type: "tool-input-end",
2845
+ id: contentBlock.toolCallId
2800
2846
  });
2801
- break;
2802
- }
2803
- case "reasoning": {
2847
+ const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2804
2848
  controller.enqueue({
2805
- type: "reasoning-end",
2806
- id: String(value.index)
2849
+ type: "tool-call",
2850
+ toolCallId: contentBlock.toolCallId,
2851
+ toolName,
2852
+ input: contentBlock.input,
2853
+ providerExecuted: contentBlock.providerExecuted
2807
2854
  });
2808
- break;
2809
2855
  }
2810
- case "tool-call":
2811
- const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
2812
- if (!isJsonResponseTool) {
2813
- controller.enqueue({
2814
- type: "tool-input-end",
2815
- id: contentBlock.toolCallId
2816
- });
2817
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2818
- controller.enqueue({
2819
- type: "tool-call",
2820
- toolCallId: contentBlock.toolCallId,
2821
- toolName,
2822
- input: contentBlock.input,
2823
- providerExecuted: contentBlock.providerExecuted
2824
- });
2825
- }
2826
- break;
2827
- }
2828
- delete contentBlocks[value.index];
2856
+ break;
2829
2857
  }
2830
- blockType = void 0;
2831
- return;
2858
+ delete contentBlocks[value.index];
2832
2859
  }
2833
- case "content_block_delta": {
2834
- const deltaType = value.delta.type;
2835
- switch (deltaType) {
2836
- case "text_delta": {
2837
- if (usesJsonResponseTool) {
2838
- return;
2839
- }
2840
- controller.enqueue({
2841
- type: "text-delta",
2842
- id: String(value.index),
2843
- delta: value.delta.text
2844
- });
2860
+ blockType = void 0;
2861
+ return;
2862
+ }
2863
+ case "content_block_delta": {
2864
+ const deltaType = value.delta.type;
2865
+ switch (deltaType) {
2866
+ case "text_delta": {
2867
+ if (usesJsonResponseTool) {
2845
2868
  return;
2846
2869
  }
2847
- case "thinking_delta": {
2870
+ controller.enqueue({
2871
+ type: "text-delta",
2872
+ id: String(value.index),
2873
+ delta: value.delta.text
2874
+ });
2875
+ return;
2876
+ }
2877
+ case "thinking_delta": {
2878
+ controller.enqueue({
2879
+ type: "reasoning-delta",
2880
+ id: String(value.index),
2881
+ delta: value.delta.thinking
2882
+ });
2883
+ return;
2884
+ }
2885
+ case "signature_delta": {
2886
+ if (blockType === "thinking") {
2848
2887
  controller.enqueue({
2849
2888
  type: "reasoning-delta",
2850
2889
  id: String(value.index),
2851
- delta: value.delta.thinking
2890
+ delta: "",
2891
+ providerMetadata: {
2892
+ anthropic: {
2893
+ signature: value.delta.signature
2894
+ }
2895
+ }
2852
2896
  });
2853
- return;
2854
2897
  }
2855
- case "signature_delta": {
2856
- if (blockType === "thinking") {
2857
- controller.enqueue({
2858
- type: "reasoning-delta",
2859
- id: String(value.index),
2860
- delta: "",
2861
- providerMetadata: {
2862
- anthropic: {
2863
- signature: value.delta.signature
2864
- }
2865
- }
2866
- });
2867
- }
2898
+ return;
2899
+ }
2900
+ case "input_json_delta": {
2901
+ const contentBlock = contentBlocks[value.index];
2902
+ let delta = value.delta.partial_json;
2903
+ if (delta.length === 0) {
2868
2904
  return;
2869
2905
  }
2870
- case "input_json_delta": {
2871
- const contentBlock = contentBlocks[value.index];
2872
- let delta = value.delta.partial_json;
2873
- if (delta.length === 0) {
2906
+ if (isJsonResponseFromTool) {
2907
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
2874
2908
  return;
2875
2909
  }
2876
- if (isJsonResponseFromTool) {
2877
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
2878
- return;
2879
- }
2880
- controller.enqueue({
2881
- type: "text-delta",
2882
- id: String(value.index),
2883
- delta
2884
- });
2885
- } else {
2886
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2887
- return;
2888
- }
2889
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2890
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2891
- }
2892
- controller.enqueue({
2893
- type: "tool-input-delta",
2894
- id: contentBlock.toolCallId,
2895
- delta
2896
- });
2897
- contentBlock.input += delta;
2898
- contentBlock.firstDelta = false;
2910
+ controller.enqueue({
2911
+ type: "text-delta",
2912
+ id: String(value.index),
2913
+ delta
2914
+ });
2915
+ } else {
2916
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2917
+ return;
2899
2918
  }
2900
- return;
2901
- }
2902
- case "citations_delta": {
2903
- const citation = value.delta.citation;
2904
- const source = createCitationSource(
2905
- citation,
2906
- citationDocuments,
2907
- generateId2
2908
- );
2909
- if (source) {
2910
- controller.enqueue(source);
2919
+ if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2920
+ delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2911
2921
  }
2912
- return;
2922
+ controller.enqueue({
2923
+ type: "tool-input-delta",
2924
+ id: contentBlock.toolCallId,
2925
+ delta
2926
+ });
2927
+ contentBlock.input += delta;
2928
+ contentBlock.firstDelta = false;
2913
2929
  }
2914
- default: {
2915
- const _exhaustiveCheck = deltaType;
2916
- throw new Error(
2917
- `Unsupported delta type: ${_exhaustiveCheck}`
2918
- );
2930
+ return;
2931
+ }
2932
+ case "citations_delta": {
2933
+ const citation = value.delta.citation;
2934
+ const source = createCitationSource(
2935
+ citation,
2936
+ citationDocuments,
2937
+ generateId2
2938
+ );
2939
+ if (source) {
2940
+ controller.enqueue(source);
2919
2941
  }
2942
+ return;
2943
+ }
2944
+ default: {
2945
+ const _exhaustiveCheck = deltaType;
2946
+ throw new Error(
2947
+ `Unsupported delta type: ${_exhaustiveCheck}`
2948
+ );
2920
2949
  }
2921
2950
  }
2922
- case "message_start": {
2923
- usage.inputTokens = value.message.usage.input_tokens;
2924
- usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2925
- rawUsage = {
2926
- ...value.message.usage
2927
- };
2928
- cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
2929
- controller.enqueue({
2930
- type: "response-metadata",
2931
- id: (_d = value.message.id) != null ? _d : void 0,
2932
- modelId: (_e = value.message.model) != null ? _e : void 0
2933
- });
2934
- return;
2935
- }
2936
- case "message_delta": {
2937
- usage.outputTokens = value.usage.output_tokens;
2938
- usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
2939
- finishReason = mapAnthropicStopReason({
2940
- finishReason: value.delta.stop_reason,
2941
- isJsonResponseFromTool
2942
- });
2943
- stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
2944
- container = value.delta.container != null ? {
2945
- expiresAt: value.delta.container.expires_at,
2946
- id: value.delta.container.id,
2947
- skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
2948
- type: skill.type,
2949
- skillId: skill.skill_id,
2950
- version: skill.version
2951
- }))) != null ? _j : null
2952
- } : null;
2953
- rawUsage = {
2954
- ...rawUsage,
2955
- ...value.usage
2956
- };
2957
- return;
2958
- }
2959
- case "message_stop": {
2960
- controller.enqueue({
2961
- type: "finish",
2962
- finishReason,
2963
- usage,
2964
- providerMetadata: {
2965
- anthropic: {
2966
- usage: rawUsage != null ? rawUsage : null,
2967
- cacheCreationInputTokens,
2968
- stopSequence,
2969
- container
2970
- }
2951
+ }
2952
+ case "message_start": {
2953
+ usage.inputTokens = value.message.usage.input_tokens;
2954
+ usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2955
+ rawUsage = {
2956
+ ...value.message.usage
2957
+ };
2958
+ cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
2959
+ controller.enqueue({
2960
+ type: "response-metadata",
2961
+ id: (_d = value.message.id) != null ? _d : void 0,
2962
+ modelId: (_e = value.message.model) != null ? _e : void 0
2963
+ });
2964
+ return;
2965
+ }
2966
+ case "message_delta": {
2967
+ usage.outputTokens = value.usage.output_tokens;
2968
+ usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
2969
+ finishReason = mapAnthropicStopReason({
2970
+ finishReason: value.delta.stop_reason,
2971
+ isJsonResponseFromTool
2972
+ });
2973
+ stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
2974
+ container = value.delta.container != null ? {
2975
+ expiresAt: value.delta.container.expires_at,
2976
+ id: value.delta.container.id,
2977
+ skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
2978
+ type: skill.type,
2979
+ skillId: skill.skill_id,
2980
+ version: skill.version
2981
+ }))) != null ? _j : null
2982
+ } : null;
2983
+ rawUsage = {
2984
+ ...rawUsage,
2985
+ ...value.usage
2986
+ };
2987
+ return;
2988
+ }
2989
+ case "message_stop": {
2990
+ controller.enqueue({
2991
+ type: "finish",
2992
+ finishReason,
2993
+ usage,
2994
+ providerMetadata: {
2995
+ anthropic: {
2996
+ usage: rawUsage != null ? rawUsage : null,
2997
+ cacheCreationInputTokens,
2998
+ stopSequence,
2999
+ container
2971
3000
  }
2972
- });
2973
- return;
2974
- }
2975
- case "error": {
2976
- controller.enqueue({ type: "error", error: value.error });
2977
- return;
2978
- }
2979
- default: {
2980
- const _exhaustiveCheck = value;
2981
- throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
2982
- }
3001
+ }
3002
+ });
3003
+ return;
3004
+ }
3005
+ case "error": {
3006
+ controller.enqueue({ type: "error", error: value.error });
3007
+ return;
3008
+ }
3009
+ default: {
3010
+ const _exhaustiveCheck = value;
3011
+ throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
2983
3012
  }
2984
3013
  }
2985
- })
2986
- ),
2987
- request: { body },
2988
- response: { headers: responseHeaders }
2989
- };
3014
+ }
3015
+ })
3016
+ );
3017
+ const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
3018
+ stream = streamForConsumer;
3019
+ const reader = streamForFirstChunk.getReader();
3020
+ (async () => {
3021
+ try {
3022
+ const { done } = await reader.read();
3023
+ if (!done) {
3024
+ await reader.cancel();
3025
+ }
3026
+ } catch (error) {
3027
+ try {
3028
+ await reader.cancel();
3029
+ } catch (e) {
3030
+ }
3031
+ } finally {
3032
+ reader.releaseLock();
3033
+ }
3034
+ })();
3035
+ return returnPromise.promise;
2990
3036
  }
2991
3037
  };
2992
3038
  function getModelCapabilities(modelId) {
@@ -3048,7 +3094,6 @@ var bash_20241022InputSchema = (0, import_provider_utils12.lazySchema)(
3048
3094
  );
3049
3095
  var bash_20241022 = (0, import_provider_utils12.createProviderDefinedToolFactory)({
3050
3096
  id: "anthropic.bash_20241022",
3051
- name: "bash",
3052
3097
  inputSchema: bash_20241022InputSchema
3053
3098
  });
3054
3099
 
@@ -3065,7 +3110,6 @@ var bash_20250124InputSchema = (0, import_provider_utils13.lazySchema)(
3065
3110
  );
3066
3111
  var bash_20250124 = (0, import_provider_utils13.createProviderDefinedToolFactory)({
3067
3112
  id: "anthropic.bash_20250124",
3068
- name: "bash",
3069
3113
  inputSchema: bash_20250124InputSchema
3070
3114
  });
3071
3115
 
@@ -3094,7 +3138,6 @@ var computer_20241022InputSchema = (0, import_provider_utils14.lazySchema)(
3094
3138
  );
3095
3139
  var computer_20241022 = (0, import_provider_utils14.createProviderDefinedToolFactory)({
3096
3140
  id: "anthropic.computer_20241022",
3097
- name: "computer",
3098
3141
  inputSchema: computer_20241022InputSchema
3099
3142
  });
3100
3143
 
@@ -3133,7 +3176,6 @@ var computer_20250124InputSchema = (0, import_provider_utils15.lazySchema)(
3133
3176
  );
3134
3177
  var computer_20250124 = (0, import_provider_utils15.createProviderDefinedToolFactory)({
3135
3178
  id: "anthropic.computer_20250124",
3136
- name: "computer",
3137
3179
  inputSchema: computer_20250124InputSchema
3138
3180
  });
3139
3181
 
@@ -3179,7 +3221,6 @@ var memory_20250818InputSchema = (0, import_provider_utils16.lazySchema)(
3179
3221
  );
3180
3222
  var memory_20250818 = (0, import_provider_utils16.createProviderDefinedToolFactory)({
3181
3223
  id: "anthropic.memory_20250818",
3182
- name: "memory",
3183
3224
  inputSchema: memory_20250818InputSchema
3184
3225
  });
3185
3226
 
@@ -3201,7 +3242,6 @@ var textEditor_20241022InputSchema = (0, import_provider_utils17.lazySchema)(
3201
3242
  );
3202
3243
  var textEditor_20241022 = (0, import_provider_utils17.createProviderDefinedToolFactory)({
3203
3244
  id: "anthropic.text_editor_20241022",
3204
- name: "str_replace_editor",
3205
3245
  inputSchema: textEditor_20241022InputSchema
3206
3246
  });
3207
3247
 
@@ -3223,7 +3263,6 @@ var textEditor_20250124InputSchema = (0, import_provider_utils18.lazySchema)(
3223
3263
  );
3224
3264
  var textEditor_20250124 = (0, import_provider_utils18.createProviderDefinedToolFactory)({
3225
3265
  id: "anthropic.text_editor_20250124",
3226
- name: "str_replace_editor",
3227
3266
  inputSchema: textEditor_20250124InputSchema
3228
3267
  });
3229
3268
 
@@ -3245,7 +3284,6 @@ var textEditor_20250429InputSchema = (0, import_provider_utils19.lazySchema)(
3245
3284
  );
3246
3285
  var textEditor_20250429 = (0, import_provider_utils19.createProviderDefinedToolFactory)({
3247
3286
  id: "anthropic.text_editor_20250429",
3248
- name: "str_replace_based_edit_tool",
3249
3287
  inputSchema: textEditor_20250429InputSchema
3250
3288
  });
3251
3289