@ai-sdk/anthropic 4.0.14 → 4.0.16

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,20 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.16
4
+
5
+ ### Patch Changes
6
+
7
+ - afcf19c: fix(provider/anthropic): preserve web search citations when replaying assistant messages
8
+ - Updated dependencies [cd06458]
9
+ - @ai-sdk/provider-utils@5.0.11
10
+
11
+ ## 4.0.15
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [31c7be8]
16
+ - @ai-sdk/provider-utils@5.0.10
17
+
3
18
  ## 4.0.14
4
19
 
5
20
  ### Patch Changes
package/dist/index.js CHANGED
@@ -2747,6 +2747,9 @@ async function convertToAnthropicPrompt({
2747
2747
  // in pre-filled assistant responses
2748
2748
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
2749
2749
  ),
2750
+ ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
2751
+ citations: textMetadata.citations
2752
+ },
2750
2753
  cache_control: cacheControl
2751
2754
  });
2752
2755
  }
@@ -4049,7 +4052,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4049
4052
  });
4050
4053
  }
4051
4054
  async doGenerate(options) {
4052
- var _a, _b, _c, _d, _e, _f, _g;
4055
+ var _a, _b, _c, _d, _e, _f, _g, _h;
4053
4056
  const {
4054
4057
  args,
4055
4058
  warnings,
@@ -4092,7 +4095,20 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4092
4095
  switch (part.type) {
4093
4096
  case "text": {
4094
4097
  if (!usesJsonResponseTool) {
4095
- content.push({ type: "text", text: part.text });
4098
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
4099
+ (citation) => citation.type === "web_search_result_location"
4100
+ );
4101
+ content.push({
4102
+ type: "text",
4103
+ text: part.text,
4104
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
4105
+ providerMetadata: {
4106
+ anthropic: {
4107
+ citations: webSearchCitations
4108
+ }
4109
+ }
4110
+ }
4111
+ });
4096
4112
  if (part.citations) {
4097
4113
  for (const citation of part.citations) {
4098
4114
  const source = createCitationSource(
@@ -4256,7 +4272,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4256
4272
  case "web_fetch_tool_result": {
4257
4273
  if (part.content.type === "web_fetch_result") {
4258
4274
  citationDocuments.push({
4259
- title: (_a = part.content.content.title) != null ? _a : part.content.url,
4275
+ title: (_b = part.content.content.title) != null ? _b : part.content.url,
4260
4276
  mediaType: part.content.content.source.media_type
4261
4277
  });
4262
4278
  content.push({
@@ -4319,7 +4335,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4319
4335
  title: result.title,
4320
4336
  providerMetadata: {
4321
4337
  anthropic: {
4322
- pageAge: (_b = result.page_age) != null ? _b : null
4338
+ pageAge: (_c = result.page_age) != null ? _c : null
4323
4339
  }
4324
4340
  }
4325
4341
  });
@@ -4350,7 +4366,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4350
4366
  stdout: part.content.stdout,
4351
4367
  stderr: part.content.stderr,
4352
4368
  return_code: part.content.return_code,
4353
- content: (_c = part.content.content) != null ? _c : []
4369
+ content: (_d = part.content.content) != null ? _d : []
4354
4370
  }
4355
4371
  });
4356
4372
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -4363,7 +4379,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4363
4379
  encrypted_stdout: part.content.encrypted_stdout,
4364
4380
  stderr: part.content.stderr,
4365
4381
  return_code: part.content.return_code,
4366
- content: (_d = part.content.content) != null ? _d : []
4382
+ content: (_e = part.content.content) != null ? _e : []
4367
4383
  }
4368
4384
  });
4369
4385
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -4485,13 +4501,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4485
4501
  finishReason: response.stop_reason,
4486
4502
  isJsonResponseFromTool
4487
4503
  }),
4488
- raw: (_e = response.stop_reason) != null ? _e : void 0
4504
+ raw: (_f = response.stop_reason) != null ? _f : void 0
4489
4505
  },
4490
4506
  usage: convertAnthropicUsage({ usage: response.usage }),
4491
4507
  request: { body: args },
4492
4508
  response: {
4493
- id: (_f = response.id) != null ? _f : void 0,
4494
- modelId: (_g = response.model) != null ? _g : void 0,
4509
+ id: (_g = response.id) != null ? _g : void 0,
4510
+ modelId: (_h = response.model) != null ? _h : void 0,
4495
4511
  headers: responseHeaders,
4496
4512
  body: rawResponse
4497
4513
  },
@@ -4625,7 +4641,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4625
4641
  if (usesJsonResponseTool) {
4626
4642
  return;
4627
4643
  }
4628
- contentBlocks[value.index] = { type: "text" };
4644
+ contentBlocks[value.index] = {
4645
+ type: "text",
4646
+ citations: []
4647
+ };
4629
4648
  controller.enqueue({
4630
4649
  type: "text-start",
4631
4650
  id: String(value.index)
@@ -4654,7 +4673,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4654
4673
  return;
4655
4674
  }
4656
4675
  case "compaction": {
4657
- contentBlocks[value.index] = { type: "text" };
4676
+ contentBlocks[value.index] = {
4677
+ type: "text",
4678
+ citations: []
4679
+ };
4658
4680
  controller.enqueue({
4659
4681
  type: "text-start",
4660
4682
  id: String(value.index),
@@ -4670,7 +4692,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4670
4692
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
4671
4693
  if (isJsonResponseTool) {
4672
4694
  isJsonResponseFromTool = true;
4673
- contentBlocks[value.index] = { type: "text" };
4695
+ contentBlocks[value.index] = {
4696
+ type: "text",
4697
+ citations: []
4698
+ };
4674
4699
  controller.enqueue({
4675
4700
  type: "text-start",
4676
4701
  id: String(value.index)
@@ -5043,7 +5068,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5043
5068
  case "text": {
5044
5069
  controller.enqueue({
5045
5070
  type: "text-end",
5046
- id: String(value.index)
5071
+ id: String(value.index),
5072
+ ...contentBlock.citations.length > 0 && {
5073
+ providerMetadata: {
5074
+ anthropic: {
5075
+ citations: contentBlock.citations
5076
+ }
5077
+ }
5078
+ }
5047
5079
  });
5048
5080
  break;
5049
5081
  }
@@ -5182,6 +5214,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5182
5214
  }
5183
5215
  case "citations_delta": {
5184
5216
  const citation = value.delta.citation;
5217
+ const contentBlock = contentBlocks[value.index];
5218
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
5219
+ contentBlock.citations.push(citation);
5220
+ }
5185
5221
  const source = createCitationSource(
5186
5222
  citation,
5187
5223
  citationDocuments,
@@ -6297,7 +6333,7 @@ var AnthropicSkills = class {
6297
6333
  };
6298
6334
 
6299
6335
  // src/version.ts
6300
- var VERSION = true ? "4.0.14" : "0.0.0-test";
6336
+ var VERSION = true ? "4.0.16" : "0.0.0-test";
6301
6337
 
6302
6338
  // src/anthropic-provider.ts
6303
6339
  var ANTHROPIC_API_URL = "https://api.anthropic.com";