/** * Session Manager * * Manages isolated photon instances per client session. * Supports named instances: each session maps to an instanceName, * and multiple sessions can share the same instance. * * Instance naming is transparent to the photon developer — * the runtime handles everything via _use/_instances tools. */ import { PhotonLoader, type ConstructorEnvReplayOptions } from '../loader.js'; import { PhotonSession } from './protocol.js'; import { Logger } from '../shared/logger.js'; import type { ConstructorEnvReplayIdentity, ConstructorEnvReplayStore } from './constructor-env-replay.js'; export declare class SessionManager { private sessions; /** Maps instanceName → loaded photon instance (shared across sessions) */ private instances; /** Inflight instance loads — prevents concurrent duplicate loadFile calls */ private inflightLoads; private photonPath; private photonName; loader: PhotonLoader; private sessionTimeout; private cleanupInterval; private logger; private constructorEnv?; private constructorEnvReplay?; constructor(photonPath: string, photonName: string, sessionTimeout?: number, logger?: Logger, workingDir?: string, constructorEnvReplay?: { store: ConstructorEnvReplayStore; identity: ConstructorEnvReplayIdentity; }); setConstructorEnv(values: Record | undefined): void; /** * Get or create a session. New sessions start on the default instance. */ getOrCreateSession(sessionId: string | undefined, clientType?: string): Promise; /** * Switch a session to a different named instance. * Loads the instance if not already loaded. */ switchInstance(sessionId: string, instanceName: string): Promise; /** * Get or load a photon instance for a given instanceName. * Instances are shared: multiple sessions on the same instanceName share state. */ getOrLoadInstance(instanceName: string): Promise; /** * Get the current loaded instance for a given name (synchronous). * Returns undefined if not yet loaded. Used by @photon proxy to * always resolve the latest instance after hot-reload. */ getCurrentInstance(instanceName?: string): any; /** * List all loaded instance names. */ getLoadedInstances(): string[]; /** * Get session count */ getSessionCount(): number; /** * Get all sessions (for debugging) */ getSessions(): PhotonSession[]; /** * Migrate this session manager to a new workingDir (e.g. after a rename). * Updates the loader's baseDir so all subsequent loadFile calls set * PHOTON_DIR to the new path — photon module-level constants like STATE_DIR * pick up the new location on the next fresh import. */ migrateBaseDir(newBaseDir: string): Promise; /** * Clear all cached instances and reload active sessions from disk. * Called when the workingDir is freshly created to avoid stale in-memory state. */ clearInstances(reason?: string): Promise; private shutdownLoadedInstances; /** * Update a session's instance (used during hot-reload) * Returns true if session was found and updated */ updateSessionInstance(sessionId: string, newInstance: any): boolean; /** * Clean up idle sessions (instances stay loaded until daemon shutdown) */ private cleanup; /** * Start periodic cleanup */ private startCleanup; /** * Gracefully destroy all sessions and instances. * Calls onShutdown() on all loaded instances in parallel with a 5s ceiling. * Use this during daemon shutdown to give photons a chance to clean up * resources (sockets, timers, file handles). */ destroyGraceful(): Promise; /** * Stop cleanup and destroy all sessions (sync, no lifecycle hooks). * Use destroyGraceful() for normal shutdown. */ destroy(): void; /** * Get last activity time across all sessions */ getLastActivity(): number; getConstructorEnvReplayOptions(): ConstructorEnvReplayOptions | undefined; } //# sourceMappingURL=session-manager.d.ts.map