/** * World Subscription Runtime * * Features: * - Manages world lifecycle subscriptions and realtime event forwarding. * - Registers message/world/sse/system listeners for subscribed clients. * - Tracks active world runtimes for core operations that need the live emitter. * * Implementation Notes: * - Keeps forwarding listeners optional based on client callback capabilities. * - Uses world-id keyed runtime tracking with safe register/unregister semantics. * * Recent Changes: * - 2026-03-10: Rebound the idle activity listener during standalone runtime startup so * idle-only title generation still works when event persistence is unavailable. * - 2026-03-04: Queue/runtime selection no longer relies on `world.currentChatId`. * - `getActiveSubscribedWorld(worldId, preferredChatId)` now matches only by runtime chat membership. * - Subscription startup no longer auto-resumes queue from runtime `currentChatId`. * - 2026-02-28: Re-applied world-level message subscriptions during runtime refresh to preserve chat-title scheduling after session/world updates. * - 2026-02-14: Added active runtime world tracking and `getActiveSubscribedWorld()` for core edit-message resubmission to publish on live emitters. */ import { World } from './types.js'; import { type LogLevel } from './logger.js'; export interface LogStreamEvent { level: LogLevel; category: string; message: string; timestamp: string; data?: any; messageId: string; } export interface ClientConnection { isOpen: boolean; onWorldEvent?: (eventType: string, eventData: any) => void; onError?: (error: string) => void; onLog?: (logEvent: LogStreamEvent) => void; } export interface WorldSubscription { world: World; unsubscribe: () => Promise; refresh: () => Promise; destroy: () => Promise; } export declare function getActiveSubscribedWorld(worldIdentifier: string, preferredChatId?: string | null): World | null; export declare function getActiveSubscribedWorlds(worldIdentifier: string): World[]; export declare function startWorld(world: World, client: ClientConnection): Promise; export declare function subscribeWorld(worldIdentifier: string, client: ClientConnection): Promise; export declare function setupWorldEventListeners(world: World, client: ClientConnection): Map void>; export declare function cleanupWorldSubscription(world: World, worldEventListeners: Map void>): Promise;