@ai-sdk/anthropic 4.0.78 → 4.0.79

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,18 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.79
4
+
5
+ ### Patch Changes
6
+
7
+ - 1ccc7fb: fix(anthropic): preserve tools when disabling tool calls
8
+ - c91c857: fix(anthropic): preserve failed tool search results in conversation history
9
+ - e57803c: Keep retrieved web-search sources separate from normalized inline citations on text parts and text-end events. Preserve every supported web and document citation kind in generation, streaming, and batch results, with typed AnthropicCitation and AnthropicTextProviderMetadata exports. Retain document source compatibility and web citation source fallbacks when retrieval results are unavailable.
10
+ - Updated dependencies [9667bf2]
11
+ - Updated dependencies [e57803c]
12
+ - Updated dependencies [81663cc]
13
+ - @ai-sdk/provider-utils@5.0.59
14
+ - @ai-sdk/provider@4.0.27
15
+
3
16
  ## 4.0.78
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Experimental_BatchV4, Experimental_DecisionModelV4, FilesV4, JSONObject, LanguageModelV4, ProviderV4, SkillsV4 } from "@ai-sdk/provider";
2
- import { Experimental_SandboxSession, FetchFunction, ProviderDefinedTool, Tool, ToolExecuteFunction } from "@ai-sdk/provider-utils";
2
+ import { Experimental_SandboxSession, FetchFunction, InferSchema, ProviderDefinedTool, Tool, ToolExecuteFunction } from "@ai-sdk/provider-utils";
3
3
  import { z } from "zod/v4";
4
4
  //#region src/anthropic-api.d.ts
5
5
  declare const anthropicSafeguardResultSchema: z.ZodObject<{
@@ -14,6 +14,338 @@ declare const anthropicSafeguardResultSchema: z.ZodObject<{
14
14
  }, z.core.$strip>;
15
15
  }, z.core.$strip>;
16
16
  type AnthropicSafeguardResult = z.infer<typeof anthropicSafeguardResultSchema>;
17
+ declare const anthropicResponseSchema: import("@ai-sdk/provider-utils").LazySchema<{
18
+ type: "message";
19
+ content: ({
20
+ type: "text";
21
+ text: string;
22
+ citations?: ({
23
+ type: "web_search_result_location";
24
+ cited_text: string;
25
+ url: string;
26
+ title: string | null;
27
+ encrypted_index: string;
28
+ } | {
29
+ type: "page_location";
30
+ cited_text: string;
31
+ document_index: number;
32
+ document_title: string | null;
33
+ start_page_number: number;
34
+ end_page_number: number;
35
+ file_id?: string | null | undefined;
36
+ } | {
37
+ type: "char_location";
38
+ cited_text: string;
39
+ document_index: number;
40
+ document_title: string | null;
41
+ start_char_index: number;
42
+ end_char_index: number;
43
+ file_id?: string | null | undefined;
44
+ } | {
45
+ type: "content_block_location";
46
+ cited_text: string;
47
+ document_index: number;
48
+ document_title: string | null;
49
+ start_block_index: number;
50
+ end_block_index: number;
51
+ file_id: string | null;
52
+ } | {
53
+ type: "search_result_location";
54
+ cited_text: string;
55
+ search_result_index: number;
56
+ source: string;
57
+ title: string | null;
58
+ start_block_index: number;
59
+ end_block_index: number;
60
+ })[] | null | undefined;
61
+ } | {
62
+ type: "thinking";
63
+ thinking: string;
64
+ signature: string;
65
+ } | {
66
+ type: "redacted_thinking";
67
+ data: string;
68
+ } | {
69
+ type: "compaction";
70
+ content?: string | null | undefined;
71
+ signature?: string | null | undefined;
72
+ } | {
73
+ type: "tool_use";
74
+ id: string;
75
+ name: string;
76
+ input: unknown;
77
+ caller?: {
78
+ type: "code_execution_20250825";
79
+ tool_id: string;
80
+ } | {
81
+ type: "code_execution_20260120";
82
+ tool_id: string;
83
+ } | {
84
+ type: "direct";
85
+ } | undefined;
86
+ toolset_name?: string | null | undefined;
87
+ } | {
88
+ type: "server_tool_use";
89
+ id: string;
90
+ name: string;
91
+ input?: Record<string, unknown> | null | undefined;
92
+ caller?: {
93
+ type: "code_execution_20250825";
94
+ tool_id: string;
95
+ } | {
96
+ type: "code_execution_20260120";
97
+ tool_id: string;
98
+ } | {
99
+ type: "direct";
100
+ } | undefined;
101
+ } | {
102
+ type: "mcp_tool_use";
103
+ id: string;
104
+ name: string;
105
+ input: unknown;
106
+ server_name: string;
107
+ } | {
108
+ type: "mcp_tool_result";
109
+ tool_use_id: string;
110
+ is_error: boolean;
111
+ content: string | (string | {
112
+ type: "text";
113
+ text: string;
114
+ citations?: z.core.util.JSONType[] | null | undefined;
115
+ })[];
116
+ } | {
117
+ type: "web_fetch_tool_result";
118
+ tool_use_id: string;
119
+ content: {
120
+ type: "web_fetch_result";
121
+ url: string;
122
+ retrieved_at: string | null;
123
+ content: {
124
+ type: "document";
125
+ title: string | null;
126
+ source: {
127
+ type: "base64";
128
+ media_type: "application/pdf";
129
+ data: string;
130
+ } | {
131
+ type: "text";
132
+ media_type: "text/plain";
133
+ data: string;
134
+ };
135
+ citations?: {
136
+ enabled: boolean;
137
+ } | undefined;
138
+ };
139
+ } | {
140
+ type: "web_fetch_tool_result_error";
141
+ error_code: string;
142
+ };
143
+ caller?: {
144
+ type: "code_execution_20250825";
145
+ tool_id: string;
146
+ } | {
147
+ type: "code_execution_20260120";
148
+ tool_id: string;
149
+ } | {
150
+ type: "direct";
151
+ } | undefined;
152
+ } | {
153
+ type: "web_search_tool_result";
154
+ tool_use_id: string;
155
+ content: {
156
+ type: "web_search_result";
157
+ url: string;
158
+ title: string | null;
159
+ encrypted_content: string;
160
+ page_age?: string | null | undefined;
161
+ }[] | {
162
+ type: "web_search_tool_result_error";
163
+ error_code: string;
164
+ };
165
+ caller?: {
166
+ type: "code_execution_20250825";
167
+ tool_id: string;
168
+ } | {
169
+ type: "code_execution_20260120";
170
+ tool_id: string;
171
+ } | {
172
+ type: "direct";
173
+ } | undefined;
174
+ } | {
175
+ type: "code_execution_tool_result";
176
+ tool_use_id: string;
177
+ content: {
178
+ type: "code_execution_result";
179
+ stdout: string;
180
+ stderr: string;
181
+ return_code: number;
182
+ content: {
183
+ type: "code_execution_output";
184
+ file_id: string;
185
+ }[];
186
+ } | {
187
+ type: "encrypted_code_execution_result";
188
+ encrypted_stdout: string;
189
+ stderr: string;
190
+ return_code: number;
191
+ content: {
192
+ type: "code_execution_output";
193
+ file_id: string;
194
+ }[];
195
+ } | {
196
+ type: "code_execution_tool_result_error";
197
+ error_code: string;
198
+ };
199
+ } | {
200
+ type: "bash_code_execution_tool_result";
201
+ tool_use_id: string;
202
+ content: {
203
+ type: "bash_code_execution_result";
204
+ content: {
205
+ type: "bash_code_execution_output";
206
+ file_id: string;
207
+ }[];
208
+ stdout: string;
209
+ stderr: string;
210
+ return_code: number;
211
+ } | {
212
+ type: "bash_code_execution_tool_result_error";
213
+ error_code: string;
214
+ };
215
+ } | {
216
+ type: "text_editor_code_execution_tool_result";
217
+ tool_use_id: string;
218
+ content: {
219
+ type: "text_editor_code_execution_tool_result_error";
220
+ error_code: string;
221
+ } | {
222
+ type: "text_editor_code_execution_view_result";
223
+ content: string;
224
+ file_type: string;
225
+ num_lines: number | null;
226
+ start_line: number | null;
227
+ total_lines: number | null;
228
+ } | {
229
+ type: "text_editor_code_execution_create_result";
230
+ is_file_update: boolean;
231
+ } | {
232
+ type: "text_editor_code_execution_str_replace_result";
233
+ lines: string[] | null;
234
+ new_lines: number | null;
235
+ new_start: number | null;
236
+ old_lines: number | null;
237
+ old_start: number | null;
238
+ };
239
+ } | {
240
+ type: "tool_search_tool_result";
241
+ tool_use_id: string;
242
+ content: {
243
+ type: "tool_search_tool_search_result";
244
+ tool_references: {
245
+ type: "tool_reference";
246
+ tool_name: string;
247
+ }[];
248
+ } | {
249
+ type: "tool_search_tool_result_error";
250
+ error_code: string;
251
+ };
252
+ } | {
253
+ type: "container_upload";
254
+ file_id: string;
255
+ } | {
256
+ type: "advisor_tool_result";
257
+ tool_use_id: string;
258
+ content: {
259
+ type: "advisor_result";
260
+ text: string;
261
+ stop_reason?: string | null | undefined;
262
+ } | {
263
+ type: "advisor_redacted_result";
264
+ encrypted_content: string;
265
+ stop_reason?: string | null | undefined;
266
+ } | {
267
+ type: "advisor_tool_result_error";
268
+ error_code: string;
269
+ };
270
+ } | {
271
+ type: "fallback";
272
+ from: {
273
+ model: string;
274
+ };
275
+ to: {
276
+ model: string;
277
+ };
278
+ })[];
279
+ usage: {
280
+ [x: string]: unknown;
281
+ input_tokens: number;
282
+ output_tokens: number;
283
+ output_tokens_details?: {
284
+ thinking_tokens?: number | null | undefined;
285
+ } | null | undefined;
286
+ cache_creation_input_tokens?: number | null | undefined;
287
+ cache_read_input_tokens?: number | null | undefined;
288
+ iterations?: {
289
+ type: "message" | "compaction" | "advisor_message" | "fallback_message";
290
+ input_tokens: number;
291
+ output_tokens: number;
292
+ model?: string | null | undefined;
293
+ cache_creation_input_tokens?: number | null | undefined;
294
+ cache_read_input_tokens?: number | null | undefined;
295
+ }[] | null | undefined;
296
+ };
297
+ id?: string | null | undefined;
298
+ model?: string | null | undefined;
299
+ stop_reason?: string | null | undefined;
300
+ stop_sequence?: string | null | undefined;
301
+ stop_details?: {
302
+ type: string;
303
+ category?: string | null | undefined;
304
+ explanation?: string | null | undefined;
305
+ recommended_model?: string | null | undefined;
306
+ } | null | undefined;
307
+ input_transformations?: {
308
+ type: string;
309
+ path: string;
310
+ reason: string;
311
+ }[] | null | undefined;
312
+ safeguard_results?: {
313
+ type: string;
314
+ status: {
315
+ type: string;
316
+ tool_uses?: Record<string, {
317
+ type: string;
318
+ outcome?: string | null | undefined;
319
+ explanation?: string | null | undefined;
320
+ }> | null | undefined;
321
+ };
322
+ }[] | null | undefined;
323
+ container?: {
324
+ expires_at: string;
325
+ id: string;
326
+ skills?: {
327
+ type: "custom" | "anthropic";
328
+ skill_id: string;
329
+ version: string;
330
+ }[] | null | undefined;
331
+ } | null | undefined;
332
+ context_management?: {
333
+ applied_edits: ({
334
+ type: "clear_tool_uses_20250919";
335
+ cleared_tool_uses: number;
336
+ cleared_input_tokens: number;
337
+ } | {
338
+ type: "clear_thinking_20251015";
339
+ cleared_thinking_turns: number;
340
+ cleared_input_tokens: number;
341
+ } | {
342
+ type: "compact_20260112";
343
+ })[];
344
+ } | null | undefined;
345
+ }>;
346
+ type Citation = NonNullable<(InferSchema<typeof anthropicResponseSchema>['content'][number] & {
347
+ type: 'text';
348
+ })['citations']>[number];
17
349
  //#endregion
18
350
  //#region src/anthropic-message-metadata.d.ts
19
351
  /**
@@ -219,6 +551,21 @@ interface AnthropicMessageMetadata {
219
551
  } | null;
220
552
  }
221
553
  //#endregion
554
+ //#region src/anthropic-provider-metadata.d.ts
555
+ /**
556
+ * Citation metadata returned by Anthropic for generated text.
557
+ */
558
+ type AnthropicCitation = Citation;
559
+ /**
560
+ * Anthropic provider metadata attached to generated text that contains
561
+ * citations.
562
+ */
563
+ type AnthropicTextProviderMetadata = {
564
+ anthropic: {
565
+ citations: AnthropicCitation[];
566
+ };
567
+ };
568
+ //#endregion
222
569
  //#region src/anthropic-language-model-options.d.ts
223
570
  type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-haiku-5-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
224
571
  /**
@@ -1550,5 +1897,5 @@ export declare function forwardAnthropicContainerIdFromLastStep({ steps }: {
1550
1897
  //#region src/version.d.ts
1551
1898
  export declare const VERSION: string;
1552
1899
  //#endregion
1553
- export type { AnthropicLanguageModelOptions, AnthropicLanguageModelOptions as AnthropicProviderOptions, AnthropicMessageMetadata, AnthropicProvider, AnthropicProviderSettings, AnthropicSystemMessageProviderOptions, AnthropicToolOptions, AnthropicUsageIteration };
1900
+ export type { AnthropicCitation, AnthropicLanguageModelOptions, AnthropicLanguageModelOptions as AnthropicProviderOptions, AnthropicMessageMetadata, AnthropicProvider, AnthropicProviderSettings, AnthropicSystemMessageProviderOptions, AnthropicTextProviderMetadata, AnthropicToolOptions, AnthropicUsageIteration };
1554
1901
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member","DecisionModelV4","BatchV4"],"sources":["../src/anthropic-api.ts","../src/anthropic-message-metadata.ts","../src/anthropic-language-model-options.ts","../src/anthropic-prepare-tools.ts","../src/tool/computer-toolset_20260801.ts","../src/tool/bash_20241022.ts","../src/tool/bash_20250124.ts","../src/anthropic-tools.ts","../src/anthropic-provider.ts","../src/forward-anthropic-container-id-from-last-step.ts","../src/version.ts"],"mappings":";;;;cAmrBM,gCAA8B,EAAA;;;;;;;;;;GAelC,EAAA,KAAA;KAEU,2BAA2B,EAAE,aAChC;;;;;;;;;;;;;;;;;;KCnrBG;EACV;;;;;;EAOA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;UAGe;EACf,OAAO;EACP;;;;;;;EAQA,uBAAuB;IACrB;IACA;IACA;;;;;;;;;;;;;EAcF,mBAAmB;;;;;;;;;;EAWnB;;;;;IAKE;;;;;IAMA;;;;;IAMA;;;;;;IAOA;;;;;;;;;EAUF,YAAY;;;;;;;EAQZ;;;;IAIE;;;;IAKA;;;;IAKA,QAAQ;;;;MAIN;;;;MAKA;;;;MAKA;;;;;;;;EASJ;;;;;IAKE,cAAc;;;;;;;;;MASR;;;;;MAMA;;;;;MAMA;;;;;;;;;;MAUA;;;;;MAMA;;;;;MAMA;;;;;;;;;;MAUA;;;;;;KC7NE;;;;cAwEC,uCAAqC,EAAA;;;;;;;;;;;;;;;;GA8ChD,EAAA,KAAA;KAEU,wCAAwC,EAAE,aAC7C;cAGI,+BAA6B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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0BAA0B;;;;GAIxC,SAAS,mBAAmB;;;;EAK7B,cAAc,SAAS,mBAAmB;EAE1C,KAAK,SAAS,mBAAmB;EAEjC,SAAS,SAAS,mBAAmB;;EAGrC,cAAc,SAAS,mBAAmBE;;EAE1C,gBAAgB,SAAS,mBAAmBA;IAC1C,YAAYA;;EAGd,sBAAsBC;IAAU,MAAM;;;;;EAKtC,mBAAmB;EAEnB,SAAS;;;;EAKT,UAAU;;;;EAKV,cAAc;;UAGC;;EAEf;;IAEE;;;;;;EAOF;;;;;;EAOA;;;;;;EAOA;;;;EAKA,UAAU;;;;;EAMV,QAAQ;EAER;;;;;EAMA;;;;;wBAMc,gBACd,UAAS,4BACR;;;;qBA0HU,WAAS;;;;;;;;;;wBCvPN,0CACd;EAEA,OAAO;IACL,mBAAmB,eAAe;;;EAEpB,kBAAkB,eAAe;;;;qBCdtC"}
1
+ {"version":3,"file":"index.d.ts","names":["SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member","DecisionModelV4","BatchV4"],"sources":["../src/anthropic-api.ts","../src/anthropic-message-metadata.ts","../src/anthropic-provider-metadata.ts","../src/anthropic-language-model-options.ts","../src/anthropic-prepare-tools.ts","../src/tool/computer-toolset_20260801.ts","../src/tool/bash_20241022.ts","../src/tool/bash_20250124.ts","../src/anthropic-tools.ts","../src/anthropic-provider.ts","../src/forward-anthropic-container-id-from-last-step.ts","../src/version.ts"],"mappings":";;;;cAorBM,gCAA8B,EAAA;;;;;;;;;;GAelC,EAAA,KAAA;KAEU,2BAA2B,EAAE,aAChC;cAuFI,0DAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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KA,UAAU;;;;;EAMV,QAAQ;EAER;;;;;EAMA;;;;;wBAMc,gBACd,UAAS,4BACR;;;;qBA0HU,WAAS;;;;;;;;;;wBCvPN,0CACd;EAEA,OAAO;IACL,mBAAmB,eAAe;;;EAEpB,kBAAkB,eAAe;;;;qBCdtC"}
package/dist/index.js CHANGED
@@ -64,6 +64,37 @@ var AnthropicFiles = class {
64
64
  }
65
65
  };
66
66
  //#endregion
67
+ //#region src/map-anthropic-citation.ts
68
+ function mapAnthropicCitation(citation, documents) {
69
+ if (citation.type === "web_search_result_location" || citation.type === "search_result_location") {
70
+ const url = citation.type === "web_search_result_location" ? citation.url : citation.source;
71
+ return {
72
+ source: {
73
+ type: "source",
74
+ sourceType: "url",
75
+ id: url,
76
+ url,
77
+ title: citation.title ?? void 0,
78
+ providerMetadata: { anthropic: { ...citation } }
79
+ },
80
+ citedText: citation.cited_text
81
+ };
82
+ }
83
+ const document = documents[citation.document_index];
84
+ return {
85
+ source: {
86
+ type: "source",
87
+ sourceType: "document",
88
+ id: citation.file_id ?? String(citation.document_index),
89
+ mediaType: document?.mediaType ?? "text/plain",
90
+ title: citation.document_title ?? document?.title ?? `Document ${citation.document_index}`,
91
+ filename: document?.filename,
92
+ providerMetadata: { anthropic: { ...citation } }
93
+ },
94
+ citedText: citation.cited_text
95
+ };
96
+ }
97
+ //#endregion
67
98
  //#region src/anthropic-api.ts
68
99
  const anthropicFallbackContentSchema = z.object({
69
100
  type: z.literal("fallback"),
@@ -1834,8 +1865,8 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
1834
1865
  betas
1835
1866
  };
1836
1867
  case "none": return {
1837
- tools: void 0,
1838
- toolChoice: void 0,
1868
+ tools: anthropicTools,
1869
+ toolChoice: { type: "none" },
1839
1870
  toolWarnings,
1840
1871
  betas
1841
1872
  };
@@ -3028,6 +3059,18 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
3028
3059
  }
3029
3060
  if (providerToolName === "tool_search_tool_regex" || providerToolName === "tool_search_tool_bm25") {
3030
3061
  const output = part.output;
3062
+ if (output.type === "error-json" || output.type === "json" && output.value != null && typeof output.value === "object" && !Array.isArray(output.value) && "type" in output.value && output.value.type === "tool_search_tool_result_error") {
3063
+ anthropicContent.push({
3064
+ type: "tool_search_tool_result",
3065
+ tool_use_id: part.toolCallId,
3066
+ content: {
3067
+ type: "tool_search_tool_result_error",
3068
+ error_code: extractErrorValue(output.value).errorCode ?? "unavailable"
3069
+ },
3070
+ cache_control: cacheControl
3071
+ });
3072
+ break;
3073
+ }
3031
3074
  if (output.type !== "json") {
3032
3075
  warnings.push({
3033
3076
  type: "other",
@@ -3974,16 +4017,19 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3974
4017
  const mcpToolCalls = {};
3975
4018
  const serverToolCalls = {};
3976
4019
  let isJsonResponseFromTool = false;
4020
+ const hasWebSearchResults = response.content.some((part) => part.type === "web_search_tool_result" && Array.isArray(part.content) && part.content.length > 0);
3977
4021
  for (const part of response.content) switch (part.type) {
3978
4022
  case "text":
3979
4023
  if (!usesJsonResponseTool) {
3980
- const webSearchCitations = part.citations?.filter((citation) => citation.type === "web_search_result_location");
4024
+ const citations = part.citations ?? [];
3981
4025
  content.push({
3982
4026
  type: "text",
3983
4027
  text: part.text,
3984
- ...webSearchCitations != null && webSearchCitations.length > 0 && { providerMetadata: { anthropic: { citations: webSearchCitations } } }
4028
+ ...citations.length > 0 && { citations: citations.map((citation) => mapAnthropicCitation(citation, citationDocuments)) },
4029
+ ...citations.length > 0 && { providerMetadata: { anthropic: { citations } } }
3985
4030
  });
3986
4031
  if (part.citations) for (const citation of part.citations) {
4032
+ if (citation.type === "web_search_result_location" && hasWebSearchResults) continue;
3987
4033
  const source = createCitationSource(citation, citationDocuments, this.generateId);
3988
4034
  if (source) content.push(source);
3989
4035
  }
@@ -4409,6 +4455,8 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4409
4455
  let safeguardResults;
4410
4456
  let container = null;
4411
4457
  let isJsonResponseFromTool = false;
4458
+ let hasWebSearchResults = false;
4459
+ const fallbackWebCitations = [];
4412
4460
  let isMessageOpen = false;
4413
4461
  let activeMessageId;
4414
4462
  let hasInvalidMessageSequence = false;
@@ -4675,14 +4723,17 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4675
4723
  })),
4676
4724
  ...getAnthropicCallerMetadata(part.caller)
4677
4725
  });
4678
- for (const result of part.content) controller.enqueue({
4679
- type: "source",
4680
- sourceType: "url",
4681
- id: generateId(),
4682
- url: result.url,
4683
- ...result.title != null ? { title: result.title } : {},
4684
- providerMetadata: { anthropic: { pageAge: result.page_age ?? null } }
4685
- });
4726
+ for (const result of part.content) {
4727
+ hasWebSearchResults = true;
4728
+ controller.enqueue({
4729
+ type: "source",
4730
+ sourceType: "url",
4731
+ id: generateId(),
4732
+ url: result.url,
4733
+ ...result.title != null ? { title: result.title } : {},
4734
+ providerMetadata: { anthropic: { pageAge: result.page_age ?? null } }
4735
+ });
4736
+ }
4686
4737
  } else controller.enqueue({
4687
4738
  type: "tool-result",
4688
4739
  toolCallId: part.tool_use_id,
@@ -4841,7 +4892,10 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4841
4892
  controller.enqueue({
4842
4893
  type: "text-end",
4843
4894
  id: String(value.index),
4844
- ...contentBlock.citations.length > 0 && { providerMetadata: { anthropic: { citations: contentBlock.citations } } }
4895
+ ...contentBlock.citations.length > 0 && {
4896
+ citations: contentBlock.citations.map((citation) => mapAnthropicCitation(citation, citationDocuments)),
4897
+ providerMetadata: { anthropic: { citations: contentBlock.citations } }
4898
+ }
4845
4899
  });
4846
4900
  break;
4847
4901
  case "reasoning":
@@ -4962,9 +5016,12 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4962
5016
  case "citations_delta": {
4963
5017
  const citation = value.delta.citation;
4964
5018
  const contentBlock = contentBlocks[value.index];
4965
- if (contentBlock?.type === "text" && citation.type === "web_search_result_location") contentBlock.citations.push(citation);
4966
- const source = createCitationSource(citation, citationDocuments, generateId);
4967
- if (source) controller.enqueue(source);
5019
+ if (contentBlock?.type === "text") contentBlock.citations.push(citation);
5020
+ if (citation.type === "web_search_result_location") fallbackWebCitations.push(citation);
5021
+ else {
5022
+ const source = createCitationSource(citation, citationDocuments, generateId);
5023
+ if (source) controller.enqueue(source);
5024
+ }
4968
5025
  return;
4969
5026
  }
4970
5027
  default: throw new Error(`Unsupported delta type: ${deltaType}`);
@@ -5100,6 +5157,11 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
5100
5157
  };
5101
5158
  const providerMetadata = { anthropic: anthropicMetadata };
5102
5159
  if (usedCustomProviderKey && providerOptionsName !== "anthropic") providerMetadata[providerOptionsName] = anthropicMetadata;
5160
+ if (!hasWebSearchResults) for (const citation of fallbackWebCitations) {
5161
+ const source = createCitationSource(citation, citationDocuments, generateId);
5162
+ if (source) controller.enqueue(source);
5163
+ }
5164
+ fallbackWebCitations.length = 0;
5103
5165
  controller.enqueue({
5104
5166
  type: "finish",
5105
5167
  finishReason,
@@ -5857,17 +5919,19 @@ function convertAnthropicBatchResponse(response, generateId) {
5857
5919
  const content = [];
5858
5920
  const mcpToolCalls = {};
5859
5921
  const serverToolCalls = {};
5922
+ const hasWebSearchResults = response.content.some((part) => part.type === "web_search_tool_result" && Array.isArray(part.content) && part.content.length > 0);
5860
5923
  for (const part of response.content) switch (part.type) {
5861
5924
  case "text":
5862
5925
  const citations = part.citations;
5863
5926
  content.push({
5864
5927
  type: "text",
5865
5928
  text: part.text,
5929
+ ...citations != null && citations.length > 0 && { citations: citations.map((citation) => mapAnthropicCitation(citation, [])) },
5866
5930
  ...citations != null && citations.length > 0 && { providerMetadata: { anthropic: { citations } } }
5867
5931
  });
5868
- for (const citation of part.citations ?? []) {
5932
+ for (const citation of part.citations ?? []) if (citation.type === "web_search_result_location" && !hasWebSearchResults) {
5869
5933
  const source = createCitationSource(citation, [], generateId);
5870
- if (source != null) content.push(source);
5934
+ if (source) content.push(source);
5871
5935
  }
5872
5936
  break;
5873
5937
  case "thinking":
@@ -6869,7 +6933,7 @@ var AnthropicSkills = class {
6869
6933
  };
6870
6934
  //#endregion
6871
6935
  //#region src/version.ts
6872
- const VERSION = "4.0.78";
6936
+ const VERSION = "4.0.79";
6873
6937
  //#endregion
6874
6938
  //#region src/anthropic-provider.ts
6875
6939
  const ANTHROPIC_API_URL = "https://api.anthropic.com";