import { AsyncLocalStorage } from "async_hooks"; import type { ClioTokens } from "../auth/clioOAuth.js"; import type { ClioRegion } from "./clioRegion.js"; /** * Per-request identity and token access for everything that runs inside a * session (the built-in HTTP transport, or a host embedding the connector). * stdio mode never establishes a context: the tools fall back to the local * token file there, and nowhere else. */ /** Half-finished broker handshake: the PKCE verifier held between authorize and callback. */ export interface PendingBrokerSession { brokerSessionId: string; codeVerifier: string; } export interface SessionContext { sessionId: string; /** Caller identity as known to the host (hosted deployments). Written to every audit entry. */ userId?: string; /** Clio user id when the host already knows it; saves a token lookup per audit entry. */ clioUserId?: string; /** Host request id, for correlating audit entries with request logs. */ requestId?: string; /** Clio region of the caller's firm. Hosts serving firms in several regions set this so data calls go to the right Clio server; unset falls back to CLIO_REGION. */ region?: ClioRegion; getAccessToken(): Promise; getTokens(): Promise; storeTokens(tokens: ClioTokens): Promise; clearTokens(): Promise; /** Present only when this connector owns the Clio login flow (built-in HTTP mode). Hosts that log users in themselves leave it out. */ setPendingNonce?(nonce: string): void; /** Broker mode only: the PKCE verifier is parked here between authorize and callback, so the connector never needs the client secret. */ setPendingBrokerSession?(session: PendingBrokerSession | null): void; getPendingBrokerSession?(): PendingBrokerSession | null; } export declare const sessionStorage: AsyncLocalStorage; export declare function getSessionContext(): SessionContext | undefined; /** Run `fn` with `ctx` as the current session context. */ export declare function runWithSessionContext(ctx: SessionContext, fn: () => Promise): Promise; /** True when the connector runs as a Claude Desktop child process (TRANSPORT=stdio). */ export declare function isStdioMode(env?: NodeJS.ProcessEnv): boolean; /** * Fail-closed variant of getSessionContext(). Outside stdio mode a missing * context means some code path forgot to run inside the session, and silently * falling back to the shared single-user token file would leak one session's * Clio identity into another's request. Only stdio mode may return null. */ export declare function requireSessionContext(): SessionContext | null; //# sourceMappingURL=sessionContext.d.ts.map