@ai.ntellect/core 0.7.1 → 0.7.4
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 +13 -28
- package/dist/graph/controller.d.ts +33 -0
- package/dist/graph/controller.d.ts.map +1 -0
- package/dist/graph/controller.js +73 -0
- package/dist/graph/controller.js.map +1 -0
- package/dist/graph/event-manager.d.ts +92 -0
- package/dist/graph/event-manager.d.ts.map +1 -0
- package/dist/graph/event-manager.js +244 -0
- package/dist/graph/event-manager.js.map +1 -0
- package/dist/graph/index.d.ts +157 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +299 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/logger.d.ts +46 -0
- package/dist/graph/logger.d.ts.map +1 -0
- package/dist/graph/logger.js +69 -0
- package/dist/graph/logger.js.map +1 -0
- package/dist/graph/node.d.ts +103 -0
- package/dist/graph/node.d.ts.map +1 -0
- package/dist/graph/node.js +284 -0
- package/dist/graph/node.js.map +1 -0
- package/dist/graph/observer.d.ts +113 -0
- package/dist/graph/observer.d.ts.map +1 -0
- package/dist/graph/observer.js +199 -0
- package/dist/graph/observer.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +447 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +75 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts +17 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.js +30 -0
- package/dist/modules/agenda/adapters/node-cron/index.js.map +1 -0
- package/dist/modules/agenda/index.d.ts +63 -0
- package/dist/modules/agenda/index.d.ts.map +1 -0
- package/dist/modules/agenda/index.js +141 -0
- package/dist/modules/agenda/index.js.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts +29 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.js +58 -0
- package/dist/modules/embedding/adapters/ai/index.js.map +1 -0
- package/dist/modules/embedding/index.d.ts +36 -0
- package/dist/modules/embedding/index.d.ts.map +1 -0
- package/dist/modules/embedding/index.js +60 -0
- package/dist/modules/embedding/index.js.map +1 -0
- package/dist/modules/memory/adapters/in-memory/index.d.ts +120 -0
- package/dist/modules/memory/adapters/in-memory/index.d.ts.map +1 -0
- package/dist/modules/memory/adapters/in-memory/index.js +211 -0
- package/dist/modules/memory/adapters/in-memory/index.js.map +1 -0
- package/dist/modules/memory/adapters/meilisearch/index.d.ts +110 -0
- package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +1 -0
- package/dist/modules/memory/adapters/meilisearch/index.js +321 -0
- package/dist/modules/memory/adapters/meilisearch/index.js.map +1 -0
- package/dist/modules/memory/adapters/redis/index.d.ts +82 -0
- package/dist/modules/memory/adapters/redis/index.d.ts.map +1 -0
- package/dist/modules/memory/adapters/redis/index.js +159 -0
- package/dist/modules/memory/adapters/redis/index.js.map +1 -0
- package/dist/modules/memory/index.d.ts +67 -0
- package/dist/modules/memory/index.d.ts.map +1 -0
- package/dist/modules/memory/index.js +104 -0
- package/dist/modules/memory/index.js.map +1 -0
- package/dist/types/index.d.ts +166 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/generate-action-schema.d.ts +5 -0
- package/dist/utils/generate-action-schema.d.ts.map +1 -0
- package/dist/utils/generate-action-schema.js +44 -0
- package/dist/utils/generate-action-schema.js.map +1 -0
- package/dist/utils/header-builder.d.ts +12 -0
- package/dist/utils/header-builder.d.ts.map +1 -0
- package/dist/utils/header-builder.js +35 -0
- package/dist/utils/header-builder.js.map +1 -0
- package/graph/event-manager.ts +9 -2
- package/graph/node.ts +25 -63
- package/graph/observer.ts +17 -9
- package/package.json +5 -1
- package/test/graph/controller.test.ts +0 -0
- package/test/graph/event-manager.test.ts +72 -0
- package/test/graph/index.test.ts +41 -34
- package/test/graph/node.test.ts +197 -0
- package/tsconfig.json +13 -2
@@ -0,0 +1,157 @@
|
|
1
|
+
import { ZodSchema } from "zod";
|
2
|
+
import { GraphObservable } from "../interfaces";
|
3
|
+
import { GraphContext, GraphDefinition, Node } from "../types";
|
4
|
+
import { GraphObserver } from "./observer";
|
5
|
+
/**
|
6
|
+
* @module GraphFlow
|
7
|
+
* @description A flexible workflow engine that manages the execution of nodes in a graph-like structure.
|
8
|
+
*
|
9
|
+
* Key features:
|
10
|
+
* - Multiple branches support
|
11
|
+
* - Conditional branching (runs first matching condition, or all if none have conditions)
|
12
|
+
* - Event-driven nodes
|
13
|
+
* - Zod validation of context/inputs/outputs
|
14
|
+
* - Automatic retry on node failures
|
15
|
+
*
|
16
|
+
* @template T - Extends ZodSchema for type validation
|
17
|
+
*/
|
18
|
+
export declare class GraphFlow<T extends ZodSchema> {
|
19
|
+
name: string;
|
20
|
+
private context;
|
21
|
+
validator?: T;
|
22
|
+
private eventEmitter;
|
23
|
+
private globalErrorHandler?;
|
24
|
+
private graphEvents?;
|
25
|
+
private entryNode?;
|
26
|
+
private verbose;
|
27
|
+
nodes: Map<string, Node<T, any>>;
|
28
|
+
private eventSubject;
|
29
|
+
private stateSubject;
|
30
|
+
private destroySubject;
|
31
|
+
observer: GraphObserver<T>;
|
32
|
+
private logger;
|
33
|
+
private eventManager;
|
34
|
+
private nodeExecutor;
|
35
|
+
/**
|
36
|
+
* Creates a new instance of GraphFlow
|
37
|
+
* @param {string} name - The name of the graph flow
|
38
|
+
* @param {GraphDefinition<T>} config - Configuration object containing nodes, schema, context, and error handlers
|
39
|
+
* @param {Object} options - Optional options for the graph flow
|
40
|
+
*/
|
41
|
+
constructor(name: string, config: GraphDefinition<T>, options?: {
|
42
|
+
verbose?: boolean;
|
43
|
+
});
|
44
|
+
/**
|
45
|
+
* Sets up event listeners for node-based events
|
46
|
+
* @private
|
47
|
+
* @description Attaches all node-based event triggers while preserving external listeners
|
48
|
+
*/
|
49
|
+
private setupEventStreams;
|
50
|
+
/**
|
51
|
+
* Sets up event listeners for node-based events
|
52
|
+
* @private
|
53
|
+
* @description Attaches all node-based event triggers while preserving external listeners
|
54
|
+
*/
|
55
|
+
private setupEventListeners;
|
56
|
+
/**
|
57
|
+
* Sets up event listeners for graph-based events
|
58
|
+
* @private
|
59
|
+
* @description Attaches all graph-based event triggers
|
60
|
+
*/
|
61
|
+
private setupGraphEventListeners;
|
62
|
+
/**
|
63
|
+
* Executes a specific node in the graph
|
64
|
+
* @private
|
65
|
+
* @param {string} nodeName - Name of the node to execute
|
66
|
+
* @param {GraphContext<T>} context - Current execution context
|
67
|
+
* @param {any} inputs - Input parameters for the node
|
68
|
+
* @param {boolean} triggeredByEvent - Whether the execution was triggered by an event
|
69
|
+
* @returns {Promise<void>}
|
70
|
+
*/
|
71
|
+
private executeNode;
|
72
|
+
private addLog;
|
73
|
+
getLogs(): string[];
|
74
|
+
clearLogs(): void;
|
75
|
+
/**
|
76
|
+
* Get the observer instance for monitoring graph state and events
|
77
|
+
*/
|
78
|
+
observe(options?: {
|
79
|
+
debounce?: number;
|
80
|
+
delay?: number;
|
81
|
+
stream?: boolean;
|
82
|
+
properties?: (keyof GraphContext<T> extends string ? keyof GraphContext<T> : never)[];
|
83
|
+
onStreamLetter?: (data: {
|
84
|
+
letter: string;
|
85
|
+
property: string;
|
86
|
+
}) => void;
|
87
|
+
onStreamComplete?: () => void;
|
88
|
+
}): GraphObservable<T>;
|
89
|
+
/**
|
90
|
+
* Enable or disable verbose logging
|
91
|
+
* @param {boolean} enabled - Whether to enable verbose logging
|
92
|
+
*/
|
93
|
+
setVerbose(enabled: boolean): void;
|
94
|
+
/**
|
95
|
+
* Get current verbose setting
|
96
|
+
* @returns {boolean} Current verbose setting
|
97
|
+
*/
|
98
|
+
isVerbose(): boolean;
|
99
|
+
/**
|
100
|
+
* Executes the graph flow starting from a specific node
|
101
|
+
* @param {string} startNode - Name of the node to start execution from
|
102
|
+
* @param {Partial<GraphContext<T>>} inputContext - Optional partial context to merge with current context
|
103
|
+
* @param {any} inputParams - Optional input parameters for the start node
|
104
|
+
* @returns {Promise<GraphContext<T>>} Final context after execution
|
105
|
+
*/
|
106
|
+
execute(startNode: string, inputParams?: any, inputContext?: Partial<GraphContext<T>>): Promise<GraphContext<T>>;
|
107
|
+
/**
|
108
|
+
* Emits an event to trigger event-based nodes
|
109
|
+
* @param {string} eventName - Name of the event to emit
|
110
|
+
* @param {Partial<GraphContext<T>>} data - Optional data to merge with context
|
111
|
+
* @returns {Promise<void>}
|
112
|
+
*/
|
113
|
+
emit(eventName: string, data?: Partial<GraphContext<T>>): Promise<void>;
|
114
|
+
/**
|
115
|
+
* Registers an event handler
|
116
|
+
* @param {string} eventName - Name of the event to listen for
|
117
|
+
* @param {Function} handler - Handler function to execute when event is emitted
|
118
|
+
*/
|
119
|
+
on(eventName: string, handler: (...args: any[]) => void): void;
|
120
|
+
/**
|
121
|
+
* Updates the graph definition with new configuration
|
122
|
+
* @param {GraphDefinition<T>} definition - New graph definition
|
123
|
+
*/
|
124
|
+
load(definition: GraphDefinition<T>): void;
|
125
|
+
/**
|
126
|
+
* Gets a copy of the current context
|
127
|
+
* @returns {GraphContext<T>} A deep copy of the current context
|
128
|
+
*/
|
129
|
+
getContext(): GraphContext<T>;
|
130
|
+
/**
|
131
|
+
* Logs a message with optional data
|
132
|
+
* @param {string} message - Message to log
|
133
|
+
* @param {any} data - Optional data to log
|
134
|
+
*/
|
135
|
+
log(message: string, data?: any): void;
|
136
|
+
/**
|
137
|
+
* Adds a new node to the graph
|
138
|
+
* @param {Node<T>} node - Node to add
|
139
|
+
* @throws {Error} If node with same name already exists
|
140
|
+
*/
|
141
|
+
addNode(node: Node<T, any>): void;
|
142
|
+
/**
|
143
|
+
* Removes a node from the graph
|
144
|
+
* @param {string} nodeName - Name of the node to remove
|
145
|
+
*/
|
146
|
+
removeNode(nodeName: string): void;
|
147
|
+
/**
|
148
|
+
* Returns all nodes in the graph
|
149
|
+
* @returns {Node<T>[]} Array of all nodes
|
150
|
+
*/
|
151
|
+
getNodes(): Node<T, any>[];
|
152
|
+
/**
|
153
|
+
* Cleanup resources
|
154
|
+
*/
|
155
|
+
destroy(): void;
|
156
|
+
}
|
157
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../graph/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,eAAe,EAAiB,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAc,IAAI,EAAE,MAAM,UAAU,CAAC;AAI3E,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,qBAAa,SAAS,CAAC,CAAC,SAAS,SAAS;IA0B/B,IAAI,EAAE,MAAM;IAzBrB,OAAO,CAAC,OAAO,CAAkB;IAC1B,SAAS,CAAC,EAAE,CAAC,CAAC;IACrB,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,kBAAkB,CAAC,CAAmD;IAC9E,OAAO,CAAC,WAAW,CAAC,CAAW;IAC/B,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAkB;IAC1B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAExC,OAAO,CAAC,YAAY,CAAyC;IAC7D,OAAO,CAAC,YAAY,CAAmC;IACvD,OAAO,CAAC,cAAc,CAAgC;IAE/C,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAClC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,YAAY,CAAuB;IAC3C,OA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I,CACf,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;IAUhB;;;;OAIG;IACI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAIrE;;;OAGG;IACI,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI;IAiDjD;;;OAGG;IACI,UAAU,IAAI,YAAY,CAAC,CAAC,CAAC;IAIpC;;;;OAIG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAI7C;;;;OAIG;IACI,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI;IAKxC;;;OAGG;IACI,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKzC;;;OAGG;IACI,QAAQ,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;IAIjC;;OAEG;IACI,OAAO,IAAI,IAAI;CAMvB"}
|
@@ -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;;;;;;;;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,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,E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