effect-browser 0.3.0-beta.15 → 0.3.0-beta.19
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 +18 -6
- package/dist/{Browser-BBSySyjT.mjs → Browser-H63wiekr.mjs} +5 -5
- package/dist/Browser-H63wiekr.mjs.map +1 -0
- package/dist/Browser.d.mts +2 -2
- package/dist/Browser.mjs +1 -1
- package/dist/{BrowserEvent-BRu2juEz.d.mts → BrowserEvent-dq6FRT8w.d.mts} +9 -9
- package/dist/BrowserEvent.d.mts +1 -1
- package/dist/BrowserEvent.mjs +7 -12
- package/dist/BrowserEvent.mjs.map +1 -1
- package/dist/Cdp.mjs +2 -2
- package/dist/{Change-iMlcuzVD.d.mts → Change-DqING3tr.d.mts} +2 -2
- package/dist/Change.d.mts +1 -1
- package/dist/Chromium.mjs +2 -2
- package/dist/Expect.d.mts +1 -1
- package/dist/Expect.mjs +2 -2
- package/dist/Moment.d.mts +1 -1
- package/dist/Moment.mjs +3 -3
- package/dist/Moment.mjs.map +1 -1
- package/dist/Motion-DND6I-64.d.mts +40 -0
- package/dist/Motion.d.mts +2 -40
- package/dist/Motion.mjs +1 -2
- package/dist/Motion.mjs.map +1 -1
- package/dist/{Page-B5cjaUp5.mjs → Page-CfB6Zn1p.mjs} +7 -15
- package/dist/Page-CfB6Zn1p.mjs.map +1 -0
- package/dist/{Page-DL9eylp3.d.mts → Page-ku6j5t-v.d.mts} +23 -25
- package/dist/Page.d.mts +1 -1
- package/dist/Page.mjs +1 -1
- package/dist/{Plan-CXA2BW-G.mjs → Plan-C-d5QYS8.mjs} +6 -9
- package/dist/Plan-C-d5QYS8.mjs.map +1 -0
- package/dist/{Plan-6As6vcwT.d.mts → Plan-DJ4hEEna.d.mts} +3 -3
- package/dist/Plan.d.mts +1 -1
- package/dist/Plan.mjs +1 -1
- package/dist/Policy.d.mts +1 -1
- package/dist/Policy.mjs +1 -1
- package/dist/Presentation.d.mts +2 -2
- package/dist/Presentation.mjs +3 -2
- package/dist/Presentation.mjs.map +1 -1
- package/dist/Stage.d.mts +1 -1
- package/dist/Stage.mjs +8 -7
- package/dist/Stage.mjs.map +1 -1
- package/dist/{Supervisor-DaGlQVjv.mjs → Supervisor-2mPjIYYs.mjs} +44 -19
- package/dist/Supervisor-2mPjIYYs.mjs.map +1 -0
- package/dist/{Supervisor-5tZ47hR5.d.mts → Supervisor-mVPeEUp8.d.mts} +12 -5
- package/dist/Supervisor.d.mts +1 -1
- package/dist/Supervisor.mjs +1 -1
- package/dist/{context-BAjRj7Xo.mjs → context-w3NJPRLo.mjs} +81 -9
- package/dist/context-w3NJPRLo.mjs.map +1 -0
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +4 -4
- package/dist/match.inpage-xOe9LNO0.mjs.map +1 -1
- package/dist/{page-B92QnRfT.mjs → page-BKwfF6z-.mjs} +213 -218
- package/dist/page-BKwfF6z-.mjs.map +1 -0
- package/package.json +1 -1
- package/src/Browser.ts +1 -1
- package/src/BrowserEvent.ts +7 -12
- package/src/Moment.ts +3 -6
- package/src/Motion.ts +1 -2
- package/src/Page.ts +18 -20
- package/src/Plan.ts +1 -2
- package/src/Presentation.ts +2 -1
- package/src/Stage.ts +10 -17
- package/src/Supervisor.ts +9 -9
- package/src/internal/input/actions.ts +53 -97
- package/src/internal/input/dispatch.ts +25 -11
- package/src/internal/input/edit.inpage.ts +26 -11
- package/src/internal/input/evidence.inpage.ts +1 -21
- package/src/internal/input/guard.inpage.ts +9 -29
- package/src/internal/input/guard.ts +15 -10
- package/src/internal/input/perform.ts +14 -10
- package/src/internal/input/pointer.ts +3 -6
- package/src/internal/input/replies.ts +19 -8
- package/src/internal/input/settle.ts +3 -2
- package/src/internal/input/targets.inpage.ts +6 -13
- package/src/internal/input/targets.ts +13 -32
- package/src/internal/page/bridge.ts +2 -2
- package/src/internal/page/context.ts +15 -3
- package/src/internal/page/navigation.ts +3 -12
- package/src/internal/pictures/capture.ts +11 -4
- package/src/internal/pictures/clock.ts +8 -3
- package/src/internal/pictures/motion.ts +65 -0
- package/src/internal/pictures/pictures.ts +22 -17
- package/src/internal/pictures/utilsBundle.d.ts +9 -0
- package/src/internal/reading/controls.inpage.ts +8 -1
- package/src/internal/reading/match.inpage.ts +2 -1
- package/src/internal/reading/outline.inpage.ts +7 -4
- package/src/internal/reading/reading.ts +10 -25
- package/src/internal/reading/ready.ts +66 -14
- package/src/internal/supervisor/lifecycle.ts +56 -13
- package/src/internal/timeline/events.ts +5 -8
- package/src/internal/timeline/window.ts +3 -8
- package/dist/Browser-BBSySyjT.mjs.map +0 -1
- package/dist/Page-B5cjaUp5.mjs.map +0 -1
- package/dist/Plan-CXA2BW-G.mjs.map +0 -1
- package/dist/Supervisor-DaGlQVjv.mjs.map +0 -1
- package/dist/context-BAjRj7Xo.mjs.map +0 -1
- package/dist/page-B92QnRfT.mjs.map +0 -1
|
@@ -34,13 +34,15 @@ var Lost = class extends Schema.TaggedClass()("Lost", {
|
|
|
34
34
|
}) {};
|
|
35
35
|
/**
|
|
36
36
|
* It never opened: its last try failed with `cause`, which the provider deems definite, or after
|
|
37
|
-
* which the reopen schedule gave up.
|
|
37
|
+
* which the reopen schedule gave up. `released` combines this generation's failed-try cleanup,
|
|
38
|
+
* retaining the first unconfirmed end; it is absent when no try reported cleanup.
|
|
38
39
|
*/
|
|
39
40
|
var Down = class extends Schema.TaggedClass()("Down", {
|
|
40
41
|
detail: Schema.String,
|
|
41
|
-
cause: Schema.Defect()
|
|
42
|
+
cause: Schema.Defect(),
|
|
43
|
+
released: Schema.optional(Released)
|
|
42
44
|
}) {};
|
|
43
|
-
/** It ended. `released`
|
|
45
|
+
/** It ended. `released` includes reported cleanup when retired while opening, if any. */
|
|
44
46
|
var Closed = class extends Schema.TaggedClass()("Closed", { released: Schema.optional(Released) }) {};
|
|
45
47
|
/**
|
|
46
48
|
* It was serving as the supervisor's scope closed, and was left running, not released: its scope
|
|
@@ -153,7 +155,8 @@ const next = (change, number, reopen) => {
|
|
|
153
155
|
number,
|
|
154
156
|
serving: reopen || exclusive ? void 0 : current,
|
|
155
157
|
draining: change.state.draining,
|
|
156
|
-
released: change.state.released
|
|
158
|
+
released: change.state.released,
|
|
159
|
+
attempts: change.state.attempts
|
|
157
160
|
};
|
|
158
161
|
change.events.push([number, reopen ? new Reopening() : new Opening()]);
|
|
159
162
|
change.commands.push({
|
|
@@ -184,6 +187,17 @@ const lost = (change, input) => {
|
|
|
184
187
|
}
|
|
185
188
|
}
|
|
186
189
|
};
|
|
190
|
+
/** End one opening without confusing its cleanup with preceding generations' releases. */
|
|
191
|
+
const finishAttempt = (change, number) => {
|
|
192
|
+
const attempts = new Map(change.state.attempts);
|
|
193
|
+
const released = attempts.get(number);
|
|
194
|
+
attempts.delete(number);
|
|
195
|
+
change.state = {
|
|
196
|
+
...change.state,
|
|
197
|
+
attempts
|
|
198
|
+
};
|
|
199
|
+
return released;
|
|
200
|
+
};
|
|
187
201
|
/** Pure admission and lifecycle changes. A rejected hold preserves state identity. */
|
|
188
202
|
const transition = (state, input, exclusive, now = 0, handover = 3e4) => {
|
|
189
203
|
const change = {
|
|
@@ -210,6 +224,7 @@ const transition = (state, input, exclusive, now = 0, handover = 3e4) => {
|
|
|
210
224
|
if (lookup(state, live.number) !== void 0) break;
|
|
211
225
|
if (state._tag !== "Opening" || state.number !== live.number) end(change, live, "retired");
|
|
212
226
|
else {
|
|
227
|
+
finishAttempt(change, live.number);
|
|
213
228
|
change.events.push([live.number, new Open()]);
|
|
214
229
|
change.commands.push({
|
|
215
230
|
_tag: "Watch",
|
|
@@ -220,7 +235,8 @@ const transition = (state, input, exclusive, now = 0, handover = 3e4) => {
|
|
|
220
235
|
_tag: "Open",
|
|
221
236
|
serving: live,
|
|
222
237
|
draining: change.state.draining,
|
|
223
|
-
released: change.state.released
|
|
238
|
+
released: change.state.released,
|
|
239
|
+
attempts: change.state.attempts
|
|
224
240
|
};
|
|
225
241
|
}
|
|
226
242
|
break;
|
|
@@ -235,30 +251,34 @@ const transition = (state, input, exclusive, now = 0, handover = 3e4) => {
|
|
|
235
251
|
};
|
|
236
252
|
change.events.push([number, new Down({
|
|
237
253
|
detail,
|
|
238
|
-
cause
|
|
254
|
+
cause,
|
|
255
|
+
released: finishAttempt(change, number)
|
|
239
256
|
})]);
|
|
240
257
|
break;
|
|
241
258
|
}
|
|
242
259
|
case "Abandoned":
|
|
243
|
-
change.events.push([input.number, new Closed({})]);
|
|
260
|
+
change.events.push([input.number, new Closed({ released: finishAttempt(change, input.number) })]);
|
|
244
261
|
break;
|
|
245
262
|
case "AttemptReleased":
|
|
246
263
|
change.state = {
|
|
247
264
|
...state,
|
|
248
|
-
released: combine(state.released, input.released)
|
|
265
|
+
released: combine(state.released, input.released),
|
|
266
|
+
attempts: new Map(state.attempts).set(input.number, combine(state.attempts?.get(input.number), input.released))
|
|
249
267
|
};
|
|
250
268
|
break;
|
|
251
269
|
case "Released": {
|
|
252
|
-
const
|
|
270
|
+
const { number, released } = input;
|
|
271
|
+
const drain = state.draining.get(number);
|
|
253
272
|
if (drain === void 0 || drain._tag === "Draining" || drain.live.holds.size > 0) break;
|
|
254
273
|
const draining = new Map(state.draining);
|
|
255
|
-
draining.delete(
|
|
274
|
+
draining.delete(number);
|
|
256
275
|
change.state = {
|
|
257
276
|
...state,
|
|
258
277
|
draining,
|
|
259
|
-
released: combine(state.released,
|
|
278
|
+
released: combine(state.released, released)
|
|
260
279
|
};
|
|
261
|
-
|
|
280
|
+
const outcome = combine(finishAttempt(change, number), released);
|
|
281
|
+
change.events.push([number, released === void 0 ? new Kept() : new Closed({ released: outcome })]);
|
|
262
282
|
break;
|
|
263
283
|
}
|
|
264
284
|
case "Lost":
|
|
@@ -277,13 +297,15 @@ const transition = (state, input, exclusive, now = 0, handover = 3e4) => {
|
|
|
277
297
|
change.state = {
|
|
278
298
|
_tag: "Retired",
|
|
279
299
|
draining: change.state.draining,
|
|
280
|
-
released: change.state.released
|
|
300
|
+
released: change.state.released,
|
|
301
|
+
attempts: change.state.attempts
|
|
281
302
|
};
|
|
282
303
|
}
|
|
283
304
|
return change;
|
|
284
305
|
};
|
|
285
|
-
|
|
286
|
-
|
|
306
|
+
function combine(before, next) {
|
|
307
|
+
return before?._tag === "Unconfirmed" ? before : next ?? before;
|
|
308
|
+
}
|
|
287
309
|
/** An unheld browser resolution; use obtains its hold atomically through Hold instead. */
|
|
288
310
|
const resolve = (state, target) => {
|
|
289
311
|
if (state._tag === "Retired") return {
|
|
@@ -370,7 +392,8 @@ var Unavailable = class extends Schema.TaggedError()("Unavailable", {
|
|
|
370
392
|
/**
|
|
371
393
|
* Optional service supplied during `open`. Providers report failed-attempt cleanup here before
|
|
372
394
|
* their scope closes; successful generations instead return `Opened.release`. Reporting does
|
|
373
|
-
* not release resources or replace the original acquisition failure.
|
|
395
|
+
* not release resources or replace the original acquisition failure. Terminal `Down` and opening
|
|
396
|
+
* `Closed` states publish the reported outcomes of their own generation's tries.
|
|
374
397
|
*/
|
|
375
398
|
var Releasing = class extends Context.Service()("effect-browser/Supervisor/Releasing") {};
|
|
376
399
|
/** Work whose generation was revoked; input receipts still determine whether input reached a site. */
|
|
@@ -598,6 +621,7 @@ const makeScoped = Effect.fn("Supervisor.make")(function* (options) {
|
|
|
598
621
|
}) ?? Effect.void;
|
|
599
622
|
return yield* options.open.pipe(Effect.provideService(Releasing, { released: (released) => apply({
|
|
600
623
|
_tag: "AttemptReleased",
|
|
624
|
+
number,
|
|
601
625
|
released
|
|
602
626
|
}).pipe(Effect.asVoid) }));
|
|
603
627
|
}), own).pipe(Effect.provideContext(context));
|
|
@@ -632,13 +656,14 @@ const makeScoped = Effect.fn("Supervisor.make")(function* (options) {
|
|
|
632
656
|
if (yield* Deferred.isDone(releases.deferred)) yield* FiberMap.join(releases);
|
|
633
657
|
}, Effect.ensuring(end));
|
|
634
658
|
const retire = yield* Effect.cached(stop({ _tag: "Retire" }));
|
|
659
|
+
const browserOf = (target) => Effect.map(waitFor(state, waitTimeout, clock, target), (live) => live.value.opened.browser);
|
|
635
660
|
yield* Effect.addFinalizer(() => options.keep === true ? stop({ _tag: "Keep" }) : retire);
|
|
636
661
|
yield* perform(started);
|
|
637
662
|
return {
|
|
638
|
-
browser:
|
|
663
|
+
browser: browserOf(),
|
|
639
664
|
use: leasing(state, apply, waitTimeout, now, clock),
|
|
640
665
|
states: Stream.fromPubSubTake(events),
|
|
641
|
-
rotate: apply({ _tag: "Rotate" }).pipe(Effect.flatMap(({ reply }) => reply === void 0 ? Effect.fail(retired()) :
|
|
666
|
+
rotate: apply({ _tag: "Rotate" }).pipe(Effect.flatMap(({ reply }) => reply === void 0 ? Effect.fail(retired()) : browserOf(reply))),
|
|
642
667
|
retire
|
|
643
668
|
};
|
|
644
669
|
});
|
|
@@ -648,4 +673,4 @@ function make(options) {
|
|
|
648
673
|
//#endregion
|
|
649
674
|
export { Settled as _, Unavailable as a, Down as c, Kept as d, Lost as f, Reopening as g, Released as h, Supervisor_exports as i, Draining as l, Opening as m, Releasing as n, make as o, Open as p, Superseded as r, Closed as s, Generation as t, GenerationState as u, Unconfirmed as v };
|
|
650
675
|
|
|
651
|
-
//# sourceMappingURL=Supervisor-
|
|
676
|
+
//# sourceMappingURL=Supervisor-2mPjIYYs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Supervisor-2mPjIYYs.mjs","names":["Lifecycle.GenerationState","Lifecycle.resolve","Lifecycle.lookup","Lifecycle.Settled","Lifecycle.Unconfirmed","Lifecycle.combine","Lifecycle.start","Lifecycle.transition"],"sources":["../src/internal/supervisor/lifecycle.ts","../src/Supervisor.ts"],"sourcesContent":["/**\n * A supervisor's life as one state and one transition function, and the generation states it\n * publishes. The transition has no effects: `Supervisor.make` applies each input under one lock,\n * publishes the events in order and runs the commands, so the rules here are tested alone.\n */\nimport { Schema } from \"effect\";\n\nimport { DisconnectCause } from \"../../BrowserEvent.ts\";\n\n/** The provider confirmed that the generation's browser ended. */\nexport class Settled extends Schema.TaggedClass<Settled>()(\"Settled\", {}) {}\n\n/** The provider could not confirm the end by its deadline, so the browser may still run, and bill. */\nexport class Unconfirmed extends Schema.TaggedClass<Unconfirmed>()(\"Unconfirmed\", {\n detail: Schema.String,\n}) {}\n\nexport const Released = Schema.Union([Settled, Unconfirmed]);\n\nexport type Released = typeof Released.Type;\n\n/** Opening, but not after a loss: the first generation, a rotation, or the one after `Down`. */\nexport class Opening extends Schema.TaggedClass<Opening>()(\"Opening\", {}) {}\n\n/** Opening after the generation before it was lost. */\nexport class Reopening extends Schema.TaggedClass<Reopening>()(\"Reopening\", {}) {}\n\n/** Open: `browser` gives this generation until the next one opens. */\nexport class Open extends Schema.TaggedClass<Open>()(\"Open\", {}) {}\n\n/** No longer serving; holds end at this host-monotonic deadline or when their owners let go. */\nexport class Draining extends Schema.TaggedClass<Draining>()(\"Draining\", {\n reason: Schema.Literals([\"rotated\", \"lost\", \"retired\"]),\n revokeAt: Schema.Finite,\n}) {}\n\n/** Lost through disconnection or a consumer's declaration that it is unusable. */\nexport class Lost extends Schema.TaggedClass<Lost>()(\"Lost\", {\n cause: Schema.Union([DisconnectCause, Schema.Literal(\"declared\")]),\n detail: Schema.optional(Schema.String),\n}) {}\n\n/**\n * It never opened: its last try failed with `cause`, which the provider deems definite, or after\n * which the reopen schedule gave up. `released` combines this generation's failed-try cleanup,\n * retaining the first unconfirmed end; it is absent when no try reported cleanup.\n */\nexport class Down extends Schema.TaggedClass<Down>()(\"Down\", {\n detail: Schema.String,\n cause: Schema.Defect(),\n released: Schema.optional(Released),\n}) {}\n\n/** It ended. `released` includes reported cleanup when retired while opening, if any. */\nexport class Closed extends Schema.TaggedClass<Closed>()(\"Closed\", {\n released: Schema.optional(Released),\n}) {}\n\n/**\n * It was serving as the supervisor's scope closed, and was left running, not released: its scope\n * closed, and its provider runs it on, and bills, until something adopts and releases it.\n */\nexport class Kept extends Schema.TaggedClass<Kept>()(\"Kept\", {}) {}\n\nexport const GenerationState = Schema.Union([\n Opening,\n Reopening,\n Open,\n Draining,\n Lost,\n Down,\n Closed,\n Kept,\n]);\n\nexport type GenerationState = typeof GenerationState.Type;\n\n/** A generation that opened: its number, and what the runtime keeps to serve and end it. */\nexport interface Live<A> {\n readonly number: number;\n readonly value: A;\n}\n\nexport interface Held<A, H> extends Live<A> {\n readonly holds: ReadonlySet<H>;\n}\n\n/** Release ownership remains here until the provider and generation scope have finished. */\nexport interface Drain<A, H> {\n readonly _tag: \"Draining\" | \"Releasing\" | \"Leaving\";\n readonly live: Held<A, H>;\n readonly ending: Draining;\n}\n\n/** One serving generation, one shared acquisition, and prior generations still owned. */\nexport type State<A, H = unknown> = (\n | { readonly _tag: \"Opening\"; readonly number: number; readonly serving: Held<A, H> | undefined }\n | { readonly _tag: \"Open\"; readonly serving: Held<A, H> }\n | {\n readonly _tag: \"Down\";\n readonly number: number;\n readonly detail: string;\n readonly cause: unknown;\n readonly serving: Held<A, H> | undefined;\n }\n | { readonly _tag: \"Retired\" }\n) & {\n readonly draining: ReadonlyMap<number, Drain<A, H>>;\n /** Retain the first unconfirmed end, otherwise the latest settled end, without its resources. */\n readonly released?: Released | undefined;\n /** Failed-try outcomes by their opening generation, forgotten when that opening ends. */\n readonly attempts?: ReadonlyMap<number, Released> | undefined;\n};\n\nexport type Input<A, H = unknown> =\n | { readonly _tag: \"Opened\"; readonly live: Live<A> }\n | { readonly _tag: \"AttemptReleased\"; readonly number: number; readonly released: Released }\n | {\n readonly _tag: \"Failed\";\n readonly number: number;\n readonly detail: string;\n readonly cause: unknown;\n }\n | { readonly _tag: \"Abandoned\"; readonly number: number }\n | {\n readonly _tag: \"Lost\";\n readonly number: number;\n readonly cause: Lost[\"cause\"];\n readonly detail?: string | undefined;\n }\n | { readonly _tag: \"Rotate\"; readonly due?: number | undefined }\n | { readonly _tag: \"Retire\" }\n | { readonly _tag: \"Keep\" }\n | {\n readonly _tag: \"Hold\";\n readonly number?: number | undefined;\n readonly hold: H;\n }\n | { readonly _tag: \"Let\"; readonly number: number; readonly hold: H }\n | { readonly _tag: \"Revoke\"; readonly number: number }\n | {\n readonly _tag: \"Released\";\n readonly number: number;\n readonly released?: Released | undefined;\n };\n\nexport type Command<A> =\n | { readonly _tag: \"Open\"; readonly number: number }\n | { readonly _tag: \"Watch\"; readonly live: Live<A> }\n /** Signal ending and arrange revocation. Repeated only when loss/retirement accelerates it. */\n | { readonly _tag: \"Drain\"; readonly live: Live<A>; readonly ending: Draining }\n /** Revoke/close holds, await their Let inputs, release the provider, then close its scope. */\n | { readonly _tag: \"Release\"; readonly live: Live<A>; readonly ending: Draining }\n | { readonly _tag: \"Leave\"; readonly live: Live<A>; readonly ending: Draining };\n\nexport interface Step<A, H = unknown> {\n readonly state: State<A, H>;\n readonly events: ReadonlyArray<readonly [number, GenerationState]>;\n readonly commands: ReadonlyArray<Command<A>>;\n readonly reply?: number | undefined;\n readonly borrowed?: Live<A> | undefined;\n}\n\nexport const start = <A, H = unknown>(): Step<A, H> => ({\n state: { _tag: \"Opening\", number: 1, serving: undefined, draining: new Map() },\n events: [[1, new Opening()]],\n commands: [{ _tag: \"Open\", number: 1 }],\n});\n\nconst servingOf = <A, H>(state: State<A, H>) =>\n state._tag === \"Retired\" ? undefined : state.serving;\n\n/** The holds still owned for a generation, including one whose release has begun. */\nexport const lookup = <A, H>(state: State<A, H>, number: number): Held<A, H> | undefined =>\n servingOf(state)?.number === number ? servingOf(state) : state.draining.get(number)?.live;\n\n/** A transition's local result builder; input state and its collections remain immutable. */\ninterface Change<A, H> {\n readonly now: number;\n readonly handover: number;\n readonly exclusive: boolean;\n state: State<A, H>;\n events: Array<readonly [number, GenerationState]>;\n commands: Array<Command<A>>;\n reply?: number;\n borrowed?: Live<A>;\n}\n\n/** The sole writer of a drain's ending and phase; each release command is emitted once. */\nconst draining = <A, H>(change: Change<A, H>, drain: Drain<A, H>) => {\n const before = change.state.draining.get(drain.live.number);\n const { live, ending, _tag } = drain;\n\n change.state = {\n ...change.state,\n draining: new Map(change.state.draining).set(live.number, drain),\n };\n if (before?.ending !== ending) {\n change.events.push([live.number, ending]);\n change.commands.push({ _tag: \"Drain\", live, ending });\n }\n if (_tag !== \"Draining\" && before?._tag !== _tag)\n change.commands.push({ _tag: _tag === \"Leaving\" ? \"Leave\" : \"Release\", live, ending });\n};\n\nconst end = <A, H>(\n change: Change<A, H>,\n live: Held<A, H>,\n reason: Draining[\"reason\"],\n keep = false,\n) => {\n const ending = new Draining({\n reason,\n revokeAt: change.now + (reason === \"rotated\" ? change.handover : 0),\n });\n\n draining(change, {\n live,\n ending,\n _tag: keep\n ? \"Leaving\"\n : live.holds.size === 0 || ending.revokeAt <= change.now\n ? \"Releasing\"\n : \"Draining\",\n });\n};\n\nconst revoke = <A, H>(change: Change<A, H>, number: number, reason?: \"lost\" | \"retired\") => {\n const drain = change.state.draining.get(number);\n\n if (drain?._tag !== \"Draining\" || (reason === undefined && change.now < drain.ending.revokeAt))\n return;\n draining(change, {\n ...drain,\n _tag: \"Releasing\",\n ending: reason === undefined ? drain.ending : new Draining({ reason, revokeAt: change.now }),\n });\n};\n\nconst holds = <A, H>(\n change: Change<A, H>,\n input: Extract<Input<A, H>, { readonly _tag: \"Hold\" | \"Let\" }>,\n) => {\n const number = input.number ?? servingOf(change.state)?.number;\n const live = number === undefined ? undefined : lookup(change.state, number);\n\n if (live === undefined) return;\n const drain = change.state.draining.get(live.number);\n\n if (\n input._tag === \"Hold\" &&\n drain !== undefined &&\n (drain._tag !== \"Draining\" || change.now >= drain.ending.revokeAt)\n )\n return;\n if (live.holds.has(input.hold) === (input._tag === \"Hold\")) return;\n const holds = new Set(live.holds);\n\n if (input._tag === \"Hold\") {\n holds.add(input.hold);\n change.borrowed = live;\n } else holds.delete(input.hold);\n const held = { ...live, holds };\n\n if (drain !== undefined)\n draining(change, {\n ...drain,\n live: held,\n _tag: drain._tag === \"Draining\" && holds.size === 0 ? \"Releasing\" : drain._tag,\n });\n else if (change.state._tag !== \"Retired\") change.state = { ...change.state, serving: held };\n};\n\nconst next = <A, H>(change: Change<A, H>, number: number, reopen: boolean) => {\n const { exclusive } = change;\n const current = servingOf(change.state);\n\n if (current !== undefined && (reopen || exclusive))\n end(change, current, reopen ? \"lost\" : \"rotated\");\n change.state = {\n _tag: \"Opening\",\n number,\n serving: reopen || exclusive ? undefined : current,\n draining: change.state.draining,\n released: change.state.released,\n attempts: change.state.attempts,\n };\n change.events.push([number, reopen ? new Reopening() : new Opening()]);\n change.commands.push({ _tag: \"Open\", number });\n};\n\nconst lost = <A, H>(\n change: Change<A, H>,\n input: Extract<Input<A, H>, { readonly _tag: \"Lost\" }>,\n) => {\n const { state } = change;\n const drain = state.draining.get(input.number);\n const current = servingOf(state);\n\n if (input.cause === \"declared\" && current?.number !== input.number) return;\n if (drain?._tag === \"Draining\") {\n change.events.push([input.number, new Lost({ cause: input.cause })]);\n revoke(change, input.number, \"lost\");\n } else if (state._tag !== \"Retired\" && current?.number === input.number) {\n change.events.push([input.number, new Lost({ cause: input.cause, detail: input.detail })]);\n if (state._tag !== \"Opening\")\n next(change, (state._tag === \"Open\" ? current.number : state.number) + 1, true);\n else {\n change.state = { ...state, serving: undefined };\n end(change, current, \"lost\");\n }\n }\n};\n\n/** End one opening without confusing its cleanup with preceding generations' releases. */\nconst finishAttempt = <A, H>(change: Change<A, H>, number: number) => {\n const attempts = new Map(change.state.attempts);\n const released = attempts.get(number);\n\n attempts.delete(number);\n change.state = { ...change.state, attempts };\n\n return released;\n};\n\n/** Pure admission and lifecycle changes. A rejected hold preserves state identity. */\nexport const transition = <A, H = unknown>(\n state: State<A, H>,\n input: Input<A, H>,\n exclusive: boolean,\n now = 0,\n handover = 30_000,\n): Step<A, H> => {\n const change: Change<A, H> = {\n state,\n events: [],\n commands: [],\n exclusive,\n handover,\n now,\n };\n\n switch (input._tag) {\n case \"Hold\":\n case \"Let\":\n holds(change, input);\n break;\n case \"Revoke\":\n revoke(change, input.number);\n break;\n case \"Opened\": {\n const live = { ...input.live, holds: new Set<H>() };\n\n if (lookup(state, live.number) !== undefined) break;\n if (state._tag !== \"Opening\" || state.number !== live.number) end(change, live, \"retired\");\n else {\n finishAttempt(change, live.number);\n change.events.push([live.number, new Open()]);\n change.commands.push({ _tag: \"Watch\", live });\n if (state.serving !== undefined) end(change, state.serving, \"rotated\");\n change.state = {\n _tag: \"Open\",\n serving: live,\n draining: change.state.draining,\n released: change.state.released,\n attempts: change.state.attempts,\n };\n }\n break;\n }\n case \"Failed\": {\n const { number, detail, cause } = input;\n\n if (state._tag === \"Opening\" && state.number === number)\n change.state = { ...state, _tag: \"Down\", detail, cause };\n change.events.push([\n number,\n new Down({ detail, cause, released: finishAttempt(change, number) }),\n ]);\n break;\n }\n case \"Abandoned\":\n change.events.push([\n input.number,\n new Closed({ released: finishAttempt(change, input.number) }),\n ]);\n break;\n case \"AttemptReleased\":\n change.state = {\n ...state,\n released: combine(state.released, input.released),\n attempts: new Map(state.attempts).set(\n input.number,\n combine(state.attempts?.get(input.number), input.released),\n ),\n };\n break;\n case \"Released\": {\n const { number, released } = input;\n const drain = state.draining.get(number);\n\n if (drain === undefined || drain._tag === \"Draining\" || drain.live.holds.size > 0) break;\n const draining = new Map(state.draining);\n\n draining.delete(number);\n change.state = { ...state, draining, released: combine(state.released, released) };\n const outcome = combine(finishAttempt(change, number), released);\n\n change.events.push([\n number,\n released === undefined ? new Kept() : new Closed({ released: outcome }),\n ]);\n break;\n }\n case \"Lost\":\n lost(change, input);\n break;\n case \"Rotate\": {\n if (\n state._tag === \"Retired\" ||\n (input.due !== undefined && (state._tag !== \"Open\" || state.serving.number !== input.due))\n )\n break;\n change.reply =\n state._tag === \"Opening\"\n ? state.number\n : (state._tag === \"Open\" ? state.serving.number : state.number) + 1;\n if (state._tag !== \"Opening\") next(change, change.reply, false);\n break;\n }\n case \"Keep\":\n case \"Retire\":\n if (state._tag === \"Retired\") break;\n for (const number of state.draining.keys()) revoke(change, number, \"retired\");\n if (state.serving !== undefined) end(change, state.serving, \"retired\", input._tag === \"Keep\");\n change.state = {\n _tag: \"Retired\",\n draining: change.state.draining,\n released: change.state.released,\n attempts: change.state.attempts,\n };\n }\n\n return change;\n};\n\n/** Later confirmations cannot establish that an earlier unconfirmed session ended. */\nexport function combine(before: Released | undefined, next: Released): Released;\n\nexport function combine(\n before: Released | undefined,\n next: Released | undefined,\n): Released | undefined;\n\nexport function combine(before: Released | undefined, next: Released | undefined) {\n return before?._tag === \"Unconfirmed\" ? before : (next ?? before);\n}\n\nexport type Resolution<A> =\n | { readonly _tag: \"Serve\"; readonly live: Live<A> }\n | {\n readonly _tag: \"Unavailable\";\n readonly reason: \"down\" | \"retired\";\n readonly detail: string;\n readonly cause?: unknown;\n };\n\n/** An unheld browser resolution; use obtains its hold atomically through Hold instead. */\nexport const resolve = <A, H>(\n state: State<A, H>,\n target: number | undefined,\n): Resolution<A> | undefined => {\n if (state._tag === \"Retired\")\n return { _tag: \"Unavailable\", reason: \"retired\", detail: \"the supervisor was retired\" };\n if (\n state.serving !== undefined &&\n (target === undefined || (state._tag === \"Open\" && state.serving.number >= target))\n )\n return { _tag: \"Serve\", live: state.serving };\n if (state._tag === \"Down\" && (target === undefined || state.number >= target))\n return { _tag: \"Unavailable\", reason: \"down\", detail: state.detail, cause: state.cause };\n\n return undefined;\n};\n","/**\n * A browser kept open across losses and session ends, as a series of generations, each a new\n * browser from the same provider. Pages don't carry over from one generation to the next.\n *\n * `make` opens the first generation at once with the provider's `open`, in a scope of its own, so\n * a caller that stops waiting never interrupts a half-open browser. `browser` gives the current\n * generation; callers wait, bounded, and share one open. A loss is published at once and the next\n * generation opens on the `reopen` schedule, which also retries a failed open, unless the provider\n * deems its failure `definite`: that goes `Down` at once, with its cause. `rotate` opens the\n * next generation now, and so does the time `rotateBefore` ahead of a generation's `expiresAt`. A\n * rotation makes the next generation before it breaks the current one, unless generations are\n * `exclusive`, as sessions saving to one stored context must be: then the current one is released\n * first. `retire` stops reopening at once and releases what is open; the scope's close retires\n * too, unless the supervisor `keep`s: then it leaves the serving generation running, `Kept`. `states`\n * publishes each generation's changes, with the provider's release outcome last.\n *\n * Providers supply the specifics: `Browserbase.supervise` opens hosted sessions this way.\n *\n * @since 0.3.0\n */\nimport {\n Cause,\n Clock,\n Context,\n DateTime,\n Deferred,\n Duration,\n Effect,\n Exit,\n FiberHandle,\n FiberMap,\n Option,\n Predicate,\n PubSub,\n Schedule,\n Schema,\n Scope,\n Semaphore,\n Stream,\n SubscriptionRef,\n type Take,\n} from \"effect\";\n\nimport type * as Browser from \"./Browser.ts\";\nimport * as Lifecycle from \"./internal/supervisor/lifecycle.ts\";\n\nexport {\n Closed,\n Down,\n Draining,\n GenerationState,\n Kept,\n Lost,\n Open,\n Opening,\n Released,\n Reopening,\n Settled,\n Unconfirmed,\n} from \"./internal/supervisor/lifecycle.ts\";\n\n/** One change in a generation's life. `at` is wall-clock epoch milliseconds from the Effect `Clock`. */\nexport class Generation extends Schema.Class<Generation>(\"effect-browser/Generation\")({\n number: Schema.Int.check(Schema.isGreaterThan(0)),\n at: Schema.Finite,\n hostTime: Schema.Finite,\n state: Lifecycle.GenerationState,\n}) {}\n\n/**\n * No browser to give: none opened within `waitTimeout` (`opening`), the latest generation failed\n * to open (`down`, with what it failed with as `cause`), or the supervisor was retired.\n */\nexport class Unavailable extends Schema.TaggedError<Unavailable>()(\"Unavailable\", {\n reason: Schema.Literals([\"opening\", \"down\", \"retired\"]),\n detail: Schema.String,\n cause: Schema.optional(Schema.Defect()),\n}) {\n override get message() {\n return `no browser: ${this.detail}`;\n }\n}\n\n/** One generation, as a provider opened it in the scope the supervisor gave it. */\nexport interface Opened<A = void> {\n readonly value: A;\n readonly browser: Browser.Service;\n /**\n * End the generation, and say whether the provider confirmed its end. The supervisor asks it\n * before it closes the generation's scope; without it, closing the scope ends the generation,\n * which counts as `Settled`.\n */\n readonly release?: Effect.Effect<Lifecycle.Released> | undefined;\n}\n\n/** Facts available before an acquisition attempt; awaiting `after` never changes release order. */\nexport interface Admission {\n readonly number: number;\n /**\n * Every earlier session that stopped serving, including failed attempts and older drains.\n * Waits for all pending releases; an Unconfirmed end remains visible to later attempts.\n * Undefined before any release. A still-serving nonexclusive predecessor is excluded.\n */\n readonly after: Effect.Effect<Lifecycle.Released> | undefined;\n}\n\n/**\n * Optional service supplied during `open`. Providers report failed-attempt cleanup here before\n * their scope closes; successful generations instead return `Opened.release`. Reporting does\n * not release resources or replace the original acquisition failure. Terminal `Down` and opening\n * `Closed` states publish the reported outcomes of their own generation's tries.\n */\nexport class Releasing extends Context.Service<\n Releasing,\n { readonly released: (outcome: Lifecycle.Released) => Effect.Effect<void> }\n>()(\"effect-browser/Supervisor/Releasing\") {}\n\nexport interface Options<E, R, A = void> {\n /** Opens one generation in the scope it is given. */\n readonly open: Effect.Effect<Opened<A>, E, R>;\n /** Runs before every open attempt, including the first; failures follow `reopen` and `definite`. */\n readonly admit?: ((opening: Admission) => Effect.Effect<void, E, R>) | undefined;\n /** When to try a failed open again. Defaults to exponential from 1 second, for 5 minutes. */\n readonly reopen?: Schedule.Schedule<unknown, E> | undefined;\n /**\n * Failures no new try mends, such as a refused key: an open that fails so is `Down` at once.\n * Defaults to none.\n */\n readonly definite?: ((error: E) => boolean) | undefined;\n /**\n * Rotate this long ahead of a generation's `expiresAt`, but no sooner than halfway through its\n * life. Without it, a generation's end is a loss.\n */\n readonly rotateBefore?: Duration.Input | undefined;\n /** Generations must not overlap: a rotation releases the current one before it opens the next. */\n readonly exclusive?: boolean | undefined;\n /** Finite, nonnegative time outgoing holds may finish; defaults to 30 seconds. */\n readonly handover?: Duration.Input | undefined;\n /**\n * Closing the scope leaves the serving generation running, `Kept`: it closes the generation's\n * scope but never asks `release`. For providers whose scope only disconnects, such as\n * `Browserbase.supervise` with `keep`. `retire` still releases it.\n */\n readonly keep?: boolean | undefined;\n /** How long `browser` and `rotate` wait for a generation to open. Defaults to 2 minutes. */\n readonly waitTimeout?: Duration.Input | undefined;\n}\n\n/** Work whose generation was revoked; input receipts still determine whether input reached a site. */\nexport class Superseded extends Schema.TaggedError<Superseded>()(\"Superseded\", {\n generation: Schema.Int,\n reason: Schema.Literals([\"rotated\", \"lost\", \"retired\"]),\n revokeAt: Schema.Finite,\n}) {}\n\nexport interface Lease<A> {\n readonly generation: number;\n readonly browser: Browser.Service;\n readonly value: A;\n /** Declare this serving generation unusable and revoke it now; stale declarations do nothing. */\n readonly lose: (detail: string) => Effect.Effect<void>;\n /** First notice that serving ended; loss or retirement may revoke before its deadline. */\n readonly ending: Effect.Effect<Superseded>;\n /** An independent scope; its resources close before provider release. Fails once revoked. */\n readonly retain: Effect.Effect<Scope.Closeable, Superseded>;\n}\n\nexport interface UseOptions {\n /** Finite, nonnegative wait for a serving generation. Zero makes an immediate attempt. */\n readonly wait?: Duration.Input | undefined;\n}\n\nexport interface Supervisor<A = void> {\n /** Scoped work on the current generation. Revocation interrupts it and waits for its cleanup. */\n readonly use: <B, E, R>(\n work: (lease: Lease<A>) => Effect.Effect<B, E, R>,\n options?: UseOptions,\n ) => Effect.Effect<B, E | Unavailable | Superseded, Exclude<R, Scope.Scope>>;\n /** The current generation's browser, waiting up to `waitTimeout` while none is open. */\n readonly browser: Effect.Effect<Browser.Service, Unavailable>;\n /** Each generation's changes, in order. A new reader first gets the latest 64; ends on retiring. */\n readonly states: Stream.Stream<Generation>;\n /** Open the next generation now, or join the one opening, and wait for it. */\n readonly rotate: Effect.Effect<Browser.Service, Unavailable>;\n /** Stop opening at once, release every generation, and wait until each release has finished. */\n readonly retire: Effect.Effect<void>;\n}\n\ntype Hold =\n | { readonly _tag: \"Use\" }\n | { readonly _tag: \"Retained\"; readonly scope: Scope.Closeable };\n\ninterface Held<A> {\n readonly opened: Opened<A>;\n readonly ending: Deferred.Deferred<Superseded>;\n readonly revoked: Deferred.Deferred<Superseded>;\n readonly released: Deferred.Deferred<Lifecycle.Released>;\n readonly scope: Scope.Closeable;\n}\n\ntype State<A> = Lifecycle.State<Held<A>, Hold>;\ntype Input<A> = Lifecycle.Input<Held<A>, Hold>;\ntype Step<A> = Lifecycle.Step<Held<A>, Hold>;\ntype Apply<A> = (input: Input<A>) => Effect.Effect<Step<A>>;\n\nconst superseded = (generation: number, { reason, revokeAt }: Lifecycle.Draining) =>\n new Superseded({ generation, reason, revokeAt });\n\nconst retired = () => new Unavailable({ reason: \"retired\", detail: \"the supervisor was retired\" });\n\nconst describe = (cause: Cause.Cause<unknown>) => {\n const error = Cause.squash(cause);\n\n return Predicate.isError(error) ? error.message : String(error);\n};\n\nconst timedOut = () =>\n new Unavailable({ reason: \"opening\", detail: \"no generation opened within the wait\" });\n\nconst bounded = (input: Duration.Input, name: string) =>\n Effect.suspend(() => {\n const duration = Duration.fromInput(input);\n\n return Option.isSome(duration) &&\n Duration.isFinite(duration.value) &&\n !Duration.isNegative(duration.value)\n ? Effect.succeed(duration.value)\n : Effect.die(new RangeError(`${name} must be a finite nonnegative duration`));\n });\n\n/** Resolve immediately before starting a bounded wait, including when its duration is zero. */\nconst waitFor = <A, H>(\n state: SubscriptionRef.SubscriptionRef<Lifecycle.State<A, H>>,\n wait: Duration.Duration,\n clock: Clock.Clock,\n target?: number,\n) => {\n const result = (resolution: Lifecycle.Resolution<A>) =>\n resolution._tag === \"Serve\"\n ? Effect.succeed(resolution.live)\n : Effect.fail(new Unavailable(resolution));\n\n return Effect.suspend(() => {\n const current = Lifecycle.resolve(state.value, target);\n\n return current === undefined\n ? SubscriptionRef.changes(state).pipe(\n Stream.map((state) => Lifecycle.resolve(state, target)),\n Stream.filter(Predicate.isNotUndefined),\n Stream.runHead,\n Effect.flatMap(Option.match({ onNone: () => Effect.fail(retired()), onSome: result })),\n Effect.timeoutOrElse({ duration: wait, orElse: () => Effect.fail(timedOut()) }),\n )\n : result(current);\n }).pipe(Effect.provideService(Clock.Clock, clock));\n};\n\n/** Sleep until `before` ahead of `expiresAt`, but no sooner than halfway there from now. */\nconst untilRotation = (expiresAt: DateTime.Utc, before: Duration.Duration) =>\n Clock.currentTimeMillis.pipe(\n Effect.flatMap((now) => {\n const left = DateTime.toEpochMillis(expiresAt) - now;\n\n return Effect.sleep(Duration.millis(Math.max(left - Duration.toMillis(before), left / 2, 0)));\n }),\n );\n\n/** Native timers may wake a fraction early; a revocation must reach its monotonic deadline. */\nconst until = (at: number, now: () => number): Effect.Effect<void> =>\n Effect.suspend(() =>\n now() >= at\n ? Effect.void\n : Effect.sleep(Duration.millis(Math.ceil(at - now()))).pipe(Effect.andThen(until(at, now))),\n );\n\n/** Borrowed work and transferred scopes hold a generation until cleanup lets it go. */\nconst leasing = <A>(\n state: SubscriptionRef.SubscriptionRef<State<A>>,\n apply: Apply<A>,\n waitTimeout: Duration.Duration,\n now: () => number,\n clock: Clock.Clock,\n) => {\n const borrow = Effect.fnUntraced(function* (hold: Hold, wait: Duration.Duration) {\n const until = now() + Duration.toMillis(wait);\n\n for (;;) {\n const step = yield* apply({ _tag: \"Hold\", hold });\n\n if (step.borrowed !== undefined) return step.borrowed;\n yield* waitFor(state, Duration.millis(Math.max(0, until - now())), clock).pipe(\n Effect.interruptible,\n );\n if (now() >= until) return yield* timedOut();\n }\n });\n\n const leaseOf = (live: Lifecycle.Live<Held<A>>): Lease<A> => ({\n generation: live.number,\n browser: live.value.opened.browser,\n value: live.value.opened.value,\n lose: (detail) =>\n apply({ _tag: \"Lost\", number: live.number, cause: \"declared\", detail }).pipe(Effect.asVoid),\n ending: Deferred.await(live.value.ending),\n retain: Effect.uninterruptible(\n Effect.gen(function* () {\n const scope = yield* Scope.make();\n const hold: Hold = { _tag: \"Retained\", scope };\n const step = yield* apply({ _tag: \"Hold\", number: live.number, hold });\n\n if (step.borrowed === undefined) {\n yield* Scope.close(scope, Exit.void);\n\n return yield* yield* Deferred.await(live.value.ending);\n }\n yield* Scope.addFinalizer(\n scope,\n apply({ _tag: \"Let\", number: live.number, hold }).pipe(Effect.asVoid),\n );\n\n return scope;\n }),\n ),\n });\n\n const use: Supervisor<A>[\"use\"] = (work, options = {}) =>\n Effect.scoped(\n Effect.gen(function* () {\n const hold: Hold = { _tag: \"Use\" };\n const wait = yield* bounded(options.wait ?? waitTimeout, \"wait\");\n\n const live = yield* Effect.acquireRelease(borrow(hold, wait), (live) =>\n apply({ _tag: \"Let\", number: live.number, hold }).pipe(Effect.asVoid),\n );\n\n const revoked = Deferred.await(live.value.revoked).pipe(Effect.flatMap(Effect.fail));\n\n return yield* Effect.raceFirst(\n work(leaseOf(live)).pipe(\n // Declaring loss and returning can finish before the race's other fiber runs.\n Effect.tap(() =>\n Deferred.isDone(live.value.revoked).pipe(\n Effect.flatMap((done) => (done ? revoked : Effect.void)),\n ),\n ),\n ),\n revoked,\n );\n }),\n );\n\n return use;\n};\n\ntype Provider = Omit<Opened, \"value\">;\ntype MakeOptions<E, R, A> = Omit<Options<E, R, A>, \"open\"> & {\n readonly open: Effect.Effect<Opened<A> | Provider, E, R>;\n};\n\nconst acquireGeneration = <A, E, R>(\n open: Effect.Effect<Opened<A> | Provider, E, R>,\n own: Scope.Scope,\n) =>\n Effect.uninterruptibleMask((restore) =>\n Effect.flatMap(Scope.fork(own), (scope) =>\n restore(open.pipe(Scope.provide(scope))).pipe(\n Effect.onError((cause) => Scope.close(scope, Exit.failCause(cause))),\n Effect.map((opened): Held<A | void> => ({\n opened: { ...opened, value: \"value\" in opened ? opened.value : undefined },\n scope,\n ending: Deferred.makeUnsafe<Superseded>(),\n revoked: Deferred.makeUnsafe<Superseded>(),\n released: Deferred.makeUnsafe<Lifecycle.Released>(),\n })),\n ),\n ),\n );\n\nconst watchGeneration = <A>(\n live: Lifecycle.Live<Held<A>>,\n rotateBefore: Duration.Duration | undefined,\n apply: Apply<A>,\n) => {\n const { browser } = live.value.opened;\n\n const loss = browser.disconnected.pipe(\n Effect.flatMap((cause) => apply({ _tag: \"Lost\", number: live.number, cause })),\n );\n\n const rotation =\n browser.expiresAt === undefined || rotateBefore === undefined\n ? Effect.void\n : untilRotation(browser.expiresAt, rotateBefore).pipe(\n Effect.andThen(apply({ _tag: \"Rotate\", due: live.number })),\n );\n\n return Effect.all([loss, rotation], { concurrency: 2, discard: true });\n};\n\n// After revocation, retained resources and use finalizers let go before the provider.\nconst releaseGeneration = Effect.fnUntraced(function* <A>(\n command: Extract<Lifecycle.Command<Held<A>>, { readonly _tag: \"Release\" | \"Leave\" }>,\n state: SubscriptionRef.SubscriptionRef<State<A>>,\n apply: Apply<A>,\n) {\n const { live } = command;\n\n const cleaned = yield* Effect.forEach(\n Lifecycle.lookup(state.value, live.number)?.holds ?? [],\n (hold) =>\n Effect.exit(hold._tag === \"Retained\" ? Scope.close(hold.scope, Exit.void) : Effect.void),\n { concurrency: 8 },\n );\n\n yield* SubscriptionRef.changes(state).pipe(\n Stream.filter((current) => (Lifecycle.lookup(current, live.number)?.holds.size ?? 0) === 0),\n Stream.runHead,\n );\n\n const released =\n command._tag === \"Leave\"\n ? undefined\n : yield* (live.value.opened.release ?? Effect.succeed(new Lifecycle.Settled())).pipe(\n Effect.catchCause((cause) =>\n Effect.succeed(\n new Lifecycle.Unconfirmed({ detail: `the release failed: ${describe(cause)}` }),\n ),\n ),\n );\n\n const closed = yield* Effect.exit(Scope.close(live.value.scope, Exit.void));\n\n yield* apply({ _tag: \"Released\", number: live.number, released });\n if (released !== undefined) yield* Deferred.succeed(live.value.released, released);\n yield* Exit.asVoidAll([...cleaned, closed]);\n});\n\nconst admissionAfter = <A>(state: State<A>) => {\n const released = state.released;\n\n const pending = [...state.draining.values()]\n .filter((drain) => drain._tag !== \"Leaving\")\n .map(({ live }) => live.value.released);\n\n return pending.length === 0 && released === undefined\n ? undefined\n : Effect.gen(function* () {\n let outcome = released;\n\n for (const release of pending)\n outcome = Lifecycle.combine(outcome, yield* Deferred.await(release));\n\n return outcome ?? new Lifecycle.Settled();\n });\n};\n\nconst makeScoped = Effect.fn(\"Supervisor.make\")(function* <E, R, A>(\n options: MakeOptions<E, R, A>,\n): Effect.fn.Return<Supervisor<A | void>, never, Scope.Scope | Exclude<R, Scope.Scope>> {\n const clock = yield* Clock.Clock;\n const now = () => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;\n const context = yield* Effect.context<Exclude<R, Scope.Scope>>();\n const own = yield* Scope.fork(yield* Effect.scope);\n const exclusive = options.exclusive ?? false;\n\n const reopen: Schedule.Schedule<unknown, E> =\n options.reopen ??\n Schedule.exponential(\"1 second\").pipe(Schedule.upTo({ duration: Duration.minutes(5) }));\n\n const rotateBefore =\n options.rotateBefore === undefined ? undefined : Duration.fromInputUnsafe(options.rotateBefore);\n\n const waitTimeout = yield* bounded(options.waitTimeout ?? Duration.minutes(2), \"waitTimeout\");\n\n const handover = Duration.toMillis(\n yield* bounded(options.handover ?? Duration.seconds(30), \"handover\"),\n );\n\n const started = Lifecycle.start<Held<A | void>, Hold>();\n const state = yield* SubscriptionRef.make(started.state);\n const applying = yield* Semaphore.make(1);\n const events = yield* PubSub.unbounded<Take.Take<Generation>>({ replay: 64 });\n const opening = yield* FiberHandle.make<unknown, never>();\n const releases = yield* FiberMap.make<number, unknown, never>();\n const runOpen = yield* FiberHandle.runtime(opening)();\n const runRelease = yield* FiberMap.runtime(releases)();\n\n const apply: Apply<A | void> = Effect.fnUntraced(\n function* (input: Input<A | void>) {\n const current = state.value;\n const step = Lifecycle.transition(current, input, exclusive, now(), handover);\n\n if (step.state !== current) yield* SubscriptionRef.set(state, step.state);\n yield* perform(step);\n\n return step;\n },\n (effect) => applying.withPermit(effect),\n Effect.uninterruptible,\n Effect.provideService(Clock.Clock, clock),\n );\n\n const perform = Effect.fnUntraced(function* (step: Step<A | void>): Effect.fn.Return<void> {\n for (const [number, generation] of step.events)\n PubSub.publishUnsafe(events, [\n new Generation({\n number,\n at: clock.currentTimeMillisUnsafe(),\n hostTime: now(),\n state: generation,\n }),\n ]);\n for (const command of step.commands)\n switch (command._tag) {\n case \"Open\":\n runOpen(openGeneration(command.number));\n break;\n case \"Watch\":\n yield* Effect.forkIn(\n Effect.provideContext(watchGeneration(command.live, rotateBefore, apply), context),\n command.live.value.scope,\n );\n break;\n case \"Drain\": {\n const ending = superseded(command.live.number, command.ending);\n\n yield* Deferred.succeed(command.live.value.ending, ending);\n yield* Effect.forkIn(\n until(ending.revokeAt, now).pipe(\n Effect.andThen(\n Effect.suspend(() => apply({ _tag: \"Revoke\", number: command.live.number })),\n ),\n ),\n command.live.value.scope,\n );\n break;\n }\n case \"Release\":\n case \"Leave\":\n yield* Deferred.succeed(\n command.live.value.revoked,\n superseded(command.live.number, command.ending),\n );\n runRelease(command.live.number, releaseGeneration(command, state, apply));\n break;\n }\n });\n\n const openGeneration = (number: number) => {\n const openOnce = acquireGeneration(\n Effect.gen(function* () {\n const after = admissionAfter(state.value);\n\n if (exclusive && after !== undefined) yield* after;\n yield* options.admit?.({ number, after }) ?? Effect.void;\n\n return yield* options.open.pipe(\n Effect.provideService(Releasing, {\n released: (released) =>\n apply({ _tag: \"AttemptReleased\", number, released }).pipe(Effect.asVoid),\n }),\n );\n }),\n own,\n ).pipe(Effect.provideContext(context));\n\n return Effect.uninterruptibleMask((restore) =>\n restore(\n Effect.retry(openOnce, {\n schedule: reopen,\n while: (error) => !options.definite?.(error),\n }),\n ).pipe(\n Effect.exit,\n Effect.flatMap((exit) => {\n if (Exit.isSuccess(exit))\n return apply({ _tag: \"Opened\", live: { number, value: exit.value } });\n const cause = exit.cause;\n\n return apply(\n Cause.hasInterruptsOnly(cause)\n ? { _tag: \"Abandoned\", number }\n : { _tag: \"Failed\", number, detail: describe(cause), cause: Cause.squash(cause) },\n );\n }),\n ),\n );\n };\n\n const end = yield* Effect.cached(PubSub.publish(events, Exit.void));\n\n const stop = Effect.fnUntraced(function* (input: Input<A | void>) {\n yield* apply(input);\n yield* FiberHandle.clear(opening);\n yield* FiberMap.awaitEmpty(releases);\n if (yield* Deferred.isDone(releases.deferred)) yield* FiberMap.join(releases);\n }, Effect.ensuring(end));\n\n const retire = yield* Effect.cached(stop({ _tag: \"Retire\" }));\n\n // The browser of the generation serving, or of the one `target` names once it serves.\n const browserOf = (target?: number) =>\n Effect.map(waitFor(state, waitTimeout, clock, target), (live) => live.value.opened.browser);\n\n yield* Effect.addFinalizer(() => (options.keep === true ? stop({ _tag: \"Keep\" }) : retire));\n yield* perform(started);\n\n return {\n browser: browserOf(),\n use: leasing(state, apply, waitTimeout, now, clock),\n states: Stream.fromPubSubTake(events),\n rotate: apply({ _tag: \"Rotate\" }).pipe(\n Effect.flatMap(({ reply }) =>\n reply === undefined ? Effect.fail(retired()) : browserOf(reply),\n ),\n ),\n retire,\n };\n});\n\n/** Supervise scoped generation values. Browser-only providers retain their existing void value. */\nexport function make<E, R, A = void>(\n options: Options<E, R, A>,\n): Effect.Effect<Supervisor<A>, never, Scope.Scope | Exclude<R, Scope.Scope>>;\n\nexport function make<E, R>(\n options: MakeOptions<E, R, never>,\n): Effect.Effect<Supervisor<void>, never, Scope.Scope | Exclude<R, Scope.Scope>>;\n\nexport function make<E, R, A>(options: MakeOptions<E, R, A>) {\n return makeScoped(options);\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;;AAG3E,IAAa,cAAb,cAAiC,OAAO,YAAyB,CAAC,CAAC,eAAe,EAChF,QAAQ,OAAO,OACjB,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAa,WAAW,OAAO,MAAM,CAAC,SAAS,WAAW,CAAC;;AAK3D,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;;AAG3E,IAAa,YAAb,cAA+B,OAAO,YAAuB,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;;AAGjF,IAAa,OAAb,cAA0B,OAAO,YAAkB,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;;AAGlE,IAAa,WAAb,cAA8B,OAAO,YAAsB,CAAC,CAAC,YAAY;CACvE,QAAQ,OAAO,SAAS;EAAC;EAAW;EAAQ;CAAS,CAAC;CACtD,UAAU,OA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AAQ,CAAC,IAAI,UAAU,KAAK,CAChE,CACF;EACA;CACF;AACF,CAAC;AAWD,SAAgB,KAAc,SAA+B;CAC3D,OAAO,WAAW,OAAO;AAC3B"}
|
|
@@ -37,16 +37,18 @@ declare class Lost extends Lost_base {}
|
|
|
37
37
|
declare const Down_base: Schema.Class<Down, Schema.TaggedStruct<"Down", {
|
|
38
38
|
readonly detail: Schema.String;
|
|
39
39
|
readonly cause: Schema.Defect;
|
|
40
|
+
readonly released: Schema.optional<Schema.Union<readonly [typeof Settled, typeof Unconfirmed]>>;
|
|
40
41
|
}>, {}>;
|
|
41
42
|
/**
|
|
42
43
|
* It never opened: its last try failed with `cause`, which the provider deems definite, or after
|
|
43
|
-
* which the reopen schedule gave up.
|
|
44
|
+
* which the reopen schedule gave up. `released` combines this generation's failed-try cleanup,
|
|
45
|
+
* retaining the first unconfirmed end; it is absent when no try reported cleanup.
|
|
44
46
|
*/
|
|
45
47
|
declare class Down extends Down_base {}
|
|
46
48
|
declare const Closed_base: Schema.Class<Closed, Schema.TaggedStruct<"Closed", {
|
|
47
49
|
readonly released: Schema.optional<Schema.Union<readonly [typeof Settled, typeof Unconfirmed]>>;
|
|
48
50
|
}>, {}>;
|
|
49
|
-
/** It ended. `released`
|
|
51
|
+
/** It ended. `released` includes reported cleanup when retired while opening, if any. */
|
|
50
52
|
declare class Closed extends Closed_base {}
|
|
51
53
|
declare const Kept_base: Schema.Class<Kept, Schema.TaggedStruct<"Kept", {}>, {}>;
|
|
52
54
|
/**
|
|
@@ -90,12 +92,15 @@ type State<A, H = unknown> = ({
|
|
|
90
92
|
readonly draining: ReadonlyMap<number, Drain<A, H>>;
|
|
91
93
|
/** Retain the first unconfirmed end, otherwise the latest settled end, without its resources. */
|
|
92
94
|
readonly released?: Released | undefined;
|
|
95
|
+
/** Failed-try outcomes by their opening generation, forgotten when that opening ends. */
|
|
96
|
+
readonly attempts?: ReadonlyMap<number, Released> | undefined;
|
|
93
97
|
};
|
|
94
98
|
type Input<A, H = unknown> = {
|
|
95
99
|
readonly _tag: "Opened";
|
|
96
100
|
readonly live: Live<A>;
|
|
97
101
|
} | {
|
|
98
102
|
readonly _tag: "AttemptReleased";
|
|
103
|
+
readonly number: number;
|
|
99
104
|
readonly released: Released;
|
|
100
105
|
} | {
|
|
101
106
|
readonly _tag: "Failed";
|
|
@@ -169,7 +174,8 @@ declare const lookup: <A, H>(state: State<A, H>, number: number) => Held<A, H> |
|
|
|
169
174
|
/** Pure admission and lifecycle changes. A rejected hold preserves state identity. */
|
|
170
175
|
declare const transition: <A, H = unknown>(state: State<A, H>, input: Input<A, H>, exclusive: boolean, now?: number, handover?: number) => Step<A, H>;
|
|
171
176
|
/** Later confirmations cannot establish that an earlier unconfirmed session ended. */
|
|
172
|
-
declare
|
|
177
|
+
declare function combine(before: Released | undefined, next: Released): Released;
|
|
178
|
+
declare function combine(before: Released | undefined, next: Released | undefined): Released | undefined;
|
|
173
179
|
type Resolution<A> = {
|
|
174
180
|
readonly _tag: "Serve";
|
|
175
181
|
readonly live: Live<A>;
|
|
@@ -231,7 +237,8 @@ declare const Releasing_base: Context.ServiceClass<Releasing, "effect-browser/Su
|
|
|
231
237
|
/**
|
|
232
238
|
* Optional service supplied during `open`. Providers report failed-attempt cleanup here before
|
|
233
239
|
* their scope closes; successful generations instead return `Opened.release`. Reporting does
|
|
234
|
-
* not release resources or replace the original acquisition failure.
|
|
240
|
+
* not release resources or replace the original acquisition failure. Terminal `Down` and opening
|
|
241
|
+
* `Closed` states publish the reported outcomes of their own generation's tries.
|
|
235
242
|
*/
|
|
236
243
|
declare class Releasing extends Releasing_base {}
|
|
237
244
|
interface Options<E, R, A = void> {
|
|
@@ -307,4 +314,4 @@ declare function make<E, R, A = void>(options: Options<E, R, A>): Effect.Effect<
|
|
|
307
314
|
declare function make<E, R>(options: MakeOptions<E, R, never>): Effect.Effect<Supervisor<void>, never, Scope.Scope | Exclude<R, Scope.Scope>>;
|
|
308
315
|
//#endregion
|
|
309
316
|
export { Settled as C, Reopening as S, Kept as _, Options as a, Opening as b, Supervisor as c, UseOptions as d, make as f, GenerationState as g, Draining as h, Opened as i, Supervisor_d_exports as l, Down as m, Generation as n, Releasing as o, Closed as p, Lease as r, Superseded as s, Admission as t, Unavailable as u, Lost as v, Unconfirmed as w, Released as x, Open as y };
|
|
310
|
-
//# sourceMappingURL=Supervisor-
|
|
317
|
+
//# sourceMappingURL=Supervisor-mVPeEUp8.d.mts.map
|
package/dist/Supervisor.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as Settled, S as Reopening, _ as Kept, a as Options, b as Opening, c as Supervisor, d as UseOptions, f as make, g as GenerationState, h as Draining, i as Opened, m as Down, n as Generation, o as Releasing, p as Closed, r as Lease, s as Superseded, t as Admission, u as Unavailable, v as Lost, w as Unconfirmed, x as Released, y as Open } from "./Supervisor-
|
|
1
|
+
import { C as Settled, S as Reopening, _ as Kept, a as Options, b as Opening, c as Supervisor, d as UseOptions, f as make, g as GenerationState, h as Draining, i as Opened, m as Down, n as Generation, o as Releasing, p as Closed, r as Lease, s as Superseded, t as Admission, u as Unavailable, v as Lost, w as Unconfirmed, x as Released, y as Open } from "./Supervisor-mVPeEUp8.mjs";
|
|
2
2
|
export { Admission, Closed, Down, Draining, Generation, GenerationState, Kept, Lease, Lost, Open, Opened, Opening, Options, Released, Releasing, Reopening, Settled, Superseded, Supervisor, Unavailable, Unconfirmed, UseOptions, make };
|
package/dist/Supervisor.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as Settled, a as Unavailable, c as Down, d as Kept, f as Lost, g as Reopening, h as Released, l as Draining, m as Opening, n as Releasing, o as make, p as Open, r as Superseded, s as Closed, t as Generation, u as GenerationState, v as Unconfirmed } from "./Supervisor-
|
|
1
|
+
import { _ as Settled, a as Unavailable, c as Down, d as Kept, f as Lost, g as Reopening, h as Released, l as Draining, m as Opening, n as Releasing, o as make, p as Open, r as Superseded, s as Closed, t as Generation, u as GenerationState, v as Unconfirmed } from "./Supervisor-2mPjIYYs.mjs";
|
|
2
2
|
export { Closed, Down, Draining, Generation, GenerationState, Kept, Lost, Open, Opening, Released, Releasing, Reopening, Settled, Superseded, Unavailable, Unconfirmed, make };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { maximumSamples } from "./Motion.mjs";
|
|
2
|
-
import { BrowserError, Closed, Failed, Timeout } from "./BrowserError.mjs";
|
|
2
|
+
import { BrowserError, Closed, Failed, InvalidRequest, Timeout } from "./BrowserError.mjs";
|
|
3
3
|
import { a as redactWithin, l as make$2 } from "./url-Cd04Okid.mjs";
|
|
4
4
|
import { Clock, Context, Data, Duration, Effect, Fiber, MutableRef, Option, Schema } from "effect";
|
|
5
5
|
var InputFailure = class extends Data.TaggedError("InputFailure") {};
|
|
@@ -49,14 +49,11 @@ const make$1 = () => {
|
|
|
49
49
|
const submit = (command) => {
|
|
50
50
|
if (reserved < 1) throw new Error("input must reserve capacity before dispatch");
|
|
51
51
|
reserved--;
|
|
52
|
-
let response;
|
|
53
52
|
try {
|
|
54
|
-
|
|
53
|
+
track(command(), true);
|
|
55
54
|
} catch (cause) {
|
|
56
55
|
failure ??= new InputFailure({ cause });
|
|
57
|
-
return;
|
|
58
56
|
}
|
|
59
|
-
track(response, true);
|
|
60
57
|
};
|
|
61
58
|
const reserve = (commands, maximum, limit) => Effect.gen(function* () {
|
|
62
59
|
yield* requireOpen;
|
|
@@ -69,12 +66,18 @@ const make$1 = () => {
|
|
|
69
66
|
}
|
|
70
67
|
reserved += commands;
|
|
71
68
|
});
|
|
72
|
-
|
|
69
|
+
const run = {
|
|
73
70
|
track,
|
|
74
71
|
afterIdle: (end) => {
|
|
75
72
|
if (pending.size === 0) end();
|
|
76
73
|
else endings.add(end);
|
|
77
74
|
},
|
|
75
|
+
recover: (cleanup, scope) => Effect.gen(function* () {
|
|
76
|
+
const replies = [...pending];
|
|
77
|
+
const done = Promise.withResolvers();
|
|
78
|
+
track(done.promise);
|
|
79
|
+
yield* Effect.promise(() => Promise.all(replies)).pipe(Effect.andThen(cleanup), Effect.ensuring(Effect.sync(() => done.resolve())), Effect.provideService(Current, run), Effect.interruptible, Effect.forkIn(scope));
|
|
80
|
+
}),
|
|
78
81
|
reserve: (commands) => reserve(commands, 64, 64),
|
|
79
82
|
reserveMotion: (commands) => reserve(commands, maximumSamples, 64 + maximumSamples),
|
|
80
83
|
send: (command) => Effect.gen(function* () {
|
|
@@ -118,10 +121,76 @@ const make$1 = () => {
|
|
|
118
121
|
reserved = 0;
|
|
119
122
|
})
|
|
120
123
|
};
|
|
124
|
+
return run;
|
|
121
125
|
})
|
|
122
126
|
};
|
|
123
127
|
};
|
|
124
128
|
//#endregion
|
|
129
|
+
//#region src/internal/pictures/clock.ts
|
|
130
|
+
/**
|
|
131
|
+
* Host monotonic milliseconds and the browser's clock read on the owner's: estimates of their
|
|
132
|
+
* offset from timed probes, how an estimate ages, and the mapping a browser's pages share.
|
|
133
|
+
* `pictures.ts` takes the probes.
|
|
134
|
+
*/
|
|
135
|
+
/** Read the captured owner's clock, including from native callbacks, without changing its origin. */
|
|
136
|
+
const monotonicMillis = (clock) => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;
|
|
137
|
+
/** The fastest complete probe limits uncertainty without mistaking transit delay for clock offset. */
|
|
138
|
+
const estimate = (probes) => {
|
|
139
|
+
let best;
|
|
140
|
+
for (const probe of probes) {
|
|
141
|
+
const roundTripMillis = probe.hostEnd - probe.hostStart;
|
|
142
|
+
if (!Number.isFinite(probe.hostStart) || !Number.isFinite(probe.hostEnd) || !Number.isFinite(probe.browserTime) || !Number.isFinite(roundTripMillis) || roundTripMillis < 0) continue;
|
|
143
|
+
const sampledAt = probe.hostStart + roundTripMillis / 2;
|
|
144
|
+
const offsetMillis = probe.browserTime - sampledAt;
|
|
145
|
+
if (!Number.isFinite(offsetMillis) || !Number.isFinite(probe.browserTime - probe.hostStart) || !Number.isFinite(probe.browserTime - probe.hostEnd)) continue;
|
|
146
|
+
if (best === void 0 || roundTripMillis < best.roundTripMillis) best = {
|
|
147
|
+
offsetMillis,
|
|
148
|
+
uncertaintyMillis: roundTripMillis / 2,
|
|
149
|
+
roundTripMillis,
|
|
150
|
+
sampledAt
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return Option.fromUndefinedOr(best);
|
|
154
|
+
};
|
|
155
|
+
const driftPerMillis = 1e-4;
|
|
156
|
+
/** An estimate's uncertainty at `hostTime`, wider the further that is from when it was sampled. */
|
|
157
|
+
const uncertaintyAt = (estimate, hostTime) => estimate.uncertaintyMillis + Math.abs(hostTime - estimate.sampledAt) * driftPerMillis;
|
|
158
|
+
const renewAfter = Duration.seconds(10);
|
|
159
|
+
/**
|
|
160
|
+
* Whether a new measurement should replace the current estimate. Each interval contains the true
|
|
161
|
+
* offset, so overlapping intervals agree and the narrower one is kept, the current one widened by
|
|
162
|
+
* its age: a probe delayed behind a busy page cannot widen every tab's stamps. A disjoint
|
|
163
|
+
* measurement means the clocks moved (a wall clock step, or drift between a remote browser and
|
|
164
|
+
* this host), so the newer evidence wins.
|
|
165
|
+
*/
|
|
166
|
+
const supersedes = (next, current) => {
|
|
167
|
+
const aged = uncertaintyAt(current, next.sampledAt);
|
|
168
|
+
return next.uncertaintyMillis <= aged || Math.abs(next.offsetMillis - current.offsetMillis) > next.uncertaintyMillis + aged;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Every renderer of a browser reads the same host wall clock, so the offset belongs to the
|
|
172
|
+
* browser rather than a page. A busy page cannot fail work that an earlier estimate can serve.
|
|
173
|
+
*/
|
|
174
|
+
const mapping = (now) => {
|
|
175
|
+
let latest;
|
|
176
|
+
let measuredAt = Number.NEGATIVE_INFINITY;
|
|
177
|
+
const adopt = (measure) => {
|
|
178
|
+
measuredAt = now();
|
|
179
|
+
return measure.pipe(Effect.map((estimate) => {
|
|
180
|
+
if (latest === void 0 || supersedes(estimate, latest)) latest = estimate;
|
|
181
|
+
return latest;
|
|
182
|
+
}));
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
latest: () => latest,
|
|
186
|
+
current: (measure) => Effect.suspend(() => latest === void 0 ? adopt(measure) : Effect.succeed(latest)),
|
|
187
|
+
renew: (measure) => Effect.suspend(() => latest === void 0 || now() - measuredAt < Duration.toMillis(renewAfter) ? Effect.void : Effect.ignore(adopt(measure)))
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
const toHostTime = (calibration, browserEpochMillis) => browserEpochMillis - calibration.offsetMillis;
|
|
191
|
+
/** CDP input timestamps use seconds, unlike browser frame timestamps and the owner's clock. */
|
|
192
|
+
const toBrowserSeconds = (calibration, hostMillis) => (hostMillis + calibration.offsetMillis) / 1e3;
|
|
193
|
+
//#endregion
|
|
125
194
|
//#region src/internal/page/context.ts
|
|
126
195
|
/**
|
|
127
196
|
* What a page's parts share: the browser state they act on, the page's own lane, pointer and
|
|
@@ -164,10 +233,12 @@ const undispatched = (operation, reason) => new BrowserError({
|
|
|
164
233
|
dispatched: false
|
|
165
234
|
});
|
|
166
235
|
const failWith = (operation, reason) => Effect.fail(undispatched(operation, reason));
|
|
236
|
+
/** Refuse a request to `operation` that could never succeed, before sending anything. */
|
|
237
|
+
const refuse = (operation, detail) => failWith(operation, new InvalidRequest({ detail }));
|
|
167
238
|
const decodeWith = (operation, schema) => (value) => Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError((error) => undispatched(operation, new Failed({ detail: error.message }))));
|
|
168
239
|
const make = (options, scope) => {
|
|
169
240
|
const { id, clock } = options;
|
|
170
|
-
const now = () =>
|
|
241
|
+
const now = () => monotonicMillis(clock);
|
|
171
242
|
const owned = Effect.provideService(Clock.Clock, clock);
|
|
172
243
|
const span = (name, attributes = {}, level) => (effect) => Effect.gen(function* () {
|
|
173
244
|
const cost = {
|
|
@@ -247,6 +318,7 @@ const make = (options, scope) => {
|
|
|
247
318
|
lane,
|
|
248
319
|
pointer,
|
|
249
320
|
now,
|
|
321
|
+
scope,
|
|
250
322
|
owned,
|
|
251
323
|
span,
|
|
252
324
|
protocol,
|
|
@@ -258,6 +330,6 @@ const make = (options, scope) => {
|
|
|
258
330
|
};
|
|
259
331
|
};
|
|
260
332
|
//#endregion
|
|
261
|
-
export { make as a,
|
|
333
|
+
export { make as a, undispatched as c, monotonicMillis as d, toBrowserSeconds as f, make$1 as g, Current as h, failWith as i, estimate as l, uncertaintyAt as m, contextGone as n, reasonOf as o, toHostTime as p, decodeWith as r, refuse as s, call as t, mapping as u };
|
|
262
334
|
|
|
263
|
-
//# sourceMappingURL=context-
|
|
335
|
+
//# sourceMappingURL=context-w3NJPRLo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-w3NJPRLo.mjs","names":["make","Url.redactWithin","BrowserClock.monotonicMillis","Lane.make"],"sources":["../src/internal/input/replies.ts","../src/internal/pictures/clock.ts","../src/internal/page/context.ts"],"sourcesContent":["/**\n * Bounded input replies owned by the page, including after an action is interrupted.\n * Canceling a caller cannot cancel a protocol command already sent. The next action waits for\n * those replies, while a stopped run releases only held keys or buttons whose release was never submitted.\n */\nimport { Context, Data, Effect, type Scope } from \"effect\";\n\nimport { maximumSamples } from \"../../Motion.ts\";\n\nexport const capacity = 64;\n\nexport class InputFailure extends Data.TaggedError(\"InputFailure\")<{\n readonly cause: unknown;\n}> {}\n\nexport interface Run {\n /** A native call made by this operation: cancellation cannot cancel its actual reply. */\n readonly track: <A>(reply: Promise<A>) => Promise<A>;\n /** End ownership after the record and all this operation's native replies have settled. */\n readonly afterIdle: (ended: () => void) => void;\n /** Retain authority through scoped cleanup after the replies already submitted. */\n readonly recover: (cleanup: Effect.Effect<void>, scope: Scope.Scope) => Effect.Effect<void>;\n /** Reserve a complete stroke, including its releases, before sending its first event. */\n readonly reserve: (commands: number) => Effect.Effect<void, InputFailure>;\n /** Admit every sample before a motion starts its published clock; ordinary input stays bounded separately. */\n readonly reserveMotion: (commands: number) => Effect.Effect<void, InputFailure>;\n readonly send: (command: () => Promise<unknown>) => Effect.Effect<void, InputFailure>;\n readonly down: (\n key: string,\n press: () => Promise<unknown>,\n release: () => Promise<unknown>,\n ) => Effect.Effect<void, InputFailure>;\n readonly up: (key: string) => Effect.Effect<void, InputFailure>;\n readonly drain: Effect.Effect<void, InputFailure>;\n /** Stop future input and submit missing releases without waiting indefinitely for replies. */\n readonly close: Effect.Effect<void>;\n}\n\n/** Native page calls join their operation's reply ownership, including script mutations. */\nexport const Current = Context.Reference<Run | undefined>(\"effect-browser/internal/input/Current\", {\n defaultValue: () => undefined,\n});\n\nexport const make = () => {\n const outstanding = new Set<Promise<void>>();\n\n // A timed-out action keeps capacity until its real replies arrive. Waiting for them sends\n // nothing, so cancellation here cannot leave a detached continuation that later types.\n const idle = Effect.gen(function* () {\n while (outstanding.size > 0) yield* Effect.promise(() => Promise.all(outstanding));\n });\n\n const begin = Effect.gen(function* () {\n yield* idle;\n const pending = new Set<Promise<void>>();\n const held: Array<{ readonly key: string; readonly release: () => Promise<unknown> }> = [];\n let failure: InputFailure | undefined;\n let reserved = 0;\n let closed = false;\n const observed = new WeakMap<Promise<unknown>, { input: boolean }>();\n const endings = new Set<() => void>();\n\n const track = <A>(response: Promise<A>, input = false): Promise<A> => {\n const existing = observed.get(response);\n\n if (existing !== undefined) {\n existing.input ||= input;\n\n return response;\n }\n const entry = { input };\n\n observed.set(response, entry);\n\n const reply = response\n .then(\n () => undefined,\n (cause: unknown) => {\n if (entry.input) failure ??= new InputFailure({ cause });\n },\n )\n .then(() => {\n pending.delete(reply);\n outstanding.delete(reply);\n if (pending.size === 0) {\n for (const end of endings) end();\n endings.clear();\n }\n });\n\n pending.add(reply);\n outstanding.add(reply);\n\n return response;\n };\n\n const requireOpen = Effect.suspend(() =>\n closed\n ? Effect.fail(new InputFailure({ cause: new Error(\"the input run has stopped\") }))\n : Effect.void,\n );\n\n const requireSuccess = Effect.suspend(() =>\n failure === undefined ? Effect.void : Effect.fail(failure),\n );\n\n const submit = (command: () => Promise<unknown>) => {\n if (reserved < 1) throw new Error(\"input must reserve capacity before dispatch\");\n reserved--;\n try {\n void track(command(), true);\n } catch (cause) {\n failure ??= new InputFailure({ cause });\n }\n };\n\n const reserve = (commands: number, maximum: number, limit: number) =>\n Effect.gen(function* () {\n yield* requireOpen;\n yield* requireSuccess;\n if (!Number.isInteger(commands) || commands < 1 || commands > maximum)\n return yield* Effect.die(new Error(\"invalid input reservation\"));\n while (outstanding.size + reserved + commands > limit) {\n yield* Effect.promise(() => Promise.race(outstanding));\n yield* requireOpen;\n yield* requireSuccess;\n }\n reserved += commands;\n });\n\n const run: Run = {\n track,\n afterIdle: (end) => {\n if (pending.size === 0) end();\n else endings.add(end);\n },\n recover: (cleanup, scope) =>\n Effect.gen(function* () {\n const replies = [...pending];\n const done = Promise.withResolvers<void>();\n\n // This reservation prevents a new action or suspension from overtaking cleanup.\n void track(done.promise);\n yield* Effect.promise(() => Promise.all(replies)).pipe(\n Effect.andThen(cleanup),\n Effect.ensuring(Effect.sync(() => done.resolve())),\n Effect.provideService(Current, run),\n Effect.interruptible,\n Effect.forkIn(scope),\n );\n }),\n reserve: (commands) => reserve(commands, capacity, capacity),\n // A dense stroke cannot wait for replies midway without changing its published timing.\n // Its finite reservation also leaves room for the ordinary pool's already-owned releases.\n reserveMotion: (commands) => reserve(commands, maximumSamples, capacity + maximumSamples),\n send: (command) =>\n Effect.gen(function* () {\n yield* requireOpen;\n yield* requireSuccess;\n yield* Effect.sync(() => submit(command));\n yield* requireSuccess;\n }),\n down: (key, press, release) =>\n Effect.gen(function* () {\n yield* requireOpen;\n yield* requireSuccess;\n yield* Effect.sync(() => {\n held.push({ key, release });\n submit(press);\n });\n yield* requireSuccess;\n }),\n up: (key) =>\n Effect.gen(function* () {\n yield* requireOpen;\n yield* Effect.sync(() => {\n const index = held.findLastIndex((entry) => entry.key === key);\n const entry = held[index];\n\n if (entry === undefined) return;\n // Submission owns the release, even if its reply fails. Retrying an uncertain\n // release could run page handlers twice, so cleanup never sends it again.\n held.splice(index, 1);\n submit(entry.release);\n });\n yield* requireSuccess;\n }),\n drain: Effect.gen(function* () {\n while (pending.size > 0) yield* Effect.promise(() => Promise.all(pending));\n yield* requireSuccess;\n }),\n close: Effect.sync(() => {\n if (closed) return;\n closed = true;\n for (const entry of held.toReversed()) submit(entry.release);\n held.length = 0;\n reserved = 0;\n }),\n };\n\n return run;\n });\n\n /** `idle` lets an action wait, in its page's turn, for the page's earlier replies. */\n return { idle, begin };\n};\n","/**\n * Host monotonic milliseconds and the browser's clock read on the owner's: estimates of their\n * offset from timed probes, how an estimate ages, and the mapping a browser's pages share.\n * `pictures.ts` takes the probes.\n */\nimport { type Clock, Duration, Effect, Option } from \"effect\";\n\n/** Read the captured owner's clock, including from native callbacks, without changing its origin. */\nexport const monotonicMillis = (clock: Clock.Clock): number =>\n Number(clock.monotonicTimeNanosUnsafe()) / 1e6;\n\nexport interface Probe {\n readonly hostStart: number;\n readonly hostEnd: number;\n readonly browserTime: number;\n}\n\nexport interface Estimate {\n /** Browser epoch milliseconds minus the owner's host monotonic milliseconds. */\n readonly offsetMillis: number;\n /** Either transport direction can own the entire round trip; symmetry is not assumed. */\n readonly uncertaintyMillis: number;\n readonly roundTripMillis: number;\n readonly sampledAt: number;\n}\n\n/** The fastest complete probe limits uncertainty without mistaking transit delay for clock offset. */\nexport const estimate = (probes: ReadonlyArray<Probe>): Option.Option<Estimate> => {\n let best: Estimate | undefined;\n\n for (const probe of probes) {\n const roundTripMillis = probe.hostEnd - probe.hostStart;\n\n if (\n !Number.isFinite(probe.hostStart) ||\n !Number.isFinite(probe.hostEnd) ||\n !Number.isFinite(probe.browserTime) ||\n !Number.isFinite(roundTripMillis) ||\n roundTripMillis < 0\n )\n continue;\n const sampledAt = probe.hostStart + roundTripMillis / 2;\n const offsetMillis = probe.browserTime - sampledAt;\n\n if (\n !Number.isFinite(offsetMillis) ||\n !Number.isFinite(probe.browserTime - probe.hostStart) ||\n !Number.isFinite(probe.browserTime - probe.hostEnd)\n )\n continue;\n if (best === undefined || roundTripMillis < best.roundTripMillis)\n best = {\n offsetMillis,\n uncertaintyMillis: roundTripMillis / 2,\n roundTripMillis,\n sampledAt,\n };\n }\n\n return Option.fromUndefinedOr(best);\n};\n\n// Two machines' clocks drift apart by up to about 100 parts per million, so an estimate says this\n// much less about the offset for each millisecond of its age.\nconst driftPerMillis = 1e-4;\n\n/** An estimate's uncertainty at `hostTime`, wider the further that is from when it was sampled. */\nexport const uncertaintyAt = (estimate: Estimate, hostTime: number): number =>\n estimate.uncertaintyMillis + Math.abs(hostTime - estimate.sampledAt) * driftPerMillis;\n\n// Ten seconds widen an estimate by a millisecond, far less than a remote round trip, so it is\n// measured again no more often than this.\nconst renewAfter = Duration.seconds(10);\n\n/**\n * The browser's one epoch mapping, shared by its pages, input runs and capture generations. It is\n * measured on first need, by the first capture, never ahead of it.\n */\nexport interface Mapping {\n /** The latest estimate, without measuring: input uses it, and never waits for one. */\n readonly latest: () => Estimate | undefined;\n /** The latest estimate, measured through `measure` only while the browser has none. */\n readonly current: <E>(measure: Effect.Effect<Estimate, E>) => Effect.Effect<Estimate, E>;\n /**\n * Measure again once ten seconds have passed since the latest measurement began. A failed\n * measurement keeps the estimate, which keeps widening with its age.\n */\n readonly renew: <E>(measure: Effect.Effect<Estimate, E>) => Effect.Effect<void>;\n}\n\n/**\n * Whether a new measurement should replace the current estimate. Each interval contains the true\n * offset, so overlapping intervals agree and the narrower one is kept, the current one widened by\n * its age: a probe delayed behind a busy page cannot widen every tab's stamps. A disjoint\n * measurement means the clocks moved (a wall clock step, or drift between a remote browser and\n * this host), so the newer evidence wins.\n */\nexport const supersedes = (next: Estimate, current: Estimate): boolean => {\n const aged = uncertaintyAt(current, next.sampledAt);\n\n return (\n next.uncertaintyMillis <= aged ||\n Math.abs(next.offsetMillis - current.offsetMillis) > next.uncertaintyMillis + aged\n );\n};\n\n/**\n * Every renderer of a browser reads the same host wall clock, so the offset belongs to the\n * browser rather than a page. A busy page cannot fail work that an earlier estimate can serve.\n */\nexport const mapping = (now: () => number): Mapping => {\n let latest: Estimate | undefined;\n let measuredAt = Number.NEGATIVE_INFINITY;\n\n // Called where a measurement is decided, so no other can be decided before this one begins.\n const adopt = <E>(measure: Effect.Effect<Estimate, E>) => {\n measuredAt = now();\n\n return measure.pipe(\n Effect.map((estimate) => {\n if (latest === undefined || supersedes(estimate, latest)) latest = estimate;\n\n return latest;\n }),\n );\n };\n\n return {\n latest: () => latest,\n current: (measure) =>\n Effect.suspend(() => (latest === undefined ? adopt(measure) : Effect.succeed(latest))),\n renew: (measure) =>\n Effect.suspend(() =>\n latest === undefined || now() - measuredAt < Duration.toMillis(renewAfter)\n ? Effect.void\n : Effect.ignore(adopt(measure)),\n ),\n };\n};\n\nexport const toHostTime = (calibration: Estimate, browserEpochMillis: number): number =>\n browserEpochMillis - calibration.offsetMillis;\n\n/** CDP input timestamps use seconds, unlike browser frame timestamps and the owner's clock. */\nexport const toBrowserSeconds = (calibration: Estimate, hostMillis: number): number =>\n (hostMillis + calibration.offsetMillis) / 1000;\n","/**\n * What a page's parts share: the browser state they act on, the page's own lane, pointer and\n * clock, and how they call the browser and report its failures. The assembly in `page.ts` builds\n * one context per page.\n */\nimport {\n Clock,\n Context,\n Duration,\n Effect,\n Fiber,\n MutableRef,\n Option,\n Schema,\n type Scope,\n} from \"effect\";\nimport type { CDPSession, Page as PlaywrightPage } from \"playwright-core\";\n\nimport type { CaptureSource } from \"../../Browser.ts\";\nimport {\n BrowserError,\n Closed,\n Failed,\n InvalidRequest,\n type Reason,\n Timeout,\n} from \"../../BrowserError.ts\";\nimport type { BrowserEvent } from \"../../BrowserEvent.ts\";\nimport type { InputGuard, Point } from \"../../Page.ts\";\nimport type { Gate } from \"../input/gate.ts\";\nimport { Current } from \"../input/replies.ts\";\nimport * as BrowserClock from \"../pictures/clock.ts\";\nimport * as Lane from \"./lane.ts\";\nimport type { Openings } from \"./openings.ts\";\nimport * as Url from \"./url.ts\";\n\n/** Why a page is gone. */\nexport type ClosedCause = Closed[\"cause\"];\n\n/** What every page of a browser shares, from its options. */\nexport interface Settings {\n readonly actionTimeout: Duration.Duration;\n readonly policyTimeout: Duration.Duration;\n readonly navigationTimeout: Duration.Duration;\n /** How long screencast frames stay in `recentFrames`, measured back from the newest. */\n readonly frameHistory: Duration.Duration;\n readonly guard: InputGuard | undefined;\n}\n\nexport interface MakeOptions {\n /** The page's CDP target id, which is also its main frame's id. */\n readonly id: string;\n /** The id of the browser's session, which its frames carry. */\n readonly session: string;\n /** This tracking connection, distinct from the provider session and capture socket. */\n readonly connection: string;\n /** The page's address when the browser began tracking it. */\n readonly url: string;\n readonly playwright: PlaywrightPage;\n readonly cdp: CDPSession;\n /** A call's reply, or a failure as for a closed page once the browser is lost first. */\n readonly untilLost: <A>(reply: Promise<A>) => Promise<A>;\n readonly settings: Settings;\n readonly clock: Clock.Clock;\n /** Browser-wide input authority; direct internal page fixtures need not provide one. */\n readonly inputGate?: Gate | undefined;\n /** The browser's epoch mapping: its first capture measures it, and later ones renew it. */\n readonly mapping: BrowserClock.Mapping;\n readonly publish: (event: BrowserEvent) => number;\n /** This page's retained events, oldest first. */\n readonly recentEvents: Effect.Effect<ReadonlyArray<BrowserEvent>>;\n /** Registration of the actual popups this page's current input opened. */\n readonly openings: Openings;\n /** Succeeds once the page's own session holds focus emulation, which keeps it painting behind. */\n readonly focused: Effect.Effect<void, BrowserError>;\n /** Succeeds once the page's own session has the Page domain on, so it sees every later commit. */\n readonly paging: (operation: string) => Effect.Effect<void, BrowserError>;\n /** Why the page is gone, once it is: its browser's loss, else its own close or crash. */\n readonly closedBy: () => ClosedCause;\n /** Where the page's screencast runs, if not on its own session. */\n readonly capture?: CaptureSource | undefined;\n}\n\nconst messageOf = (cause: unknown): string =>\n cause instanceof Error ? cause.message : typeof cause === \"string\" ? cause : \"unknown error\";\n\nconst closedPattern =\n /has been closed|Target closed|Session closed|browser has disconnected|Target page, context or browser/i;\n\n/**\n * Map a Playwright or protocol failure to a reason, `Closed` with `closed` as its cause for a page\n * or browser that is gone. A call that gives Playwright a timeout passes the same bound, so its\n * `Timeout` reports it; without one, Playwright's own message stays.\n */\nexport const reasonOf = (\n cause: unknown,\n timeoutMillis?: number,\n closed: ClosedCause = \"connection\",\n): Reason => {\n const message = messageOf(cause);\n\n if (closedPattern.test(message)) return new Closed({ cause: closed });\n if (cause instanceof Error && cause.name === \"TimeoutError\" && timeoutMillis !== undefined)\n return new Timeout({ millis: timeoutMillis });\n const line = message.split(\"\\n\")[0] ?? message;\n\n return new Failed({ detail: Url.redactWithin(line.replace(/^[\\w.]+: /, \"\")) });\n};\n\n/**\n * One Playwright or protocol call, failing undispatched. A closed page says why it is gone as the\n * browser knows then: the library's own calls fail with the browser's loss, and Playwright fails\n * its calls on a dropped connection after reporting the context closed.\n */\nexport const call = <A>(\n operation: string,\n run: () => Promise<A>,\n closedBy: () => ClosedCause,\n timeoutMillis?: number,\n) =>\n Effect.tryPromise({\n try: run,\n catch: (cause) => undispatched(operation, reasonOf(cause, timeoutMillis, closedBy())),\n });\n\nexport const contextGone = (error: BrowserError) =>\n error.reason._tag === \"Failed\" &&\n /Cannot find context|Execution context was destroyed|__effectBrowser|Inspected target navigated/i.test(\n error.reason.detail,\n );\n\n/**\n * What a page operation spent on the page's own protocol session: its calls, the bytes of their\n * parameters and results, and how long at least one of them awaited its reply. An operation inside\n * another counts toward both.\n */\ninterface Cost {\n readonly enclosing: Cost | undefined;\n calls: number;\n bytesOut: number;\n bytesIn: number;\n waitedMillis: number;\n awaiting: number;\n awaitingSince: number;\n}\n\n/** The cost of the page operation the current fiber runs, if any. */\nconst CurrentCost = Context.Reference<Cost | undefined>(\n \"effect-browser/internal/page/CurrentCost\",\n {\n defaultValue: () => undefined,\n },\n);\n\n/** Track the promise returned to the action, after tracing wraps it, so input counts once. */\nconst track = <A>(reply: Promise<A>) => Fiber.getCurrent()?.getRef(Current)?.track(reply) ?? reply;\n\n// A message's size on the wire, give or take its envelope.\nconst sizeOf = (value: unknown) =>\n value === undefined ? 0 : Buffer.byteLength(JSON.stringify(value));\n\n/** A failure of `operation` before any of its input reached the browser. */\nexport const undispatched = (operation: string, reason: Reason) =>\n new BrowserError({ operation, reason, dispatched: false });\n\nexport const failWith = (operation: string, reason: Reason) =>\n Effect.fail(undispatched(operation, reason));\n\n/** Refuse a request to `operation` that could never succeed, before sending anything. */\nexport const refuse = (operation: string, detail: string) =>\n failWith(operation, new InvalidRequest({ detail }));\n\nexport const decodeWith =\n <A>(operation: string, schema: Schema.Codec<A, unknown>) =>\n (value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError((error) => undispatched(operation, new Failed({ detail: error.message }))),\n );\n\nexport const make = (options: MakeOptions, scope: Scope.Scope) => {\n const { id, clock } = options;\n const now = () => BrowserClock.monotonicMillis(clock);\n // Deadlines and pacing guard the page's lane, so page operations run on the owner's clock; a\n // caller's clock, such as a TestClock, cannot stall or stretch them.\n const owned = Effect.provideService(Clock.Clock, clock);\n\n // This page's spans name it and report what the operation cost on the protocol. Fine-grained\n // ones carry a level below the default Info, so an application keeps only the coarse ones by\n // raising `Tracer.MinimumTraceLevel`.\n const span =\n (name: string, attributes: Record<string, unknown> = {}, level?: \"Debug\" | \"Trace\") =>\n <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n Effect.gen(function* () {\n const cost: Cost = {\n enclosing: yield* CurrentCost,\n calls: 0,\n bytesOut: 0,\n bytesIn: 0,\n waitedMillis: 0,\n awaiting: 0,\n awaitingSince: 0,\n };\n\n return yield* effect.pipe(\n Effect.provideService(CurrentCost, cost),\n Effect.ensuring(\n Effect.suspend(() =>\n Effect.annotateCurrentSpan({\n calls: cost.calls,\n bytesOut: cost.bytesOut,\n bytesIn: cost.bytesIn,\n waitedMillis: Math.round(cost.waitedMillis * 10) / 10,\n }),\n ),\n ),\n );\n }).pipe(\n Effect.withSpan(\n name,\n { attributes: { page: id, ...attributes }, ...(level === undefined ? {} : { level }) },\n { captureStackTrace: false },\n ),\n );\n\n // Every call on the page's own protocol session, counted into the operation that sends it and\n // the operations around that one. It is looked up when the call is sent, so input pipelined\n // from inside an operation counts toward it too.\n const send: CDPSession[\"send\"] = (method, params) => {\n const cost = Fiber.getCurrent()?.getRef(CurrentCost);\n const sentAt = now();\n const bytesOut = sizeOf(params);\n\n for (let each = cost; each !== undefined; each = each.enclosing) {\n each.calls++;\n each.bytesOut += bytesOut;\n if (each.awaiting++ === 0) each.awaitingSince = sentAt;\n }\n const reply = options.untilLost(options.cdp.send(method, params));\n\n if (cost === undefined) return track(reply);\n\n const settle = (bytesIn: number) => {\n const at = now();\n\n for (let each: Cost | undefined = cost; each !== undefined; each = each.enclosing) {\n each.bytesIn += bytesIn;\n if (--each.awaiting === 0) each.waitedMillis += at - each.awaitingSince;\n }\n };\n\n return track(\n reply.then(\n (result) => {\n settle(sizeOf(result));\n\n return result;\n },\n (cause: unknown) => {\n settle(0);\n\n return Promise.reject(cause);\n },\n ),\n );\n };\n\n // Every protocol or Playwright call. Errors are undispatched here; `perform` marks them\n // dispatched once input has gone out.\n const native = <A>(operation: string, run: () => Promise<A>, timeoutMillis?: number) =>\n call(operation, () => track(run()), options.closedBy, timeoutMillis);\n\n /** Fail with `Timeout` once `duration` has passed, the action timeout unless another is given. */\n const within =\n (operation: string, duration: Duration.Input = options.settings.actionTimeout) =>\n <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n Effect.timeoutOrElse(effect, {\n duration,\n orElse: () => failWith(operation, new Timeout({ millis: Duration.toMillis(duration) })),\n });\n\n // Stop a navigation whose bounded wait failed. The stop and original mutation keep their\n // actual replies owned; this cleanup does not turn an unanswered acknowledgement into success.\n const stopLoading = native(\"stopLoading\", () => send(\"Page.stopLoading\")).pipe(\n within(\"stopLoading\", options.settings.navigationTimeout),\n Effect.ignore,\n );\n\n // The latest submitted input or page change. A read that must follow it waits for the action in\n // flight, so only paint from after its latest input is current. An action ends after its input\n // was handled, so if that input changed the page, newer paint follows; a lost final paint is\n // bounded by recency instead. Paint from before the current document began, when the page's own\n // session saw the main frame commit it, shows a page the tab has left, so no read reuses it,\n // whatever it asks.\n const activity = { inputAt: 0, documentAt: Number.NEGATIVE_INFINITY };\n\n const noteInput = () => {\n activity.inputAt = Math.max(activity.inputAt, now());\n };\n\n const lane = Lane.make({\n now,\n actionTimeout: options.settings.actionTimeout,\n documentAt: () => activity.documentAt,\n gone: (operation) => undispatched(operation, new Closed({ cause: options.closedBy() })),\n scope,\n inputGate: options.inputGate,\n });\n\n // Where this page's latest move left its pointer, which is where its next plain glide starts and\n // where a held button is released. Its lane orders the page's input, and Chromium keeps a\n // pointer per page too.\n const pointer = MutableRef.make(Option.none<Point>());\n\n // Named, so that the declarations of what holds it need not spell out Playwright's protocol types.\n const protocol: Pick<CDPSession, \"send\"> = { send };\n\n return {\n ...options,\n lane,\n pointer,\n now,\n scope,\n owned,\n span,\n protocol,\n native,\n within,\n stopLoading,\n activity,\n noteInput,\n };\n};\n\nexport type PageContext = ReturnType<typeof make>;\n"],"mappings":";;;;AAWA,IAAa,eAAb,cAAkC,KAAK,YAAY,cAAc,CAAC,CAE/D,CAAC;;AA0BJ,MAAa,UAAU,QAAQ,UAA2B,yCAAyC,EACjG,oBAAoB,KAAA,EACtB,CAAC;AAED,MAAaA,eAAa;CACxB,MAAM,8BAAc,IAAI,IAAmB;CAI3C,MAAM,OAAO,OAAO,IAAI,aAAa;EACnC,OAAO,YAAY,OAAO,GAAG,OAAO,OAAO,cAAc,QAAQ,IAAI,WAAW,CAAC;CACnF,CAAC;;CA0JD,OAAO;EAAE;EAAM,OAxJD,OAAO,IAAI,aAAa;GACpC,OAAO;GACP,MAAM,0BAAU,IAAI,IAAmB;GACvC,MAAM,OAAkF,CAAC;GACzF,IAAI;GACJ,IAAI,WAAW;GACf,IAAI,SAAS;GACb,MAAM,2BAAW,IAAI,QAA8C;GACnE,MAAM,0BAAU,IAAI,IAAgB;GAEpC,MAAM,SAAY,UAAsB,QAAQ,UAAsB;IACpE,MAAM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