crewai-ts
Version:
TypeScript port of crewAI for agent-based workflows
85 lines (84 loc) • 2.4 kB
JavaScript
/**
* UserMemoryAdapter
*
* Adapts UserMemory to implement the BaseMemory interface
* Optimized for performance with proper type safety
*/
/**
* Adapter class to make UserMemory compatible with BaseMemory interface
* This adapter implements all required methods of BaseMemory, delegating to the
* wrapped UserMemory instance where possible and providing optimized
* implementations.
*/
export class UserMemoryAdapter {
userMemory;
constructor(userMemory) {
this.userMemory = userMemory;
}
/**
* Add an item to memory with memory-efficient implementation
*/
async add(content, metadata) {
return this.userMemory.add(content, metadata);
}
/**
* Search for items in memory with optimized retrieval
*/
async search(params) {
return this.userMemory.search(params);
}
/**
* Get an item by ID with optimized access time tracking
*/
async get(id) {
return this.userMemory.get(id);
}
/**
* Update an existing memory item with efficient index management
*/
async update(id, updates) {
return this.userMemory.update(id, updates);
}
/**
* Remove an item from memory with proper index cleanup
*/
async remove(id) {
return this.userMemory.remove(id);
}
/**
* Clear all items from memory with optimized resource cleanup
*/
async clear() {
return this.userMemory.clear();
}
/**
* Reset the memory system with efficient reinitialization
*/
async reset() {
return this.userMemory.reset();
}
/**
* Get all memory items for a specific user with optimized retrieval
*/
async getUserItems(userId, limit = 100) {
return this.userMemory.getUserItems(userId, limit);
}
/**
* Get user preferences with efficient data aggregation
*/
async getUserPreferences(userId) {
return this.userMemory.getUserPreferences(userId);
}
/**
* Store a user preference with optimized indexing
*/
async setUserPreference(userId, key, value) {
return this.userMemory.setUserPreference(userId, key, value);
}
/**
* Add a user interaction to memory with efficient storage
*/
async addUserInteraction(userId, interaction) {
return this.userMemory.addUserInteraction(userId, interaction);
}
}