export declare const STABLE_REF_PREFIX = "r"; export interface RefBinding { ref: string; frameKey: string; backendNodeId: number; role: string; name: string; snapshotGeneration?: number; documentGeneration?: number; } export declare class StableRefs { private documentGeneration; private next; private byKey; private byNum; private static keyOf; private sync; /** Stable ref for every binding of the current snapshot (snapshot ref -> * stable ref). Records each node's latest role and label. */ assign(documentGeneration: number, bindings: Iterable): Map; /** Stable ref of a binding already numbered (no new number). */ stableOf(documentGeneration: number, b: { frameKey: string; backendNodeId: number; }): string | null; /** The current snapshot's ref for a stable ref, or null when the element is * gone, the document changed, or the node no longer carries the role and * label it was read with. Never a guess. */ resolve(stableRef: string, documentGeneration: number, current: Iterable): string | null; } export declare function isStableRef(ref: unknown): boolean; /** One rendered node of the bridge's last snapshot (captureSnapshot keeps * them per lease for this module). */ export interface SnapItem extends RefBinding { aria: string; domId: string; href: string; click: boolean; edit: boolean; covered: boolean; l: number; t: number; r: number; b: number; /** Editable fields only, never a secret field's. */ value?: string; } /** The screen in the line format the server's parseBrowserTree reads: * `r@e12 [click] [edit] [COVERED] "name" ="value" ~aria #id @href `. * A COVERED element (something else is painted over its centre) is not * offered as clickable: a click there lands on whatever covers it. */ export declare function renderFastLines(items: SnapItem[], toStable: Map): string[]; /** The LLM usually read the page with browser_get_screen_tree before planning, * so its steps may quote that snapshot's @eN (a target's `ref`, a list's * `in`). The run's first read takes a new snapshot, which would orphan them: * translate them to stable refs now, while that snapshot is still current. * A ref that no longer resolves is dropped; the step falls back to its label. */ export declare function translateStepRefs(steps: unknown, toStable: (snapshotRef: string) => string | null): unknown; /** The run's autonomy: the registered (server-clamped) mode, which a caller * holding the bridge token may TIGHTEN but never loosen (same rule as the * bridge's publish gate). No registered mode: the caller's, default safe. */ export declare function clampHitlMode(specMode: unknown, bodyMode: unknown): "safe" | "payments_only" | "autonomous"; export interface FastObservation { url: string; title: string; generation: number; documentGeneration: number; items: SnapItem[]; } /** What the bridge gives a fast session. Every write goes through act, which * is the bridge's performAct for this run's registration. */ export interface FastBridgeOps { /** The run is torn down, its grant expired, or the user took over. */ state(): { cancelled: boolean; expired: boolean; paused: boolean; }; /** Take a snapshot (the bridge binds its @eN refs) and return its nodes. */ observe(): Promise; /** The current snapshot's bindings, for resolving a stable ref. */ bindings(): Promise<{ documentGeneration: number; refs: RefBinding[]; }>; /** One act through performAct. Throws {code, message} on refusal. */ act(args: Record): Promise; /** Stage (or correlate) the approval a submitting Enter needs, BEFORE * anything is typed. Throws approval_required while it is pending. */ gateSubmit(mode: string): Promise; /** URL and title of the controlled tab. */ location(): Promise<{ url: string; title: string; }>; wait(ms: number): Promise; /** Stable refs of this lease (kept across fast runs, per document). */ stableRefs(): Promise; } export interface FastCommand { seq: number; kind: string; body: Record; } export type FastOutcome = { ok: true; data: Record; } | { ok: false; code: string; message: string; }; export declare class FastCommandError extends Error { code: string; constructor(code: string, message: string); } /** Run one command the server's executor sent, under this run's grant and * autonomy (`mode`, clamped on this side: the server cannot loosen it). */ export declare function execFastCommand(ops: FastBridgeOps, cmd: FastCommand, mode: string): Promise; export interface PumpReply { command?: FastCommand; end?: boolean; idle?: boolean; } /** Pull the server executor's commands and run them, one at a time, until the * server ends the run or this run is torn down. A command is executed once: * its outcome is carried by the next poll, resent unchanged if that poll * fails, and the server ignores an outcome it already has. Nothing is ever * re-run here. */ export declare function runFastPump(o: { fastId: string; post: (body: Record) => Promise; exec: (cmd: FastCommand) => Promise; isCancelled: () => boolean; log?: (msg: string) => void; /** Consecutive failed polls before giving up (the server's own command * deadline then reports the step as unknown). */ maxFailures?: number; sleep?: (ms: number) => Promise; }): Promise; export declare function postServerJson(serverBase: string, path: string, authHeader: string, body: Record, timeoutMs: number): Promise<{ status: number; json: Record; }>;