/** * Represents a managed, stateful workflow session (e.g., script tracing, impersonation). * * Unlike SessionManager (which caches HTTP sessions by instance alias), an ActiveSession * bundles together the stateful resources needed for a multi-step workflow under a unique ID. * This allows stateless callers (MCP tools, CLI commands) to start a workflow, receive a * session handle, and reference it in subsequent operations. */ export interface ActiveSession { /** Unique session identifier (UUID v4) */ readonly id: string; /** Session type discriminator (e.g., 'script-tracer', 'impersonation') */ readonly type: string; /** The ServiceNow instance alias this session targets */ readonly instanceAlias: string; /** When the session was created */ readonly createdAt: Date; /** When the session was last accessed (updated on every getSession/getResource call) */ lastAccessedAt: Date; /** Arbitrary keyed resources attached to this session (e.g., ScriptTracer, AMBClient) */ resources: Map; } export interface CreateSessionOptions { /** Session type discriminator */ type: string; /** The ServiceNow instance alias */ instanceAlias: string; /** Initial resources to attach (key → value) */ resources?: Record; /** Time-to-live in milliseconds. Session expires if not accessed within this window. */ ttlMs?: number; } /** * Singleton registry of active workflow sessions. * * Provides a unique-ID-based lookup for stateful sessions that span multiple * operations (e.g., start tracing → execute script → get results → stop tracing). * * Intended consumers: * - MCP tools: create a session on "start", return the ID, retrieve on subsequent tool calls * - CLI commands: same pattern when a command stays alive, or via future file-based persistence * * Resources are stored as opaque values — the registry does not know about ScriptTracer, * AMBClient, etc. Callers use typed getResource() to retrieve them. */ export declare class ActiveSessionRegistry { private static _instance; private _sessions; private _ttls; private _logger; private constructor(); static getInstance(): ActiveSessionRegistry; /** @internal Visible for testing only */ static resetInstance(): void; /** * Create a new active session and return its unique ID. */ createSession(options: CreateSessionOptions): string; /** * Retrieve an active session by ID. Returns null if not found or expired. * Updates lastAccessedAt on access. */ getSession(id: string): ActiveSession | null; /** * Typed convenience for retrieving a single resource from a session. * Returns null if the session doesn't exist, is expired, or the key is missing. */ getResource(sessionId: string, key: string): T | null; /** * Attach or update a resource on an existing session. */ setResource(sessionId: string, key: string, value: unknown): boolean; /** * Destroy a session and remove all its resources. * Callers are responsible for cleanup of resources (e.g., stopping a ScriptTracer) * before calling this method. */ destroySession(id: string): boolean; /** * List active (non-expired) sessions, optionally filtered by type and/or instance alias. */ listSessions(filter?: { type?: string; instanceAlias?: string; }): ActiveSession[]; /** * Number of active sessions. */ get size(): number; private isExpired; }