@ai-sdk/anthropic 4.0.15 → 4.0.17

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,23 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.17
4
+
5
+ ### Patch Changes
6
+
7
+ - b72fc7c: fix(amazon-bedrock): sanitize unsupported JSON Schema constraints in native Anthropic structured output
8
+ - 9218ebe: fix(provider/anthropic): warn when parallel tool use is requested with JSON tool structured output
9
+ - Updated dependencies [02ffdcb]
10
+ - Updated dependencies [76cb673]
11
+ - @ai-sdk/provider-utils@5.0.12
12
+
13
+ ## 4.0.16
14
+
15
+ ### Patch Changes
16
+
17
+ - afcf19c: fix(provider/anthropic): preserve web search citations when replaying assistant messages
18
+ - Updated dependencies [cd06458]
19
+ - @ai-sdk/provider-utils@5.0.11
20
+
3
21
  ## 4.0.15
4
22
 
5
23
  ### Patch Changes
package/dist/index.js CHANGED
@@ -2747,6 +2747,9 @@ async function convertToAnthropicPrompt({
2747
2747
  // in pre-filled assistant responses
2748
2748
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
2749
2749
  ),
2750
+ ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
2751
+ citations: textMetadata.citations
2752
+ },
2750
2753
  cache_control: cacheControl
2751
2754
  });
2752
2755
  }
@@ -3662,6 +3665,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3662
3665
  description: "Respond with a JSON object.",
3663
3666
  inputSchema: responseFormat.schema
3664
3667
  } : void 0;
3668
+ if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
3669
+ warnings.push({
3670
+ type: "unsupported",
3671
+ feature: "providerOptions.anthropic.disableParallelToolUse",
3672
+ details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
3673
+ });
3674
+ }
3665
3675
  const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
3666
3676
  const cacheControlValidator = new CacheControlValidator();
3667
3677
  const toolNameMapping = createToolNameMapping({
@@ -4049,7 +4059,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4049
4059
  });
4050
4060
  }
4051
4061
  async doGenerate(options) {
4052
- var _a, _b, _c, _d, _e, _f, _g;
4062
+ var _a, _b, _c, _d, _e, _f, _g, _h;
4053
4063
  const {
4054
4064
  args,
4055
4065
  warnings,
@@ -4092,7 +4102,20 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4092
4102
  switch (part.type) {
4093
4103
  case "text": {
4094
4104
  if (!usesJsonResponseTool) {
4095
- content.push({ type: "text", text: part.text });
4105
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
4106
+ (citation) => citation.type === "web_search_result_location"
4107
+ );
4108
+ content.push({
4109
+ type: "text",
4110
+ text: part.text,
4111
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
4112
+ providerMetadata: {
4113
+ anthropic: {
4114
+ citations: webSearchCitations
4115
+ }
4116
+ }
4117
+ }
4118
+ });
4096
4119
  if (part.citations) {
4097
4120
  for (const citation of part.citations) {
4098
4121
  const source = createCitationSource(
@@ -4256,7 +4279,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4256
4279
  case "web_fetch_tool_result": {
4257
4280
  if (part.content.type === "web_fetch_result") {
4258
4281
  citationDocuments.push({
4259
- title: (_a = part.content.content.title) != null ? _a : part.content.url,
4282
+ title: (_b = part.content.content.title) != null ? _b : part.content.url,
4260
4283
  mediaType: part.content.content.source.media_type
4261
4284
  });
4262
4285
  content.push({
@@ -4319,7 +4342,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4319
4342
  title: result.title,
4320
4343
  providerMetadata: {
4321
4344
  anthropic: {
4322
- pageAge: (_b = result.page_age) != null ? _b : null
4345
+ pageAge: (_c = result.page_age) != null ? _c : null
4323
4346
  }
4324
4347
  }
4325
4348
  });
@@ -4350,7 +4373,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4350
4373
  stdout: part.content.stdout,
4351
4374
  stderr: part.content.stderr,
4352
4375
  return_code: part.content.return_code,
4353
- content: (_c = part.content.content) != null ? _c : []
4376
+ content: (_d = part.content.content) != null ? _d : []
4354
4377
  }
4355
4378
  });
4356
4379
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -4363,7 +4386,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4363
4386
  encrypted_stdout: part.content.encrypted_stdout,
4364
4387
  stderr: part.content.stderr,
4365
4388
  return_code: part.content.return_code,
4366
- content: (_d = part.content.content) != null ? _d : []
4389
+ content: (_e = part.content.content) != null ? _e : []
4367
4390
  }
4368
4391
  });
4369
4392
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -4485,13 +4508,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4485
4508
  finishReason: response.stop_reason,
4486
4509
  isJsonResponseFromTool
4487
4510
  }),
4488
- raw: (_e = response.stop_reason) != null ? _e : void 0
4511
+ raw: (_f = response.stop_reason) != null ? _f : void 0
4489
4512
  },
4490
4513
  usage: convertAnthropicUsage({ usage: response.usage }),
4491
4514
  request: { body: args },
4492
4515
  response: {
4493
- id: (_f = response.id) != null ? _f : void 0,
4494
- modelId: (_g = response.model) != null ? _g : void 0,
4516
+ id: (_g = response.id) != null ? _g : void 0,
4517
+ modelId: (_h = response.model) != null ? _h : void 0,
4495
4518
  headers: responseHeaders,
4496
4519
  body: rawResponse
4497
4520
  },
@@ -4625,7 +4648,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4625
4648
  if (usesJsonResponseTool) {
4626
4649
  return;
4627
4650
  }
4628
- contentBlocks[value.index] = { type: "text" };
4651
+ contentBlocks[value.index] = {
4652
+ type: "text",
4653
+ citations: []
4654
+ };
4629
4655
  controller.enqueue({
4630
4656
  type: "text-start",
4631
4657
  id: String(value.index)
@@ -4654,7 +4680,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4654
4680
  return;
4655
4681
  }
4656
4682
  case "compaction": {
4657
- contentBlocks[value.index] = { type: "text" };
4683
+ contentBlocks[value.index] = {
4684
+ type: "text",
4685
+ citations: []
4686
+ };
4658
4687
  controller.enqueue({
4659
4688
  type: "text-start",
4660
4689
  id: String(value.index),
@@ -4670,7 +4699,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4670
4699
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
4671
4700
  if (isJsonResponseTool) {
4672
4701
  isJsonResponseFromTool = true;
4673
- contentBlocks[value.index] = { type: "text" };
4702
+ contentBlocks[value.index] = {
4703
+ type: "text",
4704
+ citations: []
4705
+ };
4674
4706
  controller.enqueue({
4675
4707
  type: "text-start",
4676
4708
  id: String(value.index)
@@ -5043,7 +5075,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5043
5075
  case "text": {
5044
5076
  controller.enqueue({
5045
5077
  type: "text-end",
5046
- id: String(value.index)
5078
+ id: String(value.index),
5079
+ ...contentBlock.citations.length > 0 && {
5080
+ providerMetadata: {
5081
+ anthropic: {
5082
+ citations: contentBlock.citations
5083
+ }
5084
+ }
5085
+ }
5047
5086
  });
5048
5087
  break;
5049
5088
  }
@@ -5182,6 +5221,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5182
5221
  }
5183
5222
  case "citations_delta": {
5184
5223
  const citation = value.delta.citation;
5224
+ const contentBlock = contentBlocks[value.index];
5225
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
5226
+ contentBlock.citations.push(citation);
5227
+ }
5185
5228
  const source = createCitationSource(
5186
5229
  citation,
5187
5230
  citationDocuments,
@@ -6297,7 +6340,7 @@ var AnthropicSkills = class {
6297
6340
  };
6298
6341
 
6299
6342
  // src/version.ts
6300
- var VERSION = true ? "4.0.15" : "0.0.0-test";
6343
+ var VERSION = true ? "4.0.17" : "0.0.0-test";
6301
6344
 
6302
6345
  // src/anthropic-provider.ts
6303
6346
  var ANTHROPIC_API_URL = "https://api.anthropic.com";