@ai.ntellect/core 0.7.7 → 1.0.0

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 (111) hide show
  1. package/README.md +158 -81
  2. package/index.ts +462 -22
  3. package/package copy.json +21 -0
  4. package/package.json +9 -44
  5. package/tsconfig.json +108 -22
  6. package/types.ts +62 -0
  7. package/utils/executor.ts +42 -0
  8. package/.mocharc.json +0 -5
  9. package/dist/graph/controller.d.ts +0 -31
  10. package/dist/graph/controller.d.ts.map +0 -1
  11. package/dist/graph/controller.js +0 -71
  12. package/dist/graph/controller.js.map +0 -1
  13. package/dist/graph/event-manager.d.ts +0 -92
  14. package/dist/graph/event-manager.d.ts.map +0 -1
  15. package/dist/graph/event-manager.js +0 -244
  16. package/dist/graph/event-manager.js.map +0 -1
  17. package/dist/graph/index.d.ts +0 -159
  18. package/dist/graph/index.d.ts.map +0 -1
  19. package/dist/graph/index.js +0 -303
  20. package/dist/graph/index.js.map +0 -1
  21. package/dist/graph/logger.d.ts +0 -46
  22. package/dist/graph/logger.d.ts.map +0 -1
  23. package/dist/graph/logger.js +0 -69
  24. package/dist/graph/logger.js.map +0 -1
  25. package/dist/graph/node.d.ts +0 -92
  26. package/dist/graph/node.d.ts.map +0 -1
  27. package/dist/graph/node.js +0 -249
  28. package/dist/graph/node.js.map +0 -1
  29. package/dist/graph/observer.d.ts +0 -113
  30. package/dist/graph/observer.d.ts.map +0 -1
  31. package/dist/graph/observer.js +0 -198
  32. package/dist/graph/observer.js.map +0 -1
  33. package/dist/index.d.ts +0 -26
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/index.js +0 -42
  36. package/dist/index.js.map +0 -1
  37. package/dist/interfaces/index.d.ts +0 -447
  38. package/dist/interfaces/index.d.ts.map +0 -1
  39. package/dist/interfaces/index.js +0 -75
  40. package/dist/interfaces/index.js.map +0 -1
  41. package/dist/modules/agenda/adapters/node-cron/index.d.ts +0 -17
  42. package/dist/modules/agenda/adapters/node-cron/index.d.ts.map +0 -1
  43. package/dist/modules/agenda/adapters/node-cron/index.js +0 -30
  44. package/dist/modules/agenda/adapters/node-cron/index.js.map +0 -1
  45. package/dist/modules/agenda/index.d.ts +0 -63
  46. package/dist/modules/agenda/index.d.ts.map +0 -1
  47. package/dist/modules/agenda/index.js +0 -141
  48. package/dist/modules/agenda/index.js.map +0 -1
  49. package/dist/modules/embedding/adapters/ai/index.d.ts +0 -29
  50. package/dist/modules/embedding/adapters/ai/index.d.ts.map +0 -1
  51. package/dist/modules/embedding/adapters/ai/index.js +0 -58
  52. package/dist/modules/embedding/adapters/ai/index.js.map +0 -1
  53. package/dist/modules/embedding/index.d.ts +0 -36
  54. package/dist/modules/embedding/index.d.ts.map +0 -1
  55. package/dist/modules/embedding/index.js +0 -60
  56. package/dist/modules/embedding/index.js.map +0 -1
  57. package/dist/modules/memory/adapters/in-memory/index.d.ts +0 -120
  58. package/dist/modules/memory/adapters/in-memory/index.d.ts.map +0 -1
  59. package/dist/modules/memory/adapters/in-memory/index.js +0 -211
  60. package/dist/modules/memory/adapters/in-memory/index.js.map +0 -1
  61. package/dist/modules/memory/adapters/meilisearch/index.d.ts +0 -110
  62. package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +0 -1
  63. package/dist/modules/memory/adapters/meilisearch/index.js +0 -321
  64. package/dist/modules/memory/adapters/meilisearch/index.js.map +0 -1
  65. package/dist/modules/memory/adapters/redis/index.d.ts +0 -82
  66. package/dist/modules/memory/adapters/redis/index.d.ts.map +0 -1
  67. package/dist/modules/memory/adapters/redis/index.js +0 -159
  68. package/dist/modules/memory/adapters/redis/index.js.map +0 -1
  69. package/dist/modules/memory/index.d.ts +0 -67
  70. package/dist/modules/memory/index.d.ts.map +0 -1
  71. package/dist/modules/memory/index.js +0 -104
  72. package/dist/modules/memory/index.js.map +0 -1
  73. package/dist/types/index.d.ts +0 -166
  74. package/dist/types/index.d.ts.map +0 -1
  75. package/dist/types/index.js +0 -3
  76. package/dist/types/index.js.map +0 -1
  77. package/dist/utils/generate-action-schema.d.ts +0 -5
  78. package/dist/utils/generate-action-schema.d.ts.map +0 -1
  79. package/dist/utils/generate-action-schema.js +0 -44
  80. package/dist/utils/generate-action-schema.js.map +0 -1
  81. package/dist/utils/header-builder.d.ts +0 -12
  82. package/dist/utils/header-builder.d.ts.map +0 -1
  83. package/dist/utils/header-builder.js +0 -35
  84. package/dist/utils/header-builder.js.map +0 -1
  85. package/graph/controller.ts +0 -74
  86. package/graph/event-manager.ts +0 -295
  87. package/graph/index.ts +0 -397
  88. package/graph/logger.ts +0 -70
  89. package/graph/node.ts +0 -305
  90. package/graph/observer.ts +0 -368
  91. package/interfaces/index.ts +0 -545
  92. package/modules/agenda/adapters/node-cron/index.ts +0 -25
  93. package/modules/agenda/index.ts +0 -146
  94. package/modules/embedding/adapters/ai/index.ts +0 -42
  95. package/modules/embedding/index.ts +0 -45
  96. package/modules/memory/adapters/in-memory/index.ts +0 -207
  97. package/modules/memory/adapters/meilisearch/index.ts +0 -361
  98. package/modules/memory/adapters/redis/index.ts +0 -164
  99. package/modules/memory/index.ts +0 -93
  100. package/test/graph/controller.test.ts +0 -187
  101. package/test/graph/event-manager.test.ts +0 -72
  102. package/test/graph/index.test.ts +0 -768
  103. package/test/graph/node.test.ts +0 -510
  104. package/test/graph/observer.test.ts +0 -398
  105. package/test/modules/agenda/node-cron.test.ts +0 -307
  106. package/test/modules/memory/adapters/in-memory.test.ts +0 -153
  107. package/test/modules/memory/adapters/meilisearch.test.ts +0 -287
  108. package/test/modules/memory/base.test.ts +0 -230
  109. package/types/index.ts +0 -184
  110. package/utils/generate-action-schema.ts +0 -46
  111. package/utils/header-builder.ts +0 -40
package/tsconfig.json CHANGED
@@ -1,26 +1,112 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2016",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "declarationMap": true,
7
- "sourceMap": true,
8
- "esModuleInterop": true,
9
- "forceConsistentCasingInFileNames": true,
10
- "strict": true,
11
- "skipLibCheck": true,
12
- "baseUrl": ".",
13
3
  "outDir": "./dist",
14
- "types": ["node", "mocha"],
15
- "resolveJsonModule": true
16
- },
17
- "include": [
18
- "index.ts",
19
- "modules/**/*",
20
- "graph/**/*",
21
- "types/**/*",
22
- "interfaces/**/*",
23
- "utils/**/*"
24
- ],
25
- "exclude": ["node_modules", "dist", "test", "examples"]
4
+ /* Visit https://aka.ms/tsconfig to read more about this file */
5
+
6
+ /* Projects */
7
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
8
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
9
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
10
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
11
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
12
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
13
+
14
+ /* Language and Environment */
15
+ "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
16
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
17
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
18
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
19
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
20
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
21
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
22
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
23
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
24
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
25
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
26
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
27
+
28
+ /* Modules */
29
+ "module": "commonjs" /* Specify what module code is generated. */,
30
+ // "rootDir": "./", /* Specify the root folder within your source files. */
31
+ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
32
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
33
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
34
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
35
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
36
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
37
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
38
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
39
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
40
+ // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
41
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
42
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
43
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
44
+ // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
45
+ // "resolveJsonModule": true, /* Enable importing .json files. */
46
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
47
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
48
+
49
+ /* JavaScript Support */
50
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
51
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
52
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
53
+
54
+ /* Emit */
55
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
56
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
57
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
58
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
59
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
60
+ // "noEmit": true, /* Disable emitting files from a compilation. */
61
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
62
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
63
+ // "removeComments": true, /* Disable emitting comments. */
64
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
65
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
66
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
67
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
68
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
69
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
70
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
71
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
72
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
73
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
74
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
75
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
76
+
77
+ /* Interop Constraints */
78
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
79
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
80
+ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
81
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
82
+ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
83
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
84
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
85
+
86
+ /* Type Checking */
87
+ "strict": true /* Enable all strict type-checking options. */,
88
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
89
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
90
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
91
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
92
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
93
+ // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
94
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
95
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
96
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
97
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
98
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
99
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
100
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
101
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
102
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
103
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
104
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
105
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
106
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
107
+
108
+ /* Completeness */
109
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
110
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
111
+ }
26
112
  }
package/types.ts ADDED
@@ -0,0 +1,62 @@
1
+ export interface SharedState<T> {
2
+ messages?: { [key: string]: any }[]; // Historique des interactions
3
+ context: T;
4
+ }
5
+
6
+ export function mergeState<T>(
7
+ current: SharedState<T>,
8
+ updates: Partial<SharedState<T>>
9
+ ): SharedState<T> {
10
+ const uniqueMessages = new Map(
11
+ [...(current.messages || []), ...(updates.messages || [])].map((msg) => [
12
+ JSON.stringify(msg),
13
+ msg,
14
+ ])
15
+ );
16
+ return {
17
+ ...current,
18
+ context: { ...current.context, ...updates.context },
19
+ messages: Array.from(uniqueMessages.values()), // Messages uniques
20
+ };
21
+ }
22
+ export interface RetryConfig {
23
+ maxRetries: number;
24
+ retryDelay: number;
25
+ shouldRetry?: (error: Error) => boolean;
26
+ }
27
+
28
+ export interface Node<T> {
29
+ name: string;
30
+ description?: string;
31
+ execute: (state: SharedState<T>) => Promise<Partial<SharedState<T>>>;
32
+ condition?: (state: SharedState<T>) => boolean;
33
+ next?: string[];
34
+ events?: string[];
35
+ retry?: RetryConfig;
36
+ }
37
+
38
+ export interface Persistence<T> {
39
+ saveState(
40
+ graphName: string,
41
+ state: SharedState<T>,
42
+ currentNode: string
43
+ ): Promise<void>;
44
+ loadState(
45
+ graphName: string
46
+ ): Promise<{ state: SharedState<T>; currentNode: string } | null>;
47
+ }
48
+
49
+ export interface RealTimeNotifier {
50
+ notify(event: string, data: any): void;
51
+ }
52
+
53
+ export interface WorkflowDefinition<T> {
54
+ name: string;
55
+ nodes: {
56
+ [key: string]: Node<T> & {
57
+ condition?: (state: SharedState<T>) => boolean;
58
+ next?: string[];
59
+ };
60
+ };
61
+ entryNode: string;
62
+ }
@@ -0,0 +1,42 @@
1
+ import { Workflow } from "..";
2
+
3
+ export class Executor {
4
+ private workflows: Record<string, Workflow<any>>;
5
+
6
+ constructor() {
7
+ this.workflows = {};
8
+ }
9
+
10
+ addWorkflow(workflowName: string, workflowInstance: Workflow<any>) {
11
+ this.workflows[workflowName] = workflowInstance;
12
+ }
13
+
14
+ async executeWorkflowsInParallel(
15
+ workflowNames: string[],
16
+ initialState: any,
17
+ concurrencyLimit: number = 5
18
+ ) {
19
+ console.log(
20
+ `\n🚀 Starting parallel execution of workflows: ${workflowNames.join(
21
+ ", "
22
+ )}`
23
+ );
24
+
25
+ const workflowPromises = workflowNames.map(async (workflowName) => {
26
+ const workflow = this.workflows[workflowName];
27
+ if (!workflow) {
28
+ console.error(`❌ Workflow not found: ${workflowName}`);
29
+ return;
30
+ }
31
+
32
+ console.log(`➡️ Starting execution of workflow: ${workflowName}`);
33
+ const nodeNames = Array.from(workflow.nodes.keys());
34
+ await workflow.executeParallel(initialState, nodeNames, concurrencyLimit);
35
+ console.log(`✔️ Workflow "${workflowName}" completed.`);
36
+ });
37
+
38
+ await Promise.all(workflowPromises);
39
+
40
+ console.log("\n✅ All workflows executed successfully.");
41
+ }
42
+ }
package/.mocharc.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extension": ["ts"],
3
- "require": ["./node_modules/ts-node/register"],
4
- "timeout": 5000
5
- }
@@ -1,31 +0,0 @@
1
- import { ZodSchema } from "zod";
2
- import { GraphContext } from "../types";
3
- import { GraphFlow } from "./index";
4
- import { NodeParams } from "./node";
5
- /**
6
- * Controller class for managing the execution of graph flows
7
- * Handles both sequential and parallel execution of multiple graphs
8
- */
9
- export declare class GraphController {
10
- /**
11
- * Executes multiple graphs sequentially
12
- * @param graphs - Array of GraphFlow instances to execute
13
- * @param startNodes - Array of starting node identifiers for each graph
14
- * @param params - Optional array of node parameters for each graph
15
- * @returns Map containing results of each graph execution, keyed by graph name and index
16
- * @template T - Zod schema type for graph context validation
17
- */
18
- static executeSequential<T extends ZodSchema>(graphs: GraphFlow<T>[], startNodes: string[], params?: NodeParams[]): Promise<any[]>;
19
- private static executeGraph;
20
- /**
21
- * Executes multiple graphs in parallel with optional concurrency control
22
- * @param graphs - Array of GraphFlow instances to execute
23
- * @param startNodes - Array of starting node identifiers for each graph
24
- * @param concurrency - Optional limit on number of concurrent graph executions
25
- * @param params - Optional array of node parameters for each graph
26
- * @returns Map containing results of each graph execution, keyed by graph name
27
- * @template T - Zod schema type for graph context validation
28
- */
29
- static executeParallel<T extends ZodSchema>(graphs: GraphFlow<T>[], startNodes: string[], concurrency: number, params?: NodeParams[]): Promise<GraphContext<T>[]>;
30
- }
31
- //# sourceMappingURL=controller.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../graph/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;;GAGG;AACH,qBAAa,eAAe;IAC1B;;;;;;;OAOG;WACU,iBAAiB,CAAC,CAAC,SAAS,SAAS,EAChD,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,EACtB,UAAU,EAAE,MAAM,EAAE,EACpB,MAAM,CAAC,EAAE,UAAU,EAAE,GACpB,OAAO,CAAC,GAAG,EAAE,CAAC;mBASI,YAAY;IAYjC;;;;;;;;OAQG;WACU,eAAe,CAAC,CAAC,SAAS,SAAS,EAC9C,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,EACtB,UAAU,EAAE,MAAM,EAAE,EACpB,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,UAAU,EAAE,GACpB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;CAgB9B"}
@@ -1,71 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GraphController = void 0;
13
- /**
14
- * Controller class for managing the execution of graph flows
15
- * Handles both sequential and parallel execution of multiple graphs
16
- */
17
- class GraphController {
18
- /**
19
- * Executes multiple graphs sequentially
20
- * @param graphs - Array of GraphFlow instances to execute
21
- * @param startNodes - Array of starting node identifiers for each graph
22
- * @param params - Optional array of node parameters for each graph
23
- * @returns Map containing results of each graph execution, keyed by graph name and index
24
- * @template T - Zod schema type for graph context validation
25
- */
26
- static executeSequential(graphs, startNodes, params) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const results = new Map();
29
- for (let i = 0; i < graphs.length; i++) {
30
- const result = yield graphs[i].execute(startNodes[i], params === null || params === void 0 ? void 0 : params[i]);
31
- results.set(`${graphs[i].name}-${i}`, result);
32
- }
33
- return Array.from(results.values());
34
- });
35
- }
36
- static executeGraph(graph, startNode, params) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- try {
39
- return yield graph.execute(startNode, params);
40
- }
41
- catch (error) {
42
- throw error;
43
- }
44
- });
45
- }
46
- /**
47
- * Executes multiple graphs in parallel with optional concurrency control
48
- * @param graphs - Array of GraphFlow instances to execute
49
- * @param startNodes - Array of starting node identifiers for each graph
50
- * @param concurrency - Optional limit on number of concurrent graph executions
51
- * @param params - Optional array of node parameters for each graph
52
- * @returns Map containing results of each graph execution, keyed by graph name
53
- * @template T - Zod schema type for graph context validation
54
- */
55
- static executeParallel(graphs, startNodes, concurrency, params) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const results = [];
58
- for (let i = 0; i < graphs.length; i += concurrency) {
59
- const batch = graphs.slice(i, i + concurrency);
60
- const batchResults = yield Promise.all(batch.map((graph, idx) => {
61
- const param = params === null || params === void 0 ? void 0 : params[i + idx];
62
- return this.executeGraph(graph, startNodes[i + idx], param);
63
- }));
64
- results.push(...batchResults);
65
- }
66
- return results;
67
- });
68
- }
69
- }
70
- exports.GraphController = GraphController;
71
- //# sourceMappingURL=controller.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../graph/controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA;;;GAGG;AACH,MAAa,eAAe;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAO,iBAAiB,CAC5B,MAAsB,EACtB,UAAoB,EACpB,MAAqB;;YAErB,MAAM,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;YACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACvC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,CAAC,CAAC,CAAC,CAAC;gBACnE,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACtC,CAAC;KAAA;IAEO,MAAM,CAAO,YAAY,CAC/B,KAAmB,EACnB,SAAiB,EACjB,MAAmB;;YAEnB,IAAI,CAAC;gBACH,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KAAA;IAED;;;;;;;;OAQG;IACH,MAAM,CAAO,eAAe,CAC1B,MAAsB,EACtB,UAAoB,EACpB,WAAmB,EACnB,MAAqB;;YAErB,MAAM,OAAO,GAAsB,EAAE,CAAC;YAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC;gBACpD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC;gBAC/C,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CACpC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;oBACvB,MAAM,KAAK,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,CAAC,GAAG,GAAG,CAAC,CAAC;oBAChC,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC9D,CAAC,CAAC,CACH,CAAC;gBACF,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;YAChC,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;CACF;AAhED,0CAgEC"}
@@ -1,92 +0,0 @@
1
- import { ZodSchema } from "zod";
2
- import { IEventEmitter } from "../interfaces";
3
- import { GraphContext, Node } from "../types";
4
- import { GraphNode } from "./node";
5
- /**
6
- * Manages event handling and routing for a graph
7
- * Coordinates event emission, listening, and execution of event-driven nodes
8
- * @template T - The Zod schema type for validation
9
- */
10
- export declare class GraphEventManager<T extends ZodSchema> {
11
- private eventEmitter;
12
- private nodes;
13
- private nodeExecutor?;
14
- private eventSubject;
15
- private nodeStreams;
16
- private context;
17
- private name;
18
- private graphEvents?;
19
- private entryNode?;
20
- private globalErrorHandler?;
21
- /**
22
- * Creates a new GraphEventManager instance
23
- * @param eventEmitter - The event emitter implementation to use
24
- * @param nodes - Map of all nodes in the graph
25
- * @param name - Name of the graph
26
- * @param context - Initial graph context
27
- * @param graphEvents - List of events the graph should listen to
28
- * @param entryNode - Name of the entry node for graph events
29
- * @param globalErrorHandler - Global error handling function
30
- * @param nodeExecutor - GraphNode instance for executing nodes
31
- */
32
- constructor(eventEmitter: IEventEmitter, nodes: Map<string, Node<T, any>>, name: string, context: GraphContext<T>, graphEvents?: string[], entryNode?: string, globalErrorHandler?: (error: Error, context: GraphContext<T>) => void, nodeExecutor?: GraphNode<T> | undefined);
33
- /**
34
- * Sets up event streams for all nodes that listen to events
35
- */
36
- setupEventStreams(): void;
37
- /**
38
- * Emits an event with optional payload and context
39
- * @param type - The type of event to emit
40
- * @param payload - Optional payload data
41
- * @param context - Optional graph context
42
- */
43
- emitEvent<P = any>(type: string, payload?: P, context?: GraphContext<T>): void;
44
- /**
45
- * Sets up event listeners for all nodes in the graph
46
- * Handles cleanup and re-registration of event listeners
47
- */
48
- setupEventListeners(): void;
49
- /**
50
- * Sets up listeners for graph-level events
51
- * Handles graph start, completion, and error events
52
- */
53
- setupGraphEventListeners(): void;
54
- /**
55
- * Waits for a set of events to occur within a timeout period
56
- * @param events - Array of event names to wait for
57
- * @param timeout - Maximum time to wait in milliseconds
58
- * @returns Promise that resolves with array of received events
59
- * @throws Error if timeout occurs before all events are received
60
- */
61
- waitForEvents(events: string[], timeout?: number): Promise<any[]>;
62
- /**
63
- * Registers an event handler
64
- * @param eventName - Name of the event to listen for
65
- * @param handler - Function to handle the event
66
- */
67
- on(eventName: string, handler: (...args: any[]) => void): void;
68
- /**
69
- * Emits an event through the event emitter
70
- * @param eventName - Name of the event to emit
71
- * @param data - Optional data to include with the event
72
- */
73
- emit(eventName: string, data?: any): void;
74
- /**
75
- * Creates a new context object by cloning the current context
76
- * @returns A new graph context instance
77
- * @private
78
- */
79
- private createNewContext;
80
- /**
81
- * Executes a node with the given parameters
82
- * @param nodeName - Name of the node to execute
83
- * @param context - Graph context for execution
84
- * @param inputs - Input data for the node
85
- * @param triggeredByEvent - Whether execution was triggered by an event
86
- * @returns Promise that resolves when execution is complete
87
- * @throws Error if nodeExecutor is not initialized
88
- * @private
89
- */
90
- private executeNode;
91
- }
92
- //# sourceMappingURL=event-manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-manager.d.ts","sourceRoot":"","sources":["../../graph/event-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAc,IAAI,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;;;GAIG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,SAAS;IAqB9C,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,YAAY,CAAC;IA3BvB,OAAO,CAAC,YAAY,CAAyC;IAC7D,OAAO,CAAC,WAAW,CAAqD;IACxE,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,WAAW,CAAC,CAAW;IAC/B,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,kBAAkB,CAAC,CAAmD;IAE9E;;;;;;;;;;OAUG;gBAEO,YAAY,EAAE,aAAa,EAC3B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EACxC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,SAAS,CAAC,EAAE,MAAM,EAClB,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,EAC7D,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,YAAA;IAUrC;;OAEG;IACI,iBAAiB,IAAI,IAAI;IAWhC;;;;;OAKG;IACI,SAAS,CAAC,CAAC,GAAG,GAAG,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,CAAC,EACX,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,IAAI;IAaP;;;OAGG;IACH,mBAAmB,IAAI,IAAI;IAiD3B;;;OAGG;IACH,wBAAwB,IAAI,IAAI;IAuChC;;;;;;OAMG;IACG,aAAa,CACjB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,GAAE,MAAc,GACtB,OAAO,CAAC,GAAG,EAAE,CAAC;IAiDjB;;;;OAIG;IACH,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAI9D;;;;OAIG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAIzC;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;;;;;;;;OASG;YACW,WAAW;CAgB1B"}