@ai.ntellect/core 0.6.1 → 0.6.2
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/dist/create-llm-to-select-multiple-graph copy.js +201 -0
- package/dist/create-llm-to-select-multiple-graph.js +142 -0
- package/dist/graph/controller.js +6 -6
- package/dist/graph/engine.js +198 -135
- package/dist/index copy.js +76 -0
- package/dist/utils/setup-graphs.js +28 -0
- package/dist/utils/stringifiy-zod-schema.js +41 -0
- package/graph/controller.ts +7 -9
- package/graph/engine.ts +0 -3
- package/index.ts +1 -1
- package/package.json +1 -1
- package/dist/test/graph/controller.test.js +0 -170
- package/dist/test/graph/engine.test.js +0 -465
- package/dist/test/memory/adapters/meilisearch.test.js +0 -250
- package/dist/test/memory/adapters/redis.test.js +0 -143
- package/dist/test/memory/base.test.js +0 -209
- package/dist/test/services/agenda.test.js +0 -230
- package/dist/test/services/queue.test.js +0 -258
- package/dist/utils/schema-generator.js +0 -46
- package/dist/utils/state-manager.js +0 -20
@@ -1,250 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
-
};
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
const meilisearch_1 = require("@/memory/adapters/meilisearch");
|
16
|
-
const chai_1 = require("chai");
|
17
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
18
|
-
// Load environment variables
|
19
|
-
dotenv_1.default.config();
|
20
|
-
describe("MeilisearchAdapter", () => {
|
21
|
-
let meilisearchAdapter;
|
22
|
-
let mockBaseMemoryService;
|
23
|
-
const TEST_ROOM_ID = "test-room";
|
24
|
-
const testMemory = {
|
25
|
-
id: "test-id",
|
26
|
-
data: "test data",
|
27
|
-
query: "test query",
|
28
|
-
embedding: [0.1, 0.2, 0.3],
|
29
|
-
roomId: "test-room",
|
30
|
-
createdAt: new Date(),
|
31
|
-
};
|
32
|
-
beforeEach(() => {
|
33
|
-
// Use real Meilisearch if environment variables are set, otherwise mock
|
34
|
-
if (process.env.MEILISEARCH_HOST && process.env.MEILISEARCH_API_KEY) {
|
35
|
-
// Real Meilisearch configuration
|
36
|
-
// console.log("Real Meilisearch configuration");
|
37
|
-
meilisearchAdapter = new meilisearch_1.MeilisearchAdapter({
|
38
|
-
host: process.env.MEILISEARCH_HOST,
|
39
|
-
apiKey: process.env.MEILISEARCH_API_KEY,
|
40
|
-
searchableAttributes: ["content"],
|
41
|
-
sortableAttributes: ["createdAt"],
|
42
|
-
}, mockBaseMemoryService);
|
43
|
-
}
|
44
|
-
else {
|
45
|
-
// Mock fetch implementation
|
46
|
-
// console.log("Mock Meilisearch configuration");
|
47
|
-
global.fetch = (input, init) => __awaiter(void 0, void 0, void 0, function* () {
|
48
|
-
const url = input.toString();
|
49
|
-
// Mock for index check/creation
|
50
|
-
if (url.includes("/indexes")) {
|
51
|
-
if ((init === null || init === void 0 ? void 0 : init.method) === "POST") {
|
52
|
-
return new Response(JSON.stringify({ taskUid: 1 }));
|
53
|
-
}
|
54
|
-
if (url.endsWith("/indexes")) {
|
55
|
-
return new Response(JSON.stringify({ results: [] }));
|
56
|
-
}
|
57
|
-
// Mock for specific index check
|
58
|
-
if (url.includes(`/indexes/${TEST_ROOM_ID}`)) {
|
59
|
-
return new Response(JSON.stringify({
|
60
|
-
uid: TEST_ROOM_ID,
|
61
|
-
primaryKey: "id",
|
62
|
-
}));
|
63
|
-
}
|
64
|
-
if (url.includes("/indexes/memories")) {
|
65
|
-
return new Response(JSON.stringify({
|
66
|
-
uid: "memories",
|
67
|
-
primaryKey: "id",
|
68
|
-
}));
|
69
|
-
}
|
70
|
-
}
|
71
|
-
// Mock for settings
|
72
|
-
if (url.includes("/settings")) {
|
73
|
-
return new Response(JSON.stringify({ acknowledged: true }));
|
74
|
-
}
|
75
|
-
// Mock for documents
|
76
|
-
if (url.includes("/documents")) {
|
77
|
-
if ((init === null || init === void 0 ? void 0 : init.method) === "POST") {
|
78
|
-
return new Response(JSON.stringify({ taskUid: 2 }));
|
79
|
-
}
|
80
|
-
if ((init === null || init === void 0 ? void 0 : init.method) === "DELETE") {
|
81
|
-
return new Response(JSON.stringify({ taskUid: 3 }));
|
82
|
-
}
|
83
|
-
return new Response(JSON.stringify([testMemory]));
|
84
|
-
}
|
85
|
-
return new Response(JSON.stringify({}));
|
86
|
-
});
|
87
|
-
mockBaseMemoryService = {
|
88
|
-
initializeConnection: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
89
|
-
createMemory: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
90
|
-
getMemoryById: () => __awaiter(void 0, void 0, void 0, function* () { return testMemory; }),
|
91
|
-
getMemoryByIndex: () => __awaiter(void 0, void 0, void 0, function* () { return [testMemory]; }),
|
92
|
-
getAllMemories: () => __awaiter(void 0, void 0, void 0, function* () { return [testMemory]; }),
|
93
|
-
clearMemoryById: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
94
|
-
clearAllMemories: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
95
|
-
};
|
96
|
-
meilisearchAdapter = new meilisearch_1.MeilisearchAdapter({
|
97
|
-
host: "http://localhost:7700",
|
98
|
-
apiKey: "aSampleMasterKey",
|
99
|
-
searchableAttributes: ["content"],
|
100
|
-
sortableAttributes: ["createdAt"],
|
101
|
-
}, mockBaseMemoryService);
|
102
|
-
}
|
103
|
-
});
|
104
|
-
describe("Initialization", () => {
|
105
|
-
it("should initialize storage", () => __awaiter(void 0, void 0, void 0, function* () {
|
106
|
-
yield (0, chai_1.expect)(meilisearchAdapter.init()).to.not.throw;
|
107
|
-
}));
|
108
|
-
});
|
109
|
-
describe("Memory Operations", () => {
|
110
|
-
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
111
|
-
// Reset fetch mock for each test
|
112
|
-
if (!process.env.MEILISEARCH_HOST) {
|
113
|
-
global.fetch = (input, init) => __awaiter(void 0, void 0, void 0, function* () {
|
114
|
-
const url = input.toString();
|
115
|
-
// Mock for index check/creation
|
116
|
-
if (url.includes("/indexes")) {
|
117
|
-
if ((init === null || init === void 0 ? void 0 : init.method) === "POST") {
|
118
|
-
return new Response(JSON.stringify({ taskUid: 1 }));
|
119
|
-
}
|
120
|
-
if (url.endsWith("/indexes")) {
|
121
|
-
return new Response(JSON.stringify({ results: [] }));
|
122
|
-
}
|
123
|
-
// Mock for specific index check
|
124
|
-
if (url.includes(`/indexes/${TEST_ROOM_ID}`)) {
|
125
|
-
return new Response(JSON.stringify({
|
126
|
-
uid: TEST_ROOM_ID,
|
127
|
-
primaryKey: "id",
|
128
|
-
}));
|
129
|
-
}
|
130
|
-
if (url.includes("/indexes/memories")) {
|
131
|
-
return new Response(JSON.stringify({
|
132
|
-
uid: "memories",
|
133
|
-
primaryKey: "id",
|
134
|
-
}));
|
135
|
-
}
|
136
|
-
}
|
137
|
-
// Mock for settings
|
138
|
-
if (url.includes("/settings")) {
|
139
|
-
return new Response(JSON.stringify({ acknowledged: true }));
|
140
|
-
}
|
141
|
-
// Mock for documents
|
142
|
-
if (url.includes("/documents")) {
|
143
|
-
if ((init === null || init === void 0 ? void 0 : init.method) === "POST") {
|
144
|
-
return new Response(JSON.stringify({ taskUid: 2 }));
|
145
|
-
}
|
146
|
-
if ((init === null || init === void 0 ? void 0 : init.method) === "DELETE") {
|
147
|
-
return new Response(JSON.stringify({ taskUid: 3 }));
|
148
|
-
}
|
149
|
-
return new Response(JSON.stringify([testMemory]));
|
150
|
-
}
|
151
|
-
return new Response(JSON.stringify({}));
|
152
|
-
});
|
153
|
-
}
|
154
|
-
try {
|
155
|
-
yield meilisearchAdapter.init();
|
156
|
-
yield meilisearchAdapter.initializeStorage(TEST_ROOM_ID);
|
157
|
-
}
|
158
|
-
catch (error) {
|
159
|
-
console.error("Failed to initialize:", error);
|
160
|
-
throw error;
|
161
|
-
}
|
162
|
-
}));
|
163
|
-
it("should create memory", () => __awaiter(void 0, void 0, void 0, function* () {
|
164
|
-
const result = yield meilisearchAdapter.createMemory({
|
165
|
-
data: "test data",
|
166
|
-
query: "test query",
|
167
|
-
roomId: TEST_ROOM_ID,
|
168
|
-
});
|
169
|
-
(0, chai_1.expect)(result).to.exist;
|
170
|
-
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.data).to.equal("test data");
|
171
|
-
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.embedding).to.be.null;
|
172
|
-
}));
|
173
|
-
it("should search memories", () => __awaiter(void 0, void 0, void 0, function* () {
|
174
|
-
const results = yield meilisearchAdapter.getMemoryByIndex("test", {
|
175
|
-
roomId: TEST_ROOM_ID,
|
176
|
-
limit: 10,
|
177
|
-
});
|
178
|
-
(0, chai_1.expect)(results).to.be.an("array");
|
179
|
-
if (results.length > 0) {
|
180
|
-
const result = results[0];
|
181
|
-
if (result) {
|
182
|
-
result.createdAt = new Date(result.createdAt);
|
183
|
-
}
|
184
|
-
(0, chai_1.expect)(result).to.deep.equal(testMemory);
|
185
|
-
}
|
186
|
-
}));
|
187
|
-
it("should handle memory retrieval by ID", () => __awaiter(void 0, void 0, void 0, function* () {
|
188
|
-
global.fetch = (input) => __awaiter(void 0, void 0, void 0, function* () {
|
189
|
-
const url = input.toString();
|
190
|
-
if (url.includes(`/indexes/${TEST_ROOM_ID}/documents/test-id`)) {
|
191
|
-
return new Response(JSON.stringify(Object.assign(Object.assign({}, testMemory), { createdAt: testMemory.createdAt.toISOString() })));
|
192
|
-
}
|
193
|
-
return new Response(JSON.stringify({}));
|
194
|
-
});
|
195
|
-
const result = yield meilisearchAdapter.getMemoryById("test-id", TEST_ROOM_ID);
|
196
|
-
if (result) {
|
197
|
-
result.createdAt = new Date(result.createdAt);
|
198
|
-
}
|
199
|
-
(0, chai_1.expect)(result).to.deep.equal(testMemory);
|
200
|
-
}));
|
201
|
-
it("should handle non-existent memory", () => __awaiter(void 0, void 0, void 0, function* () {
|
202
|
-
global.fetch = () => __awaiter(void 0, void 0, void 0, function* () {
|
203
|
-
throw new Error("Not found");
|
204
|
-
});
|
205
|
-
const result = yield meilisearchAdapter.getMemoryById("non-existent", TEST_ROOM_ID);
|
206
|
-
(0, chai_1.expect)(result).to.be.null;
|
207
|
-
}));
|
208
|
-
it("should clear all memories", () => __awaiter(void 0, void 0, void 0, function* () {
|
209
|
-
yield (0, chai_1.expect)(meilisearchAdapter.clearAllMemories()).to.not.throw;
|
210
|
-
}));
|
211
|
-
it("should not create duplicate memory with same data", () => __awaiter(void 0, void 0, void 0, function* () {
|
212
|
-
// Create first memory
|
213
|
-
const firstMemory = yield meilisearchAdapter.createMemory({
|
214
|
-
data: "test data",
|
215
|
-
query: "test query",
|
216
|
-
roomId: TEST_ROOM_ID,
|
217
|
-
});
|
218
|
-
// Try to create second memory with same data
|
219
|
-
const secondMemory = yield meilisearchAdapter.createMemory({
|
220
|
-
data: "test data",
|
221
|
-
query: "test query",
|
222
|
-
roomId: TEST_ROOM_ID,
|
223
|
-
});
|
224
|
-
(0, chai_1.expect)(secondMemory).to.exist;
|
225
|
-
(0, chai_1.expect)(secondMemory === null || secondMemory === void 0 ? void 0 : secondMemory.id).to.equal(firstMemory === null || firstMemory === void 0 ? void 0 : firstMemory.id);
|
226
|
-
(0, chai_1.expect)(secondMemory === null || secondMemory === void 0 ? void 0 : secondMemory.data).to.equal(firstMemory === null || firstMemory === void 0 ? void 0 : firstMemory.data);
|
227
|
-
(0, chai_1.expect)(secondMemory === null || secondMemory === void 0 ? void 0 : secondMemory.query).to.equal(firstMemory === null || firstMemory === void 0 ? void 0 : firstMemory.query);
|
228
|
-
(0, chai_1.expect)(secondMemory === null || secondMemory === void 0 ? void 0 : secondMemory.roomId).to.equal(firstMemory === null || firstMemory === void 0 ? void 0 : firstMemory.roomId);
|
229
|
-
}));
|
230
|
-
it("should initialize storage", () => __awaiter(void 0, void 0, void 0, function* () {
|
231
|
-
global.fetch = (input, init) => __awaiter(void 0, void 0, void 0, function* () {
|
232
|
-
const url = input.toString();
|
233
|
-
// Mock pour la vérification de l'existence de l'index
|
234
|
-
if (url.includes(`/indexes/${TEST_ROOM_ID}`)) {
|
235
|
-
return new Response(JSON.stringify({
|
236
|
-
uid: TEST_ROOM_ID,
|
237
|
-
primaryKey: "id",
|
238
|
-
}));
|
239
|
-
}
|
240
|
-
// Mock pour les settings
|
241
|
-
if (url.includes("/settings")) {
|
242
|
-
return new Response(JSON.stringify({ acknowledged: true }));
|
243
|
-
}
|
244
|
-
return new Response(JSON.stringify({}));
|
245
|
-
});
|
246
|
-
yield (0, chai_1.expect)(meilisearchAdapter.initializeStorage(TEST_ROOM_ID)).to.not
|
247
|
-
.throw;
|
248
|
-
}));
|
249
|
-
});
|
250
|
-
});
|
@@ -1,143 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
-
};
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
const redis_1 = require("@/memory/adapters/redis");
|
16
|
-
const chai_1 = require("chai");
|
17
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
18
|
-
const ioredis_1 = __importDefault(require("ioredis"));
|
19
|
-
// Load environment variables
|
20
|
-
dotenv_1.default.config();
|
21
|
-
describe("RedisAdapter", () => {
|
22
|
-
before(function () {
|
23
|
-
this.timeout(15000);
|
24
|
-
});
|
25
|
-
let redisAdapter;
|
26
|
-
let mockBaseMemoryService;
|
27
|
-
let redisClient = null;
|
28
|
-
const fixedDate = new Date("2025-01-30T07:43:50.626Z");
|
29
|
-
const testMemory = {
|
30
|
-
id: "test-id",
|
31
|
-
data: "test data",
|
32
|
-
query: "test query",
|
33
|
-
embedding: [0.1, 0.2, 0.3],
|
34
|
-
roomId: "test-room",
|
35
|
-
createdAt: fixedDate,
|
36
|
-
};
|
37
|
-
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
38
|
-
mockBaseMemoryService = {
|
39
|
-
initializeConnection: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
40
|
-
createMemory: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
41
|
-
getMemoryById: () => __awaiter(void 0, void 0, void 0, function* () { return testMemory; }),
|
42
|
-
getMemoryByIndex: () => __awaiter(void 0, void 0, void 0, function* () { return [testMemory]; }),
|
43
|
-
getAllMemories: () => __awaiter(void 0, void 0, void 0, function* () { return [testMemory]; }),
|
44
|
-
clearMemoryById: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
45
|
-
clearAllMemories: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
46
|
-
};
|
47
|
-
// Use real Redis if environment variables are set, otherwise mock
|
48
|
-
if (process.env.REDIS_URL) {
|
49
|
-
redisClient = new ioredis_1.default(process.env.REDIS_URL);
|
50
|
-
redisAdapter = new redis_1.RedisAdapter(process.env.REDIS_URL, {
|
51
|
-
cachePrefix: "test-prefix",
|
52
|
-
cacheTTL: 3600,
|
53
|
-
});
|
54
|
-
}
|
55
|
-
else {
|
56
|
-
// Mock Redis implementation
|
57
|
-
const mockRedis = {
|
58
|
-
connect: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
59
|
-
disconnect: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
60
|
-
set: (key, value) => __awaiter(void 0, void 0, void 0, function* () { return "OK"; }),
|
61
|
-
get: (key) => __awaiter(void 0, void 0, void 0, function* () {
|
62
|
-
if (key.includes("test-id")) {
|
63
|
-
return JSON.stringify(Object.assign(Object.assign({}, testMemory), { createdAt: fixedDate.toISOString() }));
|
64
|
-
}
|
65
|
-
return null;
|
66
|
-
}),
|
67
|
-
keys: (pattern) => __awaiter(void 0, void 0, void 0, function* () {
|
68
|
-
return [`${pattern}test-id`];
|
69
|
-
}),
|
70
|
-
mget: (keys) => __awaiter(void 0, void 0, void 0, function* () {
|
71
|
-
return keys.map(() => JSON.stringify(Object.assign(Object.assign({}, testMemory), { createdAt: fixedDate.toISOString() })));
|
72
|
-
}),
|
73
|
-
del: () => __awaiter(void 0, void 0, void 0, function* () { return 1; }),
|
74
|
-
flushall: () => __awaiter(void 0, void 0, void 0, function* () { return "OK"; }),
|
75
|
-
quit: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
76
|
-
};
|
77
|
-
redisAdapter = new redis_1.RedisAdapter(mockRedis, {
|
78
|
-
cachePrefix: "test-prefix",
|
79
|
-
cacheTTL: 3600,
|
80
|
-
});
|
81
|
-
}
|
82
|
-
yield redisAdapter.initializeConnection();
|
83
|
-
}));
|
84
|
-
afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
85
|
-
var _a;
|
86
|
-
if (redisClient) {
|
87
|
-
yield redisClient.quit();
|
88
|
-
redisClient = null;
|
89
|
-
}
|
90
|
-
// @ts-ignore pour éviter l'erreur de typage
|
91
|
-
yield ((_a = redisAdapter === null || redisAdapter === void 0 ? void 0 : redisAdapter.quit) === null || _a === void 0 ? void 0 : _a.call(redisAdapter));
|
92
|
-
}));
|
93
|
-
describe("Initialization", () => {
|
94
|
-
it("should initialize storage", () => __awaiter(void 0, void 0, void 0, function* () {
|
95
|
-
yield (0, chai_1.expect)(redisAdapter.initializeConnection()).to.not.throw;
|
96
|
-
}));
|
97
|
-
});
|
98
|
-
describe("Memory Operations", () => {
|
99
|
-
const TEST_ROOM_ID = "test-room";
|
100
|
-
it("should create memory", () => __awaiter(void 0, void 0, void 0, function* () {
|
101
|
-
yield (0, chai_1.expect)(redisAdapter.createMemory({
|
102
|
-
data: "test data",
|
103
|
-
query: "test query",
|
104
|
-
roomId: TEST_ROOM_ID,
|
105
|
-
id: "test-id",
|
106
|
-
embedding: [0.1, 0.2, 0.3],
|
107
|
-
createdAt: fixedDate,
|
108
|
-
})).to.not.throw;
|
109
|
-
}));
|
110
|
-
it("should get memory by ID", () => __awaiter(void 0, void 0, void 0, function* () {
|
111
|
-
const result = yield redisAdapter.getMemoryById("test-id", TEST_ROOM_ID);
|
112
|
-
if (result) {
|
113
|
-
result.createdAt = new Date(result.createdAt);
|
114
|
-
}
|
115
|
-
(0, chai_1.expect)(result).to.deep.equal(Object.assign(Object.assign({}, testMemory), { createdAt: testMemory.createdAt }));
|
116
|
-
}));
|
117
|
-
it("should get memories by index", () => __awaiter(void 0, void 0, void 0, function* () {
|
118
|
-
const results = yield redisAdapter.getMemoryByIndex("test", {
|
119
|
-
roomId: TEST_ROOM_ID,
|
120
|
-
limit: 10,
|
121
|
-
});
|
122
|
-
(0, chai_1.expect)(results).to.be.an("array");
|
123
|
-
if (results[0]) {
|
124
|
-
results[0].createdAt = new Date(results[0].createdAt);
|
125
|
-
}
|
126
|
-
(0, chai_1.expect)(results[0]).to.deep.equal(testMemory);
|
127
|
-
}));
|
128
|
-
it("should get all memories", () => __awaiter(void 0, void 0, void 0, function* () {
|
129
|
-
const results = yield redisAdapter.getAllMemories();
|
130
|
-
(0, chai_1.expect)(results).to.be.an("array");
|
131
|
-
if (results[0]) {
|
132
|
-
results[0].createdAt = new Date(results[0].createdAt);
|
133
|
-
}
|
134
|
-
(0, chai_1.expect)(results[0]).to.deep.equal(testMemory);
|
135
|
-
}));
|
136
|
-
it("should clear memory by ID", () => __awaiter(void 0, void 0, void 0, function* () {
|
137
|
-
yield (0, chai_1.expect)(redisAdapter.clearMemoryById("test-id")).to.not.throw;
|
138
|
-
}));
|
139
|
-
it("should clear all memories", () => __awaiter(void 0, void 0, void 0, function* () {
|
140
|
-
yield (0, chai_1.expect)(redisAdapter.clearAllMemories()).to.not.throw;
|
141
|
-
}));
|
142
|
-
});
|
143
|
-
});
|
@@ -1,209 +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
|
-
const memory_1 = require("@/memory");
|
13
|
-
const chai_1 = require("chai");
|
14
|
-
/**
|
15
|
-
* Test suite for the BaseMemory service
|
16
|
-
* This suite tests the memory management system that handles storage and retrieval of memory entries
|
17
|
-
*/
|
18
|
-
// Classe concrète pour tester BaseMemory
|
19
|
-
class TestMemory extends memory_1.BaseMemory {
|
20
|
-
init() {
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
22
|
-
yield this.cacheService.initializeConnection();
|
23
|
-
});
|
24
|
-
}
|
25
|
-
createMemory(input) {
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
27
|
-
const memory = {
|
28
|
-
id: crypto.randomUUID(),
|
29
|
-
data: input.data,
|
30
|
-
query: input.query,
|
31
|
-
embedding: input.embedding || null,
|
32
|
-
roomId: input.roomId,
|
33
|
-
createdAt: new Date(),
|
34
|
-
};
|
35
|
-
yield this.cacheService.createMemory(memory, input.ttl);
|
36
|
-
return memory;
|
37
|
-
});
|
38
|
-
}
|
39
|
-
getMemoryById(id, roomId) {
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
41
|
-
return this.cacheService.getMemoryById(id);
|
42
|
-
});
|
43
|
-
}
|
44
|
-
getMemoryByIndex(query, options) {
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
46
|
-
return this.cacheService.getMemoryByIndex(query, options);
|
47
|
-
});
|
48
|
-
}
|
49
|
-
getAllMemories(roomId) {
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
51
|
-
return this.cacheService.getAllMemories();
|
52
|
-
});
|
53
|
-
}
|
54
|
-
clearMemoryById(id, roomId) {
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
56
|
-
yield this.cacheService.clearMemoryById(id);
|
57
|
-
});
|
58
|
-
}
|
59
|
-
clearAllMemories() {
|
60
|
-
return __awaiter(this, void 0, void 0, function* () {
|
61
|
-
yield this.cacheService.clearAllMemories();
|
62
|
-
});
|
63
|
-
}
|
64
|
-
}
|
65
|
-
describe("BaseMemory", () => {
|
66
|
-
let memory;
|
67
|
-
let mockMemoryService;
|
68
|
-
const TEST_ROOM_ID = "test-room";
|
69
|
-
// Mock data for testing
|
70
|
-
const testMemory = {
|
71
|
-
id: "test-id",
|
72
|
-
data: "test data",
|
73
|
-
query: "test query",
|
74
|
-
embedding: [0.1, 0.2, 0.3],
|
75
|
-
roomId: "test-room",
|
76
|
-
createdAt: new Date(),
|
77
|
-
};
|
78
|
-
beforeEach(() => {
|
79
|
-
// Create mock implementation of BaseMemoryService
|
80
|
-
mockMemoryService = {
|
81
|
-
initializeConnection: () => __awaiter(void 0, void 0, void 0, function* () { return Promise.resolve(); }),
|
82
|
-
createMemory: (memory) => __awaiter(void 0, void 0, void 0, function* () { return Promise.resolve(); }),
|
83
|
-
getMemoryById: (id) => __awaiter(void 0, void 0, void 0, function* () { return Promise.resolve(testMemory); }),
|
84
|
-
getMemoryByIndex: (query, options) => __awaiter(void 0, void 0, void 0, function* () { return Promise.resolve([testMemory]); }),
|
85
|
-
getAllMemories: () => __awaiter(void 0, void 0, void 0, function* () { return Promise.resolve([testMemory]); }),
|
86
|
-
clearMemoryById: (id) => __awaiter(void 0, void 0, void 0, function* () { return Promise.resolve(); }),
|
87
|
-
clearAllMemories: () => __awaiter(void 0, void 0, void 0, function* () { return Promise.resolve(); }),
|
88
|
-
};
|
89
|
-
memory = new TestMemory(mockMemoryService);
|
90
|
-
});
|
91
|
-
describe("Initialization", () => {
|
92
|
-
it("should initialize the memory service", () => __awaiter(void 0, void 0, void 0, function* () {
|
93
|
-
let initCalled = false;
|
94
|
-
mockMemoryService.initializeConnection = () => __awaiter(void 0, void 0, void 0, function* () {
|
95
|
-
initCalled = true;
|
96
|
-
});
|
97
|
-
yield memory.init();
|
98
|
-
(0, chai_1.expect)(initCalled).to.be.true;
|
99
|
-
}));
|
100
|
-
});
|
101
|
-
describe("Memory Creation", () => {
|
102
|
-
it("should create a new memory entry", () => __awaiter(void 0, void 0, void 0, function* () {
|
103
|
-
const input = {
|
104
|
-
data: "test data",
|
105
|
-
query: "test query",
|
106
|
-
roomId: "test-room",
|
107
|
-
ttl: 3600,
|
108
|
-
};
|
109
|
-
const result = yield memory.createMemory(input);
|
110
|
-
(0, chai_1.expect)(result).to.exist;
|
111
|
-
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.data).to.equal(input.data);
|
112
|
-
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.query).to.equal(input.query);
|
113
|
-
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.roomId).to.equal(input.roomId);
|
114
|
-
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.id).to.be.a("string");
|
115
|
-
}));
|
116
|
-
it("should create memory with embedding", () => __awaiter(void 0, void 0, void 0, function* () {
|
117
|
-
const input = {
|
118
|
-
data: "test data",
|
119
|
-
query: "test query",
|
120
|
-
roomId: "test-room",
|
121
|
-
embedding: [0.1, 0.2, 0.3],
|
122
|
-
};
|
123
|
-
const result = yield memory.createMemory(input);
|
124
|
-
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.embedding).to.deep.equal(input.embedding);
|
125
|
-
}));
|
126
|
-
});
|
127
|
-
describe("Memory Retrieval", () => {
|
128
|
-
it("should retrieve memory by ID", () => __awaiter(void 0, void 0, void 0, function* () {
|
129
|
-
const result = yield memory.getMemoryById("test-id", TEST_ROOM_ID);
|
130
|
-
(0, chai_1.expect)(result).to.deep.equal(testMemory);
|
131
|
-
}));
|
132
|
-
it("should retrieve memories by index", () => __awaiter(void 0, void 0, void 0, function* () {
|
133
|
-
const results = yield memory.getMemoryByIndex("test query", {
|
134
|
-
roomId: "test-room",
|
135
|
-
limit: 10,
|
136
|
-
});
|
137
|
-
(0, chai_1.expect)(results).to.be.an("array");
|
138
|
-
(0, chai_1.expect)(results[0]).to.deep.equal(testMemory);
|
139
|
-
}));
|
140
|
-
it("should retrieve all memories", () => __awaiter(void 0, void 0, void 0, function* () {
|
141
|
-
const results = yield memory.getAllMemories(TEST_ROOM_ID);
|
142
|
-
(0, chai_1.expect)(results).to.be.an("array");
|
143
|
-
}));
|
144
|
-
});
|
145
|
-
describe("Memory Clearing", () => {
|
146
|
-
it("should clear memory by ID", () => __awaiter(void 0, void 0, void 0, function* () {
|
147
|
-
yield memory.clearMemoryById("test-id", TEST_ROOM_ID);
|
148
|
-
}));
|
149
|
-
it("should clear all memories", () => __awaiter(void 0, void 0, void 0, function* () {
|
150
|
-
yield memory.clearAllMemories();
|
151
|
-
}));
|
152
|
-
});
|
153
|
-
describe("Error Handling", () => {
|
154
|
-
it("should handle errors during memory creation", () => __awaiter(void 0, void 0, void 0, function* () {
|
155
|
-
mockMemoryService.createMemory = () => __awaiter(void 0, void 0, void 0, function* () {
|
156
|
-
throw new Error("Creation failed");
|
157
|
-
});
|
158
|
-
try {
|
159
|
-
yield memory.createMemory({
|
160
|
-
data: "test",
|
161
|
-
query: "test",
|
162
|
-
roomId: "test",
|
163
|
-
});
|
164
|
-
chai_1.expect.fail("Should have thrown an error");
|
165
|
-
}
|
166
|
-
catch (error) {
|
167
|
-
(0, chai_1.expect)(error).to.be.instanceOf(Error);
|
168
|
-
(0, chai_1.expect)(error.message).to.equal("Creation failed");
|
169
|
-
}
|
170
|
-
}));
|
171
|
-
it("should handle errors during memory retrieval", () => __awaiter(void 0, void 0, void 0, function* () {
|
172
|
-
mockMemoryService.getMemoryById = () => __awaiter(void 0, void 0, void 0, function* () {
|
173
|
-
throw new Error("Retrieval failed");
|
174
|
-
});
|
175
|
-
try {
|
176
|
-
yield memory.getMemoryById("test-id", TEST_ROOM_ID);
|
177
|
-
chai_1.expect.fail("Should have thrown an error");
|
178
|
-
}
|
179
|
-
catch (error) {
|
180
|
-
(0, chai_1.expect)(error).to.be.instanceOf(Error);
|
181
|
-
(0, chai_1.expect)(error.message).to.equal("Retrieval failed");
|
182
|
-
}
|
183
|
-
}));
|
184
|
-
});
|
185
|
-
describe("Edge Cases", () => {
|
186
|
-
it("should handle undefined embedding", () => __awaiter(void 0, void 0, void 0, function* () {
|
187
|
-
const input = {
|
188
|
-
data: "test data",
|
189
|
-
query: "test query",
|
190
|
-
roomId: "test-room",
|
191
|
-
embedding: undefined,
|
192
|
-
};
|
193
|
-
const result = yield memory.createMemory(input);
|
194
|
-
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.embedding).to.be.null;
|
195
|
-
}));
|
196
|
-
it("should handle empty query results", () => __awaiter(void 0, void 0, void 0, function* () {
|
197
|
-
mockMemoryService.getMemoryByIndex = () => __awaiter(void 0, void 0, void 0, function* () { return []; });
|
198
|
-
const results = yield memory.getMemoryByIndex("nonexistent", {
|
199
|
-
roomId: "test-room",
|
200
|
-
});
|
201
|
-
(0, chai_1.expect)(results).to.be.an("array").that.is.empty;
|
202
|
-
}));
|
203
|
-
it("should handle non-existent memory ID", () => __awaiter(void 0, void 0, void 0, function* () {
|
204
|
-
mockMemoryService.getMemoryById = () => __awaiter(void 0, void 0, void 0, function* () { return null; });
|
205
|
-
const result = yield memory.getMemoryById("nonexistent", TEST_ROOM_ID);
|
206
|
-
(0, chai_1.expect)(result).to.be.null;
|
207
|
-
}));
|
208
|
-
});
|
209
|
-
});
|