@langchain/anthropic 1.3.19 → 1.3.21

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/dist/profiles.js CHANGED
@@ -1,12 +1,12 @@
1
1
  //#region src/profiles.ts
2
2
  const PROFILES = {
3
- "claude-opus-4-5-20251101": {
3
+ "claude-opus-4-0": {
4
4
  maxInputTokens: 2e5,
5
5
  imageInputs: true,
6
6
  audioInputs: false,
7
7
  pdfInputs: true,
8
8
  videoInputs: false,
9
- maxOutputTokens: 64e3,
9
+ maxOutputTokens: 32e3,
10
10
  reasoningOutput: true,
11
11
  imageOutputs: false,
12
12
  audioOutputs: false,
@@ -17,7 +17,7 @@ const PROFILES = {
17
17
  pdfToolMessage: true,
18
18
  imageToolMessage: true
19
19
  },
20
- "claude-3-5-haiku-latest": {
20
+ "claude-3-5-sonnet-20241022": {
21
21
  maxInputTokens: 2e5,
22
22
  imageInputs: true,
23
23
  audioInputs: false,
@@ -51,14 +51,14 @@ const PROFILES = {
51
51
  pdfToolMessage: true,
52
52
  imageToolMessage: true
53
53
  },
54
- "claude-3-5-sonnet-20241022": {
54
+ "claude-haiku-4-5": {
55
55
  maxInputTokens: 2e5,
56
56
  imageInputs: true,
57
57
  audioInputs: false,
58
58
  pdfInputs: true,
59
59
  videoInputs: false,
60
- maxOutputTokens: 8192,
61
- reasoningOutput: false,
60
+ maxOutputTokens: 64e3,
61
+ reasoningOutput: true,
62
62
  imageOutputs: false,
63
63
  audioOutputs: false,
64
64
  videoOutputs: false,
@@ -68,14 +68,14 @@ const PROFILES = {
68
68
  pdfToolMessage: true,
69
69
  imageToolMessage: true
70
70
  },
71
- "claude-3-sonnet-20240229": {
71
+ "claude-sonnet-4-6": {
72
72
  maxInputTokens: 2e5,
73
73
  imageInputs: true,
74
74
  audioInputs: false,
75
75
  pdfInputs: true,
76
76
  videoInputs: false,
77
- maxOutputTokens: 4096,
78
- reasoningOutput: false,
77
+ maxOutputTokens: 64e3,
78
+ reasoningOutput: true,
79
79
  imageOutputs: false,
80
80
  audioOutputs: false,
81
81
  videoOutputs: false,
@@ -85,14 +85,14 @@ const PROFILES = {
85
85
  pdfToolMessage: true,
86
86
  imageToolMessage: true
87
87
  },
88
- "claude-opus-4-6": {
88
+ "claude-3-5-sonnet-20240620": {
89
89
  maxInputTokens: 2e5,
90
90
  imageInputs: true,
91
91
  audioInputs: false,
92
92
  pdfInputs: true,
93
93
  videoInputs: false,
94
- maxOutputTokens: 128e3,
95
- reasoningOutput: true,
94
+ maxOutputTokens: 8192,
95
+ reasoningOutput: false,
96
96
  imageOutputs: false,
97
97
  audioOutputs: false,
98
98
  videoOutputs: false,
@@ -102,13 +102,13 @@ const PROFILES = {
102
102
  pdfToolMessage: true,
103
103
  imageToolMessage: true
104
104
  },
105
- "claude-sonnet-4-6": {
105
+ "claude-opus-4-6": {
106
106
  maxInputTokens: 2e5,
107
107
  imageInputs: true,
108
108
  audioInputs: false,
109
109
  pdfInputs: true,
110
110
  videoInputs: false,
111
- maxOutputTokens: 64e3,
111
+ maxOutputTokens: 128e3,
112
112
  reasoningOutput: true,
113
113
  imageOutputs: false,
114
114
  audioOutputs: false,
@@ -119,14 +119,14 @@ const PROFILES = {
119
119
  pdfToolMessage: true,
120
120
  imageToolMessage: true
121
121
  },
122
- "claude-sonnet-4-0": {
122
+ "claude-3-5-haiku-latest": {
123
123
  maxInputTokens: 2e5,
124
124
  imageInputs: true,
125
125
  audioInputs: false,
126
126
  pdfInputs: true,
127
127
  videoInputs: false,
128
- maxOutputTokens: 64e3,
129
- reasoningOutput: true,
128
+ maxOutputTokens: 8192,
129
+ reasoningOutput: false,
130
130
  imageOutputs: false,
131
131
  audioOutputs: false,
132
132
  videoOutputs: false,
@@ -136,13 +136,13 @@ const PROFILES = {
136
136
  pdfToolMessage: true,
137
137
  imageToolMessage: true
138
138
  },
139
- "claude-opus-4-20250514": {
139
+ "claude-opus-4-5": {
140
140
  maxInputTokens: 2e5,
141
141
  imageInputs: true,
142
142
  audioInputs: false,
143
143
  pdfInputs: true,
144
144
  videoInputs: false,
145
- maxOutputTokens: 32e3,
145
+ maxOutputTokens: 64e3,
146
146
  reasoningOutput: true,
147
147
  imageOutputs: false,
148
148
  audioOutputs: false,
@@ -153,14 +153,14 @@ const PROFILES = {
153
153
  pdfToolMessage: true,
154
154
  imageToolMessage: true
155
155
  },
156
- "claude-sonnet-4-5-20250929": {
156
+ "claude-3-opus-20240229": {
157
157
  maxInputTokens: 2e5,
158
158
  imageInputs: true,
159
159
  audioInputs: false,
160
160
  pdfInputs: true,
161
161
  videoInputs: false,
162
- maxOutputTokens: 64e3,
163
- reasoningOutput: true,
162
+ maxOutputTokens: 4096,
163
+ reasoningOutput: false,
164
164
  imageOutputs: false,
165
165
  audioOutputs: false,
166
166
  videoOutputs: false,
@@ -170,13 +170,13 @@ const PROFILES = {
170
170
  pdfToolMessage: true,
171
171
  imageToolMessage: true
172
172
  },
173
- "claude-opus-4-0": {
173
+ "claude-opus-4-5-20251101": {
174
174
  maxInputTokens: 2e5,
175
175
  imageInputs: true,
176
176
  audioInputs: false,
177
177
  pdfInputs: true,
178
178
  videoInputs: false,
179
- maxOutputTokens: 32e3,
179
+ maxOutputTokens: 64e3,
180
180
  reasoningOutput: true,
181
181
  imageOutputs: false,
182
182
  audioOutputs: false,
@@ -187,14 +187,14 @@ const PROFILES = {
187
187
  pdfToolMessage: true,
188
188
  imageToolMessage: true
189
189
  },
190
- "claude-3-5-haiku-20241022": {
190
+ "claude-sonnet-4-5": {
191
191
  maxInputTokens: 2e5,
192
192
  imageInputs: true,
193
193
  audioInputs: false,
194
194
  pdfInputs: true,
195
195
  videoInputs: false,
196
- maxOutputTokens: 8192,
197
- reasoningOutput: false,
196
+ maxOutputTokens: 64e3,
197
+ reasoningOutput: true,
198
198
  imageOutputs: false,
199
199
  audioOutputs: false,
200
200
  videoOutputs: false,
@@ -204,14 +204,14 @@ const PROFILES = {
204
204
  pdfToolMessage: true,
205
205
  imageToolMessage: true
206
206
  },
207
- "claude-3-5-sonnet-20240620": {
207
+ "claude-sonnet-4-5-20250929": {
208
208
  maxInputTokens: 2e5,
209
209
  imageInputs: true,
210
210
  audioInputs: false,
211
211
  pdfInputs: true,
212
212
  videoInputs: false,
213
- maxOutputTokens: 8192,
214
- reasoningOutput: false,
213
+ maxOutputTokens: 64e3,
214
+ reasoningOutput: true,
215
215
  imageOutputs: false,
216
216
  audioOutputs: false,
217
217
  videoOutputs: false,
@@ -221,7 +221,7 @@ const PROFILES = {
221
221
  pdfToolMessage: true,
222
222
  imageToolMessage: true
223
223
  },
224
- "claude-3-7-sonnet-latest": {
224
+ "claude-sonnet-4-20250514": {
225
225
  maxInputTokens: 2e5,
226
226
  imageInputs: true,
227
227
  audioInputs: false,
@@ -238,13 +238,13 @@ const PROFILES = {
238
238
  pdfToolMessage: true,
239
239
  imageToolMessage: true
240
240
  },
241
- "claude-3-7-sonnet-20250219": {
241
+ "claude-opus-4-20250514": {
242
242
  maxInputTokens: 2e5,
243
243
  imageInputs: true,
244
244
  audioInputs: false,
245
245
  pdfInputs: true,
246
246
  videoInputs: false,
247
- maxOutputTokens: 64e3,
247
+ maxOutputTokens: 32e3,
248
248
  reasoningOutput: true,
249
249
  imageOutputs: false,
250
250
  audioOutputs: false,
@@ -255,13 +255,13 @@ const PROFILES = {
255
255
  pdfToolMessage: true,
256
256
  imageToolMessage: true
257
257
  },
258
- "claude-3-haiku-20240307": {
258
+ "claude-3-5-haiku-20241022": {
259
259
  maxInputTokens: 2e5,
260
260
  imageInputs: true,
261
261
  audioInputs: false,
262
262
  pdfInputs: true,
263
263
  videoInputs: false,
264
- maxOutputTokens: 4096,
264
+ maxOutputTokens: 8192,
265
265
  reasoningOutput: false,
266
266
  imageOutputs: false,
267
267
  audioOutputs: false,
@@ -272,14 +272,14 @@ const PROFILES = {
272
272
  pdfToolMessage: true,
273
273
  imageToolMessage: true
274
274
  },
275
- "claude-haiku-4-5-20251001": {
275
+ "claude-3-haiku-20240307": {
276
276
  maxInputTokens: 2e5,
277
277
  imageInputs: true,
278
278
  audioInputs: false,
279
279
  pdfInputs: true,
280
280
  videoInputs: false,
281
- maxOutputTokens: 64e3,
282
- reasoningOutput: true,
281
+ maxOutputTokens: 4096,
282
+ reasoningOutput: false,
283
283
  imageOutputs: false,
284
284
  audioOutputs: false,
285
285
  videoOutputs: false,
@@ -289,7 +289,7 @@ const PROFILES = {
289
289
  pdfToolMessage: true,
290
290
  imageToolMessage: true
291
291
  },
292
- "claude-haiku-4-5": {
292
+ "claude-3-7-sonnet-20250219": {
293
293
  maxInputTokens: 2e5,
294
294
  imageInputs: true,
295
295
  audioInputs: false,
@@ -306,7 +306,7 @@ const PROFILES = {
306
306
  pdfToolMessage: true,
307
307
  imageToolMessage: true
308
308
  },
309
- "claude-opus-4-5": {
309
+ "claude-3-7-sonnet-latest": {
310
310
  maxInputTokens: 2e5,
311
311
  imageInputs: true,
312
312
  audioInputs: false,
@@ -323,14 +323,14 @@ const PROFILES = {
323
323
  pdfToolMessage: true,
324
324
  imageToolMessage: true
325
325
  },
326
- "claude-3-opus-20240229": {
326
+ "claude-sonnet-4-0": {
327
327
  maxInputTokens: 2e5,
328
328
  imageInputs: true,
329
329
  audioInputs: false,
330
330
  pdfInputs: true,
331
331
  videoInputs: false,
332
- maxOutputTokens: 4096,
333
- reasoningOutput: false,
332
+ maxOutputTokens: 64e3,
333
+ reasoningOutput: true,
334
334
  imageOutputs: false,
335
335
  audioOutputs: false,
336
336
  videoOutputs: false,
@@ -340,13 +340,13 @@ const PROFILES = {
340
340
  pdfToolMessage: true,
341
341
  imageToolMessage: true
342
342
  },
343
- "claude-sonnet-4-5": {
343
+ "claude-opus-4-1-20250805": {
344
344
  maxInputTokens: 2e5,
345
345
  imageInputs: true,
346
346
  audioInputs: false,
347
347
  pdfInputs: true,
348
348
  videoInputs: false,
349
- maxOutputTokens: 64e3,
349
+ maxOutputTokens: 32e3,
350
350
  reasoningOutput: true,
351
351
  imageOutputs: false,
352
352
  audioOutputs: false,
@@ -357,14 +357,14 @@ const PROFILES = {
357
357
  pdfToolMessage: true,
358
358
  imageToolMessage: true
359
359
  },
360
- "claude-sonnet-4-20250514": {
360
+ "claude-3-sonnet-20240229": {
361
361
  maxInputTokens: 2e5,
362
362
  imageInputs: true,
363
363
  audioInputs: false,
364
364
  pdfInputs: true,
365
365
  videoInputs: false,
366
- maxOutputTokens: 64e3,
367
- reasoningOutput: true,
366
+ maxOutputTokens: 4096,
367
+ reasoningOutput: false,
368
368
  imageOutputs: false,
369
369
  audioOutputs: false,
370
370
  videoOutputs: false,
@@ -374,13 +374,13 @@ const PROFILES = {
374
374
  pdfToolMessage: true,
375
375
  imageToolMessage: true
376
376
  },
377
- "claude-opus-4-1-20250805": {
377
+ "claude-haiku-4-5-20251001": {
378
378
  maxInputTokens: 2e5,
379
379
  imageInputs: true,
380
380
  audioInputs: false,
381
381
  pdfInputs: true,
382
382
  videoInputs: false,
383
- maxOutputTokens: 32e3,
383
+ maxOutputTokens: 64e3,
384
384
  reasoningOutput: true,
385
385
  imageOutputs: false,
386
386
  audioOutputs: false,
@@ -1 +1 @@
1
- {"version":3,"file":"profiles.js","names":[],"sources":["../src/profiles.ts"],"sourcesContent":["/**\n * This file was automatically generated by an automated script. Do not edit manually.\n */\nimport type { ModelProfile } from \"@langchain/core/language_models/profile\";\nconst PROFILES: Record<string, ModelProfile> = {\n \"claude-opus-4-5-20251101\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-5-haiku-latest\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 8192,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-1\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 32000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-5-sonnet-20241022\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 8192,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-sonnet-20240229\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 4096,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-6\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 128000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-6\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-0\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-20250514\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 32000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-5-20250929\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-0\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 32000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-5-haiku-20241022\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 8192,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-5-sonnet-20240620\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 8192,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-7-sonnet-latest\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-7-sonnet-20250219\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-haiku-20240307\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 4096,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-haiku-4-5-20251001\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-haiku-4-5\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-5\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-opus-20240229\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 4096,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-5\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-20250514\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-1-20250805\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 32000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n};\nexport default PROFILES;\n"],"mappings":";AAIA,MAAM,WAAyC;CAC7C,4BAA4B;EAC1B,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,2BAA2B;EACzB,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,mBAAmB;EACjB,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,8BAA8B;EAC5B,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,4BAA4B;EAC1B,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,mBAAmB;E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gB;EAChB,kBAAkB;EACnB;CACF"}
1
+ {"version":3,"file":"profiles.js","names":[],"sources":["../src/profiles.ts"],"sourcesContent":["/**\n * This file was automatically generated by an automated script. Do not edit manually.\n */\nimport type { ModelProfile } from \"@langchain/core/language_models/profile\";\nconst PROFILES: Record<string, ModelProfile> = {\n \"claude-opus-4-0\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 32000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-5-sonnet-20241022\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 8192,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-1\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 32000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-haiku-4-5\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-6\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-5-sonnet-20240620\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 8192,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-6\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 128000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-5-haiku-latest\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 8192,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-5\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-opus-20240229\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 4096,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-5-20251101\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-5\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-5-20250929\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-20250514\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-20250514\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 32000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-5-haiku-20241022\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 8192,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-haiku-20240307\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 4096,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-7-sonnet-20250219\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-7-sonnet-latest\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-sonnet-4-0\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-opus-4-1-20250805\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 32000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-3-sonnet-20240229\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 4096,\n reasoningOutput: false,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n \"claude-haiku-4-5-20251001\": {\n maxInputTokens: 200000,\n imageInputs: true,\n audioInputs: false,\n pdfInputs: true,\n videoInputs: false,\n maxOutputTokens: 64000,\n reasoningOutput: true,\n imageOutputs: false,\n audioOutputs: false,\n videoOutputs: false,\n toolCalling: true,\n structuredOutput: false,\n imageUrlInputs: true,\n pdfToolMessage: true,\n imageToolMessage: true,\n },\n};\nexport default PROFILES;\n"],"mappings":";AAIA,MAAM,WAAyC;CAC7C,mBAAmB;EACjB,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,8BAA8B;EAC5B,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,mBAAmB;EACjB,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;E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AAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,4BAA4B;EAC1B,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,6BAA6B;EAC3B,gBAAgB;EAChB,aAAa;EACb,aAAa;EACb,WAAW;EACX,aAAa;EACb,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;EACd,cAAc;EACd,cAAc;EACd,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,kBAAkB;EACnB;CACF"}
@@ -224,10 +224,15 @@ function _convertMessagesToAnthropicPayload(messages) {
224
224
  };
225
225
  else {
226
226
  const { content } = message;
227
- if (!message.tool_calls.every((toolCall) => content.find((contentPart) => (contentPart.type === "tool_use" || contentPart.type === "input_json_delta" || contentPart.type === "server_tool_use") && contentPart.id === toolCall.id))) console.warn(`The "tool_calls" field on a message is only respected if content is a string.`);
227
+ const formattedContent = _formatContent(message, message.tool_calls);
228
+ const formattedContentArr = Array.isArray(formattedContent) ? formattedContent : [{
229
+ type: "text",
230
+ text: formattedContent
231
+ }];
232
+ const missingToolCalls = message.tool_calls.filter((toolCall) => !content.find((contentPart) => (contentPart.type === "tool_use" || contentPart.type === "input_json_delta" || contentPart.type === "server_tool_use") && contentPart.id === toolCall.id));
228
233
  return {
229
234
  role,
230
- content: _formatContent(message, message.tool_calls)
235
+ content: [...formattedContentArr, ...missingToolCalls.map(_convertLangChainToolCallToAnthropic)]
231
236
  };
232
237
  }
233
238
  else return {
@@ -1 +1 @@
1
- {"version":3,"file":"message_inputs.cjs","names":["HumanMessage","standardContentBlockConverter","_isAnthropicImageBlockParam","_isAnthropicThinkingBlock","_isAnthropicRedactedThinkingBlock","_isAnthropicCompactionBlock","_isAnthropicSearchResultBlock","AIMessage","_formatStandardContent"],"sources":["../../src/utils/message_inputs.ts"],"sourcesContent":["/**\n * This util file contains functions for converting LangChain messages to Anthropic messages.\n */\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport {\n type BaseMessage,\n HumanMessage,\n ToolMessage,\n MessageContentComplex,\n isDataContentBlock,\n convertToProviderContentBlock,\n parseBase64DataUrl,\n ContentBlock,\n AIMessage,\n} from \"@langchain/core/messages\";\nimport { ToolCall } from \"@langchain/core/messages/tool\";\nimport {\n AnthropicImageBlockParam,\n AnthropicMessageCreateParams,\n AnthropicTextBlockParam,\n AnthropicToolResultBlockParam,\n AnthropicToolUseBlockParam,\n AnthropicDocumentBlockParam,\n AnthropicThinkingBlockParam,\n AnthropicRedactedThinkingBlockParam,\n AnthropicServerToolUseBlockParam,\n AnthropicWebSearchToolResultBlockParam,\n AnthropicSearchResultBlockParam,\n AnthropicToolResponse,\n AnthropicContainerUploadBlockParam,\n AnthropicCompactionBlockParam,\n} from \"../types.js\";\nimport {\n _isAnthropicImageBlockParam,\n _isAnthropicRedactedThinkingBlock,\n _isAnthropicSearchResultBlock,\n _isAnthropicThinkingBlock,\n _isAnthropicCompactionBlock,\n standardContentBlockConverter,\n} from \"./content.js\";\nimport { _formatStandardContent } from \"./standard.js\";\n\nfunction _formatImage(imageUrl: string) {\n const parsed = parseBase64DataUrl({ dataUrl: imageUrl });\n if (parsed) {\n return {\n type: \"base64\",\n media_type: parsed.mime_type,\n data: parsed.data,\n };\n }\n let parsedUrl: URL;\n\n try {\n parsedUrl = new URL(imageUrl);\n } catch {\n throw new Error(\n [\n `Malformed image URL: ${JSON.stringify(\n imageUrl\n )}. Content blocks of type 'image_url' must be a valid http, https, or base64-encoded data URL.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n }\n\n if (parsedUrl.protocol === \"http:\" || parsedUrl.protocol === \"https:\") {\n return {\n type: \"url\",\n url: imageUrl,\n };\n }\n\n throw new Error(\n [\n `Invalid image URL protocol: ${JSON.stringify(\n parsedUrl.protocol\n )}. Anthropic only supports images as http, https, or base64-encoded data URLs on 'image_url' content blocks.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n}\n\nfunction _ensureMessageContents(messages: BaseMessage[]): BaseMessage[] {\n // Merge runs of human/tool messages into single human messages with content blocks.\n const updatedMsgs = [];\n for (const message of messages) {\n if (message._getType() === \"tool\") {\n if (typeof message.content === \"string\") {\n const previousMessage = updatedMsgs[updatedMsgs.length - 1];\n if (\n previousMessage?._getType() === \"human\" &&\n Array.isArray(previousMessage.content) &&\n \"type\" in previousMessage.content[0] &&\n previousMessage.content[0].type === \"tool_result\"\n ) {\n // If the previous message was a tool result, we merge this tool message into it.\n (previousMessage.content as MessageContentComplex[]).push({\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n });\n } else {\n // If not, we create a new human message with the tool result.\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n // rare case: message.content could be undefined\n ...(message.content != null\n ? { content: _formatContent(message) }\n : {}),\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(message);\n }\n }\n return updatedMsgs;\n}\n\nexport function _convertLangChainToolCallToAnthropic(\n toolCall: ToolCall\n): AnthropicToolResponse {\n if (toolCall.id === undefined) {\n throw new Error(`Anthropic requires all tool calls to have an \"id\".`);\n }\n return {\n type: \"tool_use\",\n id: toolCall.id,\n name: toolCall.name,\n input: toolCall.args,\n };\n}\n\nfunction* _formatContentBlocks(\n content: ContentBlock[],\n toolCalls?: ToolCall[]\n): Generator<Anthropic.Beta.BetaContentBlockParam> {\n const toolTypes = [\n \"bash_code_execution_tool_result\",\n \"input_json_delta\",\n \"server_tool_use\",\n \"text_editor_code_execution_tool_result\",\n \"tool_result\",\n \"tool_use\",\n \"web_search_result\",\n \"web_search_tool_result\",\n ];\n const textTypes = [\"text\", \"text_delta\"];\n for (const contentPart of content) {\n if (isDataContentBlock(contentPart)) {\n yield convertToProviderContentBlock(\n contentPart,\n standardContentBlockConverter\n );\n }\n\n const cacheControl =\n \"cache_control\" in contentPart\n ? (contentPart.cache_control as Anthropic.Beta.BetaCacheControlEphemeral)\n : undefined;\n\n if (contentPart.type === \"image_url\") {\n let source;\n if (typeof contentPart.image_url === \"string\") {\n source = _formatImage(contentPart.image_url);\n } else if (\n typeof contentPart.image_url === \"object\" &&\n contentPart.image_url !== null &&\n \"url\" in contentPart.image_url &&\n typeof contentPart.image_url.url === \"string\"\n ) {\n source = _formatImage(contentPart.image_url.url);\n }\n if (source) {\n yield {\n type: \"image\" as const, // Explicitly setting the type as \"image\"\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (_isAnthropicImageBlockParam(contentPart)) {\n yield contentPart;\n } else if (contentPart.type === \"image\") {\n // Handle new ContentBlock.Multimodal.Image format\n let source;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // URL-based image\n source = _formatImage(contentPart.url);\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // eslint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // Base64-based image\n const mimeType =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"image/jpeg\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n source = {\n type: \"base64\" as const,\n media_type: mimeType as\n | \"image/jpeg\"\n | \"image/png\"\n | \"image/gif\"\n | \"image/webp\",\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID-based image\n // Note: Anthropic supports file IDs for images that have been uploaded\n // to their servers via the Files API\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"image\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (contentPart.type === \"file\") {\n // Handle new ContentBlock.Multimodal.File format\n let source:\n | { type: \"url\"; url: string }\n | { type: \"base64\"; media_type: string; data: string }\n | { type: \"file\"; file_id: string }\n | undefined;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // File with URL\n source = {\n type: \"url\" as const,\n url: contentPart.url,\n };\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // eslint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // File with base64 data (string or Uint8Array)\n const media_type =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"application/pdf\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n\n source = {\n type: \"base64\" as const,\n media_type,\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID from Anthropic Files API\n // https://platform.claude.com/docs/en/build-with-claude/pdf-support#option-3-files-api\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"document\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n }\n } else if (contentPart.type === \"document\") {\n // PDF\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else if (_isAnthropicThinkingBlock(contentPart)) {\n const block: AnthropicThinkingBlockParam = {\n type: \"thinking\" as const, // Explicitly setting the type as \"thinking\"\n thinking: contentPart.thinking,\n signature: contentPart.signature,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicRedactedThinkingBlock(contentPart)) {\n const block: AnthropicRedactedThinkingBlockParam = {\n type: \"redacted_thinking\" as const, // Explicitly setting the type as \"redacted_thinking\"\n data: contentPart.data,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicCompactionBlock(contentPart)) {\n const block: AnthropicCompactionBlockParam = {\n type: \"compaction\" as const,\n content: contentPart.content,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicSearchResultBlock(contentPart)) {\n const block: AnthropicSearchResultBlockParam = {\n type: \"search_result\" as const, // Explicitly setting the type as \"search_result\"\n title: contentPart.title,\n source: contentPart.source,\n ...(\"cache_control\" in contentPart && contentPart.cache_control\n ? { cache_control: contentPart.cache_control }\n : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n content: contentPart.content,\n };\n yield block as Anthropic.Beta.BetaSearchResultBlockParam;\n } else if (\n textTypes.find((t) => t === contentPart.type) &&\n \"text\" in contentPart\n ) {\n // Assuming contentPart is of type MessageContentText here\n yield {\n type: \"text\" as const, // Explicitly setting the type as \"text\"\n text: contentPart.text,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n } as Anthropic.Messages.TextBlockParam;\n } else if (toolTypes.find((t) => t === contentPart.type)) {\n const contentPartCopy = { ...contentPart };\n\n if (contentPartCopy.type === \"input_json_delta\") {\n // `input_json_delta` type only represents yielding partial tool inputs\n // and is not a valid type for Anthropic messages.\n // These blocks appear in streaming responses and should be skipped\n // as their input data is already captured in tool_calls.\n continue;\n }\n\n if (\n contentPartCopy.type === \"tool_use\" &&\n typeof contentPartCopy.input === \"string\"\n ) {\n // First, try to get the input from the corresponding tool_call.\n // This is the most reliable source since tool_calls are properly\n // consolidated from tool_call_chunks during streaming.\n const matchingToolCall = toolCalls?.find(\n (tc) => tc.id === contentPartCopy.id\n );\n if (matchingToolCall) {\n contentPartCopy.input = matchingToolCall.args;\n } else {\n // Fallback: `tool_use` content part may be followed by `input_json_delta`\n // content parts which are chunks of a stringified JSON input,\n // so we need to collect them and merge their inputs.\n const inputDeltas = content.filter(\n (nestedContentPart) =>\n nestedContentPart.index === contentPartCopy.index &&\n nestedContentPart.type === \"input_json_delta\" &&\n typeof nestedContentPart.input === \"string\"\n );\n // If no `input_json_delta` parts are found, this line will just\n // return `contentPartCopy.input`, so no additional check is needed\n contentPartCopy.input = inputDeltas.reduce(\n (accumulator, nestedContentPart) =>\n accumulator + nestedContentPart.input,\n contentPartCopy.input\n );\n }\n }\n\n if (\"index\" in contentPartCopy) {\n // Anthropic does not support passing the index field here, so we remove it.\n delete contentPartCopy.index;\n }\n\n if (\"input\" in contentPartCopy) {\n // Anthropic tool use inputs should be valid objects, when applicable.\n if (typeof contentPartCopy.input === \"string\") {\n try {\n contentPartCopy.input = JSON.parse(contentPartCopy.input);\n } catch {\n contentPartCopy.input = {};\n }\n }\n }\n // TODO: Fix when SDK types are fixed\n yield {\n ...contentPartCopy,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n } else if (contentPart.type === \"container_upload\") {\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as AnthropicContainerUploadBlockParam;\n }\n\n // Note that we are intentionally dropping any blocks that we don't\n // recognize. This is to allow for cross-compatibility between different\n // providers that may have different block types. Ie if we take a message\n // output from OpenAI and send it to Anthropic, we want to drop any blocks\n // that Anthropic doesn't understand.\n }\n}\n\nfunction _formatContent(message: BaseMessage, toolCalls?: ToolCall[]) {\n const { content } = message;\n\n if (typeof content === \"string\") {\n return content;\n } else {\n return Array.from(_formatContentBlocks(content, toolCalls));\n }\n}\n\n/**\n * Formats messages as a prompt for the model.\n * Used in LangSmith, export is important here.\n * @param messages The base messages to format as a prompt.\n * @returns The formatted prompt.\n */\nexport function _convertMessagesToAnthropicPayload(\n messages: BaseMessage[]\n): AnthropicMessageCreateParams {\n const mergedMessages = _ensureMessageContents(messages);\n let system;\n if (mergedMessages.length > 0 && mergedMessages[0]._getType() === \"system\") {\n system = messages[0].content;\n }\n const conversationMessages =\n system !== undefined ? mergedMessages.slice(1) : mergedMessages;\n const formattedMessages = conversationMessages.map((message) => {\n let role;\n if (message._getType() === \"human\") {\n role = \"user\" as const;\n } else if (message._getType() === \"ai\") {\n role = \"assistant\" as const;\n } else if (message._getType() === \"tool\") {\n role = \"user\" as const;\n } else if (message._getType() === \"system\") {\n throw new Error(\n \"System messages are only permitted as the first passed message.\"\n );\n } else {\n throw new Error(`Message type \"${message.type}\" is not supported.`);\n }\n if (\n AIMessage.isInstance(message) &&\n message.response_metadata?.output_version === \"v1\"\n ) {\n return {\n role,\n content: _formatStandardContent(message),\n };\n }\n if (AIMessage.isInstance(message) && !!message.tool_calls?.length) {\n if (typeof message.content === \"string\") {\n if (message.content === \"\") {\n return {\n role,\n content: message.tool_calls.map(\n _convertLangChainToolCallToAnthropic\n ),\n };\n } else {\n return {\n role,\n content: [\n { type: \"text\", text: message.content },\n ...message.tool_calls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else {\n const { content } = message;\n const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) =>\n content.find(\n (contentPart) =>\n (contentPart.type === \"tool_use\" ||\n contentPart.type === \"input_json_delta\" ||\n contentPart.type === \"server_tool_use\") &&\n contentPart.id === toolCall.id\n )\n );\n if (hasMismatchedToolCalls) {\n console.warn(\n `The \"tool_calls\" field on a message is only respected if content is a string.`\n );\n }\n return {\n role,\n content: _formatContent(message, message.tool_calls),\n };\n }\n } else {\n return {\n role,\n content: _formatContent(\n message,\n AIMessage.isInstance(message) ? message.tool_calls : undefined\n ),\n };\n }\n });\n return {\n messages: mergeMessages(\n formattedMessages as AnthropicMessageCreateParams[\"messages\"]\n ),\n system,\n } as AnthropicMessageCreateParams;\n}\n\n/**\n * Cache control configuration for Anthropic prompt caching.\n */\ninterface CacheControl {\n type: \"ephemeral\";\n ttl?: \"5m\" | \"1h\";\n}\n\n/**\n * Applies cache_control to the last content block of the last message in the payload.\n * This is the recommended approach for prompt caching as it applies the cache_control\n * at the final formatting layer, after all message processing is complete.\n *\n * This matches the Python langchain-anthropic implementation where cache_control\n * is applied via model_settings rather than modifying message content blocks directly.\n *\n * @param payload - The formatted Anthropic message payload\n * @param cacheControl - The cache control configuration to apply\n * @returns The payload with cache_control applied to the last content block\n */\nexport function applyCacheControlToPayload(\n payload: AnthropicMessageCreateParams,\n cacheControl: CacheControl\n): AnthropicMessageCreateParams {\n if (!payload.messages || payload.messages.length === 0) {\n return payload;\n }\n\n const messages = [...payload.messages];\n const lastMessageIndex = messages.length - 1;\n const lastMessage = messages[lastMessageIndex];\n\n if (!lastMessage) {\n return payload;\n }\n\n // Handle string content - convert to text block with cache_control\n if (typeof lastMessage.content === \"string\") {\n messages[lastMessageIndex] = {\n ...lastMessage,\n content: [\n {\n type: \"text\",\n text: lastMessage.content,\n cache_control: cacheControl,\n },\n ],\n };\n return { ...payload, messages };\n }\n\n // Handle array content - add cache_control to the last block\n if (Array.isArray(lastMessage.content) && lastMessage.content.length > 0) {\n const content = [...lastMessage.content];\n const lastBlockIndex = content.length - 1;\n const lastBlock = content[lastBlockIndex];\n\n // Add cache_control to the last block\n content[lastBlockIndex] = {\n ...lastBlock,\n cache_control: cacheControl,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n\n messages[lastMessageIndex] = {\n ...lastMessage,\n content,\n };\n return { ...payload, messages };\n }\n\n return payload;\n}\n\nfunction mergeMessages(messages: AnthropicMessageCreateParams[\"messages\"]) {\n if (!messages || messages.length <= 1) {\n return messages;\n }\n\n const result: AnthropicMessageCreateParams[\"messages\"] = [];\n let currentMessage = messages[0];\n\n const normalizeContent = (\n content:\n | string\n | Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n >\n ): Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n > => {\n if (typeof content === \"string\") {\n return [\n {\n type: \"text\",\n text: content,\n },\n ];\n }\n return content;\n };\n\n const isToolResultMessage = (msg: (typeof messages)[0]) => {\n if (msg.role !== \"user\") return false;\n\n if (typeof msg.content === \"string\") {\n return false;\n }\n\n return (\n Array.isArray(msg.content) &&\n msg.content.every((item) => item.type === \"tool_result\")\n );\n };\n\n for (let i = 1; i < messages.length; i += 1) {\n const nextMessage = messages[i];\n\n if (\n isToolResultMessage(currentMessage) &&\n isToolResultMessage(nextMessage)\n ) {\n // Merge the messages by combining their content arrays\n currentMessage = {\n ...currentMessage,\n content: [\n ...normalizeContent(currentMessage.content),\n ...normalizeContent(nextMessage.content),\n ],\n };\n } else {\n result.push(currentMessage);\n currentMessage = nextMessage;\n }\n }\n\n result.push(currentMessage);\n return result;\n}\n"],"mappings":";;;;;;AA0CA,SAAS,aAAa,UAAkB;CACtC,MAAM,0DAA4B,EAAE,SAAS,UAAU,CAAC;AACxD,KAAI,OAC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KAAK,GAAG;EAC3C,MAAM,cAAc,SAAS;AAE7B,MACE,oBAAoB,eAAe,IACnC,oBAAoB,YAAY,CAGhC,kBAAiB;GACf,GAAG;GACH,SAAS,CACP,GAAG,iBAAiB,eAAe,QAAQ,EAC3C,GAAG,iBAAiB,YAAY,QAAQ,CACzC;GACF;OACI;AACL,UAAO,KAAK,eAAe;AAC3B,oBAAiB;;;AAIrB,QAAO,KAAK,eAAe;AAC3B,QAAO"}
1
+ {"version":3,"file":"message_inputs.cjs","names":["HumanMessage","standardContentBlockConverter","_isAnthropicImageBlockParam","_isAnthropicThinkingBlock","_isAnthropicRedactedThinkingBlock","_isAnthropicCompactionBlock","_isAnthropicSearchResultBlock","AIMessage","_formatStandardContent"],"sources":["../../src/utils/message_inputs.ts"],"sourcesContent":["/**\n * This util file contains functions for converting LangChain messages to Anthropic messages.\n */\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport {\n type BaseMessage,\n HumanMessage,\n ToolMessage,\n MessageContentComplex,\n isDataContentBlock,\n convertToProviderContentBlock,\n parseBase64DataUrl,\n ContentBlock,\n AIMessage,\n} from \"@langchain/core/messages\";\nimport { ToolCall } from \"@langchain/core/messages/tool\";\nimport {\n AnthropicImageBlockParam,\n AnthropicMessageCreateParams,\n AnthropicTextBlockParam,\n AnthropicToolResultBlockParam,\n AnthropicToolUseBlockParam,\n AnthropicDocumentBlockParam,\n AnthropicThinkingBlockParam,\n AnthropicRedactedThinkingBlockParam,\n AnthropicServerToolUseBlockParam,\n AnthropicWebSearchToolResultBlockParam,\n AnthropicSearchResultBlockParam,\n AnthropicToolResponse,\n AnthropicContainerUploadBlockParam,\n AnthropicCompactionBlockParam,\n} from \"../types.js\";\nimport {\n _isAnthropicImageBlockParam,\n _isAnthropicRedactedThinkingBlock,\n _isAnthropicSearchResultBlock,\n _isAnthropicThinkingBlock,\n _isAnthropicCompactionBlock,\n standardContentBlockConverter,\n} from \"./content.js\";\nimport { _formatStandardContent } from \"./standard.js\";\n\nfunction _formatImage(imageUrl: string) {\n const parsed = parseBase64DataUrl({ dataUrl: imageUrl });\n if (parsed) {\n return {\n type: \"base64\",\n media_type: parsed.mime_type,\n data: parsed.data,\n };\n }\n let parsedUrl: URL;\n\n try {\n parsedUrl = new URL(imageUrl);\n } catch {\n throw new Error(\n [\n `Malformed image URL: ${JSON.stringify(\n imageUrl\n )}. Content blocks of type 'image_url' must be a valid http, https, or base64-encoded data URL.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n }\n\n if (parsedUrl.protocol === \"http:\" || parsedUrl.protocol === \"https:\") {\n return {\n type: \"url\",\n url: imageUrl,\n };\n }\n\n throw new Error(\n [\n `Invalid image URL protocol: ${JSON.stringify(\n parsedUrl.protocol\n )}. Anthropic only supports images as http, https, or base64-encoded data URLs on 'image_url' content blocks.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n}\n\nfunction _ensureMessageContents(messages: BaseMessage[]): BaseMessage[] {\n // Merge runs of human/tool messages into single human messages with content blocks.\n const updatedMsgs = [];\n for (const message of messages) {\n if (message._getType() === \"tool\") {\n if (typeof message.content === \"string\") {\n const previousMessage = updatedMsgs[updatedMsgs.length - 1];\n if (\n previousMessage?._getType() === \"human\" &&\n Array.isArray(previousMessage.content) &&\n \"type\" in previousMessage.content[0] &&\n previousMessage.content[0].type === \"tool_result\"\n ) {\n // If the previous message was a tool result, we merge this tool message into it.\n (previousMessage.content as MessageContentComplex[]).push({\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n });\n } else {\n // If not, we create a new human message with the tool result.\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n // rare case: message.content could be undefined\n ...(message.content != null\n ? { content: _formatContent(message) }\n : {}),\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(message);\n }\n }\n return updatedMsgs;\n}\n\nexport function _convertLangChainToolCallToAnthropic(\n toolCall: ToolCall\n): AnthropicToolResponse {\n if (toolCall.id === undefined) {\n throw new Error(`Anthropic requires all tool calls to have an \"id\".`);\n }\n return {\n type: \"tool_use\",\n id: toolCall.id,\n name: toolCall.name,\n input: toolCall.args,\n };\n}\n\nfunction* _formatContentBlocks(\n content: ContentBlock[],\n toolCalls?: ToolCall[]\n): Generator<Anthropic.Beta.BetaContentBlockParam> {\n const toolTypes = [\n \"bash_code_execution_tool_result\",\n \"input_json_delta\",\n \"server_tool_use\",\n \"text_editor_code_execution_tool_result\",\n \"tool_result\",\n \"tool_use\",\n \"web_search_result\",\n \"web_search_tool_result\",\n ];\n const textTypes = [\"text\", \"text_delta\"];\n for (const contentPart of content) {\n if (isDataContentBlock(contentPart)) {\n yield convertToProviderContentBlock(\n contentPart,\n standardContentBlockConverter\n );\n }\n\n const cacheControl =\n \"cache_control\" in contentPart\n ? (contentPart.cache_control as Anthropic.Beta.BetaCacheControlEphemeral)\n : undefined;\n\n if (contentPart.type === \"image_url\") {\n let source;\n if (typeof contentPart.image_url === \"string\") {\n source = _formatImage(contentPart.image_url);\n } else if (\n typeof contentPart.image_url === \"object\" &&\n contentPart.image_url !== null &&\n \"url\" in contentPart.image_url &&\n typeof contentPart.image_url.url === \"string\"\n ) {\n source = _formatImage(contentPart.image_url.url);\n }\n if (source) {\n yield {\n type: \"image\" as const, // Explicitly setting the type as \"image\"\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (_isAnthropicImageBlockParam(contentPart)) {\n yield contentPart;\n } else if (contentPart.type === \"image\") {\n // Handle new ContentBlock.Multimodal.Image format\n let source;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // URL-based image\n source = _formatImage(contentPart.url);\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // eslint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // Base64-based image\n const mimeType =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"image/jpeg\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n source = {\n type: \"base64\" as const,\n media_type: mimeType as\n | \"image/jpeg\"\n | \"image/png\"\n | \"image/gif\"\n | \"image/webp\",\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID-based image\n // Note: Anthropic supports file IDs for images that have been uploaded\n // to their servers via the Files API\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"image\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (contentPart.type === \"file\") {\n // Handle new ContentBlock.Multimodal.File format\n let source:\n | { type: \"url\"; url: string }\n | { type: \"base64\"; media_type: string; data: string }\n | { type: \"file\"; file_id: string }\n | undefined;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // File with URL\n source = {\n type: \"url\" as const,\n url: contentPart.url,\n };\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // eslint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // File with base64 data (string or Uint8Array)\n const media_type =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"application/pdf\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n\n source = {\n type: \"base64\" as const,\n media_type,\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID from Anthropic Files API\n // https://platform.claude.com/docs/en/build-with-claude/pdf-support#option-3-files-api\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"document\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n }\n } else if (contentPart.type === \"document\") {\n // PDF\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else if (_isAnthropicThinkingBlock(contentPart)) {\n const block: AnthropicThinkingBlockParam = {\n type: \"thinking\" as const, // Explicitly setting the type as \"thinking\"\n thinking: contentPart.thinking,\n signature: contentPart.signature,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicRedactedThinkingBlock(contentPart)) {\n const block: AnthropicRedactedThinkingBlockParam = {\n type: \"redacted_thinking\" as const, // Explicitly setting the type as \"redacted_thinking\"\n data: contentPart.data,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicCompactionBlock(contentPart)) {\n const block: AnthropicCompactionBlockParam = {\n type: \"compaction\" as const,\n content: contentPart.content,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicSearchResultBlock(contentPart)) {\n const block: AnthropicSearchResultBlockParam = {\n type: \"search_result\" as const, // Explicitly setting the type as \"search_result\"\n title: contentPart.title,\n source: contentPart.source,\n ...(\"cache_control\" in contentPart && contentPart.cache_control\n ? { cache_control: contentPart.cache_control }\n : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n content: contentPart.content,\n };\n yield block as Anthropic.Beta.BetaSearchResultBlockParam;\n } else if (\n textTypes.find((t) => t === contentPart.type) &&\n \"text\" in contentPart\n ) {\n // Assuming contentPart is of type MessageContentText here\n yield {\n type: \"text\" as const, // Explicitly setting the type as \"text\"\n text: contentPart.text,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n } as Anthropic.Messages.TextBlockParam;\n } else if (toolTypes.find((t) => t === contentPart.type)) {\n const contentPartCopy = { ...contentPart };\n\n if (contentPartCopy.type === \"input_json_delta\") {\n // `input_json_delta` type only represents yielding partial tool inputs\n // and is not a valid type for Anthropic messages.\n // These blocks appear in streaming responses and should be skipped\n // as their input data is already captured in tool_calls.\n continue;\n }\n\n if (\n contentPartCopy.type === \"tool_use\" &&\n typeof contentPartCopy.input === \"string\"\n ) {\n // First, try to get the input from the corresponding tool_call.\n // This is the most reliable source since tool_calls are properly\n // consolidated from tool_call_chunks during streaming.\n const matchingToolCall = toolCalls?.find(\n (tc) => tc.id === contentPartCopy.id\n );\n if (matchingToolCall) {\n contentPartCopy.input = matchingToolCall.args;\n } else {\n // Fallback: `tool_use` content part may be followed by `input_json_delta`\n // content parts which are chunks of a stringified JSON input,\n // so we need to collect them and merge their inputs.\n const inputDeltas = content.filter(\n (nestedContentPart) =>\n nestedContentPart.index === contentPartCopy.index &&\n nestedContentPart.type === \"input_json_delta\" &&\n typeof nestedContentPart.input === \"string\"\n );\n // If no `input_json_delta` parts are found, this line will just\n // return `contentPartCopy.input`, so no additional check is needed\n contentPartCopy.input = inputDeltas.reduce(\n (accumulator, nestedContentPart) =>\n accumulator + nestedContentPart.input,\n contentPartCopy.input\n );\n }\n }\n\n if (\"index\" in contentPartCopy) {\n // Anthropic does not support passing the index field here, so we remove it.\n delete contentPartCopy.index;\n }\n\n if (\"input\" in contentPartCopy) {\n // Anthropic tool use inputs should be valid objects, when applicable.\n if (typeof contentPartCopy.input === \"string\") {\n try {\n contentPartCopy.input = JSON.parse(contentPartCopy.input);\n } catch {\n contentPartCopy.input = {};\n }\n }\n }\n // TODO: Fix when SDK types are fixed\n yield {\n ...contentPartCopy,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n } else if (contentPart.type === \"container_upload\") {\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as AnthropicContainerUploadBlockParam;\n }\n\n // Note that we are intentionally dropping any blocks that we don't\n // recognize. This is to allow for cross-compatibility between different\n // providers that may have different block types. Ie if we take a message\n // output from OpenAI and send it to Anthropic, we want to drop any blocks\n // that Anthropic doesn't understand.\n }\n}\n\nfunction _formatContent(message: BaseMessage, toolCalls?: ToolCall[]) {\n const { content } = message;\n\n if (typeof content === \"string\") {\n return content;\n } else {\n return Array.from(_formatContentBlocks(content, toolCalls));\n }\n}\n\n/**\n * Formats messages as a prompt for the model.\n * Used in LangSmith, export is important here.\n * @param messages The base messages to format as a prompt.\n * @returns The formatted prompt.\n */\nexport function _convertMessagesToAnthropicPayload(\n messages: BaseMessage[]\n): AnthropicMessageCreateParams {\n const mergedMessages = _ensureMessageContents(messages);\n let system;\n if (mergedMessages.length > 0 && mergedMessages[0]._getType() === \"system\") {\n system = messages[0].content;\n }\n const conversationMessages =\n system !== undefined ? mergedMessages.slice(1) : mergedMessages;\n const formattedMessages = conversationMessages.map((message) => {\n let role;\n if (message._getType() === \"human\") {\n role = \"user\" as const;\n } else if (message._getType() === \"ai\") {\n role = \"assistant\" as const;\n } else if (message._getType() === \"tool\") {\n role = \"user\" as const;\n } else if (message._getType() === \"system\") {\n throw new Error(\n \"System messages are only permitted as the first passed message.\"\n );\n } else {\n throw new Error(`Message type \"${message.type}\" is not supported.`);\n }\n if (\n AIMessage.isInstance(message) &&\n message.response_metadata?.output_version === \"v1\"\n ) {\n return {\n role,\n content: _formatStandardContent(message),\n };\n }\n if (AIMessage.isInstance(message) && !!message.tool_calls?.length) {\n if (typeof message.content === \"string\") {\n if (message.content === \"\") {\n return {\n role,\n content: message.tool_calls.map(\n _convertLangChainToolCallToAnthropic\n ),\n };\n } else {\n return {\n role,\n content: [\n { type: \"text\", text: message.content },\n ...message.tool_calls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else {\n const { content } = message;\n const formattedContent = _formatContent(message, message.tool_calls);\n const formattedContentArr = Array.isArray(formattedContent)\n ? formattedContent\n : [{ type: \"text\" as const, text: formattedContent }];\n const missingToolCalls = message.tool_calls.filter(\n (toolCall) =>\n !content.find(\n (contentPart) =>\n (contentPart.type === \"tool_use\" ||\n contentPart.type === \"input_json_delta\" ||\n contentPart.type === \"server_tool_use\") &&\n contentPart.id === toolCall.id\n )\n );\n return {\n role,\n content: [\n ...formattedContentArr,\n ...missingToolCalls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else {\n return {\n role,\n content: _formatContent(\n message,\n AIMessage.isInstance(message) ? message.tool_calls : undefined\n ),\n };\n }\n });\n return {\n messages: mergeMessages(\n formattedMessages as AnthropicMessageCreateParams[\"messages\"]\n ),\n system,\n } as AnthropicMessageCreateParams;\n}\n\n/**\n * Cache control configuration for Anthropic prompt caching.\n */\ninterface CacheControl {\n type: \"ephemeral\";\n ttl?: \"5m\" | \"1h\";\n}\n\n/**\n * Applies cache_control to the last content block of the last message in the payload.\n * This is the recommended approach for prompt caching as it applies the cache_control\n * at the final formatting layer, after all message processing is complete.\n *\n * This matches the Python langchain-anthropic implementation where cache_control\n * is applied via model_settings rather than modifying message content blocks directly.\n *\n * @param payload - The formatted Anthropic message payload\n * @param cacheControl - The cache control configuration to apply\n * @returns The payload with cache_control applied to the last content block\n */\nexport function applyCacheControlToPayload(\n payload: AnthropicMessageCreateParams,\n cacheControl: CacheControl\n): AnthropicMessageCreateParams {\n if (!payload.messages || payload.messages.length === 0) {\n return payload;\n }\n\n const messages = [...payload.messages];\n const lastMessageIndex = messages.length - 1;\n const lastMessage = messages[lastMessageIndex];\n\n if (!lastMessage) {\n return payload;\n }\n\n // Handle string content - convert to text block with cache_control\n if (typeof lastMessage.content === \"string\") {\n messages[lastMessageIndex] = {\n ...lastMessage,\n content: [\n {\n type: \"text\",\n text: lastMessage.content,\n cache_control: cacheControl,\n },\n ],\n };\n return { ...payload, messages };\n }\n\n // Handle array content - add cache_control to the last block\n if (Array.isArray(lastMessage.content) && lastMessage.content.length > 0) {\n const content = [...lastMessage.content];\n const lastBlockIndex = content.length - 1;\n const lastBlock = content[lastBlockIndex];\n\n // Add cache_control to the last block\n content[lastBlockIndex] = {\n ...lastBlock,\n cache_control: cacheControl,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n\n messages[lastMessageIndex] = {\n ...lastMessage,\n content,\n };\n return { ...payload, messages };\n }\n\n return payload;\n}\n\nfunction mergeMessages(messages: AnthropicMessageCreateParams[\"messages\"]) {\n if (!messages || messages.length <= 1) {\n return messages;\n }\n\n const result: AnthropicMessageCreateParams[\"messages\"] = [];\n let currentMessage = messages[0];\n\n const normalizeContent = (\n content:\n | string\n | Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n >\n ): Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n > => {\n if (typeof content === \"string\") {\n return [\n {\n type: \"text\",\n text: content,\n },\n ];\n }\n return content;\n };\n\n const isToolResultMessage = (msg: (typeof messages)[0]) => {\n if (msg.role !== \"user\") return false;\n\n if (typeof msg.content === \"string\") {\n return false;\n }\n\n return (\n Array.isArray(msg.content) &&\n msg.content.every((item) => item.type === \"tool_result\")\n );\n };\n\n for (let i = 1; i < messages.length; i += 1) {\n const nextMessage = messages[i];\n\n if (\n isToolResultMessage(currentMessage) &&\n isToolResultMessage(nextMessage)\n ) {\n // Merge the messages by combining their content arrays\n currentMessage = {\n ...currentMessage,\n content: [\n ...normalizeContent(currentMessage.content),\n ...normalizeContent(nextMessage.content),\n ],\n };\n } else {\n result.push(currentMessage);\n currentMessage = nextMessage;\n }\n }\n\n result.push(currentMessage);\n return result;\n}\n"],"mappings":";;;;;;AA0CA,SAAS,aAAa,UAAkB;CACtC,MAAM,0DAA4B,EAAE,SAAS,UAAU,CAAC;AACxD,KAAI,OACF,QAAO;EACL,MAAM;EACN,YAAY,OAAO;EACnB,MAAM,OAAO;EACd;CAEH,IAAI;AAEJ,KAAI;AACF,cAAY,IAAI,IAAI,SAAS;SACvB;AACN,QAAM,IAAI,MACR;GACE,wBAAwB,KAAK,UAC3B,SACD,CAAC;GACF;GACA;GACD,CAAC,KAAK,OAAO,CACf;;AAGH,KAAI,UAAU,aAAa,WAAW,UAAU,aAAa,SAC3D,QAAO;EACL,MAAM;EACN,KAAK;EACN;AAGH,OAAM,IAAI,MACR;EACE,+BAA+B,KAAK,UAClC,UAAU,SACX,CAAC;EACF;EACA;EACD,CAAC,KAAK,OAAO,CACf;;AAGH,SAAS,uBAAuB,UAAwC;CAEtE,MAAM,cAAc,EAAE;AACtB,MAAK,MAAM,WAAW,SACpB,KAAI,QAAQ,UAAU,KAAK,OACzB,KAAI,OAAO,QAAQ,YAAY,UAAU;EACvC,MAAM,kBAAkB,YAAY,YAAY,SAAS;AACzD,MACE,iBAAiB,UAAU,KAAK,WAChC,MAAM,QAAQ,gBAAgB,QAAQ,IACtC,UAAU,gBAAgB,QAAQ,MAClC,gBAAgB,QAAQ,GAAG,SAAS,cAGpC,CAAC,gBAAgB,QAAoC,KAAK;GACxD,MAAM;GACN,SAAS,QAAQ;GACjB,aAAc,QAAwB;GACvC,CAAC;MAGF,aAAY,KACV,IAAIA,sCAAa,EACf,SAAS,CAC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AO;GAAE,GAAG;GAAS;GAAU;;AAGjC,QAAO;;AAGT,SAAS,cAAc,UAAoD;AACzE,KAAI,CAAC,YAAY,SAAS,UAAU,EAClC,QAAO;CAGT,MAAM,SAAmD,EAAE;CAC3D,IAAI,iBAAiB,SAAS;CAE9B,MAAM,oBACJ,YAyBG;AACH,MAAI,OAAO,YAAY,SACrB,QAAO,CACL;GACE,MAAM;GACN,MAAM;GACP,CACF;AAEH,SAAO;;CAGT,MAAM,uBAAuB,QAA8B;AACzD,MAAI,IAAI,SAAS,OAAQ,QAAO;AAEhC,MAAI,OAAO,IAAI,YAAY,SACzB,QAAO;AAGT,SACE,MAAM,QAAQ,IAAI,QAAQ,IAC1B,IAAI,QAAQ,OAAO,SAAS,KAAK,SAAS,cAAc;;AAI5D,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK,GAAG;EAC3C,MAAM,cAAc,SAAS;AAE7B,MACE,oBAAoB,eAAe,IACnC,oBAAoB,YAAY,CAGhC,kBAAiB;GACf,GAAG;GACH,SAAS,CACP,GAAG,iBAAiB,eAAe,QAAQ,EAC3C,GAAG,iBAAiB,YAAY,QAAQ,CACzC;GACF;OACI;AACL,UAAO,KAAK,eAAe;AAC3B,oBAAiB;;;AAIrB,QAAO,KAAK,eAAe;AAC3B,QAAO"}
@@ -223,10 +223,15 @@ function _convertMessagesToAnthropicPayload(messages) {
223
223
  };
224
224
  else {
225
225
  const { content } = message;
226
- if (!message.tool_calls.every((toolCall) => content.find((contentPart) => (contentPart.type === "tool_use" || contentPart.type === "input_json_delta" || contentPart.type === "server_tool_use") && contentPart.id === toolCall.id))) console.warn(`The "tool_calls" field on a message is only respected if content is a string.`);
226
+ const formattedContent = _formatContent(message, message.tool_calls);
227
+ const formattedContentArr = Array.isArray(formattedContent) ? formattedContent : [{
228
+ type: "text",
229
+ text: formattedContent
230
+ }];
231
+ const missingToolCalls = message.tool_calls.filter((toolCall) => !content.find((contentPart) => (contentPart.type === "tool_use" || contentPart.type === "input_json_delta" || contentPart.type === "server_tool_use") && contentPart.id === toolCall.id));
227
232
  return {
228
233
  role,
229
- content: _formatContent(message, message.tool_calls)
234
+ content: [...formattedContentArr, ...missingToolCalls.map(_convertLangChainToolCallToAnthropic)]
230
235
  };
231
236
  }
232
237
  else return {