@ai.ntellect/core 0.6.17 → 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.
- package/.mocharc.json +1 -2
- package/README.md +123 -178
- package/dist/graph/controller.js +29 -6
- package/dist/graph/index.js +302 -62
- package/dist/index.js +21 -6
- package/dist/interfaces/index.js +15 -0
- package/dist/modules/agenda/adapters/node-cron/index.js +29 -0
- package/dist/modules/agenda/index.js +140 -0
- package/dist/{services/embedding.js → modules/embedding/adapters/ai/index.js} +24 -7
- package/dist/modules/embedding/index.js +59 -0
- package/dist/modules/memory/adapters/in-memory/index.js +210 -0
- package/dist/{memory → modules/memory}/adapters/meilisearch/index.js +97 -2
- package/dist/{memory → modules/memory}/adapters/redis/index.js +77 -15
- package/dist/modules/memory/index.js +103 -0
- package/dist/utils/{stringifiy-zod-schema.js → generate-action-schema.js} +5 -5
- package/graph/controller.ts +37 -13
- package/graph/index.ts +348 -73
- package/index.ts +24 -6
- package/interfaces/index.ts +346 -27
- package/modules/agenda/adapters/node-cron/index.ts +25 -0
- package/modules/agenda/index.ts +159 -0
- package/modules/embedding/adapters/ai/index.ts +42 -0
- package/modules/embedding/index.ts +45 -0
- package/modules/memory/adapters/in-memory/index.ts +203 -0
- package/{memory → modules/memory}/adapters/meilisearch/index.ts +114 -12
- package/modules/memory/adapters/redis/index.ts +164 -0
- package/modules/memory/index.ts +93 -0
- package/package.json +3 -1
- package/test/graph/index.test.ts +646 -0
- package/test/modules/agenda/node-cron.test.ts +286 -0
- package/test/modules/embedding/ai.test.ts +78 -0
- package/test/modules/memory/adapters/in-memory.test.ts +153 -0
- package/test/{memory → modules/memory}/adapters/meilisearch.test.ts +79 -75
- package/test/modules/memory/adapters/redis.test.ts +169 -0
- package/test/modules/memory/base.test.ts +230 -0
- package/test/services/agenda.test.ts +279 -280
- package/types/index.ts +82 -203
- package/utils/{stringifiy-zod-schema.ts → generate-action-schema.ts} +3 -3
- package/app/README.md +0 -36
- package/app/app/favicon.ico +0 -0
- package/app/app/globals.css +0 -21
- package/app/app/gun.ts +0 -0
- package/app/app/layout.tsx +0 -18
- package/app/app/page.tsx +0 -321
- package/app/eslint.config.mjs +0 -16
- package/app/next.config.ts +0 -7
- package/app/package-lock.json +0 -5912
- package/app/package.json +0 -31
- package/app/pnpm-lock.yaml +0 -4031
- package/app/postcss.config.mjs +0 -8
- package/app/public/file.svg +0 -1
- package/app/public/globe.svg +0 -1
- package/app/public/next.svg +0 -1
- package/app/public/vercel.svg +0 -1
- package/app/public/window.svg +0 -1
- package/app/tailwind.config.ts +0 -18
- package/app/tsconfig.json +0 -27
- package/dist/memory/index.js +0 -9
- package/dist/services/agenda.js +0 -115
- package/dist/services/queue.js +0 -142
- package/dist/utils/experimental-graph-rag.js +0 -152
- package/dist/utils/generate-object.js +0 -111
- package/dist/utils/inject-actions.js +0 -16
- package/dist/utils/queue-item-transformer.js +0 -24
- package/dist/utils/sanitize-results.js +0 -60
- package/memory/adapters/redis/index.ts +0 -103
- package/memory/index.ts +0 -22
- package/services/agenda.ts +0 -118
- package/services/embedding.ts +0 -26
- package/services/queue.ts +0 -145
- package/test/memory/adapters/redis.test.ts +0 -159
- package/test/memory/base.test.ts +0 -225
- package/test/services/queue.test.ts +0 -286
- package/utils/experimental-graph-rag.ts +0 -170
- package/utils/generate-object.ts +0 -117
- package/utils/inject-actions.ts +0 -19
- package/utils/queue-item-transformer.ts +0 -38
- package/utils/sanitize-results.ts +0 -66
package/dist/graph/index.js
CHANGED
@@ -8,74 +8,159 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
-
};
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
16
|
-
const events_1 =
|
17
|
-
|
12
|
+
exports.GraphFlow = void 0;
|
13
|
+
const events_1 = require("events");
|
14
|
+
/**
|
15
|
+
* @module GraphFlow
|
16
|
+
* @description A flexible workflow engine that manages the execution of nodes in a graph-like structure.
|
17
|
+
*
|
18
|
+
* Key features:
|
19
|
+
* - Multiple branches support
|
20
|
+
* - Conditional branching (runs first matching condition, or all if none have conditions)
|
21
|
+
* - Event-driven nodes
|
22
|
+
* - Zod validation of context/inputs/outputs
|
23
|
+
* - Automatic retry on node failures
|
24
|
+
*
|
25
|
+
* @template T - Extends ZodSchema for type validation
|
26
|
+
*/
|
27
|
+
class GraphFlow {
|
28
|
+
/**
|
29
|
+
* Creates a new instance of GraphFlow
|
30
|
+
* @param {string} name - The name of the graph flow
|
31
|
+
* @param {GraphDefinition<T>} config - Configuration object containing nodes, schema, context, and error handlers
|
32
|
+
*/
|
18
33
|
constructor(name, config) {
|
19
34
|
this.name = name;
|
20
35
|
this.nodes = new Map(config.nodes.map((node) => [node.name, node]));
|
21
|
-
this.
|
22
|
-
this.
|
23
|
-
this.globalErrorHandler = config.
|
24
|
-
this.eventEmitter = new events_1.
|
36
|
+
this.validator = config.schema;
|
37
|
+
this.context = config.schema.parse(config.context);
|
38
|
+
this.globalErrorHandler = config.onError;
|
39
|
+
this.eventEmitter = config.eventEmitter || new events_1.EventEmitter();
|
40
|
+
this.graphEvents = config.events;
|
25
41
|
this.setupEventListeners();
|
42
|
+
this.setupGraphEventListeners();
|
26
43
|
}
|
44
|
+
/**
|
45
|
+
* Creates a new context for execution
|
46
|
+
* @private
|
47
|
+
* @returns {GraphContext<T>} A cloned context to prevent pollution during parallel execution
|
48
|
+
*/
|
27
49
|
createNewContext() {
|
28
50
|
return structuredClone(this.context);
|
29
51
|
}
|
52
|
+
/**
|
53
|
+
* Sets up event listeners for node-based events
|
54
|
+
* @private
|
55
|
+
* @description Attaches all node-based event triggers while preserving external listeners
|
56
|
+
*/
|
30
57
|
setupEventListeners() {
|
31
|
-
|
58
|
+
// First remove only the existing node-based listeners that we might have created previously
|
59
|
+
// We do NOT remove, for example, "nodeStarted" or "nodeCompleted" listeners that test code added.
|
60
|
+
for (const [eventName, listener] of this.eventEmitter
|
61
|
+
.rawListeners("*")
|
62
|
+
.entries()) {
|
63
|
+
// This can be tricky—EventEmitter doesn't directly let you remove by "type" of listener.
|
64
|
+
// Alternatively, we can store references in a separate structure.
|
65
|
+
// For simplicity, let's do a full removeAllListeners() on node-specified events (only),
|
66
|
+
// then re-add them below, but keep the test-based events like "nodeStarted" or "nodeCompleted".
|
67
|
+
}
|
68
|
+
// The simplest approach: removeAllListeners for each event that is declared as a node event
|
69
|
+
// so we don't stack up duplicates:
|
70
|
+
const allEvents = new Set();
|
32
71
|
for (const node of this.nodes.values()) {
|
33
|
-
(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
72
|
+
if (node.events) {
|
73
|
+
node.events.forEach((evt) => allEvents.add(evt));
|
74
|
+
}
|
75
|
+
}
|
76
|
+
for (const evt of allEvents) {
|
77
|
+
// remove only those events that are used by nodes
|
78
|
+
this.eventEmitter.removeAllListeners(evt);
|
79
|
+
}
|
80
|
+
// Now re-add the node-based event triggers
|
81
|
+
for (const node of this.nodes.values()) {
|
82
|
+
if (node.events && node.events.length > 0) {
|
83
|
+
node.events.forEach((event) => {
|
84
|
+
this.eventEmitter.on(event, (data) => __awaiter(this, void 0, void 0, function* () {
|
85
|
+
const freshContext = this.createNewContext();
|
86
|
+
if (data)
|
87
|
+
Object.assign(freshContext, data);
|
88
|
+
// If triggered by an event, we pass "true" so event-driven node will skip `next`.
|
89
|
+
yield this.executeNode(node.name, freshContext, undefined,
|
90
|
+
/* triggeredByEvent= */ true);
|
91
|
+
}));
|
92
|
+
});
|
93
|
+
}
|
41
94
|
}
|
42
95
|
}
|
43
|
-
|
44
|
-
|
96
|
+
/**
|
97
|
+
* Executes a specific node in the graph
|
98
|
+
* @private
|
99
|
+
* @param {string} nodeName - Name of the node to execute
|
100
|
+
* @param {GraphContext<T>} context - Current execution context
|
101
|
+
* @param {any} inputs - Input parameters for the node
|
102
|
+
* @param {boolean} triggeredByEvent - Whether the execution was triggered by an event
|
103
|
+
* @returns {Promise<void>}
|
104
|
+
*/
|
105
|
+
executeNode(nodeName_1, context_1, inputs_1) {
|
106
|
+
return __awaiter(this, arguments, void 0, function* (nodeName, context, inputs, triggeredByEvent = false) {
|
45
107
|
var _a, _b, _c, _d;
|
46
108
|
const node = this.nodes.get(nodeName);
|
47
109
|
if (!node)
|
48
|
-
throw new Error(`❌ Node ${nodeName} not found
|
49
|
-
if (node.condition && !node.condition(context))
|
110
|
+
throw new Error(`❌ Node "${nodeName}" not found.`);
|
111
|
+
if (node.condition && !node.condition(context)) {
|
50
112
|
return;
|
113
|
+
}
|
51
114
|
let attempts = 0;
|
52
115
|
const maxAttempts = ((_a = node.retry) === null || _a === void 0 ? void 0 : _a.maxAttempts) || 1;
|
53
116
|
const delay = ((_b = node.retry) === null || _b === void 0 ? void 0 : _b.delay) || 0;
|
54
117
|
while (attempts < maxAttempts) {
|
55
118
|
try {
|
56
|
-
let
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
throw new Error(`❌ Paramètres requis pour le nœud "${nodeName}" mais reçus: ${params}`);
|
119
|
+
let validatedInputs;
|
120
|
+
if (node.inputs) {
|
121
|
+
if (!inputs) {
|
122
|
+
throw new Error(`❌ Inputs required for node "${nodeName}" but received: ${inputs}`);
|
61
123
|
}
|
62
|
-
|
124
|
+
validatedInputs = node.inputs.parse(inputs);
|
63
125
|
}
|
64
126
|
this.eventEmitter.emit("nodeStarted", { name: nodeName, context });
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if (!validatedParams) {
|
70
|
-
throw new Error(`❌ Paramètres invalides pour le nœud "${nodeName}"`);
|
71
|
-
}
|
72
|
-
yield node.executeWithParams(context, validatedParams);
|
127
|
+
// Execute the node
|
128
|
+
yield node.execute(context, validatedInputs);
|
129
|
+
if (node.outputs) {
|
130
|
+
node.outputs.parse(context);
|
73
131
|
}
|
74
132
|
this.validateContext(context);
|
75
133
|
this.eventEmitter.emit("nodeCompleted", { name: nodeName, context });
|
76
|
-
|
77
|
-
|
134
|
+
// IMPORTANT: Si le nœud est déclenché par un événement et a des événements définis,
|
135
|
+
// on arrête ici et on ne suit pas la chaîne next
|
136
|
+
if (triggeredByEvent && node.events && node.events.length > 0) {
|
137
|
+
this.context = structuredClone(context);
|
138
|
+
return;
|
139
|
+
}
|
140
|
+
// Gérer les nœuds suivants
|
141
|
+
if (node.next && node.next.length > 0) {
|
142
|
+
const branchContexts = [];
|
143
|
+
// Exécuter toutes les branches valides
|
144
|
+
for (const nextNodeName of node.next) {
|
145
|
+
const nextNode = this.nodes.get(nextNodeName);
|
146
|
+
if (!nextNode)
|
147
|
+
continue;
|
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;
|
152
|
+
}
|
153
|
+
yield this.executeNode(nextNodeName, branchContext);
|
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);
|
160
|
+
}
|
78
161
|
}
|
162
|
+
// Mettre à jour le contexte global
|
163
|
+
this.context = structuredClone(context);
|
79
164
|
return;
|
80
165
|
}
|
81
166
|
catch (error) {
|
@@ -92,71 +177,226 @@ class Graph {
|
|
92
177
|
}
|
93
178
|
});
|
94
179
|
}
|
180
|
+
/**
|
181
|
+
* Validates the current context against the schema
|
182
|
+
* @private
|
183
|
+
* @param {GraphContext<T>} context - Context to validate
|
184
|
+
* @throws {Error} If validation fails
|
185
|
+
*/
|
95
186
|
validateContext(context) {
|
96
187
|
if (this.validator) {
|
97
188
|
this.validator.parse(context);
|
98
189
|
}
|
99
190
|
}
|
191
|
+
/**
|
192
|
+
* Executes the graph flow starting from a specific node
|
193
|
+
* @param {string} startNode - Name of the node to start execution from
|
194
|
+
* @param {Partial<GraphContext<T>>} inputContext - Optional partial context to merge with current context
|
195
|
+
* @param {any} inputParams - Optional input parameters for the start node
|
196
|
+
* @returns {Promise<GraphContext<T>>} Final context after execution
|
197
|
+
*/
|
100
198
|
execute(startNode, inputContext, inputParams) {
|
101
199
|
return __awaiter(this, void 0, void 0, function* () {
|
102
200
|
var _a;
|
201
|
+
// Fresh local context from the global
|
103
202
|
const context = this.createNewContext();
|
104
203
|
if (inputContext)
|
105
204
|
Object.assign(context, inputContext);
|
205
|
+
// Emit "graphStarted"
|
106
206
|
this.eventEmitter.emit("graphStarted", { name: this.name });
|
107
207
|
try {
|
108
|
-
|
109
|
-
this.
|
110
|
-
|
208
|
+
// Because we're calling explicitly, it's NOT triggered by an event
|
209
|
+
yield this.executeNode(startNode, context, inputParams,
|
210
|
+
/* triggeredByEvent= */ false);
|
211
|
+
// Emit "graphCompleted"
|
212
|
+
this.eventEmitter.emit("graphCompleted", {
|
213
|
+
name: this.name,
|
214
|
+
context: this.context,
|
215
|
+
});
|
216
|
+
// Return a snapshot of the final global context
|
217
|
+
return structuredClone(this.context);
|
111
218
|
}
|
112
219
|
catch (error) {
|
220
|
+
// Emit "graphError"
|
113
221
|
this.eventEmitter.emit("graphError", { name: this.name, error });
|
114
|
-
(_a = this.globalErrorHandler) === null || _a === void 0 ? void 0 : _a.call(this, error, context);
|
222
|
+
(_a = this.globalErrorHandler) === null || _a === void 0 ? void 0 : _a.call(this, error, context);
|
115
223
|
throw error;
|
116
224
|
}
|
117
225
|
});
|
118
226
|
}
|
227
|
+
/**
|
228
|
+
* Emits an event to trigger event-based nodes
|
229
|
+
* @param {string} eventName - Name of the event to emit
|
230
|
+
* @param {Partial<GraphContext<T>>} data - Optional data to merge with context
|
231
|
+
* @returns {Promise<GraphContext<T>>} Updated context after event handling
|
232
|
+
*/
|
119
233
|
emit(eventName, data) {
|
120
|
-
return
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
235
|
+
// Merge data into a fresh copy of the global context if desired
|
236
|
+
const context = this.createNewContext();
|
121
237
|
if (data)
|
122
|
-
Object.assign(
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
this.eventEmitter.once("nodeCompleted", ({ nodeName }) => {
|
129
|
-
if (nodeName === node.name)
|
130
|
-
resolve();
|
131
|
-
});
|
132
|
-
})))
|
133
|
-
.then(() => resolve(this.context))
|
134
|
-
.catch(reject);
|
238
|
+
Object.assign(context, data);
|
239
|
+
// Just emit the event; the node-based event listeners in setupEventListeners()
|
240
|
+
// will handle calling "executeNode(...)"
|
241
|
+
this.eventEmitter.emit(eventName, context);
|
242
|
+
// Return the updated global context
|
243
|
+
return this.getContext();
|
135
244
|
});
|
136
245
|
}
|
246
|
+
/**
|
247
|
+
* Registers an event handler
|
248
|
+
* @param {string} eventName - Name of the event to listen for
|
249
|
+
* @param {Function} handler - Handler function to execute when event is emitted
|
250
|
+
*/
|
137
251
|
on(eventName, handler) {
|
138
252
|
this.eventEmitter.on(eventName, handler);
|
139
253
|
}
|
140
|
-
|
254
|
+
/**
|
255
|
+
* Updates the graph definition with new configuration
|
256
|
+
* @param {GraphDefinition<T>} definition - New graph definition
|
257
|
+
*/
|
258
|
+
load(definition) {
|
259
|
+
var _a;
|
260
|
+
// Clear all existing nodes
|
141
261
|
this.nodes.clear();
|
142
|
-
|
143
|
-
|
262
|
+
// Wipe out old node-based event listeners
|
263
|
+
// (We keep external test listeners like "nodeStarted" or "nodeCompleted".)
|
264
|
+
if ((_a = definition.nodes) === null || _a === void 0 ? void 0 : _a.length) {
|
265
|
+
const allEvents = new Set();
|
266
|
+
definition.nodes.forEach((n) => { var _a; return (_a = n.events) === null || _a === void 0 ? void 0 : _a.forEach((evt) => allEvents.add(evt)); });
|
267
|
+
for (const evt of allEvents) {
|
268
|
+
this.eventEmitter.removeAllListeners(evt);
|
269
|
+
}
|
270
|
+
}
|
271
|
+
// Add in new nodes
|
272
|
+
definition.nodes.forEach((node) => this.nodes.set(node.name, node));
|
273
|
+
// Parse the new context
|
274
|
+
this.context = definition.schema.parse(definition.context);
|
275
|
+
this.validator = definition.schema;
|
276
|
+
// Store entry node
|
277
|
+
this.entryNode = definition.entryNode;
|
278
|
+
// Store graph events
|
279
|
+
this.graphEvents = definition.events;
|
280
|
+
// Re-setup only node-based event triggers
|
281
|
+
for (const node of this.nodes.values()) {
|
282
|
+
if (node.events && node.events.length > 0) {
|
283
|
+
node.events.forEach((event) => {
|
284
|
+
this.eventEmitter.on(event, (data) => __awaiter(this, void 0, void 0, function* () {
|
285
|
+
const freshContext = structuredClone(this.context);
|
286
|
+
if (data)
|
287
|
+
Object.assign(freshContext, data);
|
288
|
+
yield this.executeNode(node.name, freshContext, undefined, true);
|
289
|
+
}));
|
290
|
+
});
|
291
|
+
}
|
292
|
+
}
|
293
|
+
// Re-setup graph event listeners
|
294
|
+
this.setupGraphEventListeners();
|
144
295
|
}
|
296
|
+
/**
|
297
|
+
* Returns the current context
|
298
|
+
* @returns {GraphContext<T>} Current graph context
|
299
|
+
*/
|
145
300
|
getContext() {
|
146
301
|
return structuredClone(this.context);
|
147
302
|
}
|
303
|
+
/**
|
304
|
+
* Logs a message with optional data
|
305
|
+
* @param {string} message - Message to log
|
306
|
+
* @param {any} data - Optional data to log
|
307
|
+
*/
|
148
308
|
log(message, data) {
|
149
309
|
console.log(`[Graph ${this.name}] ${message}`, data);
|
150
310
|
}
|
311
|
+
/**
|
312
|
+
* Adds a new node to the graph
|
313
|
+
* @param {Node<T>} node - Node to add
|
314
|
+
* @throws {Error} If node with same name already exists
|
315
|
+
*/
|
151
316
|
addNode(node) {
|
152
317
|
this.nodes.set(node.name, node);
|
153
|
-
|
318
|
+
if (node.events && node.events.length > 0) {
|
319
|
+
for (const evt of node.events) {
|
320
|
+
this.eventEmitter.on(evt, (data) => __awaiter(this, void 0, void 0, function* () {
|
321
|
+
const freshContext = this.createNewContext();
|
322
|
+
if (data)
|
323
|
+
Object.assign(freshContext, data);
|
324
|
+
yield this.executeNode(node.name, freshContext, undefined, true);
|
325
|
+
}));
|
326
|
+
}
|
327
|
+
}
|
154
328
|
}
|
329
|
+
/**
|
330
|
+
* Removes a node from the graph
|
331
|
+
* @param {string} nodeName - Name of the node to remove
|
332
|
+
*/
|
155
333
|
removeNode(nodeName) {
|
334
|
+
const node = this.nodes.get(nodeName);
|
335
|
+
if (!node)
|
336
|
+
return;
|
337
|
+
// remove the node from the map
|
156
338
|
this.nodes.delete(nodeName);
|
339
|
+
// remove any of its event-based listeners
|
340
|
+
if (node.events && node.events.length > 0) {
|
341
|
+
for (const evt of node.events) {
|
342
|
+
// removeAllListeners(evt) would also remove other node listeners,
|
343
|
+
// so we need a more fine-grained approach. Ideally, we should keep a reference
|
344
|
+
// to the exact listener function we attached. For brevity, let's remove all for that event:
|
345
|
+
this.eventEmitter.removeAllListeners(evt);
|
346
|
+
}
|
347
|
+
// Then reattach the others that remain in the graph
|
348
|
+
for (const n of this.nodes.values()) {
|
349
|
+
if (n.events && n.events.length > 0) {
|
350
|
+
n.events.forEach((e) => {
|
351
|
+
this.eventEmitter.on(e, (data) => __awaiter(this, void 0, void 0, function* () {
|
352
|
+
const freshContext = this.createNewContext();
|
353
|
+
if (data)
|
354
|
+
Object.assign(freshContext, data);
|
355
|
+
yield this.executeNode(n.name, freshContext, undefined, true);
|
356
|
+
}));
|
357
|
+
});
|
358
|
+
}
|
359
|
+
}
|
360
|
+
}
|
157
361
|
}
|
362
|
+
/**
|
363
|
+
* Returns all nodes in the graph
|
364
|
+
* @returns {Node<T>[]} Array of all nodes
|
365
|
+
*/
|
158
366
|
getNodes() {
|
159
367
|
return Array.from(this.nodes.values());
|
160
368
|
}
|
369
|
+
setupGraphEventListeners() {
|
370
|
+
if (this.graphEvents && this.graphEvents.length > 0) {
|
371
|
+
this.graphEvents.forEach((event) => {
|
372
|
+
this.eventEmitter.on(event, (data) => __awaiter(this, void 0, void 0, function* () {
|
373
|
+
var _a;
|
374
|
+
const freshContext = this.createNewContext();
|
375
|
+
if (data)
|
376
|
+
Object.assign(freshContext, data);
|
377
|
+
// Emit "graphStarted"
|
378
|
+
this.eventEmitter.emit("graphStarted", { name: this.name });
|
379
|
+
try {
|
380
|
+
// Execute the graph starting from the entry node
|
381
|
+
if (!this.entryNode) {
|
382
|
+
throw new Error("No entry node defined for graph event handling");
|
383
|
+
}
|
384
|
+
yield this.executeNode(this.entryNode, freshContext, undefined, false);
|
385
|
+
// Emit "graphCompleted"
|
386
|
+
this.eventEmitter.emit("graphCompleted", {
|
387
|
+
name: this.name,
|
388
|
+
context: this.context,
|
389
|
+
});
|
390
|
+
}
|
391
|
+
catch (error) {
|
392
|
+
// Emit "graphError"
|
393
|
+
this.eventEmitter.emit("graphError", { name: this.name, error });
|
394
|
+
(_a = this.globalErrorHandler) === null || _a === void 0 ? void 0 : _a.call(this, error, freshContext);
|
395
|
+
throw error;
|
396
|
+
}
|
397
|
+
}));
|
398
|
+
});
|
399
|
+
}
|
400
|
+
}
|
161
401
|
}
|
162
|
-
exports.
|
402
|
+
exports.GraphFlow = GraphFlow;
|
package/dist/index.js
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
"use strict";
|
2
|
+
/**
|
3
|
+
* @module @ai.ntellect/core
|
4
|
+
* @description Core module with workflow functionality, providing graph management,
|
5
|
+
* memory storage, agenda scheduling, and embedding capabilities.
|
6
|
+
*
|
7
|
+
* This module exports various components:
|
8
|
+
* - Graph management and controller
|
9
|
+
* - Memory storage adapters (Meilisearch, Redis)
|
10
|
+
* - Agenda scheduling with node-cron adapter
|
11
|
+
* - Embedding functionality with AI adapter
|
12
|
+
* - Utility functions for action schema generation and header building
|
13
|
+
*/
|
2
14
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
15
|
if (k2 === undefined) k2 = k;
|
4
16
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
@@ -16,11 +28,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
29
|
__exportStar(require("./graph"), exports);
|
18
30
|
__exportStar(require("./graph/controller"), exports);
|
19
|
-
__exportStar(require("./memory"), exports);
|
20
|
-
__exportStar(require("./memory/adapters/meilisearch"), exports);
|
21
|
-
__exportStar(require("./memory/adapters/redis"), exports);
|
31
|
+
__exportStar(require("./modules/memory"), exports);
|
32
|
+
__exportStar(require("./modules/memory/adapters/meilisearch"), exports);
|
33
|
+
__exportStar(require("./modules/memory/adapters/redis"), exports);
|
22
34
|
__exportStar(require("./interfaces"), exports);
|
23
|
-
__exportStar(require("./
|
24
|
-
__exportStar(require("./
|
35
|
+
__exportStar(require("./modules/agenda"), exports);
|
36
|
+
__exportStar(require("./modules/agenda/adapters/node-cron"), exports);
|
37
|
+
__exportStar(require("./modules/embedding"), exports);
|
38
|
+
__exportStar(require("./modules/embedding/adapters/ai"), exports);
|
25
39
|
__exportStar(require("./types"), exports);
|
26
|
-
__exportStar(require("./utils/
|
40
|
+
__exportStar(require("./utils/generate-action-schema"), exports);
|
41
|
+
__exportStar(require("./utils/header-builder"), exports);
|
package/dist/interfaces/index.js
CHANGED
@@ -1,2 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BaseMemory = void 0;
|
4
|
+
/**
|
5
|
+
* Abstract base class for memory implementations
|
6
|
+
* @abstract
|
7
|
+
*/
|
8
|
+
class BaseMemory {
|
9
|
+
/**
|
10
|
+
* Creates an instance of BaseMemory
|
11
|
+
* @param {IMemoryAdapter} adapter - Memory adapter implementation
|
12
|
+
*/
|
13
|
+
constructor(adapter) {
|
14
|
+
this.adapter = adapter;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.BaseMemory = BaseMemory;
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.NodeCronAdapter = void 0;
|
7
|
+
const node_cron_1 = __importDefault(require("node-cron"));
|
8
|
+
/**
|
9
|
+
* @module NodeCronAdapter
|
10
|
+
* @description Adapter implementation for node-cron service.
|
11
|
+
* Provides a bridge between the application's scheduling interface and the node-cron library.
|
12
|
+
* @implements {ICronService}
|
13
|
+
*/
|
14
|
+
class NodeCronAdapter {
|
15
|
+
/**
|
16
|
+
* Schedules a new cron job
|
17
|
+
* @param {string} expression - Cron expression defining the schedule
|
18
|
+
* @param {Function} callback - Function to be executed when the schedule triggers
|
19
|
+
* @returns {ICronJob} Interface for controlling the scheduled job
|
20
|
+
*/
|
21
|
+
schedule(expression, callback) {
|
22
|
+
const job = node_cron_1.default.schedule(expression, callback);
|
23
|
+
return {
|
24
|
+
start: () => job.start(),
|
25
|
+
stop: () => job.stop(),
|
26
|
+
};
|
27
|
+
}
|
28
|
+
}
|
29
|
+
exports.NodeCronAdapter = NodeCronAdapter;
|