import { BrowserSession, InteractionControllerBinding, type BrowserSessionCapabilities as BrowserSessionCapabilitiesValue, type BrowserRevisionMaterialization as BrowserRevisionMaterializationValue, type BrowserSessionListResponse as BrowserSessionListResponseValue, type BrowserSessionMutationResponse as BrowserSessionMutationResponseValue, type InteractionError as InteractionErrorValue, type InteractionLifecycleOperationKind, type InteractionLifecycleOperationReceipt as InteractionLifecycleOperationReceiptValue, type InteractionPlacement, type NetworkRouteConfiguration as NetworkRouteConfigurationValue, type NetworkRouteConsistency as NetworkRouteConsistencyValue } from "@opengeni/contracts"; import { type Database } from "./database.js"; import { type BrowserStateArtifactCommitInput } from "./browser-state-artifacts.js"; import * as schema from "./schema.js"; import { type BrowserDeadlineCheckpointTarget } from "./browser-deadline-checkpoints.js"; type BrowserSessionRow = typeof schema.browserSessions.$inferSelect; type InteractionOperationRow = typeof schema.interactionOperations.$inferSelect; export declare const MANAGED_BROWSER_SESSION_CAPABILITIES: { semanticObservation: boolean; screenshots: boolean; liveFrames: boolean; humanInput: boolean; tabs: boolean; downloads: boolean; uploads: boolean; clipboard: boolean; permissions: boolean; diagnostics: boolean; rawCdp: boolean; linkedComputer: boolean; privateCheckpoint: boolean; identityPublication: boolean; parallelTargets: boolean; }; export declare const EPHEMERAL_BROWSER_SESSION_CAPABILITIES: { semanticObservation: boolean; screenshots: boolean; liveFrames: boolean; humanInput: boolean; tabs: boolean; downloads: boolean; uploads: boolean; clipboard: boolean; permissions: boolean; diagnostics: boolean; rawCdp: boolean; linkedComputer: boolean; privateCheckpoint: boolean; identityPublication: boolean; parallelTargets: boolean; }; export declare const ATTACHED_BROWSER_SESSION_CAPABILITIES: { semanticObservation: boolean; screenshots: boolean; liveFrames: boolean; humanInput: boolean; tabs: boolean; downloads: boolean; uploads: boolean; clipboard: boolean; permissions: boolean; diagnostics: boolean; rawCdp: boolean; linkedComputer: boolean; privateCheckpoint: boolean; identityPublication: boolean; parallelTargets: boolean; }; /** Remote Chromium controlled through the same native CDP driver. Files and * portable profile state remain false because their bytes live on another host. */ export declare const EXTERNAL_BROWSER_SESSION_CAPABILITIES: { semanticObservation: boolean; screenshots: boolean; liveFrames: boolean; humanInput: boolean; tabs: boolean; downloads: boolean; uploads: boolean; clipboard: boolean; permissions: boolean; diagnostics: boolean; rawCdp: boolean; linkedComputer: boolean; privateCheckpoint: boolean; identityPublication: boolean; parallelTargets: boolean; }; /** Measured against Lightpanda 0.3.5. Unsupported Chromium-only affordances * remain false instead of being emulated or silently routed elsewhere. */ export declare const LIGHTPANDA_BROWSER_SESSION_CAPABILITIES: { semanticObservation: boolean; screenshots: boolean; liveFrames: boolean; humanInput: boolean; tabs: boolean; downloads: boolean; uploads: boolean; clipboard: boolean; permissions: boolean; diagnostics: boolean; rawCdp: boolean; linkedComputer: boolean; privateCheckpoint: boolean; identityPublication: boolean; parallelTargets: boolean; }; export declare class BrowserSessionNotFoundError extends Error { readonly name = "BrowserSessionNotFoundError"; } export declare class BrowserSessionOperationConflictError extends Error { readonly name = "BrowserSessionOperationConflictError"; } export declare class BrowserSessionStateError extends Error { readonly name = "BrowserSessionStateError"; } /** A capacity save's candidate no longer qualifies; nothing was written. */ export declare class BrowserCapacitySuspendClaimRejectedError extends Error { readonly name = "BrowserCapacitySuspendClaimRejectedError"; } export type PrepareBrowserSessionCreateInput = { accountId: string; workspaceId: string; operationId: string; associatedSessionId: string; actorSubjectId: string; name: string; initialUrl: string | null; placement: InteractionPlacement; driverId: string; engine: BrowserSessionRow["engine"]; headless: boolean; identityId: string | null; baseRevisionId: string | null; networkRouteId?: string | null; linkedComputerSessionId?: string | null; resolveDefaultRevision?: boolean; capabilities?: BrowserSessionCapabilitiesValue; /** Workspace storing an attached-device placement's Chrome profile, where * its machine is enrolled. Defaults to this workspace. */ attachedDeviceWorkspaceId?: string | null; }; export type PrepareBrowserSessionEndInput = { accountId: string; workspaceId: string; browserSessionId: string; operationId: string; actorSubjectId: string; expectedLifecycle?: BrowserSessionRow["lifecycle"]; expectedControllerGeneration?: string | null; expectedFailureCode?: string | null; }; export type PrepareBrowserSessionLifecycleInput = Omit; /** * What a capacity save claims: the browser it picked as idle, exactly as it * was picked. Under the browser's row lock the save goes ahead only while the * browser is still active on that controller, still unused since the cutoff, * and has no operation in flight. */ export type BrowserCapacitySuspendClaim = { idleBefore: Date; placementInstanceId: string; controllerGeneration: string; }; export type BrowserPrivateCheckpointAuthority = { artifactId: string; sourceBrowserSessionId: string; objectKey: string; encryptedDataKey: string; format: string; artifactDigest: string; contentDigest: string; manifestDigest: string; sizeBytes: number; materialization: BrowserRevisionMaterializationValue; /** When this checkpoint was taken. */ createdAt: string; }; /** Internal executor view of one BrowserSession. Plaintext controller * credentials are deliberately absent; callers derive them from this fenced * durable state. */ export type BrowserSessionControlRecord = { session: BrowserSession; tokenGeneration: number; sourceSessionId: string; /** Workspace storing an attached-device placement's Chrome profile, which * can be another workspace than the session's; null otherwise. */ deviceWorkspaceId: string | null; /** Placement hosting browserd. It equals the logical sandbox placement for * managed browsers and remains the source home sandbox for remote browsers. */ controllerHostSandboxGroupId: string | null; createOperationId: string; networkRouteAuthority: BrowserSessionNetworkRouteAuthority | null; operation: null | { operationId: string; kind: InteractionLifecycleOperationKind; state: InteractionOperationRow["state"]; controllerGeneration: string | null; actorSubjectId: string; }; }; export type BrowserSessionNetworkRouteAuthority = { routeId: string; routeVersion: number; credentialVersion: number | null; authorityDigest: string | null; configuration: NetworkRouteConfigurationValue; consistency: NetworkRouteConsistencyValue; }; /** Legacy resources predate permission control; absence must never advertise support. */ export declare function readStoredBrowserCapabilities(value: Record, engine?: string): { semanticObservation: boolean; screenshots: boolean; liveFrames: boolean; humanInput: boolean; tabs: boolean; downloads: boolean; uploads: boolean; clipboard: boolean; permissions: boolean; diagnostics: boolean; rawCdp: boolean; linkedComputer: boolean; privateCheckpoint: boolean; identityPublication: boolean; parallelTargets: boolean; }; export declare function browserSessionCreateRequestDigest(input: PrepareBrowserSessionCreateInput): string; /** * Saveable browsers on one controller, least recently used first, that a full * controller may suspend to make room for a new browser. Only active browsers * with a private checkpoint, bound to this exact placement instance, unused * since `idleBefore` and with no lifecycle operation in flight qualify. */ export declare function listBrowserCapacitySuspendCandidates(db: Database, input: { accountId: string; workspaceId: string; placement: InteractionPlacement; placementInstanceId: string; excludeBrowserSessionId: string; idleBefore: Date; limit: number; }): Promise; export declare function listBrowserSessions(db: Database, input: { accountId: string; workspaceId: string; /** Only sessions with any association to this agent session. */ associatedSessionId?: string; /** Defaults to true (complete history). */ includeTerminal?: boolean; }): Promise; /** Managed browsers that may still have a live browser process on one * Connected Machine: every non-terminal browser except a saved one whose * controller binding was already released (its process is gone). */ export declare function countLiveConnectedMachineBrowsers(db: Database, input: { accountId: string; workspaceId: string; enrollmentId: string; }): Promise; /** The live managed browsers on one Connected Machine (see * countLiveConnectedMachineBrowsers), and how many of them a working session * may be using now: a session associated with the browser (the one that * opened it, or one that attached to it) has a turn underway, or waits for * input within its turn and will continue it. A live browser no such * session holds is open but idle. Counts the machine's browsers in this * workspace only. */ export declare function connectedMachineBrowserUse(db: Database, input: { accountId: string; workspaceId: string; enrollmentId: string; }): Promise<{ live: number; inUse: number; }>; export declare function getBrowserSession(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; }): Promise<{ id: string; accountId: string; workspaceId: string; name: string; lifecycle: "active" | "ended" | "ending" | "failed" | "lost" | "repair_required" | "restoring" | "starting" | "suspended" | "suspending"; placement: { kind: "sandbox_group"; sandboxGroupId: string; } | { kind: "connected_machine"; sandboxId: string; } | { kind: "attached_device"; deviceId: string; } | { kind: "external_provider"; providerId: string; placementId: string; }; controller: { controllerId: string; controllerGeneration: string; placementInstanceId: string; } | null; driverId: string; engine: "chrome" | "chromium" | "external" | "firefox" | "lightpanda" | "webkit"; engineVersion: string | null; headless: boolean; display?: "offscreen" | "window" | undefined; identityId: string | null; baseRevisionId: string | null; networkRouteId: string | null; linkedComputerSessionId: string | null; capabilities: { semanticObservation: boolean; screenshots: boolean; liveFrames: boolean; humanInput: boolean; tabs: boolean; downloads: boolean; uploads: boolean; clipboard: boolean; permissions: boolean; diagnostics: boolean; rawCdp: boolean; linkedComputer: boolean; privateCheckpoint: boolean; identityPublication: boolean; parallelTargets: boolean; }; associations: { sessionId: string; turnId: string | null; attemptId: string | null; relationship: "created" | "observing" | "related" | "using"; actorSubjectId: string; lastUsedAt: string; }[]; createdBySubjectId: string; createdAt: string; lastUsedAt: string; failureCode: string | null; }>; export declare function getBrowserSessionControlRecord(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; operationId?: string; }): Promise; export declare function getBrowserPrivateCheckpointAuthority(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; }): Promise; /** Resolve an idempotency key before inspecting mutable placement. This keeps * a retried create bound to its original BrowserSession even if the source * session's active sandbox pointer has since changed. */ export declare function findBrowserSessionControlRecordByOperation(db: Database, input: { accountId: string; workspaceId: string; operationId: string; }): Promise; export declare function prepareBrowserSessionCreate(db: Database, input: PrepareBrowserSessionCreateInput): Promise; /** * Bind the broker-resolved, secret-free launch authority before controller * dispatch. A prepared operation may refresh this binding while no physical * controller owns it; after dispatch it is immutable and replay-fenced. */ export declare function bindBrowserSessionNetworkRouteAuthority(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; operationId: string; routeVersion: number; credentialVersion: number | null; authorityDigest: string; }): Promise; export declare function dispatchBrowserSessionOperation(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; controllerGeneration: string; controller?: InteractionControllerBinding; stateUpload?: { objectKey: string; cleanupAfter: Date; }; deadlineTarget?: BrowserDeadlineCheckpointTarget; }): Promise; /** Pulse one exact dispatched lifecycle operation while its controller mutation * is still in flight. This is not viewer or resource activity: it exists only * so the global reaper can distinguish a long profile transfer from an API * caller that disappeared after dispatch. */ export declare function touchInteractionOperation(db: Database, input: { accountId: string; workspaceId: string; operationId: string; resourceId: string; controllerGeneration: string; }): Promise; export declare function activateBrowserSession(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; controller: InteractionControllerBinding; engineVersion: string | null; /** How the controller launched this headed browser, when it reports it. */ display?: "window" | "offscreen" | null; }): Promise; export declare function failBrowserSessionOperation(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; state?: "failed" | "outcome_unknown"; onlyIfPreparedCreate?: boolean; error: InteractionErrorValue; }): Promise; export declare function prepareBrowserSessionSuspend(db: Database, input: PrepareBrowserSessionLifecycleInput & { /** Set for a capacity save; see {@link BrowserCapacitySuspendClaim}. A * browser that no longer qualifies, including one already suspended by * another save, is refused with BrowserCapacitySuspendClaimRejectedError. */ capacityClaim?: BrowserCapacitySuspendClaim; }): Promise; /** Restore the active controller when placement fails before a suspend was dispatched. */ export declare function failPreparedBrowserSessionSuspend(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; error: InteractionErrorValue; }): Promise; /** Restore the previous lifecycle when an end fails before controller dispatch. */ export declare function failPreparedBrowserSessionEnd(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; restoreLifecycle: BrowserSessionRow["lifecycle"]; restoreFailureCode: string | null; expectedControllerGeneration: string | null; error: InteractionErrorValue; }): Promise; export declare function prepareBrowserSessionResume(db: Database, input: PrepareBrowserSessionLifecycleInput): Promise; export declare function commitBrowserSessionSuspension(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; controllerGeneration: string; artifact: BrowserStateArtifactCommitInput; deadlineTarget?: BrowserDeadlineCheckpointTarget; }): Promise; export declare function clearSuspendedBrowserSessionController(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; expectedControllerGeneration: string; }): Promise; export type ExpiredBrowserSessionResume = { /** Generation owning the retained working copy. For an expired resume this * is its retained binding, which must be ended before settling. */ controllerGeneration: string | null; /** Whether the browser may be returned to suspended on its durable state * when its working copy cannot be continued. Only an expired resume, whose * durable state is unchanged, may; a browser lost to a controller restart * ran past its checkpoint and stays lost rather than silently reverting. */ settleable: boolean; }; /** A lost browser whose working copy its controller may still hold: an expired * resume, or a browser whose suspension found its controller restarted (see * `retainedWorkingCopyLoss`). Losses of create or end transitions, and * anything with a newer lifecycle operation, are excluded. */ export declare function getExpiredBrowserSessionResume(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; }): Promise; /** Controller authority of an in-flight continuation of an expired resume. * That continuation has no dispatched operation of its own (its operation is * recorded only once the controller adopts the working copy), so its authority * is the expired resume itself: the browser is still lost from that resume and * still bound to the same retained controller generation. */ export declare function touchExpiredBrowserSessionResume(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; controllerGeneration: string; }): Promise; /** Return an expired resume to an ordinary suspended browser once its retained * controller generation was ended. The next resume restores the same durable * state under a fresh controller generation; nothing durable is deleted. */ export declare function settleExpiredBrowserSessionResume(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; expectedControllerGeneration: string | null; }): Promise; /** Continue an expired resume on its retained controller generation after that * controller re-adopted the generation's own working copy. The browser keeps * its record, history and working profile; nothing is restored or discarded. * The new resume operation completes on that generation, and the expired one * stays settled as `outcome_unknown`. */ export declare function continueExpiredBrowserSessionResume(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; operationId: string; actorSubjectId: string; controller: InteractionControllerBinding; /** How the controller relaunched this headed browser, when it reports it. */ display?: "window" | "offscreen" | null; }): Promise; export declare function failBrowserSessionSuspension(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; controllerGeneration: string; state?: "failed" | "outcome_unknown"; missingControllerSession?: boolean; error: InteractionErrorValue; }): Promise; export declare function failBrowserSessionResume(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; controllerGeneration: string; error: InteractionErrorValue; }): Promise; /** Return a browser to suspended when its resume fails before controller * dispatch. Returns null once the operation was dispatched or settled, so the * caller's original error stands and the dispatched path keeps its own * settlement. */ export declare function failBrowserSessionResumePreparation(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; error: InteractionErrorValue; }): Promise; export declare function prepareBrowserSessionEnd(db: Database, input: PrepareBrowserSessionEndInput): Promise; export declare function completeBrowserSessionEnd(db: Database, input: { accountId: string; workspaceId: string; operationId: string; browserSessionId: string; expectedControllerGeneration: string | null; }): Promise; /** Record the display a controller reports after relaunching an active * browser in place (recovery of a lost controller). Only the generation that * relaunched it may write, so a newer generation's value is never overwritten. * Returns whether the stored value changed. */ export declare function recordBrowserSessionDisplay(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; controllerGeneration: string; display: "window" | "offscreen" | null; }): Promise; export declare function touchBrowserSessionController(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; controllerGeneration: string; }): Promise; /** Retire only the exact ephemeral generation proven absent by its authenticated * controller. No profile restore, replacement creation or operation replay. */ export declare function markEphemeralBrowserSessionLost(db: Database, input: { accountId: string; workspaceId: string; browserSessionId: string; controllerGeneration: string; }): Promise; export {};