@elizaos/core 1.5.1 → 1.5.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.
Files changed (88) hide show
  1. package/dist/browser/index.browser.js +120 -120
  2. package/dist/browser/index.browser.js.map +5 -21
  3. package/dist/browser/index.d.ts +3 -1
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.js +1 -5
  6. package/dist/node/index.d.ts +3 -1
  7. package/package.json +10 -4
  8. package/src/__tests__/action-chaining-simple.test.ts +203 -0
  9. package/src/__tests__/actions.test.ts +218 -0
  10. package/src/__tests__/buffer.test.ts +337 -0
  11. package/src/__tests__/character-validation.test.ts +309 -0
  12. package/src/__tests__/database.test.ts +750 -0
  13. package/src/__tests__/entities.test.ts +727 -0
  14. package/src/__tests__/env.test.ts +23 -0
  15. package/src/__tests__/environment.test.ts +285 -0
  16. package/src/__tests__/logger-browser-node.test.ts +716 -0
  17. package/src/__tests__/logger.test.ts +403 -0
  18. package/src/__tests__/messages.test.ts +196 -0
  19. package/src/__tests__/mockCharacter.ts +544 -0
  20. package/src/__tests__/parsing.test.ts +58 -0
  21. package/src/__tests__/prompts.test.ts +159 -0
  22. package/src/__tests__/roles.test.ts +331 -0
  23. package/src/__tests__/runtime-embedding.test.ts +343 -0
  24. package/src/__tests__/runtime.test.ts +978 -0
  25. package/src/__tests__/search.test.ts +15 -0
  26. package/src/__tests__/services-by-type.test.ts +204 -0
  27. package/src/__tests__/services.test.ts +136 -0
  28. package/src/__tests__/settings.test.ts +810 -0
  29. package/src/__tests__/utils.test.ts +1105 -0
  30. package/src/__tests__/uuid.test.ts +94 -0
  31. package/src/actions.ts +122 -0
  32. package/src/database.ts +579 -0
  33. package/src/entities.ts +406 -0
  34. package/src/index.browser.ts +48 -0
  35. package/src/index.node.ts +39 -0
  36. package/src/index.ts +50 -0
  37. package/src/logger.ts +527 -0
  38. package/src/prompts.ts +243 -0
  39. package/src/roles.ts +85 -0
  40. package/src/runtime.ts +2514 -0
  41. package/src/schemas/character.ts +149 -0
  42. package/src/search.ts +1543 -0
  43. package/src/sentry/instrument.browser.ts +65 -0
  44. package/src/sentry/instrument.node.ts +57 -0
  45. package/src/sentry/instrument.ts +82 -0
  46. package/src/services.ts +105 -0
  47. package/src/settings.ts +409 -0
  48. package/src/test_resources/constants.ts +12 -0
  49. package/src/test_resources/testSetup.ts +21 -0
  50. package/src/test_resources/types.ts +22 -0
  51. package/src/types/agent.ts +112 -0
  52. package/src/types/browser.ts +145 -0
  53. package/src/types/components.ts +184 -0
  54. package/src/types/database.ts +348 -0
  55. package/src/types/email.ts +162 -0
  56. package/src/types/environment.ts +129 -0
  57. package/src/types/events.ts +249 -0
  58. package/src/types/index.ts +29 -0
  59. package/src/types/knowledge.ts +65 -0
  60. package/src/types/lp.ts +124 -0
  61. package/src/types/memory.ts +228 -0
  62. package/src/types/message.ts +233 -0
  63. package/src/types/messaging.ts +57 -0
  64. package/src/types/model.ts +359 -0
  65. package/src/types/pdf.ts +77 -0
  66. package/src/types/plugin.ts +78 -0
  67. package/src/types/post.ts +271 -0
  68. package/src/types/primitives.ts +97 -0
  69. package/src/types/runtime.ts +190 -0
  70. package/src/types/service.ts +198 -0
  71. package/src/types/settings.ts +30 -0
  72. package/src/types/state.ts +60 -0
  73. package/src/types/task.ts +72 -0
  74. package/src/types/tee.ts +107 -0
  75. package/src/types/testing.ts +30 -0
  76. package/src/types/token.ts +96 -0
  77. package/src/types/transcription.ts +133 -0
  78. package/src/types/video.ts +108 -0
  79. package/src/types/wallet.ts +56 -0
  80. package/src/types/web-search.ts +146 -0
  81. package/src/utils/__tests__/buffer.test.ts +80 -0
  82. package/src/utils/__tests__/environment.test.ts +58 -0
  83. package/src/utils/__tests__/stringToUuid.test.ts +88 -0
  84. package/src/utils/buffer.ts +312 -0
  85. package/src/utils/environment.ts +316 -0
  86. package/src/utils/server-health.ts +117 -0
  87. package/src/utils.ts +1076 -0
  88. package/dist/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,750 @@
1
+ import { describe, expect, beforeEach, it } from 'bun:test';
2
+ import { DatabaseAdapter } from '../database';
3
+ import type {
4
+ Agent,
5
+ ChannelType,
6
+ Component,
7
+ Entity,
8
+ Log,
9
+ Memory,
10
+ Participant,
11
+ Relationship,
12
+ Room,
13
+ Task,
14
+ UUID,
15
+ World,
16
+ } from '../types';
17
+
18
+ /**
19
+ * MockDatabaseAdapter class extends DatabaseAdapter class and provides mock implementations for various database operations.
20
+ * @extends {DatabaseAdapter}
21
+ */
22
+ /**
23
+ * MockDatabaseAdapter class extends DatabaseAdapter class and provides mock implementations for various database operations.
24
+ * @extends {DatabaseAdapter}
25
+ */
26
+ /**
27
+ * Mock Database Adapter class that extends DatabaseAdapter.
28
+ *
29
+ * @class
30
+ *
31
+ * @method init
32
+ * @returns {Promise<void>} Promise that resolves with void
33
+ * @description Initializes the database adapter
34
+ *
35
+ * @method close
36
+ * @returns {Promise<void>} Promise that resolves with void
37
+ * @description Closes the database adapter
38
+ *
39
+ * @method getEntitiesForRoom
40
+ * @param {UUID} roomId - The UUID of the room
41
+ * @param {boolean} [includeComponents] - Optional parameter to include components
42
+ * @returns {Promise<Entity[]>} Promise that resolves with an array of entities
43
+ * @description Gets entities for a specific room
44
+ */
45
+ class MockDatabaseAdapter extends DatabaseAdapter {
46
+ init(): Promise<void> {
47
+ throw new Error('Method not implemented.');
48
+ }
49
+ initialize(): Promise<void> {
50
+ throw new Error('Method not implemented.');
51
+ }
52
+ runMigrations(): Promise<void> {
53
+ throw new Error('Method not implemented.');
54
+ }
55
+ isReady(): Promise<boolean> {
56
+ throw new Error('Method not implemented.');
57
+ }
58
+ close(): Promise<void> {
59
+ throw new Error('Method not implemented.');
60
+ }
61
+ getEntitiesForRoom(roomId: UUID, includeComponents?: boolean): Promise<Entity[]> {
62
+ throw new Error('Method not implemented.');
63
+ }
64
+ updateEntity(entity: Entity): Promise<void> {
65
+ throw new Error('Method not implemented.');
66
+ }
67
+ getComponent(
68
+ entityId: UUID,
69
+ type: string,
70
+ worldId?: UUID,
71
+ sourceEntityId?: UUID
72
+ ): Promise<Component | null> {
73
+ throw new Error('Method not implemented.');
74
+ }
75
+ getComponents(entityId: UUID, worldId?: UUID, sourceEntityId?: UUID): Promise<Component[]> {
76
+ throw new Error('Method not implemented.');
77
+ }
78
+ createComponent(component: Component): Promise<boolean> {
79
+ throw new Error('Method not implemented.');
80
+ }
81
+ updateComponent(component: Component): Promise<void> {
82
+ throw new Error('Method not implemented.');
83
+ }
84
+ deleteComponent(componentId: UUID): Promise<void> {
85
+ throw new Error('Method not implemented.');
86
+ }
87
+ getLogs(params: {
88
+ entityId: UUID;
89
+ roomId?: UUID;
90
+ type?: string;
91
+ count?: number;
92
+ offset?: number;
93
+ }): Promise<Log[]> {
94
+ throw new Error('Method not implemented.');
95
+ }
96
+ deleteLog(logId: UUID): Promise<void> {
97
+ throw new Error('Method not implemented.');
98
+ }
99
+ getWorld(id: UUID): Promise<World | null> {
100
+ throw new Error('Method not implemented.');
101
+ }
102
+ getAllWorlds(): Promise<World[]> {
103
+ throw new Error('Method not implemented.');
104
+ }
105
+ createWorld(world: World): Promise<UUID> {
106
+ throw new Error('Method not implemented.');
107
+ }
108
+ updateWorld(world: World): Promise<void> {
109
+ throw new Error('Method not implemented.');
110
+ }
111
+ removeWorld(id: UUID): Promise<void> {
112
+ throw new Error('Method not implemented.');
113
+ }
114
+ getRooms(worldId: UUID): Promise<Room[]> {
115
+ throw new Error('Method not implemented.');
116
+ }
117
+ updateRoom(room: Room): Promise<void> {
118
+ throw new Error('Method not implemented.');
119
+ }
120
+ deleteRoom(roomId: UUID): Promise<void> {
121
+ throw new Error('Method not implemented.');
122
+ }
123
+ getParticipantsForEntity(entityId: UUID): Promise<Participant[]> {
124
+ throw new Error('Method not implemented.');
125
+ }
126
+ updateRelationship(params: {
127
+ sourceEntityId: UUID;
128
+ targetEntityId: UUID;
129
+ tags?: string[];
130
+ metadata?: Record<string, unknown>;
131
+ }): Promise<void> {
132
+ throw new Error('Method not implemented.');
133
+ }
134
+ getAgent(agentId: UUID): Promise<Agent | null> {
135
+ throw new Error('Method not implemented.');
136
+ }
137
+ getAgents(): Promise<Agent[]> {
138
+ throw new Error('Method not implemented.');
139
+ }
140
+ createAgent(agent: Partial<Agent>): Promise<boolean> {
141
+ throw new Error('Method not implemented.');
142
+ }
143
+ updateAgent(agentId: UUID, agent: Partial<Agent>): Promise<boolean> {
144
+ throw new Error('Method not implemented.');
145
+ }
146
+ deleteAgent(agentId: UUID): Promise<boolean> {
147
+ throw new Error('Method not implemented.');
148
+ }
149
+ ensureAgentExists(agent: Partial<Agent>): Promise<void> {
150
+ throw new Error('Method not implemented.');
151
+ }
152
+ ensureEmbeddingDimension(dimension: number): Promise<void> {
153
+ throw new Error('Method not implemented.');
154
+ }
155
+ getCache<T>(key: string): Promise<T | undefined> {
156
+ throw new Error('Method not implemented.');
157
+ }
158
+ setCache<T>(key: string, value: T): Promise<boolean> {
159
+ throw new Error('Method not implemented.');
160
+ }
161
+ deleteCache(key: string): Promise<boolean> {
162
+ throw new Error('Method not implemented.');
163
+ }
164
+ createTask(task: Task): Promise<UUID> {
165
+ throw new Error('Method not implemented.');
166
+ }
167
+ getTasks(params: { roomId?: UUID; tags?: string[] }): Promise<Task[]> {
168
+ throw new Error('Method not implemented.');
169
+ }
170
+ getTask(id: UUID): Promise<Task | null> {
171
+ throw new Error('Method not implemented.');
172
+ }
173
+ getTasksByName(name: string): Promise<Task[]> {
174
+ throw new Error('Method not implemented.');
175
+ }
176
+ updateTask(id: UUID, task: Partial<Task>): Promise<void> {
177
+ throw new Error('Method not implemented.');
178
+ }
179
+ deleteTask(id: UUID): Promise<void> {
180
+ throw new Error('Method not implemented.');
181
+ }
182
+ /**
183
+ * Asynchronous function to retrieve a Memory object by its unique ID.
184
+ *
185
+ * @param {UUID} _id - The unique identifier of the Memory object to retrieve.
186
+ * @returns {Promise<Memory | null>} - A Promise that resolves to the retrieved Memory object, or null if not found.
187
+ * @throws {Error} - If the method is not implemented.
188
+ */
189
+
190
+ getMemoryById(_id: UUID): Promise<Memory | null> {
191
+ throw new Error('Method not implemented.');
192
+ }
193
+ /**
194
+ * Retrieve memories by their IDs.
195
+ *
196
+ * @param {UUID[]} memoryIds - An array of memory IDs to fetch.
197
+ * @param {string} [_tableName] - Optional table name parameter.
198
+ * @returns {Promise<Memory[]>} - A Promise that resolves to an array of Memory objects.
199
+ */
200
+ async getMemoriesByIds(memoryIds: UUID[], _tableName?: string): Promise<Memory[]> {
201
+ return memoryIds.map((id) => ({
202
+ id: id,
203
+ content: { text: 'Test Memory' },
204
+ roomId: 'room-id' as UUID,
205
+ entityId: 'user-id' as UUID,
206
+ })) as Memory[];
207
+ }
208
+ /**
209
+ * Logs an event for a specific user in a specific room.
210
+ *
211
+ * @param {object} _params - The parameters for the log function.
212
+ * @param {object} _params.body - The data object containing the event details.
213
+ * @param {string} _params.entityId - The unique identifier of the user performing the event.
214
+ * @param {string} _params.roomId - The unique identifier of the room where the event occurred.
215
+ * @param {string} _params.type - The type of event being logged.
216
+ * @returns {Promise<void>}
217
+ */
218
+ log(_params: {
219
+ body: { [key: string]: unknown };
220
+ entityId: UUID;
221
+ roomId: UUID;
222
+ type: string;
223
+ }): Promise<void> {
224
+ throw new Error('Method not implemented.');
225
+ }
226
+ /**
227
+ * Retrieve details of entities in a specific room.
228
+ *
229
+ * @param {Object} _params - The parameters for the method.
230
+ * @param {UUID} _params.roomId - The UUID of the room to retrieve actor details from.
231
+ * @returns {Promise<Entity[]>} - A promise that resolves to an array of Entity objects representing the details of entities in the specified room.
232
+ * @throws {Error} - If the method is not implemented.
233
+ */
234
+ getEntityDetails(_params: { roomId: UUID }): Promise<Entity[]> {
235
+ throw new Error('Method not implemented.');
236
+ }
237
+ /**
238
+ * Creates a new memory in the specified table.
239
+ * @param _memory The memory object to be created.
240
+ * @param _tableName The name of the table where the memory should be created.
241
+ * @param _unique Optional parameter to specify if the memory should be unique within the table.
242
+ * @returns A Promise that resolves when the memory is successfully created.
243
+ */
244
+ createMemory(_memory: Memory, _tableName: string, _unique?: boolean): Promise<UUID> {
245
+ throw new Error('Method not implemented.');
246
+ }
247
+ /**
248
+ * Removes a memory from a specific table.
249
+ *
250
+ * @param {UUID} _memoryId - The ID of the memory to be removed.
251
+ * @returns {Promise<void>} A promise that resolves when the memory is successfully removed.
252
+ */
253
+ deleteMemory(_memoryId: UUID): Promise<void> {
254
+ throw new Error('Method not implemented.');
255
+ }
256
+ /**
257
+ * Removes multiple memories from the database in a single batch operation.
258
+ *
259
+ * @param {UUID[]} _memoryIds - An array of UUIDs of the memories to remove.
260
+ * @returns {Promise<void>} A promise that resolves when all memories are successfully removed.
261
+ */
262
+ deleteManyMemories(_memoryIds: UUID[]): Promise<void> {
263
+ return Promise.resolve();
264
+ }
265
+ /**
266
+ * Remove all memories associated with a specific room and table.
267
+ *
268
+ * @param {UUID} _roomId - The unique identifier of the room.
269
+ * @param {string} _tableName - The name of the table containing the memories.
270
+ * @returns {Promise<void>} A promise that resolves when all memories are successfully removed.
271
+ */
272
+ deleteAllMemories(_roomId: UUID, _tableName: string): Promise<void> {
273
+ throw new Error('Method not implemented.');
274
+ }
275
+ /**
276
+ * Count the number of memories for a specific room.
277
+ *
278
+ * @param {UUID} _roomId - The ID of the room to count memories for.
279
+ * @param {boolean} [_unique] - Flag to indicate if only unique memories should be counted.
280
+ * @param {string} [_tableName] - The name of the table to count memories from.
281
+ * @return {Promise<number>} - A Promise that resolves to the number of memories.
282
+ */
283
+ countMemories(_roomId: UUID, _unique?: boolean, _tableName?: string): Promise<number> {
284
+ throw new Error('Method not implemented.');
285
+ }
286
+ /**
287
+ * Retrieve the room data for a specific room and agent.
288
+ *
289
+ * @param {_roomId} UUID - The unique identifier of the room.
290
+ * @param {_agentId} UUID - The unique identifier of the agent.
291
+ * @returns {Promise<Room | null>} - The room data if found, otherwise null.
292
+ */
293
+ getRoom(_roomId: UUID): Promise<Room | null> {
294
+ throw new Error('Method not implemented.');
295
+ }
296
+ /**
297
+ * Creates a room with the given parameters.
298
+ *
299
+ * @param {Object} _params - The parameters for creating the room.
300
+ * @param {UUID} _params.id - The ID of the room.
301
+ * @param {UUID} _params.agentId - The ID of the agent associated with the room.
302
+ * @param {string} _params.source - The source of the room.
303
+ * @param {ChannelType} _params.type - The type of channel.
304
+ * @param {string} [_params.channelId] - Optional channel ID.
305
+ * @param {string} [_params.serverId] - Optional server ID.
306
+ * @param {UUID} [_params.worldId] - Optional world ID.
307
+ * @returns {Promise<UUID>} - A promise that resolves with the ID of the created room.
308
+ */
309
+ createRoom(_params: {
310
+ id: UUID;
311
+ agentId: UUID;
312
+ source: string;
313
+ type: ChannelType;
314
+ channelId?: string;
315
+ serverId?: string;
316
+ worldId?: UUID;
317
+ }): Promise<UUID> {
318
+ throw new Error('Method not implemented.');
319
+ }
320
+ /**
321
+ * Removes a room with the given ID.
322
+ *
323
+ * @param {_roomId: UUID} _roomId - The ID of the room to remove.
324
+ * @returns {Promise<void>} - A promise that resolves when the room is successfully removed.
325
+ */
326
+ removeRoom(_roomId: UUID): Promise<void> {
327
+ throw new Error('Method not implemented.');
328
+ }
329
+ /**
330
+ * Retrieve a list of room IDs for a given participant.
331
+ * @param {UUID} _entityId - The ID of the participant
332
+ * @returns {Promise<UUID[]>} - A promise that resolves with an array of room IDs
333
+ */
334
+ getRoomsForParticipant(_entityId: UUID): Promise<UUID[]> {
335
+ throw new Error('Method not implemented.');
336
+ }
337
+ /**
338
+ * Retrieves the rooms for the specified participants.
339
+ *
340
+ * @param {UUID[]} _entityIds - An array of UUIDs representing the participants whose rooms need to be retrieved.
341
+ * @returns {Promise<UUID[]>} - A promise that resolves to an array of UUIDs representing the rooms for the specified participants.
342
+ * @throws {Error} - If the method is not implemented.
343
+ */
344
+ getRoomsForParticipants(_entityIds: UUID[]): Promise<UUID[]> {
345
+ throw new Error('Method not implemented.');
346
+ }
347
+ /**
348
+ * Add a participant to a room.
349
+ *
350
+ * @param {UUID} _entityId - The ID of the user to add to the room.
351
+ * @param {UUID} _roomId - The ID of the room to add the user to.
352
+ * @returns {Promise<boolean>} - A promise that resolves to true if the user was successfully added to the room, otherwise false.
353
+ */
354
+ addParticipant(_entityId: UUID, _roomId: UUID): Promise<boolean> {
355
+ throw new Error('Method not implemented.');
356
+ }
357
+ /**
358
+ * Remove a participant from a room.
359
+ *
360
+ * @param {_entityId} UUID - The ID of the user to remove from the room.
361
+ * @param {_roomId} UUID - The ID of the room from which to remove the participant.
362
+ * @returns {Promise<boolean>} A promise that resolves to true if the participant was successfully removed, otherwise false.
363
+ */
364
+ removeParticipant(_entityId: UUID, _roomId: UUID): Promise<boolean> {
365
+ throw new Error('Method not implemented.');
366
+ }
367
+
368
+ getConnection(): Promise<any> {
369
+ throw new Error('Method not implemented.');
370
+ }
371
+
372
+ getEntitiesByIds(_entityIds: UUID[]): Promise<Entity[]> {
373
+ throw new Error('Method not implemented.');
374
+ }
375
+
376
+ createEntities(_entities: Entity[]): Promise<boolean> {
377
+ throw new Error('Method not implemented.');
378
+ }
379
+
380
+ updateMemory(_memory: Partial<Memory> & { id: UUID }): Promise<boolean> {
381
+ throw new Error('Method not implemented.');
382
+ }
383
+
384
+ getMemoriesByWorldId(_params: { worldId: UUID; tableName?: string }): Promise<Memory[]> {
385
+ throw new Error('Method not implemented.');
386
+ }
387
+
388
+ getMemoriesByEntities(_params: { entityIds: UUID[]; tableName?: string }): Promise<Memory[]> {
389
+ throw new Error('Method not implemented.');
390
+ }
391
+
392
+ searchMemoriesByEmbedding(
393
+ _embedding: number[],
394
+ _params?: {
395
+ tableName?: string;
396
+ roomId?: UUID;
397
+ match_threshold?: number;
398
+ match_count?: number;
399
+ unique?: boolean;
400
+ }
401
+ ): Promise<Memory[]> {
402
+ throw new Error('Method not implemented.');
403
+ }
404
+
405
+ deleteEntity(_entityId: UUID): Promise<void> {
406
+ throw new Error('Method not implemented.');
407
+ }
408
+
409
+ getRoomsByIds(_roomIds: UUID[]): Promise<Room[]> {
410
+ throw new Error('Method not implemented.');
411
+ }
412
+
413
+ getRoomsByWorld(_worldId: UUID): Promise<Room[]> {
414
+ throw new Error('Method not implemented.');
415
+ }
416
+
417
+ createRooms(_rooms: Room[]): Promise<UUID[]> {
418
+ throw new Error('Method not implemented.');
419
+ }
420
+
421
+ addParticipantsRoom(_entityIds: UUID[], _roomId: UUID): Promise<boolean> {
422
+ throw new Error('Method not implemented.');
423
+ }
424
+
425
+ deleteRoomsByWorldId(_worldId: UUID): Promise<void> {
426
+ throw new Error('Method not implemented.');
427
+ }
428
+ /**
429
+ * Retrieve a list of participants associated with the specified account user ID.
430
+ *
431
+ * @param {UUID} entityId - The unique identifier of the account user.
432
+ * @returns {Promise<Participant[]>} - A promise that resolves to an array of Participant objects.
433
+ */
434
+ getParticipantsForAccount(entityId: UUID): Promise<Participant[]>;
435
+ /**
436
+ * Retrieves the participants associated with a specific user account.
437
+ *
438
+ * @param {unknown} _entityId - The ID of the user account to retrieve participants for.
439
+ * @returns {Promise<import("../src/types.ts").Participant[]>} A Promise that resolves to an array of participants.
440
+ */
441
+ getParticipantsForAccount(_entityId: unknown): Promise<Participant[]> {
442
+ throw new Error('Method not implemented.');
443
+ }
444
+ /**
445
+ * Get the list of participants for a specific room.
446
+ *
447
+ * @param {_roomId} UUID - The UUID of the room for which participants need to be retrieved.
448
+ * @returns {Promise<UUID[]>} - A Promise that resolves to an array of UUIDs representing the participants of the room.
449
+ * @throws {Error} - If the method is not implemented.
450
+ */
451
+ getParticipantsForRoom(_roomId: UUID): Promise<UUID[]> {
452
+ throw new Error('Method not implemented.');
453
+ }
454
+ /**
455
+ * Get the state of a participant user in a specific room.
456
+ * @param {UUID} _roomId - The ID of the room.
457
+ * @param {UUID} _entityId - The ID of the user.
458
+ * @returns {Promise<"FOLLOWED" | "MUTED" | null>} The state of the participant user (FOLLOWED, MUTED, or null).
459
+ */
460
+ getParticipantUserState(_roomId: UUID, _entityId: UUID): Promise<'FOLLOWED' | 'MUTED' | null> {
461
+ throw new Error('Method not implemented.');
462
+ }
463
+ /**
464
+ * Set the state of a participant in a room.
465
+ *
466
+ * @param {UUID} _roomId - The unique identifier of the room.
467
+ * @param {UUID} _entityId - The unique identifier of the user.
468
+ * @param {UUID} _agentId - The unique identifier of the agent.
469
+ * @param {"FOLLOWED" | "MUTED" | null} _state - The state to set for the participant (FOLLOWED, MUTED, or null).
470
+ * @returns {Promise<void>} - A promise that resolves when the state is set.
471
+ */
472
+ setParticipantUserState(
473
+ _roomId: UUID,
474
+ _entityId: UUID,
475
+ _state: 'FOLLOWED' | 'MUTED' | null
476
+ ): Promise<void> {
477
+ throw new Error('Method not implemented.');
478
+ }
479
+ /**
480
+ * Creates a relationship between two users.
481
+ *
482
+ * @param {Object} _params - The parameters for creating the relationship.
483
+ * @param {UUID} _params.sourceEntityId - The UUID of the first user.
484
+ * @param {UUID} _params.targetEntityId - The UUID of the second user.
485
+ * @returns {Promise<boolean>} - A promise that resolves to true if the relationship was successfully created.
486
+ */
487
+ createRelationship(_params: { sourceEntityId: UUID; targetEntityId: UUID }): Promise<boolean> {
488
+ throw new Error('Method not implemented.');
489
+ }
490
+ /**
491
+ * Retrieves the relationship between two users.
492
+ * @param {object} _params The parameters for which relationship to get.
493
+ * @param {UUID} _params.sourceEntityId The UUID of the first user.
494
+ * @param {UUID} _params.targetEntityId The UUID of the second user.
495
+ * @returns {Promise<Relationship | null>} A Promise that resolves with the relationship between the two users, or null if no relationship exists.
496
+ */
497
+ getRelationship(_params: {
498
+ sourceEntityId: UUID;
499
+ targetEntityId: UUID;
500
+ }): Promise<Relationship | null> {
501
+ throw new Error('Method not implemented.');
502
+ }
503
+ /**
504
+ * Retrieves relationships for a specific user based on the provided user ID.
505
+ * @param {Object} _params - The parameters object containing the user ID.
506
+ * @param {string} _params.entityId - The unique identifier for the user to retrieve relationships for.
507
+ * @returns {Promise<Relationship[]>} - A promise that resolves to an array of Relationship objects.
508
+ */
509
+ getRelationships(_params: { entityId: UUID }): Promise<Relationship[]> {
510
+ throw new Error('Method not implemented.');
511
+ }
512
+ db: Record<string, unknown> = {};
513
+
514
+ // Mock method for getting memories by room IDs
515
+ /**
516
+ *
517
+ * Retrieves memories based on given roomIds and optional agentId.
518
+ *
519
+ * @param {Object} params - The parameters for fetching memories.
520
+ * @param {string[]} params.roomIds - An array of roomIds to filter memories by.
521
+ * @param {string} [params.agentId] - An optional agentId to further filter memories by.
522
+ * @param {string} params.tableName - The name of the table storing memories.
523
+ * @returns {Promise<Memory[]>} - The Promise that resolves to an array of Memory objects.
524
+ */
525
+ async getMemoriesByRoomIds(params: {
526
+ roomIds: `${string}-${string}-${string}-${string}-${string}`[];
527
+ agentId?: `${string}-${string}-${string}-${string}-${string}`;
528
+ tableName: string;
529
+ }): Promise<Memory[]> {
530
+ return [
531
+ {
532
+ id: 'memory-id' as UUID,
533
+ content: 'Test Memory',
534
+ roomId: params.roomIds[0],
535
+ entityId: 'user-id' as UUID,
536
+ agentId: params.agentId ?? ('agent-id' as UUID),
537
+ },
538
+ ] as unknown as Memory[];
539
+ }
540
+
541
+ // Mock method for getting cached embeddings
542
+ /**
543
+ * Fetch cached embeddings based on the query parameters.
544
+ *
545
+ * @param {Object} _params - The parameters used to query the cached embeddings.
546
+ * @param {string} _params.query_table_name - The name of the table used for the query.
547
+ * @param {number} _params.query_threshold - The threshold value for the query.
548
+ * @param {string} _params.query_input - The input string for the query.
549
+ * @param {string} _params.query_field_name - The name of the field used in the query.
550
+ * @param {string} _params.query_field_sub_name - The subfield name used in the query.
551
+ * @param {number} _params.query_match_count - The number of matches for the query.
552
+ * @return {Promise<{embedding: number[], levenshtein_score: number}[]>} The cached embeddings with their Levenshtein scores.
553
+ */
554
+
555
+ async getCachedEmbeddings(_params: {
556
+ query_table_name: string;
557
+ query_threshold: number;
558
+ query_input: string;
559
+ query_field_name: string;
560
+ query_field_sub_name: string;
561
+ query_match_count: number;
562
+ }): Promise<
563
+ {
564
+ embedding: number[];
565
+ levenshtein_score: number;
566
+ }[]
567
+ > {
568
+ return [
569
+ {
570
+ embedding: [0.1, 0.2, 0.3],
571
+ levenshtein_score: 0.4,
572
+ },
573
+ ];
574
+ }
575
+
576
+ // Mock method for searching memories
577
+ /**
578
+ * Asynchronously searches for memories based on the provided parameters.
579
+ *
580
+ * @param {Object} params - The parameters for the memory search.
581
+ * @param {string} params.tableName - The name of the table to search memories in.
582
+ * @param {string} params.roomId - The room ID to search memories related to.
583
+ * @param {number[]} params.embedding - The memory embedding for similarity matching.
584
+ * @param {number} params.match_threshold - The threshold for match similarity.
585
+ * @param {number} params.count - The number of memories to retrieve.
586
+ * @param {boolean} params.unique - Flag to retrieve unique memories only.
587
+ * @returns {Promise<Array<Memory>>} The list of memories that match the search criteria.
588
+ */
589
+ async searchMemories(params: {
590
+ tableName: string;
591
+ roomId: `${string}-${string}-${string}-${string}-${string}`;
592
+ embedding: number[];
593
+ match_threshold: number;
594
+ count: number;
595
+ unique: boolean;
596
+ }): Promise<Memory[]> {
597
+ return [
598
+ {
599
+ id: 'memory-id' as UUID,
600
+ content: 'Test Memory',
601
+ roomId: params.roomId,
602
+ entityId: 'user-id' as UUID,
603
+ agentId: 'agent-id' as UUID,
604
+ },
605
+ ] as unknown as Memory[];
606
+ }
607
+
608
+ // Mock method for getting account by ID
609
+ /**
610
+ * Asynchronously retrieves an Entity by its unique ID.
611
+ *
612
+ * @param {UUID} entityId - The unique identifier of the Entity to retrieve.
613
+ * @returns {Promise<Entity | null>} A Promise that resolves with the Entity object if found, otherwise null.
614
+ */
615
+ async getEntityById(entityId: UUID): Promise<Entity | null> {
616
+ return {
617
+ id: entityId,
618
+ metadata: {
619
+ username: 'testuser',
620
+ name: 'Test Entity',
621
+ },
622
+ names: ['Test Entity'],
623
+ agentId: 'agent-id' as UUID,
624
+ } as Entity;
625
+ }
626
+
627
+ // Other methods stay the same...
628
+ /**
629
+ * Asynchronously creates a new entity for a given account.
630
+ *
631
+ * @param {Entity} _account - The account for which the entity is being created.
632
+ * @returns {Promise<boolean>} A Promise that resolves to true if entity creation is successful.
633
+ */
634
+ async createEntity(_account: Entity): Promise<boolean> {
635
+ return true;
636
+ }
637
+
638
+ /**
639
+ * Retrieves memories based on the specified parameters.
640
+ *
641
+ * @param {Object} params - The parameters for fetching memories.
642
+ * @param {UUID} params.roomId - The ID of the room to fetch memories from.
643
+ * @param {number} [params.count] - The number of memories to fetch.
644
+ * @param {boolean} [params.unique] - Whether to fetch unique memories.
645
+ * @param {string} params.tableName - The name of the table storing the memories.
646
+ * @returns {Promise<Memory[]>} - A Promise that resolves to an array of Memory objects.
647
+ */
648
+ async getMemories(params: {
649
+ roomId: UUID;
650
+ count?: number;
651
+ unique?: boolean;
652
+ tableName: string;
653
+ }): Promise<Memory[]> {
654
+ return [
655
+ {
656
+ id: 'memory-id' as UUID,
657
+ content: 'Test Memory',
658
+ roomId: params.roomId,
659
+ entityId: 'user-id' as UUID,
660
+ agentId: 'agent-id' as UUID,
661
+ },
662
+ ] as unknown as Memory[];
663
+ }
664
+
665
+ /**
666
+ * Asynchronously retrieves a list of entities based on the provided roomId.
667
+ * @param {Object} _params - The parameters object.
668
+ * @param {UUID} _params.roomId - The roomId to filter entities by.
669
+ * @returns {Promise<Entity[]>} - A promise that resolves to an array of Entity objects.
670
+ */
671
+ async getEntities(_params: { roomId: UUID }): Promise<Entity[]> {
672
+ return [
673
+ {
674
+ id: 'actor-id' as UUID,
675
+ name: 'Test Entity',
676
+ username: 'testactor',
677
+ roomId: 'room-id' as UUID, // Ensure roomId is provided
678
+ },
679
+ ] as unknown as Entity[];
680
+ }
681
+ }
682
+
683
+ describe('DatabaseAdapter Tests', () => {
684
+ let adapter: MockDatabaseAdapter;
685
+ const roomId = 'room-id' as UUID;
686
+
687
+ beforeEach(() => {
688
+ adapter = new MockDatabaseAdapter();
689
+ });
690
+
691
+ it('should return memories by room ID', async () => {
692
+ const memories = await adapter.getMemoriesByRoomIds({
693
+ roomIds: ['room-id' as `${string}-${string}-${string}-${string}-${string}`],
694
+ tableName: 'test_table',
695
+ });
696
+ expect(memories).toHaveLength(1);
697
+ expect(memories[0].roomId).toBe('room-id' as UUID);
698
+ });
699
+
700
+ it('should return cached embeddings', async () => {
701
+ const embeddings = await adapter.getCachedEmbeddings({
702
+ query_table_name: 'test_table',
703
+ query_threshold: 0.5,
704
+ query_input: 'test query',
705
+ query_field_name: 'field',
706
+ query_field_sub_name: 'subfield',
707
+ query_match_count: 5,
708
+ });
709
+ expect(embeddings).toHaveLength(1);
710
+ expect(embeddings[0].embedding).toEqual([0.1, 0.2, 0.3]);
711
+ });
712
+
713
+ it('should search memories based on embedding', async () => {
714
+ const memories = await adapter.searchMemories({
715
+ tableName: 'test_table',
716
+ roomId: 'room-id' as `${string}-${string}-${string}-${string}-${string}`,
717
+ embedding: [0.1, 0.2, 0.3],
718
+ match_threshold: 0.5,
719
+ count: 3,
720
+ unique: true,
721
+ });
722
+ expect(memories).toHaveLength(1);
723
+ expect(memories[0].roomId).toBe('room-id' as UUID);
724
+ });
725
+
726
+ it('should get an account by user ID', async () => {
727
+ const account = await adapter.getEntityById('test-user-id' as UUID);
728
+ expect(account).not.toBeNull();
729
+ expect(account?.metadata?.username).toBe('testuser');
730
+ });
731
+
732
+ it('should create a new account', async () => {
733
+ const newEntity: Entity = {
734
+ id: 'new-user-id' as UUID,
735
+ names: ['New Entity'],
736
+ metadata: {
737
+ username: 'newuser',
738
+ name: 'New Entity',
739
+ },
740
+ agentId: 'agent-id' as UUID,
741
+ };
742
+ const result = await adapter.createEntity(newEntity);
743
+ expect(result).toBe(true);
744
+ });
745
+
746
+ it('should return entities by room ID', async () => {
747
+ const entities = await adapter.getEntities({ roomId });
748
+ expect(entities).toHaveLength(1);
749
+ });
750
+ });