@ai.ntellect/core 0.4.1 → 0.6.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 (125) hide show
  1. package/.mocharc.json +1 -1
  2. package/README.md +311 -272
  3. package/dist/graph/controller.js +63 -0
  4. package/dist/graph/engine.js +563 -0
  5. package/dist/index.js +6 -6
  6. package/dist/memory/adapters/meilisearch/index.js +249 -0
  7. package/dist/memory/adapters/redis/index.js +96 -0
  8. package/dist/memory/index.js +9 -0
  9. package/dist/services/agenda.js +115 -0
  10. package/dist/services/embedding.js +40 -0
  11. package/dist/services/queue.js +99 -103
  12. package/dist/test/graph/controller.test.js +170 -0
  13. package/dist/test/graph/engine.test.js +465 -0
  14. package/dist/test/memory/adapters/meilisearch.test.js +250 -0
  15. package/dist/test/memory/adapters/redis.test.js +143 -0
  16. package/dist/test/memory/base.test.js +209 -0
  17. package/dist/test/services/agenda.test.js +230 -0
  18. package/dist/test/services/queue.test.js +258 -0
  19. package/dist/types/index.js +2 -0
  20. package/dist/utils/generate-object.js +32 -11
  21. package/dist/utils/inject-actions.js +2 -2
  22. package/dist/utils/queue-item-transformer.js +2 -2
  23. package/dist/utils/state-manager.js +20 -0
  24. package/graph/controller.ts +60 -0
  25. package/graph/engine.ts +709 -0
  26. package/index.ts +7 -7
  27. package/interfaces/index.ts +119 -0
  28. package/memory/adapters/meilisearch/index.ts +286 -0
  29. package/memory/adapters/redis/index.ts +103 -0
  30. package/memory/index.ts +22 -0
  31. package/package.json +9 -2
  32. package/services/agenda.ts +118 -0
  33. package/services/embedding.ts +26 -0
  34. package/services/queue.ts +5 -32
  35. package/test/.env.test +4 -0
  36. package/test/graph/controller.test.ts +186 -0
  37. package/test/graph/engine.test.ts +563 -0
  38. package/test/memory/adapters/meilisearch.test.ts +297 -0
  39. package/test/memory/adapters/redis.test.ts +160 -0
  40. package/test/memory/base.test.ts +229 -0
  41. package/test/services/agenda.test.ts +280 -0
  42. package/test/services/queue.test.ts +286 -44
  43. package/tsconfig.json +10 -9
  44. package/types/index.ts +270 -0
  45. package/utils/generate-object.js +111 -0
  46. package/utils/generate-object.ts +24 -12
  47. package/utils/header-builder.js +34 -0
  48. package/utils/inject-actions.js +16 -0
  49. package/utils/inject-actions.ts +3 -3
  50. package/utils/queue-item-transformer.js +24 -0
  51. package/utils/queue-item-transformer.ts +8 -11
  52. package/utils/sanitize-results.js +60 -0
  53. package/utils/schema-generator.js +46 -0
  54. package/utils/state-manager.js +20 -0
  55. package/utils/state-manager.ts +30 -0
  56. package/.nvmrc +0 -1
  57. package/README.FR.md +0 -365
  58. package/agent/index.ts +0 -244
  59. package/agent/tools/get-rss.ts +0 -64
  60. package/bull.ts +0 -5
  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/index.ts +0 -103
  107. package/llm/interpreter/context.ts +0 -101
  108. package/llm/interpreter/index.ts +0 -136
  109. package/llm/memory-manager/context.ts +0 -21
  110. package/llm/memory-manager/index.ts +0 -163
  111. package/llm/orchestrator/context.ts +0 -22
  112. package/llm/orchestrator/index.ts +0 -232
  113. package/llm/orchestrator/types.ts +0 -14
  114. package/memory/cache.ts +0 -221
  115. package/memory/persistent.ts +0 -265
  116. package/services/redis-cache.ts +0 -128
  117. package/services/scheduler.ts +0 -128
  118. package/services/telegram-monitor.ts +0 -138
  119. package/t.py +0 -79
  120. package/t.spec +0 -38
  121. package/t.ts +0 -133
  122. package/test/llm/orchestrator.test.ts +0 -47
  123. package/test/llm/synthesizer.test.ts +0 -31
  124. package/types.ts +0 -288
  125. /package/dist/{llm/orchestrator/types.js → interfaces/index.js} +0 -0
@@ -0,0 +1,26 @@
1
+ import { EmbeddingService } from "@/interfaces";
2
+ import { cosineSimilarity, embed, EmbeddingModel, embedMany } from "ai";
3
+
4
+ export class AIEmbeddingService implements EmbeddingService {
5
+ constructor(private readonly model: EmbeddingModel<string>) {}
6
+
7
+ async embedText(text: string): Promise<number[]> {
8
+ const { embedding } = await embed({
9
+ model: this.model,
10
+ value: text,
11
+ });
12
+ return embedding;
13
+ }
14
+
15
+ async embedMany(texts: string[]): Promise<number[][]> {
16
+ const { embeddings } = await embedMany({
17
+ model: this.model,
18
+ values: texts,
19
+ });
20
+ return embeddings;
21
+ }
22
+
23
+ calculateSimilarity(embedding1: number[], embedding2: number[]): number {
24
+ return (cosineSimilarity(embedding1, embedding2) + 1) * 50;
25
+ }
26
+ }
package/services/queue.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  QueueResult,
7
7
  } from "../types";
8
8
 
9
- export class ActionQueueManager {
9
+ export class Queue {
10
10
  private queue: QueueItem[] = [];
11
11
  private results: QueueResult[] = [];
12
12
  private callbacks: QueueCallbacks;
@@ -18,40 +18,31 @@ export class ActionQueueManager {
18
18
  this.callbacks = callbacks;
19
19
  }
20
20
 
21
- addToQueue(actions: QueueItem | QueueItem[]) {
21
+ add(actions: QueueItem | QueueItem[]) {
22
22
  if (Array.isArray(actions)) {
23
- console.log("\n📋 Adding actions to queue:");
24
- actions.forEach((action, index) => {
25
- console.log(` ${index + 1}. ${action.name}`);
26
- });
27
23
  this.queue.push(...actions);
28
24
  } else {
29
- console.log("\n📋 Adding single action to queue:", actions.name);
30
25
  this.queue.push(actions);
31
26
  }
32
27
  }
33
28
 
34
- async processQueue() {
29
+ async execute() {
35
30
  if (this.isProcessing) {
36
- console.log("\n⚠️ Queue is already being processed");
37
31
  return;
38
32
  }
39
33
 
40
- console.log("\n🔄 Starting queue processing");
41
34
  this.isProcessing = true;
42
35
  const actionPromises: Promise<QueueResult>[] = [];
43
36
 
44
37
  for (const action of this.queue) {
45
38
  const actionConfig = this.actions.find((a) => a.name === action.name);
46
39
  if (actionConfig?.confirmation?.requireConfirmation) {
47
- console.log("\n🔒 Action requires confirmation:", action.name);
48
40
  const shouldProceed = await this.callbacks.onConfirmationRequired?.(
49
41
  actionConfig.confirmation.message ||
50
42
  `Do you want to proceed with action: ${action.name}?`
51
43
  );
52
44
 
53
45
  if (!shouldProceed) {
54
- console.log("❌ Action cancelled by user:", action.name);
55
46
  this.results.push({
56
47
  name: action.name,
57
48
  parameters: this.formatArguments(action.parameters),
@@ -61,7 +52,6 @@ export class ActionQueueManager {
61
52
  });
62
53
  continue;
63
54
  }
64
- console.log("✅ Action confirmed by user");
65
55
  }
66
56
  const parameters = this.formatArguments(action.parameters);
67
57
 
@@ -85,17 +75,14 @@ export class ActionQueueManager {
85
75
  }
86
76
 
87
77
  try {
88
- console.log("\n⏳ Waiting for all actions to complete...");
89
78
  const results = await Promise.all(actionPromises);
90
79
  this.results.push(...results);
91
80
  this.queue = [];
92
81
  this.callbacks.onQueueComplete?.(this.results);
93
82
  this.isProcessing = false;
94
- console.log("\n✅ Queue processing completed successfully");
95
83
  return this.results;
96
84
  } catch (error) {
97
85
  this.isProcessing = false;
98
- console.error("\n❌ Unexpected error in queue processing:", error);
99
86
  throw error;
100
87
  }
101
88
  }
@@ -124,12 +111,10 @@ export class ActionQueueManager {
124
111
  }
125
112
 
126
113
  private async executeAction(action: QueueItem): Promise<QueueResult> {
127
- console.log("\n🎯 Executing action:", action.name);
128
114
  this.callbacks.onActionStart?.(action);
129
115
 
130
116
  const actionConfig = this.actions.find((a) => a.name === action.name);
131
117
  if (!actionConfig) {
132
- console.error("❌ Action not found:", action.name);
133
118
  return {
134
119
  name: action.name,
135
120
  parameters: {},
@@ -138,35 +123,23 @@ export class ActionQueueManager {
138
123
  };
139
124
  }
140
125
 
141
- console.log(
142
- "📝 Action parameters:",
143
- JSON.stringify(action.parameters, null, 2)
144
- );
145
126
  const actionArgs = this.formatArguments(action.parameters);
146
127
 
147
128
  try {
148
129
  const result = await actionConfig.execute(actionArgs);
149
- const actionResult = {
130
+ return {
150
131
  name: action.name,
151
132
  parameters: actionArgs,
152
133
  result,
153
134
  error: null,
154
135
  };
155
- console.log(`\n✨ Action "${action.name}" completed successfully`);
156
- return actionResult;
157
136
  } catch (error) {
158
- const actionResult = {
137
+ return {
159
138
  name: action.name,
160
139
  parameters: actionArgs,
161
140
  result: null,
162
141
  error: (error as Error).message || "Unknown error occurred",
163
142
  };
164
- console.error(`\n❌ Action "${action.name}" failed:`, error);
165
- console.log(
166
- "Failed action details:",
167
- JSON.stringify(actionResult, null, 2)
168
- );
169
- return actionResult;
170
143
  }
171
144
  }
172
145
  }
package/test/.env.test ADDED
@@ -0,0 +1,4 @@
1
+ MEILISEARCH_HOST=http://localhost:7700
2
+ MEILISEARCH_API_KEY=aSampleMasterKey
3
+ REDIS_URL=redis://localhost:6379
4
+ REDIS_TEST_DB=1
@@ -0,0 +1,186 @@
1
+ import { GraphController } from "@/graph/controller";
2
+ import { GraphDefinition } from "@/types";
3
+ import { expect } from "chai";
4
+ import { z } from "zod";
5
+
6
+ describe("Controller", () => {
7
+ // Define test schema
8
+ const TestSchema = z.object({
9
+ status: z.string(),
10
+ count: z.number(),
11
+ });
12
+
13
+ type TestState = z.infer<typeof TestSchema>;
14
+
15
+ // Sample workflow definitions
16
+ const simpleWorkflow: GraphDefinition<TestState> = {
17
+ name: "simple-workflow",
18
+ entryNode: "start",
19
+ nodes: {
20
+ start: {
21
+ name: "start",
22
+ execute: async (_params: any, state: any) => ({
23
+ context: {
24
+ ...state.context,
25
+ status: "completed",
26
+ count: state.context.count + 1,
27
+ },
28
+ }),
29
+ relationships: [],
30
+ },
31
+ },
32
+ schema: TestSchema,
33
+ };
34
+
35
+ const complexWorkflow: GraphDefinition<TestState> = {
36
+ name: "complex-workflow",
37
+ entryNode: "first",
38
+ nodes: {
39
+ first: {
40
+ name: "first",
41
+ execute: async (_params: any, state: any) => ({
42
+ context: {
43
+ ...state.context,
44
+ status: "step1",
45
+ count: state.context.count + 2,
46
+ },
47
+ }),
48
+ relationships: [],
49
+ },
50
+ },
51
+ schema: TestSchema,
52
+ };
53
+
54
+ let controller: GraphController<TestState>;
55
+
56
+ beforeEach(() => {
57
+ controller = new GraphController<TestState>();
58
+ });
59
+
60
+ describe("Basic Execution", () => {
61
+ it("should execute a single workflow successfully", async () => {
62
+ const actions = [
63
+ {
64
+ name: "simple-workflow",
65
+ parameters: [
66
+ { name: "status", value: "initial" },
67
+ { name: "count", value: 0 },
68
+ ],
69
+ },
70
+ ];
71
+
72
+ const result = await controller.run(actions, [simpleWorkflow]);
73
+
74
+ expect(result.context).to.deep.equal({
75
+ status: "completed",
76
+ count: 1,
77
+ });
78
+ });
79
+
80
+ it("should handle multiple workflows", async () => {
81
+ const actions = [
82
+ {
83
+ name: "complex-workflow",
84
+ parameters: [
85
+ { name: "status", value: "initial" },
86
+ { name: "count", value: 0 },
87
+ ],
88
+ },
89
+ ];
90
+
91
+ const result = await controller.run(actions, [
92
+ simpleWorkflow,
93
+ complexWorkflow,
94
+ ]);
95
+
96
+ expect(result.context).to.deep.equal({
97
+ status: "step1",
98
+ count: 2,
99
+ });
100
+ });
101
+ });
102
+
103
+ describe("Error Handling", () => {
104
+ it("should throw error when no actions provided", async () => {
105
+ try {
106
+ await controller.run([], [simpleWorkflow]);
107
+ expect.fail("Should have thrown an error");
108
+ } catch (error) {
109
+ expect((error as Error).message).to.equal("No actions provided");
110
+ }
111
+ });
112
+
113
+ it("should throw error when workflow not found", async () => {
114
+ const actions = [
115
+ {
116
+ name: "non-existent-workflow",
117
+ parameters: [
118
+ { name: "status", value: "initial" },
119
+ { name: "count", value: 0 },
120
+ ],
121
+ },
122
+ ];
123
+
124
+ try {
125
+ await controller.run(actions, [simpleWorkflow]);
126
+ expect.fail("Should have thrown an error");
127
+ } catch (error) {
128
+ expect((error as Error).message).to.equal(
129
+ "Graph not found: non-existent-workflow"
130
+ );
131
+ }
132
+ });
133
+ });
134
+
135
+ describe("Parameter Handling", () => {
136
+ it("should correctly process workflow parameters", async () => {
137
+ const actions = [
138
+ {
139
+ name: "simple-workflow",
140
+ parameters: [
141
+ { name: "status", value: "custom-initial" },
142
+ { name: "count", value: 10 },
143
+ ],
144
+ },
145
+ ];
146
+
147
+ const result = await controller.run(actions, [simpleWorkflow]);
148
+
149
+ expect(result.context).to.deep.equal({
150
+ status: "completed",
151
+ count: 11,
152
+ });
153
+ });
154
+ });
155
+
156
+ describe("Multiple Actions", () => {
157
+ it("should process the first action only", async () => {
158
+ const actions = [
159
+ {
160
+ name: "simple-workflow",
161
+ parameters: [
162
+ { name: "status", value: "initial" },
163
+ { name: "count", value: 0 },
164
+ ],
165
+ },
166
+ {
167
+ name: "complex-workflow",
168
+ parameters: [
169
+ { name: "status", value: "initial" },
170
+ { name: "count", value: 5 },
171
+ ],
172
+ },
173
+ ];
174
+
175
+ const result = await controller.run(actions, [
176
+ simpleWorkflow,
177
+ complexWorkflow,
178
+ ]);
179
+
180
+ expect(result.context).to.deep.equal({
181
+ status: "completed",
182
+ count: 1,
183
+ });
184
+ });
185
+ });
186
+ });