@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.
@@ -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
  }
@@ -3465,6 +3468,13 @@ var AnthropicMessagesLanguageModel = class {
3465
3468
  description: "Respond with a JSON object.",
3466
3469
  inputSchema: responseFormat.schema
3467
3470
  } : void 0;
3471
+ if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
3472
+ warnings.push({
3473
+ type: "unsupported",
3474
+ feature: "providerOptions.anthropic.disableParallelToolUse",
3475
+ details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
3476
+ });
3477
+ }
3468
3478
  const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
3469
3479
  const cacheControlValidator = new CacheControlValidator();
3470
3480
  const toolNameMapping = createToolNameMapping({
@@ -3832,7 +3842,7 @@ var AnthropicMessagesLanguageModel = class {
3832
3842
  });
3833
3843
  }
3834
3844
  async doGenerate(options) {
3835
- var _a, _b, _c, _d, _e, _f, _g;
3845
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3836
3846
  const {
3837
3847
  args,
3838
3848
  warnings,
@@ -3875,7 +3885,20 @@ var AnthropicMessagesLanguageModel = class {
3875
3885
  switch (part.type) {
3876
3886
  case "text": {
3877
3887
  if (!usesJsonResponseTool) {
3878
- content.push({ type: "text", text: part.text });
3888
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
3889
+ (citation) => citation.type === "web_search_result_location"
3890
+ );
3891
+ content.push({
3892
+ type: "text",
3893
+ text: part.text,
3894
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
3895
+ providerMetadata: {
3896
+ anthropic: {
3897
+ citations: webSearchCitations
3898
+ }
3899
+ }
3900
+ }
3901
+ });
3879
3902
  if (part.citations) {
3880
3903
  for (const citation of part.citations) {
3881
3904
  const source = createCitationSource(
@@ -4039,7 +4062,7 @@ var AnthropicMessagesLanguageModel = class {
4039
4062
  case "web_fetch_tool_result": {
4040
4063
  if (part.content.type === "web_fetch_result") {
4041
4064
  citationDocuments.push({
4042
- title: (_a = part.content.content.title) != null ? _a : part.content.url,
4065
+ title: (_b = part.content.content.title) != null ? _b : part.content.url,
4043
4066
  mediaType: part.content.content.source.media_type
4044
4067
  });
4045
4068
  content.push({
@@ -4102,7 +4125,7 @@ var AnthropicMessagesLanguageModel = class {
4102
4125
  title: result.title,
4103
4126
  providerMetadata: {
4104
4127
  anthropic: {
4105
- pageAge: (_b = result.page_age) != null ? _b : null
4128
+ pageAge: (_c = result.page_age) != null ? _c : null
4106
4129
  }
4107
4130
  }
4108
4131
  });
@@ -4133,7 +4156,7 @@ var AnthropicMessagesLanguageModel = class {
4133
4156
  stdout: part.content.stdout,
4134
4157
  stderr: part.content.stderr,
4135
4158
  return_code: part.content.return_code,
4136
- content: (_c = part.content.content) != null ? _c : []
4159
+ content: (_d = part.content.content) != null ? _d : []
4137
4160
  }
4138
4161
  });
4139
4162
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -4146,7 +4169,7 @@ var AnthropicMessagesLanguageModel = class {
4146
4169
  encrypted_stdout: part.content.encrypted_stdout,
4147
4170
  stderr: part.content.stderr,
4148
4171
  return_code: part.content.return_code,
4149
- content: (_d = part.content.content) != null ? _d : []
4172
+ content: (_e = part.content.content) != null ? _e : []
4150
4173
  }
4151
4174
  });
4152
4175
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -4268,13 +4291,13 @@ var AnthropicMessagesLanguageModel = class {
4268
4291
  finishReason: response.stop_reason,
4269
4292
  isJsonResponseFromTool
4270
4293
  }),
4271
- raw: (_e = response.stop_reason) != null ? _e : void 0
4294
+ raw: (_f = response.stop_reason) != null ? _f : void 0
4272
4295
  },
4273
4296
  usage: convertAnthropicMessagesUsage({ usage: response.usage }),
4274
4297
  request: { body: args },
4275
4298
  response: {
4276
- id: (_f = response.id) != null ? _f : void 0,
4277
- modelId: (_g = response.model) != null ? _g : void 0,
4299
+ id: (_g = response.id) != null ? _g : void 0,
4300
+ modelId: (_h = response.model) != null ? _h : void 0,
4278
4301
  headers: responseHeaders,
4279
4302
  body: rawResponse
4280
4303
  },
@@ -4411,7 +4434,10 @@ var AnthropicMessagesLanguageModel = class {
4411
4434
  if (usesJsonResponseTool) {
4412
4435
  return;
4413
4436
  }
4414
- contentBlocks[value.index] = { type: "text" };
4437
+ contentBlocks[value.index] = {
4438
+ type: "text",
4439
+ citations: []
4440
+ };
4415
4441
  controller.enqueue({
4416
4442
  type: "text-start",
4417
4443
  id: String(value.index)
@@ -4440,7 +4466,10 @@ var AnthropicMessagesLanguageModel = class {
4440
4466
  return;
4441
4467
  }
4442
4468
  case "compaction": {
4443
- contentBlocks[value.index] = { type: "text" };
4469
+ contentBlocks[value.index] = {
4470
+ type: "text",
4471
+ citations: []
4472
+ };
4444
4473
  controller.enqueue({
4445
4474
  type: "text-start",
4446
4475
  id: String(value.index),
@@ -4456,7 +4485,10 @@ var AnthropicMessagesLanguageModel = class {
4456
4485
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
4457
4486
  if (isJsonResponseTool) {
4458
4487
  isJsonResponseFromTool = true;
4459
- contentBlocks[value.index] = { type: "text" };
4488
+ contentBlocks[value.index] = {
4489
+ type: "text",
4490
+ citations: []
4491
+ };
4460
4492
  controller.enqueue({
4461
4493
  type: "text-start",
4462
4494
  id: String(value.index)
@@ -4829,7 +4861,14 @@ var AnthropicMessagesLanguageModel = class {
4829
4861
  case "text": {
4830
4862
  controller.enqueue({
4831
4863
  type: "text-end",
4832
- id: String(value.index)
4864
+ id: String(value.index),
4865
+ ...contentBlock.citations.length > 0 && {
4866
+ providerMetadata: {
4867
+ anthropic: {
4868
+ citations: contentBlock.citations
4869
+ }
4870
+ }
4871
+ }
4833
4872
  });
4834
4873
  break;
4835
4874
  }
@@ -4968,6 +5007,10 @@ var AnthropicMessagesLanguageModel = class {
4968
5007
  }
4969
5008
  case "citations_delta": {
4970
5009
  const citation = value.delta.citation;
5010
+ const contentBlock = contentBlocks[value.index];
5011
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
5012
+ contentBlock.citations.push(citation);
5013
+ }
4971
5014
  const source = createCitationSource(
4972
5015
  citation,
4973
5016
  citationDocuments,
@@ -5861,6 +5904,7 @@ var anthropicTools = {
5861
5904
  export {
5862
5905
  AnthropicMessagesLanguageModel,
5863
5906
  anthropicTools,
5864
- prepareTools
5907
+ prepareTools,
5908
+ sanitizeJsonSchema
5865
5909
  };
5866
5910
  //# sourceMappingURL=index.mjs.map