/** * World Storage Module - File I/O Operations for World Data and Chat Operations * * Logger Category: storage.query * Purpose: World and chat data file I/O operations * * Enable with: LOG_STORAGE_QUERY=debug npm run server * * What you'll see: * - World config saves and loads * - Chat data operations * - Memory aggregation queries * - File operation errors * * Features: * - World configuration persistence to config.json with flattened structure * - Complete chat operations with file-based storage (chats directory) * - Cross-agent memory aggregation for world-level chat sessions * - Kebab-case directory naming from world names * - Clean separation of storage data from runtime objects * - Handles World serialization without EventEmitter and agents Map * - Complete isolation from other internal modules * - Explicit rootPath parameter handling (no environment variables) * - Cascade deletion for data integrity (world → agents/chats, chat → messages) * * Core Functions: * - saveWorld: Save world config.json with flat structure (excludes runtime properties: eventEmitter, agents, chats, eventStorage, _eventPersistenceCleanup) * - loadWorld: Load world configuration from file * - deleteWorld: Remove world directory and all contents (cascades to agents and chats) * - listWorlds: Scan and load all worlds in root directory * - worldExists: Check if world directory exists * * Changes: * - 2026-02-13: Added compare-and-set chat title helper (`updateChatNameIfCurrent`) for safer concurrent title commits. * - 2025-11-01: Explicitly exclude runtime properties (eventEmitter, agents, chats, eventStorage, _eventPersistenceCleanup) from saveWorld * - getWorldDir: Get world directory path * - ensureWorldDirectory: Create world directory structure * * Chat Functions: * - saveChatData: Save complete chat data with metadata and content * - loadChatData: Load complete chat data with Date reconstruction * - deleteChatData: Remove chat files and cascade delete associated messages from agent memory * - listChatHistories: List all chat metadata for a world * - updateChatData: Update existing chat with partial data * - getMemory: Aggregate memory across all agents for chat sessions * * Version: 2.1.0 - Added cascade deletion for chat operations * Date: 2025-10-30 * Version: 2.2.0 - Updated to structured logging (storage.query) * Date: 2025-10-31 */ import type { World, Chat, UpdateChatParams, AgentMessage } from '../types.js'; /** * World directory and file path utilities */ export declare function getWorldDir(rootPath: string, worldId: string): string; export declare function ensureWorldDirectory(root: string, worldId: string): Promise; /** * Check if world exists on disk */ export declare function worldExists(root: string, worldId: string): Promise; /** * Save world to disk */ export declare function saveWorld(root: string, worldData: World): Promise; /** * Load world from disk */ export declare function loadWorld(root: string, worldId: string): Promise; /** * Delete world from disk */ export declare function deleteWorld(root: string, worldId: string): Promise; /** * List all worlds in root directory */ export declare function listWorlds(root: string): Promise; /** * Chat directory and file path utilities */ export declare function getChatDir(rootPath: string, worldId: string): string; export declare function getChatFilePath(rootPath: string, worldId: string, chatId: string): string; export declare function ensureChatDirectory(rootPath: string, worldId: string): Promise; /** * Save chat data (metadata + content) to disk */ export declare function saveChatData(rootPath: string, worldId: string, chatData: Chat): Promise; /** * Load chat data (metadata + content) from disk */ export declare function loadChatData(rootPath: string, worldId: string, chatId: string): Promise; /** * Update chat data on disk */ export declare function updateChatData(rootPath: string, worldId: string, chatId: string, updates: UpdateChatParams): Promise; /** * Compare-and-set chat name on disk. * Updates name only when the current name exactly matches expectedName. */ export declare function updateChatNameIfCurrent(rootPath: string, worldId: string, chatId: string, expectedName: string, nextName: string, nextProvenance?: import('../chat-constants.js').TitleProvenance): Promise; /** * Delete chat data from disk with cascade deletion of associated messages */ export declare function deleteChatData(rootPath: string, worldId: string, chatId: string): Promise; /** * List chat histories (metadata only) */ export declare function listChatHistories(rootPath: string, worldId: string): Promise; /** * Get aggregated memory across all agents for a given chat * Filters messages by chatId and includes agentId for proper message attribution */ export declare function getMemory(rootPath: string, worldId: string, chatId: string): Promise;