/** * Event Publishers - Event Emission Functions * * Purpose: Functions that emit events to World.eventEmitter * Features: * - Message publishing with chat session management * - SSE event publishing for streaming * - Tool event publishing for agent behaviors * * Implementation Notes: * - Uses parseMessageContent to preserve enhanced tool-result protocol support * - Emits events synchronously through world-scoped EventEmitter channels * * Recent Changes: * - 2026-03-13: Preserved optional SSE `reasoningContent` so reasoning tokens survive world-scoped event publication. * - 2026-03-06: Required explicit `chatId` for message/system/SSE/tool publication; removed `world.currentChatId` fallback from event emitters. * - 2026-02-13: Added optional explicit `chatId` override for `publishEvent` to preserve session context across async flows. * - 2026-02-13: Added chat-scoped tool-event propagation (`chatId`) so realtime tool updates remain session-isolated. * - 2026-02-11: Fixed publishSSE to include toolName and stream fields for tool-stream events * - 2026-02-08: Added core-level sender normalization for consistent user-role detection * - 2026-02-08: Removed legacy manual tool-result publishing helper from event API * * All functions emit events synchronously and return immediately */ import { World, WorldMessageEvent, WorldSSEEvent, WorldToolEvent } from '../types.js'; export declare function enableStreaming(): void; export declare function disableStreaming(): void; export declare function isStreamingEnabled(): boolean; /** * Normalize sender values so role/persistence logic remains consistent across clients. * Examples: * - "HUMAN", "user", "User42" => "human" * - "SYSTEM" => "system" * - Agent IDs remain unchanged. */ export declare function normalizeSender(sender: string): string; /** * Publish event to a specific channel using World.eventEmitter */ export declare function publishEvent(world: World, type: string, content: any, chatId: string): void; /** * Message publishing using World.eventEmitter with chat session management * Parses enhanced string protocol and automatically prepends @mention if agentId detected * Returns the messageEvent so callers can access the generated messageId * * @param chatId - Explicit chat ID for concurrency-safe routing * @param replyToMessageId - Optional parent message ID for threading */ export declare function publishMessage(world: World, content: string, sender: string, chatId: string, replyToMessageId?: string): WorldMessageEvent; /** * Message publishing with pre-generated messageId * Used when messageId needs to be known before publishing (e.g., for agent responses) * * @param chatId - Explicit chat ID for concurrency-safe routing * @param replyToMessageId - Optional parent message ID for threading */ export declare function publishMessageWithId(world: World, content: string, sender: string, messageId: string, chatId: string, replyToMessageId?: string): WorldMessageEvent; /** * Subscribe to message events */ export declare function subscribeToMessages(world: World, handler: (event: WorldMessageEvent) => void | Promise): () => void; /** * SSE events using World.eventEmitter (for LLM streaming) */ export declare function publishSSE(world: World, data: Partial & { chatId: string; }): void; /** * Tool events using World.eventEmitter (for agent behavioral events) */ export declare function publishToolEvent(world: World, data: Partial & { chatId: string; }): void; /** * SSE subscription using World.eventEmitter */ export declare function subscribeToSSE(world: World, handler: (event: WorldSSEEvent) => void): () => void;