Skip to content

Commit

Permalink
Merge main into sweep/update_the_docstrings_and_comments_in_sd
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Apr 18, 2024
2 parents fe6a810 + 03302c9 commit 8541776
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sdks/ts/src/managers/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ import { invariant } from "../utils/invariant";
import { isValidUuid4 } from "../utils/isValidUuid4";

export class MemoriesManager extends BaseManager {
/**
* Manages memory-related operations for agents. Inherits from BaseManager.
* Provides functionality to list memories associated with a given agent.
*/
/**
* Lists memories based on the provided parameters.
* @param {string} agentId - The UUID of the agent whose memories are to be listed. Must be a valid UUID v4.
* @param {string} query - A query string to filter memories.
* @param {string} [userId] - The UUID of the user associated with the memories. Optional.
* @param {number} [limit=100] - The maximum number of memories to return. Optional.
* @param {number} [offset=0] - The offset for pagination. Optional.
* @returns {Promise<Memory[]>} A promise that resolves to an array of Memory objects.
*/
async list({
agentId,
query,
Expand All @@ -18,7 +31,9 @@ export class MemoriesManager extends BaseManager {
limit?: number;
offset?: number;
}): Promise<Memory[]> {
// Validates that the agentId is a valid UUID v4 format.
invariant(isValidUuid4(agentId), "agentId must be a valid UUID v4");
// Validates that the userId, if provided, is a valid UUID v4 format.
userId && invariant(isValidUuid4(userId), "userId must be a valid UUID v4");

const response = await this.apiClient.default.getAgentMemories({
Expand Down
6 changes: 6 additions & 0 deletions sdks/ts/src/utils/invariant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* Ensures that a condition is met, throwing a custom error message if not.
* @param condition The condition to test. If falsy, an error is thrown.
* @param message Optional. The error message to throw if the condition is not met. Defaults to "Invariant Violation".
*/
export function invariant(
condition: any,
message: string = "Invariant Violation",
): void {
// Throw an error with the provided message if the condition is falsy
if (!condition) {
throw new Error(message);
}
Expand Down

0 comments on commit 8541776

Please sign in to comment.