import type { Browser } from "@opencode-ai/schema/browser" /** Connection details for the attachment's private authenticated proxy. */ export interface BrowserProxy { readonly url: string readonly host: string readonly port: number readonly credentials: { readonly username: string readonly password: string } readonly certificateFingerprint: string } export interface BrowserDriverContext { readonly proxy: BrowserProxy readonly signal: AbortSignal } export interface BrowserDriverInstance { readonly resource: Resource readonly state: () => Browser.State readonly subscribe: (listener: (state: Browser.State) => void) => () => void readonly execute: (command: Browser.Command, options: { readonly signal: AbortSignal }) => Promise readonly dispose: () => Promise | void } export type BrowserDriverFactory = ( context: BrowserDriverContext, ) => Promise> | BrowserDriverInstance /** Error returned to the server when a browser adapter cannot execute a command. */ export class BrowserDriverError extends Error { override readonly name = "BrowserDriverError" constructor( readonly code: Browser.ErrorCode, message: string, options?: ErrorOptions, ) { super(message, options) } } /** Structural adapter descriptor, represented by its factory function. */ export type BrowserDriver = BrowserDriverFactory export const BrowserDriver = { define(create: BrowserDriverFactory): BrowserDriver { if (typeof create !== "function") throw new TypeError("Browser driver factory must be a function") return Object.freeze(create) }, } export function browserDriverFactory(driver: BrowserDriver) { if (typeof driver !== "function") throw new TypeError("Browser driver must be a factory function") return driver }