@ai-sdk/anthropic 2.0.86 → 2.0.88

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,19 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.88
4
+
5
+ ### Patch Changes
6
+
7
+ - 30c69e6: fix(provider/anthropic): warn when parallel tool use is requested with JSON tool structured output
8
+
9
+ ## 2.0.87
10
+
11
+ ### Patch Changes
12
+
13
+ - 5082ee8: fix(provider/anthropic): preserve web search citations when replaying assistant messages
14
+ - Updated dependencies [2fd6076]
15
+ - @ai-sdk/provider-utils@3.0.30
16
+
3
17
  ## 2.0.86
4
18
 
5
19
  ### Patch Changes
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "2.0.86" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.88" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -1697,6 +1697,9 @@ async function convertToAnthropicMessagesPrompt({
1697
1697
  // in pre-filled assistant responses
1698
1698
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
1699
1699
  ),
1700
+ ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
1701
+ citations: textMetadata.citations
1702
+ },
1700
1703
  cache_control: cacheControl
1701
1704
  });
1702
1705
  }
@@ -2301,6 +2304,13 @@ var AnthropicMessagesLanguageModel = class {
2301
2304
  description: "Respond with a JSON object.",
2302
2305
  inputSchema: responseFormat.schema
2303
2306
  } : void 0;
2307
+ if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
2308
+ warnings.push({
2309
+ type: "unsupported-setting",
2310
+ setting: "providerOptions",
2311
+ details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
2312
+ });
2313
+ }
2304
2314
  const cacheControlValidator = new CacheControlValidator();
2305
2315
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
2306
2316
  prompt,
@@ -2605,7 +2615,7 @@ var AnthropicMessagesLanguageModel = class {
2605
2615
  });
2606
2616
  }
2607
2617
  async doGenerate(options) {
2608
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2618
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2609
2619
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2610
2620
  ...options,
2611
2621
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2631,7 +2641,20 @@ var AnthropicMessagesLanguageModel = class {
2631
2641
  switch (part.type) {
2632
2642
  case "text": {
2633
2643
  if (!usesJsonResponseTool) {
2634
- content.push({ type: "text", text: part.text });
2644
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
2645
+ (citation) => citation.type === "web_search_result_location"
2646
+ );
2647
+ content.push({
2648
+ type: "text",
2649
+ text: part.text,
2650
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
2651
+ providerMetadata: {
2652
+ anthropic: {
2653
+ citations: webSearchCitations
2654
+ }
2655
+ }
2656
+ }
2657
+ });
2635
2658
  if (part.citations) {
2636
2659
  for (const citation of part.citations) {
2637
2660
  const source = createCitationSource(
@@ -2783,7 +2806,7 @@ var AnthropicMessagesLanguageModel = class {
2783
2806
  title: result.title,
2784
2807
  providerMetadata: {
2785
2808
  anthropic: {
2786
- pageAge: (_a = result.page_age) != null ? _a : null
2809
+ pageAge: (_b = result.page_age) != null ? _b : null
2787
2810
  }
2788
2811
  }
2789
2812
  });
@@ -2855,7 +2878,7 @@ var AnthropicMessagesLanguageModel = class {
2855
2878
  }
2856
2879
  let inputTokens;
2857
2880
  let outputTokens;
2858
- const servedByFallback = (_b = response.usage.iterations) == null ? void 0 : _b.some(
2881
+ const servedByFallback = (_c = response.usage.iterations) == null ? void 0 : _c.some(
2859
2882
  (iter) => iter.type === "fallback_message"
2860
2883
  );
2861
2884
  if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
@@ -2883,12 +2906,12 @@ var AnthropicMessagesLanguageModel = class {
2883
2906
  inputTokens,
2884
2907
  outputTokens,
2885
2908
  totalTokens: inputTokens + outputTokens,
2886
- cachedInputTokens: (_c = response.usage.cache_read_input_tokens) != null ? _c : void 0
2909
+ cachedInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : void 0
2887
2910
  },
2888
2911
  request: { body: args },
2889
2912
  response: {
2890
- id: (_d = response.id) != null ? _d : void 0,
2891
- modelId: (_e = response.model) != null ? _e : void 0,
2913
+ id: (_e = response.id) != null ? _e : void 0,
2914
+ modelId: (_f = response.model) != null ? _f : void 0,
2892
2915
  headers: responseHeaders,
2893
2916
  body: rawResponse
2894
2917
  },
@@ -2896,8 +2919,8 @@ var AnthropicMessagesLanguageModel = class {
2896
2919
  providerMetadata: {
2897
2920
  anthropic: {
2898
2921
  usage: response.usage,
2899
- cacheCreationInputTokens: (_f = response.usage.cache_creation_input_tokens) != null ? _f : null,
2900
- stopSequence: (_g = response.stop_sequence) != null ? _g : null,
2922
+ cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
2923
+ stopSequence: (_h = response.stop_sequence) != null ? _h : null,
2901
2924
  ...stopDetails != null ? { stopDetails } : {},
2902
2925
  iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
2903
2926
  type: iter.type,
@@ -2908,11 +2931,11 @@ var AnthropicMessagesLanguageModel = class {
2908
2931
  container: response.container ? {
2909
2932
  expiresAt: response.container.expires_at,
2910
2933
  id: response.container.id,
2911
- skills: (_i = (_h = response.container.skills) == null ? void 0 : _h.map((skill) => ({
2934
+ skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
2912
2935
  type: skill.type,
2913
2936
  skillId: skill.skill_id,
2914
2937
  version: skill.version
2915
- }))) != null ? _i : null
2938
+ }))) != null ? _j : null
2916
2939
  } : null,
2917
2940
  contextManagement: response.context_management ? {
2918
2941
  appliedEdits: response.context_management.applied_edits.map(
@@ -3006,7 +3029,10 @@ var AnthropicMessagesLanguageModel = class {
3006
3029
  blockType = contentBlockType;
3007
3030
  switch (contentBlockType) {
3008
3031
  case "text": {
3009
- contentBlocks[value.index] = { type: "text" };
3032
+ contentBlocks[value.index] = {
3033
+ type: "text",
3034
+ citations: []
3035
+ };
3010
3036
  controller.enqueue({
3011
3037
  type: "text-start",
3012
3038
  id: String(value.index)
@@ -3035,7 +3061,10 @@ var AnthropicMessagesLanguageModel = class {
3035
3061
  return;
3036
3062
  }
3037
3063
  case "compaction": {
3038
- contentBlocks[value.index] = { type: "text" };
3064
+ contentBlocks[value.index] = {
3065
+ type: "text",
3066
+ citations: []
3067
+ };
3039
3068
  controller.enqueue({
3040
3069
  type: "text-start",
3041
3070
  id: String(value.index),
@@ -3048,7 +3077,7 @@ var AnthropicMessagesLanguageModel = class {
3048
3077
  return;
3049
3078
  }
3050
3079
  case "tool_use": {
3051
- contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
3080
+ contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
3052
3081
  type: "tool-call",
3053
3082
  toolCallId: value.content_block.id,
3054
3083
  toolName: value.content_block.name,
@@ -3239,7 +3268,14 @@ var AnthropicMessagesLanguageModel = class {
3239
3268
  case "text": {
3240
3269
  controller.enqueue({
3241
3270
  type: "text-end",
3242
- id: String(value.index)
3271
+ id: String(value.index),
3272
+ ...contentBlock.citations.length > 0 && {
3273
+ providerMetadata: {
3274
+ anthropic: {
3275
+ citations: contentBlock.citations
3276
+ }
3277
+ }
3278
+ }
3243
3279
  });
3244
3280
  break;
3245
3281
  }
@@ -3353,6 +3389,10 @@ var AnthropicMessagesLanguageModel = class {
3353
3389
  }
3354
3390
  case "citations_delta": {
3355
3391
  const citation = value.delta.citation;
3392
+ const contentBlock = contentBlocks[value.index];
3393
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
3394
+ contentBlock.citations.push(citation);
3395
+ }
3356
3396
  const source = createCitationSource(
3357
3397
  citation,
3358
3398
  citationDocuments,