@ai-sdk/anthropic 3.0.0-beta.67 → 3.0.0-beta.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.0-beta.69
4
+
5
+ ### Patch Changes
6
+
7
+ - 589a4ee: fix(anthropic): simplify pulling first chunk
8
+
9
+ ## 3.0.0-beta.68
10
+
11
+ ### Patch Changes
12
+
13
+ - 9e35785: fix(anthropic): send {} as tool input when streaming tool calls without arguments
14
+
3
15
  ## 3.0.0-beta.67
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "3.0.0-beta.67" : "0.0.0-test";
34
+ var VERSION = true ? "3.0.0-beta.69" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -2485,6 +2485,7 @@ var AnthropicMessagesLanguageModel = class {
2485
2485
  };
2486
2486
  }
2487
2487
  async doStream(options) {
2488
+ var _a, _b;
2488
2489
  const {
2489
2490
  args: body,
2490
2491
  warnings,
@@ -2523,25 +2524,13 @@ var AnthropicMessagesLanguageModel = class {
2523
2524
  let isJsonResponseFromTool = false;
2524
2525
  let blockType = void 0;
2525
2526
  const generateId3 = this.generateId;
2526
- let isFirstChunk = true;
2527
- let stream = void 0;
2528
- const returnPromise = new import_provider_utils11.DelayedPromise();
2529
2527
  const transformedStream = response.pipeThrough(
2530
2528
  new TransformStream({
2531
2529
  start(controller) {
2532
2530
  controller.enqueue({ type: "stream-start", warnings });
2533
2531
  },
2534
- async flush() {
2535
- if (returnPromise.isPending()) {
2536
- returnPromise.resolve({
2537
- stream,
2538
- request: { body },
2539
- response: { headers: responseHeaders }
2540
- });
2541
- }
2542
- },
2543
2532
  transform(chunk, controller) {
2544
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2533
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
2545
2534
  if (options.includeRawChunks) {
2546
2535
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2547
2536
  }
@@ -2549,29 +2538,6 @@ var AnthropicMessagesLanguageModel = class {
2549
2538
  controller.enqueue({ type: "error", error: chunk.error });
2550
2539
  return;
2551
2540
  }
2552
- if (isFirstChunk) {
2553
- if (chunk.value.type === "error") {
2554
- returnPromise.reject(
2555
- new import_provider3.APICallError({
2556
- message: chunk.value.error.message,
2557
- url,
2558
- requestBodyValues: body,
2559
- statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
2560
- responseHeaders,
2561
- responseBody: JSON.stringify(chunk.value.error),
2562
- isRetryable: chunk.value.error.type === "overloaded_error"
2563
- })
2564
- );
2565
- controller.terminate();
2566
- return;
2567
- }
2568
- isFirstChunk = false;
2569
- returnPromise.resolve({
2570
- stream,
2571
- request: { body },
2572
- response: { headers: responseHeaders }
2573
- });
2574
- }
2575
2541
  const value = chunk.value;
2576
2542
  switch (value.type) {
2577
2543
  case "ping": {
@@ -2711,11 +2677,11 @@ var AnthropicMessagesLanguageModel = class {
2711
2677
  toolCallId: part.tool_use_id,
2712
2678
  toolName: "web_search",
2713
2679
  result: part.content.map((result) => {
2714
- var _a2;
2680
+ var _a3;
2715
2681
  return {
2716
2682
  url: result.url,
2717
2683
  title: result.title,
2718
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2684
+ pageAge: (_a3 = result.page_age) != null ? _a3 : null,
2719
2685
  encryptedContent: result.encrypted_content,
2720
2686
  type: result.type
2721
2687
  };
@@ -2730,7 +2696,7 @@ var AnthropicMessagesLanguageModel = class {
2730
2696
  title: result.title,
2731
2697
  providerMetadata: {
2732
2698
  anthropic: {
2733
- pageAge: (_a = result.page_age) != null ? _a : null
2699
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null
2734
2700
  }
2735
2701
  }
2736
2702
  });
@@ -2856,7 +2822,7 @@ var AnthropicMessagesLanguageModel = class {
2856
2822
  type: "tool-call",
2857
2823
  toolCallId: contentBlock.toolCallId,
2858
2824
  toolName,
2859
- input: contentBlock.input,
2825
+ input: contentBlock.input === "" ? "{}" : contentBlock.input,
2860
2826
  providerExecuted: contentBlock.providerExecuted
2861
2827
  });
2862
2828
  }
@@ -2958,7 +2924,7 @@ var AnthropicMessagesLanguageModel = class {
2958
2924
  }
2959
2925
  case "message_start": {
2960
2926
  usage.inputTokens = value.message.usage.input_tokens;
2961
- usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2927
+ usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
2962
2928
  rawUsage = {
2963
2929
  ...value.message.usage
2964
2930
  };
@@ -3022,22 +2988,35 @@ var AnthropicMessagesLanguageModel = class {
3022
2988
  })
3023
2989
  );
3024
2990
  const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
3025
- stream = streamForConsumer;
3026
2991
  const firstChunkReader = streamForFirstChunk.getReader();
3027
2992
  try {
3028
- const { done } = await firstChunkReader.read();
3029
- if (!done) {
3030
- firstChunkReader.cancel();
2993
+ await firstChunkReader.read();
2994
+ let result = await firstChunkReader.read();
2995
+ if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
2996
+ result = await firstChunkReader.read();
3031
2997
  }
3032
- } catch (error) {
3033
- try {
3034
- firstChunkReader.cancel();
3035
- } catch (e) {
2998
+ if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
2999
+ const error = result.value.error;
3000
+ throw new import_provider3.APICallError({
3001
+ message: error.message,
3002
+ url,
3003
+ requestBodyValues: body,
3004
+ statusCode: error.type === "overloaded_error" ? 529 : 500,
3005
+ responseHeaders,
3006
+ responseBody: JSON.stringify(error),
3007
+ isRetryable: error.type === "overloaded_error"
3008
+ });
3036
3009
  }
3037
3010
  } finally {
3011
+ firstChunkReader.cancel().catch(() => {
3012
+ });
3038
3013
  firstChunkReader.releaseLock();
3039
3014
  }
3040
- return returnPromise.promise;
3015
+ return {
3016
+ stream: streamForConsumer,
3017
+ request: { body },
3018
+ response: { headers: responseHeaders }
3019
+ };
3041
3020
  }
3042
3021
  };
3043
3022
  function getModelCapabilities(modelId) {