/** * World Markdown Export Functionality * * Provides comprehensive world export functionality to Markdown format including: * - World configuration and metadata * - Agent configurations and system prompts (memory excluded) * - Chat sessions with complete message histories * - World events in chronological order with CLI-style formatting * - Improved message labeling for better readability * - In-memory message detection (messages received without reply) * - Timestamp formatting and content preservation * - Message deduplication using messageId (consistent with frontend) * * Features: * - Complete world export with only the current chat * - Agent configuration details (without memory) * - Current chat message history with improved formatting: * - Human messages: "From: HUMAN / To: agent1, agent2" * - Agent incoming: "Agent: agentName (incoming from sender)" * - Agent reply: "Agent: agentName (reply to targetName)" * - In-memory detection: "[in-memory, no reply]" for received messages without response * - Chat events section for current chat only with chronological order: * - Message events: ● [message] sender: full content (no truncation) * - SSE events: ● [sse] agent: type content (shows full streaming chunks) * - World events: ● [world] agent: activity pending=N (activity tracking) * - Tool events: ● [tool] agent type (tool execution) * - System events: ● [system] full content (no truncation) * - Timestamp shown as HH:MM:SS for readability * - Structured markdown with clear sections and navigation * - Uses getMemory() for efficient message retrieval * - O(n) messageId-based deduplication (replaces O(n²) content-based approach) * - Tool call detection and summarization * - Enhanced tool call request display with tool name and argument details * - Enhanced tool result display with tool name and argument details * * Message Format Examples: * ``` * From: HUMAN * To: a1 * Time: 2025-10-25T21:24:51.218Z * hi * * Agent: o1 (incoming from HUMAN) * Time: 2025-10-25T21:24:57.105Z * [Tool: shell_cmd (command: ls -la, cwd: /home/user)] * * Agent: o1 (reply to human) * Time: 2025-10-25T21:24:57.105Z * [2 tool calls: * 1. read_file (filePath: /path/to/file.txt, limit: 100) * 2. grep (query: pattern, isRegexp: true, ...)] * * Agent: a1 (tool result) * Time: 2025-10-25T21:24:58.395Z * [Tool: run_command (command: ls -la, cwd: /home/user)] * * Agent: a1 (incoming from o1) [in-memory, no reply] * Time: 2025-10-25T21:24:58.395Z * Hi — how can I help you today? * ``` * * Event Format Examples: * ``` * 1. `10:00:00` ● [message] human: Test message content * 2. `10:01:00` ● [sse] Test Agent: start * 3. `10:01:01` ● [sse] Test Agent: chunk Hello world * 4. `10:01:02` ● [sse] Test Agent: end * 5. `10:02:00` ● [world] a1: response-start pending=1 * 6. `10:03:00` ● [world] a1: response-end pending=0 * 7. `10:04:00` ● [tool] Test Agent tool-start * 8. `10:05:00` ● [system] chat-title-updated * ``` * * Implementation: * - Uses managers module for data access * - Formats dates consistently as ISO strings * - Preserves message content with proper escaping * - Organizes export by logical sections (world → agents → current chat → events) * - Simplified chat loading using world.chats.get() and getMemory() * - Maps agentId to agent names for clear identification * - Deduplicates user messages by messageId using Map for O(1) lookup * - Detects in-memory messages by checking for subsequent assistant replies * - Events displayed in chronological order for current chat only * - Limits event display to 100 events with overflow indication * - Event format: time ● [type] agent: event-name content * * Deduplication Strategy: * - Only user messages with messageId are deduplicated * - Uses exact messageId matching (no fuzzy content comparison) * - Agent messages remain separate (one per agent) * - Tracks which agents received each message via agentIds/agentNames arrays * - Consistent with frontend deduplication logic for predictable behavior * * Changes: * - 2025-11-11: Removed all content truncation - show full message and event content without cutting off * - 2025-11-01: Fixed export to show events for current chat only (not all chats) * - 2025-11-01: Reformatted events to show: time ● [type] agent: event-name content * - 2025-11-01: SSE chunk events now properly display content in export * - 2025-11-01: Fixed null chatId bug - all events now default to world.currentChatId during persistence */ /** * Export world configuration, agents, and chats to Markdown format */ export declare function exportWorldToMarkdown(worldName: string): Promise; export declare function exportChatToMarkdown(worldId: string, chatId: string): Promise;