@ai.ntellect/core 0.7.10 → 0.7.12
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/event-manager.d.ts +2 -2
- package/dist/graph/event-manager.d.ts.map +1 -1
- package/dist/graph/event-manager.js.map +1 -1
- package/dist/graph/index.d.ts +15 -9
- package/dist/graph/index.d.ts.map +1 -1
- package/dist/graph/index.js +11 -3
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/node.d.ts +2 -2
- package/dist/graph/node.d.ts.map +1 -1
- package/dist/graph/node.js +2 -1
- package/dist/graph/node.js.map +1 -1
- package/dist/graph/visualizer.d.ts +34 -0
- package/dist/graph/visualizer.d.ts.map +1 -0
- package/dist/graph/visualizer.js +227 -0
- package/dist/graph/visualizer.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +11 -8
- package/dist/types/index.d.ts.map +1 -1
- package/graph/event-manager.ts +2 -2
- package/graph/index.ts +25 -11
- package/graph/node.ts +10 -8
- package/graph/visualizer.ts +243 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/test/graph/controller.test.ts +2 -2
- package/test/graph/index.test.ts +27 -27
- package/test/graph/observer.test.ts +9 -9
- package/types/index.ts +15 -8
package/test/graph/index.test.ts
CHANGED
@@ -6,7 +6,7 @@ import { z } from "zod";
|
|
6
6
|
import { GraphController } from "../../graph/controller";
|
7
7
|
import { GraphFlow } from "../../graph/index";
|
8
8
|
import { NodeParams } from "../../graph/node";
|
9
|
-
import { GraphContext,
|
9
|
+
import { GraphContext, GraphConfig, GraphNodeConfig } from "../../types";
|
10
10
|
|
11
11
|
use(chaiAsPromised);
|
12
12
|
|
@@ -69,7 +69,7 @@ describe("GraphFlow", function () {
|
|
69
69
|
* - The updated context is accessible after execution
|
70
70
|
*/
|
71
71
|
it("should execute a simple node and update the context", async function () {
|
72
|
-
const simpleNode:
|
72
|
+
const simpleNode: GraphNodeConfig<TestSchema> = {
|
73
73
|
name: "simpleNode",
|
74
74
|
execute: async (context) => {
|
75
75
|
context.value = (context.value ?? 0) + 1;
|
@@ -98,7 +98,7 @@ describe("GraphFlow", function () {
|
|
98
98
|
graph.on("nodeStarted", nodeStartedSpy);
|
99
99
|
graph.on("nodeCompleted", nodeCompletedSpy);
|
100
100
|
|
101
|
-
const testNode:
|
101
|
+
const testNode: GraphNodeConfig<TestSchema> = {
|
102
102
|
name: "testNode",
|
103
103
|
execute: async (context) => {
|
104
104
|
context.value = (context.value ?? 0) + 1;
|
@@ -122,7 +122,7 @@ describe("GraphFlow", function () {
|
|
122
122
|
* This ensures robust error handling in the workflow
|
123
123
|
*/
|
124
124
|
it("should handle errors and trigger `nodeError` event", async function () {
|
125
|
-
const errorNode:
|
125
|
+
const errorNode: GraphNodeConfig<TestSchema> = {
|
126
126
|
name: "errorNode",
|
127
127
|
execute: async () => {
|
128
128
|
throw new Error("Test error");
|
@@ -155,7 +155,7 @@ describe("GraphFlow", function () {
|
|
155
155
|
const invalidContext = { value: "invalid_string" };
|
156
156
|
|
157
157
|
try {
|
158
|
-
const simpleNode:
|
158
|
+
const simpleNode: GraphNodeConfig<TestSchema> = {
|
159
159
|
name: "simpleNode",
|
160
160
|
execute: async (context) => {
|
161
161
|
context.value = (context.value ?? 0) + 1;
|
@@ -181,7 +181,7 @@ describe("GraphFlow", function () {
|
|
181
181
|
* Ensures type safety and data consistency in node interactions
|
182
182
|
*/
|
183
183
|
it("should execute a node with validated params and outputs", async function () {
|
184
|
-
const paramNode:
|
184
|
+
const paramNode: GraphNodeConfig<TestSchema, { increment: number }> = {
|
185
185
|
name: "paramNode",
|
186
186
|
params: z.object({
|
187
187
|
increment: z.number(),
|
@@ -209,7 +209,7 @@ describe("GraphFlow", function () {
|
|
209
209
|
* This enables dynamic workflow paths based on state
|
210
210
|
*/
|
211
211
|
it("should not execute a node when condition is false", async function () {
|
212
|
-
const conditionalNode:
|
212
|
+
const conditionalNode: GraphNodeConfig<TestSchema> = {
|
213
213
|
name: "conditionalNode",
|
214
214
|
condition: (context) => (context.value ?? 0) > 0,
|
215
215
|
execute: async (context) => {
|
@@ -236,7 +236,7 @@ describe("GraphFlow", function () {
|
|
236
236
|
*/
|
237
237
|
it("should retry a node execution when it fails", async () => {
|
238
238
|
let attempts = 0;
|
239
|
-
const retryNode:
|
239
|
+
const retryNode: GraphNodeConfig<TestSchema> = {
|
240
240
|
name: "retryNode",
|
241
241
|
execute: async (context) => {
|
242
242
|
attempts++;
|
@@ -267,7 +267,7 @@ describe("GraphFlow", function () {
|
|
267
267
|
* Tests node removal functionality
|
268
268
|
*/
|
269
269
|
it("should remove a node from the graph", function () {
|
270
|
-
const testNode:
|
270
|
+
const testNode: GraphNodeConfig<TestSchema> = {
|
271
271
|
name: "testNode",
|
272
272
|
execute: async () => {},
|
273
273
|
};
|
@@ -281,16 +281,16 @@ describe("GraphFlow", function () {
|
|
281
281
|
* Tests graph reloading functionality
|
282
282
|
*/
|
283
283
|
it("should clear and reload the graph using `load`", function () {
|
284
|
-
const nodeA:
|
284
|
+
const nodeA: GraphNodeConfig<TestSchema> = {
|
285
285
|
name: "A",
|
286
286
|
execute: async () => {},
|
287
287
|
};
|
288
|
-
const nodeB:
|
288
|
+
const nodeB: GraphNodeConfig<TestSchema> = {
|
289
289
|
name: "B",
|
290
290
|
execute: async () => {},
|
291
291
|
};
|
292
292
|
|
293
|
-
const newDefinition:
|
293
|
+
const newDefinition: GraphConfig<TestSchema> = {
|
294
294
|
name: "TestGraph",
|
295
295
|
entryNode: "A",
|
296
296
|
nodes: [nodeA, nodeB],
|
@@ -307,7 +307,7 @@ describe("GraphFlow", function () {
|
|
307
307
|
* Tests input validation error handling
|
308
308
|
*/
|
309
309
|
it("should throw error when node input validation fails", async () => {
|
310
|
-
const node:
|
310
|
+
const node: GraphNodeConfig<TestSchema> = {
|
311
311
|
name: "test",
|
312
312
|
params: z.object({
|
313
313
|
value: z.number().min(0),
|
@@ -406,7 +406,7 @@ describe("GraphFlow", function () {
|
|
406
406
|
* This validates the graph's ability to handle complex business processes
|
407
407
|
*/
|
408
408
|
it("should execute a complex workflow with multiple nodes and accumulate the value", async function () {
|
409
|
-
const nodeA:
|
409
|
+
const nodeA: GraphNodeConfig<TestSchema> = {
|
410
410
|
name: "nodeA",
|
411
411
|
execute: async (context) => {
|
412
412
|
context.value = (context.value ?? 0) + 1;
|
@@ -414,7 +414,7 @@ describe("GraphFlow", function () {
|
|
414
414
|
next: ["nodeB1", "nodeB2"],
|
415
415
|
};
|
416
416
|
|
417
|
-
const nodeB1:
|
417
|
+
const nodeB1: GraphNodeConfig<TestSchema> = {
|
418
418
|
name: "nodeB1",
|
419
419
|
execute: async (context) => {
|
420
420
|
context.value = (context.value ?? 0) * 2;
|
@@ -422,7 +422,7 @@ describe("GraphFlow", function () {
|
|
422
422
|
next: ["nodeC"],
|
423
423
|
};
|
424
424
|
|
425
|
-
const nodeB2:
|
425
|
+
const nodeB2: GraphNodeConfig<TestSchema> = {
|
426
426
|
name: "nodeB2",
|
427
427
|
execute: async (context) => {
|
428
428
|
context.value = (context.value ?? 0) + 3;
|
@@ -430,7 +430,7 @@ describe("GraphFlow", function () {
|
|
430
430
|
next: ["nodeC"],
|
431
431
|
};
|
432
432
|
|
433
|
-
const nodeC:
|
433
|
+
const nodeC: GraphNodeConfig<TestSchema> = {
|
434
434
|
name: "nodeC",
|
435
435
|
execute: async (context) => {
|
436
436
|
context.value = (context.value ?? 0) + 5;
|
@@ -447,7 +447,7 @@ describe("GraphFlow", function () {
|
|
447
447
|
* Tests conditional branching in workflows
|
448
448
|
*/
|
449
449
|
it("should execute different branches based on conditions", async function () {
|
450
|
-
const startNode:
|
450
|
+
const startNode: GraphNodeConfig<TestSchema> = {
|
451
451
|
name: "start",
|
452
452
|
execute: async (context) => {
|
453
453
|
context.value = (context.value ?? 0) + 5;
|
@@ -455,7 +455,7 @@ describe("GraphFlow", function () {
|
|
455
455
|
next: ["end"],
|
456
456
|
};
|
457
457
|
|
458
|
-
const endNode:
|
458
|
+
const endNode: GraphNodeConfig<TestSchema> = {
|
459
459
|
name: "end",
|
460
460
|
execute: async (context) => {
|
461
461
|
if ((context.value ?? 0) < 10) {
|
@@ -490,7 +490,7 @@ describe("GraphFlow", function () {
|
|
490
490
|
schema: TestSchema,
|
491
491
|
});
|
492
492
|
|
493
|
-
const processNode1:
|
493
|
+
const processNode1: GraphNodeConfig<TestSchema> = {
|
494
494
|
name: "process1",
|
495
495
|
execute: async (context) => {
|
496
496
|
context.value = 1;
|
@@ -498,7 +498,7 @@ describe("GraphFlow", function () {
|
|
498
498
|
next: ["finalize1"],
|
499
499
|
};
|
500
500
|
|
501
|
-
const finalizeNode1:
|
501
|
+
const finalizeNode1: GraphNodeConfig<TestSchema> = {
|
502
502
|
name: "finalize1",
|
503
503
|
execute: async (context) => {
|
504
504
|
context.value = (context.value ?? 0) * 2;
|
@@ -513,7 +513,7 @@ describe("GraphFlow", function () {
|
|
513
513
|
schema: TestSchema,
|
514
514
|
});
|
515
515
|
|
516
|
-
const processNode2:
|
516
|
+
const processNode2: GraphNodeConfig<TestSchema> = {
|
517
517
|
name: "process2",
|
518
518
|
execute: async (context) => {
|
519
519
|
context.value = 2;
|
@@ -521,7 +521,7 @@ describe("GraphFlow", function () {
|
|
521
521
|
next: ["finalize2"],
|
522
522
|
};
|
523
523
|
|
524
|
-
const finalizeNode2:
|
524
|
+
const finalizeNode2: GraphNodeConfig<TestSchema> = {
|
525
525
|
name: "finalize2",
|
526
526
|
execute: async (context) => {
|
527
527
|
context.value = (context.value ?? 0) + 3;
|
@@ -556,7 +556,7 @@ describe("GraphFlow", function () {
|
|
556
556
|
schema: TestSchema,
|
557
557
|
});
|
558
558
|
|
559
|
-
const startNode1:
|
559
|
+
const startNode1: GraphNodeConfig<TestSchema> = {
|
560
560
|
name: "start1",
|
561
561
|
execute: async (context) => {
|
562
562
|
context.value = (context.value ?? 0) * 2;
|
@@ -571,7 +571,7 @@ describe("GraphFlow", function () {
|
|
571
571
|
schema: TestSchema,
|
572
572
|
});
|
573
573
|
|
574
|
-
const startNode2:
|
574
|
+
const startNode2: GraphNodeConfig<TestSchema> = {
|
575
575
|
name: "start2",
|
576
576
|
execute: async (context) => {
|
577
577
|
context.value = (context.value ?? 0) + 2;
|
@@ -597,7 +597,7 @@ describe("GraphFlow", function () {
|
|
597
597
|
it("should wait for a single event before continuing", async function () {
|
598
598
|
this.timeout(5000);
|
599
599
|
|
600
|
-
const waitingNode:
|
600
|
+
const waitingNode: GraphNodeConfig<TestSchema> = {
|
601
601
|
name: "waitingNode",
|
602
602
|
execute: async (context: GraphContext<typeof TestSchema>) => {
|
603
603
|
context.value = 1;
|
@@ -606,7 +606,7 @@ describe("GraphFlow", function () {
|
|
606
606
|
next: ["finalNode"],
|
607
607
|
};
|
608
608
|
|
609
|
-
const finalNode:
|
609
|
+
const finalNode: GraphNodeConfig<TestSchema> = {
|
610
610
|
name: "finalNode",
|
611
611
|
execute: async (context: GraphContext<typeof TestSchema>) => {
|
612
612
|
context.value = (context.value ?? 0) + 5;
|
@@ -3,7 +3,7 @@ import { BehaviorSubject, Subject } from "rxjs";
|
|
3
3
|
import { z } from "zod";
|
4
4
|
import { GraphFlow } from "../../graph";
|
5
5
|
import { GraphObserver } from "../../graph/observer";
|
6
|
-
import { GraphContext, GraphEvent,
|
6
|
+
import { GraphContext, GraphEvent, GraphNodeConfig } from "../../types";
|
7
7
|
|
8
8
|
/**
|
9
9
|
* Test schema definition for observer tests
|
@@ -69,7 +69,7 @@ describe("GraphObserver", () => {
|
|
69
69
|
*/
|
70
70
|
it("should observe state changes", async () => {
|
71
71
|
const states: any[] = [];
|
72
|
-
const testNode:
|
72
|
+
const testNode: GraphNodeConfig<typeof TestSchema> = {
|
73
73
|
name: "testNode",
|
74
74
|
execute: async (context) => {
|
75
75
|
context.value = 1;
|
@@ -104,7 +104,7 @@ describe("GraphObserver", () => {
|
|
104
104
|
*/
|
105
105
|
it("should observe specific node state changes", async () => {
|
106
106
|
const states: any[] = [];
|
107
|
-
const testNode:
|
107
|
+
const testNode: GraphNodeConfig<typeof TestSchema> = {
|
108
108
|
name: "testNode",
|
109
109
|
execute: async (context) => {
|
110
110
|
context.status = "pending";
|
@@ -135,13 +135,13 @@ describe("GraphObserver", () => {
|
|
135
135
|
*/
|
136
136
|
it("should observe multiple nodes", async () => {
|
137
137
|
const states: any[] = [];
|
138
|
-
const node1:
|
138
|
+
const node1: GraphNodeConfig<typeof TestSchema> = {
|
139
139
|
name: "node1",
|
140
140
|
execute: async (context) => {
|
141
141
|
context.value = 1;
|
142
142
|
},
|
143
143
|
};
|
144
|
-
const node2:
|
144
|
+
const node2: GraphNodeConfig<typeof TestSchema> = {
|
145
145
|
name: "node2",
|
146
146
|
execute: async (context) => {
|
147
147
|
context.value = 2;
|
@@ -181,7 +181,7 @@ describe("GraphObserver", () => {
|
|
181
181
|
*/
|
182
182
|
it("should observe single property", async () => {
|
183
183
|
const values: any[] = [];
|
184
|
-
const testNode:
|
184
|
+
const testNode: GraphNodeConfig<typeof TestSchema> = {
|
185
185
|
name: "testNode",
|
186
186
|
execute: async (context) => {
|
187
187
|
context.value = 42;
|
@@ -209,7 +209,7 @@ describe("GraphObserver", () => {
|
|
209
209
|
*/
|
210
210
|
it("should observe multiple properties", async () => {
|
211
211
|
const values: any[] = [];
|
212
|
-
const testNode:
|
212
|
+
const testNode: GraphNodeConfig<typeof TestSchema> = {
|
213
213
|
name: "testNode",
|
214
214
|
execute: async (context) => {
|
215
215
|
context.value = 42;
|
@@ -244,7 +244,7 @@ describe("GraphObserver", () => {
|
|
244
244
|
* - State reflects all required changes
|
245
245
|
*/
|
246
246
|
it("should wait for multiple conditions", async () => {
|
247
|
-
const testNode:
|
247
|
+
const testNode: GraphNodeConfig<typeof TestSchema> = {
|
248
248
|
name: "testNode",
|
249
249
|
execute: async (context) => {
|
250
250
|
context.value = 42;
|
@@ -372,7 +372,7 @@ describe("GraphObserver", () => {
|
|
372
372
|
*/
|
373
373
|
it("should observe complete workflow", async () => {
|
374
374
|
const states: any[] = [];
|
375
|
-
const node:
|
375
|
+
const node: GraphNodeConfig<typeof TestSchema> = {
|
376
376
|
name: "testNode",
|
377
377
|
execute: async (context) => {
|
378
378
|
context.status = "pending";
|
package/types/index.ts
CHANGED
@@ -80,7 +80,7 @@ export type GraphContext<T extends ZodSchema> = {
|
|
80
80
|
* @template I - Input schema type
|
81
81
|
* @template O - Output schema type
|
82
82
|
*/
|
83
|
-
export
|
83
|
+
export type GraphNodeConfig<T extends ZodSchema, P = any> = {
|
84
84
|
/** Name of the node */
|
85
85
|
name: string;
|
86
86
|
/** Description of the node */
|
@@ -93,10 +93,17 @@ export interface Node<T extends ZodSchema, P = any> {
|
|
93
93
|
params?: P,
|
94
94
|
tools?: { eventEmitter: IEventEmitter }
|
95
95
|
) => Promise<void>;
|
96
|
-
/** Optional condition for node execution */
|
96
|
+
/** Optional condition for node start execution */
|
97
97
|
condition?: (context: GraphContext<T>, params?: P) => boolean;
|
98
|
-
|
99
|
-
next
|
98
|
+
|
99
|
+
/** Array of next node names or objects with conditions for the next node */
|
100
|
+
next?:
|
101
|
+
| Array<
|
102
|
+
| string
|
103
|
+
| { node: string; condition: (context: GraphContext<T>) => boolean }
|
104
|
+
>
|
105
|
+
| string
|
106
|
+
| ((context: GraphContext<T>) => string[]);
|
100
107
|
/** Array of event names that trigger this node */
|
101
108
|
events?: string[];
|
102
109
|
/** Wait for a single event before continuing */
|
@@ -122,18 +129,18 @@ export interface Node<T extends ZodSchema, P = any> {
|
|
122
129
|
};
|
123
130
|
/** Error handler function */
|
124
131
|
onError?: (error: Error) => void;
|
125
|
-
}
|
132
|
+
};
|
126
133
|
|
127
134
|
/**
|
128
135
|
* Interface for graph definition
|
129
136
|
* @interface
|
130
137
|
* @template T - Schema type
|
131
138
|
*/
|
132
|
-
export
|
139
|
+
export type GraphConfig<T extends ZodSchema> = {
|
133
140
|
/** Name of the graph */
|
134
141
|
name: string;
|
135
142
|
/** Array of nodes in the graph */
|
136
|
-
nodes:
|
143
|
+
nodes: GraphNodeConfig<T, any>[];
|
137
144
|
/** Initial context */
|
138
145
|
context: SchemaType<T>;
|
139
146
|
/** Schema for validation */
|
@@ -146,7 +153,7 @@ export interface GraphDefinition<T extends ZodSchema> {
|
|
146
153
|
eventEmitter?: IEventEmitter | EventEmitter;
|
147
154
|
/** Array of events */
|
148
155
|
events?: string[];
|
149
|
-
}
|
156
|
+
};
|
150
157
|
|
151
158
|
/* ======================== MEILISEARCH ======================== */
|
152
159
|
|