import type { ToolSession } from "../../sdk";
import { CmuxTab } from "./cmux/cmux-tab";
import { type BrowserHandle, type BrowserKindTag, type CmuxBrowserHandle, type PuppeteerBrowserHandle } from "./registry";
import type { ReadyInfo, RunResultOk, Transferable, WorkerInbound, WorkerInitPayload, WorkerOutbound } from "./tab-protocol";
interface WorkerHandle {
    send(msg: WorkerInbound, transferList?: Transferable[]): void;
    onMessage(handler: (msg: WorkerOutbound) => void): () => void;
    onError(handler: (error: Error) => void): () => void;
    terminate(): Promise<void>;
    readonly mode: "worker" | "inline";
}
export type DialogPolicy = "accept" | "dismiss";
export interface PendingRun {
    resolve(result: RunResultOk): void;
    reject(error: unknown): void;
    session: ToolSession;
    signal?: AbortSignal;
    toolCalls: Map<string, AbortController>;
}
interface TabSessionBase<TBrowser extends BrowserHandle = BrowserHandle> {
    name: string;
    browser: TBrowser;
    targetId: string;
    state: "alive" | "dead";
    info: ReadyInfo;
    pending: Map<string, PendingRun>;
    dialogPolicy?: DialogPolicy;
    kindTag: BrowserKindTag;
}
export interface WorkerTabSession extends TabSessionBase<PuppeteerBrowserHandle> {
    backend: "worker";
    worker: WorkerHandle;
}
export interface CmuxTabSession extends TabSessionBase<CmuxBrowserHandle> {
    backend: "cmux";
    cmuxTab: CmuxTab;
    cmuxOwnsSurface: boolean;
    cmuxAttachedSurface?: string;
}
export type TabSession = WorkerTabSession | CmuxTabSession;
export interface AcquireTabOptions {
    url?: string;
    waitUntil?: "load" | "domcontentloaded" | "networkidle0" | "networkidle2";
    viewport?: {
        width: number;
        height: number;
        deviceScaleFactor?: number;
    };
    target?: string;
    signal?: AbortSignal;
    timeoutMs: number;
    dialogs?: DialogPolicy;
    cmuxSurface?: string;
}
export interface AcquireTabResult {
    tab: TabSession;
    created: boolean;
}
export interface RunInTabOptions {
    code: string;
    timeoutMs: number;
    signal?: AbortSignal;
    session: ToolSession;
}
export interface ReleaseTabOptions {
    kill?: boolean;
}
export declare function getTab(name: string): TabSession | undefined;
export declare function acquireTab(name: string, browser: BrowserHandle, opts: AcquireTabOptions): Promise<AcquireTabResult>;
export declare function runInTab(name: string, opts: RunInTabOptions): Promise<RunResultOk>;
export declare function releaseTab(name: string, opts?: ReleaseTabOptions): Promise<boolean>;
export declare function releaseAllTabs(opts?: ReleaseTabOptions): Promise<number>;
export declare function dropHeadlessTabs(): Promise<void>;
export declare function initializeTabWorkerForTest(worker: WorkerHandle, payload: WorkerInitPayload, timeoutMs: number): Promise<ReadyInfo>;
export {};
