effect-browserbase 0.3.0-beta.6 → 0.3.0-beta.8

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/README.md CHANGED
@@ -7,8 +7,8 @@
7
7
  npm install effect-browserbase@beta effect-browser@beta effect playwright-core
8
8
  ```
9
9
 
10
- - `Browserbase`: `open` and `layer` create a session and release it when their scope closes, so
11
- billing stops then rather than at the session's timeout, and closing it waits for the release.
10
+ - `Browserbase`: `open` and `layer` create a session and request its release when their scope
11
+ closes. Closing waits for the outcome; an `Unconfirmed` session may still run and bill.
12
12
  `attach` connects to a running session without taking ownership of it, as from another process:
13
13
  that is resume, of a session created with `keepAlive`. `supervise` keeps
14
14
  sessions open across losses and session ends, and with `keep`, past its own scope. `reconcile`
@@ -79,13 +79,25 @@ session outlives the process that opened it, for another to attach to.
79
79
  ## Supervised sessions
80
80
 
81
81
  `supervise` keeps a browser on Browserbase as `Supervisor` generations, each a new session made
82
- from `session`. A lost session is published at once, `Lost` with its cause, and replaced on the
83
- `reopen` schedule; the next session opens `rotateBefore` ahead of the current browser's
84
- `expiresAt`, or on `rotate`, before the current one is released. `states` reports each session's release outcome. Sessions that
85
- persist to a stored context are exclusive: a rotation releases the current session, and lets its
86
- save settle, before the next one opens. An open Browserbase refused, as for a bad key or an invalid
87
- request, is `Down` at once with its cause, since no new try mends it; everything else, a held
88
- context included, is tried again on the schedule.
82
+ from `session`. Use `sessions.use` to hold a generation while working: its lease gives the
83
+ `browser` and `value`, which is the `Session` unless `build` supplies an application value.
84
+ `build(hosted)` runs in the generation's scope on every acquisition, including adoption; failed
85
+ or cancelled construction closes that scope and releases the acquired session before retry.
86
+ The [generic supervisor contract](../browser/README.md#supervising-browser-generations) describes
87
+ `use`, transferable `retain` scopes, cancellation and stale-work refusal.
88
+
89
+ Outgoing holds drain for `handover`, 30 seconds by default. A lost session revokes immediately and
90
+ is replaced on `reopen`; `rotateBefore` and `rotate` keep their normal schedule while older
91
+ nonexclusive generations drain. This can overlap more than two hosted sessions. The consumer
92
+ owns its overlap and billing policy. `states` reports each generation's release outcome;
93
+ `Unconfirmed` means the old session might still run even after local ownership ends.
94
+
95
+ Sessions that persist to a stored context are exclusive: rotation first drains the current
96
+ generation, releases its session and lets its save settle. If release is unconfirmed, the next
97
+ writer reconciles the context and fails `ContextHeld` while the old writer cannot be confirmed
98
+ ended. It does not silently create another writer. An open Browserbase refused, as for a bad key
99
+ or an invalid request, is `Down` at once; everything else, a held context included, is tried again
100
+ on the schedule.
89
101
 
90
102
  ```ts
91
103
  const program = Effect.gen(function* () {
@@ -93,12 +105,21 @@ const program = Effect.gen(function* () {
93
105
  session: { timeout: 6 * 60 * 60 },
94
106
  reopen: Schedule.exponential("1 second").pipe(Schedule.upTo({ duration: "5 minutes" })),
95
107
  rotateBefore: "20 minutes",
108
+ build: ({ browser, session }) =>
109
+ browser.firstPage.pipe(Effect.map((page) => ({ page, session }))),
96
110
  });
97
- const browser = yield* sessions.browser;
98
111
  // `retire` releases every session; so does the scope's close.
112
+ return yield* sessions.use(({ value }) => value.page.text());
99
113
  });
100
114
  ```
101
115
 
116
+ Keep pages that must close before provider release in a `use` or retained scope. Resources
117
+ acquired by `build` live in the generation's scope, which closes after provider release.
118
+ Generation `hostTime` uses the owning Effect clock; provider `createdAt` and `endedAt` are separate
119
+ wall-clock evidence. Fake-provider ordering tests do not prove hosted context-save timing or
120
+ billing. The included-hours-only [H2 recipe](../../docs/HOSTED_CHECKS.md) remains a hosted check to
121
+ run after its allowance is verified.
122
+
102
123
  ### Keeping a session past the scope
103
124
 
104
125
  With `keep`, a name, closing the supervisor's scope leaves its current session running instead of
@@ -107,6 +128,8 @@ name adopts that session, its pages and their ids with it, rather than creating
107
128
  a restart of the process that owns the browser keeps its prepared pages and its signed-in state.
108
129
  It is off by default, and opt-in, because a kept session bills until something adopts and releases
109
130
  it, or until its own `timeout` ends it: set one that bounds what a forgotten session costs.
131
+ Keeping revokes active work and closes retained and generation application scopes. The next
132
+ supervisor rebuilds its value when it adopts the session; only the provider's browser state stays.
110
133
 
111
134
  - Each session is created with `keepAlive`, so it outlives its connection, and labelled
112
135
  `keptAs: <name>` in its user metadata, since Browserbase sets user metadata only at the create.
@@ -509,34 +509,36 @@ const verifyContext = Effect.fn("Browserbase.verifyContext")(function* (contextI
509
509
  * Browserbase refused the request: no new try mends a refused key, request or id. A context held
510
510
  * is not among them, since each try ends its sessions again.
511
511
  */
512
- const refused = (error) => error._tag === "BrowserbaseError" && !isTransient(error) && error.reason._tag !== "Decode";
513
- /**
514
- * Keep Browserbase sessions open as `Supervisor` generations, each a new session made from
515
- * `session`. Sessions that persist to a stored context are exclusive: a rotation releases the
516
- * current one, and its context's save settles, before the next one opens. An open Browserbase
517
- * refused, as for a bad key or an invalid request, is `Down` at once. With `keep`, closing the
518
- * scope leaves the current session running for the next `supervise` under that name to adopt.
519
- */
520
- const supervise = (options = {}) => Effect.suspend(() => {
521
- const { keep } = options;
522
- let opened = false;
523
- return Supervisor.make({
524
- open: Effect.suspend(() => start(options, keep === void 0 ? void 0 : {
525
- name: keep,
526
- adopt: !opened
527
- })).pipe(Effect.tap(() => Effect.sync(() => {
528
- opened = true;
529
- })), Effect.withSpan("Browserbase.open", {}, { captureStackTrace: false })),
530
- exclusive: options.session?.browserSettings?.context?.persist === true,
531
- keep: keep !== void 0,
532
- reopen: options.reopen,
533
- definite: refused,
534
- rotateBefore: options.rotateBefore,
535
- waitTimeout: options.waitTimeout
512
+ const refused = (error) => Schema.is(BrowserbaseError)(error) && !isTransient(error) && error.reason._tag !== "Decode";
513
+ function supervise(options = {}) {
514
+ return Effect.suspend(() => {
515
+ const { keep } = options;
516
+ let opened = false;
517
+ return Supervisor.make({
518
+ open: Effect.gen(function* () {
519
+ const hosted = yield* start(options, keep === void 0 ? void 0 : {
520
+ name: keep,
521
+ adopt: !opened
522
+ });
523
+ opened = true;
524
+ const value = options.build === void 0 ? hosted.session : yield* options.build(hosted);
525
+ return {
526
+ ...hosted,
527
+ value
528
+ };
529
+ }).pipe(Effect.withSpan("Browserbase.open", {}, { captureStackTrace: false })),
530
+ exclusive: options.session?.browserSettings?.context?.persist === true,
531
+ keep: keep !== void 0,
532
+ reopen: options.reopen,
533
+ definite: refused,
534
+ rotateBefore: options.rotateBefore,
535
+ waitTimeout: options.waitTimeout,
536
+ handover: options.handover
537
+ });
536
538
  });
537
- });
539
+ }
538
540
  const layer = (options = {}) => Layer.effect(Browser.Browser, Effect.map(open(options), ({ browser }) => browser));
539
541
  //#endregion
540
542
  export { reconcile as a, open as i, attach as n, supervise as o, layer as r, verifyContext as s, Browserbase_exports as t };
541
543
 
542
- //# sourceMappingURL=Browserbase-FDltiz36.mjs.map
544
+ //# sourceMappingURL=Browserbase-CaPKwEY9.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Browserbase-CaPKwEY9.mjs","names":["CaptureConnection.make"],"sources":["../src/internal/captureConnection.ts","../src/Browserbase.ts"],"sourcesContent":["/**\n * The capture connection: a second DevTools connection to a session, for its pages' screencasts\n * alone. A frame and its acknowledgement then never wait behind a large message on the\n * connection Playwright drives the pages over, such as an upload or a read's answer: Browserbase\n * refuses compression, and on air those waits stopped the picture for as long as the message took\n * to cross.\n *\n * Raw CDP over the global WebSocket, with no Playwright. A page's session on it sends only the\n * capture's commands, and receives that page's events. The connection opens as the first capture\n * starts and stays until the scope closes, which closes it and waits, bounded, for it to close;\n * one that fails ends every page's session on it, and the next capture opens another.\n */\nimport { Duration, Effect, Option, Redacted, Schema, Semaphore } from \"effect\";\nimport type { CaptureSource } from \"effect-browser/Browser\";\nimport { BrowserError, Failed } from \"effect-browser/BrowserError\";\n\nconst Message = Schema.fromJsonString(\n Schema.Struct({\n id: Schema.optionalKey(Schema.Int),\n sessionId: Schema.optionalKey(Schema.String),\n method: Schema.optionalKey(Schema.String),\n params: Schema.optionalKey(Schema.Unknown),\n result: Schema.optionalKey(Schema.Unknown),\n error: Schema.optionalKey(Schema.Struct({ message: Schema.String })),\n }),\n);\n\nconst Session = Schema.Struct({ sessionId: Schema.String });\n\ntype Listener = Parameters<CaptureSource[\"attach\"]>[1];\n\ninterface Open {\n readonly socket: WebSocket;\n /** Replies awaited, by command id. */\n readonly replies: Map<\n number,\n { readonly resolve: (result: unknown) => void; readonly reject: (error: BrowserError) => void }\n >;\n /** Each attached page's listener, by its session id. */\n readonly sessions: Map<string, Listener>;\n}\n\ntype State =\n | { readonly _tag: \"Idle\" }\n | { readonly _tag: \"Open\"; readonly open: Open }\n | { readonly _tag: \"Closed\" };\n\nconst failure = (detail: string) =>\n new BrowserError({ operation: \"screencast\", reason: new Failed({ detail }), dispatched: false });\n\nconst closing = Duration.seconds(2);\n\n/** The capture connection to the DevTools address `url`, for the scope. */\nexport const make = Effect.fnUntraced(function* (url: Redacted.Redacted<string>) {\n let state: State = { _tag: \"Idle\" };\n let ids = 0;\n const opening = yield* Semaphore.make(1);\n\n // A failure ends every page's session on the connection; the next capture opens another.\n const lose = (open: Open, error: BrowserError) => {\n if (state._tag !== \"Open\" || state.open !== open) return;\n state = { _tag: \"Idle\" };\n for (const reply of open.replies.values()) reply.reject(error);\n for (const listener of open.sessions.values()) listener.lost(error);\n open.replies.clear();\n open.sessions.clear();\n };\n\n const receive = (open: Open, data: unknown) => {\n const decoded = typeof data === \"string\" ? Schema.decodeOption(Message)(data) : Option.none();\n\n if (Option.isNone(decoded))\n return lose(open, failure(\"the capture connection sent a message it could not read\"));\n const { id, sessionId, method, params, result, error } = decoded.value;\n\n if (id !== undefined) {\n const reply = open.replies.get(id);\n\n open.replies.delete(id);\n if (error === undefined) reply?.resolve(result);\n else reply?.reject(failure(error.message));\n } else if (method === undefined) return;\n else if (sessionId !== undefined) open.sessions.get(sessionId)?.event(method, params);\n // The connection's own session announces that a page's session ended.\n else if (method === \"Target.detachedFromTarget\") {\n const detached = Schema.decodeUnknownOption(Session)(params);\n const ended = Option.isSome(detached) ? detached.value.sessionId : \"\";\n const listener = open.sessions.get(ended);\n\n open.sessions.delete(ended);\n listener?.event(method, params);\n }\n };\n\n const send = (\n open: Open,\n method: string,\n params: Record<string, unknown> | undefined,\n sessionId?: string,\n ) => {\n if (state._tag !== \"Open\" || state.open !== open)\n return Promise.reject(failure(\"the capture connection was lost\"));\n const id = ++ids;\n const { promise, resolve, reject } = Promise.withResolvers<unknown>();\n\n open.replies.set(id, { resolve, reject });\n try {\n open.socket.send(JSON.stringify({ id, method, params, sessionId }));\n } catch {\n open.replies.delete(id);\n reject(failure(\"the capture connection could not send\"));\n }\n\n return promise;\n };\n\n const connect = Effect.callback<Open, BrowserError>((resume) => {\n const socket = new WebSocket(Redacted.value(url));\n const open: Open = { socket, replies: new Map(), sessions: new Map() };\n\n const unopened = () => resume(Effect.fail(failure(\"the capture connection did not open\")));\n\n socket.addEventListener(\"close\", unopened, { once: true });\n socket.addEventListener(\n \"open\",\n () => {\n socket.removeEventListener(\"close\", unopened);\n // A scope that closed meanwhile keeps no connection.\n if (state._tag === \"Closed\") {\n socket.close(1000);\n\n return resume(Effect.fail(failure(\"the capture connection is closed\")));\n }\n state = { _tag: \"Open\", open };\n socket.addEventListener(\"close\", () =>\n lose(open, failure(\"the capture connection was lost\")),\n );\n resume(Effect.succeed(open));\n },\n { once: true },\n );\n socket.addEventListener(\"message\", ({ data }: MessageEvent<unknown>) => receive(open, data));\n\n return Effect.sync(() => socket.close(1000));\n });\n\n const current = opening.withPermits(1)(\n Effect.suspend(() =>\n state._tag === \"Open\"\n ? Effect.succeed(state.open)\n : state._tag === \"Closed\"\n ? Effect.fail(failure(\"the capture connection is closed\"))\n : connect,\n ),\n );\n\n const replied = (reply: () => Promise<unknown>) =>\n Effect.tryPromise({\n try: reply,\n catch: (cause) =>\n Schema.is(BrowserError)(cause) ? cause : failure(\"the capture connection failed\"),\n });\n\n const attach: CaptureSource[\"attach\"] = (target, listener) =>\n Effect.gen(function* () {\n const open = yield* current;\n\n const { sessionId } = yield* replied(() =>\n send(open, \"Target.attachToTarget\", { targetId: target, flatten: true }),\n ).pipe(\n Effect.flatMap((result) =>\n Schema.decodeUnknownEffect(Session)(result).pipe(\n Effect.mapError(() => failure(\"the capture connection's attach had no session\")),\n ),\n ),\n );\n\n open.sessions.set(sessionId, listener);\n // Detached as the page's scope closes; a connection that closes detaches every session.\n yield* Effect.addFinalizer(() =>\n Effect.sync(() => {\n if (open.sessions.delete(sessionId))\n void send(open, \"Target.detachFromTarget\", { sessionId }, undefined).catch(\n () => undefined,\n );\n }),\n );\n\n return (method, params) => send(open, method, params, sessionId);\n });\n\n // Closing the scope closes the connection and waits, bounded, until it has closed.\n yield* Effect.addFinalizer(() =>\n Effect.suspend(() => {\n const previous = state;\n\n state = { _tag: \"Closed\" };\n if (previous._tag !== \"Open\") return Effect.void;\n const { socket, replies, sessions } = previous.open;\n\n for (const reply of replies.values()) reply.reject(failure(\"the capture connection closed\"));\n replies.clear();\n sessions.clear();\n\n return Effect.callback<void>((resume) => {\n if (socket.readyState === WebSocket.CLOSED) return resume(Effect.void);\n socket.addEventListener(\"close\", () => resume(Effect.void), { once: true });\n socket.close(1000);\n }).pipe(Effect.timeoutOrElse({ duration: closing, orElse: () => Effect.void }));\n }),\n );\n\n return { attach } satisfies CaptureSource;\n});\n","/**\n * A `Browser` running on Browserbase.\n *\n * `open` creates a session and connects to it over CDP. When its scope closes it disconnects,\n * releases the session and confirms that Browserbase reports it ended, so billing stops then\n * rather than at the session's timeout. `release` does the same sooner and says how it went:\n * `Settled`, or `Unconfirmed` when Browserbase still reported the session running, or could not\n * be asked, at the deadline. Each create carries a nonce of its own in its user metadata, so a\n * session made by a create whose answer was lost is found and ended too, rather than billing\n * unseen until its timeout.\n *\n * A session that persists to a stored context saves to it when the session ends, so two at once\n * can lose one's changes. `open` holds the context through the `ContextLease` the application\n * provides, from before it creates such a session until Browserbase reports the session ended and\n * `contextSettle` has passed, since the save lands later and nothing acknowledges it. A writer that\n * leaves a session that saves to the context possibly running, its release `Unconfirmed`, its\n * create's answer lost or its session kept, leaves the context unsettled: the next writer first ends\n * the context's sessions, which `open` labels in their user metadata, and fails with `ContextHeld`\n * while they can't be confirmed ended. `reconcile` ends them without opening, and `verifyContext`\n * reads a context back under the same hold, from a session that saves nothing.\n *\n * `attach` connects to a session that already runs, as from another process: its pages keep their\n * ids, so a page stored before is found again. `supervise` keeps a session open across losses and\n * session ends, as `Supervisor` generations, and with `keep`, past its own scope, for the next\n * `supervise` to adopt.\n *\n * @since 0.3.0\n */\nimport {\n DateTime,\n Duration,\n Effect,\n Exit,\n Layer,\n Option,\n Random,\n Redacted,\n Schedule,\n Schema,\n Scope,\n} from \"effect\";\nimport * as Browser from \"effect-browser/Browser\";\nimport { BrowserError, Closed } from \"effect-browser/BrowserError\";\nimport * as Cdp from \"effect-browser/Cdp\";\nimport * as Supervisor from \"effect-browser/Supervisor\";\n\nimport {\n BrowserbaseClient,\n type Service,\n type Session,\n type SessionOptions,\n} from \"./BrowserbaseClient.ts\";\nimport { BrowserbaseError, Decode, InvalidRequest, isTransient } from \"./BrowserbaseError.ts\";\nimport { ContextHeld, ContextLease } from \"./ContextLease.ts\";\nimport * as CaptureConnection from \"./internal/captureConnection.ts\";\n\nexport interface Options extends Browser.Options {\n readonly session?: SessionOptions | undefined;\n /** Bound on connecting to the session. Defaults to 30 seconds. */\n readonly connectTimeoutMillis?: number | undefined;\n /**\n * How long a persisting session's context stays held after the session ends, for its save to\n * land. Defaults to 10 seconds, after which hosted checks have read a save back.\n */\n readonly contextSettle?: Duration.Input | undefined;\n /**\n * Run the pages' screencasts on a second connection to the session, which carries nothing else,\n * so that a frame never waits behind a large message, such as an upload or a read's answer, on\n * the connection that drives the page. Defaults to true.\n */\n readonly captureConnection?: boolean | undefined;\n}\n\n/** A browser on a Browserbase session. */\nexport interface Hosted {\n readonly browser: Browser.Service;\n readonly session: Session;\n /**\n * Release the session and confirm it ended, once: `open`'s scope runs it as it closes, while\n * `attach`'s only disconnects. It disconnects `browser` first, which is lost as `released`, so a\n * call in flight or a capture's reader is told so. Asked again, it reports the same outcome.\n */\n readonly release: Effect.Effect<Supervisor.Released>;\n}\n\n/** The user metadata key naming the stored context a persisting session writes to. */\nconst contextLabel = \"persistsContext\";\n\n/** The user metadata key holding each create's own nonce, which finds a session made unseen. */\nconst createLabel = \"createNonce\";\n\n/** The user metadata key naming what a supervisor keeps its sessions under, past its scope. */\nconst keepLabel = \"keptAs\";\n\n/**\n * How long a create whose answer was lost has its session looked for: Browserbase can list a new\n * session late, or still be making it when the client stops waiting.\n */\nconst orphanSearch = Duration.seconds(30);\n\n/** How long a release waits for Browserbase to report the session ended. */\nconst releaseDeadline = Duration.minutes(1);\n\nconst ended = (session: Session) => session.status !== \"PENDING\" && session.status !== \"RUNNING\";\n\n/**\n * End the session and confirm Browserbase reports it ended. The release request and the status\n * reads are each tried again a second apart until the deadline; a session still running then, or\n * one Browserbase could not be asked about, is `Unconfirmed`. Once it has ended, wait `settle`\n * longer, for its context's save to land. It runs to the end once started.\n */\nconst confirm = (client: Service, id: string, settle: Duration.Duration | undefined) =>\n Effect.gen(function* () {\n // What Browserbase last said, for an end it never confirmed.\n let last = \"Browserbase did not answer\";\n\n const heard = (error: BrowserbaseError) => Effect.sync(() => (last = error.message));\n\n const read = client.getSession(id).pipe(\n Effect.tapError(heard),\n Effect.tap((session) => Effect.sync(() => (last = `the session was ${session.status}`))),\n Effect.retry(Schedule.spaced(\"1 second\")),\n Effect.repeat({ until: ended, schedule: Schedule.spaced(\"1 second\") }),\n );\n\n // A release that keeps failing leaves the status reads to tell whether the session ended.\n const confirmed = yield* client.releaseSession(id).pipe(\n Effect.tapError(heard),\n Effect.retry({ while: isTransient, schedule: Schedule.spaced(\"1 second\") }),\n Effect.exit,\n Effect.andThen(read),\n Effect.as(true),\n Effect.timeoutOrElse({ duration: releaseDeadline, orElse: () => Effect.succeed(false) }),\n // The reads are retried until the deadline, so a failure here is the same unconfirmed end.\n Effect.orElseSucceed(() => false),\n );\n\n if (!confirmed)\n return new Supervisor.Unconfirmed({\n detail: `${last} ${Duration.format(releaseDeadline)} after its release`,\n });\n if (settle !== undefined) yield* Effect.sleep(settle);\n\n return new Supervisor.Settled();\n }).pipe(\n Effect.tap((released) => Effect.annotateCurrentSpan({ released: released._tag })),\n Effect.withSpan(\n \"Browserbase.release\",\n { attributes: { session: id, settle: settle !== undefined } },\n { captureStackTrace: false },\n ),\n Effect.uninterruptible,\n );\n\n/** A search for the sessions with `value` under the user metadata key `label`. */\nconst labelled = (label: string, value: string) => `user_metadata['${label}']:'${value}'`;\n\n/**\n * The sessions a search finds that have not ended. Pending ones are listed first, since one listed\n * as pending may be running by the second query.\n */\nconst unended = (client: Service, query: string) =>\n Effect.forEach([\"PENDING\", \"RUNNING\"], (status) => client.listSessions({ status, query })).pipe(\n Effect.map((found) => [\n ...new Map(found.flat().map((session) => [session.id, session])).values(),\n ]),\n );\n\n/**\n * End the sessions and confirm they ended; then wait `settle`, if given, for the last save to land.\n * One still running at its release's deadline makes the outcome `Unconfirmed`.\n */\nconst endAll = (\n client: Service,\n sessions: ReadonlyArray<string>,\n settle: Duration.Duration | undefined,\n) =>\n Effect.forEach(sessions, (session) => confirm(client, session, undefined), {\n concurrency: 4,\n }).pipe(\n Effect.flatMap((outcomes) => {\n const unconfirmed = outcomes.find((outcome) => outcome._tag === \"Unconfirmed\");\n\n return unconfirmed === undefined\n ? Effect.sleep(settle ?? Duration.zero).pipe(\n Effect.as<Supervisor.Released>(new Supervisor.Settled()),\n )\n : Effect.succeed<Supervisor.Released>(unconfirmed);\n }),\n );\n\n/**\n * End the session a create may have made though its answer was lost, found in any state by the\n * create's own label, and then wait `settle`, if given, for its save. Browserbase can list a new\n * session late, so it is looked for again, more and more seldom, until it is found or\n * `orphanSearch` has passed. A search Browserbase never answered is `Unconfirmed`, as is a session\n * still running at its release's deadline.\n */\nconst endOrphan = (client: Service, nonce: string, settle: Duration.Duration | undefined) =>\n Effect.gen(function* () {\n let answered = false;\n\n const found = yield* client.listSessions({ query: labelled(createLabel, nonce) }).pipe(\n Effect.tap(() =>\n Effect.sync(() => {\n answered = true;\n }),\n ),\n Effect.retry(Schedule.exponential(\"1 second\")),\n Effect.repeat({\n schedule: Schedule.exponential(\"1 second\"),\n until: (sessions) => sessions.length > 0,\n }),\n Effect.timeoutOption(orphanSearch),\n );\n\n if (Option.isNone(found) && !answered)\n return new Supervisor.Unconfirmed({\n detail: `Browserbase did not answer a search for it within ${Duration.format(orphanSearch)}`,\n });\n const running = Option.getOrElse(found, () => []).filter((session) => !ended(session));\n\n return yield* endAll(\n client,\n running.map((session) => session.id),\n settle,\n );\n });\n\n/**\n * Hold the stored context through the lease, as its only writer, until the scope closes or the\n * session's end is known; the hold goes once, saying how this writer leaves the context.\n */\nconst holdContext = Effect.fnUntraced(function* (\n client: Service,\n lease: ContextLease[\"Service\"],\n id: string,\n settle: Duration.Duration,\n) {\n const scope = yield* Scope.fork(yield* Effect.scope);\n\n // A second writer waits here for the first one's whole session and the save after it.\n const hold = yield* lease\n .hold(id)\n .pipe(\n Scope.provide(scope),\n Effect.withSpan(\"Browserbase.holdContext\", {}, { captureStackTrace: false }),\n );\n\n // Whether a session that saves to the context may run, as this writer would leave it now.\n let unsettled = hold.unsettled;\n\n const set = (now: boolean) =>\n Effect.sync(() => {\n unsettled = now;\n });\n\n yield* Scope.addFinalizer(\n scope,\n Effect.suspend(() => hold.leave(unsettled)),\n );\n\n const letGo = (now: boolean) => set(now).pipe(Effect.andThen(Scope.close(scope, Exit.void)));\n\n /** End the context's sessions but `except`, found by the label `open` gives them. */\n const end = (except: ReadonlyArray<string>) =>\n unended(client, labelled(contextLabel, id)).pipe(\n Effect.flatMap((found) =>\n endAll(\n client,\n found.map((session) => session.id).filter((session) => !except.includes(session)),\n settle,\n ),\n ),\n Effect.onExit((exit) => set(!(Exit.isSuccess(exit) && exit.value._tag === \"Settled\"))),\n );\n\n const refuse = (outcome: Supervisor.Released) =>\n outcome._tag === \"Settled\"\n ? Effect.void\n : Effect.fail(new ContextHeld({ context: id, detail: outcome.detail }));\n\n return {\n end,\n /**\n * End the sessions, but `except`, that a writer before may have left saving to the context,\n * failing with `ContextHeld` while they can't be confirmed ended.\n */\n clear: (except: ReadonlyArray<string>) =>\n Effect.suspend(() => (unsettled ? Effect.flatMap(end(except), refuse) : Effect.void)),\n /** A session that saves to the context runs from now. */\n writing: set(true),\n /** How the writer's session ended: unconfirmed, it may still save to the context. */\n released: (outcome: Supervisor.Released) => letGo(outcome._tag === \"Unconfirmed\"),\n /** How ending the session a lost create may have made went: unconfirmed, the open fails. */\n lost: (outcome: Supervisor.Released) =>\n letGo(outcome._tag === \"Unconfirmed\").pipe(Effect.andThen(refuse(outcome))),\n /** The writer's session runs on past its scope, saving to the context when it ends. */\n kept: letGo(true),\n };\n});\n\n/** A create that failed so may still have made its session: its answer is lost or unreadable. */\nconst mayHaveCreated = (error: BrowserbaseError) =>\n error.reason._tag === \"Transport\" ||\n error.reason._tag === \"Decode\" ||\n (error.reason._tag === \"Status\" && (error.reason.status >= 500 || error.reason.status === 408));\n\n/** A create's own nonce: two random draws, which no other create draws in practice. */\nconst nonce = Effect.map(Effect.all([Random.nextInt, Random.nextInt]), (draws) =>\n draws.map((draw) => Math.abs(draw).toString(36)).join(\"-\"),\n);\n\n/**\n * The create request, labelled with its own nonce, a persisting session with its context too, so\n * either can be found, and a kept one with what it is kept under, kept alive past disconnecting.\n */\nconst withLabels = (\n session: SessionOptions | undefined,\n own: string,\n context: string | undefined,\n keep: string | undefined,\n) => ({\n ...session,\n ...(keep === undefined ? {} : { keepAlive: true }),\n userMetadata: {\n ...session?.userMetadata,\n [createLabel]: own,\n ...(context === undefined ? {} : { [contextLabel]: context }),\n ...(keep === undefined ? {} : { [keepLabel]: keep }),\n },\n});\n\n/**\n * A release by the browser's owner: it closes the browser first, so that whatever fails then, a\n * capture's reader or a call in flight, says the session was released, and not that the\n * connection Browserbase cuts as the session ends was lost.\n */\nconst releasing = (browser: Scope.Closeable, end: Effect.Effect<Supervisor.Released>) =>\n Scope.close(browser, Exit.void).pipe(Effect.andThen(end));\n\n/**\n * A browser over the session's DevTools address, its pages' screencasts on a capture connection of\n * their own. A DevTools server's HTTP address, as a local Chromium gives in tests, keeps them on\n * each page's own session: there the connection is loopback, and fast. A session that has ended\n * fails `Closed` by the session, with no connect.\n */\nconst connect = Effect.fnUntraced(function* (\n operation: string,\n session: Session,\n options: Options,\n) {\n const endpoint = session.connectUrl;\n\n if (ended(session))\n return yield* new BrowserError({\n operation,\n reason: new Closed({ cause: \"session\" }),\n dispatched: false,\n });\n if (endpoint === undefined)\n return yield* new BrowserbaseError({\n operation,\n reason: new Decode({ detail: `session ${session.id} has no connectUrl` }),\n });\n const apart = options.captureConnection !== false && /^wss?:/i.test(Redacted.value(endpoint));\n\n return yield* Cdp.open({\n ...options,\n endpoint,\n id: session.id,\n provider: \"browserbase\",\n expiresAt: Option.getOrUndefined(DateTime.make(session.expiresAt)),\n capture: apart ? yield* CaptureConnection.make(endpoint) : undefined,\n });\n});\n\n/** How a supervisor keeps its sessions past its scope: under `name`, adopting one first if `adopt`. */\ninterface Keeping {\n readonly name: string;\n readonly adopt: boolean;\n}\n\nconst keepName = /^[\\w.:-]{1,64}$/;\n\nconst newestFirst = (sessions: ReadonlyArray<Session>) => {\n const created = (session: Session) =>\n Option.getOrElse(Option.map(DateTime.make(session.createdAt), DateTime.toEpochMillis), () => 0);\n\n return sessions.toSorted((a, b) => created(b) - created(a));\n};\n\n/**\n * The newest session kept under `name` that saves where this open would, to adopt. Every other\n * session kept under it is to end, since nothing else adopts it: those that save to this open's\n * context are its writers, for the context's hold to end, as `writers` says, and the rest end here.\n */\nconst adoptable = Effect.fnUntraced(function* (\n client: Service,\n name: string,\n persisting: string | undefined,\n) {\n const [newest, ...older] = newestFirst(yield* unended(client, labelled(keepLabel, name)));\n const fits = newest !== undefined && newest.userMetadata?.[contextLabel] === persisting;\n const others = [...(fits || newest === undefined ? [] : [newest]), ...older];\n\n const writes = (session: Session) =>\n persisting !== undefined && session.userMetadata?.[contextLabel] === persisting;\n\n const rest = others.filter((session) => !writes(session));\n\n if (rest.length > 0) {\n const outcome = yield* endAll(\n client,\n rest.map((session) => session.id),\n undefined,\n );\n\n yield* Effect.annotateCurrentSpan({ endedKept: rest.length, endedKeptAs: outcome._tag });\n }\n\n return { adoptee: fits ? newest : undefined, writers: others.some(writes) };\n});\n\n/**\n * Open a browser on a new session, or, when keeping, adopt one a supervisor kept before. A kept\n * session's scope only disconnects, unless it closes on a failure: `release` ends it.\n */\nconst start = Effect.fnUntraced(function* (options: Options, keeping: Keeping | undefined) {\n const client = yield* BrowserbaseClient;\n const lease = yield* ContextLease;\n const context = options.session?.browserSettings?.context;\n const persisting = context?.persist === true ? context.id : undefined;\n const local = yield* Scope.fork(yield* Effect.scope);\n const settle = Duration.fromInputUnsafe(options.contextSettle ?? Duration.seconds(10));\n\n return yield* Effect.gen(function* () {\n if (keeping !== undefined && !keepName.test(keeping.name))\n return yield* new BrowserbaseError({\n operation: \"supervise\",\n reason: new InvalidRequest({\n detail: `keep must be 1 to 64 letters, digits, \"_\", \".\", \":\" or \"-\"`,\n }),\n });\n\n const writing =\n persisting === undefined ? undefined : yield* holdContext(client, lease, persisting, settle);\n\n const adoption = keeping?.adopt\n ? yield* adoptable(client, keeping.name, persisting)\n : undefined;\n\n const adopted = adoption?.adoptee;\n\n // Another writer kept under the name may still save to the context: clear it as any other.\n if (adoption?.writers === true) yield* writing?.writing ?? Effect.void;\n yield* writing?.clear(adopted === undefined ? [] : [adopted.id]) ?? Effect.void;\n const connected = yield* Scope.fork(local);\n const own = yield* nonce;\n\n // Releasing ends the session; leaving, as a kept session's scope does, only disconnects.\n const ending = (session: Session) =>\n Effect.gen(function* () {\n let asked = false;\n\n const release = yield* Effect.cached(\n Effect.suspend(() => {\n asked = true;\n\n return releasing(connected, confirm(client, session.id, writing && settle)).pipe(\n Effect.tap((outcome) => writing?.released(outcome) ?? Effect.void),\n );\n }),\n );\n\n const leave = Effect.suspend(() =>\n asked\n ? Effect.void\n : Scope.close(connected, Exit.void).pipe(Effect.andThen(writing?.kept ?? Effect.void)),\n );\n\n return { session, release, leave };\n });\n\n const made = yield* Effect.acquireRelease(\n Effect.gen(function* () {\n const session =\n adopted === undefined\n ? yield* client.createSession(\n withLabels(options.session, own, persisting, keeping?.name),\n )\n : yield* client.getSession(adopted.id);\n\n yield* writing?.writing ?? Effect.void;\n\n return yield* ending(session);\n }),\n ({ release, leave }, exit) =>\n keeping !== undefined && Exit.isSuccess(exit) ? leave : Effect.asVoid(release),\n ).pipe(\n // A session nobody can see bills until its timeout, and one that saves to the context would\n // write beside the next writer: end it, found by its create's own label.\n Effect.tapError((error) =>\n adopted === undefined && mayHaveCreated(error)\n ? endOrphan(client, own, writing && settle).pipe(\n Effect.flatMap((outcome) => writing?.lost(outcome) ?? Effect.void),\n )\n : Effect.void,\n ),\n );\n\n const { session, release } = made;\n\n yield* Effect.annotateCurrentSpan({\n session: session.id,\n region: session.region,\n adopted: adopted !== undefined,\n });\n\n const browser = yield* connect(\n adopted === undefined ? \"open\" : \"attach\",\n session,\n options,\n ).pipe(Scope.provide(connected));\n\n return { browser, session, release } satisfies Hosted;\n }).pipe(\n Scope.provide(local),\n Effect.onError((cause) => Scope.close(local, Exit.failCause(cause))),\n );\n});\n\n/**\n * Create a session and open a `Browser` on it, for as long as the scope is open. If opening\n * fails, the session and context are released then, so a retry in the same scope can take them.\n * A persisting open holds its context through the `ContextLease`; a session that may still save\n * to it, as one whose release was left `Unconfirmed` or whose create's answer was lost, is ended\n * first, and the open fails with `ContextHeld` while that can't be confirmed. A lost create's own\n * open looks for its session by the create's nonce, within `orphanSearch`, ends it, then fails with\n * the create's error. `release` disconnects the browser before it asks Browserbase to end the\n * session, so what fails meanwhile says it was released.\n */\nexport const open = Effect.fn(\"Browserbase.open\")(function* (options: Options = {}) {\n return yield* start(options, undefined);\n});\n\n/**\n * Open a `Browser` on a session that already runs, such as a `keepAlive` session another process\n * opened. This is resume: its pages keep their ids, their CDP target ids, so `browser.page(id)`\n * finds a page stored before. Closing the scope disconnects and leaves the session running;\n * `release` ends it. A session that has ended fails `Closed` by the session. It holds no context.\n */\nexport const attach = Effect.fn(\"Browserbase.attach\")(function* (\n sessionId: string,\n options: Options = {},\n) {\n const client = yield* BrowserbaseClient;\n const session = yield* client.getSession(sessionId);\n\n yield* Effect.annotateCurrentSpan({ session: session.id, region: session.region });\n\n const connected = yield* Scope.fork(yield* Effect.scope);\n const browser = yield* connect(\"attach\", session, options).pipe(Scope.provide(connected));\n\n const release = yield* Effect.cached(\n releasing(connected, confirm(client, session.id, undefined)),\n );\n\n return { browser, session, release } satisfies Hosted;\n});\n\n/**\n * End a stored context's sessions, the ones `open` labelled as writing to it, and let the context\n * go once they are confirmed ended and its save has settled. `open` does this itself when a writer\n * before it may still run; `reconcile` does it without opening, as for sessions another process\n * left running. It holds the context through the `ContextLease`, so it waits for a writer. A\n * session still running at the deadline makes it `Unconfirmed`, and leaves the context unsettled,\n * as a failure does.\n */\nexport const reconcile = Effect.fn(\"Browserbase.reconcile\")(function* (\n contextId: string,\n options: { readonly contextSettle?: Duration.Input | undefined } = {},\n) {\n const client = yield* BrowserbaseClient;\n const lease = yield* ContextLease;\n const settle = Duration.fromInputUnsafe(options.contextSettle ?? Duration.seconds(10));\n\n // Reading the context first refuses an id that is not one before it reaches the query.\n yield* client.getContext(contextId);\n const hold = yield* holdContext(client, lease, contextId, settle);\n\n return yield* hold.end([]);\n}, Effect.scoped);\n\n/**\n * Read a stored context back, as a login: a session that loads it and saves nothing runs `check`\n * on its browser, and is released. The context is held through the `ContextLease` meanwhile, so\n * the read never runs beside a writer, which a site could sign out, and it reads what the last\n * writer saved, once that save settled. A session a writer before may have left saving to it is\n * ended first, as for `open`.\n */\nexport const verifyContext = Effect.fn(\"Browserbase.verifyContext\")(function* <A, E, R>(\n contextId: string,\n check: (browser: Browser.Service) => Effect.Effect<A, E, R>,\n options: Options = {},\n) {\n const client = yield* BrowserbaseClient;\n const lease = yield* ContextLease;\n const settle = Duration.fromInputUnsafe(options.contextSettle ?? Duration.seconds(10));\n const reading = yield* holdContext(client, lease, contextId, settle);\n\n yield* reading.clear([]);\n\n const { browser } = yield* start(\n {\n ...options,\n session: {\n ...options.session,\n browserSettings: {\n ...options.session?.browserSettings,\n context: { id: contextId, persist: false },\n },\n },\n },\n undefined,\n );\n\n return yield* check(browser);\n}, Effect.scoped);\n\nexport interface SuperviseOptions<A = Session, E = never, R = never>\n extends\n Options,\n Pick<\n Supervisor.Options<\n BrowserError | BrowserbaseError | ContextHeld | E,\n BrowserbaseClient | ContextLease | R,\n A\n >,\n \"reopen\" | \"rotateBefore\" | \"waitTimeout\" | \"handover\"\n > {\n /**\n * Keep the session past the supervisor's scope, under this name: 1 to 64 letters, digits, `_`,\n * `.`, `:` or `-`. Each session is created with `keepAlive` and labelled `keptAs: <keep>` in its\n * user metadata. Closing the scope only disconnects the current one, published as `Kept`, and\n * the first generation of the next `supervise` under the same name adopts it, with its pages,\n * rather than creating a session; other sessions kept under it are ended. `retire` releases. A\n * kept session bills until it is adopted and released, or until its timeout ends it.\n */\n readonly keep?: string | undefined;\n /** Build the generation's value in its scope. Without a builder, its value is its Session. */\n readonly build?: ((hosted: Hosted) => Effect.Effect<A, E, R>) | undefined;\n}\n\n/**\n * Browserbase refused the request: no new try mends a refused key, request or id. A context held\n * is not among them, since each try ends its sessions again.\n */\nconst refused = (error: unknown) =>\n Schema.is(BrowserbaseError)(error) && !isTransient(error) && error.reason._tag !== \"Decode\";\n\n/**\n * Keep Browserbase sessions open as `Supervisor` generations, each a new session made from\n * `session`. Sessions that persist to a stored context are exclusive: a rotation releases the\n * current one, and its context's save settles, before the next one opens. An open Browserbase\n * refused, as for a bad key or an invalid request, is `Down` at once. With `keep`, closing the\n * scope leaves the current session running for the next `supervise` under that name to adopt.\n */\nexport function supervise<A, E, R>(\n options: SuperviseOptions<A, E, R> & {\n readonly build: (hosted: Hosted) => Effect.Effect<A, E, R>;\n },\n): Effect.Effect<\n Supervisor.Supervisor<A>,\n never,\n Scope.Scope | BrowserbaseClient | ContextLease | Exclude<R, Scope.Scope>\n>;\n\nexport function supervise<A = Session, E = never, R = never>(\n options?: SuperviseOptions<A, E, R>,\n): Effect.Effect<\n Supervisor.Supervisor<A | Session>,\n never,\n Scope.Scope | BrowserbaseClient | ContextLease | Exclude<R, Scope.Scope>\n>;\n\nexport function supervise<A = Session, E = never, R = never>(\n options: SuperviseOptions<A, E, R> = {},\n) {\n return Effect.suspend(() => {\n const { keep } = options;\n // Only the first generation adopts a kept session: a later one would find its own.\n let opened = false;\n\n return Supervisor.make({\n open: Effect.gen(function* () {\n const hosted = yield* start(\n options,\n keep === undefined ? undefined : { name: keep, adopt: !opened },\n );\n\n opened = true;\n // The generation owns resources acquired by build, including on failure or cancellation.\n const value = options.build === undefined ? hosted.session : yield* options.build(hosted);\n\n return { ...hosted, value };\n }).pipe(Effect.withSpan(\"Browserbase.open\", {}, { captureStackTrace: false })),\n exclusive: options.session?.browserSettings?.context?.persist === true,\n keep: keep !== undefined,\n reopen: options.reopen,\n definite: refused,\n rotateBefore: options.rotateBefore,\n waitTimeout: options.waitTimeout,\n handover: options.handover,\n });\n });\n}\n\nexport const layer = (\n options: Options = {},\n): Layer.Layer<\n Browser.Browser,\n BrowserError | BrowserbaseError | ContextHeld,\n BrowserbaseClient | ContextLease\n> =>\n Layer.effect(\n Browser.Browser,\n Effect.map(open(options), ({ browser }) => browser),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,UAAU,OAAO,eACrB,OAAO,OAAO;CACZ,IAAI,OAAO,YAAY,OAAO,GAAG;CACjC,WAAW,OAAO,YAAY,OAAO,MAAM;CAC3C,QAAQ,OAAO,YAAY,OAAO,MAAM;CACxC,QAAQ,OAAO,YAAY,OAAO,OAAO;CACzC,QAAQ,OAAO,YAAY,OAAO,OAAO;CACzC,OAAO,OAAO,YAAY,OAAO,OAAO,EAAE,SAAS,OAAO,OAAO,CAAC,CAAC;AACrE,CAAC,CACH;A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UAAqC,CAAC,GACtC;CACA,OAAO,OAAO,cAAc;EAC1B,MAAM,EAAE,SAAS;EAEjB,IAAI,SAAS;EAEb,OAAO,WAAW,KAAK;GACrB,MAAM,OAAO,IAAI,aAAa;IAC5B,MAAM,SAAS,OAAO,MACpB,SACA,SAAS,KAAA,IAAY,KAAA,IAAY;KAAE,MAAM;KAAM,OAAO,CAAC;IAAO,CAChE;IAEA,SAAS;IAET,MAAM,QAAQ,QAAQ,UAAU,KAAA,IAAY,OAAO,UAAU,OAAO,QAAQ,MAAM,MAAM;IAExF,OAAO;KAAE,GAAG;KAAQ;IAAM;GAC5B,CAAC,CAAC,CAAC,KAAK,OAAO,SAAS,oBAAoB,CAAC,GAAG,EAAE,mBAAmB,MAAM,CAAC,CAAC;GAC7E,WAAW,QAAQ,SAAS,iBAAiB,SAAS,YAAY;GAClE,MAAM,SAAS,KAAA;GACf,QAAQ,QAAQ;GAChB,UAAU;GACV,cAAc,QAAQ;GACtB,aAAa,QAAQ;GACrB,UAAU,QAAQ;EACpB,CAAC;CACH,CAAC;AACH;AAEA,MAAa,SACX,UAAmB,CAAC,MAMpB,MAAM,OACJ,QAAQ,SACR,OAAO,IAAI,KAAK,OAAO,IAAI,EAAE,cAAc,OAAO,CACpD"}
@@ -80,7 +80,7 @@ export declare const reconcile: (contextId: string, options?: {
80
80
  * ended first, as for `open`.
81
81
  */
82
82
  export declare const verifyContext: <A, E, R>(contextId: string, check: (browser: Browser.Service) => Effect.Effect<A, E, R>, options?: Options | undefined) => Effect.Effect<A, E | BrowserError | BrowserbaseError | ContextHeld, BrowserbaseClient | ContextLease | Exclude<R, Scope.Scope>>;
83
- export interface SuperviseOptions extends Options, Pick<Supervisor.Options<BrowserError | BrowserbaseError | ContextHeld, BrowserbaseClient>, "reopen" | "rotateBefore" | "waitTimeout"> {
83
+ export interface SuperviseOptions<A = Session, E = never, R = never> extends Options, Pick<Supervisor.Options<BrowserError | BrowserbaseError | ContextHeld | E, BrowserbaseClient | ContextLease | R, A>, "reopen" | "rotateBefore" | "waitTimeout" | "handover"> {
84
84
  /**
85
85
  * Keep the session past the supervisor's scope, under this name: 1 to 64 letters, digits, `_`,
86
86
  * `.`, `:` or `-`. Each session is created with `keepAlive` and labelled `keptAs: <keep>` in its
@@ -90,6 +90,8 @@ export interface SuperviseOptions extends Options, Pick<Supervisor.Options<Brows
90
90
  * kept session bills until it is adopted and released, or until its timeout ends it.
91
91
  */
92
92
  readonly keep?: string | undefined;
93
+ /** Build the generation's value in its scope. Without a builder, its value is its Session. */
94
+ readonly build?: ((hosted: Hosted) => Effect.Effect<A, E, R>) | undefined;
93
95
  }
94
96
  /**
95
97
  * Keep Browserbase sessions open as `Supervisor` generations, each a new session made from
@@ -98,7 +100,10 @@ export interface SuperviseOptions extends Options, Pick<Supervisor.Options<Brows
98
100
  * refused, as for a bad key or an invalid request, is `Down` at once. With `keep`, closing the
99
101
  * scope leaves the current session running for the next `supervise` under that name to adopt.
100
102
  */
101
- export declare const supervise: (options?: SuperviseOptions) => Effect.Effect<Supervisor.Supervisor, never, BrowserbaseClient | ContextLease | Scope.Scope>;
103
+ export declare function supervise<A, E, R>(options: SuperviseOptions<A, E, R> & {
104
+ readonly build: (hosted: Hosted) => Effect.Effect<A, E, R>;
105
+ }): Effect.Effect<Supervisor.Supervisor<A>, never, Scope.Scope | BrowserbaseClient | ContextLease | Exclude<R, Scope.Scope>>;
106
+ export declare function supervise<A = Session, E = never, R = never>(options?: SuperviseOptions<A, E, R>): Effect.Effect<Supervisor.Supervisor<A | Session>, never, Scope.Scope | BrowserbaseClient | ContextLease | Exclude<R, Scope.Scope>>;
102
107
  export declare const layer: (options?: Options) => Layer.Layer<Browser.Browser, BrowserError | BrowserbaseError | ContextHeld, BrowserbaseClient | ContextLease>;
103
108
  //#endregion
104
109
  export { Browserbase_d_exports as t };
@@ -1,3 +1,3 @@
1
1
  import "./ContextLease.mjs";
2
- import { a as reconcile, i as open, n as attach, o as supervise, r as layer, s as verifyContext } from "./Browserbase-FDltiz36.mjs";
2
+ import { a as reconcile, i as open, n as attach, o as supervise, r as layer, s as verifyContext } from "./Browserbase-CaPKwEY9.mjs";
3
3
  export { attach, layer, open, reconcile, supervise, verifyContext };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as BrowserbaseError_exports } from "./BrowserbaseError.mjs";
2
2
  import { t as BrowserbaseClient_exports } from "./BrowserbaseClient.mjs";
3
3
  import { t as ContextLease_exports } from "./ContextLease.mjs";
4
- import { t as Browserbase_exports } from "./Browserbase-FDltiz36.mjs";
4
+ import { t as Browserbase_exports } from "./Browserbase-CaPKwEY9.mjs";
5
5
  export { Browserbase_exports as Browserbase, BrowserbaseClient_exports as BrowserbaseClient, BrowserbaseError_exports as BrowserbaseError, ContextLease_exports as ContextLease };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-browserbase",
3
- "version": "0.3.0-beta.6",
3
+ "version": "0.3.0-beta.8",
4
4
  "description": "Browserbase for effect-browser: hosted browser sessions, contexts, web search and page fetch.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -58,7 +58,7 @@
58
58
  "@effect/vitest": "4.0.0",
59
59
  "@types/node": "26.1.2",
60
60
  "effect": "4.0.0",
61
- "effect-browser": "0.3.0-beta.6",
61
+ "effect-browser": "0.3.0-beta.8",
62
62
  "playwright-core": "1.63.0",
63
63
  "typescript": "7.0.2",
64
64
  "vite": "npm:@voidzero-dev/vite-plus-core@1.1.0",
@@ -67,7 +67,7 @@
67
67
  },
68
68
  "peerDependencies": {
69
69
  "effect": "~4.0.0",
70
- "effect-browser": "^0.3.0-beta.6",
70
+ "effect-browser": "^0.3.0-beta.8",
71
71
  "playwright-core": "^1.63.0"
72
72
  },
73
73
  "engines": {
@@ -36,6 +36,7 @@ import {
36
36
  Random,
37
37
  Redacted,
38
38
  Schedule,
39
+ Schema,
39
40
  Scope,
40
41
  } from "effect";
41
42
  import * as Browser from "effect-browser/Browser";
@@ -627,12 +628,16 @@ export const verifyContext = Effect.fn("Browserbase.verifyContext")(function* <A
627
628
  return yield* check(browser);
628
629
  }, Effect.scoped);
629
630
 
630
- export interface SuperviseOptions
631
+ export interface SuperviseOptions<A = Session, E = never, R = never>
631
632
  extends
632
633
  Options,
633
634
  Pick<
634
- Supervisor.Options<BrowserError | BrowserbaseError | ContextHeld, BrowserbaseClient>,
635
- "reopen" | "rotateBefore" | "waitTimeout"
635
+ Supervisor.Options<
636
+ BrowserError | BrowserbaseError | ContextHeld | E,
637
+ BrowserbaseClient | ContextLease | R,
638
+ A
639
+ >,
640
+ "reopen" | "rotateBefore" | "waitTimeout" | "handover"
636
641
  > {
637
642
  /**
638
643
  * Keep the session past the supervisor's scope, under this name: 1 to 64 letters, digits, `_`,
@@ -643,14 +648,16 @@ export interface SuperviseOptions
643
648
  * kept session bills until it is adopted and released, or until its timeout ends it.
644
649
  */
645
650
  readonly keep?: string | undefined;
651
+ /** Build the generation's value in its scope. Without a builder, its value is its Session. */
652
+ readonly build?: ((hosted: Hosted) => Effect.Effect<A, E, R>) | undefined;
646
653
  }
647
654
 
648
655
  /**
649
656
  * Browserbase refused the request: no new try mends a refused key, request or id. A context held
650
657
  * is not among them, since each try ends its sessions again.
651
658
  */
652
- const refused = (error: BrowserError | BrowserbaseError | ContextHeld) =>
653
- error._tag === "BrowserbaseError" && !isTransient(error) && error.reason._tag !== "Decode";
659
+ const refused = (error: unknown) =>
660
+ Schema.is(BrowserbaseError)(error) && !isTransient(error) && error.reason._tag !== "Decode";
654
661
 
655
662
  /**
656
663
  * Keep Browserbase sessions open as `Supervisor` generations, each a new session made from
@@ -659,31 +666,55 @@ const refused = (error: BrowserError | BrowserbaseError | ContextHeld) =>
659
666
  * refused, as for a bad key or an invalid request, is `Down` at once. With `keep`, closing the
660
667
  * scope leaves the current session running for the next `supervise` under that name to adopt.
661
668
  */
662
- export const supervise = (options: SuperviseOptions = {}) =>
663
- Effect.suspend(() => {
669
+ export function supervise<A, E, R>(
670
+ options: SuperviseOptions<A, E, R> & {
671
+ readonly build: (hosted: Hosted) => Effect.Effect<A, E, R>;
672
+ },
673
+ ): Effect.Effect<
674
+ Supervisor.Supervisor<A>,
675
+ never,
676
+ Scope.Scope | BrowserbaseClient | ContextLease | Exclude<R, Scope.Scope>
677
+ >;
678
+
679
+ export function supervise<A = Session, E = never, R = never>(
680
+ options?: SuperviseOptions<A, E, R>,
681
+ ): Effect.Effect<
682
+ Supervisor.Supervisor<A | Session>,
683
+ never,
684
+ Scope.Scope | BrowserbaseClient | ContextLease | Exclude<R, Scope.Scope>
685
+ >;
686
+
687
+ export function supervise<A = Session, E = never, R = never>(
688
+ options: SuperviseOptions<A, E, R> = {},
689
+ ) {
690
+ return Effect.suspend(() => {
664
691
  const { keep } = options;
665
692
  // Only the first generation adopts a kept session: a later one would find its own.
666
693
  let opened = false;
667
694
 
668
695
  return Supervisor.make({
669
- open: Effect.suspend(() =>
670
- start(options, keep === undefined ? undefined : { name: keep, adopt: !opened }),
671
- ).pipe(
672
- Effect.tap(() =>
673
- Effect.sync(() => {
674
- opened = true;
675
- }),
676
- ),
677
- Effect.withSpan("Browserbase.open", {}, { captureStackTrace: false }),
678
- ),
696
+ open: Effect.gen(function* () {
697
+ const hosted = yield* start(
698
+ options,
699
+ keep === undefined ? undefined : { name: keep, adopt: !opened },
700
+ );
701
+
702
+ opened = true;
703
+ // The generation owns resources acquired by build, including on failure or cancellation.
704
+ const value = options.build === undefined ? hosted.session : yield* options.build(hosted);
705
+
706
+ return { ...hosted, value };
707
+ }).pipe(Effect.withSpan("Browserbase.open", {}, { captureStackTrace: false })),
679
708
  exclusive: options.session?.browserSettings?.context?.persist === true,
680
709
  keep: keep !== undefined,
681
710
  reopen: options.reopen,
682
711
  definite: refused,
683
712
  rotateBefore: options.rotateBefore,
684
713
  waitTimeout: options.waitTimeout,
714
+ handover: options.handover,
685
715
  });
686
716
  });
717
+ }
687
718
 
688
719
  export const layer = (
689
720
  options: Options = {},
@@ -1 +0,0 @@
1
- {"version":3,"file":"Browserbase-FDltiz36.mjs","names":["CaptureConnection.make"],"sources":["../src/internal/captureConnection.ts","../src/Browserbase.ts"],"sourcesContent":["/**\n * The capture connection: a second DevTools connection to a session, for its pages' screencasts\n * alone. A frame and its acknowledgement then never wait behind a large message on the\n * connection Playwright drives the pages over, such as an upload or a read's answer: Browserbase\n * refuses compression, and on air those waits stopped the picture for as long as the message took\n * to cross.\n *\n * Raw CDP over the global WebSocket, with no Playwright. A page's session on it sends only the\n * capture's commands, and receives that page's events. The connection opens as the first capture\n * starts and stays until the scope closes, which closes it and waits, bounded, for it to close;\n * one that fails ends every page's session on it, and the next capture opens another.\n */\nimport { Duration, Effect, Option, Redacted, Schema, Semaphore } from \"effect\";\nimport type { CaptureSource } from \"effect-browser/Browser\";\nimport { BrowserError, Failed } from \"effect-browser/BrowserError\";\n\nconst Message = Schema.fromJsonString(\n Schema.Struct({\n id: Schema.optionalKey(Schema.Int),\n sessionId: Schema.optionalKey(Schema.String),\n method: Schema.optionalKey(Schema.String),\n params: Schema.optionalKey(Schema.Unknown),\n result: Schema.optionalKey(Schema.Unknown),\n error: Schema.optionalKey(Schema.Struct({ message: Schema.String })),\n }),\n);\n\nconst Session = Schema.Struct({ sessionId: Schema.String });\n\ntype Listener = Parameters<CaptureSource[\"attach\"]>[1];\n\ninterface Open {\n readonly socket: WebSocket;\n /** Replies awaited, by command id. */\n readonly replies: Map<\n number,\n { readonly resolve: (result: unknown) => void; readonly reject: (error: BrowserError) => void }\n >;\n /** Each attached page's listener, by its session id. */\n readonly sessions: Map<string, Listener>;\n}\n\ntype State =\n | { readonly _tag: \"Idle\" }\n | { readonly _tag: \"Open\"; readonly open: Open }\n | { readonly _tag: \"Closed\" };\n\nconst failure = (detail: string) =>\n new BrowserError({ operation: \"screencast\", reason: new Failed({ detail }), dispatched: false });\n\nconst closing = Duration.seconds(2);\n\n/** The capture connection to the DevTools address `url`, for the scope. */\nexport const make = Effect.fnUntraced(function* (url: Redacted.Redacted<string>) {\n let state: State = { _tag: \"Idle\" };\n let ids = 0;\n const opening = yield* Semaphore.make(1);\n\n // A failure ends every page's session on the connection; the next capture opens another.\n const lose = (open: Open, error: BrowserError) => {\n if (state._tag !== \"Open\" || state.open !== open) return;\n state = { _tag: \"Idle\" };\n for (const reply of open.replies.values()) reply.reject(error);\n for (const listener of open.sessions.values()) listener.lost(error);\n open.replies.clear();\n open.sessions.clear();\n };\n\n const receive = (open: Open, data: unknown) => {\n const decoded = typeof data === \"string\" ? Schema.decodeOption(Message)(data) : Option.none();\n\n if (Option.isNone(decoded))\n return lose(open, failure(\"the capture connection sent a message it could not read\"));\n const { id, sessionId, method, params, result, error } = decoded.value;\n\n if (id !== undefined) {\n const reply = open.replies.get(id);\n\n open.replies.delete(id);\n if (error === undefined) reply?.resolve(result);\n else reply?.reject(failure(error.message));\n } else if (method === undefined) return;\n else if (sessionId !== undefined) open.sessions.get(sessionId)?.event(method, params);\n // The connection's own session announces that a page's session ended.\n else if (method === \"Target.detachedFromTarget\") {\n const detached = Schema.decodeUnknownOption(Session)(params);\n const ended = Option.isSome(detached) ? detached.value.sessionId : \"\";\n const listener = open.sessions.get(ended);\n\n open.sessions.delete(ended);\n listener?.event(method, params);\n }\n };\n\n const send = (\n open: Open,\n method: string,\n params: Record<string, unknown> | undefined,\n sessionId?: string,\n ) => {\n if (state._tag !== \"Open\" || state.open !== open)\n return Promise.reject(failure(\"the capture connection was lost\"));\n const id = ++ids;\n const { promise, resolve, reject } = Promise.withResolvers<unknown>();\n\n open.replies.set(id, { resolve, reject });\n try {\n open.socket.send(JSON.stringify({ id, method, params, sessionId }));\n } catch {\n open.replies.delete(id);\n reject(failure(\"the capture connection could not send\"));\n }\n\n return promise;\n };\n\n const connect = Effect.callback<Open, BrowserError>((resume) => {\n const socket = new WebSocket(Redacted.value(url));\n const open: Open = { socket, replies: new Map(), sessions: new Map() };\n\n const unopened = () => resume(Effect.fail(failure(\"the capture connection did not open\")));\n\n socket.addEventListener(\"close\", unopened, { once: true });\n socket.addEventListener(\n \"open\",\n () => {\n socket.removeEventListener(\"close\", unopened);\n // A scope that closed meanwhile keeps no connection.\n if (state._tag === \"Closed\") {\n socket.close(1000);\n\n return resume(Effect.fail(failure(\"the capture connection is closed\")));\n }\n state = { _tag: \"Open\", open };\n socket.addEventListener(\"close\", () =>\n lose(open, failure(\"the capture connection was lost\")),\n );\n resume(Effect.succeed(open));\n },\n { once: true },\n );\n socket.addEventListener(\"message\", ({ data }: MessageEvent<unknown>) => receive(open, data));\n\n return Effect.sync(() => socket.close(1000));\n });\n\n const current = opening.withPermits(1)(\n Effect.suspend(() =>\n state._tag === \"Open\"\n ? Effect.succeed(state.open)\n : state._tag === \"Closed\"\n ? Effect.fail(failure(\"the capture connection is closed\"))\n : connect,\n ),\n );\n\n const replied = (reply: () => Promise<unknown>) =>\n Effect.tryPromise({\n try: reply,\n catch: (cause) =>\n Schema.is(BrowserError)(cause) ? cause : failure(\"the capture connection failed\"),\n });\n\n const attach: CaptureSource[\"attach\"] = (target, listener) =>\n Effect.gen(function* () {\n const open = yield* current;\n\n const { sessionId } = yield* replied(() =>\n send(open, \"Target.attachToTarget\", { targetId: target, flatten: true }),\n ).pipe(\n Effect.flatMap((result) =>\n Schema.decodeUnknownEffect(Session)(result).pipe(\n Effect.mapError(() => failure(\"the capture connection's attach had no session\")),\n ),\n ),\n );\n\n open.sessions.set(sessionId, listener);\n // Detached as the page's scope closes; a connection that closes detaches every session.\n yield* Effect.addFinalizer(() =>\n Effect.sync(() => {\n if (open.sessions.delete(sessionId))\n void send(open, \"Target.detachFromTarget\", { sessionId }, undefined).catch(\n () => undefined,\n );\n }),\n );\n\n return (method, params) => send(open, method, params, sessionId);\n });\n\n // Closing the scope closes the connection and waits, bounded, until it has closed.\n yield* Effect.addFinalizer(() =>\n Effect.suspend(() => {\n const previous = state;\n\n state = { _tag: \"Closed\" };\n if (previous._tag !== \"Open\") return Effect.void;\n const { socket, replies, sessions } = previous.open;\n\n for (const reply of replies.values()) reply.reject(failure(\"the capture connection closed\"));\n replies.clear();\n sessions.clear();\n\n return Effect.callback<void>((resume) => {\n if (socket.readyState === WebSocket.CLOSED) return resume(Effect.void);\n socket.addEventListener(\"close\", () => resume(Effect.void), { once: true });\n socket.close(1000);\n }).pipe(Effect.timeoutOrElse({ duration: closing, orElse: () => Effect.void }));\n }),\n );\n\n return { attach } satisfies CaptureSource;\n});\n","/**\n * A `Browser` running on Browserbase.\n *\n * `open` creates a session and connects to it over CDP. When its scope closes it disconnects,\n * releases the session and confirms that Browserbase reports it ended, so billing stops then\n * rather than at the session's timeout. `release` does the same sooner and says how it went:\n * `Settled`, or `Unconfirmed` when Browserbase still reported the session running, or could not\n * be asked, at the deadline. Each create carries a nonce of its own in its user metadata, so a\n * session made by a create whose answer was lost is found and ended too, rather than billing\n * unseen until its timeout.\n *\n * A session that persists to a stored context saves to it when the session ends, so two at once\n * can lose one's changes. `open` holds the context through the `ContextLease` the application\n * provides, from before it creates such a session until Browserbase reports the session ended and\n * `contextSettle` has passed, since the save lands later and nothing acknowledges it. A writer that\n * leaves a session that saves to the context possibly running, its release `Unconfirmed`, its\n * create's answer lost or its session kept, leaves the context unsettled: the next writer first ends\n * the context's sessions, which `open` labels in their user metadata, and fails with `ContextHeld`\n * while they can't be confirmed ended. `reconcile` ends them without opening, and `verifyContext`\n * reads a context back under the same hold, from a session that saves nothing.\n *\n * `attach` connects to a session that already runs, as from another process: its pages keep their\n * ids, so a page stored before is found again. `supervise` keeps a session open across losses and\n * session ends, as `Supervisor` generations, and with `keep`, past its own scope, for the next\n * `supervise` to adopt.\n *\n * @since 0.3.0\n */\nimport {\n DateTime,\n Duration,\n Effect,\n Exit,\n Layer,\n Option,\n Random,\n Redacted,\n Schedule,\n Scope,\n} from \"effect\";\nimport * as Browser from \"effect-browser/Browser\";\nimport { BrowserError, Closed } from \"effect-browser/BrowserError\";\nimport * as Cdp from \"effect-browser/Cdp\";\nimport * as Supervisor from \"effect-browser/Supervisor\";\n\nimport {\n BrowserbaseClient,\n type Service,\n type Session,\n type SessionOptions,\n} from \"./BrowserbaseClient.ts\";\nimport { BrowserbaseError, Decode, InvalidRequest, isTransient } from \"./BrowserbaseError.ts\";\nimport { ContextHeld, ContextLease } from \"./ContextLease.ts\";\nimport * as CaptureConnection from \"./internal/captureConnection.ts\";\n\nexport interface Options extends Browser.Options {\n readonly session?: SessionOptions | undefined;\n /** Bound on connecting to the session. Defaults to 30 seconds. */\n readonly connectTimeoutMillis?: number | undefined;\n /**\n * How long a persisting session's context stays held after the session ends, for its save to\n * land. Defaults to 10 seconds, after which hosted checks have read a save back.\n */\n readonly contextSettle?: Duration.Input | undefined;\n /**\n * Run the pages' screencasts on a second connection to the session, which carries nothing else,\n * so that a frame never waits behind a large message, such as an upload or a read's answer, on\n * the connection that drives the page. Defaults to true.\n */\n readonly captureConnection?: boolean | undefined;\n}\n\n/** A browser on a Browserbase session. */\nexport interface Hosted {\n readonly browser: Browser.Service;\n readonly session: Session;\n /**\n * Release the session and confirm it ended, once: `open`'s scope runs it as it closes, while\n * `attach`'s only disconnects. It disconnects `browser` first, which is lost as `released`, so a\n * call in flight or a capture's reader is told so. Asked again, it reports the same outcome.\n */\n readonly release: Effect.Effect<Supervisor.Released>;\n}\n\n/** The user metadata key naming the stored context a persisting session writes to. */\nconst contextLabel = \"persistsContext\";\n\n/** The user metadata key holding each create's own nonce, which finds a session made unseen. */\nconst createLabel = \"createNonce\";\n\n/** The user metadata key naming what a supervisor keeps its sessions under, past its scope. */\nconst keepLabel = \"keptAs\";\n\n/**\n * How long a create whose answer was lost has its session looked for: Browserbase can list a new\n * session late, or still be making it when the client stops waiting.\n */\nconst orphanSearch = Duration.seconds(30);\n\n/** How long a release waits for Browserbase to report the session ended. */\nconst releaseDeadline = Duration.minutes(1);\n\nconst ended = (session: Session) => session.status !== \"PENDING\" && session.status !== \"RUNNING\";\n\n/**\n * End the session and confirm Browserbase reports it ended. The release request and the status\n * reads are each tried again a second apart until the deadline; a session still running then, or\n * one Browserbase could not be asked about, is `Unconfirmed`. Once it has ended, wait `settle`\n * longer, for its context's save to land. It runs to the end once started.\n */\nconst confirm = (client: Service, id: string, settle: Duration.Duration | undefined) =>\n Effect.gen(function* () {\n // What Browserbase last said, for an end it never confirmed.\n let last = \"Browserbase did not answer\";\n\n const heard = (error: BrowserbaseError) => Effect.sync(() => (last = error.message));\n\n const read = client.getSession(id).pipe(\n Effect.tapError(heard),\n Effect.tap((session) => Effect.sync(() => (last = `the session was ${session.status}`))),\n Effect.retry(Schedule.spaced(\"1 second\")),\n Effect.repeat({ until: ended, schedule: Schedule.spaced(\"1 second\") }),\n );\n\n // A release that keeps failing leaves the status reads to tell whether the session ended.\n const confirmed = yield* client.releaseSession(id).pipe(\n Effect.tapError(heard),\n Effect.retry({ while: isTransient, schedule: Schedule.spaced(\"1 second\") }),\n Effect.exit,\n Effect.andThen(read),\n Effect.as(true),\n Effect.timeoutOrElse({ duration: releaseDeadline, orElse: () => Effect.succeed(false) }),\n // The reads are retried until the deadline, so a failure here is the same unconfirmed end.\n Effect.orElseSucceed(() => false),\n );\n\n if (!confirmed)\n return new Supervisor.Unconfirmed({\n detail: `${last} ${Duration.format(releaseDeadline)} after its release`,\n });\n if (settle !== undefined) yield* Effect.sleep(settle);\n\n return new Supervisor.Settled();\n }).pipe(\n Effect.tap((released) => Effect.annotateCurrentSpan({ released: released._tag })),\n Effect.withSpan(\n \"Browserbase.release\",\n { attributes: { session: id, settle: settle !== undefined } },\n { captureStackTrace: false },\n ),\n Effect.uninterruptible,\n );\n\n/** A search for the sessions with `value` under the user metadata key `label`. */\nconst labelled = (label: string, value: string) => `user_metadata['${label}']:'${value}'`;\n\n/**\n * The sessions a search finds that have not ended. Pending ones are listed first, since one listed\n * as pending may be running by the second query.\n */\nconst unended = (client: Service, query: string) =>\n Effect.forEach([\"PENDING\", \"RUNNING\"], (status) => client.listSessions({ status, query })).pipe(\n Effect.map((found) => [\n ...new Map(found.flat().map((session) => [session.id, session])).values(),\n ]),\n );\n\n/**\n * End the sessions and confirm they ended; then wait `settle`, if given, for the last save to land.\n * One still running at its release's deadline makes the outcome `Unconfirmed`.\n */\nconst endAll = (\n client: Service,\n sessions: ReadonlyArray<string>,\n settle: Duration.Duration | undefined,\n) =>\n Effect.forEach(sessions, (session) => confirm(client, session, undefined), {\n concurrency: 4,\n }).pipe(\n Effect.flatMap((outcomes) => {\n const unconfirmed = outcomes.find((outcome) => outcome._tag === \"Unconfirmed\");\n\n return unconfirmed === undefined\n ? Effect.sleep(settle ?? Duration.zero).pipe(\n Effect.as<Supervisor.Released>(new Supervisor.Settled()),\n )\n : Effect.succeed<Supervisor.Released>(unconfirmed);\n }),\n );\n\n/**\n * End the session a create may have made though its answer was lost, found in any state by the\n * create's own label, and then wait `settle`, if given, for its save. Browserbase can list a new\n * session late, so it is looked for again, more and more seldom, until it is found or\n * `orphanSearch` has passed. A search Browserbase never answered is `Unconfirmed`, as is a session\n * still running at its release's deadline.\n */\nconst endOrphan = (client: Service, nonce: string, settle: Duration.Duration | undefined) =>\n Effect.gen(function* () {\n let answered = false;\n\n const found = yield* client.listSessions({ query: labelled(createLabel, nonce) }).pipe(\n Effect.tap(() =>\n Effect.sync(() => {\n answered = true;\n }),\n ),\n Effect.retry(Schedule.exponential(\"1 second\")),\n Effect.repeat({\n schedule: Schedule.exponential(\"1 second\"),\n until: (sessions) => sessions.length > 0,\n }),\n Effect.timeoutOption(orphanSearch),\n );\n\n if (Option.isNone(found) && !answered)\n return new Supervisor.Unconfirmed({\n detail: `Browserbase did not answer a search for it within ${Duration.format(orphanSearch)}`,\n });\n const running = Option.getOrElse(found, () => []).filter((session) => !ended(session));\n\n return yield* endAll(\n client,\n running.map((session) => session.id),\n settle,\n );\n });\n\n/**\n * Hold the stored context through the lease, as its only writer, until the scope closes or the\n * session's end is known; the hold goes once, saying how this writer leaves the context.\n */\nconst holdContext = Effect.fnUntraced(function* (\n client: Service,\n lease: ContextLease[\"Service\"],\n id: string,\n settle: Duration.Duration,\n) {\n const scope = yield* Scope.fork(yield* Effect.scope);\n\n // A second writer waits here for the first one's whole session and the save after it.\n const hold = yield* lease\n .hold(id)\n .pipe(\n Scope.provide(scope),\n Effect.withSpan(\"Browserbase.holdContext\", {}, { captureStackTrace: false }),\n );\n\n // Whether a session that saves to the context may run, as this writer would leave it now.\n let unsettled = hold.unsettled;\n\n const set = (now: boolean) =>\n Effect.sync(() => {\n unsettled = now;\n });\n\n yield* Scope.addFinalizer(\n scope,\n Effect.suspend(() => hold.leave(unsettled)),\n );\n\n const letGo = (now: boolean) => set(now).pipe(Effect.andThen(Scope.close(scope, Exit.void)));\n\n /** End the context's sessions but `except`, found by the label `open` gives them. */\n const end = (except: ReadonlyArray<string>) =>\n unended(client, labelled(contextLabel, id)).pipe(\n Effect.flatMap((found) =>\n endAll(\n client,\n found.map((session) => session.id).filter((session) => !except.includes(session)),\n settle,\n ),\n ),\n Effect.onExit((exit) => set(!(Exit.isSuccess(exit) && exit.value._tag === \"Settled\"))),\n );\n\n const refuse = (outcome: Supervisor.Released) =>\n outcome._tag === \"Settled\"\n ? Effect.void\n : Effect.fail(new ContextHeld({ context: id, detail: outcome.detail }));\n\n return {\n end,\n /**\n * End the sessions, but `except`, that a writer before may have left saving to the context,\n * failing with `ContextHeld` while they can't be confirmed ended.\n */\n clear: (except: ReadonlyArray<string>) =>\n Effect.suspend(() => (unsettled ? Effect.flatMap(end(except), refuse) : Effect.void)),\n /** A session that saves to the context runs from now. */\n writing: set(true),\n /** How the writer's session ended: unconfirmed, it may still save to the context. */\n released: (outcome: Supervisor.Released) => letGo(outcome._tag === \"Unconfirmed\"),\n /** How ending the session a lost create may have made went: unconfirmed, the open fails. */\n lost: (outcome: Supervisor.Released) =>\n letGo(outcome._tag === \"Unconfirmed\").pipe(Effect.andThen(refuse(outcome))),\n /** The writer's session runs on past its scope, saving to the context when it ends. */\n kept: letGo(true),\n };\n});\n\n/** A create that failed so may still have made its session: its answer is lost or unreadable. */\nconst mayHaveCreated = (error: BrowserbaseError) =>\n error.reason._tag === \"Transport\" ||\n error.reason._tag === \"Decode\" ||\n (error.reason._tag === \"Status\" && (error.reason.status >= 500 || error.reason.status === 408));\n\n/** A create's own nonce: two random draws, which no other create draws in practice. */\nconst nonce = Effect.map(Effect.all([Random.nextInt, Random.nextInt]), (draws) =>\n draws.map((draw) => Math.abs(draw).toString(36)).join(\"-\"),\n);\n\n/**\n * The create request, labelled with its own nonce, a persisting session with its context too, so\n * either can be found, and a kept one with what it is kept under, kept alive past disconnecting.\n */\nconst withLabels = (\n session: SessionOptions | undefined,\n own: string,\n context: string | undefined,\n keep: string | undefined,\n) => ({\n ...session,\n ...(keep === undefined ? {} : { keepAlive: true }),\n userMetadata: {\n ...session?.userMetadata,\n [createLabel]: own,\n ...(context === undefined ? {} : { [contextLabel]: context }),\n ...(keep === undefined ? {} : { [keepLabel]: keep }),\n },\n});\n\n/**\n * A release by the browser's owner: it closes the browser first, so that whatever fails then, a\n * capture's reader or a call in flight, says the session was released, and not that the\n * connection Browserbase cuts as the session ends was lost.\n */\nconst releasing = (browser: Scope.Closeable, end: Effect.Effect<Supervisor.Released>) =>\n Scope.close(browser, Exit.void).pipe(Effect.andThen(end));\n\n/**\n * A browser over the session's DevTools address, its pages' screencasts on a capture connection of\n * their own. A DevTools server's HTTP address, as a local Chromium gives in tests, keeps them on\n * each page's own session: there the connection is loopback, and fast. A session that has ended\n * fails `Closed` by the session, with no connect.\n */\nconst connect = Effect.fnUntraced(function* (\n operation: string,\n session: Session,\n options: Options,\n) {\n const endpoint = session.connectUrl;\n\n if (ended(session))\n return yield* new BrowserError({\n operation,\n reason: new Closed({ cause: \"session\" }),\n dispatched: false,\n });\n if (endpoint === undefined)\n return yield* new BrowserbaseError({\n operation,\n reason: new Decode({ detail: `session ${session.id} has no connectUrl` }),\n });\n const apart = options.captureConnection !== false && /^wss?:/i.test(Redacted.value(endpoint));\n\n return yield* Cdp.open({\n ...options,\n endpoint,\n id: session.id,\n provider: \"browserbase\",\n expiresAt: Option.getOrUndefined(DateTime.make(session.expiresAt)),\n capture: apart ? yield* CaptureConnection.make(endpoint) : undefined,\n });\n});\n\n/** How a supervisor keeps its sessions past its scope: under `name`, adopting one first if `adopt`. */\ninterface Keeping {\n readonly name: string;\n readonly adopt: boolean;\n}\n\nconst keepName = /^[\\w.:-]{1,64}$/;\n\nconst newestFirst = (sessions: ReadonlyArray<Session>) => {\n const created = (session: Session) =>\n Option.getOrElse(Option.map(DateTime.make(session.createdAt), DateTime.toEpochMillis), () => 0);\n\n return sessions.toSorted((a, b) => created(b) - created(a));\n};\n\n/**\n * The newest session kept under `name` that saves where this open would, to adopt. Every other\n * session kept under it is to end, since nothing else adopts it: those that save to this open's\n * context are its writers, for the context's hold to end, as `writers` says, and the rest end here.\n */\nconst adoptable = Effect.fnUntraced(function* (\n client: Service,\n name: string,\n persisting: string | undefined,\n) {\n const [newest, ...older] = newestFirst(yield* unended(client, labelled(keepLabel, name)));\n const fits = newest !== undefined && newest.userMetadata?.[contextLabel] === persisting;\n const others = [...(fits || newest === undefined ? [] : [newest]), ...older];\n\n const writes = (session: Session) =>\n persisting !== undefined && session.userMetadata?.[contextLabel] === persisting;\n\n const rest = others.filter((session) => !writes(session));\n\n if (rest.length > 0) {\n const outcome = yield* endAll(\n client,\n rest.map((session) => session.id),\n undefined,\n );\n\n yield* Effect.annotateCurrentSpan({ endedKept: rest.length, endedKeptAs: outcome._tag });\n }\n\n return { adoptee: fits ? newest : undefined, writers: others.some(writes) };\n});\n\n/**\n * Open a browser on a new session, or, when keeping, adopt one a supervisor kept before. A kept\n * session's scope only disconnects, unless it closes on a failure: `release` ends it.\n */\nconst start = Effect.fnUntraced(function* (options: Options, keeping: Keeping | undefined) {\n const client = yield* BrowserbaseClient;\n const lease = yield* ContextLease;\n const context = options.session?.browserSettings?.context;\n const persisting = context?.persist === true ? context.id : undefined;\n const local = yield* Scope.fork(yield* Effect.scope);\n const settle = Duration.fromInputUnsafe(options.contextSettle ?? Duration.seconds(10));\n\n return yield* Effect.gen(function* () {\n if (keeping !== undefined && !keepName.test(keeping.name))\n return yield* new BrowserbaseError({\n operation: \"supervise\",\n reason: new InvalidRequest({\n detail: `keep must be 1 to 64 letters, digits, \"_\", \".\", \":\" or \"-\"`,\n }),\n });\n\n const writing =\n persisting === undefined ? undefined : yield* holdContext(client, lease, persisting, settle);\n\n const adoption = keeping?.adopt\n ? yield* adoptable(client, keeping.name, persisting)\n : undefined;\n\n const adopted = adoption?.adoptee;\n\n // Another writer kept under the name may still save to the context: clear it as any other.\n if (adoption?.writers === true) yield* writing?.writing ?? Effect.void;\n yield* writing?.clear(adopted === undefined ? [] : [adopted.id]) ?? Effect.void;\n const connected = yield* Scope.fork(local);\n const own = yield* nonce;\n\n // Releasing ends the session; leaving, as a kept session's scope does, only disconnects.\n const ending = (session: Session) =>\n Effect.gen(function* () {\n let asked = false;\n\n const release = yield* Effect.cached(\n Effect.suspend(() => {\n asked = true;\n\n return releasing(connected, confirm(client, session.id, writing && settle)).pipe(\n Effect.tap((outcome) => writing?.released(outcome) ?? Effect.void),\n );\n }),\n );\n\n const leave = Effect.suspend(() =>\n asked\n ? Effect.void\n : Scope.close(connected, Exit.void).pipe(Effect.andThen(writing?.kept ?? Effect.void)),\n );\n\n return { session, release, leave };\n });\n\n const made = yield* Effect.acquireRelease(\n Effect.gen(function* () {\n const session =\n adopted === undefined\n ? yield* client.createSession(\n withLabels(options.session, own, persisting, keeping?.name),\n )\n : yield* client.getSession(adopted.id);\n\n yield* writing?.writing ?? Effect.void;\n\n return yield* ending(session);\n }),\n ({ release, leave }, exit) =>\n keeping !== undefined && Exit.isSuccess(exit) ? leave : Effect.asVoid(release),\n ).pipe(\n // A session nobody can see bills until its timeout, and one that saves to the context would\n // write beside the next writer: end it, found by its create's own label.\n Effect.tapError((error) =>\n adopted === undefined && mayHaveCreated(error)\n ? endOrphan(client, own, writing && settle).pipe(\n Effect.flatMap((outcome) => writing?.lost(outcome) ?? Effect.void),\n )\n : Effect.void,\n ),\n );\n\n const { session, release } = made;\n\n yield* Effect.annotateCurrentSpan({\n session: session.id,\n region: session.region,\n adopted: adopted !== undefined,\n });\n\n const browser = yield* connect(\n adopted === undefined ? \"open\" : \"attach\",\n session,\n options,\n ).pipe(Scope.provide(connected));\n\n return { browser, session, release } satisfies Hosted;\n }).pipe(\n Scope.provide(local),\n Effect.onError((cause) => Scope.close(local, Exit.failCause(cause))),\n );\n});\n\n/**\n * Create a session and open a `Browser` on it, for as long as the scope is open. If opening\n * fails, the session and context are released then, so a retry in the same scope can take them.\n * A persisting open holds its context through the `ContextLease`; a session that may still save\n * to it, as one whose release was left `Unconfirmed` or whose create's answer was lost, is ended\n * first, and the open fails with `ContextHeld` while that can't be confirmed. A lost create's own\n * open looks for its session by the create's nonce, within `orphanSearch`, ends it, then fails with\n * the create's error. `release` disconnects the browser before it asks Browserbase to end the\n * session, so what fails meanwhile says it was released.\n */\nexport const open = Effect.fn(\"Browserbase.open\")(function* (options: Options = {}) {\n return yield* start(options, undefined);\n});\n\n/**\n * Open a `Browser` on a session that already runs, such as a `keepAlive` session another process\n * opened. This is resume: its pages keep their ids, their CDP target ids, so `browser.page(id)`\n * finds a page stored before. Closing the scope disconnects and leaves the session running;\n * `release` ends it. A session that has ended fails `Closed` by the session. It holds no context.\n */\nexport const attach = Effect.fn(\"Browserbase.attach\")(function* (\n sessionId: string,\n options: Options = {},\n) {\n const client = yield* BrowserbaseClient;\n const session = yield* client.getSession(sessionId);\n\n yield* Effect.annotateCurrentSpan({ session: session.id, region: session.region });\n\n const connected = yield* Scope.fork(yield* Effect.scope);\n const browser = yield* connect(\"attach\", session, options).pipe(Scope.provide(connected));\n\n const release = yield* Effect.cached(\n releasing(connected, confirm(client, session.id, undefined)),\n );\n\n return { browser, session, release } satisfies Hosted;\n});\n\n/**\n * End a stored context's sessions, the ones `open` labelled as writing to it, and let the context\n * go once they are confirmed ended and its save has settled. `open` does this itself when a writer\n * before it may still run; `reconcile` does it without opening, as for sessions another process\n * left running. It holds the context through the `ContextLease`, so it waits for a writer. A\n * session still running at the deadline makes it `Unconfirmed`, and leaves the context unsettled,\n * as a failure does.\n */\nexport const reconcile = Effect.fn(\"Browserbase.reconcile\")(function* (\n contextId: string,\n options: { readonly contextSettle?: Duration.Input | undefined } = {},\n) {\n const client = yield* BrowserbaseClient;\n const lease = yield* ContextLease;\n const settle = Duration.fromInputUnsafe(options.contextSettle ?? Duration.seconds(10));\n\n // Reading the context first refuses an id that is not one before it reaches the query.\n yield* client.getContext(contextId);\n const hold = yield* holdContext(client, lease, contextId, settle);\n\n return yield* hold.end([]);\n}, Effect.scoped);\n\n/**\n * Read a stored context back, as a login: a session that loads it and saves nothing runs `check`\n * on its browser, and is released. The context is held through the `ContextLease` meanwhile, so\n * the read never runs beside a writer, which a site could sign out, and it reads what the last\n * writer saved, once that save settled. A session a writer before may have left saving to it is\n * ended first, as for `open`.\n */\nexport const verifyContext = Effect.fn(\"Browserbase.verifyContext\")(function* <A, E, R>(\n contextId: string,\n check: (browser: Browser.Service) => Effect.Effect<A, E, R>,\n options: Options = {},\n) {\n const client = yield* BrowserbaseClient;\n const lease = yield* ContextLease;\n const settle = Duration.fromInputUnsafe(options.contextSettle ?? Duration.seconds(10));\n const reading = yield* holdContext(client, lease, contextId, settle);\n\n yield* reading.clear([]);\n\n const { browser } = yield* start(\n {\n ...options,\n session: {\n ...options.session,\n browserSettings: {\n ...options.session?.browserSettings,\n context: { id: contextId, persist: false },\n },\n },\n },\n undefined,\n );\n\n return yield* check(browser);\n}, Effect.scoped);\n\nexport interface SuperviseOptions\n extends\n Options,\n Pick<\n Supervisor.Options<BrowserError | BrowserbaseError | ContextHeld, BrowserbaseClient>,\n \"reopen\" | \"rotateBefore\" | \"waitTimeout\"\n > {\n /**\n * Keep the session past the supervisor's scope, under this name: 1 to 64 letters, digits, `_`,\n * `.`, `:` or `-`. Each session is created with `keepAlive` and labelled `keptAs: <keep>` in its\n * user metadata. Closing the scope only disconnects the current one, published as `Kept`, and\n * the first generation of the next `supervise` under the same name adopts it, with its pages,\n * rather than creating a session; other sessions kept under it are ended. `retire` releases. A\n * kept session bills until it is adopted and released, or until its timeout ends it.\n */\n readonly keep?: string | undefined;\n}\n\n/**\n * Browserbase refused the request: no new try mends a refused key, request or id. A context held\n * is not among them, since each try ends its sessions again.\n */\nconst refused = (error: BrowserError | BrowserbaseError | ContextHeld) =>\n error._tag === \"BrowserbaseError\" && !isTransient(error) && error.reason._tag !== \"Decode\";\n\n/**\n * Keep Browserbase sessions open as `Supervisor` generations, each a new session made from\n * `session`. Sessions that persist to a stored context are exclusive: a rotation releases the\n * current one, and its context's save settles, before the next one opens. An open Browserbase\n * refused, as for a bad key or an invalid request, is `Down` at once. With `keep`, closing the\n * scope leaves the current session running for the next `supervise` under that name to adopt.\n */\nexport const supervise = (options: SuperviseOptions = {}) =>\n Effect.suspend(() => {\n const { keep } = options;\n // Only the first generation adopts a kept session: a later one would find its own.\n let opened = false;\n\n return Supervisor.make({\n open: Effect.suspend(() =>\n start(options, keep === undefined ? undefined : { name: keep, adopt: !opened }),\n ).pipe(\n Effect.tap(() =>\n Effect.sync(() => {\n opened = true;\n }),\n ),\n Effect.withSpan(\"Browserbase.open\", {}, { captureStackTrace: false }),\n ),\n exclusive: options.session?.browserSettings?.context?.persist === true,\n keep: keep !== undefined,\n reopen: options.reopen,\n definite: refused,\n rotateBefore: options.rotateBefore,\n waitTimeout: options.waitTimeout,\n });\n });\n\nexport const layer = (\n options: Options = {},\n): Layer.Layer<\n Browser.Browser,\n BrowserError | BrowserbaseError | ContextHeld,\n BrowserbaseClient | ContextLease\n> =>\n Layer.effect(\n Browser.Browser,\n Effect.map(open(options), ({ browser }) => browser),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,UAAU,OAAO,eACrB,OAAO,OAAO;CACZ,IAAI,OAAO,YAAY,OAAO,GAAG;CACjC,WAAW,OAAO,YAAY,OAAO,MAAM;CAC3C,QAAQ,OAAO,YAAY,OAAO,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