@ai.ntellect/core 0.6.16 → 0.6.19

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.
Files changed (83) hide show
  1. package/.mocharc.json +1 -2
  2. package/README.md +123 -178
  3. package/dist/graph/controller.js +29 -6
  4. package/dist/graph/index.js +402 -0
  5. package/dist/index.js +22 -7
  6. package/dist/interfaces/index.js +15 -0
  7. package/dist/modules/agenda/adapters/node-cron/index.js +29 -0
  8. package/dist/modules/agenda/index.js +140 -0
  9. package/dist/{services/embedding.js → modules/embedding/adapters/ai/index.js} +24 -7
  10. package/dist/modules/embedding/index.js +59 -0
  11. package/dist/modules/memory/adapters/in-memory/index.js +210 -0
  12. package/dist/{memory → modules/memory}/adapters/meilisearch/index.js +97 -2
  13. package/dist/{memory → modules/memory}/adapters/redis/index.js +77 -15
  14. package/dist/modules/memory/index.js +103 -0
  15. package/dist/utils/{stringifiy-zod-schema.js → generate-action-schema.js} +5 -5
  16. package/graph/controller.ts +38 -14
  17. package/graph/index.ts +468 -0
  18. package/index.ts +25 -7
  19. package/interfaces/index.ts +346 -28
  20. package/modules/agenda/adapters/node-cron/index.ts +25 -0
  21. package/modules/agenda/index.ts +159 -0
  22. package/modules/embedding/adapters/ai/index.ts +42 -0
  23. package/modules/embedding/index.ts +45 -0
  24. package/modules/memory/adapters/in-memory/index.ts +203 -0
  25. package/{memory → modules/memory}/adapters/meilisearch/index.ts +114 -8
  26. package/modules/memory/adapters/redis/index.ts +164 -0
  27. package/modules/memory/index.ts +93 -0
  28. package/package.json +4 -4
  29. package/test/graph/index.test.ts +646 -0
  30. package/test/modules/agenda/node-cron.test.ts +286 -0
  31. package/test/modules/embedding/ai.test.ts +78 -0
  32. package/test/modules/memory/adapters/in-memory.test.ts +153 -0
  33. package/test/{memory → modules/memory}/adapters/meilisearch.test.ts +80 -94
  34. package/test/modules/memory/adapters/redis.test.ts +169 -0
  35. package/test/modules/memory/base.test.ts +230 -0
  36. package/test/services/agenda.test.ts +279 -280
  37. package/tsconfig.json +0 -3
  38. package/types/index.ts +82 -203
  39. package/utils/{stringifiy-zod-schema.ts → generate-action-schema.ts} +3 -3
  40. package/app/README.md +0 -36
  41. package/app/app/favicon.ico +0 -0
  42. package/app/app/globals.css +0 -21
  43. package/app/app/gun.ts +0 -0
  44. package/app/app/layout.tsx +0 -18
  45. package/app/app/page.tsx +0 -321
  46. package/app/eslint.config.mjs +0 -16
  47. package/app/next.config.ts +0 -7
  48. package/app/package-lock.json +0 -5912
  49. package/app/package.json +0 -31
  50. package/app/pnpm-lock.yaml +0 -4031
  51. package/app/postcss.config.mjs +0 -8
  52. package/app/public/file.svg +0 -1
  53. package/app/public/globe.svg +0 -1
  54. package/app/public/next.svg +0 -1
  55. package/app/public/vercel.svg +0 -1
  56. package/app/public/window.svg +0 -1
  57. package/app/tailwind.config.ts +0 -18
  58. package/app/tsconfig.json +0 -27
  59. package/dist/graph/graph.js +0 -162
  60. package/dist/memory/index.js +0 -9
  61. package/dist/services/agenda.js +0 -115
  62. package/dist/services/queue.js +0 -142
  63. package/dist/utils/experimental-graph-rag.js +0 -152
  64. package/dist/utils/generate-object.js +0 -111
  65. package/dist/utils/inject-actions.js +0 -16
  66. package/dist/utils/queue-item-transformer.js +0 -24
  67. package/dist/utils/sanitize-results.js +0 -60
  68. package/graph/graph.ts +0 -193
  69. package/memory/adapters/redis/index.ts +0 -103
  70. package/memory/index.ts +0 -22
  71. package/services/agenda.ts +0 -118
  72. package/services/embedding.ts +0 -26
  73. package/services/queue.ts +0 -145
  74. package/test/.env.test +0 -4
  75. package/test/graph/engine.test.ts +0 -533
  76. package/test/memory/adapters/redis.test.ts +0 -160
  77. package/test/memory/base.test.ts +0 -229
  78. package/test/services/queue.test.ts +0 -286
  79. package/utils/experimental-graph-rag.ts +0 -170
  80. package/utils/generate-object.ts +0 -117
  81. package/utils/inject-actions.ts +0 -19
  82. package/utils/queue-item-transformer.ts +0 -38
  83. package/utils/sanitize-results.ts +0 -66
package/services/queue.ts DELETED
@@ -1,145 +0,0 @@
1
- import {
2
- ActionSchema,
3
- QueueCallbacks,
4
- QueueItem,
5
- QueueItemParameter,
6
- QueueResult,
7
- } from "../types";
8
-
9
- export class Queue {
10
- private queue: QueueItem[] = [];
11
- private results: QueueResult[] = [];
12
- private callbacks: QueueCallbacks;
13
- private actions: ActionSchema[];
14
- private isProcessing: boolean = false;
15
-
16
- constructor(actions: ActionSchema[], callbacks: QueueCallbacks = {}) {
17
- this.actions = actions;
18
- this.callbacks = callbacks;
19
- }
20
-
21
- add(actions: QueueItem | QueueItem[]) {
22
- if (Array.isArray(actions)) {
23
- this.queue.push(...actions);
24
- } else {
25
- this.queue.push(actions);
26
- }
27
- }
28
-
29
- async execute() {
30
- if (this.isProcessing) {
31
- return;
32
- }
33
-
34
- this.isProcessing = true;
35
- const actionPromises: Promise<QueueResult>[] = [];
36
-
37
- for (const action of this.queue) {
38
- const actionConfig = this.actions.find((a) => a.name === action.name);
39
- if (actionConfig?.confirmation?.requireConfirmation) {
40
- const shouldProceed = await this.callbacks.onConfirmationRequired?.(
41
- actionConfig.confirmation.message ||
42
- `Do you want to proceed with action: ${action.name}?`
43
- );
44
-
45
- if (!shouldProceed) {
46
- this.results.push({
47
- name: action.name,
48
- parameters: this.formatArguments(action.parameters),
49
- result: null,
50
- error: "Action cancelled by user",
51
- cancelled: true,
52
- });
53
- continue;
54
- }
55
- }
56
- const parameters = this.formatArguments(action.parameters);
57
-
58
- actionPromises.push(
59
- this.executeAction(action)
60
- .then((result) => {
61
- this.callbacks.onActionComplete?.(result);
62
- return result;
63
- })
64
- .catch((error) => {
65
- const result = {
66
- name: action.name,
67
- parameters,
68
- result: null,
69
- error: error.message || "Unknown error occurred",
70
- };
71
- this.callbacks.onActionComplete?.(result);
72
- return result;
73
- })
74
- );
75
- }
76
-
77
- try {
78
- const results = await Promise.all(actionPromises);
79
- this.results.push(...results);
80
- this.queue = [];
81
- this.callbacks.onQueueComplete?.(this.results);
82
- this.isProcessing = false;
83
- return this.results;
84
- } catch (error) {
85
- this.isProcessing = false;
86
- throw error;
87
- }
88
- }
89
-
90
- private formatArguments(args: QueueItemParameter[]): Record<string, string> {
91
- return args.reduce<Record<string, string>>((acc, arg) => {
92
- try {
93
- // Parse the JSON string if the value is a stringified JSON object
94
- const parsedValue = JSON.parse(arg.value);
95
- if (
96
- parsedValue &&
97
- typeof parsedValue === "object" &&
98
- "value" in parsedValue
99
- ) {
100
- acc[parsedValue.name] = parsedValue.value;
101
- } else {
102
- // Fallback to original value if not in expected format
103
- acc[arg.name] = arg.value;
104
- }
105
- } catch {
106
- // If JSON parsing fails, use the original value
107
- acc[arg.name] = arg.value;
108
- }
109
- return acc;
110
- }, {});
111
- }
112
-
113
- private async executeAction(action: QueueItem): Promise<QueueResult> {
114
- this.callbacks.onActionStart?.(action);
115
-
116
- const actionConfig = this.actions.find((a) => a.name === action.name);
117
- if (!actionConfig) {
118
- return {
119
- name: action.name,
120
- parameters: {},
121
- result: null,
122
- error: `Action '${action.name}' not found in actions list`,
123
- };
124
- }
125
-
126
- const actionArgs = this.formatArguments(action.parameters);
127
-
128
- try {
129
- const result = await actionConfig.execute(actionArgs);
130
- return {
131
- name: action.name,
132
- parameters: actionArgs,
133
- result,
134
- error: null,
135
- };
136
- } catch (error) {
137
- return {
138
- name: action.name,
139
- parameters: actionArgs,
140
- result: null,
141
- error: (error as Error).message || "Unknown error occurred",
142
- };
143
- }
144
- }
145
- }
package/test/.env.test DELETED
@@ -1,4 +0,0 @@
1
- MEILISEARCH_HOST=http://localhost:7700
2
- MEILISEARCH_API_KEY=aSampleMasterKey
3
- REDIS_URL=redis://localhost:6379
4
- REDIS_TEST_DB=1
@@ -1,533 +0,0 @@
1
- import { GraphEngine } from "@/graph/engine";
2
- import { Persistence, RealTimeNotifier } from "@/interfaces";
3
- import { GraphDefinition, SharedState } from "@/types";
4
- import { expect } from "chai";
5
- import { z } from "zod";
6
-
7
- /**
8
- * Test suite for the Graph service
9
- * This suite tests the workflow execution engine that manages state transitions and node execution
10
- */
11
- describe("Graph", () => {
12
- /**
13
- * Test schema definition using Zod
14
- * Defines the structure and validation rules for the workflow state
15
- */
16
- const TestSchema = z.object({
17
- status: z.string(),
18
- step: z.number(),
19
- });
20
-
21
- type TestState = z.infer<typeof TestSchema>;
22
-
23
- let graph: GraphEngine<TestState>;
24
- /**
25
- * Test definition of a simple workflow graph
26
- * Contains 3 nodes: start -> process -> end
27
- * Each node updates the state with new status and step values
28
- */
29
- const testDefinition: GraphDefinition<TestState> = {
30
- name: "simple-workflow",
31
- entryNode: "start",
32
- nodes: {
33
- start: {
34
- name: "start",
35
- description: "Starting node",
36
- execute: async (state: SharedState<TestState>) => {
37
- return graph.updateState({
38
- ...state,
39
- status: "started",
40
- step: 1,
41
- });
42
- },
43
- relationships: [{ name: "process" }],
44
- },
45
- process: {
46
- name: "process",
47
- description: "Processing node",
48
- execute: async (state: SharedState<TestState>) => {
49
- return graph.updateState({
50
- ...state,
51
- status: "processing",
52
- step: 2,
53
- });
54
- },
55
- condition: (state) => state.step === 1,
56
- relationships: [{ name: "end" }],
57
- },
58
- end: {
59
- name: "end",
60
- description: "End node",
61
- execute: async (state: SharedState<TestState>) => {
62
- return graph.updateState({
63
- ...state,
64
- status: "completed",
65
- step: 3,
66
- });
67
- },
68
- relationships: [],
69
- },
70
- },
71
- schema: TestSchema,
72
- };
73
-
74
- beforeEach(() => {
75
- graph = new GraphEngine(testDefinition);
76
- });
77
-
78
- describe("Workflow Execution", () => {
79
- /**
80
- * Tests the complete execution flow of the workflow
81
- * Verifies that state transitions occur correctly from start to end
82
- */
83
- it("should execute the complete workflow sequence", async () => {
84
- const initialState: SharedState<TestState> = {
85
- status: "init",
86
- step: 0,
87
- };
88
-
89
- // Initialiser le graph avec l'état initial
90
- graph = new GraphEngine(testDefinition, {
91
- schema: TestSchema,
92
- initialState,
93
- });
94
-
95
- // Exécuter le workflow
96
- await graph.execute(initialState, "start");
97
- const result = graph.getState();
98
-
99
- expect(result).to.deep.equal({
100
- status: "completed",
101
- step: 3,
102
- });
103
- });
104
-
105
- /**
106
- * Tests that conditional logic in nodes is respected
107
- * The process node should only execute when step === 1
108
- */
109
- it("should respect conditions in workflow", async () => {
110
- const initialState: SharedState<TestState> = {
111
- status: "init",
112
- step: 2,
113
- };
114
-
115
- // Initialiser le graph avec l'état initial
116
- graph = new GraphEngine(testDefinition, {
117
- schema: TestSchema,
118
- initialState,
119
- });
120
-
121
- await graph.execute(initialState, "process");
122
- const result = graph.getState();
123
-
124
- expect(result).to.deep.equal({
125
- status: "init",
126
- step: 2,
127
- });
128
- });
129
- });
130
-
131
- describe("Graph Management", () => {
132
- it("should add a new node to the graph", () => {
133
- const newNode = {
134
- name: "new-node",
135
- description: "A new test node",
136
- execute: async (state: SharedState<TestState>) => {
137
- return graph.updateState({
138
- ...state,
139
- status: "new",
140
- step: 4,
141
- });
142
- },
143
- relationships: [{ name: "end" }],
144
- };
145
-
146
- graph.addNode(newNode);
147
-
148
- expect(graph.nodes.has("new-node")).to.be.true;
149
- const addedNode = graph.nodes.get("new-node");
150
- expect(addedNode?.relationships).to.have.lengthOf(1);
151
- });
152
-
153
- it("should update existing graph with new definition", () => {
154
- const newDefinition: GraphDefinition<TestState> = {
155
- name: "updated-workflow",
156
- entryNode: "start",
157
- nodes: {
158
- ...testDefinition.nodes,
159
- "new-step": {
160
- name: "new-step",
161
- description: "New step node",
162
- execute: async (state: SharedState<TestState>) => {
163
- return graph.updateState({
164
- ...state,
165
- status: "new-step",
166
- step: 4,
167
- });
168
- },
169
- relationships: [],
170
- },
171
- },
172
- schema: TestSchema,
173
- };
174
-
175
- graph.updateGraph(newDefinition);
176
- expect(graph.nodes.has("new-step")).to.be.true;
177
- });
178
- });
179
-
180
- describe("State Management", () => {
181
- it("should properly update and retrieve state", async () => {
182
- const newState: SharedState<TestState> = {
183
- status: "test",
184
- step: 5,
185
- };
186
-
187
- graph.setState(newState);
188
- const retrievedState = graph.getState();
189
-
190
- expect(retrievedState).to.deep.equal(newState);
191
- });
192
-
193
- it("should merge states correctly when updating partially", () => {
194
- const initialState: SharedState<TestState> = {
195
- status: "initial",
196
- step: 1,
197
- };
198
-
199
- graph.setState(initialState);
200
-
201
- const partialUpdate = {
202
- status: "updated",
203
- };
204
-
205
- const updatedState = graph.updateState(partialUpdate);
206
-
207
- expect(updatedState).to.deep.equal({
208
- status: "updated",
209
- step: 1,
210
- });
211
- });
212
- });
213
-
214
- describe("Error Handling", () => {
215
- it("should handle execution errors gracefully", async () => {
216
- const errorNode = {
217
- name: "error-node",
218
- execute: async () => {
219
- throw new Error("Test error");
220
- },
221
- };
222
-
223
- graph.addNode(errorNode);
224
-
225
- let errorCaught = false;
226
- try {
227
- await graph.execute(
228
- { status: "test", step: 1 },
229
- "error-node",
230
- undefined,
231
- (error) => {
232
- expect(error.message).to.equal("Test error");
233
- errorCaught = true;
234
- }
235
- );
236
- } catch (error) {
237
- expect(error).to.be.instanceOf(Error);
238
- expect((error as Error).message).to.equal("Test error");
239
- }
240
-
241
- expect(errorCaught).to.be.true;
242
- });
243
-
244
- it("should validate state against schema", async () => {
245
- // Créer un nouveau graph avec validation stricte
246
- const strictGraph = new GraphEngine(testDefinition, {
247
- schema: TestSchema,
248
- initialState: {
249
- status: "init",
250
- step: 0,
251
- },
252
- });
253
-
254
- const invalidState: SharedState<any> = {
255
- context: {
256
- status: 123, // Should be string
257
- step: "invalid", // Should be number
258
- },
259
- };
260
-
261
- try {
262
- await strictGraph.execute(invalidState, "start");
263
- // Si on arrive ici, le test doit échouer car on s'attend à une erreur
264
- expect.fail("Expected validation error but none was thrown");
265
- } catch (error) {
266
- expect(error).to.be.instanceOf(Error);
267
- const errorMessage = (error as Error).message;
268
- expect(
269
- errorMessage.includes("Expected string") ||
270
- errorMessage.includes("Expected number") ||
271
- errorMessage.includes("validation")
272
- ).to.be.true;
273
- }
274
- });
275
- });
276
-
277
- describe("Parallel Execution", () => {
278
- /**
279
- * Tests concurrent execution of multiple nodes
280
- * Important: The execution order is not guaranteed due to async nature
281
- * @param concurrency - Maximum number of nodes that can execute simultaneously
282
- */
283
- it("should execute multiple nodes in parallel", async () => {
284
- const executionOrder: string[] = [];
285
-
286
- const parallelNodes = ["node1", "node2", "node3"].map((name) => ({
287
- name,
288
- execute: async (state: SharedState<TestState>) => {
289
- executionOrder.push(name);
290
- await new Promise((resolve) => setTimeout(resolve, 10));
291
- return state;
292
- },
293
- }));
294
-
295
- parallelNodes.forEach((node) => {
296
- graph.addNode(node);
297
- });
298
-
299
- await graph.executeParallel(
300
- { status: "test", step: 1 },
301
- ["node1", "node2", "node3"],
302
- 2
303
- );
304
-
305
- expect(executionOrder).to.have.lengthOf(3);
306
- expect(executionOrder).to.include.members(["node1", "node2", "node3"]);
307
- });
308
- });
309
-
310
- describe("Event Handling", () => {
311
- /**
312
- * Tests the event emission and handling system
313
- * Events can trigger node execution asynchronously
314
- * Note: Uses setTimeout to ensure event processing completes
315
- */
316
- it("should emit and handle events correctly", async () => {
317
- const eventNode = {
318
- name: "event-node",
319
- execute: async (state: SharedState<TestState>) => {
320
- return graph.updateState({
321
- ...state,
322
- status: "event-triggered",
323
- step: 10,
324
- });
325
- },
326
- events: ["test-event"],
327
- };
328
-
329
- graph.addNode(eventNode);
330
-
331
- // Émettre l'événement
332
- graph.emit("test-event", {
333
- state: { context: { status: "init", step: 0 } },
334
- });
335
-
336
- // Attendre un peu pour que l'événement soit traité
337
- await new Promise((resolve) => setTimeout(resolve, 50));
338
-
339
- const state = graph.getState();
340
- expect(state.status).to.equal("event-triggered");
341
- });
342
- });
343
-
344
- describe("Subgraph Integration", () => {
345
- /**
346
- * Tests nested workflow execution through subgraphs
347
- * Subgraphs allow modular workflow composition
348
- * The main graph can delegate execution to subgraphs
349
- */
350
- it("should execute subgraph as part of main graph", async () => {
351
- const subGraphDef: GraphDefinition<TestState> = {
352
- name: "sub-workflow",
353
- entryNode: "sub-start",
354
- nodes: {
355
- "sub-start": {
356
- name: "sub-start",
357
- execute: async (state: SharedState<TestState>) => {
358
- return graph.updateState({
359
- ...state,
360
- status: "sub-completed",
361
- step: 100,
362
- });
363
- },
364
- relationships: [],
365
- },
366
- },
367
- schema: TestSchema,
368
- };
369
-
370
- const subGraph = new GraphEngine(subGraphDef);
371
- graph.addSubGraph(subGraph, "sub-start", "sub-workflow");
372
-
373
- const initialState: SharedState<TestState> = {
374
- status: "init",
375
- step: 0,
376
- };
377
-
378
- await graph.execute(initialState, "sub-workflow");
379
- const state = graph.getState();
380
-
381
- expect(state.status).to.equal("sub-completed");
382
- expect(state.step).to.equal(100);
383
- });
384
- });
385
-
386
- describe("Global Context Management", () => {
387
- it("should manage global context correctly", () => {
388
- graph.addToContext("testKey", "testValue");
389
- expect(graph.getContext("testKey")).to.equal("testValue");
390
-
391
- graph.removeFromContext("testKey");
392
- expect(graph.getContext("testKey")).to.be.undefined;
393
- });
394
-
395
- it("should handle multiple context values", () => {
396
- graph.addToContext("key1", "value1");
397
- graph.addToContext("key2", { nested: "value2" });
398
-
399
- expect(graph.getContext("key1")).to.equal("value1");
400
- expect(graph.getContext("key2")).to.deep.equal({ nested: "value2" });
401
- });
402
- });
403
-
404
- describe("Graph Visualization", () => {
405
- it("should generate valid mermaid diagram", () => {
406
- const diagram = graph.generateMermaidDiagram("Test Workflow");
407
- expect(diagram).to.include("flowchart TD");
408
- expect(diagram).to.include("subgraph Test Workflow");
409
- expect(diagram).to.include("start");
410
- expect(diagram).to.include("process");
411
- expect(diagram).to.include("end");
412
- });
413
- });
414
-
415
- describe("Schema Visualization", () => {
416
- /**
417
- * Tests the schema visualization functionality
418
- * This helps developers understand the workflow structure
419
- * The visualization includes:
420
- * - Node relationships
421
- * - State schema
422
- * - Validation rules
423
- */
424
- it("should generate schema visualization", () => {
425
- // Créer un nouveau graph avec un schéma pour le test
426
- const graphWithSchema = new GraphEngine(testDefinition, {
427
- schema: TestSchema,
428
- });
429
-
430
- const schemaVisualization = graphWithSchema.visualizeSchema();
431
-
432
- // Vérifier les sections attendues dans la visualisation
433
- expect(schemaVisualization).to.include("📋 Graph:");
434
- expect(schemaVisualization).to.include("🔷 Nodes:");
435
-
436
- // Vérifier les détails du schéma
437
- expect(schemaVisualization).to.satisfy((text: string) => {
438
- return text.includes("status:") && text.includes("step:");
439
- });
440
-
441
- // Vérifier la présence des nœuds
442
- expect(schemaVisualization).to.include("start");
443
- expect(schemaVisualization).to.include("process");
444
- expect(schemaVisualization).to.include("end");
445
- });
446
- });
447
-
448
- describe("Persistence Integration", () => {
449
- it("should work with persistence layer", async () => {
450
- const mockPersistence: Persistence<TestState> = {
451
- saveState: async (graphName, state, currentNode) => {
452
- expect(graphName).to.equal("simple-workflow");
453
- expect(state).to.exist;
454
- expect(currentNode).to.exist;
455
- },
456
- loadState: async () => null,
457
- };
458
-
459
- graph.setPersistence(mockPersistence);
460
- await graph.execute({ status: "init", step: 0 }, "start");
461
- });
462
- });
463
-
464
- describe("Real-time Notifications", () => {
465
- /**
466
- * Tests the notification system during workflow execution
467
- * Notifications are sent for:
468
- * - Node execution start
469
- * - Node execution completion
470
- * - State updates
471
- * - Error events
472
- */
473
- it("should send notifications during execution", async () => {
474
- const notifications: any[] = [];
475
- const mockNotifier: RealTimeNotifier = {
476
- notify: (event, data) => {
477
- notifications.push({ event, data });
478
- },
479
- };
480
-
481
- graph.setNotifier(mockNotifier);
482
- await graph.execute({ status: "init", step: 0 }, "start");
483
-
484
- expect(notifications).to.have.length.greaterThan(0);
485
- expect(notifications[0].event).to.equal("nodeExecutionStarted");
486
- expect(notifications).to.deep.include.members([
487
- {
488
- event: "nodeExecutionCompleted",
489
- data: {
490
- workflow: "simple-workflow",
491
- node: "start",
492
- state: {
493
- context: {
494
- status: "started",
495
- step: 1,
496
- },
497
- },
498
- },
499
- },
500
- ]);
501
- });
502
- });
503
-
504
- describe("Cycle Detection", () => {
505
- /**
506
- * Tests the cycle detection mechanism
507
- * Cycles in workflow definitions can cause infinite loops
508
- * The graph constructor should detect and prevent cyclic dependencies
509
- */
510
- it("should detect cycles in graph", () => {
511
- const cyclicDefinition: GraphDefinition<TestState> = {
512
- name: "cyclic-workflow",
513
- entryNode: "node1",
514
- nodes: {
515
- node1: {
516
- name: "node1",
517
- execute: async (state) => state,
518
- relationships: [{ name: "node2" }],
519
- },
520
- node2: {
521
- name: "node2",
522
- execute: async (state) => state,
523
- relationships: [{ name: "node1" }],
524
- },
525
- },
526
- };
527
-
528
- expect(
529
- () => new GraphEngine(cyclicDefinition, { autoDetectCycles: true })
530
- ).to.throw;
531
- });
532
- });
533
- });