@ai-sdk/anthropic 2.0.86 → 2.0.87

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.
@@ -1707,6 +1707,9 @@ async function convertToAnthropicMessagesPrompt({
1707
1707
  // in pre-filled assistant responses
1708
1708
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
1709
1709
  ),
1710
+ ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
1711
+ citations: textMetadata.citations
1712
+ },
1710
1713
  cache_control: cacheControl
1711
1714
  });
1712
1715
  }
@@ -2615,7 +2618,7 @@ var AnthropicMessagesLanguageModel = class {
2615
2618
  });
2616
2619
  }
2617
2620
  async doGenerate(options) {
2618
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2621
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2619
2622
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2620
2623
  ...options,
2621
2624
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2641,7 +2644,20 @@ var AnthropicMessagesLanguageModel = class {
2641
2644
  switch (part.type) {
2642
2645
  case "text": {
2643
2646
  if (!usesJsonResponseTool) {
2644
- content.push({ type: "text", text: part.text });
2647
+ const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
2648
+ (citation) => citation.type === "web_search_result_location"
2649
+ );
2650
+ content.push({
2651
+ type: "text",
2652
+ text: part.text,
2653
+ ...webSearchCitations != null && webSearchCitations.length > 0 && {
2654
+ providerMetadata: {
2655
+ anthropic: {
2656
+ citations: webSearchCitations
2657
+ }
2658
+ }
2659
+ }
2660
+ });
2645
2661
  if (part.citations) {
2646
2662
  for (const citation of part.citations) {
2647
2663
  const source = createCitationSource(
@@ -2793,7 +2809,7 @@ var AnthropicMessagesLanguageModel = class {
2793
2809
  title: result.title,
2794
2810
  providerMetadata: {
2795
2811
  anthropic: {
2796
- pageAge: (_a = result.page_age) != null ? _a : null
2812
+ pageAge: (_b = result.page_age) != null ? _b : null
2797
2813
  }
2798
2814
  }
2799
2815
  });
@@ -2865,7 +2881,7 @@ var AnthropicMessagesLanguageModel = class {
2865
2881
  }
2866
2882
  let inputTokens;
2867
2883
  let outputTokens;
2868
- const servedByFallback = (_b = response.usage.iterations) == null ? void 0 : _b.some(
2884
+ const servedByFallback = (_c = response.usage.iterations) == null ? void 0 : _c.some(
2869
2885
  (iter) => iter.type === "fallback_message"
2870
2886
  );
2871
2887
  if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
@@ -2893,12 +2909,12 @@ var AnthropicMessagesLanguageModel = class {
2893
2909
  inputTokens,
2894
2910
  outputTokens,
2895
2911
  totalTokens: inputTokens + outputTokens,
2896
- cachedInputTokens: (_c = response.usage.cache_read_input_tokens) != null ? _c : void 0
2912
+ cachedInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : void 0
2897
2913
  },
2898
2914
  request: { body: args },
2899
2915
  response: {
2900
- id: (_d = response.id) != null ? _d : void 0,
2901
- modelId: (_e = response.model) != null ? _e : void 0,
2916
+ id: (_e = response.id) != null ? _e : void 0,
2917
+ modelId: (_f = response.model) != null ? _f : void 0,
2902
2918
  headers: responseHeaders,
2903
2919
  body: rawResponse
2904
2920
  },
@@ -2906,8 +2922,8 @@ var AnthropicMessagesLanguageModel = class {
2906
2922
  providerMetadata: {
2907
2923
  anthropic: {
2908
2924
  usage: response.usage,
2909
- cacheCreationInputTokens: (_f = response.usage.cache_creation_input_tokens) != null ? _f : null,
2910
- stopSequence: (_g = response.stop_sequence) != null ? _g : null,
2925
+ cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
2926
+ stopSequence: (_h = response.stop_sequence) != null ? _h : null,
2911
2927
  ...stopDetails != null ? { stopDetails } : {},
2912
2928
  iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
2913
2929
  type: iter.type,
@@ -2918,11 +2934,11 @@ var AnthropicMessagesLanguageModel = class {
2918
2934
  container: response.container ? {
2919
2935
  expiresAt: response.container.expires_at,
2920
2936
  id: response.container.id,
2921
- skills: (_i = (_h = response.container.skills) == null ? void 0 : _h.map((skill) => ({
2937
+ skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
2922
2938
  type: skill.type,
2923
2939
  skillId: skill.skill_id,
2924
2940
  version: skill.version
2925
- }))) != null ? _i : null
2941
+ }))) != null ? _j : null
2926
2942
  } : null,
2927
2943
  contextManagement: response.context_management ? {
2928
2944
  appliedEdits: response.context_management.applied_edits.map(
@@ -3016,7 +3032,10 @@ var AnthropicMessagesLanguageModel = class {
3016
3032
  blockType = contentBlockType;
3017
3033
  switch (contentBlockType) {
3018
3034
  case "text": {
3019
- contentBlocks[value.index] = { type: "text" };
3035
+ contentBlocks[value.index] = {
3036
+ type: "text",
3037
+ citations: []
3038
+ };
3020
3039
  controller.enqueue({
3021
3040
  type: "text-start",
3022
3041
  id: String(value.index)
@@ -3045,7 +3064,10 @@ var AnthropicMessagesLanguageModel = class {
3045
3064
  return;
3046
3065
  }
3047
3066
  case "compaction": {
3048
- contentBlocks[value.index] = { type: "text" };
3067
+ contentBlocks[value.index] = {
3068
+ type: "text",
3069
+ citations: []
3070
+ };
3049
3071
  controller.enqueue({
3050
3072
  type: "text-start",
3051
3073
  id: String(value.index),
@@ -3058,7 +3080,7 @@ var AnthropicMessagesLanguageModel = class {
3058
3080
  return;
3059
3081
  }
3060
3082
  case "tool_use": {
3061
- contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
3083
+ contentBlocks[value.index] = usesJsonResponseTool ? { type: "text", citations: [] } : {
3062
3084
  type: "tool-call",
3063
3085
  toolCallId: value.content_block.id,
3064
3086
  toolName: value.content_block.name,
@@ -3249,7 +3271,14 @@ var AnthropicMessagesLanguageModel = class {
3249
3271
  case "text": {
3250
3272
  controller.enqueue({
3251
3273
  type: "text-end",
3252
- id: String(value.index)
3274
+ id: String(value.index),
3275
+ ...contentBlock.citations.length > 0 && {
3276
+ providerMetadata: {
3277
+ anthropic: {
3278
+ citations: contentBlock.citations
3279
+ }
3280
+ }
3281
+ }
3253
3282
  });
3254
3283
  break;
3255
3284
  }
@@ -3363,6 +3392,10 @@ var AnthropicMessagesLanguageModel = class {
3363
3392
  }
3364
3393
  case "citations_delta": {
3365
3394
  const citation = value.delta.citation;
3395
+ const contentBlock = contentBlocks[value.index];
3396
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
3397
+ contentBlock.citations.push(citation);
3398
+ }
3366
3399
  const source = createCitationSource(
3367
3400
  citation,
3368
3401
  citationDocuments,