@ai.ntellect/core 0.7.5 → 0.7.7
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/graph/controller.d.ts +8 -10
- package/dist/graph/controller.d.ts.map +1 -1
- package/dist/graph/controller.js +25 -27
- package/dist/graph/controller.js.map +1 -1
- package/dist/graph/index.d.ts +5 -3
- package/dist/graph/index.d.ts.map +1 -1
- package/dist/graph/index.js +13 -9
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/node.d.ts +15 -26
- package/dist/graph/node.d.ts.map +1 -1
- package/dist/graph/node.js +66 -101
- package/dist/graph/node.js.map +1 -1
- package/dist/graph/observer.d.ts.map +1 -1
- package/dist/graph/observer.js +0 -1
- package/dist/graph/observer.js.map +1 -1
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/generate-action-schema.js +2 -2
- package/graph/controller.ts +36 -40
- package/graph/index.ts +17 -13
- package/graph/node.ts +79 -134
- package/graph/observer.ts +0 -1
- package/package.json +1 -1
- package/test/graph/controller.test.ts +187 -0
- package/test/graph/index.test.ts +138 -97
- package/test/graph/node.test.ts +319 -6
- package/types/index.ts +5 -8
- package/utils/generate-action-schema.ts +2 -2
@@ -1,5 +1,7 @@
|
|
1
1
|
import { ZodSchema } from "zod";
|
2
|
+
import { GraphContext } from "../types";
|
2
3
|
import { GraphFlow } from "./index";
|
4
|
+
import { NodeParams } from "./node";
|
3
5
|
/**
|
4
6
|
* Controller class for managing the execution of graph flows
|
5
7
|
* Handles both sequential and parallel execution of multiple graphs
|
@@ -9,25 +11,21 @@ export declare class GraphController {
|
|
9
11
|
* Executes multiple graphs sequentially
|
10
12
|
* @param graphs - Array of GraphFlow instances to execute
|
11
13
|
* @param startNodes - Array of starting node identifiers for each graph
|
12
|
-
* @param
|
14
|
+
* @param params - Optional array of node parameters for each graph
|
13
15
|
* @returns Map containing results of each graph execution, keyed by graph name and index
|
14
16
|
* @template T - Zod schema type for graph context validation
|
15
17
|
*/
|
16
|
-
static executeSequential<T extends ZodSchema
|
17
|
-
|
18
|
-
}, startNodes: string[], inputs: any[]): Promise<any[]>;
|
18
|
+
static executeSequential<T extends ZodSchema>(graphs: GraphFlow<T>[], startNodes: string[], params?: NodeParams[]): Promise<any[]>;
|
19
|
+
private static executeGraph;
|
19
20
|
/**
|
20
21
|
* Executes multiple graphs in parallel with optional concurrency control
|
21
22
|
* @param graphs - Array of GraphFlow instances to execute
|
22
23
|
* @param startNodes - Array of starting node identifiers for each graph
|
23
|
-
* @param
|
24
|
-
* @param
|
25
|
-
* @param concurrencyLimit - Optional limit on number of concurrent graph executions
|
24
|
+
* @param concurrency - Optional limit on number of concurrent graph executions
|
25
|
+
* @param params - Optional array of node parameters for each graph
|
26
26
|
* @returns Map containing results of each graph execution, keyed by graph name
|
27
27
|
* @template T - Zod schema type for graph context validation
|
28
28
|
*/
|
29
|
-
static executeParallel<T extends ZodSchema
|
30
|
-
[K in keyof T]: GraphFlow<T[K]>;
|
31
|
-
}, startNodes: string[], concurrency: number, inputs: any[]): Promise<any[]>;
|
29
|
+
static executeParallel<T extends ZodSchema>(graphs: GraphFlow<T>[], startNodes: string[], concurrency: number, params?: NodeParams[]): Promise<GraphContext<T>[]>;
|
32
30
|
}
|
33
31
|
//# sourceMappingURL=controller.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../graph/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../graph/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;;GAGG;AACH,qBAAa,eAAe;IAC1B;;;;;;;OAOG;WACU,iBAAiB,CAAC,CAAC,SAAS,SAAS,EAChD,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,EACtB,UAAU,EAAE,MAAM,EAAE,EACpB,MAAM,CAAC,EAAE,UAAU,EAAE,GACpB,OAAO,CAAC,GAAG,EAAE,CAAC;mBASI,YAAY;IAYjC;;;;;;;;OAQG;WACU,eAAe,CAAC,CAAC,SAAS,SAAS,EAC9C,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,EACtB,UAAU,EAAE,MAAM,EAAE,EACpB,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,UAAU,EAAE,GACpB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;CAgB9B"}
|
package/dist/graph/controller.js
CHANGED
@@ -19,53 +19,51 @@ class GraphController {
|
|
19
19
|
* Executes multiple graphs sequentially
|
20
20
|
* @param graphs - Array of GraphFlow instances to execute
|
21
21
|
* @param startNodes - Array of starting node identifiers for each graph
|
22
|
-
* @param
|
22
|
+
* @param params - Optional array of node parameters for each graph
|
23
23
|
* @returns Map containing results of each graph execution, keyed by graph name and index
|
24
24
|
* @template T - Zod schema type for graph context validation
|
25
25
|
*/
|
26
|
-
static executeSequential(graphs, startNodes,
|
26
|
+
static executeSequential(graphs, startNodes, params) {
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
28
28
|
const results = new Map();
|
29
29
|
for (let i = 0; i < graphs.length; i++) {
|
30
|
-
const result = yield graphs[i].execute(startNodes[i],
|
30
|
+
const result = yield graphs[i].execute(startNodes[i], params === null || params === void 0 ? void 0 : params[i]);
|
31
31
|
results.set(`${graphs[i].name}-${i}`, result);
|
32
32
|
}
|
33
33
|
return Array.from(results.values());
|
34
34
|
});
|
35
35
|
}
|
36
|
+
static executeGraph(graph, startNode, params) {
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
38
|
+
try {
|
39
|
+
return yield graph.execute(startNode, params);
|
40
|
+
}
|
41
|
+
catch (error) {
|
42
|
+
throw error;
|
43
|
+
}
|
44
|
+
});
|
45
|
+
}
|
36
46
|
/**
|
37
47
|
* Executes multiple graphs in parallel with optional concurrency control
|
38
48
|
* @param graphs - Array of GraphFlow instances to execute
|
39
49
|
* @param startNodes - Array of starting node identifiers for each graph
|
40
|
-
* @param
|
41
|
-
* @param
|
42
|
-
* @param concurrencyLimit - Optional limit on number of concurrent graph executions
|
50
|
+
* @param concurrency - Optional limit on number of concurrent graph executions
|
51
|
+
* @param params - Optional array of node parameters for each graph
|
43
52
|
* @returns Map containing results of each graph execution, keyed by graph name
|
44
53
|
* @template T - Zod schema type for graph context validation
|
45
54
|
*/
|
46
|
-
static executeParallel(graphs, startNodes, concurrency,
|
55
|
+
static executeParallel(graphs, startNodes, concurrency, params) {
|
47
56
|
return __awaiter(this, void 0, void 0, function* () {
|
48
|
-
const results =
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
.map((graph, index) => graph.execute(startNodes[i + index], inputs === null || inputs === void 0 ? void 0 : inputs[i + index])));
|
57
|
-
batchResults.forEach((result, index) => {
|
58
|
-
results.set(`${graphs[i + index].name}`, result);
|
59
|
-
});
|
60
|
-
}
|
57
|
+
const results = [];
|
58
|
+
for (let i = 0; i < graphs.length; i += concurrency) {
|
59
|
+
const batch = graphs.slice(i, i + concurrency);
|
60
|
+
const batchResults = yield Promise.all(batch.map((graph, idx) => {
|
61
|
+
const param = params === null || params === void 0 ? void 0 : params[i + idx];
|
62
|
+
return this.executeGraph(graph, startNodes[i + idx], param);
|
63
|
+
}));
|
64
|
+
results.push(...batchResults);
|
61
65
|
}
|
62
|
-
|
63
|
-
const allResults = yield Promise.all(graphs.map((graph, index) => graph.execute(startNodes[index], (inputs === null || inputs === void 0 ? void 0 : inputs[index]) || {})));
|
64
|
-
allResults.forEach((result, index) => {
|
65
|
-
results.set(`${graphs[index].name}`, result);
|
66
|
-
});
|
67
|
-
}
|
68
|
-
return Array.from(results.values());
|
66
|
+
return results;
|
69
67
|
});
|
70
68
|
}
|
71
69
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../graph/controller.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../graph/controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA;;;GAGG;AACH,MAAa,eAAe;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAO,iBAAiB,CAC5B,MAAsB,EACtB,UAAoB,EACpB,MAAqB;;YAErB,MAAM,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;YACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACvC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,CAAC,CAAC,CAAC,CAAC;gBACnE,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACtC,CAAC;KAAA;IAEO,MAAM,CAAO,YAAY,CAC/B,KAAmB,EACnB,SAAiB,EACjB,MAAmB;;YAEnB,IAAI,CAAC;gBACH,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KAAA;IAED;;;;;;;;OAQG;IACH,MAAM,CAAO,eAAe,CAC1B,MAAsB,EACtB,UAAoB,EACpB,WAAmB,EACnB,MAAqB;;YAErB,MAAM,OAAO,GAAsB,EAAE,CAAC;YAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC;gBACpD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC;gBAC/C,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CACpC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;oBACvB,MAAM,KAAK,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,CAAC,GAAG,GAAG,CAAC,CAAC;oBAChC,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC9D,CAAC,CAAC,CACH,CAAC;gBACF,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;YAChC,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;CACF;AAhED,0CAgEC"}
|
package/dist/graph/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { ZodSchema } from "zod";
|
2
2
|
import { GraphObservable } from "../interfaces";
|
3
3
|
import { GraphContext, GraphDefinition, Node } from "../types";
|
4
|
+
import { NodeParams } from "./node";
|
4
5
|
import { GraphObserver } from "./observer";
|
5
6
|
/**
|
6
7
|
* @module GraphFlow
|
@@ -99,11 +100,12 @@ export declare class GraphFlow<T extends ZodSchema> {
|
|
99
100
|
/**
|
100
101
|
* Executes the graph flow starting from a specific node
|
101
102
|
* @param {string} startNode - Name of the node to start execution from
|
102
|
-
* @param {
|
103
|
-
* @param {
|
103
|
+
* @param {any} inputs - Optional input parameters for the start node
|
104
|
+
* @param {Partial<GraphContext<T>>} context - Optional context to merge
|
105
|
+
* @param {NodeParams} params - Optional node parameters
|
104
106
|
* @returns {Promise<GraphContext<T>>} Final context after execution
|
105
107
|
*/
|
106
|
-
execute(startNode: string,
|
108
|
+
execute(startNode: string, params?: NodeParams, context?: Partial<GraphContext<T>>): Promise<GraphContext<T>>;
|
107
109
|
/**
|
108
110
|
* Emits an event to trigger event-based nodes
|
109
111
|
* @param {string} eventName - Name of the event to emit
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../graph/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,eAAe,EAAiB,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAc,IAAI,EAAE,MAAM,UAAU,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../graph/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,eAAe,EAAiB,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAc,IAAI,EAAE,MAAM,UAAU,CAAC;AAG3E,OAAO,EAAa,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,qBAAa,SAAS,CAAC,CAAC,SAAS,SAAS;IA0B/B,IAAI,EAAE,MAAM;IAzBrB,OAAO,CAAC,OAAO,CAAkB;IAC1B,SAAS,CAAC,EAAE,CAAC,CAAC;IACrB,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,kBAAkB,CAAC,CAAmD;IAC9E,OAAO,CAAC,WAAW,CAAC,CAAW;IAC/B,OAAO,CAAC,SAAS,CAAC,CAAS;IA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CAAC,CAAC;IAIrB;;;OAGG;IACI,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIzC;;;OAGG;IACI,SAAS,IAAI,OAAO;IAI3B;;;;;;;OAOG;IACU,OAAO,CAClB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,UAAU,EACnB,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAmC3B;;;;;OAKG;IACU,IAAI,CACf,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;IAUhB;;;;OAIG;IACI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAIrE;;;OAGG;IACI,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI;IAiDjD;;;OAGG;IACI,UAAU,IAAI,YAAY,CAAC,CAAC,CAAC;IAIpC;;;;OAIG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAI7C;;;;OAIG;IACI,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI;IAKxC;;;OAGG;IACI,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKzC;;;OAGG;IACI,QAAQ,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;IAIjC;;OAEG;IACI,OAAO,IAAI,IAAI;CAMvB"}
|
package/dist/graph/index.js
CHANGED
@@ -150,22 +150,26 @@ class GraphFlow {
|
|
150
150
|
/**
|
151
151
|
* Executes the graph flow starting from a specific node
|
152
152
|
* @param {string} startNode - Name of the node to start execution from
|
153
|
-
* @param {
|
154
|
-
* @param {
|
153
|
+
* @param {any} inputs - Optional input parameters for the start node
|
154
|
+
* @param {Partial<GraphContext<T>>} context - Optional context to merge
|
155
|
+
* @param {NodeParams} params - Optional node parameters
|
155
156
|
* @returns {Promise<GraphContext<T>>} Final context after execution
|
156
157
|
*/
|
157
|
-
execute(startNode,
|
158
|
+
execute(startNode, params, context) {
|
158
159
|
return __awaiter(this, void 0, void 0, function* () {
|
159
160
|
var _a;
|
160
|
-
if (
|
161
|
-
Object.assign(this.context,
|
162
|
-
}
|
163
|
-
if (inputContext) {
|
164
|
-
Object.assign(this.context, inputContext);
|
161
|
+
if (context) {
|
162
|
+
Object.assign(this.context, context);
|
165
163
|
}
|
166
164
|
this.eventEmitter.emit("graphStarted", { name: this.name });
|
167
165
|
try {
|
168
|
-
|
166
|
+
const node = this.nodes.get(startNode);
|
167
|
+
if (!node)
|
168
|
+
throw new Error(`Node "${startNode}" not found`);
|
169
|
+
if (node.params && !params) {
|
170
|
+
throw new Error(`Params required for node "${startNode}"`);
|
171
|
+
}
|
172
|
+
yield this.nodeExecutor.executeNode(startNode, this.context, params, false);
|
169
173
|
this.eventEmitter.emit("graphCompleted", {
|
170
174
|
name: this.name,
|
171
175
|
context: this.context,
|
package/dist/graph/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../graph/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAsC;AACtC,+BAAgD;AAIhD,mDAAoD;AACpD,qCAAuC;AACvC,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../graph/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAsC;AACtC,+BAAgD;AAIhD,mDAAoD;AACpD,qCAAuC;AACvC,iCAA+C;AAC/C,yCAA2C;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAa,SAAS;IAmBpB;;;;;OAKG;IACH,YACS,IAAY,EACnB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G,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,IAAkB;QAC/B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACI,UAAU,CAAC,QAAgB;QAChC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5B,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;QAC7B,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF;AArXD,8BAqXC"}
|
package/dist/graph/node.d.ts
CHANGED
@@ -2,17 +2,23 @@ import { BehaviorSubject, Subject } from "rxjs";
|
|
2
2
|
import { ZodSchema } from "zod";
|
3
3
|
import { GraphContext, GraphEvent, Node } from "../types";
|
4
4
|
import { GraphEventManager } from "./event-manager";
|
5
|
-
import { GraphLogger } from "./logger";
|
6
5
|
/**
|
7
6
|
* Represents a node in the graph that can execute operations and manage state
|
8
7
|
* @template T - The Zod schema type for validation
|
9
8
|
*/
|
9
|
+
export interface NodeParams<T = any> {
|
10
|
+
[key: string]: T;
|
11
|
+
}
|
12
|
+
export interface GraphLogger {
|
13
|
+
addLog: (message: string, data?: any) => void;
|
14
|
+
}
|
10
15
|
export declare class GraphNode<T extends ZodSchema> {
|
11
16
|
private nodes;
|
12
17
|
private logger;
|
13
18
|
private eventManager;
|
14
19
|
private eventSubject;
|
15
20
|
private stateSubject;
|
21
|
+
private lastStateEvent;
|
16
22
|
/**
|
17
23
|
* Creates a new GraphNode instance
|
18
24
|
* @param nodes - Map of all nodes in the graph
|
@@ -33,29 +39,20 @@ export declare class GraphNode<T extends ZodSchema> {
|
|
33
39
|
* Executes a node with the given name and context
|
34
40
|
* @param nodeName - The name of the node to execute
|
35
41
|
* @param context - The current graph context
|
36
|
-
* @param
|
42
|
+
* @param params - Input data for the node
|
37
43
|
* @param triggeredByEvent - Whether the execution was triggered by an event
|
38
44
|
* @throws Error if the node is not found or execution fails
|
39
45
|
*/
|
40
|
-
executeNode(nodeName: string, context: GraphContext<T>,
|
46
|
+
executeNode(nodeName: string, context: GraphContext<T>, params: any, triggeredByEvent?: boolean): Promise<void>;
|
41
47
|
/**
|
42
|
-
* Validates the
|
43
|
-
* @param node - The node whose
|
44
|
-
* @param
|
48
|
+
* Validates the params for a node using its schema
|
49
|
+
* @param node - The node whose params need validation
|
50
|
+
* @param params - The input data to validate
|
45
51
|
* @param nodeName - The name of the node (for error messages)
|
46
52
|
* @throws Error if validation fails
|
47
53
|
* @private
|
48
54
|
*/
|
49
|
-
private
|
50
|
-
/**
|
51
|
-
* Validates the outputs of a node against its schema
|
52
|
-
* @param node - The node whose outputs need validation
|
53
|
-
* @param context - The current graph context
|
54
|
-
* @param nodeName - The name of the node (for error messages)
|
55
|
-
* @throws Error if validation fails
|
56
|
-
* @private
|
57
|
-
*/
|
58
|
-
private validateOutputs;
|
55
|
+
private validateParams;
|
59
56
|
/**
|
60
57
|
* Handles event-related operations for a node
|
61
58
|
* @param node - The node whose events need handling
|
@@ -68,21 +65,13 @@ export declare class GraphNode<T extends ZodSchema> {
|
|
68
65
|
* Executes a node with retry logic
|
69
66
|
* @param node - The node to execute
|
70
67
|
* @param contextProxy - The proxied graph context
|
71
|
-
* @param
|
68
|
+
* @param params - Input data for the node
|
72
69
|
* @param nodeName - The name of the node
|
70
|
+
* @param params - Parameters for the node
|
73
71
|
* @throws Error if all retry attempts fail
|
74
72
|
* @private
|
75
73
|
*/
|
76
74
|
private executeWithRetry;
|
77
|
-
/**
|
78
|
-
* Handles the failure of retry attempts
|
79
|
-
* @param node - The node that failed
|
80
|
-
* @param error - The error that caused the failure
|
81
|
-
* @param context - The current graph context
|
82
|
-
* @param nodeName - The name of the node
|
83
|
-
* @private
|
84
|
-
*/
|
85
|
-
private handleRetryFailure;
|
86
75
|
/**
|
87
76
|
* Handles correlated events for a node
|
88
77
|
* @param node - The node with correlated events
|
package/dist/graph/node.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../graph/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../graph/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;GAGG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,GAAG;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CAC/C;AAED,qBAAa,SAAS,CAAC,CAAC,SAAS,SAAS;IAYtC,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,YAAY;IAftB,OAAO,CAAC,cAAc,CAA8B;IAEpD;;;;;;;OAOG;gBAEO,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAChC,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAClC,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACpC,YAAY,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAGxD;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IA+BjB;;;;;;;OAOG;IACU,WAAW,CACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,MAAM,EAAE,GAAG,EACX,gBAAgB,GAAE,OAAe,GAChC,OAAO,CAAC,IAAI,CAAC;IAqDhB;;;;;;;OAOG;YACW,cAAc;IAoB5B;;;;;;OAMG;YACW,YAAY;IAc1B;;;;;;;;;OASG;YACW,gBAAgB;IAwC9B;;;;;;OAMG;YACW,sBAAsB;IAuCpC;;;;;;OAMG;YACW,mBAAmB;CAalC"}
|
package/dist/graph/node.js
CHANGED
@@ -10,10 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.GraphNode = void 0;
|
13
|
-
/**
|
14
|
-
* Represents a node in the graph that can execute operations and manage state
|
15
|
-
* @template T - The Zod schema type for validation
|
16
|
-
*/
|
17
13
|
class GraphNode {
|
18
14
|
/**
|
19
15
|
* Creates a new GraphNode instance
|
@@ -29,6 +25,7 @@ class GraphNode {
|
|
29
25
|
this.eventManager = eventManager;
|
30
26
|
this.eventSubject = eventSubject;
|
31
27
|
this.stateSubject = stateSubject;
|
28
|
+
this.lastStateEvent = null;
|
32
29
|
}
|
33
30
|
/**
|
34
31
|
* Emits an event with the specified type and payload
|
@@ -37,18 +34,24 @@ class GraphNode {
|
|
37
34
|
* @private
|
38
35
|
*/
|
39
36
|
emitEvent(type, payload) {
|
40
|
-
|
37
|
+
var _a;
|
38
|
+
if (type === "nodeStateChanged") {
|
39
|
+
if (((_a = this.lastStateEvent) === null || _a === void 0 ? void 0 : _a.type) === type &&
|
40
|
+
this.lastStateEvent.payload.property === payload.property &&
|
41
|
+
this.lastStateEvent.payload.newValue === payload.newValue &&
|
42
|
+
this.lastStateEvent.payload.nodeName === payload.nodeName) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
}
|
41
46
|
const event = {
|
42
47
|
type,
|
43
|
-
payload: Object.assign(Object.assign({}, payload), { name: type === "nodeStateChanged"
|
44
|
-
? payload.name || payload.nodeName
|
45
|
-
: payload.name, context: Object.assign({}, payload.context) }),
|
48
|
+
payload: Object.assign(Object.assign({}, payload), { name: type === "nodeStateChanged" ? payload.nodeName : payload.name, context: Object.assign({}, payload.context) }),
|
46
49
|
timestamp: Date.now(),
|
47
50
|
};
|
48
51
|
this.eventSubject.next(event);
|
49
52
|
this.eventManager.emitEvent(type, event);
|
50
|
-
// Update state subject only for state changes
|
51
53
|
if (type === "nodeStateChanged") {
|
54
|
+
this.lastStateEvent = event;
|
52
55
|
this.stateSubject.next(Object.assign({}, payload.context));
|
53
56
|
}
|
54
57
|
}
|
@@ -56,101 +59,82 @@ class GraphNode {
|
|
56
59
|
* Executes a node with the given name and context
|
57
60
|
* @param nodeName - The name of the node to execute
|
58
61
|
* @param context - The current graph context
|
59
|
-
* @param
|
62
|
+
* @param params - Input data for the node
|
60
63
|
* @param triggeredByEvent - Whether the execution was triggered by an event
|
61
64
|
* @throws Error if the node is not found or execution fails
|
62
65
|
*/
|
63
|
-
executeNode(nodeName_1, context_1,
|
64
|
-
return __awaiter(this, arguments, void 0, function* (nodeName, context,
|
66
|
+
executeNode(nodeName_1, context_1, params_1) {
|
67
|
+
return __awaiter(this, arguments, void 0, function* (nodeName, context, params, triggeredByEvent = false) {
|
65
68
|
const node = this.nodes.get(nodeName);
|
66
69
|
if (!node)
|
67
70
|
throw new Error(`Node "${nodeName}" not found.`);
|
68
|
-
|
69
|
-
|
71
|
+
// Créer une copie du contexte pour ce nœud
|
72
|
+
const nodeContext = Object.assign({}, context);
|
73
|
+
this.emitEvent("nodeStarted", { name: nodeName, context: nodeContext });
|
70
74
|
try {
|
71
|
-
|
72
|
-
if (node.condition && !node.condition(context)) {
|
73
|
-
this.logger.addLog(`⏭️ Skipping node "${nodeName}" - condition not met`);
|
74
|
-
return;
|
75
|
-
}
|
76
|
-
const contextProxy = new Proxy(context, {
|
75
|
+
const contextProxy = new Proxy(nodeContext, {
|
77
76
|
set: (target, prop, value) => {
|
78
77
|
const oldValue = target[prop];
|
79
78
|
if (oldValue === value)
|
80
79
|
return true;
|
81
80
|
target[prop] = value;
|
81
|
+
// Mettre à jour le contexte global
|
82
|
+
context[prop] = value;
|
82
83
|
this.emitEvent("nodeStateChanged", {
|
83
84
|
nodeName,
|
84
85
|
property: prop.toString(),
|
85
86
|
oldValue,
|
86
87
|
newValue: value,
|
87
|
-
context: target,
|
88
|
+
context: Object.assign({}, target),
|
88
89
|
});
|
89
90
|
return true;
|
90
91
|
},
|
91
|
-
get: (target, prop) => target[prop],
|
92
92
|
});
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
93
|
+
if (node.condition && !node.condition(contextProxy, params)) {
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
yield this.executeWithRetry(node, contextProxy, nodeName, params);
|
97
|
+
this.emitEvent("nodeCompleted", { name: nodeName, context: nodeContext });
|
98
|
+
if (!triggeredByEvent && node.next) {
|
99
|
+
const nextNodes = typeof node.next === "function" ? node.next(contextProxy) : node.next;
|
100
100
|
for (const nextNodeName of nextNodes) {
|
101
101
|
yield this.executeNode(nextNodeName, context, undefined, false);
|
102
102
|
}
|
103
103
|
}
|
104
|
-
this.logger.addLog(`✅ Node "${nodeName}" executed successfully`);
|
105
|
-
this.emitEvent("nodeCompleted", { name: nodeName, context });
|
106
104
|
}
|
107
105
|
catch (error) {
|
108
|
-
this.
|
109
|
-
|
106
|
+
this.emitEvent("nodeError", {
|
107
|
+
name: nodeName,
|
108
|
+
error,
|
109
|
+
context: nodeContext,
|
110
|
+
});
|
110
111
|
throw error;
|
111
112
|
}
|
112
113
|
});
|
113
114
|
}
|
114
115
|
/**
|
115
|
-
* Validates the
|
116
|
-
* @param node - The node whose
|
117
|
-
* @param
|
116
|
+
* Validates the params for a node using its schema
|
117
|
+
* @param node - The node whose params need validation
|
118
|
+
* @param params - The input data to validate
|
118
119
|
* @param nodeName - The name of the node (for error messages)
|
119
120
|
* @throws Error if validation fails
|
120
121
|
* @private
|
121
122
|
*/
|
122
|
-
|
123
|
+
validateParams(node, params, nodeName) {
|
123
124
|
return __awaiter(this, void 0, void 0, function* () {
|
124
125
|
var _a, _b;
|
125
|
-
|
126
|
-
|
126
|
+
// Si pas de schéma de validation ou si le schéma est optionnel, accepter n'importe quels params
|
127
|
+
if (!node.params || ((_b = (_a = node.params).isOptional) === null || _b === void 0 ? void 0 : _b.call(_a)))
|
128
|
+
return;
|
129
|
+
// Vérifier les params uniquement si un schéma est défini et non optionnel
|
130
|
+
if (!params) {
|
131
|
+
throw new Error(`Params required for node "${nodeName}"`);
|
127
132
|
}
|
128
133
|
try {
|
129
|
-
return node.
|
134
|
+
return node.params.parse(params);
|
130
135
|
}
|
131
136
|
catch (error) {
|
132
|
-
throw
|
133
|
-
}
|
134
|
-
});
|
135
|
-
}
|
136
|
-
/**
|
137
|
-
* Validates the outputs of a node against its schema
|
138
|
-
* @param node - The node whose outputs need validation
|
139
|
-
* @param context - The current graph context
|
140
|
-
* @param nodeName - The name of the node (for error messages)
|
141
|
-
* @throws Error if validation fails
|
142
|
-
* @private
|
143
|
-
*/
|
144
|
-
validateOutputs(node, context, nodeName) {
|
145
|
-
return __awaiter(this, void 0, void 0, function* () {
|
146
|
-
var _a, _b;
|
147
|
-
try {
|
148
|
-
node.outputs.parse(context);
|
149
|
-
}
|
150
|
-
catch (error) {
|
151
|
-
throw new Error(((_b = (_a = error.errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) ||
|
152
|
-
error.message ||
|
153
|
-
"Output validation failed");
|
137
|
+
throw error;
|
154
138
|
}
|
155
139
|
});
|
156
140
|
}
|
@@ -175,28 +159,37 @@ class GraphNode {
|
|
175
159
|
* Executes a node with retry logic
|
176
160
|
* @param node - The node to execute
|
177
161
|
* @param contextProxy - The proxied graph context
|
178
|
-
* @param
|
162
|
+
* @param params - Input data for the node
|
179
163
|
* @param nodeName - The name of the node
|
164
|
+
* @param params - Parameters for the node
|
180
165
|
* @throws Error if all retry attempts fail
|
181
166
|
* @private
|
182
167
|
*/
|
183
|
-
executeWithRetry(node, contextProxy,
|
168
|
+
executeWithRetry(node, contextProxy, nodeName, params) {
|
184
169
|
return __awaiter(this, void 0, void 0, function* () {
|
170
|
+
var _a, _b, _c;
|
185
171
|
let attempts = 0;
|
186
|
-
let lastError =
|
187
|
-
while (attempts < node.retry.maxAttempts) {
|
172
|
+
let lastError = new Error("Unknown error");
|
173
|
+
while (attempts < (((_a = node.retry) === null || _a === void 0 ? void 0 : _a.maxAttempts) || 1)) {
|
188
174
|
try {
|
189
|
-
|
190
|
-
|
175
|
+
// Valider les params uniquement si un schéma est défini
|
176
|
+
if (node.params) {
|
177
|
+
yield this.validateParams(node, params, nodeName);
|
178
|
+
}
|
179
|
+
yield node.execute(contextProxy, params);
|
191
180
|
return;
|
192
181
|
}
|
193
182
|
catch (error) {
|
194
|
-
lastError =
|
183
|
+
lastError =
|
184
|
+
error instanceof Error
|
185
|
+
? error
|
186
|
+
: new Error((error === null || error === void 0 ? void 0 : error.message) || "Unknown error");
|
195
187
|
attempts++;
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
188
|
+
if (attempts === (((_b = node.retry) === null || _b === void 0 ? void 0 : _b.maxAttempts) || 1)) {
|
189
|
+
if ((_c = node.retry) === null || _c === void 0 ? void 0 : _c.onRetryFailed) {
|
190
|
+
yield node.retry.onRetryFailed(lastError, contextProxy);
|
191
|
+
if (node.retry.continueOnFailed)
|
192
|
+
return;
|
200
193
|
}
|
201
194
|
throw lastError;
|
202
195
|
}
|
@@ -205,34 +198,6 @@ class GraphNode {
|
|
205
198
|
}
|
206
199
|
});
|
207
200
|
}
|
208
|
-
/**
|
209
|
-
* Handles the failure of retry attempts
|
210
|
-
* @param node - The node that failed
|
211
|
-
* @param error - The error that caused the failure
|
212
|
-
* @param context - The current graph context
|
213
|
-
* @param nodeName - The name of the node
|
214
|
-
* @private
|
215
|
-
*/
|
216
|
-
handleRetryFailure(node, error, context, nodeName) {
|
217
|
-
return __awaiter(this, void 0, void 0, function* () {
|
218
|
-
var _a;
|
219
|
-
this.logger.addLog(`🔄 Executing retry failure handler for node "${nodeName}"`);
|
220
|
-
try {
|
221
|
-
if ((_a = node.retry) === null || _a === void 0 ? void 0 : _a.onRetryFailed) {
|
222
|
-
yield node.retry.onRetryFailed(error, context);
|
223
|
-
if (node.retry.continueOnFailed) {
|
224
|
-
this.logger.addLog(`✅ Retry failure handler succeeded - continuing execution`);
|
225
|
-
return;
|
226
|
-
}
|
227
|
-
this.logger.addLog(`⚠️ Retry failure handler executed but node will still fail`);
|
228
|
-
}
|
229
|
-
}
|
230
|
-
catch (handlerError) {
|
231
|
-
this.logger.addLog(`❌ Retry failure handler failed: ${handlerError.message}`);
|
232
|
-
throw handlerError;
|
233
|
-
}
|
234
|
-
});
|
235
|
-
}
|
236
201
|
/**
|
237
202
|
* Handles correlated events for a node
|
238
203
|
* @param node - The node with correlated events
|