@librechat/agents 3.0.79 → 3.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/llm/bedrock/index.cjs +35 -74
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +35 -74
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/types/llm/bedrock/index.d.ts +7 -4
- package/package.json +2 -1
- package/src/llm/bedrock/index.ts +42 -96
- package/src/llm/bedrock/utils/message_outputs.ts +34 -20
- package/src/scripts/thinking-bedrock.ts +159 -0
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +0 -465
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +0 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +0 -238
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +0 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +0 -460
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +0 -1
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs +0 -231
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +0 -1
|
@@ -1,465 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var messages = require('@langchain/core/messages');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Utility functions for converting LangChain messages to Bedrock Converse messages.
|
|
7
|
-
* Ported from @langchain/aws common.js
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Convert a LangChain reasoning block to a Bedrock reasoning block.
|
|
11
|
-
*/
|
|
12
|
-
function langchainReasoningBlockToBedrockReasoningBlock(content) {
|
|
13
|
-
if (content.reasoningText != null) {
|
|
14
|
-
return {
|
|
15
|
-
reasoningText: content.reasoningText,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
if (content.redactedContent != null && content.redactedContent !== '') {
|
|
19
|
-
return {
|
|
20
|
-
redactedContent: new Uint8Array(Buffer.from(content.redactedContent, 'base64')),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
throw new Error('Invalid reasoning content');
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Concatenate consecutive reasoning blocks in content array.
|
|
27
|
-
*/
|
|
28
|
-
function concatenateLangchainReasoningBlocks(content) {
|
|
29
|
-
const result = [];
|
|
30
|
-
for (const block of content) {
|
|
31
|
-
if (block.type === 'reasoning_content') {
|
|
32
|
-
const currentReasoning = block;
|
|
33
|
-
const lastIndex = result.length - 1;
|
|
34
|
-
// Check if we can merge with the previous block
|
|
35
|
-
if (lastIndex >= 0) {
|
|
36
|
-
const lastBlock = result[lastIndex];
|
|
37
|
-
if (lastBlock.type === 'reasoning_content' &&
|
|
38
|
-
lastBlock.reasoningText != null &&
|
|
39
|
-
currentReasoning.reasoningText != null) {
|
|
40
|
-
const lastReasoning = lastBlock;
|
|
41
|
-
// Merge consecutive reasoning text blocks
|
|
42
|
-
const lastText = lastReasoning.reasoningText?.text;
|
|
43
|
-
const currentText = currentReasoning.reasoningText.text;
|
|
44
|
-
if (lastText != null &&
|
|
45
|
-
lastText !== '' &&
|
|
46
|
-
currentText != null &&
|
|
47
|
-
currentText !== '') {
|
|
48
|
-
lastReasoning.reasoningText.text = lastText + currentText;
|
|
49
|
-
}
|
|
50
|
-
else if (currentReasoning.reasoningText.signature != null &&
|
|
51
|
-
currentReasoning.reasoningText.signature !== '') {
|
|
52
|
-
lastReasoning.reasoningText.signature =
|
|
53
|
-
currentReasoning.reasoningText.signature;
|
|
54
|
-
}
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
result.push({ ...block });
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
result.push(block);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Extract image info from a base64 string or URL.
|
|
68
|
-
*/
|
|
69
|
-
function extractImageInfo(base64) {
|
|
70
|
-
// Extract the format from the base64 string
|
|
71
|
-
const formatMatch = base64.match(/^data:image\/(\w+);base64,/);
|
|
72
|
-
let format;
|
|
73
|
-
if (formatMatch) {
|
|
74
|
-
const extractedFormat = formatMatch[1].toLowerCase();
|
|
75
|
-
if (['gif', 'jpeg', 'png', 'webp'].includes(extractedFormat)) {
|
|
76
|
-
format = extractedFormat;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Remove the data URL prefix if present
|
|
80
|
-
const base64Data = base64.replace(/^data:image\/\w+;base64,/, '');
|
|
81
|
-
// Convert base64 to Uint8Array
|
|
82
|
-
const binaryString = atob(base64Data);
|
|
83
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
84
|
-
for (let i = 0; i < binaryString.length; i += 1) {
|
|
85
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
image: {
|
|
89
|
-
format,
|
|
90
|
-
source: {
|
|
91
|
-
bytes,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Check if a block has a cache point.
|
|
98
|
-
*/
|
|
99
|
-
function isDefaultCachePoint(block) {
|
|
100
|
-
if (typeof block !== 'object' || block === null) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
if (!('cachePoint' in block)) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
const cachePoint = block.cachePoint;
|
|
107
|
-
if (typeof cachePoint !== 'object' || cachePoint === null) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
if (!('type' in cachePoint)) {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
return cachePoint.type === 'default';
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Convert a LangChain content block to a Bedrock Converse content block.
|
|
117
|
-
*/
|
|
118
|
-
function convertLangChainContentBlockToConverseContentBlock({ block, onUnknown = 'throw', }) {
|
|
119
|
-
if (typeof block === 'string') {
|
|
120
|
-
return { text: block };
|
|
121
|
-
}
|
|
122
|
-
if (block.type === 'text') {
|
|
123
|
-
return { text: block.text };
|
|
124
|
-
}
|
|
125
|
-
if (block.type === 'image_url') {
|
|
126
|
-
const imageUrl = typeof block.image_url ===
|
|
127
|
-
'string'
|
|
128
|
-
? block.image_url
|
|
129
|
-
: block.image_url.url;
|
|
130
|
-
return extractImageInfo(imageUrl);
|
|
131
|
-
}
|
|
132
|
-
if (block.type === 'image') {
|
|
133
|
-
// Handle standard image block format
|
|
134
|
-
const imageBlock = block;
|
|
135
|
-
if (imageBlock.source_type === 'url' &&
|
|
136
|
-
imageBlock.url != null &&
|
|
137
|
-
imageBlock.url !== '') {
|
|
138
|
-
const parsedData = messages.parseBase64DataUrl({
|
|
139
|
-
dataUrl: imageBlock.url,
|
|
140
|
-
asTypedArray: true,
|
|
141
|
-
});
|
|
142
|
-
if (parsedData != null) {
|
|
143
|
-
const parsedMimeType = messages.parseMimeType(parsedData.mime_type);
|
|
144
|
-
return {
|
|
145
|
-
image: {
|
|
146
|
-
format: parsedMimeType.subtype,
|
|
147
|
-
source: {
|
|
148
|
-
bytes: parsedData.data,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else if (imageBlock.source_type === 'base64' &&
|
|
155
|
-
imageBlock.data != null &&
|
|
156
|
-
imageBlock.data !== '') {
|
|
157
|
-
let format;
|
|
158
|
-
if (imageBlock.mime_type != null && imageBlock.mime_type !== '') {
|
|
159
|
-
const parsedMimeType = messages.parseMimeType(imageBlock.mime_type);
|
|
160
|
-
format = parsedMimeType.subtype;
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
image: {
|
|
164
|
-
format,
|
|
165
|
-
source: {
|
|
166
|
-
bytes: Uint8Array.from(atob(imageBlock.data), (c) => c.charCodeAt(0)),
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
// If it already has the Bedrock image structure, pass through
|
|
172
|
-
if (block.image !== undefined) {
|
|
173
|
-
return {
|
|
174
|
-
image: block.image,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (block.type === 'document' &&
|
|
179
|
-
block.document !== undefined) {
|
|
180
|
-
return {
|
|
181
|
-
document: block.document,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
if (isDefaultCachePoint(block)) {
|
|
185
|
-
return {
|
|
186
|
-
cachePoint: {
|
|
187
|
-
type: 'default',
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
if (onUnknown === 'throw') {
|
|
192
|
-
throw new Error(`Unsupported content block type: ${block.type}`);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
return block;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Convert a system message to Bedrock system content blocks.
|
|
200
|
-
*/
|
|
201
|
-
function convertSystemMessageToConverseMessage(msg) {
|
|
202
|
-
if (typeof msg.content === 'string') {
|
|
203
|
-
return [{ text: msg.content }];
|
|
204
|
-
}
|
|
205
|
-
else if (Array.isArray(msg.content) && msg.content.length > 0) {
|
|
206
|
-
const contentBlocks = [];
|
|
207
|
-
for (const block of msg.content) {
|
|
208
|
-
if (typeof block === 'object' &&
|
|
209
|
-
block.type === 'text' &&
|
|
210
|
-
typeof block.text === 'string') {
|
|
211
|
-
contentBlocks.push({
|
|
212
|
-
text: block.text,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
else if (isDefaultCachePoint(block)) {
|
|
216
|
-
contentBlocks.push({
|
|
217
|
-
cachePoint: {
|
|
218
|
-
type: 'default',
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (msg.content.length === contentBlocks.length) {
|
|
227
|
-
return contentBlocks;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
throw new Error('System message content must be either a string, or an array of text blocks, optionally including a cache point.');
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Convert an AI message to a Bedrock message.
|
|
234
|
-
*/
|
|
235
|
-
function convertAIMessageToConverseMessage(msg) {
|
|
236
|
-
// Check for v1 format from other providers (PR #9766 fix)
|
|
237
|
-
if (msg.response_metadata.output_version === 'v1') {
|
|
238
|
-
return convertFromV1ToChatBedrockConverseMessage(msg);
|
|
239
|
-
}
|
|
240
|
-
const assistantMsg = {
|
|
241
|
-
role: 'assistant',
|
|
242
|
-
content: [],
|
|
243
|
-
};
|
|
244
|
-
if (typeof msg.content === 'string' && msg.content !== '') {
|
|
245
|
-
assistantMsg.content?.push({ text: msg.content });
|
|
246
|
-
}
|
|
247
|
-
else if (Array.isArray(msg.content)) {
|
|
248
|
-
const concatenatedBlocks = concatenateLangchainReasoningBlocks(msg.content);
|
|
249
|
-
const contentBlocks = [];
|
|
250
|
-
concatenatedBlocks.forEach((block) => {
|
|
251
|
-
if (block.type === 'text' && block.text !== '') {
|
|
252
|
-
// Merge whitespace/newlines with previous text blocks to avoid validation errors.
|
|
253
|
-
const text = block.text;
|
|
254
|
-
const cleanedText = text.replace(/\n/g, '').trim();
|
|
255
|
-
if (cleanedText === '') {
|
|
256
|
-
if (contentBlocks.length > 0) {
|
|
257
|
-
const lastBlock = contentBlocks[contentBlocks.length - 1];
|
|
258
|
-
if ('text' in lastBlock) {
|
|
259
|
-
const mergedTextContent = `${lastBlock.text}${text}`;
|
|
260
|
-
lastBlock.text = mergedTextContent;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
contentBlocks.push({ text });
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
else if (block.type === 'reasoning_content') {
|
|
269
|
-
contentBlocks.push({
|
|
270
|
-
reasoningContent: langchainReasoningBlockToBedrockReasoningBlock(block),
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
else if (isDefaultCachePoint(block)) {
|
|
274
|
-
contentBlocks.push({
|
|
275
|
-
cachePoint: {
|
|
276
|
-
type: 'default',
|
|
277
|
-
},
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
const blockValues = Object.fromEntries(Object.entries(block).filter(([key]) => key !== 'type'));
|
|
282
|
-
throw new Error(`Unsupported content block type: ${block.type} with content of ${JSON.stringify(blockValues, null, 2)}`);
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
assistantMsg.content = [...(assistantMsg.content ?? []), ...contentBlocks];
|
|
286
|
-
}
|
|
287
|
-
// Important: this must be placed after any reasoning content blocks
|
|
288
|
-
if (messages.isAIMessage(msg) && msg.tool_calls != null && msg.tool_calls.length > 0) {
|
|
289
|
-
const toolUseBlocks = msg.tool_calls.map((tc) => ({
|
|
290
|
-
toolUse: {
|
|
291
|
-
toolUseId: tc.id,
|
|
292
|
-
name: tc.name,
|
|
293
|
-
input: tc.args,
|
|
294
|
-
},
|
|
295
|
-
}));
|
|
296
|
-
assistantMsg.content = [
|
|
297
|
-
...(assistantMsg.content ?? []),
|
|
298
|
-
...toolUseBlocks,
|
|
299
|
-
];
|
|
300
|
-
}
|
|
301
|
-
return assistantMsg;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Convert a v1 format message from other providers to Bedrock format.
|
|
305
|
-
* This handles messages with standard content blocks like tool_call and reasoning.
|
|
306
|
-
* (Implements PR #9766 fix for output_version v1 detection)
|
|
307
|
-
*/
|
|
308
|
-
function convertFromV1ToChatBedrockConverseMessage(msg) {
|
|
309
|
-
const assistantMsg = {
|
|
310
|
-
role: 'assistant',
|
|
311
|
-
content: [],
|
|
312
|
-
};
|
|
313
|
-
if (Array.isArray(msg.content)) {
|
|
314
|
-
for (const block of msg.content) {
|
|
315
|
-
if (typeof block === 'string') {
|
|
316
|
-
assistantMsg.content?.push({ text: block });
|
|
317
|
-
}
|
|
318
|
-
else if (block.type === 'text') {
|
|
319
|
-
assistantMsg.content?.push({ text: block.text });
|
|
320
|
-
}
|
|
321
|
-
else if (block.type === 'tool_call') {
|
|
322
|
-
const toolCall = block;
|
|
323
|
-
assistantMsg.content?.push({
|
|
324
|
-
toolUse: {
|
|
325
|
-
toolUseId: toolCall.id,
|
|
326
|
-
name: toolCall.name,
|
|
327
|
-
input: toolCall.args,
|
|
328
|
-
},
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
else if (block.type === 'reasoning') {
|
|
332
|
-
const reasoning = block;
|
|
333
|
-
assistantMsg.content?.push({
|
|
334
|
-
reasoningContent: {
|
|
335
|
-
reasoningText: { text: reasoning.reasoning },
|
|
336
|
-
},
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
else if (block.type === 'reasoning_content') {
|
|
340
|
-
assistantMsg.content?.push({
|
|
341
|
-
reasoningContent: langchainReasoningBlockToBedrockReasoningBlock(block),
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
else if (typeof msg.content === 'string' && msg.content !== '') {
|
|
347
|
-
assistantMsg.content?.push({ text: msg.content });
|
|
348
|
-
}
|
|
349
|
-
// Also handle tool_calls from the message
|
|
350
|
-
if (messages.isAIMessage(msg) && msg.tool_calls != null && msg.tool_calls.length > 0) {
|
|
351
|
-
// Check if tool calls are already in content
|
|
352
|
-
const existingToolUseIds = new Set(assistantMsg.content
|
|
353
|
-
?.filter((c) => 'toolUse' in c)
|
|
354
|
-
.map((c) => c.toolUse.toolUseId) ?? []);
|
|
355
|
-
for (const tc of msg.tool_calls) {
|
|
356
|
-
if (!existingToolUseIds.has(tc.id ?? '')) {
|
|
357
|
-
assistantMsg.content?.push({
|
|
358
|
-
toolUse: {
|
|
359
|
-
toolUseId: tc.id,
|
|
360
|
-
name: tc.name,
|
|
361
|
-
input: tc.args,
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return assistantMsg;
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Convert a human message to a Bedrock message.
|
|
371
|
-
*/
|
|
372
|
-
function convertHumanMessageToConverseMessage(msg) {
|
|
373
|
-
const userMessage = {
|
|
374
|
-
role: 'user',
|
|
375
|
-
content: [],
|
|
376
|
-
};
|
|
377
|
-
if (typeof msg.content === 'string') {
|
|
378
|
-
userMessage.content = [{ text: msg.content }];
|
|
379
|
-
}
|
|
380
|
-
else if (Array.isArray(msg.content)) {
|
|
381
|
-
userMessage.content = msg.content.map((block) => convertLangChainContentBlockToConverseContentBlock({ block }));
|
|
382
|
-
}
|
|
383
|
-
return userMessage;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Convert a tool message to a Bedrock message.
|
|
387
|
-
*/
|
|
388
|
-
function convertToolMessageToConverseMessage(msg) {
|
|
389
|
-
const toolCallId = msg.tool_call_id;
|
|
390
|
-
let content;
|
|
391
|
-
if (typeof msg.content === 'string') {
|
|
392
|
-
content = [{ text: msg.content }];
|
|
393
|
-
}
|
|
394
|
-
else if (Array.isArray(msg.content)) {
|
|
395
|
-
content = msg.content.map((block) => convertLangChainContentBlockToConverseContentBlock({
|
|
396
|
-
block,
|
|
397
|
-
onUnknown: 'passthrough',
|
|
398
|
-
}));
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
content = [{ text: String(msg.content) }];
|
|
402
|
-
}
|
|
403
|
-
return {
|
|
404
|
-
role: 'user',
|
|
405
|
-
content: [
|
|
406
|
-
{
|
|
407
|
-
toolResult: {
|
|
408
|
-
toolUseId: toolCallId,
|
|
409
|
-
content: content,
|
|
410
|
-
},
|
|
411
|
-
},
|
|
412
|
-
],
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Convert LangChain messages to Bedrock Converse messages.
|
|
417
|
-
*/
|
|
418
|
-
function convertToConverseMessages(messages) {
|
|
419
|
-
const converseSystem = messages
|
|
420
|
-
.filter((msg) => msg._getType() === 'system')
|
|
421
|
-
.flatMap((msg) => convertSystemMessageToConverseMessage(msg));
|
|
422
|
-
const converseMessages = messages
|
|
423
|
-
.filter((msg) => msg._getType() !== 'system')
|
|
424
|
-
.map((msg) => {
|
|
425
|
-
if (msg._getType() === 'ai') {
|
|
426
|
-
return convertAIMessageToConverseMessage(msg);
|
|
427
|
-
}
|
|
428
|
-
else if (msg._getType() === 'human' || msg._getType() === 'generic') {
|
|
429
|
-
return convertHumanMessageToConverseMessage(msg);
|
|
430
|
-
}
|
|
431
|
-
else if (msg._getType() === 'tool') {
|
|
432
|
-
return convertToolMessageToConverseMessage(msg);
|
|
433
|
-
}
|
|
434
|
-
else {
|
|
435
|
-
throw new Error(`Unsupported message type: ${msg._getType()}`);
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
// Combine consecutive user tool result messages into a single message
|
|
439
|
-
const combinedConverseMessages = converseMessages.reduce((acc, curr) => {
|
|
440
|
-
const lastMessage = acc[acc.length - 1];
|
|
441
|
-
if (lastMessage == null) {
|
|
442
|
-
acc.push(curr);
|
|
443
|
-
return acc;
|
|
444
|
-
}
|
|
445
|
-
const lastHasToolResult = lastMessage.content?.some((c) => 'toolResult' in c) === true;
|
|
446
|
-
const currHasToolResult = curr.content?.some((c) => 'toolResult' in c) === true;
|
|
447
|
-
if (lastMessage.role === 'user' &&
|
|
448
|
-
lastHasToolResult &&
|
|
449
|
-
curr.role === 'user' &&
|
|
450
|
-
currHasToolResult) {
|
|
451
|
-
lastMessage.content = lastMessage.content?.concat(curr.content ?? []);
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
acc.push(curr);
|
|
455
|
-
}
|
|
456
|
-
return acc;
|
|
457
|
-
}, []);
|
|
458
|
-
return { converseMessages: combinedConverseMessages, converseSystem };
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
exports.concatenateLangchainReasoningBlocks = concatenateLangchainReasoningBlocks;
|
|
462
|
-
exports.convertToConverseMessages = convertToConverseMessages;
|
|
463
|
-
exports.extractImageInfo = extractImageInfo;
|
|
464
|
-
exports.langchainReasoningBlockToBedrockReasoningBlock = langchainReasoningBlockToBedrockReasoningBlock;
|
|
465
|
-
//# sourceMappingURL=message_inputs.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message_inputs.cjs","sources":["../../../../../src/llm/bedrock/utils/message_inputs.ts"],"sourcesContent":["/**\n * Utility functions for converting LangChain messages to Bedrock Converse messages.\n * Ported from @langchain/aws common.js\n */\nimport {\n type BaseMessage,\n isAIMessage,\n parseBase64DataUrl,\n parseMimeType,\n MessageContentComplex,\n} from '@langchain/core/messages';\nimport type {\n BedrockMessage,\n BedrockSystemContentBlock,\n BedrockContentBlock,\n MessageContentReasoningBlock,\n} from '../types';\n\n/**\n * Convert a LangChain reasoning block to a Bedrock reasoning block.\n */\nexport function langchainReasoningBlockToBedrockReasoningBlock(\n content: MessageContentReasoningBlock\n): {\n reasoningText?: { text?: string; signature?: string };\n redactedContent?: Uint8Array;\n} {\n if (content.reasoningText != null) {\n return {\n reasoningText: content.reasoningText,\n };\n }\n if (content.redactedContent != null && content.redactedContent !== '') {\n return {\n redactedContent: new Uint8Array(\n Buffer.from(content.redactedContent, 'base64')\n ),\n };\n }\n throw new Error('Invalid reasoning content');\n}\n\n/**\n * Concatenate consecutive reasoning blocks in content array.\n */\nexport function concatenateLangchainReasoningBlocks(\n content: Array<MessageContentComplex | MessageContentReasoningBlock>\n): Array<MessageContentComplex | MessageContentReasoningBlock> {\n const result: Array<MessageContentComplex | MessageContentReasoningBlock> =\n [];\n\n for (const block of content) {\n if (block.type === 'reasoning_content') {\n const currentReasoning = block as MessageContentReasoningBlock;\n const lastIndex = result.length - 1;\n\n // Check if we can merge with the previous block\n if (lastIndex >= 0) {\n const lastBlock = result[lastIndex];\n if (\n lastBlock.type === 'reasoning_content' &&\n (lastBlock as MessageContentReasoningBlock).reasoningText != null &&\n currentReasoning.reasoningText != null\n ) {\n const lastReasoning = lastBlock as MessageContentReasoningBlock;\n // Merge consecutive reasoning text blocks\n const lastText = lastReasoning.reasoningText?.text;\n const currentText = currentReasoning.reasoningText.text;\n if (\n lastText != null &&\n lastText !== '' &&\n currentText != null &&\n currentText !== ''\n ) {\n lastReasoning.reasoningText!.text = lastText + currentText;\n } else if (\n currentReasoning.reasoningText.signature != null &&\n currentReasoning.reasoningText.signature !== ''\n ) {\n lastReasoning.reasoningText!.signature =\n currentReasoning.reasoningText.signature;\n }\n continue;\n }\n }\n\n result.push({ ...block } as MessageContentReasoningBlock);\n } else {\n result.push(block);\n }\n }\n\n return result;\n}\n\n/**\n * Extract image info from a base64 string or URL.\n */\nexport function extractImageInfo(base64: string): BedrockContentBlock {\n // Extract the format from the base64 string\n const formatMatch = base64.match(/^data:image\\/(\\w+);base64,/);\n let format: 'gif' | 'jpeg' | 'png' | 'webp' | undefined;\n if (formatMatch) {\n const extractedFormat = formatMatch[1].toLowerCase();\n if (['gif', 'jpeg', 'png', 'webp'].includes(extractedFormat)) {\n format = extractedFormat as typeof format;\n }\n }\n\n // Remove the data URL prefix if present\n const base64Data = base64.replace(/^data:image\\/\\w+;base64,/, '');\n\n // Convert base64 to Uint8Array\n const binaryString = atob(base64Data);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i += 1) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n\n return {\n image: {\n format,\n source: {\n bytes,\n },\n },\n };\n}\n\n/**\n * Check if a block has a cache point.\n */\nfunction isDefaultCachePoint(block: unknown): boolean {\n if (typeof block !== 'object' || block === null) {\n return false;\n }\n if (!('cachePoint' in block)) {\n return false;\n }\n const cachePoint = (block as { cachePoint?: unknown }).cachePoint;\n if (typeof cachePoint !== 'object' || cachePoint === null) {\n return false;\n }\n if (!('type' in cachePoint)) {\n return false;\n }\n return (cachePoint as { type?: string }).type === 'default';\n}\n\n/**\n * Convert a LangChain content block to a Bedrock Converse content block.\n */\nfunction convertLangChainContentBlockToConverseContentBlock({\n block,\n onUnknown = 'throw',\n}: {\n block: string | MessageContentComplex;\n onUnknown?: 'throw' | 'passthrough';\n}): BedrockContentBlock {\n if (typeof block === 'string') {\n return { text: block };\n }\n\n if (block.type === 'text') {\n return { text: (block as { text: string }).text };\n }\n\n if (block.type === 'image_url') {\n const imageUrl =\n typeof (block as { image_url: string | { url: string } }).image_url ===\n 'string'\n ? (block as { image_url: string }).image_url\n : (block as { image_url: { url: string } }).image_url.url;\n return extractImageInfo(imageUrl);\n }\n\n if (block.type === 'image') {\n // Handle standard image block format\n const imageBlock = block as {\n source_type?: string;\n url?: string;\n data?: string;\n mime_type?: string;\n };\n if (\n imageBlock.source_type === 'url' &&\n imageBlock.url != null &&\n imageBlock.url !== ''\n ) {\n const parsedData = parseBase64DataUrl({\n dataUrl: imageBlock.url,\n asTypedArray: true,\n });\n if (parsedData != null) {\n const parsedMimeType = parseMimeType(parsedData.mime_type);\n return {\n image: {\n format: parsedMimeType.subtype as 'gif' | 'jpeg' | 'png' | 'webp',\n source: {\n bytes: parsedData.data as Uint8Array,\n },\n },\n };\n }\n } else if (\n imageBlock.source_type === 'base64' &&\n imageBlock.data != null &&\n imageBlock.data !== ''\n ) {\n let format: 'gif' | 'jpeg' | 'png' | 'webp' | undefined;\n if (imageBlock.mime_type != null && imageBlock.mime_type !== '') {\n const parsedMimeType = parseMimeType(imageBlock.mime_type);\n format = parsedMimeType.subtype as typeof format;\n }\n return {\n image: {\n format,\n source: {\n bytes: Uint8Array.from(atob(imageBlock.data), (c) =>\n c.charCodeAt(0)\n ),\n },\n },\n };\n }\n // If it already has the Bedrock image structure, pass through\n if ((block as { image?: unknown }).image !== undefined) {\n return {\n image: (block as { image: unknown }).image,\n } as BedrockContentBlock;\n }\n }\n\n if (\n block.type === 'document' &&\n (block as { document?: unknown }).document !== undefined\n ) {\n return {\n document: (block as { document: unknown }).document,\n } as BedrockContentBlock;\n }\n\n if (isDefaultCachePoint(block)) {\n return {\n cachePoint: {\n type: 'default',\n },\n } as BedrockContentBlock;\n }\n\n if (onUnknown === 'throw') {\n throw new Error(`Unsupported content block type: ${block.type}`);\n } else {\n return block as unknown as BedrockContentBlock;\n }\n}\n\n/**\n * Convert a system message to Bedrock system content blocks.\n */\nfunction convertSystemMessageToConverseMessage(\n msg: BaseMessage\n): BedrockSystemContentBlock[] {\n if (typeof msg.content === 'string') {\n return [{ text: msg.content }];\n } else if (Array.isArray(msg.content) && msg.content.length > 0) {\n const contentBlocks: BedrockSystemContentBlock[] = [];\n for (const block of msg.content) {\n if (\n typeof block === 'object' &&\n block.type === 'text' &&\n typeof (block as { text?: string }).text === 'string'\n ) {\n contentBlocks.push({\n text: (block as { text: string }).text,\n });\n } else if (isDefaultCachePoint(block)) {\n contentBlocks.push({\n cachePoint: {\n type: 'default',\n },\n } as BedrockSystemContentBlock);\n } else {\n break;\n }\n }\n if (msg.content.length === contentBlocks.length) {\n return contentBlocks;\n }\n }\n throw new Error(\n 'System message content must be either a string, or an array of text blocks, optionally including a cache point.'\n );\n}\n\n/**\n * Convert an AI message to a Bedrock message.\n */\nfunction convertAIMessageToConverseMessage(msg: BaseMessage): BedrockMessage {\n // Check for v1 format from other providers (PR #9766 fix)\n if (msg.response_metadata.output_version === 'v1') {\n return convertFromV1ToChatBedrockConverseMessage(msg);\n }\n\n const assistantMsg: BedrockMessage = {\n role: 'assistant',\n content: [],\n };\n\n if (typeof msg.content === 'string' && msg.content !== '') {\n assistantMsg.content?.push({ text: msg.content });\n } else if (Array.isArray(msg.content)) {\n const concatenatedBlocks = concatenateLangchainReasoningBlocks(\n msg.content as Array<MessageContentComplex | MessageContentReasoningBlock>\n );\n const contentBlocks: BedrockContentBlock[] = [];\n\n concatenatedBlocks.forEach((block) => {\n if (block.type === 'text' && (block as { text?: string }).text !== '') {\n // Merge whitespace/newlines with previous text blocks to avoid validation errors.\n const text = (block as { text: string }).text;\n const cleanedText = text.replace(/\\n/g, '').trim();\n if (cleanedText === '') {\n if (contentBlocks.length > 0) {\n const lastBlock = contentBlocks[contentBlocks.length - 1];\n if ('text' in lastBlock) {\n const mergedTextContent = `${lastBlock.text}${text}`;\n (lastBlock as { text: string }).text = mergedTextContent;\n }\n }\n } else {\n contentBlocks.push({ text });\n }\n } else if (block.type === 'reasoning_content') {\n contentBlocks.push({\n reasoningContent: langchainReasoningBlockToBedrockReasoningBlock(\n block as MessageContentReasoningBlock\n ),\n } as BedrockContentBlock);\n } else if (isDefaultCachePoint(block)) {\n contentBlocks.push({\n cachePoint: {\n type: 'default',\n },\n } as BedrockContentBlock);\n } else {\n const blockValues = Object.fromEntries(\n Object.entries(block).filter(([key]) => key !== 'type')\n );\n throw new Error(\n `Unsupported content block type: ${block.type} with content of ${JSON.stringify(blockValues, null, 2)}`\n );\n }\n });\n\n assistantMsg.content = [...(assistantMsg.content ?? []), ...contentBlocks];\n }\n\n // Important: this must be placed after any reasoning content blocks\n if (isAIMessage(msg) && msg.tool_calls != null && msg.tool_calls.length > 0) {\n const toolUseBlocks = msg.tool_calls.map((tc) => ({\n toolUse: {\n toolUseId: tc.id,\n name: tc.name,\n input: tc.args as Record<string, unknown>,\n },\n }));\n assistantMsg.content = [\n ...(assistantMsg.content ?? []),\n ...toolUseBlocks,\n ] as BedrockContentBlock[];\n }\n\n return assistantMsg;\n}\n\n/**\n * Convert a v1 format message from other providers to Bedrock format.\n * This handles messages with standard content blocks like tool_call and reasoning.\n * (Implements PR #9766 fix for output_version v1 detection)\n */\nfunction convertFromV1ToChatBedrockConverseMessage(\n msg: BaseMessage\n): BedrockMessage {\n const assistantMsg: BedrockMessage = {\n role: 'assistant',\n content: [],\n };\n\n if (Array.isArray(msg.content)) {\n for (const block of msg.content) {\n if (typeof block === 'string') {\n assistantMsg.content?.push({ text: block });\n } else if (block.type === 'text') {\n assistantMsg.content?.push({ text: (block as { text: string }).text });\n } else if (block.type === 'tool_call') {\n const toolCall = block as {\n id: string;\n name: string;\n args: Record<string, unknown>;\n };\n assistantMsg.content?.push({\n toolUse: {\n toolUseId: toolCall.id,\n name: toolCall.name,\n input: toolCall.args as Record<string, unknown>,\n },\n } as BedrockContentBlock);\n } else if (block.type === 'reasoning') {\n const reasoning = block as { reasoning: string };\n assistantMsg.content?.push({\n reasoningContent: {\n reasoningText: { text: reasoning.reasoning },\n },\n } as BedrockContentBlock);\n } else if (block.type === 'reasoning_content') {\n assistantMsg.content?.push({\n reasoningContent: langchainReasoningBlockToBedrockReasoningBlock(\n block as MessageContentReasoningBlock\n ),\n } as BedrockContentBlock);\n }\n }\n } else if (typeof msg.content === 'string' && msg.content !== '') {\n assistantMsg.content?.push({ text: msg.content });\n }\n\n // Also handle tool_calls from the message\n if (isAIMessage(msg) && msg.tool_calls != null && msg.tool_calls.length > 0) {\n // Check if tool calls are already in content\n const existingToolUseIds = new Set(\n assistantMsg.content\n ?.filter((c) => 'toolUse' in c)\n .map(\n (c) => (c as { toolUse: { toolUseId: string } }).toolUse.toolUseId\n ) ?? []\n );\n\n for (const tc of msg.tool_calls) {\n if (!existingToolUseIds.has(tc.id ?? '')) {\n assistantMsg.content?.push({\n toolUse: {\n toolUseId: tc.id,\n name: tc.name,\n input: tc.args as Record<string, unknown>,\n },\n } as BedrockContentBlock);\n }\n }\n }\n\n return assistantMsg;\n}\n\n/**\n * Convert a human message to a Bedrock message.\n */\nfunction convertHumanMessageToConverseMessage(\n msg: BaseMessage\n): BedrockMessage {\n const userMessage: BedrockMessage = {\n role: 'user',\n content: [],\n };\n\n if (typeof msg.content === 'string') {\n userMessage.content = [{ text: msg.content }];\n } else if (Array.isArray(msg.content)) {\n userMessage.content = msg.content.map((block) =>\n convertLangChainContentBlockToConverseContentBlock({ block })\n );\n }\n\n return userMessage;\n}\n\n/**\n * Convert a tool message to a Bedrock message.\n */\nfunction convertToolMessageToConverseMessage(msg: BaseMessage): BedrockMessage {\n const toolCallId = (msg as { tool_call_id?: string }).tool_call_id;\n\n let content: BedrockContentBlock[];\n if (typeof msg.content === 'string') {\n content = [{ text: msg.content }];\n } else if (Array.isArray(msg.content)) {\n content = msg.content.map((block) =>\n convertLangChainContentBlockToConverseContentBlock({\n block,\n onUnknown: 'passthrough',\n })\n );\n } else {\n content = [{ text: String(msg.content) }];\n }\n\n return {\n role: 'user',\n content: [\n {\n toolResult: {\n toolUseId: toolCallId,\n content: content as { text: string }[],\n },\n },\n ],\n };\n}\n\n/**\n * Convert LangChain messages to Bedrock Converse messages.\n */\nexport function convertToConverseMessages(messages: BaseMessage[]): {\n converseMessages: BedrockMessage[];\n converseSystem: BedrockSystemContentBlock[];\n} {\n const converseSystem = messages\n .filter((msg) => msg._getType() === 'system')\n .flatMap((msg) => convertSystemMessageToConverseMessage(msg));\n\n const converseMessages = messages\n .filter((msg) => msg._getType() !== 'system')\n .map((msg) => {\n if (msg._getType() === 'ai') {\n return convertAIMessageToConverseMessage(msg);\n } else if (msg._getType() === 'human' || msg._getType() === 'generic') {\n return convertHumanMessageToConverseMessage(msg);\n } else if (msg._getType() === 'tool') {\n return convertToolMessageToConverseMessage(msg);\n } else {\n throw new Error(`Unsupported message type: ${msg._getType()}`);\n }\n });\n\n // Combine consecutive user tool result messages into a single message\n const combinedConverseMessages = converseMessages.reduce<BedrockMessage[]>(\n (acc, curr) => {\n const lastMessage = acc[acc.length - 1];\n if (lastMessage == null) {\n acc.push(curr);\n return acc;\n }\n const lastHasToolResult =\n lastMessage.content?.some((c) => 'toolResult' in c) === true;\n const currHasToolResult =\n curr.content?.some((c) => 'toolResult' in c) === true;\n if (\n lastMessage.role === 'user' &&\n lastHasToolResult &&\n curr.role === 'user' &&\n currHasToolResult\n ) {\n lastMessage.content = lastMessage.content?.concat(curr.content ?? []);\n } else {\n acc.push(curr);\n }\n return acc;\n },\n []\n );\n\n return { converseMessages: combinedConverseMessages, converseSystem };\n}\n"],"names":["parseBase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