/**
 * src/integrations/browser-session.ts
 *
 * Persistent Playwright browser session keyed by tenant. Survives across
 * tool-call turns so chain operations like "open youtube → type 'hi' →
 * press enter" work as expected. Without this, every fast-path-style
 * "open url" spawned a new process and lost state.
 *
 * Lifecycle:
 *   - First tool call lazily spawns a Chromium instance (headed by default
 *     so the owner sees it; can be flipped to headless via env).
 *   - Subsequent calls reuse the same browser + page.
 *   - Idle timeout (15 min) auto-closes to free RAM.
 *   - Process exit handler closes cleanly.
 *
 * Safety:
 *   - One browser per tenant. Cross-tenant isolation via separate Browser
 *     instances + storage state, not just incognito contexts.
 *   - URL allow/deny is enforced at the browser tools layer, not here —
 *     this module is a transport.
 */
import type { Browser, BrowserContext, Page } from 'playwright';
interface TenantSession {
    browser: Browser;
    context: BrowserContext;
    page: Page;
    createdAt: number;
    lastUsed: number;
    idleTimer: NodeJS.Timeout;
    /** Number of in-flight tool calls. Idle close blocks while > 0 to avoid
     * "Cannot use closed page" mid-tool. (Audit C2.) */
    inFlight: number;
    /** When set, a deferred close will fire as soon as inFlight returns to 0. */
    pendingClose: boolean;
}
/**
 * Run an operation against a tenant's browser session with refcount protection.
 * Use this from every browser_* tool — it guarantees the session won't be
 * closed mid-operation by the idle timer.
 */
export declare function withBrowser<T>(tenantId: string, fn: (session: TenantSession) => Promise<T>, options?: {
    headless?: boolean;
}): Promise<T>;
export declare function getOrCreateSession(tenantId: string, options?: {
    headless?: boolean;
}): Promise<TenantSession>;
export declare function closeSession(tenantId: string, options?: {
    force?: boolean;
}): Promise<void>;
export declare function isSessionActive(tenantId: string): boolean;
/**
 * (Caveat fix) Pre-warm the browser session for a tenant during gateway boot.
 * Eliminates the ~10s first-call delay from launching Chromium. Opt-in via
 * MUASSIS_BROWSER_PREWARM=true to avoid the +200MB RAM cost on installs that
 * don't need browser tools.
 */
export declare function prewarmBrowser(tenantId: string): Promise<void>;
export declare function listSessions(): Array<{
    tenantId: string;
    createdAt: number;
    lastUsed: number;
    url: string | null;
}>;
export {};
//# sourceMappingURL=browser-session.d.ts.map