@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.
@@ -2565,6 +2565,9 @@ async function convertToAnthropicMessagesPrompt({
2565
2565
  // in pre-filled assistant responses
2566
2566
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
2567
2567
  ),
2568
+ ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
2569
+ citations: textMetadata.citations
2570
+ },
2568
2571
  cache_control: cacheControl
2569
2572
  });
2570
2573
  }
@@ -3832,7 +3835,7 @@ var AnthropicMessagesLanguageModel = class {
3832
3835
  });
3833
3836
  }
3834
3837
  async doGenerate(options) {
3835
- var _a, _b, _c, _d, _e, _f, _g;
3838
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3836
3839
  const {
3837
3840
  args,
3838
3841
  warnings,
@@ -3875,7 +3878,20 @@ var AnthropicMessagesLanguageModel = class {
3875
3878
  switch (part.type) {
3876
3879
  case "text": {
3877
3880
  if (!usesJsonResponseTool) {
3878
- content.push({ type: "text", text: part.text });
3881
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
3882
+ (citation) => citation.type === "web_search_result_location"
3883
+ );
3884
+ content.push({
3885
+ type: "text",
3886
+ text: part.text,
3887
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
3888
+ providerMetadata: {
3889
+ anthropic: {
3890
+ citations: webSearchCitations
3891
+ }
3892
+ }
3893
+ }
3894
+ });
3879
3895
  if (part.citations) {
3880
3896
  for (const citation of part.citations) {
3881
3897
  const source = createCitationSource(
@@ -4039,7 +4055,7 @@ var AnthropicMessagesLanguageModel = class {
4039
4055
  case "web_fetch_tool_result": {
4040
4056
  if (part.content.type === "web_fetch_result") {
4041
4057
  citationDocuments.push({
4042
- title: (_a = part.content.content.title) != null ? _a : part.content.url,
4058
+ title: (_b = part.content.content.title) != null ? _b : part.content.url,
4043
4059
  mediaType: part.content.content.source.media_type
4044
4060
  });
4045
4061
  content.push({
@@ -4102,7 +4118,7 @@ var AnthropicMessagesLanguageModel = class {
4102
4118
  title: result.title,
4103
4119
  providerMetadata: {
4104
4120
  anthropic: {
4105
- pageAge: (_b = result.page_age) != null ? _b : null
4121
+ pageAge: (_c = result.page_age) != null ? _c : null
4106
4122
  }
4107
4123
  }
4108
4124
  });
@@ -4133,7 +4149,7 @@ var AnthropicMessagesLanguageModel = class {
4133
4149
  stdout: part.content.stdout,
4134
4150
  stderr: part.content.stderr,
4135
4151
  return_code: part.content.return_code,
4136
- content: (_c = part.content.content) != null ? _c : []
4152
+ content: (_d = part.content.content) != null ? _d : []
4137
4153
  }
4138
4154
  });
4139
4155
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -4146,7 +4162,7 @@ var AnthropicMessagesLanguageModel = class {
4146
4162
  encrypted_stdout: part.content.encrypted_stdout,
4147
4163
  stderr: part.content.stderr,
4148
4164
  return_code: part.content.return_code,
4149
- content: (_d = part.content.content) != null ? _d : []
4165
+ content: (_e = part.content.content) != null ? _e : []
4150
4166
  }
4151
4167
  });
4152
4168
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -4268,13 +4284,13 @@ var AnthropicMessagesLanguageModel = class {
4268
4284
  finishReason: response.stop_reason,
4269
4285
  isJsonResponseFromTool
4270
4286
  }),
4271
- raw: (_e = response.stop_reason) != null ? _e : void 0
4287
+ raw: (_f = response.stop_reason) != null ? _f : void 0
4272
4288
  },
4273
4289
  usage: convertAnthropicMessagesUsage({ usage: response.usage }),
4274
4290
  request: { body: args },
4275
4291
  response: {
4276
- id: (_f = response.id) != null ? _f : void 0,
4277
- modelId: (_g = response.model) != null ? _g : void 0,
4292
+ id: (_g = response.id) != null ? _g : void 0,
4293
+ modelId: (_h = response.model) != null ? _h : void 0,
4278
4294
  headers: responseHeaders,
4279
4295
  body: rawResponse
4280
4296
  },
@@ -4411,7 +4427,10 @@ var AnthropicMessagesLanguageModel = class {
4411
4427
  if (usesJsonResponseTool) {
4412
4428
  return;
4413
4429
  }
4414
- contentBlocks[value.index] = { type: "text" };
4430
+ contentBlocks[value.index] = {
4431
+ type: "text",
4432
+ citations: []
4433
+ };
4415
4434
  controller.enqueue({
4416
4435
  type: "text-start",
4417
4436
  id: String(value.index)
@@ -4440,7 +4459,10 @@ var AnthropicMessagesLanguageModel = class {
4440
4459
  return;
4441
4460
  }
4442
4461
  case "compaction": {
4443
- contentBlocks[value.index] = { type: "text" };
4462
+ contentBlocks[value.index] = {
4463
+ type: "text",
4464
+ citations: []
4465
+ };
4444
4466
  controller.enqueue({
4445
4467
  type: "text-start",
4446
4468
  id: String(value.index),
@@ -4456,7 +4478,10 @@ var AnthropicMessagesLanguageModel = class {
4456
4478
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
4457
4479
  if (isJsonResponseTool) {
4458
4480
  isJsonResponseFromTool = true;
4459
- contentBlocks[value.index] = { type: "text" };
4481
+ contentBlocks[value.index] = {
4482
+ type: "text",
4483
+ citations: []
4484
+ };
4460
4485
  controller.enqueue({
4461
4486
  type: "text-start",
4462
4487
  id: String(value.index)
@@ -4829,7 +4854,14 @@ var AnthropicMessagesLanguageModel = class {
4829
4854
  case "text": {
4830
4855
  controller.enqueue({
4831
4856
  type: "text-end",
4832
- id: String(value.index)
4857
+ id: String(value.index),
4858
+ ...contentBlock.citations.length > 0 && {
4859
+ providerMetadata: {
4860
+ anthropic: {
4861
+ citations: contentBlock.citations
4862
+ }
4863
+ }
4864
+ }
4833
4865
  });
4834
4866
  break;
4835
4867
  }
@@ -4968,6 +5000,10 @@ var AnthropicMessagesLanguageModel = class {
4968
5000
  }
4969
5001
  case "citations_delta": {
4970
5002
  const citation = value.delta.citation;
5003
+ const contentBlock = contentBlocks[value.index];
5004
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
5005
+ contentBlock.citations.push(citation);
5006
+ }
4971
5007
  const source = createCitationSource(
4972
5008
  citation,
4973
5009
  citationDocuments,