@minded-ai/mindedjs 3.1.16 → 3.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/internalTools/documentExtraction/documentExtraction.d.ts.map +1 -1
- package/dist/internalTools/documentExtraction/documentExtraction.js +10 -0
- package/dist/internalTools/documentExtraction/documentExtraction.js.map +1 -1
- package/dist/internalTools/documentExtraction/extractStructuredData.d.ts.map +1 -1
- package/dist/internalTools/documentExtraction/extractStructuredData.js +6 -0
- package/dist/internalTools/documentExtraction/extractStructuredData.js.map +1 -1
- package/dist/nodes/addAppToolNode.js +1 -1
- package/dist/nodes/addAppToolNode.js.map +1 -1
- package/dist/nodes/addToolNode.js +1 -1
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/compilePrompt.d.ts +38 -6
- package/dist/nodes/compilePrompt.d.ts.map +1 -1
- package/dist/nodes/compilePrompt.js +203 -55
- package/dist/nodes/compilePrompt.js.map +1 -1
- package/dist/toolsLibrary/parseDocument.d.ts.map +1 -1
- package/dist/toolsLibrary/parseDocument.js +15 -6
- package/dist/toolsLibrary/parseDocument.js.map +1 -1
- package/package.json +2 -2
- package/src/internalTools/documentExtraction/documentExtraction.ts +11 -0
- package/src/internalTools/documentExtraction/extractStructuredData.ts +7 -0
- package/src/nodes/addAppToolNode.ts +1 -1
- package/src/nodes/addToolNode.ts +1 -1
- package/src/nodes/compilePrompt.ts +229 -58
- package/src/toolsLibrary/parseDocument.ts +15 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentExtraction.d.ts","sourceRoot":"","sources":["../../../src/internalTools/documentExtraction/documentExtraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,sBAAsB,EAAiB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"documentExtraction.d.ts","sourceRoot":"","sources":["../../../src/internalTools/documentExtraction/documentExtraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,sBAAsB,EAAiB,MAAM,iBAAiB,CAAC;AAGxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,wBAAsB,qCAAqC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EACzF,eAAe,EACf,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,sBAA8B,EAC9B,GAAG,EACH,YAAY,EACZ,kBAAkB,GACnB,EAAE;IACD,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,CAAC,EAAE,sBAAsB,CAAC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB,EAAE,OAAO,CAAC;IAChC,GAAG,CAAC,EAAE,iBAAiB,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,GAAG,OAAO,CAAC;IACV,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;CAChC,CAAC,CAsDD"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseDocumentAndExtractStructuredData = parseDocumentAndExtractStructuredData;
|
|
4
4
|
const extractStructuredData_1 = require("./extractStructuredData");
|
|
5
5
|
const parseDocument_1 = require("./parseDocument");
|
|
6
|
+
const logger_1 = require("../../utils/logger");
|
|
6
7
|
/**
|
|
7
8
|
* Parse document and extract structured data using AI.
|
|
8
9
|
*
|
|
@@ -74,6 +75,15 @@ const parseDocument_1 = require("./parseDocument");
|
|
|
74
75
|
* ```
|
|
75
76
|
*/
|
|
76
77
|
async function parseDocumentAndExtractStructuredData({ documentSources, processingMode, sessionId, llamaCloudApiKey, returnStructuredOutput = false, llm, outputSchema, outputSchemaPrompt, }) {
|
|
78
|
+
logger_1.logger.debug({
|
|
79
|
+
msg: 'parsing documents and extracting structured data',
|
|
80
|
+
sessionId,
|
|
81
|
+
documentSources,
|
|
82
|
+
processingMode,
|
|
83
|
+
returnStructuredOutput,
|
|
84
|
+
hasOutputSchema: !!outputSchema,
|
|
85
|
+
hasOutputSchemaPrompt: !!outputSchemaPrompt,
|
|
86
|
+
});
|
|
77
87
|
// Parse each document and concatenate results
|
|
78
88
|
const results = await Promise.all(documentSources.map((documentSource) => (0, parseDocument_1.parseDocument)({
|
|
79
89
|
documentSource,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentExtraction.js","sourceRoot":"","sources":["../../../src/internalTools/documentExtraction/documentExtraction.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"documentExtraction.js","sourceRoot":"","sources":["../../../src/internalTools/documentExtraction/documentExtraction.ts"],"names":[],"mappings":";;AA4EA,sFA2EC;AArJD,mEAA0E;AAC1E,mDAAwE;AACxE,+CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACI,KAAK,UAAU,qCAAqC,CAAgC,EACzF,eAAe,EACf,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,sBAAsB,GAAG,KAAK,EAC9B,GAAG,EACH,YAAY,EACZ,kBAAkB,GAUnB;IAIC,eAAM,CAAC,KAAK,CAAC;QACX,GAAG,EAAE,kDAAkD;QACvD,SAAS;QACT,eAAe;QACf,cAAc;QACd,sBAAsB;QACtB,eAAe,EAAE,CAAC,CAAC,YAAY;QAC/B,qBAAqB,EAAE,CAAC,CAAC,kBAAkB;KAC5C,CAAC,CAAC;IAEH,8CAA8C;IAC9C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,eAAe,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CACrC,IAAA,6BAAa,EAAC;QACZ,cAAc;QACd,cAAc;QACd,SAAS;QACT,gBAAgB;KACjB,CAAC,CACH,CACF,CAAC;IAEF,wEAAwE;IACxE,MAAM,mBAAmB,GAAG,OAAO;SAChC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;SACxB,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,MAAM,CAAC,CAAC;IAEhB,MAAM,MAAM,GAAG;QACb,UAAU,EAAE,mBAAmB;KAChC,CAAC;IAEF,IAAI,CAAC,sBAAsB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QAClD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;IACnH,CAAC;IAED,mDAAmD;IACnD,MAAM,iBAAiB,GAAG,MAAM,IAAA,uDAA+B,EAAI;QACjE,OAAO,EAAE,MAAM,CAAC,UAAW;QAC3B,GAAG;QACH,MAAM,EAAE,YAAY;QACpB,MAAM,EAAE,kBAAkB;QAC1B,SAAS;KACV,CAAC,CAAC;IAEH,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,iBAAiB;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractStructuredData.d.ts","sourceRoot":"","sources":["../../../src/internalTools/documentExtraction/extractStructuredData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAsB,+BAA+B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EACnF,OAAO,EACP,GAAG,EACH,MAAM,EACN,MAAM,EACN,SAAS,GACV,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,iBAAiB,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"extractStructuredData.d.ts","sourceRoot":"","sources":["../../../src/internalTools/documentExtraction/extractStructuredData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAsB,+BAA+B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EACnF,OAAO,EACP,GAAG,EACH,MAAM,EACN,MAAM,EACN,SAAS,GACV,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,iBAAiB,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,CA2EtB"}
|
|
@@ -53,6 +53,12 @@ async function extractStructuredDataFromString({ content, llm, schema, prompt, s
|
|
|
53
53
|
if (!llm) {
|
|
54
54
|
throw new Error('LLM instance is required for structured data extraction. Please provide an LLM when calling extractStructuredDataFromString.');
|
|
55
55
|
}
|
|
56
|
+
logger_1.logger.debug({
|
|
57
|
+
msg: 'extracting structured data from string',
|
|
58
|
+
sessionId,
|
|
59
|
+
hasSchema: !!schema,
|
|
60
|
+
hasPrompt: !!prompt,
|
|
61
|
+
});
|
|
56
62
|
const messages = [
|
|
57
63
|
{
|
|
58
64
|
role: 'system',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractStructuredData.js","sourceRoot":"","sources":["../../../src/internalTools/documentExtraction/extractStructuredData.ts"],"names":[],"mappings":";;AAmDA,
|
|
1
|
+
{"version":3,"file":"extractStructuredData.js","sourceRoot":"","sources":["../../../src/internalTools/documentExtraction/extractStructuredData.ts"],"names":[],"mappings":";;AAmDA,0EAuFC;AAzID,+CAA4C;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACI,KAAK,UAAU,+BAA+B,CAAgC,EACnF,OAAO,EACP,GAAG,EACH,MAAM,EACN,MAAM,EACN,SAAS,GAOV;IACC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,8HAA8H,CAC/H,CAAC;IACJ,CAAC;IAED,eAAM,CAAC,KAAK,CAAC;QACX,GAAG,EAAE,wCAAwC;QAC7C,SAAS;QACT,SAAS,EAAE,CAAC,CAAC,MAAM;QACnB,SAAS,EAAE,CAAC,CAAC,MAAM;KACpB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG;QACf;YACE,IAAI,EAAE,QAAQ;YACd,OAAO,EACL,+CAA+C;gBAC/C,wEAAwE;gBACxE,2FAA2F;gBAC3F,+CAA+C;gBAC/C,8FAA8F;SACjG;QACD;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,iEAAiE,OAAO,EAAE;SACnH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C;YAED,+DAA+D;YAC/D,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;YAE1C,eAAM,CAAC,KAAK,CAAC;gBACX,GAAG,EAAE,4DAA4D;gBACjE,SAAS;gBACT,aAAa,EAAE,WAAW;aAC3B,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChG,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC"}
|
|
@@ -32,7 +32,7 @@ const addAppToolNode = async ({ graph, node, llm, agent, tools, }) => {
|
|
|
32
32
|
if (value !== '') {
|
|
33
33
|
// If the value is a string, compile it to allow variable injection
|
|
34
34
|
if (typeof value === 'string') {
|
|
35
|
-
compiledParameters[key] = (0, compilePrompt_1.compileParameter)(value, compileContext);
|
|
35
|
+
compiledParameters[key] = (0, compilePrompt_1.compileParameter)(value, compileContext, key, appRunnerTool.input);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
compiledParameters[key] = value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addAppToolNode.js","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":";;;AAAA,sDAAwF;AACxF,iDAA8D;AAE9D,uDAAyD;AAMzD,4CAAyC;AACzC,8CAAqD;AAErD,sDAA0D;AAC1D,mDAAkE;AAClE,uDAAuD;AACvD,8DAA8D;AAC9D,0DAAiE;AAE1D,MAAM,cAAc,G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is a string, compile it to allow variable injection
|
|
40
40
|
if (typeof value === 'string') {
|
|
41
|
-
compiledParameters[key] = (0, compilePrompt_1.compileParameter)(value, compileContext);
|
|
41
|
+
compiledParameters[key] = (0, compilePrompt_1.compileParameter)(value, compileContext, key, matchedTool.input);
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
44
|
compiledParameters[key] = value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addToolNode.js","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":";;;AAAA,sDAAkF;AAClF,sDAAsD;AACtD,iDAA8D;AAE9D,uDAAoE;AAGpE,4CAAyC;AAEzC,8CAAqD;AAErD,sDAA0D;AAC1D,mDAAkE;AAClE,8DAA8D;AAC9D,0DAAiE;AACjE,6BAAwB;AAEjB,MAAM,WAAW,GAAG,KAAK,EAAE,EAChC,KAAK,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,KAAK,GAON,EAAE,EAAE;IACH,MAAM,QAAQ,GAAG,IAAgB,CAAC;IAClC,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC1E,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,mBAAmB,QAAQ,CAAC,QAAQ,YAAY,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/E,CAAC;IACD,MAAM,QAAQ,GAAiB,KAAK,EAAE,KAAmC,EAAE,EAAE;;QAC3E,IAAA,+BAAmB,EACjB,oCAAkB,CAAC,cAAc,EACjC;YACE,QAAQ,EAAE,sBAAQ,CAAC,IAAI;YACvB,QAAQ,EAAE,IAAI,CAAC,IAAI;YACnB,eAAe,EAAE,IAAI,CAAC,WAAW;YACjC,UAAU,EAAE;gBACV,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,MAAM,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C3C,CAAC;QACD,iBAAiB,CAAC,iBAAiB,CAAC,cAAc,GAAG;YACnD,QAAQ,EAAE,sBAAQ,CAAC,IAAI;YACvB,eAAe,EAAE,IAAI,CAAC,WAAW;YACjC,QAAQ,EAAE,WAAW,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,sBAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,sBAAQ,CAAC,OAAO;YACtE,SAAS,EAAE,KAAK,CAAC,SAAS;SACD,CAAC;QAE5B,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEvC,MAAM,UAAU,GAAG,IAAA,2BAAiB,EAAc,KAAK,CAAC,OAAO,EAAE;YAC/D,IAAI,EAAE,sBAAQ,CAAC,IAAI;YACnB,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,eAAe,EAAE,IAAI,CAAC,WAAW;YACjC,GAAG,EAAE,CAAA,MAAA,iBAAiB,CAAC,UAAU,0CAAG,CAAC,CAAC,KAAI,EAAE;YAC5C,UAAU,EAAE,CAAC,iBAAiB,CAAC,EAAG,CAAC;SACpC,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE/B,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAvMW,QAAA,WAAW,eAuMtB"}
|
|
@@ -1,13 +1,45 @@
|
|
|
1
|
+
import { ZodSchema } from 'zod';
|
|
2
|
+
import { State } from '../types/LangGraph.types';
|
|
3
|
+
export type ContextData = {
|
|
4
|
+
state?: State;
|
|
5
|
+
memory?: State['memory'];
|
|
6
|
+
env?: NodeJS.ProcessEnv;
|
|
7
|
+
input?: Record<string, any>;
|
|
8
|
+
steps?: string;
|
|
9
|
+
messages?: string;
|
|
10
|
+
};
|
|
11
|
+
export type ExtendedContextData = ContextData & {
|
|
12
|
+
system: {
|
|
13
|
+
currentTime: string;
|
|
14
|
+
};
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
1
17
|
/**
|
|
2
|
-
* Compile a
|
|
3
|
-
*
|
|
18
|
+
* Compile a parameter string with EJS templates and placeholders, returning the value
|
|
19
|
+
* in a native format matching the expected type in the provided inputSchema.
|
|
20
|
+
*
|
|
21
|
+
* This function processes the parameter string through multiple stages:
|
|
22
|
+
* 1. Renders EJS templates (e.g., `<%= 2 + 3 %>`)
|
|
23
|
+
* 2. Replaces placeholders in {key.path} format with context values
|
|
24
|
+
* 3. Extracts node outputs from state.history and state.messages (accessible as {NodeName.field} or {tools.NodeName.field})
|
|
25
|
+
* 4. Coerces the result to match the type defined in inputSchema (if provided)
|
|
26
|
+
*
|
|
27
|
+
* When the parameter contains a single placeholder (e.g., `{memory.value}`), the native value is returned.
|
|
28
|
+
* Otherwise, a string is returned with all placeholders replaced.
|
|
29
|
+
*
|
|
30
|
+
* @param parameter - The parameter string to compile, can contain EJS templates and {key.path} placeholders
|
|
31
|
+
* @param context - Context data including state, memory, env, and input. Node outputs are automatically extracted from state.
|
|
32
|
+
* @param inputKey - Optional key name in the inputSchema to use for type coercion
|
|
33
|
+
* @param inputSchema - Optional Zod schema to coerce the result to the expected type
|
|
34
|
+
* @returns The compiled parameter value in native format (string, number, boolean, array, object) or the original string on error
|
|
35
|
+
*
|
|
4
36
|
* @example
|
|
5
|
-
*
|
|
6
|
-
*
|
|
37
|
+
* compileParameter('Count: {memory.count}, Name: {memory.name}', { memory: { count: 5, name: 'test' } });
|
|
38
|
+
* // Returns "Count: 5, Name: test" (string)
|
|
7
39
|
*/
|
|
8
|
-
export declare function compileParameter(parameter: string, context?:
|
|
40
|
+
export declare function compileParameter(parameter: string, context?: ContextData, inputKey?: string, inputSchema?: ZodSchema): any;
|
|
9
41
|
/**
|
|
10
42
|
* Compile prompt with parameters using EJS and placeholder replacement
|
|
11
43
|
*/
|
|
12
|
-
export declare function compilePrompt(prompt: string,
|
|
44
|
+
export declare function compilePrompt(prompt: string, context: ContextData): string;
|
|
13
45
|
//# sourceMappingURL=compilePrompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilePrompt.d.ts","sourceRoot":"","sources":["../../src/nodes/compilePrompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compilePrompt.d.ts","sourceRoot":"","sources":["../../src/nodes/compilePrompt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAK,SAAS,EAAc,MAAM,KAAK,CAAC;AAG/C,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAwEjD,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG;IAC9C,MAAM,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,SAAS,GAAG,GAAG,CAyB9H;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAe1E"}
|
|
@@ -37,6 +37,7 @@ exports.compileParameter = compileParameter;
|
|
|
37
37
|
exports.compilePrompt = compilePrompt;
|
|
38
38
|
const ejs = __importStar(require("ejs"));
|
|
39
39
|
const lodash_1 = require("lodash");
|
|
40
|
+
const zod_1 = require("zod");
|
|
40
41
|
const logger_1 = require("../utils/logger");
|
|
41
42
|
/**
|
|
42
43
|
* Extract node outputs from state.history and state.messages
|
|
@@ -76,6 +77,13 @@ function extractNodeOutputs(state) {
|
|
|
76
77
|
logger_1.logger.debug({ message: 'Failed to parse tool message content', toolCallId, err });
|
|
77
78
|
}
|
|
78
79
|
},
|
|
80
|
+
appTool: (item) => {
|
|
81
|
+
var _a;
|
|
82
|
+
// appTool history entries store the result directly in raw.result
|
|
83
|
+
if (((_a = item.raw) === null || _a === void 0 ? void 0 : _a.result) !== undefined) {
|
|
84
|
+
setOutput(item, item.raw.result);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
79
87
|
thinking: (item) => {
|
|
80
88
|
var _a, _b;
|
|
81
89
|
const messageId = (_a = item.messageIds) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -98,31 +106,62 @@ function extractNodeOutputs(state) {
|
|
|
98
106
|
return outputs;
|
|
99
107
|
}
|
|
100
108
|
/**
|
|
101
|
-
* Compile a
|
|
102
|
-
*
|
|
109
|
+
* Compile a parameter string with EJS templates and placeholders, returning the value
|
|
110
|
+
* in a native format matching the expected type in the provided inputSchema.
|
|
111
|
+
*
|
|
112
|
+
* This function processes the parameter string through multiple stages:
|
|
113
|
+
* 1. Renders EJS templates (e.g., `<%= 2 + 3 %>`)
|
|
114
|
+
* 2. Replaces placeholders in {key.path} format with context values
|
|
115
|
+
* 3. Extracts node outputs from state.history and state.messages (accessible as {NodeName.field} or {tools.NodeName.field})
|
|
116
|
+
* 4. Coerces the result to match the type defined in inputSchema (if provided)
|
|
117
|
+
*
|
|
118
|
+
* When the parameter contains a single placeholder (e.g., `{memory.value}`), the native value is returned.
|
|
119
|
+
* Otherwise, a string is returned with all placeholders replaced.
|
|
120
|
+
*
|
|
121
|
+
* @param parameter - The parameter string to compile, can contain EJS templates and {key.path} placeholders
|
|
122
|
+
* @param context - Context data including state, memory, env, and input. Node outputs are automatically extracted from state.
|
|
123
|
+
* @param inputKey - Optional key name in the inputSchema to use for type coercion
|
|
124
|
+
* @param inputSchema - Optional Zod schema to coerce the result to the expected type
|
|
125
|
+
* @returns The compiled parameter value in native format (string, number, boolean, array, object) or the original string on error
|
|
126
|
+
*
|
|
103
127
|
* @example
|
|
104
|
-
*
|
|
105
|
-
*
|
|
128
|
+
* compileParameter('Count: {memory.count}, Name: {memory.name}', { memory: { count: 5, name: 'test' } });
|
|
129
|
+
* // Returns "Count: 5, Name: test" (string)
|
|
106
130
|
*/
|
|
107
|
-
function compileParameter(parameter, context = {}) {
|
|
108
|
-
const compiledPrompt = compilePrompt(parameter, context);
|
|
131
|
+
function compileParameter(parameter, context = {}, inputKey, inputSchema) {
|
|
109
132
|
try {
|
|
110
|
-
|
|
133
|
+
context = extendContextData(context);
|
|
134
|
+
// First, render with EJS
|
|
135
|
+
let compiledParameter = ejs.render(parameter, context).trim();
|
|
136
|
+
// Then, replace placeholders in {} format
|
|
137
|
+
// If the result contains only one set of curly braces, get the native value at that key path, e.g., {state.memory.arrayOfStrings} -> state.memory.arrayOfStrings
|
|
138
|
+
// Otherwise, compile it into a string.
|
|
139
|
+
const keyPathMatch = compiledParameter.match(/^\{([^}]+)}$/);
|
|
140
|
+
if (keyPathMatch) {
|
|
141
|
+
const keyPath = keyPathMatch[1];
|
|
142
|
+
compiledParameter = getContextValueFromPath(keyPath, context, compiledParameter);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
compiledParameter = replacePlaceholders(compiledParameter, context);
|
|
146
|
+
}
|
|
147
|
+
compiledParameter = coerceValueWithZodType(compiledParameter, inputKey, inputSchema);
|
|
148
|
+
return compiledParameter;
|
|
111
149
|
}
|
|
112
|
-
catch (
|
|
113
|
-
|
|
150
|
+
catch (err) {
|
|
151
|
+
logger_1.logger.error({ message: 'Error compiling parameter', err, parameter });
|
|
152
|
+
return parameter; // Return uncompiled if there's an error
|
|
114
153
|
}
|
|
115
154
|
}
|
|
116
155
|
/**
|
|
117
156
|
* Compile prompt with parameters using EJS and placeholder replacement
|
|
118
157
|
*/
|
|
119
|
-
function compilePrompt(prompt,
|
|
158
|
+
function compilePrompt(prompt, context) {
|
|
120
159
|
try {
|
|
121
|
-
|
|
160
|
+
context = extendContextData(context);
|
|
122
161
|
// First, render with EJS
|
|
123
|
-
let compiledPrompt = ejs.render(prompt,
|
|
162
|
+
let compiledPrompt = ejs.render(prompt, context);
|
|
124
163
|
// Then, replace placeholders in {} format
|
|
125
|
-
compiledPrompt = replacePlaceholders(compiledPrompt,
|
|
164
|
+
compiledPrompt = replacePlaceholders(compiledPrompt, context);
|
|
126
165
|
return compiledPrompt;
|
|
127
166
|
}
|
|
128
167
|
catch (err) {
|
|
@@ -131,57 +170,38 @@ function compilePrompt(prompt, params = {}) {
|
|
|
131
170
|
}
|
|
132
171
|
}
|
|
133
172
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
173
|
+
* Extend context data for prompt/parameters compilation.
|
|
174
|
+
*
|
|
175
|
+
* Extracts node outputs from state.history and state.messages, merging them into the context object.
|
|
176
|
+
* This enables placeholder replacement like {tools.NodeName.field} or {NodeName.field} by making
|
|
177
|
+
* previous node outputs available during compilation.
|
|
178
|
+
*
|
|
179
|
+
* Also adds system data like {system.currentTime} to the context.
|
|
180
|
+
*
|
|
181
|
+
* @param context - The base context data containing state, memory, env, and input
|
|
182
|
+
* @returns Extended context with node outputs merged in and system data added
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* // If ExtractUser node outputs { userName: "Bob", userAge: 35 }
|
|
186
|
+
* // The prompt "Hello {tools.ExtractUser.userName}" becomes "Hello Bob"
|
|
136
187
|
*/
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
...
|
|
188
|
+
function extendContextData(context = {}) {
|
|
189
|
+
const nodeOutputs = context.state ? extractNodeOutputs(context.state) : {};
|
|
190
|
+
return {
|
|
191
|
+
...context,
|
|
192
|
+
...nodeOutputs,
|
|
141
193
|
system: { currentTime: new Date().toISOString() },
|
|
142
194
|
};
|
|
143
|
-
// Extract node outputs from state if available
|
|
144
|
-
// This enables placeholder replacement like {tools.NodeName.field} or {NodeName.field}
|
|
145
|
-
// by making previous node outputs available in the params object.
|
|
146
|
-
// Example: If ExtractUser node outputs { userName: "Bob", userAge: 35 },
|
|
147
|
-
// the prompt "Hello {tools.ExtractUser.userName}" becomes "Hello Bob"
|
|
148
|
-
if (params.state) {
|
|
149
|
-
const nodeOutputs = extractNodeOutputs(params.state);
|
|
150
|
-
// Merge node outputs into params so they're accessible during placeholder replacement
|
|
151
|
-
params = { ...params, ...nodeOutputs };
|
|
152
|
-
}
|
|
153
|
-
return params;
|
|
154
195
|
}
|
|
155
196
|
/**
|
|
156
|
-
* Replace placeholders in {key} format
|
|
197
|
+
* Replace placeholders in {object.key} format
|
|
157
198
|
* Supports both:
|
|
158
199
|
* - {NodeName.field} - direct node reference
|
|
159
200
|
* - {tools.NodeName.field} - node reference with 'tools' prefix (alias)
|
|
160
201
|
*/
|
|
161
|
-
function replacePlaceholders(text,
|
|
162
|
-
return text.replace(/\{([^}]+)}/g, (match,
|
|
163
|
-
|
|
164
|
-
// Handle 'tools.' prefix as an alias for node outputs
|
|
165
|
-
// {tools.NodeName.field} -> {NodeName.field}
|
|
166
|
-
if (keys[0] === 'tools' && keys.length >= 3) {
|
|
167
|
-
keys = keys.slice(1); // Remove 'tools' prefix
|
|
168
|
-
}
|
|
169
|
-
let value = params;
|
|
170
|
-
for (let i = 0; i < keys.length; i++) {
|
|
171
|
-
const k = keys[i];
|
|
172
|
-
if (value && Array.isArray(value) && k !== '' && Number.isInteger(Number(k))) {
|
|
173
|
-
value = value[Number(k)];
|
|
174
|
-
}
|
|
175
|
-
else if (value && typeof value === 'object' && k in value) {
|
|
176
|
-
value = value[k];
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
logger_1.logger.warn({
|
|
180
|
-
message: `Placeholder {${key}} in prompt not found in params. It will remain as placeholder.`,
|
|
181
|
-
});
|
|
182
|
-
return match; // Return original if key not found
|
|
183
|
-
}
|
|
184
|
-
}
|
|
202
|
+
function replacePlaceholders(text, context) {
|
|
203
|
+
return text.replace(/\{([^}]+)}/g, (match, keyPath) => {
|
|
204
|
+
const value = getContextValueFromPath(keyPath, context, match);
|
|
185
205
|
// In the case of complex values (e.g., arrays or objects), JSON stringify them to ensure all data is preserved.
|
|
186
206
|
if (Array.isArray(value) || (typeof value === 'object' && value !== null)) {
|
|
187
207
|
try {
|
|
@@ -194,4 +214,132 @@ function replacePlaceholders(text, params) {
|
|
|
194
214
|
return String(value);
|
|
195
215
|
});
|
|
196
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Get value from a context object using dot notation path.
|
|
219
|
+
*
|
|
220
|
+
* Tool output placeholders can be in the form of {NodeName.field} or {tools.NodeName.field}.
|
|
221
|
+
*
|
|
222
|
+
* @param keyPath Dot notation and array-notation path to the value, e.g., "NodeName.array[1].field".
|
|
223
|
+
* @param context Context object to search in
|
|
224
|
+
* @param dft Default value to return if key not found
|
|
225
|
+
* @returns Value from context object or default value if not found
|
|
226
|
+
* @example
|
|
227
|
+
*/
|
|
228
|
+
function getContextValueFromPath(keyPath, context, dft) {
|
|
229
|
+
let propPath = (0, lodash_1.toPath)(keyPath);
|
|
230
|
+
// Remove the 'tools.' prefix as an alias for node outputs
|
|
231
|
+
// {tools.NodeName.field} -> {NodeName.field}
|
|
232
|
+
if (propPath[0] === 'tools' && propPath.length >= 3) {
|
|
233
|
+
propPath = propPath.slice(1); // Remove 'tools' prefix
|
|
234
|
+
}
|
|
235
|
+
let value = context;
|
|
236
|
+
for (const propName of propPath) {
|
|
237
|
+
if (value && Array.isArray(value) && propName !== '' && Number.isInteger(Number(propName))) {
|
|
238
|
+
value = value[Number(propName)];
|
|
239
|
+
}
|
|
240
|
+
else if (value && typeof value === 'object' && propName in value) {
|
|
241
|
+
value = value[propName];
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
// The prompt may include a JSON serialized object, e.g.,:
|
|
245
|
+
// Parameters manually configured by the user are: {"...":"..."}
|
|
246
|
+
// In this case this is not a valid placeholder, so we should not warn.
|
|
247
|
+
if (!keyPath.startsWith('"')) {
|
|
248
|
+
logger_1.logger.warn({
|
|
249
|
+
message: `Placeholder {${keyPath}} not found in context data. It will remain as placeholder.`,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return dft; // Return default if key not found
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Coerce a value to a native type matching the provided ZodSchema, if possible.
|
|
259
|
+
* @param value
|
|
260
|
+
* @param inputKey
|
|
261
|
+
* @param inputSchema
|
|
262
|
+
*/
|
|
263
|
+
function coerceValueWithZodType(value, inputKey, inputSchema) {
|
|
264
|
+
if (!inputKey || !(inputSchema instanceof zod_1.z.ZodObject)) {
|
|
265
|
+
return value;
|
|
266
|
+
}
|
|
267
|
+
const zodShape = inputSchema.shape;
|
|
268
|
+
if (!zodShape || !(inputKey in zodShape)) {
|
|
269
|
+
return value;
|
|
270
|
+
}
|
|
271
|
+
const keySchema = zodShape[inputKey];
|
|
272
|
+
const schemaType = keySchema._def.typeName;
|
|
273
|
+
let coercedValue = value;
|
|
274
|
+
switch (schemaType) {
|
|
275
|
+
case zod_1.z.ZodFirstPartyTypeKind.ZodString:
|
|
276
|
+
// Coerce to string if it is not already a string
|
|
277
|
+
if (typeof value !== 'string') {
|
|
278
|
+
coercedValue = String(value);
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
case zod_1.z.ZodFirstPartyTypeKind.ZodNumber:
|
|
282
|
+
// Coerce to number from string only if it is a valid number
|
|
283
|
+
if (typeof value === 'string' && value !== '') {
|
|
284
|
+
const num = Number(value);
|
|
285
|
+
if (!isNaN(num)) {
|
|
286
|
+
coercedValue = num;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
case zod_1.z.ZodFirstPartyTypeKind.ZodBoolean:
|
|
291
|
+
// Coerce to boolean only if the value is a string "true" or "false"
|
|
292
|
+
if (value === 'true') {
|
|
293
|
+
coercedValue = true;
|
|
294
|
+
}
|
|
295
|
+
else if (value === 'false') {
|
|
296
|
+
coercedValue = false;
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
case zod_1.z.ZodFirstPartyTypeKind.ZodArray:
|
|
300
|
+
// Coerce to array
|
|
301
|
+
if (typeof value === 'string') {
|
|
302
|
+
try {
|
|
303
|
+
const parsed = JSON.parse(value);
|
|
304
|
+
if (Array.isArray(parsed)) {
|
|
305
|
+
coercedValue = parsed;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
catch (_a) {
|
|
309
|
+
// Not valid JSON, keep as is
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
break;
|
|
313
|
+
case zod_1.z.ZodFirstPartyTypeKind.ZodObject:
|
|
314
|
+
// Coerce to object
|
|
315
|
+
if (typeof value === 'string') {
|
|
316
|
+
try {
|
|
317
|
+
const parsed = JSON.parse(value);
|
|
318
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
319
|
+
coercedValue = parsed;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
catch (_b) {
|
|
323
|
+
// Not valid JSON, keep as is
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
break;
|
|
327
|
+
default:
|
|
328
|
+
// For other types, keep the original value
|
|
329
|
+
coercedValue = value;
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
// Validate the coerced value against the schema
|
|
333
|
+
const parseResult = keySchema.safeParse(coercedValue);
|
|
334
|
+
if (parseResult.success) {
|
|
335
|
+
return coercedValue;
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
logger_1.logger.warn({
|
|
339
|
+
message: `Failed to coerce parameter's value for key "${inputKey}" to the type defined by the input schema. Error: ${parseResult.error.message}. Using the original value instead.`,
|
|
340
|
+
value,
|
|
341
|
+
});
|
|
342
|
+
return value;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
197
345
|
//# sourceMappingURL=compilePrompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilePrompt.js","sourceRoot":"","sources":["../../src/nodes/compilePrompt.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"compilePrompt.js","sourceRoot":"","sources":["../../src/nodes/compilePrompt.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHA,4CAyBC;AAKD,sCAeC;AA/JD,yCAA2B;AAC3B,mCAAgC;AAChC,6BAA+C;AAC/C,4CAAyC;AAIzC;;;GAGG;AACH,SAAS,kBAAkB,CAAC,KAAU;;IACpC,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAA,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,CAAA,EAAE,CAAC;QACxC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,OAAO,GAAwB,EAAE,CAAC;IAExC,oCAAoC;IACpC,MAAM,cAAc,GAAG;QACrB,IAAI,EAAE,IAAI,GAAG,CACX,KAAK,CAAC,QAAQ;aACX,MAAM,CAAC,CAAC,GAAQ,EAAE,EAAE,WAAC,OAAA,CAAA,MAAA,GAAG,CAAC,WAAW,0CAAE,IAAI,MAAK,aAAa,IAAI,GAAG,CAAC,YAAY,CAAA,EAAA,CAAC;aACjF,GAAG,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAC9C;QACD,EAAE,EAA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E,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAO5C,eAAO,MAAM,MAAM;;;;;;;;;EAKjB,CAAC;AAEH;;;;;;;GAOG;AACH,QAAA,MAAM,iBAAiB,EAAE,IAAI,CAAC,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"parseDocument.d.ts","sourceRoot":"","sources":["../../src/toolsLibrary/parseDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAO5C,eAAO,MAAM,MAAM;;;;;;;;;EAKjB,CAAC;AAEH;;;;;;;GAOG;AACH,QAAA,MAAM,iBAAiB,EAAE,IAAI,CAAC,OAAO,MAAM,CAwE1C,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -35,14 +35,23 @@ const parseDocumentTool = {
|
|
|
35
35
|
if (!input.documentSource || input.documentSource.length === 0) {
|
|
36
36
|
throw new Error('documentSource is required - provide a URL, file path, or array of URLs/file paths');
|
|
37
37
|
}
|
|
38
|
-
const node = await agent.getCurrentNode(state.sessionId);
|
|
39
|
-
const appToolNode = (node === null || node === void 0 ? void 0 : node.type) === Flows_types_1.NodeType.APP_TOOL ? node : undefined;
|
|
40
38
|
// Get processing mode from environment variable
|
|
41
39
|
const processingMode = process.env.DOCUMENT_PROCESSING_MODE === 'local' ? parseDocument_1.DocumentProcessingMode.LOCAL : parseDocument_1.DocumentProcessingMode.MANAGED;
|
|
42
40
|
const llamaCloudApiKey = process.env.LLAMA_CLOUD_API_KEY;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const node = await agent.getCurrentNode(state.sessionId);
|
|
42
|
+
const appToolNode = (node === null || node === void 0 ? void 0 : node.type) === Flows_types_1.NodeType.APP_TOOL ? node : undefined;
|
|
43
|
+
let outputSchema;
|
|
44
|
+
if (!appToolNode) {
|
|
45
|
+
logger_1.logger.error({
|
|
46
|
+
msg: `[minded-parse-documents] Current node was not found or not an appTool. Output schema could not be inferred. Will use unstructured output.`,
|
|
47
|
+
nodeType: node === null || node === void 0 ? void 0 : node.type,
|
|
48
|
+
nodeName: node === null || node === void 0 ? void 0 : node.name,
|
|
49
|
+
sessionId: state.sessionId,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else if (input.returnStructuredOutput && agent.llm && ((_a = appToolNode.outputSchema) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
53
|
+
outputSchema = (0, schemaUtils_1.createZodSchemaFromFields)(appToolNode.outputSchema);
|
|
54
|
+
}
|
|
46
55
|
const documentSources = Array.isArray(input.documentSource) ? input.documentSource : [input.documentSource];
|
|
47
56
|
const result = await (0, documentExtraction_1.parseDocumentAndExtractStructuredData)({
|
|
48
57
|
documentSources,
|
|
@@ -67,7 +76,7 @@ const parseDocumentTool = {
|
|
|
67
76
|
}
|
|
68
77
|
catch (err) {
|
|
69
78
|
logger_1.logger.error({
|
|
70
|
-
message: 'Failed to parse document',
|
|
79
|
+
message: '[minded-parse-documents] Failed to parse document',
|
|
71
80
|
sessionId: state.sessionId,
|
|
72
81
|
err,
|
|
73
82
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDocument.js","sourceRoot":"","sources":["../../src/toolsLibrary/parseDocument.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,+FAA+G;AAC/G,qFAA2F;AAC3F,4CAAyC;AACzC,sDAAgD;AAChD,sDAAiE;AAEpD,QAAA,MAAM,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7B,cAAc,EAAE,OAAC;SACd,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;SACxC,QAAQ,CAAC,sGAAsG,CAAC;IACnH,sBAAsB,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO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AC5D,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,GAAG;aACJ,CAAC,CAAC;YAEH,KAAK,CAAC,MAAM,CAAC,oBAAoB,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAErF,OAAO;gBACL,MAAM,EAAE,6BAA6B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;aACxF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC;AAEF,kBAAe,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minded-ai/mindedjs",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.17",
|
|
4
4
|
"description": "MindedJS is a TypeScript library for building agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -76,4 +76,4 @@
|
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"playwright": "^1.55.0"
|
|
78
78
|
}
|
|
79
|
-
}
|
|
79
|
+
}
|
|
@@ -2,6 +2,7 @@ import { ZodType } from 'zod';
|
|
|
2
2
|
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
3
3
|
import { extractStructuredDataFromString } from './extractStructuredData';
|
|
4
4
|
import { DocumentProcessingMode, parseDocument } from './parseDocument';
|
|
5
|
+
import { logger } from '../../utils/logger';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Parse document and extract structured data using AI.
|
|
@@ -95,6 +96,16 @@ export async function parseDocumentAndExtractStructuredData<T extends Record<str
|
|
|
95
96
|
rawContent?: string;
|
|
96
97
|
structuredContent?: T | string;
|
|
97
98
|
}> {
|
|
99
|
+
logger.debug({
|
|
100
|
+
msg: 'parsing documents and extracting structured data',
|
|
101
|
+
sessionId,
|
|
102
|
+
documentSources,
|
|
103
|
+
processingMode,
|
|
104
|
+
returnStructuredOutput,
|
|
105
|
+
hasOutputSchema: !!outputSchema,
|
|
106
|
+
hasOutputSchemaPrompt: !!outputSchemaPrompt,
|
|
107
|
+
});
|
|
108
|
+
|
|
98
109
|
// Parse each document and concatenate results
|
|
99
110
|
const results = await Promise.all(
|
|
100
111
|
documentSources.map((documentSource) =>
|
|
@@ -68,6 +68,13 @@ export async function extractStructuredDataFromString<T extends Record<string, a
|
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
logger.debug({
|
|
72
|
+
msg: 'extracting structured data from string',
|
|
73
|
+
sessionId,
|
|
74
|
+
hasSchema: !!schema,
|
|
75
|
+
hasPrompt: !!prompt,
|
|
76
|
+
});
|
|
77
|
+
|
|
71
78
|
const messages = [
|
|
72
79
|
{
|
|
73
80
|
role: 'system',
|
|
@@ -57,7 +57,7 @@ export const addAppToolNode = async ({
|
|
|
57
57
|
if (value !== '') {
|
|
58
58
|
// If the value is a string, compile it to allow variable injection
|
|
59
59
|
if (typeof value === 'string') {
|
|
60
|
-
compiledParameters[key] = compileParameter(value, compileContext);
|
|
60
|
+
compiledParameters[key] = compileParameter(value, compileContext, key, appRunnerTool.input);
|
|
61
61
|
} else {
|
|
62
62
|
compiledParameters[key] = value;
|
|
63
63
|
}
|
package/src/nodes/addToolNode.ts
CHANGED
|
@@ -58,7 +58,7 @@ export const addToolNode = async ({
|
|
|
58
58
|
if (value !== '') {
|
|
59
59
|
// If the value is a string, compile it to allow variable injection
|
|
60
60
|
if (typeof value === 'string') {
|
|
61
|
-
compiledParameters[key] = compileParameter(value, compileContext);
|
|
61
|
+
compiledParameters[key] = compileParameter(value, compileContext, key, matchedTool.input);
|
|
62
62
|
} else {
|
|
63
63
|
compiledParameters[key] = value;
|
|
64
64
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as ejs from 'ejs';
|
|
2
2
|
import { toPath } from 'lodash';
|
|
3
|
+
import { z, ZodSchema, ZodTypeAny } from 'zod';
|
|
3
4
|
import { logger } from '../utils/logger';
|
|
4
5
|
import { HistoryStep } from '../types/Agent.types';
|
|
6
|
+
import { State } from '../types/LangGraph.types';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Extract node outputs from state.history and state.messages
|
|
@@ -43,6 +45,13 @@ function extractNodeOutputs(state: any): Record<string, any> {
|
|
|
43
45
|
}
|
|
44
46
|
},
|
|
45
47
|
|
|
48
|
+
appTool: (item: any) => {
|
|
49
|
+
// appTool history entries store the result directly in raw.result
|
|
50
|
+
if (item.raw?.result !== undefined) {
|
|
51
|
+
setOutput(item, item.raw.result);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
|
|
46
55
|
thinking: (item) => {
|
|
47
56
|
const messageId = item.messageIds?.[0];
|
|
48
57
|
if (!messageId) return;
|
|
@@ -66,34 +75,82 @@ function extractNodeOutputs(state: any): Record<string, any> {
|
|
|
66
75
|
return outputs;
|
|
67
76
|
}
|
|
68
77
|
|
|
78
|
+
export type ContextData = {
|
|
79
|
+
state?: State;
|
|
80
|
+
memory?: State['memory'];
|
|
81
|
+
env?: NodeJS.ProcessEnv;
|
|
82
|
+
input?: Record<string, any>;
|
|
83
|
+
steps?: string;
|
|
84
|
+
messages?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type ExtendedContextData = ContextData & {
|
|
88
|
+
system: { currentTime: string };
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
};
|
|
91
|
+
|
|
69
92
|
/**
|
|
70
|
-
* Compile a
|
|
71
|
-
*
|
|
93
|
+
* Compile a parameter string with EJS templates and placeholders, returning the value
|
|
94
|
+
* in a native format matching the expected type in the provided inputSchema.
|
|
95
|
+
*
|
|
96
|
+
* This function processes the parameter string through multiple stages:
|
|
97
|
+
* 1. Renders EJS templates (e.g., `<%= 2 + 3 %>`)
|
|
98
|
+
* 2. Replaces placeholders in {key.path} format with context values
|
|
99
|
+
* 3. Extracts node outputs from state.history and state.messages (accessible as {NodeName.field} or {tools.NodeName.field})
|
|
100
|
+
* 4. Coerces the result to match the type defined in inputSchema (if provided)
|
|
101
|
+
*
|
|
102
|
+
* When the parameter contains a single placeholder (e.g., `{memory.value}`), the native value is returned.
|
|
103
|
+
* Otherwise, a string is returned with all placeholders replaced.
|
|
104
|
+
*
|
|
105
|
+
* @param parameter - The parameter string to compile, can contain EJS templates and {key.path} placeholders
|
|
106
|
+
* @param context - Context data including state, memory, env, and input. Node outputs are automatically extracted from state.
|
|
107
|
+
* @param inputKey - Optional key name in the inputSchema to use for type coercion
|
|
108
|
+
* @param inputSchema - Optional Zod schema to coerce the result to the expected type
|
|
109
|
+
* @returns The compiled parameter value in native format (string, number, boolean, array, object) or the original string on error
|
|
110
|
+
*
|
|
72
111
|
* @example
|
|
73
|
-
*
|
|
74
|
-
*
|
|
112
|
+
* compileParameter('Count: {memory.count}, Name: {memory.name}', { memory: { count: 5, name: 'test' } });
|
|
113
|
+
* // Returns "Count: 5, Name: test" (string)
|
|
75
114
|
*/
|
|
76
|
-
export function compileParameter(parameter: string, context:
|
|
77
|
-
const compiledPrompt = compilePrompt(parameter, context);
|
|
115
|
+
export function compileParameter(parameter: string, context: ContextData = {}, inputKey?: string, inputSchema?: ZodSchema): any {
|
|
78
116
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
117
|
+
context = extendContextData(context);
|
|
118
|
+
|
|
119
|
+
// First, render with EJS
|
|
120
|
+
let compiledParameter = ejs.render(parameter, context).trim();
|
|
121
|
+
|
|
122
|
+
// Then, replace placeholders in {} format
|
|
123
|
+
// If the result contains only one set of curly braces, get the native value at that key path, e.g., {state.memory.arrayOfStrings} -> state.memory.arrayOfStrings
|
|
124
|
+
// Otherwise, compile it into a string.
|
|
125
|
+
const keyPathMatch = compiledParameter.match(/^\{([^}]+)}$/);
|
|
126
|
+
if (keyPathMatch) {
|
|
127
|
+
const keyPath = keyPathMatch[1];
|
|
128
|
+
compiledParameter = getContextValueFromPath(keyPath, context, compiledParameter);
|
|
129
|
+
} else {
|
|
130
|
+
compiledParameter = replacePlaceholders(compiledParameter, context);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
compiledParameter = coerceValueWithZodType(compiledParameter, inputKey, inputSchema);
|
|
134
|
+
|
|
135
|
+
return compiledParameter;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
logger.error({ message: 'Error compiling parameter', err, parameter });
|
|
138
|
+
return parameter; // Return uncompiled if there's an error
|
|
82
139
|
}
|
|
83
140
|
}
|
|
84
141
|
|
|
85
142
|
/**
|
|
86
143
|
* Compile prompt with parameters using EJS and placeholder replacement
|
|
87
144
|
*/
|
|
88
|
-
export function compilePrompt(prompt: string,
|
|
145
|
+
export function compilePrompt(prompt: string, context: ContextData): string {
|
|
89
146
|
try {
|
|
90
|
-
|
|
147
|
+
context = extendContextData(context);
|
|
91
148
|
|
|
92
149
|
// First, render with EJS
|
|
93
|
-
let compiledPrompt = ejs.render(prompt,
|
|
150
|
+
let compiledPrompt = ejs.render(prompt, context);
|
|
94
151
|
|
|
95
152
|
// Then, replace placeholders in {} format
|
|
96
|
-
compiledPrompt = replacePlaceholders(compiledPrompt,
|
|
153
|
+
compiledPrompt = replacePlaceholders(compiledPrompt, context);
|
|
97
154
|
|
|
98
155
|
return compiledPrompt;
|
|
99
156
|
} catch (err) {
|
|
@@ -103,61 +160,39 @@ export function compilePrompt(prompt: string, params: Record<string, any> = {}):
|
|
|
103
160
|
}
|
|
104
161
|
|
|
105
162
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
163
|
+
* Extend context data for prompt/parameters compilation.
|
|
164
|
+
*
|
|
165
|
+
* Extracts node outputs from state.history and state.messages, merging them into the context object.
|
|
166
|
+
* This enables placeholder replacement like {tools.NodeName.field} or {NodeName.field} by making
|
|
167
|
+
* previous node outputs available during compilation.
|
|
168
|
+
*
|
|
169
|
+
* Also adds system data like {system.currentTime} to the context.
|
|
170
|
+
*
|
|
171
|
+
* @param context - The base context data containing state, memory, env, and input
|
|
172
|
+
* @returns Extended context with node outputs merged in and system data added
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* // If ExtractUser node outputs { userName: "Bob", userAge: 35 }
|
|
176
|
+
* // The prompt "Hello {tools.ExtractUser.userName}" becomes "Hello Bob"
|
|
108
177
|
*/
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
...
|
|
178
|
+
function extendContextData(context: ContextData = {}): ExtendedContextData {
|
|
179
|
+
const nodeOutputs = context.state ? extractNodeOutputs(context.state) : {};
|
|
180
|
+
return {
|
|
181
|
+
...context,
|
|
182
|
+
...nodeOutputs,
|
|
113
183
|
system: { currentTime: new Date().toISOString() },
|
|
114
184
|
};
|
|
115
|
-
|
|
116
|
-
// Extract node outputs from state if available
|
|
117
|
-
// This enables placeholder replacement like {tools.NodeName.field} or {NodeName.field}
|
|
118
|
-
// by making previous node outputs available in the params object.
|
|
119
|
-
// Example: If ExtractUser node outputs { userName: "Bob", userAge: 35 },
|
|
120
|
-
// the prompt "Hello {tools.ExtractUser.userName}" becomes "Hello Bob"
|
|
121
|
-
if (params.state) {
|
|
122
|
-
const nodeOutputs = extractNodeOutputs(params.state);
|
|
123
|
-
// Merge node outputs into params so they're accessible during placeholder replacement
|
|
124
|
-
params = { ...params, ...nodeOutputs };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return params;
|
|
128
185
|
}
|
|
129
186
|
|
|
130
187
|
/**
|
|
131
|
-
* Replace placeholders in {key} format
|
|
188
|
+
* Replace placeholders in {object.key} format
|
|
132
189
|
* Supports both:
|
|
133
190
|
* - {NodeName.field} - direct node reference
|
|
134
191
|
* - {tools.NodeName.field} - node reference with 'tools' prefix (alias)
|
|
135
192
|
*/
|
|
136
|
-
function replacePlaceholders(text: string,
|
|
137
|
-
return text.replace(/\{([^}]+)}/g, (match,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// Handle 'tools.' prefix as an alias for node outputs
|
|
141
|
-
// {tools.NodeName.field} -> {NodeName.field}
|
|
142
|
-
if (keys[0] === 'tools' && keys.length >= 3) {
|
|
143
|
-
keys = keys.slice(1); // Remove 'tools' prefix
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
let value: any = params;
|
|
147
|
-
|
|
148
|
-
for (let i = 0; i < keys.length; i++) {
|
|
149
|
-
const k = keys[i];
|
|
150
|
-
if (value && Array.isArray(value) && k !== '' && Number.isInteger(Number(k))) {
|
|
151
|
-
value = value[Number(k)];
|
|
152
|
-
} else if (value && typeof value === 'object' && k in value) {
|
|
153
|
-
value = value[k];
|
|
154
|
-
} else {
|
|
155
|
-
logger.warn({
|
|
156
|
-
message: `Placeholder {${key}} in prompt not found in params. It will remain as placeholder.`,
|
|
157
|
-
});
|
|
158
|
-
return match; // Return original if key not found
|
|
159
|
-
}
|
|
160
|
-
}
|
|
193
|
+
function replacePlaceholders(text: string, context: Record<string, any>): string {
|
|
194
|
+
return text.replace(/\{([^}]+)}/g, (match, keyPath) => {
|
|
195
|
+
const value = getContextValueFromPath(keyPath, context, match);
|
|
161
196
|
|
|
162
197
|
// In the case of complex values (e.g., arrays or objects), JSON stringify them to ensure all data is preserved.
|
|
163
198
|
if (Array.isArray(value) || (typeof value === 'object' && value !== null)) {
|
|
@@ -170,3 +205,139 @@ function replacePlaceholders(text: string, params: Record<string, any>): string
|
|
|
170
205
|
return String(value);
|
|
171
206
|
});
|
|
172
207
|
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Get value from a context object using dot notation path.
|
|
211
|
+
*
|
|
212
|
+
* Tool output placeholders can be in the form of {NodeName.field} or {tools.NodeName.field}.
|
|
213
|
+
*
|
|
214
|
+
* @param keyPath Dot notation and array-notation path to the value, e.g., "NodeName.array[1].field".
|
|
215
|
+
* @param context Context object to search in
|
|
216
|
+
* @param dft Default value to return if key not found
|
|
217
|
+
* @returns Value from context object or default value if not found
|
|
218
|
+
* @example
|
|
219
|
+
*/
|
|
220
|
+
function getContextValueFromPath(keyPath: string, context: Record<string, any>, dft: string): any {
|
|
221
|
+
let propPath = toPath(keyPath);
|
|
222
|
+
|
|
223
|
+
// Remove the 'tools.' prefix as an alias for node outputs
|
|
224
|
+
// {tools.NodeName.field} -> {NodeName.field}
|
|
225
|
+
if (propPath[0] === 'tools' && propPath.length >= 3) {
|
|
226
|
+
propPath = propPath.slice(1); // Remove 'tools' prefix
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
let value: any = context;
|
|
230
|
+
|
|
231
|
+
for (const propName of propPath) {
|
|
232
|
+
if (value && Array.isArray(value) && propName !== '' && Number.isInteger(Number(propName))) {
|
|
233
|
+
value = value[Number(propName)];
|
|
234
|
+
} else if (value && typeof value === 'object' && propName in value) {
|
|
235
|
+
value = value[propName];
|
|
236
|
+
} else {
|
|
237
|
+
// The prompt may include a JSON serialized object, e.g.,:
|
|
238
|
+
// Parameters manually configured by the user are: {"...":"..."}
|
|
239
|
+
// In this case this is not a valid placeholder, so we should not warn.
|
|
240
|
+
if (!keyPath.startsWith('"')) {
|
|
241
|
+
logger.warn({
|
|
242
|
+
message: `Placeholder {${keyPath}} not found in context data. It will remain as placeholder.`,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return dft; // Return default if key not found
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return value;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Coerce a value to a native type matching the provided ZodSchema, if possible.
|
|
254
|
+
* @param value
|
|
255
|
+
* @param inputKey
|
|
256
|
+
* @param inputSchema
|
|
257
|
+
*/
|
|
258
|
+
function coerceValueWithZodType(value: any, inputKey?: string, inputSchema?: ZodSchema) {
|
|
259
|
+
if (!inputKey || !(inputSchema instanceof z.ZodObject)) {
|
|
260
|
+
return value;
|
|
261
|
+
}
|
|
262
|
+
const zodShape: Record<string, ZodTypeAny> = inputSchema.shape;
|
|
263
|
+
if (!zodShape || !(inputKey in zodShape)) {
|
|
264
|
+
return value;
|
|
265
|
+
}
|
|
266
|
+
const keySchema: ZodTypeAny = zodShape[inputKey];
|
|
267
|
+
|
|
268
|
+
const schemaType = keySchema._def.typeName;
|
|
269
|
+
let coercedValue: any = value;
|
|
270
|
+
|
|
271
|
+
switch (schemaType) {
|
|
272
|
+
case z.ZodFirstPartyTypeKind.ZodString:
|
|
273
|
+
// Coerce to string if it is not already a string
|
|
274
|
+
if (typeof value !== 'string') {
|
|
275
|
+
coercedValue = String(value);
|
|
276
|
+
}
|
|
277
|
+
break;
|
|
278
|
+
|
|
279
|
+
case z.ZodFirstPartyTypeKind.ZodNumber:
|
|
280
|
+
// Coerce to number from string only if it is a valid number
|
|
281
|
+
if (typeof value === 'string' && value !== '') {
|
|
282
|
+
const num = Number(value);
|
|
283
|
+
if (!isNaN(num)) {
|
|
284
|
+
coercedValue = num;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
break;
|
|
288
|
+
|
|
289
|
+
case z.ZodFirstPartyTypeKind.ZodBoolean:
|
|
290
|
+
// Coerce to boolean only if the value is a string "true" or "false"
|
|
291
|
+
if (value === 'true') {
|
|
292
|
+
coercedValue = true;
|
|
293
|
+
} else if (value === 'false') {
|
|
294
|
+
coercedValue = false;
|
|
295
|
+
}
|
|
296
|
+
break;
|
|
297
|
+
|
|
298
|
+
case z.ZodFirstPartyTypeKind.ZodArray:
|
|
299
|
+
// Coerce to array
|
|
300
|
+
if (typeof value === 'string') {
|
|
301
|
+
try {
|
|
302
|
+
const parsed = JSON.parse(value);
|
|
303
|
+
if (Array.isArray(parsed)) {
|
|
304
|
+
coercedValue = parsed;
|
|
305
|
+
}
|
|
306
|
+
} catch {
|
|
307
|
+
// Not valid JSON, keep as is
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
break;
|
|
311
|
+
|
|
312
|
+
case z.ZodFirstPartyTypeKind.ZodObject:
|
|
313
|
+
// Coerce to object
|
|
314
|
+
if (typeof value === 'string') {
|
|
315
|
+
try {
|
|
316
|
+
const parsed = JSON.parse(value);
|
|
317
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
318
|
+
coercedValue = parsed;
|
|
319
|
+
}
|
|
320
|
+
} catch {
|
|
321
|
+
// Not valid JSON, keep as is
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
break;
|
|
325
|
+
|
|
326
|
+
default:
|
|
327
|
+
// For other types, keep the original value
|
|
328
|
+
coercedValue = value;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Validate the coerced value against the schema
|
|
333
|
+
const parseResult = keySchema.safeParse(coercedValue);
|
|
334
|
+
if (parseResult.success) {
|
|
335
|
+
return coercedValue;
|
|
336
|
+
} else {
|
|
337
|
+
logger.warn({
|
|
338
|
+
message: `Failed to coerce parameter's value for key "${inputKey}" to the type defined by the input schema. Error: ${parseResult.error.message}. Using the original value instead.`,
|
|
339
|
+
value,
|
|
340
|
+
});
|
|
341
|
+
return value;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
@@ -36,17 +36,24 @@ const parseDocumentTool: Tool<typeof schema> = {
|
|
|
36
36
|
throw new Error('documentSource is required - provide a URL, file path, or array of URLs/file paths');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const node = await agent.getCurrentNode(state.sessionId);
|
|
40
|
-
const appToolNode = node?.type === NodeType.APP_TOOL ? node : undefined;
|
|
41
|
-
|
|
42
39
|
// Get processing mode from environment variable
|
|
43
40
|
const processingMode =
|
|
44
41
|
process.env.DOCUMENT_PROCESSING_MODE === 'local' ? DocumentProcessingMode.LOCAL : DocumentProcessingMode.MANAGED;
|
|
45
42
|
const llamaCloudApiKey: string | undefined = process.env.LLAMA_CLOUD_API_KEY;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
|
|
44
|
+
const node = await agent.getCurrentNode(state.sessionId);
|
|
45
|
+
const appToolNode = node?.type === NodeType.APP_TOOL ? node : undefined;
|
|
46
|
+
let outputSchema: undefined | z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
47
|
+
if (!appToolNode) {
|
|
48
|
+
logger.error({
|
|
49
|
+
msg: `[minded-parse-documents] Current node was not found or not an appTool. Output schema could not be inferred. Will use unstructured output.`,
|
|
50
|
+
nodeType: node?.type,
|
|
51
|
+
nodeName: node?.name,
|
|
52
|
+
sessionId: state.sessionId,
|
|
53
|
+
})
|
|
54
|
+
} else if (input.returnStructuredOutput && agent.llm && appToolNode.outputSchema?.length) {
|
|
55
|
+
outputSchema = createZodSchemaFromFields(appToolNode.outputSchema);
|
|
56
|
+
}
|
|
50
57
|
|
|
51
58
|
const documentSources = Array.isArray(input.documentSource) ? input.documentSource : [input.documentSource];
|
|
52
59
|
|
|
@@ -74,7 +81,7 @@ const parseDocumentTool: Tool<typeof schema> = {
|
|
|
74
81
|
};
|
|
75
82
|
} catch (err) {
|
|
76
83
|
logger.error({
|
|
77
|
-
message: 'Failed to parse document',
|
|
84
|
+
message: '[minded-parse-documents] Failed to parse document',
|
|
78
85
|
sessionId: state.sessionId,
|
|
79
86
|
err,
|
|
80
87
|
});
|