import type { ClientToolDefinition } from '@mondaydotcomorg/atp-protocol'; import type { TokenRefreshConfig } from './types.js'; /** * Token credentials returned from init and refresh operations */ export interface TokenCredentials { clientId: string; token: string; expiresAt: number; tokenRotateAt: number; } /** * Session interface for ATP client operations */ export interface ISession { init(clientInfo?: { name?: string; version?: string; [key: string]: unknown; }, tools?: ClientToolDefinition[], services?: { hasLLM: boolean; hasApproval: boolean; hasEmbedding: boolean; hasTools: boolean; }): Promise; getClientId(): string; ensureInitialized(): Promise; getHeaders(): Record; getBaseUrl(): string; prepareHeaders(method: string, url: string, body?: unknown): Promise>; refreshTokenIfNeeded(): Promise; setTokenRefreshConfig(config: Partial): void; } /** * Stored init parameters for re-initialization during token refresh. */ export interface StoredInitParams { clientInfo?: { name?: string; version?: string; [key: string]: unknown; }; tools?: ClientToolDefinition[]; services?: { hasLLM: boolean; hasApproval: boolean; hasEmbedding: boolean; hasTools: boolean; }; } /** * Base session class with shared token management logic. * Subclasses implement the transport-specific operations (HTTP vs in-process). */ export declare abstract class BaseSession implements ISession { protected clientId?: string; protected clientToken?: string; protected tokenExpiresAt?: number; protected tokenRotateAt?: number; protected initPromise?: Promise; protected refreshPromise?: Promise; protected storedInitParams?: StoredInitParams; protected tokenRefreshConfig: TokenRefreshConfig; protected constructor(tokenRefreshConfig?: Partial); /** * Initialize the session - must be implemented by subclass */ abstract init(clientInfo?: { name?: string; version?: string; [key: string]: unknown; }, tools?: ClientToolDefinition[], services?: { hasLLM: boolean; hasApproval: boolean; hasEmbedding: boolean; hasTools: boolean; }): Promise; /** * Get headers for requests - must be implemented by subclass */ abstract getHeaders(): Record; /** * Get base URL - must be implemented by subclass */ abstract getBaseUrl(): string; /** * Ensure client is initialized - must be implemented by subclass */ abstract ensureInitialized(): Promise; /** * Prepare headers for a request - must be implemented by subclass */ abstract prepareHeaders(method: string, url: string, body?: unknown): Promise>; /** * Perform token refresh by re-initializing the session. * Resets the init guard and calls init() again with the stored params, * effectively creating a fresh session without depending on the old * session still existing in the server's cache. */ protected doRefreshToken(): Promise; /** * Gets the unique client ID. */ getClientId(): string; /** * Configure automatic token refresh behavior */ setTokenRefreshConfig(config: Partial): void; /** * Check if token needs refresh based on current time and config */ protected needsTokenRefresh(): boolean; /** * Refresh token if needed (past rotateAt time or expired). * This is called automatically before requests when autoRefresh is enabled. * Uses a shared promise to prevent concurrent refresh requests. * * Refresh works by re-initializing the session (calling init() again), * so it does not depend on the old session still existing in the server's cache. */ refreshTokenIfNeeded(): Promise; /** * Update token state after successful init or refresh */ protected updateTokenState(credentials: TokenCredentials): void; /** * Check if URL should skip token refresh (to avoid infinite recursion). * Since refresh now calls init(), we only need to guard the init path. */ protected shouldSkipRefreshForUrl(url: string): boolean; } //# sourceMappingURL=base-session.d.ts.map