effect-browserbase 0.1.0-beta.104 → 0.2.0-beta.1

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.
Files changed (158) hide show
  1. package/README.md +106 -307
  2. package/dist/Account.d.mts +17 -19
  3. package/dist/Account.mjs +4 -9
  4. package/dist/Account.mjs.map +1 -1
  5. package/dist/{Acquisition-WBafHwXH.mjs → Acquisition-CAsTTXp4.mjs} +25 -70
  6. package/dist/Acquisition-CAsTTXp4.mjs.map +1 -0
  7. package/dist/Agents-5HpTp9YE.d.mts +155 -0
  8. package/dist/Agents.d.mts +3 -156
  9. package/dist/Agents.mjs +4 -20
  10. package/dist/Agents.mjs.map +1 -1
  11. package/dist/Allocation.d.mts +9 -11
  12. package/dist/Allocation.mjs +2 -4
  13. package/dist/Allocation.mjs.map +1 -1
  14. package/dist/Browser-DpSajNai.mjs +270 -0
  15. package/dist/Browser-DpSajNai.mjs.map +1 -0
  16. package/dist/Browser.d.mts +26 -143
  17. package/dist/Browser.mjs +3 -223
  18. package/dist/BrowserBinding.d.mts +7 -34
  19. package/dist/BrowserBinding.mjs +30 -1
  20. package/dist/BrowserBinding.mjs.map +1 -0
  21. package/dist/Certificates-D4NQmyeA.d.mts +34 -0
  22. package/dist/Certificates.d.mts +3 -35
  23. package/dist/Certificates.mjs +2 -7
  24. package/dist/Certificates.mjs.map +1 -1
  25. package/dist/{Cleanup-G2YpTCuU.d.mts → Cleanup-DMTDBir8.d.mts} +5 -6
  26. package/dist/Cleanup.d.mts +3 -2
  27. package/dist/Cleanup.mjs +1 -6
  28. package/dist/Cleanup.mjs.map +1 -1
  29. package/dist/{Client-D1_xYM9o.mjs → Client-4RMKIpL2.mjs} +12 -12
  30. package/dist/Client-4RMKIpL2.mjs.map +1 -0
  31. package/dist/{Client-Ca0zSg1n.d.mts → Client-B_f6bBLT.d.mts} +4 -5
  32. package/dist/Client.d.mts +3 -2
  33. package/dist/Client.mjs +1 -1
  34. package/dist/Connection-sxyxtwlk.mjs +56 -0
  35. package/dist/Connection-sxyxtwlk.mjs.map +1 -0
  36. package/dist/ContextCoordination.d.mts +5 -6
  37. package/dist/ContextCoordination.mjs +2 -9
  38. package/dist/ContextCoordination.mjs.map +1 -1
  39. package/dist/{ContextWriter-BrQmoXRg.mjs → ContextWriter-oKWFLHuP.mjs} +8 -12
  40. package/dist/ContextWriter-oKWFLHuP.mjs.map +1 -0
  41. package/dist/Contexts-DqdL7cyX.d.mts +31 -0
  42. package/dist/Contexts.d.mts +3 -32
  43. package/dist/Contexts.mjs +3 -9
  44. package/dist/Contexts.mjs.map +1 -1
  45. package/dist/Downloads-CdhiCO5X.d.mts +43 -0
  46. package/dist/Downloads.d.mts +3 -44
  47. package/dist/Downloads.mjs +3 -8
  48. package/dist/Downloads.mjs.map +1 -1
  49. package/dist/Errors.d.mts +3 -26
  50. package/dist/Errors.mjs +1 -137
  51. package/dist/Errors.mjs.map +1 -1
  52. package/dist/Extensions-DBXuVM1f.d.mts +43 -0
  53. package/dist/{Extensions-ClZbYb1H.mjs → Extensions-Dg3jHOf0.mjs} +3 -9
  54. package/dist/Extensions-Dg3jHOf0.mjs.map +1 -0
  55. package/dist/Extensions.d.mts +3 -44
  56. package/dist/Extensions.mjs +1 -1
  57. package/dist/Functions-CsKMMUuZ.d.mts +226 -0
  58. package/dist/Functions.d.mts +3 -227
  59. package/dist/Functions.mjs +4 -18
  60. package/dist/Functions.mjs.map +1 -1
  61. package/dist/{Launch-BHcAEq05.mjs → Launch-cAdE2rrZ.mjs} +16 -12
  62. package/dist/Launch-cAdE2rrZ.mjs.map +1 -0
  63. package/dist/Launch.d.mts +127 -2
  64. package/dist/Launch.mjs +5 -13
  65. package/dist/Launch.mjs.map +1 -1
  66. package/dist/PageFetch-CAMqb5m8.d.mts +39 -0
  67. package/dist/PageFetch.d.mts +3 -40
  68. package/dist/PageFetch.mjs +2 -8
  69. package/dist/PageFetch.mjs.map +1 -1
  70. package/dist/Projects-tm5bTDH0.d.mts +38 -0
  71. package/dist/Projects.d.mts +3 -39
  72. package/dist/Projects.mjs +2 -8
  73. package/dist/Projects.mjs.map +1 -1
  74. package/dist/Recordings-bVI33sTq.d.mts +27 -0
  75. package/dist/Recordings.d.mts +3 -28
  76. package/dist/Recordings.mjs +3 -5
  77. package/dist/Recordings.mjs.map +1 -1
  78. package/dist/{References-URDAtapt.d.mts → References-DOH3Wu44.d.mts} +5 -6
  79. package/dist/References.d.mts +3 -2
  80. package/dist/References.mjs +10 -18
  81. package/dist/References.mjs.map +1 -1
  82. package/dist/Replays-Bo-9xeLz.d.mts +27 -0
  83. package/dist/Replays.d.mts +3 -28
  84. package/dist/Replays.mjs +3 -5
  85. package/dist/Replays.mjs.map +1 -1
  86. package/dist/Search-1g6TUem7.d.mts +37 -0
  87. package/dist/Search.d.mts +3 -38
  88. package/dist/Search.mjs +2 -9
  89. package/dist/Search.mjs.map +1 -1
  90. package/dist/{SessionData-DRKcKCqw.d.mts → SessionData-5xYZDshJ.d.mts} +5 -6
  91. package/dist/SessionData.d.mts +3 -2
  92. package/dist/SessionData.mjs +1 -8
  93. package/dist/SessionData.mjs.map +1 -1
  94. package/dist/{Sessions-B8E4kMxo.d.mts → Sessions-BpZgjteE.d.mts} +8 -8
  95. package/dist/{Sessions-CtbseWEh.mjs → Sessions-suOLSym9.mjs} +34 -18
  96. package/dist/Sessions-suOLSym9.mjs.map +1 -0
  97. package/dist/Sessions.d.mts +4 -3
  98. package/dist/Sessions.mjs +1 -1
  99. package/dist/Testing.d.mts +119 -0
  100. package/dist/Testing.mjs +206 -0
  101. package/dist/Testing.mjs.map +1 -0
  102. package/dist/{Transfers-Czv5IZzJ.d.mts → Transfers-GVqzrDWl.d.mts} +22 -9
  103. package/dist/Transfers.d.mts +3 -2
  104. package/dist/Transfers.mjs +12 -28
  105. package/dist/Transfers.mjs.map +1 -1
  106. package/dist/Uploads-C2neBEpj.d.mts +28 -0
  107. package/dist/Uploads.d.mts +3 -29
  108. package/dist/Uploads.mjs +3 -5
  109. package/dist/Uploads.mjs.map +1 -1
  110. package/dist/Webhooks-BoeRAxzG.d.mts +59 -0
  111. package/dist/Webhooks.d.mts +3 -60
  112. package/dist/Webhooks.mjs +2 -11
  113. package/dist/Webhooks.mjs.map +1 -1
  114. package/dist/{WriterFacts-osvYAsIx.d.mts → WriterFacts-BBJRDZYY.d.mts} +8 -15
  115. package/dist/index.d.mts +27 -31
  116. package/dist/index.mjs +26 -31
  117. package/package.json +7 -28
  118. package/dist/Acquisition-WBafHwXH.mjs.map +0 -1
  119. package/dist/Association-CEps4hYP.mjs +0 -10
  120. package/dist/Association-CEps4hYP.mjs.map +0 -1
  121. package/dist/Bootstrap-BXuzZojd.mjs +0 -194
  122. package/dist/Bootstrap-BXuzZojd.mjs.map +0 -1
  123. package/dist/Bootstrap-m7lHgj0D.d.mts +0 -177
  124. package/dist/Bootstrap.d.mts +0 -2
  125. package/dist/Bootstrap.mjs +0 -2
  126. package/dist/Browser.mjs.map +0 -1
  127. package/dist/BrowserBinding-DlJTGYZL.mjs +0 -2508
  128. package/dist/BrowserBinding-DlJTGYZL.mjs.map +0 -1
  129. package/dist/BrowserData-LpcAuAub.d.mts +0 -369
  130. package/dist/BrowserData.d.mts +0 -2
  131. package/dist/BrowserData.mjs +0 -442
  132. package/dist/BrowserData.mjs.map +0 -1
  133. package/dist/Capture-Bc0z9IAi.mjs +0 -571
  134. package/dist/Capture-Bc0z9IAi.mjs.map +0 -1
  135. package/dist/Capture-BvWI-l1A.d.mts +0 -168
  136. package/dist/Capture.d.mts +0 -2
  137. package/dist/Capture.mjs +0 -2
  138. package/dist/Client-D1_xYM9o.mjs.map +0 -1
  139. package/dist/ContextWriter-BrQmoXRg.mjs.map +0 -1
  140. package/dist/Extensions-ClZbYb1H.mjs.map +0 -1
  141. package/dist/Images-DgscEfSf.mjs +0 -127
  142. package/dist/Images-DgscEfSf.mjs.map +0 -1
  143. package/dist/Launch-BHcAEq05.mjs.map +0 -1
  144. package/dist/Launch-C8CfaYxb.d.mts +0 -132
  145. package/dist/LocalBrowser-BLancJ3R.d.mts +0 -79
  146. package/dist/LocalBrowser-DsQLWNL1.mjs +0 -439
  147. package/dist/LocalBrowser-DsQLWNL1.mjs.map +0 -1
  148. package/dist/LocalBrowser.d.mts +0 -2
  149. package/dist/LocalBrowser.mjs +0 -2
  150. package/dist/PageControl.d.mts +0 -16
  151. package/dist/PageControl.mjs +0 -36
  152. package/dist/PageControl.mjs.map +0 -1
  153. package/dist/PageControlAssociation-DabEg5AR.mjs +0 -10
  154. package/dist/PageControlAssociation-DabEg5AR.mjs.map +0 -1
  155. package/dist/Session-D4nT9hOO.mjs +0 -1379
  156. package/dist/Session-D4nT9hOO.mjs.map +0 -1
  157. package/dist/Sessions-CtbseWEh.mjs.map +0 -1
  158. package/dist/rolldown-runtime-D7D4PA-g.mjs +0 -13
@@ -1,194 +0,0 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { Identifier } from "./References.mjs";
3
- import { BrowserError, InitializationError } from "./Errors.mjs";
4
- import { Effect, Schema } from "effect";
5
- //#region src/internal/browser/BindingRegistration.ts
6
- const Invoke = Symbol("BrowserbaseBindingRegistration");
7
- const issued = /* @__PURE__ */ new WeakSet();
8
- const Origin$1 = Schema.NonEmptyString.check(Schema.isMaxLength(2048), Schema.makeFilter((value) => {
9
- try {
10
- const url = new URL(value);
11
- return ["http:", "https:"].includes(url.protocol) && url.origin === value && !url.username && !url.password;
12
- } catch {
13
- return false;
14
- }
15
- }, { title: "an exact http(s) origin" }));
16
- const FailureMode = Schema.Literals(["reject-call", "fail-session"]);
17
- const metadataSchema = Schema.Struct({
18
- name: Identifier,
19
- origins: Schema.Array(Origin$1).check(Schema.isMaxLength(16), Schema.isUnique(), Schema.makeFilter((origins) => origins.length > 0, { title: "at least one allowed origin" })),
20
- maxConcurrent: Schema.Int.check(Schema.isBetween({
21
- minimum: 1,
22
- maximum: 64
23
- })),
24
- maxInputBytes: Schema.Int.check(Schema.isBetween({
25
- minimum: 1,
26
- maximum: 1048576
27
- })),
28
- maxOutputBytes: Schema.Int.check(Schema.isBetween({
29
- minimum: 1,
30
- maximum: 4194304
31
- })),
32
- timeoutMillis: Schema.Int.check(Schema.isBetween({
33
- minimum: 1,
34
- maximum: 12e4
35
- })),
36
- failureMode: FailureMode
37
- });
38
- /** Retain an issued live capability at schema boundaries; a copied shape is not authority. */
39
- const schema = Schema.declare((value) => typeof value === "object" && value !== null && issued.has(value), { title: "an issued Browserbase binding registration" });
40
- const issue = (metadata, invoke) => {
41
- const registration = Object.freeze({
42
- ...metadata,
43
- origins: Object.freeze([...metadata.origins]),
44
- [Invoke]: invoke
45
- });
46
- issued.add(registration);
47
- return registration;
48
- };
49
- /** Pack heterogeneous codecs and handlers while their concrete input/output types are known. */
50
- const make = (options) => {
51
- const metadata = Schema.decodeSync(metadataSchema)(options);
52
- const { input, output, handle } = options;
53
- if (!Schema.isSchema(input) || !Schema.isSchema(output) || typeof handle !== "function") throw new TypeError("Invalid binding registration");
54
- const fail = (reason) => InitializationError.make({
55
- operation: "callback",
56
- step: metadata.name,
57
- reason
58
- });
59
- return issue(metadata, Effect.fnUntraced(function* (text, check) {
60
- if (new TextEncoder().encode(text).length > metadata.maxInputBytes) return yield* fail("input");
61
- const decoded = yield* Schema.decodeEffect(Schema.fromJsonString(input))(text).pipe(Effect.catchCause(() => Effect.fail(fail("input"))));
62
- yield* check;
63
- const value = yield* Effect.suspend(() => handle(decoded));
64
- const encoded = yield* Schema.encodeEffect(output)(value).pipe(Effect.catchCause(() => Effect.fail(fail("output"))));
65
- const json = yield* Schema.decodeUnknownEffect(Schema.Json)(encoded).pipe(Effect.catchCause(() => Effect.fail(fail("output"))));
66
- const result = yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Json))(json).pipe(Effect.catchCause(() => Effect.fail(fail("output"))));
67
- if (new TextEncoder().encode(result).length > metadata.maxOutputBytes) return yield* fail("output");
68
- return result;
69
- }));
70
- };
71
- /** Authentication is identity-based even when a caller copies every enumerable field/symbol. */
72
- const snapshot = Effect.fnUntraced(function* (registration) {
73
- const invalid = () => BrowserError.make({
74
- operation: "configure",
75
- reason: "configuration",
76
- outcome: "undispatched"
77
- });
78
- if (!issued.has(registration)) return yield* invalid();
79
- const metadata = yield* Schema.decodeEffect(metadataSchema)(registration).pipe(Effect.mapError(invalid));
80
- return issue(metadata, registration[Invoke]);
81
- });
82
- const invoke = (registration, text, check) => registration[Invoke](text, check);
83
- //#endregion
84
- //#region src/Bootstrap.ts
85
- var Bootstrap_exports = /* @__PURE__ */ __exportAll({
86
- BindingFailureMode: () => BindingFailureMode,
87
- InitScript: () => InitScript,
88
- Origin: () => Origin,
89
- Permission: () => Permission,
90
- PermissionGrant: () => PermissionGrant,
91
- Plan: () => Plan,
92
- Readiness: () => Readiness,
93
- binding: () => binding,
94
- combine: () => combine,
95
- empty: () => empty,
96
- init: () => init,
97
- permissions: () => permissions
98
- });
99
- /**
100
- * Exact scheme-and-host origin, as a document reports it. Patterns are deliberately absent:
101
- * a registration that cannot say exactly where it applies does not belong in a plan.
102
- */
103
- const Origin = Origin$1;
104
- /**
105
- * The reviewed subset of native permission capabilities. Each name is checked against a real
106
- * browser in native acceptance; an unsupported capability is refused before it is exposed.
107
- */
108
- const Permission = Schema.Literals([
109
- "accelerometer",
110
- "background-sync",
111
- "camera",
112
- "clipboard-read",
113
- "clipboard-write",
114
- "geolocation",
115
- "gyroscope",
116
- "magnetometer",
117
- "microphone",
118
- "midi",
119
- "notifications",
120
- "payment-handler",
121
- "storage-access"
122
- ]);
123
- const PermissionGrant = Schema.Struct({
124
- origin: Origin,
125
- permissions: Schema.Array(Permission).check(Schema.isMaxLength(16), Schema.isUnique())
126
- });
127
- /**
128
- * Registration is not readiness. A script may start asynchronous work, but it cannot pause the
129
- * website's own scripts, so a document is ready only when its expression resolves to exactly
130
- * `true`. A document that was already running when the bundle was registered never ran it:
131
- * `RequireFreshNavigation` reports that instead of pretending otherwise, and an explicit
132
- * reload of possibly uncertain work stays a caller's decision.
133
- */
134
- const Readiness = Schema.Struct({
135
- expression: Schema.NonEmptyString.check(Schema.isMaxLength(4096)),
136
- timeoutMillis: Schema.Int.check(Schema.isBetween({
137
- minimum: 1,
138
- maximum: 12e4
139
- })),
140
- existingDocuments: Schema.Literals(["RequireFreshNavigation", "AcceptAlreadyRunning"])
141
- });
142
- /** Trusted host configuration. Script content is never model output or page input. */
143
- const InitScript = Schema.Struct({
144
- id: Identifier,
145
- content: Schema.NonEmptyString.check(Schema.isMaxLength(65536)),
146
- /** When present, the step runs only on these documents and readiness skips the rest. */
147
- origins: Schema.optionalKey(Schema.Array(Origin).check(Schema.isMaxLength(16), Schema.isUnique())),
148
- readiness: Schema.optionalKey(Readiness)
149
- });
150
- /** A callback failure can reject one page invocation or permanently fence the session. */
151
- const BindingFailureMode = FailureMode;
152
- /**
153
- * Static plans remain serializable. Live binding plans retain issued registrations by identity;
154
- * this schema neither executes their callbacks nor turns copied metadata into authority. Typed
155
- * acquisition validates a separate snapshot so consumer E/R is not erased by a generic decoder.
156
- */
157
- const Plan = Schema.Struct({
158
- scripts: Schema.Array(InitScript).check(Schema.isMaxLength(16)),
159
- permissions: Schema.Array(PermissionGrant).check(Schema.isMaxLength(16)),
160
- bindings: Schema.optionalKey(Schema.Array(schema).check(Schema.isMaxLength(16)))
161
- });
162
- const empty = {
163
- scripts: [],
164
- permissions: []
165
- };
166
- const init = (script) => ({
167
- scripts: [script],
168
- permissions: []
169
- });
170
- const permissions = (grant) => ({
171
- scripts: [],
172
- permissions: [grant]
173
- });
174
- /**
175
- * Register a page-callable host callback without running it or capturing an ambient runtime.
176
- * Native installation later owns origin/document checks, bounded admission and disposal.
177
- */
178
- const binding = (options) => ({
179
- scripts: [],
180
- permissions: [],
181
- bindings: [make(options)]
182
- });
183
- function combine(...plans) {
184
- const bindings = plans.flatMap((plan) => plan.bindings === void 0 ? [] : [...plan.bindings]);
185
- return {
186
- scripts: plans.flatMap((plan) => [...plan.scripts]),
187
- permissions: plans.flatMap((plan) => [...plan.permissions]),
188
- ...bindings.length === 0 ? {} : { bindings }
189
- };
190
- }
191
- //#endregion
192
- export { Permission as a, Readiness as c, empty as d, init as f, snapshot as h, Origin as i, binding as l, invoke as m, Bootstrap_exports as n, PermissionGrant as o, permissions as p, InitScript as r, Plan as s, BindingFailureMode as t, combine as u };
193
-
194
- //# sourceMappingURL=Bootstrap-BXuzZojd.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Bootstrap-BXuzZojd.mjs","names":["Origin","Registration.Origin","Registration.FailureMode","Registration.schema","Registration.make"],"sources":["../src/internal/browser/BindingRegistration.ts","../src/Bootstrap.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\";\n\nimport type * as Bootstrap from \"../../Bootstrap.ts\";\nimport { BrowserError, InitializationError } from \"../../Errors.ts\";\nimport { Identifier } from \"../../References.ts\";\n\nconst Invoke = Symbol(\"BrowserbaseBindingRegistration\");\nconst issued = new WeakSet<object>();\n\nexport const Origin = Schema.NonEmptyString.check(\n Schema.isMaxLength(2048),\n Schema.makeFilter(\n (value) => {\n try {\n const url = new URL(value);\n\n return (\n [\"http:\", \"https:\"].includes(url.protocol) &&\n url.origin === value &&\n !url.username &&\n !url.password\n );\n } catch {\n return false;\n }\n },\n { title: \"an exact http(s) origin\" },\n ),\n);\n\nexport const FailureMode = Schema.Literals([\"reject-call\", \"fail-session\"]);\n\nconst metadataSchema = Schema.Struct({\n name: Identifier,\n origins: Schema.Array(Origin).check(\n Schema.isMaxLength(16),\n Schema.isUnique(),\n Schema.makeFilter((origins) => origins.length > 0, { title: \"at least one allowed origin\" }),\n ),\n maxConcurrent: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 64 })),\n maxInputBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1024 * 1024 })),\n maxOutputBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 4 * 1024 * 1024 })),\n timeoutMillis: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 120_000 })),\n failureMode: FailureMode,\n});\n\ntype Metadata = typeof metadataSchema.Type;\n\nexport interface Registration<E, R> extends Metadata {\n readonly [Invoke]: (\n text: string,\n check: Effect.Effect<void, InitializationError>,\n ) => Effect.Effect<string, E | InitializationError, R>;\n}\n\n/** Retain an issued live capability at schema boundaries; a copied shape is not authority. */\nexport const schema = Schema.declare<Registration<unknown, unknown>>(\n (value): value is Registration<unknown, unknown> =>\n typeof value === \"object\" && value !== null && issued.has(value),\n { title: \"an issued Browserbase binding registration\" },\n);\n\nconst issue = <E, R>(\n metadata: Metadata,\n invoke: Registration<E, R>[typeof Invoke],\n): Registration<E, R> => {\n const registration = Object.freeze({\n ...metadata,\n origins: Object.freeze([...metadata.origins]),\n [Invoke]: invoke,\n });\n\n issued.add(registration);\n\n return registration;\n};\n\n/** Pack heterogeneous codecs and handlers while their concrete input/output types are known. */\nexport const make = <I, IEncoded, O, OEncoded, E, R>(\n options: Bootstrap.BindingOptions<I, IEncoded, O, OEncoded, E, R>,\n): Registration<E, R> => {\n const metadata = Schema.decodeSync(metadataSchema)(options);\n const { input, output, handle } = options;\n\n if (!Schema.isSchema(input) || !Schema.isSchema(output) || typeof handle !== \"function\") {\n throw new TypeError(\"Invalid binding registration\");\n }\n\n const fail = (reason: \"input\" | \"output\") =>\n InitializationError.make({ operation: \"callback\", step: metadata.name, reason });\n\n return issue(\n metadata,\n Effect.fnUntraced(function* (text, check) {\n if (new TextEncoder().encode(text).length > metadata.maxInputBytes)\n return yield* fail(\"input\");\n\n const decoded = yield* Schema.decodeEffect(Schema.fromJsonString(input))(text).pipe(\n Effect.catchCause(() => Effect.fail(fail(\"input\"))),\n );\n\n yield* check;\n const value = yield* Effect.suspend(() => handle(decoded));\n\n const encoded = yield* Schema.encodeEffect(output)(value).pipe(\n Effect.catchCause(() => Effect.fail(fail(\"output\"))),\n );\n\n const json = yield* Schema.decodeUnknownEffect(Schema.Json)(encoded).pipe(\n Effect.catchCause(() => Effect.fail(fail(\"output\"))),\n );\n\n const result = yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Json))(json).pipe(\n Effect.catchCause(() => Effect.fail(fail(\"output\"))),\n );\n\n if (new TextEncoder().encode(result).length > metadata.maxOutputBytes)\n return yield* fail(\"output\");\n\n return result;\n }),\n );\n};\n\n/** Authentication is identity-based even when a caller copies every enumerable field/symbol. */\nexport const snapshot = Effect.fnUntraced(function* <E, R>(\n registration: Registration<E, R>,\n): Effect.fn.Return<Registration<E, R>, BrowserError> {\n const invalid = () =>\n BrowserError.make({ operation: \"configure\", reason: \"configuration\", outcome: \"undispatched\" });\n\n if (!issued.has(registration)) return yield* invalid();\n\n const metadata = yield* Schema.decodeEffect(metadataSchema)(registration).pipe(\n Effect.mapError(invalid),\n );\n\n return issue(metadata, registration[Invoke]);\n});\n\nexport const invoke = <E, R>(\n registration: Registration<E, R>,\n text: string,\n check: Effect.Effect<void, InitializationError>,\n): Effect.Effect<string, E | InitializationError, R> => registration[Invoke](text, check);\n","import { type Cause, type Effect, Schema } from \"effect\";\n\nimport type { InitializationError } from \"./Errors.ts\";\nimport * as Registration from \"./internal/browser/BindingRegistration.ts\";\nimport { Identifier } from \"./References.ts\";\n\n/**\n * Exact scheme-and-host origin, as a document reports it. Patterns are deliberately absent:\n * a registration that cannot say exactly where it applies does not belong in a plan.\n */\nexport const Origin = Registration.Origin;\n\nexport type Origin = typeof Origin.Type;\n\n/**\n * The reviewed subset of native permission capabilities. Each name is checked against a real\n * browser in native acceptance; an unsupported capability is refused before it is exposed.\n */\nexport const Permission = Schema.Literals([\n \"accelerometer\",\n \"background-sync\",\n \"camera\",\n \"clipboard-read\",\n \"clipboard-write\",\n \"geolocation\",\n \"gyroscope\",\n \"magnetometer\",\n \"microphone\",\n \"midi\",\n \"notifications\",\n \"payment-handler\",\n \"storage-access\",\n]);\n\nexport type Permission = typeof Permission.Type;\n\nexport const PermissionGrant = Schema.Struct({\n origin: Origin,\n permissions: Schema.Array(Permission).check(Schema.isMaxLength(16), Schema.isUnique()),\n});\n\nexport type PermissionGrant = typeof PermissionGrant.Type;\n\n/**\n * Registration is not readiness. A script may start asynchronous work, but it cannot pause the\n * website's own scripts, so a document is ready only when its expression resolves to exactly\n * `true`. A document that was already running when the bundle was registered never ran it:\n * `RequireFreshNavigation` reports that instead of pretending otherwise, and an explicit\n * reload of possibly uncertain work stays a caller's decision.\n */\nexport const Readiness = Schema.Struct({\n expression: Schema.NonEmptyString.check(Schema.isMaxLength(4096)),\n timeoutMillis: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 120_000 })),\n existingDocuments: Schema.Literals([\"RequireFreshNavigation\", \"AcceptAlreadyRunning\"]),\n});\n\nexport type Readiness = typeof Readiness.Type;\n\n/** Trusted host configuration. Script content is never model output or page input. */\nexport const InitScript = Schema.Struct({\n id: Identifier,\n content: Schema.NonEmptyString.check(Schema.isMaxLength(64 * 1024)),\n /** When present, the step runs only on these documents and readiness skips the rest. */\n origins: Schema.optionalKey(\n Schema.Array(Origin).check(Schema.isMaxLength(16), Schema.isUnique()),\n ),\n readiness: Schema.optionalKey(Readiness),\n});\n\nexport type InitScript = typeof InitScript.Type;\n\n/** A callback failure can reject one page invocation or permanently fence the session. */\nexport const BindingFailureMode = Registration.FailureMode;\n\nexport type BindingFailureMode = typeof BindingFailureMode.Type;\n\n/**\n * A registration issued by `binding`. Its private executable closure carries the real consumer\n * E/R; copying the metadata or fabricating an object does not grant callback authority.\n */\nexport type BindingRegistration<E = never, R = never> = Registration.Registration<E, R>;\n\n/**\n * Environment-free boundary codecs keep page data validation separate from consumer services.\n * The handler's E/R remain visible on the Plan and are supplied only by the trusted host.\n */\nexport interface BindingOptions<I, IEncoded, O, OEncoded, E, R> {\n readonly name: string;\n readonly origins: ReadonlyArray<Origin>;\n readonly input: Schema.ConstraintCodec<I, IEncoded, never, never>;\n readonly output: Schema.ConstraintCodec<O, OEncoded, never, never>;\n readonly maxConcurrent: number;\n readonly maxInputBytes: number;\n readonly maxOutputBytes: number;\n readonly timeoutMillis: number;\n readonly failureMode: BindingFailureMode;\n readonly handle: (input: I) => Effect.Effect<O, E, R>;\n}\n\n/**\n * One ordered bundle plus its host capabilities. Callback registrations preserve E/R through\n * their executable closures; static script/permission plans remain serializable values.\n */\nexport interface Plan<E = unknown, R = unknown> {\n readonly scripts: ReadonlyArray<InitScript>;\n readonly permissions: ReadonlyArray<PermissionGrant>;\n readonly bindings?: ReadonlyArray<BindingRegistration<E, R>>;\n}\n\n/** Host-only typed evidence. Causes are never logged or returned to page callers. */\nexport interface BindingFailure<E> {\n readonly name: string;\n readonly mode: BindingFailureMode;\n readonly cause: Cause.Cause<E | InitializationError>;\n}\n\nexport interface BindingStatistics {\n readonly name: string;\n readonly inFlight: number;\n readonly pendingNative: number;\n /** Finished/interrupted invocations whose native work or disposal has not settled. */\n readonly retired: number;\n readonly accepted: number;\n readonly succeeded: number;\n readonly rejected: number;\n}\n\n/** Copied snapshot: at most sixteen bindings and the latest thirty-two failure records. */\nexport interface BindingDiagnostics<E> {\n readonly faulted: boolean;\n readonly bindings: ReadonlyArray<BindingStatistics>;\n readonly failures: ReadonlyArray<BindingFailure<E>>;\n readonly droppedFailures: number;\n}\n\n/**\n * Static plans remain serializable. Live binding plans retain issued registrations by identity;\n * this schema neither executes their callbacks nor turns copied metadata into authority. Typed\n * acquisition validates a separate snapshot so consumer E/R is not erased by a generic decoder.\n */\nexport const Plan = Schema.Struct({\n scripts: Schema.Array(InitScript).check(Schema.isMaxLength(16)),\n permissions: Schema.Array(PermissionGrant).check(Schema.isMaxLength(16)),\n bindings: Schema.optionalKey(Schema.Array(Registration.schema).check(Schema.isMaxLength(16))),\n});\n\ntype AnyPlan = Plan<unknown, unknown>;\n\nexport type PlanError<P extends AnyPlan> = P extends Plan<infer E, infer _R> ? E : never;\nexport type PlanRequirements<P extends AnyPlan> = P extends Plan<infer _E, infer R> ? R : never;\n\nexport const empty: Plan<never, never> = { scripts: [], permissions: [] };\n\nexport const init = (script: InitScript): Plan<never, never> => ({\n scripts: [script],\n permissions: [],\n});\n\nexport const permissions = (grant: PermissionGrant): Plan<never, never> => ({\n scripts: [],\n permissions: [grant],\n});\n\n/**\n * Register a page-callable host callback without running it or capturing an ambient runtime.\n * Native installation later owns origin/document checks, bounded admission and disposal.\n */\nexport const binding = <I, IEncoded, O, OEncoded, E, R>(\n options: BindingOptions<I, IEncoded, O, OEncoded, E, R>,\n): Plan<E, R> => ({\n scripts: [],\n permissions: [],\n bindings: [Registration.make(options)],\n});\n\n/** Combination is ordered and preserves every callback's consumer E/R union. */\nexport function combine<const Plans extends ReadonlyArray<AnyPlan>>(\n ...plans: Plans\n): Plan<PlanError<Plans[number]>, PlanRequirements<Plans[number]>>;\n\nexport function combine(...plans: ReadonlyArray<AnyPlan>): AnyPlan {\n const bindings = plans.flatMap((plan) => (plan.bindings === undefined ? [] : [...plan.bindings]));\n\n return {\n scripts: plans.flatMap((plan) => [...plan.scripts]),\n permissions: plans.flatMap((plan) => [...plan.permissions]),\n ...(bindings.length === 0 ? {} : { bindings }),\n };\n}\n\n/** What the current document is, not a promise about any other document. */\nexport type ReadinessOutcome =\n | { readonly _tag: \"Ready\" }\n | { readonly _tag: \"NotApplicable\" }\n | { readonly _tag: \"RequiresNavigation\" };\n"],"mappings":";;;;;AAMA,MAAM,SAAS,OAAO,gCAAgC;AACtD,MAAM,yBAAS,IAAI,QAAgB;AAEnC,MAAaA,WAAS,OAAO,eAAe,MAC1C,OAAO,YAAY,IAAI,GACvB,OAAO,YACJ,UAAU;CACT,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,KAAK;EAEzB,OACE,CAAC,SAAS,QAAQ,CAAC,CAAC,SAAS,IAAI,QAAQ,KACzC,IAAI,WAAW,SACf,CAAC,IAAI,YACL,CAAC,IAAI;CAET,QAAQ;EACN,OAAO;CACT;AACF,GACA,EAAE,OAAO,0BAA0B,CACrC,CACF;AAEA,MAAa,cAAc,OAAO,SAAS,CAAC,eAAe,cAAc,CAAC;AA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S,CAAC;CAAG,aAAa,CAAC;AAAE;AAExE,MAAa,QAAQ,YAA4C;CAC/D,SAAS,CAAC,MAAM;CAChB,aAAa,CAAC;AAChB;AAEA,MAAa,eAAe,WAAgD;CAC1E,SAAS,CAAC;CACV,aAAa,CAAC,KAAK;AACrB;;;;;AAMA,MAAa,WACX,aACgB;CAChB,SAAS,CAAC;CACV,aAAa,CAAC;CACd,UAAU,CAACC,KAAkB,OAAO,CAAC;AACvC;AAOA,SAAgB,QAAQ,GAAG,OAAwC;CACjE,MAAM,WAAW,MAAM,SAAS,SAAU,KAAK,aAAa,KAAA,IAAY,CAAC,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAE;CAEhG,OAAO;EACL,SAAS,MAAM,SAAS,SAAS,CAAC,GAAG,KAAK,OAAO,CAAC;EAClD,aAAa,MAAM,SAAS,SAAS,CAAC,GAAG,KAAK,WAAW,CAAC;EAC1D,GAAI,SAAS,WAAW,IAAI,CAAC,IAAI,EAAE,SAAS;CAC9C;AACF"}
@@ -1,177 +0,0 @@
1
- import { BrowserError, InitializationError } from "./Errors.mjs";
2
- import { Cause, Effect, Schema } from "effect";
3
- declare namespace BindingRegistration_d_exports {
4
- export { FailureMode, Origin$1 as Origin, Registration, invoke, make, schema, snapshot };
5
- }
6
- declare const Invoke: unique symbol;
7
- declare const Origin$1: Schema.NonEmptyString;
8
- declare const FailureMode: Schema.Literals<readonly ["reject-call", "fail-session"]>;
9
- declare const metadataSchema: Schema.Struct<{
10
- readonly name: Schema.NonEmptyString;
11
- readonly origins: Schema.$Array<Schema.NonEmptyString>;
12
- readonly maxConcurrent: Schema.Int;
13
- readonly maxInputBytes: Schema.Int;
14
- readonly maxOutputBytes: Schema.Int;
15
- readonly timeoutMillis: Schema.Int;
16
- readonly failureMode: Schema.Literals<readonly ["reject-call", "fail-session"]>;
17
- }>;
18
- type Metadata = typeof metadataSchema.Type;
19
- interface Registration<E, R> extends Metadata {
20
- readonly [Invoke]: (text: string, check: Effect.Effect<void, InitializationError>) => Effect.Effect<string, E | InitializationError, R>;
21
- }
22
- /** Retain an issued live capability at schema boundaries; a copied shape is not authority. */
23
- declare const schema: Schema.declare<Registration<unknown, unknown>, Registration<unknown, unknown>>;
24
- /** Pack heterogeneous codecs and handlers while their concrete input/output types are known. */
25
- declare const make: <I, IEncoded, O, OEncoded, E, R>(options: BindingOptions<I, IEncoded, O, OEncoded, E, R>) => Registration<E, R>;
26
- /** Authentication is identity-based even when a caller copies every enumerable field/symbol. */
27
- declare const snapshot: <E, R>(registration: Registration<E, R>) => Effect.Effect<Registration<E, R>, BrowserError, never>;
28
- declare const invoke: <E, R>(registration: Registration<E, R>, text: string, check: Effect.Effect<void, InitializationError>) => Effect.Effect<string, E | InitializationError, R>;
29
- declare namespace Bootstrap_d_exports {
30
- export { BindingDiagnostics, BindingFailure, BindingFailureMode, BindingOptions, BindingRegistration, BindingStatistics, InitScript, Origin, Permission, PermissionGrant, Plan, PlanError, PlanRequirements, Readiness, ReadinessOutcome, binding, combine, empty, init, permissions };
31
- }
32
- /**
33
- * Exact scheme-and-host origin, as a document reports it. Patterns are deliberately absent:
34
- * a registration that cannot say exactly where it applies does not belong in a plan.
35
- */
36
- declare const Origin: Schema.NonEmptyString;
37
- type Origin = typeof Origin.Type;
38
- /**
39
- * The reviewed subset of native permission capabilities. Each name is checked against a real
40
- * browser in native acceptance; an unsupported capability is refused before it is exposed.
41
- */
42
- declare const Permission: Schema.Literals<readonly ["accelerometer", "background-sync", "camera", "clipboard-read", "clipboard-write", "geolocation", "gyroscope", "magnetometer", "microphone", "midi", "notifications", "payment-handler", "storage-access"]>;
43
- type Permission = typeof Permission.Type;
44
- declare const PermissionGrant: Schema.Struct<{
45
- readonly origin: Schema.NonEmptyString;
46
- readonly permissions: Schema.$Array<Schema.Literals<readonly ["accelerometer", "background-sync", "camera", "clipboard-read", "clipboard-write", "geolocation", "gyroscope", "magnetometer", "microphone", "midi", "notifications", "payment-handler", "storage-access"]>>;
47
- }>;
48
- type PermissionGrant = typeof PermissionGrant.Type;
49
- /**
50
- * Registration is not readiness. A script may start asynchronous work, but it cannot pause the
51
- * website's own scripts, so a document is ready only when its expression resolves to exactly
52
- * `true`. A document that was already running when the bundle was registered never ran it:
53
- * `RequireFreshNavigation` reports that instead of pretending otherwise, and an explicit
54
- * reload of possibly uncertain work stays a caller's decision.
55
- */
56
- declare const Readiness: Schema.Struct<{
57
- readonly expression: Schema.NonEmptyString;
58
- readonly timeoutMillis: Schema.Int;
59
- readonly existingDocuments: Schema.Literals<readonly ["RequireFreshNavigation", "AcceptAlreadyRunning"]>;
60
- }>;
61
- type Readiness = typeof Readiness.Type;
62
- /** Trusted host configuration. Script content is never model output or page input. */
63
- declare const InitScript: Schema.Struct<{
64
- readonly id: Schema.NonEmptyString;
65
- readonly content: Schema.NonEmptyString;
66
- /** When present, the step runs only on these documents and readiness skips the rest. */
67
- readonly origins: Schema.optionalKey<Schema.$Array<Schema.NonEmptyString>>;
68
- readonly readiness: Schema.optionalKey<Schema.Struct<{
69
- readonly expression: Schema.NonEmptyString;
70
- readonly timeoutMillis: Schema.Int;
71
- readonly existingDocuments: Schema.Literals<readonly ["RequireFreshNavigation", "AcceptAlreadyRunning"]>;
72
- }>>;
73
- }>;
74
- type InitScript = typeof InitScript.Type;
75
- /** A callback failure can reject one page invocation or permanently fence the session. */
76
- declare const BindingFailureMode: Schema.Literals<readonly ["reject-call", "fail-session"]>;
77
- type BindingFailureMode = typeof BindingFailureMode.Type;
78
- /**
79
- * A registration issued by `binding`. Its private executable closure carries the real consumer
80
- * E/R; copying the metadata or fabricating an object does not grant callback authority.
81
- */
82
- type BindingRegistration<E = never, R = never> = Registration<E, R>;
83
- /**
84
- * Environment-free boundary codecs keep page data validation separate from consumer services.
85
- * The handler's E/R remain visible on the Plan and are supplied only by the trusted host.
86
- */
87
- interface BindingOptions<I, IEncoded, O, OEncoded, E, R> {
88
- readonly name: string;
89
- readonly origins: ReadonlyArray<Origin>;
90
- readonly input: Schema.ConstraintCodec<I, IEncoded, never, never>;
91
- readonly output: Schema.ConstraintCodec<O, OEncoded, never, never>;
92
- readonly maxConcurrent: number;
93
- readonly maxInputBytes: number;
94
- readonly maxOutputBytes: number;
95
- readonly timeoutMillis: number;
96
- readonly failureMode: BindingFailureMode;
97
- readonly handle: (input: I) => Effect.Effect<O, E, R>;
98
- }
99
- /**
100
- * One ordered bundle plus its host capabilities. Callback registrations preserve E/R through
101
- * their executable closures; static script/permission plans remain serializable values.
102
- */
103
- interface Plan<E = unknown, R = unknown> {
104
- readonly scripts: ReadonlyArray<InitScript>;
105
- readonly permissions: ReadonlyArray<PermissionGrant>;
106
- readonly bindings?: ReadonlyArray<BindingRegistration<E, R>>;
107
- }
108
- /** Host-only typed evidence. Causes are never logged or returned to page callers. */
109
- interface BindingFailure<E> {
110
- readonly name: string;
111
- readonly mode: BindingFailureMode;
112
- readonly cause: Cause.Cause<E | InitializationError>;
113
- }
114
- interface BindingStatistics {
115
- readonly name: string;
116
- readonly inFlight: number;
117
- readonly pendingNative: number;
118
- /** Finished/interrupted invocations whose native work or disposal has not settled. */
119
- readonly retired: number;
120
- readonly accepted: number;
121
- readonly succeeded: number;
122
- readonly rejected: number;
123
- }
124
- /** Copied snapshot: at most sixteen bindings and the latest thirty-two failure records. */
125
- interface BindingDiagnostics<E> {
126
- readonly faulted: boolean;
127
- readonly bindings: ReadonlyArray<BindingStatistics>;
128
- readonly failures: ReadonlyArray<BindingFailure<E>>;
129
- readonly droppedFailures: number;
130
- }
131
- /**
132
- * Static plans remain serializable. Live binding plans retain issued registrations by identity;
133
- * this schema neither executes their callbacks nor turns copied metadata into authority. Typed
134
- * acquisition validates a separate snapshot so consumer E/R is not erased by a generic decoder.
135
- */
136
- declare const Plan: Schema.Struct<{
137
- readonly scripts: Schema.$Array<Schema.Struct<{
138
- readonly id: Schema.NonEmptyString;
139
- readonly content: Schema.NonEmptyString;
140
- /** When present, the step runs only on these documents and readiness skips the rest. */
141
- readonly origins: Schema.optionalKey<Schema.$Array<Schema.NonEmptyString>>;
142
- readonly readiness: Schema.optionalKey<Schema.Struct<{
143
- readonly expression: Schema.NonEmptyString;
144
- readonly timeoutMillis: Schema.Int;
145
- readonly existingDocuments: Schema.Literals<readonly ["RequireFreshNavigation", "AcceptAlreadyRunning"]>;
146
- }>>;
147
- }>>;
148
- readonly permissions: Schema.$Array<Schema.Struct<{
149
- readonly origin: Schema.NonEmptyString;
150
- readonly permissions: Schema.$Array<Schema.Literals<readonly ["accelerometer", "background-sync", "camera", "clipboard-read", "clipboard-write", "geolocation", "gyroscope", "magnetometer", "microphone", "midi", "notifications", "payment-handler", "storage-access"]>>;
151
- }>>;
152
- readonly bindings: Schema.optionalKey<Schema.$Array<Schema.declare<Registration<unknown, unknown>, Registration<unknown, unknown>>>>;
153
- }>;
154
- type AnyPlan = Plan<unknown, unknown>;
155
- type PlanError<P extends AnyPlan> = P extends Plan<infer E, infer _R> ? E : never;
156
- type PlanRequirements<P extends AnyPlan> = P extends Plan<infer _E, infer R> ? R : never;
157
- declare const empty: Plan<never, never>;
158
- declare const init: (script: InitScript) => Plan<never, never>;
159
- declare const permissions: (grant: PermissionGrant) => Plan<never, never>;
160
- /**
161
- * Register a page-callable host callback without running it or capturing an ambient runtime.
162
- * Native installation later owns origin/document checks, bounded admission and disposal.
163
- */
164
- declare const binding: <I, IEncoded, O, OEncoded, E, R>(options: BindingOptions<I, IEncoded, O, OEncoded, E, R>) => Plan<E, R>;
165
- /** Combination is ordered and preserves every callback's consumer E/R union. */
166
- declare function combine<const Plans extends ReadonlyArray<AnyPlan>>(...plans: Plans): Plan<PlanError<Plans[number]>, PlanRequirements<Plans[number]>>;
167
- /** What the current document is, not a promise about any other document. */
168
- type ReadinessOutcome = {
169
- readonly _tag: "Ready";
170
- } | {
171
- readonly _tag: "NotApplicable";
172
- } | {
173
- readonly _tag: "RequiresNavigation";
174
- };
175
- //#endregion
176
- export { binding as _, BindingRegistration as a, init as b, InitScript as c, PermissionGrant as d, Plan as f, ReadinessOutcome as g, Readiness as h, BindingOptions as i, Origin as l, PlanRequirements as m, BindingFailure as n, BindingStatistics as o, PlanError as p, BindingFailureMode as r, Bootstrap_d_exports as s, BindingDiagnostics as t, Permission as u, combine as v, permissions as x, empty as y };
177
- //# sourceMappingURL=Bootstrap-m7lHgj0D.d.mts.map
@@ -1,2 +0,0 @@
1
- import { _ as binding, a as BindingRegistration, b as init, c as InitScript, d as PermissionGrant, f as Plan, g as ReadinessOutcome, h as Readiness, i as BindingOptions, l as Origin, m as PlanRequirements, n as BindingFailure, o as BindingStatistics, p as PlanError, r as BindingFailureMode, t as BindingDiagnostics, u as Permission, v as combine, x as permissions, y as empty } from "./Bootstrap-m7lHgj0D.mjs";
2
- export { BindingDiagnostics, BindingFailure, BindingFailureMode, BindingOptions, BindingRegistration, BindingStatistics, InitScript, Origin, Permission, PermissionGrant, Plan, PlanError, PlanRequirements, Readiness, ReadinessOutcome, binding, combine, empty, init, permissions };
@@ -1,2 +0,0 @@
1
- import { a as Permission, c as Readiness, d as empty, f as init, i as Origin, l as binding, o as PermissionGrant, p as permissions, r as InitScript, s as Plan, t as BindingFailureMode, u as combine } from "./Bootstrap-BXuzZojd.mjs";
2
- export { BindingFailureMode, InitScript, Origin, Permission, PermissionGrant, Plan, Readiness, binding, combine, empty, init, permissions };
@@ -1 +0,0 @@
1
- {"version":3,"file":"Browser.mjs","names":["makeBrowserSession","Bootstrap.empty"],"sources":["../src/Browser.ts"],"sourcesContent":["import { Context, Effect, Layer, type Option, type Redacted, Scope } from \"effect\";\n\nimport * as Bootstrap from \"./Bootstrap.ts\";\nimport { BrowserbaseBrowserBinding } from \"./BrowserBinding.ts\";\nimport type {\n Checkpoint,\n CheckpointOptions,\n FillRequest,\n HoverRequest,\n InputReceipt,\n KeyStroke,\n NavigateRequest,\n NavigationResult,\n ObservationOptions,\n ObservedElement,\n PointerMoveRequest,\n PressRequest,\n ReadTextRequest,\n ScreenshotRequest,\n ScreenshotResult,\n ScrollRequest,\n StartNavigationRequest,\n TextResult,\n TypeRequest,\n WheelRequest,\n} from \"./BrowserData.ts\";\nimport {\n type ControlFacts,\n ActionResult,\n AutomationOptions,\n BrowserPolicy,\n ClickRequest,\n type FrameInfo,\n InlineFiles,\n type Observation,\n type PageInfo,\n type SelectFilesRequest,\n Selector,\n type Target,\n Viewport,\n} from \"./BrowserData.ts\";\nimport type { CleanupResult } from \"./Cleanup.ts\";\nimport { BrowserbaseClient } from \"./Client.ts\";\nimport type { InitializationError } from \"./Errors.ts\";\nimport {\n type AllocationError,\n BrowserError,\n type BrowserOperation,\n type ContextError,\n type SessionError,\n} from \"./Errors.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 {\n checked,\n decoded,\n makeSession as makeBrowserSession,\n} from \"./internal/browser/PublicSession.ts\";\nimport {\n acquireSession,\n borrowedRemote,\n ownedRemote,\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 BrowserSession<E = never> {\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 /**\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}\n\n/** Browserbase identity, remote artifacts and provider cleanup remain hosted capabilities. */\nexport interface BrowserbaseSession<E = never> extends BrowserSession<E> {\n readonly reference: SessionReference;\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 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\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\nconst makeSession = <E>(\n controls: SessionControls,\n bindings: Bindings<E>,\n): BrowserbaseSession<E> => {\n const session = makeBrowserSession(controls, bindings);\n const navigate = (url: string) => decoded(ActionResult, \"action-result\")({ url });\n\n return Object.assign(session, {\n reference: controls.reference,\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 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 } satisfies Omit<BrowserbaseSession<E>, keyof BrowserSession<E>>);\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":";;;;;;;;;;;;;;;;;;;AA+RA,MAAM,aACJ,SACA,WACA,cAEA,OAAO,cAAc;CACnB,MAAM,UAAU,aAAa,KAAK;EAChC;EACA,QAAQ;EACR,SAAS;CACX,CAAC;CAED,IAAI,QAAQ,UAAU,SAAS,UAC7B,OAAO,QAAQ,aAAa,QAAQ,UAAU,OAAO,SAAS,CAAC,CAAC,KAC9D,OAAO,KAAK,UACV,MAAM,KAAK,UAAU;EACnB,MAAM;EACN,MAAM,KAAK;EACX,WAAW,KAAK;EAEhB,OAAO,IAAI,WAAW,KAAK,KAAK;CAClC,EAAE,CACJ,CACF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