@ai.ntellect/core 0.6.10 → 0.6.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.
Files changed (44) hide show
  1. package/app/README.md +36 -0
  2. package/app/app/favicon.ico +0 -0
  3. package/app/app/globals.css +21 -0
  4. package/app/app/gun.ts +0 -0
  5. package/app/app/layout.tsx +18 -0
  6. package/app/app/page.tsx +321 -0
  7. package/app/eslint.config.mjs +16 -0
  8. package/app/next.config.ts +7 -0
  9. package/app/package-lock.json +5912 -0
  10. package/app/package.json +31 -0
  11. package/app/pnpm-lock.yaml +4031 -0
  12. package/app/postcss.config.mjs +8 -0
  13. package/app/public/file.svg +1 -0
  14. package/app/public/globe.svg +1 -0
  15. package/app/public/next.svg +1 -0
  16. package/app/public/vercel.svg +1 -0
  17. package/app/public/window.svg +1 -0
  18. package/app/tailwind.config.ts +18 -0
  19. package/app/tsconfig.json +27 -0
  20. package/dist/graph/controller.js +30 -41
  21. package/dist/graph/graph.js +167 -0
  22. package/dist/index.js +1 -2
  23. package/dist/memory/adapters/meilisearch/index.js +39 -63
  24. package/dist/utils/experimental-graph-rag.js +152 -0
  25. package/dist/utils/stringifiy-zod-schema.js +7 -6
  26. package/graph/controller.ts +57 -52
  27. package/graph/graph.ts +198 -0
  28. package/index.ts +1 -2
  29. package/memory/adapters/meilisearch/index.ts +41 -76
  30. package/package.json +2 -2
  31. package/tsconfig.json +1 -1
  32. package/types/index.ts +35 -38
  33. package/utils/experimental-graph-rag.ts +170 -0
  34. package/utils/stringifiy-zod-schema.ts +6 -6
  35. package/create-llm-to-select-multiple-graph copy.ts +0 -237
  36. package/create-llm-to-select-multiple-graph.ts +0 -148
  37. package/dist/create-llm-to-select-multiple-graph copy.js +0 -171
  38. package/dist/create-llm-to-select-multiple-graph.js +0 -142
  39. package/dist/graph/engine.js +0 -634
  40. package/dist/index copy.js +0 -76
  41. package/dist/utils/setup-graphs.js +0 -28
  42. package/graph/engine.ts +0 -793
  43. package/index copy.ts +0 -81
  44. package/utils/setup-graphs.ts +0 -45
@@ -1,634 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.GraphEngine = void 0;
16
- const events_1 = __importDefault(require("events"));
17
- const zod_1 = require("zod");
18
- /**
19
- * Représente un workflow dirigé capable d’exécuter des noeuds en séquence ou en parallèle.
20
- *
21
- * @template T - Le type de données stockées dans le contexte du workflow
22
- */
23
- class GraphEngine {
24
- /**
25
- * Crée une nouvelle instance de GraphEngine.
26
- *
27
- * @param {GraphDefinition<T>} [definition] - La définition initiale du workflow
28
- * @param {GraphOptions<T>} [options] - Options de configuration
29
- */
30
- constructor(definition, options) {
31
- this.name = (definition === null || definition === void 0 ? void 0 : definition.name) || "anonymous";
32
- this.eventEmitter = new events_1.default();
33
- this.globalContext = new Map();
34
- this.nodes = new Map();
35
- this.executedNodes = new Set();
36
- this.persistence = null;
37
- this.notifier = null;
38
- this.schema = options === null || options === void 0 ? void 0 : options.schema;
39
- this.currentState = {};
40
- if (definition) {
41
- this.loadFromDefinition(definition);
42
- }
43
- if ((options === null || options === void 0 ? void 0 : options.autoDetectCycles) && this.checkForCycles()) {
44
- throw new Error("Cycle détecté dans le workflow");
45
- }
46
- if (options === null || options === void 0 ? void 0 : options.initialState) {
47
- // this.setState(options.initialState);
48
- }
49
- }
50
- /**
51
- * Ajoute un élément au contexte global.
52
- * @param {string} key - La clé
53
- * @param {any} value - La valeur
54
- */
55
- addToContext(key, value) {
56
- this.globalContext.set(key, value);
57
- }
58
- /**
59
- * Récupère un élément du contexte global.
60
- * @param {string} key - La clé
61
- */
62
- getContext(key) {
63
- return this.globalContext.get(key);
64
- }
65
- /**
66
- * Supprime un élément du contexte global.
67
- * @param {string} key - La clé
68
- */
69
- removeFromContext(key) {
70
- this.globalContext.delete(key);
71
- }
72
- /**
73
- * Définit la couche de persistance.
74
- * @param {Persistence<T>} persistence
75
- */
76
- setPersistence(persistence) {
77
- this.persistence = persistence;
78
- }
79
- /**
80
- * Définit le notifier en temps réel.
81
- * @param {RealTimeNotifier} notifier
82
- */
83
- setNotifier(notifier) {
84
- this.notifier = notifier;
85
- }
86
- /**
87
- * Charge un workflow à partir d'une définition.
88
- * @private
89
- * @param {GraphDefinition<T>} definition
90
- */
91
- loadFromDefinition(definition) {
92
- Object.entries(definition.nodes).forEach(([_, nodeConfig]) => {
93
- this.addNode(nodeConfig);
94
- });
95
- }
96
- /**
97
- * Vérifie récursivement s’il existe un cycle dans le workflow.
98
- * @param {string} nodeName
99
- * @param {Set<string>} visited
100
- * @param {Set<string>} recStack
101
- * @returns {boolean}
102
- */
103
- isCyclic(nodeName, visited, recStack) {
104
- if (!visited.has(nodeName)) {
105
- visited.add(nodeName);
106
- recStack.add(nodeName);
107
- const currentNode = this.nodes.get(nodeName);
108
- if (currentNode === null || currentNode === void 0 ? void 0 : currentNode.relationships) {
109
- for (const relation of currentNode.relationships) {
110
- const targetNode = relation.name;
111
- if (!visited.has(targetNode) &&
112
- this.isCyclic(targetNode, visited, recStack)) {
113
- return true;
114
- }
115
- else if (recStack.has(targetNode)) {
116
- return true;
117
- }
118
- }
119
- }
120
- }
121
- recStack.delete(nodeName);
122
- return false;
123
- }
124
- /**
125
- * Vérifie si le workflow contient des cycles.
126
- * @returns {boolean}
127
- */
128
- checkForCycles() {
129
- const visited = new Set();
130
- const recStack = new Set();
131
- for (const nodeName of this.nodes.keys()) {
132
- if (this.isCyclic(nodeName, visited, recStack)) {
133
- return true;
134
- }
135
- }
136
- return false;
137
- }
138
- /**
139
- * Ajoute un nouveau nœud au workflow.
140
- * @param {Node<T>} node
141
- */
142
- addNode(node) {
143
- if (node.relationships) {
144
- node.relationships.forEach((relationship) => {
145
- var _a, _b;
146
- (_b = (_a = this.nodes.get(relationship.name)) === null || _a === void 0 ? void 0 : _a.relationships) === null || _b === void 0 ? void 0 : _b.push(relationship);
147
- });
148
- }
149
- if (node.events) {
150
- node.events.forEach((event) => {
151
- this.eventEmitter.on(event, (data) => __awaiter(this, void 0, void 0, function* () {
152
- const state = data.state || {};
153
- yield this.execute(state, node.name);
154
- }));
155
- });
156
- }
157
- this.nodes.set(node.name, node);
158
- }
159
- /**
160
- * Émet un événement sur l'event emitter du workflow.
161
- * @param {string} eventName
162
- * @param {any} data
163
- */
164
- emit(eventName, data) {
165
- this.eventEmitter.emit(eventName, data);
166
- }
167
- /**
168
- * Ajoute un sous-graph (GraphEngine) comme un nœud dans le workflow courant.
169
- * @param {GraphEngine<T>} subGraph
170
- * @param {string} entryNode - Le nom du nœud de démarrage dans le sous-graph
171
- * @param {string} name - Le nom symbolique à donner au sous-graph
172
- */
173
- addSubGraph(subGraph, entryNode, name) {
174
- const subGraphNode = {
175
- name: name,
176
- execute: (state) => __awaiter(this, void 0, void 0, function* () {
177
- yield subGraph.execute(state, entryNode);
178
- return state;
179
- }),
180
- };
181
- this.nodes.set(name, subGraphNode);
182
- }
183
- /**
184
- * Exécute le workflow à partir d’un nœud donné.
185
- * @param {SharedState<T>} state
186
- * @param {string} startNode
187
- * @param {(state: SharedState<T>) => void} [onStream] - Callback sur l’évolution de l’état
188
- * @param {(error: Error, nodeName: string, state: SharedState<T>) => void} [onError] - Callback sur erreur
189
- */
190
- execute(state, startNode, onStream, onError) {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- var _a;
193
- try {
194
- // Valide l'état initial via le schéma global (si défini)
195
- if (this.schema) {
196
- try {
197
- this.schema.parse(state);
198
- }
199
- catch (error) {
200
- const validationError = new Error(`Échec de la validation de l'état initial: ${error instanceof Error ? error.message : error}`);
201
- if (onError)
202
- onError(validationError, startNode, state);
203
- throw validationError;
204
- }
205
- }
206
- this.setState(state);
207
- let currentNodeName = startNode;
208
- while (currentNodeName) {
209
- this.executedNodes.add(currentNodeName);
210
- const currentNode = this.nodes.get(currentNodeName);
211
- if (!currentNode) {
212
- throw new Error(`Node ${currentNodeName} introuvable.`);
213
- }
214
- // Vérification de condition (si présente)
215
- if (currentNode.condition &&
216
- !currentNode.condition(this.currentState)) {
217
- break;
218
- }
219
- try {
220
- // Notifier : début d'exécution du nœud
221
- if (this.notifier) {
222
- this.notifier.notify("nodeExecutionStarted", {
223
- workflow: this.name,
224
- node: currentNodeName,
225
- });
226
- }
227
- const newState = yield currentNode.execute(this.currentState);
228
- if (newState) {
229
- this.setState(newState);
230
- if (onStream)
231
- onStream(this);
232
- }
233
- // Sauvegarde via la persistence (optionnel)
234
- if (this.persistence) {
235
- yield this.persistence.saveState(this.name, this.currentState, currentNodeName);
236
- }
237
- // Notifier : fin d'exécution du nœud
238
- if (this.notifier) {
239
- yield this.notifier.notify("nodeExecutionCompleted", {
240
- workflow: this.name,
241
- node: currentNodeName,
242
- state: this.currentState,
243
- });
244
- }
245
- }
246
- catch (error) {
247
- if (onError) {
248
- onError(error, currentNodeName, this.currentState);
249
- }
250
- if (this.notifier) {
251
- this.notifier.notify("nodeExecutionFailed", {
252
- workflow: this.name,
253
- node: currentNodeName,
254
- state: this.currentState,
255
- error,
256
- });
257
- }
258
- break;
259
- }
260
- // Gestion des relations (branchements)
261
- const relationsNodes = currentNode.relationships || [];
262
- if (relationsNodes.length > 1) {
263
- // Exécution parallèle des branches
264
- yield Promise.all(relationsNodes.map((relation) => this.execute(this.currentState, relation.name, onStream, onError)));
265
- // Après exécution en parallèle, on arrête la boucle
266
- break;
267
- }
268
- else {
269
- // Cas normal : un seul chemin
270
- currentNodeName = ((_a = relationsNodes[0]) === null || _a === void 0 ? void 0 : _a.name) || "";
271
- }
272
- }
273
- return this.getState();
274
- }
275
- catch (error) {
276
- if (onError) {
277
- onError(error, startNode, state);
278
- }
279
- throw error;
280
- }
281
- });
282
- }
283
- /**
284
- * Exécute plusieurs nœuds en parallèle au sein du même workflow, avec une limite de concurrence.
285
- * @param {SharedState<T>} state
286
- * @param {string[]} nodeNames
287
- * @param {number} [concurrencyLimit=5]
288
- */
289
- executeParallel(state_1, nodeNames_1) {
290
- return __awaiter(this, arguments, void 0, function* (state, nodeNames, concurrencyLimit = 5, onStream, onError) {
291
- const executeWithLimit = (nodeName) => __awaiter(this, void 0, void 0, function* () {
292
- yield this.execute(state, nodeName, onStream, onError);
293
- });
294
- const chunks = [];
295
- for (let i = 0; i < nodeNames.length; i += concurrencyLimit) {
296
- chunks.push(nodeNames.slice(i, i + concurrencyLimit));
297
- }
298
- for (const chunk of chunks) {
299
- yield Promise.all(chunk.map(executeWithLimit));
300
- }
301
- });
302
- }
303
- /**
304
- * Met à jour le workflow avec une nouvelle définition (mise à jour des nœuds existants ou ajout de nouveaux).
305
- * @param {GraphDefinition<T>} definition
306
- */
307
- updateGraph(definition) {
308
- Object.entries(definition.nodes).forEach(([_, nodeConfig]) => {
309
- if (this.nodes.has(nodeConfig.name)) {
310
- const existingNode = this.nodes.get(nodeConfig.name);
311
- existingNode.relationships =
312
- nodeConfig.relationships || existingNode.relationships;
313
- existingNode.condition = nodeConfig.condition || existingNode.condition;
314
- existingNode.events = nodeConfig.events || existingNode.events;
315
- }
316
- else {
317
- this.addNode(nodeConfig);
318
- }
319
- });
320
- }
321
- /**
322
- * Remplace complètement le workflow par une nouvelle définition.
323
- * @param {GraphDefinition<T>} definition
324
- */
325
- replaceGraph(definition) {
326
- this.nodes.clear();
327
- this.loadFromDefinition(definition);
328
- }
329
- /**
330
- * Génère un diagramme Mermaid pour visualiser le workflow.
331
- * @param {string} [title]
332
- * @returns {string}
333
- */
334
- generateMermaidDiagram(title) {
335
- const lines = ["flowchart TD"];
336
- if (title) {
337
- lines.push(` subgraph ${title}`);
338
- }
339
- // Ajout des nœuds
340
- this.nodes.forEach((node, nodeName) => {
341
- const hasEvents = node.events && node.events.length > 0;
342
- const hasCondition = !!node.condition;
343
- // Style selon les propriétés
344
- let style = "";
345
- if (hasEvents) {
346
- style = "style " + nodeName + " fill:#FFD700,stroke:#DAA520"; // Jaune pour event
347
- }
348
- else if (hasCondition) {
349
- style = "style " + nodeName + " fill:#FFA500,stroke:#FF8C00"; // Orange pour condition
350
- }
351
- lines.push(` ${nodeName}[${nodeName}]`);
352
- if (style) {
353
- lines.push(` ${style}`);
354
- }
355
- });
356
- // Ajout des connexions
357
- this.nodes.forEach((node, nodeName) => {
358
- if (node.relationships) {
359
- node.relationships.forEach((relationsNode) => {
360
- let connectionStyle = "";
361
- if (node.condition) {
362
- connectionStyle = "---|condition|";
363
- }
364
- else {
365
- connectionStyle = "-->";
366
- }
367
- lines.push(` ${nodeName} ${connectionStyle} ${relationsNode}`);
368
- });
369
- }
370
- // Gestion des events
371
- if (node.events && node.events.length > 0) {
372
- node.events.forEach((event) => {
373
- const eventNodeId = `${event}_event`;
374
- lines.push(` ${eventNodeId}((${event})):::event`);
375
- lines.push(` ${eventNodeId} -.->|trigger| ${nodeName}`);
376
- });
377
- lines.push(" classDef event fill:#FFD700,stroke:#DAA520");
378
- }
379
- });
380
- if (title) {
381
- lines.push(" end");
382
- }
383
- return lines.join("\n");
384
- }
385
- /**
386
- * Affiche le diagramme Mermaid dans la console.
387
- * @param {string} [title]
388
- */
389
- visualize(title) {
390
- const diagram = this.generateMermaidDiagram(title);
391
- console.log("Pour visualiser ce workflow, utilisez un rendu compatible Mermaid avec la syntaxe suivante :");
392
- console.log("\n```mermaid");
393
- console.log(diagram);
394
- console.log("```\n");
395
- }
396
- /**
397
- * Exporte la définition du workflow au format JSON (pour debug ou documentation).
398
- * @param {GraphDefinition<T>} workflow
399
- * @returns {string} JSON string
400
- */
401
- exportGraphToJson(workflow) {
402
- const result = {
403
- workflowName: workflow.name,
404
- entryNode: workflow.entryNode,
405
- nodes: Object.entries(workflow.nodes).reduce((acc, [key, node]) => {
406
- acc[key] = {
407
- name: node.name,
408
- description: node.description || "No description provided",
409
- execute: node.execute.name,
410
- condition: node.condition ? node.condition.toString() : "None",
411
- relationships: node.relationships || [],
412
- };
413
- return acc;
414
- }, {}),
415
- };
416
- return JSON.stringify(result, null, 2);
417
- }
418
- /**
419
- * Génère une représentation textuelle (console) du schéma du workflow.
420
- * @returns {string}
421
- */
422
- visualizeSchema() {
423
- const output = [];
424
- output.push(`📋 Graph: ${this.name}`);
425
- output.push("=".repeat(50));
426
- // Schéma global
427
- if (this.schema) {
428
- output.push("🔷 Global Schema:");
429
- output.push("-".repeat(30));
430
- if (this.schema instanceof zod_1.z.ZodObject) {
431
- const shape = this.schema.shape;
432
- Object.entries(shape).forEach(([key, value]) => {
433
- const description = this.describeZodType(value, 1);
434
- output.push(`${key}:`);
435
- output.push(description);
436
- });
437
- }
438
- output.push("");
439
- }
440
- // Détails des nœuds
441
- output.push("🔷 Nodes:");
442
- output.push("-".repeat(30));
443
- this.nodes.forEach((node, nodeName) => {
444
- output.push(`\n📍 Node: ${nodeName}`);
445
- output.push(`Description: ${node.description || "No description provided"}`);
446
- if (node.relationships && node.relationships.length > 0) {
447
- const rels = node.relationships.map((r) => r.name).join(", ");
448
- output.push(`Next nodes: ${rels}`);
449
- }
450
- output.push("");
451
- });
452
- return output.join("\n");
453
- }
454
- /**
455
- * Décrit récursivement un type Zod pour l'affichage.
456
- * @param {z.ZodType} type
457
- * @param {number} indent
458
- * @returns {string}
459
- */
460
- describeZodType(type, indent = 0) {
461
- const padding = " ".repeat(indent);
462
- if (type instanceof zod_1.z.ZodObject) {
463
- const shape = type.shape;
464
- const lines = [];
465
- Object.entries(shape).forEach(([key, value]) => {
466
- const isOptional = value instanceof zod_1.z.ZodOptional;
467
- const actualType = isOptional
468
- ? value.unwrap()
469
- : value;
470
- const description = this.describeZodType(actualType, indent + 1);
471
- lines.push(`${padding}${key}${isOptional ? "?" : ""}: ${description}`);
472
- });
473
- return lines.join("\n");
474
- }
475
- if (type instanceof zod_1.z.ZodArray) {
476
- const elementType = this.describeZodType(type.element, indent);
477
- return `Array<${elementType}>`;
478
- }
479
- if (type instanceof zod_1.z.ZodString) {
480
- const checks = type._def.checks || [];
481
- const constraints = checks
482
- .map((check) => {
483
- if (check.kind === "url")
484
- return "url";
485
- if (check.kind === "email")
486
- return "email";
487
- return check.kind;
488
- })
489
- .join(", ");
490
- return constraints ? `string (${constraints})` : "string";
491
- }
492
- if (type instanceof zod_1.z.ZodNumber) {
493
- return "number";
494
- }
495
- if (type instanceof zod_1.z.ZodBoolean) {
496
- return "boolean";
497
- }
498
- if (type instanceof zod_1.z.ZodOptional) {
499
- return `${this.describeZodType(type.unwrap(), indent)} (optional)`;
500
- }
501
- return type.constructor.name.replace("Zod", "") || "unknown";
502
- }
503
- /**
504
- * Met à jour le contexte du workflow pour un nœud, en renvoyant un nouvel état.
505
- * @param {SharedState<T>} state
506
- * @param {Partial<T>} updates
507
- * @returns {SharedState<T>}
508
- */
509
- updateNodeState(state, updates) {
510
- return Object.assign(Object.assign({}, state), updates);
511
- }
512
- /**
513
- * Récupère l'état courant du workflow.
514
- * @returns {SharedState<T>}
515
- */
516
- getState() {
517
- return this.currentState;
518
- }
519
- /**
520
- * Définit le nouvel état courant du workflow et met à jour le contexte global.
521
- * @param {Partial<SharedState<T>>} state
522
- */
523
- setState(state) {
524
- this.currentState = this.mergeStates(this.currentState, state);
525
- if (state) {
526
- Object.entries(state).forEach(([key, value]) => {
527
- this.globalContext.set(key, value);
528
- });
529
- }
530
- const currentNode = Array.from(this.executedNodes).pop();
531
- if (currentNode) {
532
- const node = this.nodes.get(currentNode);
533
- if (node) {
534
- node.state = Object.assign(Object.assign({}, (node.state || {})), (state || {}));
535
- }
536
- }
537
- }
538
- /**
539
- * Fusionne deux états.
540
- * @param {SharedState<T>} currentState
541
- * @param {Partial<SharedState<T>>} newState
542
- * @returns {SharedState<T>}
543
- */
544
- mergeStates(currentState, newState) {
545
- return Object.assign(Object.assign({}, currentState), (newState || {}));
546
- }
547
- /**
548
- * Met à jour l'état courant et le renvoie.
549
- * @param {Partial<T>} updates
550
- * @returns {SharedState<T>}
551
- */
552
- updateState(updates) {
553
- const currentState = this.getState();
554
- const newState = Object.assign(Object.assign({}, currentState), updates);
555
- this.setState(newState);
556
- return newState;
557
- }
558
- /* =============================================
559
- = MÉTHODES STATIQUES POUR PLUSIEURS GRAPHES =
560
- ============================================= */
561
- /**
562
- * Exécute plusieurs GraphEngine en **séquence** (l'un après l'autre).
563
- * @param graphs Liste des graphes à exécuter
564
- * @param startNodes Noms des nœuds de départ correspondants
565
- * @param initialStates États initiaux correspondants
566
- * @param onStream Callback d'avancement
567
- * @param onError Callback d'erreur
568
- * @returns Tableau des états finaux de chaque graphe
569
- */
570
- static executeGraphsInSequence(graphs, startNodes, initialStates, actions, // Pass actions here
571
- onStream, onError) {
572
- return __awaiter(this, void 0, void 0, function* () {
573
- // Return updated actions directly
574
- const finalStates = [];
575
- for (let i = 0; i < graphs.length; i++) {
576
- const graph = graphs[i];
577
- const startNode = startNodes[i];
578
- const initialState = initialStates[i];
579
- const result = yield graph.execute(initialState, startNode, onStream, onError);
580
- finalStates.push({
581
- name: graph.name,
582
- result,
583
- });
584
- }
585
- // Map results to actions
586
- return actions.map((action) => {
587
- const result = finalStates.find((state) => state.name === action.name);
588
- return Object.assign(Object.assign({}, action), { result: result ? result.result : null });
589
- });
590
- });
591
- }
592
- /**
593
- * Exécute plusieurs GraphEngine en **parallèle** (sans limite de concurrence).
594
- * @param graphs Liste des graphes
595
- * @param startNodes Noms des nœuds de départ
596
- * @param initialStates États initiaux
597
- * @param onStream Callback d'avancement
598
- * @param onError Callback d'erreur
599
- * @returns Tableau des états finaux de chaque graphe
600
- */
601
- static executeGraphsInParallel(graphs, startNodes, initialStates, onStream, onError) {
602
- return __awaiter(this, void 0, void 0, function* () {
603
- const promises = graphs.map((graph, index) => graph.execute(initialStates[index], startNodes[index], onStream, onError));
604
- return Promise.all(promises);
605
- });
606
- }
607
- /**
608
- * Exécute plusieurs GraphEngine en parallèle **avec une limite de concurrence**.
609
- * @param graphs Liste des graphes
610
- * @param startNodes Noms des nœuds de départ
611
- * @param initialStates États initiaux
612
- * @param concurrencyLimit Limite de concurrence
613
- * @param onStream Callback d'avancement
614
- * @param onError Callback d'erreur
615
- * @returns Tableau des états finaux de chaque graphe
616
- */
617
- static executeGraphsWithConcurrencyLimit(graphs, startNodes, initialStates, concurrencyLimit, onStream, onError) {
618
- return __awaiter(this, void 0, void 0, function* () {
619
- const results = [];
620
- for (let i = 0; i < graphs.length; i += concurrencyLimit) {
621
- const chunkGraphs = graphs.slice(i, i + concurrencyLimit);
622
- const chunkStartNodes = startNodes.slice(i, i + concurrencyLimit);
623
- const chunkInitialStates = initialStates.slice(i, i + concurrencyLimit);
624
- const chunkPromises = chunkGraphs.map((graph, index) => {
625
- return graph.execute(chunkInitialStates[index], chunkStartNodes[index], onStream, onError);
626
- });
627
- const chunkResults = yield Promise.all(chunkPromises);
628
- results.push(...chunkResults);
629
- }
630
- return results;
631
- });
632
- }
633
- }
634
- exports.GraphEngine = GraphEngine;