import { n as browserbaseCredentialSet, t as BrowserbaseCredentials } from "./browserbase.credential-set-Ds-uVVNX.mjs"; import { a as getBrowserbaseContextOperation, c as deleteBrowserbaseContextOperation, d as actOperation, i as getBrowserbaseLiveViewOperation, l as createBrowserbaseSessionOperation, n as observeOperation, o as fetchUrlOperation, r as navigateOperation, s as extractOperation, t as screenshotOperation, u as createBrowserbaseContextOperation } from "./screenshot.operation-CSIOsUYN.mjs"; import { ActResult, Action, BrowserbaseContext, BrowserbaseFetchResult, BrowserbaseLiveView, BrowserbaseSession, ExtractResult, NavigateResult, ObserveResult, ScreenshotResult, actInputSchema, actResultSchema, actionSchema, browserbaseContextSchema, browserbaseFetchResultSchema, browserbaseLiveViewPageSchema, browserbaseLiveViewSchema, browserbaseSessionSchema, extractInputSchema, extractResultSchema, navigateInputSchema, navigateResultSchema, observeInputSchema, observeResultSchema, screenshotInputSchema, screenshotResultSchema } from "./schemas/index.mjs"; import { z } from "zod"; import { Stagehand } from "@browserbasehq/stagehand"; import { Browserbase } from "@browserbasehq/sdk"; import { CredentialsExchangeConnectionConfig } from "@keystrokehq/core/credential-set"; //#region src/utils/client.d.ts declare function createBrowserbaseClient(credentials: BrowserbaseCredentials): Browserbase; //#endregion //#region src/utils/stagehand-runners.d.ts /** * Minimal page interface covering what the runners need. Browserbase's * Stagehand `context.pages()[0]` satisfies this contract; we use a narrow * structural type so we don't drag Playwright's full `Page` into the * public surface. */ interface StagehandPage { goto(url: string, options?: { waitUntil?: string; timeoutMs?: number; }): Promise<{ status(): number | null; } | null>; url(): string; sendCDP?(method: string, params?: object): Promise; } interface StagehandSession { stagehand: Stagehand; sessionId: string; page: StagehandPage; ownsSession: boolean; } //#endregion //#region src/utils/stagehand-client.d.ts interface BrowserbaseSessionOptions { contextId?: string; persist?: boolean; /** Stagehand model selector, e.g. "anthropic/claude-sonnet-4-5" or * "google/gemini-2.5-flash". Defaults to gemini-2.5-flash. The matching * `modelApiKey` MUST be supplied (Stagehand's control plane validates * that we can actually call the model and 400s on init otherwise). */ model?: string; /** API key for the LLM provider implied by `model` — e.g. an Anthropic * key for `anthropic/...` models, a Google key for `google/...` models. * Required when calling Stagehand v3's API; the SDK forwards it to the * control plane on `init` and the control plane uses it for every * subsequent act/extract/observe call. */ modelApiKey?: string; timeout?: number; keepAlive?: boolean; region?: 'us-west-2' | 'us-east-1' | 'eu-central-1' | 'ap-southeast-1'; proxies?: boolean; blockAds?: boolean; solveCaptchas?: boolean; advancedStealth?: boolean; viewport?: { width: number; height: number; }; recordSession?: boolean; domSettleTimeout?: number; selfHeal?: boolean; serverCache?: boolean; } declare function createBrowserbaseSession(credentials: BrowserbaseCredentials, options?: BrowserbaseSessionOptions): Promise; declare function connectToBrowserbaseSession(credentials: BrowserbaseCredentials, sessionId: string, options?: Pick): Promise; declare function getOrCreateBrowserbaseSession(credentials: BrowserbaseCredentials, options?: BrowserbaseSessionOptions & { sessionId?: string; }): Promise; declare function closeStagehandSession(stagehand: Stagehand): Promise; //#endregion //#region src/utils/create-browser-login-exchange.d.ts type AnyZodObject = z.ZodObject; /** * Success probe for a completed browser login. * * `waitForUrl` matches the URL after the submit click; `waitForSelector` * waits for a DOM selector to appear. Both carry an optional per-probe * timeout; absence falls back to {@link BrowserLoginExchangeConfig.timeoutMs}. * * @see {@link BrowserLoginExchangeConfig.successSignal} */ type BrowserLoginSuccessSignal = { readonly waitForUrl: RegExp; readonly timeoutMs?: number; } | { readonly waitForSelector: string; readonly timeoutMs?: number; }; /** * Declarative cookie-extraction target for a successful browser login. * * The preset reads cookies via Chromium DevTools (`Network.getCookies`) * scoped to {@link BrowserLoginCookieTarget.domain} and returns the first * cookie whose name matches {@link BrowserLoginCookieTarget.name}. */ interface BrowserLoginCookieTarget { readonly name: string; readonly domain: string; } /** * Authored configuration for {@link createBrowserLoginExchange}. * * `stored` must declare the cookie slot the preset writes (the returned * record always includes `sessionCookie`, `cookieName`, `cookieDomain`, * and `browserbaseContextId`). `rotate` probes the persistent * Browserbase context; pair this preset with a conservative scheduler * tolerance so session renewal succeeds before the old cookie expires. * * @example * ```ts * createBrowserLoginExchange({ * input: z.object({ username: z.email(), password: z.string().min(1) }), * stored: z.object({ * sessionCookie: z.string(), * cookieName: z.string(), * cookieDomain: z.string(), * browserbaseContextId: z.string(), * }), * loginUrl: 'https://example.com/login', * fields: { * username: 'Type %username% into the email field', * password: 'Type %password% into the password field', * }, * submit: 'Click the Sign in button', * successSignal: { waitForUrl: /\/dashboard/ }, * cookie: { name: 'example_session', domain: 'example.com' }, * resolveBrowserbaseCredentials: async () => getBrowserbaseCreds(), * }); * ``` */ interface BrowserLoginExchangeConfig { readonly input: TInputSchema; readonly stored: TStoredSchema; readonly instructions?: string; readonly loginUrl: string; /** * Stagehand `act` instructions, keyed by input-schema field name. * Each instruction MUST reference its value via `%fieldName%` so * Stagehand substitutes at Chromium level (the LLM only sees the * placeholder, never the secret). */ readonly fields: Record; /** Stagehand `act` instruction to click the submit button. */ readonly submit: string; /** How the preset decides the login succeeded. */ readonly successSignal: BrowserLoginSuccessSignal; /** Which cookie to extract and persist as `sessionCookie`. */ readonly cookie: BrowserLoginCookieTarget; /** * Fetch the platform-owned Browserbase credentials that drive the * Stagehand session. Called once per exchange/rotate invocation. * * @remarks * The preset intentionally defers this to the caller rather than * pulling from the credential runtime directly — explicit authoring * keeps the trust boundary visible and avoids coupling this module to * the resolver. */ readonly resolveBrowserbaseCredentials: () => Promise; /** Optional Stagehand session overrides (model, region, etc.). */ readonly sessionOptions?: BrowserbaseSessionOptions; /** Overall timeout for a single exchange or rotate attempt. */ readonly timeoutMs?: number; /** * URL the rotate probe navigates to when checking session liveness. * A 30x redirect back to {@link loginUrl} signals the session is * dead and the preset returns `'needs-reinput'`. */ readonly rotateProbeUrl?: string; /** * Inject a custom driver for tests. The default driver wires up * Stagehand + Browserbase via {@link createBrowserbaseSession} and * {@link runAct}. * * @remarks * Expose this only for unit testing. Production adopters supply * Browserbase credentials and let the default driver run. */ readonly driver?: BrowserLoginDriver; } /** * Injection point for the preset's Stagehand/browser plumbing. * * The default implementation ({@link defaultBrowserLoginDriver}) uses * Browserbase + Stagehand. Unit tests replace the driver with a stub so * the preset's orchestration (Zod parse, variables substitution, cookie * extraction) can be exercised without launching a real browser. */ interface BrowserLoginDriver { runLogin(params: { readonly credentials: BrowserbaseCredentials; readonly loginUrl: string; readonly fields: Record; readonly fieldValues: Record; readonly submit: string; readonly successSignal: BrowserLoginSuccessSignal; readonly cookie: BrowserLoginCookieTarget; readonly sessionOptions?: BrowserbaseSessionOptions; readonly timeoutMs?: number; }): Promise<{ readonly status: 'ok'; readonly sessionCookie: string; readonly browserbaseContextId: string; } | { readonly status: 'needs-reinput'; readonly message?: string; }>; probeSession(params: { readonly credentials: BrowserbaseCredentials; readonly browserbaseContextId: string; readonly probeUrl: string; readonly loginUrlPattern: RegExp; readonly timeoutMs?: number; }): Promise; } /** * Build a `credentials-exchange` connection config whose `exchange` hook * drives Browserbase + Stagehand to complete a browser login. * * @throws No synchronous throws; runtime errors from the underlying * browser driver bubble up as thrown errors from the `exchange`/`rotate` * hooks, which the server exchange endpoint maps to 5xx responses. * @see {@link BrowserLoginExchangeConfig} * @see Keystroke credentials-exchange runtime (`executeCredentialsExchange`) * * @remarks * Workspace-authored browser-login is out of v1 scope; the preset is * intended for Keystroke-official integrations only. The trust model * assumes the `resolveBrowserbaseCredentials` callback returns * platform-owned credentials, not user-supplied ones. */ declare function createBrowserLoginExchange(config: BrowserLoginExchangeConfig): CredentialsExchangeConnectionConfig; /** * Default browser-login driver backed by Browserbase + Stagehand. * * Tests typically provide their own driver; production adopters let the * default drive a real Browserbase session. Each login call owns a fresh * persistent context so the cookie survives across rotate probes. * * @see createBrowserLoginExchange */ declare const defaultBrowserLoginDriver: BrowserLoginDriver; //#endregion //#region src/utils/stagehand-session-helpers.d.ts declare function withSession(credentials: BrowserbaseCredentials, options: BrowserbaseSessionOptions, fn: (ctx: { page: StagehandPage; stagehand: Stagehand; }) => Promise): Promise; //#endregion export { ActResult, Action, type BrowserLoginCookieTarget, type BrowserLoginDriver, type BrowserLoginExchangeConfig, type BrowserLoginSuccessSignal, BrowserbaseContext, BrowserbaseCredentials, BrowserbaseFetchResult, BrowserbaseLiveView, BrowserbaseSession, type BrowserbaseSessionOptions, ExtractResult, NavigateResult, ObserveResult, ScreenshotResult, type StagehandPage, type StagehandSession, actInputSchema, actOperation, actOperation as actTool, actResultSchema, actionSchema, browserbaseContextSchema, browserbaseCredentialSet, browserbaseFetchResultSchema, browserbaseLiveViewPageSchema, browserbaseLiveViewSchema, browserbaseSessionSchema, closeStagehandSession, connectToBrowserbaseSession, createBrowserLoginExchange, createBrowserbaseClient, createBrowserbaseContextOperation, createBrowserbaseSession, createBrowserbaseSessionOperation, defaultBrowserLoginDriver, deleteBrowserbaseContextOperation, extractInputSchema, extractOperation, extractOperation as extractTool, extractResultSchema, fetchUrlOperation, getBrowserbaseContextOperation, getBrowserbaseLiveViewOperation, getOrCreateBrowserbaseSession, navigateInputSchema, navigateOperation, navigateOperation as navigateTool, navigateResultSchema, observeInputSchema, observeOperation, observeOperation as observeTool, observeResultSchema, screenshotInputSchema, screenshotOperation, screenshotOperation as screenshotTool, screenshotResultSchema, withSession };