@ai.ntellect/core 0.6.20 → 0.7.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 (41) hide show
  1. package/.mocharc.json +2 -1
  2. package/README.md +87 -148
  3. package/graph/controller.ts +1 -1
  4. package/graph/event-manager.ts +288 -0
  5. package/graph/index.ts +152 -384
  6. package/graph/logger.ts +70 -0
  7. package/graph/node.ts +398 -0
  8. package/graph/observer.ts +361 -0
  9. package/interfaces/index.ts +102 -1
  10. package/modules/agenda/index.ts +3 -16
  11. package/modules/embedding/index.ts +3 -3
  12. package/package.json +12 -20
  13. package/test/graph/index.test.ts +296 -154
  14. package/test/graph/observer.test.ts +398 -0
  15. package/test/modules/agenda/node-cron.test.ts +37 -16
  16. package/test/modules/memory/adapters/in-memory.test.ts +2 -2
  17. package/test/modules/memory/adapters/meilisearch.test.ts +28 -24
  18. package/test/modules/memory/base.test.ts +3 -3
  19. package/tsconfig.json +4 -2
  20. package/types/index.ts +23 -2
  21. package/utils/generate-action-schema.ts +8 -7
  22. package/.env.example +0 -2
  23. package/dist/graph/controller.js +0 -75
  24. package/dist/graph/index.js +0 -402
  25. package/dist/index.js +0 -41
  26. package/dist/interfaces/index.js +0 -17
  27. package/dist/modules/agenda/adapters/node-cron/index.js +0 -29
  28. package/dist/modules/agenda/index.js +0 -140
  29. package/dist/modules/embedding/adapters/ai/index.js +0 -57
  30. package/dist/modules/embedding/index.js +0 -59
  31. package/dist/modules/memory/adapters/in-memory/index.js +0 -210
  32. package/dist/modules/memory/adapters/meilisearch/index.js +0 -320
  33. package/dist/modules/memory/adapters/redis/index.js +0 -158
  34. package/dist/modules/memory/index.js +0 -103
  35. package/dist/types/index.js +0 -2
  36. package/dist/utils/generate-action-schema.js +0 -42
  37. package/dist/utils/header-builder.js +0 -34
  38. package/graph.ts +0 -74
  39. package/test/modules/embedding/ai.test.ts +0 -78
  40. package/test/modules/memory/adapters/redis.test.ts +0 -169
  41. package/test/services/agenda.test.ts +0 -279
@@ -1,140 +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.Agenda = void 0;
13
- /**
14
- * @module Agenda
15
- * @description A module for scheduling and managing cron-based tasks.
16
- * Provides functionality for scheduling requests, managing their lifecycle,
17
- * and handling recurring and one-time tasks.
18
- */
19
- class Agenda {
20
- /**
21
- * Creates an instance of Agenda
22
- * @param {ICronService} cronService - The cron service implementation
23
- * @param {IMemoryAdapter} storage - The storage service for jobs and requests
24
- */
25
- constructor(cronService, storage) {
26
- this.cronService = cronService;
27
- this.storage = storage;
28
- }
29
- /**
30
- * Schedule a new request to be processed later
31
- * @param {Object} request - The request configuration
32
- * @param {string} request.originalRequest - The original request to be executed
33
- * @param {string} request.cronExpression - The cron expression for scheduling
34
- * @param {Object} [callbacks] - Optional callback functions
35
- * @param {Function} [callbacks.onScheduled] - Called when request is scheduled
36
- * @param {Function} [callbacks.onExecuted] - Called when request is executed
37
- * @returns {Promise<string>} The ID of the scheduled request
38
- */
39
- scheduleRequest(request, callbacks) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const id = crypto.randomUUID();
42
- const scheduledRequest = {
43
- id,
44
- originalRequest: request.originalRequest,
45
- cronExpression: request.cronExpression,
46
- isRecurring: false,
47
- createdAt: new Date(),
48
- };
49
- // Create cron job using the injected service
50
- const cronJob = this.cronService.schedule(request.cronExpression, () => __awaiter(this, void 0, void 0, function* () {
51
- console.log(`🔄 Executing scheduled request: ${id}`);
52
- if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onExecuted) {
53
- callbacks.onExecuted(id, scheduledRequest.originalRequest);
54
- }
55
- console.log(`✅ Scheduled request executed successfully: ${id}`);
56
- // Auto-stop for non-recurring tasks
57
- if (!scheduledRequest.isRecurring) {
58
- yield this.cancelScheduledRequest(id);
59
- }
60
- }));
61
- // Start job in non-running mode
62
- cronJob.stop();
63
- // Store request and job using storage service
64
- yield this.storage.saveRequest(id, scheduledRequest);
65
- yield this.storage.saveJob(id, cronJob);
66
- if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onScheduled)
67
- callbacks.onScheduled(id);
68
- // Start the job after storing
69
- cronJob.start();
70
- return id;
71
- });
72
- }
73
- /**
74
- * Cancels a scheduled request by its ID
75
- * @param {string} requestId - The ID of the request to cancel
76
- * @returns {Promise<boolean>} True if the request was found and cancelled, false otherwise
77
- */
78
- cancelScheduledRequest(requestId) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- const cronJob = yield this.storage.getJob(requestId);
81
- if (cronJob) {
82
- try {
83
- cronJob.stop();
84
- yield this.storage.deleteJob(requestId);
85
- yield this.storage.deleteRequest(requestId);
86
- return true;
87
- }
88
- catch (error) {
89
- console.error(`Failed to stop cron job ${requestId}:`, error);
90
- return false;
91
- }
92
- }
93
- return false;
94
- });
95
- }
96
- /**
97
- * Retrieves all scheduled requests
98
- * @returns {Promise<ScheduledRequest[]>} Array of all scheduled requests
99
- */
100
- getScheduledRequests() {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- return this.storage.getAllRequests();
103
- });
104
- }
105
- /**
106
- * Stops all scheduled jobs
107
- * @returns {Promise<void>}
108
- */
109
- stopAll() {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const requests = yield this.getScheduledRequests();
112
- for (const request of requests) {
113
- yield this.cancelScheduledRequest(request.id);
114
- }
115
- yield this.storage.clear();
116
- });
117
- }
118
- /**
119
- * Stops the agenda service
120
- * @returns {Promise<void>}
121
- */
122
- stop() {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- yield this.stopAll();
125
- yield new Promise((resolve) => setTimeout(resolve, 100));
126
- });
127
- }
128
- /**
129
- * Cancels requests matching the query
130
- * @param {Object} query - Query to match requests against
131
- * @returns {Promise<void>}
132
- */
133
- cancel(query) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- yield this.stopAll();
136
- yield new Promise((resolve) => setTimeout(resolve, 100));
137
- });
138
- }
139
- }
140
- exports.Agenda = Agenda;
@@ -1,57 +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.AIEmbeddingAdapter = void 0;
13
- const ai_1 = require("ai");
14
- /**
15
- * @module AIEmbeddingAdapter
16
- * @description Adapter implementation for AI-based embedding service.
17
- * Provides integration with AI models for text embedding generation.
18
- * @implements {IEmbeddingModel}
19
- */
20
- class AIEmbeddingAdapter {
21
- /**
22
- * Creates an instance of AIEmbeddingAdapter
23
- * @param {EmbeddingModel<string>} model - The AI embedding model to use
24
- */
25
- constructor(model) {
26
- this.model = model;
27
- }
28
- /**
29
- * Generates an embedding vector for a single text using the AI model
30
- * @param {string} text - The text to embed
31
- * @returns {Promise<number[]>} The generated embedding vector
32
- */
33
- embed(text) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const { embedding } = yield (0, ai_1.embed)({
36
- model: this.model,
37
- value: text,
38
- });
39
- return embedding;
40
- });
41
- }
42
- /**
43
- * Generates embedding vectors for multiple texts using the AI model
44
- * @param {string[]} texts - Array of texts to embed
45
- * @returns {Promise<number[][]>} Array of generated embedding vectors
46
- */
47
- embedMany(texts) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const { embeddings } = yield (0, ai_1.embedMany)({
50
- model: this.model,
51
- values: texts,
52
- });
53
- return embeddings;
54
- });
55
- }
56
- }
57
- exports.AIEmbeddingAdapter = AIEmbeddingAdapter;
@@ -1,59 +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.Embedding = void 0;
13
- const ai_1 = require("ai");
14
- /**
15
- * @module Embedding
16
- * @description A module for generating and managing text embeddings.
17
- * Provides functionality for converting text into vector representations
18
- * and calculating similarities between embeddings.
19
- * @implements {IEmbeddingModule}
20
- */
21
- class Embedding {
22
- /**
23
- * Creates an instance of Embedding
24
- * @param {IEmbeddingModel} embeddingModel - The embedding model implementation to use
25
- */
26
- constructor(embeddingModel) {
27
- this.embeddingModel = embeddingModel;
28
- }
29
- /**
30
- * Generates an embedding vector for a single text
31
- * @param {string} text - The text to embed
32
- * @returns {Promise<number[]>} The embedding vector
33
- */
34
- embedText(text) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- return this.embeddingModel.embed(text);
37
- });
38
- }
39
- /**
40
- * Generates embedding vectors for multiple texts
41
- * @param {string[]} texts - Array of texts to embed
42
- * @returns {Promise<number[][]>} Array of embedding vectors
43
- */
44
- embedMany(texts) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- return this.embeddingModel.embedMany(texts);
47
- });
48
- }
49
- /**
50
- * Calculates the similarity score between two embeddings
51
- * @param {number[]} embedding1 - First embedding vector
52
- * @param {number[]} embedding2 - Second embedding vector
53
- * @returns {number} Similarity score between 0 and 100
54
- */
55
- calculateSimilarity(embedding1, embedding2) {
56
- return ((0, ai_1.cosineSimilarity)(embedding1, embedding2) + 1) * 50;
57
- }
58
- }
59
- exports.Embedding = Embedding;
@@ -1,210 +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.InMemoryAdapter = void 0;
13
- /**
14
- * @module InMemoryAdapter
15
- * @description In-memory implementation of the memory storage adapter.
16
- * Provides a simple Map-based storage solution
17
- * @implements {IMemoryAdapter}
18
- */
19
- class InMemoryAdapter {
20
- /**
21
- * Creates an instance of InMemoryAdapter
22
- */
23
- constructor() {
24
- this.storage = new Map();
25
- this.jobs = new Map();
26
- this.requests = new Map();
27
- }
28
- /**
29
- * Initializes storage for a room
30
- * @param {string} roomId - Room identifier
31
- * @returns {Promise<void>}
32
- */
33
- init(roomId) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- if (!this.storage.has(roomId)) {
36
- this.storage.set(roomId, []);
37
- }
38
- });
39
- }
40
- /**
41
- * Creates a new memory entry
42
- * @param {CreateMemoryInput & { embedding?: number[] }} input - Memory data with optional embedding
43
- * @returns {Promise<BaseMemoryType | undefined>} Created memory or existing memory if duplicate
44
- */
45
- createMemory(input) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- yield this.init(input.roomId);
48
- // Check if memory already exists
49
- const memories = this.storage.get(input.roomId) || [];
50
- const existingMemory = memories.find((m) => m.data === input.data);
51
- if (existingMemory) {
52
- return existingMemory;
53
- }
54
- // Create new memory
55
- const memory = {
56
- id: input.id || crypto.randomUUID(),
57
- data: input.data,
58
- embedding: input.embedding,
59
- roomId: input.roomId,
60
- createdAt: new Date(),
61
- };
62
- memories.push(memory);
63
- this.storage.set(input.roomId, memories);
64
- return memory;
65
- });
66
- }
67
- /**
68
- * Retrieves a memory by ID and room ID
69
- * @param {string} id - Memory identifier
70
- * @param {string} roomId - Room identifier
71
- * @returns {Promise<BaseMemoryType | null>} Memory entry or null if not found
72
- */
73
- getMemoryById(id, roomId) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- const memories = this.storage.get(roomId) || [];
76
- return memories.find((m) => m.id === id) || null;
77
- });
78
- }
79
- /**
80
- * Searches for memories based on query and options
81
- * @param {string} query - Search query
82
- * @param {Object} options - Search options
83
- * @param {string} options.roomId - Room identifier
84
- * @param {number} [options.limit] - Maximum number of results
85
- * @returns {Promise<BaseMemoryType[]>} Array of matching memories
86
- */
87
- getMemoryByIndex(query, options) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- const memories = this.storage.get(options.roomId) || [];
90
- const filtered = memories.filter((m) => m.data.includes(query));
91
- return filtered.slice(0, options.limit || filtered.length);
92
- });
93
- }
94
- /**
95
- * Retrieves all memories for a room
96
- * @param {string} roomId - Room identifier
97
- * @returns {Promise<BaseMemoryType[]>} Array of all memories
98
- */
99
- getAllMemories(roomId) {
100
- return __awaiter(this, void 0, void 0, function* () {
101
- return this.storage.get(roomId) || [];
102
- });
103
- }
104
- /**
105
- * Deletes a specific memory
106
- * @param {string} id - Memory identifier
107
- * @param {string} roomId - Room identifier
108
- * @returns {Promise<void>}
109
- */
110
- clearMemoryById(id, roomId) {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- const memories = this.storage.get(roomId) || [];
113
- const filtered = memories.filter((m) => m.id !== id);
114
- this.storage.set(roomId, filtered);
115
- });
116
- }
117
- /**
118
- * Clears all memories across all rooms
119
- * @returns {Promise<void>}
120
- */
121
- clearAllMemories() {
122
- return __awaiter(this, void 0, void 0, function* () {
123
- this.storage.clear();
124
- this.jobs.clear();
125
- this.requests.clear();
126
- });
127
- }
128
- /**
129
- * Saves a job to the internal storage
130
- * @param {string} id - Job identifier
131
- * @param {ICronJob} job - Job data
132
- * @returns {Promise<void>}
133
- */
134
- saveJob(id, job) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- this.jobs.set(id, job);
137
- });
138
- }
139
- /**
140
- * Saves a request to the internal storage
141
- * @param {string} id - Request identifier
142
- * @param {ScheduledRequest} request - Request data
143
- * @returns {Promise<void>}
144
- */
145
- saveRequest(id, request) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- this.requests.set(id, request);
148
- });
149
- }
150
- /**
151
- * Retrieves a job by ID
152
- * @param {string} id - Job identifier
153
- * @returns {Promise<ICronJob | undefined>} Job data or undefined if not found
154
- */
155
- getJob(id) {
156
- return __awaiter(this, void 0, void 0, function* () {
157
- return this.jobs.get(id);
158
- });
159
- }
160
- /**
161
- * Retrieves a request by ID
162
- * @param {string} id - Request identifier
163
- * @returns {Promise<ScheduledRequest | undefined>} Request data or undefined if not found
164
- */
165
- getRequest(id) {
166
- return __awaiter(this, void 0, void 0, function* () {
167
- return this.requests.get(id);
168
- });
169
- }
170
- /**
171
- * Deletes a job by ID
172
- * @param {string} id - Job identifier
173
- * @returns {Promise<void>}
174
- */
175
- deleteJob(id) {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- this.jobs.delete(id);
178
- });
179
- }
180
- /**
181
- * Deletes a request by ID
182
- * @param {string} id - Request identifier
183
- * @returns {Promise<void>}
184
- */
185
- deleteRequest(id) {
186
- return __awaiter(this, void 0, void 0, function* () {
187
- this.requests.delete(id);
188
- });
189
- }
190
- /**
191
- * Retrieves all requests
192
- * @returns {Promise<ScheduledRequest[]>} Array of all requests
193
- */
194
- getAllRequests() {
195
- return __awaiter(this, void 0, void 0, function* () {
196
- return Array.from(this.requests.values());
197
- });
198
- }
199
- /**
200
- * Clears all jobs and requests
201
- * @returns {Promise<void>}
202
- */
203
- clear() {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- this.jobs.clear();
206
- this.requests.clear();
207
- });
208
- }
209
- }
210
- exports.InMemoryAdapter = InMemoryAdapter;