@ai-sdk/anthropic 3.0.97 → 3.0.99

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.99" : "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
  }
@@ -3481,6 +3484,13 @@ var AnthropicMessagesLanguageModel = class {
3481
3484
  description: "Respond with a JSON object.",
3482
3485
  inputSchema: responseFormat.schema
3483
3486
  } : void 0;
3487
+ if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
3488
+ warnings.push({
3489
+ type: "unsupported",
3490
+ feature: "providerOptions.anthropic.disableParallelToolUse",
3491
+ details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
3492
+ });
3493
+ }
3484
3494
  const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
3485
3495
  const cacheControlValidator = new CacheControlValidator();
3486
3496
  const toolNameMapping = createToolNameMapping({
@@ -3848,7 +3858,7 @@ var AnthropicMessagesLanguageModel = class {
3848
3858
  });
3849
3859
  }
3850
3860
  async doGenerate(options) {
3851
- var _a, _b, _c, _d, _e, _f, _g;
3861
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3852
3862
  const {
3853
3863
  args,
3854
3864
  warnings,
@@ -3891,7 +3901,20 @@ var AnthropicMessagesLanguageModel = class {
3891
3901
  switch (part.type) {
3892
3902
  case "text": {
3893
3903
  if (!usesJsonResponseTool) {
3894
- content.push({ type: "text", text: part.text });
3904
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
3905
+ (citation) => citation.type === "web_search_result_location"
3906
+ );
3907
+ content.push({
3908
+ type: "text",
3909
+ text: part.text,
3910
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
3911
+ providerMetadata: {
3912
+ anthropic: {
3913
+ citations: webSearchCitations
3914
+ }
3915
+ }
3916
+ }
3917
+ });
3895
3918
  if (part.citations) {
3896
3919
  for (const citation of part.citations) {
3897
3920
  const source = createCitationSource(
@@ -4055,7 +4078,7 @@ var AnthropicMessagesLanguageModel = class {
4055
4078
  case "web_fetch_tool_result": {
4056
4079
  if (part.content.type === "web_fetch_result") {
4057
4080
  citationDocuments.push({
4058
- title: (_a = part.content.content.title) != null ? _a : part.content.url,
4081
+ title: (_b = part.content.content.title) != null ? _b : part.content.url,
4059
4082
  mediaType: part.content.content.source.media_type
4060
4083
  });
4061
4084
  content.push({
@@ -4118,7 +4141,7 @@ var AnthropicMessagesLanguageModel = class {
4118
4141
  title: result.title,
4119
4142
  providerMetadata: {
4120
4143
  anthropic: {
4121
- pageAge: (_b = result.page_age) != null ? _b : null
4144
+ pageAge: (_c = result.page_age) != null ? _c : null
4122
4145
  }
4123
4146
  }
4124
4147
  });
@@ -4149,7 +4172,7 @@ var AnthropicMessagesLanguageModel = class {
4149
4172
  stdout: part.content.stdout,
4150
4173
  stderr: part.content.stderr,
4151
4174
  return_code: part.content.return_code,
4152
- content: (_c = part.content.content) != null ? _c : []
4175
+ content: (_d = part.content.content) != null ? _d : []
4153
4176
  }
4154
4177
  });
4155
4178
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -4162,7 +4185,7 @@ var AnthropicMessagesLanguageModel = class {
4162
4185
  encrypted_stdout: part.content.encrypted_stdout,
4163
4186
  stderr: part.content.stderr,
4164
4187
  return_code: part.content.return_code,
4165
- content: (_d = part.content.content) != null ? _d : []
4188
+ content: (_e = part.content.content) != null ? _e : []
4166
4189
  }
4167
4190
  });
4168
4191
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -4284,13 +4307,13 @@ var AnthropicMessagesLanguageModel = class {
4284
4307
  finishReason: response.stop_reason,
4285
4308
  isJsonResponseFromTool
4286
4309
  }),
4287
- raw: (_e = response.stop_reason) != null ? _e : void 0
4310
+ raw: (_f = response.stop_reason) != null ? _f : void 0
4288
4311
  },
4289
4312
  usage: convertAnthropicMessagesUsage({ usage: response.usage }),
4290
4313
  request: { body: args },
4291
4314
  response: {
4292
- id: (_f = response.id) != null ? _f : void 0,
4293
- modelId: (_g = response.model) != null ? _g : void 0,
4315
+ id: (_g = response.id) != null ? _g : void 0,
4316
+ modelId: (_h = response.model) != null ? _h : void 0,
4294
4317
  headers: responseHeaders,
4295
4318
  body: rawResponse
4296
4319
  },
@@ -4427,7 +4450,10 @@ var AnthropicMessagesLanguageModel = class {
4427
4450
  if (usesJsonResponseTool) {
4428
4451
  return;
4429
4452
  }
4430
- contentBlocks[value.index] = { type: "text" };
4453
+ contentBlocks[value.index] = {
4454
+ type: "text",
4455
+ citations: []
4456
+ };
4431
4457
  controller.enqueue({
4432
4458
  type: "text-start",
4433
4459
  id: String(value.index)
@@ -4456,7 +4482,10 @@ var AnthropicMessagesLanguageModel = class {
4456
4482
  return;
4457
4483
  }
4458
4484
  case "compaction": {
4459
- contentBlocks[value.index] = { type: "text" };
4485
+ contentBlocks[value.index] = {
4486
+ type: "text",
4487
+ citations: []
4488
+ };
4460
4489
  controller.enqueue({
4461
4490
  type: "text-start",
4462
4491
  id: String(value.index),
@@ -4472,7 +4501,10 @@ var AnthropicMessagesLanguageModel = class {
4472
4501
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
4473
4502
  if (isJsonResponseTool) {
4474
4503
  isJsonResponseFromTool = true;
4475
- contentBlocks[value.index] = { type: "text" };
4504
+ contentBlocks[value.index] = {
4505
+ type: "text",
4506
+ citations: []
4507
+ };
4476
4508
  controller.enqueue({
4477
4509
  type: "text-start",
4478
4510
  id: String(value.index)
@@ -4845,7 +4877,14 @@ var AnthropicMessagesLanguageModel = class {
4845
4877
  case "text": {
4846
4878
  controller.enqueue({
4847
4879
  type: "text-end",
4848
- id: String(value.index)
4880
+ id: String(value.index),
4881
+ ...contentBlock.citations.length > 0 && {
4882
+ providerMetadata: {
4883
+ anthropic: {
4884
+ citations: contentBlock.citations
4885
+ }
4886
+ }
4887
+ }
4849
4888
  });
4850
4889
  break;
4851
4890
  }
@@ -4984,6 +5023,10 @@ var AnthropicMessagesLanguageModel = class {
4984
5023
  }
4985
5024
  case "citations_delta": {
4986
5025
  const citation = value.delta.citation;
5026
+ const contentBlock = contentBlocks[value.index];
5027
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
5028
+ contentBlock.citations.push(citation);
5029
+ }
4987
5030
  const source = createCitationSource(
4988
5031
  citation,
4989
5032
  citationDocuments,