import { PrivacyConfig } from "./core/privacy.js"; import { AmplitudeLike } from "./types.js"; import { AsyncLocalStorage } from "node:async_hooks"; //#region src/context.d.ts interface SessionContextOptions { sessionId: string; traceId?: string | null; userId?: string | null; agentId?: string | null; parentAgentId?: string | null; env?: string | null; customerOrgId?: string | null; agentVersion?: string | null; description?: string | null; context?: Record | null; groups?: Record | null; tags?: string[] | null; idleTimeoutMinutes?: number | null; deviceId?: string | null; browserSessionId?: string | null; nextTurnIdFn?: (() => number) | null; amplitude?: AmplitudeLike | null; /** Privacy config of the `AmplitudeAI` that owns this session. */ privacyConfig?: PrivacyConfig | null; trackerManaged?: boolean; skipAutoUserTracking?: boolean; } declare class SessionContext { readonly sessionId: string; traceId: string | null; readonly userId: string | null; readonly agentId: string | null; readonly parentAgentId: string | null; readonly env: string | null; readonly customerOrgId: string | null; readonly agentVersion: string | null; readonly description: string | null; readonly context: Record | null; readonly groups: Record | null; readonly tags: string[] | null; readonly idleTimeoutMinutes: number | null; readonly deviceId: string | null; readonly browserSessionId: string | null; readonly amplitude: AmplitudeLike | null; readonly privacyConfig: PrivacyConfig | null; readonly trackerManaged: boolean; readonly skipAutoUserTracking: boolean; private readonly _nextTurnIdFn; constructor(options: SessionContextOptions); nextTurnId(): number | null; } declare const _sessionStorage: AsyncLocalStorage; declare function getActiveContext(): SessionContext | null; /** * Return `true` when a higher-level tracker (e.g. `AgentAnalyticsTracker`) * owns event emission for this context. * * `patch()` provider wrappers check this to avoid duplicate events. */ declare function isTrackerManaged(): boolean; declare function runWithContext(ctx: SessionContext, fn: () => T): T; declare function runWithContextAsync(ctx: SessionContext, fn: () => Promise): Promise; /** @internal Reset the one-time warning flag. For test isolation only. */ declare function _resetPushContextWarning(): void; /** * Run `fn` with `ctx` as the active SessionContext. * * The context is visible to `fn` and everything it awaits or schedules, and * is gone once `fn` returns (same semantics as {@link runWithContext}). Use * this in middleware by wrapping the downstream handler: * * ```typescript * app.use((req, res, next) => pushContext(ctxFor(req), next)); * ``` * * For Express-style apps, `createAmplitudeAIMiddleware()` does this for you. */ declare function pushContext(ctx: SessionContext | null, fn: () => T): T; /** * @deprecated Set the context for the rest of the current async scope and * return a cleanup function that restores the previous context. Logs a * one-time warning. * * Unsafe on HTTP servers: `AsyncLocalStorage.enterWith()` attaches the * context to the socket's execution context, so later requests on the same * keep-alive connection that never call `pushContext` inherit the previous * caller's identity, and the cleanup does not undo that. Prefer * `pushContext(ctx, fn)`, `runWithContext()` or `session.run()`. */ declare function pushContext(ctx: SessionContext | null): () => void; //#endregion export { SessionContext, SessionContextOptions, _resetPushContextWarning, _sessionStorage, getActiveContext, isTrackerManaged, pushContext, runWithContext, runWithContextAsync }; //# sourceMappingURL=context.d.ts.map