/** * World Activity Tracker * * Purpose: * - Track world-level processing lifecycle and emit activity events. * * Key Features: * - Emits `response-start`, `response-end`, and `idle` events. * - Tracks active sources and active chat IDs for concurrent chat operations. * - Maintains `world.isProcessing` based on lifecycle transitions. * * Implementation Notes: * - Activity state is stored on the world instance via a private symbol key. * - Events include a chat context (`chatId`) captured from the originating operation. * * Recent Changes: * - 2026-02-27: Added chat-scoped `chatId` metadata to world activity events to prevent cross-chat idle-side effects. */ import { World } from './types.js'; import { getLLMQueueStatus } from './llm-manager.js'; export type WorldActivityEventType = 'response-start' | 'response-end' | 'idle'; export interface WorldActivityEventPayload { type: WorldActivityEventType; pendingOperations: number; activityId: number; timestamp: string; source?: string; chatId?: string | null; activeSources: string[]; activeChatIds: string[]; queuedChatIds: string[]; activeAgentNames: string[]; queue: ReturnType; messageId: string; } export declare function beginWorldActivity(world: World, source?: string, chatId?: string): () => void; /** * Returns the set of chatIds currently being actively processed in this world. * Useful for parallel-chat monitoring and targeted mutation guards. */ export declare function getActiveProcessingChatIds(world: World): ReadonlySet; /** * Returns the names of agents currently generating responses in this world. * Derived from activeSources keys (stored as `agent:`). */ export declare function getActiveAgentNames(world: World): string[]; /** * Returns true if the given chatId has at least one active processing operation. */ export declare function isChatProcessing(world: World, chatId: string): boolean; export declare function trackWorldActivity(world: World, operation: () => Promise, source?: string, chatId?: string): Promise;