@langchain/core 1.1.12 → 1.1.13
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/README.md +1 -1
- package/dist/caches/index.d.cts.map +1 -1
- package/dist/callbacks/base.d.cts.map +1 -1
- package/dist/messages/block_translators/deepseek.cjs +59 -0
- package/dist/messages/block_translators/deepseek.cjs.map +1 -0
- package/dist/messages/block_translators/deepseek.js +59 -0
- package/dist/messages/block_translators/deepseek.js.map +1 -0
- package/dist/messages/block_translators/google_genai.cjs +7 -0
- package/dist/messages/block_translators/google_genai.cjs.map +1 -1
- package/dist/messages/block_translators/google_genai.js +7 -0
- package/dist/messages/block_translators/google_genai.js.map +1 -1
- package/dist/messages/block_translators/google_vertexai.cjs +7 -0
- package/dist/messages/block_translators/google_vertexai.cjs.map +1 -1
- package/dist/messages/block_translators/google_vertexai.js +7 -0
- package/dist/messages/block_translators/google_vertexai.js.map +1 -1
- package/dist/messages/block_translators/groq.cjs +97 -0
- package/dist/messages/block_translators/groq.cjs.map +1 -0
- package/dist/messages/block_translators/groq.js +97 -0
- package/dist/messages/block_translators/groq.js.map +1 -0
- package/dist/messages/block_translators/index.cjs +9 -1
- package/dist/messages/block_translators/index.cjs.map +1 -1
- package/dist/messages/block_translators/index.js +9 -1
- package/dist/messages/block_translators/index.js.map +1 -1
- package/dist/messages/block_translators/ollama.cjs +59 -0
- package/dist/messages/block_translators/ollama.cjs.map +1 -0
- package/dist/messages/block_translators/ollama.js +59 -0
- package/dist/messages/block_translators/ollama.js.map +1 -0
- package/dist/messages/block_translators/xai.cjs +95 -0
- package/dist/messages/block_translators/xai.cjs.map +1 -0
- package/dist/messages/block_translators/xai.js +95 -0
- package/dist/messages/block_translators/xai.js.map +1 -0
- package/dist/output_parsers/json.cjs +10 -0
- package/dist/output_parsers/json.cjs.map +1 -1
- package/dist/output_parsers/json.d.cts +9 -0
- package/dist/output_parsers/json.d.cts.map +1 -1
- package/dist/output_parsers/json.d.ts +10 -1
- package/dist/output_parsers/json.d.ts.map +1 -1
- package/dist/output_parsers/json.js +10 -0
- package/dist/output_parsers/json.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +9 -2
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +9 -2
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { _isString } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/messages/block_translators/groq.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a Groq AI message to an array of v1 standard content blocks.
|
|
6
|
+
*
|
|
7
|
+
* This function processes an AI message from Groq's API format
|
|
8
|
+
* and converts it to the standardized v1 content block format. It handles
|
|
9
|
+
* both parsed reasoning (in additional_kwargs.reasoning) and raw reasoning
|
|
10
|
+
* (in <think> tags within content).
|
|
11
|
+
*
|
|
12
|
+
* @param message - The AI message containing Groq-formatted content
|
|
13
|
+
* @returns Array of content blocks in v1 standard format
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Parsed format (reasoning_format="parsed")
|
|
18
|
+
* const message = new AIMessage({
|
|
19
|
+
* content: "The answer is 42",
|
|
20
|
+
* additional_kwargs: { reasoning: "Let me think about this..." }
|
|
21
|
+
* });
|
|
22
|
+
* const standardBlocks = convertToV1FromGroqMessage(message);
|
|
23
|
+
* // Returns:
|
|
24
|
+
* // [
|
|
25
|
+
* // { type: "reasoning", reasoning: "Let me think about this..." },
|
|
26
|
+
* // { type: "text", text: "The answer is 42" }
|
|
27
|
+
* // ]
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Raw format (reasoning_format="raw")
|
|
33
|
+
* const message = new AIMessage({
|
|
34
|
+
* content: "<think>Let me think...</think>The answer is 42"
|
|
35
|
+
* });
|
|
36
|
+
* const standardBlocks = convertToV1FromGroqMessage(message);
|
|
37
|
+
* // Returns:
|
|
38
|
+
* // [
|
|
39
|
+
* // { type: "reasoning", reasoning: "Let me think..." },
|
|
40
|
+
* // { type: "text", text: "The answer is 42" }
|
|
41
|
+
* // ]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function convertToV1FromGroqMessage(message) {
|
|
45
|
+
const blocks = [];
|
|
46
|
+
const parsedReasoning = message.additional_kwargs?.reasoning;
|
|
47
|
+
if (_isString(parsedReasoning) && parsedReasoning.length > 0) blocks.push({
|
|
48
|
+
type: "reasoning",
|
|
49
|
+
reasoning: parsedReasoning
|
|
50
|
+
});
|
|
51
|
+
if (typeof message.content === "string") {
|
|
52
|
+
let textContent = message.content;
|
|
53
|
+
const thinkMatch = textContent.match(/<think>([\s\S]*?)<\/think>/);
|
|
54
|
+
if (thinkMatch) {
|
|
55
|
+
const thinkingContent = thinkMatch[1].trim();
|
|
56
|
+
if (thinkingContent.length > 0) blocks.push({
|
|
57
|
+
type: "reasoning",
|
|
58
|
+
reasoning: thinkingContent
|
|
59
|
+
});
|
|
60
|
+
textContent = textContent.replace(/<think>[\s\S]*?<\/think>/, "").trim();
|
|
61
|
+
}
|
|
62
|
+
if (textContent.length > 0) blocks.push({
|
|
63
|
+
type: "text",
|
|
64
|
+
text: textContent
|
|
65
|
+
});
|
|
66
|
+
} else for (const block of message.content) if (typeof block === "object" && "type" in block && block.type === "text" && "text" in block && _isString(block.text)) {
|
|
67
|
+
let textContent = block.text;
|
|
68
|
+
const thinkMatch = textContent.match(/<think>([\s\S]*?)<\/think>/);
|
|
69
|
+
if (thinkMatch) {
|
|
70
|
+
const thinkingContent = thinkMatch[1].trim();
|
|
71
|
+
if (thinkingContent.length > 0) blocks.push({
|
|
72
|
+
type: "reasoning",
|
|
73
|
+
reasoning: thinkingContent
|
|
74
|
+
});
|
|
75
|
+
textContent = textContent.replace(/<think>[\s\S]*?<\/think>/, "").trim();
|
|
76
|
+
}
|
|
77
|
+
if (textContent.length > 0) blocks.push({
|
|
78
|
+
type: "text",
|
|
79
|
+
text: textContent
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
for (const toolCall of message.tool_calls ?? []) blocks.push({
|
|
83
|
+
type: "tool_call",
|
|
84
|
+
id: toolCall.id,
|
|
85
|
+
name: toolCall.name,
|
|
86
|
+
args: toolCall.args
|
|
87
|
+
});
|
|
88
|
+
return blocks;
|
|
89
|
+
}
|
|
90
|
+
const ChatGroqTranslator = {
|
|
91
|
+
translateContent: convertToV1FromGroqMessage,
|
|
92
|
+
translateContentChunk: convertToV1FromGroqMessage
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { ChatGroqTranslator };
|
|
97
|
+
//# sourceMappingURL=groq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groq.js","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","ChatGroqTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/groq.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isString } from \"./utils.js\";\n\n/**\n * Converts a Groq AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from Groq's API format\n * and converts it to the standardized v1 content block format. It handles\n * both parsed reasoning (in additional_kwargs.reasoning) and raw reasoning\n * (in <think> tags within content).\n *\n * @param message - The AI message containing Groq-formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * // Parsed format (reasoning_format=\"parsed\")\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: { reasoning: \"Let me think about this...\" }\n * });\n * const standardBlocks = convertToV1FromGroqMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n *\n * @example\n * ```typescript\n * // Raw format (reasoning_format=\"raw\")\n * const message = new AIMessage({\n * content: \"<think>Let me think...</think>The answer is 42\"\n * });\n * const standardBlocks = convertToV1FromGroqMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n */\nexport function convertToV1FromGroqMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n\n // Check for parsed reasoning format in additional_kwargs.reasoning\n const parsedReasoning = message.additional_kwargs?.reasoning;\n if (_isString(parsedReasoning) && parsedReasoning.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: parsedReasoning,\n });\n }\n\n // Handle text content\n if (typeof message.content === \"string\") {\n let textContent = message.content;\n\n // Check for raw reasoning format with <think> tags\n const thinkMatch = textContent.match(/<think>([\\s\\S]*?)<\\/think>/);\n if (thinkMatch) {\n const thinkingContent = thinkMatch[1].trim();\n if (thinkingContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: thinkingContent,\n });\n }\n // Remove the think tags from the text content\n textContent = textContent.replace(/<think>[\\s\\S]*?<\\/think>/, \"\").trim();\n }\n\n if (textContent.length > 0) {\n blocks.push({\n type: \"text\",\n text: textContent,\n });\n }\n } else {\n for (const block of message.content) {\n if (\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n _isString(block.text)\n ) {\n let textContent = block.text;\n\n // Check for raw reasoning format with <think> tags\n const thinkMatch = textContent.match(/<think>([\\s\\S]*?)<\\/think>/);\n if (thinkMatch) {\n const thinkingContent = thinkMatch[1].trim();\n if (thinkingContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: thinkingContent,\n });\n }\n textContent = textContent\n .replace(/<think>[\\s\\S]*?<\\/think>/, \"\")\n .trim();\n }\n\n if (textContent.length > 0) {\n blocks.push({\n type: \"text\",\n text: textContent,\n });\n }\n }\n }\n }\n\n // Add tool calls if present\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n\n return blocks;\n}\n\nexport const ChatGroqTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromGroqMessage,\n translateContentChunk: convertToV1FromGroqMessage,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,2BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;CAG/C,MAAM,kBAAkB,QAAQ,mBAAmB;AACnD,KAAI,UAAU,gBAAgB,IAAI,gBAAgB,SAAS,GACzD,OAAO,KAAK;EACV,MAAM;EACN,WAAW;CACZ,EAAC;AAIJ,KAAI,OAAO,QAAQ,YAAY,UAAU;EACvC,IAAI,cAAc,QAAQ;EAG1B,MAAM,aAAa,YAAY,MAAM,6BAA6B;AAClE,MAAI,YAAY;GACd,MAAM,kBAAkB,WAAW,GAAG,MAAM;AAC5C,OAAI,gBAAgB,SAAS,GAC3B,OAAO,KAAK;IACV,MAAM;IACN,WAAW;GACZ,EAAC;GAGJ,cAAc,YAAY,QAAQ,4BAA4B,GAAG,CAAC,MAAM;EACzE;AAED,MAAI,YAAY,SAAS,GACvB,OAAO,KAAK;GACV,MAAM;GACN,MAAM;EACP,EAAC;CAEL,MACC,MAAK,MAAM,SAAS,QAAQ,QAC1B,KACE,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,UACf,UAAU,SACV,UAAU,MAAM,KAAK,EACrB;EACA,IAAI,cAAc,MAAM;EAGxB,MAAM,aAAa,YAAY,MAAM,6BAA6B;AAClE,MAAI,YAAY;GACd,MAAM,kBAAkB,WAAW,GAAG,MAAM;AAC5C,OAAI,gBAAgB,SAAS,GAC3B,OAAO,KAAK;IACV,MAAM;IACN,WAAW;GACZ,EAAC;GAEJ,cAAc,YACX,QAAQ,4BAA4B,GAAG,CACvC,MAAM;EACV;AAED,MAAI,YAAY,SAAS,GACvB,OAAO,KAAK;GACV,MAAM;GACN,MAAM;EACP,EAAC;CAEL;AAKL,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,qBAAqD;CAChE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
const require_anthropic = require('./anthropic.cjs');
|
|
2
2
|
const require_openai = require('./openai.cjs');
|
|
3
3
|
const require_bedrock_converse = require('./bedrock_converse.cjs');
|
|
4
|
+
const require_deepseek = require('./deepseek.cjs');
|
|
4
5
|
const require_google_genai = require('./google_genai.cjs');
|
|
5
6
|
const require_google_vertexai = require('./google_vertexai.cjs');
|
|
7
|
+
const require_groq = require('./groq.cjs');
|
|
8
|
+
const require_ollama = require('./ollama.cjs');
|
|
9
|
+
const require_xai = require('./xai.cjs');
|
|
6
10
|
|
|
7
11
|
//#region src/messages/block_translators/index.ts
|
|
8
12
|
globalThis.lc_block_translators_registry ??= new Map([
|
|
9
13
|
["anthropic", require_anthropic.ChatAnthropicTranslator],
|
|
10
14
|
["bedrock-converse", require_bedrock_converse.ChatBedrockConverseTranslator],
|
|
15
|
+
["deepseek", require_deepseek.ChatDeepSeekTranslator],
|
|
11
16
|
["google-genai", require_google_genai.ChatGoogleGenAITranslator],
|
|
12
17
|
["google-vertexai", require_google_vertexai.ChatVertexTranslator],
|
|
13
|
-
["
|
|
18
|
+
["groq", require_groq.ChatGroqTranslator],
|
|
19
|
+
["ollama", require_ollama.ChatOllamaTranslator],
|
|
20
|
+
["openai", require_openai.ChatOpenAITranslator],
|
|
21
|
+
["xai", require_xai.ChatXAITranslator]
|
|
14
22
|
]);
|
|
15
23
|
function getTranslator(modelProvider) {
|
|
16
24
|
return globalThis.lc_block_translators_registry.get(modelProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["ChatAnthropicTranslator","ChatBedrockConverseTranslator","ChatGoogleGenAITranslator","ChatVertexTranslator","ChatOpenAITranslator","modelProvider: string"],"sources":["../../../src/messages/block_translators/index.ts"],"sourcesContent":["import type { AIMessage, AIMessageChunk } from \"../ai.js\";\nimport type { ContentBlock } from \"../content/index.js\";\n\nimport { ChatAnthropicTranslator } from \"./anthropic.js\";\nimport { ChatBedrockConverseTranslator } from \"./bedrock_converse.js\";\nimport { ChatGoogleGenAITranslator } from \"./google_genai.js\";\nimport { ChatVertexTranslator } from \"./google_vertexai.js\";\nimport { ChatOpenAITranslator } from \"./openai.js\";\n\nexport interface StandardContentBlockTranslator {\n translateContent(message: AIMessage): Array<ContentBlock.Standard>;\n translateContentChunk(chunk: AIMessageChunk): Array<ContentBlock.Standard>;\n}\n\ntype TranslatorRegistry = Map<string, StandardContentBlockTranslator>;\n\ndeclare global {\n var lc_block_translators_registry: TranslatorRegistry;\n}\n\nglobalThis.lc_block_translators_registry ??= new Map([\n [\"anthropic\", ChatAnthropicTranslator],\n [\"bedrock-converse\", ChatBedrockConverseTranslator],\n [\"google-genai\", ChatGoogleGenAITranslator],\n [\"google-vertexai\", ChatVertexTranslator],\n [\"openai\", ChatOpenAITranslator],\n]);\n\nexport function registerTranslator(\n modelProvider: string,\n translator: StandardContentBlockTranslator\n) {\n globalThis.lc_block_translators_registry.set(modelProvider, translator);\n}\n\nexport function getTranslator(\n modelProvider: string\n): StandardContentBlockTranslator | undefined {\n return globalThis.lc_block_translators_registry.get(modelProvider);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ChatAnthropicTranslator","ChatBedrockConverseTranslator","ChatDeepSeekTranslator","ChatGoogleGenAITranslator","ChatVertexTranslator","ChatGroqTranslator","ChatOllamaTranslator","ChatOpenAITranslator","ChatXAITranslator","modelProvider: string"],"sources":["../../../src/messages/block_translators/index.ts"],"sourcesContent":["import type { AIMessage, AIMessageChunk } from \"../ai.js\";\nimport type { ContentBlock } from \"../content/index.js\";\n\nimport { ChatAnthropicTranslator } from \"./anthropic.js\";\nimport { ChatBedrockConverseTranslator } from \"./bedrock_converse.js\";\nimport { ChatDeepSeekTranslator } from \"./deepseek.js\";\nimport { ChatGoogleGenAITranslator } from \"./google_genai.js\";\nimport { ChatVertexTranslator } from \"./google_vertexai.js\";\nimport { ChatGroqTranslator } from \"./groq.js\";\nimport { ChatOllamaTranslator } from \"./ollama.js\";\nimport { ChatOpenAITranslator } from \"./openai.js\";\nimport { ChatXAITranslator } from \"./xai.js\";\n\nexport interface StandardContentBlockTranslator {\n translateContent(message: AIMessage): Array<ContentBlock.Standard>;\n translateContentChunk(chunk: AIMessageChunk): Array<ContentBlock.Standard>;\n}\n\ntype TranslatorRegistry = Map<string, StandardContentBlockTranslator>;\n\ndeclare global {\n var lc_block_translators_registry: TranslatorRegistry;\n}\n\nglobalThis.lc_block_translators_registry ??= new Map([\n [\"anthropic\", ChatAnthropicTranslator],\n [\"bedrock-converse\", ChatBedrockConverseTranslator],\n [\"deepseek\", ChatDeepSeekTranslator],\n [\"google-genai\", ChatGoogleGenAITranslator],\n [\"google-vertexai\", ChatVertexTranslator],\n [\"groq\", ChatGroqTranslator],\n [\"ollama\", ChatOllamaTranslator],\n [\"openai\", ChatOpenAITranslator],\n [\"xai\", ChatXAITranslator],\n]);\n\nexport function registerTranslator(\n modelProvider: string,\n translator: StandardContentBlockTranslator\n) {\n globalThis.lc_block_translators_registry.set(modelProvider, translator);\n}\n\nexport function getTranslator(\n modelProvider: string\n): StandardContentBlockTranslator | undefined {\n return globalThis.lc_block_translators_registry.get(modelProvider);\n}\n"],"mappings":";;;;;;;;;;;AAwBA,WAAW,kCAAkC,IAAI,IAAI;CACnD,CAAC,aAAaA,yCAAwB;CACtC,CAAC,oBAAoBC,sDAA8B;CACnD,CAAC,YAAYC,uCAAuB;CACpC,CAAC,gBAAgBC,8CAA0B;CAC3C,CAAC,mBAAmBC,4CAAqB;CACzC,CAAC,QAAQC,+BAAmB;CAC5B,CAAC,UAAUC,mCAAqB;CAChC,CAAC,UAAUC,mCAAqB;CAChC,CAAC,OAAOC,6BAAkB;AAC3B;AASD,SAAgB,cACdC,eAC4C;AAC5C,QAAO,WAAW,8BAA8B,IAAI,cAAc;AACnE"}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { ChatAnthropicTranslator } from "./anthropic.js";
|
|
2
2
|
import { ChatOpenAITranslator } from "./openai.js";
|
|
3
3
|
import { ChatBedrockConverseTranslator } from "./bedrock_converse.js";
|
|
4
|
+
import { ChatDeepSeekTranslator } from "./deepseek.js";
|
|
4
5
|
import { ChatGoogleGenAITranslator } from "./google_genai.js";
|
|
5
6
|
import { ChatVertexTranslator } from "./google_vertexai.js";
|
|
7
|
+
import { ChatGroqTranslator } from "./groq.js";
|
|
8
|
+
import { ChatOllamaTranslator } from "./ollama.js";
|
|
9
|
+
import { ChatXAITranslator } from "./xai.js";
|
|
6
10
|
|
|
7
11
|
//#region src/messages/block_translators/index.ts
|
|
8
12
|
globalThis.lc_block_translators_registry ??= new Map([
|
|
9
13
|
["anthropic", ChatAnthropicTranslator],
|
|
10
14
|
["bedrock-converse", ChatBedrockConverseTranslator],
|
|
15
|
+
["deepseek", ChatDeepSeekTranslator],
|
|
11
16
|
["google-genai", ChatGoogleGenAITranslator],
|
|
12
17
|
["google-vertexai", ChatVertexTranslator],
|
|
13
|
-
["
|
|
18
|
+
["groq", ChatGroqTranslator],
|
|
19
|
+
["ollama", ChatOllamaTranslator],
|
|
20
|
+
["openai", ChatOpenAITranslator],
|
|
21
|
+
["xai", ChatXAITranslator]
|
|
14
22
|
]);
|
|
15
23
|
function getTranslator(modelProvider) {
|
|
16
24
|
return globalThis.lc_block_translators_registry.get(modelProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["modelProvider: string"],"sources":["../../../src/messages/block_translators/index.ts"],"sourcesContent":["import type { AIMessage, AIMessageChunk } from \"../ai.js\";\nimport type { ContentBlock } from \"../content/index.js\";\n\nimport { ChatAnthropicTranslator } from \"./anthropic.js\";\nimport { ChatBedrockConverseTranslator } from \"./bedrock_converse.js\";\nimport { ChatGoogleGenAITranslator } from \"./google_genai.js\";\nimport { ChatVertexTranslator } from \"./google_vertexai.js\";\nimport { ChatOpenAITranslator } from \"./openai.js\";\n\nexport interface StandardContentBlockTranslator {\n translateContent(message: AIMessage): Array<ContentBlock.Standard>;\n translateContentChunk(chunk: AIMessageChunk): Array<ContentBlock.Standard>;\n}\n\ntype TranslatorRegistry = Map<string, StandardContentBlockTranslator>;\n\ndeclare global {\n var lc_block_translators_registry: TranslatorRegistry;\n}\n\nglobalThis.lc_block_translators_registry ??= new Map([\n [\"anthropic\", ChatAnthropicTranslator],\n [\"bedrock-converse\", ChatBedrockConverseTranslator],\n [\"google-genai\", ChatGoogleGenAITranslator],\n [\"google-vertexai\", ChatVertexTranslator],\n [\"openai\", ChatOpenAITranslator],\n]);\n\nexport function registerTranslator(\n modelProvider: string,\n translator: StandardContentBlockTranslator\n) {\n globalThis.lc_block_translators_registry.set(modelProvider, translator);\n}\n\nexport function getTranslator(\n modelProvider: string\n): StandardContentBlockTranslator | undefined {\n return globalThis.lc_block_translators_registry.get(modelProvider);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["modelProvider: string"],"sources":["../../../src/messages/block_translators/index.ts"],"sourcesContent":["import type { AIMessage, AIMessageChunk } from \"../ai.js\";\nimport type { ContentBlock } from \"../content/index.js\";\n\nimport { ChatAnthropicTranslator } from \"./anthropic.js\";\nimport { ChatBedrockConverseTranslator } from \"./bedrock_converse.js\";\nimport { ChatDeepSeekTranslator } from \"./deepseek.js\";\nimport { ChatGoogleGenAITranslator } from \"./google_genai.js\";\nimport { ChatVertexTranslator } from \"./google_vertexai.js\";\nimport { ChatGroqTranslator } from \"./groq.js\";\nimport { ChatOllamaTranslator } from \"./ollama.js\";\nimport { ChatOpenAITranslator } from \"./openai.js\";\nimport { ChatXAITranslator } from \"./xai.js\";\n\nexport interface StandardContentBlockTranslator {\n translateContent(message: AIMessage): Array<ContentBlock.Standard>;\n translateContentChunk(chunk: AIMessageChunk): Array<ContentBlock.Standard>;\n}\n\ntype TranslatorRegistry = Map<string, StandardContentBlockTranslator>;\n\ndeclare global {\n var lc_block_translators_registry: TranslatorRegistry;\n}\n\nglobalThis.lc_block_translators_registry ??= new Map([\n [\"anthropic\", ChatAnthropicTranslator],\n [\"bedrock-converse\", ChatBedrockConverseTranslator],\n [\"deepseek\", ChatDeepSeekTranslator],\n [\"google-genai\", ChatGoogleGenAITranslator],\n [\"google-vertexai\", ChatVertexTranslator],\n [\"groq\", ChatGroqTranslator],\n [\"ollama\", ChatOllamaTranslator],\n [\"openai\", ChatOpenAITranslator],\n [\"xai\", ChatXAITranslator],\n]);\n\nexport function registerTranslator(\n modelProvider: string,\n translator: StandardContentBlockTranslator\n) {\n globalThis.lc_block_translators_registry.set(modelProvider, translator);\n}\n\nexport function getTranslator(\n modelProvider: string\n): StandardContentBlockTranslator | undefined {\n return globalThis.lc_block_translators_registry.get(modelProvider);\n}\n"],"mappings":";;;;;;;;;;;AAwBA,WAAW,kCAAkC,IAAI,IAAI;CACnD,CAAC,aAAa,uBAAwB;CACtC,CAAC,oBAAoB,6BAA8B;CACnD,CAAC,YAAY,sBAAuB;CACpC,CAAC,gBAAgB,yBAA0B;CAC3C,CAAC,mBAAmB,oBAAqB;CACzC,CAAC,QAAQ,kBAAmB;CAC5B,CAAC,UAAU,oBAAqB;CAChC,CAAC,UAAU,oBAAqB;CAChC,CAAC,OAAO,iBAAkB;AAC3B;AASD,SAAgB,cACdA,eAC4C;AAC5C,QAAO,WAAW,8BAA8B,IAAI,cAAc;AACnE"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const require_utils = require('./utils.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/messages/block_translators/ollama.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts an Ollama AI message to an array of v1 standard content blocks.
|
|
6
|
+
*
|
|
7
|
+
* This function processes an AI message from Ollama's API format
|
|
8
|
+
* and converts it to the standardized v1 content block format. It handles
|
|
9
|
+
* the reasoning_content in additional_kwargs (populated when think mode is enabled).
|
|
10
|
+
*
|
|
11
|
+
* @param message - The AI message containing Ollama-formatted content
|
|
12
|
+
* @returns Array of content blocks in v1 standard format
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const message = new AIMessage({
|
|
17
|
+
* content: "The answer is 42",
|
|
18
|
+
* additional_kwargs: { reasoning_content: "Let me think about this..." }
|
|
19
|
+
* });
|
|
20
|
+
* const standardBlocks = convertToV1FromOllamaMessage(message);
|
|
21
|
+
* // Returns:
|
|
22
|
+
* // [
|
|
23
|
+
* // { type: "reasoning", reasoning: "Let me think about this..." },
|
|
24
|
+
* // { type: "text", text: "The answer is 42" }
|
|
25
|
+
* // ]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function convertToV1FromOllamaMessage(message) {
|
|
29
|
+
const blocks = [];
|
|
30
|
+
const reasoningContent = message.additional_kwargs?.reasoning_content;
|
|
31
|
+
if (require_utils._isString(reasoningContent) && reasoningContent.length > 0) blocks.push({
|
|
32
|
+
type: "reasoning",
|
|
33
|
+
reasoning: reasoningContent
|
|
34
|
+
});
|
|
35
|
+
if (typeof message.content === "string") {
|
|
36
|
+
if (message.content.length > 0) blocks.push({
|
|
37
|
+
type: "text",
|
|
38
|
+
text: message.content
|
|
39
|
+
});
|
|
40
|
+
} else for (const block of message.content) if (typeof block === "object" && "type" in block && block.type === "text" && "text" in block && require_utils._isString(block.text)) blocks.push({
|
|
41
|
+
type: "text",
|
|
42
|
+
text: block.text
|
|
43
|
+
});
|
|
44
|
+
for (const toolCall of message.tool_calls ?? []) blocks.push({
|
|
45
|
+
type: "tool_call",
|
|
46
|
+
id: toolCall.id,
|
|
47
|
+
name: toolCall.name,
|
|
48
|
+
args: toolCall.args
|
|
49
|
+
});
|
|
50
|
+
return blocks;
|
|
51
|
+
}
|
|
52
|
+
const ChatOllamaTranslator = {
|
|
53
|
+
translateContent: convertToV1FromOllamaMessage,
|
|
54
|
+
translateContentChunk: convertToV1FromOllamaMessage
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.ChatOllamaTranslator = ChatOllamaTranslator;
|
|
59
|
+
//# sourceMappingURL=ollama.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.cjs","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","_isString","ChatOllamaTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/ollama.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isString } from \"./utils.js\";\n\n/**\n * Converts an Ollama AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from Ollama's API format\n * and converts it to the standardized v1 content block format. It handles\n * the reasoning_content in additional_kwargs (populated when think mode is enabled).\n *\n * @param message - The AI message containing Ollama-formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: { reasoning_content: \"Let me think about this...\" }\n * });\n * const standardBlocks = convertToV1FromOllamaMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n */\nexport function convertToV1FromOllamaMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n\n // Extract reasoning from additional_kwargs.reasoning_content\n const reasoningContent = message.additional_kwargs?.reasoning_content;\n if (_isString(reasoningContent) && reasoningContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: reasoningContent,\n });\n }\n\n // Handle text content\n if (typeof message.content === \"string\") {\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n }\n } else {\n for (const block of message.content) {\n if (\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n _isString(block.text)\n ) {\n blocks.push({\n type: \"text\",\n text: block.text,\n });\n }\n }\n }\n\n // Add tool calls if present\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n\n return blocks;\n}\n\nexport const ChatOllamaTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromOllamaMessage,\n translateContentChunk: convertToV1FromOllamaMessage,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,6BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;CAG/C,MAAM,mBAAmB,QAAQ,mBAAmB;AACpD,KAAIC,wBAAU,iBAAiB,IAAI,iBAAiB,SAAS,GAC3D,OAAO,KAAK;EACV,MAAM;EACN,WAAW;CACZ,EAAC;AAIJ,KAAI,OAAO,QAAQ,YAAY,UAC7B;MAAI,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EACf,EAAC;CACH,MAED,MAAK,MAAM,SAAS,QAAQ,QAC1B,KACE,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,UACf,UAAU,SACVA,wBAAU,MAAM,KAAK,EAErB,OAAO,KAAK;EACV,MAAM;EACN,MAAM,MAAM;CACb,EAAC;AAMR,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,uBAAuD;CAClE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { _isString } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/messages/block_translators/ollama.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts an Ollama AI message to an array of v1 standard content blocks.
|
|
6
|
+
*
|
|
7
|
+
* This function processes an AI message from Ollama's API format
|
|
8
|
+
* and converts it to the standardized v1 content block format. It handles
|
|
9
|
+
* the reasoning_content in additional_kwargs (populated when think mode is enabled).
|
|
10
|
+
*
|
|
11
|
+
* @param message - The AI message containing Ollama-formatted content
|
|
12
|
+
* @returns Array of content blocks in v1 standard format
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const message = new AIMessage({
|
|
17
|
+
* content: "The answer is 42",
|
|
18
|
+
* additional_kwargs: { reasoning_content: "Let me think about this..." }
|
|
19
|
+
* });
|
|
20
|
+
* const standardBlocks = convertToV1FromOllamaMessage(message);
|
|
21
|
+
* // Returns:
|
|
22
|
+
* // [
|
|
23
|
+
* // { type: "reasoning", reasoning: "Let me think about this..." },
|
|
24
|
+
* // { type: "text", text: "The answer is 42" }
|
|
25
|
+
* // ]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function convertToV1FromOllamaMessage(message) {
|
|
29
|
+
const blocks = [];
|
|
30
|
+
const reasoningContent = message.additional_kwargs?.reasoning_content;
|
|
31
|
+
if (_isString(reasoningContent) && reasoningContent.length > 0) blocks.push({
|
|
32
|
+
type: "reasoning",
|
|
33
|
+
reasoning: reasoningContent
|
|
34
|
+
});
|
|
35
|
+
if (typeof message.content === "string") {
|
|
36
|
+
if (message.content.length > 0) blocks.push({
|
|
37
|
+
type: "text",
|
|
38
|
+
text: message.content
|
|
39
|
+
});
|
|
40
|
+
} else for (const block of message.content) if (typeof block === "object" && "type" in block && block.type === "text" && "text" in block && _isString(block.text)) blocks.push({
|
|
41
|
+
type: "text",
|
|
42
|
+
text: block.text
|
|
43
|
+
});
|
|
44
|
+
for (const toolCall of message.tool_calls ?? []) blocks.push({
|
|
45
|
+
type: "tool_call",
|
|
46
|
+
id: toolCall.id,
|
|
47
|
+
name: toolCall.name,
|
|
48
|
+
args: toolCall.args
|
|
49
|
+
});
|
|
50
|
+
return blocks;
|
|
51
|
+
}
|
|
52
|
+
const ChatOllamaTranslator = {
|
|
53
|
+
translateContent: convertToV1FromOllamaMessage,
|
|
54
|
+
translateContentChunk: convertToV1FromOllamaMessage
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { ChatOllamaTranslator };
|
|
59
|
+
//# sourceMappingURL=ollama.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.js","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","ChatOllamaTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/ollama.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isString } from \"./utils.js\";\n\n/**\n * Converts an Ollama AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from Ollama's API format\n * and converts it to the standardized v1 content block format. It handles\n * the reasoning_content in additional_kwargs (populated when think mode is enabled).\n *\n * @param message - The AI message containing Ollama-formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: { reasoning_content: \"Let me think about this...\" }\n * });\n * const standardBlocks = convertToV1FromOllamaMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n */\nexport function convertToV1FromOllamaMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n\n // Extract reasoning from additional_kwargs.reasoning_content\n const reasoningContent = message.additional_kwargs?.reasoning_content;\n if (_isString(reasoningContent) && reasoningContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: reasoningContent,\n });\n }\n\n // Handle text content\n if (typeof message.content === \"string\") {\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n }\n } else {\n for (const block of message.content) {\n if (\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n _isString(block.text)\n ) {\n blocks.push({\n type: \"text\",\n text: block.text,\n });\n }\n }\n }\n\n // Add tool calls if present\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n\n return blocks;\n}\n\nexport const ChatOllamaTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromOllamaMessage,\n translateContentChunk: convertToV1FromOllamaMessage,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,6BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;CAG/C,MAAM,mBAAmB,QAAQ,mBAAmB;AACpD,KAAI,UAAU,iBAAiB,IAAI,iBAAiB,SAAS,GAC3D,OAAO,KAAK;EACV,MAAM;EACN,WAAW;CACZ,EAAC;AAIJ,KAAI,OAAO,QAAQ,YAAY,UAC7B;MAAI,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EACf,EAAC;CACH,MAED,MAAK,MAAM,SAAS,QAAQ,QAC1B,KACE,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,UACf,UAAU,SACV,UAAU,MAAM,KAAK,EAErB,OAAO,KAAK;EACV,MAAM;EACN,MAAM,MAAM;CACb,EAAC;AAMR,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,uBAAuD;CAClE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const require_utils = require('./utils.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/messages/block_translators/xai.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts an xAI AI message to an array of v1 standard content blocks.
|
|
6
|
+
*
|
|
7
|
+
* This function processes an AI message from xAI's API format
|
|
8
|
+
* and converts it to the standardized v1 content block format. It handles
|
|
9
|
+
* both the responses API (reasoning object with summary) and completions API
|
|
10
|
+
* (reasoning_content string) formats.
|
|
11
|
+
*
|
|
12
|
+
* @param message - The AI message containing xAI-formatted content
|
|
13
|
+
* @returns Array of content blocks in v1 standard format
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Responses API format
|
|
18
|
+
* const message = new AIMessage({
|
|
19
|
+
* content: "The answer is 42",
|
|
20
|
+
* additional_kwargs: {
|
|
21
|
+
* reasoning: {
|
|
22
|
+
* id: "reasoning_123",
|
|
23
|
+
* type: "reasoning",
|
|
24
|
+
* summary: [{ type: "summary_text", text: "Let me think..." }]
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* });
|
|
28
|
+
* const standardBlocks = convertToV1FromXAIMessage(message);
|
|
29
|
+
* // Returns:
|
|
30
|
+
* // [
|
|
31
|
+
* // { type: "reasoning", reasoning: "Let me think..." },
|
|
32
|
+
* // { type: "text", text: "The answer is 42" }
|
|
33
|
+
* // ]
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Completions API format
|
|
39
|
+
* const message = new AIMessage({
|
|
40
|
+
* content: "The answer is 42",
|
|
41
|
+
* additional_kwargs: { reasoning_content: "Let me think about this..." }
|
|
42
|
+
* });
|
|
43
|
+
* const standardBlocks = convertToV1FromXAIMessage(message);
|
|
44
|
+
* // Returns:
|
|
45
|
+
* // [
|
|
46
|
+
* // { type: "reasoning", reasoning: "Let me think about this..." },
|
|
47
|
+
* // { type: "text", text: "The answer is 42" }
|
|
48
|
+
* // ]
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
function convertToV1FromXAIMessage(message) {
|
|
52
|
+
const blocks = [];
|
|
53
|
+
if (require_utils._isObject(message.additional_kwargs?.reasoning)) {
|
|
54
|
+
const reasoning = message.additional_kwargs.reasoning;
|
|
55
|
+
if (require_utils._isArray(reasoning.summary)) {
|
|
56
|
+
const summaryText = reasoning.summary.reduce((acc, item) => {
|
|
57
|
+
if (require_utils._isObject(item) && require_utils._isString(item.text)) return `${acc}${item.text}`;
|
|
58
|
+
return acc;
|
|
59
|
+
}, "");
|
|
60
|
+
if (summaryText.length > 0) blocks.push({
|
|
61
|
+
type: "reasoning",
|
|
62
|
+
reasoning: summaryText
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const reasoningContent = message.additional_kwargs?.reasoning_content;
|
|
67
|
+
if (require_utils._isString(reasoningContent) && reasoningContent.length > 0) blocks.push({
|
|
68
|
+
type: "reasoning",
|
|
69
|
+
reasoning: reasoningContent
|
|
70
|
+
});
|
|
71
|
+
if (typeof message.content === "string") {
|
|
72
|
+
if (message.content.length > 0) blocks.push({
|
|
73
|
+
type: "text",
|
|
74
|
+
text: message.content
|
|
75
|
+
});
|
|
76
|
+
} else for (const block of message.content) if (typeof block === "object" && "type" in block && block.type === "text" && "text" in block && require_utils._isString(block.text)) blocks.push({
|
|
77
|
+
type: "text",
|
|
78
|
+
text: block.text
|
|
79
|
+
});
|
|
80
|
+
for (const toolCall of message.tool_calls ?? []) blocks.push({
|
|
81
|
+
type: "tool_call",
|
|
82
|
+
id: toolCall.id,
|
|
83
|
+
name: toolCall.name,
|
|
84
|
+
args: toolCall.args
|
|
85
|
+
});
|
|
86
|
+
return blocks;
|
|
87
|
+
}
|
|
88
|
+
const ChatXAITranslator = {
|
|
89
|
+
translateContent: convertToV1FromXAIMessage,
|
|
90
|
+
translateContentChunk: convertToV1FromXAIMessage
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
exports.ChatXAITranslator = ChatXAITranslator;
|
|
95
|
+
//# sourceMappingURL=xai.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xai.cjs","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","_isObject","_isArray","_isString","ChatXAITranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/xai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isArray, _isObject, _isString } from \"./utils.js\";\n\n/**\n * Converts an xAI AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from xAI's API format\n * and converts it to the standardized v1 content block format. It handles\n * both the responses API (reasoning object with summary) and completions API\n * (reasoning_content string) formats.\n *\n * @param message - The AI message containing xAI-formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * // Responses API format\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: {\n * reasoning: {\n * id: \"reasoning_123\",\n * type: \"reasoning\",\n * summary: [{ type: \"summary_text\", text: \"Let me think...\" }]\n * }\n * }\n * });\n * const standardBlocks = convertToV1FromXAIMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n *\n * @example\n * ```typescript\n * // Completions API format\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: { reasoning_content: \"Let me think about this...\" }\n * });\n * const standardBlocks = convertToV1FromXAIMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n */\nexport function convertToV1FromXAIMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n\n // Check for Responses API format: additional_kwargs.reasoning with summary array\n if (_isObject(message.additional_kwargs?.reasoning)) {\n const reasoning = message.additional_kwargs.reasoning;\n if (_isArray(reasoning.summary)) {\n const summaryText = reasoning.summary.reduce<string>((acc, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return `${acc}${item.text}`;\n }\n return acc;\n }, \"\");\n if (summaryText.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: summaryText,\n });\n }\n }\n }\n\n // Check for Completions API format: additional_kwargs.reasoning_content\n const reasoningContent = message.additional_kwargs?.reasoning_content;\n if (_isString(reasoningContent) && reasoningContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: reasoningContent,\n });\n }\n\n // Handle text content\n if (typeof message.content === \"string\") {\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n }\n } else {\n for (const block of message.content) {\n if (\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n _isString(block.text)\n ) {\n blocks.push({\n type: \"text\",\n text: block.text,\n });\n }\n }\n }\n\n // Add tool calls if present\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n\n return blocks;\n}\n\nexport const ChatXAITranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromXAIMessage,\n translateContentChunk: convertToV1FromXAIMessage,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,0BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAG/C,KAAIC,wBAAU,QAAQ,mBAAmB,UAAU,EAAE;EACnD,MAAM,YAAY,QAAQ,kBAAkB;AAC5C,MAAIC,uBAAS,UAAU,QAAQ,EAAE;GAC/B,MAAM,cAAc,UAAU,QAAQ,OAAe,CAAC,KAAK,SAAS;AAClE,QAAID,wBAAU,KAAK,IAAIE,wBAAU,KAAK,KAAK,CACzC,QAAO,GAAG,MAAM,KAAK,MAAM;AAE7B,WAAO;GACR,GAAE,GAAG;AACN,OAAI,YAAY,SAAS,GACvB,OAAO,KAAK;IACV,MAAM;IACN,WAAW;GACZ,EAAC;EAEL;CACF;CAGD,MAAM,mBAAmB,QAAQ,mBAAmB;AACpD,KAAIA,wBAAU,iBAAiB,IAAI,iBAAiB,SAAS,GAC3D,OAAO,KAAK;EACV,MAAM;EACN,WAAW;CACZ,EAAC;AAIJ,KAAI,OAAO,QAAQ,YAAY,UAC7B;MAAI,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EACf,EAAC;CACH,MAED,MAAK,MAAM,SAAS,QAAQ,QAC1B,KACE,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,UACf,UAAU,SACVA,wBAAU,MAAM,KAAK,EAErB,OAAO,KAAK;EACV,MAAM;EACN,MAAM,MAAM;CACb,EAAC;AAMR,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,oBAAoD;CAC/D,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { _isArray, _isObject, _isString } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/messages/block_translators/xai.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts an xAI AI message to an array of v1 standard content blocks.
|
|
6
|
+
*
|
|
7
|
+
* This function processes an AI message from xAI's API format
|
|
8
|
+
* and converts it to the standardized v1 content block format. It handles
|
|
9
|
+
* both the responses API (reasoning object with summary) and completions API
|
|
10
|
+
* (reasoning_content string) formats.
|
|
11
|
+
*
|
|
12
|
+
* @param message - The AI message containing xAI-formatted content
|
|
13
|
+
* @returns Array of content blocks in v1 standard format
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Responses API format
|
|
18
|
+
* const message = new AIMessage({
|
|
19
|
+
* content: "The answer is 42",
|
|
20
|
+
* additional_kwargs: {
|
|
21
|
+
* reasoning: {
|
|
22
|
+
* id: "reasoning_123",
|
|
23
|
+
* type: "reasoning",
|
|
24
|
+
* summary: [{ type: "summary_text", text: "Let me think..." }]
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* });
|
|
28
|
+
* const standardBlocks = convertToV1FromXAIMessage(message);
|
|
29
|
+
* // Returns:
|
|
30
|
+
* // [
|
|
31
|
+
* // { type: "reasoning", reasoning: "Let me think..." },
|
|
32
|
+
* // { type: "text", text: "The answer is 42" }
|
|
33
|
+
* // ]
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Completions API format
|
|
39
|
+
* const message = new AIMessage({
|
|
40
|
+
* content: "The answer is 42",
|
|
41
|
+
* additional_kwargs: { reasoning_content: "Let me think about this..." }
|
|
42
|
+
* });
|
|
43
|
+
* const standardBlocks = convertToV1FromXAIMessage(message);
|
|
44
|
+
* // Returns:
|
|
45
|
+
* // [
|
|
46
|
+
* // { type: "reasoning", reasoning: "Let me think about this..." },
|
|
47
|
+
* // { type: "text", text: "The answer is 42" }
|
|
48
|
+
* // ]
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
function convertToV1FromXAIMessage(message) {
|
|
52
|
+
const blocks = [];
|
|
53
|
+
if (_isObject(message.additional_kwargs?.reasoning)) {
|
|
54
|
+
const reasoning = message.additional_kwargs.reasoning;
|
|
55
|
+
if (_isArray(reasoning.summary)) {
|
|
56
|
+
const summaryText = reasoning.summary.reduce((acc, item) => {
|
|
57
|
+
if (_isObject(item) && _isString(item.text)) return `${acc}${item.text}`;
|
|
58
|
+
return acc;
|
|
59
|
+
}, "");
|
|
60
|
+
if (summaryText.length > 0) blocks.push({
|
|
61
|
+
type: "reasoning",
|
|
62
|
+
reasoning: summaryText
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const reasoningContent = message.additional_kwargs?.reasoning_content;
|
|
67
|
+
if (_isString(reasoningContent) && reasoningContent.length > 0) blocks.push({
|
|
68
|
+
type: "reasoning",
|
|
69
|
+
reasoning: reasoningContent
|
|
70
|
+
});
|
|
71
|
+
if (typeof message.content === "string") {
|
|
72
|
+
if (message.content.length > 0) blocks.push({
|
|
73
|
+
type: "text",
|
|
74
|
+
text: message.content
|
|
75
|
+
});
|
|
76
|
+
} else for (const block of message.content) if (typeof block === "object" && "type" in block && block.type === "text" && "text" in block && _isString(block.text)) blocks.push({
|
|
77
|
+
type: "text",
|
|
78
|
+
text: block.text
|
|
79
|
+
});
|
|
80
|
+
for (const toolCall of message.tool_calls ?? []) blocks.push({
|
|
81
|
+
type: "tool_call",
|
|
82
|
+
id: toolCall.id,
|
|
83
|
+
name: toolCall.name,
|
|
84
|
+
args: toolCall.args
|
|
85
|
+
});
|
|
86
|
+
return blocks;
|
|
87
|
+
}
|
|
88
|
+
const ChatXAITranslator = {
|
|
89
|
+
translateContent: convertToV1FromXAIMessage,
|
|
90
|
+
translateContentChunk: convertToV1FromXAIMessage
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
export { ChatXAITranslator };
|
|
95
|
+
//# sourceMappingURL=xai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xai.js","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","ChatXAITranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/xai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isArray, _isObject, _isString } from \"./utils.js\";\n\n/**\n * Converts an xAI AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from xAI's API format\n * and converts it to the standardized v1 content block format. It handles\n * both the responses API (reasoning object with summary) and completions API\n * (reasoning_content string) formats.\n *\n * @param message - The AI message containing xAI-formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * // Responses API format\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: {\n * reasoning: {\n * id: \"reasoning_123\",\n * type: \"reasoning\",\n * summary: [{ type: \"summary_text\", text: \"Let me think...\" }]\n * }\n * }\n * });\n * const standardBlocks = convertToV1FromXAIMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n *\n * @example\n * ```typescript\n * // Completions API format\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: { reasoning_content: \"Let me think about this...\" }\n * });\n * const standardBlocks = convertToV1FromXAIMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n */\nexport function convertToV1FromXAIMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n\n // Check for Responses API format: additional_kwargs.reasoning with summary array\n if (_isObject(message.additional_kwargs?.reasoning)) {\n const reasoning = message.additional_kwargs.reasoning;\n if (_isArray(reasoning.summary)) {\n const summaryText = reasoning.summary.reduce<string>((acc, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return `${acc}${item.text}`;\n }\n return acc;\n }, \"\");\n if (summaryText.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: summaryText,\n });\n }\n }\n }\n\n // Check for Completions API format: additional_kwargs.reasoning_content\n const reasoningContent = message.additional_kwargs?.reasoning_content;\n if (_isString(reasoningContent) && reasoningContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: reasoningContent,\n });\n }\n\n // Handle text content\n if (typeof message.content === \"string\") {\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n }\n } else {\n for (const block of message.content) {\n if (\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n _isString(block.text)\n ) {\n blocks.push({\n type: \"text\",\n text: block.text,\n });\n }\n }\n }\n\n // Add tool calls if present\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n\n return blocks;\n}\n\nexport const ChatXAITranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromXAIMessage,\n translateContentChunk: convertToV1FromXAIMessage,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,0BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAG/C,KAAI,UAAU,QAAQ,mBAAmB,UAAU,EAAE;EACnD,MAAM,YAAY,QAAQ,kBAAkB;AAC5C,MAAI,SAAS,UAAU,QAAQ,EAAE;GAC/B,MAAM,cAAc,UAAU,QAAQ,OAAe,CAAC,KAAK,SAAS;AAClE,QAAI,UAAU,KAAK,IAAI,UAAU,KAAK,KAAK,CACzC,QAAO,GAAG,MAAM,KAAK,MAAM;AAE7B,WAAO;GACR,GAAE,GAAG;AACN,OAAI,YAAY,SAAS,GACvB,OAAO,KAAK;IACV,MAAM;IACN,WAAW;GACZ,EAAC;EAEL;CACF;CAGD,MAAM,mBAAmB,QAAQ,mBAAmB;AACpD,KAAI,UAAU,iBAAiB,IAAI,iBAAiB,SAAS,GAC3D,OAAO,KAAK;EACV,MAAM;EACN,WAAW;CACZ,EAAC;AAIJ,KAAI,OAAO,QAAQ,YAAY,UAC7B;MAAI,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EACf,EAAC;CACH,MAED,MAAK,MAAM,SAAS,QAAQ,QAC1B,KACE,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,UACf,UAAU,SACV,UAAU,MAAM,KAAK,EAErB,OAAO,KAAK;EACV,MAAM;EACN,MAAM,MAAM;CACb,EAAC;AAMR,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,oBAAoD;CAC/D,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -36,6 +36,16 @@ var JsonOutputParser = class extends require_transform.BaseCumulativeTransformOu
|
|
|
36
36
|
getFormatInstructions() {
|
|
37
37
|
return "";
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Extracts text content from a message for JSON parsing.
|
|
41
|
+
* Uses the message's `.text` accessor which properly handles both
|
|
42
|
+
* string content and ContentBlock[] arrays (extracting text from text blocks).
|
|
43
|
+
* @param message The message to extract text from
|
|
44
|
+
* @returns The text content of the message
|
|
45
|
+
*/
|
|
46
|
+
_baseMessageToString(message) {
|
|
47
|
+
return message.text;
|
|
48
|
+
}
|
|
39
49
|
};
|
|
40
50
|
|
|
41
51
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.cjs","names":["BaseCumulativeTransformOutputParser","first: T","second: T","prev: unknown | undefined","next: unknown","compare","generations: ChatGeneration[] | Generation[]","parseJsonMarkdown","text: string"],"sources":["../../src/output_parsers/json.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation, compare } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport class JsonOutputParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputParser\";\n }\n\n lc_namespace = [\"langchain_core\", \"output_parsers\"];\n\n lc_serializable = true;\n\n /** @internal */\n override _concatOutputChunks<T>(first: T, second: T): T {\n if (this.diff) {\n return super._concatOutputChunks(first, second);\n }\n return second;\n }\n\n protected _diff(\n prev: unknown | undefined,\n next: unknown\n ): Operation[] | undefined {\n if (!next) {\n return undefined;\n }\n if (!prev) {\n return [{ op: \"replace\", path: \"\", value: next }];\n }\n return compare(prev, next);\n }\n\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n async parsePartialResult(\n generations: ChatGeneration[] | Generation[]\n ): Promise<T | undefined> {\n return parseJsonMarkdown(generations[0].text) as T | undefined;\n }\n\n async parse(text: string): Promise<T> {\n return parseJsonMarkdown(text, JSON.parse) as T;\n }\n\n getFormatInstructions(): string {\n return \"\";\n }\n}\n\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"json.cjs","names":["BaseCumulativeTransformOutputParser","first: T","second: T","prev: unknown | undefined","next: unknown","compare","generations: ChatGeneration[] | Generation[]","parseJsonMarkdown","text: string","message: BaseMessage"],"sources":["../../src/output_parsers/json.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation, compare } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\nimport type { BaseMessage } from \"../messages/index.js\";\n\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport class JsonOutputParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>,\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputParser\";\n }\n\n lc_namespace = [\"langchain_core\", \"output_parsers\"];\n\n lc_serializable = true;\n\n /** @internal */\n override _concatOutputChunks<T>(first: T, second: T): T {\n if (this.diff) {\n return super._concatOutputChunks(first, second);\n }\n return second;\n }\n\n protected _diff(\n prev: unknown | undefined,\n next: unknown\n ): Operation[] | undefined {\n if (!next) {\n return undefined;\n }\n if (!prev) {\n return [{ op: \"replace\", path: \"\", value: next }];\n }\n return compare(prev, next);\n }\n\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n async parsePartialResult(\n generations: ChatGeneration[] | Generation[]\n ): Promise<T | undefined> {\n return parseJsonMarkdown(generations[0].text) as T | undefined;\n }\n\n async parse(text: string): Promise<T> {\n return parseJsonMarkdown(text, JSON.parse) as T;\n }\n\n getFormatInstructions(): string {\n return \"\";\n }\n\n /**\n * Extracts text content from a message for JSON parsing.\n * Uses the message's `.text` accessor which properly handles both\n * string content and ContentBlock[] arrays (extracting text from text blocks).\n * @param message The message to extract text from\n * @returns The text content of the message\n */\n protected _baseMessageToString(message: BaseMessage): string {\n return message.text;\n }\n}\n\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;AASA,IAAa,mBAAb,cAGUA,sDAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe,CAAC,kBAAkB,gBAAiB;CAEnD,kBAAkB;;CAGlB,AAAS,oBAAuBC,OAAUC,QAAc;AACtD,MAAI,KAAK,KACP,QAAO,MAAM,oBAAoB,OAAO,OAAO;AAEjD,SAAO;CACR;CAED,AAAU,MACRC,MACAC,MACyB;AACzB,MAAI,CAAC,KACH,QAAO;AAET,MAAI,CAAC,KACH,QAAO,CAAC;GAAE,IAAI;GAAW,MAAM;GAAI,OAAO;EAAM,CAAC;AAEnD,SAAOC,uBAAQ,MAAM,KAAK;CAC3B;CAID,MAAM,mBACJC,aACwB;AACxB,SAAOC,+BAAkB,YAAY,GAAG,KAAK;CAC9C;CAED,MAAM,MAAMC,MAA0B;AACpC,SAAOD,+BAAkB,MAAM,KAAK,MAAM;CAC3C;CAED,wBAAgC;AAC9B,SAAO;CACR;;;;;;;;CASD,AAAU,qBAAqBE,SAA8B;AAC3D,SAAO,QAAQ;CAChB;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BaseMessage } from "../messages/base.cjs";
|
|
1
2
|
import { ChatGeneration, Generation } from "../outputs.cjs";
|
|
2
3
|
import { Operation } from "../utils/fast-json-patch/src/core.cjs";
|
|
3
4
|
import { BaseCumulativeTransformOutputParser } from "./transform.cjs";
|
|
@@ -18,6 +19,14 @@ declare class JsonOutputParser<T extends Record<string, any> = Record<string, an
|
|
|
18
19
|
parsePartialResult(generations: ChatGeneration[] | Generation[]): Promise<T | undefined>;
|
|
19
20
|
parse(text: string): Promise<T>;
|
|
20
21
|
getFormatInstructions(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Extracts text content from a message for JSON parsing.
|
|
24
|
+
* Uses the message's `.text` accessor which properly handles both
|
|
25
|
+
* string content and ContentBlock[] arrays (extracting text from text blocks).
|
|
26
|
+
* @param message The message to extract text from
|
|
27
|
+
* @returns The text content of the message
|
|
28
|
+
*/
|
|
29
|
+
protected _baseMessageToString(message: BaseMessage): string;
|
|
21
30
|
}
|
|
22
31
|
//#endregion
|
|
23
32
|
export { JsonOutputParser };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.cts","names":["BaseCumulativeTransformOutputParser","Operation","ChatGeneration","Generation","parseJsonMarkdown","parsePartialJson","JsonOutputParser","T","Record","Promise"],"sources":["../../src/output_parsers/json.d.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport declare class JsonOutputParser<T extends Record<string, any> = Record<string, any>> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name(): string;\n lc_namespace: string[];\n lc_serializable: boolean;\n /** @internal */\n _concatOutputChunks<T>(first: T, second: T): T;\n protected _diff(prev: unknown | undefined, next: unknown): Operation[] | undefined;\n parsePartialResult(generations: ChatGeneration[] | Generation[]): Promise<T | undefined>;\n parse(text: string): Promise<T>;\n getFormatInstructions(): string;\n}\nexport { parsePartialJson, parseJsonMarkdown };\n//# sourceMappingURL=json.d.ts.map"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json.d.cts","names":["BaseCumulativeTransformOutputParser","Operation","ChatGeneration","Generation","parseJsonMarkdown","parsePartialJson","BaseMessage","JsonOutputParser","T","Record","Promise"],"sources":["../../src/output_parsers/json.d.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\nimport type { BaseMessage } from \"../messages/index.js\";\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport declare class JsonOutputParser<T extends Record<string, any> = Record<string, any>> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name(): string;\n lc_namespace: string[];\n lc_serializable: boolean;\n /** @internal */\n _concatOutputChunks<T>(first: T, second: T): T;\n protected _diff(prev: unknown | undefined, next: unknown): Operation[] | undefined;\n parsePartialResult(generations: ChatGeneration[] | Generation[]): Promise<T | undefined>;\n parse(text: string): Promise<T>;\n getFormatInstructions(): string;\n /**\n * Extracts text content from a message for JSON parsing.\n * Uses the message's `.text` accessor which properly handles both\n * string content and ContentBlock[] arrays (extracting text from text blocks).\n * @param message The message to extract text from\n * @returns The text content of the message\n */\n protected _baseMessageToString(message: BaseMessage): string;\n}\nexport { parsePartialJson, parseJsonMarkdown };\n//# sourceMappingURL=json.d.ts.map"],"mappings":";;;;;;;;;;AAQA;AAAgDS,cAA3BF,gBAA2BE,CAAAA,UAAAA,MAAAA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAAsBA,MAAtBA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,SAAmDT,mCAAnDS,CAAuFD,CAAvFC,CAAAA,CAAAA;EAAsBA,OAAAA,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAiED,YAAAA,EAAAA,MAAAA,EAAAA;EAKrGA,eAAAA,EAAAA,OAAAA;EAAWA;EAAIA,mBAAAA,CAAAA,CAAAA,CAAAA,CAAAA,KAAAA,EAAfA,CAAeA,EAAAA,MAAAA,EAAJA,CAAIA,CAAAA,EAAAA,CAAAA;EACcP,UAAAA,KAAAA,CAAAA,IAAAA,EAAAA,OAAAA,GAAAA,SAAAA,EAAAA,IAAAA,EAAAA,OAAAA,CAAAA,EAAAA,SAAAA,EAAAA,GAAAA,SAAAA;EAC3BC,kBAAAA,CAAAA,WAAAA,EAAAA,cAAAA,EAAAA,GAAmBC,UAAnBD,EAAAA,CAAAA,EAAkCQ,OAAlCR,CAA0CM,CAA1CN,GAAAA,SAAAA,CAAAA;EAAmBC,KAAAA,CAAAA,IAAAA,EAAAA,MAAAA,CAAAA,EAC9BO,OAD8BP,CACtBK,CADsBL,CAAAA;EAAuBK,qBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAARE;;;;;AAPgE;;0CAiB1FJ"}
|