/** * Event Metadata Calculation Helpers * * Pure functions that calculate enhanced metadata for message and tool events. * These functions analyze the world state, message content, and agent configurations * to determine ownership, recipients, threading, and message classification. * * Features: * - calculateOwnerAgentIds: Determine which agents should have message in memory * - calculateRecipientAgentId: Identify intended recipient from @mentions * - calculateMessageDirection: Classify as outgoing/incoming/broadcast * - calculateIsMemoryOnly: Detect cross-agent messages (saved but no response) * - calculateIsCrossAgentMessage: Identify agent-to-agent communication * - calculateThreadMetadata: Compute thread depth and root with cycle detection * * All functions are pure - no side effects, deterministic output, easy to test. * * Implementation: 2025-11-07 * - Clean build approach with complete metadata from creation * - Supports human broadcasts, @mention targeting, and cross-agent messaging * - Thread depth calculation with circular reference protection */ import type { World, WorldMessageEvent, AgentMessage } from './types.js'; /** * Calculate which agents should have this message in their memory * * Rules: * - Human messages: All agents receive (broadcast) * - Agent messages with @mention: Only recipient gets it * - Agent messages without @mention: All agents get it (broadcast) * - Cross-agent messages: Both sender and recipient */ export declare function calculateOwnerAgentIds(world: World, message: WorldMessageEvent): string[]; /** * Calculate the intended recipient from @mentions * Returns agentId if found, null for broadcast */ export declare function calculateRecipientAgentId(world: World, message: WorldMessageEvent): string | null; /** * Calculate message direction from agent's perspective * * - outgoing: Agent is sender * - incoming: Agent is recipient (has @mention) * - broadcast: No specific recipient */ export declare function calculateMessageDirection(world: World, message: WorldMessageEvent): 'outgoing' | 'incoming' | 'broadcast'; /** * Calculate if message is memory-only (cross-agent, no response expected) * * Memory-only messages: * - Agent messages with @mention (cross-agent communication) * - Saved to recipient's memory but doesn't trigger response */ export declare function calculateIsMemoryOnly(world: World, message: WorldMessageEvent): boolean; /** * Calculate if message is agent-to-agent communication */ export declare function calculateIsCrossAgentMessage(world: World, message: WorldMessageEvent): boolean; /** * Calculate thread metadata: root ID, depth, and circular reference detection * * Returns: * - threadRootId: ID of root message (null if this is root) * - threadDepth: 0 for root, 1 for reply, 2 for reply-to-reply, etc. * - isReply: true if replyToMessageId is set */ export declare function calculateThreadMetadata(message: WorldMessageEvent, allMessages: AgentMessage[]): { threadRootId: string | null; threadDepth: number; isReply: boolean; };