@ai.ntellect/core 0.6.20 → 0.6.21
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/README.md +110 -147
- package/dist/graph/controller.js +10 -13
- package/dist/graph/index.js +184 -85
- package/dist/index.js +1 -1
- package/dist/modules/embedding/index.js +5 -5
- package/dist/utils/generate-action-schema.js +7 -6
- package/graph/index.ts +13 -31
- package/modules/embedding/index.ts +3 -3
- package/package.json +3 -16
- package/test/graph/index.test.ts +105 -94
- package/utils/generate-action-schema.ts +8 -7
- package/.env.example +0 -2
- package/graph.ts +0 -74
package/dist/graph/index.js
CHANGED
@@ -29,15 +29,21 @@ class GraphFlow {
|
|
29
29
|
* Creates a new instance of GraphFlow
|
30
30
|
* @param {string} name - The name of the graph flow
|
31
31
|
* @param {GraphDefinition<T>} config - Configuration object containing nodes, schema, context, and error handlers
|
32
|
+
* @param {Object} options - Optional options for the graph flow
|
32
33
|
*/
|
33
|
-
constructor(name, config) {
|
34
|
+
constructor(name, config, options = {}) {
|
35
|
+
var _a;
|
34
36
|
this.name = name;
|
37
|
+
this.logs = [];
|
38
|
+
this.verbose = false;
|
35
39
|
this.nodes = new Map(config.nodes.map((node) => [node.name, node]));
|
36
40
|
this.validator = config.schema;
|
37
41
|
this.context = config.schema.parse(config.context);
|
38
42
|
this.globalErrorHandler = config.onError;
|
39
|
-
this.eventEmitter =
|
43
|
+
this.eventEmitter =
|
44
|
+
config.eventEmitter || new events_1.EventEmitter();
|
40
45
|
this.graphEvents = config.events;
|
46
|
+
this.verbose = (_a = options.verbose) !== null && _a !== void 0 ? _a : false;
|
41
47
|
this.setupEventListeners();
|
42
48
|
this.setupGraphEventListeners();
|
43
49
|
}
|
@@ -93,6 +99,27 @@ class GraphFlow {
|
|
93
99
|
}
|
94
100
|
}
|
95
101
|
}
|
102
|
+
addLog(message) {
|
103
|
+
const logMessage = `[${new Date().toISOString()}] ${message}`;
|
104
|
+
this.logs.push(logMessage);
|
105
|
+
if (this.verbose) {
|
106
|
+
console.log(`[${this.name}] ${message}`);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
/**
|
110
|
+
* Enable or disable verbose logging
|
111
|
+
* @param {boolean} enabled - Whether to enable verbose logging
|
112
|
+
*/
|
113
|
+
setVerbose(enabled) {
|
114
|
+
this.verbose = enabled;
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* Get current verbose setting
|
118
|
+
* @returns {boolean} Current verbose setting
|
119
|
+
*/
|
120
|
+
isVerbose() {
|
121
|
+
return this.verbose;
|
122
|
+
}
|
96
123
|
/**
|
97
124
|
* Executes a specific node in the graph
|
98
125
|
* @private
|
@@ -104,76 +131,142 @@ class GraphFlow {
|
|
104
131
|
*/
|
105
132
|
executeNode(nodeName_1, context_1, inputs_1) {
|
106
133
|
return __awaiter(this, arguments, void 0, function* (nodeName, context, inputs, triggeredByEvent = false) {
|
107
|
-
var _a
|
134
|
+
var _a;
|
108
135
|
const node = this.nodes.get(nodeName);
|
109
136
|
if (!node)
|
110
|
-
throw new Error(
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
}
|
124
|
-
validatedInputs = node.inputs.parse(inputs);
|
125
|
-
}
|
126
|
-
this.eventEmitter.emit("nodeStarted", { name: nodeName, context });
|
127
|
-
// Execute the node
|
128
|
-
yield node.execute(context, validatedInputs);
|
129
|
-
if (node.outputs) {
|
130
|
-
node.outputs.parse(context);
|
137
|
+
throw new Error(`Node "${nodeName}" not found.`);
|
138
|
+
this.addLog(`🚀 Starting node "${nodeName}"`);
|
139
|
+
this.eventEmitter.emit("nodeStarted", { name: nodeName });
|
140
|
+
try {
|
141
|
+
const localContext = structuredClone(context);
|
142
|
+
if (node.condition && !node.condition(localContext)) {
|
143
|
+
this.addLog(`⏭️ Skipping node "${nodeName}" - condition not met`);
|
144
|
+
return;
|
145
|
+
}
|
146
|
+
// Validate inputs
|
147
|
+
if (node.inputs) {
|
148
|
+
if (!inputs) {
|
149
|
+
this.addLog(`❌ Missing required inputs for node "${nodeName}"`);
|
150
|
+
throw new Error(`Inputs required for node "${nodeName}"`);
|
131
151
|
}
|
132
|
-
this.
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
152
|
+
this.addLog(`📥 Validating inputs for node "${nodeName}"`);
|
153
|
+
inputs = node.inputs.parse(inputs);
|
154
|
+
}
|
155
|
+
// Handle retry logic
|
156
|
+
if (node.retry && node.retry.maxAttempts > 0) {
|
157
|
+
let attempts = 0;
|
158
|
+
let lastError = null;
|
159
|
+
while (attempts < node.retry.maxAttempts) {
|
160
|
+
try {
|
161
|
+
this.addLog(`🔄 Attempt ${attempts + 1}/${node.retry.maxAttempts}`);
|
162
|
+
yield node.execute(localContext, inputs);
|
163
|
+
lastError = null;
|
164
|
+
break;
|
165
|
+
}
|
166
|
+
catch (error) {
|
167
|
+
lastError = error;
|
168
|
+
attempts++;
|
169
|
+
this.addLog(`❌ Attempt ${attempts} failed: ${error.message}`);
|
170
|
+
if (attempts === node.retry.maxAttempts) {
|
171
|
+
// Si toutes les tentatives ont échoué et qu'il y a un gestionnaire d'échec
|
172
|
+
if (node.retry.onRetryFailed) {
|
173
|
+
this.addLog(`🔄 Executing retry failure handler for node "${nodeName}"`);
|
174
|
+
try {
|
175
|
+
yield node.retry.onRetryFailed(lastError, localContext);
|
176
|
+
// Si le gestionnaire d'échec réussit, on continue l'exécution
|
177
|
+
// SEULEMENT si le gestionnaire a explicitement retourné true
|
178
|
+
if (node.retry.continueOnFailed) {
|
179
|
+
this.addLog(`✅ Retry failure handler succeeded for node "${nodeName}" - continuing execution`);
|
180
|
+
break;
|
181
|
+
}
|
182
|
+
else {
|
183
|
+
this.addLog(`⚠️ Retry failure handler executed but node "${nodeName}" will still fail`);
|
184
|
+
throw lastError;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
catch (handlerError) {
|
188
|
+
this.addLog(`❌ Retry failure handler failed for node "${nodeName}": ${handlerError.message}`);
|
189
|
+
throw handlerError;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
// Si pas de gestionnaire d'échec ou si le gestionnaire a échoué
|
193
|
+
throw lastError;
|
194
|
+
}
|
195
|
+
if (attempts < node.retry.maxAttempts) {
|
196
|
+
this.addLog(`⏳ Waiting ${node.retry.delay}ms before next attempt`);
|
197
|
+
yield new Promise((resolve) => { var _a; return setTimeout(resolve, ((_a = node.retry) === null || _a === void 0 ? void 0 : _a.delay) || 0); });
|
198
|
+
}
|
199
|
+
}
|
139
200
|
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
201
|
+
}
|
202
|
+
else {
|
203
|
+
yield node.execute(localContext, inputs);
|
204
|
+
}
|
205
|
+
// Validate outputs
|
206
|
+
if (node.outputs) {
|
207
|
+
this.addLog(`📤 Validating outputs for node "${nodeName}"`);
|
208
|
+
node.outputs.parse(localContext);
|
209
|
+
}
|
210
|
+
Object.assign(context, localContext);
|
211
|
+
this.addLog(`✅ Node "${nodeName}" executed successfully ${JSON.stringify(context)}`);
|
212
|
+
this.eventEmitter.emit("nodeCompleted", { name: nodeName });
|
213
|
+
// Handle waitForEvent
|
214
|
+
if (node.waitForEvent && !triggeredByEvent) {
|
215
|
+
this.addLog(`⏳ Node "${nodeName}" waiting for events: ${(_a = node.events) === null || _a === void 0 ? void 0 : _a.join(", ")}`);
|
216
|
+
yield new Promise((resolve) => {
|
217
|
+
var _a;
|
218
|
+
const eventHandler = () => {
|
219
|
+
this.addLog(`🚀 Event received for node "${nodeName}"`);
|
220
|
+
resolve();
|
221
|
+
};
|
222
|
+
(_a = node.events) === null || _a === void 0 ? void 0 : _a.forEach((event) => {
|
223
|
+
this.eventEmitter.once(event, eventHandler);
|
224
|
+
});
|
225
|
+
});
|
226
|
+
const nextNodes = typeof node.next === "function"
|
227
|
+
? node.next(context)
|
228
|
+
: node.next || [];
|
229
|
+
if (nextNodes.length > 0) {
|
230
|
+
this.addLog(`➡️ Executing next nodes: ${nextNodes.join(", ")}`);
|
231
|
+
// Execute next nodes
|
232
|
+
for (const nextNodeName of nextNodes) {
|
233
|
+
this.addLog(`🔄 Starting branch for node "${nextNodeName}"`);
|
145
234
|
const nextNode = this.nodes.get(nextNodeName);
|
146
|
-
if (
|
147
|
-
|
148
|
-
const branchContext = structuredClone(context);
|
149
|
-
// Si le nœud a une condition et qu'elle n'est pas remplie, passer au suivant
|
150
|
-
if (nextNode.condition && !nextNode.condition(branchContext)) {
|
151
|
-
continue;
|
235
|
+
if (nextNode) {
|
236
|
+
yield this.executeNode(nextNodeName, context, undefined, nextNode.waitForEvent);
|
152
237
|
}
|
153
|
-
|
154
|
-
branchContexts.push(branchContext);
|
155
|
-
}
|
156
|
-
// Fusionner les résultats des branches dans l'ordre
|
157
|
-
if (branchContexts.length > 0) {
|
158
|
-
const finalContext = branchContexts[branchContexts.length - 1];
|
159
|
-
Object.assign(context, finalContext);
|
238
|
+
this.addLog(`✅ Branch "${nextNodeName}" completed`);
|
160
239
|
}
|
240
|
+
this.eventEmitter.emit("graphCompleted", {
|
241
|
+
name: this.name,
|
242
|
+
context: this.context,
|
243
|
+
});
|
244
|
+
return;
|
161
245
|
}
|
162
|
-
// Mettre à jour le contexte global
|
163
|
-
this.context = structuredClone(context);
|
164
|
-
return;
|
165
246
|
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
247
|
+
// Execute next nodes
|
248
|
+
const nextNodes = typeof node.next === "function"
|
249
|
+
? node.next(localContext)
|
250
|
+
: node.next || [];
|
251
|
+
if (nextNodes.length > 0) {
|
252
|
+
this.addLog(`➡️ Executing next nodes: ${nextNodes.join(", ")}`);
|
253
|
+
// Execute next nodes
|
254
|
+
for (const nextNodeName of nextNodes) {
|
255
|
+
this.addLog(`🔄 Starting branch for node "${nextNodeName}"`);
|
256
|
+
const nextNode = this.nodes.get(nextNodeName);
|
257
|
+
if (nextNode) {
|
258
|
+
yield this.executeNode(nextNodeName, context, undefined, nextNode.waitForEvent);
|
259
|
+
}
|
260
|
+
this.addLog(`✅ Branch "${nextNodeName}" completed`);
|
173
261
|
}
|
174
|
-
console.warn(`[Graph ${this.name}] Retry attempt ${attempts} for node ${nodeName}`, { error });
|
175
|
-
yield new Promise((resolve) => setTimeout(resolve, delay));
|
176
262
|
}
|
263
|
+
// Mettre à jour le contexte global
|
264
|
+
Object.assign(this.context, context);
|
265
|
+
}
|
266
|
+
catch (error) {
|
267
|
+
this.addLog(`❌ Error in node "${nodeName}": ${error.message}`);
|
268
|
+
this.eventEmitter.emit("nodeError", { name: nodeName, error });
|
269
|
+
throw error;
|
177
270
|
}
|
178
271
|
});
|
179
272
|
}
|
@@ -195,31 +288,28 @@ class GraphFlow {
|
|
195
288
|
* @param {any} inputParams - Optional input parameters for the start node
|
196
289
|
* @returns {Promise<GraphContext<T>>} Final context after execution
|
197
290
|
*/
|
198
|
-
execute(startNode,
|
291
|
+
execute(startNode, inputParams, inputContext) {
|
199
292
|
return __awaiter(this, void 0, void 0, function* () {
|
200
293
|
var _a;
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
294
|
+
if (inputParams) {
|
295
|
+
// Merge inputParams into context
|
296
|
+
Object.assign(this.context, inputParams);
|
297
|
+
}
|
298
|
+
if (inputContext) {
|
299
|
+
Object.assign(this.context, inputContext);
|
300
|
+
}
|
206
301
|
this.eventEmitter.emit("graphStarted", { name: this.name });
|
207
302
|
try {
|
208
|
-
|
209
|
-
yield this.executeNode(startNode, context, inputParams,
|
210
|
-
/* triggeredByEvent= */ false);
|
211
|
-
// Emit "graphCompleted"
|
303
|
+
yield this.executeNode(startNode, this.context, inputParams, false);
|
212
304
|
this.eventEmitter.emit("graphCompleted", {
|
213
305
|
name: this.name,
|
214
306
|
context: this.context,
|
215
307
|
});
|
216
|
-
|
217
|
-
return structuredClone(this.context);
|
308
|
+
return this.getContext();
|
218
309
|
}
|
219
310
|
catch (error) {
|
220
|
-
// Emit "graphError"
|
221
311
|
this.eventEmitter.emit("graphError", { name: this.name, error });
|
222
|
-
(_a = this.globalErrorHandler) === null || _a === void 0 ? void 0 : _a.call(this, error, context);
|
312
|
+
(_a = this.globalErrorHandler) === null || _a === void 0 ? void 0 : _a.call(this, error, this.context);
|
223
313
|
throw error;
|
224
314
|
}
|
225
315
|
});
|
@@ -232,14 +322,17 @@ class GraphFlow {
|
|
232
322
|
*/
|
233
323
|
emit(eventName, data) {
|
234
324
|
return __awaiter(this, void 0, void 0, function* () {
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
//
|
241
|
-
|
242
|
-
|
325
|
+
const workingContext = this.createNewContext();
|
326
|
+
if (data) {
|
327
|
+
Object.assign(workingContext, data);
|
328
|
+
}
|
329
|
+
const eventNodes = Array.from(this.nodes.values()).filter((node) => { var _a; return (_a = node.events) === null || _a === void 0 ? void 0 : _a.includes(eventName); });
|
330
|
+
// Exécuter les nœuds d'événements séquentiellement
|
331
|
+
for (const node of eventNodes) {
|
332
|
+
yield this.executeNode(node.name, workingContext, undefined, true);
|
333
|
+
}
|
334
|
+
// Mettre à jour le contexte global
|
335
|
+
this.context = workingContext;
|
243
336
|
return this.getContext();
|
244
337
|
});
|
245
338
|
}
|
@@ -294,8 +387,8 @@ class GraphFlow {
|
|
294
387
|
this.setupGraphEventListeners();
|
295
388
|
}
|
296
389
|
/**
|
297
|
-
*
|
298
|
-
* @returns {GraphContext<T>}
|
390
|
+
* Gets a copy of the current context
|
391
|
+
* @returns {GraphContext<T>} A deep copy of the current context
|
299
392
|
*/
|
300
393
|
getContext() {
|
301
394
|
return structuredClone(this.context);
|
@@ -398,5 +491,11 @@ class GraphFlow {
|
|
398
491
|
});
|
399
492
|
}
|
400
493
|
}
|
494
|
+
getLogs() {
|
495
|
+
return [...this.logs];
|
496
|
+
}
|
497
|
+
clearLogs() {
|
498
|
+
this.logs = [];
|
499
|
+
}
|
401
500
|
}
|
402
501
|
exports.GraphFlow = GraphFlow;
|
package/dist/index.js
CHANGED
@@ -26,8 +26,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
__exportStar(require("./graph"), exports);
|
30
29
|
__exportStar(require("./graph/controller"), exports);
|
30
|
+
__exportStar(require("./graph/index"), exports);
|
31
31
|
__exportStar(require("./modules/memory"), exports);
|
32
32
|
__exportStar(require("./modules/memory/adapters/meilisearch"), exports);
|
33
33
|
__exportStar(require("./modules/memory/adapters/redis"), exports);
|
@@ -9,18 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.
|
12
|
+
exports.EmbeddingManager = void 0;
|
13
13
|
const ai_1 = require("ai");
|
14
14
|
/**
|
15
|
-
* @module
|
15
|
+
* @module EmbeddingManager
|
16
16
|
* @description A module for generating and managing text embeddings.
|
17
17
|
* Provides functionality for converting text into vector representations
|
18
18
|
* and calculating similarities between embeddings.
|
19
19
|
* @implements {IEmbeddingModule}
|
20
20
|
*/
|
21
|
-
class
|
21
|
+
class EmbeddingManager {
|
22
22
|
/**
|
23
|
-
* Creates an instance of
|
23
|
+
* Creates an instance of EmbeddingManager
|
24
24
|
* @param {IEmbeddingModel} embeddingModel - The embedding model implementation to use
|
25
25
|
*/
|
26
26
|
constructor(embeddingModel) {
|
@@ -56,4 +56,4 @@ class Embedding {
|
|
56
56
|
return ((0, ai_1.cosineSimilarity)(embedding1, embedding2) + 1) * 50;
|
57
57
|
}
|
58
58
|
}
|
59
|
-
exports.
|
59
|
+
exports.EmbeddingManager = EmbeddingManager;
|
@@ -2,13 +2,14 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getSchemaString = exports.generateActionSchema = void 0;
|
4
4
|
const zod_1 = require("zod");
|
5
|
-
const generateActionSchema = (
|
6
|
-
return
|
7
|
-
.map((
|
8
|
-
const
|
9
|
-
|
5
|
+
const generateActionSchema = (graphs) => {
|
6
|
+
return graphs
|
7
|
+
.map((graph) => {
|
8
|
+
const rootNode = Array.from(graph.nodes.values())[0];
|
9
|
+
const schemaStr = rootNode.inputs
|
10
|
+
? (0, exports.getSchemaString)(rootNode.inputs)
|
10
11
|
: "No parameters";
|
11
|
-
return `Workflow: ${
|
12
|
+
return `Workflow: ${graph.name}\nParameters: ${schemaStr}`;
|
12
13
|
})
|
13
14
|
.join("\n\n");
|
14
15
|
};
|
package/graph/index.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { EventEmitter } from "events";
|
2
|
-
import { IEventEmitter } from "interfaces";
|
3
2
|
import { ZodSchema } from "zod";
|
4
3
|
import { GraphContext, GraphDefinition, Node } from "../types";
|
4
|
+
import { IEventEmitter } from "../interfaces";
|
5
5
|
|
6
6
|
/**
|
7
7
|
* @module GraphFlow
|
@@ -17,7 +17,6 @@ import { GraphContext, GraphDefinition, Node } from "../types";
|
|
17
17
|
* @template T - Extends ZodSchema for type validation
|
18
18
|
*/
|
19
19
|
export class GraphFlow<T extends ZodSchema> {
|
20
|
-
private nodes: Map<string, Node<T, any>>;
|
21
20
|
private context: GraphContext<T>;
|
22
21
|
public validator?: T;
|
23
22
|
private eventEmitter: IEventEmitter;
|
@@ -26,6 +25,7 @@ export class GraphFlow<T extends ZodSchema> {
|
|
26
25
|
private entryNode?: string;
|
27
26
|
private logs: string[] = [];
|
28
27
|
private verbose: boolean = false;
|
28
|
+
public nodes: Map<string, Node<T, any>>;
|
29
29
|
|
30
30
|
/**
|
31
31
|
* Creates a new instance of GraphFlow
|
@@ -279,18 +279,14 @@ export class GraphFlow<T extends ZodSchema> {
|
|
279
279
|
if (nextNodes.length > 0) {
|
280
280
|
this.addLog(`➡️ Executing next nodes: ${nextNodes.join(", ")}`);
|
281
281
|
|
282
|
-
//
|
283
|
-
const branchContext = structuredClone(context);
|
284
|
-
|
285
|
-
// Exécuter les branches séquentiellement avec le même contexte
|
282
|
+
// Execute next nodes
|
286
283
|
for (const nextNodeName of nextNodes) {
|
287
284
|
this.addLog(`🔄 Starting branch for node "${nextNodeName}"`);
|
288
285
|
const nextNode = this.nodes.get(nextNodeName);
|
289
286
|
if (nextNode) {
|
290
|
-
// Utiliser le même contexte pour toutes les branches
|
291
287
|
await this.executeNode(
|
292
288
|
nextNodeName,
|
293
|
-
|
289
|
+
context,
|
294
290
|
undefined,
|
295
291
|
nextNode.waitForEvent
|
296
292
|
);
|
@@ -298,10 +294,6 @@ export class GraphFlow<T extends ZodSchema> {
|
|
298
294
|
this.addLog(`✅ Branch "${nextNodeName}" completed`);
|
299
295
|
}
|
300
296
|
|
301
|
-
// Mettre à jour le contexte global avec le résultat final des branches
|
302
|
-
Object.assign(context, branchContext);
|
303
|
-
this.context = structuredClone(context);
|
304
|
-
|
305
297
|
this.eventEmitter.emit("graphCompleted", {
|
306
298
|
name: this.name,
|
307
299
|
context: this.context,
|
@@ -320,29 +312,24 @@ export class GraphFlow<T extends ZodSchema> {
|
|
320
312
|
if (nextNodes.length > 0) {
|
321
313
|
this.addLog(`➡️ Executing next nodes: ${nextNodes.join(", ")}`);
|
322
314
|
|
323
|
-
//
|
324
|
-
const branchContext = structuredClone(context);
|
325
|
-
|
326
|
-
// Exécuter les branches séquentiellement avec le même contexte
|
315
|
+
// Execute next nodes
|
327
316
|
for (const nextNodeName of nextNodes) {
|
328
317
|
this.addLog(`🔄 Starting branch for node "${nextNodeName}"`);
|
329
318
|
const nextNode = this.nodes.get(nextNodeName);
|
330
319
|
if (nextNode) {
|
331
|
-
// Utiliser le même contexte pour toutes les branches
|
332
320
|
await this.executeNode(
|
333
321
|
nextNodeName,
|
334
|
-
|
322
|
+
context,
|
335
323
|
undefined,
|
336
324
|
nextNode.waitForEvent
|
337
325
|
);
|
338
326
|
}
|
339
327
|
this.addLog(`✅ Branch "${nextNodeName}" completed`);
|
340
328
|
}
|
341
|
-
|
342
|
-
// Mettre à jour le contexte global avec le résultat final des branches
|
343
|
-
Object.assign(context, branchContext);
|
344
|
-
this.context = structuredClone(context);
|
345
329
|
}
|
330
|
+
|
331
|
+
// Mettre à jour le contexte global
|
332
|
+
Object.assign(this.context, context);
|
346
333
|
} catch (error: any) {
|
347
334
|
this.addLog(`❌ Error in node "${nodeName}": ${error.message}`);
|
348
335
|
this.eventEmitter.emit("nodeError", { name: nodeName, error });
|
@@ -411,7 +398,7 @@ export class GraphFlow<T extends ZodSchema> {
|
|
411
398
|
eventName: string,
|
412
399
|
data?: Partial<GraphContext<T>>
|
413
400
|
): Promise<GraphContext<T>> {
|
414
|
-
const workingContext =
|
401
|
+
const workingContext = this.createNewContext();
|
415
402
|
|
416
403
|
if (data) {
|
417
404
|
Object.assign(workingContext, data);
|
@@ -421,18 +408,13 @@ export class GraphFlow<T extends ZodSchema> {
|
|
421
408
|
node.events?.includes(eventName)
|
422
409
|
);
|
423
410
|
|
424
|
-
//
|
411
|
+
// Exécuter les nœuds d'événements séquentiellement
|
425
412
|
for (const node of eventNodes) {
|
426
413
|
await this.executeNode(node.name, workingContext, undefined, true);
|
427
414
|
}
|
428
415
|
|
429
|
-
//
|
430
|
-
this.context =
|
431
|
-
|
432
|
-
this.eventEmitter.emit("graphCompleted", {
|
433
|
-
name: this.name,
|
434
|
-
context: this.context,
|
435
|
-
});
|
416
|
+
// Mettre à jour le contexte global
|
417
|
+
this.context = workingContext;
|
436
418
|
|
437
419
|
return this.getContext();
|
438
420
|
}
|
@@ -2,15 +2,15 @@ import { cosineSimilarity } from "ai";
|
|
2
2
|
import { IEmbeddingModel, IEmbeddingModule } from "../../interfaces";
|
3
3
|
|
4
4
|
/**
|
5
|
-
* @module
|
5
|
+
* @module EmbeddingManager
|
6
6
|
* @description A module for generating and managing text embeddings.
|
7
7
|
* Provides functionality for converting text into vector representations
|
8
8
|
* and calculating similarities between embeddings.
|
9
9
|
* @implements {IEmbeddingModule}
|
10
10
|
*/
|
11
|
-
export class
|
11
|
+
export class EmbeddingManager implements IEmbeddingModule {
|
12
12
|
/**
|
13
|
-
* Creates an instance of
|
13
|
+
* Creates an instance of EmbeddingManager
|
14
14
|
* @param {IEmbeddingModel} embeddingModel - The embedding model implementation to use
|
15
15
|
*/
|
16
16
|
constructor(private readonly embeddingModel: IEmbeddingModel) {}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ai.ntellect/core",
|
3
|
-
"version": "0.6.
|
3
|
+
"version": "0.6.21",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"scripts": {
|
@@ -13,34 +13,21 @@
|
|
13
13
|
"author": "Lorcann Rauzduel",
|
14
14
|
"license": "ISC",
|
15
15
|
"dependencies": {
|
16
|
-
"@ai-sdk/deepseek": "^0.1.0",
|
17
|
-
"@ai-sdk/openai": "1.0.6",
|
18
16
|
"@types/node-cron": "^3.0.11",
|
19
17
|
"ai": "^3.0.0",
|
20
|
-
"chalk": "^5.4.1",
|
21
|
-
"ethers": "^6.13.5",
|
22
|
-
"ioredis": "^5.4.2",
|
23
|
-
"langchain": "^0.3.11",
|
24
18
|
"node-cron": "^3.0.3",
|
25
|
-
"readline": "^1.3.0",
|
26
19
|
"redis": "^4.7.0",
|
27
|
-
"rss-parser": "^3.13.0",
|
28
|
-
"sinon": "^19.0.2",
|
29
|
-
"ws": "^8.18.0",
|
30
20
|
"zod": "^3.24.1"
|
31
21
|
},
|
32
22
|
"devDependencies": {
|
33
|
-
"@jest/globals": "^29.7.0",
|
34
23
|
"@types/chai": "^4.3.20",
|
35
|
-
"@types/mocha": "^10.0.
|
24
|
+
"@types/mocha": "^10.0.10",
|
36
25
|
"@types/sinon": "^17.0.3",
|
37
|
-
"@types/ws": "^8.5.14",
|
38
26
|
"chai": "^4.5.0",
|
39
|
-
"dotenv": "^16.4.7",
|
40
|
-
"meilisearch": "^0.37.0",
|
41
27
|
"mocha": "^10.0.0",
|
42
28
|
"nyc": "^17.1.0",
|
43
29
|
"redis": "^4.6.13",
|
30
|
+
"sinon": "^19.0.2",
|
44
31
|
"ts-node": "^10.9.0",
|
45
32
|
"typescript": "^5.7.2"
|
46
33
|
},
|