@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.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.63" : "0.0.0-test";
34
+ var VERSION = true ? "3.0.0-beta.65" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -740,7 +740,6 @@ var textEditor_20250728InputSchema = (0, import_provider_utils4.lazySchema)(
740
740
  );
741
741
  var factory = (0, import_provider_utils3.createProviderDefinedToolFactory)({
742
742
  id: "anthropic.text_editor_20250728",
743
- name: "str_replace_based_edit_tool",
744
743
  inputSchema: textEditor_20250728InputSchema
745
744
  });
746
745
  var textEditor_20250728 = (args = {}) => {
@@ -788,7 +787,6 @@ var webSearch_20250305InputSchema = (0, import_provider_utils5.lazySchema)(
788
787
  );
789
788
  var factory2 = (0, import_provider_utils5.createProviderDefinedToolFactoryWithOutputSchema)({
790
789
  id: "anthropic.web_search_20250305",
791
- name: "web_search",
792
790
  inputSchema: webSearch_20250305InputSchema,
793
791
  outputSchema: webSearch_20250305OutputSchema
794
792
  });
@@ -845,7 +843,6 @@ var webFetch_20250910InputSchema = (0, import_provider_utils6.lazySchema)(
845
843
  );
846
844
  var factory3 = (0, import_provider_utils6.createProviderDefinedToolFactoryWithOutputSchema)({
847
845
  id: "anthropic.web_fetch_20250910",
848
- name: "web_fetch",
849
846
  inputSchema: webFetch_20250910InputSchema,
850
847
  outputSchema: webFetch_20250910OutputSchema
851
848
  });
@@ -1124,7 +1121,6 @@ var codeExecution_20250522InputSchema = (0, import_provider_utils8.lazySchema)(
1124
1121
  );
1125
1122
  var factory4 = (0, import_provider_utils8.createProviderDefinedToolFactoryWithOutputSchema)({
1126
1123
  id: "anthropic.code_execution_20250522",
1127
- name: "code_execution",
1128
1124
  inputSchema: codeExecution_20250522InputSchema,
1129
1125
  outputSchema: codeExecution_20250522OutputSchema
1130
1126
  });
@@ -1213,7 +1209,6 @@ var codeExecution_20250825InputSchema = (0, import_provider_utils9.lazySchema)(
1213
1209
  );
1214
1210
  var factory5 = (0, import_provider_utils9.createProviderDefinedToolFactoryWithOutputSchema)({
1215
1211
  id: "anthropic.code_execution_20250825",
1216
- name: "code_execution",
1217
1212
  inputSchema: codeExecution_20250825InputSchema,
1218
1213
  outputSchema: codeExecution_20250825OutputSchema
1219
1214
  });
@@ -2501,8 +2496,9 @@ var AnthropicMessagesLanguageModel = class {
2501
2496
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2502
2497
  });
2503
2498
  const citationDocuments = this.extractCitationDocuments(options.prompt);
2499
+ const url = this.buildRequestUrl(true);
2504
2500
  const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
2505
- url: this.buildRequestUrl(true),
2501
+ url,
2506
2502
  headers: await this.getHeaders({ betas, headers: options.headers }),
2507
2503
  body: this.transformRequestBody(body),
2508
2504
  failedResponseHandler: anthropicFailedResponseHandler,
@@ -2527,473 +2523,523 @@ var AnthropicMessagesLanguageModel = class {
2527
2523
  let isJsonResponseFromTool = false;
2528
2524
  let blockType = void 0;
2529
2525
  const generateId3 = this.generateId;
2530
- return {
2531
- stream: response.pipeThrough(
2532
- new TransformStream({
2533
- start(controller) {
2534
- controller.enqueue({ type: "stream-start", warnings });
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 });
2526
+ let isFirstChunk = true;
2527
+ let stream = void 0;
2528
+ const returnPromise = new import_provider_utils11.DelayedPromise();
2529
+ const transformedStream = response.pipeThrough(
2530
+ new TransformStream({
2531
+ start(controller) {
2532
+ controller.enqueue({ type: "stream-start", warnings });
2533
+ },
2534
+ async flush() {
2535
+ if (returnPromise.isPending()) {
2536
+ returnPromise.resolve({
2537
+ stream,
2538
+ request: { body },
2539
+ response: { headers: responseHeaders }
2540
+ });
2541
+ }
2542
+ },
2543
+ transform(chunk, controller) {
2544
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2545
+ if (options.includeRawChunks) {
2546
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2547
+ }
2548
+ if (!chunk.success) {
2549
+ controller.enqueue({ type: "error", error: chunk.error });
2550
+ return;
2551
+ }
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;
2540
2567
  }
2541
- if (!chunk.success) {
2542
- controller.enqueue({ type: "error", error: chunk.error });
2568
+ isFirstChunk = false;
2569
+ returnPromise.resolve({
2570
+ stream,
2571
+ request: { body },
2572
+ response: { headers: responseHeaders }
2573
+ });
2574
+ }
2575
+ const value = chunk.value;
2576
+ switch (value.type) {
2577
+ case "ping": {
2543
2578
  return;
2544
2579
  }
2545
- const value = chunk.value;
2546
- switch (value.type) {
2547
- case "ping": {
2548
- return;
2549
- }
2550
- case "content_block_start": {
2551
- const part = value.content_block;
2552
- const contentBlockType = part.type;
2553
- blockType = contentBlockType;
2554
- switch (contentBlockType) {
2555
- case "text": {
2556
- if (usesJsonResponseTool) {
2557
- return;
2580
+ case "content_block_start": {
2581
+ const part = value.content_block;
2582
+ const contentBlockType = part.type;
2583
+ blockType = contentBlockType;
2584
+ switch (contentBlockType) {
2585
+ case "text": {
2586
+ if (usesJsonResponseTool) {
2587
+ return;
2588
+ }
2589
+ contentBlocks[value.index] = { type: "text" };
2590
+ controller.enqueue({
2591
+ type: "text-start",
2592
+ id: String(value.index)
2593
+ });
2594
+ return;
2595
+ }
2596
+ case "thinking": {
2597
+ contentBlocks[value.index] = { type: "reasoning" };
2598
+ controller.enqueue({
2599
+ type: "reasoning-start",
2600
+ id: String(value.index)
2601
+ });
2602
+ return;
2603
+ }
2604
+ case "redacted_thinking": {
2605
+ contentBlocks[value.index] = { type: "reasoning" };
2606
+ controller.enqueue({
2607
+ type: "reasoning-start",
2608
+ id: String(value.index),
2609
+ providerMetadata: {
2610
+ anthropic: {
2611
+ redactedData: part.data
2612
+ }
2558
2613
  }
2614
+ });
2615
+ return;
2616
+ }
2617
+ case "tool_use": {
2618
+ const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2619
+ if (isJsonResponseTool) {
2620
+ isJsonResponseFromTool = true;
2559
2621
  contentBlocks[value.index] = { type: "text" };
2560
2622
  controller.enqueue({
2561
2623
  type: "text-start",
2562
2624
  id: String(value.index)
2563
2625
  });
2564
- return;
2565
- }
2566
- case "thinking": {
2567
- contentBlocks[value.index] = { type: "reasoning" };
2626
+ } else {
2627
+ contentBlocks[value.index] = {
2628
+ type: "tool-call",
2629
+ toolCallId: part.id,
2630
+ toolName: part.name,
2631
+ input: "",
2632
+ firstDelta: true
2633
+ };
2568
2634
  controller.enqueue({
2569
- type: "reasoning-start",
2570
- id: String(value.index)
2635
+ type: "tool-input-start",
2636
+ id: part.id,
2637
+ toolName: part.name
2571
2638
  });
2572
- return;
2573
2639
  }
2574
- case "redacted_thinking": {
2575
- contentBlocks[value.index] = { type: "reasoning" };
2640
+ return;
2641
+ }
2642
+ case "server_tool_use": {
2643
+ if ([
2644
+ "web_fetch",
2645
+ "web_search",
2646
+ // code execution 20250825:
2647
+ "code_execution",
2648
+ // code execution 20250825 text editor:
2649
+ "text_editor_code_execution",
2650
+ // code execution 20250825 bash:
2651
+ "bash_code_execution"
2652
+ ].includes(part.name)) {
2653
+ contentBlocks[value.index] = {
2654
+ type: "tool-call",
2655
+ toolCallId: part.id,
2656
+ toolName: part.name,
2657
+ input: "",
2658
+ providerExecuted: true,
2659
+ firstDelta: true
2660
+ };
2661
+ const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2576
2662
  controller.enqueue({
2577
- type: "reasoning-start",
2578
- id: String(value.index),
2579
- providerMetadata: {
2580
- anthropic: {
2581
- redactedData: part.data
2582
- }
2583
- }
2663
+ type: "tool-input-start",
2664
+ id: part.id,
2665
+ toolName: mappedToolName,
2666
+ providerExecuted: true
2584
2667
  });
2585
- return;
2586
2668
  }
2587
- case "tool_use": {
2588
- const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2589
- if (isJsonResponseTool) {
2590
- isJsonResponseFromTool = true;
2591
- contentBlocks[value.index] = { type: "text" };
2592
- controller.enqueue({
2593
- type: "text-start",
2594
- id: String(value.index)
2595
- });
2596
- } else {
2597
- contentBlocks[value.index] = {
2598
- type: "tool-call",
2599
- toolCallId: part.id,
2600
- toolName: part.name,
2601
- input: "",
2602
- firstDelta: true
2603
- };
2604
- controller.enqueue({
2605
- type: "tool-input-start",
2606
- id: part.id,
2607
- toolName: part.name
2608
- });
2609
- }
2610
- return;
2611
- }
2612
- case "server_tool_use": {
2613
- if ([
2614
- "web_fetch",
2615
- "web_search",
2616
- // code execution 20250825:
2617
- "code_execution",
2618
- // code execution 20250825 text editor:
2619
- "text_editor_code_execution",
2620
- // code execution 20250825 bash:
2621
- "bash_code_execution"
2622
- ].includes(part.name)) {
2623
- contentBlocks[value.index] = {
2624
- type: "tool-call",
2625
- toolCallId: part.id,
2626
- toolName: part.name,
2627
- input: "",
2628
- providerExecuted: true,
2629
- firstDelta: true
2630
- };
2631
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2632
- controller.enqueue({
2633
- type: "tool-input-start",
2634
- id: part.id,
2635
- toolName: mappedToolName,
2636
- providerExecuted: true
2637
- });
2638
- }
2639
- return;
2640
- }
2641
- case "web_fetch_tool_result": {
2642
- if (part.content.type === "web_fetch_result") {
2643
- controller.enqueue({
2644
- type: "tool-result",
2645
- toolCallId: part.tool_use_id,
2646
- toolName: "web_fetch",
2647
- result: {
2648
- type: "web_fetch_result",
2649
- url: part.content.url,
2650
- retrievedAt: part.content.retrieved_at,
2651
- content: {
2652
- type: part.content.content.type,
2653
- title: part.content.content.title,
2654
- citations: part.content.content.citations,
2655
- source: {
2656
- type: part.content.content.source.type,
2657
- mediaType: part.content.content.source.media_type,
2658
- data: part.content.content.source.data
2659
- }
2669
+ return;
2670
+ }
2671
+ case "web_fetch_tool_result": {
2672
+ if (part.content.type === "web_fetch_result") {
2673
+ controller.enqueue({
2674
+ type: "tool-result",
2675
+ toolCallId: part.tool_use_id,
2676
+ toolName: "web_fetch",
2677
+ result: {
2678
+ type: "web_fetch_result",
2679
+ url: part.content.url,
2680
+ retrievedAt: part.content.retrieved_at,
2681
+ content: {
2682
+ type: part.content.content.type,
2683
+ title: part.content.content.title,
2684
+ citations: part.content.content.citations,
2685
+ source: {
2686
+ type: part.content.content.source.type,
2687
+ mediaType: part.content.content.source.media_type,
2688
+ data: part.content.content.source.data
2660
2689
  }
2661
2690
  }
2662
- });
2663
- } else if (part.content.type === "web_fetch_tool_result_error") {
2664
- controller.enqueue({
2665
- type: "tool-result",
2666
- toolCallId: part.tool_use_id,
2667
- toolName: "web_fetch",
2668
- isError: true,
2669
- result: {
2670
- type: "web_fetch_tool_result_error",
2671
- errorCode: part.content.error_code
2672
- }
2673
- });
2674
- }
2675
- return;
2691
+ }
2692
+ });
2693
+ } else if (part.content.type === "web_fetch_tool_result_error") {
2694
+ controller.enqueue({
2695
+ type: "tool-result",
2696
+ toolCallId: part.tool_use_id,
2697
+ toolName: "web_fetch",
2698
+ isError: true,
2699
+ result: {
2700
+ type: "web_fetch_tool_result_error",
2701
+ errorCode: part.content.error_code
2702
+ }
2703
+ });
2676
2704
  }
2677
- case "web_search_tool_result": {
2678
- if (Array.isArray(part.content)) {
2679
- controller.enqueue({
2680
- type: "tool-result",
2681
- toolCallId: part.tool_use_id,
2682
- toolName: "web_search",
2683
- result: part.content.map((result) => {
2684
- var _a2;
2685
- return {
2686
- url: result.url,
2687
- title: result.title,
2688
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2689
- encryptedContent: result.encrypted_content,
2690
- type: result.type
2691
- };
2692
- })
2693
- });
2694
- for (const result of part.content) {
2695
- controller.enqueue({
2696
- type: "source",
2697
- sourceType: "url",
2698
- id: generateId3(),
2705
+ return;
2706
+ }
2707
+ case "web_search_tool_result": {
2708
+ if (Array.isArray(part.content)) {
2709
+ controller.enqueue({
2710
+ type: "tool-result",
2711
+ toolCallId: part.tool_use_id,
2712
+ toolName: "web_search",
2713
+ result: part.content.map((result) => {
2714
+ var _a2;
2715
+ return {
2699
2716
  url: result.url,
2700
2717
  title: result.title,
2701
- providerMetadata: {
2702
- anthropic: {
2703
- pageAge: (_a = result.page_age) != null ? _a : null
2704
- }
2705
- }
2706
- });
2707
- }
2708
- } else {
2709
- controller.enqueue({
2710
- type: "tool-result",
2711
- toolCallId: part.tool_use_id,
2712
- toolName: "web_search",
2713
- isError: true,
2714
- result: {
2715
- type: "web_search_tool_result_error",
2716
- errorCode: part.content.error_code
2717
- }
2718
- });
2719
- }
2720
- return;
2721
- }
2722
- // code execution 20250522:
2723
- case "code_execution_tool_result": {
2724
- if (part.content.type === "code_execution_result") {
2725
- controller.enqueue({
2726
- type: "tool-result",
2727
- toolCallId: part.tool_use_id,
2728
- toolName: "code_execution",
2729
- result: {
2730
- type: part.content.type,
2731
- stdout: part.content.stdout,
2732
- stderr: part.content.stderr,
2733
- return_code: part.content.return_code
2734
- }
2735
- });
2736
- } else if (part.content.type === "code_execution_tool_result_error") {
2718
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2719
+ encryptedContent: result.encrypted_content,
2720
+ type: result.type
2721
+ };
2722
+ })
2723
+ });
2724
+ for (const result of part.content) {
2737
2725
  controller.enqueue({
2738
- type: "tool-result",
2739
- toolCallId: part.tool_use_id,
2740
- toolName: "code_execution",
2741
- isError: true,
2742
- result: {
2743
- type: "code_execution_tool_result_error",
2744
- errorCode: part.content.error_code
2726
+ type: "source",
2727
+ sourceType: "url",
2728
+ id: generateId3(),
2729
+ url: result.url,
2730
+ title: result.title,
2731
+ providerMetadata: {
2732
+ anthropic: {
2733
+ pageAge: (_a = result.page_age) != null ? _a : null
2734
+ }
2745
2735
  }
2746
2736
  });
2747
2737
  }
2748
- return;
2749
- }
2750
- // code execution 20250825:
2751
- case "bash_code_execution_tool_result":
2752
- case "text_editor_code_execution_tool_result": {
2738
+ } else {
2753
2739
  controller.enqueue({
2754
2740
  type: "tool-result",
2755
2741
  toolCallId: part.tool_use_id,
2756
- toolName: "code_execution",
2757
- result: part.content
2742
+ toolName: "web_search",
2743
+ isError: true,
2744
+ result: {
2745
+ type: "web_search_tool_result_error",
2746
+ errorCode: part.content.error_code
2747
+ }
2758
2748
  });
2759
- return;
2760
2749
  }
2761
- case "mcp_tool_use": {
2762
- mcpToolCalls[part.id] = {
2763
- type: "tool-call",
2764
- toolCallId: part.id,
2765
- toolName: part.name,
2766
- input: JSON.stringify(part.input),
2767
- providerExecuted: true,
2768
- dynamic: true,
2769
- providerMetadata: {
2770
- anthropic: {
2771
- type: "mcp-tool-use",
2772
- serverName: part.server_name
2773
- }
2750
+ return;
2751
+ }
2752
+ // code execution 20250522:
2753
+ case "code_execution_tool_result": {
2754
+ if (part.content.type === "code_execution_result") {
2755
+ controller.enqueue({
2756
+ type: "tool-result",
2757
+ toolCallId: part.tool_use_id,
2758
+ toolName: "code_execution",
2759
+ result: {
2760
+ type: part.content.type,
2761
+ stdout: part.content.stdout,
2762
+ stderr: part.content.stderr,
2763
+ return_code: part.content.return_code
2774
2764
  }
2775
- };
2776
- controller.enqueue(mcpToolCalls[part.id]);
2777
- return;
2778
- }
2779
- case "mcp_tool_result": {
2765
+ });
2766
+ } else if (part.content.type === "code_execution_tool_result_error") {
2780
2767
  controller.enqueue({
2781
2768
  type: "tool-result",
2782
2769
  toolCallId: part.tool_use_id,
2783
- toolName: mcpToolCalls[part.tool_use_id].toolName,
2784
- isError: part.is_error,
2785
- result: part.content,
2786
- dynamic: true,
2787
- providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
2770
+ toolName: "code_execution",
2771
+ isError: true,
2772
+ result: {
2773
+ type: "code_execution_tool_result_error",
2774
+ errorCode: part.content.error_code
2775
+ }
2788
2776
  });
2789
- return;
2790
- }
2791
- default: {
2792
- const _exhaustiveCheck = contentBlockType;
2793
- throw new Error(
2794
- `Unsupported content block type: ${_exhaustiveCheck}`
2795
- );
2796
2777
  }
2778
+ return;
2779
+ }
2780
+ // code execution 20250825:
2781
+ case "bash_code_execution_tool_result":
2782
+ case "text_editor_code_execution_tool_result": {
2783
+ controller.enqueue({
2784
+ type: "tool-result",
2785
+ toolCallId: part.tool_use_id,
2786
+ toolName: "code_execution",
2787
+ result: part.content
2788
+ });
2789
+ return;
2790
+ }
2791
+ case "mcp_tool_use": {
2792
+ mcpToolCalls[part.id] = {
2793
+ type: "tool-call",
2794
+ toolCallId: part.id,
2795
+ toolName: part.name,
2796
+ input: JSON.stringify(part.input),
2797
+ providerExecuted: true,
2798
+ dynamic: true,
2799
+ providerMetadata: {
2800
+ anthropic: {
2801
+ type: "mcp-tool-use",
2802
+ serverName: part.server_name
2803
+ }
2804
+ }
2805
+ };
2806
+ controller.enqueue(mcpToolCalls[part.id]);
2807
+ return;
2808
+ }
2809
+ case "mcp_tool_result": {
2810
+ controller.enqueue({
2811
+ type: "tool-result",
2812
+ toolCallId: part.tool_use_id,
2813
+ toolName: mcpToolCalls[part.tool_use_id].toolName,
2814
+ isError: part.is_error,
2815
+ result: part.content,
2816
+ dynamic: true,
2817
+ providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
2818
+ });
2819
+ return;
2820
+ }
2821
+ default: {
2822
+ const _exhaustiveCheck = contentBlockType;
2823
+ throw new Error(
2824
+ `Unsupported content block type: ${_exhaustiveCheck}`
2825
+ );
2797
2826
  }
2798
2827
  }
2799
- case "content_block_stop": {
2800
- if (contentBlocks[value.index] != null) {
2801
- const contentBlock = contentBlocks[value.index];
2802
- switch (contentBlock.type) {
2803
- case "text": {
2828
+ }
2829
+ case "content_block_stop": {
2830
+ if (contentBlocks[value.index] != null) {
2831
+ const contentBlock = contentBlocks[value.index];
2832
+ switch (contentBlock.type) {
2833
+ case "text": {
2834
+ controller.enqueue({
2835
+ type: "text-end",
2836
+ id: String(value.index)
2837
+ });
2838
+ break;
2839
+ }
2840
+ case "reasoning": {
2841
+ controller.enqueue({
2842
+ type: "reasoning-end",
2843
+ id: String(value.index)
2844
+ });
2845
+ break;
2846
+ }
2847
+ case "tool-call":
2848
+ const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
2849
+ if (!isJsonResponseTool) {
2804
2850
  controller.enqueue({
2805
- type: "text-end",
2806
- id: String(value.index)
2851
+ type: "tool-input-end",
2852
+ id: contentBlock.toolCallId
2807
2853
  });
2808
- break;
2809
- }
2810
- case "reasoning": {
2854
+ const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2811
2855
  controller.enqueue({
2812
- type: "reasoning-end",
2813
- id: String(value.index)
2856
+ type: "tool-call",
2857
+ toolCallId: contentBlock.toolCallId,
2858
+ toolName,
2859
+ input: contentBlock.input,
2860
+ providerExecuted: contentBlock.providerExecuted
2814
2861
  });
2815
- break;
2816
2862
  }
2817
- case "tool-call":
2818
- const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
2819
- if (!isJsonResponseTool) {
2820
- controller.enqueue({
2821
- type: "tool-input-end",
2822
- id: contentBlock.toolCallId
2823
- });
2824
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2825
- controller.enqueue({
2826
- type: "tool-call",
2827
- toolCallId: contentBlock.toolCallId,
2828
- toolName,
2829
- input: contentBlock.input,
2830
- providerExecuted: contentBlock.providerExecuted
2831
- });
2832
- }
2833
- break;
2834
- }
2835
- delete contentBlocks[value.index];
2863
+ break;
2836
2864
  }
2837
- blockType = void 0;
2838
- return;
2865
+ delete contentBlocks[value.index];
2839
2866
  }
2840
- case "content_block_delta": {
2841
- const deltaType = value.delta.type;
2842
- switch (deltaType) {
2843
- case "text_delta": {
2844
- if (usesJsonResponseTool) {
2845
- return;
2846
- }
2847
- controller.enqueue({
2848
- type: "text-delta",
2849
- id: String(value.index),
2850
- delta: value.delta.text
2851
- });
2867
+ blockType = void 0;
2868
+ return;
2869
+ }
2870
+ case "content_block_delta": {
2871
+ const deltaType = value.delta.type;
2872
+ switch (deltaType) {
2873
+ case "text_delta": {
2874
+ if (usesJsonResponseTool) {
2852
2875
  return;
2853
2876
  }
2854
- case "thinking_delta": {
2877
+ controller.enqueue({
2878
+ type: "text-delta",
2879
+ id: String(value.index),
2880
+ delta: value.delta.text
2881
+ });
2882
+ return;
2883
+ }
2884
+ case "thinking_delta": {
2885
+ controller.enqueue({
2886
+ type: "reasoning-delta",
2887
+ id: String(value.index),
2888
+ delta: value.delta.thinking
2889
+ });
2890
+ return;
2891
+ }
2892
+ case "signature_delta": {
2893
+ if (blockType === "thinking") {
2855
2894
  controller.enqueue({
2856
2895
  type: "reasoning-delta",
2857
2896
  id: String(value.index),
2858
- delta: value.delta.thinking
2897
+ delta: "",
2898
+ providerMetadata: {
2899
+ anthropic: {
2900
+ signature: value.delta.signature
2901
+ }
2902
+ }
2859
2903
  });
2860
- return;
2861
2904
  }
2862
- case "signature_delta": {
2863
- if (blockType === "thinking") {
2864
- controller.enqueue({
2865
- type: "reasoning-delta",
2866
- id: String(value.index),
2867
- delta: "",
2868
- providerMetadata: {
2869
- anthropic: {
2870
- signature: value.delta.signature
2871
- }
2872
- }
2873
- });
2874
- }
2905
+ return;
2906
+ }
2907
+ case "input_json_delta": {
2908
+ const contentBlock = contentBlocks[value.index];
2909
+ let delta = value.delta.partial_json;
2910
+ if (delta.length === 0) {
2875
2911
  return;
2876
2912
  }
2877
- case "input_json_delta": {
2878
- const contentBlock = contentBlocks[value.index];
2879
- let delta = value.delta.partial_json;
2880
- if (delta.length === 0) {
2913
+ if (isJsonResponseFromTool) {
2914
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
2881
2915
  return;
2882
2916
  }
2883
- if (isJsonResponseFromTool) {
2884
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
2885
- return;
2886
- }
2887
- controller.enqueue({
2888
- type: "text-delta",
2889
- id: String(value.index),
2890
- delta
2891
- });
2892
- } else {
2893
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2894
- return;
2895
- }
2896
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2897
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2898
- }
2899
- controller.enqueue({
2900
- type: "tool-input-delta",
2901
- id: contentBlock.toolCallId,
2902
- delta
2903
- });
2904
- contentBlock.input += delta;
2905
- contentBlock.firstDelta = false;
2917
+ controller.enqueue({
2918
+ type: "text-delta",
2919
+ id: String(value.index),
2920
+ delta
2921
+ });
2922
+ } else {
2923
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2924
+ return;
2906
2925
  }
2907
- return;
2908
- }
2909
- case "citations_delta": {
2910
- const citation = value.delta.citation;
2911
- const source = createCitationSource(
2912
- citation,
2913
- citationDocuments,
2914
- generateId3
2915
- );
2916
- if (source) {
2917
- controller.enqueue(source);
2926
+ if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2927
+ delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2918
2928
  }
2919
- return;
2929
+ controller.enqueue({
2930
+ type: "tool-input-delta",
2931
+ id: contentBlock.toolCallId,
2932
+ delta
2933
+ });
2934
+ contentBlock.input += delta;
2935
+ contentBlock.firstDelta = false;
2920
2936
  }
2921
- default: {
2922
- const _exhaustiveCheck = deltaType;
2923
- throw new Error(
2924
- `Unsupported delta type: ${_exhaustiveCheck}`
2925
- );
2937
+ return;
2938
+ }
2939
+ case "citations_delta": {
2940
+ const citation = value.delta.citation;
2941
+ const source = createCitationSource(
2942
+ citation,
2943
+ citationDocuments,
2944
+ generateId3
2945
+ );
2946
+ if (source) {
2947
+ controller.enqueue(source);
2926
2948
  }
2949
+ return;
2950
+ }
2951
+ default: {
2952
+ const _exhaustiveCheck = deltaType;
2953
+ throw new Error(
2954
+ `Unsupported delta type: ${_exhaustiveCheck}`
2955
+ );
2927
2956
  }
2928
2957
  }
2929
- case "message_start": {
2930
- usage.inputTokens = value.message.usage.input_tokens;
2931
- usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2932
- rawUsage = {
2933
- ...value.message.usage
2934
- };
2935
- cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
2936
- controller.enqueue({
2937
- type: "response-metadata",
2938
- id: (_d = value.message.id) != null ? _d : void 0,
2939
- modelId: (_e = value.message.model) != null ? _e : void 0
2940
- });
2941
- return;
2942
- }
2943
- case "message_delta": {
2944
- usage.outputTokens = value.usage.output_tokens;
2945
- usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
2946
- finishReason = mapAnthropicStopReason({
2947
- finishReason: value.delta.stop_reason,
2948
- isJsonResponseFromTool
2949
- });
2950
- stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
2951
- container = value.delta.container != null ? {
2952
- expiresAt: value.delta.container.expires_at,
2953
- id: value.delta.container.id,
2954
- skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
2955
- type: skill.type,
2956
- skillId: skill.skill_id,
2957
- version: skill.version
2958
- }))) != null ? _j : null
2959
- } : null;
2960
- rawUsage = {
2961
- ...rawUsage,
2962
- ...value.usage
2963
- };
2964
- return;
2965
- }
2966
- case "message_stop": {
2967
- controller.enqueue({
2968
- type: "finish",
2969
- finishReason,
2970
- usage,
2971
- providerMetadata: {
2972
- anthropic: {
2973
- usage: rawUsage != null ? rawUsage : null,
2974
- cacheCreationInputTokens,
2975
- stopSequence,
2976
- container
2977
- }
2958
+ }
2959
+ case "message_start": {
2960
+ usage.inputTokens = value.message.usage.input_tokens;
2961
+ usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2962
+ rawUsage = {
2963
+ ...value.message.usage
2964
+ };
2965
+ cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
2966
+ controller.enqueue({
2967
+ type: "response-metadata",
2968
+ id: (_d = value.message.id) != null ? _d : void 0,
2969
+ modelId: (_e = value.message.model) != null ? _e : void 0
2970
+ });
2971
+ return;
2972
+ }
2973
+ case "message_delta": {
2974
+ usage.outputTokens = value.usage.output_tokens;
2975
+ usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
2976
+ finishReason = mapAnthropicStopReason({
2977
+ finishReason: value.delta.stop_reason,
2978
+ isJsonResponseFromTool
2979
+ });
2980
+ stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
2981
+ container = value.delta.container != null ? {
2982
+ expiresAt: value.delta.container.expires_at,
2983
+ id: value.delta.container.id,
2984
+ skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
2985
+ type: skill.type,
2986
+ skillId: skill.skill_id,
2987
+ version: skill.version
2988
+ }))) != null ? _j : null
2989
+ } : null;
2990
+ rawUsage = {
2991
+ ...rawUsage,
2992
+ ...value.usage
2993
+ };
2994
+ return;
2995
+ }
2996
+ case "message_stop": {
2997
+ controller.enqueue({
2998
+ type: "finish",
2999
+ finishReason,
3000
+ usage,
3001
+ providerMetadata: {
3002
+ anthropic: {
3003
+ usage: rawUsage != null ? rawUsage : null,
3004
+ cacheCreationInputTokens,
3005
+ stopSequence,
3006
+ container
2978
3007
  }
2979
- });
2980
- return;
2981
- }
2982
- case "error": {
2983
- controller.enqueue({ type: "error", error: value.error });
2984
- return;
2985
- }
2986
- default: {
2987
- const _exhaustiveCheck = value;
2988
- throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
2989
- }
3008
+ }
3009
+ });
3010
+ return;
3011
+ }
3012
+ case "error": {
3013
+ controller.enqueue({ type: "error", error: value.error });
3014
+ return;
3015
+ }
3016
+ default: {
3017
+ const _exhaustiveCheck = value;
3018
+ throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
2990
3019
  }
2991
3020
  }
2992
- })
2993
- ),
2994
- request: { body },
2995
- response: { headers: responseHeaders }
2996
- };
3021
+ }
3022
+ })
3023
+ );
3024
+ const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
3025
+ stream = streamForConsumer;
3026
+ const reader = streamForFirstChunk.getReader();
3027
+ (async () => {
3028
+ try {
3029
+ const { done } = await reader.read();
3030
+ if (!done) {
3031
+ await reader.cancel();
3032
+ }
3033
+ } catch (error) {
3034
+ try {
3035
+ await reader.cancel();
3036
+ } catch (e) {
3037
+ }
3038
+ } finally {
3039
+ reader.releaseLock();
3040
+ }
3041
+ })();
3042
+ return returnPromise.promise;
2997
3043
  }
2998
3044
  };
2999
3045
  function getModelCapabilities(modelId) {
@@ -3055,7 +3101,6 @@ var bash_20241022InputSchema = (0, import_provider_utils12.lazySchema)(
3055
3101
  );
3056
3102
  var bash_20241022 = (0, import_provider_utils12.createProviderDefinedToolFactory)({
3057
3103
  id: "anthropic.bash_20241022",
3058
- name: "bash",
3059
3104
  inputSchema: bash_20241022InputSchema
3060
3105
  });
3061
3106
 
@@ -3072,7 +3117,6 @@ var bash_20250124InputSchema = (0, import_provider_utils13.lazySchema)(
3072
3117
  );
3073
3118
  var bash_20250124 = (0, import_provider_utils13.createProviderDefinedToolFactory)({
3074
3119
  id: "anthropic.bash_20250124",
3075
- name: "bash",
3076
3120
  inputSchema: bash_20250124InputSchema
3077
3121
  });
3078
3122
 
@@ -3101,7 +3145,6 @@ var computer_20241022InputSchema = (0, import_provider_utils14.lazySchema)(
3101
3145
  );
3102
3146
  var computer_20241022 = (0, import_provider_utils14.createProviderDefinedToolFactory)({
3103
3147
  id: "anthropic.computer_20241022",
3104
- name: "computer",
3105
3148
  inputSchema: computer_20241022InputSchema
3106
3149
  });
3107
3150
 
@@ -3140,7 +3183,6 @@ var computer_20250124InputSchema = (0, import_provider_utils15.lazySchema)(
3140
3183
  );
3141
3184
  var computer_20250124 = (0, import_provider_utils15.createProviderDefinedToolFactory)({
3142
3185
  id: "anthropic.computer_20250124",
3143
- name: "computer",
3144
3186
  inputSchema: computer_20250124InputSchema
3145
3187
  });
3146
3188
 
@@ -3186,7 +3228,6 @@ var memory_20250818InputSchema = (0, import_provider_utils16.lazySchema)(
3186
3228
  );
3187
3229
  var memory_20250818 = (0, import_provider_utils16.createProviderDefinedToolFactory)({
3188
3230
  id: "anthropic.memory_20250818",
3189
- name: "memory",
3190
3231
  inputSchema: memory_20250818InputSchema
3191
3232
  });
3192
3233
 
@@ -3208,7 +3249,6 @@ var textEditor_20241022InputSchema = (0, import_provider_utils17.lazySchema)(
3208
3249
  );
3209
3250
  var textEditor_20241022 = (0, import_provider_utils17.createProviderDefinedToolFactory)({
3210
3251
  id: "anthropic.text_editor_20241022",
3211
- name: "str_replace_editor",
3212
3252
  inputSchema: textEditor_20241022InputSchema
3213
3253
  });
3214
3254
 
@@ -3230,7 +3270,6 @@ var textEditor_20250124InputSchema = (0, import_provider_utils18.lazySchema)(
3230
3270
  );
3231
3271
  var textEditor_20250124 = (0, import_provider_utils18.createProviderDefinedToolFactory)({
3232
3272
  id: "anthropic.text_editor_20250124",
3233
- name: "str_replace_editor",
3234
3273
  inputSchema: textEditor_20250124InputSchema
3235
3274
  });
3236
3275
 
@@ -3252,7 +3291,6 @@ var textEditor_20250429InputSchema = (0, import_provider_utils19.lazySchema)(
3252
3291
  );
3253
3292
  var textEditor_20250429 = (0, import_provider_utils19.createProviderDefinedToolFactory)({
3254
3293
  id: "anthropic.text_editor_20250429",
3255
- name: "str_replace_based_edit_tool",
3256
3294
  inputSchema: textEditor_20250429InputSchema
3257
3295
  });
3258
3296