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