@ai-sdk/anthropic 3.0.97 → 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.
package/dist/index.mjs CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  } from "@ai-sdk/provider-utils";
13
13
 
14
14
  // src/version.ts
15
- var VERSION = true ? "3.0.97" : "0.0.0-test";
15
+ var VERSION = true ? "3.0.98" : "0.0.0-test";
16
16
 
17
17
  // src/anthropic-messages-language-model.ts
18
18
  import {
@@ -2581,6 +2581,9 @@ async function convertToAnthropicMessagesPrompt({
2581
2581
  // in pre-filled assistant responses
2582
2582
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
2583
2583
  ),
2584
+ ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
2585
+ citations: textMetadata.citations
2586
+ },
2584
2587
  cache_control: cacheControl
2585
2588
  });
2586
2589
  }
@@ -3848,7 +3851,7 @@ var AnthropicMessagesLanguageModel = class {
3848
3851
  });
3849
3852
  }
3850
3853
  async doGenerate(options) {
3851
- var _a, _b, _c, _d, _e, _f, _g;
3854
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3852
3855
  const {
3853
3856
  args,
3854
3857
  warnings,
@@ -3891,7 +3894,20 @@ var AnthropicMessagesLanguageModel = class {
3891
3894
  switch (part.type) {
3892
3895
  case "text": {
3893
3896
  if (!usesJsonResponseTool) {
3894
- content.push({ type: "text", text: part.text });
3897
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
3898
+ (citation) => citation.type === "web_search_result_location"
3899
+ );
3900
+ content.push({
3901
+ type: "text",
3902
+ text: part.text,
3903
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
3904
+ providerMetadata: {
3905
+ anthropic: {
3906
+ citations: webSearchCitations
3907
+ }
3908
+ }
3909
+ }
3910
+ });
3895
3911
  if (part.citations) {
3896
3912
  for (const citation of part.citations) {
3897
3913
  const source = createCitationSource(
@@ -4055,7 +4071,7 @@ var AnthropicMessagesLanguageModel = class {
4055
4071
  case "web_fetch_tool_result": {
4056
4072
  if (part.content.type === "web_fetch_result") {
4057
4073
  citationDocuments.push({
4058
- title: (_a = part.content.content.title) != null ? _a : part.content.url,
4074
+ title: (_b = part.content.content.title) != null ? _b : part.content.url,
4059
4075
  mediaType: part.content.content.source.media_type
4060
4076
  });
4061
4077
  content.push({
@@ -4118,7 +4134,7 @@ var AnthropicMessagesLanguageModel = class {
4118
4134
  title: result.title,
4119
4135
  providerMetadata: {
4120
4136
  anthropic: {
4121
- pageAge: (_b = result.page_age) != null ? _b : null
4137
+ pageAge: (_c = result.page_age) != null ? _c : null
4122
4138
  }
4123
4139
  }
4124
4140
  });
@@ -4149,7 +4165,7 @@ var AnthropicMessagesLanguageModel = class {
4149
4165
  stdout: part.content.stdout,
4150
4166
  stderr: part.content.stderr,
4151
4167
  return_code: part.content.return_code,
4152
- content: (_c = part.content.content) != null ? _c : []
4168
+ content: (_d = part.content.content) != null ? _d : []
4153
4169
  }
4154
4170
  });
4155
4171
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -4162,7 +4178,7 @@ var AnthropicMessagesLanguageModel = class {
4162
4178
  encrypted_stdout: part.content.encrypted_stdout,
4163
4179
  stderr: part.content.stderr,
4164
4180
  return_code: part.content.return_code,
4165
- content: (_d = part.content.content) != null ? _d : []
4181
+ content: (_e = part.content.content) != null ? _e : []
4166
4182
  }
4167
4183
  });
4168
4184
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -4284,13 +4300,13 @@ var AnthropicMessagesLanguageModel = class {
4284
4300
  finishReason: response.stop_reason,
4285
4301
  isJsonResponseFromTool
4286
4302
  }),
4287
- raw: (_e = response.stop_reason) != null ? _e : void 0
4303
+ raw: (_f = response.stop_reason) != null ? _f : void 0
4288
4304
  },
4289
4305
  usage: convertAnthropicMessagesUsage({ usage: response.usage }),
4290
4306
  request: { body: args },
4291
4307
  response: {
4292
- id: (_f = response.id) != null ? _f : void 0,
4293
- modelId: (_g = response.model) != null ? _g : void 0,
4308
+ id: (_g = response.id) != null ? _g : void 0,
4309
+ modelId: (_h = response.model) != null ? _h : void 0,
4294
4310
  headers: responseHeaders,
4295
4311
  body: rawResponse
4296
4312
  },
@@ -4427,7 +4443,10 @@ var AnthropicMessagesLanguageModel = class {
4427
4443
  if (usesJsonResponseTool) {
4428
4444
  return;
4429
4445
  }
4430
- contentBlocks[value.index] = { type: "text" };
4446
+ contentBlocks[value.index] = {
4447
+ type: "text",
4448
+ citations: []
4449
+ };
4431
4450
  controller.enqueue({
4432
4451
  type: "text-start",
4433
4452
  id: String(value.index)
@@ -4456,7 +4475,10 @@ var AnthropicMessagesLanguageModel = class {
4456
4475
  return;
4457
4476
  }
4458
4477
  case "compaction": {
4459
- contentBlocks[value.index] = { type: "text" };
4478
+ contentBlocks[value.index] = {
4479
+ type: "text",
4480
+ citations: []
4481
+ };
4460
4482
  controller.enqueue({
4461
4483
  type: "text-start",
4462
4484
  id: String(value.index),
@@ -4472,7 +4494,10 @@ var AnthropicMessagesLanguageModel = class {
4472
4494
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
4473
4495
  if (isJsonResponseTool) {
4474
4496
  isJsonResponseFromTool = true;
4475
- contentBlocks[value.index] = { type: "text" };
4497
+ contentBlocks[value.index] = {
4498
+ type: "text",
4499
+ citations: []
4500
+ };
4476
4501
  controller.enqueue({
4477
4502
  type: "text-start",
4478
4503
  id: String(value.index)
@@ -4845,7 +4870,14 @@ var AnthropicMessagesLanguageModel = class {
4845
4870
  case "text": {
4846
4871
  controller.enqueue({
4847
4872
  type: "text-end",
4848
- id: String(value.index)
4873
+ id: String(value.index),
4874
+ ...contentBlock.citations.length > 0 && {
4875
+ providerMetadata: {
4876
+ anthropic: {
4877
+ citations: contentBlock.citations
4878
+ }
4879
+ }
4880
+ }
4849
4881
  });
4850
4882
  break;
4851
4883
  }
@@ -4984,6 +5016,10 @@ var AnthropicMessagesLanguageModel = class {
4984
5016
  }
4985
5017
  case "citations_delta": {
4986
5018
  const citation = value.delta.citation;
5019
+ const contentBlock = contentBlocks[value.index];
5020
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
5021
+ contentBlock.citations.push(citation);
5022
+ }
4987
5023
  const source = createCitationSource(
4988
5024
  citation,
4989
5025
  citationDocuments,