/** * Memory Storage Implementation * * Logger Category: storage.memory * Purpose: In-memory storage operations for tests and browser environments * * Enable with: LOG_STORAGE_MEMORY=debug npm run server * * What you'll see: * - World/agent/chat CRUD operations * - Memory operations and queries * - Data validation errors * * In-memory storage backend for unit tests, browser environments, and development. * Provides full StorageAPI compatibility with data persistence during runtime session. * * Features: * - Full StorageAPI implementation using in-memory Maps * - No external dependencies or file system access required * - Suitable for unit tests, browser environments, and development * - Complete chat lifecycle management with parent-child relationships * - Cross-agent memory aggregation for world-level contexts * - Data integrity through cascade deletion * - In-memory queue row persistence for user-turn queue workflows in tests * - Runtime property exclusion: eventEmitter, agents, chats, eventStorage are not persisted * * Changes: * - 2026-02-13: Added compare-and-set chat title update helper (`updateChatNameIfCurrent`) for race-safe title commits. * - 2026-03-12: Removed dormant world-chat snapshot storage; chats persist as metadata plus aggregated agent memory only. * - 2025-11-01: Exclude runtime properties from saveWorld to prevent storing EventEmitter and Map instances * - Batch operations with atomic-like behavior * - Memory archiving and cleanup operations * - Data validation and integrity checks * - Compatible agentId inclusion in getMemory for export functionality * * Implementation: * - Uses nested Maps for hierarchical data organization * - Maintains separate stores for worlds, agents, chats, and archived memory * - Deep cloning for data isolation and immutability * - Proper error handling with meaningful error messages * - ID-based lookups with existence validation * - Ensures getMemory includes agentId for message source identification * * Changes: * - 2025-08-07: Initial implementation for non-Node environments * - 2025-08-09: Added agentId to getMemory response for storage compatibility * - 2025-10-31: Updated to structured logging (storage.memory category) */ import type { StorageAPI, World, Agent, Chat, UpdateChatParams, AgentMessage, EditErrorLog, QueueMessageStatus, QueuedMessage } from '../types.js'; /** * Memory-based storage implementation */ export declare class MemoryStorage implements StorageAPI { private worlds; private agents; private chats; private archivedMemory; private editErrors; private queuedMessages; private nextQueueRowId; saveWorld(worldData: World): Promise; loadWorld(worldId: string): Promise; deleteWorld(worldId: string): Promise; listWorlds(): Promise; worldExists(worldId: string): Promise; getMemory(worldId: string, chatId: string): Promise; saveAgent(worldId: string, agent: Agent): Promise; loadAgent(worldId: string, agentId: string): Promise; loadAgentWithRetry(worldId: string, agentId: string, options?: any): Promise; deleteAgent(worldId: string, agentId: string): Promise; listAgents(worldId: string): Promise; agentExists(worldId: string, agentId: string): Promise; saveAgentMemory(worldId: string, agentId: string, memory: AgentMessage[]): Promise; archiveMemory(worldId: string, agentId: string, memory: AgentMessage[]): Promise; deleteMemoryByChatId(worldId: string, chatId: string): Promise; saveAgentsBatch(worldId: string, agents: Agent[]): Promise; loadAgentsBatch(worldId: string, agentIds: string[]): Promise; saveChatData(worldId: string, chat: Chat): Promise; loadChatData(worldId: string, chatId: string): Promise; deleteChatData(worldId: string, chatId: string): Promise; getQueuedMessages(worldId: string, chatId: string): Promise; addQueuedMessage(worldId: string, chatId: string, messageId: string, content: string, sender: string): Promise; updateMessageQueueStatus(messageId: string, status: QueueMessageStatus): Promise; incrementQueueMessageRetry(messageId: string): Promise; removeQueuedMessage(messageId: string): Promise; resetQueueMessageForRetry(messageId: string): Promise; cancelQueuedMessages(worldId: string, chatId: string): Promise; recoverSendingMessages(): Promise; deleteQueueForChat(worldId: string, chatId: string): Promise; listChats(worldId: string): Promise; updateChatData(worldId: string, chatId: string, updates: UpdateChatParams): Promise; updateChatNameIfCurrent(worldId: string, chatId: string, expectedName: string, nextName: string, nextProvenance?: import('../chat-constants.js').TitleProvenance): Promise; validateIntegrity(worldId: string, agentId?: string): Promise; repairData(worldId: string, agentId?: string): Promise; /** * Clear all stored data - useful for test cleanup */ saveEditErrors(worldId: string, errors: EditErrorLog[]): Promise; loadEditErrors(worldId: string): Promise; clear(): Promise; /** * Get storage statistics - useful for debugging */ getStats(): { worlds: number; totalAgents: number; totalChats: number; totalArchivedMemory: number; totalQueuedMessages: number; }; } /** * Create a new memory storage instance */ export declare function createMemoryStorage(): StorageAPI;