@ai-sdk/anthropic 3.0.96 → 3.0.98

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.
@@ -2522,6 +2522,9 @@ async function convertToAnthropicMessagesPrompt({
2522
2522
  // in pre-filled assistant responses
2523
2523
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
2524
2524
  ),
2525
+ ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
2526
+ citations: textMetadata.citations
2527
+ },
2525
2528
  cache_control: cacheControl
2526
2529
  });
2527
2530
  }
@@ -3789,7 +3792,7 @@ var AnthropicMessagesLanguageModel = class {
3789
3792
  });
3790
3793
  }
3791
3794
  async doGenerate(options) {
3792
- var _a, _b, _c, _d, _e, _f, _g;
3795
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3793
3796
  const {
3794
3797
  args,
3795
3798
  warnings,
@@ -3832,7 +3835,20 @@ var AnthropicMessagesLanguageModel = class {
3832
3835
  switch (part.type) {
3833
3836
  case "text": {
3834
3837
  if (!usesJsonResponseTool) {
3835
- content.push({ type: "text", text: part.text });
3838
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
3839
+ (citation) => citation.type === "web_search_result_location"
3840
+ );
3841
+ content.push({
3842
+ type: "text",
3843
+ text: part.text,
3844
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
3845
+ providerMetadata: {
3846
+ anthropic: {
3847
+ citations: webSearchCitations
3848
+ }
3849
+ }
3850
+ }
3851
+ });
3836
3852
  if (part.citations) {
3837
3853
  for (const citation of part.citations) {
3838
3854
  const source = createCitationSource(
@@ -3996,7 +4012,7 @@ var AnthropicMessagesLanguageModel = class {
3996
4012
  case "web_fetch_tool_result": {
3997
4013
  if (part.content.type === "web_fetch_result") {
3998
4014
  citationDocuments.push({
3999
- title: (_a = part.content.content.title) != null ? _a : part.content.url,
4015
+ title: (_b = part.content.content.title) != null ? _b : part.content.url,
4000
4016
  mediaType: part.content.content.source.media_type
4001
4017
  });
4002
4018
  content.push({
@@ -4059,7 +4075,7 @@ var AnthropicMessagesLanguageModel = class {
4059
4075
  title: result.title,
4060
4076
  providerMetadata: {
4061
4077
  anthropic: {
4062
- pageAge: (_b = result.page_age) != null ? _b : null
4078
+ pageAge: (_c = result.page_age) != null ? _c : null
4063
4079
  }
4064
4080
  }
4065
4081
  });
@@ -4090,7 +4106,7 @@ var AnthropicMessagesLanguageModel = class {
4090
4106
  stdout: part.content.stdout,
4091
4107
  stderr: part.content.stderr,
4092
4108
  return_code: part.content.return_code,
4093
- content: (_c = part.content.content) != null ? _c : []
4109
+ content: (_d = part.content.content) != null ? _d : []
4094
4110
  }
4095
4111
  });
4096
4112
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -4103,7 +4119,7 @@ var AnthropicMessagesLanguageModel = class {
4103
4119
  encrypted_stdout: part.content.encrypted_stdout,
4104
4120
  stderr: part.content.stderr,
4105
4121
  return_code: part.content.return_code,
4106
- content: (_d = part.content.content) != null ? _d : []
4122
+ content: (_e = part.content.content) != null ? _e : []
4107
4123
  }
4108
4124
  });
4109
4125
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -4225,13 +4241,13 @@ var AnthropicMessagesLanguageModel = class {
4225
4241
  finishReason: response.stop_reason,
4226
4242
  isJsonResponseFromTool
4227
4243
  }),
4228
- raw: (_e = response.stop_reason) != null ? _e : void 0
4244
+ raw: (_f = response.stop_reason) != null ? _f : void 0
4229
4245
  },
4230
4246
  usage: convertAnthropicMessagesUsage({ usage: response.usage }),
4231
4247
  request: { body: args },
4232
4248
  response: {
4233
- id: (_f = response.id) != null ? _f : void 0,
4234
- modelId: (_g = response.model) != null ? _g : void 0,
4249
+ id: (_g = response.id) != null ? _g : void 0,
4250
+ modelId: (_h = response.model) != null ? _h : void 0,
4235
4251
  headers: responseHeaders,
4236
4252
  body: rawResponse
4237
4253
  },
@@ -4368,7 +4384,10 @@ var AnthropicMessagesLanguageModel = class {
4368
4384
  if (usesJsonResponseTool) {
4369
4385
  return;
4370
4386
  }
4371
- contentBlocks[value.index] = { type: "text" };
4387
+ contentBlocks[value.index] = {
4388
+ type: "text",
4389
+ citations: []
4390
+ };
4372
4391
  controller.enqueue({
4373
4392
  type: "text-start",
4374
4393
  id: String(value.index)
@@ -4397,7 +4416,10 @@ var AnthropicMessagesLanguageModel = class {
4397
4416
  return;
4398
4417
  }
4399
4418
  case "compaction": {
4400
- contentBlocks[value.index] = { type: "text" };
4419
+ contentBlocks[value.index] = {
4420
+ type: "text",
4421
+ citations: []
4422
+ };
4401
4423
  controller.enqueue({
4402
4424
  type: "text-start",
4403
4425
  id: String(value.index),
@@ -4413,7 +4435,10 @@ var AnthropicMessagesLanguageModel = class {
4413
4435
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
4414
4436
  if (isJsonResponseTool) {
4415
4437
  isJsonResponseFromTool = true;
4416
- contentBlocks[value.index] = { type: "text" };
4438
+ contentBlocks[value.index] = {
4439
+ type: "text",
4440
+ citations: []
4441
+ };
4417
4442
  controller.enqueue({
4418
4443
  type: "text-start",
4419
4444
  id: String(value.index)
@@ -4786,7 +4811,14 @@ var AnthropicMessagesLanguageModel = class {
4786
4811
  case "text": {
4787
4812
  controller.enqueue({
4788
4813
  type: "text-end",
4789
- id: String(value.index)
4814
+ id: String(value.index),
4815
+ ...contentBlock.citations.length > 0 && {
4816
+ providerMetadata: {
4817
+ anthropic: {
4818
+ citations: contentBlock.citations
4819
+ }
4820
+ }
4821
+ }
4790
4822
  });
4791
4823
  break;
4792
4824
  }
@@ -4925,6 +4957,10 @@ var AnthropicMessagesLanguageModel = class {
4925
4957
  }
4926
4958
  case "citations_delta": {
4927
4959
  const citation = value.delta.citation;
4960
+ const contentBlock = contentBlocks[value.index];
4961
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
4962
+ contentBlock.citations.push(citation);
4963
+ }
4928
4964
  const source = createCitationSource(
4929
4965
  citation,
4930
4966
  citationDocuments,