@ai.ntellect/core 0.5.0 → 0.6.1

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 (131) hide show
  1. package/.mocharc.json +1 -1
  2. package/README.md +311 -272
  3. package/create-llm-to-select-multiple-graph copy.ts +243 -0
  4. package/create-llm-to-select-multiple-graph.ts +148 -0
  5. package/dist/graph/controller.js +63 -0
  6. package/dist/graph/engine.js +563 -0
  7. package/dist/index.js +6 -6
  8. package/dist/memory/adapters/meilisearch/index.js +249 -0
  9. package/dist/memory/adapters/redis/index.js +96 -0
  10. package/dist/memory/index.js +9 -0
  11. package/dist/services/agenda.js +115 -0
  12. package/dist/services/embedding.js +40 -0
  13. package/dist/services/queue.js +99 -103
  14. package/dist/test/graph/controller.test.js +170 -0
  15. package/dist/test/graph/engine.test.js +465 -0
  16. package/dist/test/memory/adapters/meilisearch.test.js +250 -0
  17. package/dist/test/memory/adapters/redis.test.js +143 -0
  18. package/dist/test/memory/base.test.js +209 -0
  19. package/dist/test/services/agenda.test.js +230 -0
  20. package/dist/test/services/queue.test.js +258 -0
  21. package/dist/types/index.js +2 -0
  22. package/dist/utils/generate-object.js +32 -11
  23. package/dist/utils/inject-actions.js +2 -2
  24. package/dist/utils/queue-item-transformer.js +2 -2
  25. package/dist/utils/state-manager.js +20 -0
  26. package/graph/controller.ts +64 -0
  27. package/graph/engine.ts +790 -0
  28. package/index copy.ts +81 -0
  29. package/index.ts +7 -7
  30. package/interfaces/index.ts +119 -0
  31. package/memory/adapters/meilisearch/index.ts +286 -0
  32. package/memory/adapters/redis/index.ts +103 -0
  33. package/memory/index.ts +22 -0
  34. package/package.json +7 -2
  35. package/services/agenda.ts +48 -43
  36. package/services/embedding.ts +26 -0
  37. package/services/queue.ts +2 -29
  38. package/test/.env.test +4 -0
  39. package/test/graph/controller.test.ts +186 -0
  40. package/test/graph/engine.test.ts +546 -0
  41. package/test/memory/adapters/meilisearch.test.ts +297 -0
  42. package/test/memory/adapters/redis.test.ts +160 -0
  43. package/test/memory/base.test.ts +229 -0
  44. package/test/services/agenda.test.ts +280 -0
  45. package/test/services/queue.test.ts +286 -44
  46. package/tsconfig.json +10 -10
  47. package/types/index.ts +278 -0
  48. package/utils/queue-item-transformer.ts +8 -11
  49. package/utils/setup-graphs.ts +45 -0
  50. package/utils/stringifiy-zod-schema.ts +45 -0
  51. package/.nvmrc +0 -1
  52. package/README.FR.md +0 -916
  53. package/agent/index.ts +0 -151
  54. package/agent/workflow/conditions.ts +0 -16
  55. package/agent/workflow/handlers/interpreter.handler.ts +0 -48
  56. package/agent/workflow/handlers/memory.handler.ts +0 -106
  57. package/agent/workflow/handlers/orchestrator.handler.ts +0 -23
  58. package/agent/workflow/handlers/queue.handler.ts +0 -34
  59. package/agent/workflow/handlers/scheduler.handler.ts +0 -61
  60. package/agent/workflow/index.ts +0 -62
  61. package/dist/agent/index.d.ts +0 -38
  62. package/dist/agent/index.js +0 -143
  63. package/dist/agent/tools/get-rss.d.ts +0 -16
  64. package/dist/agent/tools/get-rss.js +0 -62
  65. package/dist/bull.d.ts +0 -1
  66. package/dist/bull.js +0 -9
  67. package/dist/examples/index.d.ts +0 -2
  68. package/dist/examples/index.js +0 -89
  69. package/dist/index.d.ts +0 -7
  70. package/dist/llm/interpreter/context.d.ts +0 -15
  71. package/dist/llm/interpreter/context.js +0 -89
  72. package/dist/llm/interpreter/index.d.ts +0 -21
  73. package/dist/llm/interpreter/index.js +0 -87
  74. package/dist/llm/memory-manager/context.d.ts +0 -2
  75. package/dist/llm/memory-manager/context.js +0 -22
  76. package/dist/llm/memory-manager/index.d.ts +0 -17
  77. package/dist/llm/memory-manager/index.js +0 -107
  78. package/dist/llm/orchestrator/context.d.ts +0 -2
  79. package/dist/llm/orchestrator/context.js +0 -23
  80. package/dist/llm/orchestrator/index.d.ts +0 -44
  81. package/dist/llm/orchestrator/index.js +0 -139
  82. package/dist/llm/orchestrator/types.d.ts +0 -12
  83. package/dist/memory/cache.d.ts +0 -22
  84. package/dist/memory/cache.js +0 -165
  85. package/dist/memory/persistent.d.ts +0 -57
  86. package/dist/memory/persistent.js +0 -189
  87. package/dist/services/queue.d.ts +0 -13
  88. package/dist/services/redis-cache.d.ts +0 -37
  89. package/dist/services/redis-cache.js +0 -93
  90. package/dist/services/scheduler.d.ts +0 -40
  91. package/dist/services/scheduler.js +0 -99
  92. package/dist/services/telegram-monitor.d.ts +0 -0
  93. package/dist/services/telegram-monitor.js +0 -118
  94. package/dist/t.d.ts +0 -46
  95. package/dist/t.js +0 -102
  96. package/dist/test.d.ts +0 -0
  97. package/dist/test.js +0 -438
  98. package/dist/types.d.ts +0 -258
  99. package/dist/types.js +0 -22
  100. package/dist/utils/generate-object.d.ts +0 -12
  101. package/dist/utils/header-builder.d.ts +0 -11
  102. package/dist/utils/inject-actions.d.ts +0 -2
  103. package/dist/utils/queue-item-transformer.d.ts +0 -7
  104. package/dist/utils/sanitize-results.d.ts +0 -17
  105. package/dist/utils/schema-generator.d.ts +0 -16
  106. package/examples/actions/get-rss.ts +0 -71
  107. package/examples/index.ts +0 -98
  108. package/index.html +0 -42
  109. package/llm/dynamic-condition/example.ts +0 -36
  110. package/llm/dynamic-condition/index.ts +0 -108
  111. package/llm/interpreter/context.ts +0 -94
  112. package/llm/interpreter/index.ts +0 -140
  113. package/llm/memory-manager/context.ts +0 -19
  114. package/llm/memory-manager/index.ts +0 -115
  115. package/llm/orchestrator/context.ts +0 -19
  116. package/llm/orchestrator/index.ts +0 -192
  117. package/llm/orchestrator/types.ts +0 -14
  118. package/memory/cache.ts +0 -221
  119. package/memory/persistent.ts +0 -265
  120. package/script.js +0 -167
  121. package/services/cache.ts +0 -298
  122. package/services/telegram-monitor.ts +0 -138
  123. package/services/workflow.ts +0 -491
  124. package/t.py +0 -79
  125. package/t.ts +0 -25
  126. package/test/llm/orchestrator.test.ts +0 -47
  127. package/test/llm/synthesizer.test.ts +0 -31
  128. package/types.ts +0 -367
  129. package/utils/schema-generator.ts +0 -73
  130. package/utils/state-manager.ts +0 -25
  131. /package/dist/{llm/orchestrator/types.js → interfaces/index.js} +0 -0
@@ -1,7 +1,16 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActionQueueManager = void 0;
4
- class ActionQueueManager {
12
+ exports.Queue = void 0;
13
+ class Queue {
5
14
  constructor(actions, callbacks = {}) {
6
15
  this.queue = [];
7
16
  this.results = [];
@@ -9,78 +18,70 @@ class ActionQueueManager {
9
18
  this.actions = actions;
10
19
  this.callbacks = callbacks;
11
20
  }
12
- addToQueue(actions) {
21
+ add(actions) {
13
22
  if (Array.isArray(actions)) {
14
- console.log("\n📋 Adding actions to queue:");
15
- actions.forEach((action, index) => {
16
- console.log(` ${index + 1}. ${action.name}`);
17
- });
18
23
  this.queue.push(...actions);
19
24
  }
20
25
  else {
21
- console.log("\n📋 Adding single action to queue:", actions.name);
22
26
  this.queue.push(actions);
23
27
  }
24
28
  }
25
- async processQueue() {
26
- if (this.isProcessing) {
27
- console.log("\n⚠️ Queue is already being processed");
28
- return;
29
- }
30
- console.log("\n🔄 Starting queue processing");
31
- this.isProcessing = true;
32
- const actionPromises = [];
33
- for (const action of this.queue) {
34
- const actionConfig = this.actions.find((a) => a.name === action.name);
35
- if (actionConfig?.confirmation?.requireConfirmation) {
36
- console.log("\n🔒 Action requires confirmation:", action.name);
37
- const shouldProceed = await this.callbacks.onConfirmationRequired?.(actionConfig.confirmation.message ||
38
- `Do you want to proceed with action: ${action.name}?`);
39
- if (!shouldProceed) {
40
- console.log("❌ Action cancelled by user:", action.name);
41
- this.results.push({
29
+ execute() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ var _a, _b, _c, _d, _e;
32
+ if (this.isProcessing) {
33
+ return;
34
+ }
35
+ this.isProcessing = true;
36
+ const actionPromises = [];
37
+ for (const action of this.queue) {
38
+ const actionConfig = this.actions.find((a) => a.name === action.name);
39
+ if ((_a = actionConfig === null || actionConfig === void 0 ? void 0 : actionConfig.confirmation) === null || _a === void 0 ? void 0 : _a.requireConfirmation) {
40
+ const shouldProceed = yield ((_c = (_b = this.callbacks).onConfirmationRequired) === null || _c === void 0 ? void 0 : _c.call(_b, actionConfig.confirmation.message ||
41
+ `Do you want to proceed with action: ${action.name}?`));
42
+ if (!shouldProceed) {
43
+ this.results.push({
44
+ name: action.name,
45
+ parameters: this.formatArguments(action.parameters),
46
+ result: null,
47
+ error: "Action cancelled by user",
48
+ cancelled: true,
49
+ });
50
+ continue;
51
+ }
52
+ }
53
+ const parameters = this.formatArguments(action.parameters);
54
+ actionPromises.push(this.executeAction(action)
55
+ .then((result) => {
56
+ var _a, _b;
57
+ (_b = (_a = this.callbacks).onActionComplete) === null || _b === void 0 ? void 0 : _b.call(_a, result);
58
+ return result;
59
+ })
60
+ .catch((error) => {
61
+ var _a, _b;
62
+ const result = {
42
63
  name: action.name,
43
- parameters: this.formatArguments(action.parameters),
64
+ parameters,
44
65
  result: null,
45
- error: "Action cancelled by user",
46
- cancelled: true,
47
- });
48
- continue;
49
- }
50
- console.log("✅ Action confirmed by user");
66
+ error: error.message || "Unknown error occurred",
67
+ };
68
+ (_b = (_a = this.callbacks).onActionComplete) === null || _b === void 0 ? void 0 : _b.call(_a, result);
69
+ return result;
70
+ }));
51
71
  }
52
- const parameters = this.formatArguments(action.parameters);
53
- actionPromises.push(this.executeAction(action)
54
- .then((result) => {
55
- this.callbacks.onActionComplete?.(result);
56
- return result;
57
- })
58
- .catch((error) => {
59
- const result = {
60
- name: action.name,
61
- parameters,
62
- result: null,
63
- error: error.message || "Unknown error occurred",
64
- };
65
- this.callbacks.onActionComplete?.(result);
66
- return result;
67
- }));
68
- }
69
- try {
70
- console.log("\n⏳ Waiting for all actions to complete...");
71
- const results = await Promise.all(actionPromises);
72
- this.results.push(...results);
73
- this.queue = [];
74
- this.callbacks.onQueueComplete?.(this.results);
75
- this.isProcessing = false;
76
- console.log("\n✅ Queue processing completed successfully");
77
- return this.results;
78
- }
79
- catch (error) {
80
- this.isProcessing = false;
81
- console.error("\n❌ Unexpected error in queue processing:", error);
82
- throw error;
83
- }
72
+ try {
73
+ const results = yield Promise.all(actionPromises);
74
+ this.results.push(...results);
75
+ this.queue = [];
76
+ (_e = (_d = this.callbacks).onQueueComplete) === null || _e === void 0 ? void 0 : _e.call(_d, this.results);
77
+ this.isProcessing = false;
78
+ return this.results;
79
+ }
80
+ catch (error) {
81
+ this.isProcessing = false;
82
+ throw error;
83
+ }
84
+ });
84
85
  }
85
86
  formatArguments(args) {
86
87
  return args.reduce((acc, arg) => {
@@ -97,50 +98,45 @@ class ActionQueueManager {
97
98
  acc[arg.name] = arg.value;
98
99
  }
99
100
  }
100
- catch {
101
+ catch (_a) {
101
102
  // If JSON parsing fails, use the original value
102
103
  acc[arg.name] = arg.value;
103
104
  }
104
105
  return acc;
105
106
  }, {});
106
107
  }
107
- async executeAction(action) {
108
- console.log("\n🎯 Executing action:", action.name);
109
- this.callbacks.onActionStart?.(action);
110
- const actionConfig = this.actions.find((a) => a.name === action.name);
111
- if (!actionConfig) {
112
- console.error("❌ Action not found:", action.name);
113
- return {
114
- name: action.name,
115
- parameters: {},
116
- result: null,
117
- error: `Action '${action.name}' not found in actions list`,
118
- };
119
- }
120
- console.log("📝 Action parameters:", JSON.stringify(action.parameters, null, 2));
121
- const actionArgs = this.formatArguments(action.parameters);
122
- try {
123
- const result = await actionConfig.execute(actionArgs);
124
- const actionResult = {
125
- name: action.name,
126
- parameters: actionArgs,
127
- result,
128
- error: null,
129
- };
130
- console.log(`\n✨ Action "${action.name}" completed successfully`);
131
- return actionResult;
132
- }
133
- catch (error) {
134
- const actionResult = {
135
- name: action.name,
136
- parameters: actionArgs,
137
- result: null,
138
- error: error.message || "Unknown error occurred",
139
- };
140
- console.error(`\n❌ Action "${action.name}" failed:`, error);
141
- console.log("Failed action details:", JSON.stringify(actionResult, null, 2));
142
- return actionResult;
143
- }
108
+ executeAction(action) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ var _a, _b;
111
+ (_b = (_a = this.callbacks).onActionStart) === null || _b === void 0 ? void 0 : _b.call(_a, action);
112
+ const actionConfig = this.actions.find((a) => a.name === action.name);
113
+ if (!actionConfig) {
114
+ return {
115
+ name: action.name,
116
+ parameters: {},
117
+ result: null,
118
+ error: `Action '${action.name}' not found in actions list`,
119
+ };
120
+ }
121
+ const actionArgs = this.formatArguments(action.parameters);
122
+ try {
123
+ const result = yield actionConfig.execute(actionArgs);
124
+ return {
125
+ name: action.name,
126
+ parameters: actionArgs,
127
+ result,
128
+ error: null,
129
+ };
130
+ }
131
+ catch (error) {
132
+ return {
133
+ name: action.name,
134
+ parameters: actionArgs,
135
+ result: null,
136
+ error: error.message || "Unknown error occurred",
137
+ };
138
+ }
139
+ });
144
140
  }
145
141
  }
146
- exports.ActionQueueManager = ActionQueueManager;
142
+ exports.Queue = Queue;
@@ -0,0 +1,170 @@
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
+ const controller_1 = require("@/graph/controller");
13
+ const chai_1 = require("chai");
14
+ const zod_1 = require("zod");
15
+ describe("Controller", () => {
16
+ // Define test schema
17
+ const TestSchema = zod_1.z.object({
18
+ status: zod_1.z.string(),
19
+ count: zod_1.z.number(),
20
+ });
21
+ // Sample workflow definitions
22
+ const simpleWorkflow = {
23
+ name: "simple-workflow",
24
+ entryNode: "start",
25
+ nodes: {
26
+ start: {
27
+ name: "start",
28
+ execute: (_params, state) => __awaiter(void 0, void 0, void 0, function* () {
29
+ return ({
30
+ context: Object.assign(Object.assign({}, state.context), { status: "completed", count: state.context.count + 1 }),
31
+ });
32
+ }),
33
+ relationships: [],
34
+ },
35
+ },
36
+ schema: TestSchema,
37
+ };
38
+ const complexWorkflow = {
39
+ name: "complex-workflow",
40
+ entryNode: "first",
41
+ nodes: {
42
+ first: {
43
+ name: "first",
44
+ execute: (_params, state) => __awaiter(void 0, void 0, void 0, function* () {
45
+ return ({
46
+ context: Object.assign(Object.assign({}, state.context), { status: "step1", count: state.context.count + 2 }),
47
+ });
48
+ }),
49
+ relationships: [],
50
+ },
51
+ },
52
+ schema: TestSchema,
53
+ };
54
+ let controller;
55
+ beforeEach(() => {
56
+ controller = new controller_1.GraphController();
57
+ });
58
+ describe("Basic Execution", () => {
59
+ it("should execute a single workflow successfully", () => __awaiter(void 0, void 0, void 0, function* () {
60
+ const actions = [
61
+ {
62
+ name: "simple-workflow",
63
+ parameters: [
64
+ { name: "status", value: "initial" },
65
+ { name: "count", value: 0 },
66
+ ],
67
+ },
68
+ ];
69
+ const result = yield controller.run(actions, [simpleWorkflow]);
70
+ (0, chai_1.expect)(result.context).to.deep.equal({
71
+ status: "completed",
72
+ count: 1,
73
+ });
74
+ }));
75
+ it("should handle multiple workflows", () => __awaiter(void 0, void 0, void 0, function* () {
76
+ const actions = [
77
+ {
78
+ name: "complex-workflow",
79
+ parameters: [
80
+ { name: "status", value: "initial" },
81
+ { name: "count", value: 0 },
82
+ ],
83
+ },
84
+ ];
85
+ const result = yield controller.run(actions, [
86
+ simpleWorkflow,
87
+ complexWorkflow,
88
+ ]);
89
+ (0, chai_1.expect)(result.context).to.deep.equal({
90
+ status: "step1",
91
+ count: 2,
92
+ });
93
+ }));
94
+ });
95
+ describe("Error Handling", () => {
96
+ it("should throw error when no actions provided", () => __awaiter(void 0, void 0, void 0, function* () {
97
+ try {
98
+ yield controller.run([], [simpleWorkflow]);
99
+ chai_1.expect.fail("Should have thrown an error");
100
+ }
101
+ catch (error) {
102
+ (0, chai_1.expect)(error.message).to.equal("No actions provided");
103
+ }
104
+ }));
105
+ it("should throw error when workflow not found", () => __awaiter(void 0, void 0, void 0, function* () {
106
+ const actions = [
107
+ {
108
+ name: "non-existent-workflow",
109
+ parameters: [
110
+ { name: "status", value: "initial" },
111
+ { name: "count", value: 0 },
112
+ ],
113
+ },
114
+ ];
115
+ try {
116
+ yield controller.run(actions, [simpleWorkflow]);
117
+ chai_1.expect.fail("Should have thrown an error");
118
+ }
119
+ catch (error) {
120
+ (0, chai_1.expect)(error.message).to.equal("Graph not found: non-existent-workflow");
121
+ }
122
+ }));
123
+ });
124
+ describe("Parameter Handling", () => {
125
+ it("should correctly process workflow parameters", () => __awaiter(void 0, void 0, void 0, function* () {
126
+ const actions = [
127
+ {
128
+ name: "simple-workflow",
129
+ parameters: [
130
+ { name: "status", value: "custom-initial" },
131
+ { name: "count", value: 10 },
132
+ ],
133
+ },
134
+ ];
135
+ const result = yield controller.run(actions, [simpleWorkflow]);
136
+ (0, chai_1.expect)(result.context).to.deep.equal({
137
+ status: "completed",
138
+ count: 11,
139
+ });
140
+ }));
141
+ });
142
+ describe("Multiple Actions", () => {
143
+ it("should process the first action only", () => __awaiter(void 0, void 0, void 0, function* () {
144
+ const actions = [
145
+ {
146
+ name: "simple-workflow",
147
+ parameters: [
148
+ { name: "status", value: "initial" },
149
+ { name: "count", value: 0 },
150
+ ],
151
+ },
152
+ {
153
+ name: "complex-workflow",
154
+ parameters: [
155
+ { name: "status", value: "initial" },
156
+ { name: "count", value: 5 },
157
+ ],
158
+ },
159
+ ];
160
+ const result = yield controller.run(actions, [
161
+ simpleWorkflow,
162
+ complexWorkflow,
163
+ ]);
164
+ (0, chai_1.expect)(result.context).to.deep.equal({
165
+ status: "completed",
166
+ count: 1,
167
+ });
168
+ }));
169
+ });
170
+ });