@minded-ai/mindedjs 1.0.80-beta.1 → 1.0.80-beta.10
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/edges/createLogicalRouter.d.ts +1 -1
- package/dist/edges/createLogicalRouter.d.ts.map +1 -1
- package/dist/edges/createLogicalRouter.js +16 -5
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/edges/edgeFactory.d.ts.map +1 -1
- package/dist/edges/edgeFactory.js +4 -2
- package/dist/edges/edgeFactory.js.map +1 -1
- package/package.json +4 -4
- package/src/edges/createLogicalRouter.ts +18 -5
- package/src/edges/edgeFactory.ts +4 -2
|
@@ -2,5 +2,5 @@ import { LogicalConditionEdge } from '../types/Flows.types';
|
|
|
2
2
|
import { stateAnnotation } from '../types/LangGraph.types';
|
|
3
3
|
export declare const createLogicalRouter: ({ edges }: {
|
|
4
4
|
edges: LogicalConditionEdge[];
|
|
5
|
-
}) => (state: typeof stateAnnotation.State) => Promise<string>;
|
|
5
|
+
}) => (state: typeof stateAnnotation.State) => Promise<string | null>;
|
|
6
6
|
//# sourceMappingURL=createLogicalRouter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLogicalRouter.d.ts","sourceRoot":"","sources":["../../src/edges/createLogicalRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAO3D,eAAO,MAAM,mBAAmB,GAAI,WAAW;IAAE,KAAK,EAAE,oBAAoB,EAAE,CAAA;CAAE,MAChE,OAAO,OAAO,eAAe,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"createLogicalRouter.d.ts","sourceRoot":"","sources":["../../src/edges/createLogicalRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAO3D,eAAO,MAAM,mBAAmB,GAAI,WAAW;IAAE,KAAK,EAAE,oBAAoB,EAAE,CAAA;CAAE,MAChE,OAAO,OAAO,eAAe,CAAC,KAAK,2BAwFlD,CAAC"}
|
|
@@ -41,7 +41,11 @@ const CONDITION_TIMEOUT = 5000; // 5 seconds
|
|
|
41
41
|
const createLogicalRouter = ({ edges }) => {
|
|
42
42
|
return async (state) => {
|
|
43
43
|
logger_1.logger.debug(`Evaluating logical conditions for ${edges.length} edges`);
|
|
44
|
-
|
|
44
|
+
// Separate regular conditions from "else" conditions
|
|
45
|
+
const regularEdges = edges.filter(edge => edge.condition.trim() !== 'else');
|
|
46
|
+
const elseEdges = edges.filter(edge => edge.condition.trim() === 'else');
|
|
47
|
+
// First, evaluate all regular conditions
|
|
48
|
+
for (const edge of regularEdges) {
|
|
45
49
|
try {
|
|
46
50
|
// Customer is responsible for providing valid JavaScript syntax
|
|
47
51
|
// We execute their condition in a sandboxed VM with timeout protection
|
|
@@ -79,11 +83,10 @@ const createLogicalRouter = ({ edges }) => {
|
|
|
79
83
|
Promise.resolve(conditionFn({ state })),
|
|
80
84
|
new Promise((_, reject) => setTimeout(() => reject(new Error('Condition execution timeout')), CONDITION_TIMEOUT)),
|
|
81
85
|
]);
|
|
82
|
-
if (result) {
|
|
86
|
+
if (result === true) {
|
|
83
87
|
logger_1.logger.info(`Condition matched for edge ${edge.source} → ${edge.target}`);
|
|
84
88
|
return edge.target;
|
|
85
89
|
}
|
|
86
|
-
logger_1.logger.debug(`Condition not matched for edge ${edge.source} → ${edge.target}`);
|
|
87
90
|
}
|
|
88
91
|
catch (error) {
|
|
89
92
|
// Provide detailed error information back to the customer
|
|
@@ -101,9 +104,17 @@ const createLogicalRouter = ({ edges }) => {
|
|
|
101
104
|
continue;
|
|
102
105
|
}
|
|
103
106
|
}
|
|
107
|
+
// If no regular conditions matched, check for "else" conditions
|
|
108
|
+
if (elseEdges.length > 0) {
|
|
109
|
+
logger_1.logger.info(`No regular conditions matched, evaluating ${elseEdges.length} else condition(s)`);
|
|
110
|
+
// Return the first "else" condition's target
|
|
111
|
+
const elseEdge = elseEdges[0];
|
|
112
|
+
logger_1.logger.info(`Else condition matched for edge ${elseEdge.source} → ${elseEdge.target}`);
|
|
113
|
+
return elseEdge.target;
|
|
114
|
+
}
|
|
104
115
|
// If no conditions matched or all failed, return to the source node
|
|
105
|
-
logger_1.logger.info(
|
|
106
|
-
return
|
|
116
|
+
logger_1.logger.info('No conditions matched');
|
|
117
|
+
return null;
|
|
107
118
|
};
|
|
108
119
|
};
|
|
109
120
|
exports.createLogicalRouter = createLogicalRouter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLogicalRouter.js","sourceRoot":"","sources":["../../src/edges/createLogicalRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,4CAAyC;AACzC,uCAAyB;AAEzB,6DAA6D;AAC7D,MAAM,iBAAiB,GAAG,IAAI,CAAC,CAAC,YAAY;AAErC,MAAM,mBAAmB,GAAG,CAAC,EAAE,KAAK,EAAqC,EAAE,EAAE;IAClF,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;QACnD,eAAM,CAAC,KAAK,CAAC,qCAAqC,KAAK,CAAC,MAAM,QAAQ,CAAC,CAAC;QAExE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"createLogicalRouter.js","sourceRoot":"","sources":["../../src/edges/createLogicalRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,4CAAyC;AACzC,uCAAyB;AAEzB,6DAA6D;AAC7D,MAAM,iBAAiB,GAAG,IAAI,CAAC,CAAC,YAAY;AAErC,MAAM,mBAAmB,GAAG,CAAC,EAAE,KAAK,EAAqC,EAAE,EAAE;IAClF,OAAO,KAAK,EAAE,KAAmC,EAAE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K,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,GAAG,EAAE,iBAAiB,CAAC;IACvB,KAAK,EAAE,KAAK,CAAC;CACd,
|
|
1
|
+
{"version":3,"file":"edgeFactory.d.ts","sourceRoot":"","sources":["../../src/edges/edgeFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,IAAI,EAAkF,MAAM,sBAAsB,CAAC;AAC5I,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAMzE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AASjC,eAAO,MAAM,WAAW,GAAI,6CAOzB;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5B,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,GAAG,EAAE,iBAAiB,CAAC;IACvB,KAAK,EAAE,KAAK,CAAC;CACd,SA4FA,CAAC"}
|
|
@@ -23,7 +23,7 @@ const edgeFactory = ({ graph, edges, nodes, tools, llm, agent, }) => {
|
|
|
23
23
|
if (edgesBySource.logical.length > 0) {
|
|
24
24
|
const logicalRouter = (0, createLogicalRouter_1.createLogicalRouter)({ edges: edgesBySource.logical });
|
|
25
25
|
const result = await logicalRouter(state);
|
|
26
|
-
if (result
|
|
26
|
+
if (result) {
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
@@ -43,7 +43,9 @@ const edgeFactory = ({ graph, edges, nodes, tools, llm, agent, }) => {
|
|
|
43
43
|
return await promptRouter(state);
|
|
44
44
|
}
|
|
45
45
|
// Fallback: stay at current source node
|
|
46
|
-
|
|
46
|
+
const source = (originalNode === null || originalNode === void 0 ? void 0 : originalNode.name) || sourceNode;
|
|
47
|
+
logger_1.logger.info(`No conditions matched, returning to source: ${source}`);
|
|
48
|
+
return source;
|
|
47
49
|
};
|
|
48
50
|
};
|
|
49
51
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edgeFactory.js","sourceRoot":"","sources":["../../src/edges/edgeFactory.ts"],"names":[],"mappings":";;;AAAA,sDAA4I;AAG5I,6DAA0D;AAC1D,+DAA4D;AAC5D,yDAAsD;AACtD,0EAAoG;AACpG,4DAA+E;AAG/E,4CAAyC;AAQlC,MAAM,WAAW,GAAG,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,GAAG,EACH,KAAK,GAQN,EAAE,EAAE;IACH;;OAEG;IACH,MAAM,oBAAoB,GAAG,CAAC,UAAkB,EAAE,aAA4B,EAAE,YAAkB,EAAE,EAAE;QACpG,OAAO,KAAK,EAAE,KAAU,EAAE,EAAE;YAC1B,wCAAwC;YACxC,IAAI,aAAa,CAAC,WAAW,EAAE,CAAC;gBAC9B,MAAM,YAAY,GAAG,IAAA,mCAAgB,EAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gBACjE,OAAO,MAAM,YAAY,EAAE,CAAC;YAC9B,CAAC;YAED,sCAAsC;YACtC,IAAI,aAAa,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrC,MAAM,aAAa,GAAG,IAAA,yCAAmB,EAAC,EAAE,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC5E,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;gBAC1C,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"edgeFactory.js","sourceRoot":"","sources":["../../src/edges/edgeFactory.ts"],"names":[],"mappings":";;;AAAA,sDAA4I;AAG5I,6DAA0D;AAC1D,+DAA4D;AAC5D,yDAA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3
|
-
"version": "1.0.80-beta.
|
|
3
|
+
"version": "1.0.80-beta.10",
|
|
4
4
|
"description": "MindedJS is a TypeScript library for building agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"ts-node": "^10.9.2",
|
|
48
48
|
"typedoc": "^0.28.5",
|
|
49
49
|
"typescript": "^5.3.3",
|
|
50
|
-
"typescript-eslint": "^8.32.1"
|
|
50
|
+
"typescript-eslint": "^8.32.1",
|
|
51
|
+
"zod": "^3.25.74"
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
54
|
"@langchain/core": "^0.3.55",
|
|
@@ -63,7 +64,6 @@
|
|
|
63
64
|
"socket.io-client": "^4.8.1",
|
|
64
65
|
"turndown": "^7.2.0",
|
|
65
66
|
"uuid": "^11.1.0",
|
|
66
|
-
"ws": "^8.15.1"
|
|
67
|
-
"zod": "^3.24.4"
|
|
67
|
+
"ws": "^8.15.1"
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -10,7 +10,12 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
10
10
|
return async (state: typeof stateAnnotation.State) => {
|
|
11
11
|
logger.debug(`Evaluating logical conditions for ${edges.length} edges`);
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// Separate regular conditions from "else" conditions
|
|
14
|
+
const regularEdges = edges.filter(edge => edge.condition.trim() !== 'else');
|
|
15
|
+
const elseEdges = edges.filter(edge => edge.condition.trim() === 'else');
|
|
16
|
+
|
|
17
|
+
// First, evaluate all regular conditions
|
|
18
|
+
for (const edge of regularEdges) {
|
|
14
19
|
try {
|
|
15
20
|
// Customer is responsible for providing valid JavaScript syntax
|
|
16
21
|
// We execute their condition in a sandboxed VM with timeout protection
|
|
@@ -53,12 +58,11 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
53
58
|
new Promise((_, reject) => setTimeout(() => reject(new Error('Condition execution timeout')), CONDITION_TIMEOUT)),
|
|
54
59
|
]);
|
|
55
60
|
|
|
56
|
-
if (result) {
|
|
61
|
+
if (result === true) {
|
|
57
62
|
logger.info(`Condition matched for edge ${edge.source} → ${edge.target}`);
|
|
58
63
|
return edge.target;
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
logger.debug(`Condition not matched for edge ${edge.source} → ${edge.target}`);
|
|
62
66
|
} catch (error) {
|
|
63
67
|
// Provide detailed error information back to the customer
|
|
64
68
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -78,8 +82,17 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
|
|
85
|
+
// If no regular conditions matched, check for "else" conditions
|
|
86
|
+
if (elseEdges.length > 0) {
|
|
87
|
+
logger.info(`No regular conditions matched, evaluating ${elseEdges.length} else condition(s)`);
|
|
88
|
+
// Return the first "else" condition's target
|
|
89
|
+
const elseEdge = elseEdges[0];
|
|
90
|
+
logger.info(`Else condition matched for edge ${elseEdge.source} → ${elseEdge.target}`);
|
|
91
|
+
return elseEdge.target;
|
|
92
|
+
}
|
|
93
|
+
|
|
81
94
|
// If no conditions matched or all failed, return to the source node
|
|
82
|
-
logger.info(
|
|
83
|
-
return
|
|
95
|
+
logger.info('No conditions matched');
|
|
96
|
+
return null;
|
|
84
97
|
};
|
|
85
98
|
};
|
package/src/edges/edgeFactory.ts
CHANGED
|
@@ -46,7 +46,7 @@ export const edgeFactory = ({
|
|
|
46
46
|
if (edgesBySource.logical.length > 0) {
|
|
47
47
|
const logicalRouter = createLogicalRouter({ edges: edgesBySource.logical });
|
|
48
48
|
const result = await logicalRouter(state);
|
|
49
|
-
if (result
|
|
49
|
+
if (result) {
|
|
50
50
|
return result;
|
|
51
51
|
} else {
|
|
52
52
|
logger.debug('No logical conditions matched, continuing to prompt conditions');
|
|
@@ -68,7 +68,9 @@ export const edgeFactory = ({
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// Fallback: stay at current source node
|
|
71
|
-
|
|
71
|
+
const source = originalNode?.name || sourceNode;
|
|
72
|
+
logger.info(`No conditions matched, returning to source: ${source}`);
|
|
73
|
+
return source;
|
|
72
74
|
};
|
|
73
75
|
};
|
|
74
76
|
|