@codemation/core-nodes-ocr 0.2.5 → 0.2.7

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/codemation.plugin.cjs +1153 -14470
  3. package/dist/codemation.plugin.cjs.map +1 -1
  4. package/dist/codemation.plugin.d.cts +1 -1
  5. package/dist/codemation.plugin.d.ts +1 -1
  6. package/dist/codemation.plugin.js +1193 -14509
  7. package/dist/codemation.plugin.js.map +1 -1
  8. package/dist/dist-BDgdLisG.js +5378 -0
  9. package/dist/dist-BDgdLisG.js.map +1 -0
  10. package/dist/dist-BYInIjS8.js +2246 -0
  11. package/dist/dist-BYInIjS8.js.map +1 -0
  12. package/dist/dist-BlD4pqf2.cjs +4358 -0
  13. package/dist/dist-BlD4pqf2.cjs.map +1 -0
  14. package/dist/dist-CUcwHflE.cjs +14870 -0
  15. package/dist/dist-CUcwHflE.cjs.map +1 -0
  16. package/dist/dist-DB2xMXXm.cjs +5380 -0
  17. package/dist/dist-DB2xMXXm.cjs.map +1 -0
  18. package/dist/dist-DBYFkhSG.js +14739 -0
  19. package/dist/dist-DBYFkhSG.js.map +1 -0
  20. package/dist/dist-DZfaPW8T.js +4356 -0
  21. package/dist/dist-DZfaPW8T.js.map +1 -0
  22. package/dist/dist-Zdvm5pqX.cjs +2464 -0
  23. package/dist/dist-Zdvm5pqX.cjs.map +1 -0
  24. package/dist/{index-DF2ht42F.d.ts → index-RNoZqCPr.d.ts} +30 -4
  25. package/dist/index.d.cts +23 -4
  26. package/dist/index.d.ts +1 -1
  27. package/dist/metadata.json +1 -1
  28. package/dist/{runtimeTypes-WCvsnJMY.d.cts → runtimeTypes-B6RO-Yki.d.cts} +8 -1
  29. package/dist/{token-CgF09kyP.cjs → token-Cbd8b88n.cjs} +2 -2
  30. package/dist/{token-CgF09kyP.cjs.map → token-Cbd8b88n.cjs.map} +1 -1
  31. package/dist/{token-CIu4PqRI.js → token-P-r3QR1d.js} +2 -2
  32. package/dist/{token-CIu4PqRI.js.map → token-P-r3QR1d.js.map} +1 -1
  33. package/dist/{token-util-B2kSJtEV.cjs → token-util-B2Ofk2zk.cjs} +77 -77
  34. package/dist/token-util-B2Ofk2zk.cjs.map +1 -0
  35. package/dist/{token-util-Lr5foG4r.cjs → token-util-CT85hbGe.cjs} +1 -1
  36. package/dist/{token-util-EUxa8JtH.js → token-util-CfNdwRXi.js} +77 -77
  37. package/dist/token-util-CfNdwRXi.js.map +1 -0
  38. package/dist/token-util-rTxWuZPt.js +5 -0
  39. package/package.json +2 -2
  40. package/dist/token-util-B2kSJtEV.cjs.map +0 -1
  41. package/dist/token-util-BsR6OYHz.js +0 -5
  42. package/dist/token-util-EUxa8JtH.js.map +0 -1
@@ -0,0 +1,4358 @@
1
+ const require_chunk = require('./chunk-BaqVhFee.cjs');
2
+ const require_dist = require('./dist-Zdvm5pqX.cjs');
3
+ let zod_v4 = require("zod/v4");
4
+ zod_v4 = require_chunk.__toESM(zod_v4);
5
+
6
+ //#region ../../node_modules/.pnpm/@ai-sdk+anthropic@3.0.85_zod@4.3.6/node_modules/@ai-sdk/anthropic/dist/index.mjs
7
+ var VERSION = "3.0.85";
8
+ var anthropicFailedResponseHandler = require_dist.createJsonErrorResponseHandler({
9
+ errorSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
10
+ type: zod_v4.z.literal("error"),
11
+ error: zod_v4.z.object({
12
+ type: zod_v4.z.string(),
13
+ message: zod_v4.z.string()
14
+ })
15
+ }))),
16
+ errorToMessage: (data) => data.error.message
17
+ });
18
+ var anthropicStopDetailsSchema = zod_v4.z.object({
19
+ type: zod_v4.z.string(),
20
+ category: zod_v4.z.string().nullish(),
21
+ explanation: zod_v4.z.string().nullish(),
22
+ recommended_model: zod_v4.z.string().nullish()
23
+ });
24
+ var anthropicMessagesResponseSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
25
+ type: zod_v4.z.literal("message"),
26
+ id: zod_v4.z.string().nullish(),
27
+ model: zod_v4.z.string().nullish(),
28
+ content: zod_v4.z.array(zod_v4.z.discriminatedUnion("type", [
29
+ zod_v4.z.object({
30
+ type: zod_v4.z.literal("text"),
31
+ text: zod_v4.z.string(),
32
+ citations: zod_v4.z.array(zod_v4.z.discriminatedUnion("type", [
33
+ zod_v4.z.object({
34
+ type: zod_v4.z.literal("web_search_result_location"),
35
+ cited_text: zod_v4.z.string(),
36
+ url: zod_v4.z.string(),
37
+ title: zod_v4.z.string(),
38
+ encrypted_index: zod_v4.z.string()
39
+ }),
40
+ zod_v4.z.object({
41
+ type: zod_v4.z.literal("page_location"),
42
+ cited_text: zod_v4.z.string(),
43
+ document_index: zod_v4.z.number(),
44
+ document_title: zod_v4.z.string().nullable(),
45
+ start_page_number: zod_v4.z.number(),
46
+ end_page_number: zod_v4.z.number()
47
+ }),
48
+ zod_v4.z.object({
49
+ type: zod_v4.z.literal("char_location"),
50
+ cited_text: zod_v4.z.string(),
51
+ document_index: zod_v4.z.number(),
52
+ document_title: zod_v4.z.string().nullable(),
53
+ start_char_index: zod_v4.z.number(),
54
+ end_char_index: zod_v4.z.number()
55
+ })
56
+ ])).optional()
57
+ }),
58
+ zod_v4.z.object({
59
+ type: zod_v4.z.literal("thinking"),
60
+ thinking: zod_v4.z.string(),
61
+ signature: zod_v4.z.string()
62
+ }),
63
+ zod_v4.z.object({
64
+ type: zod_v4.z.literal("redacted_thinking"),
65
+ data: zod_v4.z.string()
66
+ }),
67
+ zod_v4.z.object({
68
+ type: zod_v4.z.literal("compaction"),
69
+ content: zod_v4.z.string()
70
+ }),
71
+ zod_v4.z.object({
72
+ type: zod_v4.z.literal("tool_use"),
73
+ id: zod_v4.z.string(),
74
+ name: zod_v4.z.string(),
75
+ input: zod_v4.z.unknown(),
76
+ caller: zod_v4.z.union([
77
+ zod_v4.z.object({
78
+ type: zod_v4.z.literal("code_execution_20250825"),
79
+ tool_id: zod_v4.z.string()
80
+ }),
81
+ zod_v4.z.object({
82
+ type: zod_v4.z.literal("code_execution_20260120"),
83
+ tool_id: zod_v4.z.string()
84
+ }),
85
+ zod_v4.z.object({ type: zod_v4.z.literal("direct") })
86
+ ]).optional()
87
+ }),
88
+ zod_v4.z.object({
89
+ type: zod_v4.z.literal("server_tool_use"),
90
+ id: zod_v4.z.string(),
91
+ name: zod_v4.z.string(),
92
+ input: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown()).nullish(),
93
+ caller: zod_v4.z.union([zod_v4.z.object({
94
+ type: zod_v4.z.literal("code_execution_20260120"),
95
+ tool_id: zod_v4.z.string()
96
+ }), zod_v4.z.object({ type: zod_v4.z.literal("direct") })]).optional()
97
+ }),
98
+ zod_v4.z.object({
99
+ type: zod_v4.z.literal("mcp_tool_use"),
100
+ id: zod_v4.z.string(),
101
+ name: zod_v4.z.string(),
102
+ input: zod_v4.z.unknown(),
103
+ server_name: zod_v4.z.string()
104
+ }),
105
+ zod_v4.z.object({
106
+ type: zod_v4.z.literal("mcp_tool_result"),
107
+ tool_use_id: zod_v4.z.string(),
108
+ is_error: zod_v4.z.boolean(),
109
+ content: zod_v4.z.array(zod_v4.z.union([zod_v4.z.string(), zod_v4.z.object({
110
+ type: zod_v4.z.literal("text"),
111
+ text: zod_v4.z.string()
112
+ })]))
113
+ }),
114
+ zod_v4.z.object({
115
+ type: zod_v4.z.literal("web_fetch_tool_result"),
116
+ tool_use_id: zod_v4.z.string(),
117
+ content: zod_v4.z.union([zod_v4.z.object({
118
+ type: zod_v4.z.literal("web_fetch_result"),
119
+ url: zod_v4.z.string(),
120
+ retrieved_at: zod_v4.z.string(),
121
+ content: zod_v4.z.object({
122
+ type: zod_v4.z.literal("document"),
123
+ title: zod_v4.z.string().nullable(),
124
+ citations: zod_v4.z.object({ enabled: zod_v4.z.boolean() }).optional(),
125
+ source: zod_v4.z.union([zod_v4.z.object({
126
+ type: zod_v4.z.literal("base64"),
127
+ media_type: zod_v4.z.literal("application/pdf"),
128
+ data: zod_v4.z.string()
129
+ }), zod_v4.z.object({
130
+ type: zod_v4.z.literal("text"),
131
+ media_type: zod_v4.z.literal("text/plain"),
132
+ data: zod_v4.z.string()
133
+ })])
134
+ })
135
+ }), zod_v4.z.object({
136
+ type: zod_v4.z.literal("web_fetch_tool_result_error"),
137
+ error_code: zod_v4.z.string()
138
+ })])
139
+ }),
140
+ zod_v4.z.object({
141
+ type: zod_v4.z.literal("web_search_tool_result"),
142
+ tool_use_id: zod_v4.z.string(),
143
+ content: zod_v4.z.union([zod_v4.z.array(zod_v4.z.object({
144
+ type: zod_v4.z.literal("web_search_result"),
145
+ url: zod_v4.z.string(),
146
+ title: zod_v4.z.string(),
147
+ encrypted_content: zod_v4.z.string(),
148
+ page_age: zod_v4.z.string().nullish()
149
+ })), zod_v4.z.object({
150
+ type: zod_v4.z.literal("web_search_tool_result_error"),
151
+ error_code: zod_v4.z.string()
152
+ })])
153
+ }),
154
+ zod_v4.z.object({
155
+ type: zod_v4.z.literal("code_execution_tool_result"),
156
+ tool_use_id: zod_v4.z.string(),
157
+ content: zod_v4.z.union([
158
+ zod_v4.z.object({
159
+ type: zod_v4.z.literal("code_execution_result"),
160
+ stdout: zod_v4.z.string(),
161
+ stderr: zod_v4.z.string(),
162
+ return_code: zod_v4.z.number(),
163
+ content: zod_v4.z.array(zod_v4.z.object({
164
+ type: zod_v4.z.literal("code_execution_output"),
165
+ file_id: zod_v4.z.string()
166
+ })).optional().default([])
167
+ }),
168
+ zod_v4.z.object({
169
+ type: zod_v4.z.literal("encrypted_code_execution_result"),
170
+ encrypted_stdout: zod_v4.z.string(),
171
+ stderr: zod_v4.z.string(),
172
+ return_code: zod_v4.z.number(),
173
+ content: zod_v4.z.array(zod_v4.z.object({
174
+ type: zod_v4.z.literal("code_execution_output"),
175
+ file_id: zod_v4.z.string()
176
+ })).optional().default([])
177
+ }),
178
+ zod_v4.z.object({
179
+ type: zod_v4.z.literal("code_execution_tool_result_error"),
180
+ error_code: zod_v4.z.string()
181
+ })
182
+ ])
183
+ }),
184
+ zod_v4.z.object({
185
+ type: zod_v4.z.literal("bash_code_execution_tool_result"),
186
+ tool_use_id: zod_v4.z.string(),
187
+ content: zod_v4.z.discriminatedUnion("type", [zod_v4.z.object({
188
+ type: zod_v4.z.literal("bash_code_execution_result"),
189
+ content: zod_v4.z.array(zod_v4.z.object({
190
+ type: zod_v4.z.literal("bash_code_execution_output"),
191
+ file_id: zod_v4.z.string()
192
+ })),
193
+ stdout: zod_v4.z.string(),
194
+ stderr: zod_v4.z.string(),
195
+ return_code: zod_v4.z.number()
196
+ }), zod_v4.z.object({
197
+ type: zod_v4.z.literal("bash_code_execution_tool_result_error"),
198
+ error_code: zod_v4.z.string()
199
+ })])
200
+ }),
201
+ zod_v4.z.object({
202
+ type: zod_v4.z.literal("text_editor_code_execution_tool_result"),
203
+ tool_use_id: zod_v4.z.string(),
204
+ content: zod_v4.z.discriminatedUnion("type", [
205
+ zod_v4.z.object({
206
+ type: zod_v4.z.literal("text_editor_code_execution_tool_result_error"),
207
+ error_code: zod_v4.z.string()
208
+ }),
209
+ zod_v4.z.object({
210
+ type: zod_v4.z.literal("text_editor_code_execution_view_result"),
211
+ content: zod_v4.z.string(),
212
+ file_type: zod_v4.z.string(),
213
+ num_lines: zod_v4.z.number().nullable(),
214
+ start_line: zod_v4.z.number().nullable(),
215
+ total_lines: zod_v4.z.number().nullable()
216
+ }),
217
+ zod_v4.z.object({
218
+ type: zod_v4.z.literal("text_editor_code_execution_create_result"),
219
+ is_file_update: zod_v4.z.boolean()
220
+ }),
221
+ zod_v4.z.object({
222
+ type: zod_v4.z.literal("text_editor_code_execution_str_replace_result"),
223
+ lines: zod_v4.z.array(zod_v4.z.string()).nullable(),
224
+ new_lines: zod_v4.z.number().nullable(),
225
+ new_start: zod_v4.z.number().nullable(),
226
+ old_lines: zod_v4.z.number().nullable(),
227
+ old_start: zod_v4.z.number().nullable()
228
+ })
229
+ ])
230
+ }),
231
+ zod_v4.z.object({
232
+ type: zod_v4.z.literal("tool_search_tool_result"),
233
+ tool_use_id: zod_v4.z.string(),
234
+ content: zod_v4.z.union([zod_v4.z.object({
235
+ type: zod_v4.z.literal("tool_search_tool_search_result"),
236
+ tool_references: zod_v4.z.array(zod_v4.z.object({
237
+ type: zod_v4.z.literal("tool_reference"),
238
+ tool_name: zod_v4.z.string()
239
+ }))
240
+ }), zod_v4.z.object({
241
+ type: zod_v4.z.literal("tool_search_tool_result_error"),
242
+ error_code: zod_v4.z.string()
243
+ })])
244
+ }),
245
+ zod_v4.z.object({
246
+ type: zod_v4.z.literal("advisor_tool_result"),
247
+ tool_use_id: zod_v4.z.string(),
248
+ content: zod_v4.z.discriminatedUnion("type", [
249
+ zod_v4.z.object({
250
+ type: zod_v4.z.literal("advisor_result"),
251
+ text: zod_v4.z.string()
252
+ }),
253
+ zod_v4.z.object({
254
+ type: zod_v4.z.literal("advisor_redacted_result"),
255
+ encrypted_content: zod_v4.z.string()
256
+ }),
257
+ zod_v4.z.object({
258
+ type: zod_v4.z.literal("advisor_tool_result_error"),
259
+ error_code: zod_v4.z.string()
260
+ })
261
+ ])
262
+ }),
263
+ zod_v4.z.object({ type: zod_v4.z.literal("fallback") })
264
+ ])),
265
+ stop_reason: zod_v4.z.string().nullish(),
266
+ stop_sequence: zod_v4.z.string().nullish(),
267
+ stop_details: anthropicStopDetailsSchema.nullish(),
268
+ usage: zod_v4.z.looseObject({
269
+ input_tokens: zod_v4.z.number(),
270
+ output_tokens: zod_v4.z.number(),
271
+ cache_creation_input_tokens: zod_v4.z.number().nullish(),
272
+ cache_read_input_tokens: zod_v4.z.number().nullish(),
273
+ iterations: zod_v4.z.array(zod_v4.z.object({
274
+ type: zod_v4.z.union([
275
+ zod_v4.z.literal("compaction"),
276
+ zod_v4.z.literal("message"),
277
+ zod_v4.z.literal("advisor_message"),
278
+ zod_v4.z.literal("fallback_message")
279
+ ]),
280
+ model: zod_v4.z.string().nullish(),
281
+ input_tokens: zod_v4.z.number(),
282
+ output_tokens: zod_v4.z.number(),
283
+ cache_creation_input_tokens: zod_v4.z.number().nullish(),
284
+ cache_read_input_tokens: zod_v4.z.number().nullish()
285
+ })).nullish()
286
+ }),
287
+ container: zod_v4.z.object({
288
+ expires_at: zod_v4.z.string(),
289
+ id: zod_v4.z.string(),
290
+ skills: zod_v4.z.array(zod_v4.z.object({
291
+ type: zod_v4.z.union([zod_v4.z.literal("anthropic"), zod_v4.z.literal("custom")]),
292
+ skill_id: zod_v4.z.string(),
293
+ version: zod_v4.z.string()
294
+ })).nullish()
295
+ }).nullish(),
296
+ context_management: zod_v4.z.object({ applied_edits: zod_v4.z.array(zod_v4.z.union([
297
+ zod_v4.z.object({
298
+ type: zod_v4.z.literal("clear_tool_uses_20250919"),
299
+ cleared_tool_uses: zod_v4.z.number(),
300
+ cleared_input_tokens: zod_v4.z.number()
301
+ }),
302
+ zod_v4.z.object({
303
+ type: zod_v4.z.literal("clear_thinking_20251015"),
304
+ cleared_thinking_turns: zod_v4.z.number(),
305
+ cleared_input_tokens: zod_v4.z.number()
306
+ }),
307
+ zod_v4.z.object({ type: zod_v4.z.literal("compact_20260112") })
308
+ ])) }).nullish()
309
+ })));
310
+ var anthropicMessagesChunkSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.discriminatedUnion("type", [
311
+ zod_v4.z.object({
312
+ type: zod_v4.z.literal("message_start"),
313
+ message: zod_v4.z.object({
314
+ id: zod_v4.z.string().nullish(),
315
+ model: zod_v4.z.string().nullish(),
316
+ role: zod_v4.z.string().nullish(),
317
+ usage: zod_v4.z.looseObject({
318
+ input_tokens: zod_v4.z.number(),
319
+ cache_creation_input_tokens: zod_v4.z.number().nullish(),
320
+ cache_read_input_tokens: zod_v4.z.number().nullish()
321
+ }),
322
+ content: zod_v4.z.array(zod_v4.z.discriminatedUnion("type", [zod_v4.z.object({
323
+ type: zod_v4.z.literal("tool_use"),
324
+ id: zod_v4.z.string(),
325
+ name: zod_v4.z.string(),
326
+ input: zod_v4.z.unknown(),
327
+ caller: zod_v4.z.union([
328
+ zod_v4.z.object({
329
+ type: zod_v4.z.literal("code_execution_20250825"),
330
+ tool_id: zod_v4.z.string()
331
+ }),
332
+ zod_v4.z.object({
333
+ type: zod_v4.z.literal("code_execution_20260120"),
334
+ tool_id: zod_v4.z.string()
335
+ }),
336
+ zod_v4.z.object({ type: zod_v4.z.literal("direct") })
337
+ ]).optional()
338
+ })])).nullish(),
339
+ stop_reason: zod_v4.z.string().nullish(),
340
+ container: zod_v4.z.object({
341
+ expires_at: zod_v4.z.string(),
342
+ id: zod_v4.z.string()
343
+ }).nullish()
344
+ })
345
+ }),
346
+ zod_v4.z.object({
347
+ type: zod_v4.z.literal("content_block_start"),
348
+ index: zod_v4.z.number(),
349
+ content_block: zod_v4.z.discriminatedUnion("type", [
350
+ zod_v4.z.object({
351
+ type: zod_v4.z.literal("text"),
352
+ text: zod_v4.z.string()
353
+ }),
354
+ zod_v4.z.object({
355
+ type: zod_v4.z.literal("thinking"),
356
+ thinking: zod_v4.z.string()
357
+ }),
358
+ zod_v4.z.object({
359
+ type: zod_v4.z.literal("tool_use"),
360
+ id: zod_v4.z.string(),
361
+ name: zod_v4.z.string(),
362
+ input: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown()).optional(),
363
+ caller: zod_v4.z.union([
364
+ zod_v4.z.object({
365
+ type: zod_v4.z.literal("code_execution_20250825"),
366
+ tool_id: zod_v4.z.string()
367
+ }),
368
+ zod_v4.z.object({
369
+ type: zod_v4.z.literal("code_execution_20260120"),
370
+ tool_id: zod_v4.z.string()
371
+ }),
372
+ zod_v4.z.object({ type: zod_v4.z.literal("direct") })
373
+ ]).optional()
374
+ }),
375
+ zod_v4.z.object({
376
+ type: zod_v4.z.literal("redacted_thinking"),
377
+ data: zod_v4.z.string()
378
+ }),
379
+ zod_v4.z.object({
380
+ type: zod_v4.z.literal("compaction"),
381
+ content: zod_v4.z.string().nullish()
382
+ }),
383
+ zod_v4.z.object({
384
+ type: zod_v4.z.literal("server_tool_use"),
385
+ id: zod_v4.z.string(),
386
+ name: zod_v4.z.string(),
387
+ input: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown()).nullish(),
388
+ caller: zod_v4.z.union([zod_v4.z.object({
389
+ type: zod_v4.z.literal("code_execution_20260120"),
390
+ tool_id: zod_v4.z.string()
391
+ }), zod_v4.z.object({ type: zod_v4.z.literal("direct") })]).optional()
392
+ }),
393
+ zod_v4.z.object({
394
+ type: zod_v4.z.literal("mcp_tool_use"),
395
+ id: zod_v4.z.string(),
396
+ name: zod_v4.z.string(),
397
+ input: zod_v4.z.unknown(),
398
+ server_name: zod_v4.z.string()
399
+ }),
400
+ zod_v4.z.object({
401
+ type: zod_v4.z.literal("mcp_tool_result"),
402
+ tool_use_id: zod_v4.z.string(),
403
+ is_error: zod_v4.z.boolean(),
404
+ content: zod_v4.z.array(zod_v4.z.union([zod_v4.z.string(), zod_v4.z.object({
405
+ type: zod_v4.z.literal("text"),
406
+ text: zod_v4.z.string()
407
+ })]))
408
+ }),
409
+ zod_v4.z.object({
410
+ type: zod_v4.z.literal("web_fetch_tool_result"),
411
+ tool_use_id: zod_v4.z.string(),
412
+ content: zod_v4.z.union([zod_v4.z.object({
413
+ type: zod_v4.z.literal("web_fetch_result"),
414
+ url: zod_v4.z.string(),
415
+ retrieved_at: zod_v4.z.string(),
416
+ content: zod_v4.z.object({
417
+ type: zod_v4.z.literal("document"),
418
+ title: zod_v4.z.string().nullable(),
419
+ citations: zod_v4.z.object({ enabled: zod_v4.z.boolean() }).optional(),
420
+ source: zod_v4.z.union([zod_v4.z.object({
421
+ type: zod_v4.z.literal("base64"),
422
+ media_type: zod_v4.z.literal("application/pdf"),
423
+ data: zod_v4.z.string()
424
+ }), zod_v4.z.object({
425
+ type: zod_v4.z.literal("text"),
426
+ media_type: zod_v4.z.literal("text/plain"),
427
+ data: zod_v4.z.string()
428
+ })])
429
+ })
430
+ }), zod_v4.z.object({
431
+ type: zod_v4.z.literal("web_fetch_tool_result_error"),
432
+ error_code: zod_v4.z.string()
433
+ })])
434
+ }),
435
+ zod_v4.z.object({
436
+ type: zod_v4.z.literal("web_search_tool_result"),
437
+ tool_use_id: zod_v4.z.string(),
438
+ content: zod_v4.z.union([zod_v4.z.array(zod_v4.z.object({
439
+ type: zod_v4.z.literal("web_search_result"),
440
+ url: zod_v4.z.string(),
441
+ title: zod_v4.z.string(),
442
+ encrypted_content: zod_v4.z.string(),
443
+ page_age: zod_v4.z.string().nullish()
444
+ })), zod_v4.z.object({
445
+ type: zod_v4.z.literal("web_search_tool_result_error"),
446
+ error_code: zod_v4.z.string()
447
+ })])
448
+ }),
449
+ zod_v4.z.object({
450
+ type: zod_v4.z.literal("code_execution_tool_result"),
451
+ tool_use_id: zod_v4.z.string(),
452
+ content: zod_v4.z.union([
453
+ zod_v4.z.object({
454
+ type: zod_v4.z.literal("code_execution_result"),
455
+ stdout: zod_v4.z.string(),
456
+ stderr: zod_v4.z.string(),
457
+ return_code: zod_v4.z.number(),
458
+ content: zod_v4.z.array(zod_v4.z.object({
459
+ type: zod_v4.z.literal("code_execution_output"),
460
+ file_id: zod_v4.z.string()
461
+ })).optional().default([])
462
+ }),
463
+ zod_v4.z.object({
464
+ type: zod_v4.z.literal("encrypted_code_execution_result"),
465
+ encrypted_stdout: zod_v4.z.string(),
466
+ stderr: zod_v4.z.string(),
467
+ return_code: zod_v4.z.number(),
468
+ content: zod_v4.z.array(zod_v4.z.object({
469
+ type: zod_v4.z.literal("code_execution_output"),
470
+ file_id: zod_v4.z.string()
471
+ })).optional().default([])
472
+ }),
473
+ zod_v4.z.object({
474
+ type: zod_v4.z.literal("code_execution_tool_result_error"),
475
+ error_code: zod_v4.z.string()
476
+ })
477
+ ])
478
+ }),
479
+ zod_v4.z.object({
480
+ type: zod_v4.z.literal("bash_code_execution_tool_result"),
481
+ tool_use_id: zod_v4.z.string(),
482
+ content: zod_v4.z.discriminatedUnion("type", [zod_v4.z.object({
483
+ type: zod_v4.z.literal("bash_code_execution_result"),
484
+ content: zod_v4.z.array(zod_v4.z.object({
485
+ type: zod_v4.z.literal("bash_code_execution_output"),
486
+ file_id: zod_v4.z.string()
487
+ })),
488
+ stdout: zod_v4.z.string(),
489
+ stderr: zod_v4.z.string(),
490
+ return_code: zod_v4.z.number()
491
+ }), zod_v4.z.object({
492
+ type: zod_v4.z.literal("bash_code_execution_tool_result_error"),
493
+ error_code: zod_v4.z.string()
494
+ })])
495
+ }),
496
+ zod_v4.z.object({
497
+ type: zod_v4.z.literal("text_editor_code_execution_tool_result"),
498
+ tool_use_id: zod_v4.z.string(),
499
+ content: zod_v4.z.discriminatedUnion("type", [
500
+ zod_v4.z.object({
501
+ type: zod_v4.z.literal("text_editor_code_execution_tool_result_error"),
502
+ error_code: zod_v4.z.string()
503
+ }),
504
+ zod_v4.z.object({
505
+ type: zod_v4.z.literal("text_editor_code_execution_view_result"),
506
+ content: zod_v4.z.string(),
507
+ file_type: zod_v4.z.string(),
508
+ num_lines: zod_v4.z.number().nullable(),
509
+ start_line: zod_v4.z.number().nullable(),
510
+ total_lines: zod_v4.z.number().nullable()
511
+ }),
512
+ zod_v4.z.object({
513
+ type: zod_v4.z.literal("text_editor_code_execution_create_result"),
514
+ is_file_update: zod_v4.z.boolean()
515
+ }),
516
+ zod_v4.z.object({
517
+ type: zod_v4.z.literal("text_editor_code_execution_str_replace_result"),
518
+ lines: zod_v4.z.array(zod_v4.z.string()).nullable(),
519
+ new_lines: zod_v4.z.number().nullable(),
520
+ new_start: zod_v4.z.number().nullable(),
521
+ old_lines: zod_v4.z.number().nullable(),
522
+ old_start: zod_v4.z.number().nullable()
523
+ })
524
+ ])
525
+ }),
526
+ zod_v4.z.object({
527
+ type: zod_v4.z.literal("tool_search_tool_result"),
528
+ tool_use_id: zod_v4.z.string(),
529
+ content: zod_v4.z.union([zod_v4.z.object({
530
+ type: zod_v4.z.literal("tool_search_tool_search_result"),
531
+ tool_references: zod_v4.z.array(zod_v4.z.object({
532
+ type: zod_v4.z.literal("tool_reference"),
533
+ tool_name: zod_v4.z.string()
534
+ }))
535
+ }), zod_v4.z.object({
536
+ type: zod_v4.z.literal("tool_search_tool_result_error"),
537
+ error_code: zod_v4.z.string()
538
+ })])
539
+ }),
540
+ zod_v4.z.object({
541
+ type: zod_v4.z.literal("advisor_tool_result"),
542
+ tool_use_id: zod_v4.z.string(),
543
+ content: zod_v4.z.discriminatedUnion("type", [
544
+ zod_v4.z.object({
545
+ type: zod_v4.z.literal("advisor_result"),
546
+ text: zod_v4.z.string()
547
+ }),
548
+ zod_v4.z.object({
549
+ type: zod_v4.z.literal("advisor_redacted_result"),
550
+ encrypted_content: zod_v4.z.string()
551
+ }),
552
+ zod_v4.z.object({
553
+ type: zod_v4.z.literal("advisor_tool_result_error"),
554
+ error_code: zod_v4.z.string()
555
+ })
556
+ ])
557
+ }),
558
+ zod_v4.z.object({ type: zod_v4.z.literal("fallback") })
559
+ ])
560
+ }),
561
+ zod_v4.z.object({
562
+ type: zod_v4.z.literal("content_block_delta"),
563
+ index: zod_v4.z.number(),
564
+ delta: zod_v4.z.discriminatedUnion("type", [
565
+ zod_v4.z.object({
566
+ type: zod_v4.z.literal("input_json_delta"),
567
+ partial_json: zod_v4.z.string()
568
+ }),
569
+ zod_v4.z.object({
570
+ type: zod_v4.z.literal("text_delta"),
571
+ text: zod_v4.z.string()
572
+ }),
573
+ zod_v4.z.object({
574
+ type: zod_v4.z.literal("thinking_delta"),
575
+ thinking: zod_v4.z.string()
576
+ }),
577
+ zod_v4.z.object({
578
+ type: zod_v4.z.literal("signature_delta"),
579
+ signature: zod_v4.z.string()
580
+ }),
581
+ zod_v4.z.object({
582
+ type: zod_v4.z.literal("compaction_delta"),
583
+ content: zod_v4.z.string().nullish()
584
+ }),
585
+ zod_v4.z.object({
586
+ type: zod_v4.z.literal("citations_delta"),
587
+ citation: zod_v4.z.discriminatedUnion("type", [
588
+ zod_v4.z.object({
589
+ type: zod_v4.z.literal("web_search_result_location"),
590
+ cited_text: zod_v4.z.string(),
591
+ url: zod_v4.z.string(),
592
+ title: zod_v4.z.string(),
593
+ encrypted_index: zod_v4.z.string()
594
+ }),
595
+ zod_v4.z.object({
596
+ type: zod_v4.z.literal("page_location"),
597
+ cited_text: zod_v4.z.string(),
598
+ document_index: zod_v4.z.number(),
599
+ document_title: zod_v4.z.string().nullable(),
600
+ start_page_number: zod_v4.z.number(),
601
+ end_page_number: zod_v4.z.number()
602
+ }),
603
+ zod_v4.z.object({
604
+ type: zod_v4.z.literal("char_location"),
605
+ cited_text: zod_v4.z.string(),
606
+ document_index: zod_v4.z.number(),
607
+ document_title: zod_v4.z.string().nullable(),
608
+ start_char_index: zod_v4.z.number(),
609
+ end_char_index: zod_v4.z.number()
610
+ })
611
+ ])
612
+ })
613
+ ])
614
+ }),
615
+ zod_v4.z.object({
616
+ type: zod_v4.z.literal("content_block_stop"),
617
+ index: zod_v4.z.number()
618
+ }),
619
+ zod_v4.z.object({
620
+ type: zod_v4.z.literal("error"),
621
+ error: zod_v4.z.object({
622
+ type: zod_v4.z.string(),
623
+ message: zod_v4.z.string()
624
+ })
625
+ }),
626
+ zod_v4.z.object({
627
+ type: zod_v4.z.literal("message_delta"),
628
+ delta: zod_v4.z.object({
629
+ stop_reason: zod_v4.z.string().nullish(),
630
+ stop_sequence: zod_v4.z.string().nullish(),
631
+ stop_details: anthropicStopDetailsSchema.nullish(),
632
+ container: zod_v4.z.object({
633
+ expires_at: zod_v4.z.string(),
634
+ id: zod_v4.z.string(),
635
+ skills: zod_v4.z.array(zod_v4.z.object({
636
+ type: zod_v4.z.union([zod_v4.z.literal("anthropic"), zod_v4.z.literal("custom")]),
637
+ skill_id: zod_v4.z.string(),
638
+ version: zod_v4.z.string()
639
+ })).nullish()
640
+ }).nullish()
641
+ }),
642
+ usage: zod_v4.z.looseObject({
643
+ input_tokens: zod_v4.z.number().nullish(),
644
+ output_tokens: zod_v4.z.number(),
645
+ cache_creation_input_tokens: zod_v4.z.number().nullish(),
646
+ cache_read_input_tokens: zod_v4.z.number().nullish(),
647
+ iterations: zod_v4.z.array(zod_v4.z.object({
648
+ type: zod_v4.z.union([
649
+ zod_v4.z.literal("compaction"),
650
+ zod_v4.z.literal("message"),
651
+ zod_v4.z.literal("advisor_message"),
652
+ zod_v4.z.literal("fallback_message")
653
+ ]),
654
+ model: zod_v4.z.string().nullish(),
655
+ input_tokens: zod_v4.z.number(),
656
+ output_tokens: zod_v4.z.number(),
657
+ cache_creation_input_tokens: zod_v4.z.number().nullish(),
658
+ cache_read_input_tokens: zod_v4.z.number().nullish()
659
+ })).nullish()
660
+ }),
661
+ context_management: zod_v4.z.object({ applied_edits: zod_v4.z.array(zod_v4.z.union([
662
+ zod_v4.z.object({
663
+ type: zod_v4.z.literal("clear_tool_uses_20250919"),
664
+ cleared_tool_uses: zod_v4.z.number(),
665
+ cleared_input_tokens: zod_v4.z.number()
666
+ }),
667
+ zod_v4.z.object({
668
+ type: zod_v4.z.literal("clear_thinking_20251015"),
669
+ cleared_thinking_turns: zod_v4.z.number(),
670
+ cleared_input_tokens: zod_v4.z.number()
671
+ }),
672
+ zod_v4.z.object({ type: zod_v4.z.literal("compact_20260112") })
673
+ ])) }).nullish()
674
+ }),
675
+ zod_v4.z.object({ type: zod_v4.z.literal("message_stop") }),
676
+ zod_v4.z.object({ type: zod_v4.z.literal("ping") })
677
+ ])));
678
+ var anthropicReasoningMetadataSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
679
+ signature: zod_v4.z.string().optional(),
680
+ redactedData: zod_v4.z.string().optional()
681
+ })));
682
+ var anthropicFilePartProviderOptions = zod_v4.z.object({
683
+ citations: zod_v4.z.object({ enabled: zod_v4.z.boolean() }).optional(),
684
+ title: zod_v4.z.string().optional(),
685
+ context: zod_v4.z.string().optional()
686
+ });
687
+ var anthropicLanguageModelOptions = zod_v4.z.object({
688
+ sendReasoning: zod_v4.z.boolean().optional(),
689
+ structuredOutputMode: zod_v4.z.enum([
690
+ "outputFormat",
691
+ "jsonTool",
692
+ "auto"
693
+ ]).optional(),
694
+ thinking: zod_v4.z.discriminatedUnion("type", [
695
+ zod_v4.z.object({
696
+ type: zod_v4.z.literal("adaptive"),
697
+ display: zod_v4.z.enum(["omitted", "summarized"]).optional()
698
+ }),
699
+ zod_v4.z.object({
700
+ type: zod_v4.z.literal("enabled"),
701
+ budgetTokens: zod_v4.z.number().optional()
702
+ }),
703
+ zod_v4.z.object({ type: zod_v4.z.literal("disabled") })
704
+ ]).optional(),
705
+ disableParallelToolUse: zod_v4.z.boolean().optional(),
706
+ cacheControl: zod_v4.z.object({
707
+ type: zod_v4.z.literal("ephemeral"),
708
+ ttl: zod_v4.z.union([zod_v4.z.literal("5m"), zod_v4.z.literal("1h")]).optional()
709
+ }).optional(),
710
+ metadata: zod_v4.z.object({ userId: zod_v4.z.string().optional() }).optional(),
711
+ mcpServers: zod_v4.z.array(zod_v4.z.object({
712
+ type: zod_v4.z.literal("url"),
713
+ name: zod_v4.z.string(),
714
+ url: zod_v4.z.string(),
715
+ authorizationToken: zod_v4.z.string().nullish(),
716
+ toolConfiguration: zod_v4.z.object({
717
+ enabled: zod_v4.z.boolean().nullish(),
718
+ allowedTools: zod_v4.z.array(zod_v4.z.string()).nullish()
719
+ }).nullish()
720
+ })).optional(),
721
+ container: zod_v4.z.object({
722
+ id: zod_v4.z.string().optional(),
723
+ skills: zod_v4.z.array(zod_v4.z.object({
724
+ type: zod_v4.z.union([zod_v4.z.literal("anthropic"), zod_v4.z.literal("custom")]),
725
+ skillId: zod_v4.z.string(),
726
+ version: zod_v4.z.string().optional()
727
+ })).optional()
728
+ }).optional(),
729
+ toolStreaming: zod_v4.z.boolean().optional(),
730
+ effort: zod_v4.z.enum([
731
+ "low",
732
+ "medium",
733
+ "high",
734
+ "xhigh",
735
+ "max"
736
+ ]).optional(),
737
+ taskBudget: zod_v4.z.object({
738
+ type: zod_v4.z.literal("tokens"),
739
+ total: zod_v4.z.number().int().min(2e4),
740
+ remaining: zod_v4.z.number().int().min(0).optional()
741
+ }).optional(),
742
+ speed: zod_v4.z.enum(["fast", "standard"]).optional(),
743
+ inferenceGeo: zod_v4.z.enum(["us", "global"]).optional(),
744
+ fallbacks: zod_v4.z.array(zod_v4.z.object({
745
+ model: zod_v4.z.string(),
746
+ max_tokens: zod_v4.z.number().int().optional(),
747
+ thinking: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown()).optional(),
748
+ output_config: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown()).optional(),
749
+ speed: zod_v4.z.enum(["fast", "standard"]).optional()
750
+ })).optional(),
751
+ anthropicBeta: zod_v4.z.array(zod_v4.z.string()).optional(),
752
+ contextManagement: zod_v4.z.object({ edits: zod_v4.z.array(zod_v4.z.discriminatedUnion("type", [
753
+ zod_v4.z.object({
754
+ type: zod_v4.z.literal("clear_tool_uses_20250919"),
755
+ trigger: zod_v4.z.discriminatedUnion("type", [zod_v4.z.object({
756
+ type: zod_v4.z.literal("input_tokens"),
757
+ value: zod_v4.z.number()
758
+ }), zod_v4.z.object({
759
+ type: zod_v4.z.literal("tool_uses"),
760
+ value: zod_v4.z.number()
761
+ })]).optional(),
762
+ keep: zod_v4.z.object({
763
+ type: zod_v4.z.literal("tool_uses"),
764
+ value: zod_v4.z.number()
765
+ }).optional(),
766
+ clearAtLeast: zod_v4.z.object({
767
+ type: zod_v4.z.literal("input_tokens"),
768
+ value: zod_v4.z.number()
769
+ }).optional(),
770
+ clearToolInputs: zod_v4.z.boolean().optional(),
771
+ excludeTools: zod_v4.z.array(zod_v4.z.string()).optional()
772
+ }),
773
+ zod_v4.z.object({
774
+ type: zod_v4.z.literal("clear_thinking_20251015"),
775
+ keep: zod_v4.z.union([zod_v4.z.literal("all"), zod_v4.z.object({
776
+ type: zod_v4.z.literal("thinking_turns"),
777
+ value: zod_v4.z.number()
778
+ })]).optional()
779
+ }),
780
+ zod_v4.z.object({
781
+ type: zod_v4.z.literal("compact_20260112"),
782
+ trigger: zod_v4.z.object({
783
+ type: zod_v4.z.literal("input_tokens"),
784
+ value: zod_v4.z.number()
785
+ }).optional(),
786
+ pauseAfterCompaction: zod_v4.z.boolean().optional(),
787
+ instructions: zod_v4.z.string().optional()
788
+ })
789
+ ])) }).optional()
790
+ });
791
+ var MAX_CACHE_BREAKPOINTS = 4;
792
+ function getCacheControl(providerMetadata) {
793
+ var _a;
794
+ const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
795
+ return (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a : anthropic2 == null ? void 0 : anthropic2.cache_control;
796
+ }
797
+ var CacheControlValidator = class {
798
+ constructor() {
799
+ this.breakpointCount = 0;
800
+ this.warnings = [];
801
+ }
802
+ getCacheControl(providerMetadata, context) {
803
+ const cacheControlValue = getCacheControl(providerMetadata);
804
+ if (!cacheControlValue) return;
805
+ if (!context.canCache) {
806
+ this.warnings.push({
807
+ type: "unsupported",
808
+ feature: "cache_control on non-cacheable context",
809
+ details: `cache_control cannot be set on ${context.type}. It will be ignored.`
810
+ });
811
+ return;
812
+ }
813
+ this.breakpointCount++;
814
+ if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
815
+ this.warnings.push({
816
+ type: "unsupported",
817
+ feature: "cacheControl breakpoint limit",
818
+ details: `Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`
819
+ });
820
+ return;
821
+ }
822
+ return cacheControlValue;
823
+ }
824
+ getWarnings() {
825
+ return this.warnings;
826
+ }
827
+ };
828
+ var advisor_20260301ArgsSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
829
+ model: zod_v4.z.string(),
830
+ maxUses: zod_v4.z.number().optional(),
831
+ caching: zod_v4.z.object({
832
+ type: zod_v4.z.literal("ephemeral"),
833
+ ttl: zod_v4.z.union([zod_v4.z.literal("5m"), zod_v4.z.literal("1h")])
834
+ }).optional()
835
+ })));
836
+ var advisor_20260301OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.discriminatedUnion("type", [
837
+ zod_v4.z.object({
838
+ type: zod_v4.z.literal("advisor_result"),
839
+ text: zod_v4.z.string()
840
+ }),
841
+ zod_v4.z.object({
842
+ type: zod_v4.z.literal("advisor_redacted_result"),
843
+ encryptedContent: zod_v4.z.string()
844
+ }),
845
+ zod_v4.z.object({
846
+ type: zod_v4.z.literal("advisor_tool_result_error"),
847
+ errorCode: zod_v4.z.string()
848
+ })
849
+ ])));
850
+ var factory = require_dist.createProviderToolFactoryWithOutputSchema({
851
+ id: "anthropic.advisor_20260301",
852
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({}).strict())),
853
+ outputSchema: advisor_20260301OutputSchema,
854
+ supportsDeferredResults: true
855
+ });
856
+ var advisor_20260301 = (args) => {
857
+ return factory(args);
858
+ };
859
+ var textEditor_20250728ArgsSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({ maxCharacters: zod_v4.z.number().optional() })));
860
+ var factory2 = require_dist.createProviderToolFactory({
861
+ id: "anthropic.text_editor_20250728",
862
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
863
+ command: zod_v4.z.enum([
864
+ "view",
865
+ "create",
866
+ "str_replace",
867
+ "insert"
868
+ ]),
869
+ path: zod_v4.z.string(),
870
+ file_text: zod_v4.z.string().optional(),
871
+ insert_line: zod_v4.z.number().int().optional(),
872
+ new_str: zod_v4.z.string().optional(),
873
+ insert_text: zod_v4.z.string().optional(),
874
+ old_str: zod_v4.z.string().optional(),
875
+ view_range: zod_v4.z.array(zod_v4.z.number().int()).optional()
876
+ })))
877
+ });
878
+ var textEditor_20250728 = (args = {}) => {
879
+ return factory2(args);
880
+ };
881
+ var webSearch_20260209ArgsSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
882
+ maxUses: zod_v4.z.number().optional(),
883
+ allowedDomains: zod_v4.z.array(zod_v4.z.string()).optional(),
884
+ blockedDomains: zod_v4.z.array(zod_v4.z.string()).optional(),
885
+ userLocation: zod_v4.z.object({
886
+ type: zod_v4.z.literal("approximate"),
887
+ city: zod_v4.z.string().optional(),
888
+ region: zod_v4.z.string().optional(),
889
+ country: zod_v4.z.string().optional(),
890
+ timezone: zod_v4.z.string().optional()
891
+ }).optional()
892
+ })));
893
+ var webSearch_20260209OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.array(zod_v4.z.object({
894
+ url: zod_v4.z.string(),
895
+ title: zod_v4.z.string().nullable(),
896
+ pageAge: zod_v4.z.string().nullable(),
897
+ encryptedContent: zod_v4.z.string(),
898
+ type: zod_v4.z.literal("web_search_result")
899
+ }))));
900
+ var factory3 = require_dist.createProviderToolFactoryWithOutputSchema({
901
+ id: "anthropic.web_search_20260209",
902
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({ query: zod_v4.z.string() }))),
903
+ outputSchema: webSearch_20260209OutputSchema,
904
+ supportsDeferredResults: true
905
+ });
906
+ var webSearch_20260209 = (args = {}) => {
907
+ return factory3(args);
908
+ };
909
+ var webSearch_20250305ArgsSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
910
+ maxUses: zod_v4.z.number().optional(),
911
+ allowedDomains: zod_v4.z.array(zod_v4.z.string()).optional(),
912
+ blockedDomains: zod_v4.z.array(zod_v4.z.string()).optional(),
913
+ userLocation: zod_v4.z.object({
914
+ type: zod_v4.z.literal("approximate"),
915
+ city: zod_v4.z.string().optional(),
916
+ region: zod_v4.z.string().optional(),
917
+ country: zod_v4.z.string().optional(),
918
+ timezone: zod_v4.z.string().optional()
919
+ }).optional()
920
+ })));
921
+ var webSearch_20250305OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.array(zod_v4.z.object({
922
+ url: zod_v4.z.string(),
923
+ title: zod_v4.z.string().nullable(),
924
+ pageAge: zod_v4.z.string().nullable(),
925
+ encryptedContent: zod_v4.z.string(),
926
+ type: zod_v4.z.literal("web_search_result")
927
+ }))));
928
+ var factory4 = require_dist.createProviderToolFactoryWithOutputSchema({
929
+ id: "anthropic.web_search_20250305",
930
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({ query: zod_v4.z.string() }))),
931
+ outputSchema: webSearch_20250305OutputSchema,
932
+ supportsDeferredResults: true
933
+ });
934
+ var webSearch_20250305 = (args = {}) => {
935
+ return factory4(args);
936
+ };
937
+ var webFetch_20260209ArgsSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
938
+ maxUses: zod_v4.z.number().optional(),
939
+ allowedDomains: zod_v4.z.array(zod_v4.z.string()).optional(),
940
+ blockedDomains: zod_v4.z.array(zod_v4.z.string()).optional(),
941
+ citations: zod_v4.z.object({ enabled: zod_v4.z.boolean() }).optional(),
942
+ maxContentTokens: zod_v4.z.number().optional()
943
+ })));
944
+ var webFetch_20260209OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
945
+ type: zod_v4.z.literal("web_fetch_result"),
946
+ url: zod_v4.z.string(),
947
+ content: zod_v4.z.object({
948
+ type: zod_v4.z.literal("document"),
949
+ title: zod_v4.z.string().nullable(),
950
+ citations: zod_v4.z.object({ enabled: zod_v4.z.boolean() }).optional(),
951
+ source: zod_v4.z.union([zod_v4.z.object({
952
+ type: zod_v4.z.literal("base64"),
953
+ mediaType: zod_v4.z.literal("application/pdf"),
954
+ data: zod_v4.z.string()
955
+ }), zod_v4.z.object({
956
+ type: zod_v4.z.literal("text"),
957
+ mediaType: zod_v4.z.literal("text/plain"),
958
+ data: zod_v4.z.string()
959
+ })])
960
+ }),
961
+ retrievedAt: zod_v4.z.string().nullable()
962
+ })));
963
+ var factory5 = require_dist.createProviderToolFactoryWithOutputSchema({
964
+ id: "anthropic.web_fetch_20260209",
965
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({ url: zod_v4.z.string() }))),
966
+ outputSchema: webFetch_20260209OutputSchema,
967
+ supportsDeferredResults: true
968
+ });
969
+ var webFetch_20260209 = (args = {}) => {
970
+ return factory5(args);
971
+ };
972
+ var webFetch_20250910ArgsSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
973
+ maxUses: zod_v4.z.number().optional(),
974
+ allowedDomains: zod_v4.z.array(zod_v4.z.string()).optional(),
975
+ blockedDomains: zod_v4.z.array(zod_v4.z.string()).optional(),
976
+ citations: zod_v4.z.object({ enabled: zod_v4.z.boolean() }).optional(),
977
+ maxContentTokens: zod_v4.z.number().optional()
978
+ })));
979
+ var webFetch_20250910OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
980
+ type: zod_v4.z.literal("web_fetch_result"),
981
+ url: zod_v4.z.string(),
982
+ content: zod_v4.z.object({
983
+ type: zod_v4.z.literal("document"),
984
+ title: zod_v4.z.string().nullable(),
985
+ citations: zod_v4.z.object({ enabled: zod_v4.z.boolean() }).optional(),
986
+ source: zod_v4.z.union([zod_v4.z.object({
987
+ type: zod_v4.z.literal("base64"),
988
+ mediaType: zod_v4.z.literal("application/pdf"),
989
+ data: zod_v4.z.string()
990
+ }), zod_v4.z.object({
991
+ type: zod_v4.z.literal("text"),
992
+ mediaType: zod_v4.z.literal("text/plain"),
993
+ data: zod_v4.z.string()
994
+ })])
995
+ }),
996
+ retrievedAt: zod_v4.z.string().nullable()
997
+ })));
998
+ var factory6 = require_dist.createProviderToolFactoryWithOutputSchema({
999
+ id: "anthropic.web_fetch_20250910",
1000
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({ url: zod_v4.z.string() }))),
1001
+ outputSchema: webFetch_20250910OutputSchema,
1002
+ supportsDeferredResults: true
1003
+ });
1004
+ var webFetch_20250910 = (args = {}) => {
1005
+ return factory6(args);
1006
+ };
1007
+ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming = false }) {
1008
+ var _a, _b;
1009
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1010
+ const toolWarnings = [];
1011
+ const betas = /* @__PURE__ */ new Set();
1012
+ const validator = cacheControlValidator || new CacheControlValidator();
1013
+ if (tools == null) return {
1014
+ tools: void 0,
1015
+ toolChoice: void 0,
1016
+ toolWarnings,
1017
+ betas
1018
+ };
1019
+ const anthropicTools2 = [];
1020
+ for (const tool of tools) switch (tool.type) {
1021
+ case "function": {
1022
+ const cacheControl = validator.getCacheControl(tool.providerOptions, {
1023
+ type: "tool definition",
1024
+ canCache: true
1025
+ });
1026
+ const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
1027
+ const eagerInputStreaming = (_b = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming) != null ? _b : defaultEagerInputStreaming;
1028
+ const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1029
+ const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1030
+ if (!supportsStrictTools && tool.strict != null) toolWarnings.push({
1031
+ type: "unsupported",
1032
+ feature: "strict",
1033
+ details: `Tool '${tool.name}' has strict: ${tool.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`
1034
+ });
1035
+ anthropicTools2.push({
1036
+ name: tool.name,
1037
+ description: tool.description,
1038
+ input_schema: tool.inputSchema,
1039
+ cache_control: cacheControl,
1040
+ ...eagerInputStreaming ? { eager_input_streaming: true } : {},
1041
+ ...supportsStrictTools === true && tool.strict != null ? { strict: tool.strict } : {},
1042
+ ...deferLoading != null ? { defer_loading: deferLoading } : {},
1043
+ ...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
1044
+ ...tool.inputExamples != null ? { input_examples: tool.inputExamples.map((example) => example.input) } : {}
1045
+ });
1046
+ if (supportsStructuredOutput === true) betas.add("structured-outputs-2025-11-13");
1047
+ if (tool.inputExamples != null || allowedCallers != null) betas.add("advanced-tool-use-2025-11-20");
1048
+ break;
1049
+ }
1050
+ case "provider":
1051
+ switch (tool.id) {
1052
+ case "anthropic.code_execution_20250522":
1053
+ betas.add("code-execution-2025-05-22");
1054
+ anthropicTools2.push({
1055
+ type: "code_execution_20250522",
1056
+ name: "code_execution",
1057
+ cache_control: void 0
1058
+ });
1059
+ break;
1060
+ case "anthropic.code_execution_20250825":
1061
+ betas.add("code-execution-2025-08-25");
1062
+ anthropicTools2.push({
1063
+ type: "code_execution_20250825",
1064
+ name: "code_execution"
1065
+ });
1066
+ break;
1067
+ case "anthropic.code_execution_20260120":
1068
+ anthropicTools2.push({
1069
+ type: "code_execution_20260120",
1070
+ name: "code_execution"
1071
+ });
1072
+ break;
1073
+ case "anthropic.computer_20250124":
1074
+ betas.add("computer-use-2025-01-24");
1075
+ anthropicTools2.push({
1076
+ name: "computer",
1077
+ type: "computer_20250124",
1078
+ display_width_px: tool.args.displayWidthPx,
1079
+ display_height_px: tool.args.displayHeightPx,
1080
+ display_number: tool.args.displayNumber,
1081
+ cache_control: void 0
1082
+ });
1083
+ break;
1084
+ case "anthropic.computer_20251124":
1085
+ betas.add("computer-use-2025-11-24");
1086
+ anthropicTools2.push({
1087
+ name: "computer",
1088
+ type: "computer_20251124",
1089
+ display_width_px: tool.args.displayWidthPx,
1090
+ display_height_px: tool.args.displayHeightPx,
1091
+ display_number: tool.args.displayNumber,
1092
+ enable_zoom: tool.args.enableZoom,
1093
+ cache_control: void 0
1094
+ });
1095
+ break;
1096
+ case "anthropic.computer_20241022":
1097
+ betas.add("computer-use-2024-10-22");
1098
+ anthropicTools2.push({
1099
+ name: "computer",
1100
+ type: "computer_20241022",
1101
+ display_width_px: tool.args.displayWidthPx,
1102
+ display_height_px: tool.args.displayHeightPx,
1103
+ display_number: tool.args.displayNumber,
1104
+ cache_control: void 0
1105
+ });
1106
+ break;
1107
+ case "anthropic.text_editor_20250124":
1108
+ betas.add("computer-use-2025-01-24");
1109
+ anthropicTools2.push({
1110
+ name: "str_replace_editor",
1111
+ type: "text_editor_20250124",
1112
+ cache_control: void 0
1113
+ });
1114
+ break;
1115
+ case "anthropic.text_editor_20241022":
1116
+ betas.add("computer-use-2024-10-22");
1117
+ anthropicTools2.push({
1118
+ name: "str_replace_editor",
1119
+ type: "text_editor_20241022",
1120
+ cache_control: void 0
1121
+ });
1122
+ break;
1123
+ case "anthropic.text_editor_20250429":
1124
+ betas.add("computer-use-2025-01-24");
1125
+ anthropicTools2.push({
1126
+ name: "str_replace_based_edit_tool",
1127
+ type: "text_editor_20250429",
1128
+ cache_control: void 0
1129
+ });
1130
+ break;
1131
+ case "anthropic.text_editor_20250728": {
1132
+ const args = await require_dist.validateTypes({
1133
+ value: tool.args,
1134
+ schema: textEditor_20250728ArgsSchema
1135
+ });
1136
+ anthropicTools2.push({
1137
+ name: "str_replace_based_edit_tool",
1138
+ type: "text_editor_20250728",
1139
+ max_characters: args.maxCharacters,
1140
+ cache_control: void 0
1141
+ });
1142
+ break;
1143
+ }
1144
+ case "anthropic.bash_20250124":
1145
+ betas.add("computer-use-2025-01-24");
1146
+ anthropicTools2.push({
1147
+ name: "bash",
1148
+ type: "bash_20250124",
1149
+ cache_control: void 0
1150
+ });
1151
+ break;
1152
+ case "anthropic.bash_20241022":
1153
+ betas.add("computer-use-2024-10-22");
1154
+ anthropicTools2.push({
1155
+ name: "bash",
1156
+ type: "bash_20241022",
1157
+ cache_control: void 0
1158
+ });
1159
+ break;
1160
+ case "anthropic.memory_20250818":
1161
+ betas.add("context-management-2025-06-27");
1162
+ anthropicTools2.push({
1163
+ name: "memory",
1164
+ type: "memory_20250818"
1165
+ });
1166
+ break;
1167
+ case "anthropic.web_fetch_20250910": {
1168
+ betas.add("web-fetch-2025-09-10");
1169
+ const args = await require_dist.validateTypes({
1170
+ value: tool.args,
1171
+ schema: webFetch_20250910ArgsSchema
1172
+ });
1173
+ anthropicTools2.push({
1174
+ type: "web_fetch_20250910",
1175
+ name: "web_fetch",
1176
+ max_uses: args.maxUses,
1177
+ allowed_domains: args.allowedDomains,
1178
+ blocked_domains: args.blockedDomains,
1179
+ citations: args.citations,
1180
+ max_content_tokens: args.maxContentTokens,
1181
+ cache_control: void 0
1182
+ });
1183
+ break;
1184
+ }
1185
+ case "anthropic.web_fetch_20260209": {
1186
+ betas.add("code-execution-web-tools-2026-02-09");
1187
+ const args = await require_dist.validateTypes({
1188
+ value: tool.args,
1189
+ schema: webFetch_20260209ArgsSchema
1190
+ });
1191
+ anthropicTools2.push({
1192
+ type: "web_fetch_20260209",
1193
+ name: "web_fetch",
1194
+ max_uses: args.maxUses,
1195
+ allowed_domains: args.allowedDomains,
1196
+ blocked_domains: args.blockedDomains,
1197
+ citations: args.citations,
1198
+ max_content_tokens: args.maxContentTokens,
1199
+ cache_control: void 0
1200
+ });
1201
+ break;
1202
+ }
1203
+ case "anthropic.web_search_20250305": {
1204
+ const args = await require_dist.validateTypes({
1205
+ value: tool.args,
1206
+ schema: webSearch_20250305ArgsSchema
1207
+ });
1208
+ anthropicTools2.push({
1209
+ type: "web_search_20250305",
1210
+ name: "web_search",
1211
+ max_uses: args.maxUses,
1212
+ allowed_domains: args.allowedDomains,
1213
+ blocked_domains: args.blockedDomains,
1214
+ user_location: args.userLocation,
1215
+ cache_control: void 0
1216
+ });
1217
+ break;
1218
+ }
1219
+ case "anthropic.web_search_20260209": {
1220
+ betas.add("code-execution-web-tools-2026-02-09");
1221
+ const args = await require_dist.validateTypes({
1222
+ value: tool.args,
1223
+ schema: webSearch_20260209ArgsSchema
1224
+ });
1225
+ anthropicTools2.push({
1226
+ type: "web_search_20260209",
1227
+ name: "web_search",
1228
+ max_uses: args.maxUses,
1229
+ allowed_domains: args.allowedDomains,
1230
+ blocked_domains: args.blockedDomains,
1231
+ user_location: args.userLocation,
1232
+ cache_control: void 0
1233
+ });
1234
+ break;
1235
+ }
1236
+ case "anthropic.tool_search_regex_20251119":
1237
+ anthropicTools2.push({
1238
+ type: "tool_search_tool_regex_20251119",
1239
+ name: "tool_search_tool_regex"
1240
+ });
1241
+ break;
1242
+ case "anthropic.tool_search_bm25_20251119":
1243
+ anthropicTools2.push({
1244
+ type: "tool_search_tool_bm25_20251119",
1245
+ name: "tool_search_tool_bm25"
1246
+ });
1247
+ break;
1248
+ case "anthropic.advisor_20260301": {
1249
+ betas.add("advisor-tool-2026-03-01");
1250
+ const args = await require_dist.validateTypes({
1251
+ value: tool.args,
1252
+ schema: advisor_20260301ArgsSchema
1253
+ });
1254
+ anthropicTools2.push({
1255
+ type: "advisor_20260301",
1256
+ name: "advisor",
1257
+ model: args.model,
1258
+ ...args.maxUses !== void 0 && { max_uses: args.maxUses },
1259
+ ...args.caching !== void 0 && { caching: args.caching }
1260
+ });
1261
+ break;
1262
+ }
1263
+ default:
1264
+ toolWarnings.push({
1265
+ type: "unsupported",
1266
+ feature: `provider-defined tool ${tool.id}`
1267
+ });
1268
+ break;
1269
+ }
1270
+ break;
1271
+ default:
1272
+ toolWarnings.push({
1273
+ type: "unsupported",
1274
+ feature: `tool ${tool}`
1275
+ });
1276
+ break;
1277
+ }
1278
+ if (toolChoice == null) return {
1279
+ tools: anthropicTools2,
1280
+ toolChoice: disableParallelToolUse ? {
1281
+ type: "auto",
1282
+ disable_parallel_tool_use: disableParallelToolUse
1283
+ } : void 0,
1284
+ toolWarnings,
1285
+ betas
1286
+ };
1287
+ const type = toolChoice.type;
1288
+ switch (type) {
1289
+ case "auto": return {
1290
+ tools: anthropicTools2,
1291
+ toolChoice: {
1292
+ type: "auto",
1293
+ disable_parallel_tool_use: disableParallelToolUse
1294
+ },
1295
+ toolWarnings,
1296
+ betas
1297
+ };
1298
+ case "required": return {
1299
+ tools: anthropicTools2,
1300
+ toolChoice: {
1301
+ type: "any",
1302
+ disable_parallel_tool_use: disableParallelToolUse
1303
+ },
1304
+ toolWarnings,
1305
+ betas
1306
+ };
1307
+ case "none": return {
1308
+ tools: void 0,
1309
+ toolChoice: void 0,
1310
+ toolWarnings,
1311
+ betas
1312
+ };
1313
+ case "tool": return {
1314
+ tools: anthropicTools2,
1315
+ toolChoice: {
1316
+ type: "tool",
1317
+ name: toolChoice.toolName,
1318
+ disable_parallel_tool_use: disableParallelToolUse
1319
+ },
1320
+ toolWarnings,
1321
+ betas
1322
+ };
1323
+ default: throw new require_dist.UnsupportedFunctionalityError({ functionality: `tool choice type: ${type}` });
1324
+ }
1325
+ }
1326
+ function convertAnthropicMessagesUsage({ usage, rawUsage }) {
1327
+ var _a, _b, _c;
1328
+ const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
1329
+ const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
1330
+ let inputTokens;
1331
+ let outputTokens;
1332
+ const servedByFallback = (_c = usage.iterations) == null ? void 0 : _c.some((iter) => iter.type === "fallback_message");
1333
+ if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
1334
+ const executorIterations = usage.iterations.filter((iter) => iter.type === "compaction" || iter.type === "message");
1335
+ if (executorIterations.length > 0) {
1336
+ const totals = executorIterations.reduce((acc, iter) => ({
1337
+ input: acc.input + iter.input_tokens,
1338
+ output: acc.output + iter.output_tokens
1339
+ }), {
1340
+ input: 0,
1341
+ output: 0
1342
+ });
1343
+ inputTokens = totals.input;
1344
+ outputTokens = totals.output;
1345
+ } else {
1346
+ inputTokens = usage.input_tokens;
1347
+ outputTokens = usage.output_tokens;
1348
+ }
1349
+ } else {
1350
+ inputTokens = usage.input_tokens;
1351
+ outputTokens = usage.output_tokens;
1352
+ }
1353
+ return {
1354
+ inputTokens: {
1355
+ total: inputTokens + cacheCreationTokens + cacheReadTokens,
1356
+ noCache: inputTokens,
1357
+ cacheRead: cacheReadTokens,
1358
+ cacheWrite: cacheCreationTokens
1359
+ },
1360
+ outputTokens: {
1361
+ total: outputTokens,
1362
+ text: void 0,
1363
+ reasoning: void 0
1364
+ },
1365
+ raw: rawUsage != null ? rawUsage : usage
1366
+ };
1367
+ }
1368
+ var codeExecution_20250522OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
1369
+ type: zod_v4.z.literal("code_execution_result"),
1370
+ stdout: zod_v4.z.string(),
1371
+ stderr: zod_v4.z.string(),
1372
+ return_code: zod_v4.z.number(),
1373
+ content: zod_v4.z.array(zod_v4.z.object({
1374
+ type: zod_v4.z.literal("code_execution_output"),
1375
+ file_id: zod_v4.z.string()
1376
+ })).optional().default([])
1377
+ })));
1378
+ var factory7 = require_dist.createProviderToolFactoryWithOutputSchema({
1379
+ id: "anthropic.code_execution_20250522",
1380
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({ code: zod_v4.z.string() }))),
1381
+ outputSchema: codeExecution_20250522OutputSchema
1382
+ });
1383
+ var codeExecution_20250522 = (args = {}) => {
1384
+ return factory7(args);
1385
+ };
1386
+ var codeExecution_20250825OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.discriminatedUnion("type", [
1387
+ zod_v4.z.object({
1388
+ type: zod_v4.z.literal("code_execution_result"),
1389
+ stdout: zod_v4.z.string(),
1390
+ stderr: zod_v4.z.string(),
1391
+ return_code: zod_v4.z.number(),
1392
+ content: zod_v4.z.array(zod_v4.z.object({
1393
+ type: zod_v4.z.literal("code_execution_output"),
1394
+ file_id: zod_v4.z.string()
1395
+ })).optional().default([])
1396
+ }),
1397
+ zod_v4.z.object({
1398
+ type: zod_v4.z.literal("bash_code_execution_result"),
1399
+ content: zod_v4.z.array(zod_v4.z.object({
1400
+ type: zod_v4.z.literal("bash_code_execution_output"),
1401
+ file_id: zod_v4.z.string()
1402
+ })),
1403
+ stdout: zod_v4.z.string(),
1404
+ stderr: zod_v4.z.string(),
1405
+ return_code: zod_v4.z.number()
1406
+ }),
1407
+ zod_v4.z.object({
1408
+ type: zod_v4.z.literal("bash_code_execution_tool_result_error"),
1409
+ error_code: zod_v4.z.string()
1410
+ }),
1411
+ zod_v4.z.object({
1412
+ type: zod_v4.z.literal("text_editor_code_execution_tool_result_error"),
1413
+ error_code: zod_v4.z.string()
1414
+ }),
1415
+ zod_v4.z.object({
1416
+ type: zod_v4.z.literal("text_editor_code_execution_view_result"),
1417
+ content: zod_v4.z.string(),
1418
+ file_type: zod_v4.z.string(),
1419
+ num_lines: zod_v4.z.number().nullable(),
1420
+ start_line: zod_v4.z.number().nullable(),
1421
+ total_lines: zod_v4.z.number().nullable()
1422
+ }),
1423
+ zod_v4.z.object({
1424
+ type: zod_v4.z.literal("text_editor_code_execution_create_result"),
1425
+ is_file_update: zod_v4.z.boolean()
1426
+ }),
1427
+ zod_v4.z.object({
1428
+ type: zod_v4.z.literal("text_editor_code_execution_str_replace_result"),
1429
+ lines: zod_v4.z.array(zod_v4.z.string()).nullable(),
1430
+ new_lines: zod_v4.z.number().nullable(),
1431
+ new_start: zod_v4.z.number().nullable(),
1432
+ old_lines: zod_v4.z.number().nullable(),
1433
+ old_start: zod_v4.z.number().nullable()
1434
+ })
1435
+ ])));
1436
+ var factory8 = require_dist.createProviderToolFactoryWithOutputSchema({
1437
+ id: "anthropic.code_execution_20250825",
1438
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.discriminatedUnion("type", [
1439
+ zod_v4.z.object({
1440
+ type: zod_v4.z.literal("programmatic-tool-call"),
1441
+ code: zod_v4.z.string()
1442
+ }),
1443
+ zod_v4.z.object({
1444
+ type: zod_v4.z.literal("bash_code_execution"),
1445
+ command: zod_v4.z.string()
1446
+ }),
1447
+ zod_v4.z.discriminatedUnion("command", [
1448
+ zod_v4.z.object({
1449
+ type: zod_v4.z.literal("text_editor_code_execution"),
1450
+ command: zod_v4.z.literal("view"),
1451
+ path: zod_v4.z.string()
1452
+ }),
1453
+ zod_v4.z.object({
1454
+ type: zod_v4.z.literal("text_editor_code_execution"),
1455
+ command: zod_v4.z.literal("create"),
1456
+ path: zod_v4.z.string(),
1457
+ file_text: zod_v4.z.string().nullish()
1458
+ }),
1459
+ zod_v4.z.object({
1460
+ type: zod_v4.z.literal("text_editor_code_execution"),
1461
+ command: zod_v4.z.literal("str_replace"),
1462
+ path: zod_v4.z.string(),
1463
+ old_str: zod_v4.z.string(),
1464
+ new_str: zod_v4.z.string()
1465
+ })
1466
+ ])
1467
+ ]))),
1468
+ outputSchema: codeExecution_20250825OutputSchema,
1469
+ supportsDeferredResults: true
1470
+ });
1471
+ var codeExecution_20250825 = (args = {}) => {
1472
+ return factory8(args);
1473
+ };
1474
+ var codeExecution_20260120OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.discriminatedUnion("type", [
1475
+ zod_v4.z.object({
1476
+ type: zod_v4.z.literal("code_execution_result"),
1477
+ stdout: zod_v4.z.string(),
1478
+ stderr: zod_v4.z.string(),
1479
+ return_code: zod_v4.z.number(),
1480
+ content: zod_v4.z.array(zod_v4.z.object({
1481
+ type: zod_v4.z.literal("code_execution_output"),
1482
+ file_id: zod_v4.z.string()
1483
+ })).optional().default([])
1484
+ }),
1485
+ zod_v4.z.object({
1486
+ type: zod_v4.z.literal("encrypted_code_execution_result"),
1487
+ encrypted_stdout: zod_v4.z.string(),
1488
+ stderr: zod_v4.z.string(),
1489
+ return_code: zod_v4.z.number(),
1490
+ content: zod_v4.z.array(zod_v4.z.object({
1491
+ type: zod_v4.z.literal("code_execution_output"),
1492
+ file_id: zod_v4.z.string()
1493
+ })).optional().default([])
1494
+ }),
1495
+ zod_v4.z.object({
1496
+ type: zod_v4.z.literal("bash_code_execution_result"),
1497
+ content: zod_v4.z.array(zod_v4.z.object({
1498
+ type: zod_v4.z.literal("bash_code_execution_output"),
1499
+ file_id: zod_v4.z.string()
1500
+ })),
1501
+ stdout: zod_v4.z.string(),
1502
+ stderr: zod_v4.z.string(),
1503
+ return_code: zod_v4.z.number()
1504
+ }),
1505
+ zod_v4.z.object({
1506
+ type: zod_v4.z.literal("bash_code_execution_tool_result_error"),
1507
+ error_code: zod_v4.z.string()
1508
+ }),
1509
+ zod_v4.z.object({
1510
+ type: zod_v4.z.literal("text_editor_code_execution_tool_result_error"),
1511
+ error_code: zod_v4.z.string()
1512
+ }),
1513
+ zod_v4.z.object({
1514
+ type: zod_v4.z.literal("text_editor_code_execution_view_result"),
1515
+ content: zod_v4.z.string(),
1516
+ file_type: zod_v4.z.string(),
1517
+ num_lines: zod_v4.z.number().nullable(),
1518
+ start_line: zod_v4.z.number().nullable(),
1519
+ total_lines: zod_v4.z.number().nullable()
1520
+ }),
1521
+ zod_v4.z.object({
1522
+ type: zod_v4.z.literal("text_editor_code_execution_create_result"),
1523
+ is_file_update: zod_v4.z.boolean()
1524
+ }),
1525
+ zod_v4.z.object({
1526
+ type: zod_v4.z.literal("text_editor_code_execution_str_replace_result"),
1527
+ lines: zod_v4.z.array(zod_v4.z.string()).nullable(),
1528
+ new_lines: zod_v4.z.number().nullable(),
1529
+ new_start: zod_v4.z.number().nullable(),
1530
+ old_lines: zod_v4.z.number().nullable(),
1531
+ old_start: zod_v4.z.number().nullable()
1532
+ })
1533
+ ])));
1534
+ var factory9 = require_dist.createProviderToolFactoryWithOutputSchema({
1535
+ id: "anthropic.code_execution_20260120",
1536
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.discriminatedUnion("type", [
1537
+ zod_v4.z.object({
1538
+ type: zod_v4.z.literal("programmatic-tool-call"),
1539
+ code: zod_v4.z.string()
1540
+ }),
1541
+ zod_v4.z.object({
1542
+ type: zod_v4.z.literal("bash_code_execution"),
1543
+ command: zod_v4.z.string()
1544
+ }),
1545
+ zod_v4.z.discriminatedUnion("command", [
1546
+ zod_v4.z.object({
1547
+ type: zod_v4.z.literal("text_editor_code_execution"),
1548
+ command: zod_v4.z.literal("view"),
1549
+ path: zod_v4.z.string()
1550
+ }),
1551
+ zod_v4.z.object({
1552
+ type: zod_v4.z.literal("text_editor_code_execution"),
1553
+ command: zod_v4.z.literal("create"),
1554
+ path: zod_v4.z.string(),
1555
+ file_text: zod_v4.z.string().nullish()
1556
+ }),
1557
+ zod_v4.z.object({
1558
+ type: zod_v4.z.literal("text_editor_code_execution"),
1559
+ command: zod_v4.z.literal("str_replace"),
1560
+ path: zod_v4.z.string(),
1561
+ old_str: zod_v4.z.string(),
1562
+ new_str: zod_v4.z.string()
1563
+ })
1564
+ ])
1565
+ ]))),
1566
+ outputSchema: codeExecution_20260120OutputSchema,
1567
+ supportsDeferredResults: true
1568
+ });
1569
+ var codeExecution_20260120 = (args = {}) => {
1570
+ return factory9(args);
1571
+ };
1572
+ var toolSearchRegex_20251119OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.array(zod_v4.z.object({
1573
+ type: zod_v4.z.literal("tool_reference"),
1574
+ toolName: zod_v4.z.string()
1575
+ }))));
1576
+ var factory10 = require_dist.createProviderToolFactoryWithOutputSchema({
1577
+ id: "anthropic.tool_search_regex_20251119",
1578
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
1579
+ pattern: zod_v4.z.string(),
1580
+ limit: zod_v4.z.number().optional()
1581
+ }))),
1582
+ outputSchema: toolSearchRegex_20251119OutputSchema,
1583
+ supportsDeferredResults: true
1584
+ });
1585
+ var toolSearchRegex_20251119 = (args = {}) => {
1586
+ return factory10(args);
1587
+ };
1588
+ function convertToString(data) {
1589
+ if (typeof data === "string") return new TextDecoder().decode(require_dist.convertBase64ToUint8Array(data));
1590
+ if (data instanceof Uint8Array) return new TextDecoder().decode(data);
1591
+ if (data instanceof URL) throw new require_dist.UnsupportedFunctionalityError({ functionality: "URL-based text documents are not supported for citations" });
1592
+ throw new require_dist.UnsupportedFunctionalityError({ functionality: `unsupported data type for text documents: ${typeof data}` });
1593
+ }
1594
+ function isUrlData(data) {
1595
+ return data instanceof URL || isUrlString(data);
1596
+ }
1597
+ function isUrlString(data) {
1598
+ return typeof data === "string" && /^https?:\/\//i.test(data);
1599
+ }
1600
+ function getUrlString(data) {
1601
+ return data instanceof URL ? data.toString() : data;
1602
+ }
1603
+ async function extractErrorValue(value) {
1604
+ if (typeof value === "string") {
1605
+ const result = await require_dist.safeParseJSON({ text: value });
1606
+ if (result.success && typeof result.value === "object" && result.value !== null) return result.value;
1607
+ return { errorCode: "unavailable" };
1608
+ }
1609
+ if (typeof value === "object" && value !== null) return value;
1610
+ return {};
1611
+ }
1612
+ async function convertToAnthropicMessagesPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping }) {
1613
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
1614
+ const betas = /* @__PURE__ */ new Set();
1615
+ const blocks = groupIntoBlocks(prompt);
1616
+ const validator = cacheControlValidator || new CacheControlValidator();
1617
+ let system = void 0;
1618
+ const messages = [];
1619
+ async function shouldEnableCitations(providerMetadata) {
1620
+ var _a2, _b2;
1621
+ const anthropicOptions = await require_dist.parseProviderOptions({
1622
+ provider: "anthropic",
1623
+ providerOptions: providerMetadata,
1624
+ schema: anthropicFilePartProviderOptions
1625
+ });
1626
+ return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
1627
+ }
1628
+ async function getDocumentMetadata(providerMetadata) {
1629
+ const anthropicOptions = await require_dist.parseProviderOptions({
1630
+ provider: "anthropic",
1631
+ providerOptions: providerMetadata,
1632
+ schema: anthropicFilePartProviderOptions
1633
+ });
1634
+ return {
1635
+ title: anthropicOptions == null ? void 0 : anthropicOptions.title,
1636
+ context: anthropicOptions == null ? void 0 : anthropicOptions.context
1637
+ };
1638
+ }
1639
+ for (let i = 0; i < blocks.length; i++) {
1640
+ const block = blocks[i];
1641
+ const isLastBlock = i === blocks.length - 1;
1642
+ const type = block.type;
1643
+ switch (type) {
1644
+ case "system": {
1645
+ const content = block.messages.map(({ content: content2, providerOptions }) => ({
1646
+ type: "text",
1647
+ text: content2,
1648
+ cache_control: validator.getCacheControl(providerOptions, {
1649
+ type: "system message",
1650
+ canCache: true
1651
+ })
1652
+ }));
1653
+ if (system == null) system = content;
1654
+ else {
1655
+ messages.push({
1656
+ role: "system",
1657
+ content
1658
+ });
1659
+ betas.add("mid-conversation-system-2026-04-07");
1660
+ }
1661
+ break;
1662
+ }
1663
+ case "user": {
1664
+ const anthropicContent = [];
1665
+ for (const message of block.messages) {
1666
+ const { role, content } = message;
1667
+ switch (role) {
1668
+ case "user":
1669
+ for (let j = 0; j < content.length; j++) {
1670
+ const part = content[j];
1671
+ const isLastPart = j === content.length - 1;
1672
+ const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
1673
+ type: "user message part",
1674
+ canCache: true
1675
+ })) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
1676
+ type: "user message",
1677
+ canCache: true
1678
+ }) : void 0;
1679
+ switch (part.type) {
1680
+ case "text":
1681
+ anthropicContent.push({
1682
+ type: "text",
1683
+ text: part.text,
1684
+ cache_control: cacheControl
1685
+ });
1686
+ break;
1687
+ case "file":
1688
+ if (part.mediaType.startsWith("image/")) anthropicContent.push({
1689
+ type: "image",
1690
+ source: isUrlData(part.data) ? {
1691
+ type: "url",
1692
+ url: getUrlString(part.data)
1693
+ } : {
1694
+ type: "base64",
1695
+ media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
1696
+ data: require_dist.convertToBase64(part.data)
1697
+ },
1698
+ cache_control: cacheControl
1699
+ });
1700
+ else if (part.mediaType === "application/pdf") {
1701
+ betas.add("pdfs-2024-09-25");
1702
+ const enableCitations = await shouldEnableCitations(part.providerOptions);
1703
+ const metadata = await getDocumentMetadata(part.providerOptions);
1704
+ anthropicContent.push({
1705
+ type: "document",
1706
+ source: isUrlData(part.data) ? {
1707
+ type: "url",
1708
+ url: getUrlString(part.data)
1709
+ } : {
1710
+ type: "base64",
1711
+ media_type: "application/pdf",
1712
+ data: require_dist.convertToBase64(part.data)
1713
+ },
1714
+ title: (_b = metadata.title) != null ? _b : part.filename,
1715
+ ...metadata.context && { context: metadata.context },
1716
+ ...enableCitations && { citations: { enabled: true } },
1717
+ cache_control: cacheControl
1718
+ });
1719
+ } else if (part.mediaType === "text/plain") {
1720
+ const enableCitations = await shouldEnableCitations(part.providerOptions);
1721
+ const metadata = await getDocumentMetadata(part.providerOptions);
1722
+ anthropicContent.push({
1723
+ type: "document",
1724
+ source: isUrlData(part.data) ? {
1725
+ type: "url",
1726
+ url: getUrlString(part.data)
1727
+ } : {
1728
+ type: "text",
1729
+ media_type: "text/plain",
1730
+ data: convertToString(part.data)
1731
+ },
1732
+ title: (_c = metadata.title) != null ? _c : part.filename,
1733
+ ...metadata.context && { context: metadata.context },
1734
+ ...enableCitations && { citations: { enabled: true } },
1735
+ cache_control: cacheControl
1736
+ });
1737
+ } else throw new require_dist.UnsupportedFunctionalityError({ functionality: `media type: ${part.mediaType}` });
1738
+ break;
1739
+ }
1740
+ }
1741
+ break;
1742
+ case "tool":
1743
+ for (let i2 = 0; i2 < content.length; i2++) {
1744
+ const part = content[i2];
1745
+ if (part.type === "tool-approval-response") continue;
1746
+ const output = part.output;
1747
+ const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_d = output.value.find((contentPart) => contentPart.providerOptions != null)) == null ? void 0 : _d.providerOptions : void 0;
1748
+ const isLastPart = i2 === content.length - 1;
1749
+ const cacheControl = (_f = (_e = validator.getCacheControl(part.providerOptions, {
1750
+ type: "tool result part",
1751
+ canCache: true
1752
+ })) != null ? _e : validator.getCacheControl(outputProviderOptions, {
1753
+ type: "tool result output",
1754
+ canCache: true
1755
+ })) != null ? _f : isLastPart ? validator.getCacheControl(message.providerOptions, {
1756
+ type: "tool result message",
1757
+ canCache: true
1758
+ }) : void 0;
1759
+ let contentValue;
1760
+ switch (output.type) {
1761
+ case "content":
1762
+ contentValue = output.value.map((contentPart) => {
1763
+ var _a2;
1764
+ switch (contentPart.type) {
1765
+ case "text": return {
1766
+ type: "text",
1767
+ text: contentPart.text
1768
+ };
1769
+ case "image-data": return {
1770
+ type: "image",
1771
+ source: {
1772
+ type: "base64",
1773
+ media_type: contentPart.mediaType,
1774
+ data: contentPart.data
1775
+ }
1776
+ };
1777
+ case "image-url": return {
1778
+ type: "image",
1779
+ source: {
1780
+ type: "url",
1781
+ url: contentPart.url
1782
+ }
1783
+ };
1784
+ case "file-url": return {
1785
+ type: "document",
1786
+ source: {
1787
+ type: "url",
1788
+ url: contentPart.url
1789
+ }
1790
+ };
1791
+ case "file-data":
1792
+ if (contentPart.mediaType === "application/pdf") {
1793
+ betas.add("pdfs-2024-09-25");
1794
+ return {
1795
+ type: "document",
1796
+ source: {
1797
+ type: "base64",
1798
+ media_type: contentPart.mediaType,
1799
+ data: contentPart.data
1800
+ }
1801
+ };
1802
+ }
1803
+ warnings.push({
1804
+ type: "other",
1805
+ message: `unsupported tool content part type: ${contentPart.type} with media type: ${contentPart.mediaType}`
1806
+ });
1807
+ return;
1808
+ case "custom": {
1809
+ const anthropicOptions = (_a2 = contentPart.providerOptions) == null ? void 0 : _a2.anthropic;
1810
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.type) === "tool-reference") return {
1811
+ type: "tool_reference",
1812
+ tool_name: anthropicOptions.toolName
1813
+ };
1814
+ warnings.push({
1815
+ type: "other",
1816
+ message: `unsupported custom tool content part`
1817
+ });
1818
+ return;
1819
+ }
1820
+ default:
1821
+ warnings.push({
1822
+ type: "other",
1823
+ message: `unsupported tool content part type: ${contentPart.type}`
1824
+ });
1825
+ return;
1826
+ }
1827
+ }).filter(require_dist.isNonNullable);
1828
+ break;
1829
+ case "text":
1830
+ case "error-text":
1831
+ contentValue = output.value;
1832
+ break;
1833
+ case "execution-denied":
1834
+ contentValue = (_g = output.reason) != null ? _g : "Tool execution denied.";
1835
+ break;
1836
+ case "json":
1837
+ case "error-json":
1838
+ default:
1839
+ contentValue = JSON.stringify(output.value);
1840
+ break;
1841
+ }
1842
+ anthropicContent.push({
1843
+ type: "tool_result",
1844
+ tool_use_id: part.toolCallId,
1845
+ content: contentValue,
1846
+ is_error: output.type === "error-text" || output.type === "error-json" ? true : void 0,
1847
+ cache_control: cacheControl
1848
+ });
1849
+ }
1850
+ break;
1851
+ default: {
1852
+ const _exhaustiveCheck = role;
1853
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
1854
+ }
1855
+ }
1856
+ }
1857
+ messages.push({
1858
+ role: "user",
1859
+ content: anthropicContent
1860
+ });
1861
+ break;
1862
+ }
1863
+ case "assistant": {
1864
+ const anthropicContent = [];
1865
+ const mcpToolUseIds = /* @__PURE__ */ new Set();
1866
+ for (let j = 0; j < block.messages.length; j++) {
1867
+ const message = block.messages[j];
1868
+ const isLastMessage = j === block.messages.length - 1;
1869
+ const { content } = message;
1870
+ for (let k = 0; k < content.length; k++) {
1871
+ const part = content[k];
1872
+ const isLastContentPart = k === content.length - 1;
1873
+ const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1874
+ type: "assistant message part",
1875
+ canCache: true
1876
+ })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1877
+ type: "assistant message",
1878
+ canCache: true
1879
+ }) : void 0;
1880
+ switch (part.type) {
1881
+ case "text": {
1882
+ const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1883
+ if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") anthropicContent.push({
1884
+ type: "compaction",
1885
+ content: part.text,
1886
+ cache_control: cacheControl
1887
+ });
1888
+ else anthropicContent.push({
1889
+ type: "text",
1890
+ text: isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text,
1891
+ cache_control: cacheControl
1892
+ });
1893
+ break;
1894
+ }
1895
+ case "reasoning":
1896
+ if (sendReasoning) {
1897
+ const reasoningMetadata = await require_dist.parseProviderOptions({
1898
+ provider: "anthropic",
1899
+ providerOptions: part.providerOptions,
1900
+ schema: anthropicReasoningMetadataSchema
1901
+ });
1902
+ if (reasoningMetadata != null) if (reasoningMetadata.signature != null) {
1903
+ validator.getCacheControl(part.providerOptions, {
1904
+ type: "thinking block",
1905
+ canCache: false
1906
+ });
1907
+ anthropicContent.push({
1908
+ type: "thinking",
1909
+ thinking: part.text,
1910
+ signature: reasoningMetadata.signature
1911
+ });
1912
+ } else if (reasoningMetadata.redactedData != null) {
1913
+ validator.getCacheControl(part.providerOptions, {
1914
+ type: "redacted thinking block",
1915
+ canCache: false
1916
+ });
1917
+ anthropicContent.push({
1918
+ type: "redacted_thinking",
1919
+ data: reasoningMetadata.redactedData
1920
+ });
1921
+ } else warnings.push({
1922
+ type: "other",
1923
+ message: "unsupported reasoning metadata"
1924
+ });
1925
+ else warnings.push({
1926
+ type: "other",
1927
+ message: "unsupported reasoning metadata"
1928
+ });
1929
+ } else warnings.push({
1930
+ type: "other",
1931
+ message: "sending reasoning content is disabled for this model"
1932
+ });
1933
+ break;
1934
+ case "tool-call": {
1935
+ if (part.providerExecuted) {
1936
+ const providerToolName = toolNameMapping.toProviderToolName(part.toolName);
1937
+ if (((_k = (_j = part.providerOptions) == null ? void 0 : _j.anthropic) == null ? void 0 : _k.type) === "mcp-tool-use") {
1938
+ mcpToolUseIds.add(part.toolCallId);
1939
+ const serverName = (_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.serverName;
1940
+ if (serverName == null || typeof serverName !== "string") {
1941
+ warnings.push({
1942
+ type: "other",
1943
+ message: "mcp tool use server name is required and must be a string"
1944
+ });
1945
+ break;
1946
+ }
1947
+ anthropicContent.push({
1948
+ type: "mcp_tool_use",
1949
+ id: part.toolCallId,
1950
+ name: part.toolName,
1951
+ input: part.input,
1952
+ server_name: serverName,
1953
+ cache_control: cacheControl
1954
+ });
1955
+ } else if (providerToolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && typeof part.input.type === "string" && (part.input.type === "bash_code_execution" || part.input.type === "text_editor_code_execution")) anthropicContent.push({
1956
+ type: "server_tool_use",
1957
+ id: part.toolCallId,
1958
+ name: part.input.type,
1959
+ input: part.input,
1960
+ cache_control: cacheControl
1961
+ });
1962
+ else if (providerToolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && part.input.type === "programmatic-tool-call") {
1963
+ const { type: _,...inputWithoutType } = part.input;
1964
+ anthropicContent.push({
1965
+ type: "server_tool_use",
1966
+ id: part.toolCallId,
1967
+ name: "code_execution",
1968
+ input: inputWithoutType,
1969
+ cache_control: cacheControl
1970
+ });
1971
+ } else if (providerToolName === "code_execution" || providerToolName === "web_fetch" || providerToolName === "web_search") anthropicContent.push({
1972
+ type: "server_tool_use",
1973
+ id: part.toolCallId,
1974
+ name: providerToolName,
1975
+ input: part.input,
1976
+ cache_control: cacheControl
1977
+ });
1978
+ else if (providerToolName === "tool_search_tool_regex" || providerToolName === "tool_search_tool_bm25") anthropicContent.push({
1979
+ type: "server_tool_use",
1980
+ id: part.toolCallId,
1981
+ name: providerToolName,
1982
+ input: part.input,
1983
+ cache_control: cacheControl
1984
+ });
1985
+ else if (providerToolName === "advisor") anthropicContent.push({
1986
+ type: "server_tool_use",
1987
+ id: part.toolCallId,
1988
+ name: "advisor",
1989
+ input: {},
1990
+ cache_control: cacheControl
1991
+ });
1992
+ else warnings.push({
1993
+ type: "other",
1994
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
1995
+ });
1996
+ break;
1997
+ }
1998
+ const callerOptions = (_n = part.providerOptions) == null ? void 0 : _n.anthropic;
1999
+ const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
2000
+ type: callerOptions.caller.type,
2001
+ tool_id: callerOptions.caller.toolId
2002
+ } : callerOptions.caller.type === "direct" ? { type: "direct" } : void 0 : void 0;
2003
+ anthropicContent.push({
2004
+ type: "tool_use",
2005
+ id: part.toolCallId,
2006
+ name: part.toolName,
2007
+ input: part.input,
2008
+ ...caller && { caller },
2009
+ cache_control: cacheControl
2010
+ });
2011
+ break;
2012
+ }
2013
+ case "tool-result": {
2014
+ const providerToolName = toolNameMapping.toProviderToolName(part.toolName);
2015
+ if (mcpToolUseIds.has(part.toolCallId)) {
2016
+ const output = part.output;
2017
+ if (output.type !== "json" && output.type !== "error-json") {
2018
+ warnings.push({
2019
+ type: "other",
2020
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
2021
+ });
2022
+ break;
2023
+ }
2024
+ anthropicContent.push({
2025
+ type: "mcp_tool_result",
2026
+ tool_use_id: part.toolCallId,
2027
+ is_error: output.type === "error-json",
2028
+ content: output.value,
2029
+ cache_control: cacheControl
2030
+ });
2031
+ } else if (providerToolName === "code_execution") {
2032
+ const output = part.output;
2033
+ if (output.type === "error-text" || output.type === "error-json") {
2034
+ let errorInfo = {};
2035
+ try {
2036
+ if (typeof output.value === "string") errorInfo = JSON.parse(output.value);
2037
+ else if (typeof output.value === "object" && output.value !== null) errorInfo = output.value;
2038
+ } catch (e) {}
2039
+ if (errorInfo.type === "code_execution_tool_result_error") anthropicContent.push({
2040
+ type: "code_execution_tool_result",
2041
+ tool_use_id: part.toolCallId,
2042
+ content: {
2043
+ type: "code_execution_tool_result_error",
2044
+ error_code: (_o = errorInfo.errorCode) != null ? _o : "unknown"
2045
+ },
2046
+ cache_control: cacheControl
2047
+ });
2048
+ else anthropicContent.push({
2049
+ type: "bash_code_execution_tool_result",
2050
+ tool_use_id: part.toolCallId,
2051
+ cache_control: cacheControl,
2052
+ content: {
2053
+ type: "bash_code_execution_tool_result_error",
2054
+ error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
2055
+ }
2056
+ });
2057
+ break;
2058
+ }
2059
+ if (output.type !== "json") {
2060
+ warnings.push({
2061
+ type: "other",
2062
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
2063
+ });
2064
+ break;
2065
+ }
2066
+ if (output.value == null || typeof output.value !== "object" || !("type" in output.value) || typeof output.value.type !== "string") {
2067
+ warnings.push({
2068
+ type: "other",
2069
+ message: `provider executed tool result output value is not a valid code execution result for tool ${part.toolName}`
2070
+ });
2071
+ break;
2072
+ }
2073
+ if (output.value.type === "code_execution_result") {
2074
+ const codeExecutionOutput = await require_dist.validateTypes({
2075
+ value: output.value,
2076
+ schema: codeExecution_20250522OutputSchema
2077
+ });
2078
+ anthropicContent.push({
2079
+ type: "code_execution_tool_result",
2080
+ tool_use_id: part.toolCallId,
2081
+ content: {
2082
+ type: codeExecutionOutput.type,
2083
+ stdout: codeExecutionOutput.stdout,
2084
+ stderr: codeExecutionOutput.stderr,
2085
+ return_code: codeExecutionOutput.return_code,
2086
+ content: (_q = codeExecutionOutput.content) != null ? _q : []
2087
+ },
2088
+ cache_control: cacheControl
2089
+ });
2090
+ } else if (output.value.type === "encrypted_code_execution_result") {
2091
+ const codeExecutionOutput = await require_dist.validateTypes({
2092
+ value: output.value,
2093
+ schema: codeExecution_20260120OutputSchema
2094
+ });
2095
+ if (codeExecutionOutput.type === "encrypted_code_execution_result") anthropicContent.push({
2096
+ type: "code_execution_tool_result",
2097
+ tool_use_id: part.toolCallId,
2098
+ content: {
2099
+ type: codeExecutionOutput.type,
2100
+ encrypted_stdout: codeExecutionOutput.encrypted_stdout,
2101
+ stderr: codeExecutionOutput.stderr,
2102
+ return_code: codeExecutionOutput.return_code,
2103
+ content: (_r = codeExecutionOutput.content) != null ? _r : []
2104
+ },
2105
+ cache_control: cacheControl
2106
+ });
2107
+ } else {
2108
+ const codeExecutionOutput = await require_dist.validateTypes({
2109
+ value: output.value,
2110
+ schema: codeExecution_20250825OutputSchema
2111
+ });
2112
+ if (codeExecutionOutput.type === "code_execution_result") anthropicContent.push({
2113
+ type: "code_execution_tool_result",
2114
+ tool_use_id: part.toolCallId,
2115
+ content: {
2116
+ type: codeExecutionOutput.type,
2117
+ stdout: codeExecutionOutput.stdout,
2118
+ stderr: codeExecutionOutput.stderr,
2119
+ return_code: codeExecutionOutput.return_code,
2120
+ content: (_s = codeExecutionOutput.content) != null ? _s : []
2121
+ },
2122
+ cache_control: cacheControl
2123
+ });
2124
+ else if (codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error") anthropicContent.push({
2125
+ type: "bash_code_execution_tool_result",
2126
+ tool_use_id: part.toolCallId,
2127
+ cache_control: cacheControl,
2128
+ content: codeExecutionOutput
2129
+ });
2130
+ else anthropicContent.push({
2131
+ type: "text_editor_code_execution_tool_result",
2132
+ tool_use_id: part.toolCallId,
2133
+ cache_control: cacheControl,
2134
+ content: codeExecutionOutput
2135
+ });
2136
+ }
2137
+ break;
2138
+ }
2139
+ if (providerToolName === "web_fetch") {
2140
+ const output = part.output;
2141
+ if (output.type === "error-json") {
2142
+ anthropicContent.push({
2143
+ type: "web_fetch_tool_result",
2144
+ tool_use_id: part.toolCallId,
2145
+ content: {
2146
+ type: "web_fetch_tool_result_error",
2147
+ error_code: (_t = (await extractErrorValue(output.value)).errorCode) != null ? _t : "unavailable"
2148
+ },
2149
+ cache_control: cacheControl
2150
+ });
2151
+ break;
2152
+ }
2153
+ if (output.type !== "json") {
2154
+ warnings.push({
2155
+ type: "other",
2156
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
2157
+ });
2158
+ break;
2159
+ }
2160
+ const webFetchOutput = await require_dist.validateTypes({
2161
+ value: output.value,
2162
+ schema: webFetch_20250910OutputSchema
2163
+ });
2164
+ anthropicContent.push({
2165
+ type: "web_fetch_tool_result",
2166
+ tool_use_id: part.toolCallId,
2167
+ content: {
2168
+ type: "web_fetch_result",
2169
+ url: webFetchOutput.url,
2170
+ retrieved_at: webFetchOutput.retrievedAt,
2171
+ content: {
2172
+ type: "document",
2173
+ title: webFetchOutput.content.title,
2174
+ citations: webFetchOutput.content.citations,
2175
+ source: {
2176
+ type: webFetchOutput.content.source.type,
2177
+ media_type: webFetchOutput.content.source.mediaType,
2178
+ data: webFetchOutput.content.source.data
2179
+ }
2180
+ }
2181
+ },
2182
+ cache_control: cacheControl
2183
+ });
2184
+ break;
2185
+ }
2186
+ if (providerToolName === "web_search") {
2187
+ const output = part.output;
2188
+ if (output.type === "error-json") {
2189
+ anthropicContent.push({
2190
+ type: "web_search_tool_result",
2191
+ tool_use_id: part.toolCallId,
2192
+ content: {
2193
+ type: "web_search_tool_result_error",
2194
+ error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
2195
+ },
2196
+ cache_control: cacheControl
2197
+ });
2198
+ break;
2199
+ }
2200
+ if (output.type !== "json") {
2201
+ warnings.push({
2202
+ type: "other",
2203
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
2204
+ });
2205
+ break;
2206
+ }
2207
+ const webSearchOutput = await require_dist.validateTypes({
2208
+ value: output.value,
2209
+ schema: webSearch_20250305OutputSchema
2210
+ });
2211
+ anthropicContent.push({
2212
+ type: "web_search_tool_result",
2213
+ tool_use_id: part.toolCallId,
2214
+ content: webSearchOutput.map((result) => ({
2215
+ url: result.url,
2216
+ title: result.title,
2217
+ page_age: result.pageAge,
2218
+ encrypted_content: result.encryptedContent,
2219
+ type: result.type
2220
+ })),
2221
+ cache_control: cacheControl
2222
+ });
2223
+ break;
2224
+ }
2225
+ if (providerToolName === "tool_search_tool_regex" || providerToolName === "tool_search_tool_bm25") {
2226
+ const output = part.output;
2227
+ if (output.type !== "json") {
2228
+ warnings.push({
2229
+ type: "other",
2230
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
2231
+ });
2232
+ break;
2233
+ }
2234
+ const toolReferences = (await require_dist.validateTypes({
2235
+ value: output.value,
2236
+ schema: toolSearchRegex_20251119OutputSchema
2237
+ })).map((ref) => ({
2238
+ type: "tool_reference",
2239
+ tool_name: ref.toolName
2240
+ }));
2241
+ anthropicContent.push({
2242
+ type: "tool_search_tool_result",
2243
+ tool_use_id: part.toolCallId,
2244
+ content: {
2245
+ type: "tool_search_tool_search_result",
2246
+ tool_references: toolReferences
2247
+ },
2248
+ cache_control: cacheControl
2249
+ });
2250
+ break;
2251
+ }
2252
+ if (providerToolName === "advisor") {
2253
+ const output = part.output;
2254
+ if (output.type !== "json" && output.type !== "error-json") {
2255
+ warnings.push({
2256
+ type: "other",
2257
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
2258
+ });
2259
+ break;
2260
+ }
2261
+ const advisorOutput = await require_dist.validateTypes({
2262
+ value: output.value,
2263
+ schema: advisor_20260301OutputSchema
2264
+ });
2265
+ if (advisorOutput.type === "advisor_result") anthropicContent.push({
2266
+ type: "advisor_tool_result",
2267
+ tool_use_id: part.toolCallId,
2268
+ content: {
2269
+ type: "advisor_result",
2270
+ text: advisorOutput.text
2271
+ },
2272
+ cache_control: cacheControl
2273
+ });
2274
+ else if (advisorOutput.type === "advisor_redacted_result") anthropicContent.push({
2275
+ type: "advisor_tool_result",
2276
+ tool_use_id: part.toolCallId,
2277
+ content: {
2278
+ type: "advisor_redacted_result",
2279
+ encrypted_content: advisorOutput.encryptedContent
2280
+ },
2281
+ cache_control: cacheControl
2282
+ });
2283
+ else anthropicContent.push({
2284
+ type: "advisor_tool_result",
2285
+ tool_use_id: part.toolCallId,
2286
+ content: {
2287
+ type: "advisor_tool_result_error",
2288
+ error_code: advisorOutput.errorCode
2289
+ },
2290
+ cache_control: cacheControl
2291
+ });
2292
+ break;
2293
+ }
2294
+ warnings.push({
2295
+ type: "other",
2296
+ message: `provider executed tool result for tool ${part.toolName} is not supported`
2297
+ });
2298
+ break;
2299
+ }
2300
+ }
2301
+ }
2302
+ }
2303
+ messages.push({
2304
+ role: "assistant",
2305
+ content: anthropicContent
2306
+ });
2307
+ break;
2308
+ }
2309
+ default: {
2310
+ const _exhaustiveCheck = type;
2311
+ throw new Error(`content type: ${_exhaustiveCheck}`);
2312
+ }
2313
+ }
2314
+ }
2315
+ return {
2316
+ prompt: {
2317
+ system,
2318
+ messages
2319
+ },
2320
+ betas
2321
+ };
2322
+ }
2323
+ function groupIntoBlocks(prompt) {
2324
+ const blocks = [];
2325
+ let currentBlock = void 0;
2326
+ for (const message of prompt) {
2327
+ const { role } = message;
2328
+ switch (role) {
2329
+ case "system":
2330
+ if ((currentBlock == null ? void 0 : currentBlock.type) !== "system") {
2331
+ currentBlock = {
2332
+ type: "system",
2333
+ messages: []
2334
+ };
2335
+ blocks.push(currentBlock);
2336
+ }
2337
+ currentBlock.messages.push(message);
2338
+ break;
2339
+ case "assistant":
2340
+ if ((currentBlock == null ? void 0 : currentBlock.type) !== "assistant") {
2341
+ currentBlock = {
2342
+ type: "assistant",
2343
+ messages: []
2344
+ };
2345
+ blocks.push(currentBlock);
2346
+ }
2347
+ currentBlock.messages.push(message);
2348
+ break;
2349
+ case "user":
2350
+ if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
2351
+ currentBlock = {
2352
+ type: "user",
2353
+ messages: []
2354
+ };
2355
+ blocks.push(currentBlock);
2356
+ }
2357
+ currentBlock.messages.push(message);
2358
+ break;
2359
+ case "tool":
2360
+ if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
2361
+ currentBlock = {
2362
+ type: "user",
2363
+ messages: []
2364
+ };
2365
+ blocks.push(currentBlock);
2366
+ }
2367
+ currentBlock.messages.push(message);
2368
+ break;
2369
+ default: {
2370
+ const _exhaustiveCheck = role;
2371
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
2372
+ }
2373
+ }
2374
+ }
2375
+ return blocks;
2376
+ }
2377
+ function mapAnthropicStopReason({ finishReason, isJsonResponseFromTool }) {
2378
+ switch (finishReason) {
2379
+ case "pause_turn":
2380
+ case "end_turn":
2381
+ case "stop_sequence": return "stop";
2382
+ case "refusal": return "content-filter";
2383
+ case "tool_use": return isJsonResponseFromTool ? "stop" : "tool-calls";
2384
+ case "max_tokens":
2385
+ case "model_context_window_exceeded": return "length";
2386
+ case "compaction": return "other";
2387
+ default: return "other";
2388
+ }
2389
+ }
2390
+ var SUPPORTED_STRING_FORMATS = /* @__PURE__ */ new Set([
2391
+ "date-time",
2392
+ "time",
2393
+ "date",
2394
+ "duration",
2395
+ "email",
2396
+ "hostname",
2397
+ "uri",
2398
+ "ipv4",
2399
+ "ipv6",
2400
+ "uuid"
2401
+ ]);
2402
+ var DESCRIPTION_CONSTRAINT_KEYS = [
2403
+ "minimum",
2404
+ "maximum",
2405
+ "exclusiveMinimum",
2406
+ "exclusiveMaximum",
2407
+ "multipleOf",
2408
+ "minLength",
2409
+ "maxLength",
2410
+ "pattern",
2411
+ "minItems",
2412
+ "maxItems",
2413
+ "uniqueItems",
2414
+ "minProperties",
2415
+ "maxProperties",
2416
+ "not"
2417
+ ];
2418
+ function sanitizeJsonSchema(schema) {
2419
+ return sanitizeSchema(schema);
2420
+ }
2421
+ function sanitizeDefinition(definition) {
2422
+ if (typeof definition === "boolean" || !isPlainObject(definition)) return definition;
2423
+ return sanitizeSchema(definition);
2424
+ }
2425
+ function sanitizeSchema(schema) {
2426
+ const result = {};
2427
+ const schemaWithDefs = schema;
2428
+ if (schema.$ref != null) return { $ref: schema.$ref };
2429
+ if (schema.$schema != null) result.$schema = schema.$schema;
2430
+ if (schema.$id != null) result.$id = schema.$id;
2431
+ if (schema.title != null) result.title = schema.title;
2432
+ if (schema.description != null) result.description = schema.description;
2433
+ if (schema.default !== void 0) result.default = schema.default;
2434
+ if (schema.const !== void 0) result.const = schema.const;
2435
+ if (schema.enum != null) result.enum = schema.enum;
2436
+ if (schema.type != null) result.type = schema.type;
2437
+ if (schema.anyOf != null) result.anyOf = schema.anyOf.map(sanitizeDefinition);
2438
+ else if (schema.oneOf != null) result.anyOf = schema.oneOf.map(sanitizeDefinition);
2439
+ if (schema.allOf != null) result.allOf = schema.allOf.map(sanitizeDefinition);
2440
+ if (schema.definitions != null) result.definitions = Object.fromEntries(Object.entries(schema.definitions).map(([name, definition]) => [name, sanitizeDefinition(definition)]));
2441
+ if (schemaWithDefs.$defs != null) {
2442
+ const resultWithDefs = result;
2443
+ resultWithDefs.$defs = Object.fromEntries(Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [name, sanitizeDefinition(definition)]));
2444
+ }
2445
+ if (schema.type === "object" || schema.properties != null) {
2446
+ if (schema.properties != null) result.properties = Object.fromEntries(Object.entries(schema.properties).map(([name, definition]) => [name, sanitizeDefinition(definition)]));
2447
+ result.additionalProperties = false;
2448
+ if (schema.required != null) result.required = schema.required;
2449
+ }
2450
+ if (schema.items != null) result.items = Array.isArray(schema.items) ? schema.items.map(sanitizeDefinition) : sanitizeDefinition(schema.items);
2451
+ if (typeof schema.format === "string" && SUPPORTED_STRING_FORMATS.has(schema.format)) result.format = schema.format;
2452
+ const constraintDescription = getConstraintDescription(schema);
2453
+ if (constraintDescription != null) result.description = result.description == null ? constraintDescription : `${result.description}
2454
+ ${constraintDescription}`;
2455
+ return result;
2456
+ }
2457
+ function getConstraintDescription(schema) {
2458
+ const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
2459
+ const value = schema[key];
2460
+ if (value == null || value === false) return [];
2461
+ return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
2462
+ });
2463
+ if (typeof schema.format === "string" && !SUPPORTED_STRING_FORMATS.has(schema.format)) descriptions.push(`format: ${schema.format}`);
2464
+ return descriptions.length === 0 ? void 0 : `${descriptions.join("; ")}.`;
2465
+ }
2466
+ function formatConstraintName(key) {
2467
+ return key.replace(/[A-Z]/g, (match) => ` ${match.toLowerCase()}`);
2468
+ }
2469
+ function formatConstraintValue(value) {
2470
+ if (typeof value === "string") return value;
2471
+ return JSON.stringify(value);
2472
+ }
2473
+ function isPlainObject(value) {
2474
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2475
+ }
2476
+ function createCitationSource(citation, citationDocuments, generateId3) {
2477
+ var _a;
2478
+ if (citation.type === "web_search_result_location") return {
2479
+ type: "source",
2480
+ sourceType: "url",
2481
+ id: generateId3(),
2482
+ url: citation.url,
2483
+ title: citation.title,
2484
+ providerMetadata: { anthropic: {
2485
+ citedText: citation.cited_text,
2486
+ encryptedIndex: citation.encrypted_index
2487
+ } }
2488
+ };
2489
+ if (citation.type !== "page_location" && citation.type !== "char_location") return;
2490
+ const documentInfo = citationDocuments[citation.document_index];
2491
+ if (!documentInfo) return;
2492
+ return {
2493
+ type: "source",
2494
+ sourceType: "document",
2495
+ id: generateId3(),
2496
+ mediaType: documentInfo.mediaType,
2497
+ title: (_a = citation.document_title) != null ? _a : documentInfo.title,
2498
+ filename: documentInfo.filename,
2499
+ providerMetadata: { anthropic: citation.type === "page_location" ? {
2500
+ citedText: citation.cited_text,
2501
+ startPageNumber: citation.start_page_number,
2502
+ endPageNumber: citation.end_page_number
2503
+ } : {
2504
+ citedText: citation.cited_text,
2505
+ startCharIndex: citation.start_char_index,
2506
+ endCharIndex: citation.end_char_index
2507
+ } }
2508
+ };
2509
+ }
2510
+ var AnthropicMessagesLanguageModel = class {
2511
+ constructor(modelId, config) {
2512
+ this.specificationVersion = "v3";
2513
+ var _a;
2514
+ this.modelId = modelId;
2515
+ this.config = config;
2516
+ this.generateId = (_a = config.generateId) != null ? _a : require_dist.generateId;
2517
+ }
2518
+ supportsUrl(url) {
2519
+ return url.protocol === "https:";
2520
+ }
2521
+ get provider() {
2522
+ return this.config.provider;
2523
+ }
2524
+ /**
2525
+ * Extracts the dynamic provider name from the config.provider string.
2526
+ * e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
2527
+ */
2528
+ get providerOptionsName() {
2529
+ const provider = this.config.provider;
2530
+ const dotIndex = provider.indexOf(".");
2531
+ return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
2532
+ }
2533
+ get supportedUrls() {
2534
+ var _a, _b, _c;
2535
+ return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
2536
+ }
2537
+ async getArgs({ userSuppliedBetas, prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, providerOptions, stream }) {
2538
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2539
+ const warnings = [];
2540
+ if (frequencyPenalty != null) warnings.push({
2541
+ type: "unsupported",
2542
+ feature: "frequencyPenalty"
2543
+ });
2544
+ if (presencePenalty != null) warnings.push({
2545
+ type: "unsupported",
2546
+ feature: "presencePenalty"
2547
+ });
2548
+ if (seed != null) warnings.push({
2549
+ type: "unsupported",
2550
+ feature: "seed"
2551
+ });
2552
+ if (temperature != null && temperature > 1) {
2553
+ warnings.push({
2554
+ type: "unsupported",
2555
+ feature: "temperature",
2556
+ details: `${temperature} exceeds anthropic maximum of 1.0. clamped to 1.0`
2557
+ });
2558
+ temperature = 1;
2559
+ } else if (temperature != null && temperature < 0) {
2560
+ warnings.push({
2561
+ type: "unsupported",
2562
+ feature: "temperature",
2563
+ details: `${temperature} is below anthropic minimum of 0. clamped to 0`
2564
+ });
2565
+ temperature = 0;
2566
+ }
2567
+ if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
2568
+ if (responseFormat.schema == null) warnings.push({
2569
+ type: "unsupported",
2570
+ feature: "responseFormat",
2571
+ details: "JSON response format requires a schema. The response format is ignored."
2572
+ });
2573
+ }
2574
+ const providerOptionsName = this.providerOptionsName;
2575
+ const canonicalOptions = await require_dist.parseProviderOptions({
2576
+ provider: "anthropic",
2577
+ providerOptions,
2578
+ schema: anthropicLanguageModelOptions
2579
+ });
2580
+ const customProviderOptions = providerOptionsName !== "anthropic" ? await require_dist.parseProviderOptions({
2581
+ provider: providerOptionsName,
2582
+ providerOptions,
2583
+ schema: anthropicLanguageModelOptions
2584
+ }) : null;
2585
+ const usedCustomProviderKey = customProviderOptions != null;
2586
+ const anthropicOptions = Object.assign({}, canonicalOptions != null ? canonicalOptions : {}, customProviderOptions != null ? customProviderOptions : {});
2587
+ const { maxOutputTokens: maxOutputTokensForModel, supportsStructuredOutput: modelSupportsStructuredOutput, rejectsSamplingParameters, isKnownModel } = getModelCapabilities(this.modelId);
2588
+ if (rejectsSamplingParameters) {
2589
+ if (temperature != null) {
2590
+ warnings.push({
2591
+ type: "unsupported",
2592
+ feature: "temperature",
2593
+ details: `temperature is not supported by ${this.modelId} and will be ignored`
2594
+ });
2595
+ temperature = void 0;
2596
+ }
2597
+ if (topK != null) {
2598
+ warnings.push({
2599
+ type: "unsupported",
2600
+ feature: "topK",
2601
+ details: `topK is not supported by ${this.modelId} and will be ignored`
2602
+ });
2603
+ topK = void 0;
2604
+ }
2605
+ if (topP != null) {
2606
+ warnings.push({
2607
+ type: "unsupported",
2608
+ feature: "topP",
2609
+ details: `topP is not supported by ${this.modelId} and will be ignored`
2610
+ });
2611
+ topP = void 0;
2612
+ }
2613
+ }
2614
+ const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
2615
+ const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
2616
+ const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
2617
+ const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
2618
+ const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2619
+ const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
2620
+ type: "function",
2621
+ name: "json",
2622
+ description: "Respond with a JSON object.",
2623
+ inputSchema: responseFormat.schema
2624
+ } : void 0;
2625
+ const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
2626
+ const cacheControlValidator = new CacheControlValidator();
2627
+ const toolNameMapping = require_dist.createToolNameMapping({
2628
+ tools,
2629
+ providerToolNames: {
2630
+ "anthropic.code_execution_20250522": "code_execution",
2631
+ "anthropic.code_execution_20250825": "code_execution",
2632
+ "anthropic.code_execution_20260120": "code_execution",
2633
+ "anthropic.computer_20241022": "computer",
2634
+ "anthropic.computer_20250124": "computer",
2635
+ "anthropic.text_editor_20241022": "str_replace_editor",
2636
+ "anthropic.text_editor_20250124": "str_replace_editor",
2637
+ "anthropic.text_editor_20250429": "str_replace_based_edit_tool",
2638
+ "anthropic.text_editor_20250728": "str_replace_based_edit_tool",
2639
+ "anthropic.bash_20241022": "bash",
2640
+ "anthropic.bash_20250124": "bash",
2641
+ "anthropic.memory_20250818": "memory",
2642
+ "anthropic.web_search_20250305": "web_search",
2643
+ "anthropic.web_search_20260209": "web_search",
2644
+ "anthropic.web_fetch_20250910": "web_fetch",
2645
+ "anthropic.web_fetch_20260209": "web_fetch",
2646
+ "anthropic.tool_search_regex_20251119": "tool_search_tool_regex",
2647
+ "anthropic.tool_search_bm25_20251119": "tool_search_tool_bm25",
2648
+ "anthropic.advisor_20260301": "advisor"
2649
+ }
2650
+ });
2651
+ const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
2652
+ prompt,
2653
+ sendReasoning: (_d = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _d : true,
2654
+ warnings,
2655
+ cacheControlValidator,
2656
+ toolNameMapping
2657
+ });
2658
+ const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
2659
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2660
+ let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
2661
+ const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
2662
+ const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2663
+ const baseArgs = {
2664
+ model: this.modelId,
2665
+ max_tokens: maxTokens,
2666
+ temperature,
2667
+ top_k: topK,
2668
+ top_p: topP,
2669
+ stop_sequences: stopSequences,
2670
+ ...isThinking && { thinking: {
2671
+ type: thinkingType,
2672
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget },
2673
+ ...thinkingDisplay != null && { display: thinkingDisplay }
2674
+ } },
2675
+ ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && { output_config: {
2676
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && { effort: anthropicOptions.effort },
2677
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && { task_budget: {
2678
+ type: anthropicOptions.taskBudget.type,
2679
+ total: anthropicOptions.taskBudget.total,
2680
+ ...anthropicOptions.taskBudget.remaining != null && { remaining: anthropicOptions.taskBudget.remaining }
2681
+ } },
2682
+ ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && { format: {
2683
+ type: "json_schema",
2684
+ schema: sanitizeJsonSchema(responseFormat.schema)
2685
+ } }
2686
+ } },
2687
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && { speed: anthropicOptions.speed },
2688
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && { inference_geo: anthropicOptions.inferenceGeo },
2689
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && { fallbacks: anthropicOptions.fallbacks },
2690
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && { cache_control: anthropicOptions.cacheControl },
2691
+ ...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && { metadata: { user_id: anthropicOptions.metadata.userId } },
2692
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && { mcp_servers: anthropicOptions.mcpServers.map((server) => ({
2693
+ type: server.type,
2694
+ name: server.name,
2695
+ url: server.url,
2696
+ authorization_token: server.authorizationToken,
2697
+ tool_configuration: server.toolConfiguration ? {
2698
+ allowed_tools: server.toolConfiguration.allowedTools,
2699
+ enabled: server.toolConfiguration.enabled
2700
+ } : void 0
2701
+ })) },
2702
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && { container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? {
2703
+ id: anthropicOptions.container.id,
2704
+ skills: anthropicOptions.container.skills.map((skill) => ({
2705
+ type: skill.type,
2706
+ skill_id: skill.skillId,
2707
+ version: skill.version
2708
+ }))
2709
+ } : anthropicOptions.container.id },
2710
+ system: messagesPrompt.system,
2711
+ messages: messagesPrompt.messages,
2712
+ ...contextManagement && { context_management: { edits: contextManagement.edits.map((edit) => {
2713
+ const strategy = edit.type;
2714
+ switch (strategy) {
2715
+ case "clear_tool_uses_20250919": return {
2716
+ type: edit.type,
2717
+ ...edit.trigger !== void 0 && { trigger: edit.trigger },
2718
+ ...edit.keep !== void 0 && { keep: edit.keep },
2719
+ ...edit.clearAtLeast !== void 0 && { clear_at_least: edit.clearAtLeast },
2720
+ ...edit.clearToolInputs !== void 0 && { clear_tool_inputs: edit.clearToolInputs },
2721
+ ...edit.excludeTools !== void 0 && { exclude_tools: edit.excludeTools }
2722
+ };
2723
+ case "clear_thinking_20251015": return {
2724
+ type: edit.type,
2725
+ ...edit.keep !== void 0 && { keep: edit.keep }
2726
+ };
2727
+ case "compact_20260112": return {
2728
+ type: edit.type,
2729
+ ...edit.trigger !== void 0 && { trigger: edit.trigger },
2730
+ ...edit.pauseAfterCompaction !== void 0 && { pause_after_compaction: edit.pauseAfterCompaction },
2731
+ ...edit.instructions !== void 0 && { instructions: edit.instructions }
2732
+ };
2733
+ default:
2734
+ warnings.push({
2735
+ type: "other",
2736
+ message: `Unknown context management strategy: ${strategy}`
2737
+ });
2738
+ return;
2739
+ }
2740
+ }).filter((edit) => edit !== void 0) } }
2741
+ };
2742
+ if (isThinking) {
2743
+ if (thinkingType === "enabled" && thinkingBudget == null) {
2744
+ warnings.push({
2745
+ type: "compatibility",
2746
+ feature: "extended thinking",
2747
+ details: "thinking budget is required when thinking is enabled. using default budget of 1024 tokens."
2748
+ });
2749
+ baseArgs.thinking = {
2750
+ type: "enabled",
2751
+ budget_tokens: 1024
2752
+ };
2753
+ thinkingBudget = 1024;
2754
+ }
2755
+ if (baseArgs.temperature != null) {
2756
+ baseArgs.temperature = void 0;
2757
+ warnings.push({
2758
+ type: "unsupported",
2759
+ feature: "temperature",
2760
+ details: "temperature is not supported when thinking is enabled"
2761
+ });
2762
+ }
2763
+ if (topK != null) {
2764
+ baseArgs.top_k = void 0;
2765
+ warnings.push({
2766
+ type: "unsupported",
2767
+ feature: "topK",
2768
+ details: "topK is not supported when thinking is enabled"
2769
+ });
2770
+ }
2771
+ if (topP != null) {
2772
+ baseArgs.top_p = void 0;
2773
+ warnings.push({
2774
+ type: "unsupported",
2775
+ feature: "topP",
2776
+ details: "topP is not supported when thinking is enabled"
2777
+ });
2778
+ }
2779
+ baseArgs.max_tokens = maxTokens + (thinkingBudget != null ? thinkingBudget : 0);
2780
+ } else if (isAnthropicModel && topP != null && temperature != null) {
2781
+ warnings.push({
2782
+ type: "unsupported",
2783
+ feature: "topP",
2784
+ details: `topP is not supported when temperature is set. topP is ignored.`
2785
+ });
2786
+ baseArgs.top_p = void 0;
2787
+ }
2788
+ if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
2789
+ if (maxOutputTokens != null) warnings.push({
2790
+ type: "unsupported",
2791
+ feature: "maxOutputTokens",
2792
+ details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
2793
+ });
2794
+ baseArgs.max_tokens = maxOutputTokensForModel;
2795
+ }
2796
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) betas.add("mcp-client-2025-04-04");
2797
+ if (contextManagement) {
2798
+ betas.add("context-management-2025-06-27");
2799
+ if (contextManagement.edits.some((e) => e.type === "compact_20260112")) betas.add("compact-2026-01-12");
2800
+ }
2801
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
2802
+ betas.add("code-execution-2025-08-25");
2803
+ betas.add("skills-2025-10-02");
2804
+ betas.add("files-api-2025-04-14");
2805
+ if (!(tools == null ? void 0 : tools.some((tool) => tool.type === "provider" && (tool.id === "anthropic.code_execution_20250825" || tool.id === "anthropic.code_execution_20260120")))) warnings.push({
2806
+ type: "other",
2807
+ message: "code execution tool is required when using skills"
2808
+ });
2809
+ }
2810
+ if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) betas.add("task-budgets-2026-03-13");
2811
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") betas.add("fast-mode-2026-02-01");
2812
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) betas.add("server-side-fallback-2026-06-01");
2813
+ const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
2814
+ const { tools: anthropicTools2, toolChoice: anthropicToolChoice, toolWarnings, betas: toolsBetas } = await prepareTools(jsonResponseTool != null ? {
2815
+ tools: [...tools != null ? tools : [], jsonResponseTool],
2816
+ toolChoice: { type: "required" },
2817
+ disableParallelToolUse: true,
2818
+ cacheControlValidator,
2819
+ supportsStructuredOutput: false,
2820
+ supportsStrictTools,
2821
+ defaultEagerInputStreaming
2822
+ } : {
2823
+ tools: tools != null ? tools : [],
2824
+ toolChoice,
2825
+ disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
2826
+ cacheControlValidator,
2827
+ supportsStructuredOutput,
2828
+ supportsStrictTools,
2829
+ defaultEagerInputStreaming
2830
+ });
2831
+ const cacheWarnings = cacheControlValidator.getWarnings();
2832
+ return {
2833
+ args: {
2834
+ ...baseArgs,
2835
+ tools: anthropicTools2,
2836
+ tool_choice: anthropicToolChoice,
2837
+ stream: stream === true ? true : void 0
2838
+ },
2839
+ warnings: [
2840
+ ...warnings,
2841
+ ...toolWarnings,
2842
+ ...cacheWarnings
2843
+ ],
2844
+ betas: /* @__PURE__ */ new Set([
2845
+ ...betas,
2846
+ ...toolsBetas,
2847
+ ...userSuppliedBetas,
2848
+ ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
2849
+ ]),
2850
+ usesJsonResponseTool: jsonResponseTool != null,
2851
+ toolNameMapping,
2852
+ providerOptionsName,
2853
+ usedCustomProviderKey
2854
+ };
2855
+ }
2856
+ async getHeaders({ betas, headers }) {
2857
+ return require_dist.combineHeaders(await require_dist.resolve(this.config.headers), headers, betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {});
2858
+ }
2859
+ async getBetasFromHeaders(requestHeaders) {
2860
+ var _a, _b;
2861
+ const configBetaHeader = (_a = (await require_dist.resolve(this.config.headers))["anthropic-beta"]) != null ? _a : "";
2862
+ const requestBetaHeader = (_b = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b : "";
2863
+ return new Set([...configBetaHeader.toLowerCase().split(","), ...requestBetaHeader.toLowerCase().split(",")].map((beta) => beta.trim()).filter((beta) => beta !== ""));
2864
+ }
2865
+ buildRequestUrl(isStreaming) {
2866
+ var _a, _b, _c;
2867
+ return (_c = (_b = (_a = this.config).buildRequestUrl) == null ? void 0 : _b.call(_a, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
2868
+ }
2869
+ transformRequestBody(args, betas) {
2870
+ var _a, _b, _c;
2871
+ return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args, betas)) != null ? _c : args;
2872
+ }
2873
+ extractCitationDocuments(prompt) {
2874
+ const isCitationPart = (part) => {
2875
+ var _a, _b;
2876
+ if (part.type !== "file") return false;
2877
+ if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") return false;
2878
+ const anthropic2 = (_a = part.providerOptions) == null ? void 0 : _a.anthropic;
2879
+ const citationsConfig = anthropic2 == null ? void 0 : anthropic2.citations;
2880
+ return (_b = citationsConfig == null ? void 0 : citationsConfig.enabled) != null ? _b : false;
2881
+ };
2882
+ return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
2883
+ var _a;
2884
+ const filePart = part;
2885
+ return {
2886
+ title: (_a = filePart.filename) != null ? _a : "Untitled Document",
2887
+ filename: filePart.filename,
2888
+ mediaType: filePart.mediaType
2889
+ };
2890
+ });
2891
+ }
2892
+ async doGenerate(options) {
2893
+ var _a, _b, _c, _d, _e, _f, _g;
2894
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
2895
+ ...options,
2896
+ stream: false,
2897
+ userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2898
+ });
2899
+ const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
2900
+ const markCodeExecutionDynamic = hasWebTool20260209WithoutCodeExecution(args.tools);
2901
+ const { responseHeaders, value: response, rawValue: rawResponse } = await require_dist.postJsonToApi({
2902
+ url: this.buildRequestUrl(false),
2903
+ headers: await this.getHeaders({
2904
+ betas,
2905
+ headers: options.headers
2906
+ }),
2907
+ body: this.transformRequestBody(args, betas),
2908
+ failedResponseHandler: anthropicFailedResponseHandler,
2909
+ successfulResponseHandler: require_dist.createJsonResponseHandler(anthropicMessagesResponseSchema),
2910
+ abortSignal: options.abortSignal,
2911
+ fetch: this.config.fetch
2912
+ });
2913
+ const content = [];
2914
+ const mcpToolCalls = {};
2915
+ const serverToolCalls = {};
2916
+ let isJsonResponseFromTool = false;
2917
+ for (const part of response.content) switch (part.type) {
2918
+ case "text":
2919
+ if (!usesJsonResponseTool) {
2920
+ content.push({
2921
+ type: "text",
2922
+ text: part.text
2923
+ });
2924
+ if (part.citations) for (const citation of part.citations) {
2925
+ const source = createCitationSource(citation, citationDocuments, this.generateId);
2926
+ if (source) content.push(source);
2927
+ }
2928
+ }
2929
+ break;
2930
+ case "thinking":
2931
+ content.push({
2932
+ type: "reasoning",
2933
+ text: part.thinking,
2934
+ providerMetadata: { anthropic: { signature: part.signature } }
2935
+ });
2936
+ break;
2937
+ case "redacted_thinking":
2938
+ content.push({
2939
+ type: "reasoning",
2940
+ text: "",
2941
+ providerMetadata: { anthropic: { redactedData: part.data } }
2942
+ });
2943
+ break;
2944
+ case "compaction":
2945
+ content.push({
2946
+ type: "text",
2947
+ text: part.content,
2948
+ providerMetadata: { anthropic: { type: "compaction" } }
2949
+ });
2950
+ break;
2951
+ case "tool_use":
2952
+ if (usesJsonResponseTool && part.name === "json") {
2953
+ isJsonResponseFromTool = true;
2954
+ content.push({
2955
+ type: "text",
2956
+ text: JSON.stringify(part.input)
2957
+ });
2958
+ } else {
2959
+ const caller = part.caller;
2960
+ const callerInfo = caller ? {
2961
+ type: caller.type,
2962
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
2963
+ } : void 0;
2964
+ content.push({
2965
+ type: "tool-call",
2966
+ toolCallId: part.id,
2967
+ toolName: part.name,
2968
+ input: JSON.stringify(part.input),
2969
+ ...callerInfo && { providerMetadata: { anthropic: { caller: callerInfo } } }
2970
+ });
2971
+ }
2972
+ break;
2973
+ case "server_tool_use":
2974
+ if (part.name === "text_editor_code_execution" || part.name === "bash_code_execution") {
2975
+ const providerToolName = "code_execution";
2976
+ content.push({
2977
+ type: "tool-call",
2978
+ toolCallId: part.id,
2979
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2980
+ input: JSON.stringify({
2981
+ type: part.name,
2982
+ ...part.input
2983
+ }),
2984
+ providerExecuted: true,
2985
+ ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {}
2986
+ });
2987
+ } else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
2988
+ const inputToSerialize = part.name === "code_execution" && part.input != null && typeof part.input === "object" && "code" in part.input && !("type" in part.input) ? {
2989
+ type: "programmatic-tool-call",
2990
+ ...part.input
2991
+ } : part.input;
2992
+ content.push({
2993
+ type: "tool-call",
2994
+ toolCallId: part.id,
2995
+ toolName: toolNameMapping.toCustomToolName(part.name),
2996
+ input: JSON.stringify(inputToSerialize),
2997
+ providerExecuted: true,
2998
+ ...markCodeExecutionDynamic && part.name === "code_execution" ? { dynamic: true } : {}
2999
+ });
3000
+ } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
3001
+ serverToolCalls[part.id] = part.name;
3002
+ content.push({
3003
+ type: "tool-call",
3004
+ toolCallId: part.id,
3005
+ toolName: toolNameMapping.toCustomToolName(part.name),
3006
+ input: JSON.stringify(part.input),
3007
+ providerExecuted: true
3008
+ });
3009
+ } else if (part.name === "advisor") content.push({
3010
+ type: "tool-call",
3011
+ toolCallId: part.id,
3012
+ toolName: toolNameMapping.toCustomToolName("advisor"),
3013
+ input: JSON.stringify(part.input),
3014
+ providerExecuted: true
3015
+ });
3016
+ break;
3017
+ case "mcp_tool_use":
3018
+ mcpToolCalls[part.id] = {
3019
+ type: "tool-call",
3020
+ toolCallId: part.id,
3021
+ toolName: part.name,
3022
+ input: JSON.stringify(part.input),
3023
+ providerExecuted: true,
3024
+ dynamic: true,
3025
+ providerMetadata: { anthropic: {
3026
+ type: "mcp-tool-use",
3027
+ serverName: part.server_name
3028
+ } }
3029
+ };
3030
+ content.push(mcpToolCalls[part.id]);
3031
+ break;
3032
+ case "mcp_tool_result":
3033
+ content.push({
3034
+ type: "tool-result",
3035
+ toolCallId: part.tool_use_id,
3036
+ toolName: mcpToolCalls[part.tool_use_id].toolName,
3037
+ isError: part.is_error,
3038
+ result: part.content,
3039
+ dynamic: true,
3040
+ providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
3041
+ });
3042
+ break;
3043
+ case "web_fetch_tool_result":
3044
+ if (part.content.type === "web_fetch_result") {
3045
+ citationDocuments.push({
3046
+ title: (_a = part.content.content.title) != null ? _a : part.content.url,
3047
+ mediaType: part.content.content.source.media_type
3048
+ });
3049
+ content.push({
3050
+ type: "tool-result",
3051
+ toolCallId: part.tool_use_id,
3052
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
3053
+ result: {
3054
+ type: "web_fetch_result",
3055
+ url: part.content.url,
3056
+ retrievedAt: part.content.retrieved_at,
3057
+ content: {
3058
+ type: part.content.content.type,
3059
+ title: part.content.content.title,
3060
+ citations: part.content.content.citations,
3061
+ source: {
3062
+ type: part.content.content.source.type,
3063
+ mediaType: part.content.content.source.media_type,
3064
+ data: part.content.content.source.data
3065
+ }
3066
+ }
3067
+ }
3068
+ });
3069
+ } else if (part.content.type === "web_fetch_tool_result_error") content.push({
3070
+ type: "tool-result",
3071
+ toolCallId: part.tool_use_id,
3072
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
3073
+ isError: true,
3074
+ result: {
3075
+ type: "web_fetch_tool_result_error",
3076
+ errorCode: part.content.error_code
3077
+ }
3078
+ });
3079
+ break;
3080
+ case "web_search_tool_result":
3081
+ if (Array.isArray(part.content)) {
3082
+ content.push({
3083
+ type: "tool-result",
3084
+ toolCallId: part.tool_use_id,
3085
+ toolName: toolNameMapping.toCustomToolName("web_search"),
3086
+ result: part.content.map((result) => {
3087
+ var _a2;
3088
+ return {
3089
+ url: result.url,
3090
+ title: result.title,
3091
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null,
3092
+ encryptedContent: result.encrypted_content,
3093
+ type: result.type
3094
+ };
3095
+ })
3096
+ });
3097
+ for (const result of part.content) content.push({
3098
+ type: "source",
3099
+ sourceType: "url",
3100
+ id: this.generateId(),
3101
+ url: result.url,
3102
+ title: result.title,
3103
+ providerMetadata: { anthropic: { pageAge: (_b = result.page_age) != null ? _b : null } }
3104
+ });
3105
+ } else content.push({
3106
+ type: "tool-result",
3107
+ toolCallId: part.tool_use_id,
3108
+ toolName: toolNameMapping.toCustomToolName("web_search"),
3109
+ isError: true,
3110
+ result: {
3111
+ type: "web_search_tool_result_error",
3112
+ errorCode: part.content.error_code
3113
+ }
3114
+ });
3115
+ break;
3116
+ case "code_execution_tool_result":
3117
+ if (part.content.type === "code_execution_result") content.push({
3118
+ type: "tool-result",
3119
+ toolCallId: part.tool_use_id,
3120
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3121
+ result: {
3122
+ type: part.content.type,
3123
+ stdout: part.content.stdout,
3124
+ stderr: part.content.stderr,
3125
+ return_code: part.content.return_code,
3126
+ content: (_c = part.content.content) != null ? _c : []
3127
+ }
3128
+ });
3129
+ else if (part.content.type === "encrypted_code_execution_result") content.push({
3130
+ type: "tool-result",
3131
+ toolCallId: part.tool_use_id,
3132
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3133
+ result: {
3134
+ type: part.content.type,
3135
+ encrypted_stdout: part.content.encrypted_stdout,
3136
+ stderr: part.content.stderr,
3137
+ return_code: part.content.return_code,
3138
+ content: (_d = part.content.content) != null ? _d : []
3139
+ }
3140
+ });
3141
+ else if (part.content.type === "code_execution_tool_result_error") content.push({
3142
+ type: "tool-result",
3143
+ toolCallId: part.tool_use_id,
3144
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3145
+ isError: true,
3146
+ result: {
3147
+ type: "code_execution_tool_result_error",
3148
+ errorCode: part.content.error_code
3149
+ }
3150
+ });
3151
+ break;
3152
+ case "bash_code_execution_tool_result":
3153
+ case "text_editor_code_execution_tool_result":
3154
+ content.push({
3155
+ type: "tool-result",
3156
+ toolCallId: part.tool_use_id,
3157
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3158
+ result: part.content
3159
+ });
3160
+ break;
3161
+ case "tool_search_tool_result": {
3162
+ let providerToolName = serverToolCalls[part.tool_use_id];
3163
+ if (providerToolName == null) {
3164
+ const bm25CustomName = toolNameMapping.toCustomToolName("tool_search_tool_bm25");
3165
+ const regexCustomName = toolNameMapping.toCustomToolName("tool_search_tool_regex");
3166
+ if (bm25CustomName !== "tool_search_tool_bm25") providerToolName = "tool_search_tool_bm25";
3167
+ else if (regexCustomName !== "tool_search_tool_regex") providerToolName = "tool_search_tool_regex";
3168
+ else providerToolName = "tool_search_tool_regex";
3169
+ }
3170
+ if (part.content.type === "tool_search_tool_search_result") content.push({
3171
+ type: "tool-result",
3172
+ toolCallId: part.tool_use_id,
3173
+ toolName: toolNameMapping.toCustomToolName(providerToolName),
3174
+ result: part.content.tool_references.map((ref) => ({
3175
+ type: ref.type,
3176
+ toolName: ref.tool_name
3177
+ }))
3178
+ });
3179
+ else content.push({
3180
+ type: "tool-result",
3181
+ toolCallId: part.tool_use_id,
3182
+ toolName: toolNameMapping.toCustomToolName(providerToolName),
3183
+ isError: true,
3184
+ result: {
3185
+ type: "tool_search_tool_result_error",
3186
+ errorCode: part.content.error_code
3187
+ }
3188
+ });
3189
+ break;
3190
+ }
3191
+ case "advisor_tool_result": {
3192
+ const advisorToolName = toolNameMapping.toCustomToolName("advisor");
3193
+ if (part.content.type === "advisor_result") content.push({
3194
+ type: "tool-result",
3195
+ toolCallId: part.tool_use_id,
3196
+ toolName: advisorToolName,
3197
+ result: {
3198
+ type: "advisor_result",
3199
+ text: part.content.text
3200
+ }
3201
+ });
3202
+ else if (part.content.type === "advisor_redacted_result") content.push({
3203
+ type: "tool-result",
3204
+ toolCallId: part.tool_use_id,
3205
+ toolName: advisorToolName,
3206
+ result: {
3207
+ type: "advisor_redacted_result",
3208
+ encryptedContent: part.content.encrypted_content
3209
+ }
3210
+ });
3211
+ else content.push({
3212
+ type: "tool-result",
3213
+ toolCallId: part.tool_use_id,
3214
+ toolName: advisorToolName,
3215
+ isError: true,
3216
+ result: {
3217
+ type: "advisor_tool_result_error",
3218
+ errorCode: part.content.error_code
3219
+ }
3220
+ });
3221
+ break;
3222
+ }
3223
+ case "fallback": break;
3224
+ }
3225
+ return {
3226
+ content,
3227
+ finishReason: {
3228
+ unified: mapAnthropicStopReason({
3229
+ finishReason: response.stop_reason,
3230
+ isJsonResponseFromTool
3231
+ }),
3232
+ raw: (_e = response.stop_reason) != null ? _e : void 0
3233
+ },
3234
+ usage: convertAnthropicMessagesUsage({ usage: response.usage }),
3235
+ request: { body: args },
3236
+ response: {
3237
+ id: (_f = response.id) != null ? _f : void 0,
3238
+ modelId: (_g = response.model) != null ? _g : void 0,
3239
+ headers: responseHeaders,
3240
+ body: rawResponse
3241
+ },
3242
+ warnings,
3243
+ providerMetadata: (() => {
3244
+ var _a2, _b2, _c2, _d2, _e2;
3245
+ const stopDetails = mapAnthropicStopDetails(response.stop_details);
3246
+ const anthropicMetadata = {
3247
+ usage: response.usage,
3248
+ cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
3249
+ stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
3250
+ ...stopDetails != null ? { stopDetails } : {},
3251
+ iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
3252
+ type: iter.type,
3253
+ ...iter.model != null ? { model: iter.model } : {},
3254
+ inputTokens: iter.input_tokens,
3255
+ outputTokens: iter.output_tokens,
3256
+ ...iter.cache_creation_input_tokens ? { cacheCreationInputTokens: iter.cache_creation_input_tokens } : {},
3257
+ ...iter.cache_read_input_tokens ? { cacheReadInputTokens: iter.cache_read_input_tokens } : {}
3258
+ })) : null,
3259
+ container: response.container ? {
3260
+ expiresAt: response.container.expires_at,
3261
+ id: response.container.id,
3262
+ skills: (_d2 = (_c2 = response.container.skills) == null ? void 0 : _c2.map((skill) => ({
3263
+ type: skill.type,
3264
+ skillId: skill.skill_id,
3265
+ version: skill.version
3266
+ }))) != null ? _d2 : null
3267
+ } : null,
3268
+ contextManagement: (_e2 = mapAnthropicResponseContextManagement(response.context_management)) != null ? _e2 : null
3269
+ };
3270
+ const providerMetadata = { anthropic: anthropicMetadata };
3271
+ if (usedCustomProviderKey && providerOptionsName !== "anthropic") providerMetadata[providerOptionsName] = anthropicMetadata;
3272
+ return providerMetadata;
3273
+ })()
3274
+ };
3275
+ }
3276
+ async doStream(options) {
3277
+ var _a, _b;
3278
+ const { args: body, warnings, betas, usesJsonResponseTool, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
3279
+ ...options,
3280
+ stream: true,
3281
+ userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
3282
+ });
3283
+ const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
3284
+ const markCodeExecutionDynamic = hasWebTool20260209WithoutCodeExecution(body.tools);
3285
+ const url = this.buildRequestUrl(true);
3286
+ const { responseHeaders, value: response } = await require_dist.postJsonToApi({
3287
+ url,
3288
+ headers: await this.getHeaders({
3289
+ betas,
3290
+ headers: options.headers
3291
+ }),
3292
+ body: this.transformRequestBody(body, betas),
3293
+ failedResponseHandler: anthropicFailedResponseHandler,
3294
+ successfulResponseHandler: require_dist.createEventSourceResponseHandler(anthropicMessagesChunkSchema),
3295
+ abortSignal: options.abortSignal,
3296
+ fetch: this.config.fetch
3297
+ });
3298
+ let finishReason = {
3299
+ unified: "other",
3300
+ raw: void 0
3301
+ };
3302
+ const usage = {
3303
+ input_tokens: 0,
3304
+ output_tokens: 0,
3305
+ cache_creation_input_tokens: 0,
3306
+ cache_read_input_tokens: 0,
3307
+ iterations: null
3308
+ };
3309
+ const contentBlocks = {};
3310
+ const mcpToolCalls = {};
3311
+ const serverToolCalls = {};
3312
+ let contextManagement = null;
3313
+ let rawUsage = void 0;
3314
+ let cacheCreationInputTokens = null;
3315
+ let stopSequence = null;
3316
+ let stopDetails = void 0;
3317
+ let container = null;
3318
+ let isJsonResponseFromTool = false;
3319
+ let blockType = void 0;
3320
+ const generateId3 = this.generateId;
3321
+ const [streamForFirstChunk, streamForConsumer] = response.pipeThrough(new TransformStream({
3322
+ start(controller) {
3323
+ controller.enqueue({
3324
+ type: "stream-start",
3325
+ warnings
3326
+ });
3327
+ },
3328
+ transform(chunk, controller) {
3329
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
3330
+ if (options.includeRawChunks) controller.enqueue({
3331
+ type: "raw",
3332
+ rawValue: chunk.rawValue
3333
+ });
3334
+ if (!chunk.success) {
3335
+ controller.enqueue({
3336
+ type: "error",
3337
+ error: chunk.error
3338
+ });
3339
+ return;
3340
+ }
3341
+ const value = chunk.value;
3342
+ switch (value.type) {
3343
+ case "ping": return;
3344
+ case "content_block_start": {
3345
+ const part = value.content_block;
3346
+ const contentBlockType = part.type;
3347
+ if (contentBlockType === "fallback") return;
3348
+ blockType = contentBlockType;
3349
+ switch (contentBlockType) {
3350
+ case "text":
3351
+ if (usesJsonResponseTool) return;
3352
+ contentBlocks[value.index] = { type: "text" };
3353
+ controller.enqueue({
3354
+ type: "text-start",
3355
+ id: String(value.index)
3356
+ });
3357
+ return;
3358
+ case "thinking":
3359
+ contentBlocks[value.index] = { type: "reasoning" };
3360
+ controller.enqueue({
3361
+ type: "reasoning-start",
3362
+ id: String(value.index)
3363
+ });
3364
+ return;
3365
+ case "redacted_thinking":
3366
+ contentBlocks[value.index] = { type: "reasoning" };
3367
+ controller.enqueue({
3368
+ type: "reasoning-start",
3369
+ id: String(value.index),
3370
+ providerMetadata: { anthropic: { redactedData: part.data } }
3371
+ });
3372
+ return;
3373
+ case "compaction":
3374
+ contentBlocks[value.index] = { type: "text" };
3375
+ controller.enqueue({
3376
+ type: "text-start",
3377
+ id: String(value.index),
3378
+ providerMetadata: { anthropic: { type: "compaction" } }
3379
+ });
3380
+ return;
3381
+ case "tool_use":
3382
+ if (usesJsonResponseTool && part.name === "json") {
3383
+ isJsonResponseFromTool = true;
3384
+ contentBlocks[value.index] = { type: "text" };
3385
+ controller.enqueue({
3386
+ type: "text-start",
3387
+ id: String(value.index)
3388
+ });
3389
+ } else {
3390
+ const caller = part.caller;
3391
+ const callerInfo = caller ? {
3392
+ type: caller.type,
3393
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
3394
+ } : void 0;
3395
+ const initialInput = part.input && Object.keys(part.input).length > 0 ? JSON.stringify(part.input) : "";
3396
+ contentBlocks[value.index] = {
3397
+ type: "tool-call",
3398
+ toolCallId: part.id,
3399
+ toolName: part.name,
3400
+ input: initialInput,
3401
+ firstDelta: initialInput.length === 0,
3402
+ ...callerInfo && { caller: callerInfo }
3403
+ };
3404
+ controller.enqueue({
3405
+ type: "tool-input-start",
3406
+ id: part.id,
3407
+ toolName: part.name
3408
+ });
3409
+ }
3410
+ return;
3411
+ case "server_tool_use":
3412
+ if ([
3413
+ "web_fetch",
3414
+ "web_search",
3415
+ "code_execution",
3416
+ "text_editor_code_execution",
3417
+ "bash_code_execution"
3418
+ ].includes(part.name)) {
3419
+ const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
3420
+ const customToolName = toolNameMapping.toCustomToolName(providerToolName);
3421
+ const finalInput = part.input != null && typeof part.input === "object" && Object.keys(part.input).length > 0 ? JSON.stringify(part.input) : "";
3422
+ contentBlocks[value.index] = {
3423
+ type: "tool-call",
3424
+ toolCallId: part.id,
3425
+ toolName: customToolName,
3426
+ input: finalInput,
3427
+ providerExecuted: true,
3428
+ ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {},
3429
+ firstDelta: true,
3430
+ providerToolName
3431
+ };
3432
+ controller.enqueue({
3433
+ type: "tool-input-start",
3434
+ id: part.id,
3435
+ toolName: customToolName,
3436
+ providerExecuted: true,
3437
+ ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {}
3438
+ });
3439
+ } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
3440
+ serverToolCalls[part.id] = part.name;
3441
+ const customToolName = toolNameMapping.toCustomToolName(part.name);
3442
+ contentBlocks[value.index] = {
3443
+ type: "tool-call",
3444
+ toolCallId: part.id,
3445
+ toolName: customToolName,
3446
+ input: "",
3447
+ providerExecuted: true,
3448
+ firstDelta: true,
3449
+ providerToolName: part.name
3450
+ };
3451
+ controller.enqueue({
3452
+ type: "tool-input-start",
3453
+ id: part.id,
3454
+ toolName: customToolName,
3455
+ providerExecuted: true
3456
+ });
3457
+ } else if (part.name === "advisor") {
3458
+ const customToolName = toolNameMapping.toCustomToolName("advisor");
3459
+ contentBlocks[value.index] = {
3460
+ type: "tool-call",
3461
+ toolCallId: part.id,
3462
+ toolName: customToolName,
3463
+ input: "{}",
3464
+ providerExecuted: true,
3465
+ firstDelta: true,
3466
+ providerToolName: part.name
3467
+ };
3468
+ controller.enqueue({
3469
+ type: "tool-input-start",
3470
+ id: part.id,
3471
+ toolName: customToolName,
3472
+ providerExecuted: true
3473
+ });
3474
+ }
3475
+ return;
3476
+ case "web_fetch_tool_result":
3477
+ if (part.content.type === "web_fetch_result") {
3478
+ citationDocuments.push({
3479
+ title: (_a2 = part.content.content.title) != null ? _a2 : part.content.url,
3480
+ mediaType: part.content.content.source.media_type
3481
+ });
3482
+ controller.enqueue({
3483
+ type: "tool-result",
3484
+ toolCallId: part.tool_use_id,
3485
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
3486
+ result: {
3487
+ type: "web_fetch_result",
3488
+ url: part.content.url,
3489
+ retrievedAt: part.content.retrieved_at,
3490
+ content: {
3491
+ type: part.content.content.type,
3492
+ title: part.content.content.title,
3493
+ citations: part.content.content.citations,
3494
+ source: {
3495
+ type: part.content.content.source.type,
3496
+ mediaType: part.content.content.source.media_type,
3497
+ data: part.content.content.source.data
3498
+ }
3499
+ }
3500
+ }
3501
+ });
3502
+ } else if (part.content.type === "web_fetch_tool_result_error") controller.enqueue({
3503
+ type: "tool-result",
3504
+ toolCallId: part.tool_use_id,
3505
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
3506
+ isError: true,
3507
+ result: {
3508
+ type: "web_fetch_tool_result_error",
3509
+ errorCode: part.content.error_code
3510
+ }
3511
+ });
3512
+ return;
3513
+ case "web_search_tool_result":
3514
+ if (Array.isArray(part.content)) {
3515
+ controller.enqueue({
3516
+ type: "tool-result",
3517
+ toolCallId: part.tool_use_id,
3518
+ toolName: toolNameMapping.toCustomToolName("web_search"),
3519
+ result: part.content.map((result) => {
3520
+ var _a3;
3521
+ return {
3522
+ url: result.url,
3523
+ title: result.title,
3524
+ pageAge: (_a3 = result.page_age) != null ? _a3 : null,
3525
+ encryptedContent: result.encrypted_content,
3526
+ type: result.type
3527
+ };
3528
+ })
3529
+ });
3530
+ for (const result of part.content) controller.enqueue({
3531
+ type: "source",
3532
+ sourceType: "url",
3533
+ id: generateId3(),
3534
+ url: result.url,
3535
+ title: result.title,
3536
+ providerMetadata: { anthropic: { pageAge: (_b2 = result.page_age) != null ? _b2 : null } }
3537
+ });
3538
+ } else controller.enqueue({
3539
+ type: "tool-result",
3540
+ toolCallId: part.tool_use_id,
3541
+ toolName: toolNameMapping.toCustomToolName("web_search"),
3542
+ isError: true,
3543
+ result: {
3544
+ type: "web_search_tool_result_error",
3545
+ errorCode: part.content.error_code
3546
+ }
3547
+ });
3548
+ return;
3549
+ case "code_execution_tool_result":
3550
+ if (part.content.type === "code_execution_result") controller.enqueue({
3551
+ type: "tool-result",
3552
+ toolCallId: part.tool_use_id,
3553
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3554
+ result: {
3555
+ type: part.content.type,
3556
+ stdout: part.content.stdout,
3557
+ stderr: part.content.stderr,
3558
+ return_code: part.content.return_code,
3559
+ content: (_c = part.content.content) != null ? _c : []
3560
+ }
3561
+ });
3562
+ else if (part.content.type === "encrypted_code_execution_result") controller.enqueue({
3563
+ type: "tool-result",
3564
+ toolCallId: part.tool_use_id,
3565
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3566
+ result: {
3567
+ type: part.content.type,
3568
+ encrypted_stdout: part.content.encrypted_stdout,
3569
+ stderr: part.content.stderr,
3570
+ return_code: part.content.return_code,
3571
+ content: (_d = part.content.content) != null ? _d : []
3572
+ }
3573
+ });
3574
+ else if (part.content.type === "code_execution_tool_result_error") controller.enqueue({
3575
+ type: "tool-result",
3576
+ toolCallId: part.tool_use_id,
3577
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3578
+ isError: true,
3579
+ result: {
3580
+ type: "code_execution_tool_result_error",
3581
+ errorCode: part.content.error_code
3582
+ }
3583
+ });
3584
+ return;
3585
+ case "bash_code_execution_tool_result":
3586
+ case "text_editor_code_execution_tool_result":
3587
+ controller.enqueue({
3588
+ type: "tool-result",
3589
+ toolCallId: part.tool_use_id,
3590
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3591
+ result: part.content
3592
+ });
3593
+ return;
3594
+ case "tool_search_tool_result": {
3595
+ let providerToolName = serverToolCalls[part.tool_use_id];
3596
+ if (providerToolName == null) {
3597
+ const bm25CustomName = toolNameMapping.toCustomToolName("tool_search_tool_bm25");
3598
+ const regexCustomName = toolNameMapping.toCustomToolName("tool_search_tool_regex");
3599
+ if (bm25CustomName !== "tool_search_tool_bm25") providerToolName = "tool_search_tool_bm25";
3600
+ else if (regexCustomName !== "tool_search_tool_regex") providerToolName = "tool_search_tool_regex";
3601
+ else providerToolName = "tool_search_tool_regex";
3602
+ }
3603
+ if (part.content.type === "tool_search_tool_search_result") controller.enqueue({
3604
+ type: "tool-result",
3605
+ toolCallId: part.tool_use_id,
3606
+ toolName: toolNameMapping.toCustomToolName(providerToolName),
3607
+ result: part.content.tool_references.map((ref) => ({
3608
+ type: ref.type,
3609
+ toolName: ref.tool_name
3610
+ }))
3611
+ });
3612
+ else controller.enqueue({
3613
+ type: "tool-result",
3614
+ toolCallId: part.tool_use_id,
3615
+ toolName: toolNameMapping.toCustomToolName(providerToolName),
3616
+ isError: true,
3617
+ result: {
3618
+ type: "tool_search_tool_result_error",
3619
+ errorCode: part.content.error_code
3620
+ }
3621
+ });
3622
+ return;
3623
+ }
3624
+ case "advisor_tool_result": {
3625
+ const advisorToolName = toolNameMapping.toCustomToolName("advisor");
3626
+ if (part.content.type === "advisor_result") controller.enqueue({
3627
+ type: "tool-result",
3628
+ toolCallId: part.tool_use_id,
3629
+ toolName: advisorToolName,
3630
+ result: {
3631
+ type: "advisor_result",
3632
+ text: part.content.text
3633
+ }
3634
+ });
3635
+ else if (part.content.type === "advisor_redacted_result") controller.enqueue({
3636
+ type: "tool-result",
3637
+ toolCallId: part.tool_use_id,
3638
+ toolName: advisorToolName,
3639
+ result: {
3640
+ type: "advisor_redacted_result",
3641
+ encryptedContent: part.content.encrypted_content
3642
+ }
3643
+ });
3644
+ else controller.enqueue({
3645
+ type: "tool-result",
3646
+ toolCallId: part.tool_use_id,
3647
+ toolName: advisorToolName,
3648
+ isError: true,
3649
+ result: {
3650
+ type: "advisor_tool_result_error",
3651
+ errorCode: part.content.error_code
3652
+ }
3653
+ });
3654
+ return;
3655
+ }
3656
+ case "mcp_tool_use":
3657
+ mcpToolCalls[part.id] = {
3658
+ type: "tool-call",
3659
+ toolCallId: part.id,
3660
+ toolName: part.name,
3661
+ input: JSON.stringify(part.input),
3662
+ providerExecuted: true,
3663
+ dynamic: true,
3664
+ providerMetadata: { anthropic: {
3665
+ type: "mcp-tool-use",
3666
+ serverName: part.server_name
3667
+ } }
3668
+ };
3669
+ controller.enqueue(mcpToolCalls[part.id]);
3670
+ return;
3671
+ case "mcp_tool_result":
3672
+ controller.enqueue({
3673
+ type: "tool-result",
3674
+ toolCallId: part.tool_use_id,
3675
+ toolName: mcpToolCalls[part.tool_use_id].toolName,
3676
+ isError: part.is_error,
3677
+ result: part.content,
3678
+ dynamic: true,
3679
+ providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
3680
+ });
3681
+ return;
3682
+ default: {
3683
+ const _exhaustiveCheck = contentBlockType;
3684
+ throw new Error(`Unsupported content block type: ${_exhaustiveCheck}`);
3685
+ }
3686
+ }
3687
+ }
3688
+ case "content_block_stop":
3689
+ if (contentBlocks[value.index] != null) {
3690
+ const contentBlock = contentBlocks[value.index];
3691
+ switch (contentBlock.type) {
3692
+ case "text":
3693
+ controller.enqueue({
3694
+ type: "text-end",
3695
+ id: String(value.index)
3696
+ });
3697
+ break;
3698
+ case "reasoning":
3699
+ controller.enqueue({
3700
+ type: "reasoning-end",
3701
+ id: String(value.index)
3702
+ });
3703
+ break;
3704
+ case "tool-call":
3705
+ if (!(usesJsonResponseTool && contentBlock.toolName === "json")) {
3706
+ controller.enqueue({
3707
+ type: "tool-input-end",
3708
+ id: contentBlock.toolCallId
3709
+ });
3710
+ let finalInput = contentBlock.input === "" ? "{}" : contentBlock.input;
3711
+ if (contentBlock.providerToolName === "code_execution") try {
3712
+ const parsed = JSON.parse(finalInput);
3713
+ if (parsed != null && typeof parsed === "object" && "code" in parsed && !("type" in parsed)) finalInput = JSON.stringify({
3714
+ type: "programmatic-tool-call",
3715
+ ...parsed
3716
+ });
3717
+ } catch (e) {}
3718
+ controller.enqueue({
3719
+ type: "tool-call",
3720
+ toolCallId: contentBlock.toolCallId,
3721
+ toolName: contentBlock.toolName,
3722
+ input: finalInput,
3723
+ providerExecuted: contentBlock.providerExecuted,
3724
+ ...markCodeExecutionDynamic && contentBlock.providerToolName === "code_execution" ? { dynamic: true } : {},
3725
+ ...contentBlock.caller && { providerMetadata: { anthropic: { caller: contentBlock.caller } } }
3726
+ });
3727
+ }
3728
+ break;
3729
+ }
3730
+ delete contentBlocks[value.index];
3731
+ }
3732
+ blockType = void 0;
3733
+ return;
3734
+ case "content_block_delta": {
3735
+ const deltaType = value.delta.type;
3736
+ switch (deltaType) {
3737
+ case "text_delta":
3738
+ if (usesJsonResponseTool) return;
3739
+ controller.enqueue({
3740
+ type: "text-delta",
3741
+ id: String(value.index),
3742
+ delta: value.delta.text
3743
+ });
3744
+ return;
3745
+ case "thinking_delta":
3746
+ controller.enqueue({
3747
+ type: "reasoning-delta",
3748
+ id: String(value.index),
3749
+ delta: value.delta.thinking
3750
+ });
3751
+ return;
3752
+ case "signature_delta":
3753
+ if (blockType === "thinking") controller.enqueue({
3754
+ type: "reasoning-delta",
3755
+ id: String(value.index),
3756
+ delta: "",
3757
+ providerMetadata: { anthropic: { signature: value.delta.signature } }
3758
+ });
3759
+ return;
3760
+ case "compaction_delta":
3761
+ if (value.delta.content != null) controller.enqueue({
3762
+ type: "text-delta",
3763
+ id: String(value.index),
3764
+ delta: value.delta.content
3765
+ });
3766
+ return;
3767
+ case "input_json_delta": {
3768
+ const contentBlock = contentBlocks[value.index];
3769
+ let delta = value.delta.partial_json;
3770
+ if (delta.length === 0) return;
3771
+ if (isJsonResponseFromTool) {
3772
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") return;
3773
+ controller.enqueue({
3774
+ type: "text-delta",
3775
+ id: String(value.index),
3776
+ delta
3777
+ });
3778
+ } else {
3779
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") return;
3780
+ if (contentBlock.firstDelta && contentBlock.providerToolName === "code_execution") delta = `{"type": "programmatic-tool-call",${delta.substring(1)}`;
3781
+ controller.enqueue({
3782
+ type: "tool-input-delta",
3783
+ id: contentBlock.toolCallId,
3784
+ delta
3785
+ });
3786
+ contentBlock.input += delta;
3787
+ contentBlock.firstDelta = false;
3788
+ }
3789
+ return;
3790
+ }
3791
+ case "citations_delta": {
3792
+ const citation = value.delta.citation;
3793
+ const source = createCitationSource(citation, citationDocuments, generateId3);
3794
+ if (source) controller.enqueue(source);
3795
+ return;
3796
+ }
3797
+ default: {
3798
+ const _exhaustiveCheck = deltaType;
3799
+ throw new Error(`Unsupported delta type: ${_exhaustiveCheck}`);
3800
+ }
3801
+ }
3802
+ }
3803
+ case "message_start":
3804
+ usage.input_tokens = value.message.usage.input_tokens;
3805
+ usage.cache_read_input_tokens = (_e = value.message.usage.cache_read_input_tokens) != null ? _e : 0;
3806
+ usage.cache_creation_input_tokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : 0;
3807
+ rawUsage = { ...value.message.usage };
3808
+ cacheCreationInputTokens = (_g = value.message.usage.cache_creation_input_tokens) != null ? _g : null;
3809
+ if (value.message.container != null) container = {
3810
+ expiresAt: value.message.container.expires_at,
3811
+ id: value.message.container.id,
3812
+ skills: null
3813
+ };
3814
+ if (value.message.stop_reason != null) finishReason = {
3815
+ unified: mapAnthropicStopReason({
3816
+ finishReason: value.message.stop_reason,
3817
+ isJsonResponseFromTool
3818
+ }),
3819
+ raw: value.message.stop_reason
3820
+ };
3821
+ controller.enqueue({
3822
+ type: "response-metadata",
3823
+ id: (_h = value.message.id) != null ? _h : void 0,
3824
+ modelId: (_i = value.message.model) != null ? _i : void 0
3825
+ });
3826
+ if (value.message.content != null) for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
3827
+ const part = value.message.content[contentIndex];
3828
+ if (part.type === "tool_use") {
3829
+ const caller = part.caller;
3830
+ const callerInfo = caller ? {
3831
+ type: caller.type,
3832
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
3833
+ } : void 0;
3834
+ controller.enqueue({
3835
+ type: "tool-input-start",
3836
+ id: part.id,
3837
+ toolName: part.name
3838
+ });
3839
+ const inputStr = JSON.stringify((_j = part.input) != null ? _j : {});
3840
+ controller.enqueue({
3841
+ type: "tool-input-delta",
3842
+ id: part.id,
3843
+ delta: inputStr
3844
+ });
3845
+ controller.enqueue({
3846
+ type: "tool-input-end",
3847
+ id: part.id
3848
+ });
3849
+ controller.enqueue({
3850
+ type: "tool-call",
3851
+ toolCallId: part.id,
3852
+ toolName: part.name,
3853
+ input: inputStr,
3854
+ ...callerInfo && { providerMetadata: { anthropic: { caller: callerInfo } } }
3855
+ });
3856
+ }
3857
+ }
3858
+ return;
3859
+ case "message_delta":
3860
+ if (value.usage.input_tokens != null && usage.input_tokens !== value.usage.input_tokens) usage.input_tokens = value.usage.input_tokens;
3861
+ usage.output_tokens = value.usage.output_tokens;
3862
+ if (value.usage.cache_read_input_tokens != null) usage.cache_read_input_tokens = value.usage.cache_read_input_tokens;
3863
+ if (value.usage.cache_creation_input_tokens != null) {
3864
+ usage.cache_creation_input_tokens = value.usage.cache_creation_input_tokens;
3865
+ cacheCreationInputTokens = value.usage.cache_creation_input_tokens;
3866
+ }
3867
+ if (value.usage.iterations != null) usage.iterations = value.usage.iterations;
3868
+ finishReason = {
3869
+ unified: mapAnthropicStopReason({
3870
+ finishReason: value.delta.stop_reason,
3871
+ isJsonResponseFromTool
3872
+ }),
3873
+ raw: (_k = value.delta.stop_reason) != null ? _k : void 0
3874
+ };
3875
+ stopSequence = (_l = value.delta.stop_sequence) != null ? _l : null;
3876
+ stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
3877
+ container = value.delta.container != null ? {
3878
+ expiresAt: value.delta.container.expires_at,
3879
+ id: value.delta.container.id,
3880
+ skills: (_n = (_m = value.delta.container.skills) == null ? void 0 : _m.map((skill) => ({
3881
+ type: skill.type,
3882
+ skillId: skill.skill_id,
3883
+ version: skill.version
3884
+ }))) != null ? _n : null
3885
+ } : null;
3886
+ if (value.context_management) contextManagement = mapAnthropicResponseContextManagement(value.context_management);
3887
+ rawUsage = {
3888
+ ...rawUsage,
3889
+ ...value.usage
3890
+ };
3891
+ return;
3892
+ case "message_stop": {
3893
+ const anthropicMetadata = {
3894
+ usage: rawUsage != null ? rawUsage : null,
3895
+ cacheCreationInputTokens,
3896
+ stopSequence,
3897
+ ...stopDetails != null ? { stopDetails } : {},
3898
+ iterations: usage.iterations ? usage.iterations.map((iter) => ({
3899
+ type: iter.type,
3900
+ ...iter.model != null ? { model: iter.model } : {},
3901
+ inputTokens: iter.input_tokens,
3902
+ outputTokens: iter.output_tokens,
3903
+ ...iter.cache_creation_input_tokens ? { cacheCreationInputTokens: iter.cache_creation_input_tokens } : {},
3904
+ ...iter.cache_read_input_tokens ? { cacheReadInputTokens: iter.cache_read_input_tokens } : {}
3905
+ })) : null,
3906
+ container,
3907
+ contextManagement
3908
+ };
3909
+ const providerMetadata = { anthropic: anthropicMetadata };
3910
+ if (usedCustomProviderKey && providerOptionsName !== "anthropic") providerMetadata[providerOptionsName] = anthropicMetadata;
3911
+ controller.enqueue({
3912
+ type: "finish",
3913
+ finishReason,
3914
+ usage: convertAnthropicMessagesUsage({
3915
+ usage,
3916
+ rawUsage
3917
+ }),
3918
+ providerMetadata
3919
+ });
3920
+ return;
3921
+ }
3922
+ case "error":
3923
+ controller.enqueue({
3924
+ type: "error",
3925
+ error: value.error
3926
+ });
3927
+ return;
3928
+ default: {
3929
+ const _exhaustiveCheck = value;
3930
+ throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
3931
+ }
3932
+ }
3933
+ }
3934
+ })).tee();
3935
+ const firstChunkReader = streamForFirstChunk.getReader();
3936
+ try {
3937
+ await firstChunkReader.read();
3938
+ let result = await firstChunkReader.read();
3939
+ if (((_a = result.value) == null ? void 0 : _a.type) === "raw") result = await firstChunkReader.read();
3940
+ if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
3941
+ const error = result.value.error;
3942
+ throw new require_dist.APICallError({
3943
+ message: error.message,
3944
+ url,
3945
+ requestBodyValues: body,
3946
+ statusCode: error.type === "overloaded_error" ? 529 : 500,
3947
+ responseHeaders,
3948
+ responseBody: JSON.stringify(error),
3949
+ isRetryable: error.type === "overloaded_error"
3950
+ });
3951
+ }
3952
+ } finally {
3953
+ firstChunkReader.cancel().catch(() => {});
3954
+ firstChunkReader.releaseLock();
3955
+ }
3956
+ return {
3957
+ stream: streamForConsumer,
3958
+ request: { body },
3959
+ response: { headers: responseHeaders }
3960
+ };
3961
+ }
3962
+ };
3963
+ function getModelCapabilities(modelId) {
3964
+ if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5")) return {
3965
+ maxOutputTokens: 128e3,
3966
+ supportsStructuredOutput: true,
3967
+ rejectsSamplingParameters: true,
3968
+ isKnownModel: true
3969
+ };
3970
+ else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) return {
3971
+ maxOutputTokens: 128e3,
3972
+ supportsStructuredOutput: true,
3973
+ rejectsSamplingParameters: false,
3974
+ isKnownModel: true
3975
+ };
3976
+ else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) return {
3977
+ maxOutputTokens: 64e3,
3978
+ supportsStructuredOutput: true,
3979
+ rejectsSamplingParameters: false,
3980
+ isKnownModel: true
3981
+ };
3982
+ else if (modelId.includes("claude-opus-4-1")) return {
3983
+ maxOutputTokens: 32e3,
3984
+ supportsStructuredOutput: true,
3985
+ rejectsSamplingParameters: false,
3986
+ isKnownModel: true
3987
+ };
3988
+ else if (modelId.includes("claude-sonnet-4-")) return {
3989
+ maxOutputTokens: 64e3,
3990
+ supportsStructuredOutput: false,
3991
+ rejectsSamplingParameters: false,
3992
+ isKnownModel: true
3993
+ };
3994
+ else if (modelId.includes("claude-opus-4-")) return {
3995
+ maxOutputTokens: 32e3,
3996
+ supportsStructuredOutput: false,
3997
+ rejectsSamplingParameters: false,
3998
+ isKnownModel: true
3999
+ };
4000
+ else if (modelId.includes("claude-3-haiku")) return {
4001
+ maxOutputTokens: 4096,
4002
+ supportsStructuredOutput: false,
4003
+ rejectsSamplingParameters: false,
4004
+ isKnownModel: true
4005
+ };
4006
+ else return {
4007
+ maxOutputTokens: 4096,
4008
+ supportsStructuredOutput: false,
4009
+ rejectsSamplingParameters: false,
4010
+ isKnownModel: false
4011
+ };
4012
+ }
4013
+ function hasWebTool20260209WithoutCodeExecution(tools) {
4014
+ if (!tools) return false;
4015
+ let hasWebTool20260209 = false;
4016
+ let hasCodeExecutionTool = false;
4017
+ for (const tool of tools) {
4018
+ if ("type" in tool && (tool.type === "web_fetch_20260209" || tool.type === "web_search_20260209")) {
4019
+ hasWebTool20260209 = true;
4020
+ continue;
4021
+ }
4022
+ if (tool.name === "code_execution") {
4023
+ hasCodeExecutionTool = true;
4024
+ break;
4025
+ }
4026
+ }
4027
+ return hasWebTool20260209 && !hasCodeExecutionTool;
4028
+ }
4029
+ function mapAnthropicResponseContextManagement(contextManagement) {
4030
+ return contextManagement ? { appliedEdits: contextManagement.applied_edits.map((edit) => {
4031
+ switch (edit.type) {
4032
+ case "clear_tool_uses_20250919": return {
4033
+ type: edit.type,
4034
+ clearedToolUses: edit.cleared_tool_uses,
4035
+ clearedInputTokens: edit.cleared_input_tokens
4036
+ };
4037
+ case "clear_thinking_20251015": return {
4038
+ type: edit.type,
4039
+ clearedThinkingTurns: edit.cleared_thinking_turns,
4040
+ clearedInputTokens: edit.cleared_input_tokens
4041
+ };
4042
+ case "compact_20260112": return { type: edit.type };
4043
+ }
4044
+ }).filter((edit) => edit !== void 0) } : null;
4045
+ }
4046
+ function mapAnthropicStopDetails(stopDetails) {
4047
+ if (stopDetails == null) return;
4048
+ return {
4049
+ type: stopDetails.type,
4050
+ ...stopDetails.category != null ? { category: stopDetails.category } : {},
4051
+ ...stopDetails.explanation != null ? { explanation: stopDetails.explanation } : {},
4052
+ ...stopDetails.recommended_model != null ? { recommendedModel: stopDetails.recommended_model } : {}
4053
+ };
4054
+ }
4055
+ var bash_20241022 = require_dist.createProviderToolFactory({
4056
+ id: "anthropic.bash_20241022",
4057
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
4058
+ command: zod_v4.z.string(),
4059
+ restart: zod_v4.z.boolean().optional()
4060
+ })))
4061
+ });
4062
+ var bash_20250124 = require_dist.createProviderToolFactory({
4063
+ id: "anthropic.bash_20250124",
4064
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
4065
+ command: zod_v4.z.string(),
4066
+ restart: zod_v4.z.boolean().optional()
4067
+ })))
4068
+ });
4069
+ var computer_20241022 = require_dist.createProviderToolFactory({
4070
+ id: "anthropic.computer_20241022",
4071
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
4072
+ action: zod_v4.z.enum([
4073
+ "key",
4074
+ "type",
4075
+ "mouse_move",
4076
+ "left_click",
4077
+ "left_click_drag",
4078
+ "right_click",
4079
+ "middle_click",
4080
+ "double_click",
4081
+ "screenshot",
4082
+ "cursor_position"
4083
+ ]),
4084
+ coordinate: zod_v4.z.array(zod_v4.z.number().int()).optional(),
4085
+ text: zod_v4.z.string().optional()
4086
+ })))
4087
+ });
4088
+ var computer_20250124 = require_dist.createProviderToolFactory({
4089
+ id: "anthropic.computer_20250124",
4090
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
4091
+ action: zod_v4.z.enum([
4092
+ "key",
4093
+ "hold_key",
4094
+ "type",
4095
+ "cursor_position",
4096
+ "mouse_move",
4097
+ "left_mouse_down",
4098
+ "left_mouse_up",
4099
+ "left_click",
4100
+ "left_click_drag",
4101
+ "right_click",
4102
+ "middle_click",
4103
+ "double_click",
4104
+ "triple_click",
4105
+ "scroll",
4106
+ "wait",
4107
+ "screenshot"
4108
+ ]),
4109
+ coordinate: zod_v4.z.tuple([zod_v4.z.number().int(), zod_v4.z.number().int()]).optional(),
4110
+ duration: zod_v4.z.number().optional(),
4111
+ scroll_amount: zod_v4.z.number().optional(),
4112
+ scroll_direction: zod_v4.z.enum([
4113
+ "up",
4114
+ "down",
4115
+ "left",
4116
+ "right"
4117
+ ]).optional(),
4118
+ start_coordinate: zod_v4.z.tuple([zod_v4.z.number().int(), zod_v4.z.number().int()]).optional(),
4119
+ text: zod_v4.z.string().optional()
4120
+ })))
4121
+ });
4122
+ var computer_20251124 = require_dist.createProviderToolFactory({
4123
+ id: "anthropic.computer_20251124",
4124
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
4125
+ action: zod_v4.z.enum([
4126
+ "key",
4127
+ "hold_key",
4128
+ "type",
4129
+ "cursor_position",
4130
+ "mouse_move",
4131
+ "left_mouse_down",
4132
+ "left_mouse_up",
4133
+ "left_click",
4134
+ "left_click_drag",
4135
+ "right_click",
4136
+ "middle_click",
4137
+ "double_click",
4138
+ "triple_click",
4139
+ "scroll",
4140
+ "wait",
4141
+ "screenshot",
4142
+ "zoom"
4143
+ ]),
4144
+ coordinate: zod_v4.z.tuple([zod_v4.z.number().int(), zod_v4.z.number().int()]).optional(),
4145
+ duration: zod_v4.z.number().optional(),
4146
+ region: zod_v4.z.tuple([
4147
+ zod_v4.z.number().int(),
4148
+ zod_v4.z.number().int(),
4149
+ zod_v4.z.number().int(),
4150
+ zod_v4.z.number().int()
4151
+ ]).optional(),
4152
+ scroll_amount: zod_v4.z.number().optional(),
4153
+ scroll_direction: zod_v4.z.enum([
4154
+ "up",
4155
+ "down",
4156
+ "left",
4157
+ "right"
4158
+ ]).optional(),
4159
+ start_coordinate: zod_v4.z.tuple([zod_v4.z.number().int(), zod_v4.z.number().int()]).optional(),
4160
+ text: zod_v4.z.string().optional()
4161
+ })))
4162
+ });
4163
+ var memory_20250818 = require_dist.createProviderToolFactory({
4164
+ id: "anthropic.memory_20250818",
4165
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.discriminatedUnion("command", [
4166
+ zod_v4.z.object({
4167
+ command: zod_v4.z.literal("view"),
4168
+ path: zod_v4.z.string(),
4169
+ view_range: zod_v4.z.tuple([zod_v4.z.number(), zod_v4.z.number()]).optional()
4170
+ }),
4171
+ zod_v4.z.object({
4172
+ command: zod_v4.z.literal("create"),
4173
+ path: zod_v4.z.string(),
4174
+ file_text: zod_v4.z.string()
4175
+ }),
4176
+ zod_v4.z.object({
4177
+ command: zod_v4.z.literal("str_replace"),
4178
+ path: zod_v4.z.string(),
4179
+ old_str: zod_v4.z.string(),
4180
+ new_str: zod_v4.z.string()
4181
+ }),
4182
+ zod_v4.z.object({
4183
+ command: zod_v4.z.literal("insert"),
4184
+ path: zod_v4.z.string(),
4185
+ insert_line: zod_v4.z.number(),
4186
+ insert_text: zod_v4.z.string()
4187
+ }),
4188
+ zod_v4.z.object({
4189
+ command: zod_v4.z.literal("delete"),
4190
+ path: zod_v4.z.string()
4191
+ }),
4192
+ zod_v4.z.object({
4193
+ command: zod_v4.z.literal("rename"),
4194
+ old_path: zod_v4.z.string(),
4195
+ new_path: zod_v4.z.string()
4196
+ })
4197
+ ])))
4198
+ });
4199
+ var textEditor_20241022 = require_dist.createProviderToolFactory({
4200
+ id: "anthropic.text_editor_20241022",
4201
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
4202
+ command: zod_v4.z.enum([
4203
+ "view",
4204
+ "create",
4205
+ "str_replace",
4206
+ "insert",
4207
+ "undo_edit"
4208
+ ]),
4209
+ path: zod_v4.z.string(),
4210
+ file_text: zod_v4.z.string().optional(),
4211
+ insert_line: zod_v4.z.number().int().optional(),
4212
+ new_str: zod_v4.z.string().optional(),
4213
+ insert_text: zod_v4.z.string().optional(),
4214
+ old_str: zod_v4.z.string().optional(),
4215
+ view_range: zod_v4.z.array(zod_v4.z.number().int()).optional()
4216
+ })))
4217
+ });
4218
+ var textEditor_20250124 = require_dist.createProviderToolFactory({
4219
+ id: "anthropic.text_editor_20250124",
4220
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
4221
+ command: zod_v4.z.enum([
4222
+ "view",
4223
+ "create",
4224
+ "str_replace",
4225
+ "insert",
4226
+ "undo_edit"
4227
+ ]),
4228
+ path: zod_v4.z.string(),
4229
+ file_text: zod_v4.z.string().optional(),
4230
+ insert_line: zod_v4.z.number().int().optional(),
4231
+ new_str: zod_v4.z.string().optional(),
4232
+ insert_text: zod_v4.z.string().optional(),
4233
+ old_str: zod_v4.z.string().optional(),
4234
+ view_range: zod_v4.z.array(zod_v4.z.number().int()).optional()
4235
+ })))
4236
+ });
4237
+ var textEditor_20250429 = require_dist.createProviderToolFactory({
4238
+ id: "anthropic.text_editor_20250429",
4239
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
4240
+ command: zod_v4.z.enum([
4241
+ "view",
4242
+ "create",
4243
+ "str_replace",
4244
+ "insert"
4245
+ ]),
4246
+ path: zod_v4.z.string(),
4247
+ file_text: zod_v4.z.string().optional(),
4248
+ insert_line: zod_v4.z.number().int().optional(),
4249
+ new_str: zod_v4.z.string().optional(),
4250
+ insert_text: zod_v4.z.string().optional(),
4251
+ old_str: zod_v4.z.string().optional(),
4252
+ view_range: zod_v4.z.array(zod_v4.z.number().int()).optional()
4253
+ })))
4254
+ });
4255
+ var toolSearchBm25_20251119OutputSchema = require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.array(zod_v4.z.object({
4256
+ type: zod_v4.z.literal("tool_reference"),
4257
+ toolName: zod_v4.z.string()
4258
+ }))));
4259
+ var factory11 = require_dist.createProviderToolFactoryWithOutputSchema({
4260
+ id: "anthropic.tool_search_bm25_20251119",
4261
+ inputSchema: require_dist.lazySchema(() => require_dist.zodSchema(zod_v4.z.object({
4262
+ query: zod_v4.z.string(),
4263
+ limit: zod_v4.z.number().optional()
4264
+ }))),
4265
+ outputSchema: toolSearchBm25_20251119OutputSchema,
4266
+ supportsDeferredResults: true
4267
+ });
4268
+ var toolSearchBm25_20251119 = (args = {}) => {
4269
+ return factory11(args);
4270
+ };
4271
+ var anthropicTools = {
4272
+ advisor_20260301,
4273
+ bash_20241022,
4274
+ bash_20250124,
4275
+ codeExecution_20250522,
4276
+ codeExecution_20250825,
4277
+ codeExecution_20260120,
4278
+ computer_20241022,
4279
+ computer_20250124,
4280
+ computer_20251124,
4281
+ memory_20250818,
4282
+ textEditor_20241022,
4283
+ textEditor_20250124,
4284
+ textEditor_20250429,
4285
+ textEditor_20250728,
4286
+ webFetch_20250910,
4287
+ webFetch_20260209,
4288
+ webSearch_20250305,
4289
+ webSearch_20260209,
4290
+ toolSearchRegex_20251119,
4291
+ toolSearchBm25_20251119
4292
+ };
4293
+ function createAnthropic(options = {}) {
4294
+ var _a, _b;
4295
+ const baseURL = (_a = require_dist.withoutTrailingSlash(require_dist.loadOptionalSetting({
4296
+ settingValue: options.baseURL,
4297
+ environmentVariableName: "ANTHROPIC_BASE_URL"
4298
+ }))) != null ? _a : "https://api.anthropic.com/v1";
4299
+ const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
4300
+ if (options.apiKey && options.authToken) throw new require_dist.InvalidArgumentError({
4301
+ argument: "apiKey/authToken",
4302
+ message: "Both apiKey and authToken were provided. Please use only one authentication method."
4303
+ });
4304
+ const getHeaders = () => {
4305
+ const authHeaders = options.authToken ? { Authorization: `Bearer ${options.authToken}` } : { "x-api-key": require_dist.loadApiKey({
4306
+ apiKey: options.apiKey,
4307
+ environmentVariableName: "ANTHROPIC_API_KEY",
4308
+ description: "Anthropic"
4309
+ }) };
4310
+ return require_dist.withUserAgentSuffix({
4311
+ "anthropic-version": "2023-06-01",
4312
+ ...authHeaders,
4313
+ ...options.headers
4314
+ }, `ai-sdk/anthropic/${VERSION}`);
4315
+ };
4316
+ const createChatModel = (modelId) => {
4317
+ var _a2;
4318
+ return new AnthropicMessagesLanguageModel(modelId, {
4319
+ provider: providerName,
4320
+ baseURL,
4321
+ headers: getHeaders,
4322
+ fetch: options.fetch,
4323
+ generateId: (_a2 = options.generateId) != null ? _a2 : require_dist.generateId,
4324
+ supportedUrls: () => ({
4325
+ "image/*": [/^https?:\/\/.*$/],
4326
+ "application/pdf": [/^https?:\/\/.*$/]
4327
+ })
4328
+ });
4329
+ };
4330
+ const provider = function(modelId) {
4331
+ if (new.target) throw new Error("The Anthropic model function cannot be called with the new keyword.");
4332
+ return createChatModel(modelId);
4333
+ };
4334
+ provider.specificationVersion = "v3";
4335
+ provider.languageModel = createChatModel;
4336
+ provider.chat = createChatModel;
4337
+ provider.messages = createChatModel;
4338
+ provider.embeddingModel = (modelId) => {
4339
+ throw new require_dist.NoSuchModelError({
4340
+ modelId,
4341
+ modelType: "embeddingModel"
4342
+ });
4343
+ };
4344
+ provider.textEmbeddingModel = provider.embeddingModel;
4345
+ provider.imageModel = (modelId) => {
4346
+ throw new require_dist.NoSuchModelError({
4347
+ modelId,
4348
+ modelType: "imageModel"
4349
+ });
4350
+ };
4351
+ provider.tools = anthropicTools;
4352
+ return provider;
4353
+ }
4354
+ var anthropic = createAnthropic();
4355
+
4356
+ //#endregion
4357
+ exports.createAnthropic = createAnthropic;
4358
+ //# sourceMappingURL=dist-BlD4pqf2.cjs.map