@ai.ntellect/core 0.7.1 → 0.7.2

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 (78) hide show
  1. package/dist/graph/controller.d.ts +33 -0
  2. package/dist/graph/controller.d.ts.map +1 -0
  3. package/dist/graph/controller.js +73 -0
  4. package/dist/graph/controller.js.map +1 -0
  5. package/dist/graph/event-manager.d.ts +92 -0
  6. package/dist/graph/event-manager.d.ts.map +1 -0
  7. package/dist/graph/event-manager.js +238 -0
  8. package/dist/graph/event-manager.js.map +1 -0
  9. package/dist/graph/index.d.ts +157 -0
  10. package/dist/graph/index.d.ts.map +1 -0
  11. package/dist/graph/index.js +299 -0
  12. package/dist/graph/index.js.map +1 -0
  13. package/dist/graph/logger.d.ts +46 -0
  14. package/dist/graph/logger.d.ts.map +1 -0
  15. package/dist/graph/logger.js +69 -0
  16. package/dist/graph/logger.js.map +1 -0
  17. package/dist/graph/node.d.ts +103 -0
  18. package/dist/graph/node.d.ts.map +1 -0
  19. package/dist/graph/node.js +310 -0
  20. package/dist/graph/node.js.map +1 -0
  21. package/dist/graph/observer.d.ts +113 -0
  22. package/dist/graph/observer.d.ts.map +1 -0
  23. package/dist/graph/observer.js +197 -0
  24. package/dist/graph/observer.js.map +1 -0
  25. package/dist/index.d.ts +26 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +42 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/interfaces/index.d.ts +447 -0
  30. package/dist/interfaces/index.d.ts.map +1 -0
  31. package/dist/interfaces/index.js +75 -0
  32. package/dist/interfaces/index.js.map +1 -0
  33. package/dist/modules/agenda/adapters/node-cron/index.d.ts +17 -0
  34. package/dist/modules/agenda/adapters/node-cron/index.d.ts.map +1 -0
  35. package/dist/modules/agenda/adapters/node-cron/index.js +30 -0
  36. package/dist/modules/agenda/adapters/node-cron/index.js.map +1 -0
  37. package/dist/modules/agenda/index.d.ts +63 -0
  38. package/dist/modules/agenda/index.d.ts.map +1 -0
  39. package/dist/modules/agenda/index.js +141 -0
  40. package/dist/modules/agenda/index.js.map +1 -0
  41. package/dist/modules/embedding/adapters/ai/index.d.ts +29 -0
  42. package/dist/modules/embedding/adapters/ai/index.d.ts.map +1 -0
  43. package/dist/modules/embedding/adapters/ai/index.js +58 -0
  44. package/dist/modules/embedding/adapters/ai/index.js.map +1 -0
  45. package/dist/modules/embedding/index.d.ts +36 -0
  46. package/dist/modules/embedding/index.d.ts.map +1 -0
  47. package/dist/modules/embedding/index.js +60 -0
  48. package/dist/modules/embedding/index.js.map +1 -0
  49. package/dist/modules/memory/adapters/in-memory/index.d.ts +120 -0
  50. package/dist/modules/memory/adapters/in-memory/index.d.ts.map +1 -0
  51. package/dist/modules/memory/adapters/in-memory/index.js +211 -0
  52. package/dist/modules/memory/adapters/in-memory/index.js.map +1 -0
  53. package/dist/modules/memory/adapters/meilisearch/index.d.ts +110 -0
  54. package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +1 -0
  55. package/dist/modules/memory/adapters/meilisearch/index.js +321 -0
  56. package/dist/modules/memory/adapters/meilisearch/index.js.map +1 -0
  57. package/dist/modules/memory/adapters/redis/index.d.ts +82 -0
  58. package/dist/modules/memory/adapters/redis/index.d.ts.map +1 -0
  59. package/dist/modules/memory/adapters/redis/index.js +159 -0
  60. package/dist/modules/memory/adapters/redis/index.js.map +1 -0
  61. package/dist/modules/memory/index.d.ts +67 -0
  62. package/dist/modules/memory/index.d.ts.map +1 -0
  63. package/dist/modules/memory/index.js +104 -0
  64. package/dist/modules/memory/index.js.map +1 -0
  65. package/dist/types/index.d.ts +166 -0
  66. package/dist/types/index.d.ts.map +1 -0
  67. package/dist/types/index.js +3 -0
  68. package/dist/types/index.js.map +1 -0
  69. package/dist/utils/generate-action-schema.d.ts +5 -0
  70. package/dist/utils/generate-action-schema.d.ts.map +1 -0
  71. package/dist/utils/generate-action-schema.js +44 -0
  72. package/dist/utils/generate-action-schema.js.map +1 -0
  73. package/dist/utils/header-builder.d.ts +12 -0
  74. package/dist/utils/header-builder.d.ts.map +1 -0
  75. package/dist/utils/header-builder.js +35 -0
  76. package/dist/utils/header-builder.js.map +1 -0
  77. package/package.json +3 -1
  78. package/tsconfig.json +13 -2
@@ -0,0 +1,299 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GraphFlow = void 0;
13
+ const events_1 = require("events");
14
+ const rxjs_1 = require("rxjs");
15
+ const event_manager_1 = require("./event-manager");
16
+ const logger_1 = require("./logger");
17
+ const node_1 = require("./node");
18
+ const observer_1 = require("./observer");
19
+ /**
20
+ * @module GraphFlow
21
+ * @description A flexible workflow engine that manages the execution of nodes in a graph-like structure.
22
+ *
23
+ * Key features:
24
+ * - Multiple branches support
25
+ * - Conditional branching (runs first matching condition, or all if none have conditions)
26
+ * - Event-driven nodes
27
+ * - Zod validation of context/inputs/outputs
28
+ * - Automatic retry on node failures
29
+ *
30
+ * @template T - Extends ZodSchema for type validation
31
+ */
32
+ class GraphFlow {
33
+ /**
34
+ * Creates a new instance of GraphFlow
35
+ * @param {string} name - The name of the graph flow
36
+ * @param {GraphDefinition<T>} config - Configuration object containing nodes, schema, context, and error handlers
37
+ * @param {Object} options - Optional options for the graph flow
38
+ */
39
+ constructor(name, config, options = {}) {
40
+ var _a;
41
+ this.name = name;
42
+ this.verbose = false;
43
+ this.eventSubject = new rxjs_1.Subject();
44
+ this.destroySubject = new rxjs_1.Subject();
45
+ this.nodes = new Map(config.nodes.map((node) => [node.name, node]));
46
+ this.validator = config.schema;
47
+ this.context = config.schema.parse(config.context);
48
+ this.globalErrorHandler = config.onError;
49
+ this.eventEmitter =
50
+ config.eventEmitter || new events_1.EventEmitter();
51
+ this.graphEvents = config.events;
52
+ this.verbose = (_a = options.verbose) !== null && _a !== void 0 ? _a : false;
53
+ this.stateSubject = new rxjs_1.BehaviorSubject(this.context);
54
+ this.logger = new logger_1.GraphLogger(name, options.verbose);
55
+ this.eventManager = new event_manager_1.GraphEventManager(this.eventEmitter, this.nodes, name, this.context, config.events, config.entryNode, config.onError);
56
+ this.nodeExecutor = new node_1.GraphNode(this.nodes, this.logger, this.eventManager, this.eventSubject, this.stateSubject);
57
+ this.setupEventStreams();
58
+ this.setupEventListeners();
59
+ this.setupGraphEventListeners();
60
+ this.observer = new observer_1.GraphObserver(this, this.eventSubject, this.stateSubject, this.destroySubject);
61
+ }
62
+ /**
63
+ * Sets up event listeners for node-based events
64
+ * @private
65
+ * @description Attaches all node-based event triggers while preserving external listeners
66
+ */
67
+ setupEventStreams() {
68
+ this.eventManager.on("nodeStarted", (data) => {
69
+ this.addLog(`Event: Node "${data.name}" started`);
70
+ });
71
+ this.eventManager.on("nodeCompleted", (data) => {
72
+ this.addLog(`Event: Node "${data.name}" completed`);
73
+ });
74
+ this.eventManager.on("nodeError", (data) => {
75
+ var _a, _b;
76
+ let errorMessage = "Unknown error";
77
+ if (data.error) {
78
+ errorMessage =
79
+ data.error instanceof Error
80
+ ? data.error.message
81
+ : ((_b = (_a = data.error.errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) ||
82
+ data.error.message ||
83
+ "Unknown error";
84
+ }
85
+ this.addLog(`Event: Node "${data.name}" error: ${errorMessage}`);
86
+ });
87
+ this.eventManager.on("nodeStateChanged", (data) => {
88
+ this.addLog(`Event: Node "${data.name}" state changed`);
89
+ });
90
+ }
91
+ /**
92
+ * Sets up event listeners for node-based events
93
+ * @private
94
+ * @description Attaches all node-based event triggers while preserving external listeners
95
+ */
96
+ setupEventListeners() {
97
+ this.eventManager.setupEventListeners();
98
+ }
99
+ /**
100
+ * Sets up event listeners for graph-based events
101
+ * @private
102
+ * @description Attaches all graph-based event triggers
103
+ */
104
+ setupGraphEventListeners() {
105
+ this.eventManager.setupGraphEventListeners();
106
+ }
107
+ /**
108
+ * Executes a specific node in the graph
109
+ * @private
110
+ * @param {string} nodeName - Name of the node to execute
111
+ * @param {GraphContext<T>} context - Current execution context
112
+ * @param {any} inputs - Input parameters for the node
113
+ * @param {boolean} triggeredByEvent - Whether the execution was triggered by an event
114
+ * @returns {Promise<void>}
115
+ */
116
+ executeNode(nodeName_1, context_1, inputs_1) {
117
+ return __awaiter(this, arguments, void 0, function* (nodeName, context, inputs, triggeredByEvent = false) {
118
+ return this.nodeExecutor.executeNode(nodeName, context, inputs, triggeredByEvent);
119
+ });
120
+ }
121
+ addLog(message) {
122
+ this.logger.addLog(message);
123
+ }
124
+ getLogs() {
125
+ return this.logger.getLogs();
126
+ }
127
+ clearLogs() {
128
+ this.logger.clearLogs();
129
+ }
130
+ /**
131
+ * Get the observer instance for monitoring graph state and events
132
+ */
133
+ observe(options = {}) {
134
+ return this.observer.state(options);
135
+ }
136
+ /**
137
+ * Enable or disable verbose logging
138
+ * @param {boolean} enabled - Whether to enable verbose logging
139
+ */
140
+ setVerbose(enabled) {
141
+ this.logger.setVerbose(enabled);
142
+ }
143
+ /**
144
+ * Get current verbose setting
145
+ * @returns {boolean} Current verbose setting
146
+ */
147
+ isVerbose() {
148
+ return this.logger.isVerbose();
149
+ }
150
+ /**
151
+ * Executes the graph flow starting from a specific node
152
+ * @param {string} startNode - Name of the node to start execution from
153
+ * @param {Partial<GraphContext<T>>} inputContext - Optional partial context to merge with current context
154
+ * @param {any} inputParams - Optional input parameters for the start node
155
+ * @returns {Promise<GraphContext<T>>} Final context after execution
156
+ */
157
+ execute(startNode, inputParams, inputContext) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ var _a;
160
+ if (inputParams) {
161
+ Object.assign(this.context, inputParams);
162
+ }
163
+ if (inputContext) {
164
+ Object.assign(this.context, inputContext);
165
+ }
166
+ this.eventEmitter.emit("graphStarted", { name: this.name });
167
+ try {
168
+ yield this.nodeExecutor.executeNode(startNode, this.context, inputParams, false);
169
+ this.eventEmitter.emit("graphCompleted", {
170
+ name: this.name,
171
+ context: this.context,
172
+ });
173
+ return this.getContext();
174
+ }
175
+ catch (error) {
176
+ this.eventEmitter.emit("graphError", { name: this.name, error });
177
+ (_a = this.globalErrorHandler) === null || _a === void 0 ? void 0 : _a.call(this, error, this.context);
178
+ throw error;
179
+ }
180
+ });
181
+ }
182
+ /**
183
+ * Emits an event to trigger event-based nodes
184
+ * @param {string} eventName - Name of the event to emit
185
+ * @param {Partial<GraphContext<T>>} data - Optional data to merge with context
186
+ * @returns {Promise<void>}
187
+ */
188
+ emit(eventName, data) {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ const event = {
191
+ type: eventName,
192
+ payload: data,
193
+ timestamp: Date.now(),
194
+ };
195
+ this.eventSubject.next(event);
196
+ yield new Promise((resolve) => setTimeout(resolve, 0));
197
+ });
198
+ }
199
+ /**
200
+ * Registers an event handler
201
+ * @param {string} eventName - Name of the event to listen for
202
+ * @param {Function} handler - Handler function to execute when event is emitted
203
+ */
204
+ on(eventName, handler) {
205
+ this.eventManager.on(eventName, handler);
206
+ }
207
+ /**
208
+ * Updates the graph definition with new configuration
209
+ * @param {GraphDefinition<T>} definition - New graph definition
210
+ */
211
+ load(definition) {
212
+ var _a;
213
+ // Clear all existing nodes
214
+ this.nodes.clear();
215
+ // Wipe out old node-based event listeners
216
+ // (We keep external test listeners like "nodeStarted" or "nodeCompleted".)
217
+ if ((_a = definition.nodes) === null || _a === void 0 ? void 0 : _a.length) {
218
+ const allEvents = new Set();
219
+ definition.nodes.forEach((n) => { var _a; return (_a = n.events) === null || _a === void 0 ? void 0 : _a.forEach((evt) => allEvents.add(evt)); });
220
+ for (const evt of allEvents) {
221
+ this.eventEmitter.removeAllListeners(evt);
222
+ }
223
+ }
224
+ // Add in new nodes
225
+ definition.nodes.forEach((node) => this.nodes.set(node.name, node));
226
+ // Parse the new context
227
+ this.context = definition.schema.parse(definition.context);
228
+ this.validator = definition.schema;
229
+ // Store entry node
230
+ this.entryNode = definition.entryNode;
231
+ // Store graph events
232
+ this.graphEvents = definition.events;
233
+ // Re-setup only node-based event triggers
234
+ for (const node of this.nodes.values()) {
235
+ if (node.events && node.events.length > 0) {
236
+ node.events.forEach((event) => {
237
+ this.eventEmitter.on(event, (data) => __awaiter(this, void 0, void 0, function* () {
238
+ const freshContext = structuredClone(this.context);
239
+ if (data)
240
+ Object.assign(freshContext, data);
241
+ yield this.executeNode(node.name, freshContext, undefined, true);
242
+ }));
243
+ });
244
+ }
245
+ }
246
+ // Re-setup graph event listeners
247
+ this.setupGraphEventListeners();
248
+ }
249
+ /**
250
+ * Gets a copy of the current context
251
+ * @returns {GraphContext<T>} A deep copy of the current context
252
+ */
253
+ getContext() {
254
+ return structuredClone(this.context);
255
+ }
256
+ /**
257
+ * Logs a message with optional data
258
+ * @param {string} message - Message to log
259
+ * @param {any} data - Optional data to log
260
+ */
261
+ log(message, data) {
262
+ this.logger.log(message, data);
263
+ }
264
+ /**
265
+ * Adds a new node to the graph
266
+ * @param {Node<T>} node - Node to add
267
+ * @throws {Error} If node with same name already exists
268
+ */
269
+ addNode(node) {
270
+ this.nodes.set(node.name, node);
271
+ this.eventManager.setupEventListeners();
272
+ }
273
+ /**
274
+ * Removes a node from the graph
275
+ * @param {string} nodeName - Name of the node to remove
276
+ */
277
+ removeNode(nodeName) {
278
+ this.nodes.delete(nodeName);
279
+ this.eventManager.setupEventListeners();
280
+ }
281
+ /**
282
+ * Returns all nodes in the graph
283
+ * @returns {Node<T>[]} Array of all nodes
284
+ */
285
+ getNodes() {
286
+ return Array.from(this.nodes.values());
287
+ }
288
+ /**
289
+ * Cleanup resources
290
+ */
291
+ destroy() {
292
+ this.destroySubject.next();
293
+ this.destroySubject.complete();
294
+ this.eventSubject.complete();
295
+ this.stateSubject.complete();
296
+ }
297
+ }
298
+ exports.GraphFlow = GraphFlow;
299
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../graph/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAsC;AACtC,+BAAgD;AAIhD,mDAAoD;AACpD,qCAAuC;AACvC,iCAAmC;AACnC,yCAA2C;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAa,SAAS;IAmBpB;;;;;OAKG;IACH,YACS,IAAY,EACnB,MAA0B,EAC1B,UAAiC,EAAE;;QAF5B,SAAI,GAAJ,IAAI,CAAQ;QAnBb,YAAO,GAAY,KAAK,CAAC;QAGzB,iBAAY,GAA2B,IAAI,cAAO,EAAE,CAAC;QAErD,mBAAc,GAAkB,IAAI,cAAO,EAAE,CAAC;QAkBpD,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAClB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAkB,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAC5D,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAoB,CAAC;QACtE,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC;QACzC,IAAI,CAAC,YAAY;YACf,MAAM,CAAC,YAAY,IAAK,IAAI,qBAAY,EAAoB,CAAC;QAC/D,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,KAAK,CAAC;QA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ACL,CAAC;QACH,CAAC;QAED,iCAAiC;QACjC,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAED;;;OAGG;IACI,UAAU;QACf,OAAO,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,OAAe,EAAE,IAAU;QACpC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,IAAkB;QAC/B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACI,UAAU,CAAC,QAAgB;QAChC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5B,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;QAC7B,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF;AAjXD,8BAiXC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Handles logging operations for a graph instance
3
+ * Provides methods for adding, retrieving, and managing logs with optional verbose output
4
+ */
5
+ export declare class GraphLogger {
6
+ private graphName;
7
+ private logs;
8
+ private verbose;
9
+ /**
10
+ * Creates a new GraphLogger instance
11
+ * @param graphName - The name of the graph this logger is associated with
12
+ * @param verbose - Whether to output logs to console in real-time
13
+ */
14
+ constructor(graphName: string, verbose?: boolean);
15
+ /**
16
+ * Adds a new log entry with timestamp
17
+ * @param message - The message to log
18
+ */
19
+ addLog(message: string): void;
20
+ /**
21
+ * Returns a copy of all stored logs
22
+ * @returns Array of log messages
23
+ */
24
+ getLogs(): string[];
25
+ /**
26
+ * Clears all stored logs
27
+ */
28
+ clearLogs(): void;
29
+ /**
30
+ * Sets the verbose mode
31
+ * @param enabled - Whether to enable verbose mode
32
+ */
33
+ setVerbose(enabled: boolean): void;
34
+ /**
35
+ * Gets the current verbose mode status
36
+ * @returns Current verbose mode state
37
+ */
38
+ isVerbose(): boolean;
39
+ /**
40
+ * Logs a message to console with graph name prefix
41
+ * @param message - The message to log
42
+ * @param data - Optional data to log
43
+ */
44
+ log(message: string, data?: any): void;
45
+ }
46
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../graph/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,WAAW;IASV,OAAO,CAAC,SAAS;IAR7B,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,OAAO,CAAkB;IAEjC;;;;OAIG;gBACiB,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,OAAe;IAI/D;;;OAGG;IACI,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IASpC;;;OAGG;IACI,OAAO,IAAI,MAAM,EAAE;IAI1B;;OAEG;IACI,SAAS,IAAI,IAAI;IAIxB;;;OAGG;IACI,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIzC;;;OAGG;IACI,SAAS,IAAI,OAAO;IAI3B;;;;OAIG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;CAGvC"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphLogger = void 0;
4
+ /**
5
+ * Handles logging operations for a graph instance
6
+ * Provides methods for adding, retrieving, and managing logs with optional verbose output
7
+ */
8
+ class GraphLogger {
9
+ /**
10
+ * Creates a new GraphLogger instance
11
+ * @param graphName - The name of the graph this logger is associated with
12
+ * @param verbose - Whether to output logs to console in real-time
13
+ */
14
+ constructor(graphName, verbose = false) {
15
+ this.graphName = graphName;
16
+ this.logs = [];
17
+ this.verbose = false;
18
+ this.verbose = verbose;
19
+ }
20
+ /**
21
+ * Adds a new log entry with timestamp
22
+ * @param message - The message to log
23
+ */
24
+ addLog(message) {
25
+ const timestamp = new Date().toISOString();
26
+ const logMessage = `[${timestamp}] ${message}`;
27
+ this.logs.push(logMessage);
28
+ if (this.verbose) {
29
+ console.log(`${this.graphName} - ${message}`);
30
+ }
31
+ }
32
+ /**
33
+ * Returns a copy of all stored logs
34
+ * @returns Array of log messages
35
+ */
36
+ getLogs() {
37
+ return [...this.logs];
38
+ }
39
+ /**
40
+ * Clears all stored logs
41
+ */
42
+ clearLogs() {
43
+ this.logs = [];
44
+ }
45
+ /**
46
+ * Sets the verbose mode
47
+ * @param enabled - Whether to enable verbose mode
48
+ */
49
+ setVerbose(enabled) {
50
+ this.verbose = enabled;
51
+ }
52
+ /**
53
+ * Gets the current verbose mode status
54
+ * @returns Current verbose mode state
55
+ */
56
+ isVerbose() {
57
+ return this.verbose;
58
+ }
59
+ /**
60
+ * Logs a message to console with graph name prefix
61
+ * @param message - The message to log
62
+ * @param data - Optional data to log
63
+ */
64
+ log(message, data) {
65
+ console.log(`[Graph ${this.graphName}] ${message}`, data);
66
+ }
67
+ }
68
+ exports.GraphLogger = GraphLogger;
69
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../graph/logger.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,WAAW;IAItB;;;;OAIG;IACH,YAAoB,SAAiB,EAAE,UAAmB,KAAK;QAA3C,cAAS,GAAT,SAAS,CAAQ;QAR7B,SAAI,GAAa,EAAE,CAAC;QACpB,YAAO,GAAY,KAAK,CAAC;QAQ/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,OAAe;QAC3B,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,UAAU,GAAG,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;QAC/C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,MAAM,OAAO,EAAE,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,SAAS;QACd,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,CAAC;IAED;;;OAGG;IACI,UAAU,CAAC,OAAgB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,OAAe,EAAE,IAAU;QAC7B,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,CAAC,SAAS,KAAK,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;CACF;AAjED,kCAiEC"}
@@ -0,0 +1,103 @@
1
+ import { BehaviorSubject, Subject } from "rxjs";
2
+ import { ZodSchema } from "zod";
3
+ import { GraphContext, GraphEvent, Node } from "../types";
4
+ import { GraphEventManager } from "./event-manager";
5
+ import { GraphLogger } from "./logger";
6
+ /**
7
+ * Represents a node in the graph that can execute operations and manage state
8
+ * @template T - The Zod schema type for validation
9
+ */
10
+ export declare class GraphNode<T extends ZodSchema> {
11
+ private nodes;
12
+ private logger;
13
+ private eventManager;
14
+ private eventSubject;
15
+ private stateSubject;
16
+ /**
17
+ * Creates a new GraphNode instance
18
+ * @param nodes - Map of all nodes in the graph
19
+ * @param logger - Logger instance for tracking node operations
20
+ * @param eventManager - Manager for handling graph events
21
+ * @param eventSubject - Subject for emitting events
22
+ * @param stateSubject - Subject for managing graph state
23
+ */
24
+ constructor(nodes: Map<string, Node<T, any>>, logger: GraphLogger, eventManager: GraphEventManager<T>, eventSubject: Subject<GraphEvent<T>>, stateSubject: BehaviorSubject<GraphContext<T>>);
25
+ /**
26
+ * Emits an event with the specified type and payload
27
+ * @param type - The type of event to emit
28
+ * @param payload - The data associated with the event
29
+ * @private
30
+ */
31
+ private emitEvent;
32
+ /**
33
+ * Executes a node with the given name and context
34
+ * @param nodeName - The name of the node to execute
35
+ * @param context - The current graph context
36
+ * @param inputs - Input data for the node
37
+ * @param triggeredByEvent - Whether the execution was triggered by an event
38
+ * @throws Error if the node is not found or execution fails
39
+ */
40
+ executeNode(nodeName: string, context: GraphContext<T>, inputs: any, triggeredByEvent?: boolean): Promise<void>;
41
+ /**
42
+ * Validates the inputs for a node using its schema
43
+ * @param node - The node whose inputs need validation
44
+ * @param inputs - The input data to validate
45
+ * @param nodeName - The name of the node (for error messages)
46
+ * @throws Error if validation fails
47
+ * @private
48
+ */
49
+ private validateInputs;
50
+ /**
51
+ * Validates the outputs of a node against its schema
52
+ * @param node - The node whose outputs need validation
53
+ * @param context - The current graph context
54
+ * @param nodeName - The name of the node (for error messages)
55
+ * @throws Error if validation fails
56
+ * @private
57
+ */
58
+ private validateOutputs;
59
+ /**
60
+ * Handles event-related operations for a node
61
+ * @param node - The node whose events need handling
62
+ * @param nodeName - The name of the node
63
+ * @param context - The current graph context
64
+ * @private
65
+ */
66
+ private handleEvents;
67
+ /**
68
+ * Executes a node with retry logic
69
+ * @param node - The node to execute
70
+ * @param contextProxy - The proxied graph context
71
+ * @param inputs - Input data for the node
72
+ * @param nodeName - The name of the node
73
+ * @throws Error if all retry attempts fail
74
+ * @private
75
+ */
76
+ private executeWithRetry;
77
+ /**
78
+ * Handles the failure of retry attempts
79
+ * @param node - The node that failed
80
+ * @param error - The error that caused the failure
81
+ * @param context - The current graph context
82
+ * @param nodeName - The name of the node
83
+ * @private
84
+ */
85
+ private handleRetryFailure;
86
+ /**
87
+ * Handles correlated events for a node
88
+ * @param node - The node with correlated events
89
+ * @param nodeName - The name of the node
90
+ * @throws Error if correlation fails or timeout occurs
91
+ * @private
92
+ */
93
+ private handleCorrelatedEvents;
94
+ /**
95
+ * Handles waiting for events
96
+ * @param node - The node waiting for events
97
+ * @param nodeName - The name of the node
98
+ * @throws Error if timeout occurs
99
+ * @private
100
+ */
101
+ private handleWaitForEvents;
102
+ }
103
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../graph/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;;GAGG;AACH,qBAAa,SAAS,CAAC,CAAC,SAAS,SAAS;IAUtC,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,YAAY;IAbtB;;;;;;;OAOG;gBAEO,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC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