@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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.99
4
+
5
+ ### Patch Changes
6
+
7
+ - db8cff6: fix(amazon-bedrock): sanitize unsupported JSON Schema constraints in native Anthropic structured output
8
+ - 94d0f86: fix(provider/anthropic): warn when parallel tool use is requested with JSON tool structured output
9
+
10
+ ## 3.0.98
11
+
12
+ ### Patch Changes
13
+
14
+ - 10366a2: fix(provider/anthropic): preserve web search citations when replaying assistant messages
15
+ - Updated dependencies [19093fd]
16
+ - @ai-sdk/provider-utils@4.0.40
17
+
3
18
  ## 3.0.97
4
19
 
5
20
  ### Patch Changes
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.97" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.99" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -2530,6 +2530,9 @@ async function convertToAnthropicMessagesPrompt({
2530
2530
  // in pre-filled assistant responses
2531
2531
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
2532
2532
  ),
2533
+ ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
2534
+ citations: textMetadata.citations
2535
+ },
2533
2536
  cache_control: cacheControl
2534
2537
  });
2535
2538
  }
@@ -3430,6 +3433,13 @@ var AnthropicMessagesLanguageModel = class {
3430
3433
  description: "Respond with a JSON object.",
3431
3434
  inputSchema: responseFormat.schema
3432
3435
  } : void 0;
3436
+ if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
3437
+ warnings.push({
3438
+ type: "unsupported",
3439
+ feature: "providerOptions.anthropic.disableParallelToolUse",
3440
+ details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
3441
+ });
3442
+ }
3433
3443
  const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
3434
3444
  const cacheControlValidator = new CacheControlValidator();
3435
3445
  const toolNameMapping = (0, import_provider_utils15.createToolNameMapping)({
@@ -3797,7 +3807,7 @@ var AnthropicMessagesLanguageModel = class {
3797
3807
  });
3798
3808
  }
3799
3809
  async doGenerate(options) {
3800
- var _a, _b, _c, _d, _e, _f, _g;
3810
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3801
3811
  const {
3802
3812
  args,
3803
3813
  warnings,
@@ -3840,7 +3850,20 @@ var AnthropicMessagesLanguageModel = class {
3840
3850
  switch (part.type) {
3841
3851
  case "text": {
3842
3852
  if (!usesJsonResponseTool) {
3843
- content.push({ type: "text", text: part.text });
3853
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
3854
+ (citation) => citation.type === "web_search_result_location"
3855
+ );
3856
+ content.push({
3857
+ type: "text",
3858
+ text: part.text,
3859
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
3860
+ providerMetadata: {
3861
+ anthropic: {
3862
+ citations: webSearchCitations
3863
+ }
3864
+ }
3865
+ }
3866
+ });
3844
3867
  if (part.citations) {
3845
3868
  for (const citation of part.citations) {
3846
3869
  const source = createCitationSource(
@@ -4004,7 +4027,7 @@ var AnthropicMessagesLanguageModel = class {
4004
4027
  case "web_fetch_tool_result": {
4005
4028
  if (part.content.type === "web_fetch_result") {
4006
4029
  citationDocuments.push({
4007
- title: (_a = part.content.content.title) != null ? _a : part.content.url,
4030
+ title: (_b = part.content.content.title) != null ? _b : part.content.url,
4008
4031
  mediaType: part.content.content.source.media_type
4009
4032
  });
4010
4033
  content.push({
@@ -4067,7 +4090,7 @@ var AnthropicMessagesLanguageModel = class {
4067
4090
  title: result.title,
4068
4091
  providerMetadata: {
4069
4092
  anthropic: {
4070
- pageAge: (_b = result.page_age) != null ? _b : null
4093
+ pageAge: (_c = result.page_age) != null ? _c : null
4071
4094
  }
4072
4095
  }
4073
4096
  });
@@ -4098,7 +4121,7 @@ var AnthropicMessagesLanguageModel = class {
4098
4121
  stdout: part.content.stdout,
4099
4122
  stderr: part.content.stderr,
4100
4123
  return_code: part.content.return_code,
4101
- content: (_c = part.content.content) != null ? _c : []
4124
+ content: (_d = part.content.content) != null ? _d : []
4102
4125
  }
4103
4126
  });
4104
4127
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -4111,7 +4134,7 @@ var AnthropicMessagesLanguageModel = class {
4111
4134
  encrypted_stdout: part.content.encrypted_stdout,
4112
4135
  stderr: part.content.stderr,
4113
4136
  return_code: part.content.return_code,
4114
- content: (_d = part.content.content) != null ? _d : []
4137
+ content: (_e = part.content.content) != null ? _e : []
4115
4138
  }
4116
4139
  });
4117
4140
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -4233,13 +4256,13 @@ var AnthropicMessagesLanguageModel = class {
4233
4256
  finishReason: response.stop_reason,
4234
4257
  isJsonResponseFromTool
4235
4258
  }),
4236
- raw: (_e = response.stop_reason) != null ? _e : void 0
4259
+ raw: (_f = response.stop_reason) != null ? _f : void 0
4237
4260
  },
4238
4261
  usage: convertAnthropicMessagesUsage({ usage: response.usage }),
4239
4262
  request: { body: args },
4240
4263
  response: {
4241
- id: (_f = response.id) != null ? _f : void 0,
4242
- modelId: (_g = response.model) != null ? _g : void 0,
4264
+ id: (_g = response.id) != null ? _g : void 0,
4265
+ modelId: (_h = response.model) != null ? _h : void 0,
4243
4266
  headers: responseHeaders,
4244
4267
  body: rawResponse
4245
4268
  },
@@ -4376,7 +4399,10 @@ var AnthropicMessagesLanguageModel = class {
4376
4399
  if (usesJsonResponseTool) {
4377
4400
  return;
4378
4401
  }
4379
- contentBlocks[value.index] = { type: "text" };
4402
+ contentBlocks[value.index] = {
4403
+ type: "text",
4404
+ citations: []
4405
+ };
4380
4406
  controller.enqueue({
4381
4407
  type: "text-start",
4382
4408
  id: String(value.index)
@@ -4405,7 +4431,10 @@ var AnthropicMessagesLanguageModel = class {
4405
4431
  return;
4406
4432
  }
4407
4433
  case "compaction": {
4408
- contentBlocks[value.index] = { type: "text" };
4434
+ contentBlocks[value.index] = {
4435
+ type: "text",
4436
+ citations: []
4437
+ };
4409
4438
  controller.enqueue({
4410
4439
  type: "text-start",
4411
4440
  id: String(value.index),
@@ -4421,7 +4450,10 @@ var AnthropicMessagesLanguageModel = class {
4421
4450
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
4422
4451
  if (isJsonResponseTool) {
4423
4452
  isJsonResponseFromTool = true;
4424
- contentBlocks[value.index] = { type: "text" };
4453
+ contentBlocks[value.index] = {
4454
+ type: "text",
4455
+ citations: []
4456
+ };
4425
4457
  controller.enqueue({
4426
4458
  type: "text-start",
4427
4459
  id: String(value.index)
@@ -4794,7 +4826,14 @@ var AnthropicMessagesLanguageModel = class {
4794
4826
  case "text": {
4795
4827
  controller.enqueue({
4796
4828
  type: "text-end",
4797
- id: String(value.index)
4829
+ id: String(value.index),
4830
+ ...contentBlock.citations.length > 0 && {
4831
+ providerMetadata: {
4832
+ anthropic: {
4833
+ citations: contentBlock.citations
4834
+ }
4835
+ }
4836
+ }
4798
4837
  });
4799
4838
  break;
4800
4839
  }
@@ -4933,6 +4972,10 @@ var AnthropicMessagesLanguageModel = class {
4933
4972
  }
4934
4973
  case "citations_delta": {
4935
4974
  const citation = value.delta.citation;
4975
+ const contentBlock = contentBlocks[value.index];
4976
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
4977
+ contentBlock.citations.push(citation);
4978
+ }
4936
4979
  const source = createCitationSource(
4937
4980
  citation,
4938
4981
  citationDocuments,