@minded-ai/mindedjs 2.0.43 → 2.0.44
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/nodes/addThinkingNode.d.ts.map +1 -1
- package/dist/nodes/addThinkingNode.js +36 -11
- package/dist/nodes/addThinkingNode.js.map +1 -1
- package/dist/nodes/compilePrompt.d.ts.map +1 -1
- package/dist/nodes/compilePrompt.js +84 -4
- package/dist/nodes/compilePrompt.js.map +1 -1
- package/dist/types/Flows.types.d.ts +36 -23
- package/dist/types/Flows.types.d.ts.map +1 -1
- package/dist/types/Flows.types.js.map +1 -1
- package/dist/types/Tools.types.d.ts +5 -3
- package/dist/types/Tools.types.d.ts.map +1 -1
- package/dist/types/Tools.types.js.map +1 -1
- package/dist/utils/schemaConverter.d.ts +3 -0
- package/dist/utils/schemaConverter.d.ts.map +1 -0
- package/dist/utils/schemaConverter.js +73 -0
- package/dist/utils/schemaConverter.js.map +1 -0
- package/package.json +2 -2
- package/src/nodes/addPromptNode.ts +1 -1
- package/src/nodes/addThinkingNode.ts +40 -12
- package/src/nodes/compilePrompt.ts +92 -4
- package/src/types/Flows.types.ts +39 -32
- package/src/types/Tools.types.ts +7 -3
- package/src/utils/schemaConverter.ts +82 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addThinkingNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addThinkingNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAe,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"addThinkingNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addThinkingNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAe,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AASjC,KAAK,qBAAqB,GAAG;IAC3B,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,YAAY,CAAC;IACnB,GAAG,EAAE,iBAAiB,CAAC;IACvB,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,IAAI,EAAE,aAAa,CAAC,GAAG,EAAE,MAAM,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,6BAA6B,qBAAqB,kBAuGvF,CAAC"}
|
|
@@ -9,6 +9,8 @@ const history_1 = require("../utils/history");
|
|
|
9
9
|
const compilePrompt_1 = require("./compilePrompt");
|
|
10
10
|
const Analytics_types_1 = require("../types/Analytics.types");
|
|
11
11
|
const analytics_1 = require("../internalTools/analytics");
|
|
12
|
+
const schemaConverter_1 = require("../utils/schemaConverter");
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
12
14
|
const addThinkingNode = async ({ graph, node, llm, agent }) => {
|
|
13
15
|
const callback = async (state) => {
|
|
14
16
|
(0, analytics_1.trackAnalyticsEvent)(Analytics_types_1.AnalyticsEventName.NODE_EXECUTION, {
|
|
@@ -29,8 +31,15 @@ const addThinkingNode = async ({ graph, node, llm, agent }) => {
|
|
|
29
31
|
// We add the system message for this node
|
|
30
32
|
const messagesForModel = [...state.messages];
|
|
31
33
|
messagesForModel.push(systemMessage);
|
|
34
|
+
// Check if we need structured output
|
|
35
|
+
const useStructuredOutput = node.outputSchema && node.outputSchema.length > 0;
|
|
36
|
+
let llmWithStructuredOutput = llmToUse;
|
|
37
|
+
if (useStructuredOutput) {
|
|
38
|
+
const zodSchema = (0, schemaConverter_1.convertArraySchemaToZod)(node.outputSchema);
|
|
39
|
+
llmWithStructuredOutput = llmToUse.withStructuredOutput(zodSchema, { name: 'extract' });
|
|
40
|
+
}
|
|
32
41
|
const startTime = Date.now();
|
|
33
|
-
const result = await
|
|
42
|
+
const result = await llmWithStructuredOutput.invoke(messagesForModel);
|
|
34
43
|
const endTime = Date.now();
|
|
35
44
|
logger_1.logger.debug({
|
|
36
45
|
msg: '[Model] Thinking node execution time',
|
|
@@ -40,17 +49,33 @@ const addThinkingNode = async ({ graph, node, llm, agent }) => {
|
|
|
40
49
|
});
|
|
41
50
|
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, state);
|
|
42
51
|
// Inject metadata to identify this as a thinking node output
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
nodeType: Flows_types_1.NodeType.THINKING,
|
|
49
|
-
nodeDisplayName: node.displayName,
|
|
50
|
-
prompt: node.prompt,
|
|
51
|
-
},
|
|
52
|
+
const additionalKwargs = {
|
|
53
|
+
mindedMetadata: {
|
|
54
|
+
nodeType: Flows_types_1.NodeType.THINKING,
|
|
55
|
+
nodeDisplayName: node.displayName,
|
|
56
|
+
prompt: node.prompt,
|
|
52
57
|
},
|
|
53
|
-
|
|
58
|
+
};
|
|
59
|
+
let messageId;
|
|
60
|
+
let messageContent;
|
|
61
|
+
// When structured output is used, result is the raw extracted data (not an AIMessage)
|
|
62
|
+
// When not used, result is an AIMessage with content and id
|
|
63
|
+
if (useStructuredOutput) {
|
|
64
|
+
additionalKwargs.structuredOutput = result;
|
|
65
|
+
messageId = (0, uuid_1.v4)();
|
|
66
|
+
messageContent = JSON.stringify(result);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// result is an AIMessage, preserve its additional_kwargs and id
|
|
70
|
+
const aiResult = result;
|
|
71
|
+
Object.assign(additionalKwargs, aiResult.additional_kwargs);
|
|
72
|
+
messageId = aiResult.id;
|
|
73
|
+
messageContent = aiResult.content;
|
|
74
|
+
}
|
|
75
|
+
const messageWithMetadata = new messages_1.AIMessage({
|
|
76
|
+
content: messageContent,
|
|
77
|
+
additional_kwargs: additionalKwargs,
|
|
78
|
+
id: messageId,
|
|
54
79
|
});
|
|
55
80
|
// Add to state messages
|
|
56
81
|
state.messages.push(messageWithMetadata);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addThinkingNode.js","sourceRoot":"","sources":["../../src/nodes/addThinkingNode.ts"],"names":[],"mappings":";;;AACA,sDAA8D;AAG9D,uDAAoE;AAIpE,gEAA6D;AAE7D,4CAAyC;AACzC,8CAAqD;AACrD,mDAAgD;AAChD,8DAA8D;AAC9D,0DAAiE;
|
|
1
|
+
{"version":3,"file":"addThinkingNode.js","sourceRoot":"","sources":["../../src/nodes/addThinkingNode.ts"],"names":[],"mappings":";;;AACA,sDAA8D;AAG9D,uDAAoE;AAIpE,gEAA6D;AAE7D,4CAAyC;AACzC,8CAAqD;AACrD,mDAAgD;AAChD,8DAA8D;AAC9D,0DAAiE;AACjE,8DAAmE;AACnE,+BAAoC;AAW7B,MAAM,eAAe,GAAG,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAyB,EAAE,EAAE;IAC1F,MAAM,QAAQ,GAAiB,KAAK,EAAE,KAAmC,EAAE,EAAE;QAC3E,IAAA,+BAAmB,EACjB,oCAAkB,CAAC,cAA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YAC5D,SAAS,GAAG,QAAQ,CAAC,EAAG,CAAC;YACzB,cAAc,GAAG,QAAQ,CAAC,OAAiB,CAAC;QAC9C,CAAC;QAED,MAAM,mBAAmB,GAAG,IAAI,oBAAS,CAAC;YACxC,OAAO,EAAE,cAAc;YACvB,iBAAiB,EAAE,gBAAgB;YACnC,EAAE,EAAE,SAAS;SACd,CAAC,CAAC;QAEH,wBAAwB;QACxB,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAEzC,iBAAiB;QACjB,KAAK,CAAC,OAAO,CAAC,IAAI,CAChB,IAAA,2BAAiB,EAAc,KAAK,CAAC,OAAO,EAAE;YAC5C,IAAI,EAAE,sBAAQ,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,eAAe,EAAE,IAAI,CAAC,WAAW;YACjC,GAAG,EAAE,mBAAmB,CAAC,OAAO;YAChC,UAAU,EAAE,CAAC,mBAAmB,CAAC,EAAG,CAAC;SACtC,CAAC,CACH,CAAC;QAEF,sCAAsC;QACtC,gFAAgF;QAChF,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAElB,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAvGW,QAAA,eAAe,mBAuG1B"}
|
|
@@ -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":"AAmEA;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,MAAM,CA2BtF"}
|
|
@@ -36,6 +36,65 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.compilePrompt = compilePrompt;
|
|
37
37
|
const ejs = __importStar(require("ejs"));
|
|
38
38
|
const logger_1 = require("../utils/logger");
|
|
39
|
+
/**
|
|
40
|
+
* Extract node outputs from state.history and state.messages
|
|
41
|
+
* Returns a map of nodeId/nodeDisplayName -> output object
|
|
42
|
+
*/
|
|
43
|
+
function extractNodeOutputs(state) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
if (!(state === null || state === void 0 ? void 0 : state.history) || !(state === null || state === void 0 ? void 0 : state.messages)) {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
const outputs = {};
|
|
49
|
+
// Build lookup maps by message type
|
|
50
|
+
const messagesByType = {
|
|
51
|
+
tool: new Map(state.messages
|
|
52
|
+
.filter((msg) => { var _a; return ((_a = msg.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'ToolMessage' && msg.tool_call_id; })
|
|
53
|
+
.map((msg) => [msg.tool_call_id, msg])),
|
|
54
|
+
ai: new Map(state.messages.filter((msg) => { var _a; return ((_a = msg.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'AIMessage' && msg.id; }).map((msg) => [msg.id, msg])),
|
|
55
|
+
};
|
|
56
|
+
const setOutput = (item, value) => {
|
|
57
|
+
if (item.nodeId)
|
|
58
|
+
outputs[item.nodeId] = value;
|
|
59
|
+
if (item.nodeDisplayName)
|
|
60
|
+
outputs[item.nodeDisplayName] = value;
|
|
61
|
+
};
|
|
62
|
+
const extractors = {
|
|
63
|
+
tool: (item) => {
|
|
64
|
+
var _a, _b, _c, _d;
|
|
65
|
+
const toolCallId = (_b = (_a = item.messageIds) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : (_c = item.messageIds) === null || _c === void 0 ? void 0 : _c[0];
|
|
66
|
+
const toolMessage = messagesByType.tool.get(toolCallId);
|
|
67
|
+
if (!toolMessage)
|
|
68
|
+
return;
|
|
69
|
+
try {
|
|
70
|
+
const content = typeof toolMessage.content === 'string' ? JSON.parse(toolMessage.content) : toolMessage.content;
|
|
71
|
+
setOutput(item, (_d = content === null || content === void 0 ? void 0 : content.result) !== null && _d !== void 0 ? _d : content);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
logger_1.logger.debug({ message: 'Failed to parse tool message content', toolCallId, err });
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
thinking: (item) => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const messageId = (_a = item.messageIds) === null || _a === void 0 ? void 0 : _a[0];
|
|
80
|
+
if (!messageId)
|
|
81
|
+
return;
|
|
82
|
+
const aiMessage = messagesByType.ai.get(messageId);
|
|
83
|
+
if (!aiMessage)
|
|
84
|
+
return;
|
|
85
|
+
const structuredOutput = (_b = aiMessage.additional_kwargs) === null || _b === void 0 ? void 0 : _b.structuredOutput;
|
|
86
|
+
if (structuredOutput) {
|
|
87
|
+
setOutput(item, structuredOutput);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
for (const item of state.history) {
|
|
92
|
+
if (!((_a = item.messageIds) === null || _a === void 0 ? void 0 : _a.length))
|
|
93
|
+
continue;
|
|
94
|
+
(_b = extractors[item.type]) === null || _b === void 0 ? void 0 : _b.call(extractors, item);
|
|
95
|
+
}
|
|
96
|
+
return outputs;
|
|
97
|
+
}
|
|
39
98
|
/**
|
|
40
99
|
* Compile prompt with parameters using EJS and placeholder replacement
|
|
41
100
|
*/
|
|
@@ -43,6 +102,16 @@ function compilePrompt(prompt, params = {}) {
|
|
|
43
102
|
try {
|
|
44
103
|
// Define system parameters
|
|
45
104
|
params.system = { currentTime: new Date().toISOString() };
|
|
105
|
+
// Extract node outputs from state if available
|
|
106
|
+
// This enables placeholder replacement like {tools.NodeName.field} or {NodeName.field}
|
|
107
|
+
// by making previous node outputs available in the params object.
|
|
108
|
+
// Example: If ExtractUser node outputs { userName: "Bob", userAge: 35 },
|
|
109
|
+
// the prompt "Hello {tools.ExtractUser.userName}" becomes "Hello Bob"
|
|
110
|
+
if (params.state) {
|
|
111
|
+
const nodeOutputs = extractNodeOutputs(params.state);
|
|
112
|
+
// Merge node outputs into params so they're accessible during placeholder replacement
|
|
113
|
+
params = { ...params, ...nodeOutputs };
|
|
114
|
+
}
|
|
46
115
|
// First, render with EJS
|
|
47
116
|
let compiledPrompt = ejs.render(prompt, params);
|
|
48
117
|
// Then, replace placeholders in {} format
|
|
@@ -50,23 +119,34 @@ function compilePrompt(prompt, params = {}) {
|
|
|
50
119
|
return compiledPrompt;
|
|
51
120
|
}
|
|
52
121
|
catch (err) {
|
|
53
|
-
logger_1.logger.error({ message: 'Error compiling prompt', err });
|
|
122
|
+
logger_1.logger.error({ message: 'Error compiling prompt', err, prompt });
|
|
54
123
|
return prompt; // Return uncompiled if there's an error
|
|
55
124
|
}
|
|
56
125
|
}
|
|
57
126
|
/**
|
|
58
127
|
* Replace placeholders in {key} format
|
|
128
|
+
* Supports both:
|
|
129
|
+
* - {NodeName.field} - direct node reference
|
|
130
|
+
* - {tools.NodeName.field} - node reference with 'tools' prefix (alias)
|
|
59
131
|
*/
|
|
60
132
|
function replacePlaceholders(text, params) {
|
|
61
133
|
return text.replace(/\{([^}]+)\}/g, (match, key) => {
|
|
62
|
-
|
|
134
|
+
let keys = key.split('.');
|
|
135
|
+
// Handle 'tools.' prefix as an alias for node outputs
|
|
136
|
+
// {tools.NodeName.field} -> {NodeName.field}
|
|
137
|
+
if (keys[0] === 'tools' && keys.length >= 3) {
|
|
138
|
+
keys = keys.slice(1); // Remove 'tools' prefix
|
|
139
|
+
}
|
|
63
140
|
let value = params;
|
|
64
|
-
for (
|
|
141
|
+
for (let i = 0; i < keys.length; i++) {
|
|
142
|
+
const k = keys[i];
|
|
65
143
|
if (value && typeof value === 'object' && k in value) {
|
|
66
144
|
value = value[k];
|
|
67
145
|
}
|
|
68
146
|
else {
|
|
69
|
-
logger_1.logger.warn({
|
|
147
|
+
logger_1.logger.warn({
|
|
148
|
+
message: `Placeholder {${key}} in prompt not found in params. It will remain as placeholder.`,
|
|
149
|
+
});
|
|
70
150
|
return match; // Return original if key not found
|
|
71
151
|
}
|
|
72
152
|
}
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,sCA2BC;AAjGD,yCAA2B;AAC3B,4CAAyC;AAGzC;;;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,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,EAAE,WAAC,OAAA,CAAA,MAAA,GAAG,CAAC,WAAW,0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AK,CAAC,CAAC,mCAAmC;YACnD,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -91,6 +91,31 @@ export interface ScheduleTriggerNode extends BaseTriggerNode {
|
|
|
91
91
|
*/
|
|
92
92
|
timezone?: string;
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Base schema field type for backward compatibility with platform.
|
|
96
|
+
* Represents simple input/output schema fields (string and number only).
|
|
97
|
+
*/
|
|
98
|
+
export interface SchemaField {
|
|
99
|
+
name: string;
|
|
100
|
+
type: 'string' | 'number';
|
|
101
|
+
description?: string;
|
|
102
|
+
required?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Extended schema field type with support for complex types (boolean, array, object).
|
|
106
|
+
* Uses Omit to override the 'type' field and intersection type (&) with Partial<> to
|
|
107
|
+
* elegantly add optional properties for complex types (items, properties).
|
|
108
|
+
* Filtered for backward compatibility when communicating with platform.
|
|
109
|
+
*/
|
|
110
|
+
export type OutputSchemaField = Omit<SchemaField, 'type'> & {
|
|
111
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
112
|
+
} & Partial<{
|
|
113
|
+
items: {
|
|
114
|
+
type: 'string' | 'number' | 'boolean' | 'object';
|
|
115
|
+
properties?: any;
|
|
116
|
+
};
|
|
117
|
+
properties: any;
|
|
118
|
+
}>;
|
|
94
119
|
export interface PromptNode extends BaseNode {
|
|
95
120
|
type: NodeType.PROMPT_NODE;
|
|
96
121
|
prompt: string;
|
|
@@ -100,6 +125,7 @@ export interface ThinkingNode extends BaseNode {
|
|
|
100
125
|
type: NodeType.THINKING;
|
|
101
126
|
prompt: string;
|
|
102
127
|
llmConfig?: LLMConfig;
|
|
128
|
+
outputSchema?: OutputSchemaField[];
|
|
103
129
|
}
|
|
104
130
|
export interface JumpToNode extends BaseNode {
|
|
105
131
|
type: NodeType.JUMP_TO_NODE;
|
|
@@ -109,18 +135,8 @@ export interface BrowserTaskNode extends BaseNode {
|
|
|
109
135
|
type: NodeType.BROWSER_TASK;
|
|
110
136
|
prompt: string;
|
|
111
137
|
model?: string;
|
|
112
|
-
inputSchema?:
|
|
113
|
-
|
|
114
|
-
type: 'string' | 'number';
|
|
115
|
-
description?: string;
|
|
116
|
-
required?: boolean;
|
|
117
|
-
}[];
|
|
118
|
-
outputSchema?: {
|
|
119
|
-
name: string;
|
|
120
|
-
type: 'string' | 'number';
|
|
121
|
-
description?: string;
|
|
122
|
-
required?: boolean;
|
|
123
|
-
}[];
|
|
138
|
+
inputSchema?: SchemaField[];
|
|
139
|
+
outputSchema?: OutputSchemaField[];
|
|
124
140
|
autoTrigger?: boolean;
|
|
125
141
|
defaultPayload?: string;
|
|
126
142
|
proxy?: string;
|
|
@@ -150,17 +166,7 @@ export interface RpaStep {
|
|
|
150
166
|
shouldReplaceExistingText?: boolean;
|
|
151
167
|
waitTime?: number;
|
|
152
168
|
description?: string;
|
|
153
|
-
outputSchema?:
|
|
154
|
-
name: string;
|
|
155
|
-
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
156
|
-
description?: string;
|
|
157
|
-
required?: boolean;
|
|
158
|
-
items?: {
|
|
159
|
-
type: 'string' | 'number' | 'boolean' | 'object';
|
|
160
|
-
properties?: any;
|
|
161
|
-
};
|
|
162
|
-
properties?: any;
|
|
163
|
-
}[];
|
|
169
|
+
outputSchema?: OutputSchemaField[];
|
|
164
170
|
}
|
|
165
171
|
export type TriggerNode = AppTriggerNode | WebhookTriggerNode | ManualTriggerNode | VoiceTriggerNode | InterfaceTriggerNode | ScheduleTriggerNode;
|
|
166
172
|
export interface JunctionNode extends BaseNode {
|
|
@@ -172,6 +178,13 @@ export interface ToolNode extends BaseNode {
|
|
|
172
178
|
prompt: string;
|
|
173
179
|
appImgSrc?: string;
|
|
174
180
|
parameters?: Record<string, any>;
|
|
181
|
+
inputSchema?: {
|
|
182
|
+
name: string;
|
|
183
|
+
type: 'string' | 'number' | 'boolean' | 'array';
|
|
184
|
+
description?: string;
|
|
185
|
+
required?: boolean;
|
|
186
|
+
}[];
|
|
187
|
+
outputSchema?: OutputSchemaField[];
|
|
175
188
|
}
|
|
176
189
|
export interface AppToolNode extends BaseNode, BaseAppNode {
|
|
177
190
|
type: NodeType.APP_TOOL;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flows.types.d.ts","sourceRoot":"","sources":["../../src/types/Flows.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,MAAM,WAAW,QAAQ;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,oBAAY,QAAQ;IAClB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,QAAQ,YAAY;IACpB,WAAW,eAAe;IAC1B,YAAY,eAAe;IAC3B,YAAY,gBAAgB;IAC5B,QAAQ,aAAa;CACtB;AAED,oBAAY,QAAQ;IAClB,iBAAiB,qBAAqB;IACtC,gBAAgB,oBAAoB;IACpC,YAAY,gBAAgB;CAC7B;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,oBAAY,WAAW;IACrB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,QAAQ,aAAa;CACtB;AAED,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC;IACvB,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,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CAAA;IACb,0CAAyB,CAAA;IACzB,kCAAiB,CAAA;IACjB,gCAAe,CAAA;IACf,8BAAa,CAAA;IACb,8CAA6B,CAAA;AAC/B,CAAC,EATW,aAAa,6BAAb,aAAa,QASxB;AA6ED,IAAY,mBAEX;AAFD,WAAY,mBAAmB;IAC7B,2CAAoB,CAAA;AACtB,CAAC,EAFW,mBAAmB,mCAAnB,mBAAmB,QAE9B;AAsBD,IAAY,oBAOX;AAPD,WAAY,oBAAoB;IAC9B,yCAAiB,CAAA;IACjB,yCAAiB,CAAA;IACjB,2CAAmB,CAAA;IACnB,uCAAe,CAAA;IACf,yCAAiB,CAAA;IACjB,mCAAW,CAAA;AACb,CAAC,EAPW,oBAAoB,oCAApB,oBAAoB,QAO/B;AAQD,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,4DAAuC,CAAA;IACvC,oDAA+B,CAAA;AACjC,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B;AAED,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,4DAAqC,CAAA;IACrC,4CAAqB,CAAA;IACrB,2DAAoC,CAAA;AACtC,CAAC,EAJW,mBAAmB,mCAAnB,mBAAmB,QAI9B"}
|
|
@@ -6,11 +6,12 @@ import { BrowserTaskMode } from '../browserTask/types';
|
|
|
6
6
|
export type ToolReturnType = {
|
|
7
7
|
result?: any;
|
|
8
8
|
} | void;
|
|
9
|
-
export type Tool<Input extends z.ZodSchema, Memory = any> = RPATool<Input, Memory> | DefaultTool<Input, Memory>;
|
|
10
|
-
export interface RPATool<Input extends z.ZodSchema, Memory = any> {
|
|
9
|
+
export type Tool<Input extends z.ZodSchema, Memory = any, Output extends z.ZodSchema = any> = RPATool<Input, Memory, Output> | DefaultTool<Input, Memory, Output>;
|
|
10
|
+
export interface RPATool<Input extends z.ZodSchema, Memory = any, Output extends z.ZodSchema = any> {
|
|
11
11
|
name: string;
|
|
12
12
|
description: string;
|
|
13
13
|
input: Input;
|
|
14
|
+
output?: Output;
|
|
14
15
|
isGlobal?: boolean;
|
|
15
16
|
allowExecutionRequests?: boolean;
|
|
16
17
|
type: 'rpa';
|
|
@@ -18,10 +19,11 @@ export interface RPATool<Input extends z.ZodSchema, Memory = any> {
|
|
|
18
19
|
browserTaskMode?: BrowserTaskMode;
|
|
19
20
|
execute: (input: RPAToolExecuteInput<Input, Memory>) => Promise<ToolReturnType>;
|
|
20
21
|
}
|
|
21
|
-
export interface DefaultTool<Input extends z.ZodSchema, Memory = any> {
|
|
22
|
+
export interface DefaultTool<Input extends z.ZodSchema, Memory = any, Output extends z.ZodSchema = any> {
|
|
22
23
|
name: string;
|
|
23
24
|
description: string;
|
|
24
25
|
input: Input;
|
|
26
|
+
output?: Output;
|
|
25
27
|
isGlobal?: boolean;
|
|
26
28
|
allowExecutionRequests?: boolean;
|
|
27
29
|
type?: 'default';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tools.types.d.ts","sourceRoot":"","sources":["../../src/types/Tools.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,MAAM,MAAM,cAAc,GAAG;IAAE,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,IAAI,CAAC;AAGrD,MAAM,MAAM,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,
|
|
1
|
+
{"version":3,"file":"Tools.types.d.ts","sourceRoot":"","sources":["../../src/types/Tools.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAA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MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CAC9E;AAGD,MAAM,WAAW,gBAAgB,CAAC,KAAK,SAAS,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG;IACvE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAGD,MAAM,WAAW,mBAAmB,CAAC,KAAK,SAAS,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAAE,SAAQ,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC;IACnH,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,oBAAY,QAAQ;IAClB,GAAG,QAAQ;IACX,OAAO,YAAY;CACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tools.types.js","sourceRoot":"","sources":["../../src/types/Tools.types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Tools.types.js","sourceRoot":"","sources":["../../src/types/Tools.types.ts"],"names":[],"mappings":";;;AA2DA,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,uBAAW,CAAA;IACX,+BAAmB,CAAA;AACrB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaConverter.d.ts","sourceRoot":"","sources":["../../src/utils/schemaConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,OAAO,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CA6E9E"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertArraySchemaToZod = convertArraySchemaToZod;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
function convertArraySchemaToZod(schemaArray) {
|
|
7
|
+
if (schemaArray && typeof schemaArray === 'object' && '_def' in schemaArray) {
|
|
8
|
+
return schemaArray;
|
|
9
|
+
}
|
|
10
|
+
if (!Array.isArray(schemaArray) || schemaArray.length === 0) {
|
|
11
|
+
logger_1.logger.warn({ message: 'Empty or invalid schema array provided to convertArraySchemaToZod', schemaArray });
|
|
12
|
+
return zod_1.z.object({});
|
|
13
|
+
}
|
|
14
|
+
const typeMap = {
|
|
15
|
+
string: () => zod_1.z.string(),
|
|
16
|
+
number: () => zod_1.z.number(),
|
|
17
|
+
boolean: () => zod_1.z.boolean(),
|
|
18
|
+
// For arrays, check if items are defined, otherwise default to string array
|
|
19
|
+
array: (field) => {
|
|
20
|
+
var _a;
|
|
21
|
+
if ((_a = field.items) === null || _a === void 0 ? void 0 : _a.type) {
|
|
22
|
+
const itemTypeMap = {
|
|
23
|
+
string: zod_1.z.string(),
|
|
24
|
+
number: zod_1.z.number(),
|
|
25
|
+
boolean: zod_1.z.boolean(),
|
|
26
|
+
};
|
|
27
|
+
return zod_1.z.array(itemTypeMap[field.items.type] || zod_1.z.string());
|
|
28
|
+
}
|
|
29
|
+
return zod_1.z.array(zod_1.z.string());
|
|
30
|
+
},
|
|
31
|
+
// For objects, create a record type that allows any key-value pairs
|
|
32
|
+
// OpenAI's structured outputs don't support truly dynamic objects well
|
|
33
|
+
// So we use record(string, string) which is the most flexible allowed format
|
|
34
|
+
object: (field) => {
|
|
35
|
+
if (field.properties && Object.keys(field.properties).length > 0) {
|
|
36
|
+
// If properties are defined, create a structured object
|
|
37
|
+
const shape = Object.fromEntries(Object.entries(field.properties).map(([key, value]) => {
|
|
38
|
+
const propType = value.type || 'string';
|
|
39
|
+
const propTypeMap = {
|
|
40
|
+
string: zod_1.z.string(),
|
|
41
|
+
number: zod_1.z.number(),
|
|
42
|
+
boolean: zod_1.z.boolean(),
|
|
43
|
+
};
|
|
44
|
+
return [key, propTypeMap[propType] || zod_1.z.string()];
|
|
45
|
+
}));
|
|
46
|
+
return zod_1.z.object(shape);
|
|
47
|
+
}
|
|
48
|
+
// If no properties defined, use record(string, string) for maximum compatibility
|
|
49
|
+
// This allows any key-value pairs where values are strings
|
|
50
|
+
return zod_1.z.record(zod_1.z.string(), zod_1.z.string());
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const shape = Object.fromEntries(schemaArray.map((field) => {
|
|
54
|
+
const typeFunc = typeMap[field.type];
|
|
55
|
+
let schema = typeFunc ? typeFunc(field) : zod_1.z.any();
|
|
56
|
+
if (field.description) {
|
|
57
|
+
schema = schema.describe(field.description);
|
|
58
|
+
}
|
|
59
|
+
// OpenAI's structured outputs require all fields in the 'required' array
|
|
60
|
+
// To make a field optional, we use .nullable() which means the field is required but can be null
|
|
61
|
+
// This satisfies OpenAI's requirement while allowing optional fields
|
|
62
|
+
if (!field.required) {
|
|
63
|
+
schema = schema.nullable();
|
|
64
|
+
}
|
|
65
|
+
return [field.name, schema];
|
|
66
|
+
}));
|
|
67
|
+
// Create the final Zod object
|
|
68
|
+
// Note: All fields will be in the 'required' array for OpenAI's JSON schema
|
|
69
|
+
// Optional fields are handled by .nullable() above
|
|
70
|
+
const zodObject = zod_1.z.object(shape);
|
|
71
|
+
return zodObject;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=schemaConverter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaConverter.js","sourceRoot":"","sources":["../../src/utils/schemaConverter.ts"],"names":[],"mappings":";;AAIA,0DA6EC;AAjFD,6BAAwB;AAExB,qCAAkC;AAElC,SAAgB,uBAAuB,CAAC,WAAoB;IAC1D,IAAI,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,MAAM,IAAI,WAAW,EAAE,CAAC;QAC5E,OAAO,WAA+B,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5D,eAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,mEAAmE,EAAE,WAAW,EAAE,CAAC,CAAC;QAC3G,OAAO,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;IAED,MAAM,OAAO,GAA+D;QAC1E,MAAM,EAAE,GAAG,EAAE,CAAC,OAAC,CAAC,MAAM,EAAE;QACxB,MAAM,EAAE,GAAG,EAAE,CAAC,OAAC,CAAC,MAAM,EAAE;QACxB,OAAO,EAAE,GAAG,EAAE,CAAC,OAAC,CAAC,OAAO,EAAE;QAC1B,4EAA4E;QAC5E,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;;YACf,IAAI,MAAA,KAAK,CAAC,KAAK,0CAAE,IAAI,EAAE,CAAC;gBACtB,MAAM,WAAW,GAAiC;oBAChD,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;oBAClB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;oBAClB,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE;iBACrB,CAAC;gBACF,OAAO,OAAC,CAAC,KAAK,CAAC,WAAW,CAAC,K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AAE,EAAE;QAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;QAElD,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC9C,CAAC;QAED,yEAAyE;QACzE,iGAAiG;QACjG,qEAAqE;QACrE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACpB,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC7B,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC,CACH,CAAC;IAEF,8BAA8B;IAC9B,4EAA4E;IAC5E,mDAAmD;IACnD,MAAM,SAAS,GAAG,OAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAElC,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minded-ai/mindedjs",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.44",
|
|
4
4
|
"description": "MindedJS is a TypeScript library for building agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -72,4 +72,4 @@
|
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"playwright": "^1.55.0"
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|
|
@@ -13,6 +13,8 @@ import { createHistoryStep } from '../utils/history';
|
|
|
13
13
|
import { compilePrompt } from './compilePrompt';
|
|
14
14
|
import { AnalyticsEventName } from '../types/Analytics.types';
|
|
15
15
|
import { trackAnalyticsEvent } from '../internalTools/analytics';
|
|
16
|
+
import { convertArraySchemaToZod } from '../utils/schemaConverter';
|
|
17
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
16
18
|
|
|
17
19
|
type AddThinkingNodeParams = {
|
|
18
20
|
graph: PreCompiledGraph;
|
|
@@ -51,8 +53,17 @@ export const addThinkingNode = async ({ graph, node, llm, agent }: AddThinkingNo
|
|
|
51
53
|
const messagesForModel = [...state.messages];
|
|
52
54
|
messagesForModel.push(systemMessage);
|
|
53
55
|
|
|
56
|
+
// Check if we need structured output
|
|
57
|
+
const useStructuredOutput = node.outputSchema && node.outputSchema.length > 0;
|
|
58
|
+
let llmWithStructuredOutput = llmToUse;
|
|
59
|
+
|
|
60
|
+
if (useStructuredOutput) {
|
|
61
|
+
const zodSchema = convertArraySchemaToZod(node.outputSchema!);
|
|
62
|
+
llmWithStructuredOutput = llmToUse.withStructuredOutput(zodSchema, { name: 'extract' });
|
|
63
|
+
}
|
|
64
|
+
|
|
54
65
|
const startTime = Date.now();
|
|
55
|
-
const result
|
|
66
|
+
const result = await llmWithStructuredOutput.invoke(messagesForModel);
|
|
56
67
|
const endTime = Date.now();
|
|
57
68
|
|
|
58
69
|
logger.debug({
|
|
@@ -65,17 +76,35 @@ export const addThinkingNode = async ({ graph, node, llm, agent }: AddThinkingNo
|
|
|
65
76
|
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, state);
|
|
66
77
|
|
|
67
78
|
// Inject metadata to identify this as a thinking node output
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
nodeType: NodeType.THINKING,
|
|
74
|
-
nodeDisplayName: node.displayName,
|
|
75
|
-
prompt: node.prompt,
|
|
76
|
-
},
|
|
79
|
+
const additionalKwargs: Record<string, any> = {
|
|
80
|
+
mindedMetadata: {
|
|
81
|
+
nodeType: NodeType.THINKING,
|
|
82
|
+
nodeDisplayName: node.displayName,
|
|
83
|
+
prompt: node.prompt,
|
|
77
84
|
},
|
|
78
|
-
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
let messageId: string;
|
|
88
|
+
let messageContent: string;
|
|
89
|
+
|
|
90
|
+
// When structured output is used, result is the raw extracted data (not an AIMessage)
|
|
91
|
+
// When not used, result is an AIMessage with content and id
|
|
92
|
+
if (useStructuredOutput) {
|
|
93
|
+
additionalKwargs.structuredOutput = result;
|
|
94
|
+
messageId = uuidv4();
|
|
95
|
+
messageContent = JSON.stringify(result);
|
|
96
|
+
} else {
|
|
97
|
+
// result is an AIMessage, preserve its additional_kwargs and id
|
|
98
|
+
const aiResult = result as AIMessage;
|
|
99
|
+
Object.assign(additionalKwargs, aiResult.additional_kwargs);
|
|
100
|
+
messageId = aiResult.id!;
|
|
101
|
+
messageContent = aiResult.content as string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const messageWithMetadata = new AIMessage({
|
|
105
|
+
content: messageContent,
|
|
106
|
+
additional_kwargs: additionalKwargs,
|
|
107
|
+
id: messageId,
|
|
79
108
|
});
|
|
80
109
|
|
|
81
110
|
// Add to state messages
|
|
@@ -100,4 +129,3 @@ export const addThinkingNode = async ({ graph, node, llm, agent }: AddThinkingNo
|
|
|
100
129
|
};
|
|
101
130
|
graph.addNode(node.name, callback);
|
|
102
131
|
};
|
|
103
|
-
|
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
import * as ejs from 'ejs';
|
|
2
2
|
import { logger } from '../utils/logger';
|
|
3
|
+
import { HistoryStep } from '../types/Agent.types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Extract node outputs from state.history and state.messages
|
|
7
|
+
* Returns a map of nodeId/nodeDisplayName -> output object
|
|
8
|
+
*/
|
|
9
|
+
function extractNodeOutputs(state: any): Record<string, any> {
|
|
10
|
+
if (!state?.history || !state?.messages) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const outputs: Record<string, any> = {};
|
|
15
|
+
|
|
16
|
+
// Build lookup maps by message type
|
|
17
|
+
const messagesByType = {
|
|
18
|
+
tool: new Map(
|
|
19
|
+
state.messages
|
|
20
|
+
.filter((msg: any) => msg.constructor?.name === 'ToolMessage' && msg.tool_call_id)
|
|
21
|
+
.map((msg: any) => [msg.tool_call_id, msg]),
|
|
22
|
+
),
|
|
23
|
+
ai: new Map(state.messages.filter((msg: any) => msg.constructor?.name === 'AIMessage' && msg.id).map((msg: any) => [msg.id, msg])),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const setOutput = (item: HistoryStep, value: any) => {
|
|
27
|
+
if (item.nodeId) outputs[item.nodeId] = value;
|
|
28
|
+
if (item.nodeDisplayName) outputs[item.nodeDisplayName] = value;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const extractors: Record<string, (item: HistoryStep) => void> = {
|
|
32
|
+
tool: (item) => {
|
|
33
|
+
const toolCallId = item.messageIds?.[1] ?? item.messageIds?.[0];
|
|
34
|
+
const toolMessage: any = messagesByType.tool.get(toolCallId);
|
|
35
|
+
if (!toolMessage) return;
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const content = typeof toolMessage.content === 'string' ? JSON.parse(toolMessage.content) : toolMessage.content;
|
|
39
|
+
setOutput(item, content?.result ?? content);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
logger.debug({ message: 'Failed to parse tool message content', toolCallId, err });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
thinking: (item) => {
|
|
46
|
+
const messageId = item.messageIds?.[0];
|
|
47
|
+
if (!messageId) return;
|
|
48
|
+
|
|
49
|
+
const aiMessage: any = messagesByType.ai.get(messageId);
|
|
50
|
+
if (!aiMessage) return;
|
|
51
|
+
|
|
52
|
+
const structuredOutput = aiMessage.additional_kwargs?.structuredOutput;
|
|
53
|
+
|
|
54
|
+
if (structuredOutput) {
|
|
55
|
+
setOutput(item, structuredOutput);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
for (const item of state.history) {
|
|
61
|
+
if (!item.messageIds?.length) continue;
|
|
62
|
+
extractors[item.type]?.(item);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return outputs;
|
|
66
|
+
}
|
|
3
67
|
|
|
4
68
|
/**
|
|
5
69
|
* Compile prompt with parameters using EJS and placeholder replacement
|
|
@@ -9,6 +73,17 @@ export function compilePrompt(prompt: string, params: Record<string, any> = {}):
|
|
|
9
73
|
// Define system parameters
|
|
10
74
|
params.system = { currentTime: new Date().toISOString() };
|
|
11
75
|
|
|
76
|
+
// Extract node outputs from state if available
|
|
77
|
+
// This enables placeholder replacement like {tools.NodeName.field} or {NodeName.field}
|
|
78
|
+
// by making previous node outputs available in the params object.
|
|
79
|
+
// Example: If ExtractUser node outputs { userName: "Bob", userAge: 35 },
|
|
80
|
+
// the prompt "Hello {tools.ExtractUser.userName}" becomes "Hello Bob"
|
|
81
|
+
if (params.state) {
|
|
82
|
+
const nodeOutputs = extractNodeOutputs(params.state);
|
|
83
|
+
// Merge node outputs into params so they're accessible during placeholder replacement
|
|
84
|
+
params = { ...params, ...nodeOutputs };
|
|
85
|
+
}
|
|
86
|
+
|
|
12
87
|
// First, render with EJS
|
|
13
88
|
let compiledPrompt = ejs.render(prompt, params);
|
|
14
89
|
|
|
@@ -17,24 +92,37 @@ export function compilePrompt(prompt: string, params: Record<string, any> = {}):
|
|
|
17
92
|
|
|
18
93
|
return compiledPrompt;
|
|
19
94
|
} catch (err) {
|
|
20
|
-
logger.error({ message: 'Error compiling prompt', err });
|
|
95
|
+
logger.error({ message: 'Error compiling prompt', err, prompt });
|
|
21
96
|
return prompt; // Return uncompiled if there's an error
|
|
22
97
|
}
|
|
23
98
|
}
|
|
24
99
|
|
|
25
100
|
/**
|
|
26
101
|
* Replace placeholders in {key} format
|
|
102
|
+
* Supports both:
|
|
103
|
+
* - {NodeName.field} - direct node reference
|
|
104
|
+
* - {tools.NodeName.field} - node reference with 'tools' prefix (alias)
|
|
27
105
|
*/
|
|
28
106
|
function replacePlaceholders(text: string, params: Record<string, any>): string {
|
|
29
107
|
return text.replace(/\{([^}]+)\}/g, (match, key) => {
|
|
30
|
-
|
|
108
|
+
let keys = key.split('.');
|
|
109
|
+
|
|
110
|
+
// Handle 'tools.' prefix as an alias for node outputs
|
|
111
|
+
// {tools.NodeName.field} -> {NodeName.field}
|
|
112
|
+
if (keys[0] === 'tools' && keys.length >= 3) {
|
|
113
|
+
keys = keys.slice(1); // Remove 'tools' prefix
|
|
114
|
+
}
|
|
115
|
+
|
|
31
116
|
let value: any = params;
|
|
32
117
|
|
|
33
|
-
for (
|
|
118
|
+
for (let i = 0; i < keys.length; i++) {
|
|
119
|
+
const k = keys[i];
|
|
34
120
|
if (value && typeof value === 'object' && k in value) {
|
|
35
121
|
value = value[k];
|
|
36
122
|
} else {
|
|
37
|
-
logger.warn({
|
|
123
|
+
logger.warn({
|
|
124
|
+
message: `Placeholder {${key}} in prompt not found in params. It will remain as placeholder.`,
|
|
125
|
+
});
|
|
38
126
|
return match; // Return original if key not found
|
|
39
127
|
}
|
|
40
128
|
}
|
package/src/types/Flows.types.ts
CHANGED
|
@@ -104,6 +104,33 @@ export interface ScheduleTriggerNode extends BaseTriggerNode {
|
|
|
104
104
|
timezone?: string;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Base schema field type for backward compatibility with platform.
|
|
109
|
+
* Represents simple input/output schema fields (string and number only).
|
|
110
|
+
*/
|
|
111
|
+
export interface SchemaField {
|
|
112
|
+
name: string;
|
|
113
|
+
type: 'string' | 'number';
|
|
114
|
+
description?: string;
|
|
115
|
+
required?: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Extended schema field type with support for complex types (boolean, array, object).
|
|
120
|
+
* Uses Omit to override the 'type' field and intersection type (&) with Partial<> to
|
|
121
|
+
* elegantly add optional properties for complex types (items, properties).
|
|
122
|
+
* Filtered for backward compatibility when communicating with platform.
|
|
123
|
+
*/
|
|
124
|
+
export type OutputSchemaField = Omit<SchemaField, 'type'> & {
|
|
125
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
126
|
+
} & Partial<{
|
|
127
|
+
items: {
|
|
128
|
+
type: 'string' | 'number' | 'boolean' | 'object';
|
|
129
|
+
properties?: any;
|
|
130
|
+
};
|
|
131
|
+
properties: any;
|
|
132
|
+
}>;
|
|
133
|
+
|
|
107
134
|
export interface PromptNode extends BaseNode {
|
|
108
135
|
type: NodeType.PROMPT_NODE;
|
|
109
136
|
prompt: string;
|
|
@@ -114,6 +141,7 @@ export interface ThinkingNode extends BaseNode {
|
|
|
114
141
|
type: NodeType.THINKING;
|
|
115
142
|
prompt: string;
|
|
116
143
|
llmConfig?: LLMConfig;
|
|
144
|
+
outputSchema?: OutputSchemaField[];
|
|
117
145
|
}
|
|
118
146
|
|
|
119
147
|
export interface JumpToNode extends BaseNode {
|
|
@@ -125,18 +153,8 @@ export interface BrowserTaskNode extends BaseNode {
|
|
|
125
153
|
type: NodeType.BROWSER_TASK;
|
|
126
154
|
prompt: string;
|
|
127
155
|
model?: string;
|
|
128
|
-
inputSchema?:
|
|
129
|
-
|
|
130
|
-
type: 'string' | 'number';
|
|
131
|
-
description?: string;
|
|
132
|
-
required?: boolean;
|
|
133
|
-
}[];
|
|
134
|
-
outputSchema?: {
|
|
135
|
-
name: string;
|
|
136
|
-
type: 'string' | 'number';
|
|
137
|
-
description?: string;
|
|
138
|
-
required?: boolean;
|
|
139
|
-
}[];
|
|
156
|
+
inputSchema?: SchemaField[];
|
|
157
|
+
outputSchema?: OutputSchemaField[];
|
|
140
158
|
autoTrigger?: boolean;
|
|
141
159
|
defaultPayload?: string;
|
|
142
160
|
proxy?: string; // 2-digit country code like 'IL'
|
|
@@ -166,17 +184,7 @@ export interface RpaStep {
|
|
|
166
184
|
shouldReplaceExistingText?: boolean;
|
|
167
185
|
waitTime?: number;
|
|
168
186
|
description?: string;
|
|
169
|
-
outputSchema?:
|
|
170
|
-
name: string;
|
|
171
|
-
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
172
|
-
description?: string;
|
|
173
|
-
required?: boolean;
|
|
174
|
-
items?: {
|
|
175
|
-
type: 'string' | 'number' | 'boolean' | 'object';
|
|
176
|
-
properties?: any;
|
|
177
|
-
};
|
|
178
|
-
properties?: any;
|
|
179
|
-
}[];
|
|
187
|
+
outputSchema?: OutputSchemaField[];
|
|
180
188
|
}
|
|
181
189
|
|
|
182
190
|
export type TriggerNode =
|
|
@@ -197,6 +205,13 @@ export interface ToolNode extends BaseNode {
|
|
|
197
205
|
prompt: string;
|
|
198
206
|
appImgSrc?: string;
|
|
199
207
|
parameters?: Record<string, any>;
|
|
208
|
+
inputSchema?: {
|
|
209
|
+
name: string;
|
|
210
|
+
type: 'string' | 'number' | 'boolean' | 'array';
|
|
211
|
+
description?: string;
|
|
212
|
+
required?: boolean;
|
|
213
|
+
}[];
|
|
214
|
+
outputSchema?: OutputSchemaField[];
|
|
200
215
|
}
|
|
201
216
|
|
|
202
217
|
export interface AppToolNode extends BaseNode, BaseAppNode {
|
|
@@ -208,15 +223,7 @@ export interface AppToolNode extends BaseNode, BaseAppNode {
|
|
|
208
223
|
actionKey: string;
|
|
209
224
|
}
|
|
210
225
|
|
|
211
|
-
export type Node =
|
|
212
|
-
| TriggerNode
|
|
213
|
-
| JunctionNode
|
|
214
|
-
| ToolNode
|
|
215
|
-
| AppToolNode
|
|
216
|
-
| PromptNode
|
|
217
|
-
| JumpToNode
|
|
218
|
-
| BrowserTaskNode
|
|
219
|
-
| ThinkingNode;
|
|
226
|
+
export type Node = TriggerNode | JunctionNode | ToolNode | AppToolNode | PromptNode | JumpToNode | BrowserTaskNode | ThinkingNode;
|
|
220
227
|
|
|
221
228
|
export interface BaseEdge {
|
|
222
229
|
source: string;
|
package/src/types/Tools.types.ts
CHANGED
|
@@ -8,13 +8,16 @@ import { BrowserTaskMode } from '../browserTask/types';
|
|
|
8
8
|
export type ToolReturnType = { result?: any } | void;
|
|
9
9
|
|
|
10
10
|
// Tool can be either RPA or Default
|
|
11
|
-
export type Tool<Input extends z.ZodSchema, Memory = any
|
|
11
|
+
export type Tool<Input extends z.ZodSchema, Memory = any, Output extends z.ZodSchema = any> =
|
|
12
|
+
| RPATool<Input, Memory, Output>
|
|
13
|
+
| DefaultTool<Input, Memory, Output>;
|
|
12
14
|
|
|
13
15
|
// RPA Tool - always includes Page
|
|
14
|
-
export interface RPATool<Input extends z.ZodSchema, Memory = any> {
|
|
16
|
+
export interface RPATool<Input extends z.ZodSchema, Memory = any, Output extends z.ZodSchema = any> {
|
|
15
17
|
name: string;
|
|
16
18
|
description: string;
|
|
17
19
|
input: Input;
|
|
20
|
+
output?: Output;
|
|
18
21
|
isGlobal?: boolean;
|
|
19
22
|
allowExecutionRequests?: boolean;
|
|
20
23
|
type: 'rpa';
|
|
@@ -24,10 +27,11 @@ export interface RPATool<Input extends z.ZodSchema, Memory = any> {
|
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
// Default Tool - no Page parameter
|
|
27
|
-
export interface DefaultTool<Input extends z.ZodSchema, Memory = any> {
|
|
30
|
+
export interface DefaultTool<Input extends z.ZodSchema, Memory = any, Output extends z.ZodSchema = any> {
|
|
28
31
|
name: string;
|
|
29
32
|
description: string;
|
|
30
33
|
input: Input;
|
|
34
|
+
output?: Output;
|
|
31
35
|
isGlobal?: boolean;
|
|
32
36
|
allowExecutionRequests?: boolean;
|
|
33
37
|
type?: 'default';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { OutputSchemaField } from '../types/Flows.types';
|
|
3
|
+
import { logger } from './logger';
|
|
4
|
+
|
|
5
|
+
export function convertArraySchemaToZod(schemaArray: unknown): z.ZodObject<any> {
|
|
6
|
+
if (schemaArray && typeof schemaArray === 'object' && '_def' in schemaArray) {
|
|
7
|
+
return schemaArray as z.ZodObject<any>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (!Array.isArray(schemaArray) || schemaArray.length === 0) {
|
|
11
|
+
logger.warn({ message: 'Empty or invalid schema array provided to convertArraySchemaToZod', schemaArray });
|
|
12
|
+
return z.object({});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const typeMap: Record<string, (field: OutputSchemaField) => z.ZodTypeAny> = {
|
|
16
|
+
string: () => z.string(),
|
|
17
|
+
number: () => z.number(),
|
|
18
|
+
boolean: () => z.boolean(),
|
|
19
|
+
// For arrays, check if items are defined, otherwise default to string array
|
|
20
|
+
array: (field) => {
|
|
21
|
+
if (field.items?.type) {
|
|
22
|
+
const itemTypeMap: Record<string, z.ZodTypeAny> = {
|
|
23
|
+
string: z.string(),
|
|
24
|
+
number: z.number(),
|
|
25
|
+
boolean: z.boolean(),
|
|
26
|
+
};
|
|
27
|
+
return z.array(itemTypeMap[field.items.type] || z.string());
|
|
28
|
+
}
|
|
29
|
+
return z.array(z.string());
|
|
30
|
+
},
|
|
31
|
+
// For objects, create a record type that allows any key-value pairs
|
|
32
|
+
// OpenAI's structured outputs don't support truly dynamic objects well
|
|
33
|
+
// So we use record(string, string) which is the most flexible allowed format
|
|
34
|
+
object: (field) => {
|
|
35
|
+
if (field.properties && Object.keys(field.properties).length > 0) {
|
|
36
|
+
// If properties are defined, create a structured object
|
|
37
|
+
const shape = Object.fromEntries(
|
|
38
|
+
Object.entries(field.properties).map(([key, value]: [string, any]) => {
|
|
39
|
+
const propType = value.type || 'string';
|
|
40
|
+
const propTypeMap: Record<string, z.ZodTypeAny> = {
|
|
41
|
+
string: z.string(),
|
|
42
|
+
number: z.number(),
|
|
43
|
+
boolean: z.boolean(),
|
|
44
|
+
};
|
|
45
|
+
return [key, propTypeMap[propType] || z.string()];
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
return z.object(shape);
|
|
49
|
+
}
|
|
50
|
+
// If no properties defined, use record(string, string) for maximum compatibility
|
|
51
|
+
// This allows any key-value pairs where values are strings
|
|
52
|
+
return z.record(z.string(), z.string());
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const shape = Object.fromEntries(
|
|
57
|
+
schemaArray.map((field: OutputSchemaField) => {
|
|
58
|
+
const typeFunc = typeMap[field.type];
|
|
59
|
+
let schema = typeFunc ? typeFunc(field) : z.any();
|
|
60
|
+
|
|
61
|
+
if (field.description) {
|
|
62
|
+
schema = schema.describe(field.description);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// OpenAI's structured outputs require all fields in the 'required' array
|
|
66
|
+
// To make a field optional, we use .nullable() which means the field is required but can be null
|
|
67
|
+
// This satisfies OpenAI's requirement while allowing optional fields
|
|
68
|
+
if (!field.required) {
|
|
69
|
+
schema = schema.nullable();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return [field.name, schema];
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Create the final Zod object
|
|
77
|
+
// Note: All fields will be in the 'required' array for OpenAI's JSON schema
|
|
78
|
+
// Optional fields are handled by .nullable() above
|
|
79
|
+
const zodObject = z.object(shape);
|
|
80
|
+
|
|
81
|
+
return zodObject;
|
|
82
|
+
}
|