@ai-sdk/anthropic 2.0.52 → 2.0.54

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
+ ## 2.0.54
4
+
5
+ ### Patch Changes
6
+
7
+ - ccf34f3: fix(anthropic): make title field nullable in web_fetch and web_search tool output schemas
8
+
9
+ ## 2.0.53
10
+
11
+ ### Patch Changes
12
+
13
+ - 65dee10: fix(anthropic): simplify pulling first chunk
14
+
3
15
  ## 2.0.52
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -426,7 +426,7 @@ declare const anthropicTools: {
426
426
  url: string;
427
427
  content: {
428
428
  type: "document";
429
- title: string;
429
+ title: string | null;
430
430
  citations?: {
431
431
  enabled: boolean;
432
432
  };
@@ -456,7 +456,7 @@ declare const anthropicTools: {
456
456
  url: string;
457
457
  content: {
458
458
  type: "document";
459
- title: string;
459
+ title: string | null;
460
460
  citations?: {
461
461
  enabled: boolean;
462
462
  };
@@ -487,7 +487,7 @@ declare const anthropicTools: {
487
487
  }, {
488
488
  type: "web_search_result";
489
489
  url: string;
490
- title: string;
490
+ title: string | null;
491
491
  pageAge: string | null;
492
492
  encryptedContent: string;
493
493
  }[], {
@@ -506,7 +506,7 @@ declare const anthropicTools: {
506
506
  }, {
507
507
  type: "web_search_result";
508
508
  url: string;
509
- title: string;
509
+ title: string | null;
510
510
  pageAge: string | null;
511
511
  encryptedContent: string;
512
512
  }[]>;
package/dist/index.d.ts CHANGED
@@ -426,7 +426,7 @@ declare const anthropicTools: {
426
426
  url: string;
427
427
  content: {
428
428
  type: "document";
429
- title: string;
429
+ title: string | null;
430
430
  citations?: {
431
431
  enabled: boolean;
432
432
  };
@@ -456,7 +456,7 @@ declare const anthropicTools: {
456
456
  url: string;
457
457
  content: {
458
458
  type: "document";
459
- title: string;
459
+ title: string | null;
460
460
  citations?: {
461
461
  enabled: boolean;
462
462
  };
@@ -487,7 +487,7 @@ declare const anthropicTools: {
487
487
  }, {
488
488
  type: "web_search_result";
489
489
  url: string;
490
- title: string;
490
+ title: string | null;
491
491
  pageAge: string | null;
492
492
  encryptedContent: string;
493
493
  }[], {
@@ -506,7 +506,7 @@ declare const anthropicTools: {
506
506
  }, {
507
507
  type: "web_search_result";
508
508
  url: string;
509
- title: string;
509
+ title: string | null;
510
510
  pageAge: string | null;
511
511
  encryptedContent: string;
512
512
  }[]>;
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 ? "2.0.52" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.54" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -706,7 +706,7 @@ var webSearch_20250305OutputSchema = (0, import_provider_utils5.lazySchema)(
706
706
  import_v45.z.array(
707
707
  import_v45.z.object({
708
708
  url: import_v45.z.string(),
709
- title: import_v45.z.string(),
709
+ title: import_v45.z.string().nullable(),
710
710
  pageAge: import_v45.z.string().nullable(),
711
711
  encryptedContent: import_v45.z.string(),
712
712
  type: import_v45.z.literal("web_search_result")
@@ -752,7 +752,7 @@ var webFetch_20250910OutputSchema = (0, import_provider_utils6.lazySchema)(
752
752
  url: import_v46.z.string(),
753
753
  content: import_v46.z.object({
754
754
  type: import_v46.z.literal("document"),
755
- title: import_v46.z.string(),
755
+ title: import_v46.z.string().nullable(),
756
756
  citations: import_v46.z.object({ enabled: import_v46.z.boolean() }).optional(),
757
757
  source: import_v46.z.union([
758
758
  import_v46.z.object({
@@ -2314,6 +2314,7 @@ var AnthropicMessagesLanguageModel = class {
2314
2314
  };
2315
2315
  }
2316
2316
  async doStream(options) {
2317
+ var _a, _b;
2317
2318
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2318
2319
  ...options,
2319
2320
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2345,25 +2346,13 @@ var AnthropicMessagesLanguageModel = class {
2345
2346
  let container = null;
2346
2347
  let blockType = void 0;
2347
2348
  const generateId3 = this.generateId;
2348
- let isFirstChunk = true;
2349
- let stream = void 0;
2350
- const returnPromise = new import_provider_utils11.DelayedPromise();
2351
2349
  const transformedStream = response.pipeThrough(
2352
2350
  new TransformStream({
2353
2351
  start(controller) {
2354
2352
  controller.enqueue({ type: "stream-start", warnings });
2355
2353
  },
2356
- async flush() {
2357
- if (returnPromise.isPending()) {
2358
- returnPromise.resolve({
2359
- stream,
2360
- request: { body },
2361
- response: { headers: responseHeaders }
2362
- });
2363
- }
2364
- },
2365
2354
  transform(chunk, controller) {
2366
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2355
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
2367
2356
  if (options.includeRawChunks) {
2368
2357
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2369
2358
  }
@@ -2371,29 +2360,6 @@ var AnthropicMessagesLanguageModel = class {
2371
2360
  controller.enqueue({ type: "error", error: chunk.error });
2372
2361
  return;
2373
2362
  }
2374
- if (isFirstChunk) {
2375
- if (chunk.value.type === "error") {
2376
- returnPromise.reject(
2377
- new import_provider3.APICallError({
2378
- message: chunk.value.error.message,
2379
- url,
2380
- requestBodyValues: body,
2381
- statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
2382
- responseHeaders,
2383
- responseBody: JSON.stringify(chunk.value.error),
2384
- isRetryable: chunk.value.error.type === "overloaded_error"
2385
- })
2386
- );
2387
- controller.terminate();
2388
- return;
2389
- }
2390
- isFirstChunk = false;
2391
- returnPromise.resolve({
2392
- stream,
2393
- request: { body },
2394
- response: { headers: responseHeaders }
2395
- });
2396
- }
2397
2363
  const value = chunk.value;
2398
2364
  switch (value.type) {
2399
2365
  case "ping": {
@@ -2525,11 +2491,11 @@ var AnthropicMessagesLanguageModel = class {
2525
2491
  toolCallId: part.tool_use_id,
2526
2492
  toolName: "web_search",
2527
2493
  result: part.content.map((result) => {
2528
- var _a2;
2494
+ var _a3;
2529
2495
  return {
2530
2496
  url: result.url,
2531
2497
  title: result.title,
2532
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
2498
+ pageAge: (_a3 = result.page_age) != null ? _a3 : null,
2533
2499
  encryptedContent: result.encrypted_content,
2534
2500
  type: result.type
2535
2501
  };
@@ -2545,7 +2511,7 @@ var AnthropicMessagesLanguageModel = class {
2545
2511
  title: result.title,
2546
2512
  providerMetadata: {
2547
2513
  anthropic: {
2548
- pageAge: (_a = result.page_age) != null ? _a : null
2514
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null
2549
2515
  }
2550
2516
  }
2551
2517
  });
@@ -2748,7 +2714,7 @@ var AnthropicMessagesLanguageModel = class {
2748
2714
  }
2749
2715
  case "message_start": {
2750
2716
  usage.inputTokens = value.message.usage.input_tokens;
2751
- usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
2717
+ usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
2752
2718
  rawUsage = {
2753
2719
  ...value.message.usage
2754
2720
  };
@@ -2812,22 +2778,35 @@ var AnthropicMessagesLanguageModel = class {
2812
2778
  })
2813
2779
  );
2814
2780
  const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
2815
- stream = streamForConsumer;
2816
2781
  const firstChunkReader = streamForFirstChunk.getReader();
2817
2782
  try {
2818
- const { done } = await firstChunkReader.read();
2819
- if (!done) {
2820
- firstChunkReader.cancel();
2783
+ await firstChunkReader.read();
2784
+ let result = await firstChunkReader.read();
2785
+ if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
2786
+ result = await firstChunkReader.read();
2821
2787
  }
2822
- } catch (error) {
2823
- try {
2824
- firstChunkReader.cancel();
2825
- } catch (e) {
2788
+ if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
2789
+ const error = result.value.error;
2790
+ throw new import_provider3.APICallError({
2791
+ message: error.message,
2792
+ url,
2793
+ requestBodyValues: body,
2794
+ statusCode: error.type === "overloaded_error" ? 529 : 500,
2795
+ responseHeaders,
2796
+ responseBody: JSON.stringify(error),
2797
+ isRetryable: error.type === "overloaded_error"
2798
+ });
2826
2799
  }
2827
2800
  } finally {
2801
+ firstChunkReader.cancel().catch(() => {
2802
+ });
2828
2803
  firstChunkReader.releaseLock();
2829
2804
  }
2830
- return returnPromise.promise;
2805
+ return {
2806
+ stream: streamForConsumer,
2807
+ request: { body },
2808
+ response: { headers: responseHeaders }
2809
+ };
2831
2810
  }
2832
2811
  };
2833
2812
  function getModelCapabilities(modelId) {