/** * Core World Runtime Registry * * Purpose: * - Provide storage-aware runtime tracking for active world runtimes. * - Support idempotent runtime start with reference-counted consumers. * - Offer deterministic stop/release behavior with optional refresh support. * * Key Features: * - Composite runtime key: storageType + storagePath + worldId. * - In-flight start deduplication per runtime key. * - Consumer ref counting with last-release shutdown. * - Runtime diagnostics snapshots for inspection. * * Implementation Notes: * - The registry is runtime-process local and does not coordinate across processes. * - Storage context defaults are sourced from environment when not provided. * * Recent Changes: * - 2026-03-04: Runtime refresh now updates the registry's `world` reference. * - Prevents callers from receiving stale pre-refresh world instances. * - 2026-03-03: Initial runtime registry implementation for canonical world runtime ownership. */ type StorageType = 'file' | 'sqlite' | 'memory'; export interface WorldRuntimeStorageContext { storageType: StorageType; storagePath: string; } export interface ManagedWorldRuntime { world: TWorld; stop: () => Promise; refresh?: () => Promise; } export interface StartWorldRuntimeParams { worldId: string; consumerId: string; storageType?: StorageType; storagePath?: string; createRuntime: () => Promise>; } export interface StartedWorldRuntime { runtimeKey: string; worldId: string; storageType: StorageType; storagePath: string; world: TWorld; refCount: number; release: () => Promise; refresh: () => Promise; } export interface WorldRuntimeSnapshot { runtimeKey: string; worldId: string; storageType: StorageType; storagePath: string; startedAt: string; refCount: number; consumers: string[]; } export declare function createWorldRuntimeKey(worldId: string, context: WorldRuntimeStorageContext): string; export declare function startWorldRuntime(params: StartWorldRuntimeParams): Promise>; export declare function releaseWorldRuntime(params: { runtimeKey?: string; worldId?: string; storageType?: StorageType; storagePath?: string; consumerId: string; }): Promise; export declare function getWorldRuntime(params: { worldId: string; storageType?: StorageType; storagePath?: string; }): StartedWorldRuntime | null; export declare function getWorldRuntimeByKey(runtimeKey: string): StartedWorldRuntime | null; export declare function listWorldRuntimeSnapshots(): WorldRuntimeSnapshot[]; export declare function stopWorldRuntime(runtimeKey: string): Promise; /** * Stop all active world runtimes with the given worldId regardless of storage * context. Used when a world is deleted so subsequent subscriptions do not * reuse a stale runtime that was loaded for the previous incarnation. */ export declare function stopWorldRuntimesByWorldId(worldId: string): Promise; export declare function stopAllWorldRuntimes(): Promise; export {};