diff --git a/docs/docs/classes/BgentRuntime.md b/docs/docs/classes/BgentRuntime.md index 3b5d5a2..2526127 100644 --- a/docs/docs/classes/BgentRuntime.md +++ b/docs/docs/classes/BgentRuntime.md @@ -24,6 +24,7 @@ Creates an instance of BgentRuntime. | `opts` | `Object` | The options for configuring the BgentRuntime. | | `opts.actions?` | [`Action`](../interfaces/Action.md)[] | Optional custom actions. | | `opts.agentId?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | Optional ID of the agent. | +| `opts.conversationLength?` | `number` | The number of messages to hold in the recent message cache. | | `opts.databaseAdapter` | [`DatabaseAdapter`](DatabaseAdapter.md) | The database adapter used for interacting with the database. | | `opts.debugMode?` | `boolean` | If true, debug messages will be logged. | | `opts.embeddingModel?` | `string` | The model to use for embedding. | @@ -31,7 +32,6 @@ Creates an instance of BgentRuntime. | `opts.fetch?` | `unknown` | Custom fetch function to use for making requests. | | `opts.model?` | `string` | The model to use for completion. | | `opts.providers?` | [`Provider`](../interfaces/Provider.md)[] | Optional context providers. | -| `opts.recentMessageCount?` | `number` | The number of messages to hold in the recent message cache. | | `opts.serverUrl?` | `string` | The URL of the worker. | | `opts.token` | `string` | The JWT token, can be a JWT token if outside worker, or an OpenAI token if inside worker. | @@ -279,6 +279,55 @@ The embedding of the input. ___ +### ensureParticipantExists + +▸ **ensureParticipantExists**(`user_id`, `room_id`): `Promise`\<`void`\> + +Ensure the existence of a participant in the room. If the participant does not exist, they are added to the room. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The user ID to ensure the existence of. | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | + +#### Returns + +`Promise`\<`void`\> + +**`Throws`** + +An error if the participant cannot be added. + +___ + +### ensureRoomExists + +▸ **ensureRoomExists**(`user_id`, `room_id?`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> + +Ensure the existence of a room between the agent and a user. If no room exists, a new room is created and the user +and agent are added as participants. The room ID is returned. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The user ID to create a room with. | +| `room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | + +#### Returns + +`Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> + +The room ID of the room between the agent and the user. + +**`Throws`** + +An error if the room cannot be created. + +___ + ### evaluate ▸ **evaluate**(`message`, `state?`): `Promise`\<`string`[]\> @@ -300,9 +349,9 @@ The results of the evaluation. ___ -### getRecentMessageCount +### getConversationLength -▸ **getRecentMessageCount**(): `number` +▸ **getConversationLength**(): `number` Get the number of messages that are kept in the conversation buffer. diff --git a/docs/docs/classes/DatabaseAdapter.md b/docs/docs/classes/DatabaseAdapter.md index 4b529b0..9b66442 100644 --- a/docs/docs/classes/DatabaseAdapter.md +++ b/docs/docs/classes/DatabaseAdapter.md @@ -6,6 +6,9 @@ sidebar_position: 0 custom_edit_url: null --- +An abstract class representing a database adapter for managing various entities +like accounts, memories, actors, goals, and rooms. + ## Hierarchy - **`DatabaseAdapter`** @@ -30,18 +33,22 @@ custom_edit_url: null ### addParticipant -▸ **addParticipant**(`user_id`, `room_id`): `Promise`\<`void`\> +▸ **addParticipant**(`user_id`, `room_id`): `Promise`\<`boolean`\> + +Adds a user as a participant to a specific room. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user to add as a participant. | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to which the user will be added. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves to a boolean indicating success or failure. ___ @@ -49,33 +56,41 @@ ___ ▸ **countMemories**(`room_id`, `unique?`, `tableName?`): `Promise`\<`number`\> +Counts the number of memories in a specific room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `unique?` | `boolean` | -| `tableName?` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room for which to count memories. | +| `unique?` | `boolean` | Specifies whether to count only unique memories. | +| `tableName?` | `string` | Optional table name to count memories from. | #### Returns `Promise`\<`number`\> +A Promise that resolves to the number of memories. + ___ ### createAccount -▸ **createAccount**(`account`): `Promise`\<`void`\> +▸ **createAccount**(`account`): `Promise`\<`boolean`\> + +Creates a new account in the database. #### Parameters -| Name | Type | -| :------ | :------ | -| `account` | [`Account`](../interfaces/Account.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `account` | [`Account`](../interfaces/Account.md) | The account object to create. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves when the account creation is complete. ___ @@ -83,332 +98,484 @@ ___ ▸ **createGoal**(`goal`): `Promise`\<`void`\> +Creates a new goal in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goal` | [`Goal`](../interfaces/Goal.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goal` | [`Goal`](../interfaces/Goal.md) | The goal object to create. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been created. + ___ ### createMemory ▸ **createMemory**(`memory`, `tableName`, `unique?`): `Promise`\<`void`\> +Creates a new memory in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `memory` | [`Memory`](../interfaces/Memory.md) | -| `tableName` | `string` | -| `unique?` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `memory` | [`Memory`](../interfaces/Memory.md) | The memory object to create. | +| `tableName` | `string` | The table where the memory should be stored. | +| `unique?` | `boolean` | Indicates if the memory should be unique. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the memory has been created. + ___ ### createRelationship ▸ **createRelationship**(`params`): `Promise`\<`boolean`\> +Creates a new relationship between two users. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUIDs of the two users (userA and userB). | +| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<`boolean`\> +A Promise that resolves to a boolean indicating success or failure of the creation. + ___ ### createRoom ▸ **createRoom**(`room_id?`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> +Creates a new room with an optional specified ID. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | Optional UUID to assign to the new room. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> +A Promise that resolves to the UUID of the created room. + ___ ### getAccountById ▸ **getAccountById**(`user_id`): `Promise`\<``null`` \| [`Account`](../interfaces/Account.md)\> +Retrieves an account by its ID. + #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user account to retrieve. | #### Returns `Promise`\<``null`` \| [`Account`](../interfaces/Account.md)\> +A Promise that resolves to the Account object or null if not found. + ___ ### getActorDetails ▸ **getActorDetails**(`params`): `Promise`\<[`Actor`](../interfaces/Actor.md)[]\> +Retrieves details of actors in a given room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the room_id to search for actors. | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Actor`](../interfaces/Actor.md)[]\> +A Promise that resolves to an array of Actor objects. + ___ ### getCachedEmbeddings -▸ **getCachedEmbeddings**(`«destructured»`): `Promise`\<\{ `embedding`: `number`[] ; `levenshtein_score`: `number` }[]\> +▸ **getCachedEmbeddings**(`params`): `Promise`\<\{ `embedding`: `number`[] ; `levenshtein_score`: `number` }[]\> + +Retrieves cached embeddings based on the specified query parameters. #### Parameters -| Name | Type | -| :------ | :------ | -| `«destructured»` | `Object` | -| › `query_field_name` | `string` | -| › `query_field_sub_name` | `string` | -| › `query_input` | `string` | -| › `query_match_count` | `number` | -| › `query_table_name` | `string` | -| › `query_threshold` | `number` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the embedding retrieval. | +| `params.query_field_name` | `string` | - | +| `params.query_field_sub_name` | `string` | - | +| `params.query_input` | `string` | - | +| `params.query_match_count` | `number` | - | +| `params.query_table_name` | `string` | - | +| `params.query_threshold` | `number` | - | #### Returns `Promise`\<\{ `embedding`: `number`[] ; `levenshtein_score`: `number` }[]\> +A Promise that resolves to an array of objects containing embeddings and levenshtein scores. + ___ ### getGoals ▸ **getGoals**(`params`): `Promise`\<[`Goal`](../interfaces/Goal.md)[]\> +Retrieves goals based on specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.onlyInProgress?` | `boolean` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.user_id?` | ``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for goal retrieval. | +| `params.count?` | `number` | - | +| `params.onlyInProgress?` | `boolean` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.user_id?` | ``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Goal`](../interfaces/Goal.md)[]\> +A Promise that resolves to an array of Goal objects. + ___ ### getMemories ▸ **getMemories**(`params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Retrieves memories based on the specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique?` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the memory retrieval. | +| `params.count?` | `number` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique?` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + +___ + +### getParticipantsForAccount + +▸ **getParticipantsForAccount**(`user_id`): `Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +Retrieves participants associated with a specific account. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the account. | + +#### Returns + +`Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +A Promise that resolves to an array of Participant objects. + +▸ **getParticipantsForAccount**(`user_id`): `Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +Retrieves participants associated with a specific account. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the account. | + +#### Returns + +`Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +A Promise that resolves to an array of Participant objects. + +___ + +### getParticipantsForRoom + +▸ **getParticipantsForRoom**(`room_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +Retrieves participants for a specific room. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room for which to retrieve participants. | + +#### Returns + +`Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +A Promise that resolves to an array of UUIDs representing the participants. + ___ ### getRelationship ▸ **getRelationship**(`params`): `Promise`\<``null`` \| [`Relationship`](../interfaces/Relationship.md)\> +Retrieves a relationship between two users if it exists. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUIDs of the two users (userA and userB). | +| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<``null`` \| [`Relationship`](../interfaces/Relationship.md)\> +A Promise that resolves to the Relationship object or null if not found. + ___ ### getRelationships ▸ **getRelationships**(`params`): `Promise`\<[`Relationship`](../interfaces/Relationship.md)[]\> +Retrieves all relationships for a specific user. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUID of the user. | +| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Relationship`](../interfaces/Relationship.md)[]\> +A Promise that resolves to an array of Relationship objects. + ___ -### getRoomsByParticipant +### getRoom + +▸ **getRoom**(`room_id`): `Promise`\<``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> -▸ **getRoomsByParticipant**(`user_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +Retrieves the room ID for a given room, if it exists. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to retrieve. | + +#### Returns + +`Promise`\<``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> + +A Promise that resolves to the room ID or null if not found. + +___ + +### getRoomsForParticipant + +▸ **getRoomsForParticipant**(`user_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +Retrieves room IDs for which a specific user is a participant. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +A Promise that resolves to an array of room IDs. + ___ -### getRoomsByParticipants +### getRoomsForParticipants -▸ **getRoomsByParticipants**(`userIds`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +▸ **getRoomsForParticipants**(`userIds`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +Retrieves room IDs for which specific users are participants. #### Parameters -| Name | Type | -| :------ | :------ | -| `userIds` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] | +| Name | Type | Description | +| :------ | :------ | :------ | +| `userIds` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] | An array of UUIDs of the users. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +A Promise that resolves to an array of room IDs. + ___ ### log ▸ **log**(`params`): `Promise`\<`void`\> +Logs an event or action with the specified details. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.body` | `Object` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.type` | `string` | -| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the log entry. | +| `params.body` | `Object` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.type` | `string` | - | +| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<`void`\> +A Promise that resolves when the log entry has been saved. + ___ ### removeAllGoals ▸ **removeAllGoals**(`room_id`): `Promise`\<`void`\> +Removes all goals associated with a specific room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room whose goals should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when all goals have been removed. + ___ ### removeAllMemories ▸ **removeAllMemories**(`room_id`, `tableName`): `Promise`\<`void`\> +Removes all memories associated with a specific room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `tableName` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room whose memories should be removed. | +| `tableName` | `string` | The table from which the memories should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when all memories have been removed. + ___ ### removeGoal ▸ **removeGoal**(`goalId`): `Promise`\<`void`\> +Removes a specific goal from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the goal to remove. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been removed. + ___ ### removeMemory ▸ **removeMemory**(`memoryId`, `tableName`): `Promise`\<`void`\> +Removes a specific memory from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `memoryId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `tableName` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `memoryId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the memory to remove. | +| `tableName` | `string` | The table from which the memory should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the memory has been removed. + ___ -### removeParticipantFromRoom +### removeParticipant + +▸ **removeParticipant**(`user_id`, `room_id`): `Promise`\<`boolean`\> -▸ **removeParticipantFromRoom**(`user_id`, `room_id`): `Promise`\<`void`\> +Removes a user as a participant from a specific room. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user to remove as a participant. | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room from which the user will be removed. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves to a boolean indicating success or failure. ___ @@ -416,90 +583,110 @@ ___ ▸ **removeRoom**(`room_id`): `Promise`\<`void`\> +Removes a specific room from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to remove. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the room has been removed. + ___ ### searchMemories ▸ **searchMemories**(`params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Searches for memories based on embeddings and other specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.embedding` | `number`[] | -| `params.match_count` | `number` | -| `params.match_threshold` | `number` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the memory search. | +| `params.embedding` | `number`[] | - | +| `params.match_count` | `number` | - | +| `params.match_threshold` | `number` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + ___ ### searchMemoriesByEmbedding ▸ **searchMemoriesByEmbedding**(`embedding`, `params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Searches for memories by embedding and other specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `embedding` | `number`[] | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.match_threshold?` | `number` | -| `params.room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique?` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `embedding` | `number`[] | The embedding vector to search with. | +| `params` | `Object` | Additional parameters for the search. | +| `params.count?` | `number` | - | +| `params.match_threshold?` | `number` | - | +| `params.room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique?` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + ___ ### updateGoal ▸ **updateGoal**(`goal`): `Promise`\<`void`\> +Updates a specific goal in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goal` | [`Goal`](../interfaces/Goal.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goal` | [`Goal`](../interfaces/Goal.md) | The goal object with updated properties. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been updated. + ___ ### updateGoalStatus ▸ **updateGoalStatus**(`params`): `Promise`\<`void`\> +Updates the status of a specific goal. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.status` | [`GoalStatus`](../enums/GoalStatus.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the goalId and the new status. | +| `params.goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.status` | [`GoalStatus`](../enums/GoalStatus.md) | - | #### Returns `Promise`\<`void`\> + +A Promise that resolves when the goal status has been updated. diff --git a/docs/docs/classes/SqlJsDatabaseAdapter.md b/docs/docs/classes/SqlJsDatabaseAdapter.md index 8311b84..f15a66b 100644 --- a/docs/docs/classes/SqlJsDatabaseAdapter.md +++ b/docs/docs/classes/SqlJsDatabaseAdapter.md @@ -6,6 +6,9 @@ sidebar_position: 0 custom_edit_url: null --- +An abstract class representing a database adapter for managing various entities +like accounts, memories, actors, goals, and rooms. + ## Hierarchy - [`DatabaseAdapter`](DatabaseAdapter.md) @@ -42,18 +45,22 @@ custom_edit_url: null ### addParticipant -▸ **addParticipant**(`user_id`, `room_id`): `Promise`\<`void`\> +▸ **addParticipant**(`user_id`, `room_id`): `Promise`\<`boolean`\> + +Adds a user as a participant to a specific room. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user to add as a participant. | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to which the user will be added. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves to a boolean indicating success or failure. #### Overrides @@ -65,18 +72,22 @@ ___ ▸ **countMemories**(`room_id`, `unique?`, `tableName?`): `Promise`\<`number`\> +Counts the number of memories in a specific room. + #### Parameters -| Name | Type | Default value | -| :------ | :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | `undefined` | -| `unique` | `boolean` | `true` | -| `tableName` | `string` | `""` | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | `undefined` | The UUID of the room for which to count memories. | +| `unique` | `boolean` | `true` | Specifies whether to count only unique memories. | +| `tableName` | `string` | `""` | Optional table name to count memories from. | #### Returns `Promise`\<`number`\> +A Promise that resolves to the number of memories. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[countMemories](DatabaseAdapter.md#countmemories) @@ -85,17 +96,21 @@ ___ ### createAccount -▸ **createAccount**(`account`): `Promise`\<`void`\> +▸ **createAccount**(`account`): `Promise`\<`boolean`\> + +Creates a new account in the database. #### Parameters -| Name | Type | -| :------ | :------ | -| `account` | [`Account`](../interfaces/Account.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `account` | [`Account`](../interfaces/Account.md) | The account object to create. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves when the account creation is complete. #### Overrides @@ -107,16 +122,20 @@ ___ ▸ **createGoal**(`goal`): `Promise`\<`void`\> +Creates a new goal in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goal` | [`Goal`](../interfaces/Goal.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goal` | [`Goal`](../interfaces/Goal.md) | The goal object to create. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been created. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createGoal](DatabaseAdapter.md#creategoal) @@ -127,17 +146,21 @@ ___ ▸ **createMemory**(`memory`, `tableName`): `Promise`\<`void`\> +Creates a new memory in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `memory` | [`Memory`](../interfaces/Memory.md) | -| `tableName` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `memory` | [`Memory`](../interfaces/Memory.md) | The memory object to create. | +| `tableName` | `string` | The table where the memory should be stored. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the memory has been created. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createMemory](DatabaseAdapter.md#creatememory) @@ -148,18 +171,22 @@ ___ ▸ **createRelationship**(`params`): `Promise`\<`boolean`\> +Creates a new relationship between two users. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUIDs of the two users (userA and userB). | +| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<`boolean`\> +A Promise that resolves to a boolean indicating success or failure of the creation. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createRelationship](DatabaseAdapter.md#createrelationship) @@ -170,16 +197,20 @@ ___ ▸ **createRoom**(`room_id?`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> +Creates a new room with an optional specified ID. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | Optional UUID to assign to the new room. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> +A Promise that resolves to the UUID of the created room. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createRoom](DatabaseAdapter.md#createroom) @@ -190,16 +221,20 @@ ___ ▸ **getAccountById**(`user_id`): `Promise`\<``null`` \| [`Account`](../interfaces/Account.md)\> +Retrieves an account by its ID. + #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user account to retrieve. | #### Returns `Promise`\<``null`` \| [`Account`](../interfaces/Account.md)\> +A Promise that resolves to the Account object or null if not found. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getAccountById](DatabaseAdapter.md#getaccountbyid) @@ -210,17 +245,21 @@ ___ ▸ **getActorDetails**(`params`): `Promise`\<[`Actor`](../interfaces/Actor.md)[]\> +Retrieves details of actors in a given room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the room_id to search for actors. | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Actor`](../interfaces/Actor.md)[]\> +A Promise that resolves to an array of Actor objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getActorDetails](DatabaseAdapter.md#getactordetails) @@ -231,22 +270,26 @@ ___ ▸ **getCachedEmbeddings**(`opts`): `Promise`\<\{ `embedding`: `number`[] ; `levenshtein_score`: `number` }[]\> +Retrieves cached embeddings based on the specified query parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `opts` | `Object` | -| `opts.query_field_name` | `string` | -| `opts.query_field_sub_name` | `string` | -| `opts.query_input` | `string` | -| `opts.query_match_count` | `number` | -| `opts.query_table_name` | `string` | -| `opts.query_threshold` | `number` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `opts` | `Object` | An object containing parameters for the embedding retrieval. | +| `opts.query_field_name` | `string` | - | +| `opts.query_field_sub_name` | `string` | - | +| `opts.query_input` | `string` | - | +| `opts.query_match_count` | `number` | - | +| `opts.query_table_name` | `string` | - | +| `opts.query_threshold` | `number` | - | #### Returns `Promise`\<\{ `embedding`: `number`[] ; `levenshtein_score`: `number` }[]\> +A Promise that resolves to an array of objects containing embeddings and levenshtein scores. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getCachedEmbeddings](DatabaseAdapter.md#getcachedembeddings) @@ -257,20 +300,24 @@ ___ ▸ **getGoals**(`params`): `Promise`\<[`Goal`](../interfaces/Goal.md)[]\> +Retrieves goals based on specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.onlyInProgress?` | `boolean` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.user_id?` | ``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for goal retrieval. | +| `params.count?` | `number` | - | +| `params.onlyInProgress?` | `boolean` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.user_id?` | ``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Goal`](../interfaces/Goal.md)[]\> +A Promise that resolves to an array of Goal objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getGoals](DatabaseAdapter.md#getgoals) @@ -281,42 +328,98 @@ ___ ▸ **getMemories**(`params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Retrieves memories based on the specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique?` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the memory retrieval. | +| `params.count?` | `number` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique?` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getMemories](DatabaseAdapter.md#getmemories) ___ +### getParticipantsForAccount + +▸ **getParticipantsForAccount**(`user_id`): `Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +Retrieves participants associated with a specific account. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the account. | + +#### Returns + +`Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +A Promise that resolves to an array of Participant objects. + +#### Overrides + +[DatabaseAdapter](DatabaseAdapter.md).[getParticipantsForAccount](DatabaseAdapter.md#getparticipantsforaccount) + +___ + +### getParticipantsForRoom + +▸ **getParticipantsForRoom**(`room_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +Retrieves participants for a specific room. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room for which to retrieve participants. | + +#### Returns + +`Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +A Promise that resolves to an array of UUIDs representing the participants. + +#### Overrides + +[DatabaseAdapter](DatabaseAdapter.md).[getParticipantsForRoom](DatabaseAdapter.md#getparticipantsforroom) + +___ + ### getRelationship ▸ **getRelationship**(`params`): `Promise`\<``null`` \| [`Relationship`](../interfaces/Relationship.md)\> +Retrieves a relationship between two users if it exists. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUIDs of the two users (userA and userB). | +| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<``null`` \| [`Relationship`](../interfaces/Relationship.md)\> +A Promise that resolves to the Relationship object or null if not found. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getRelationship](DatabaseAdapter.md#getrelationship) @@ -327,60 +430,96 @@ ___ ▸ **getRelationships**(`params`): `Promise`\<[`Relationship`](../interfaces/Relationship.md)[]\> +Retrieves all relationships for a specific user. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUID of the user. | +| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Relationship`](../interfaces/Relationship.md)[]\> +A Promise that resolves to an array of Relationship objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getRelationships](DatabaseAdapter.md#getrelationships) ___ -### getRoomsByParticipant +### getRoom + +▸ **getRoom**(`room_id`): `Promise`\<``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> -▸ **getRoomsByParticipant**(`user_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +Retrieves the room ID for a given room, if it exists. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to retrieve. | + +#### Returns + +`Promise`\<``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> + +A Promise that resolves to the room ID or null if not found. + +#### Overrides + +[DatabaseAdapter](DatabaseAdapter.md).[getRoom](DatabaseAdapter.md#getroom) + +___ + +### getRoomsForParticipant + +▸ **getRoomsForParticipant**(`user_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +Retrieves room IDs for which a specific user is a participant. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +A Promise that resolves to an array of room IDs. + #### Overrides -[DatabaseAdapter](DatabaseAdapter.md).[getRoomsByParticipant](DatabaseAdapter.md#getroomsbyparticipant) +[DatabaseAdapter](DatabaseAdapter.md).[getRoomsForParticipant](DatabaseAdapter.md#getroomsforparticipant) ___ -### getRoomsByParticipants +### getRoomsForParticipants + +▸ **getRoomsForParticipants**(`userIds`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> -▸ **getRoomsByParticipants**(`userIds`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +Retrieves room IDs for which specific users are participants. #### Parameters -| Name | Type | -| :------ | :------ | -| `userIds` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] | +| Name | Type | Description | +| :------ | :------ | :------ | +| `userIds` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] | An array of UUIDs of the users. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +A Promise that resolves to an array of room IDs. + #### Overrides -[DatabaseAdapter](DatabaseAdapter.md).[getRoomsByParticipants](DatabaseAdapter.md#getroomsbyparticipants) +[DatabaseAdapter](DatabaseAdapter.md).[getRoomsForParticipants](DatabaseAdapter.md#getroomsforparticipants) ___ @@ -388,20 +527,24 @@ ___ ▸ **log**(`params`): `Promise`\<`void`\> +Logs an event or action with the specified details. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.body` | `Object` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.type` | `string` | -| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the log entry. | +| `params.body` | `Object` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.type` | `string` | - | +| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<`void`\> +A Promise that resolves when the log entry has been saved. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[log](DatabaseAdapter.md#log) @@ -412,16 +555,20 @@ ___ ▸ **removeAllGoals**(`room_id`): `Promise`\<`void`\> +Removes all goals associated with a specific room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room whose goals should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when all goals have been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeAllGoals](DatabaseAdapter.md#removeallgoals) @@ -432,17 +579,21 @@ ___ ▸ **removeAllMemories**(`room_id`, `tableName`): `Promise`\<`void`\> +Removes all memories associated with a specific room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `tableName` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room whose memories should be removed. | +| `tableName` | `string` | The table from which the memories should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when all memories have been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeAllMemories](DatabaseAdapter.md#removeallmemories) @@ -453,16 +604,20 @@ ___ ▸ **removeGoal**(`goalId`): `Promise`\<`void`\> +Removes a specific goal from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the goal to remove. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeGoal](DatabaseAdapter.md#removegoal) @@ -473,41 +628,49 @@ ___ ▸ **removeMemory**(`memoryId`, `tableName`): `Promise`\<`void`\> +Removes a specific memory from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `memoryId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `tableName` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `memoryId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the memory to remove. | +| `tableName` | `string` | The table from which the memory should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the memory has been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeMemory](DatabaseAdapter.md#removememory) ___ -### removeParticipantFromRoom +### removeParticipant -▸ **removeParticipantFromRoom**(`user_id`, `room_id`): `Promise`\<`void`\> +▸ **removeParticipant**(`user_id`, `room_id`): `Promise`\<`boolean`\> + +Removes a user as a participant from a specific room. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user to remove as a participant. | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room from which the user will be removed. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves to a boolean indicating success or failure. #### Overrides -[DatabaseAdapter](DatabaseAdapter.md).[removeParticipantFromRoom](DatabaseAdapter.md#removeparticipantfromroom) +[DatabaseAdapter](DatabaseAdapter.md).[removeParticipant](DatabaseAdapter.md#removeparticipant) ___ @@ -515,16 +678,20 @@ ___ ▸ **removeRoom**(`room_id`): `Promise`\<`void`\> +Removes a specific room from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to remove. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the room has been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeRoom](DatabaseAdapter.md#removeroom) @@ -535,22 +702,26 @@ ___ ▸ **searchMemories**(`params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Searches for memories based on embeddings and other specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.embedding` | `number`[] | -| `params.match_count` | `number` | -| `params.match_threshold` | `number` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the memory search. | +| `params.embedding` | `number`[] | - | +| `params.match_count` | `number` | - | +| `params.match_threshold` | `number` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[searchMemories](DatabaseAdapter.md#searchmemories) @@ -561,22 +732,26 @@ ___ ▸ **searchMemoriesByEmbedding**(`_embedding`, `params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Searches for memories by embedding and other specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `_embedding` | `number`[] | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.match_threshold?` | `number` | -| `params.room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique?` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `_embedding` | `number`[] | The embedding vector to search with. | +| `params` | `Object` | Additional parameters for the search. | +| `params.count?` | `number` | - | +| `params.match_threshold?` | `number` | - | +| `params.room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique?` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[searchMemoriesByEmbedding](DatabaseAdapter.md#searchmemoriesbyembedding) @@ -587,16 +762,20 @@ ___ ▸ **updateGoal**(`goal`): `Promise`\<`void`\> +Updates a specific goal in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goal` | [`Goal`](../interfaces/Goal.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goal` | [`Goal`](../interfaces/Goal.md) | The goal object with updated properties. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been updated. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[updateGoal](DatabaseAdapter.md#updategoal) @@ -607,18 +786,22 @@ ___ ▸ **updateGoalStatus**(`params`): `Promise`\<`void`\> +Updates the status of a specific goal. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.status` | [`GoalStatus`](../enums/GoalStatus.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the goalId and the new status. | +| `params.goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.status` | [`GoalStatus`](../enums/GoalStatus.md) | - | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal status has been updated. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[updateGoalStatus](DatabaseAdapter.md#updategoalstatus) diff --git a/docs/docs/classes/SqliteDatabaseAdapter.md b/docs/docs/classes/SqliteDatabaseAdapter.md index 4b099b7..d34ac6b 100644 --- a/docs/docs/classes/SqliteDatabaseAdapter.md +++ b/docs/docs/classes/SqliteDatabaseAdapter.md @@ -6,6 +6,9 @@ sidebar_position: 0 custom_edit_url: null --- +An abstract class representing a database adapter for managing various entities +like accounts, memories, actors, goals, and rooms. + ## Hierarchy - [`DatabaseAdapter`](DatabaseAdapter.md) @@ -42,18 +45,22 @@ custom_edit_url: null ### addParticipant -▸ **addParticipant**(`user_id`, `room_id`): `Promise`\<`void`\> +▸ **addParticipant**(`user_id`, `room_id`): `Promise`\<`boolean`\> + +Adds a user as a participant to a specific room. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user to add as a participant. | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to which the user will be added. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves to a boolean indicating success or failure. #### Overrides @@ -65,18 +72,22 @@ ___ ▸ **countMemories**(`room_id`, `unique?`, `tableName?`): `Promise`\<`number`\> +Counts the number of memories in a specific room. + #### Parameters -| Name | Type | Default value | -| :------ | :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | `undefined` | -| `unique` | `boolean` | `true` | -| `tableName` | `string` | `""` | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | `undefined` | The UUID of the room for which to count memories. | +| `unique` | `boolean` | `true` | Specifies whether to count only unique memories. | +| `tableName` | `string` | `""` | Optional table name to count memories from. | #### Returns `Promise`\<`number`\> +A Promise that resolves to the number of memories. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[countMemories](DatabaseAdapter.md#countmemories) @@ -85,17 +96,21 @@ ___ ### createAccount -▸ **createAccount**(`account`): `Promise`\<`void`\> +▸ **createAccount**(`account`): `Promise`\<`boolean`\> + +Creates a new account in the database. #### Parameters -| Name | Type | -| :------ | :------ | -| `account` | [`Account`](../interfaces/Account.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `account` | [`Account`](../interfaces/Account.md) | The account object to create. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves when the account creation is complete. #### Overrides @@ -107,16 +122,20 @@ ___ ▸ **createGoal**(`goal`): `Promise`\<`void`\> +Creates a new goal in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goal` | [`Goal`](../interfaces/Goal.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goal` | [`Goal`](../interfaces/Goal.md) | The goal object to create. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been created. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createGoal](DatabaseAdapter.md#creategoal) @@ -127,17 +146,21 @@ ___ ▸ **createMemory**(`memory`, `tableName`): `Promise`\<`void`\> +Creates a new memory in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `memory` | [`Memory`](../interfaces/Memory.md) | -| `tableName` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `memory` | [`Memory`](../interfaces/Memory.md) | The memory object to create. | +| `tableName` | `string` | The table where the memory should be stored. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the memory has been created. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createMemory](DatabaseAdapter.md#creatememory) @@ -148,18 +171,22 @@ ___ ▸ **createRelationship**(`params`): `Promise`\<`boolean`\> +Creates a new relationship between two users. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUIDs of the two users (userA and userB). | +| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<`boolean`\> +A Promise that resolves to a boolean indicating success or failure of the creation. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createRelationship](DatabaseAdapter.md#createrelationship) @@ -170,16 +197,20 @@ ___ ▸ **createRoom**(`room_id?`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> +Creates a new room with an optional specified ID. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | Optional UUID to assign to the new room. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> +A Promise that resolves to the UUID of the created room. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createRoom](DatabaseAdapter.md#createroom) @@ -190,16 +221,20 @@ ___ ▸ **getAccountById**(`user_id`): `Promise`\<``null`` \| [`Account`](../interfaces/Account.md)\> +Retrieves an account by its ID. + #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user account to retrieve. | #### Returns `Promise`\<``null`` \| [`Account`](../interfaces/Account.md)\> +A Promise that resolves to the Account object or null if not found. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getAccountById](DatabaseAdapter.md#getaccountbyid) @@ -210,17 +245,21 @@ ___ ▸ **getActorDetails**(`params`): `Promise`\<[`Actor`](../interfaces/Actor.md)[]\> +Retrieves details of actors in a given room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the room_id to search for actors. | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Actor`](../interfaces/Actor.md)[]\> +A Promise that resolves to an array of Actor objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getActorDetails](DatabaseAdapter.md#getactordetails) @@ -231,22 +270,26 @@ ___ ▸ **getCachedEmbeddings**(`opts`): `Promise`\<\{ `embedding`: `number`[] ; `levenshtein_score`: `number` }[]\> +Retrieves cached embeddings based on the specified query parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `opts` | `Object` | -| `opts.query_field_name` | `string` | -| `opts.query_field_sub_name` | `string` | -| `opts.query_input` | `string` | -| `opts.query_match_count` | `number` | -| `opts.query_table_name` | `string` | -| `opts.query_threshold` | `number` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `opts` | `Object` | An object containing parameters for the embedding retrieval. | +| `opts.query_field_name` | `string` | - | +| `opts.query_field_sub_name` | `string` | - | +| `opts.query_input` | `string` | - | +| `opts.query_match_count` | `number` | - | +| `opts.query_table_name` | `string` | - | +| `opts.query_threshold` | `number` | - | #### Returns `Promise`\<\{ `embedding`: `number`[] ; `levenshtein_score`: `number` }[]\> +A Promise that resolves to an array of objects containing embeddings and levenshtein scores. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getCachedEmbeddings](DatabaseAdapter.md#getcachedembeddings) @@ -257,20 +300,24 @@ ___ ▸ **getGoals**(`params`): `Promise`\<[`Goal`](../interfaces/Goal.md)[]\> +Retrieves goals based on specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.onlyInProgress?` | `boolean` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.user_id?` | ``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for goal retrieval. | +| `params.count?` | `number` | - | +| `params.onlyInProgress?` | `boolean` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.user_id?` | ``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Goal`](../interfaces/Goal.md)[]\> +A Promise that resolves to an array of Goal objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getGoals](DatabaseAdapter.md#getgoals) @@ -281,42 +328,98 @@ ___ ▸ **getMemories**(`params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Retrieves memories based on the specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique?` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the memory retrieval. | +| `params.count?` | `number` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique?` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getMemories](DatabaseAdapter.md#getmemories) ___ +### getParticipantsForAccount + +▸ **getParticipantsForAccount**(`user_id`): `Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +Retrieves participants associated with a specific account. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the account. | + +#### Returns + +`Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +A Promise that resolves to an array of Participant objects. + +#### Overrides + +[DatabaseAdapter](DatabaseAdapter.md).[getParticipantsForAccount](DatabaseAdapter.md#getparticipantsforaccount) + +___ + +### getParticipantsForRoom + +▸ **getParticipantsForRoom**(`room_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +Retrieves participants for a specific room. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room for which to retrieve participants. | + +#### Returns + +`Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +A Promise that resolves to an array of UUIDs representing the participants. + +#### Overrides + +[DatabaseAdapter](DatabaseAdapter.md).[getParticipantsForRoom](DatabaseAdapter.md#getparticipantsforroom) + +___ + ### getRelationship ▸ **getRelationship**(`params`): `Promise`\<``null`` \| [`Relationship`](../interfaces/Relationship.md)\> +Retrieves a relationship between two users if it exists. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUIDs of the two users (userA and userB). | +| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<``null`` \| [`Relationship`](../interfaces/Relationship.md)\> +A Promise that resolves to the Relationship object or null if not found. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getRelationship](DatabaseAdapter.md#getrelationship) @@ -327,60 +430,96 @@ ___ ▸ **getRelationships**(`params`): `Promise`\<[`Relationship`](../interfaces/Relationship.md)[]\> +Retrieves all relationships for a specific user. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUID of the user. | +| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Relationship`](../interfaces/Relationship.md)[]\> +A Promise that resolves to an array of Relationship objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getRelationships](DatabaseAdapter.md#getrelationships) ___ -### getRoomsByParticipant +### getRoom + +▸ **getRoom**(`room_id`): `Promise`\<``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> -▸ **getRoomsByParticipant**(`user_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +Retrieves the room ID for a given room, if it exists. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to retrieve. | + +#### Returns + +`Promise`\<``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> + +A Promise that resolves to the room ID or null if not found. + +#### Overrides + +[DatabaseAdapter](DatabaseAdapter.md).[getRoom](DatabaseAdapter.md#getroom) + +___ + +### getRoomsForParticipant + +▸ **getRoomsForParticipant**(`user_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +Retrieves room IDs for which a specific user is a participant. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +A Promise that resolves to an array of room IDs. + #### Overrides -[DatabaseAdapter](DatabaseAdapter.md).[getRoomsByParticipant](DatabaseAdapter.md#getroomsbyparticipant) +[DatabaseAdapter](DatabaseAdapter.md).[getRoomsForParticipant](DatabaseAdapter.md#getroomsforparticipant) ___ -### getRoomsByParticipants +### getRoomsForParticipants + +▸ **getRoomsForParticipants**(`userIds`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> -▸ **getRoomsByParticipants**(`userIds`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +Retrieves room IDs for which specific users are participants. #### Parameters -| Name | Type | -| :------ | :------ | -| `userIds` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] | +| Name | Type | Description | +| :------ | :------ | :------ | +| `userIds` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] | An array of UUIDs of the users. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +A Promise that resolves to an array of room IDs. + #### Overrides -[DatabaseAdapter](DatabaseAdapter.md).[getRoomsByParticipants](DatabaseAdapter.md#getroomsbyparticipants) +[DatabaseAdapter](DatabaseAdapter.md).[getRoomsForParticipants](DatabaseAdapter.md#getroomsforparticipants) ___ @@ -388,20 +527,24 @@ ___ ▸ **log**(`params`): `Promise`\<`void`\> +Logs an event or action with the specified details. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.body` | `Object` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.type` | `string` | -| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the log entry. | +| `params.body` | `Object` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.type` | `string` | - | +| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<`void`\> +A Promise that resolves when the log entry has been saved. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[log](DatabaseAdapter.md#log) @@ -412,16 +555,20 @@ ___ ▸ **removeAllGoals**(`room_id`): `Promise`\<`void`\> +Removes all goals associated with a specific room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room whose goals should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when all goals have been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeAllGoals](DatabaseAdapter.md#removeallgoals) @@ -432,17 +579,21 @@ ___ ▸ **removeAllMemories**(`room_id`, `tableName`): `Promise`\<`void`\> +Removes all memories associated with a specific room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `tableName` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room whose memories should be removed. | +| `tableName` | `string` | The table from which the memories should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when all memories have been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeAllMemories](DatabaseAdapter.md#removeallmemories) @@ -453,16 +604,20 @@ ___ ▸ **removeGoal**(`goalId`): `Promise`\<`void`\> +Removes a specific goal from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the goal to remove. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeGoal](DatabaseAdapter.md#removegoal) @@ -473,41 +628,49 @@ ___ ▸ **removeMemory**(`memoryId`, `tableName`): `Promise`\<`void`\> +Removes a specific memory from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `memoryId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `tableName` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `memoryId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the memory to remove. | +| `tableName` | `string` | The table from which the memory should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the memory has been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeMemory](DatabaseAdapter.md#removememory) ___ -### removeParticipantFromRoom +### removeParticipant -▸ **removeParticipantFromRoom**(`user_id`, `room_id`): `Promise`\<`void`\> +▸ **removeParticipant**(`user_id`, `room_id`): `Promise`\<`boolean`\> + +Removes a user as a participant from a specific room. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user to remove as a participant. | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room from which the user will be removed. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves to a boolean indicating success or failure. #### Overrides -[DatabaseAdapter](DatabaseAdapter.md).[removeParticipantFromRoom](DatabaseAdapter.md#removeparticipantfromroom) +[DatabaseAdapter](DatabaseAdapter.md).[removeParticipant](DatabaseAdapter.md#removeparticipant) ___ @@ -515,16 +678,20 @@ ___ ▸ **removeRoom**(`room_id`): `Promise`\<`void`\> +Removes a specific room from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to remove. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the room has been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeRoom](DatabaseAdapter.md#removeroom) @@ -535,22 +702,26 @@ ___ ▸ **searchMemories**(`params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Searches for memories based on embeddings and other specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.embedding` | `number`[] | -| `params.match_count` | `number` | -| `params.match_threshold` | `number` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the memory search. | +| `params.embedding` | `number`[] | - | +| `params.match_count` | `number` | - | +| `params.match_threshold` | `number` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[searchMemories](DatabaseAdapter.md#searchmemories) @@ -561,22 +732,26 @@ ___ ▸ **searchMemoriesByEmbedding**(`embedding`, `params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Searches for memories by embedding and other specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `embedding` | `number`[] | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.match_threshold?` | `number` | -| `params.room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique?` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `embedding` | `number`[] | The embedding vector to search with. | +| `params` | `Object` | Additional parameters for the search. | +| `params.count?` | `number` | - | +| `params.match_threshold?` | `number` | - | +| `params.room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique?` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[searchMemoriesByEmbedding](DatabaseAdapter.md#searchmemoriesbyembedding) @@ -587,16 +762,20 @@ ___ ▸ **updateGoal**(`goal`): `Promise`\<`void`\> +Updates a specific goal in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goal` | [`Goal`](../interfaces/Goal.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goal` | [`Goal`](../interfaces/Goal.md) | The goal object with updated properties. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been updated. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[updateGoal](DatabaseAdapter.md#updategoal) @@ -607,18 +786,22 @@ ___ ▸ **updateGoalStatus**(`params`): `Promise`\<`void`\> +Updates the status of a specific goal. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.status` | [`GoalStatus`](../enums/GoalStatus.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the goalId and the new status. | +| `params.goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.status` | [`GoalStatus`](../enums/GoalStatus.md) | - | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal status has been updated. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[updateGoalStatus](DatabaseAdapter.md#updategoalstatus) diff --git a/docs/docs/classes/SupabaseDatabaseAdapter.md b/docs/docs/classes/SupabaseDatabaseAdapter.md index e335471..09bfed2 100644 --- a/docs/docs/classes/SupabaseDatabaseAdapter.md +++ b/docs/docs/classes/SupabaseDatabaseAdapter.md @@ -6,6 +6,9 @@ sidebar_position: 0 custom_edit_url: null --- +An abstract class representing a database adapter for managing various entities +like accounts, memories, actors, goals, and rooms. + ## Hierarchy - [`DatabaseAdapter`](DatabaseAdapter.md) @@ -43,18 +46,22 @@ custom_edit_url: null ### addParticipant -▸ **addParticipant**(`user_id`, `room_id`): `Promise`\<`void`\> +▸ **addParticipant**(`user_id`, `room_id`): `Promise`\<`boolean`\> + +Adds a user as a participant to a specific room. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user to add as a participant. | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to which the user will be added. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves to a boolean indicating success or failure. #### Overrides @@ -66,18 +73,22 @@ ___ ▸ **countMemories**(`room_id`, `unique?`, `tableName`): `Promise`\<`number`\> +Counts the number of memories in a specific room. + #### Parameters -| Name | Type | Default value | -| :------ | :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | `undefined` | -| `unique` | `boolean` | `true` | -| `tableName` | `string` | `undefined` | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | `undefined` | The UUID of the room for which to count memories. | +| `unique` | `boolean` | `true` | Specifies whether to count only unique memories. | +| `tableName` | `string` | `undefined` | Optional table name to count memories from. | #### Returns `Promise`\<`number`\> +A Promise that resolves to the number of memories. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[countMemories](DatabaseAdapter.md#countmemories) @@ -86,17 +97,21 @@ ___ ### createAccount -▸ **createAccount**(`account`): `Promise`\<`void`\> +▸ **createAccount**(`account`): `Promise`\<`boolean`\> + +Creates a new account in the database. #### Parameters -| Name | Type | -| :------ | :------ | -| `account` | [`Account`](../interfaces/Account.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `account` | [`Account`](../interfaces/Account.md) | The account object to create. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves when the account creation is complete. #### Overrides @@ -108,16 +123,20 @@ ___ ▸ **createGoal**(`goal`): `Promise`\<`void`\> +Creates a new goal in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goal` | [`Goal`](../interfaces/Goal.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goal` | [`Goal`](../interfaces/Goal.md) | The goal object to create. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been created. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createGoal](DatabaseAdapter.md#creategoal) @@ -128,18 +147,22 @@ ___ ▸ **createMemory**(`memory`, `tableName`, `unique?`): `Promise`\<`void`\> +Creates a new memory in the database. + #### Parameters -| Name | Type | Default value | -| :------ | :------ | :------ | -| `memory` | [`Memory`](../interfaces/Memory.md) | `undefined` | -| `tableName` | `string` | `undefined` | -| `unique` | `boolean` | `false` | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `memory` | [`Memory`](../interfaces/Memory.md) | `undefined` | The memory object to create. | +| `tableName` | `string` | `undefined` | The table where the memory should be stored. | +| `unique` | `boolean` | `false` | Indicates if the memory should be unique. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the memory has been created. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createMemory](DatabaseAdapter.md#creatememory) @@ -150,18 +173,22 @@ ___ ▸ **createRelationship**(`params`): `Promise`\<`boolean`\> +Creates a new relationship between two users. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUIDs of the two users (userA and userB). | +| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<`boolean`\> +A Promise that resolves to a boolean indicating success or failure of the creation. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createRelationship](DatabaseAdapter.md#createrelationship) @@ -172,16 +199,20 @@ ___ ▸ **createRoom**(`room_id?`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> +Creates a new room with an optional specified ID. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | Optional UUID to assign to the new room. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> +A Promise that resolves to the UUID of the created room. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[createRoom](DatabaseAdapter.md#createroom) @@ -192,16 +223,20 @@ ___ ▸ **getAccountById**(`user_id`): `Promise`\<``null`` \| [`Account`](../interfaces/Account.md)\> +Retrieves an account by its ID. + #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user account to retrieve. | #### Returns `Promise`\<``null`` \| [`Account`](../interfaces/Account.md)\> +A Promise that resolves to the Account object or null if not found. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getAccountById](DatabaseAdapter.md#getaccountbyid) @@ -212,17 +247,21 @@ ___ ▸ **getActorDetails**(`params`): `Promise`\<[`Actor`](../interfaces/Actor.md)[]\> +Retrieves details of actors in a given room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the room_id to search for actors. | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Actor`](../interfaces/Actor.md)[]\> +A Promise that resolves to an array of Actor objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getActorDetails](DatabaseAdapter.md#getactordetails) @@ -233,22 +272,26 @@ ___ ▸ **getCachedEmbeddings**(`opts`): `Promise`\<\{ `embedding`: `number`[] ; `levenshtein_score`: `number` }[]\> +Retrieves cached embeddings based on the specified query parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `opts` | `Object` | -| `opts.query_field_name` | `string` | -| `opts.query_field_sub_name` | `string` | -| `opts.query_input` | `string` | -| `opts.query_match_count` | `number` | -| `opts.query_table_name` | `string` | -| `opts.query_threshold` | `number` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `opts` | `Object` | An object containing parameters for the embedding retrieval. | +| `opts.query_field_name` | `string` | - | +| `opts.query_field_sub_name` | `string` | - | +| `opts.query_input` | `string` | - | +| `opts.query_match_count` | `number` | - | +| `opts.query_table_name` | `string` | - | +| `opts.query_threshold` | `number` | - | #### Returns `Promise`\<\{ `embedding`: `number`[] ; `levenshtein_score`: `number` }[]\> +A Promise that resolves to an array of objects containing embeddings and levenshtein scores. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getCachedEmbeddings](DatabaseAdapter.md#getcachedembeddings) @@ -259,20 +302,24 @@ ___ ▸ **getGoals**(`params`): `Promise`\<[`Goal`](../interfaces/Goal.md)[]\> +Retrieves goals based on specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.onlyInProgress?` | `boolean` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.user_id?` | ``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for goal retrieval. | +| `params.count?` | `number` | - | +| `params.onlyInProgress?` | `boolean` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.user_id?` | ``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Goal`](../interfaces/Goal.md)[]\> +A Promise that resolves to an array of Goal objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getGoals](DatabaseAdapter.md#getgoals) @@ -283,42 +330,98 @@ ___ ▸ **getMemories**(`params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Retrieves memories based on the specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique?` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the memory retrieval. | +| `params.count?` | `number` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique?` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getMemories](DatabaseAdapter.md#getmemories) ___ +### getParticipantsForAccount + +▸ **getParticipantsForAccount**(`user_id`): `Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +Retrieves participants associated with a specific account. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the account. | + +#### Returns + +`Promise`\<[`Participant`](../interfaces/Participant.md)[]\> + +A Promise that resolves to an array of Participant objects. + +#### Overrides + +[DatabaseAdapter](DatabaseAdapter.md).[getParticipantsForAccount](DatabaseAdapter.md#getparticipantsforaccount) + +___ + +### getParticipantsForRoom + +▸ **getParticipantsForRoom**(`room_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +Retrieves participants for a specific room. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room for which to retrieve participants. | + +#### Returns + +`Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +A Promise that resolves to an array of UUIDs representing the participants. + +#### Overrides + +[DatabaseAdapter](DatabaseAdapter.md).[getParticipantsForRoom](DatabaseAdapter.md#getparticipantsforroom) + +___ + ### getRelationship ▸ **getRelationship**(`params`): `Promise`\<``null`` \| [`Relationship`](../interfaces/Relationship.md)\> +Retrieves a relationship between two users if it exists. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUIDs of the two users (userA and userB). | +| `params.userA` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.userB` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<``null`` \| [`Relationship`](../interfaces/Relationship.md)\> +A Promise that resolves to the Relationship object or null if not found. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getRelationship](DatabaseAdapter.md#getrelationship) @@ -329,60 +432,96 @@ ___ ▸ **getRelationships**(`params`): `Promise`\<[`Relationship`](../interfaces/Relationship.md)[]\> +Retrieves all relationships for a specific user. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the UUID of the user. | +| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<[`Relationship`](../interfaces/Relationship.md)[]\> +A Promise that resolves to an array of Relationship objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[getRelationships](DatabaseAdapter.md#getrelationships) ___ -### getRoomsByParticipant +### getRoom + +▸ **getRoom**(`room_id`): `Promise`\<``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> -▸ **getRoomsByParticipant**(`user_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +Retrieves the room ID for a given room, if it exists. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to retrieve. | + +#### Returns + +`Promise`\<``null`` \| \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`\> + +A Promise that resolves to the room ID or null if not found. + +#### Overrides + +[DatabaseAdapter](DatabaseAdapter.md).[getRoom](DatabaseAdapter.md#getroom) + +___ + +### getRoomsForParticipant + +▸ **getRoomsForParticipant**(`user_id`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> + +Retrieves room IDs for which a specific user is a participant. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +A Promise that resolves to an array of room IDs. + #### Overrides -[DatabaseAdapter](DatabaseAdapter.md).[getRoomsByParticipant](DatabaseAdapter.md#getroomsbyparticipant) +[DatabaseAdapter](DatabaseAdapter.md).[getRoomsForParticipant](DatabaseAdapter.md#getroomsforparticipant) ___ -### getRoomsByParticipants +### getRoomsForParticipants + +▸ **getRoomsForParticipants**(`userIds`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> -▸ **getRoomsByParticipants**(`userIds`): `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +Retrieves room IDs for which specific users are participants. #### Parameters -| Name | Type | -| :------ | :------ | -| `userIds` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] | +| Name | Type | Description | +| :------ | :------ | :------ | +| `userIds` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] | An array of UUIDs of the users. | #### Returns `Promise`\<\`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[]\> +A Promise that resolves to an array of room IDs. + #### Overrides -[DatabaseAdapter](DatabaseAdapter.md).[getRoomsByParticipants](DatabaseAdapter.md#getroomsbyparticipants) +[DatabaseAdapter](DatabaseAdapter.md).[getRoomsForParticipants](DatabaseAdapter.md#getroomsforparticipants) ___ @@ -390,20 +529,24 @@ ___ ▸ **log**(`params`): `Promise`\<`void`\> +Logs an event or action with the specified details. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.body` | `Object` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.type` | `string` | -| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the log entry. | +| `params.body` | `Object` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.type` | `string` | - | +| `params.user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | #### Returns `Promise`\<`void`\> +A Promise that resolves when the log entry has been saved. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[log](DatabaseAdapter.md#log) @@ -414,16 +557,20 @@ ___ ▸ **removeAllGoals**(`room_id`): `Promise`\<`void`\> +Removes all goals associated with a specific room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room whose goals should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when all goals have been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeAllGoals](DatabaseAdapter.md#removeallgoals) @@ -434,17 +581,21 @@ ___ ▸ **removeAllMemories**(`room_id`, `tableName`): `Promise`\<`void`\> +Removes all memories associated with a specific room. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `tableName` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room whose memories should be removed. | +| `tableName` | `string` | The table from which the memories should be removed. | #### Returns `Promise`\<`void`\> +A Promise that resolves when all memories have been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeAllMemories](DatabaseAdapter.md#removeallmemories) @@ -455,16 +606,20 @@ ___ ▸ **removeGoal**(`goalId`): `Promise`\<`void`\> +Removes a specific goal from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the goal to remove. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeGoal](DatabaseAdapter.md#removegoal) @@ -475,40 +630,48 @@ ___ ▸ **removeMemory**(`memoryId`): `Promise`\<`void`\> +Removes a specific memory from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `memoryId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `memoryId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the memory to remove. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the memory has been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeMemory](DatabaseAdapter.md#removememory) ___ -### removeParticipantFromRoom +### removeParticipant + +▸ **removeParticipant**(`user_id`, `room_id`): `Promise`\<`boolean`\> -▸ **removeParticipantFromRoom**(`user_id`, `room_id`): `Promise`\<`void`\> +Removes a user as a participant from a specific room. #### Parameters -| Name | Type | -| :------ | :------ | -| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `user_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the user to remove as a participant. | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room from which the user will be removed. | #### Returns -`Promise`\<`void`\> +`Promise`\<`boolean`\> + +A Promise that resolves to a boolean indicating success or failure. #### Overrides -[DatabaseAdapter](DatabaseAdapter.md).[removeParticipantFromRoom](DatabaseAdapter.md#removeparticipantfromroom) +[DatabaseAdapter](DatabaseAdapter.md).[removeParticipant](DatabaseAdapter.md#removeparticipant) ___ @@ -516,16 +679,20 @@ ___ ▸ **removeRoom**(`room_id`): `Promise`\<`void`\> +Removes a specific room from the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | The UUID of the room to remove. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the room has been removed. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[removeRoom](DatabaseAdapter.md#removeroom) @@ -536,22 +703,26 @@ ___ ▸ **searchMemories**(`params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Searches for memories based on embeddings and other specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.embedding` | `number`[] | -| `params.match_count` | `number` | -| `params.match_threshold` | `number` | -| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing parameters for the memory search. | +| `params.embedding` | `number`[] | - | +| `params.match_count` | `number` | - | +| `params.match_threshold` | `number` | - | +| `params.room_id` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[searchMemories](DatabaseAdapter.md#searchmemories) @@ -562,22 +733,26 @@ ___ ▸ **searchMemoriesByEmbedding**(`embedding`, `params`): `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +Searches for memories by embedding and other specified parameters. + #### Parameters -| Name | Type | -| :------ | :------ | -| `embedding` | `number`[] | -| `params` | `Object` | -| `params.count?` | `number` | -| `params.match_threshold?` | `number` | -| `params.room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.tableName` | `string` | -| `params.unique?` | `boolean` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `embedding` | `number`[] | The embedding vector to search with. | +| `params` | `Object` | Additional parameters for the search. | +| `params.count?` | `number` | - | +| `params.match_threshold?` | `number` | - | +| `params.room_id?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.tableName` | `string` | - | +| `params.unique?` | `boolean` | - | #### Returns `Promise`\<[`Memory`](../interfaces/Memory.md)[]\> +A Promise that resolves to an array of Memory objects. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[searchMemoriesByEmbedding](DatabaseAdapter.md#searchmemoriesbyembedding) @@ -588,16 +763,20 @@ ___ ▸ **updateGoal**(`goal`): `Promise`\<`void`\> +Updates a specific goal in the database. + #### Parameters -| Name | Type | -| :------ | :------ | -| `goal` | [`Goal`](../interfaces/Goal.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `goal` | [`Goal`](../interfaces/Goal.md) | The goal object with updated properties. | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal has been updated. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[updateGoal](DatabaseAdapter.md#updategoal) @@ -608,18 +787,22 @@ ___ ▸ **updateGoalStatus**(`params`): `Promise`\<`void`\> +Updates the status of a specific goal. + #### Parameters -| Name | Type | -| :------ | :------ | -| `params` | `Object` | -| `params.goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | -| `params.status` | [`GoalStatus`](../enums/GoalStatus.md) | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Object` | An object containing the goalId and the new status. | +| `params.goalId` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | - | +| `params.status` | [`GoalStatus`](../enums/GoalStatus.md) | - | #### Returns `Promise`\<`void`\> +A Promise that resolves when the goal status has been updated. + #### Overrides [DatabaseAdapter](DatabaseAdapter.md).[updateGoalStatus](DatabaseAdapter.md#updategoalstatus) diff --git a/docs/docs/interfaces/Participant.md b/docs/docs/interfaces/Participant.md new file mode 100644 index 0000000..4f2e930 --- /dev/null +++ b/docs/docs/interfaces/Participant.md @@ -0,0 +1,21 @@ +--- +id: "Participant" +title: "Interface: Participant" +sidebar_label: "Participant" +sidebar_position: 0 +custom_edit_url: null +--- + +Represents a participant in a room, including their ID and account details. + +## Properties + +### account + +• **account**: [`Account`](Account.md) + +___ + +### id + +• **id**: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` diff --git a/docs/docs/interfaces/Room.md b/docs/docs/interfaces/Room.md new file mode 100644 index 0000000..8c02891 --- /dev/null +++ b/docs/docs/interfaces/Room.md @@ -0,0 +1,21 @@ +--- +id: "Room" +title: "Interface: Room" +sidebar_label: "Room" +sidebar_position: 0 +custom_edit_url: null +--- + +Represents a room or conversation context, including its ID and a list of participants. + +## Properties + +### id + +• **id**: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` + +___ + +### participants + +• **participants**: [`Participant`](Participant.md)[] diff --git a/docs/docs/modules.md b/docs/docs/modules.md index 6b92795..49d69e3 100644 --- a/docs/docs/modules.md +++ b/docs/docs/modules.md @@ -34,8 +34,10 @@ custom_edit_url: null - [Message](interfaces/Message.md) - [MessageExample](interfaces/MessageExample.md) - [Objective](interfaces/Objective.md) +- [Participant](interfaces/Participant.md) - [Provider](interfaces/Provider.md) - [Relationship](interfaces/Relationship.md) +- [Room](interfaces/Room.md) - [State](interfaces/State.md) ## Type Aliases diff --git a/docs/docs/rooms.md b/docs/docs/rooms.md new file mode 100644 index 0000000..fe74545 --- /dev/null +++ b/docs/docs/rooms.md @@ -0,0 +1,22 @@ +# Room Model + +The 'room model' represents a physical or virtual space where interactions between agents and users take place. + +In a typical user-to-agent conversation, such as in ChatGPT, the conversation can be stored in the database with a key for the user and a key for the agent. When they agent needs to look at the recnt conversation history, they can search the database and filter by the person they are talking to. In a multi-agent environment, the conversation can be a lot more complex, with multiple people joining and leaving the conversation, multiple agents interacting with each other, and more. + +The room model is popular in multiplayer gaming, where a room can be associated with a server. For many open-world multiplayer games, the world is divided into chunks that players can move between. + +In the context of bgent, a room can be a physical space, such as a chat room, or a virtual space, such as a game world. The room model provides a way to organize interactions, manage participants, and maintain context within a specific environment. + +## Key Concepts + +### Room +A room contains a list of participants which can be agents or users, and can be added or removed from at any time. The room is keyed by the `room_id`. + +### Participant +A participant is an agent or user that is part of the room. Participants are identified by their 'user_id' which is keyed to the account of the user or agent. + +### Ensuring that a Room and Participant Exists +Every memory needs to be associated with a room and a participant. On databases where foreign keys are available, we try to enforce this constraint. + +When handling messages, you can use the built-in `BgentRuntime.ensureRoomExists(user_id, room_id)` and `BgentRuntime.ensureParticipantExists()` methods to ensure that the room and participant are correctly set up. \ No newline at end of file diff --git a/src/agents/simple/index.ts b/src/agents/simple/index.ts index 28b4b5f..662d5b2 100644 --- a/src/agents/simple/index.ts +++ b/src/agents/simple/index.ts @@ -174,7 +174,7 @@ async function ensureParticipantExists( } async function ensureRoomExists(runtime: BgentRuntime, user_id: UUID) { - const rooms = await runtime.databaseAdapter.getRoomsByParticipants([ + const rooms = await runtime.databaseAdapter.getRoomsForParticipants([ user_id, runtime.agentId, ]); diff --git a/src/lib/__tests__/evaluation.test.ts b/src/lib/__tests__/evaluation.test.ts index fb368d9..203bf0e 100644 --- a/src/lib/__tests__/evaluation.test.ts +++ b/src/lib/__tests__/evaluation.test.ts @@ -105,7 +105,7 @@ describe("Evaluation Process", () => { test("Test that fact appears in evaluation handler", async () => { const { runtime } = await createRuntime({ env: process.env as Record, - recentMessageCount: 1, + conversationLength: 1, evaluators: [fact], }); diff --git a/src/lib/__tests__/lore.test.ts b/src/lib/__tests__/lore.test.ts index be02dcc..40c5d12 100644 --- a/src/lib/__tests__/lore.test.ts +++ b/src/lib/__tests__/lore.test.ts @@ -14,12 +14,31 @@ describe("Lore", () => { let runtime: BgentRuntime; let room_id: UUID; + async function ensureRoomExists(runtime: BgentRuntime, user_id: UUID) { + const rooms = await runtime.databaseAdapter.getRoomsForParticipants([ + user_id, + runtime.agentId, + ]); + + if (rooms.length === 0) { + const room_id = await runtime.databaseAdapter.createRoom(); + runtime.databaseAdapter.addParticipant(user_id, room_id); + runtime.databaseAdapter.addParticipant(runtime.agentId, room_id); + return room_id; + } + // else return the first room + else { + return rooms[0]; + } + } + beforeAll(async () => { const result = await createRuntime({ env: process.env as Record, }); runtime = result.runtime; const user = result?.session?.user as User; + await ensureRoomExists(runtime, user?.id as UUID); const data = await getOrCreateRelationship({ runtime, userA: user?.id as UUID, diff --git a/src/lib/actions/__tests__/elaborate.test.ts b/src/lib/actions/__tests__/elaborate.test.ts index b69458a..f9dbb0c 100644 --- a/src/lib/actions/__tests__/elaborate.test.ts +++ b/src/lib/actions/__tests__/elaborate.test.ts @@ -64,8 +64,6 @@ describe("User Profile", () => { userB: zeroUuid, }); - console.log("data", data); - room_id = data.room_id; await cleanup(); diff --git a/src/lib/actions/__tests__/ignore.test.ts b/src/lib/actions/__tests__/ignore.test.ts index 7288491..4f5a3b2 100644 --- a/src/lib/actions/__tests__/ignore.test.ts +++ b/src/lib/actions/__tests__/ignore.test.ts @@ -156,6 +156,8 @@ describe("Ignore action tests", () => { console.log("data is", data); room_id = data?.room_id; + console.log("*** data", data); + console.log("Room ID", room_id); await cleanup(); }); @@ -185,7 +187,7 @@ describe("Ignore action tests", () => { return result.action === "IGNORE"; }); - }, 60000); + }, 120000); test("Action handler test 1: response should be ignore", async () => { await runAiTest( @@ -210,7 +212,7 @@ describe("Ignore action tests", () => { return (lastMessage.content as Content).action === "IGNORE"; }, ); - }, 60000); + }, 120000); test("Action handler test 2: response should be ignore", async () => { await runAiTest( @@ -235,7 +237,7 @@ describe("Ignore action tests", () => { return (lastMessage.content as Content).action === "IGNORE"; }, ); - }, 60000); + }, 120000); test("Expect ignore", async () => { await runAiTest("Expect ignore", async () => { @@ -255,5 +257,5 @@ describe("Ignore action tests", () => { return (lastMessage.content as Content).action === "IGNORE"; }); - }, 60000); + }, 120000); }); diff --git a/src/lib/adapters/sqlite.ts b/src/lib/adapters/sqlite.ts index 5b7de77..e6ba754 100644 --- a/src/lib/adapters/sqlite.ts +++ b/src/lib/adapters/sqlite.ts @@ -10,6 +10,7 @@ import { type Memory, type Relationship, type UUID, + Participant, } from "../types"; import { sqliteTables } from "./sqlite/sqliteTables"; @@ -17,6 +18,30 @@ import { sqliteTables } from "./sqlite/sqliteTables"; import { Database } from "better-sqlite3"; export class SqliteDatabaseAdapter extends DatabaseAdapter { + async getRoom(room_id: UUID): Promise { + const sql = "SELECT id FROM rooms WHERE id = ?"; + const room = this.db.prepare(sql).get(room_id) as + | { id: string } + | undefined; + return room ? (room.id as UUID) : null; + } + + async getParticipantsForAccount(user_id: UUID): Promise { + const sql = ` + SELECT p.id, p.user_id, p.room_id, p.last_message_read + FROM participants p + WHERE p.user_id = ? + `; + const rows = this.db.prepare(sql).all(user_id) as Participant[]; + return rows; + } + + async getParticipantsForRoom(room_id: UUID): Promise { + const sql = "SELECT user_id FROM participants WHERE room_id = ?"; + const rows = this.db.prepare(sql).all(room_id) as { user_id: string }[]; + return rows.map((row) => row.user_id as UUID); + } + db: Database; constructor(db: Database) { @@ -48,18 +73,24 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter { return account || null; } - async createAccount(account: Account): Promise { - const sql = - "INSERT INTO accounts (id, name, email, avatar_url, details) VALUES (?, ?, ?, ?, ?)"; - this.db - .prepare(sql) - .run( - account.id ?? v4(), - account.name, - account.email, - account.avatar_url, - JSON.stringify(account.details), - ); + async createAccount(account: Account): Promise { + try { + const sql = + "INSERT INTO accounts (id, name, email, avatar_url, details) VALUES (?, ?, ?, ?, ?)"; + this.db + .prepare(sql) + .run( + account.id ?? v4(), + account.name, + account.email, + account.avatar_url, + JSON.stringify(account.details), + ); + return true; + } catch (error) { + console.log("Error creating account", error); + return false; + } } async getActorDetails(params: { room_id: UUID }): Promise { @@ -409,13 +440,13 @@ AND room_id = ?`; this.db.prepare(sql).run(room_id); } - async getRoomsByParticipant(user_id: UUID): Promise { + async getRoomsForParticipant(user_id: UUID): Promise { const sql = "SELECT room_id FROM participants WHERE user_id = ?"; const rows = this.db.prepare(sql).all(user_id) as { room_id: string }[]; return rows.map((row) => row.room_id as UUID); } - async getRoomsByParticipants(userIds: UUID[]): Promise { + async getRoomsForParticipants(userIds: UUID[]): Promise { // Assuming userIds is an array of UUID strings, prepare a list of placeholders const placeholders = userIds.map(() => "?").join(", "); // Construct the SQL query with the correct number of placeholders @@ -426,15 +457,27 @@ AND room_id = ?`; return rows.map((row) => row.room_id as UUID); } - async addParticipant(user_id: UUID, room_id: UUID): Promise { - const sql = - "INSERT INTO participants (id, user_id, room_id) VALUES (?, ?, ?)"; - this.db.prepare(sql).run(v4(), user_id, room_id); + async addParticipant(user_id: UUID, room_id: UUID): Promise { + try { + const sql = + "INSERT INTO participants (id, user_id, room_id) VALUES (?, ?, ?)"; + this.db.prepare(sql).run(v4(), user_id, room_id); + return true; + } catch (error) { + console.log("Error adding participant", error); + return false; + } } - async removeParticipantFromRoom(user_id: UUID, room_id: UUID): Promise { - const sql = "DELETE FROM participants WHERE user_id = ? AND room_id = ?"; - this.db.prepare(sql).run(user_id, room_id); + async removeParticipant(user_id: UUID, room_id: UUID): Promise { + try { + const sql = "DELETE FROM participants WHERE user_id = ? AND room_id = ?"; + this.db.prepare(sql).run(user_id, room_id); + return true; + } catch (error) { + console.log("Error removing participant", error); + return false; + } } async createRelationship(params: { diff --git a/src/lib/adapters/sqljs.ts b/src/lib/adapters/sqljs.ts index ecac757..02b120d 100644 --- a/src/lib/adapters/sqljs.ts +++ b/src/lib/adapters/sqljs.ts @@ -10,11 +10,51 @@ import { type Memory, type Relationship, type UUID, + Participant, } from "../types"; import { sqliteTables } from "./sqlite/sqliteTables"; import { Database } from "./sqljs/types"; export class SqlJsDatabaseAdapter extends DatabaseAdapter { + async getRoom(room_id: UUID): Promise { + const sql = "SELECT id FROM rooms WHERE id = ?"; + const stmt = this.db.prepare(sql); + stmt.bind([room_id]); + const room = stmt.getAsObject() as { id: string } | undefined; + stmt.free(); + return room ? (room.id as UUID) : null; + } + + async getParticipantsForAccount(user_id: UUID): Promise { + const sql = ` + SELECT p.id, p.user_id, p.room_id, p.last_message_read + FROM participants p + WHERE p.user_id = ? + `; + const stmt = this.db.prepare(sql); + stmt.bind([user_id]); + const participants: Participant[] = []; + while (stmt.step()) { + const participant = stmt.getAsObject() as unknown as Participant; + participants.push(participant); + } + stmt.free(); + return participants; + } + + async getParticipantsForRoom(room_id: UUID): Promise { + const sql = "SELECT user_id FROM participants WHERE room_id = ?"; + const stmt = this.db.prepare(sql); + stmt.bind([room_id]); + const userIds: UUID[] = []; + while (stmt.step()) { + const row = stmt.getAsObject() as { user_id: string }; + userIds.push(row.user_id as UUID); + } + stmt.free(); + return userIds; + } + db: Database; constructor(db: Database) { @@ -46,20 +86,26 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter { return account || null; } - async createAccount(account: Account): Promise { - const sql = ` + async createAccount(account: Account): Promise { + try { + const sql = ` INSERT INTO accounts (id, name, email, avatar_url, details) VALUES (?, ?, ?, ?, ?) - `; - const stmt = this.db.prepare(sql); - stmt.run([ - account.id ?? v4(), - account.name, - account.email || "", - account.avatar_url || "", - JSON.stringify(account.details), - ]); - stmt.free(); + `; + const stmt = this.db.prepare(sql); + stmt.run([ + account.id ?? v4(), + account.name, + account.email || "", + account.avatar_url || "", + JSON.stringify(account.details), + ]); + stmt.free(); + return true; + } catch (error) { + console.log("Error creating account", error); + return false; + } } async getActorDetails(params: { room_id: UUID }): Promise { @@ -474,7 +520,7 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter { stmt.free(); } - async getRoomsByParticipant(user_id: UUID): Promise { + async getRoomsForParticipant(user_id: UUID): Promise { const sql = "SELECT room_id FROM participants WHERE user_id = ?"; const stmt = this.db.prepare(sql); stmt.bind([user_id]); @@ -487,7 +533,7 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter { return rows.map((row) => row.room_id as UUID); } - async getRoomsByParticipants(userIds: UUID[]): Promise { + async getRoomsForParticipants(userIds: UUID[]): Promise { // Assuming userIds is an array of UUID strings, prepare a list of placeholders const placeholders = userIds.map(() => "?").join(", "); // Construct the SQL query with the correct number of placeholders @@ -505,19 +551,31 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter { return rows.map((row) => row.room_id as UUID); } - async addParticipant(user_id: UUID, room_id: UUID): Promise { - const sql = - "INSERT INTO participants (id, user_id, room_id) VALUES (?, ?, ?)"; - const stmt = this.db.prepare(sql); - stmt.run([v4(), user_id, room_id]); - stmt.free(); + async addParticipant(user_id: UUID, room_id: UUID): Promise { + try { + const sql = + "INSERT INTO participants (id, user_id, room_id) VALUES (?, ?, ?)"; + const stmt = this.db.prepare(sql); + stmt.run([v4(), user_id, room_id]); + stmt.free(); + return true; + } catch (error) { + console.log("Error adding participant", error); + return false; + } } - async removeParticipantFromRoom(user_id: UUID, room_id: UUID): Promise { - const sql = "DELETE FROM participants WHERE user_id = ? AND room_id = ?"; - const stmt = this.db.prepare(sql); - stmt.run([user_id, room_id]); - stmt.free(); + async removeParticipant(user_id: UUID, room_id: UUID): Promise { + try { + const sql = "DELETE FROM participants WHERE user_id = ? AND room_id = ?"; + const stmt = this.db.prepare(sql); + stmt.run([user_id, room_id]); + stmt.free(); + return true; + } catch (error) { + console.log("Error removing participant", error); + return false; + } } async createRelationship(params: { diff --git a/src/lib/adapters/supabase.ts b/src/lib/adapters/supabase.ts index c4ceca0..b7e7496 100644 --- a/src/lib/adapters/supabase.ts +++ b/src/lib/adapters/supabase.ts @@ -8,10 +8,53 @@ import { GoalStatus, Account, type UUID, + Participant, } from "../types"; import { DatabaseAdapter } from "../database"; import { v4 as uuid } from "uuid"; export class SupabaseDatabaseAdapter extends DatabaseAdapter { + async getRoom(room_id: UUID): Promise { + const { data, error } = await this.supabase + .from("rooms") + .select("id") + .eq("id", room_id) + .single(); + + if (error) { + throw new Error(`Error getting room: ${error.message}`); + } + + return data ? (data.id as UUID) : null; + } + + async getParticipantsForAccount(user_id: UUID): Promise { + const { data, error } = await this.supabase + .from("participants") + .select("*") + .eq("user_id", user_id); + + if (error) { + throw new Error( + `Error getting participants for account: ${error.message}`, + ); + } + + return data as Participant[]; + } + + async getParticipantsForRoom(room_id: UUID): Promise { + const { data, error } = await this.supabase + .from("participants") + .select("user_id") + .eq("room_id", room_id); + + if (error) { + throw new Error(`Error getting participants for room: ${error.message}`); + } + + return data.map((row) => row.user_id as UUID); + } + supabase: SupabaseClient; constructor(supabaseUrl: string, supabaseKey: string) { @@ -30,12 +73,13 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter { return (data?.[0] as Account) || null; } - async createAccount(account: Account): Promise { - // TODO: change to insert and run tests + async createAccount(account: Account): Promise { const { error } = await this.supabase.from("accounts").upsert([account]); if (error) { - throw new Error(error.message); + console.error(error.message); + return false; } + return true; } async getActorDetails(params: { room_id: UUID }): Promise { @@ -332,7 +376,7 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter { } } - async getRoomsByParticipant(user_id: UUID): Promise { + async getRoomsForParticipant(user_id: UUID): Promise { const { data, error } = await this.supabase .from("participants") .select("room_id") @@ -345,7 +389,7 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter { return data.map((row) => row.room_id as UUID); } - async getRoomsByParticipants(userIds: UUID[]): Promise { + async getRoomsForParticipants(userIds: UUID[]): Promise { const { data, error } = await this.supabase .from("participants") .select("room_id") @@ -386,17 +430,19 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter { } } - async addParticipant(user_id: UUID, room_id: UUID): Promise { + async addParticipant(user_id: UUID, room_id: UUID): Promise { const { error } = await this.supabase .from("participants") .insert({ user_id: user_id, room_id: room_id }); if (error) { - throw new Error(`Error adding participant: ${error.message}`); + console.error(`Error adding participant: ${error.message}`); + return false; } + return true; } - async removeParticipantFromRoom(user_id: UUID, room_id: UUID): Promise { + async removeParticipant(user_id: UUID, room_id: UUID): Promise { const { error } = await this.supabase .from("participants") .delete() @@ -404,15 +450,17 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter { .eq("room_id", room_id); if (error) { - throw new Error(`Error removing participant: ${error.message}`); + console.error(`Error removing participant: ${error.message}`); + return false; } + return true; } async createRelationship(params: { userA: UUID; userB: UUID; }): Promise { - const allRoomData = await this.getRoomsByParticipants([ + const allRoomData = await this.getRoomsForParticipants([ params.userA, params.userB, ]); @@ -437,7 +485,6 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter { room_id = allRoomData[0]; } - // Add participants to the room const { error: participantsError } = await this.supabase .from("participants") .insert([ diff --git a/src/lib/database.ts b/src/lib/database.ts index b5746fb..f6cb68c 100644 --- a/src/lib/database.ts +++ b/src/lib/database.ts @@ -6,13 +6,33 @@ import { type Memory, type Relationship, type UUID, + Participant, } from "./types"; +/** + * An abstract class representing a database adapter for managing various entities + * like accounts, memories, actors, goals, and rooms. + */ export abstract class DatabaseAdapter { + /** + * Retrieves an account by its ID. + * @param user_id The UUID of the user account to retrieve. + * @returns A Promise that resolves to the Account object or null if not found. + */ abstract getAccountById(user_id: UUID): Promise; - abstract createAccount(account: Account): Promise; + /** + * Creates a new account in the database. + * @param account The account object to create. + * @returns A Promise that resolves when the account creation is complete. + */ + abstract createAccount(account: Account): Promise; + /** + * Retrieves memories based on the specified parameters. + * @param params An object containing parameters for the memory retrieval. + * @returns A Promise that resolves to an array of Memory objects. + */ abstract getMemories(params: { room_id: UUID; count?: number; @@ -20,6 +40,11 @@ export abstract class DatabaseAdapter { tableName: string; }): Promise; + /** + * Retrieves cached embeddings based on the specified query parameters. + * @param params An object containing parameters for the embedding retrieval. + * @returns A Promise that resolves to an array of objects containing embeddings and levenshtein scores. + */ abstract getCachedEmbeddings({ query_table_name, query_threshold, @@ -41,6 +66,11 @@ export abstract class DatabaseAdapter { }[] >; + /** + * Logs an event or action with the specified details. + * @param params An object containing parameters for the log entry. + * @returns A Promise that resolves when the log entry has been saved. + */ abstract log(params: { body: { [key: string]: unknown }; user_id: UUID; @@ -48,8 +78,18 @@ export abstract class DatabaseAdapter { type: string; }): Promise; + /** + * Retrieves details of actors in a given room. + * @param params An object containing the room_id to search for actors. + * @returns A Promise that resolves to an array of Actor objects. + */ abstract getActorDetails(params: { room_id: UUID }): Promise; + /** + * Searches for memories based on embeddings and other specified parameters. + * @param params An object containing parameters for the memory search. + * @returns A Promise that resolves to an array of Memory objects. + */ abstract searchMemories(params: { tableName: string; room_id: UUID; @@ -59,11 +99,22 @@ export abstract class DatabaseAdapter { unique: boolean; }): Promise; + /** + * Updates the status of a specific goal. + * @param params An object containing the goalId and the new status. + * @returns A Promise that resolves when the goal status has been updated. + */ abstract updateGoalStatus(params: { goalId: UUID; status: GoalStatus; }): Promise; + /** + * Searches for memories by embedding and other specified parameters. + * @param embedding The embedding vector to search with. + * @param params Additional parameters for the search. + * @returns A Promise that resolves to an array of Memory objects. + */ abstract searchMemoriesByEmbedding( embedding: number[], params: { @@ -75,22 +126,53 @@ export abstract class DatabaseAdapter { }, ): Promise; + /** + * Creates a new memory in the database. + * @param memory The memory object to create. + * @param tableName The table where the memory should be stored. + * @param unique Indicates if the memory should be unique. + * @returns A Promise that resolves when the memory has been created. + */ abstract createMemory( memory: Memory, tableName: string, unique?: boolean, ): Promise; + /** + * Removes a specific memory from the database. + * @param memoryId The UUID of the memory to remove. + * @param tableName The table from which the memory should be removed. + * @returns A Promise that resolves when the memory has been removed. + */ abstract removeMemory(memoryId: UUID, tableName: string): Promise; + /** + * Removes all memories associated with a specific room. + * @param room_id The UUID of the room whose memories should be removed. + * @param tableName The table from which the memories should be removed. + * @returns A Promise that resolves when all memories have been removed. + */ abstract removeAllMemories(room_id: UUID, tableName: string): Promise; + /** + * Counts the number of memories in a specific room. + * @param room_id The UUID of the room for which to count memories. + * @param unique Specifies whether to count only unique memories. + * @param tableName Optional table name to count memories from. + * @returns A Promise that resolves to the number of memories. + */ abstract countMemories( room_id: UUID, unique?: boolean, tableName?: string, ): Promise; + /** + * Retrieves goals based on specified parameters. + * @param params An object containing parameters for goal retrieval. + * @returns A Promise that resolves to an array of Goal objects. + */ abstract getGoals(params: { room_id: UUID; user_id?: UUID | null; @@ -98,38 +180,130 @@ export abstract class DatabaseAdapter { count?: number; }): Promise; + /** + * Updates a specific goal in the database. + * @param goal The goal object with updated properties. + * @returns A Promise that resolves when the goal has been updated. + */ abstract updateGoal(goal: Goal): Promise; + /** + * Creates a new goal in the database. + * @param goal The goal object to create. + * @returns A Promise that resolves when the goal has been created. + */ abstract createGoal(goal: Goal): Promise; + /** + * Removes a specific goal from the database. + * @param goalId The UUID of the goal to remove. + * @returns A Promise that resolves when the goal has been removed. + */ abstract removeGoal(goalId: UUID): Promise; + /** + * Removes all goals associated with a specific room. + * @param room_id The UUID of the room whose goals should be removed. + * @returns A Promise that resolves when all goals have been removed. + */ abstract removeAllGoals(room_id: UUID): Promise; + /** + * Retrieves the room ID for a given room, if it exists. + * @param room_id The UUID of the room to retrieve. + * @returns A Promise that resolves to the room ID or null if not found. + */ + abstract getRoom(room_id: UUID): Promise; + + /** + * Creates a new room with an optional specified ID. + * @param room_id Optional UUID to assign to the new room. + * @returns A Promise that resolves to the UUID of the created room. + */ abstract createRoom(room_id?: UUID): Promise; + /** + * Removes a specific room from the database. + * @param room_id The UUID of the room to remove. + * @returns A Promise that resolves when the room has been removed. + */ abstract removeRoom(room_id: UUID): Promise; - abstract getRoomsByParticipant(user_id: UUID): Promise; + /** + * Retrieves room IDs for which a specific user is a participant. + * @param user_id The UUID of the user. + * @returns A Promise that resolves to an array of room IDs. + */ + abstract getRoomsForParticipant(user_id: UUID): Promise; - abstract getRoomsByParticipants(userIds: UUID[]): Promise; + /** + * Retrieves room IDs for which specific users are participants. + * @param userIds An array of UUIDs of the users. + * @returns A Promise that resolves to an array of room IDs. + */ + abstract getRoomsForParticipants(userIds: UUID[]): Promise; - abstract addParticipant(user_id: UUID, room_id: UUID): Promise; + /** + * Adds a user as a participant to a specific room. + * @param user_id The UUID of the user to add as a participant. + * @param room_id The UUID of the room to which the user will be added. + * @returns A Promise that resolves to a boolean indicating success or failure. + */ + abstract addParticipant(user_id: UUID, room_id: UUID): Promise; - abstract removeParticipantFromRoom( - user_id: UUID, - room_id: UUID, - ): Promise; + /** + * Removes a user as a participant from a specific room. + * @param user_id The UUID of the user to remove as a participant. + * @param room_id The UUID of the room from which the user will be removed. + * @returns A Promise that resolves to a boolean indicating success or failure. + */ + abstract removeParticipant(user_id: UUID, room_id: UUID): Promise; + + /** + * Retrieves participants associated with a specific account. + * @param user_id The UUID of the account. + * @returns A Promise that resolves to an array of Participant objects. + */ + abstract getParticipantsForAccount(user_id: UUID): Promise; + + /** + * Retrieves participants associated with a specific account. + * @param user_id The UUID of the account. + * @returns A Promise that resolves to an array of Participant objects. + */ + abstract getParticipantsForAccount(user_id: UUID): Promise; + + /** + * Retrieves participants for a specific room. + * @param room_id The UUID of the room for which to retrieve participants. + * @returns A Promise that resolves to an array of UUIDs representing the participants. + */ + abstract getParticipantsForRoom(room_id: UUID): Promise; + /** + * Creates a new relationship between two users. + * @param params An object containing the UUIDs of the two users (userA and userB). + * @returns A Promise that resolves to a boolean indicating success or failure of the creation. + */ abstract createRelationship(params: { userA: UUID; userB: UUID; }): Promise; + /** + * Retrieves a relationship between two users if it exists. + * @param params An object containing the UUIDs of the two users (userA and userB). + * @returns A Promise that resolves to the Relationship object or null if not found. + */ abstract getRelationship(params: { userA: UUID; userB: UUID; }): Promise; + /** + * Retrieves all relationships for a specific user. + * @param params An object containing the UUID of the user. + * @returns A Promise that resolves to an array of Relationship objects. + */ abstract getRelationships(params: { user_id: UUID }): Promise; } diff --git a/src/lib/evaluators/fact.ts b/src/lib/evaluators/fact.ts index 7b71cee..72291d6 100644 --- a/src/lib/evaluators/fact.ts +++ b/src/lib/evaluators/fact.ts @@ -134,7 +134,7 @@ export default { message.room_id, )) as number; - const reflectionCount = Math.ceil(runtime.getRecentMessageCount() / 2); + const reflectionCount = Math.ceil(runtime.getConversationLength() / 2); return messageCount % reflectionCount === 0; }, diff --git a/src/lib/index.ts b/src/lib/index.ts index c05da80..2270851 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -63,7 +63,6 @@ export { BgentRuntime } from "./runtime"; export { messageHandlerTemplate } from "./templates"; // Export from ./src/types -export { GoalStatus } from "./types"; export type { Account, Action, @@ -74,13 +73,16 @@ export type { EvaluationExample, Evaluator, Goal, + GoalStatus, Handler, Memory, Message, MessageExample, Objective, + Participant, Provider, Relationship, + Room, State, Validator, } from "./types"; diff --git a/src/lib/runtime.ts b/src/lib/runtime.ts index f980b74..10c17a4 100644 --- a/src/lib/runtime.ts +++ b/src/lib/runtime.ts @@ -26,16 +26,15 @@ import { formatActionNames, formatActions, } from "./actions"; -// import { formatGoalsAsString, getGoals } from "./goals"; +import { UUID } from "crypto"; +import { zeroUuid } from "./constants"; +import { DatabaseAdapter } from "./database"; import { formatFacts } from "./evaluators/fact"; import { formatGoalsAsString, getGoals } from "./goals"; import { formatLore, getLore } from "./lore"; import { formatActors, formatMessages, getActorDetails } from "./messages"; import { defaultProviders, getProviders } from "./providers"; -import { type Actor, /*type Goal,*/ type Memory } from "./types"; -import { DatabaseAdapter } from "./database"; -import { UUID } from "crypto"; -import { zeroUuid } from "./constants"; +import { type Actor, type Memory } from "./types"; /** * Represents the runtime environment for an agent, handling message processing, @@ -46,7 +45,7 @@ export class BgentRuntime { * Default count for recent messages to be kept in memory. * @private */ - readonly #recentMessageCount = 32 as number; + readonly #conversationLength = 32 as number; /** * The ID of the agent */ @@ -137,7 +136,7 @@ export class BgentRuntime { /** * Creates an instance of BgentRuntime. * @param opts - The options for configuring the BgentRuntime. - * @param opts.recentMessageCount - The number of messages to hold in the recent message cache. + * @param opts.conversationLength - The number of messages to hold in the recent message cache. * @param opts.token - The JWT token, can be a JWT token if outside worker, or an OpenAI token if inside worker. * @param opts.debugMode - If true, debug messages will be logged. * @param opts.serverUrl - The URL of the worker. @@ -152,7 +151,7 @@ export class BgentRuntime { */ constructor(opts: { - recentMessageCount?: number; // number of messages to hold in the recent message cache + conversationLength?: number; // number of messages to hold in the recent message cache agentId?: UUID; // ID of the agent token: string; // JWT token, can be a JWT token if outside worker, or an OpenAI token if inside worker debugMode?: boolean; // If true, will log debug messages @@ -165,8 +164,8 @@ export class BgentRuntime { databaseAdapter: DatabaseAdapter; // The database adapter used for interacting with the database fetch?: typeof fetch | unknown; }) { - this.#recentMessageCount = - opts.recentMessageCount ?? this.#recentMessageCount; + this.#conversationLength = + opts.conversationLength ?? this.#conversationLength; this.debugMode = opts.debugMode ?? false; this.databaseAdapter = opts.databaseAdapter; this.agentId = opts.agentId ?? zeroUuid; @@ -201,8 +200,8 @@ export class BgentRuntime { * Get the number of messages that are kept in the conversation buffer. * @returns The number of recent messages to be kept in memory. */ - getRecentMessageCount() { - return this.#recentMessageCount; + getConversationLength() { + return this.#conversationLength; } /** @@ -452,6 +451,54 @@ export class BgentRuntime { return parsedResult; } + /** + * Ensure the existence of a participant in the room. If the participant does not exist, they are added to the room. + * @param user_id - The user ID to ensure the existence of. + * @throws An error if the participant cannot be added. + */ + async ensureParticipantExists(user_id: UUID, room_id: UUID) { + const participants = + await this.databaseAdapter.getParticipantsForAccount(user_id); + + if (participants?.length === 0) { + await this.databaseAdapter.addParticipant(user_id, room_id); + } + } + + /** + * Ensure the existence of a room between the agent and a user. If no room exists, a new room is created and the user + * and agent are added as participants. The room ID is returned. + * @param user_id - The user ID to create a room with. + * @returns The room ID of the room between the agent and the user. + * @throws An error if the room cannot be created. + */ + async ensureRoomExists(user_id: UUID, room_id?: UUID) { + if (room_id) { + // check if room exists + const created = await this.databaseAdapter.createRoom(room_id); + if (created) { + this.databaseAdapter.addParticipant(user_id, room_id); + this.databaseAdapter.addParticipant(this.agentId, room_id); + } + return room_id; + } + const rooms = await this.databaseAdapter.getRoomsForParticipants([ + user_id, + this.agentId, + ]); + + if (rooms.length === 0) { + const room_id = await this.databaseAdapter.createRoom(); + this.databaseAdapter.addParticipant(user_id, room_id); + this.databaseAdapter.addParticipant(this.agentId, room_id); + return room_id; + } + // else return the first room + else { + return rooms[0]; + } + } + /** * Compose the state of the agent into an object that can be passed or used for response generation. * @param message The message to compose the state from. @@ -463,9 +510,9 @@ export class BgentRuntime { ) { const { user_id, room_id } = message; - const recentMessageCount = this.getRecentMessageCount(); - const recentFactsCount = Math.ceil(this.getRecentMessageCount() / 2); - const relevantFactsCount = Math.ceil(this.getRecentMessageCount() / 2); + const conversationLength = this.getConversationLength(); + const recentFactsCount = Math.ceil(this.getConversationLength() / 2); + const relevantFactsCount = Math.ceil(this.getConversationLength() / 2); const [ actorsData, @@ -477,7 +524,7 @@ export class BgentRuntime { getActorDetails({ runtime: this, room_id }), this.messageManager.getMemories({ room_id, - count: recentMessageCount, + count: conversationLength, unique: false, }), this.factManager.getMemories({ diff --git a/src/lib/types.ts b/src/lib/types.ts index 3b45763..f6da1a4 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -210,3 +210,19 @@ export interface Account { email?: string; avatar_url?: string; } + +/** + * Represents a participant in a room, including their ID and account details. + */ +export interface Participant { + id: UUID; + account: Account; +} + +/** + * Represents a room or conversation context, including its ID and a list of participants. + */ +export interface Room { + id: UUID; + participants: Participant[]; +} diff --git a/src/test/createRuntime.ts b/src/test/createRuntime.ts index a6c0776..571172b 100644 --- a/src/test/createRuntime.ts +++ b/src/test/createRuntime.ts @@ -16,13 +16,13 @@ import { SqlJsDatabaseAdapter } from "../lib/adapters/sqljs"; export async function createRuntime({ env, - recentMessageCount, + conversationLength, evaluators = [], actions = [], providers = [], }: { env?: Record | NodeJS.ProcessEnv; - recentMessageCount?: number; + conversationLength?: number; evaluators?: Evaluator[]; actions?: Action[]; providers?: Provider[]; @@ -130,7 +130,7 @@ export async function createRuntime({ const runtime = new BgentRuntime({ debugMode: false, serverUrl: "https://api.openai.com/v1", - recentMessageCount, + conversationLength, token: env!.OPENAI_API_KEY!, actions: actions ?? [], evaluators: evaluators ?? [], diff --git a/src/test/getOrCreateRelationship.ts b/src/test/getOrCreateRelationship.ts index 68a5bbd..313d877 100644 --- a/src/test/getOrCreateRelationship.ts +++ b/src/test/getOrCreateRelationship.ts @@ -28,20 +28,23 @@ export async function getOrCreateRelationship({ } // Check if a room already exists for the participants - const rooms = await runtime.databaseAdapter.getRoomsByParticipants([ + const rooms = await runtime.databaseAdapter.getRoomsForParticipants([ userA, userB, ]); let room_id: UUID; if (!rooms || rooms.length === 0) { + console.log("No room found for participants"); // If no room exists, create a new room for the relationship room_id = await runtime.databaseAdapter.createRoom(); + console.log("Created room", room_id); // Add participants to the newly created room await runtime.databaseAdapter.addParticipant(userA, room_id); await runtime.databaseAdapter.addParticipant(userB, room_id); } else { + console.log("Room found for participants", rooms[0]); // If a room already exists, use the existing room room_id = rooms[0]; } @@ -59,5 +62,5 @@ export async function getOrCreateRelationship({ throw new Error("Failed to fetch the created relationship"); } } - return { ...relationship, room_id: room_id }; + return { ...relationship, room_id }; }