@symindx/cli
Version:
SYMindX - AI Agent Framework CLI with NyX agent
59 lines • 2.46 kB
JavaScript
/**
* Base Memory Provider for CLI SYMindX
*/
import { MemoryDuration, MemoryType } from '../types/memory.js';
import { v4 as uuidv4 } from 'uuid';
export class BaseMemoryProvider {
config;
metadata;
embeddingModel;
constructor(config, metadata) {
this.config = config;
this.metadata = metadata;
this.embeddingModel = config.embeddingModel || 'text-embedding-3-small';
}
async getStats(agentId) {
// Default implementation - can be overridden
const memories = await this.retrieve(agentId, 'recent', 1000);
const byType = {};
memories.forEach(memory => {
const type = memory.type;
byType[type] = (byType[type] || 0) + 1;
});
return { total: memories.length, byType };
}
async cleanup(agentId, retentionDays) {
// Default implementation - can be overridden
console.log(`Cleanup not implemented for agent ${agentId}`);
}
getMetadata() {
return this.metadata;
}
generateId() {
return uuidv4();
}
formatMemoryForStorage(memory) {
return {
...memory,
timestamp: memory.timestamp instanceof Date ? memory.timestamp.toISOString() : memory.timestamp,
metadata: typeof memory.metadata === 'object' ? JSON.stringify(memory.metadata) : memory.metadata,
tags: Array.isArray(memory.tags) ? JSON.stringify(memory.tags) : memory.tags
};
}
parseMemoryFromStorage(row) {
return {
id: row.id || row.memory_id || '',
agentId: row.agent_id,
type: row.type ? MemoryType[row.type.toUpperCase()] || MemoryType.EXPERIENCE : MemoryType.EXPERIENCE,
content: row.content,
embedding: Array.isArray(row.embedding) ? row.embedding : undefined,
metadata: typeof row.metadata === 'string' ? JSON.parse(row.metadata) : (row.metadata || {}),
importance: row.importance || 0.5,
timestamp: row.timestamp instanceof Date ? row.timestamp : new Date(row.timestamp),
tags: typeof row.tags === 'string' ? JSON.parse(row.tags) : (Array.isArray(row.tags) ? row.tags : []),
duration: (row.duration || MemoryDuration.LONG_TERM),
expiresAt: row.expires_at ? (row.expires_at instanceof Date ? row.expires_at : new Date(row.expires_at)) : undefined
};
}
}
//# sourceMappingURL=base-memory-provider.js.map