@ai.ntellect/core 0.7.8 → 1.0.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/README.md +158 -81
- package/index.ts +462 -22
- package/package copy.json +21 -0
- package/package.json +9 -44
- package/tsconfig.json +108 -22
- package/types.ts +62 -0
- package/utils/executor.ts +42 -0
- package/.mocharc.json +0 -5
- package/dist/graph/controller.d.ts +0 -31
- package/dist/graph/controller.d.ts.map +0 -1
- package/dist/graph/controller.js +0 -71
- package/dist/graph/controller.js.map +0 -1
- package/dist/graph/event-manager.d.ts +0 -93
- package/dist/graph/event-manager.d.ts.map +0 -1
- package/dist/graph/event-manager.js +0 -296
- package/dist/graph/event-manager.js.map +0 -1
- package/dist/graph/index.d.ts +0 -159
- package/dist/graph/index.d.ts.map +0 -1
- package/dist/graph/index.js +0 -303
- package/dist/graph/index.js.map +0 -1
- package/dist/graph/logger.d.ts +0 -46
- package/dist/graph/logger.d.ts.map +0 -1
- package/dist/graph/logger.js +0 -69
- package/dist/graph/logger.js.map +0 -1
- package/dist/graph/node.d.ts +0 -93
- package/dist/graph/node.d.ts.map +0 -1
- package/dist/graph/node.js +0 -259
- package/dist/graph/node.js.map +0 -1
- package/dist/graph/observer.d.ts +0 -115
- package/dist/graph/observer.d.ts.map +0 -1
- package/dist/graph/observer.js +0 -198
- package/dist/graph/observer.js.map +0 -1
- package/dist/index.d.ts +0 -26
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -42
- package/dist/index.js.map +0 -1
- package/dist/interfaces/index.d.ts +0 -447
- package/dist/interfaces/index.d.ts.map +0 -1
- package/dist/interfaces/index.js +0 -75
- package/dist/interfaces/index.js.map +0 -1
- package/dist/modules/agenda/adapters/node-cron/index.d.ts +0 -17
- package/dist/modules/agenda/adapters/node-cron/index.d.ts.map +0 -1
- package/dist/modules/agenda/adapters/node-cron/index.js +0 -30
- package/dist/modules/agenda/adapters/node-cron/index.js.map +0 -1
- package/dist/modules/agenda/index.d.ts +0 -63
- package/dist/modules/agenda/index.d.ts.map +0 -1
- package/dist/modules/agenda/index.js +0 -141
- package/dist/modules/agenda/index.js.map +0 -1
- package/dist/modules/embedding/adapters/ai/index.d.ts +0 -29
- package/dist/modules/embedding/adapters/ai/index.d.ts.map +0 -1
- package/dist/modules/embedding/adapters/ai/index.js +0 -58
- package/dist/modules/embedding/adapters/ai/index.js.map +0 -1
- package/dist/modules/embedding/index.d.ts +0 -36
- package/dist/modules/embedding/index.d.ts.map +0 -1
- package/dist/modules/embedding/index.js +0 -60
- package/dist/modules/embedding/index.js.map +0 -1
- package/dist/modules/memory/adapters/in-memory/index.d.ts +0 -120
- package/dist/modules/memory/adapters/in-memory/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/in-memory/index.js +0 -211
- package/dist/modules/memory/adapters/in-memory/index.js.map +0 -1
- package/dist/modules/memory/adapters/meilisearch/index.d.ts +0 -110
- package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/meilisearch/index.js +0 -321
- package/dist/modules/memory/adapters/meilisearch/index.js.map +0 -1
- package/dist/modules/memory/adapters/redis/index.d.ts +0 -82
- package/dist/modules/memory/adapters/redis/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/redis/index.js +0 -159
- package/dist/modules/memory/adapters/redis/index.js.map +0 -1
- package/dist/modules/memory/index.d.ts +0 -67
- package/dist/modules/memory/index.d.ts.map +0 -1
- package/dist/modules/memory/index.js +0 -104
- package/dist/modules/memory/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -170
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -3
- package/dist/types/index.js.map +0 -1
- package/dist/utils/generate-action-schema.d.ts +0 -5
- package/dist/utils/generate-action-schema.d.ts.map +0 -1
- package/dist/utils/generate-action-schema.js +0 -44
- package/dist/utils/generate-action-schema.js.map +0 -1
- package/dist/utils/header-builder.d.ts +0 -12
- package/dist/utils/header-builder.d.ts.map +0 -1
- package/dist/utils/header-builder.js +0 -35
- package/dist/utils/header-builder.js.map +0 -1
- package/graph/controller.ts +0 -74
- package/graph/event-manager.ts +0 -363
- package/graph/index.ts +0 -395
- package/graph/logger.ts +0 -70
- package/graph/node.ts +0 -327
- package/graph/observer.ts +0 -368
- package/interfaces/index.ts +0 -548
- package/modules/agenda/adapters/node-cron/index.ts +0 -25
- package/modules/agenda/index.ts +0 -146
- package/modules/embedding/adapters/ai/index.ts +0 -42
- package/modules/embedding/index.ts +0 -45
- package/modules/memory/adapters/in-memory/index.ts +0 -207
- package/modules/memory/adapters/meilisearch/index.ts +0 -361
- package/modules/memory/adapters/redis/index.ts +0 -164
- package/modules/memory/index.ts +0 -93
- package/test/graph/controller.test.ts +0 -187
- package/test/graph/event-manager.test.ts +0 -118
- package/test/graph/index.test.ts +0 -684
- package/test/graph/node.test.ts +0 -655
- package/test/graph/observer.test.ts +0 -398
- package/test/modules/agenda/node-cron.test.ts +0 -307
- package/test/modules/memory/adapters/in-memory.test.ts +0 -153
- package/test/modules/memory/adapters/meilisearch.test.ts +0 -287
- package/test/modules/memory/base.test.ts +0 -230
- package/types/index.ts +0 -190
- package/utils/generate-action-schema.ts +0 -46
- package/utils/header-builder.ts +0 -40
@@ -1,153 +0,0 @@
|
|
1
|
-
import { expect } from "chai";
|
2
|
-
import { InMemoryAdapter } from "../../../../modules/memory/adapters/in-memory";
|
3
|
-
import { BaseMemoryType } from "../../../../types";
|
4
|
-
|
5
|
-
describe("InMemoryAdapter", () => {
|
6
|
-
let inMemoryAdapter: InMemoryAdapter;
|
7
|
-
const fixedDate = new Date("2025-01-30T07:43:50.626Z");
|
8
|
-
const TEST_ROOM_ID = "test-room";
|
9
|
-
|
10
|
-
const testMemory: BaseMemoryType = {
|
11
|
-
id: "test-id",
|
12
|
-
data: "test data",
|
13
|
-
roomId: TEST_ROOM_ID,
|
14
|
-
createdAt: fixedDate,
|
15
|
-
};
|
16
|
-
|
17
|
-
beforeEach(async () => {
|
18
|
-
inMemoryAdapter = new InMemoryAdapter();
|
19
|
-
await inMemoryAdapter.init(TEST_ROOM_ID);
|
20
|
-
});
|
21
|
-
|
22
|
-
describe("Initialization", () => {
|
23
|
-
it("should initialize storage", async () => {
|
24
|
-
await expect(inMemoryAdapter.init("new-room")).to.not.throw;
|
25
|
-
const memories = await inMemoryAdapter.getAllMemories("new-room");
|
26
|
-
expect(memories).to.be.an("array").that.is.empty;
|
27
|
-
});
|
28
|
-
});
|
29
|
-
|
30
|
-
describe("Memory Operations", () => {
|
31
|
-
it("should create memory", async () => {
|
32
|
-
const memory = await inMemoryAdapter.createMemory({
|
33
|
-
data: "test data",
|
34
|
-
roomId: TEST_ROOM_ID,
|
35
|
-
id: "test-id",
|
36
|
-
embedding: [0.1, 0.2, 0.3],
|
37
|
-
});
|
38
|
-
|
39
|
-
expect(memory).to.have.property("id");
|
40
|
-
expect(memory?.data).to.equal("test data");
|
41
|
-
expect(memory?.roomId).to.equal(TEST_ROOM_ID);
|
42
|
-
});
|
43
|
-
|
44
|
-
it("should not create duplicate memory", async () => {
|
45
|
-
// Create first memory
|
46
|
-
const memory1 = await inMemoryAdapter.createMemory({
|
47
|
-
data: "test data",
|
48
|
-
roomId: TEST_ROOM_ID,
|
49
|
-
id: "test-id",
|
50
|
-
});
|
51
|
-
|
52
|
-
// Try to create duplicate
|
53
|
-
const memory2 = await inMemoryAdapter.createMemory({
|
54
|
-
data: "test data",
|
55
|
-
roomId: TEST_ROOM_ID,
|
56
|
-
id: "another-id",
|
57
|
-
});
|
58
|
-
|
59
|
-
expect(memory2?.id).to.equal(memory1?.id);
|
60
|
-
});
|
61
|
-
|
62
|
-
it("should get memory by ID", async () => {
|
63
|
-
await inMemoryAdapter.createMemory({
|
64
|
-
data: testMemory.data,
|
65
|
-
roomId: testMemory.roomId,
|
66
|
-
id: testMemory.id,
|
67
|
-
embedding: testMemory.embedding,
|
68
|
-
});
|
69
|
-
|
70
|
-
const result = await inMemoryAdapter.getMemoryById(
|
71
|
-
"test-id",
|
72
|
-
TEST_ROOM_ID
|
73
|
-
);
|
74
|
-
expect(result).to.have.property("id", "test-id");
|
75
|
-
});
|
76
|
-
|
77
|
-
it("should get memories by index", async () => {
|
78
|
-
// Create test memories
|
79
|
-
await inMemoryAdapter.createMemory({
|
80
|
-
data: "test data one",
|
81
|
-
roomId: TEST_ROOM_ID,
|
82
|
-
id: "test-id-1",
|
83
|
-
});
|
84
|
-
await inMemoryAdapter.createMemory({
|
85
|
-
data: "test data two",
|
86
|
-
roomId: TEST_ROOM_ID,
|
87
|
-
id: "test-id-2",
|
88
|
-
});
|
89
|
-
|
90
|
-
const results = await inMemoryAdapter.getMemoryByIndex("one", {
|
91
|
-
roomId: TEST_ROOM_ID,
|
92
|
-
limit: 10,
|
93
|
-
});
|
94
|
-
|
95
|
-
expect(results).to.be.an("array");
|
96
|
-
expect(results).to.have.lengthOf(1);
|
97
|
-
expect(results[0].data).to.include("one");
|
98
|
-
});
|
99
|
-
|
100
|
-
it("should get all memories", async () => {
|
101
|
-
// Create multiple memories
|
102
|
-
await inMemoryAdapter.createMemory({
|
103
|
-
data: "test data 1",
|
104
|
-
roomId: TEST_ROOM_ID,
|
105
|
-
id: "test-id-1",
|
106
|
-
});
|
107
|
-
await inMemoryAdapter.createMemory({
|
108
|
-
data: "test data 2",
|
109
|
-
roomId: TEST_ROOM_ID,
|
110
|
-
id: "test-id-2",
|
111
|
-
});
|
112
|
-
|
113
|
-
const results = await inMemoryAdapter.getAllMemories(TEST_ROOM_ID);
|
114
|
-
expect(results).to.be.an("array");
|
115
|
-
expect(results).to.have.lengthOf(2);
|
116
|
-
});
|
117
|
-
|
118
|
-
it("should clear memory by ID", async () => {
|
119
|
-
// Create a memory
|
120
|
-
await inMemoryAdapter.createMemory({
|
121
|
-
data: "test data",
|
122
|
-
roomId: TEST_ROOM_ID,
|
123
|
-
id: "test-id",
|
124
|
-
});
|
125
|
-
|
126
|
-
await inMemoryAdapter.clearMemoryById("test-id", TEST_ROOM_ID);
|
127
|
-
const result = await inMemoryAdapter.getMemoryById(
|
128
|
-
"test-id",
|
129
|
-
TEST_ROOM_ID
|
130
|
-
);
|
131
|
-
expect(result).to.be.null;
|
132
|
-
});
|
133
|
-
|
134
|
-
it("should clear all memories", async () => {
|
135
|
-
// Create multiple memories
|
136
|
-
await inMemoryAdapter.createMemory({
|
137
|
-
data: "test data 1",
|
138
|
-
roomId: TEST_ROOM_ID,
|
139
|
-
id: "test-id-1",
|
140
|
-
});
|
141
|
-
await inMemoryAdapter.createMemory({
|
142
|
-
data: "test data 2",
|
143
|
-
roomId: TEST_ROOM_ID,
|
144
|
-
id: "test-id-2",
|
145
|
-
});
|
146
|
-
|
147
|
-
await inMemoryAdapter.clearAllMemories();
|
148
|
-
const results = await inMemoryAdapter.getAllMemories(TEST_ROOM_ID);
|
149
|
-
expect(results).to.be.an("array");
|
150
|
-
expect(results).to.have.lengthOf(0);
|
151
|
-
});
|
152
|
-
});
|
153
|
-
});
|
@@ -1,287 +0,0 @@
|
|
1
|
-
import { expect } from "chai";
|
2
|
-
import dotenv from "dotenv";
|
3
|
-
import { MeilisearchAdapter } from "../../../../modules/memory/adapters/meilisearch";
|
4
|
-
import { BaseMemoryType } from "../../../../types";
|
5
|
-
// Load environment variables
|
6
|
-
dotenv.config();
|
7
|
-
|
8
|
-
describe("MeilisearchAdapter", () => {
|
9
|
-
let meilisearchAdapter: MeilisearchAdapter;
|
10
|
-
const TEST_ROOM_ID = "test-room";
|
11
|
-
|
12
|
-
const testMemory: BaseMemoryType = {
|
13
|
-
id: "test-id",
|
14
|
-
data: "test data",
|
15
|
-
roomId: "test-room",
|
16
|
-
createdAt: new Date(),
|
17
|
-
};
|
18
|
-
|
19
|
-
beforeEach(async function () {
|
20
|
-
this.timeout(10000); // Augmenter le timeout
|
21
|
-
|
22
|
-
// Mock fetch pour simuler l'existence de l'index
|
23
|
-
global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
24
|
-
const url = input.toString();
|
25
|
-
|
26
|
-
// Mock pour index check/creation
|
27
|
-
if (url.includes("/indexes")) {
|
28
|
-
if (init?.method === "POST") {
|
29
|
-
return new Response(JSON.stringify({ taskUid: 1 }));
|
30
|
-
}
|
31
|
-
if (url.endsWith("/indexes")) {
|
32
|
-
return new Response(
|
33
|
-
JSON.stringify({
|
34
|
-
results: [{ uid: TEST_ROOM_ID }], // Simuler l'existence de l'index
|
35
|
-
})
|
36
|
-
);
|
37
|
-
}
|
38
|
-
if (url.includes(`/indexes/${TEST_ROOM_ID}`)) {
|
39
|
-
return new Response(
|
40
|
-
JSON.stringify({
|
41
|
-
uid: TEST_ROOM_ID,
|
42
|
-
primaryKey: "id",
|
43
|
-
})
|
44
|
-
);
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
// Mock pour settings et autres endpoints
|
49
|
-
if (url.includes("/settings")) {
|
50
|
-
return new Response(JSON.stringify({ acknowledged: true }));
|
51
|
-
}
|
52
|
-
|
53
|
-
return new Response(JSON.stringify({}));
|
54
|
-
};
|
55
|
-
|
56
|
-
meilisearchAdapter = new MeilisearchAdapter({
|
57
|
-
host: "http://localhost:7700",
|
58
|
-
apiKey: "test_key",
|
59
|
-
searchableAttributes: ["content"],
|
60
|
-
sortableAttributes: ["createdAt"],
|
61
|
-
});
|
62
|
-
|
63
|
-
await meilisearchAdapter.init(TEST_ROOM_ID);
|
64
|
-
});
|
65
|
-
|
66
|
-
describe("Initialization", () => {
|
67
|
-
it("should initialize storage", async () => {
|
68
|
-
await expect(meilisearchAdapter.init("test-room")).to.not.throw;
|
69
|
-
});
|
70
|
-
});
|
71
|
-
|
72
|
-
describe("Memory Operations", () => {
|
73
|
-
beforeEach(async () => {
|
74
|
-
// Reset fetch mock for each test
|
75
|
-
if (!process.env.MEILISEARCH_HOST) {
|
76
|
-
global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
77
|
-
const url = input.toString();
|
78
|
-
|
79
|
-
// Mock for index check/creation
|
80
|
-
if (url.includes("/indexes")) {
|
81
|
-
if (init?.method === "POST") {
|
82
|
-
return new Response(JSON.stringify({ taskUid: 1 }));
|
83
|
-
}
|
84
|
-
if (url.endsWith("/indexes")) {
|
85
|
-
return new Response(JSON.stringify({ results: [] }));
|
86
|
-
}
|
87
|
-
// Mock for specific index check
|
88
|
-
if (url.includes(`/indexes/${TEST_ROOM_ID}`)) {
|
89
|
-
return new Response(
|
90
|
-
JSON.stringify({
|
91
|
-
uid: TEST_ROOM_ID,
|
92
|
-
primaryKey: "id",
|
93
|
-
})
|
94
|
-
);
|
95
|
-
}
|
96
|
-
if (url.includes("/indexes/memories")) {
|
97
|
-
return new Response(
|
98
|
-
JSON.stringify({
|
99
|
-
uid: "memories",
|
100
|
-
primaryKey: "id",
|
101
|
-
})
|
102
|
-
);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
// Mock for settings
|
107
|
-
if (url.includes("/settings")) {
|
108
|
-
return new Response(JSON.stringify({ acknowledged: true }));
|
109
|
-
}
|
110
|
-
|
111
|
-
// Mock for documents
|
112
|
-
if (url.includes("/documents")) {
|
113
|
-
if (init?.method === "POST") {
|
114
|
-
return new Response(JSON.stringify({ taskUid: 2 }));
|
115
|
-
}
|
116
|
-
if (init?.method === "DELETE") {
|
117
|
-
return new Response(JSON.stringify({ taskUid: 3 }));
|
118
|
-
}
|
119
|
-
return new Response(JSON.stringify([testMemory]));
|
120
|
-
}
|
121
|
-
|
122
|
-
return new Response(JSON.stringify({}));
|
123
|
-
};
|
124
|
-
}
|
125
|
-
|
126
|
-
try {
|
127
|
-
await meilisearchAdapter.init(TEST_ROOM_ID);
|
128
|
-
} catch (error) {
|
129
|
-
console.error("Failed to initialize:", error);
|
130
|
-
throw error;
|
131
|
-
}
|
132
|
-
});
|
133
|
-
|
134
|
-
it("should create memory", async () => {
|
135
|
-
const input = {
|
136
|
-
id: "test-id",
|
137
|
-
roomId: "test-room",
|
138
|
-
data: "test data",
|
139
|
-
};
|
140
|
-
|
141
|
-
const result = await meilisearchAdapter.createMemory(input);
|
142
|
-
expect(result?.embedding).to.be.undefined;
|
143
|
-
});
|
144
|
-
|
145
|
-
it("should search memories", async () => {
|
146
|
-
const results = await meilisearchAdapter.getMemoryByIndex("test", {
|
147
|
-
roomId: TEST_ROOM_ID,
|
148
|
-
limit: 10,
|
149
|
-
});
|
150
|
-
|
151
|
-
expect(results).to.be.an("array");
|
152
|
-
if (results.length > 0) {
|
153
|
-
const result = results[0];
|
154
|
-
if (result) {
|
155
|
-
result.createdAt = new Date(result.createdAt);
|
156
|
-
}
|
157
|
-
expect(result).to.deep.equal(testMemory);
|
158
|
-
}
|
159
|
-
});
|
160
|
-
|
161
|
-
it("should handle memory retrieval by ID", async () => {
|
162
|
-
const testDate = new Date("2025-02-11T08:24:38.251Z");
|
163
|
-
|
164
|
-
const mockData = {
|
165
|
-
id: "test-id",
|
166
|
-
roomId: "test-room",
|
167
|
-
data: "test data",
|
168
|
-
createdAt: testDate.toISOString(),
|
169
|
-
embedding: undefined,
|
170
|
-
};
|
171
|
-
|
172
|
-
global.fetch = async (input: RequestInfo | URL) => {
|
173
|
-
const url = input.toString();
|
174
|
-
if (url.includes(`/indexes/test-room/documents/test-id`)) {
|
175
|
-
return new Response(JSON.stringify(mockData));
|
176
|
-
}
|
177
|
-
return new Response(JSON.stringify({}));
|
178
|
-
};
|
179
|
-
|
180
|
-
const result = await meilisearchAdapter.getMemoryById(
|
181
|
-
"test-id",
|
182
|
-
"test-room"
|
183
|
-
);
|
184
|
-
|
185
|
-
expect(result?.id).to.equal(mockData.id);
|
186
|
-
expect(result?.roomId).to.equal(mockData.roomId);
|
187
|
-
expect(result?.data).to.equal(mockData.data);
|
188
|
-
expect(result?.createdAt).to.equal(mockData.createdAt); // Compare directement les strings
|
189
|
-
expect(result?.embedding).to.be.undefined;
|
190
|
-
});
|
191
|
-
|
192
|
-
it("should handle non-existent memory", async () => {
|
193
|
-
global.fetch = async (): Promise<Response> => {
|
194
|
-
throw new Error("Not found");
|
195
|
-
};
|
196
|
-
|
197
|
-
const result = await meilisearchAdapter.getMemoryById(
|
198
|
-
"non-existent",
|
199
|
-
TEST_ROOM_ID
|
200
|
-
);
|
201
|
-
expect(result).to.be.null;
|
202
|
-
});
|
203
|
-
|
204
|
-
it("should clear all memories", async () => {
|
205
|
-
// S'assurer que l'index existe avant de le supprimer
|
206
|
-
await meilisearchAdapter.init(TEST_ROOM_ID);
|
207
|
-
await expect(meilisearchAdapter.clearAllMemories()).to.not.throw;
|
208
|
-
});
|
209
|
-
|
210
|
-
it("should not create duplicate memory with same data", async () => {
|
211
|
-
// Override fetch mock for this test
|
212
|
-
const firstMemoryId = "test-memory-id";
|
213
|
-
const mockMemory = {
|
214
|
-
id: firstMemoryId,
|
215
|
-
data: "test data",
|
216
|
-
roomId: TEST_ROOM_ID,
|
217
|
-
embedding: null,
|
218
|
-
createdAt: new Date().toISOString(),
|
219
|
-
};
|
220
|
-
|
221
|
-
global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
222
|
-
const url = input.toString();
|
223
|
-
|
224
|
-
if (url.includes("/search")) {
|
225
|
-
return new Response(
|
226
|
-
JSON.stringify({
|
227
|
-
hits: [{ ...mockMemory }],
|
228
|
-
})
|
229
|
-
);
|
230
|
-
}
|
231
|
-
|
232
|
-
if (url.includes("/indexes")) {
|
233
|
-
if (init?.method === "POST") {
|
234
|
-
return new Response(JSON.stringify({ taskUid: 1 }));
|
235
|
-
}
|
236
|
-
return new Response(
|
237
|
-
JSON.stringify({
|
238
|
-
uid: TEST_ROOM_ID,
|
239
|
-
primaryKey: "id",
|
240
|
-
})
|
241
|
-
);
|
242
|
-
}
|
243
|
-
|
244
|
-
return new Response(JSON.stringify({}));
|
245
|
-
};
|
246
|
-
|
247
|
-
const firstMemory = await meilisearchAdapter.createMemory({
|
248
|
-
data: "test data",
|
249
|
-
roomId: TEST_ROOM_ID,
|
250
|
-
});
|
251
|
-
|
252
|
-
const secondMemory = await meilisearchAdapter.createMemory({
|
253
|
-
data: "test data",
|
254
|
-
roomId: TEST_ROOM_ID,
|
255
|
-
});
|
256
|
-
|
257
|
-
expect(secondMemory?.id).to.equal(firstMemory?.id);
|
258
|
-
expect(secondMemory?.data).to.equal(firstMemory?.data);
|
259
|
-
expect(secondMemory?.roomId).to.equal(firstMemory?.roomId);
|
260
|
-
});
|
261
|
-
|
262
|
-
it("should initialize storage", async () => {
|
263
|
-
global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
264
|
-
const url = input.toString();
|
265
|
-
|
266
|
-
// Mock pour la vérification de l'existence de l'index
|
267
|
-
if (url.includes(`/indexes/${TEST_ROOM_ID}`)) {
|
268
|
-
return new Response(
|
269
|
-
JSON.stringify({
|
270
|
-
uid: TEST_ROOM_ID,
|
271
|
-
primaryKey: "id",
|
272
|
-
})
|
273
|
-
);
|
274
|
-
}
|
275
|
-
|
276
|
-
// Mock pour les settings
|
277
|
-
if (url.includes("/settings")) {
|
278
|
-
return new Response(JSON.stringify({ acknowledged: true }));
|
279
|
-
}
|
280
|
-
|
281
|
-
return new Response(JSON.stringify({}));
|
282
|
-
};
|
283
|
-
|
284
|
-
await expect(meilisearchAdapter.init(TEST_ROOM_ID)).to.not.throw;
|
285
|
-
});
|
286
|
-
});
|
287
|
-
});
|
@@ -1,230 +0,0 @@
|
|
1
|
-
import { expect } from "chai";
|
2
|
-
import { IMemoryAdapter } from "../../../interfaces";
|
3
|
-
import { Memory } from "../../../modules/memory";
|
4
|
-
import { BaseMemoryType, CreateMemoryInput } from "../../../types";
|
5
|
-
|
6
|
-
/**
|
7
|
-
* @module MemoryTests
|
8
|
-
* @description Test suite for the Memory service implementation.
|
9
|
-
* Tests the core functionality of memory management including:
|
10
|
-
* - Initialization
|
11
|
-
* - Memory creation
|
12
|
-
* - Memory retrieval
|
13
|
-
* - Memory deletion
|
14
|
-
*/
|
15
|
-
|
16
|
-
describe("Memory", () => {
|
17
|
-
let memory: Memory;
|
18
|
-
let mockAdapter: IMemoryAdapter;
|
19
|
-
const TEST_ROOM_ID = "test-room";
|
20
|
-
|
21
|
-
/**
|
22
|
-
* Test data fixture
|
23
|
-
* @type {BaseMemoryType}
|
24
|
-
*/
|
25
|
-
const testMemory: BaseMemoryType = {
|
26
|
-
id: "test-id",
|
27
|
-
data: "test data",
|
28
|
-
embedding: [0.1, 0.2, 0.3],
|
29
|
-
roomId: TEST_ROOM_ID,
|
30
|
-
createdAt: new Date(),
|
31
|
-
};
|
32
|
-
|
33
|
-
/**
|
34
|
-
* Set up test environment before each test
|
35
|
-
* Creates a mock adapter and initializes the memory service
|
36
|
-
*/
|
37
|
-
beforeEach(() => {
|
38
|
-
// Create mock implementation of IMemoryAdapter
|
39
|
-
mockAdapter = {
|
40
|
-
init: async () => Promise.resolve(),
|
41
|
-
createMemory: async (input: CreateMemoryInput) => ({
|
42
|
-
...testMemory,
|
43
|
-
data: input.data,
|
44
|
-
embedding: input.embedding,
|
45
|
-
}),
|
46
|
-
getMemoryById: async () => testMemory,
|
47
|
-
getMemoryByIndex: async () => [testMemory],
|
48
|
-
getAllMemories: async () => [testMemory],
|
49
|
-
clearMemoryById: async () => Promise.resolve(),
|
50
|
-
clearAllMemories: async () => Promise.resolve(),
|
51
|
-
};
|
52
|
-
|
53
|
-
memory = new Memory(mockAdapter);
|
54
|
-
});
|
55
|
-
|
56
|
-
/**
|
57
|
-
* Test suite for initialization functionality
|
58
|
-
*/
|
59
|
-
describe("Initialization", () => {
|
60
|
-
/**
|
61
|
-
* Test case: Verify adapter initialization
|
62
|
-
*/
|
63
|
-
it("should initialize the memory adapter", async () => {
|
64
|
-
let initCalled = false;
|
65
|
-
mockAdapter.init = async () => {
|
66
|
-
initCalled = true;
|
67
|
-
};
|
68
|
-
|
69
|
-
await memory.init();
|
70
|
-
expect(initCalled).to.be.true;
|
71
|
-
});
|
72
|
-
});
|
73
|
-
|
74
|
-
/**
|
75
|
-
* Test suite for memory creation functionality
|
76
|
-
*/
|
77
|
-
describe("Memory Creation", () => {
|
78
|
-
/**
|
79
|
-
* Test case: Verify memory creation with valid input
|
80
|
-
*/
|
81
|
-
it("should create a new memory entry", async () => {
|
82
|
-
const input = {
|
83
|
-
data: "test data",
|
84
|
-
roomId: TEST_ROOM_ID,
|
85
|
-
};
|
86
|
-
|
87
|
-
const result = await memory.createMemory(input);
|
88
|
-
expect(result).to.deep.include(input);
|
89
|
-
});
|
90
|
-
|
91
|
-
/**
|
92
|
-
* Test case: Verify memory creation with embedding
|
93
|
-
*/
|
94
|
-
it("should create a memory entry with embedding", async () => {
|
95
|
-
const input = {
|
96
|
-
data: "test data",
|
97
|
-
roomId: TEST_ROOM_ID,
|
98
|
-
embedding: [0.1, 0.2, 0.3],
|
99
|
-
};
|
100
|
-
|
101
|
-
const result = await memory.createMemory(input);
|
102
|
-
expect(result).to.deep.include(input);
|
103
|
-
});
|
104
|
-
});
|
105
|
-
|
106
|
-
/**
|
107
|
-
* Test suite for memory retrieval functionality
|
108
|
-
*/
|
109
|
-
describe("Memory Retrieval", () => {
|
110
|
-
/**
|
111
|
-
* Test case: Verify memory retrieval by ID
|
112
|
-
*/
|
113
|
-
it("should retrieve a memory by ID", async () => {
|
114
|
-
const result = await memory.getMemoryById("test-id", TEST_ROOM_ID);
|
115
|
-
expect(result).to.deep.equal(testMemory);
|
116
|
-
});
|
117
|
-
|
118
|
-
/**
|
119
|
-
* Test case: Verify memory retrieval by index
|
120
|
-
*/
|
121
|
-
it("should retrieve memories by index", async () => {
|
122
|
-
const result = await memory.getMemoryByIndex("test", {
|
123
|
-
roomId: TEST_ROOM_ID,
|
124
|
-
});
|
125
|
-
expect(result).to.deep.equal([testMemory]);
|
126
|
-
});
|
127
|
-
|
128
|
-
/**
|
129
|
-
* Test case: Verify retrieval of all memories
|
130
|
-
*/
|
131
|
-
it("should retrieve all memories", async () => {
|
132
|
-
const result = await memory.getAllMemories(TEST_ROOM_ID);
|
133
|
-
expect(result).to.deep.equal([testMemory]);
|
134
|
-
});
|
135
|
-
});
|
136
|
-
|
137
|
-
/**
|
138
|
-
* Test suite for memory deletion functionality
|
139
|
-
*/
|
140
|
-
describe("Memory Deletion", () => {
|
141
|
-
/**
|
142
|
-
* Test case: Verify memory deletion by ID
|
143
|
-
*/
|
144
|
-
it("should delete a memory by ID", async () => {
|
145
|
-
let deleteCalled = false;
|
146
|
-
mockAdapter.clearMemoryById = async () => {
|
147
|
-
deleteCalled = true;
|
148
|
-
};
|
149
|
-
|
150
|
-
await memory.clearMemoryById("test-id", TEST_ROOM_ID);
|
151
|
-
expect(deleteCalled).to.be.true;
|
152
|
-
});
|
153
|
-
|
154
|
-
/**
|
155
|
-
* Test case: Verify deletion of all memories
|
156
|
-
*/
|
157
|
-
it("should clear all memories", async () => {
|
158
|
-
let clearAllCalled = false;
|
159
|
-
mockAdapter.clearAllMemories = async () => {
|
160
|
-
clearAllCalled = true;
|
161
|
-
};
|
162
|
-
|
163
|
-
await memory.clearAllMemories();
|
164
|
-
expect(clearAllCalled).to.be.true;
|
165
|
-
});
|
166
|
-
});
|
167
|
-
|
168
|
-
describe("Error Handling", () => {
|
169
|
-
it("should handle errors during memory creation", async () => {
|
170
|
-
mockAdapter.createMemory = async () => {
|
171
|
-
throw new Error("Creation failed");
|
172
|
-
};
|
173
|
-
|
174
|
-
try {
|
175
|
-
await memory.createMemory({
|
176
|
-
data: "test",
|
177
|
-
roomId: TEST_ROOM_ID,
|
178
|
-
});
|
179
|
-
expect.fail("Should have thrown an error");
|
180
|
-
} catch (error) {
|
181
|
-
expect(error).to.be.instanceOf(Error);
|
182
|
-
expect((error as Error).message).to.equal("Creation failed");
|
183
|
-
}
|
184
|
-
});
|
185
|
-
|
186
|
-
it("should handle errors during memory retrieval", async () => {
|
187
|
-
mockAdapter.getMemoryById = async () => {
|
188
|
-
throw new Error("Retrieval failed");
|
189
|
-
};
|
190
|
-
|
191
|
-
try {
|
192
|
-
await memory.getMemoryById("test-id", TEST_ROOM_ID);
|
193
|
-
expect.fail("Should have thrown an error");
|
194
|
-
} catch (error) {
|
195
|
-
expect(error).to.be.instanceOf(Error);
|
196
|
-
expect((error as Error).message).to.equal("Retrieval failed");
|
197
|
-
}
|
198
|
-
});
|
199
|
-
});
|
200
|
-
|
201
|
-
describe("Edge Cases", () => {
|
202
|
-
it("should handle undefined embedding", async () => {
|
203
|
-
const input = {
|
204
|
-
id: "test-id",
|
205
|
-
roomId: "test-room",
|
206
|
-
data: "test data",
|
207
|
-
embedding: undefined,
|
208
|
-
};
|
209
|
-
|
210
|
-
const result = await memory.createMemory(input);
|
211
|
-
expect(result?.embedding).to.be.undefined;
|
212
|
-
});
|
213
|
-
|
214
|
-
it("should handle empty query results", async () => {
|
215
|
-
mockAdapter.getMemoryByIndex = async () => [];
|
216
|
-
|
217
|
-
const results = await memory.getMemoryByIndex("nonexistent", {
|
218
|
-
roomId: "test-room",
|
219
|
-
});
|
220
|
-
expect(results).to.be.an("array").that.is.empty;
|
221
|
-
});
|
222
|
-
|
223
|
-
it("should handle non-existent memory ID", async () => {
|
224
|
-
mockAdapter.getMemoryById = async () => null;
|
225
|
-
|
226
|
-
const result = await memory.getMemoryById("nonexistent", TEST_ROOM_ID);
|
227
|
-
expect(result).to.be.null;
|
228
|
-
});
|
229
|
-
});
|
230
|
-
});
|