@ai-sdk/anthropic 4.0.78 → 4.0.80

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,27 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.80
4
+
5
+ ### Patch Changes
6
+
7
+ - 40d0aec: feat(vertex-anthropic): forward 'providerOptions.vertex.labels' as a header
8
+ - 40a4ce1: Fall back to automatic tool choice with a warning when manual thinking is enabled with a required or named tool choice, avoiding an Anthropic API 400 error. Named tool choices send only the selected tool.
9
+ - Updated dependencies [2e89fa4]
10
+ - @ai-sdk/provider-utils@5.0.60
11
+
12
+ ## 4.0.79
13
+
14
+ ### Patch Changes
15
+
16
+ - 1ccc7fb: fix(anthropic): preserve tools when disabling tool calls
17
+ - c91c857: fix(anthropic): preserve failed tool search results in conversation history
18
+ - 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.
19
+ - Updated dependencies [9667bf2]
20
+ - Updated dependencies [e57803c]
21
+ - Updated dependencies [81663cc]
22
+ - @ai-sdk/provider-utils@5.0.59
23
+ - @ai-sdk/provider@4.0.27
24
+
3
25
  ## 4.0.78
4
26
 
5
27
  ### 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;;;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;;;;;;;;;;;;MAQP;MACF;MACJ;MAEwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAJlB;MACF;MACJ;MAEwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAHxB;MACA;MAEa;MACK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UCJJ,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,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S,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"}
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"),
@@ -1812,7 +1843,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
1812
1843
  toolWarnings.push({
1813
1844
  type: "unsupported",
1814
1845
  feature: "toolChoice",
1815
- details: "toolChoice 'required' is not supported by this model because it rejects forced tool use. Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made."
1846
+ details: "toolChoice 'required' is not supported with this model or thinking configuration. Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made."
1816
1847
  });
1817
1848
  return {
1818
1849
  tools: anthropicTools,
@@ -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
  };
@@ -1844,7 +1875,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
1844
1875
  toolWarnings.push({
1845
1876
  type: "unsupported",
1846
1877
  feature: "toolChoice",
1847
- details: `toolChoice 'tool' is not supported by this model because it rejects forced tool use. Only the '${toolChoice.toolName}' tool is sent with 'auto' tool choice. Instruct the model to use the tool in the prompt and verify that a tool call was made.`
1878
+ details: `toolChoice 'tool' is not supported with this model or thinking configuration. Only the '${toolChoice.toolName}' tool is sent with 'auto' tool choice. Instruct the model to use the tool in the prompt and verify that a tool call was made.`
1848
1879
  });
1849
1880
  return {
1850
1881
  tools: anthropicTools.filter((tool) => "name" in tool && tool.name === toolChoice.toolName),
@@ -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",
@@ -3878,7 +3921,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3878
3921
  supportsStructuredOutput: false,
3879
3922
  supportsStrictTools,
3880
3923
  defaultEagerInputStreaming,
3881
- rejectsForcedToolUse
3924
+ rejectsForcedToolUse: rejectsForcedToolUse || thinkingType === "enabled"
3882
3925
  } : {
3883
3926
  tools: tools ?? [],
3884
3927
  toolChoice,
@@ -3887,7 +3930,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3887
3930
  supportsStructuredOutput,
3888
3931
  supportsStrictTools,
3889
3932
  defaultEagerInputStreaming,
3890
- rejectsForcedToolUse
3933
+ rejectsForcedToolUse: rejectsForcedToolUse || thinkingType === "enabled"
3891
3934
  });
3892
3935
  const cacheWarnings = cacheControlValidator.getWarnings();
3893
3936
  return {
@@ -3921,8 +3964,9 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3921
3964
  options
3922
3965
  });
3923
3966
  }
3924
- async getHeaders({ betas, headers }) {
3925
- return combineHeaders(this.config.headers ? await resolve(this.config.headers) : void 0, headers, betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {});
3967
+ async getHeaders({ betas, headers, providerOptions }) {
3968
+ const combinedHeaders = combineHeaders(this.config.headers ? await resolve(this.config.headers) : void 0, headers, betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {});
3969
+ return this.config.transformRequestHeaders ? this.config.transformRequestHeaders(combinedHeaders, providerOptions) : combinedHeaders;
3926
3970
  }
3927
3971
  async getBetasFromHeaders(requestHeaders) {
3928
3972
  const configBetaHeader = (this.config.headers ? await resolve(this.config.headers) : void 0)?.["anthropic-beta"] ?? "";
@@ -3962,7 +4006,8 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3962
4006
  url: this.buildRequestUrl(false),
3963
4007
  headers: await this.getHeaders({
3964
4008
  betas,
3965
- headers: options.headers
4009
+ headers: options.headers,
4010
+ providerOptions: options.providerOptions
3966
4011
  }),
3967
4012
  body: this.transformRequestBody(args, betas),
3968
4013
  failedResponseHandler: anthropicFailedResponseHandler,
@@ -3974,16 +4019,19 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3974
4019
  const mcpToolCalls = {};
3975
4020
  const serverToolCalls = {};
3976
4021
  let isJsonResponseFromTool = false;
4022
+ const hasWebSearchResults = response.content.some((part) => part.type === "web_search_tool_result" && Array.isArray(part.content) && part.content.length > 0);
3977
4023
  for (const part of response.content) switch (part.type) {
3978
4024
  case "text":
3979
4025
  if (!usesJsonResponseTool) {
3980
- const webSearchCitations = part.citations?.filter((citation) => citation.type === "web_search_result_location");
4026
+ const citations = part.citations ?? [];
3981
4027
  content.push({
3982
4028
  type: "text",
3983
4029
  text: part.text,
3984
- ...webSearchCitations != null && webSearchCitations.length > 0 && { providerMetadata: { anthropic: { citations: webSearchCitations } } }
4030
+ ...citations.length > 0 && { citations: citations.map((citation) => mapAnthropicCitation(citation, citationDocuments)) },
4031
+ ...citations.length > 0 && { providerMetadata: { anthropic: { citations } } }
3985
4032
  });
3986
4033
  if (part.citations) for (const citation of part.citations) {
4034
+ if (citation.type === "web_search_result_location" && hasWebSearchResults) continue;
3987
4035
  const source = createCitationSource(citation, citationDocuments, this.generateId);
3988
4036
  if (source) content.push(source);
3989
4037
  }
@@ -4379,7 +4427,8 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4379
4427
  url,
4380
4428
  headers: await this.getHeaders({
4381
4429
  betas,
4382
- headers: options.headers
4430
+ headers: options.headers,
4431
+ providerOptions: options.providerOptions
4383
4432
  }),
4384
4433
  body: this.transformRequestBody(body, betas),
4385
4434
  failedResponseHandler: anthropicFailedResponseHandler,
@@ -4409,6 +4458,8 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4409
4458
  let safeguardResults;
4410
4459
  let container = null;
4411
4460
  let isJsonResponseFromTool = false;
4461
+ let hasWebSearchResults = false;
4462
+ const fallbackWebCitations = [];
4412
4463
  let isMessageOpen = false;
4413
4464
  let activeMessageId;
4414
4465
  let hasInvalidMessageSequence = false;
@@ -4675,14 +4726,17 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4675
4726
  })),
4676
4727
  ...getAnthropicCallerMetadata(part.caller)
4677
4728
  });
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
- });
4729
+ for (const result of part.content) {
4730
+ hasWebSearchResults = true;
4731
+ controller.enqueue({
4732
+ type: "source",
4733
+ sourceType: "url",
4734
+ id: generateId(),
4735
+ url: result.url,
4736
+ ...result.title != null ? { title: result.title } : {},
4737
+ providerMetadata: { anthropic: { pageAge: result.page_age ?? null } }
4738
+ });
4739
+ }
4686
4740
  } else controller.enqueue({
4687
4741
  type: "tool-result",
4688
4742
  toolCallId: part.tool_use_id,
@@ -4841,7 +4895,10 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4841
4895
  controller.enqueue({
4842
4896
  type: "text-end",
4843
4897
  id: String(value.index),
4844
- ...contentBlock.citations.length > 0 && { providerMetadata: { anthropic: { citations: contentBlock.citations } } }
4898
+ ...contentBlock.citations.length > 0 && {
4899
+ citations: contentBlock.citations.map((citation) => mapAnthropicCitation(citation, citationDocuments)),
4900
+ providerMetadata: { anthropic: { citations: contentBlock.citations } }
4901
+ }
4845
4902
  });
4846
4903
  break;
4847
4904
  case "reasoning":
@@ -4962,9 +5019,12 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
4962
5019
  case "citations_delta": {
4963
5020
  const citation = value.delta.citation;
4964
5021
  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);
5022
+ if (contentBlock?.type === "text") contentBlock.citations.push(citation);
5023
+ if (citation.type === "web_search_result_location") fallbackWebCitations.push(citation);
5024
+ else {
5025
+ const source = createCitationSource(citation, citationDocuments, generateId);
5026
+ if (source) controller.enqueue(source);
5027
+ }
4968
5028
  return;
4969
5029
  }
4970
5030
  default: throw new Error(`Unsupported delta type: ${deltaType}`);
@@ -5100,6 +5160,11 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
5100
5160
  };
5101
5161
  const providerMetadata = { anthropic: anthropicMetadata };
5102
5162
  if (usedCustomProviderKey && providerOptionsName !== "anthropic") providerMetadata[providerOptionsName] = anthropicMetadata;
5163
+ if (!hasWebSearchResults) for (const citation of fallbackWebCitations) {
5164
+ const source = createCitationSource(citation, citationDocuments, generateId);
5165
+ if (source) controller.enqueue(source);
5166
+ }
5167
+ fallbackWebCitations.length = 0;
5103
5168
  controller.enqueue({
5104
5169
  type: "finish",
5105
5170
  finishReason,
@@ -5857,17 +5922,19 @@ function convertAnthropicBatchResponse(response, generateId) {
5857
5922
  const content = [];
5858
5923
  const mcpToolCalls = {};
5859
5924
  const serverToolCalls = {};
5925
+ const hasWebSearchResults = response.content.some((part) => part.type === "web_search_tool_result" && Array.isArray(part.content) && part.content.length > 0);
5860
5926
  for (const part of response.content) switch (part.type) {
5861
5927
  case "text":
5862
5928
  const citations = part.citations;
5863
5929
  content.push({
5864
5930
  type: "text",
5865
5931
  text: part.text,
5932
+ ...citations != null && citations.length > 0 && { citations: citations.map((citation) => mapAnthropicCitation(citation, [])) },
5866
5933
  ...citations != null && citations.length > 0 && { providerMetadata: { anthropic: { citations } } }
5867
5934
  });
5868
- for (const citation of part.citations ?? []) {
5935
+ for (const citation of part.citations ?? []) if (citation.type === "web_search_result_location" && !hasWebSearchResults) {
5869
5936
  const source = createCitationSource(citation, [], generateId);
5870
- if (source != null) content.push(source);
5937
+ if (source) content.push(source);
5871
5938
  }
5872
5939
  break;
5873
5940
  case "thinking":
@@ -6869,7 +6936,7 @@ var AnthropicSkills = class {
6869
6936
  };
6870
6937
  //#endregion
6871
6938
  //#region src/version.ts
6872
- const VERSION = "4.0.78";
6939
+ const VERSION = "4.0.80";
6873
6940
  //#endregion
6874
6941
  //#region src/anthropic-provider.ts
6875
6942
  const ANTHROPIC_API_URL = "https://api.anthropic.com";