@ai.ntellect/core 0.6.21 → 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.
- package/.mocharc.json +2 -1
- package/README.md +61 -85
- package/graph/controller.ts +1 -1
- package/graph/event-manager.ts +288 -0
- package/graph/index.ts +153 -367
- package/graph/logger.ts +70 -0
- package/graph/node.ts +398 -0
- package/graph/observer.ts +361 -0
- package/interfaces/index.ts +102 -1
- package/modules/agenda/index.ts +3 -16
- package/package.json +10 -5
- package/test/graph/index.test.ts +244 -113
- package/test/graph/observer.test.ts +398 -0
- package/test/modules/agenda/node-cron.test.ts +37 -16
- package/test/modules/memory/adapters/in-memory.test.ts +2 -2
- package/test/modules/memory/adapters/meilisearch.test.ts +28 -24
- package/test/modules/memory/base.test.ts +3 -3
- package/tsconfig.json +4 -2
- package/types/index.ts +23 -2
- package/dist/graph/controller.js +0 -72
- package/dist/graph/index.js +0 -501
- package/dist/index.js +0 -41
- package/dist/interfaces/index.js +0 -17
- package/dist/modules/agenda/adapters/node-cron/index.js +0 -29
- package/dist/modules/agenda/index.js +0 -140
- package/dist/modules/embedding/adapters/ai/index.js +0 -57
- package/dist/modules/embedding/index.js +0 -59
- package/dist/modules/memory/adapters/in-memory/index.js +0 -210
- package/dist/modules/memory/adapters/meilisearch/index.js +0 -320
- package/dist/modules/memory/adapters/redis/index.js +0 -158
- package/dist/modules/memory/index.js +0 -103
- package/dist/types/index.js +0 -2
- package/dist/utils/generate-action-schema.js +0 -43
- package/dist/utils/header-builder.js +0 -34
- package/test/modules/embedding/ai.test.ts +0 -78
- package/test/modules/memory/adapters/redis.test.ts +0 -169
- package/test/services/agenda.test.ts +0 -279
@@ -1,320 +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.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
|
-
*/
|
19
|
-
class MeilisearchAdapter {
|
20
|
-
/**
|
21
|
-
* Creates an instance of MeilisearchAdapter
|
22
|
-
* @param {MeilisearchConfig} config - Configuration for Meilisearch connection
|
23
|
-
*/
|
24
|
-
constructor(config) {
|
25
|
-
this.config = config;
|
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
|
-
*/
|
35
|
-
makeRequest(path, options) {
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
37
|
-
try {
|
38
|
-
const url = `${this.config.host}${path}`;
|
39
|
-
const response = yield fetch(url, Object.assign(Object.assign({}, options), { headers: Object.assign({ "Content-Type": "application/json", Authorization: `Bearer ${this.config.apiKey}` }, options === null || options === void 0 ? void 0 : options.headers) }));
|
40
|
-
if (!response.ok) {
|
41
|
-
const errorBody = yield response.text();
|
42
|
-
throw new Error(`HTTP ${response.status}: ${errorBody || response.statusText}`);
|
43
|
-
}
|
44
|
-
return response.json();
|
45
|
-
}
|
46
|
-
catch (error) {
|
47
|
-
if (error instanceof TypeError && error.message === "Failed to fetch") {
|
48
|
-
throw new Error(`Network error: Unable to connect to Meilisearch at ${this.config.host}`);
|
49
|
-
}
|
50
|
-
throw error;
|
51
|
-
}
|
52
|
-
});
|
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
|
-
*/
|
60
|
-
initializeStorage(roomId) {
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
62
|
-
try {
|
63
|
-
let indexExists = false;
|
64
|
-
try {
|
65
|
-
yield this.makeRequest(`/indexes/${roomId}`);
|
66
|
-
indexExists = true;
|
67
|
-
}
|
68
|
-
catch (error) {
|
69
|
-
if (!indexExists) {
|
70
|
-
const createResponse = yield this.makeRequest("/indexes", {
|
71
|
-
method: "POST",
|
72
|
-
body: JSON.stringify({
|
73
|
-
uid: roomId,
|
74
|
-
primaryKey: "id",
|
75
|
-
}),
|
76
|
-
});
|
77
|
-
console.log("✅ Index creation response:", createResponse);
|
78
|
-
}
|
79
|
-
}
|
80
|
-
// Appliquer les settings seulement si l'index existe bien
|
81
|
-
yield this.makeRequest(`/indexes/${roomId}/settings`, {
|
82
|
-
method: "PATCH",
|
83
|
-
body: JSON.stringify({
|
84
|
-
searchableAttributes: this.config.searchableAttributes || [
|
85
|
-
"data",
|
86
|
-
"query",
|
87
|
-
],
|
88
|
-
sortableAttributes: this.config.sortableAttributes || ["createdAt"],
|
89
|
-
}),
|
90
|
-
});
|
91
|
-
}
|
92
|
-
catch (error) {
|
93
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
94
|
-
console.error(`❌ Error initializing storage for index ${roomId}:`, errorMessage);
|
95
|
-
throw new Error(`Failed to initialize storage for index ${roomId}: ${errorMessage}`);
|
96
|
-
}
|
97
|
-
});
|
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
|
-
*/
|
106
|
-
addDocuments(documents, roomId) {
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
108
|
-
yield this.makeRequest(`/indexes/${roomId}/documents`, {
|
109
|
-
method: "POST",
|
110
|
-
body: JSON.stringify(documents),
|
111
|
-
});
|
112
|
-
});
|
113
|
-
}
|
114
|
-
/**
|
115
|
-
* Deletes a storage index for a room
|
116
|
-
* @private
|
117
|
-
* @param {string} roomId - Room identifier
|
118
|
-
* @returns {Promise<void>}
|
119
|
-
*/
|
120
|
-
deleteStorage(roomId) {
|
121
|
-
return __awaiter(this, void 0, void 0, function* () {
|
122
|
-
yield this.makeRequest(`/indexes/${roomId}`, {
|
123
|
-
method: "DELETE",
|
124
|
-
});
|
125
|
-
});
|
126
|
-
}
|
127
|
-
/**
|
128
|
-
* Initializes the adapter for a specific room
|
129
|
-
* @param {string} roomId - Room identifier
|
130
|
-
* @returns {Promise<void>}
|
131
|
-
*/
|
132
|
-
init(roomId) {
|
133
|
-
return __awaiter(this, void 0, void 0, function* () {
|
134
|
-
try {
|
135
|
-
// Initialize the default "memories" index
|
136
|
-
yield this.initializeStorage(roomId);
|
137
|
-
}
|
138
|
-
catch (error) {
|
139
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
140
|
-
console.error("Failed to initialize default index:", errorMessage);
|
141
|
-
throw new Error(`Failed to initialize default index: ${errorMessage}`);
|
142
|
-
}
|
143
|
-
});
|
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
|
-
*/
|
155
|
-
search(query, roomId, options) {
|
156
|
-
return __awaiter(this, void 0, void 0, function* () {
|
157
|
-
const searchResults = yield this.makeRequest(`/indexes/${roomId}/search`, {
|
158
|
-
method: "POST",
|
159
|
-
body: JSON.stringify({
|
160
|
-
q: query,
|
161
|
-
limit: (options === null || options === void 0 ? void 0 : options.limit) || 10,
|
162
|
-
}),
|
163
|
-
});
|
164
|
-
if (!searchResults.hits) {
|
165
|
-
return [];
|
166
|
-
}
|
167
|
-
return searchResults.hits.map((hit) => ({
|
168
|
-
document: {
|
169
|
-
id: hit.id,
|
170
|
-
data: hit.data,
|
171
|
-
embedding: hit.embedding,
|
172
|
-
roomId: hit.roomId,
|
173
|
-
createdAt: hit.createdAt,
|
174
|
-
},
|
175
|
-
score: hit._score || 0,
|
176
|
-
}));
|
177
|
-
});
|
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
|
-
*/
|
184
|
-
createMemory(input) {
|
185
|
-
return __awaiter(this, void 0, void 0, function* () {
|
186
|
-
// Initialize storage for this roomId if needed
|
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
|
-
}
|
195
|
-
// If not found, create new memory
|
196
|
-
const memory = {
|
197
|
-
id: input.id || crypto.randomUUID(),
|
198
|
-
data: input.data,
|
199
|
-
embedding: input.embedding,
|
200
|
-
roomId: input.roomId,
|
201
|
-
createdAt: new Date(),
|
202
|
-
};
|
203
|
-
yield this.addDocuments([memory], input.roomId);
|
204
|
-
return memory;
|
205
|
-
});
|
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
|
-
*/
|
213
|
-
getMemoryById(id, roomId) {
|
214
|
-
return __awaiter(this, void 0, void 0, function* () {
|
215
|
-
try {
|
216
|
-
const result = yield this.makeRequest(`/indexes/${roomId}/documents/${id}`);
|
217
|
-
return result
|
218
|
-
? {
|
219
|
-
id: result.id,
|
220
|
-
data: result.data,
|
221
|
-
embedding: result.embedding,
|
222
|
-
roomId: result.roomId,
|
223
|
-
createdAt: result.createdAt,
|
224
|
-
}
|
225
|
-
: null;
|
226
|
-
}
|
227
|
-
catch (_a) {
|
228
|
-
return null;
|
229
|
-
}
|
230
|
-
});
|
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
|
-
*/
|
240
|
-
getMemoryByIndex(query, options) {
|
241
|
-
return __awaiter(this, void 0, void 0, function* () {
|
242
|
-
const results = yield this.search(query, options.roomId, {
|
243
|
-
limit: options.limit,
|
244
|
-
});
|
245
|
-
return results
|
246
|
-
.filter((result) => result.document.roomId === options.roomId)
|
247
|
-
.map((result) => ({
|
248
|
-
id: result.document.id,
|
249
|
-
data: result.document.data,
|
250
|
-
embedding: result.document.embedding,
|
251
|
-
roomId: result.document.roomId,
|
252
|
-
createdAt: result.document.createdAt,
|
253
|
-
}));
|
254
|
-
});
|
255
|
-
}
|
256
|
-
/**
|
257
|
-
* Retrieves all memories for a room
|
258
|
-
* @param {string} roomId - Room identifier
|
259
|
-
* @returns {Promise<BaseMemoryType[]>} Array of all memories
|
260
|
-
*/
|
261
|
-
getAllMemories(roomId) {
|
262
|
-
return __awaiter(this, void 0, void 0, function* () {
|
263
|
-
const results = yield this.makeRequest(`/indexes/${roomId}/documents`);
|
264
|
-
if (results.total === 0) {
|
265
|
-
return [];
|
266
|
-
}
|
267
|
-
return results.results.map((doc) => ({
|
268
|
-
id: doc.id,
|
269
|
-
data: doc.data,
|
270
|
-
embedding: doc.embedding,
|
271
|
-
roomId: doc.roomId,
|
272
|
-
createdAt: doc.createdAt,
|
273
|
-
}));
|
274
|
-
});
|
275
|
-
}
|
276
|
-
/**
|
277
|
-
* Deletes a specific memory
|
278
|
-
* @param {string} id - Memory identifier
|
279
|
-
* @param {string} roomId - Room identifier
|
280
|
-
* @returns {Promise<void>}
|
281
|
-
*/
|
282
|
-
clearMemoryById(id, roomId) {
|
283
|
-
return __awaiter(this, void 0, void 0, function* () {
|
284
|
-
try {
|
285
|
-
// Ensure the index exists before attempting to delete
|
286
|
-
yield this.initializeStorage(roomId);
|
287
|
-
yield this.makeRequest(`/indexes/${roomId}/documents/${id}`, {
|
288
|
-
method: "DELETE",
|
289
|
-
});
|
290
|
-
}
|
291
|
-
catch (error) {
|
292
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
293
|
-
console.error(`Error clearing memory ${id} from index ${roomId}:`, errorMessage);
|
294
|
-
throw new Error(`Failed to clear memory ${id} from index ${roomId}: ${errorMessage}`);
|
295
|
-
}
|
296
|
-
});
|
297
|
-
}
|
298
|
-
/**
|
299
|
-
* Clears all memories across all rooms
|
300
|
-
* @returns {Promise<void>}
|
301
|
-
*/
|
302
|
-
clearAllMemories() {
|
303
|
-
return __awaiter(this, void 0, void 0, function* () {
|
304
|
-
try {
|
305
|
-
// Get all indexes
|
306
|
-
const response = yield this.makeRequest("/indexes");
|
307
|
-
const indexes = response.results || [];
|
308
|
-
// Delete each index
|
309
|
-
for (const index of indexes) {
|
310
|
-
yield this.deleteStorage(index.uid);
|
311
|
-
}
|
312
|
-
}
|
313
|
-
catch (error) {
|
314
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
315
|
-
throw new Error(`Failed to clear all memories: ${errorMessage}`);
|
316
|
-
}
|
317
|
-
});
|
318
|
-
}
|
319
|
-
}
|
320
|
-
exports.MeilisearchAdapter = MeilisearchAdapter;
|
@@ -1,158 +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.RedisAdapter = void 0;
|
13
|
-
const redis_1 = require("redis");
|
14
|
-
/**
|
15
|
-
* @module RedisAdapter
|
16
|
-
* @description Adapter implementation for Redis as a memory storage solution.
|
17
|
-
* Provides integration with Redis for storing and retrieving memory entries with TTL support.
|
18
|
-
* @implements {IMemoryAdapter}
|
19
|
-
*/
|
20
|
-
class RedisAdapter {
|
21
|
-
/**
|
22
|
-
* Creates an instance of RedisAdapter
|
23
|
-
* @param {string} redisUrl - Redis connection URL
|
24
|
-
* @param {Object} options - Configuration options
|
25
|
-
* @param {string} [options.cachePrefix="memory:"] - Prefix for Redis keys
|
26
|
-
* @param {number} [options.cacheTTL=3600] - Default TTL in seconds
|
27
|
-
*/
|
28
|
-
constructor(redisUrl, options) {
|
29
|
-
this.redisUrl = redisUrl;
|
30
|
-
this.cachePrefix = options.cachePrefix || "memory:";
|
31
|
-
this.cacheTTL = options.cacheTTL || 3600;
|
32
|
-
this.redis = (0, redis_1.createClient)({
|
33
|
-
url: redisUrl,
|
34
|
-
socket: {
|
35
|
-
tls: true,
|
36
|
-
rejectUnauthorized: true,
|
37
|
-
},
|
38
|
-
});
|
39
|
-
}
|
40
|
-
/**
|
41
|
-
* Initializes the Redis connection
|
42
|
-
* @param {string} roomId - Room identifier
|
43
|
-
* @returns {Promise<void>}
|
44
|
-
*/
|
45
|
-
init(roomId) {
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
47
|
-
this.redis.on("error", (err) => console.error("Redis Client Error:", err));
|
48
|
-
yield this.redis.connect();
|
49
|
-
});
|
50
|
-
}
|
51
|
-
/**
|
52
|
-
* Creates a new memory entry in Redis
|
53
|
-
* @param {CreateMemoryInput & { embedding?: number[] }} input - Memory data with optional embedding
|
54
|
-
* @returns {Promise<BaseMemoryType | undefined>} Created memory or undefined
|
55
|
-
*/
|
56
|
-
createMemory(input) {
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
58
|
-
const memory = {
|
59
|
-
id: input.id || crypto.randomUUID(),
|
60
|
-
data: input.data,
|
61
|
-
embedding: input.embedding,
|
62
|
-
roomId: input.roomId,
|
63
|
-
createdAt: new Date(),
|
64
|
-
};
|
65
|
-
const key = memory.roomId
|
66
|
-
? `${this.cachePrefix}${memory.roomId}:${memory.id}`
|
67
|
-
: `${this.cachePrefix}${memory.id}`;
|
68
|
-
yield this.redis.set(key, JSON.stringify(memory), {
|
69
|
-
EX: this.cacheTTL,
|
70
|
-
});
|
71
|
-
return memory;
|
72
|
-
});
|
73
|
-
}
|
74
|
-
/**
|
75
|
-
* Retrieves a memory by ID and room ID from Redis
|
76
|
-
* @param {string} id - Memory identifier
|
77
|
-
* @param {string} roomId - Room identifier
|
78
|
-
* @returns {Promise<BaseMemoryType | null>} Memory entry or null if not found
|
79
|
-
*/
|
80
|
-
getMemoryById(id, roomId) {
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
82
|
-
const key = `${this.cachePrefix}${roomId}:${id}`;
|
83
|
-
const data = yield this.redis.get(key);
|
84
|
-
return data ? JSON.parse(data) : null;
|
85
|
-
});
|
86
|
-
}
|
87
|
-
/**
|
88
|
-
* Searches for memories in Redis based on pattern matching
|
89
|
-
* @param {string} query - Search query
|
90
|
-
* @param {Object} options - Search options
|
91
|
-
* @param {string} options.roomId - Room identifier
|
92
|
-
* @param {number} [options.limit] - Maximum number of results
|
93
|
-
* @returns {Promise<BaseMemoryType[]>} Array of matching memories
|
94
|
-
*/
|
95
|
-
getMemoryByIndex(query, options) {
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
97
|
-
const pattern = `${this.cachePrefix}${options.roomId}:*`;
|
98
|
-
const keys = yield this.redis.keys(pattern);
|
99
|
-
const memories = yield Promise.all(keys.map((key) => __awaiter(this, void 0, void 0, function* () {
|
100
|
-
const data = yield this.redis.get(key);
|
101
|
-
return data ? JSON.parse(data) : null;
|
102
|
-
})));
|
103
|
-
return memories.filter(Boolean).slice(0, options.limit || 10);
|
104
|
-
});
|
105
|
-
}
|
106
|
-
/**
|
107
|
-
* Retrieves all memories for a room from Redis
|
108
|
-
* @param {string} roomId - Room identifier
|
109
|
-
* @returns {Promise<BaseMemoryType[]>} Array of all memories
|
110
|
-
*/
|
111
|
-
getAllMemories(roomId) {
|
112
|
-
return __awaiter(this, void 0, void 0, function* () {
|
113
|
-
const pattern = `${this.cachePrefix}${roomId}:*`;
|
114
|
-
const keys = yield this.redis.keys(pattern);
|
115
|
-
const memories = yield Promise.all(keys.map((key) => __awaiter(this, void 0, void 0, function* () {
|
116
|
-
const data = yield this.redis.get(key);
|
117
|
-
return data ? JSON.parse(data) : null;
|
118
|
-
})));
|
119
|
-
return memories.filter(Boolean);
|
120
|
-
});
|
121
|
-
}
|
122
|
-
/**
|
123
|
-
* Deletes a specific memory from Redis
|
124
|
-
* @param {string} id - Memory identifier
|
125
|
-
* @param {string} roomId - Room identifier
|
126
|
-
* @returns {Promise<void>}
|
127
|
-
*/
|
128
|
-
clearMemoryById(id, roomId) {
|
129
|
-
return __awaiter(this, void 0, void 0, function* () {
|
130
|
-
const key = `${this.cachePrefix}${roomId}:${id}`;
|
131
|
-
yield this.redis.del(key);
|
132
|
-
});
|
133
|
-
}
|
134
|
-
/**
|
135
|
-
* Clears all memories across all rooms from Redis
|
136
|
-
* @returns {Promise<void>}
|
137
|
-
*/
|
138
|
-
clearAllMemories() {
|
139
|
-
return __awaiter(this, void 0, void 0, function* () {
|
140
|
-
const keys = yield this.redis.keys(`${this.cachePrefix}*`);
|
141
|
-
if (keys.length > 0) {
|
142
|
-
yield this.redis.del(keys);
|
143
|
-
}
|
144
|
-
});
|
145
|
-
}
|
146
|
-
/**
|
147
|
-
* Closes the Redis connection
|
148
|
-
* @returns {Promise<void>}
|
149
|
-
*/
|
150
|
-
quit() {
|
151
|
-
return __awaiter(this, void 0, void 0, function* () {
|
152
|
-
if (this.redis) {
|
153
|
-
yield this.redis.quit();
|
154
|
-
}
|
155
|
-
});
|
156
|
-
}
|
157
|
-
}
|
158
|
-
exports.RedisAdapter = RedisAdapter;
|
@@ -1,103 +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.Memory = void 0;
|
13
|
-
const interfaces_1 = require("../../interfaces");
|
14
|
-
/**
|
15
|
-
* @module Memory
|
16
|
-
* @description A module for managing memory storage and retrieval operations.
|
17
|
-
* Implements the BaseMemory abstract class and provides concrete implementations
|
18
|
-
* for memory-related operations using the provided adapter.
|
19
|
-
* @extends {BaseMemory}
|
20
|
-
*/
|
21
|
-
class Memory extends interfaces_1.BaseMemory {
|
22
|
-
/**
|
23
|
-
* Creates an instance of Memory
|
24
|
-
* @param {IMemoryAdapter} adapter - The memory adapter implementation to use
|
25
|
-
*/
|
26
|
-
constructor(adapter) {
|
27
|
-
super(adapter);
|
28
|
-
}
|
29
|
-
/**
|
30
|
-
* Initializes the memory module with default room
|
31
|
-
* @returns {Promise<void>}
|
32
|
-
*/
|
33
|
-
init() {
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
35
|
-
yield this.adapter.init("default");
|
36
|
-
});
|
37
|
-
}
|
38
|
-
/**
|
39
|
-
* Creates a new memory entry
|
40
|
-
* @param {CreateMemoryInput & { embedding?: number[] }} input - Memory data with optional embedding
|
41
|
-
* @returns {Promise<BaseMemoryType | undefined>} Created memory or undefined
|
42
|
-
*/
|
43
|
-
createMemory(input) {
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
45
|
-
return this.adapter.createMemory(input);
|
46
|
-
});
|
47
|
-
}
|
48
|
-
/**
|
49
|
-
* Retrieves a memory by ID and room ID
|
50
|
-
* @param {string} id - Memory identifier
|
51
|
-
* @param {string} roomId - Room identifier
|
52
|
-
* @returns {Promise<BaseMemoryType | null>} Memory entry or null if not found
|
53
|
-
*/
|
54
|
-
getMemoryById(id, roomId) {
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
56
|
-
return this.adapter.getMemoryById(id, roomId);
|
57
|
-
});
|
58
|
-
}
|
59
|
-
/**
|
60
|
-
* Searches for memories based on query and options
|
61
|
-
* @param {string} query - Search query
|
62
|
-
* @param {Object} options - Search options
|
63
|
-
* @param {string} options.roomId - Room identifier
|
64
|
-
* @param {number} [options.limit] - Maximum number of results to return
|
65
|
-
* @returns {Promise<BaseMemoryType[]>} Array of matching memories
|
66
|
-
*/
|
67
|
-
getMemoryByIndex(query, options) {
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
69
|
-
return this.adapter.getMemoryByIndex(query, options);
|
70
|
-
});
|
71
|
-
}
|
72
|
-
/**
|
73
|
-
* Retrieves all memories for a specific room
|
74
|
-
* @param {string} roomId - Room identifier
|
75
|
-
* @returns {Promise<BaseMemoryType[]>} Array of all memories in the room
|
76
|
-
*/
|
77
|
-
getAllMemories(roomId) {
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
79
|
-
return this.adapter.getAllMemories(roomId);
|
80
|
-
});
|
81
|
-
}
|
82
|
-
/**
|
83
|
-
* Deletes a specific memory
|
84
|
-
* @param {string} id - Memory identifier
|
85
|
-
* @param {string} roomId - Room identifier
|
86
|
-
* @returns {Promise<void>}
|
87
|
-
*/
|
88
|
-
clearMemoryById(id, roomId) {
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
90
|
-
yield this.adapter.clearMemoryById(id, roomId);
|
91
|
-
});
|
92
|
-
}
|
93
|
-
/**
|
94
|
-
* Clears all memories across all rooms
|
95
|
-
* @returns {Promise<void>}
|
96
|
-
*/
|
97
|
-
clearAllMemories() {
|
98
|
-
return __awaiter(this, void 0, void 0, function* () {
|
99
|
-
yield this.adapter.clearAllMemories();
|
100
|
-
});
|
101
|
-
}
|
102
|
-
}
|
103
|
-
exports.Memory = Memory;
|
package/dist/types/index.js
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getSchemaString = exports.generateActionSchema = void 0;
|
4
|
-
const zod_1 = require("zod");
|
5
|
-
const generateActionSchema = (graphs) => {
|
6
|
-
return graphs
|
7
|
-
.map((graph) => {
|
8
|
-
const rootNode = Array.from(graph.nodes.values())[0];
|
9
|
-
const schemaStr = rootNode.inputs
|
10
|
-
? (0, exports.getSchemaString)(rootNode.inputs)
|
11
|
-
: "No parameters";
|
12
|
-
return `Workflow: ${graph.name}\nParameters: ${schemaStr}`;
|
13
|
-
})
|
14
|
-
.join("\n\n");
|
15
|
-
};
|
16
|
-
exports.generateActionSchema = generateActionSchema;
|
17
|
-
const getSchemaString = (schema) => {
|
18
|
-
if (schema instanceof zod_1.z.ZodObject) {
|
19
|
-
const entries = Object.entries(schema.shape);
|
20
|
-
const fields = entries.map(([key, value]) => {
|
21
|
-
const description = value._def.description;
|
22
|
-
const schemaStr = (0, exports.getSchemaString)(value);
|
23
|
-
return description
|
24
|
-
? `${key}: ${schemaStr} // ${description}`
|
25
|
-
: `${key}: ${schemaStr}`;
|
26
|
-
});
|
27
|
-
return `z.object({${fields.join(", ")}})`;
|
28
|
-
}
|
29
|
-
if (schema instanceof zod_1.z.ZodArray) {
|
30
|
-
return `z.array(${(0, exports.getSchemaString)(schema.element)})`;
|
31
|
-
}
|
32
|
-
if (schema instanceof zod_1.z.ZodString) {
|
33
|
-
return "z.string()";
|
34
|
-
}
|
35
|
-
if (schema instanceof zod_1.z.ZodNumber) {
|
36
|
-
return "z.number()";
|
37
|
-
}
|
38
|
-
if (schema instanceof zod_1.z.ZodBoolean) {
|
39
|
-
return "z.boolean()";
|
40
|
-
}
|
41
|
-
return `z.unknown()`;
|
42
|
-
};
|
43
|
-
exports.getSchemaString = getSchemaString;
|
@@ -1,34 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.LLMHeaderBuilder = void 0;
|
4
|
-
class LLMHeaderBuilder {
|
5
|
-
constructor() {
|
6
|
-
this.headers = new Map();
|
7
|
-
this._result = "";
|
8
|
-
}
|
9
|
-
addHeader(key, value) {
|
10
|
-
if (Array.isArray(value)) {
|
11
|
-
this.headers.set(key, value.join("\n"));
|
12
|
-
}
|
13
|
-
else {
|
14
|
-
this.headers.set(key, value);
|
15
|
-
}
|
16
|
-
// Build result immediately
|
17
|
-
this._result = Array.from(this.headers.entries())
|
18
|
-
.filter(([_, value]) => value !== undefined)
|
19
|
-
.map(([key, value]) => `# ${key}: ${value}`)
|
20
|
-
.join("\n")
|
21
|
-
.trim();
|
22
|
-
return this;
|
23
|
-
}
|
24
|
-
valueOf() {
|
25
|
-
return this._result;
|
26
|
-
}
|
27
|
-
toString() {
|
28
|
-
return this._result;
|
29
|
-
}
|
30
|
-
static create() {
|
31
|
-
return new LLMHeaderBuilder();
|
32
|
-
}
|
33
|
-
}
|
34
|
-
exports.LLMHeaderBuilder = LLMHeaderBuilder;
|