@ai.ntellect/core 0.6.17 → 0.6.19
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/.mocharc.json +1 -2
- package/README.md +123 -178
- package/dist/graph/controller.js +29 -6
- package/dist/graph/index.js +302 -62
- package/dist/index.js +21 -6
- package/dist/interfaces/index.js +15 -0
- package/dist/modules/agenda/adapters/node-cron/index.js +29 -0
- package/dist/modules/agenda/index.js +140 -0
- package/dist/{services/embedding.js → modules/embedding/adapters/ai/index.js} +24 -7
- package/dist/modules/embedding/index.js +59 -0
- package/dist/modules/memory/adapters/in-memory/index.js +210 -0
- package/dist/{memory → modules/memory}/adapters/meilisearch/index.js +97 -2
- package/dist/{memory → modules/memory}/adapters/redis/index.js +77 -15
- package/dist/modules/memory/index.js +103 -0
- package/dist/utils/{stringifiy-zod-schema.js → generate-action-schema.js} +5 -5
- package/graph/controller.ts +37 -13
- package/graph/index.ts +348 -73
- package/index.ts +24 -6
- package/interfaces/index.ts +346 -27
- package/modules/agenda/adapters/node-cron/index.ts +25 -0
- package/modules/agenda/index.ts +159 -0
- package/modules/embedding/adapters/ai/index.ts +42 -0
- package/modules/embedding/index.ts +45 -0
- package/modules/memory/adapters/in-memory/index.ts +203 -0
- package/{memory → modules/memory}/adapters/meilisearch/index.ts +114 -12
- package/modules/memory/adapters/redis/index.ts +164 -0
- package/modules/memory/index.ts +93 -0
- package/package.json +3 -1
- package/test/graph/index.test.ts +646 -0
- package/test/modules/agenda/node-cron.test.ts +286 -0
- package/test/modules/embedding/ai.test.ts +78 -0
- package/test/modules/memory/adapters/in-memory.test.ts +153 -0
- package/test/{memory → modules/memory}/adapters/meilisearch.test.ts +79 -75
- package/test/modules/memory/adapters/redis.test.ts +169 -0
- package/test/modules/memory/base.test.ts +230 -0
- package/test/services/agenda.test.ts +279 -280
- package/types/index.ts +82 -203
- package/utils/{stringifiy-zod-schema.ts → generate-action-schema.ts} +3 -3
- package/app/README.md +0 -36
- package/app/app/favicon.ico +0 -0
- package/app/app/globals.css +0 -21
- package/app/app/gun.ts +0 -0
- package/app/app/layout.tsx +0 -18
- package/app/app/page.tsx +0 -321
- package/app/eslint.config.mjs +0 -16
- package/app/next.config.ts +0 -7
- package/app/package-lock.json +0 -5912
- package/app/package.json +0 -31
- package/app/pnpm-lock.yaml +0 -4031
- package/app/postcss.config.mjs +0 -8
- package/app/public/file.svg +0 -1
- package/app/public/globe.svg +0 -1
- package/app/public/next.svg +0 -1
- package/app/public/vercel.svg +0 -1
- package/app/public/window.svg +0 -1
- package/app/tailwind.config.ts +0 -18
- package/app/tsconfig.json +0 -27
- package/dist/memory/index.js +0 -9
- package/dist/services/agenda.js +0 -115
- package/dist/services/queue.js +0 -142
- package/dist/utils/experimental-graph-rag.js +0 -152
- package/dist/utils/generate-object.js +0 -111
- package/dist/utils/inject-actions.js +0 -16
- package/dist/utils/queue-item-transformer.js +0 -24
- package/dist/utils/sanitize-results.js +0 -60
- package/memory/adapters/redis/index.ts +0 -103
- package/memory/index.ts +0 -22
- package/services/agenda.ts +0 -118
- package/services/embedding.ts +0 -26
- package/services/queue.ts +0 -145
- package/test/memory/adapters/redis.test.ts +0 -159
- package/test/memory/base.test.ts +0 -225
- package/test/services/queue.test.ts +0 -286
- package/utils/experimental-graph-rag.ts +0 -170
- package/utils/generate-object.ts +0 -117
- package/utils/inject-actions.ts +0 -19
- package/utils/queue-item-transformer.ts +0 -38
- package/utils/sanitize-results.ts +0 -66
@@ -0,0 +1,140 @@
|
|
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;
|
@@ -9,13 +9,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.
|
12
|
+
exports.AIEmbeddingAdapter = void 0;
|
13
13
|
const ai_1 = require("ai");
|
14
|
-
|
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
|
+
*/
|
15
25
|
constructor(model) {
|
16
26
|
this.model = model;
|
17
27
|
}
|
18
|
-
|
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) {
|
19
34
|
return __awaiter(this, void 0, void 0, function* () {
|
20
35
|
const { embedding } = yield (0, ai_1.embed)({
|
21
36
|
model: this.model,
|
@@ -24,6 +39,11 @@ class AIEmbeddingService {
|
|
24
39
|
return embedding;
|
25
40
|
});
|
26
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
|
+
*/
|
27
47
|
embedMany(texts) {
|
28
48
|
return __awaiter(this, void 0, void 0, function* () {
|
29
49
|
const { embeddings } = yield (0, ai_1.embedMany)({
|
@@ -33,8 +53,5 @@ class AIEmbeddingService {
|
|
33
53
|
return embeddings;
|
34
54
|
});
|
35
55
|
}
|
36
|
-
calculateSimilarity(embedding1, embedding2) {
|
37
|
-
return ((0, ai_1.cosineSimilarity)(embedding1, embedding2) + 1) * 50;
|
38
|
-
}
|
39
56
|
}
|
40
|
-
exports.
|
57
|
+
exports.AIEmbeddingAdapter = AIEmbeddingAdapter;
|
@@ -0,0 +1,59 @@
|
|
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;
|
@@ -0,0 +1,210 @@
|
|
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;
|
@@ -10,10 +10,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.MeilisearchAdapter = void 0;
|
13
|
+
/**
|
14
|
+
* @module MeilisearchAdapter
|
15
|
+
* @description Adapter implementation for Meilisearch as a memory storage solution.
|
16
|
+
* Provides integration with Meilisearch for storing and retrieving memory entries.
|
17
|
+
* @implements {IMemoryAdapter}
|
18
|
+
*/
|
13
19
|
class MeilisearchAdapter {
|
20
|
+
/**
|
21
|
+
* Creates an instance of MeilisearchAdapter
|
22
|
+
* @param {MeilisearchConfig} config - Configuration for Meilisearch connection
|
23
|
+
*/
|
14
24
|
constructor(config) {
|
15
25
|
this.config = config;
|
16
26
|
}
|
27
|
+
/**
|
28
|
+
* Makes an HTTP request to the Meilisearch API
|
29
|
+
* @private
|
30
|
+
* @param {string} path - API endpoint path
|
31
|
+
* @param {RequestInit} [options] - Fetch request options
|
32
|
+
* @returns {Promise<any>} Response data
|
33
|
+
* @throws {Error} If the request fails
|
34
|
+
*/
|
17
35
|
makeRequest(path, options) {
|
18
36
|
return __awaiter(this, void 0, void 0, function* () {
|
19
37
|
try {
|
@@ -33,6 +51,12 @@ class MeilisearchAdapter {
|
|
33
51
|
}
|
34
52
|
});
|
35
53
|
}
|
54
|
+
/**
|
55
|
+
* Initializes a storage index for a room
|
56
|
+
* @private
|
57
|
+
* @param {string} roomId - Room identifier to create index for
|
58
|
+
* @returns {Promise<void>}
|
59
|
+
*/
|
36
60
|
initializeStorage(roomId) {
|
37
61
|
return __awaiter(this, void 0, void 0, function* () {
|
38
62
|
try {
|
@@ -72,6 +96,13 @@ class MeilisearchAdapter {
|
|
72
96
|
}
|
73
97
|
});
|
74
98
|
}
|
99
|
+
/**
|
100
|
+
* Adds documents to the Meilisearch index
|
101
|
+
* @private
|
102
|
+
* @param {BaseMemoryType[]} documents - Documents to add
|
103
|
+
* @param {string} roomId - Room identifier
|
104
|
+
* @returns {Promise<void>}
|
105
|
+
*/
|
75
106
|
addDocuments(documents, roomId) {
|
76
107
|
return __awaiter(this, void 0, void 0, function* () {
|
77
108
|
yield this.makeRequest(`/indexes/${roomId}/documents`, {
|
@@ -80,6 +111,12 @@ class MeilisearchAdapter {
|
|
80
111
|
});
|
81
112
|
});
|
82
113
|
}
|
114
|
+
/**
|
115
|
+
* Deletes a storage index for a room
|
116
|
+
* @private
|
117
|
+
* @param {string} roomId - Room identifier
|
118
|
+
* @returns {Promise<void>}
|
119
|
+
*/
|
83
120
|
deleteStorage(roomId) {
|
84
121
|
return __awaiter(this, void 0, void 0, function* () {
|
85
122
|
yield this.makeRequest(`/indexes/${roomId}`, {
|
@@ -87,7 +124,11 @@ class MeilisearchAdapter {
|
|
87
124
|
});
|
88
125
|
});
|
89
126
|
}
|
90
|
-
|
127
|
+
/**
|
128
|
+
* Initializes the adapter for a specific room
|
129
|
+
* @param {string} roomId - Room identifier
|
130
|
+
* @returns {Promise<void>}
|
131
|
+
*/
|
91
132
|
init(roomId) {
|
92
133
|
return __awaiter(this, void 0, void 0, function* () {
|
93
134
|
try {
|
@@ -101,6 +142,16 @@ class MeilisearchAdapter {
|
|
101
142
|
}
|
102
143
|
});
|
103
144
|
}
|
145
|
+
/**
|
146
|
+
* Performs a search in the Meilisearch index
|
147
|
+
* @private
|
148
|
+
* @param {string} query - Search query
|
149
|
+
* @param {string} roomId - Room identifier
|
150
|
+
* @param {Object} [options] - Search options
|
151
|
+
* @param {number} [options.limit] - Maximum number of results
|
152
|
+
* @param {number} [options.threshold] - Minimum score threshold
|
153
|
+
* @returns {Promise<SearchResult[]>} Search results
|
154
|
+
*/
|
104
155
|
search(query, roomId, options) {
|
105
156
|
return __awaiter(this, void 0, void 0, function* () {
|
106
157
|
const searchResults = yield this.makeRequest(`/indexes/${roomId}/search`, {
|
@@ -110,6 +161,9 @@ class MeilisearchAdapter {
|
|
110
161
|
limit: (options === null || options === void 0 ? void 0 : options.limit) || 10,
|
111
162
|
}),
|
112
163
|
});
|
164
|
+
if (!searchResults.hits) {
|
165
|
+
return [];
|
166
|
+
}
|
113
167
|
return searchResults.hits.map((hit) => ({
|
114
168
|
document: {
|
115
169
|
id: hit.id,
|
@@ -122,15 +176,27 @@ class MeilisearchAdapter {
|
|
122
176
|
}));
|
123
177
|
});
|
124
178
|
}
|
179
|
+
/**
|
180
|
+
* Creates a new memory entry
|
181
|
+
* @param {CreateMemoryInput & { embedding?: number[] }} input - Memory data with optional embedding
|
182
|
+
* @returns {Promise<BaseMemoryType | undefined>} Created memory or undefined
|
183
|
+
*/
|
125
184
|
createMemory(input) {
|
126
185
|
return __awaiter(this, void 0, void 0, function* () {
|
127
186
|
// Initialize storage for this roomId if needed
|
128
187
|
yield this.initializeStorage(input.roomId);
|
188
|
+
// Check if the memory already exists
|
189
|
+
const existingMemory = yield this.search(input.data, input.roomId, {
|
190
|
+
limit: 1,
|
191
|
+
});
|
192
|
+
if (existingMemory.length > 0) {
|
193
|
+
return existingMemory[0].document;
|
194
|
+
}
|
129
195
|
// If not found, create new memory
|
130
196
|
const memory = {
|
131
197
|
id: input.id || crypto.randomUUID(),
|
132
198
|
data: input.data,
|
133
|
-
embedding: input.embedding
|
199
|
+
embedding: input.embedding,
|
134
200
|
roomId: input.roomId,
|
135
201
|
createdAt: new Date(),
|
136
202
|
};
|
@@ -138,6 +204,12 @@ class MeilisearchAdapter {
|
|
138
204
|
return memory;
|
139
205
|
});
|
140
206
|
}
|
207
|
+
/**
|
208
|
+
* Retrieves a memory by ID and room ID
|
209
|
+
* @param {string} id - Memory identifier
|
210
|
+
* @param {string} roomId - Room identifier
|
211
|
+
* @returns {Promise<BaseMemoryType | null>} Memory entry or null if not found
|
212
|
+
*/
|
141
213
|
getMemoryById(id, roomId) {
|
142
214
|
return __awaiter(this, void 0, void 0, function* () {
|
143
215
|
try {
|
@@ -157,6 +229,14 @@ class MeilisearchAdapter {
|
|
157
229
|
}
|
158
230
|
});
|
159
231
|
}
|
232
|
+
/**
|
233
|
+
* Searches for memories based on query and options
|
234
|
+
* @param {string} query - Search query
|
235
|
+
* @param {Object} options - Search options
|
236
|
+
* @param {string} options.roomId - Room identifier
|
237
|
+
* @param {number} [options.limit] - Maximum number of results
|
238
|
+
* @returns {Promise<BaseMemoryType[]>} Array of matching memories
|
239
|
+
*/
|
160
240
|
getMemoryByIndex(query, options) {
|
161
241
|
return __awaiter(this, void 0, void 0, function* () {
|
162
242
|
const results = yield this.search(query, options.roomId, {
|
@@ -173,6 +253,11 @@ class MeilisearchAdapter {
|
|
173
253
|
}));
|
174
254
|
});
|
175
255
|
}
|
256
|
+
/**
|
257
|
+
* Retrieves all memories for a room
|
258
|
+
* @param {string} roomId - Room identifier
|
259
|
+
* @returns {Promise<BaseMemoryType[]>} Array of all memories
|
260
|
+
*/
|
176
261
|
getAllMemories(roomId) {
|
177
262
|
return __awaiter(this, void 0, void 0, function* () {
|
178
263
|
const results = yield this.makeRequest(`/indexes/${roomId}/documents`);
|
@@ -188,6 +273,12 @@ class MeilisearchAdapter {
|
|
188
273
|
}));
|
189
274
|
});
|
190
275
|
}
|
276
|
+
/**
|
277
|
+
* Deletes a specific memory
|
278
|
+
* @param {string} id - Memory identifier
|
279
|
+
* @param {string} roomId - Room identifier
|
280
|
+
* @returns {Promise<void>}
|
281
|
+
*/
|
191
282
|
clearMemoryById(id, roomId) {
|
192
283
|
return __awaiter(this, void 0, void 0, function* () {
|
193
284
|
try {
|
@@ -204,6 +295,10 @@ class MeilisearchAdapter {
|
|
204
295
|
}
|
205
296
|
});
|
206
297
|
}
|
298
|
+
/**
|
299
|
+
* Clears all memories across all rooms
|
300
|
+
* @returns {Promise<void>}
|
301
|
+
*/
|
207
302
|
clearAllMemories() {
|
208
303
|
return __awaiter(this, void 0, void 0, function* () {
|
209
304
|
try {
|