-
Notifications
You must be signed in to change notification settings - Fork 25
/
memory.ts
49 lines (45 loc) · 1.63 KB
/
memory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Memory } from "../api";
import { BaseManager } from "./base";
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,
userId,
limit = 100,
offset = 0,
}: {
agentId: string;
query: string;
userId?: string;
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({
agentId,
query,
userId,
limit,
offset,
});
return response.items || [];
}
}