@langchain/core 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/language_models/base.cjs +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/messages/block_translators/bedrock_converse.cjs +15 -1
- package/dist/messages/block_translators/bedrock_converse.cjs.map +1 -1
- package/dist/messages/block_translators/bedrock_converse.js +15 -1
- package/dist/messages/block_translators/bedrock_converse.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @langchain/core
|
|
2
2
|
|
|
3
|
+
## 1.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#11200](https://github.com/langchain-ai/langchainjs/pull/11200) [`08e5888`](https://github.com/langchain-ai/langchainjs/commit/08e588865927c3bf0eb2ec418cfb3fba527e14bb) Thanks [@hntrl](https://github.com/hntrl)! - fix(aws): normalize and safely replay Bedrock reasoning blocks
|
|
8
|
+
|
|
9
|
+
Emit standard reasoning blocks with preserved signatures, omit incomplete signature-only reasoning during replay, and retain compatibility with legacy and redacted Bedrock reasoning.
|
|
10
|
+
|
|
3
11
|
## 1.2.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -139,7 +139,7 @@ var BaseLangChain = class extends require_base.Runnable {
|
|
|
139
139
|
this.callbacks = params.callbacks;
|
|
140
140
|
this.tags = params.tags ?? [];
|
|
141
141
|
this.metadata = params.metadata ?? {};
|
|
142
|
-
this._addVersion("@langchain/core", "1.2.
|
|
142
|
+
this._addVersion("@langchain/core", "1.2.3");
|
|
143
143
|
}
|
|
144
144
|
_addVersion(pkg, version) {
|
|
145
145
|
const existing = this.metadata?.versions;
|
|
@@ -138,7 +138,7 @@ var BaseLangChain = class extends Runnable {
|
|
|
138
138
|
this.callbacks = params.callbacks;
|
|
139
139
|
this.tags = params.tags ?? [];
|
|
140
140
|
this.metadata = params.metadata ?? {};
|
|
141
|
-
this._addVersion("@langchain/core", "1.2.
|
|
141
|
+
this._addVersion("@langchain/core", "1.2.3");
|
|
142
142
|
}
|
|
143
143
|
_addVersion(pkg, version) {
|
|
144
144
|
const existing = this.metadata?.versions;
|
|
@@ -111,7 +111,14 @@ function convertToV1FromChatBedrockConverseMessage(message) {
|
|
|
111
111
|
text: message.content
|
|
112
112
|
}] : message.content;
|
|
113
113
|
for (const block of content) {
|
|
114
|
-
if (require_utils._isContentBlock(block, "
|
|
114
|
+
if (require_utils._isContentBlock(block, "reasoning") && require_utils._isString(block.reasoning)) {
|
|
115
|
+
yield {
|
|
116
|
+
...block,
|
|
117
|
+
type: "reasoning",
|
|
118
|
+
reasoning: block.reasoning
|
|
119
|
+
};
|
|
120
|
+
continue;
|
|
121
|
+
} else if (require_utils._isContentBlock(block, "cache_point")) {
|
|
115
122
|
yield {
|
|
116
123
|
type: "non_standard",
|
|
117
124
|
value: block
|
|
@@ -163,6 +170,13 @@ function convertToV1FromChatBedrockConverseMessage(message) {
|
|
|
163
170
|
} else if (require_utils._isContentBlock(block, "image") && require_utils._isObject(block.image)) {
|
|
164
171
|
yield convertConverseImageBlock(block);
|
|
165
172
|
continue;
|
|
173
|
+
} else if (require_utils._isContentBlock(block, "reasoning_content") && require_utils._isObject(block.reasoningText) && require_utils._isString(block.reasoningText.text)) {
|
|
174
|
+
yield {
|
|
175
|
+
type: "reasoning",
|
|
176
|
+
reasoning: block.reasoningText.text,
|
|
177
|
+
...require_utils._isString(block.reasoningText.signature) ? { signature: block.reasoningText.signature } : {}
|
|
178
|
+
};
|
|
179
|
+
continue;
|
|
166
180
|
} else if (require_utils._isContentBlock(block, "reasoning_content") && require_utils._isString(block.reasoningText)) {
|
|
167
181
|
yield {
|
|
168
182
|
type: "reasoning",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock_converse.cjs","names":["_isObject","_isString","_isBytesArray","_isArray","_isContentBlock","iife","_isNumber"],"sources":["../../../src/messages/block_translators/bedrock_converse.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport { KNOWN_BLOCK_TYPES } from \"../content/tools.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport {\n _isArray,\n _isBytesArray,\n _isContentBlock,\n _isNumber,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n// see `/libs/providers/langchain-aws/src/utils/compat.ts:convertFileFormatToMimeType`\nfunction convertFileFormatToMimeType(format: string): string {\n switch (format) {\n // DocumentBlock\n case \"csv\":\n return \"text/csv\";\n case \"doc\":\n return \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\";\n case \"docx\":\n return \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\";\n case \"html\":\n return \"text/html\";\n case \"md\":\n return \"text/markdown\";\n case \"pdf\":\n return \"application/pdf\";\n case \"txt\":\n return \"text/plain\";\n case \"xls\":\n return \"application/vnd.ms-excel\";\n case \"xlsx\":\n return \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\";\n // ImageBlock\n case \"gif\":\n return \"image/gif\";\n case \"jpeg\":\n return \"image/jpeg\";\n case \"jpg\":\n return \"image/jpeg\";\n case \"png\":\n return \"image/png\";\n case \"webp\":\n return \"image/webp\";\n // VideoBlock\n case \"flv\":\n return \"video/flv\";\n case \"mkv\":\n return \"video/mkv\";\n case \"mov\":\n return \"video/mov\";\n case \"mp4\":\n return \"video/mp4\";\n case \"mpeg\":\n return \"video/mpeg\";\n case \"mpg\":\n return \"video/mpg\";\n case \"three_gp\":\n return \"video/three_gp\";\n case \"webm\":\n return \"video/webm\";\n case \"wmv\":\n return \"video/wmv\";\n default:\n return \"application/octet-stream\";\n }\n}\n\nfunction convertConverseDocumentBlock(\n block: ContentBlock\n): ContentBlock.Standard {\n if (_isObject(block.document) && _isObject(block.document.source)) {\n const format =\n _isObject(block.document) && _isString(block.document.format)\n ? block.document.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.document.source)) {\n if (\n _isObject(block.document.source.s3Location) &&\n _isString(block.document.source.s3Location.uri)\n ) {\n return {\n type: \"file\",\n mimeType,\n fileId: block.document.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.document.source.bytes)) {\n return {\n type: \"file\",\n mimeType,\n data: block.document.source.bytes,\n };\n }\n if (_isString(block.document.source.text)) {\n return {\n type: \"file\",\n mimeType,\n data: Buffer.from(block.document.source.text).toString(\"base64\"),\n };\n }\n if (_isArray(block.document.source.content)) {\n const data = block.document.source.content.reduce(\n (acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n },\n \"\"\n );\n return {\n type: \"file\",\n mimeType,\n data,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nfunction convertConverseImageBlock(block: ContentBlock): ContentBlock.Standard {\n if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n const format =\n _isObject(block.image) && _isString(block.image.format)\n ? block.image.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.image.source)) {\n if (\n _isObject(block.image.source.s3Location) &&\n _isString(block.image.source.s3Location.uri)\n ) {\n return {\n type: \"image\",\n mimeType,\n fileId: block.image.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.image.source.bytes)) {\n return {\n type: \"image\",\n mimeType,\n data: block.image.source.bytes,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nfunction convertConverseVideoBlock(block: ContentBlock): ContentBlock.Standard {\n if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n const format =\n _isObject(block.video) && _isString(block.video.format)\n ? block.video.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.video.source)) {\n if (\n _isObject(block.video.source.s3Location) &&\n _isString(block.video.source.s3Location.uri)\n ) {\n return {\n type: \"video\",\n mimeType,\n fileId: block.video.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.video.source.bytes)) {\n return {\n type: \"video\",\n mimeType,\n data: block.video.source.bytes,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nexport function convertToV1FromChatBedrockConverseInput(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n const blocks = content.map((block) => {\n if (_isContentBlock(block, \"non_standard\") && \"value\" in block) {\n return block.value as ContentBlock;\n }\n return block;\n });\n for (const block of blocks) {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.document)\n ) {\n yield convertConverseDocumentBlock(block);\n continue;\n } else if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n yield convertConverseImageBlock(block);\n continue;\n } else if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n yield convertConverseVideoBlock(block);\n continue;\n }\n if (KNOWN_BLOCK_TYPES.includes(block.type)) {\n yield block as ContentBlock.Standard;\n } else {\n yield { type: \"non_standard\", value: block };\n }\n }\n }\n return Array.from(iterateContent());\n}\n\nfunction convertToV1FromChatBedrockConverseMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `/libs/providers/langchain-aws/src/utils/message_outputs.ts:convertConverseMessageToLangChainMessage`\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"cache_point\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (\n _isContentBlock(block, \"citations_content\") &&\n _isObject(block.citationsContent)\n ) {\n const text = _isArray(block.citationsContent.content)\n ? block.citationsContent.content.reduce((acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n }, \"\")\n : \"\";\n const annotations = _isArray(block.citationsContent.citations)\n ? block.citationsContent.citations.reduce(\n (acc: Array<ContentBlock.Citation>, item) => {\n if (_isObject(item)) {\n const citedText = _isArray(item.sourceContent)\n ? item.sourceContent.reduce((acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n }, \"\")\n : \"\";\n const properties = iife(() => {\n if (_isObject(item.location)) {\n const location =\n item.location.documentChar ||\n item.location.documentPage ||\n item.location.documentChunk;\n if (_isObject(location)) {\n return {\n source: _isNumber(location.documentIndex)\n ? location.documentIndex.toString()\n : undefined,\n startIndex: _isNumber(location.start)\n ? location.start\n : undefined,\n endIndex: _isNumber(location.end)\n ? location.end\n : undefined,\n };\n }\n }\n return {};\n });\n acc.push({ type: \"citation\", citedText, ...properties });\n }\n return acc;\n },\n []\n )\n : [];\n yield { type: \"text\", text, annotations };\n continue;\n } else if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.document)\n ) {\n yield convertConverseDocumentBlock(block);\n continue;\n } else if (_isContentBlock(block, \"guard_content\")) {\n yield {\n type: \"non_standard\",\n value: block,\n };\n continue;\n } else if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n yield convertConverseImageBlock(block);\n continue;\n } else if (\n _isContentBlock(block, \"reasoning_content\") &&\n _isString(block.reasoningText)\n ) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoningText,\n };\n continue;\n } else if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (_isContentBlock(block, \"tool_result\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (_isContentBlock(block, \"tool_call\")) {\n // no-op - filtered to tools\n continue;\n } else if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n yield convertConverseVideoBlock(block);\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatBedrockConverseTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatBedrockConverseMessage,\n translateContentChunk: convertToV1FromChatBedrockConverseMessage,\n};\n"],"mappings":";;AAeA,SAAS,4BAA4B,QAAwB;AAC3D,SAAQ,QAAR;EAEE,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,QACE,QAAO;;;AAIb,SAAS,6BACP,OACuB;AACvB,KAAIA,cAAAA,UAAU,MAAM,SAAS,IAAIA,cAAAA,UAAU,MAAM,SAAS,OAAO,EAAE;EAKjE,MAAM,WAAW,4BAHfA,cAAAA,UAAU,MAAM,SAAS,IAAIC,cAAAA,UAAU,MAAM,SAAS,OAAO,GACzD,MAAM,SAAS,SACf,GAC8C;AAEpD,MAAID,cAAAA,UAAU,MAAM,SAAS,OAAO,EAAE;AACpC,OACEA,cAAAA,UAAU,MAAM,SAAS,OAAO,WAAW,IAC3CC,cAAAA,UAAU,MAAM,SAAS,OAAO,WAAW,IAAI,CAE/C,QAAO;IACL,MAAM;IACN;IACA,QAAQ,MAAM,SAAS,OAAO,WAAW;IAC1C;AAEH,OAAIC,cAAAA,cAAc,MAAM,SAAS,OAAO,MAAM,CAC5C,QAAO;IACL,MAAM;IACN;IACA,MAAM,MAAM,SAAS,OAAO;IAC7B;AAEH,OAAID,cAAAA,UAAU,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AAAA,gBAAgB,OAAO,cAAc,EAAE;AAChD,UAAM;KAAE,MAAM;KAAgB,OAAO;KAAO;AAC5C;cACSA,cAAAA,gBAAgB,OAAO,YAAY,CAE5C;YACSA,cAAAA,gBAAgB,OAAO,QAAQ,IAAIJ,cAAAA,UAAU,MAAM,MAAM,EAAE;AACpE,UAAM,0BAA0B,MAAM;AACtC;;AAEF,SAAM;IAAE,MAAM;IAAgB,OAAO;IAAO;;;AAGhD,QAAO,MAAM,KAAK,gBAAgB,CAAC;;AAGrC,MAAa,gCAAgE;CAC3E,kBAAkB;CAClB,uBAAuB;CACxB"}
|
|
1
|
+
{"version":3,"file":"bedrock_converse.cjs","names":["_isObject","_isString","_isBytesArray","_isArray","_isContentBlock","iife","_isNumber"],"sources":["../../../src/messages/block_translators/bedrock_converse.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport { KNOWN_BLOCK_TYPES } from \"../content/tools.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport {\n _isArray,\n _isBytesArray,\n _isContentBlock,\n _isNumber,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n// see `/libs/providers/langchain-aws/src/utils/compat.ts:convertFileFormatToMimeType`\nfunction convertFileFormatToMimeType(format: string): string {\n switch (format) {\n // DocumentBlock\n case \"csv\":\n return \"text/csv\";\n case \"doc\":\n return \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\";\n case \"docx\":\n return \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\";\n case \"html\":\n return \"text/html\";\n case \"md\":\n return \"text/markdown\";\n case \"pdf\":\n return \"application/pdf\";\n case \"txt\":\n return \"text/plain\";\n case \"xls\":\n return \"application/vnd.ms-excel\";\n case \"xlsx\":\n return \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\";\n // ImageBlock\n case \"gif\":\n return \"image/gif\";\n case \"jpeg\":\n return \"image/jpeg\";\n case \"jpg\":\n return \"image/jpeg\";\n case \"png\":\n return \"image/png\";\n case \"webp\":\n return \"image/webp\";\n // VideoBlock\n case \"flv\":\n return \"video/flv\";\n case \"mkv\":\n return \"video/mkv\";\n case \"mov\":\n return \"video/mov\";\n case \"mp4\":\n return \"video/mp4\";\n case \"mpeg\":\n return \"video/mpeg\";\n case \"mpg\":\n return \"video/mpg\";\n case \"three_gp\":\n return \"video/three_gp\";\n case \"webm\":\n return \"video/webm\";\n case \"wmv\":\n return \"video/wmv\";\n default:\n return \"application/octet-stream\";\n }\n}\n\nfunction convertConverseDocumentBlock(\n block: ContentBlock\n): ContentBlock.Standard {\n if (_isObject(block.document) && _isObject(block.document.source)) {\n const format =\n _isObject(block.document) && _isString(block.document.format)\n ? block.document.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.document.source)) {\n if (\n _isObject(block.document.source.s3Location) &&\n _isString(block.document.source.s3Location.uri)\n ) {\n return {\n type: \"file\",\n mimeType,\n fileId: block.document.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.document.source.bytes)) {\n return {\n type: \"file\",\n mimeType,\n data: block.document.source.bytes,\n };\n }\n if (_isString(block.document.source.text)) {\n return {\n type: \"file\",\n mimeType,\n data: Buffer.from(block.document.source.text).toString(\"base64\"),\n };\n }\n if (_isArray(block.document.source.content)) {\n const data = block.document.source.content.reduce(\n (acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n },\n \"\"\n );\n return {\n type: \"file\",\n mimeType,\n data,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nfunction convertConverseImageBlock(block: ContentBlock): ContentBlock.Standard {\n if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n const format =\n _isObject(block.image) && _isString(block.image.format)\n ? block.image.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.image.source)) {\n if (\n _isObject(block.image.source.s3Location) &&\n _isString(block.image.source.s3Location.uri)\n ) {\n return {\n type: \"image\",\n mimeType,\n fileId: block.image.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.image.source.bytes)) {\n return {\n type: \"image\",\n mimeType,\n data: block.image.source.bytes,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nfunction convertConverseVideoBlock(block: ContentBlock): ContentBlock.Standard {\n if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n const format =\n _isObject(block.video) && _isString(block.video.format)\n ? block.video.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.video.source)) {\n if (\n _isObject(block.video.source.s3Location) &&\n _isString(block.video.source.s3Location.uri)\n ) {\n return {\n type: \"video\",\n mimeType,\n fileId: block.video.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.video.source.bytes)) {\n return {\n type: \"video\",\n mimeType,\n data: block.video.source.bytes,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nexport function convertToV1FromChatBedrockConverseInput(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n const blocks = content.map((block) => {\n if (_isContentBlock(block, \"non_standard\") && \"value\" in block) {\n return block.value as ContentBlock;\n }\n return block;\n });\n for (const block of blocks) {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.document)\n ) {\n yield convertConverseDocumentBlock(block);\n continue;\n } else if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n yield convertConverseImageBlock(block);\n continue;\n } else if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n yield convertConverseVideoBlock(block);\n continue;\n }\n if (KNOWN_BLOCK_TYPES.includes(block.type)) {\n yield block as ContentBlock.Standard;\n } else {\n yield { type: \"non_standard\", value: block };\n }\n }\n }\n return Array.from(iterateContent());\n}\n\nfunction convertToV1FromChatBedrockConverseMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `/libs/providers/langchain-aws/src/utils/message_outputs.ts:convertConverseMessageToLangChainMessage`\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"reasoning\") && _isString(block.reasoning)) {\n yield { ...block, type: \"reasoning\", reasoning: block.reasoning };\n continue;\n } else if (_isContentBlock(block, \"cache_point\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (\n _isContentBlock(block, \"citations_content\") &&\n _isObject(block.citationsContent)\n ) {\n const text = _isArray(block.citationsContent.content)\n ? block.citationsContent.content.reduce((acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n }, \"\")\n : \"\";\n const annotations = _isArray(block.citationsContent.citations)\n ? block.citationsContent.citations.reduce(\n (acc: Array<ContentBlock.Citation>, item) => {\n if (_isObject(item)) {\n const citedText = _isArray(item.sourceContent)\n ? item.sourceContent.reduce((acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n }, \"\")\n : \"\";\n const properties = iife(() => {\n if (_isObject(item.location)) {\n const location =\n item.location.documentChar ||\n item.location.documentPage ||\n item.location.documentChunk;\n if (_isObject(location)) {\n return {\n source: _isNumber(location.documentIndex)\n ? location.documentIndex.toString()\n : undefined,\n startIndex: _isNumber(location.start)\n ? location.start\n : undefined,\n endIndex: _isNumber(location.end)\n ? location.end\n : undefined,\n };\n }\n }\n return {};\n });\n acc.push({ type: \"citation\", citedText, ...properties });\n }\n return acc;\n },\n []\n )\n : [];\n yield { type: \"text\", text, annotations };\n continue;\n } else if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.document)\n ) {\n yield convertConverseDocumentBlock(block);\n continue;\n } else if (_isContentBlock(block, \"guard_content\")) {\n yield {\n type: \"non_standard\",\n value: block,\n };\n continue;\n } else if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n yield convertConverseImageBlock(block);\n continue;\n } else if (\n _isContentBlock(block, \"reasoning_content\") &&\n _isObject(block.reasoningText) &&\n _isString(block.reasoningText.text)\n ) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoningText.text,\n ...(_isString(block.reasoningText.signature)\n ? { signature: block.reasoningText.signature }\n : {}),\n };\n continue;\n } else if (\n _isContentBlock(block, \"reasoning_content\") &&\n _isString(block.reasoningText)\n ) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoningText,\n };\n continue;\n } else if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (_isContentBlock(block, \"tool_result\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (_isContentBlock(block, \"tool_call\")) {\n // no-op - filtered to tools\n continue;\n } else if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n yield convertConverseVideoBlock(block);\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatBedrockConverseTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatBedrockConverseMessage,\n translateContentChunk: convertToV1FromChatBedrockConverseMessage,\n};\n"],"mappings":";;AAeA,SAAS,4BAA4B,QAAwB;AAC3D,SAAQ,QAAR;EAEE,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAA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,OAAO,YAAY,CAE5C;YACSA,cAAAA,gBAAgB,OAAO,QAAQ,IAAIJ,cAAAA,UAAU,MAAM,MAAM,EAAE;AACpE,UAAM,0BAA0B,MAAM;AACtC;;AAEF,SAAM;IAAE,MAAM;IAAgB,OAAO;IAAO;;;AAGhD,QAAO,MAAM,KAAK,gBAAgB,CAAC;;AAGrC,MAAa,gCAAgE;CAC3E,kBAAkB;CAClB,uBAAuB;CACxB"}
|
|
@@ -111,7 +111,14 @@ function convertToV1FromChatBedrockConverseMessage(message) {
|
|
|
111
111
|
text: message.content
|
|
112
112
|
}] : message.content;
|
|
113
113
|
for (const block of content) {
|
|
114
|
-
if (_isContentBlock(block, "
|
|
114
|
+
if (_isContentBlock(block, "reasoning") && _isString(block.reasoning)) {
|
|
115
|
+
yield {
|
|
116
|
+
...block,
|
|
117
|
+
type: "reasoning",
|
|
118
|
+
reasoning: block.reasoning
|
|
119
|
+
};
|
|
120
|
+
continue;
|
|
121
|
+
} else if (_isContentBlock(block, "cache_point")) {
|
|
115
122
|
yield {
|
|
116
123
|
type: "non_standard",
|
|
117
124
|
value: block
|
|
@@ -163,6 +170,13 @@ function convertToV1FromChatBedrockConverseMessage(message) {
|
|
|
163
170
|
} else if (_isContentBlock(block, "image") && _isObject(block.image)) {
|
|
164
171
|
yield convertConverseImageBlock(block);
|
|
165
172
|
continue;
|
|
173
|
+
} else if (_isContentBlock(block, "reasoning_content") && _isObject(block.reasoningText) && _isString(block.reasoningText.text)) {
|
|
174
|
+
yield {
|
|
175
|
+
type: "reasoning",
|
|
176
|
+
reasoning: block.reasoningText.text,
|
|
177
|
+
..._isString(block.reasoningText.signature) ? { signature: block.reasoningText.signature } : {}
|
|
178
|
+
};
|
|
179
|
+
continue;
|
|
166
180
|
} else if (_isContentBlock(block, "reasoning_content") && _isString(block.reasoningText)) {
|
|
167
181
|
yield {
|
|
168
182
|
type: "reasoning",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock_converse.js","names":[],"sources":["../../../src/messages/block_translators/bedrock_converse.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport { KNOWN_BLOCK_TYPES } from \"../content/tools.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport {\n _isArray,\n _isBytesArray,\n _isContentBlock,\n _isNumber,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n// see `/libs/providers/langchain-aws/src/utils/compat.ts:convertFileFormatToMimeType`\nfunction convertFileFormatToMimeType(format: string): string {\n switch (format) {\n // DocumentBlock\n case \"csv\":\n return \"text/csv\";\n case \"doc\":\n return \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\";\n case \"docx\":\n return \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\";\n case \"html\":\n return \"text/html\";\n case \"md\":\n return \"text/markdown\";\n case \"pdf\":\n return \"application/pdf\";\n case \"txt\":\n return \"text/plain\";\n case \"xls\":\n return \"application/vnd.ms-excel\";\n case \"xlsx\":\n return \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\";\n // ImageBlock\n case \"gif\":\n return \"image/gif\";\n case \"jpeg\":\n return \"image/jpeg\";\n case \"jpg\":\n return \"image/jpeg\";\n case \"png\":\n return \"image/png\";\n case \"webp\":\n return \"image/webp\";\n // VideoBlock\n case \"flv\":\n return \"video/flv\";\n case \"mkv\":\n return \"video/mkv\";\n case \"mov\":\n return \"video/mov\";\n case \"mp4\":\n return \"video/mp4\";\n case \"mpeg\":\n return \"video/mpeg\";\n case \"mpg\":\n return \"video/mpg\";\n case \"three_gp\":\n return \"video/three_gp\";\n case \"webm\":\n return \"video/webm\";\n case \"wmv\":\n return \"video/wmv\";\n default:\n return \"application/octet-stream\";\n }\n}\n\nfunction convertConverseDocumentBlock(\n block: ContentBlock\n): ContentBlock.Standard {\n if (_isObject(block.document) && _isObject(block.document.source)) {\n const format =\n _isObject(block.document) && _isString(block.document.format)\n ? block.document.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.document.source)) {\n if (\n _isObject(block.document.source.s3Location) &&\n _isString(block.document.source.s3Location.uri)\n ) {\n return {\n type: \"file\",\n mimeType,\n fileId: block.document.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.document.source.bytes)) {\n return {\n type: \"file\",\n mimeType,\n data: block.document.source.bytes,\n };\n }\n if (_isString(block.document.source.text)) {\n return {\n type: \"file\",\n mimeType,\n data: Buffer.from(block.document.source.text).toString(\"base64\"),\n };\n }\n if (_isArray(block.document.source.content)) {\n const data = block.document.source.content.reduce(\n (acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n },\n \"\"\n );\n return {\n type: \"file\",\n mimeType,\n data,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nfunction convertConverseImageBlock(block: ContentBlock): ContentBlock.Standard {\n if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n const format =\n _isObject(block.image) && _isString(block.image.format)\n ? block.image.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.image.source)) {\n if (\n _isObject(block.image.source.s3Location) &&\n _isString(block.image.source.s3Location.uri)\n ) {\n return {\n type: \"image\",\n mimeType,\n fileId: block.image.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.image.source.bytes)) {\n return {\n type: \"image\",\n mimeType,\n data: block.image.source.bytes,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nfunction convertConverseVideoBlock(block: ContentBlock): ContentBlock.Standard {\n if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n const format =\n _isObject(block.video) && _isString(block.video.format)\n ? block.video.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.video.source)) {\n if (\n _isObject(block.video.source.s3Location) &&\n _isString(block.video.source.s3Location.uri)\n ) {\n return {\n type: \"video\",\n mimeType,\n fileId: block.video.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.video.source.bytes)) {\n return {\n type: \"video\",\n mimeType,\n data: block.video.source.bytes,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nexport function convertToV1FromChatBedrockConverseInput(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n const blocks = content.map((block) => {\n if (_isContentBlock(block, \"non_standard\") && \"value\" in block) {\n return block.value as ContentBlock;\n }\n return block;\n });\n for (const block of blocks) {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.document)\n ) {\n yield convertConverseDocumentBlock(block);\n continue;\n } else if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n yield convertConverseImageBlock(block);\n continue;\n } else if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n yield convertConverseVideoBlock(block);\n continue;\n }\n if (KNOWN_BLOCK_TYPES.includes(block.type)) {\n yield block as ContentBlock.Standard;\n } else {\n yield { type: \"non_standard\", value: block };\n }\n }\n }\n return Array.from(iterateContent());\n}\n\nfunction convertToV1FromChatBedrockConverseMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `/libs/providers/langchain-aws/src/utils/message_outputs.ts:convertConverseMessageToLangChainMessage`\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"cache_point\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (\n _isContentBlock(block, \"citations_content\") &&\n _isObject(block.citationsContent)\n ) {\n const text = _isArray(block.citationsContent.content)\n ? block.citationsContent.content.reduce((acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n }, \"\")\n : \"\";\n const annotations = _isArray(block.citationsContent.citations)\n ? block.citationsContent.citations.reduce(\n (acc: Array<ContentBlock.Citation>, item) => {\n if (_isObject(item)) {\n const citedText = _isArray(item.sourceContent)\n ? item.sourceContent.reduce((acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n }, \"\")\n : \"\";\n const properties = iife(() => {\n if (_isObject(item.location)) {\n const location =\n item.location.documentChar ||\n item.location.documentPage ||\n item.location.documentChunk;\n if (_isObject(location)) {\n return {\n source: _isNumber(location.documentIndex)\n ? location.documentIndex.toString()\n : undefined,\n startIndex: _isNumber(location.start)\n ? location.start\n : undefined,\n endIndex: _isNumber(location.end)\n ? location.end\n : undefined,\n };\n }\n }\n return {};\n });\n acc.push({ type: \"citation\", citedText, ...properties });\n }\n return acc;\n },\n []\n )\n : [];\n yield { type: \"text\", text, annotations };\n continue;\n } else if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.document)\n ) {\n yield convertConverseDocumentBlock(block);\n continue;\n } else if (_isContentBlock(block, \"guard_content\")) {\n yield {\n type: \"non_standard\",\n value: block,\n };\n continue;\n } else if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n yield convertConverseImageBlock(block);\n continue;\n } else if (\n _isContentBlock(block, \"reasoning_content\") &&\n _isString(block.reasoningText)\n ) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoningText,\n };\n continue;\n } else if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (_isContentBlock(block, \"tool_result\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (_isContentBlock(block, \"tool_call\")) {\n // no-op - filtered to tools\n continue;\n } else if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n yield convertConverseVideoBlock(block);\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatBedrockConverseTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatBedrockConverseMessage,\n translateContentChunk: convertToV1FromChatBedrockConverseMessage,\n};\n"],"mappings":";;AAeA,SAAS,4BAA4B,QAAwB;AAC3D,SAAQ,QAAR;EAEE,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,QACE,QAAO;;;AAIb,SAAS,6BACP,OACuB;AACvB,KAAI,UAAU,MAAM,SAAS,IAAI,UAAU,MAAM,SAAS,OAAO,EAAE;EAKjE,MAAM,WAAW,4BAHf,UAAU,MAAM,SAAS,IAAI,UAAU,MAAM,SAAS,OAAO,GACzD,MAAM,SAAS,SACf,GAC8C;AAEpD,MAAI,UAAU,MAAM,SAAS,OAAO,EAAE;AACpC,OACE,UAAU,MAAM,SAAS,OAAO,WAAW,IAC3C,UAAU,MAAM,SAAS,OAAO,WAAW,IAAI,CAE/C,QAAO;IACL,MAAM;IACN;IACA,QAAQ,MAAM,SAAS,OAAO,WAAW;IAC1C;AAEH,OAAI,cAAc,MAAM,SAAS,OAAO,MAAM,CAC5C,QAAO;IACL,MAAM;IACN;IACA,MAAM,MAAM,SAAS,OAAO;IAC7B;AAEH,OAAI,UAAU,MAAM,SAAS,OAAO,KAAK,CACvC,QAAO;IACL,MAAM;IACN;IACA,MAAM,OAAO,KAAK,MAAM,SAAS,OAAO,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,cAAc,UAAU,GACjC,KAAA;UACJ,YAAY,UAAU,SAAS,MAAM,GACjC,SAAS,QACT,KAAA;UACJ,UAAU,UAAU,SAAS,IAAI,GAC7B,SAAS,MACT,KAAA;UACL;;AAGL,eAAO,EAAE;SACT;AACF,WAAI,KAAK;QAAE,MAAM;QAAY;QAAW,GAAG;QAAY,CAAC;;AAE1D,aAAO;QAET,EAAE,CACH,GACD,EAAE;KACmC;AACzC;cAEA,gBAAgB,OAAO,WAAW,IAClC,UAAU,MAAM,SAAS,EACzB;AACA,UAAM,6BAA6B,MAAM;AACzC;cACS,gBAAgB,OAAO,gBAAgB,EAAE;AAClD,UAAM;KACJ,MAAM;KACN,OAAO;KACR;AACD;cACS,gBAAgB,OAAO,QAAQ,IAAI,UAAU,MAAM,MAAM,EAAE;AACpE,UAAM,0BAA0B,MAAM;AACtC;cAEA,gBAAgB,OAAO,oBAAoB,IAC3C,UAAU,MAAM,cAAc,EAC9B;AACA,UAAM;KACJ,MAAM;KACN,WAAW,MAAM;KAClB;AACD;cACS,gBAAgB,OAAO,OAAO,IAAI,UAAU,MAAM,KAAK,EAAE;AAClE,UAAM;KAAE,MAAM;KAAQ,MAAM,MAAM;KAAM;AACxC;cACS,gBAAgB,OAAO,cAAc,EAAE;AAChD,UAAM;KAAE,MAAM;KAAgB,OAAO;KAAO;AAC5C;cACS,gBAAgB,OAAO,YAAY,CAE5C;YACS,gBAAgB,OAAO,QAAQ,IAAI,UAAU,MAAM,MAAM,EAAE;AACpE,UAAM,0BAA0B,MAAM;AACtC;;AAEF,SAAM;IAAE,MAAM;IAAgB,OAAO;IAAO;;;AAGhD,QAAO,MAAM,KAAK,gBAAgB,CAAC;;AAGrC,MAAa,gCAAgE;CAC3E,kBAAkB;CAClB,uBAAuB;CACxB"}
|
|
1
|
+
{"version":3,"file":"bedrock_converse.js","names":[],"sources":["../../../src/messages/block_translators/bedrock_converse.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport { KNOWN_BLOCK_TYPES } from \"../content/tools.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport {\n _isArray,\n _isBytesArray,\n _isContentBlock,\n _isNumber,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n// see `/libs/providers/langchain-aws/src/utils/compat.ts:convertFileFormatToMimeType`\nfunction convertFileFormatToMimeType(format: string): string {\n switch (format) {\n // DocumentBlock\n case \"csv\":\n return \"text/csv\";\n case \"doc\":\n return \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\";\n case \"docx\":\n return \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\";\n case \"html\":\n return \"text/html\";\n case \"md\":\n return \"text/markdown\";\n case \"pdf\":\n return \"application/pdf\";\n case \"txt\":\n return \"text/plain\";\n case \"xls\":\n return \"application/vnd.ms-excel\";\n case \"xlsx\":\n return \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\";\n // ImageBlock\n case \"gif\":\n return \"image/gif\";\n case \"jpeg\":\n return \"image/jpeg\";\n case \"jpg\":\n return \"image/jpeg\";\n case \"png\":\n return \"image/png\";\n case \"webp\":\n return \"image/webp\";\n // VideoBlock\n case \"flv\":\n return \"video/flv\";\n case \"mkv\":\n return \"video/mkv\";\n case \"mov\":\n return \"video/mov\";\n case \"mp4\":\n return \"video/mp4\";\n case \"mpeg\":\n return \"video/mpeg\";\n case \"mpg\":\n return \"video/mpg\";\n case \"three_gp\":\n return \"video/three_gp\";\n case \"webm\":\n return \"video/webm\";\n case \"wmv\":\n return \"video/wmv\";\n default:\n return \"application/octet-stream\";\n }\n}\n\nfunction convertConverseDocumentBlock(\n block: ContentBlock\n): ContentBlock.Standard {\n if (_isObject(block.document) && _isObject(block.document.source)) {\n const format =\n _isObject(block.document) && _isString(block.document.format)\n ? block.document.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.document.source)) {\n if (\n _isObject(block.document.source.s3Location) &&\n _isString(block.document.source.s3Location.uri)\n ) {\n return {\n type: \"file\",\n mimeType,\n fileId: block.document.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.document.source.bytes)) {\n return {\n type: \"file\",\n mimeType,\n data: block.document.source.bytes,\n };\n }\n if (_isString(block.document.source.text)) {\n return {\n type: \"file\",\n mimeType,\n data: Buffer.from(block.document.source.text).toString(\"base64\"),\n };\n }\n if (_isArray(block.document.source.content)) {\n const data = block.document.source.content.reduce(\n (acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n },\n \"\"\n );\n return {\n type: \"file\",\n mimeType,\n data,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nfunction convertConverseImageBlock(block: ContentBlock): ContentBlock.Standard {\n if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n const format =\n _isObject(block.image) && _isString(block.image.format)\n ? block.image.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.image.source)) {\n if (\n _isObject(block.image.source.s3Location) &&\n _isString(block.image.source.s3Location.uri)\n ) {\n return {\n type: \"image\",\n mimeType,\n fileId: block.image.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.image.source.bytes)) {\n return {\n type: \"image\",\n mimeType,\n data: block.image.source.bytes,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nfunction convertConverseVideoBlock(block: ContentBlock): ContentBlock.Standard {\n if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n const format =\n _isObject(block.video) && _isString(block.video.format)\n ? block.video.format\n : \"\";\n const mimeType = convertFileFormatToMimeType(format);\n\n if (_isObject(block.video.source)) {\n if (\n _isObject(block.video.source.s3Location) &&\n _isString(block.video.source.s3Location.uri)\n ) {\n return {\n type: \"video\",\n mimeType,\n fileId: block.video.source.s3Location.uri,\n };\n }\n if (_isBytesArray(block.video.source.bytes)) {\n return {\n type: \"video\",\n mimeType,\n data: block.video.source.bytes,\n };\n }\n }\n }\n return { type: \"non_standard\", value: block };\n}\n\nexport function convertToV1FromChatBedrockConverseInput(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n const blocks = content.map((block) => {\n if (_isContentBlock(block, \"non_standard\") && \"value\" in block) {\n return block.value as ContentBlock;\n }\n return block;\n });\n for (const block of blocks) {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.document)\n ) {\n yield convertConverseDocumentBlock(block);\n continue;\n } else if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n yield convertConverseImageBlock(block);\n continue;\n } else if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n yield convertConverseVideoBlock(block);\n continue;\n }\n if (KNOWN_BLOCK_TYPES.includes(block.type)) {\n yield block as ContentBlock.Standard;\n } else {\n yield { type: \"non_standard\", value: block };\n }\n }\n }\n return Array.from(iterateContent());\n}\n\nfunction convertToV1FromChatBedrockConverseMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `/libs/providers/langchain-aws/src/utils/message_outputs.ts:convertConverseMessageToLangChainMessage`\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"reasoning\") && _isString(block.reasoning)) {\n yield { ...block, type: \"reasoning\", reasoning: block.reasoning };\n continue;\n } else if (_isContentBlock(block, \"cache_point\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (\n _isContentBlock(block, \"citations_content\") &&\n _isObject(block.citationsContent)\n ) {\n const text = _isArray(block.citationsContent.content)\n ? block.citationsContent.content.reduce((acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n }, \"\")\n : \"\";\n const annotations = _isArray(block.citationsContent.citations)\n ? block.citationsContent.citations.reduce(\n (acc: Array<ContentBlock.Citation>, item) => {\n if (_isObject(item)) {\n const citedText = _isArray(item.sourceContent)\n ? item.sourceContent.reduce((acc: string, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return acc + item.text;\n }\n return acc;\n }, \"\")\n : \"\";\n const properties = iife(() => {\n if (_isObject(item.location)) {\n const location =\n item.location.documentChar ||\n item.location.documentPage ||\n item.location.documentChunk;\n if (_isObject(location)) {\n return {\n source: _isNumber(location.documentIndex)\n ? location.documentIndex.toString()\n : undefined,\n startIndex: _isNumber(location.start)\n ? location.start\n : undefined,\n endIndex: _isNumber(location.end)\n ? location.end\n : undefined,\n };\n }\n }\n return {};\n });\n acc.push({ type: \"citation\", citedText, ...properties });\n }\n return acc;\n },\n []\n )\n : [];\n yield { type: \"text\", text, annotations };\n continue;\n } else if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.document)\n ) {\n yield convertConverseDocumentBlock(block);\n continue;\n } else if (_isContentBlock(block, \"guard_content\")) {\n yield {\n type: \"non_standard\",\n value: block,\n };\n continue;\n } else if (_isContentBlock(block, \"image\") && _isObject(block.image)) {\n yield convertConverseImageBlock(block);\n continue;\n } else if (\n _isContentBlock(block, \"reasoning_content\") &&\n _isObject(block.reasoningText) &&\n _isString(block.reasoningText.text)\n ) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoningText.text,\n ...(_isString(block.reasoningText.signature)\n ? { signature: block.reasoningText.signature }\n : {}),\n };\n continue;\n } else if (\n _isContentBlock(block, \"reasoning_content\") &&\n _isString(block.reasoningText)\n ) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoningText,\n };\n continue;\n } else if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (_isContentBlock(block, \"tool_result\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (_isContentBlock(block, \"tool_call\")) {\n // no-op - filtered to tools\n continue;\n } else if (_isContentBlock(block, \"video\") && _isObject(block.video)) {\n yield convertConverseVideoBlock(block);\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatBedrockConverseTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatBedrockConverseMessage,\n translateContentChunk: convertToV1FromChatBedrockConverseMessage,\n};\n"],"mappings":";;AAeA,SAAS,4BAA4B,QAAwB;AAC3D,SAAQ,QAAR;EAEE,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,QACE,QAAO;;;AAIb,SAAS,6BACP,OACuB;AACvB,KAAI,UAAU,MAAM,SAAS,IAAI,UAAU,MAAM,SAAS,OAAO,EAAE;EAKjE,MAAM,WAAW,4BAHf,UAAU,MAAM,SAAS,IAAI,UAAU,MAAM,SAAS,OAAO,GACzD,MAAM,SAAS,SACf,GAC8C;AAEpD,MAAI,UAAU,MAAM,SAAS,OAAO,EAAE;AACpC,OACE,UAAU,MAAM,SAAS,OAAO,WAAW,IAC3C,UAAU,MAAM,SAAS,OAAO,WAAW,IAAI,CAE/C,QAAO;IACL,MAAM;IACN;IACA,QAAQ,MAAM,SAAS,OAAO,WAAW;IAC1C;AAEH,OAAI,cAAc,MAAM,SAAS,OAAO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;AAClE,UAAM;KAAE,MAAM;KAAQ,MAAM,MAAM;KAAM;AACxC;cACS,gBAAgB,OAAO,cAAc,EAAE;AAChD,UAAM;KAAE,MAAM;KAAgB,OAAO;KAAO;AAC5C;cACS,gBAAgB,OAAO,YAAY,CAE5C;YACS,gBAAgB,OAAO,QAAQ,IAAI,UAAU,MAAM,MAAM,EAAE;AACpE,UAAM,0BAA0B,MAAM;AACtC;;AAEF,SAAM;IAAE,MAAM;IAAgB,OAAO;IAAO;;;AAGhD,QAAO,MAAM,KAAK,gBAAgB,CAAC;;AAGrC,MAAa,gCAAgE;CAC3E,kBAAkB;CAClB,uBAAuB;CACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Core LangChain.js abstractions and schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/mustache": "^4",
|
|
29
|
-
"@types/node": "^
|
|
29
|
+
"@types/node": "^26.1.0",
|
|
30
30
|
"dotenv": "^17.4.0",
|
|
31
31
|
"dpdm": "^3.14.0",
|
|
32
32
|
"ml-matrix": "^6.10.4",
|