effect-browserbase 0.1.0-beta.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +441 -0
- package/dist/Account.d.mts +34 -0
- package/dist/Account.mjs +41 -0
- package/dist/Account.mjs.map +1 -0
- package/dist/Acquisition-WBafHwXH.mjs +280 -0
- package/dist/Acquisition-WBafHwXH.mjs.map +1 -0
- package/dist/Agents.d.mts +156 -0
- package/dist/Agents.mjs +307 -0
- package/dist/Agents.mjs.map +1 -0
- package/dist/Allocation.d.mts +99 -0
- package/dist/Allocation.mjs +29 -0
- package/dist/Allocation.mjs.map +1 -0
- package/dist/Association-CEps4hYP.mjs +10 -0
- package/dist/Association-CEps4hYP.mjs.map +1 -0
- package/dist/Authorization-Ll5f_XNM.mjs +12 -0
- package/dist/Authorization-Ll5f_XNM.mjs.map +1 -0
- package/dist/Bootstrap-BXuzZojd.mjs +194 -0
- package/dist/Bootstrap-BXuzZojd.mjs.map +1 -0
- package/dist/Bootstrap-m7lHgj0D.d.mts +177 -0
- package/dist/Bootstrap.d.mts +2 -0
- package/dist/Bootstrap.mjs +2 -0
- package/dist/Browser-joE4Zgys.mjs +1557 -0
- package/dist/Browser-joE4Zgys.mjs.map +1 -0
- package/dist/Browser.d.mts +195 -0
- package/dist/Browser.mjs +2 -0
- package/dist/BrowserBinding-qbQA6JhH.mjs +2452 -0
- package/dist/BrowserBinding-qbQA6JhH.mjs.map +1 -0
- package/dist/BrowserBinding.d.mts +40 -0
- package/dist/BrowserBinding.mjs +2 -0
- package/dist/BrowserData-LpcAuAub.d.mts +369 -0
- package/dist/BrowserData.d.mts +2 -0
- package/dist/BrowserData.mjs +442 -0
- package/dist/BrowserData.mjs.map +1 -0
- package/dist/Capture-CZJPuD7b.mjs +532 -0
- package/dist/Capture-CZJPuD7b.mjs.map +1 -0
- package/dist/Capture-Dr5MkIJb.d.mts +125 -0
- package/dist/Capture.d.mts +2 -0
- package/dist/Capture.mjs +2 -0
- package/dist/Certificates.d.mts +35 -0
- package/dist/Certificates.mjs +90 -0
- package/dist/Certificates.mjs.map +1 -0
- package/dist/Cleanup-G2YpTCuU.d.mts +24 -0
- package/dist/Cleanup.d.mts +2 -0
- package/dist/Cleanup.mjs +48 -0
- package/dist/Cleanup.mjs.map +1 -0
- package/dist/Client-Ca0zSg1n.d.mts +53 -0
- package/dist/Client-D1_xYM9o.mjs +424 -0
- package/dist/Client-D1_xYM9o.mjs.map +1 -0
- package/dist/Client.d.mts +2 -0
- package/dist/Client.mjs +2 -0
- package/dist/ContextCoordination.d.mts +16 -0
- package/dist/ContextCoordination.mjs +67 -0
- package/dist/ContextCoordination.mjs.map +1 -0
- package/dist/ContextWriter-BrQmoXRg.mjs +187 -0
- package/dist/ContextWriter-BrQmoXRg.mjs.map +1 -0
- package/dist/Contexts.d.mts +32 -0
- package/dist/Contexts.mjs +103 -0
- package/dist/Contexts.mjs.map +1 -0
- package/dist/Deadline-CrViaogr.mjs +13 -0
- package/dist/Deadline-CrViaogr.mjs.map +1 -0
- package/dist/Downloads.d.mts +44 -0
- package/dist/Downloads.mjs +142 -0
- package/dist/Downloads.mjs.map +1 -0
- package/dist/Errors.d.mts +123 -0
- package/dist/Errors.mjs +329 -0
- package/dist/Errors.mjs.map +1 -0
- package/dist/Extensions-ClZbYb1H.mjs +237 -0
- package/dist/Extensions-ClZbYb1H.mjs.map +1 -0
- package/dist/Extensions.d.mts +44 -0
- package/dist/Extensions.mjs +2 -0
- package/dist/Functions.d.mts +227 -0
- package/dist/Functions.mjs +332 -0
- package/dist/Functions.mjs.map +1 -0
- package/dist/Images-DgscEfSf.mjs +127 -0
- package/dist/Images-DgscEfSf.mjs.map +1 -0
- package/dist/Issued-DejqoMYL.mjs +15 -0
- package/dist/Issued-DejqoMYL.mjs.map +1 -0
- package/dist/Launch-BHcAEq05.mjs +111 -0
- package/dist/Launch-BHcAEq05.mjs.map +1 -0
- package/dist/Launch-C8CfaYxb.d.mts +132 -0
- package/dist/Launch.d.mts +2 -0
- package/dist/Launch.mjs +105 -0
- package/dist/Launch.mjs.map +1 -0
- package/dist/PageControl.d.mts +16 -0
- package/dist/PageControl.mjs +36 -0
- package/dist/PageControl.mjs.map +1 -0
- package/dist/PageControlAssociation-DabEg5AR.mjs +10 -0
- package/dist/PageControlAssociation-DabEg5AR.mjs.map +1 -0
- package/dist/PageFetch.d.mts +40 -0
- package/dist/PageFetch.mjs +64 -0
- package/dist/PageFetch.mjs.map +1 -0
- package/dist/Projects.d.mts +39 -0
- package/dist/Projects.mjs +71 -0
- package/dist/Projects.mjs.map +1 -0
- package/dist/Recordings.d.mts +28 -0
- package/dist/Recordings.mjs +131 -0
- package/dist/Recordings.mjs.map +1 -0
- package/dist/References-URDAtapt.d.mts +35 -0
- package/dist/References.d.mts +2 -0
- package/dist/References.mjs +41 -0
- package/dist/References.mjs.map +1 -0
- package/dist/Replays.d.mts +28 -0
- package/dist/Replays.mjs +109 -0
- package/dist/Replays.mjs.map +1 -0
- package/dist/Resource-DBksC4zB.mjs +50 -0
- package/dist/Resource-DBksC4zB.mjs.map +1 -0
- package/dist/Search.d.mts +38 -0
- package/dist/Search.mjs +53 -0
- package/dist/Search.mjs.map +1 -0
- package/dist/SessionData-DRKcKCqw.d.mts +39 -0
- package/dist/SessionData.d.mts +2 -0
- package/dist/SessionData.mjs +55 -0
- package/dist/SessionData.mjs.map +1 -0
- package/dist/Sessions-B8E4kMxo.d.mts +68 -0
- package/dist/Sessions-CtbseWEh.mjs +244 -0
- package/dist/Sessions-CtbseWEh.mjs.map +1 -0
- package/dist/Sessions.d.mts +3 -0
- package/dist/Sessions.mjs +3 -0
- package/dist/TransferPolicy-DQ06i7SZ.mjs +25 -0
- package/dist/TransferPolicy-DQ06i7SZ.mjs.map +1 -0
- package/dist/Transfers-Czv5IZzJ.d.mts +76 -0
- package/dist/Transfers.d.mts +2 -0
- package/dist/Transfers.mjs +101 -0
- package/dist/Transfers.mjs.map +1 -0
- package/dist/Uploads.d.mts +29 -0
- package/dist/Uploads.mjs +107 -0
- package/dist/Uploads.mjs.map +1 -0
- package/dist/Webhooks.d.mts +60 -0
- package/dist/Webhooks.mjs +143 -0
- package/dist/Webhooks.mjs.map +1 -0
- package/dist/WriterFacts-osvYAsIx.d.mts +61 -0
- package/dist/index.d.mts +30 -0
- package/dist/index.mjs +30 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +163 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Browser-joE4Zgys.mjs","names":["Registration.snapshot","Registration.invoke","invoke","Bootstrap.empty"],"sources":["../src/internal/browser/BindingRunner.ts","../src/internal/browser/Bootstrap.ts","../src/internal/browser/Bindings.ts","../src/internal/session/Attachment.ts","../src/internal/browser/Owner.ts","../src/internal/browser/Session.ts","../src/Browser.ts"],"sourcesContent":["import { Effect, Exit, FiberSet, Scope } from \"effect\";\n\nimport type { CallbackFailureMode } from \"./CallbackTasks.ts\";\n\nexport type BindingRejection = \"closed\" | \"capacity\";\n\nexport type BindingAdmission<A, E> =\n | { readonly _tag: \"Rejected\"; readonly reason: BindingRejection }\n | { readonly _tag: \"Accepted\"; readonly result: Promise<Exit.Exit<A, E>> };\n\n/**\n * Scoped host runner for future page-callable bindings. Admission is synchronous and finite:\n * no Fiber exists until a slot has been reserved. The owning Scope interrupts accepted work;\n * consumer failures remain in an Exit on the host and are never page reply material here.\n */\nexport interface BindingRunner<I, A, E> {\n /** Fence new callbacks synchronously; the owning Scope still owns accepted work. */\n readonly close: () => void;\n readonly submit: (input: I, failureMode?: CallbackFailureMode) => BindingAdmission<A, E>;\n}\n\nexport const makeBindingRunner = <I, A, E, R>(\n capacity: number,\n handle: (input: I) => Effect.Effect<A, E, R>,\n onFault: () => void,\n): Effect.Effect<BindingRunner<I, A, E>, never, R | Scope.Scope> => {\n if (!Number.isSafeInteger(capacity) || capacity < 1)\n throw new RangeError(\"Invalid binding callback capacity\");\n\n return Effect.gen(function* () {\n const parent = yield* Scope.Scope;\n // Do not depend on an application's ambient finalizer strategy for callback ordering.\n // One private sequential child owns both FiberSet and the admission fence.\n const runtimeScope = yield* Scope.fork(parent, \"sequential\");\n\n const run = yield* FiberSet.makeRuntimePromise<R, Exit.Exit<A, E>, never>().pipe(\n Scope.provide(runtimeScope),\n );\n\n let accepting = true;\n let faulted = false;\n let inFlight = 0;\n\n const close = () => {\n accepting = false;\n };\n\n const fault = () => {\n if (!accepting || faulted) return;\n faulted = true;\n onFault();\n };\n\n // FiberSet registered its child-scope finalizer first. Sequential reverse registration\n // order therefore closes admission before the set interrupts accepted callbacks.\n yield* Scope.addFinalizer(runtimeScope, Effect.sync(close));\n\n const submit = (\n input: I,\n failureMode: CallbackFailureMode = \"fail-session\",\n ): BindingAdmission<A, E> => {\n if (!accepting || faulted) return { _tag: \"Rejected\", reason: \"closed\" };\n if (inFlight >= capacity) {\n if (failureMode === \"fail-session\") fault();\n\n return { _tag: \"Rejected\", reason: \"capacity\" };\n }\n\n inFlight++;\n // Construct the consumer Effect inside the admitted fiber as well: a consumer callback\n // that throws while producing its Effect is a host defect, not work allowed before admission.\n const execution = run(Effect.exit(Effect.suspend(() => handle(input))));\n\n const result = execution\n .then(\n (exit) => {\n if (failureMode === \"fail-session\" && Exit.isFailure(exit)) fault();\n\n return exit;\n },\n (error) => {\n if (failureMode === \"fail-session\") fault();\n throw error;\n },\n )\n .finally(() => {\n inFlight--;\n });\n\n // A native caller may disappear while the host callback is still settling. Keep the\n // Promise observed without consuming the Exit returned to a caller that is still present.\n void result.catch(() => {});\n\n return { _tag: \"Accepted\", result };\n };\n\n return { close, submit };\n });\n};\n","import type { Plan } from \"../../Bootstrap.ts\";\n\nexport interface ReadinessRequirement {\n readonly step: string;\n readonly expression: string;\n readonly timeoutMillis: number;\n readonly origins?: ReadonlyArray<string>;\n}\n\n/** What the native driver installs: one ordered bundle, its capabilities and its gates. */\nexport interface CompiledBootstrap {\n readonly bundle?: string;\n readonly permissions: ReadonlyArray<{\n readonly origin: string;\n readonly permissions: ReadonlyArray<string>;\n }>;\n readonly readiness: ReadonlyArray<ReadinessRequirement>;\n readonly existingDocuments: \"RequireFreshNavigation\" | \"AcceptAlreadyRunning\";\n}\n\nconst guarded = (content: string, origins: ReadonlyArray<string> | undefined): string =>\n origins === undefined\n ? `(() => {\\n${content}\\n})();`\n : `(() => {\\nconst origins = ${JSON.stringify([...origins])};\\nif (!origins.includes(globalThis.location && globalThis.location.origin)) return;\\n${content}\\n})();`;\n\n/**\n * Dependent steps become one script in declared order: a failing step stops the ones after it\n * rather than letting a later step observe half-initialized state. Origin-excluded steps are\n * skipped inside the document that reports the origin, never by guessing from a navigation URL.\n */\nexport const compileBootstrap = (\n plan: Pick<Plan, \"scripts\" | \"permissions\">,\n): CompiledBootstrap | undefined => {\n if (plan.scripts.length === 0 && plan.permissions.length === 0) return undefined;\n\n const bundle =\n plan.scripts.length === 0\n ? undefined\n : plan.scripts.map((script) => guarded(script.content, script.origins)).join(\"\\n\");\n\n const readiness = plan.scripts.flatMap((script) =>\n script.readiness === undefined\n ? []\n : [\n {\n step: script.id,\n expression: script.readiness.expression,\n timeoutMillis: script.readiness.timeoutMillis,\n ...(script.origins === undefined ? {} : { origins: script.origins }),\n },\n ],\n );\n\n // The most conservative declared policy governs the whole plan: one document is either\n // admitted for dependent work or it is not, and steps cannot disagree about that.\n const existingDocuments = plan.scripts.some(\n (script) => script.readiness?.existingDocuments === \"RequireFreshNavigation\",\n )\n ? \"RequireFreshNavigation\"\n : \"AcceptAlreadyRunning\";\n\n return {\n ...(bundle === undefined ? {} : { bundle }),\n permissions: plan.permissions.map((grant) => ({\n origin: grant.origin,\n permissions: [...grant.permissions],\n })),\n readiness,\n existingDocuments,\n };\n};\n\n/** Duplicate step identity would make registration order and readiness reports ambiguous. */\nexport const duplicateStep = (plan: Pick<Plan, \"scripts\" | \"permissions\" | \"bindings\">): boolean =>\n new Set(plan.scripts.map((script) => script.id)).size !== plan.scripts.length ||\n new Set(plan.permissions.map((grant) => grant.origin)).size !== plan.permissions.length ||\n new Set((plan.bindings ?? []).map((registration) => registration.name)).size !==\n (plan.bindings?.length ?? 0);\n","import { Cause, Deferred, Effect, Exit, Schema, Scope } from \"effect\";\n\nimport * as Bootstrap from \"../../Bootstrap.ts\";\nimport { BrowserError, InitializationError } from \"../../Errors.ts\";\nimport * as Registration from \"./BindingRegistration.ts\";\nimport { makeBindingRunner } from \"./BindingRunner.ts\";\nimport { duplicateStep } from \"./Bootstrap.ts\";\n\nexport interface NativeBindingCall {\n /** Validate native membership, allowed origin and the captured document before returning JSON. */\n readonly read: (signal: AbortSignal) => Promise<string>;\n /** Revalidate the same native caller/document; never substitute a newly selected document. */\n readonly check: (signal: AbortSignal) => Promise<void>;\n /** Idempotently fence retained handles and dispose late arrivals as they become available. */\n readonly dispose: () => Promise<void>;\n}\n\nexport interface NativeBinding {\n readonly name: string;\n readonly origins: ReadonlyArray<string>;\n readonly maxConcurrent: number;\n readonly maxInputBytes: number;\n readonly timeoutMillis: number;\n /** Rejected admission never calls read/check/dispose; the native callback still owns its handles. */\n readonly invoke: (call: NativeBindingCall) => Promise<string>;\n}\n\nexport interface ConnectionBindings {\n readonly bindings: ReadonlyArray<NativeBinding>;\n readonly close: () => void;\n /** Native registration/transport failure supervises the owner, not a single page invocation. */\n readonly reportFailure: (error: InitializationError) => void;\n /** Drain scoped Effect fibers. Late native promises remain observed and occupy capacity. */\n readonly dispose: Effect.Effect<void>;\n}\n\nexport interface Bindings<E> {\n readonly failure: Effect.Effect<never, E | InitializationError>;\n readonly diagnostics: Effect.Effect<Bootstrap.BindingDiagnostics<E>>;\n readonly connect: (\n onFault: () => void,\n isActive: () => boolean,\n isCurrent?: () => boolean,\n ) => Effect.Effect<ConnectionBindings, never, Scope.Scope>;\n}\n\nconst invalidPlan = () =>\n BrowserError.make({ operation: \"configure\", reason: \"configuration\", outcome: \"undispatched\" });\n\nconst AdmissionPlan = Schema.Struct({\n ...Bootstrap.Plan.fields,\n bindings: Schema.optionalKey(Schema.Array(Schema.Unknown).check(Schema.isMaxLength(16))),\n});\n\n/** Validate before allocation and retain an immutable snapshot, including authenticated callbacks. */\nexport const preparePlan = Effect.fnUntraced(function* <E, R>(\n plan: Bootstrap.Plan<E, R>,\n): Effect.fn.Return<Bootstrap.Plan<E, R>, BrowserError> {\n const source = yield* Effect.try({\n try: () => ({ ...plan }),\n catch: invalidPlan,\n });\n\n const data = yield* Schema.decodeEffect(AdmissionPlan, { onExcessProperty: \"error\" })(\n source,\n ).pipe(Effect.mapError(invalidPlan));\n\n if (duplicateStep({ scripts: data.scripts, permissions: data.permissions }))\n return yield* invalidPlan();\n const candidates = source.bindings === undefined ? [] : source.bindings;\n\n const bindings = yield* Effect.forEach([...candidates], (registration) =>\n Registration.snapshot(registration),\n );\n\n if (new Set(bindings.map((registration) => registration.name)).size !== bindings.length) {\n return yield* invalidPlan();\n }\n\n return Object.freeze({\n scripts: Object.freeze(\n data.scripts.map((script) =>\n Object.freeze({\n ...script,\n ...(script.origins === undefined ? {} : { origins: Object.freeze([...script.origins]) }),\n ...(script.readiness === undefined\n ? {}\n : { readiness: Object.freeze({ ...script.readiness }) }),\n }),\n ),\n ),\n permissions: Object.freeze(\n data.permissions.map((grant) =>\n Object.freeze({\n ...grant,\n permissions: Object.freeze([...grant.permissions]),\n }),\n ),\n ),\n ...(bindings.length === 0 ? {} : { bindings: Object.freeze(bindings) }),\n });\n});\n\nconst rejected = (): Promise<never> => {\n const error = new Error(\"Browser binding call rejected\");\n\n error.name = \"BrowserbaseBindingError\";\n error.stack = \"\";\n const result = Promise.reject(error);\n\n void result.catch(() => {});\n\n return result;\n};\n\nconst increment = (value: number) => Math.min(Number.MAX_SAFE_INTEGER, value + 1);\n\n/** The caller must pass preparePlan's snapshot; dependencies are captured at acquisition. */\nexport const makeBindings = Effect.fnUntraced(function* <E, R>(\n plan: Bootstrap.Plan<E, R>,\n): Effect.fn.Return<Bindings<E>, never, Exclude<R, Scope.Scope> | Scope.Scope> {\n // Effect.scoped installs a fresh invocation Scope inside this captured context. A consumer\n // handler never receives the acquisition Scope even when the actual context contains it.\n const consumer = yield* Effect.context<Exclude<R, Scope.Scope>>();\n const ownerScope = yield* Scope.fork(yield* Scope.Scope, \"sequential\");\n const failure = yield* Deferred.make<never, E | InitializationError>();\n const connections = new Set<ConnectionBindings>();\n const failures: Array<Bootstrap.BindingFailure<E>> = [];\n let droppedFailures = 0;\n let faulted = false;\n let ownerClosed = false;\n\n const entries = (plan.bindings ?? []).map((registration) => ({\n registration,\n state: {\n name: registration.name,\n inFlight: 0,\n pendingNative: 0,\n retired: 0,\n accepted: 0,\n succeeded: 0,\n rejected: 0,\n },\n }));\n\n yield* Scope.addFinalizer(\n ownerScope,\n Effect.suspend(() => {\n ownerClosed = true;\n const owned = [...connections];\n\n for (const connection of owned) connection.close();\n\n return Effect.forEach(owned, (connection) => connection.dispose, { discard: true });\n }),\n );\n\n const connect = Effect.fnUntraced(function* (\n onFault: () => void,\n isActive: () => boolean,\n isCurrent: () => boolean = isActive,\n ): Effect.fn.Return<ConnectionBindings, never, Scope.Scope> {\n const connectionScope = yield* Scope.fork(yield* Scope.Scope, \"sequential\");\n let closed = ownerClosed || faulted;\n const fences: Array<() => void> = [];\n const current = () => !closed && !ownerClosed && !faulted && isCurrent();\n const active = () => current() && isActive();\n\n const close = () => {\n closed = true;\n for (const fence of fences) fence();\n };\n\n const record = (\n registration: Pick<Registration.Registration<E, R>, \"name\" | \"failureMode\">,\n cause: Cause.Cause<E | InitializationError>,\n ) => {\n if (failures.length === 32) {\n failures.shift();\n droppedFailures = increment(droppedFailures);\n }\n failures.push(\n Object.freeze({ name: registration.name, mode: registration.failureMode, cause }),\n );\n if (registration.failureMode === \"fail-session\" && current()) {\n faulted = true;\n // The host can observe the original typed cause as soon as its owner is fenced.\n Deferred.doneUnsafe(failure, Effect.failCause(cause));\n for (const connection of connections) connection.close();\n onFault();\n }\n };\n\n const bindings = yield* Effect.forEach(entries, ({ registration, state }) =>\n Effect.gen(function* () {\n const error = (\n reason: InitializationError[\"reason\"],\n operation: InitializationError[\"operation\"] = \"callback\",\n ) => InitializationError.make({ operation, step: registration.name, reason });\n\n interface Work {\n readonly call: NativeBindingCall;\n pending: number;\n finished: boolean;\n released: boolean;\n }\n\n const release = (work: Work) => {\n if (!work.finished || work.pending !== 0 || work.released) return;\n work.released = true;\n state.inFlight--;\n state.retired--;\n };\n\n const track = <A>(work: Work, promise: Promise<A>): Promise<A> => {\n work.pending++;\n state.pendingNative++;\n\n const settled = () => {\n work.pending--;\n state.pendingNative--;\n release(work);\n };\n\n void promise.then(settled, settled);\n\n return promise;\n };\n\n const finish = (work: Work) => {\n if (work.finished) return;\n work.finished = true;\n state.retired++;\n\n // Disposal may complete before an abort-ignoring read. Both remain accounted for.\n const disposing = Promise.resolve()\n .then(() => work.call.dispose())\n .catch(() => {\n record(registration, Cause.fail(error(\"native\", \"dispose\")));\n });\n\n track(work, disposing);\n };\n\n const native = <A>(work: Work, action: (signal: AbortSignal) => Promise<A>) =>\n Effect.tryPromise({\n try: (signal) => track(work, action(signal)),\n catch: (cause) =>\n Schema.is(InitializationError)(cause) ? error(cause.reason) : error(\"native\"),\n });\n\n const execute = Effect.fnUntraced(function* (work: Work) {\n const check = Effect.suspend(() =>\n active() ? native(work, work.call.check) : Effect.fail(error(\"closed\")),\n );\n\n if (!active()) return yield* error(\"closed\");\n const text = yield* native(work, work.call.read);\n const result = yield* Registration.invoke(registration, text, check);\n\n yield* check;\n\n return result;\n });\n\n const runner = yield* makeBindingRunner(\n registration.maxConcurrent,\n (work: Work) =>\n Effect.scoped(execute(work)).pipe(\n Effect.timeoutOrElse({\n duration: registration.timeoutMillis,\n orElse: () => Effect.fail(error(\"timeout\")),\n }),\n Effect.provideContext(consumer),\n ),\n () => {},\n ).pipe(Scope.provide(connectionScope));\n\n fences.push(runner.close);\n\n const invoke = (call: NativeBindingCall): Promise<string> => {\n if (!active()) {\n state.rejected = increment(state.rejected);\n\n return rejected();\n }\n if (state.inFlight >= registration.maxConcurrent) {\n state.rejected = increment(state.rejected);\n record(registration, Cause.fail(error(\"busy\")));\n\n return rejected();\n }\n // This reservation also covers codec work, native validation and late native disposal.\n // It is shared across connections, so reconnect cannot reset quarantined capacity.\n state.inFlight++;\n state.accepted = increment(state.accepted);\n const work: Work = { call, pending: 0, finished: false, released: false };\n const admission = runner.submit(work, \"reject-call\");\n\n if (admission._tag === \"Rejected\") {\n state.rejected = increment(state.rejected);\n finish(work);\n\n return rejected();\n }\n\n const result = admission.result\n .then(\n (exit) => {\n if (Exit.isFailure(exit)) {\n state.rejected = increment(state.rejected);\n record(registration, exit.cause);\n\n return rejected();\n }\n if (!active()) {\n state.rejected = increment(state.rejected);\n\n return rejected();\n }\n state.succeeded = increment(state.succeeded);\n\n return exit.value;\n },\n () => {\n state.rejected = increment(state.rejected);\n if (active()) record(registration, Cause.fail(error(\"native\")));\n\n return rejected();\n },\n )\n .finally(() => finish(work));\n\n void result.catch(() => {});\n\n return result;\n };\n\n return Object.freeze({\n name: registration.name,\n origins: registration.origins,\n maxConcurrent: registration.maxConcurrent,\n maxInputBytes: registration.maxInputBytes,\n timeoutMillis: registration.timeoutMillis,\n invoke,\n });\n }),\n );\n\n const connection: ConnectionBindings = {\n bindings: Object.freeze(bindings),\n close,\n reportFailure: (error) => {\n if (!current()) return;\n record({ name: error.step, failureMode: \"fail-session\" }, Cause.fail(error));\n },\n dispose: Effect.sync(close).pipe(Effect.andThen(Scope.close(connectionScope, Exit.void))),\n };\n\n connections.add(connection);\n yield* Scope.addFinalizer(\n connectionScope,\n Effect.sync(() => {\n close();\n connections.delete(connection);\n }),\n );\n\n return connection;\n }, Effect.uninterruptible);\n\n return {\n failure: Deferred.await(failure),\n diagnostics: Effect.sync(() =>\n Object.freeze({\n faulted,\n bindings: Object.freeze(entries.map(({ state }) => Object.freeze({ ...state }))),\n failures: Object.freeze([...failures]),\n droppedFailures,\n }),\n ),\n connect,\n };\n});\n","import { Effect, Exit, Option, Scope } from \"effect\";\n\nimport type { CleanupResult } from \"../../Cleanup.ts\";\nimport { BrowserbaseClient } from \"../../Client.ts\";\nimport { SessionError } from \"../../Errors.ts\";\nimport type { SessionReference } from \"../../References.ts\";\nimport { isTerminalSessionStatus } from \"../../SessionData.ts\";\nimport { BrowserbaseSessions } from \"../../Sessions.ts\";\nimport { connectionAddress } from \"../provider/Connection.ts\";\nimport {\n makeCleanup,\n noLocalConnection,\n reported,\n type CleanupLimits,\n type LocalCleanup,\n} from \"./Cleanup.ts\";\nimport { reportCleanup } from \"./Diagnostics.ts\";\n\nexport interface AttachmentOptions {\n readonly reference: SessionReference;\n /** Bounded admission of a session the provider has not finished starting. */\n readonly pendingWaitMillis?: number;\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n}\n\nconst failure = (reason: SessionError[\"reason\"]) =>\n SessionError.make({ operation: \"session-attach\", reason, outcome: \"undispatched\" });\n\n/**\n * Borrowing an already running session. This scope owns its local connection and nothing\n * else: no allocation attempt is made, no release is requested, and no Context-writer\n * authority is claimed. Whoever allocated the session keeps all three.\n */\nexport const attachRemote = Effect.fnUntraced(function* (\n options: AttachmentOptions,\n local: LocalCleanup = noLocalConnection,\n limits?: CleanupLimits,\n) {\n const client = yield* BrowserbaseClient;\n const sessions = yield* BrowserbaseSessions;\n const parent = yield* Scope.Scope;\n const pendingWaitMillis = options.pendingWaitMillis ?? 0;\n\n if (\n !Number.isSafeInteger(pendingWaitMillis) ||\n pendingWaitMillis < 0 ||\n pendingWaitMillis > 600_000\n )\n return yield* failure(\"configuration\");\n\n // The status read validates project authority before anything is borrowed. A terminal\n // session needs a fresh allocation from durable state, never a reattachment.\n const observed = yield* sessions.retrieve(options.reference);\n\n if (isTerminalSessionStatus(observed.status)) return yield* failure(\"expired\");\n if (observed.status !== \"RUNNING\") {\n if (pendingWaitMillis === 0) return yield* failure(\"active\");\n yield* sessions.waitUntilRunning(observed.reference, { timeoutMillis: pendingWaitMillis });\n }\n const reference = observed.reference;\n\n return yield* Effect.uninterruptible(\n Effect.gen(function* () {\n const resourceScope = yield* Scope.make();\n let closing = false;\n let cleanup: CleanupResult | undefined;\n\n const terminate = yield* Effect.cached(\n Effect.uninterruptible(\n Effect.gen(function* () {\n closing = true;\n\n const coordinator = yield* makeCleanup(\n reference,\n \"borrowed\",\n sessions,\n local,\n (result) => {\n cleanup = result;\n },\n limits,\n );\n\n yield* coordinator.close;\n if (cleanup !== undefined) yield* reportCleanup(cleanup);\n if (cleanup !== undefined && options.onCleanup !== undefined)\n yield* reported(options.onCleanup(cleanup));\n }),\n ),\n );\n\n const closeScope = yield* Effect.cached(Scope.close(resourceScope, Exit.void));\n\n // Teardown is registered before the first connection, exactly as an owned scope does.\n yield* Scope.addFinalizer(resourceScope, terminate);\n yield* Scope.addFinalizer(parent, closeScope);\n\n return {\n reference,\n status: observed,\n connection: (timeoutMillis: number) =>\n Effect.suspend(() =>\n closing\n ? Effect.fail(\n SessionError.make({\n operation: \"session-connect\",\n reason: \"expired\",\n outcome: \"undispatched\",\n }),\n )\n : // Credentials are fetched fresh: an expiry can race the caller's own read.\n connectionAddress(client, sessions, reference, timeoutMillis),\n ),\n release: closeScope.pipe(\n Effect.andThen(\n Effect.suspend(() =>\n cleanup === undefined\n ? Effect.die(new Error(\"Borrowed session closed without cleanup evidence\"))\n : Effect.succeed(cleanup),\n ),\n ),\n ),\n cleanupResult: Effect.sync(() => Option.fromNullishOr(cleanup)),\n };\n }),\n );\n});\n","import { Clock, Effect, Schema, Semaphore } from \"effect\";\n\nimport { BrowserError, type BrowserOperation } from \"../../Errors.ts\";\nimport { deadlineAfter, nowMillis, until } from \"../Deadline.ts\";\nimport { publicError } from \"./NativeCalls.ts\";\n\n/** The browser domain's bounded step: one deadline, one declared BrowserError timeout. */\nexport const within = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n deadline: number,\n operation: BrowserOperation,\n onTimeout?: () => void,\n): Effect.Effect<A, E | BrowserError, R> =>\n until(effect, deadline, () => {\n onTimeout?.();\n\n return BrowserError.make({ operation, reason: \"timeout\" });\n });\n\nexport type Phase =\n | \"acquiring\"\n | \"open\"\n | \"paused\"\n | \"detached\"\n | \"uncertain\"\n | \"closing\"\n | \"closed\";\n\nexport type Invalidation =\n | \"observation\"\n | \"target-changed\"\n | \"resized\"\n | \"paused\"\n | \"disconnected\"\n | \"uncertain\"\n | \"closed\";\n\n/** One admitted native operation; checks at dispatch also fence late Promise continuations. */\nexport interface Ticket {\n readonly signal: AbortSignal;\n readonly deadline: number;\n readonly generation: number;\n readonly dispatched: boolean;\n readonly remainingMillis: () => number;\n check(): void;\n dispatch(): void;\n}\n\n/**\n * A dispatched mutation the browser is still performing after its permit was released: an\n * in-flight navigation. It keeps other mutations off that page while reads, holds and other\n * pages proceed. Like a permit it cannot be dropped silently: only a known outcome releases it.\n */\nexport interface Reservation {\n /** Aborted by any fence, so work that outlives its connection is never treated as current. */\n readonly signal: AbortSignal;\n /** `unknown` fences the owner, exactly as a mutation interrupted after dispatch does. */\n readonly settle: (outcome: \"known\" | \"unknown\") => void;\n}\n\nexport interface Limits {\n readonly maxActions: number;\n readonly maxElapsedMillis: number;\n readonly actionTimeoutMillis: number;\n}\n\nexport const makeOwner = Effect.fnUntraced(function* (limits: Limits) {\n const semaphore = yield* Semaphore.make(1);\n const clock = yield* Clock.Clock;\n const lifetimeDeadline = yield* deadlineAfter(limits.maxElapsedMillis);\n const hooks = new Set<(reason: Invalidation) => void>();\n\n const state = {\n phase: \"acquiring\" as Phase,\n generation: 0,\n revision: 0,\n selection: 0,\n actions: 0,\n };\n\n let active: AbortController | undefined;\n const reservations = new Map<string, AbortController>();\n\n const invalidate = (reason: Invalidation) => {\n state.revision++;\n for (const hook of hooks) hook(reason);\n };\n\n const fence = (phase: Phase, reason: Invalidation) => {\n if (\n state.phase === \"closed\" ||\n (state.phase === \"closing\" && phase !== \"closed\" && phase !== \"closing\")\n )\n return;\n state.phase = phase;\n state.generation++;\n active?.abort();\n for (const reservation of reservations.values()) reservation.abort();\n reservations.clear();\n invalidate(reason);\n };\n\n /** Taken under the permit that dispatched the work, so nothing can interleave before it. */\n const reserve = (key: string): Reservation => {\n // Outlives the fiber that dispatched it, and must be abortable by a fence from outside it.\n const controller = new AbortController();\n\n reservations.set(key, controller);\n\n return {\n signal: controller.signal,\n settle: (outcome) => {\n // A fence already cleared it, and decided the outcome for everything it aborted.\n if (reservations.get(key) !== controller) return;\n reservations.delete(key);\n if (outcome === \"unknown\") fence(\"uncertain\", \"uncertain\");\n },\n };\n };\n\n const guard = <A, E, R>(\n operation: BrowserOperation,\n body: (ticket: Ticket) => Effect.Effect<A, E, R>,\n options: {\n readonly charge?: boolean;\n readonly mutation?: boolean;\n readonly phases?: ReadonlyArray<Phase>;\n readonly verifyAfter?: boolean;\n readonly preflight?: Effect.Effect<void, BrowserError>;\n } = {},\n ): Effect.Effect<A, E | BrowserError, R> =>\n semaphore\n .withPermitsIfAvailable(1)(\n Effect.gen(function* () {\n if (!(options.phases ?? [\"open\"]).includes(state.phase)) {\n return yield* BrowserError.make({\n operation,\n reason: state.phase === \"paused\" ? \"busy\" : \"closed\",\n outcome: \"undispatched\",\n });\n }\n yield* options.preflight ?? Effect.void;\n const now = yield* nowMillis;\n\n if (now >= lifetimeDeadline) {\n fence(\"uncertain\", \"uncertain\");\n\n return yield* BrowserError.make({\n operation,\n reason: \"timeout\",\n outcome: \"undispatched\",\n });\n }\n if (options.charge !== false) {\n if (state.actions >= limits.maxActions)\n return yield* BrowserError.make({\n operation,\n reason: \"limit\",\n outcome: \"undispatched\",\n });\n state.actions++;\n }\n // The lifecycle fence must actively abort admitted native work outside the current fiber.\n // @effect-diagnostics-next-line abortControllerInEffect:off\n const controller = new AbortController();\n\n active = controller;\n let dispatched = false;\n const generation = state.generation;\n const allowed = options.phases ?? [\"open\"];\n\n const check = () => {\n if (\n controller.signal.aborted ||\n state.generation !== generation ||\n !allowed.includes(state.phase)\n ) {\n throw BrowserError.make({\n operation,\n reason: \"stale\",\n outcome: dispatched ? \"unknown\" : \"undispatched\",\n });\n }\n };\n\n const ticket: Ticket = {\n signal: controller.signal,\n deadline: Math.min(now + limits.actionTimeoutMillis, lifetimeDeadline),\n generation,\n remainingMillis: () =>\n Math.max(\n 1,\n Math.min(now + limits.actionTimeoutMillis, lifetimeDeadline) -\n Number(clock.monotonicTimeNanosUnsafe()) / 1_000_000,\n ),\n get dispatched() {\n return dispatched;\n },\n check,\n dispatch() {\n check();\n if (!dispatched && options.mutation) invalidate(\"observation\");\n dispatched = true;\n },\n };\n\n const uncertain = () => {\n controller.abort();\n if (dispatched && state.phase !== \"closing\" && state.phase !== \"closed\")\n fence(\"uncertain\", \"uncertain\");\n };\n\n return yield* within(body(ticket), ticket.deadline, operation, uncertain).pipe(\n Effect.tap((_) =>\n options.verifyAfter === false\n ? Effect.void\n : Effect.try({\n try: check,\n catch: () =>\n BrowserError.make({\n operation,\n reason: \"stale\",\n outcome: dispatched ? \"unknown\" : \"undispatched\",\n }),\n }),\n ),\n Effect.catch((error): Effect.Effect<never, E | BrowserError> => {\n if (dispatched) uncertain();\n // The permit adds dispatch evidence only to browser-operation errors. Typed\n // initialization/consumer failures retain their identity and original family.\n if (!Schema.is(BrowserError)(error)) return Effect.fail(error);\n\n return Effect.fail(\n BrowserError.make({\n operation,\n reason: error.reason,\n outcome: error.outcome ?? (dispatched ? \"unknown\" : \"undispatched\"),\n ...(error.status === undefined ? {} : { status: error.status }),\n ...(error.retryAfterMillis === undefined\n ? {}\n : { retryAfterMillis: error.retryAfterMillis }),\n }),\n );\n }),\n Effect.onInterrupt(() => Effect.sync(uncertain)),\n Effect.ensuring(\n Effect.sync(() => {\n controller.abort();\n if (active === controller) active = undefined;\n }),\n ),\n );\n }),\n )\n .pipe(\n Effect.flatMap(\n Effect.fromOption(() =>\n BrowserError.make({ operation, reason: \"busy\", outcome: \"undispatched\" }),\n ),\n ),\n );\n\n /** Lifecycle transitions are performed while holding guard's permit; close alone preempts it. */\n return {\n state,\n lifetimeDeadline,\n guard,\n reserve,\n reserved: (key: string): boolean => reservations.has(key),\n invalidate,\n fence,\n onInvalidate(hook: (reason: Invalidation) => void): () => void {\n hooks.add(hook);\n\n return () => {\n hooks.delete(hook);\n };\n },\n };\n});\n\nexport type Owner = Effect.Success<ReturnType<typeof makeOwner>>;\n\n/** Without a native answer, whether the step was sent is all the owner knows about it. */\nconst unsettled = (ticket: Ticket): Pick<BrowserError, \"reason\" | \"outcome\"> => ({\n reason: \"provider\",\n outcome: ticket.dispatched ? \"unknown\" : \"undispatched\",\n});\n\n/**\n * The one place a native step becomes a public error: whatever the driver raised, the caller\n * sees the operation it asked for.\n */\nexport const native = <A>(operation: BrowserOperation, ticket: Ticket, body: () => Promise<A>) =>\n Effect.callback<A, BrowserError>((resume) => {\n let done = false;\n\n const cleanup = () => {\n done = true;\n ticket.signal.removeEventListener(\"abort\", abort);\n };\n\n const abort = () => {\n if (done) return;\n cleanup();\n resume(\n Effect.fail(\n BrowserError.make({\n operation,\n reason: \"stale\",\n outcome: ticket.dispatched ? \"unknown\" : \"undispatched\",\n }),\n ),\n );\n };\n\n ticket.signal.addEventListener(\"abort\", abort, { once: true });\n try {\n ticket.check();\n // Observe both branches even after the waiter exits. Cancellation does not undo native work.\n void body().then(\n (value) => {\n if (!done) {\n cleanup();\n resume(Effect.succeed(value));\n }\n },\n (error: unknown) => {\n if (!done) {\n cleanup();\n resume(Effect.fail(publicError(error, operation, unsettled(ticket))));\n }\n },\n );\n } catch (error) {\n cleanup();\n resume(Effect.fail(publicError(error, operation, unsettled(ticket))));\n }\n\n return Effect.sync(cleanup);\n });\n","import { Clock, Deferred, Effect, Exit, type Option, Redacted, Schema, Scope } from \"effect\";\n\nimport { BrowserbaseBrowserBinding } from \"../../BrowserBinding.ts\";\nimport {\n type KeyModifier,\n Observation,\n type ObservedElement,\n type PageInfo,\n type PageSuspension,\n Target,\n type Viewport,\n} from \"../../BrowserData.ts\";\nimport type { CleanupResult } from \"../../Cleanup.ts\";\nimport { BrowserbaseClient } from \"../../Client.ts\";\nimport {\n type AllocationError,\n type ContextError,\n type SessionError,\n BrowserError,\n type BrowserOperation,\n} from \"../../Errors.ts\";\nimport type { LaunchRecipe } from \"../../Launch.ts\";\nimport type { AllocationAttempt, SessionReference } from \"../../References.ts\";\nimport { BrowserbaseSessions } from \"../../Sessions.ts\";\nimport { acquireRemote } from \"../session/Acquisition.ts\";\nimport { attachRemote } from \"../session/Attachment.ts\";\nimport type { LocalCleanup } from \"../session/Cleanup.ts\";\nimport type { ContextWriterPermit } from \"../session/WriterFacts.ts\";\nimport { type CaptureParent } from \"./Association.ts\";\nimport { bindingImplementation } from \"./Binding.ts\";\nimport type { ConnectionBindings } from \"./Bindings.ts\";\nimport type { Driver, DriverEvents, DriverOptions, NativeFileSelection } from \"./Driver.ts\";\nimport { issueLiveView } from \"./LiveView.ts\";\nimport { publicError } from \"./NativeCalls.ts\";\nimport type { AdmissionPolicy } from \"./Observation.ts\";\nimport { makeOwner, native, type Limits, type Ticket } from \"./Owner.ts\";\nimport type { NativeInput, NativePoint } from \"./Pointer.ts\";\n\n/**\n * What this owner needs from the remote session it drives, whether it allocated that session\n * or borrowed one. Release authority lives behind `release`, so a borrowed lease cannot\n * accidentally expose one: the lease decides what closing means.\n */\nexport interface RemoteLease {\n readonly reference: SessionReference;\n readonly attempt?: AllocationAttempt;\n readonly connection: (\n timeoutMillis: number,\n ) => Effect.Effect<Redacted.Redacted<string>, SessionError>;\n readonly release: Effect.Effect<CleanupResult>;\n readonly cleanupResult: Effect.Effect<Option.Option<CleanupResult>>;\n}\n\nexport type RemoteSource<L extends RemoteLease, E> = (\n local: LocalCleanup,\n lifetimeDeadline: number,\n) => Effect.Effect<L, E, BrowserbaseClient | BrowserbaseSessions | Scope.Scope>;\n\n/** Bounds a reading of the selected document. Already validated at the public boundary. */\nexport interface Reading {\n readonly scope: \"document\" | \"viewport\";\n readonly maxTextBytes?: number;\n readonly maxControls?: number;\n}\n\nexport interface SessionOptions<L extends RemoteLease, E> {\n readonly remote: RemoteSource<L, E>;\n /** Only a keep-alive session may detach and reattach inside this owner. */\n readonly keepAlive: boolean;\n readonly driver: DriverOptions;\n readonly maxReturnedBytes: number;\n /** Consumer E/R stays with the typed public supervisor; this installs its captured runtime. */\n readonly connectBindings?: (\n onFault: () => void,\n isActive: () => boolean,\n isCurrent: () => boolean,\n ) => Effect.Effect<ConnectionBindings, never, Scope.Scope>;\n}\n\nexport interface OwnedLease extends RemoteLease {\n readonly attempt: AllocationAttempt;\n}\n\nexport interface OwnedOptions {\n /** The single provider-faithful launch description; the owner adds no second default body. */\n readonly launch: LaunchRecipe;\n /** Required for a persistent context; the writer permit, not this owner, holds that authority. */\n readonly contextWriter?: ContextWriterPermit;\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n readonly onAllocationUncertain?: (attempt: AllocationAttempt) => Effect.Effect<void>;\n}\n\n/** Allocates the session, and therefore owns releasing it. */\nexport const ownedRemote =\n (\n options: OwnedOptions,\n ): RemoteSource<OwnedLease, AllocationError | BrowserError | ContextError> =>\n (local, lifetimeDeadline) =>\n acquireRemote(\n {\n launch: options.launch,\n ...(options.contextWriter === undefined ? {} : { contextWriter: options.contextWriter }),\n allocationDeadline: lifetimeDeadline,\n ...(options.onCleanup === undefined ? {} : { onCleanup: options.onCleanup }),\n ...(options.onAllocationUncertain === undefined\n ? {}\n : { onAllocationUncertain: options.onAllocationUncertain }),\n },\n local,\n );\n\n/** Borrows a running session: local connection only, and never a release request. */\nexport const borrowedRemote =\n (options: {\n readonly reference: SessionReference;\n readonly pendingWaitMillis?: number;\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n }): RemoteSource<RemoteLease, SessionError> =>\n (local) =>\n attachRemote(options, local);\n\n/**\n * The one owned browser. Remote allocation, release and terminal observation belong to the\n * canonical control plane; this owner supplies only the local connection's cleanup evidence.\n */\nexport const acquireSession = Effect.fnUntraced(function* <L extends RemoteLease, E>(\n limits: Limits,\n options: SessionOptions<L, E>,\n) {\n // The engine is resolved before anything is allocated, so an unissued binding costs nothing.\n const engine = bindingImplementation(yield* BrowserbaseBrowserBinding);\n\n if (engine === undefined)\n return yield* BrowserError.make({\n operation: \"connect\",\n reason: \"configuration\",\n outcome: \"undispatched\",\n });\n const client = yield* BrowserbaseClient;\n const sessions = yield* BrowserbaseSessions;\n const parentScope = yield* Scope.Scope;\n // Register the binding lifetime BEFORE the remote cleanup finalizer. On natural Scope\n // shutdown that finalizer must fence the owner before any callback finalizer can reenter it.\n const bindingLifetime = yield* Scope.fork(parentScope, \"sequential\");\n const ended = yield* Deferred.make<void>();\n const owner = yield* makeOwner(limits);\n const clock = yield* Clock.Clock;\n\n let driver: Driver | undefined;\n let connectPending = false;\n // Native listeners can outlive disconnect. Authority belongs to this connection\n // lease, not merely to the current session phase or selected browser target.\n let activeConnection: object | undefined;\n let handoffToken: string | undefined;\n let reconnectTarget: string | undefined;\n let activeBindings: ConnectionBindings | undefined;\n\n const fenceBindings = () => {\n activeBindings?.close();\n driver?.fenceInitialization?.();\n };\n\n const disposeBindings = Effect.gen(function* () {\n const connection = activeBindings;\n\n activeBindings = undefined;\n const callbacks = yield* Effect.exit(connection?.dispose ?? Effect.void);\n\n const registrations = yield* Effect.tryPromise({\n try: () => driver?.disposeInitialization?.() ?? Promise.resolve(),\n catch: () => BrowserError.make({ operation: \"close\", reason: \"provider\" }),\n }).pipe(Effect.exit);\n\n if (Exit.isFailure(callbacks)) return yield* Effect.failCause(callbacks.cause);\n if (Exit.isFailure(registrations)) return yield* Effect.failCause(registrations.cause);\n });\n\n const capture: CaptureParent = {\n owner,\n target: () => {\n if (driver === undefined) throw BrowserError.make({ operation: \"target\", reason: \"closed\" });\n\n return Target.make({ generation: owner.state.generation, ...driver.selected() });\n },\n resolve: (ticket, requested) =>\n native(\"capture-start\", ticket, async () => {\n if (driver === undefined)\n throw BrowserError.make({ operation: \"capture\", reason: \"closed\" });\n const binding = await driver.capture(requested);\n\n return {\n key: binding.targetId,\n target: Target.make({\n generation: owner.state.generation,\n pageId: binding.pageId,\n frameId: binding.frameId,\n }),\n source: binding.source,\n };\n }),\n captureLeases: new Map(),\n captureReservedBytes: 0,\n };\n\n owner.onInvalidate((reason) => {\n driver?.invalidateObservation();\n if ([\"disconnected\", \"uncertain\", \"closed\"].includes(reason)) fenceBindings();\n if ([\"paused\", \"disconnected\", \"uncertain\", \"closed\"].includes(reason))\n for (const lease of capture.captureLeases.values()) lease.invalidate(reason);\n });\n\n /**\n * The local half of cleanup. Each step is an independent fact for the canonical\n * coordinator, which owns the release request and the terminal status observation.\n */\n const local: LocalCleanup = {\n fence: Effect.sync(() => {\n owner.fence(\"closing\", \"closed\");\n handoffToken = undefined;\n activeConnection = undefined;\n }),\n capture: Effect.suspend(() =>\n Effect.forEach([...capture.captureLeases.values()], (lease) => lease.stop, {\n discard: true,\n }),\n ),\n initialization: disposeBindings,\n disconnect: Effect.suspend(() => {\n const acquired = driver;\n\n driver = undefined;\n if (acquired === undefined)\n return Effect.succeed<CleanupResult[\"local\"]>(connectPending ? \"pending\" : \"not-connected\");\n\n return Effect.tryPromise({\n try: () => acquired.disconnect(),\n catch: () => BrowserError.make({ operation: \"disconnect\", reason: \"provider\" }),\n }).pipe(Effect.as<CleanupResult[\"local\"]>(\"closed\"));\n }).pipe(\n Effect.ensuring(\n Effect.sync(() => {\n owner.state.phase = \"closed\";\n }),\n ),\n ),\n };\n\n const acquired = yield* options.remote(local, owner.lifetimeDeadline);\n\n const ref = acquired.reference;\n\n const closeScope = acquired.release.pipe(\n Effect.ensuring(Deferred.succeed(ended, undefined)),\n Effect.asVoid,\n );\n\n const connectionEvents = (connectionLease: object): DriverEvents => ({\n invalidate: (reason) => {\n if (activeConnection === connectionLease) owner.invalidate(reason);\n },\n disconnected: () => {\n if (activeConnection !== connectionLease) return;\n if (\n owner.state.phase !== \"closing\" &&\n owner.state.phase !== \"closed\" &&\n owner.state.phase !== \"detached\"\n ) {\n owner.fence(\"uncertain\", \"disconnected\");\n }\n },\n pause: () => {\n if (activeConnection !== connectionLease) return;\n if (owner.state.phase === \"open\") owner.fence(\"paused\", \"paused\");\n // An unsolicited popup/dialog during setup cannot be silently admitted by\n // the later connect commit. No usable handle has been exposed: fail closed.\n else if (owner.state.phase === \"acquiring\") owner.fence(\"uncertain\", \"uncertain\");\n },\n fault: () => {\n if (activeConnection !== connectionLease) return;\n if (owner.state.phase !== \"closing\" && owner.state.phase !== \"closed\")\n owner.fence(\"uncertain\", \"uncertain\");\n },\n });\n\n const connectNative = (url: Redacted.Redacted<unknown>, nativeOptions: DriverOptions) =>\n Effect.uninterruptibleMask((restore) =>\n Effect.gen(function* () {\n const connectionLease = {};\n\n activeConnection = connectionLease;\n connectPending = true;\n const events = connectionEvents(connectionLease);\n\n const bindings =\n options.connectBindings === undefined\n ? undefined\n : yield* options\n .connectBindings(\n events.fault,\n () =>\n activeConnection === connectionLease &&\n (owner.state.phase === \"acquiring\" || owner.state.phase === \"open\"),\n () =>\n activeConnection === connectionLease &&\n [\"acquiring\", \"open\", \"paused\"].includes(owner.state.phase),\n )\n .pipe(Scope.provide(bindingLifetime));\n\n activeBindings = bindings;\n\n const retired = () =>\n activeConnection !== connectionLease ||\n [\"closing\", \"closed\", \"uncertain\"].includes(owner.state.phase);\n\n if (retired()) {\n bindings?.close();\n yield* bindings?.dispose ?? Effect.void;\n\n return yield* BrowserError.make({ operation: \"connect\", reason: \"closed\" });\n }\n\n const acquired = yield* restore(\n engine.connect({\n connection: Redacted.value(url),\n options: {\n ...nativeOptions,\n ...(bindings === undefined\n ? {}\n : {\n bindings: bindings.bindings,\n onBindingFault: bindings.reportFailure,\n }),\n },\n events,\n onAbandoned: () => bindings?.close(),\n onSettled: () => {\n if (activeConnection === connectionLease) connectPending = false;\n },\n }),\n );\n\n driver = acquired;\n if (\n activeConnection !== connectionLease ||\n owner.state.phase === \"closed\" ||\n owner.state.phase === \"closing\" ||\n owner.state.phase === \"uncertain\"\n ) {\n yield* Effect.tryPromise({\n try: () => acquired.disconnect(),\n catch: () => BrowserError.make({ operation: \"connect\", reason: \"provider\" }),\n }).pipe(Effect.ignore);\n driver = undefined;\n\n return yield* BrowserError.make({ operation: \"connect\", reason: \"closed\" });\n }\n\n return acquired;\n }),\n );\n\n const getDriver = () => {\n if (driver === undefined)\n throw BrowserError.make({\n operation: \"target\",\n reason: \"closed\",\n outcome: \"undispatched\",\n });\n\n return driver;\n };\n\n /**\n * Work that depends on an initialized document waits for the current document's readiness.\n * Navigation, selection and page management deliberately do not: initialization must never\n * deadlock the navigation that produces the document it is waiting for.\n */\n const dependent = [\n \"read-text\",\n \"checkpoint\",\n \"control-facts\",\n \"revalidate\",\n \"click\",\n \"fill\",\n \"scroll\",\n \"pointer-move\",\n \"hover\",\n \"wheel\",\n \"press\",\n \"type\",\n \"screenshot\",\n \"observe\",\n \"wait\",\n \"click-and-wait\",\n \"download-action\",\n \"select-files\",\n \"file-chooser\",\n ];\n\n const requireReady = async (operation: BrowserOperation, ticket: Ticket) => {\n if (!dependent.includes(operation)) return;\n const state = await getDriver().documentReadiness(ticket);\n\n if (state._tag === \"Ready\" || state._tag === \"NotApplicable\") return;\n throw BrowserError.make({\n operation,\n reason:\n state._tag === \"RequiresNavigation\" || state.reason === \"stale\"\n ? \"stale\"\n : state.reason === \"timeout\"\n ? \"timeout\"\n : \"failed\",\n outcome: \"undispatched\",\n });\n };\n\n /**\n * `dependent` is false for lifecycle observations, which report what is actually on the\n * reattached page. Readiness governs work that depends on initialization, not the reading\n * that tells a caller whether this document was initialized at all.\n */\n const observeInside = (\n ticket: Ticket,\n maximumBytes = Math.min(options.maxReturnedBytes, 16384),\n controls = 32,\n dependent = true,\n scope: \"document\" | \"viewport\" = \"document\",\n ) =>\n Effect.suspend(() => {\n const revision = owner.state.revision;\n\n return native(\"observe\", ticket, async () => {\n await getDriver().pageControl?.checkSelected(ticket);\n if (dependent) await requireReady(\"observe\", ticket);\n\n return getDriver().observe(scope, maximumBytes, controls, ticket);\n }).pipe(\n Effect.flatMap((raw) =>\n Effect.gen(function* () {\n if (owner.state.revision !== revision)\n return yield* BrowserError.make({ operation: \"observe\", reason: \"stale\" });\n\n const result = yield* Effect.try({\n try: () => Observation.make({ ...raw, target: capture.target(), revision }),\n catch: (error) => publicError(error, \"observe\", { reason: \"malformed\" }),\n });\n\n const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(Observation))(\n result,\n ).pipe(\n Effect.mapError(() =>\n BrowserError.make({ operation: \"observe\", reason: \"malformed\" }),\n ),\n );\n\n if (new TextEncoder().encode(encoded).length > options.maxReturnedBytes) {\n return yield* BrowserError.make({ operation: \"observe\", reason: \"limit\" });\n }\n\n return result;\n }),\n ),\n );\n });\n\n /** A requested text bound may narrow the policy's bound, never widen it. */\n const textBudget = (\n operation: BrowserOperation,\n requested: number | undefined,\n ): Effect.Effect<number, BrowserError> => {\n const bytes = requested ?? Math.min(options.maxReturnedBytes, 16384);\n\n return bytes > options.maxReturnedBytes\n ? Effect.fail(\n BrowserError.make({ operation, reason: \"configuration\", outcome: \"undispatched\" }),\n )\n : Effect.succeed(bytes);\n };\n\n // Reading a target is an ownership operation too. A native mutation that times out\n // after dispatch fences the owner as uncertain; retaining the last native target\n // must not manufacture a fresh usable handle in that state.\n const readSelected = owner.guard(\n \"target\",\n () =>\n Effect.try({\n try: capture.target,\n catch: () =>\n BrowserError.make({ operation: \"target\", reason: \"closed\", outcome: \"undispatched\" }),\n }),\n { charge: false },\n );\n\n /**\n * While a navigation is in flight on the selected page, nothing else may change that page.\n * Reads, checkpoints, holds and every other page proceed.\n */\n const unreserved = (operation: BrowserOperation) =>\n Effect.suspend(() => {\n let pageId: string | undefined;\n\n try {\n pageId = driver?.selected().pageId;\n } catch {\n // No selected target: the operation itself reports that, with its own reason.\n }\n\n return pageId !== undefined && owner.reserved(pageId)\n ? Effect.fail(BrowserError.make({ operation, reason: \"busy\", outcome: \"undispatched\" }))\n : Effect.void;\n });\n\n const nativeOperation = <A>(\n operation: BrowserOperation,\n action: (driver: Driver, ticket: Ticket) => Promise<A>,\n options: {\n readonly mutation?: boolean;\n readonly charge?: boolean;\n /** Opening or closing a tab is independent of the selected page's document. */\n readonly anyPage?: boolean;\n } = {},\n ) =>\n owner.guard(\n operation,\n (ticket) =>\n native(operation, ticket, async () => {\n // A held page is refused, never woken: none of these may run against one.\n if (\n [\n \"resize\",\n \"wait\",\n \"click-and-wait\",\n \"download-action\",\n \"select-files\",\n \"file-chooser\",\n \"checkpoint\",\n \"control-facts\",\n \"revalidate\",\n ].includes(operation)\n )\n await getDriver().pageControl?.checkSelected(ticket);\n await requireReady(operation, ticket);\n\n return action(getDriver(), ticket);\n }),\n {\n ...options,\n ...(options.mutation === true && options.anyPage !== true\n ? { preflight: unreserved(operation) }\n : {}),\n },\n );\n\n /** A bound handle captures the page selection and connection generation, never the current DOM. */\n const bind = () => {\n const generation = owner.state.generation,\n selection = owner.state.selection;\n\n const check = () => {\n if (owner.state.generation !== generation || owner.state.selection !== selection) {\n return Effect.fail(\n BrowserError.make({ operation: \"handle\", reason: \"stale\", outcome: \"undispatched\" }),\n );\n }\n\n return Effect.void;\n };\n\n const run = <A>(\n operation: BrowserOperation,\n action: (driver: Driver, ticket: Ticket) => Promise<A>,\n mutation = false,\n ) =>\n owner.guard(\n operation,\n (ticket) =>\n native(operation, ticket, async () => {\n await getDriver().pageControl?.checkSelected(ticket);\n await requireReady(operation, ticket);\n\n return action(getDriver(), ticket);\n }),\n {\n mutation,\n preflight: mutation\n ? Effect.suspend(check).pipe(Effect.andThen(unreserved(operation)))\n : Effect.suspend(check),\n },\n );\n\n /**\n * Native input, stamped on the host monotonic clock that stamps captured frames, around\n * the native command alone: admission and readiness are over before the clock is read.\n */\n const input = (\n operation: BrowserOperation,\n action: (driver: Driver, ticket: Ticket) => Promise<NativeInput>,\n ) =>\n run(\n operation,\n async (driver, ticket) => {\n // What the input is sent to, read first: input may replace the document it reaches.\n const target = capture.target();\n const startedMonotonicNanos = clock.monotonicTimeNanosUnsafe();\n const dispatched = await action(driver, ticket);\n\n return {\n ...dispatched,\n target,\n startedMonotonicNanos,\n completedMonotonicNanos: clock.monotonicTimeNanosUnsafe(),\n };\n },\n true,\n );\n\n /**\n * Dispatches under a short permit and leaves the browser loading outside it. The reservation\n * is taken under that same permit, so no other mutation can reach the page in between, and\n * it is released only on a known outcome: an unsettled operation whose scope closes, or a\n * navigation that fails after dispatch, fences the owner exactly as an interrupted mutation\n * always has. Interrupting a waiter on `completed` stops nothing; `stop` is the one way to.\n */\n const startNavigation = Effect.fnUntraced(function* (\n url: string,\n timeoutMillis = limits.actionTimeoutMillis,\n ) {\n const begun = yield* run(\n \"navigate\",\n async (driver, ticket) => {\n const target = capture.target();\n const navigation = await driver.beginNavigation(url, timeoutMillis, ticket);\n\n return { target, navigation, reservation: owner.reserve(navigation.pageId) };\n },\n true,\n );\n\n const { navigation, reservation } = begun;\n const outcome = yield* Deferred.make<string, BrowserError>();\n\n const failed = (reason: BrowserError[\"reason\"]) =>\n Effect.fail(BrowserError.make({ operation: \"navigate\", reason, outcome: \"unknown\" }));\n\n /**\n * A navigation has exactly one outcome, and whoever decides it first settles the\n * reservation. It is released before anyone waiting is told, so the operation a waiter\n * runs next is admitted rather than finding its own page still reserved.\n */\n const decide = (result: Effect.Effect<string, BrowserError>, known: boolean) => {\n if (Deferred.isDoneUnsafe(outcome)) return;\n reservation.settle(known ? \"known\" : \"unknown\");\n Deferred.doneUnsafe(outcome, result);\n };\n\n navigation.settled.then(\n (url) => decide(Effect.succeed(url), true),\n // Failed after dispatch, and nothing says what the browser did: unknown, as it always was.\n (error: unknown) =>\n decide(\n Effect.fail(publicError(error, \"navigate\", { reason: \"provider\", outcome: \"unknown\" })),\n false,\n ),\n );\n // A fence already cleared the reservation; this only releases anyone still waiting.\n reservation.signal.addEventListener(\"abort\", () => decide(failed(\"stale\"), true), {\n once: true,\n });\n // Left unsettled, nothing knows what the browser did with it.\n yield* Effect.addFinalizer(() => Effect.sync(() => decide(failed(\"stale\"), false)));\n\n return {\n target: begun.target,\n completed: Deferred.await(outcome),\n /**\n * The browser's acknowledgement is the known outcome. Playwright's own promise is not\n * waited for: an aborted parse fires no DOMContentLoaded, so it only ever times out.\n */\n stop: Effect.tryPromise({\n try: () => navigation.stop(),\n catch: (error) =>\n publicError(error, \"navigate-stop\", { reason: \"provider\", outcome: \"unknown\" }),\n }).pipe(\n Effect.timeoutOrElse({\n duration: 3000,\n orElse: () =>\n Effect.fail(\n BrowserError.make({\n operation: \"navigate-stop\",\n reason: \"timeout\",\n outcome: \"unknown\",\n }),\n ),\n }),\n Effect.tap(() => Effect.sync(() => decide(failed(\"interrupted\"), true))),\n ),\n };\n });\n\n return {\n startNavigation,\n // The same machinery, scoped to the call: leaving it unsettled fences, as it always has.\n navigate: (url: string) =>\n Effect.scoped(\n startNavigation(url).pipe(Effect.flatMap((operation) => operation.completed)),\n ),\n readText: (selector?: string) =>\n run(\"read-text\", (driver, ticket) =>\n driver.readText(selector, options.maxReturnedBytes, ticket),\n ),\n click: (target: string | ObservedElement, policy?: AdmissionPolicy) =>\n run(\"click\", (driver, ticket) => driver.click(target, ticket, policy), true),\n fill: (target: string | ObservedElement, value: string, policy?: AdmissionPolicy) =>\n run(\"fill\", (driver, ticket) => driver.fill(target, value, ticket, policy), true),\n scroll: (x: number, y: number) =>\n run(\"scroll\", (driver, ticket) => driver.scroll(x, y, ticket), true),\n pointerMove: (to: NativePoint) =>\n input(\"pointer-move\", (driver, ticket) => driver.pointerMove(to, ticket)),\n hover: (target: string | ObservedElement, policy?: AdmissionPolicy) =>\n input(\"hover\", (driver, ticket) => driver.hover(target, ticket, policy)),\n wheel: (deltaX: number, deltaY: number, at?: NativePoint) =>\n input(\"wheel\", (driver, ticket) => driver.wheel(deltaX, deltaY, at, ticket)),\n press: (\n key: string,\n modifiers: ReadonlyArray<KeyModifier>,\n into?: string | ObservedElement,\n policy?: AdmissionPolicy,\n ) => input(\"press\", (driver, ticket) => driver.press(key, modifiers, into, ticket, policy)),\n type: (text: string, into?: string | ObservedElement, policy?: AdmissionPolicy) =>\n input(\"type\", (driver, ticket) => driver.type(text, into, ticket, policy)),\n screenshot: (full: boolean) =>\n run(\"screenshot\", (driver, ticket) =>\n driver.screenshot(full, options.maxReturnedBytes, ticket),\n ),\n };\n };\n\n /**\n * The remaining execution lifetime bounds waiting for a RUNNING session and its endpoint,\n * within the resource service's own maximum wait. A long business budget does not become\n * an invalid provider-wait configuration.\n */\n const remainingMillis = () =>\n Math.min(\n 600_000,\n Math.max(\n 1,\n Math.ceil(owner.lifetimeDeadline - Number(clock.monotonicTimeNanosUnsafe()) / 1_000_000),\n ),\n );\n\n const connectionUrl = (operation: BrowserOperation) =>\n Effect.suspend(() => acquired.connection(remainingMillis())).pipe(\n Effect.mapError((error) => BrowserError.make({ operation, reason: error.reason })),\n );\n\n const connected = yield* Effect.cached(\n owner\n .guard(\n \"connect\",\n (ticket) =>\n connectionUrl(\"connect\").pipe(\n Effect.flatMap((url) => connectNative(url, options.driver)),\n Effect.andThen(\n native(\"connect\", ticket, async () => {\n getDriver().selected();\n }),\n ),\n Effect.tap(() =>\n Effect.sync(() => {\n owner.state.phase = \"open\";\n }),\n ),\n ),\n { phases: [\"acquiring\"], charge: false, verifyAfter: false },\n )\n .pipe(\n Effect.onError(() => closeScope),\n Effect.onInterrupt(() => closeScope),\n ),\n );\n\n const execution = () => {\n const port = getDriver().pageControl;\n\n if (port === undefined)\n throw BrowserError.make({\n operation: \"page-control\",\n reason: \"unsupported\",\n outcome: \"undispatched\",\n });\n\n return port;\n };\n\n const controls = {\n pageControl: {\n state: (page: PageInfo) =>\n nativeOperation(\"page-state\", (_driver, ticket) => execution().state(page, ticket), {\n charge: false,\n }),\n suspend: (page: PageInfo) =>\n nativeOperation(\"page-suspend\", (_driver, ticket) => execution().suspend(page, ticket), {\n charge: false,\n }),\n resume: (receipt: PageSuspension) =>\n nativeOperation(\"page-resume\", (_driver, ticket) => execution().resume(receipt, ticket), {\n charge: false,\n }),\n },\n reference: ref,\n capture,\n bind,\n currentTarget: readSelected,\n cleanupResult: acquired.cleanupResult,\n close: acquired.release.pipe(Effect.ensuring(Deferred.succeed(ended, undefined))),\n observe: (reading: Reading = { scope: \"document\" }) =>\n textBudget(\"observe\", reading.maxTextBytes).pipe(\n Effect.flatMap((bytes) =>\n owner.guard(\"observe\", (ticket) =>\n observeInside(ticket, bytes, reading.maxControls ?? 32, true, reading.scope),\n ),\n ),\n ),\n /**\n * Passive: not a mutation, so the action observation and the selection are left exactly as\n * they were. A held page is refused rather than woken to be read.\n */\n checkpoint: (reading: Omit<Reading, \"scope\"> & { readonly picture: boolean }) =>\n textBudget(\"checkpoint\", reading.maxTextBytes).pipe(\n Effect.flatMap((bytes) =>\n nativeOperation(\"checkpoint\", async (driver, ticket) => {\n const target = capture.target();\n const revision = owner.state.revision;\n const startedMonotonicNanos = clock.monotonicTimeNanosUnsafe();\n\n const sampled = await driver.checkpoint(\n bytes,\n reading.maxControls ?? 32,\n reading.picture ? options.maxReturnedBytes : undefined,\n ticket,\n );\n\n return {\n ...sampled,\n target,\n revision,\n startedMonotonicNanos,\n completedMonotonicNanos: clock.monotonicTimeNanosUnsafe(),\n };\n }),\n ),\n ),\n controlFacts: (reference: ObservedElement) =>\n nativeOperation(\"control-facts\", (driver, ticket) => driver.controlFacts(reference, ticket)),\n /** Not charged: it sends no input and reads one node the caller was already given. */\n revalidate: (reference: ObservedElement) =>\n nativeOperation(\"revalidate\", (driver, ticket) => driver.revalidate(reference, ticket), {\n charge: false,\n }),\n // Inspecting readiness is not an action: it charges nothing and mutates nothing.\n readiness: owner.guard(\n \"ready\",\n (ticket) => native(\"ready\", ticket, () => getDriver().documentReadiness(ticket)),\n { charge: false },\n ),\n pages: nativeOperation(\"list-pages\", (driver, ticket) => driver.listPages(ticket), {\n charge: false,\n }),\n frames: nativeOperation(\"list-frames\", (driver, ticket) => driver.listFrames(ticket), {\n charge: false,\n }),\n selectPage: (id: string) =>\n nativeOperation(\n \"select-page\",\n async (driver, ticket) => {\n await driver.selectPage(id, ticket);\n owner.state.selection++;\n },\n { charge: false },\n ),\n selectFrame: (id: string) =>\n nativeOperation(\n \"select-frame\",\n async (driver, ticket) => {\n await driver.selectFrame(id, ticket);\n owner.state.selection++;\n },\n { charge: false },\n ),\n createPage: () =>\n nativeOperation(\"new-page\", (driver, ticket) => driver.newPage(ticket), {\n mutation: true,\n charge: false,\n anyPage: true,\n }),\n closePage: (id: string) =>\n nativeOperation(\"close-page\", (driver, ticket) => driver.closePage(id, ticket), {\n mutation: true,\n charge: false,\n anyPage: true,\n }),\n resize: (viewport: Viewport) =>\n nativeOperation(\"resize\", (driver, ticket) => driver.resize(viewport, ticket), {\n mutation: true,\n charge: false,\n }),\n waitFor: (selector: string, state: \"visible\" | \"hidden\" | \"attached\" | \"detached\") =>\n nativeOperation(\"wait\", (driver, ticket) => driver.waitFor(selector, state, ticket)),\n clickAndWait: (target: string | ObservedElement) =>\n nativeOperation(\"click-and-wait\", (driver, ticket) => driver.clickAndWait(target, ticket), {\n mutation: true,\n }),\n clickForDownload: (target: string | ObservedElement) =>\n nativeOperation(\n \"download-action\",\n (driver, ticket) => driver.clickForDownload(target, ticket),\n { mutation: true },\n ),\n selectFiles: (target: string | ObservedElement, files: ReadonlyArray<NativeFileSelection>) =>\n nativeOperation(\n \"select-files\",\n (driver, ticket) => driver.selectFiles(target, files, ticket),\n { mutation: true },\n ),\n clickForFileSelection: (\n target: string | ObservedElement,\n files: ReadonlyArray<NativeFileSelection>,\n ) =>\n nativeOperation(\n \"file-chooser\",\n (driver, ticket) => driver.clickForFileSelection(target, files, ticket),\n { mutation: true },\n ),\n liveView: (ttl: number) =>\n owner.guard(\"live-view\", () => issueLiveView(client, ref, ttl), {\n charge: false,\n phases: [\"open\", \"paused\"],\n }),\n beginHandoff: (ttl: number) =>\n owner.guard(\n \"handoff\",\n () =>\n Effect.gen(function* () {\n if (options.driver.pageControl)\n return yield* BrowserError.make({\n operation: \"handoff\",\n reason: \"unsupported\",\n outcome: \"undispatched\",\n });\n if (owner.state.phase === \"open\") owner.fence(\"paused\", \"paused\");\n handoffToken ??= globalThis.crypto.randomUUID();\n // Failure to mint a view leaves automation paused; there is no finally/resume pair.\n const view = yield* issueLiveView(client, ref, ttl);\n\n return { token: Redacted.make(handoffToken), view };\n }),\n { charge: false, phases: [\"open\", \"paused\"], verifyAfter: false },\n ),\n resume: (token: Redacted.Redacted<string>, operatorReleasedControl: boolean) =>\n owner.guard(\n \"resume\",\n (ticket) =>\n Effect.gen(function* () {\n if (\n !operatorReleasedControl ||\n handoffToken === undefined ||\n Redacted.value(token) !== handoffToken\n ) {\n return yield* BrowserError.make({\n operation: \"resume\",\n reason: \"authorization\",\n outcome: \"undispatched\",\n });\n }\n yield* native(\"resume\", ticket, () => getDriver().dismissDialogs(ticket));\n const observation = yield* observeInside(ticket, undefined, undefined, false);\n\n // This synchronous commit remains under the same permit as the fresh observation.\n owner.state.phase = \"open\";\n handoffToken = undefined;\n\n return observation;\n }),\n { charge: false, phases: [\"paused\"], verifyAfter: false },\n ),\n detach: owner\n .guard(\n \"detach\",\n (ticket) =>\n Effect.gen(function* () {\n if (!options.keepAlive)\n return yield* BrowserError.make({\n operation: \"detach\",\n reason: \"unsupported\",\n outcome: \"undispatched\",\n });\n reconnectTarget = yield* native(\"detach\", ticket, () => getDriver().selectedTargetId());\n const attached = getDriver();\n\n activeConnection = undefined;\n owner.fence(\"detached\", \"disconnected\");\n const initialization = yield* Effect.exit(disposeBindings);\n\n const disconnected = yield* Effect.tryPromise({\n try: () => attached.disconnect(),\n catch: () => BrowserError.make({ operation: \"detach\", reason: \"disconnected\" }),\n }).pipe(Effect.exit);\n\n driver = undefined;\n if (Exit.isFailure(initialization))\n return yield* Effect.failCause(initialization.cause);\n if (Exit.isFailure(disconnected)) return yield* Effect.failCause(disconnected.cause);\n\n return { reference: ref, targetId: reconnectTarget };\n }),\n { charge: false, verifyAfter: false },\n )\n .pipe(Effect.onError(() => Effect.sync(() => owner.fence(\"uncertain\", \"uncertain\")))),\n reconnect: (operatorReleasedControl: boolean) =>\n owner\n .guard(\n \"reconnect\",\n (ticket) =>\n Effect.gen(function* () {\n if (!options.keepAlive || reconnectTarget === undefined || !operatorReleasedControl) {\n return yield* BrowserError.make({\n operation: \"reconnect\",\n reason: \"unsupported\",\n outcome: \"undispatched\",\n });\n }\n\n const status = yield* sessions\n .retrieve(ref)\n .pipe(\n Effect.mapError((error) =>\n BrowserError.make({ operation: \"reconnect\", reason: error.reason }),\n ),\n );\n\n if (status.status !== \"RUNNING\")\n return yield* BrowserError.make({ operation: \"reconnect\", reason: \"expired\" });\n owner.state.phase = \"acquiring\";\n const endpoint = yield* connectionUrl(\"reconnect\");\n\n yield* connectNative(endpoint, {\n ...options.driver,\n initialTargetId: reconnectTarget,\n newPage: false,\n preserveViewport: true,\n });\n const observation = yield* observeInside(ticket, undefined, undefined, false);\n\n owner.state.phase = \"open\";\n\n return observation;\n }),\n { charge: false, phases: [\"detached\", \"acquiring\"], verifyAfter: false },\n )\n .pipe(\n Effect.onError(() => closeScope),\n Effect.onInterrupt(() => closeScope),\n ),\n };\n\n // One timer belongs to the enclosing execution, never to an individual Tool call.\n const remaining = Math.max(\n 0,\n owner.lifetimeDeadline - Number(clock.monotonicTimeNanosUnsafe()) / 1_000_000,\n );\n\n // The execution lifetime distinguishes expiry from natural completion before\n // running the shared close path; this race has the required proven semantics.\n // @effect-diagnostics-next-line raceFirstWithSleepToTimeout:off\n yield* Effect.raceFirst(\n Effect.sleep(remaining).pipe(Effect.as(true)),\n Deferred.await(ended).pipe(Effect.as(false)),\n ).pipe(\n Effect.flatMap((expired) => (expired ? closeScope : Effect.void)),\n Effect.forkIn(parentScope),\n );\n\n return {\n reference: ref,\n /** The caller keeps its own lease type, including whether an allocation attempt exists. */\n lease: acquired,\n close: controls.close,\n connect: Effect.suspend(() =>\n owner.state.phase === \"closed\" || owner.state.phase === \"closing\"\n ? Effect.fail(\n BrowserError.make({\n operation: \"connect\",\n reason: \"closed\",\n outcome: \"undispatched\",\n }),\n )\n : connected.pipe(Effect.as(controls)),\n ),\n };\n});\n\nexport type SessionControls =\n Effect.Success<ReturnType<typeof acquireSession>> extends {\n connect: Effect.Effect<infer A, infer _E, infer _R>;\n }\n ? A\n : never;\n\nexport type BoundControls = ReturnType<SessionControls[\"bind\"]>;\n","import { Context, Effect, Layer, type Option, type Redacted, Schema, Scope } from \"effect\";\n\nimport * as Bootstrap from \"./Bootstrap.ts\";\nimport { BrowserbaseBrowserBinding } from \"./BrowserBinding.ts\";\nimport {\n type ControlFacts,\n ActionResult,\n AutomationOptions,\n BrowserPolicy,\n Checkpoint,\n CheckpointOptions,\n ClickRequest,\n FillRequest,\n type FrameInfo,\n HoverRequest,\n InlineFiles,\n InputReceipt,\n KeyStroke,\n NavigateRequest,\n NavigationResult,\n type Observation,\n ObservationOptions,\n ObservedElement,\n type PageInfo,\n PointerMoveRequest,\n PressRequest,\n ReadTextRequest,\n ScreenshotRequest,\n ScreenshotResult,\n ScrollRequest,\n type SelectFilesRequest,\n StartNavigationRequest,\n Selector,\n type Target,\n TextResult,\n TypeRequest,\n Viewport,\n WheelRequest,\n} from \"./BrowserData.ts\";\nimport type { CleanupResult } from \"./Cleanup.ts\";\nimport { BrowserbaseClient } from \"./Client.ts\";\nimport {\n type AllocationError,\n BrowserError,\n type BrowserOperation,\n type ContextError,\n InitializationError,\n type SessionError,\n} from \"./Errors.ts\";\nimport { associate } from \"./internal/browser/Association.ts\";\nimport { makeBindings, preparePlan, type Bindings } from \"./internal/browser/Bindings.ts\";\nimport { compileBootstrap } from \"./internal/browser/Bootstrap.ts\";\nimport type { NativeFileSelection } from \"./internal/browser/Driver.ts\";\nimport type { LiveView } from \"./internal/browser/LiveView.ts\";\nimport { associatePageControl } from \"./internal/browser/PageControlAssociation.ts\";\nimport {\n acquireSession,\n borrowedRemote,\n ownedRemote,\n type BoundControls,\n type SessionControls,\n} from \"./internal/browser/Session.ts\";\nimport type { ContextWriterPermit } from \"./internal/session/WriterFacts.ts\";\nimport { issuedUpload } from \"./internal/upload/Issued.ts\";\nimport type { LaunchRecipe } from \"./Launch.ts\";\nimport { Identifier, type AllocationAttempt, type SessionReference } from \"./References.ts\";\nimport { BrowserbaseSessions } from \"./Sessions.ts\";\nimport { DownloadObservation } from \"./Transfers.ts\";\n\nexport type { LiveView } from \"./internal/browser/LiveView.ts\";\n\n/** Host configuration. Credentials live in the Client; a model never selects these values. */\nexport interface BrowserOptions extends AutomationOptions {\n readonly launch: LaunchRecipe;\n /** Required whenever the launch recipe persists a context. */\n readonly contextWriter?: ContextWriterPermit;\n readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;\n readonly onAllocationUncertain?: (attempt: AllocationAttempt) => Effect.Effect<void>;\n}\n\nexport interface Handoff {\n readonly token: Redacted.Redacted<string>;\n readonly view: LiveView;\n}\n\n/**\n * A host's decision about one control, made on facts read from the exact node immediately\n * before input. Returning anything but `true`, or throwing, sends nothing and fails `denied`.\n * It is a plain synchronous function on purpose: it runs while the owner's permit is held, where\n * waiting on a model or a network call would stall every other operation. It is not an atomic\n * check-and-input transaction, because page script can still run before the native input lands.\n */\nexport interface ElementAdmission {\n readonly admit: (facts: ControlFacts) => boolean;\n}\n\n/**\n * A navigation the browser is still performing. The owner's permit was released when it was\n * dispatched, so while it loads a host may read, `checkpoint`, hold and resume this page, and\n * use any other page. Anything that would change this page fails `busy` until it settles.\n *\n * Leaving its scope unsettled fences the session, exactly as an interrupted mutation does,\n * because nothing then knows what the browser did. It is never replayed.\n */\nexport interface NavigationOperation {\n /** What was navigated, read before dispatch. */\n readonly target: Target;\n /**\n * The document reached DOMContentLoaded. It belongs to this one navigation: a successor that\n * reaches the same URL fails it instead. Interrupting a waiter stops nothing in the browser.\n */\n readonly completed: Effect.Effect<NavigationResult, BrowserError>;\n /**\n * Asks the browser to stop loading and waits for this navigation to settle, after which\n * `completed` fails `interrupted`. Success is a known outcome and the session stays usable:\n * the page holds whatever had loaded. It does not undo anything the page already did.\n */\n readonly stop: Effect.Effect<void, BrowserError>;\n}\n\n/** One selected page and frame at one connection generation, never the current DOM. */\nexport interface BoundTarget {\n readonly navigate: (request: NavigateRequest) => Effect.Effect<NavigationResult, BrowserError>;\n /** `navigate`, left in flight: the same single dispatch, completed by the caller. */\n readonly startNavigation: (\n request: StartNavigationRequest,\n ) => Effect.Effect<NavigationOperation, BrowserError, Scope.Scope>;\n readonly readText: (request: ReadTextRequest) => Effect.Effect<TextResult, BrowserError>;\n readonly click: (request: ClickRequest) => Effect.Effect<ActionResult, BrowserError>;\n readonly fill: (request: FillRequest) => Effect.Effect<ActionResult, BrowserError>;\n /** Script in the page: instantaneous, and it raises no wheel event. */\n readonly scroll: (request: ScrollRequest) => Effect.Effect<ActionResult, BrowserError>;\n /** One real pointer move, in main-frame viewport pixels. */\n readonly pointerMove: (request: PointerMoveRequest) => Effect.Effect<InputReceipt, BrowserError>;\n /** Places the pointer on one exact element where it is, or fails `not-visible` unsent. */\n readonly hover: (request: HoverRequest) => Effect.Effect<InputReceipt, BrowserError>;\n /** One real wheel event; the browser decides what under the pointer scrolls. */\n readonly wheel: (request: WheelRequest) => Effect.Effect<InputReceipt, BrowserError>;\n /** One real key stroke to whatever has focus, or fails `not-focused` unsent if `into` lacks it. */\n readonly press: (request: PressRequest) => Effect.Effect<InputReceipt, BrowserError>;\n /** Text as the real key strokes that produce it, under the same focus rule as `press`. */\n readonly type: (request: TypeRequest) => Effect.Effect<InputReceipt, BrowserError>;\n readonly screenshot: (\n request: ScreenshotRequest,\n ) => Effect.Effect<ScreenshotResult, BrowserError>;\n}\n\n/**\n * Host control over one owned browser. This is not a serializable model value: copying a\n * session object cannot copy its capture, page-control or connection authority.\n */\nexport interface BrowserbaseSession<E = never> {\n readonly reference: SessionReference;\n /** First fail-session callback cause, preserving the consumer's error type on the host. */\n readonly failure: Effect.Effect<never, E | InitializationError>;\n /** Bounded host-only evidence; consumer causes are never projected into a page reply. */\n readonly bindingDiagnostics: Effect.Effect<Bootstrap.BindingDiagnostics<E>>;\n readonly bind: () => BoundTarget;\n /** Re-reads the live selection first, so a stale generation fails before any dispatch. */\n readonly currentTarget: Effect.Effect<BoundTarget, BrowserError>;\n readonly target: Effect.Effect<Target, BrowserError>;\n /**\n * The one observation whose nodes later actions may name. `scope: \"viewport\"` keeps only text\n * and controls that are on screen and reachable; the default reads the whole document. It is\n * safe to show a model: it carries no destination, form or field value.\n */\n readonly observe: (options?: ObservationOptions) => Effect.Effect<Observation, BrowserError>;\n /**\n * Passive evidence for a recorder, with a picture when asked. It issues no references and\n * leaves the observation above exactly as it was. Host-only: it carries control facts.\n */\n readonly checkpoint: (options?: CheckpointOptions) => Effect.Effect<Checkpoint, BrowserError>;\n /** Host-only facts about one observed control, read from that exact node just now. */\n readonly controlFacts: (reference: ObservedElement) => Effect.Effect<ControlFacts, BrowserError>;\n /**\n * After a page hold, nothing observed on that page may be acted on unchecked. This checks one\n * reference: still attached, and still the control that was inspected. It never searches by\n * selector or label for a substitute, and it sends nothing.\n */\n readonly revalidateElement: (\n reference: ObservedElement,\n ) => Effect.Effect<ObservedElement, BrowserError>;\n readonly clickElement: (\n reference: ObservedElement,\n admission?: ElementAdmission,\n ) => Effect.Effect<ActionResult, BrowserError>;\n readonly fillElement: (\n reference: ObservedElement,\n value: string,\n admission?: ElementAdmission,\n ) => Effect.Effect<ActionResult, BrowserError>;\n readonly hoverElement: (\n reference: ObservedElement,\n admission?: ElementAdmission,\n ) => Effect.Effect<InputReceipt, BrowserError>;\n /** A key stroke sent only if the exact node an observation named already has focus. */\n readonly pressElement: (\n reference: ObservedElement,\n stroke: KeyStroke,\n admission?: ElementAdmission,\n ) => Effect.Effect<InputReceipt, BrowserError>;\n /** Real typing with `fillElement`'s exactness: that node must already have focus. */\n readonly typeElement: (\n reference: ObservedElement,\n text: string,\n admission?: ElementAdmission,\n ) => Effect.Effect<InputReceipt, BrowserError>;\n readonly pages: Effect.Effect<ReadonlyArray<PageInfo>, BrowserError>;\n readonly frames: Effect.Effect<ReadonlyArray<FrameInfo>, BrowserError>;\n readonly selectPage: (pageId: string) => Effect.Effect<BoundTarget, BrowserError>;\n readonly selectFrame: (frameId: string) => Effect.Effect<BoundTarget, BrowserError>;\n /** Create a tab without selecting it. */\n readonly createPage: Effect.Effect<string, BrowserError>;\n readonly closePage: (pageId: string) => Effect.Effect<void, BrowserError>;\n readonly resizeViewport: (viewport: Viewport) => Effect.Effect<void, BrowserError>;\n readonly waitFor: (request: {\n readonly selector: string;\n readonly state: \"visible\" | \"hidden\" | \"attached\" | \"detached\";\n }) => Effect.Effect<void, BrowserError>;\n /** Navigation observation is registered before the single click dispatch. */\n readonly clickAndWait: (request: ClickRequest) => Effect.Effect<ActionResult, BrowserError>;\n readonly clickForDownload: (\n request: ClickRequest,\n ) => Effect.Effect<DownloadObservation, BrowserError>;\n /** Attaches to an existing file input; an uploaded branch needs a receipt for this session. */\n readonly selectFiles: (request: SelectFilesRequest) => Effect.Effect<ActionResult, BrowserError>;\n /** Registers the chooser observation before the single click that opens it. */\n readonly clickForFileSelection: (\n request: SelectFilesRequest,\n ) => Effect.Effect<ActionResult, BrowserError>;\n /**\n * Readiness of the current document only. Dependent operations wait for it themselves;\n * this reports it without charging an action, so a caller can decide what to do about a\n * document that predates the registrations.\n */\n readonly ready: Effect.Effect<Bootstrap.ReadinessOutcome, InitializationError>;\n readonly liveView: (expiresInSeconds?: number) => Effect.Effect<LiveView, BrowserError>;\n readonly beginHandoff: (expiresInSeconds?: number) => Effect.Effect<Handoff, BrowserError>;\n readonly resume: (\n token: Redacted.Redacted<string>,\n operatorReleasedControl: boolean,\n ) => Effect.Effect<Observation, BrowserError>;\n readonly detach: Effect.Effect<\n { readonly reference: SessionReference; readonly targetId: string },\n BrowserError\n >;\n readonly reconnect: (\n operatorReleasedControl: boolean,\n ) => Effect.Effect<Observation, BrowserError | InitializationError>;\n readonly close: Effect.Effect<CleanupResult, BrowserError>;\n readonly cleanupResult: Effect.Effect<Option.Option<CleanupResult>>;\n}\n\n/** Dependencies are captured at acquisition, not erased into an environment-free service Layer. */\nexport interface OpenOptions<E = never, R = never> {\n readonly bootstrap?: Bootstrap.Plan<E, R>;\n}\n\nexport interface AttachRequest<E = never, R = never> extends OpenOptions<E, R> {\n readonly policy: BrowserPolicy;\n /** The exact page to resume; without it the session must have exactly one page. */\n readonly target?: { readonly targetId: string };\n /** Bounded admission of a session the provider has not finished starting. */\n readonly pendingWaitMillis?: number;\n}\n\nexport interface BrowserAcquisition<E = never> {\n readonly reference: SessionReference;\n readonly attempt: AllocationAttempt;\n readonly failure: Effect.Effect<never, E | InitializationError>;\n readonly connect: Effect.Effect<BrowserbaseSession<E>, BrowserError | E | InitializationError>;\n readonly close: Effect.Effect<CleanupResult, BrowserError>;\n}\n\nconst checked = <A>(\n schema: Schema.Codec<A, unknown, never, never>,\n value: unknown,\n operation: BrowserOperation,\n) =>\n Schema.decodeUnknownEffect(schema)(value, { onExcessProperty: \"error\" }).pipe(\n Effect.mapError(() =>\n BrowserError.make({ operation, reason: \"configuration\", outcome: \"undispatched\" }),\n ),\n );\n\nconst decoded =\n <A>(schema: Schema.Codec<A, unknown, never, never>, operation: BrowserOperation) =>\n (value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => BrowserError.make({ operation, reason: \"malformed\" })),\n );\n\nconst action = decoded(ActionResult, \"action-result\");\nconst pointerMoved = decoded(InputReceipt, \"pointer-move\");\nconst hovered = decoded(InputReceipt, \"hover\");\nconst wheeled = decoded(InputReceipt, \"wheel\");\nconst pressed = decoded(InputReceipt, \"press\");\nconst typed = decoded(InputReceipt, \"type\");\n\nconst makeTarget = (bound: BoundControls): BoundTarget => ({\n navigate: (request) =>\n checked(NavigateRequest, request, \"navigate\").pipe(\n Effect.flatMap((value) => bound.navigate(value.url)),\n Effect.flatMap((url) => decoded(NavigationResult, \"navigate\")({ url })),\n ),\n startNavigation: (request) =>\n checked(StartNavigationRequest, request, \"navigate\").pipe(\n Effect.flatMap((value) => bound.startNavigation(value.url, value.timeoutMillis)),\n Effect.map((operation) => ({\n target: operation.target,\n completed: operation.completed.pipe(\n Effect.flatMap((url) => decoded(NavigationResult, \"navigate\")({ url })),\n ),\n stop: operation.stop,\n })),\n ),\n readText: (request) =>\n checked(ReadTextRequest, request, \"read-text\").pipe(\n Effect.flatMap((value) => bound.readText(value.selector)),\n Effect.flatMap((text) => decoded(TextResult, \"read-text\")({ text })),\n ),\n click: (request) =>\n checked(ClickRequest, request, \"click\").pipe(\n Effect.flatMap((value) => bound.click(value.selector)),\n Effect.flatMap((url) => action({ url })),\n ),\n fill: (request) =>\n checked(FillRequest, request, \"fill\").pipe(\n Effect.flatMap((value) => bound.fill(value.selector, value.value)),\n Effect.flatMap((url) => action({ url })),\n ),\n scroll: (request) =>\n checked(ScrollRequest, request, \"scroll\").pipe(\n Effect.flatMap((value) => bound.scroll(value.deltaX, value.deltaY)),\n Effect.flatMap((url) => action({ url })),\n ),\n pointerMove: (request) =>\n checked(PointerMoveRequest, request, \"pointer-move\").pipe(\n Effect.flatMap((value) => bound.pointerMove(value.to)),\n Effect.flatMap((input) => pointerMoved({ ...input, kind: \"pointer-move\" })),\n ),\n hover: (request) =>\n checked(HoverRequest, request, \"hover\").pipe(\n Effect.flatMap((value) => bound.hover(value.selector)),\n Effect.flatMap((input) => hovered({ ...input, kind: \"hover\" })),\n ),\n wheel: (request) =>\n checked(WheelRequest, request, \"wheel\").pipe(\n Effect.flatMap((value) =>\n bound\n .wheel(value.deltaX, value.deltaY, value.at)\n .pipe(\n Effect.flatMap((input) =>\n wheeled({ ...input, kind: \"wheel\", delta: { x: value.deltaX, y: value.deltaY } }),\n ),\n ),\n ),\n ),\n press: (request) =>\n checked(PressRequest, request, \"press\").pipe(\n Effect.flatMap((value) => bound.press(value.key, value.modifiers ?? [], value.into)),\n Effect.flatMap((input) => pressed({ ...input, kind: \"press\" })),\n ),\n type: (request) =>\n checked(TypeRequest, request, \"type\").pipe(\n Effect.flatMap((value) => bound.type(value.text, value.into)),\n Effect.flatMap((input) => typed({ ...input, kind: \"type\" })),\n ),\n screenshot: (request) =>\n checked(ScreenshotRequest, request, \"screenshot\").pipe(\n Effect.flatMap((value) => bound.screenshot(value.fullPage)),\n Effect.flatMap((bytes) =>\n decoded(\n ScreenshotResult,\n \"screenshot\",\n )({ mediaType: \"image/png\", bytes: new Uint8Array(bytes) }),\n ),\n ),\n});\n\n/**\n * Uploaded selection is admitted by the identity of a receipt this package issued for this\n * exact session, never by a path read off the caller's value. A fabricated receipt has no\n * issuance record, so an arbitrary server pathname can never become an attached file.\n */\nconst selection = (\n request: SelectFilesRequest,\n reference: SessionReference,\n operation: BrowserOperation,\n): Effect.Effect<ReadonlyArray<NativeFileSelection>, BrowserError> =>\n Effect.suspend(() => {\n const invalid = BrowserError.make({\n operation,\n reason: \"configuration\",\n outcome: \"undispatched\",\n });\n\n if (request.selection._tag === \"Inline\") {\n return checked(InlineFiles, request.selection.files, operation).pipe(\n Effect.map((files) =>\n files.map((file) => ({\n _tag: \"Inline\" as const,\n name: file.name,\n mediaType: file.mediaType,\n // The dispatched bytes cannot change after they were validated.\n bytes: new Uint8Array(file.bytes),\n })),\n ),\n );\n }\n\n const uploads = request.selection.uploads;\n\n if (!Array.isArray(uploads) || uploads.length < 1 || uploads.length > 8)\n return Effect.fail(invalid);\n const files: NativeFileSelection[] = [];\n\n for (const receipt of uploads) {\n const issued = issuedUpload(receipt);\n\n if (issued === undefined)\n return Effect.fail(\n BrowserError.make({ operation, reason: \"authorization\", outcome: \"undispatched\" }),\n );\n if (\n issued.reference.projectId !== reference.projectId ||\n issued.reference.sessionId !== reference.sessionId\n )\n return Effect.fail(\n BrowserError.make({ operation, reason: \"authorization\", outcome: \"undispatched\" }),\n );\n files.push({ _tag: \"Remote\", path: issued.remotePath });\n }\n\n return Effect.succeed(files);\n });\n\n/** A browser-operation failure keeps its meaning when it is reported as an initialization one. */\nconst initialization = (reason: BrowserError[\"reason\"]): InitializationError[\"reason\"] =>\n reason === \"busy\"\n ? \"busy\"\n : reason === \"closed\" || reason === \"disconnected\"\n ? \"closed\"\n : reason === \"timeout\"\n ? \"timeout\"\n : reason === \"stale\"\n ? \"stale\"\n : reason === \"unsupported\"\n ? \"unsupported\"\n : reason === \"configuration\"\n ? \"configuration\"\n : \"native\";\n\nconst makeSession = <E>(\n controls: SessionControls,\n bindings: Bindings<E>,\n): BrowserbaseSession<E> => {\n const currentTarget = controls.currentTarget.pipe(Effect.map(() => makeTarget(controls.bind())));\n\n const Wait = Schema.Struct({\n selector: ClickRequest.fields.selector,\n state: Schema.Literals([\"visible\", \"hidden\", \"attached\", \"detached\"]),\n });\n\n const navigate = (url: string) => action({ url });\n\n const session: BrowserbaseSession<E> = {\n reference: controls.reference,\n failure: bindings.failure,\n bindingDiagnostics: bindings.diagnostics,\n bind: () => makeTarget(controls.bind()),\n currentTarget,\n target: controls.currentTarget,\n observe: (options = {}) =>\n checked(ObservationOptions, options, \"observe\").pipe(\n Effect.flatMap((value) => controls.observe({ ...value, scope: value.scope ?? \"document\" })),\n ),\n checkpoint: (options = {}) =>\n checked(CheckpointOptions, options, \"checkpoint\").pipe(\n Effect.flatMap((value) =>\n controls.checkpoint({ ...value, picture: value.picture ?? false }),\n ),\n Effect.flatMap(({ picture, ...sampled }) =>\n decoded(\n Checkpoint,\n \"checkpoint\",\n )({\n ...sampled,\n ...(picture === undefined\n ? {}\n : { picture: { mediaType: \"image/png\", bytes: new Uint8Array(picture) } }),\n }),\n ),\n ),\n controlFacts: (reference) =>\n checked(ObservedElement, reference, \"control-facts\").pipe(\n Effect.flatMap(controls.controlFacts),\n ),\n revalidateElement: (reference) =>\n checked(ObservedElement, reference, \"revalidate\").pipe(\n Effect.flatMap((value) => controls.revalidate(value).pipe(Effect.as(value))),\n ),\n clickElement: (reference, admission) =>\n checked(ObservedElement, reference, \"click\").pipe(\n Effect.flatMap((value) => controls.bind().click(value, admission?.admit)),\n Effect.flatMap(navigate),\n ),\n fillElement: (reference, value, admission) =>\n checked(ObservedElement, reference, \"fill\").pipe(\n Effect.flatMap((element) =>\n checked(FillRequest.fields.value, value, \"fill\").pipe(\n Effect.flatMap((text) => controls.bind().fill(element, text, admission?.admit)),\n ),\n ),\n Effect.flatMap(navigate),\n ),\n hoverElement: (reference, admission) =>\n checked(ObservedElement, reference, \"hover\").pipe(\n Effect.flatMap((value) => controls.bind().hover(value, admission?.admit)),\n Effect.flatMap((input) => hovered({ ...input, kind: \"hover\" })),\n ),\n pressElement: (reference, stroke, admission) =>\n checked(ObservedElement, reference, \"press\").pipe(\n Effect.flatMap((element) =>\n checked(KeyStroke, stroke, \"press\").pipe(\n Effect.flatMap((value) =>\n controls.bind().press(value.key, value.modifiers ?? [], element, admission?.admit),\n ),\n ),\n ),\n Effect.flatMap((input) => pressed({ ...input, kind: \"press\" })),\n ),\n typeElement: (reference, text, admission) =>\n checked(ObservedElement, reference, \"type\").pipe(\n Effect.flatMap((element) =>\n checked(TypeRequest.fields.text, text, \"type\").pipe(\n Effect.flatMap((value) => controls.bind().type(value, element, admission?.admit)),\n ),\n ),\n Effect.flatMap((input) => typed({ ...input, kind: \"type\" })),\n ),\n pages: controls.pages,\n frames: controls.frames,\n selectPage: (id) =>\n checked(Identifier, id, \"select-page\").pipe(\n Effect.flatMap(controls.selectPage),\n Effect.andThen(currentTarget),\n ),\n selectFrame: (id) =>\n checked(Identifier, id, \"select-frame\").pipe(\n Effect.flatMap(controls.selectFrame),\n Effect.andThen(currentTarget),\n ),\n createPage: controls.createPage(),\n closePage: (id) =>\n checked(Identifier, id, \"close-page\").pipe(Effect.flatMap(controls.closePage)),\n resizeViewport: (viewport) =>\n checked(Viewport, viewport, \"resize\").pipe(Effect.flatMap(controls.resize)),\n waitFor: (request) =>\n checked(Wait, request, \"wait\").pipe(\n Effect.flatMap((value) => controls.waitFor(value.selector, value.state)),\n ),\n clickAndWait: (request) =>\n checked(ClickRequest, request, \"click-and-wait\").pipe(\n Effect.flatMap((value) => controls.clickAndWait(value.selector)),\n Effect.flatMap((url) => action({ url })),\n ),\n clickForDownload: (request) =>\n checked(ClickRequest, request, \"download-action\").pipe(\n Effect.flatMap((value) => controls.clickForDownload(value.selector)),\n Effect.flatMap((raw) =>\n decoded(\n DownloadObservation,\n \"download-action\",\n )({ ...raw, reference: controls.reference }),\n ),\n ),\n selectFiles: (request) =>\n checked(Selector, request.selector, \"select-files\").pipe(\n Effect.flatMap((selector) =>\n selection(request, controls.reference, \"select-files\").pipe(\n Effect.flatMap((files) => controls.selectFiles(selector, files)),\n ),\n ),\n Effect.flatMap(navigate),\n ),\n clickForFileSelection: (request) =>\n checked(Selector, request.selector, \"file-chooser\").pipe(\n Effect.flatMap((selector) =>\n selection(request, controls.reference, \"file-chooser\").pipe(\n Effect.flatMap((files) => controls.clickForFileSelection(selector, files)),\n ),\n ),\n Effect.flatMap(navigate),\n ),\n ready: controls.readiness.pipe(\n Effect.mapError((error) =>\n InitializationError.make({\n operation: \"ready\",\n step: \"session\",\n reason: initialization(error.reason),\n }),\n ),\n Effect.flatMap((state) =>\n state._tag === \"NotReady\"\n ? Effect.fail(\n InitializationError.make({\n operation: \"ready\",\n step: state.step,\n reason: state.reason === \"failed\" ? \"output\" : state.reason,\n }),\n )\n : Effect.succeed<Bootstrap.ReadinessOutcome>({ _tag: state._tag }),\n ),\n ),\n liveView: (ttl = 60) => controls.liveView(ttl),\n beginHandoff: (ttl = 60) => controls.beginHandoff(ttl),\n resume: (token, released) => controls.resume(token, released),\n detach: controls.detach,\n reconnect: (released) => controls.reconnect(released),\n close: controls.close,\n cleanupResult: controls.cleanupResult,\n };\n\n associate(session, controls.capture);\n associatePageControl(session, controls.pageControl);\n\n return session;\n};\n\n/**\n * Credentials, budgets and connection lifetime are fixed when this Layer is built. Building it\n * allocates nothing and loads no native peer; every acquisition is scoped by its caller.\n */\nexport class BrowserbaseBrowser extends Context.Service<\n BrowserbaseBrowser,\n {\n readonly acquire: <E = never, R = never>(\n policy: BrowserPolicy,\n request?: OpenOptions<E, R>,\n ) => Effect.Effect<\n BrowserAcquisition<E>,\n AllocationError | BrowserError | ContextError,\n Scope.Scope | Exclude<R, Scope.Scope>\n >;\n /** Borrowed control of a session this process did not allocate and will not release. */\n readonly attach: <E = never, R = never>(\n reference: SessionReference,\n request: AttachRequest<E, R>,\n ) => Effect.Effect<\n BrowserbaseSession<E>,\n BrowserError | SessionError | E | InitializationError,\n Scope.Scope | Exclude<R, Scope.Scope>\n >;\n readonly open: <E = never, R = never>(\n policy: BrowserPolicy,\n request?: OpenOptions<E, R>,\n ) => Effect.Effect<\n BrowserbaseSession<E>,\n AllocationError | BrowserError | ContextError | E | InitializationError,\n Scope.Scope | Exclude<R, Scope.Scope>\n >;\n /** Race the consumer with typed callback failure and confirm cleanup before normal success. */\n readonly withBrowser: <E, R, A, E2, R2>(\n policy: BrowserPolicy,\n request: OpenOptions<E, R>,\n use: (session: BrowserbaseSession<E>) => Effect.Effect<A, E2, R2>,\n ) => Effect.Effect<\n A,\n AllocationError | BrowserError | ContextError | InitializationError | E | E2,\n Exclude<R | R2, Scope.Scope>\n >;\n }\n>()(\"effect-browserbase/Browser\") {\n static layer(\n options: BrowserOptions,\n ): Layer.Layer<BrowserbaseBrowser, BrowserError, BrowserbaseClient | BrowserbaseSessions> {\n return Layer.effect(\n BrowserbaseBrowser,\n Effect.gen(function* () {\n const client = yield* BrowserbaseClient;\n const sessions = yield* BrowserbaseSessions;\n // The engine is fixed where the Layer is built, like the account it connects for.\n const binding = yield* BrowserbaseBrowserBinding;\n const automation = yield* checked(AutomationOptions, projected(options), \"configure\");\n\n const viewport = yield* checked(\n Viewport,\n options.launch.viewport._tag === \"Fixed\"\n ? { width: options.launch.viewport.width, height: options.launch.viewport.height }\n : { width: 1280, height: 720 },\n \"configure\",\n );\n\n const actionTimeoutMillis = automation.actionTimeoutMillis ?? 10_000;\n const maxPages = automation.maxPages ?? 10;\n const pageControl = automation.pageControl ?? false;\n const popupPolicy = automation.popupPolicy ?? \"retain\";\n const dialogPolicy = automation.dialogPolicy ?? \"dismiss\";\n\n if (\n pageControl &&\n (options.launch.keepAlive === true || popupPolicy === \"pause\" || dialogPolicy === \"pause\")\n )\n return yield* BrowserError.make({\n operation: \"configure\",\n reason: \"unsupported\",\n outcome: \"undispatched\",\n });\n\n if (options.launch.context?.persist === true && options.contextWriter === undefined)\n return yield* BrowserError.make({ operation: \"configure\", reason: \"context-lease\" });\n\n // A retired layer-level bootstrap must not be silently discarded for JavaScript callers.\n if (Object.prototype.hasOwnProperty.call(options, \"bootstrap\"))\n return yield* BrowserError.make({\n operation: \"configure\",\n reason: \"configuration\",\n outcome: \"undispatched\",\n });\n\n const driver = {\n pageControl,\n viewport,\n maxPages,\n popupPolicy,\n dialogPolicy,\n preserveViewport: options.launch.viewport._tag !== \"Fixed\",\n ...(automation.initialPage === undefined\n ? {}\n : \"targetId\" in automation.initialPage\n ? { initialTargetId: automation.initialPage.targetId }\n : { newPage: true }),\n };\n\n const acquire = Effect.fnUntraced(function* <E = never, R = never>(\n policy: BrowserPolicy,\n request: OpenOptions<E, R> = {},\n ) {\n const fixed = yield* checked(BrowserPolicy, policy, \"configure\");\n const plan = yield* preparePlan<E, R>(request.bootstrap ?? Bootstrap.empty);\n // The sequential child keeps remote cleanup ahead of callback-scope finalization even\n // when a consumer deliberately gives its outer Scope parallel finalizers.\n const scope = yield* Scope.fork(yield* Scope.Scope, \"sequential\");\n const bindings = yield* makeBindings(plan).pipe(Scope.provide(scope));\n const bootstrap = compileBootstrap(plan);\n\n const acquired = yield* acquireSession(\n {\n maxActions: fixed.maxActions,\n maxElapsedMillis: fixed.maxElapsedMillis,\n actionTimeoutMillis,\n },\n {\n remote: ownedRemote({\n launch: options.launch,\n ...(options.contextWriter === undefined\n ? {}\n : { contextWriter: options.contextWriter }),\n ...(options.onCleanup === undefined ? {} : { onCleanup: options.onCleanup }),\n ...(options.onAllocationUncertain === undefined\n ? {}\n : { onAllocationUncertain: options.onAllocationUncertain }),\n }),\n keepAlive: options.launch.keepAlive === true,\n driver: { ...driver, ...(bootstrap === undefined ? {} : { bootstrap }) },\n connectBindings: bindings.connect,\n maxReturnedBytes: fixed.maxReturnedBytes,\n },\n ).pipe(\n // The Layer owns the one account and resource service; acquisition never re-resolves them.\n Effect.provideService(BrowserbaseClient, client),\n Effect.provideService(BrowserbaseSessions, sessions),\n Effect.provideService(BrowserbaseBrowserBinding, binding),\n Scope.provide(scope),\n );\n\n // One public session object is shared by repeated connect calls in this scope.\n const connected = yield* Effect.cached(\n acquired.connect.pipe(Effect.map((controls) => makeSession(controls, bindings))),\n );\n\n return {\n reference: acquired.reference,\n attempt: acquired.lease.attempt,\n failure: bindings.failure,\n close: acquired.close,\n connect: Effect.raceFirst(\n bindings.failure,\n acquired.connect.pipe(Effect.andThen(connected)),\n ).pipe(Effect.onError(() => acquired.close.pipe(Effect.asVoid))),\n } satisfies BrowserAcquisition<E>;\n });\n\n /**\n * Borrowing a session another process allocated. The launch recipe is not replayed and\n * no allocation is attempted: the requested target is resolved explicitly, credentials\n * are fetched fresh because expiry races the caller's own status read, and this scope\n * disconnects locally without ever requesting release. Detaching and reattaching inside\n * a borrowed scope is deliberately absent; attaching again is the cross-process path,\n * and it revalidates the session instead of assuming it is still there.\n */\n const attach = Effect.fnUntraced(function* <E = never, R = never>(\n reference: SessionReference,\n request: AttachRequest<E, R>,\n ) {\n const fixed = yield* checked(BrowserPolicy, request.policy, \"configure\");\n const plan = yield* preparePlan<E, R>(request.bootstrap ?? Bootstrap.empty);\n const scope = yield* Scope.fork(yield* Scope.Scope, \"sequential\");\n const bindings = yield* makeBindings(plan).pipe(Scope.provide(scope));\n const bootstrap = compileBootstrap(plan);\n\n const targetId =\n request.target === undefined\n ? undefined\n : yield* checked(Identifier, request.target.targetId, \"configure\");\n\n const acquired = yield* acquireSession(\n {\n maxActions: fixed.maxActions,\n maxElapsedMillis: fixed.maxElapsedMillis,\n actionTimeoutMillis,\n },\n {\n remote: borrowedRemote({\n reference,\n ...(request.pendingWaitMillis === undefined\n ? {}\n : { pendingWaitMillis: request.pendingWaitMillis }),\n ...(options.onCleanup === undefined ? {} : { onCleanup: options.onCleanup }),\n }),\n keepAlive: false,\n driver: {\n ...driver,\n ...(bootstrap === undefined ? {} : { bootstrap }),\n newPage: false,\n preserveViewport: true,\n ...(targetId === undefined ? {} : { initialTargetId: targetId }),\n },\n maxReturnedBytes: fixed.maxReturnedBytes,\n connectBindings: bindings.connect,\n },\n ).pipe(\n Effect.provideService(BrowserbaseClient, client),\n Effect.provideService(BrowserbaseSessions, sessions),\n Effect.provideService(BrowserbaseBrowserBinding, binding),\n Scope.provide(scope),\n );\n\n return yield* Effect.raceFirst(\n bindings.failure,\n acquired.connect.pipe(Effect.map((controls) => makeSession(controls, bindings))),\n ).pipe(Effect.onError(() => acquired.close.pipe(Effect.asVoid)));\n });\n\n return BrowserbaseBrowser.of({\n acquire,\n attach,\n open: (policy, request) =>\n acquire(policy, request).pipe(Effect.flatMap((acquired) => acquired.connect)),\n withBrowser: (policy, request, use) =>\n Effect.scoped(\n Effect.gen(function* () {\n const acquired = yield* acquire(policy, request);\n const session = yield* acquired.connect;\n\n const result = yield* Effect.raceFirst(\n session.failure,\n Effect.suspend(() => use(session)),\n );\n\n const cleanup = yield* session.close;\n\n if (\n cleanup.remote !== \"confirmed\" ||\n cleanup.local !== \"closed\" ||\n cleanup.issues.length > 0\n )\n return yield* BrowserError.make({\n operation: \"close\",\n reason: \"provider\",\n outcome: \"unknown\",\n });\n\n return result;\n }),\n ),\n });\n }),\n );\n }\n}\n\n/** Only the automation fields cross the schema boundary; launch and callbacks are separate. */\nconst projected = (options: BrowserOptions) => ({\n ...(options.actionTimeoutMillis === undefined\n ? {}\n : { actionTimeoutMillis: options.actionTimeoutMillis }),\n ...(options.maxPages === undefined ? {} : { maxPages: options.maxPages }),\n ...(options.initialPage === undefined ? {} : { initialPage: options.initialPage }),\n ...(options.popupPolicy === undefined ? {} : { popupPolicy: options.popupPolicy }),\n ...(options.dialogPolicy === undefined ? {} : { dialogPolicy: options.dialogPolicy }),\n ...(options.pageControl === undefined ? {} : { pageControl: options.pageControl }),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,MAAa,qBACX,UACA,QACA,YACkE;CAClE,IAAI,CAAC,OAAO,cAAc,QAAQ,KAAK,WAAW,GAChD,MAAM,IAAI,WAAW,mCAAmC;CAE1D,OAAO,OAAO,IAAI,aAAa;EAC7B,MAAM,SAAS,OAAO,MAAM;EAG5B,MAAM,eAAe,OAAO,MAAM,KAAK,QAAQ,YAAY;EAE3D,MAAM,MAAM,OAAO,SAAS,mBAA8C,CAAC,CAAC,KAC1E,MAAM,QAAQ,YAAY,CAC5B;EAEA,IAAI,YAAY;EAChB,IAAI,UAAU;EACd,IAAI,WAAW;EAEf,MAAM,cAAc;GAClB,YAAY;EACd;EAEA,MAAM,cAAc;GAClB,IAAI,CAAC,aAAa,SAAS;GAC3B,UAAU;GACV,QAAQ;EACV;EAIA,OAAO,MAAM,aAAa,cAAc,OAAO,KAAK,KAAK,CAAC;EAE1D,MAAM,UACJ,OACA,cAAmC,mBACR;GAC3B,IAAI,CAAC,aAAa,SAAS,OAAO;IAAE,MAAM;IAAY,QAAQ;GAAS;GACvE,IAAI,YAAY,UAAU;IACxB,IAAI,gBAAgB,gBAAgB,MAAM;IAE1C,OAAO;KAAE,MAAM;KAAY,QAAQ;IAAW;GAChD;GAEA;GAKA,MAAM,SAFY,IAAI,OAAO,KAAK,OAAO,cAAc,OAAO,KAAK,CAAC,CAAC,CAE9C,CAAC,CACrB,MACE,SAAS;IACR,IAAI,gBAAgB,kBAAkB,KAAK,UAAU,IAAI,GAAG,MAAM;IAElE,OAAO;GACT,IACC,UAAU;IACT,IAAI,gBAAgB,gBAAgB,MAAM;IAC1C,MAAM;GACR,CACF,CAAC,CACA,cAAc;IACb;GACF,CAAC;GAIH,OAAY,YAAY,CAAC,CAAC;GAE1B,OAAO;IAAE,MAAM;IAAY;GAAO;EACpC;EAEA,OAAO;GAAE;GAAO;EAAO;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AK;MAC9B,WAAW;MACX,QAAQ;MACR,SAAS;KACX,CAAC;KAEH,OAAO;IACT,CAAC,CACH;GACJ,CAAC;EACH,CAAC,CACH;CACF;AACF;;AAGA,MAAM,aAAa,aAA6B;CAC9C,GAAI,QAAQ,wBAAwB,KAAA,IAChC,CAAC,IACD,EAAE,qBAAqB,QAAQ,oBAAoB;CACvD,GAAI,QAAQ,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,QAAQ,SAAS;CACvE,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;CAChF,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;CAChF,GAAI,QAAQ,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,cAAc,QAAQ,aAAa;CACnF,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;AAClF"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { o as SessionReference, t as AllocationAttempt } from "./References-URDAtapt.mjs";
|
|
2
|
+
import { AllocationError, BrowserError, ContextError, InitializationError, SessionError } from "./Errors.mjs";
|
|
3
|
+
import { t as BrowserbaseClient } from "./Client-Ca0zSg1n.mjs";
|
|
4
|
+
import { s as LiveView, t as BrowserbaseSessions } from "./Sessions-B8E4kMxo.mjs";
|
|
5
|
+
import { r as DownloadObservation } from "./Transfers-Czv5IZzJ.mjs";
|
|
6
|
+
import { n as CleanupResult } from "./Cleanup-G2YpTCuU.mjs";
|
|
7
|
+
import { n as ContextWriterPermit } from "./WriterFacts-osvYAsIx.mjs";
|
|
8
|
+
import { f as Plan, g as ReadinessOutcome, s as Bootstrap_d_exports, t as BindingDiagnostics } from "./Bootstrap-m7lHgj0D.mjs";
|
|
9
|
+
import { A as ReadTextRequest, B as TypeRequest, E as PageInfo, G as WheelRequest, I as StartNavigationRequest, L as Target, M as ScreenshotResult, N as ScrollRequest, O as PointerMoveRequest, P as SelectFilesRequest, S as ObservationOptions, V as Viewport, _ as KeyStroke, a as Checkpoint, b as NavigationResult, c as ControlFacts, d as FrameInfo, f as HoverRequest, h as InputReceipt, i as BrowserPolicy, j as ScreenshotRequest, k as PressRequest, n as AutomationOptions, o as CheckpointOptions, s as ClickRequest, t as ActionResult, u as FillRequest, w as ObservedElement, x as Observation, y as NavigateRequest, z as TextResult } from "./BrowserData-LpcAuAub.mjs";
|
|
10
|
+
import { t as LaunchRecipe } from "./Launch-C8CfaYxb.mjs";
|
|
11
|
+
import { Context, Effect, Layer, Option, Redacted, Scope } from "effect";
|
|
12
|
+
declare namespace Browser_d_exports {
|
|
13
|
+
export { AttachRequest, BoundTarget, BrowserAcquisition, BrowserOptions, BrowserbaseBrowser, BrowserbaseSession, ElementAdmission, Handoff, LiveView, NavigationOperation, OpenOptions };
|
|
14
|
+
}
|
|
15
|
+
/** Host configuration. Credentials live in the Client; a model never selects these values. */
|
|
16
|
+
export interface BrowserOptions extends AutomationOptions {
|
|
17
|
+
readonly launch: LaunchRecipe;
|
|
18
|
+
/** Required whenever the launch recipe persists a context. */
|
|
19
|
+
readonly contextWriter?: ContextWriterPermit;
|
|
20
|
+
readonly onCleanup?: (result: CleanupResult) => Effect.Effect<void>;
|
|
21
|
+
readonly onAllocationUncertain?: (attempt: AllocationAttempt) => Effect.Effect<void>;
|
|
22
|
+
}
|
|
23
|
+
export interface Handoff {
|
|
24
|
+
readonly token: Redacted.Redacted<string>;
|
|
25
|
+
readonly view: LiveView;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A host's decision about one control, made on facts read from the exact node immediately
|
|
29
|
+
* before input. Returning anything but `true`, or throwing, sends nothing and fails `denied`.
|
|
30
|
+
* It is a plain synchronous function on purpose: it runs while the owner's permit is held, where
|
|
31
|
+
* waiting on a model or a network call would stall every other operation. It is not an atomic
|
|
32
|
+
* check-and-input transaction, because page script can still run before the native input lands.
|
|
33
|
+
*/
|
|
34
|
+
export interface ElementAdmission {
|
|
35
|
+
readonly admit: (facts: ControlFacts) => boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A navigation the browser is still performing. The owner's permit was released when it was
|
|
39
|
+
* dispatched, so while it loads a host may read, `checkpoint`, hold and resume this page, and
|
|
40
|
+
* use any other page. Anything that would change this page fails `busy` until it settles.
|
|
41
|
+
*
|
|
42
|
+
* Leaving its scope unsettled fences the session, exactly as an interrupted mutation does,
|
|
43
|
+
* because nothing then knows what the browser did. It is never replayed.
|
|
44
|
+
*/
|
|
45
|
+
export interface NavigationOperation {
|
|
46
|
+
/** What was navigated, read before dispatch. */
|
|
47
|
+
readonly target: Target;
|
|
48
|
+
/**
|
|
49
|
+
* The document reached DOMContentLoaded. It belongs to this one navigation: a successor that
|
|
50
|
+
* reaches the same URL fails it instead. Interrupting a waiter stops nothing in the browser.
|
|
51
|
+
*/
|
|
52
|
+
readonly completed: Effect.Effect<NavigationResult, BrowserError>;
|
|
53
|
+
/**
|
|
54
|
+
* Asks the browser to stop loading and waits for this navigation to settle, after which
|
|
55
|
+
* `completed` fails `interrupted`. Success is a known outcome and the session stays usable:
|
|
56
|
+
* the page holds whatever had loaded. It does not undo anything the page already did.
|
|
57
|
+
*/
|
|
58
|
+
readonly stop: Effect.Effect<void, BrowserError>;
|
|
59
|
+
}
|
|
60
|
+
/** One selected page and frame at one connection generation, never the current DOM. */
|
|
61
|
+
export interface BoundTarget {
|
|
62
|
+
readonly navigate: (request: NavigateRequest) => Effect.Effect<NavigationResult, BrowserError>;
|
|
63
|
+
/** `navigate`, left in flight: the same single dispatch, completed by the caller. */
|
|
64
|
+
readonly startNavigation: (request: StartNavigationRequest) => Effect.Effect<NavigationOperation, BrowserError, Scope.Scope>;
|
|
65
|
+
readonly readText: (request: ReadTextRequest) => Effect.Effect<TextResult, BrowserError>;
|
|
66
|
+
readonly click: (request: ClickRequest) => Effect.Effect<ActionResult, BrowserError>;
|
|
67
|
+
readonly fill: (request: FillRequest) => Effect.Effect<ActionResult, BrowserError>;
|
|
68
|
+
/** Script in the page: instantaneous, and it raises no wheel event. */
|
|
69
|
+
readonly scroll: (request: ScrollRequest) => Effect.Effect<ActionResult, BrowserError>;
|
|
70
|
+
/** One real pointer move, in main-frame viewport pixels. */
|
|
71
|
+
readonly pointerMove: (request: PointerMoveRequest) => Effect.Effect<InputReceipt, BrowserError>;
|
|
72
|
+
/** Places the pointer on one exact element where it is, or fails `not-visible` unsent. */
|
|
73
|
+
readonly hover: (request: HoverRequest) => Effect.Effect<InputReceipt, BrowserError>;
|
|
74
|
+
/** One real wheel event; the browser decides what under the pointer scrolls. */
|
|
75
|
+
readonly wheel: (request: WheelRequest) => Effect.Effect<InputReceipt, BrowserError>;
|
|
76
|
+
/** One real key stroke to whatever has focus, or fails `not-focused` unsent if `into` lacks it. */
|
|
77
|
+
readonly press: (request: PressRequest) => Effect.Effect<InputReceipt, BrowserError>;
|
|
78
|
+
/** Text as the real key strokes that produce it, under the same focus rule as `press`. */
|
|
79
|
+
readonly type: (request: TypeRequest) => Effect.Effect<InputReceipt, BrowserError>;
|
|
80
|
+
readonly screenshot: (request: ScreenshotRequest) => Effect.Effect<ScreenshotResult, BrowserError>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Host control over one owned browser. This is not a serializable model value: copying a
|
|
84
|
+
* session object cannot copy its capture, page-control or connection authority.
|
|
85
|
+
*/
|
|
86
|
+
export interface BrowserbaseSession<E = never> {
|
|
87
|
+
readonly reference: SessionReference;
|
|
88
|
+
/** First fail-session callback cause, preserving the consumer's error type on the host. */
|
|
89
|
+
readonly failure: Effect.Effect<never, E | InitializationError>;
|
|
90
|
+
/** Bounded host-only evidence; consumer causes are never projected into a page reply. */
|
|
91
|
+
readonly bindingDiagnostics: Effect.Effect<BindingDiagnostics<E>>;
|
|
92
|
+
readonly bind: () => BoundTarget;
|
|
93
|
+
/** Re-reads the live selection first, so a stale generation fails before any dispatch. */
|
|
94
|
+
readonly currentTarget: Effect.Effect<BoundTarget, BrowserError>;
|
|
95
|
+
readonly target: Effect.Effect<Target, BrowserError>;
|
|
96
|
+
/**
|
|
97
|
+
* The one observation whose nodes later actions may name. `scope: "viewport"` keeps only text
|
|
98
|
+
* and controls that are on screen and reachable; the default reads the whole document. It is
|
|
99
|
+
* safe to show a model: it carries no destination, form or field value.
|
|
100
|
+
*/
|
|
101
|
+
readonly observe: (options?: ObservationOptions) => Effect.Effect<Observation, BrowserError>;
|
|
102
|
+
/**
|
|
103
|
+
* Passive evidence for a recorder, with a picture when asked. It issues no references and
|
|
104
|
+
* leaves the observation above exactly as it was. Host-only: it carries control facts.
|
|
105
|
+
*/
|
|
106
|
+
readonly checkpoint: (options?: CheckpointOptions) => Effect.Effect<Checkpoint, BrowserError>;
|
|
107
|
+
/** Host-only facts about one observed control, read from that exact node just now. */
|
|
108
|
+
readonly controlFacts: (reference: ObservedElement) => Effect.Effect<ControlFacts, BrowserError>;
|
|
109
|
+
/**
|
|
110
|
+
* After a page hold, nothing observed on that page may be acted on unchecked. This checks one
|
|
111
|
+
* reference: still attached, and still the control that was inspected. It never searches by
|
|
112
|
+
* selector or label for a substitute, and it sends nothing.
|
|
113
|
+
*/
|
|
114
|
+
readonly revalidateElement: (reference: ObservedElement) => Effect.Effect<ObservedElement, BrowserError>;
|
|
115
|
+
readonly clickElement: (reference: ObservedElement, admission?: ElementAdmission) => Effect.Effect<ActionResult, BrowserError>;
|
|
116
|
+
readonly fillElement: (reference: ObservedElement, value: string, admission?: ElementAdmission) => Effect.Effect<ActionResult, BrowserError>;
|
|
117
|
+
readonly hoverElement: (reference: ObservedElement, admission?: ElementAdmission) => Effect.Effect<InputReceipt, BrowserError>;
|
|
118
|
+
/** A key stroke sent only if the exact node an observation named already has focus. */
|
|
119
|
+
readonly pressElement: (reference: ObservedElement, stroke: KeyStroke, admission?: ElementAdmission) => Effect.Effect<InputReceipt, BrowserError>;
|
|
120
|
+
/** Real typing with `fillElement`'s exactness: that node must already have focus. */
|
|
121
|
+
readonly typeElement: (reference: ObservedElement, text: string, admission?: ElementAdmission) => Effect.Effect<InputReceipt, BrowserError>;
|
|
122
|
+
readonly pages: Effect.Effect<ReadonlyArray<PageInfo>, BrowserError>;
|
|
123
|
+
readonly frames: Effect.Effect<ReadonlyArray<FrameInfo>, BrowserError>;
|
|
124
|
+
readonly selectPage: (pageId: string) => Effect.Effect<BoundTarget, BrowserError>;
|
|
125
|
+
readonly selectFrame: (frameId: string) => Effect.Effect<BoundTarget, BrowserError>;
|
|
126
|
+
/** Create a tab without selecting it. */
|
|
127
|
+
readonly createPage: Effect.Effect<string, BrowserError>;
|
|
128
|
+
readonly closePage: (pageId: string) => Effect.Effect<void, BrowserError>;
|
|
129
|
+
readonly resizeViewport: (viewport: Viewport) => Effect.Effect<void, BrowserError>;
|
|
130
|
+
readonly waitFor: (request: {
|
|
131
|
+
readonly selector: string;
|
|
132
|
+
readonly state: "visible" | "hidden" | "attached" | "detached";
|
|
133
|
+
}) => Effect.Effect<void, BrowserError>;
|
|
134
|
+
/** Navigation observation is registered before the single click dispatch. */
|
|
135
|
+
readonly clickAndWait: (request: ClickRequest) => Effect.Effect<ActionResult, BrowserError>;
|
|
136
|
+
readonly clickForDownload: (request: ClickRequest) => Effect.Effect<DownloadObservation, BrowserError>;
|
|
137
|
+
/** Attaches to an existing file input; an uploaded branch needs a receipt for this session. */
|
|
138
|
+
readonly selectFiles: (request: SelectFilesRequest) => Effect.Effect<ActionResult, BrowserError>;
|
|
139
|
+
/** Registers the chooser observation before the single click that opens it. */
|
|
140
|
+
readonly clickForFileSelection: (request: SelectFilesRequest) => Effect.Effect<ActionResult, BrowserError>;
|
|
141
|
+
/**
|
|
142
|
+
* Readiness of the current document only. Dependent operations wait for it themselves;
|
|
143
|
+
* this reports it without charging an action, so a caller can decide what to do about a
|
|
144
|
+
* document that predates the registrations.
|
|
145
|
+
*/
|
|
146
|
+
readonly ready: Effect.Effect<ReadinessOutcome, InitializationError>;
|
|
147
|
+
readonly liveView: (expiresInSeconds?: number) => Effect.Effect<LiveView, BrowserError>;
|
|
148
|
+
readonly beginHandoff: (expiresInSeconds?: number) => Effect.Effect<Handoff, BrowserError>;
|
|
149
|
+
readonly resume: (token: Redacted.Redacted<string>, operatorReleasedControl: boolean) => Effect.Effect<Observation, BrowserError>;
|
|
150
|
+
readonly detach: Effect.Effect<{
|
|
151
|
+
readonly reference: SessionReference;
|
|
152
|
+
readonly targetId: string;
|
|
153
|
+
}, BrowserError>;
|
|
154
|
+
readonly reconnect: (operatorReleasedControl: boolean) => Effect.Effect<Observation, BrowserError | InitializationError>;
|
|
155
|
+
readonly close: Effect.Effect<CleanupResult, BrowserError>;
|
|
156
|
+
readonly cleanupResult: Effect.Effect<Option.Option<CleanupResult>>;
|
|
157
|
+
}
|
|
158
|
+
/** Dependencies are captured at acquisition, not erased into an environment-free service Layer. */
|
|
159
|
+
export interface OpenOptions<E = never, R = never> {
|
|
160
|
+
readonly bootstrap?: Plan<E, R>;
|
|
161
|
+
}
|
|
162
|
+
export interface AttachRequest<E = never, R = never> extends OpenOptions<E, R> {
|
|
163
|
+
readonly policy: BrowserPolicy;
|
|
164
|
+
/** The exact page to resume; without it the session must have exactly one page. */
|
|
165
|
+
readonly target?: {
|
|
166
|
+
readonly targetId: string;
|
|
167
|
+
};
|
|
168
|
+
/** Bounded admission of a session the provider has not finished starting. */
|
|
169
|
+
readonly pendingWaitMillis?: number;
|
|
170
|
+
}
|
|
171
|
+
export interface BrowserAcquisition<E = never> {
|
|
172
|
+
readonly reference: SessionReference;
|
|
173
|
+
readonly attempt: AllocationAttempt;
|
|
174
|
+
readonly failure: Effect.Effect<never, E | InitializationError>;
|
|
175
|
+
readonly connect: Effect.Effect<BrowserbaseSession<E>, BrowserError | E | InitializationError>;
|
|
176
|
+
readonly close: Effect.Effect<CleanupResult, BrowserError>;
|
|
177
|
+
}
|
|
178
|
+
declare const BrowserbaseBrowser_base: Context.ServiceClass<BrowserbaseBrowser, "effect-browserbase/Browser", {
|
|
179
|
+
readonly acquire: <E = never, R = never>(policy: BrowserPolicy, request?: OpenOptions<E, R>) => Effect.Effect<BrowserAcquisition<E>, AllocationError | BrowserError | ContextError, Scope.Scope | Exclude<R, Scope.Scope>>;
|
|
180
|
+
/** Borrowed control of a session this process did not allocate and will not release. */
|
|
181
|
+
readonly attach: <E = never, R = never>(reference: SessionReference, request: AttachRequest<E, R>) => Effect.Effect<BrowserbaseSession<E>, BrowserError | SessionError | E | InitializationError, Scope.Scope | Exclude<R, Scope.Scope>>;
|
|
182
|
+
readonly open: <E = never, R = never>(policy: BrowserPolicy, request?: OpenOptions<E, R>) => Effect.Effect<BrowserbaseSession<E>, AllocationError | BrowserError | ContextError | E | InitializationError, Scope.Scope | Exclude<R, Scope.Scope>>;
|
|
183
|
+
/** Race the consumer with typed callback failure and confirm cleanup before normal success. */
|
|
184
|
+
readonly withBrowser: <E, R, A, E2, R2>(policy: BrowserPolicy, request: OpenOptions<E, R>, use: (session: BrowserbaseSession<E>) => Effect.Effect<A, E2, R2>) => Effect.Effect<A, AllocationError | BrowserError | ContextError | InitializationError | E | E2, Exclude<R | R2, Scope.Scope>>;
|
|
185
|
+
}>;
|
|
186
|
+
/**
|
|
187
|
+
* Credentials, budgets and connection lifetime are fixed when this Layer is built. Building it
|
|
188
|
+
* allocates nothing and loads no native peer; every acquisition is scoped by its caller.
|
|
189
|
+
*/
|
|
190
|
+
export declare class BrowserbaseBrowser extends BrowserbaseBrowser_base {
|
|
191
|
+
static layer(options: BrowserOptions): Layer.Layer<BrowserbaseBrowser, BrowserError, BrowserbaseClient | BrowserbaseSessions>;
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
export { type LiveView, Browser_d_exports as t };
|
|
195
|
+
//# sourceMappingURL=Browser.d.mts.map
|
package/dist/Browser.mjs
ADDED