/** * AsyncLocalStorage-based correlation context for request/session/turn/run scoping. * * Seed at HTTP entry points and session/turn creation so downstream events can * automatically attach the correct IDs without explicit threading. * * Usage: * ```ts * // Seed at HTTP request entry: * correlationCtx.run({ requestId: crypto.randomUUID() }, () => handler(req)); * * // Read anywhere downstream: * const { requestId, sessionId } = getCorrelationContext(); * ``` */ import { AsyncLocalStorage } from 'node:async_hooks'; /** Correlation identifiers propagated via AsyncLocalStorage. */ export interface CorrelationContext { /** HTTP request ID, seeded by the HTTP listener on every inbound request. */ readonly requestId?: string | undefined; /** Session ID, seeded when a session starts or resumes. */ readonly sessionId?: string | undefined; /** Run ID, seeded when a run (multi-turn conversation) begins. */ readonly runId?: string | undefined; /** Turn ID, seeded when a turn starts within a run. */ readonly turnId?: string | undefined; } /** The singleton AsyncLocalStorage instance for correlation context. */ export declare const correlationCtx: AsyncLocalStorage; /** * Get the current correlation context, or an empty object if none is active. * Safe to call from anywhere, returns {} when no context is running. */ export declare function getCorrelationContext(): Readonly; /** * Run a function within a new correlation context that inherits the current * context and overrides the provided fields. */ export declare function withCorrelation(overrides: Partial, fn: () => T): T; /** * Run an async function within a new correlation context. */ export declare function withCorrelationAsync(overrides: Partial, fn: () => Promise): Promise; //# sourceMappingURL=correlation.d.ts.map