effect-browser 0.3.0-beta.14 → 0.3.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +24 -11
  2. package/dist/{Browser-BBSySyjT.mjs → Browser-DRPthkNO.mjs} +4 -4
  3. package/dist/Browser-DRPthkNO.mjs.map +1 -0
  4. package/dist/Browser.d.mts +2 -2
  5. package/dist/Browser.mjs +1 -1
  6. package/dist/{BrowserEvent-BRu2juEz.d.mts → BrowserEvent-dq6FRT8w.d.mts} +9 -9
  7. package/dist/BrowserEvent.d.mts +1 -1
  8. package/dist/BrowserEvent.mjs +7 -12
  9. package/dist/BrowserEvent.mjs.map +1 -1
  10. package/dist/Cdp.mjs +2 -2
  11. package/dist/{Change-iMlcuzVD.d.mts → Change-DqING3tr.d.mts} +2 -2
  12. package/dist/Change.d.mts +1 -1
  13. package/dist/Chromium.mjs +2 -2
  14. package/dist/Expect.d.mts +1 -1
  15. package/dist/Expect.mjs +2 -2
  16. package/dist/Moment.d.mts +1 -1
  17. package/dist/Moment.mjs +1 -1
  18. package/dist/Motion-DND6I-64.d.mts +40 -0
  19. package/dist/Motion.d.mts +2 -40
  20. package/dist/Motion.mjs +1 -2
  21. package/dist/Motion.mjs.map +1 -1
  22. package/dist/{Page-B5cjaUp5.mjs → Page-C_VkBVwI.mjs} +5 -9
  23. package/dist/Page-C_VkBVwI.mjs.map +1 -0
  24. package/dist/{Page-DL9eylp3.d.mts → Page-jHmSJeOS.d.mts} +6 -13
  25. package/dist/Page.d.mts +1 -1
  26. package/dist/Page.mjs +1 -1
  27. package/dist/{Plan-6As6vcwT.d.mts → Plan-DLtRksuu.d.mts} +3 -3
  28. package/dist/{Plan-CXA2BW-G.mjs → Plan-X-JkACAB.mjs} +6 -9
  29. package/dist/Plan-X-JkACAB.mjs.map +1 -0
  30. package/dist/Plan.d.mts +1 -1
  31. package/dist/Plan.mjs +1 -1
  32. package/dist/Policy.d.mts +1 -1
  33. package/dist/Policy.mjs +1 -1
  34. package/dist/Presentation.d.mts +2 -2
  35. package/dist/Presentation.mjs +3 -2
  36. package/dist/Presentation.mjs.map +1 -1
  37. package/dist/Stage.d.mts +1 -1
  38. package/dist/Stage.mjs +3 -3
  39. package/dist/Stage.mjs.map +1 -1
  40. package/dist/{Supervisor-BE2sGHBK.mjs → Supervisor-BgWP8o9t.mjs} +116 -66
  41. package/dist/Supervisor-BgWP8o9t.mjs.map +1 -0
  42. package/dist/{Supervisor-W60pZWHh.d.mts → Supervisor-mVPeEUp8.d.mts} +33 -12
  43. package/dist/Supervisor.d.mts +2 -2
  44. package/dist/Supervisor.mjs +2 -2
  45. package/dist/{context-BAjRj7Xo.mjs → context-rYTk-3Cv.mjs} +68 -3
  46. package/dist/context-rYTk-3Cv.mjs.map +1 -0
  47. package/dist/index.d.mts +6 -6
  48. package/dist/index.mjs +4 -4
  49. package/dist/match.inpage-xOe9LNO0.mjs.map +1 -1
  50. package/dist/{page-B92QnRfT.mjs → page-ClEMFnBG.mjs} +48 -110
  51. package/dist/page-ClEMFnBG.mjs.map +1 -0
  52. package/package.json +1 -1
  53. package/src/Browser.ts +1 -1
  54. package/src/BrowserEvent.ts +7 -12
  55. package/src/Motion.ts +1 -2
  56. package/src/Page.ts +5 -9
  57. package/src/Plan.ts +1 -2
  58. package/src/Presentation.ts +2 -1
  59. package/src/Stage.ts +2 -1
  60. package/src/Supervisor.ts +168 -166
  61. package/src/internal/input/actions.ts +25 -33
  62. package/src/internal/input/dispatch.ts +3 -4
  63. package/src/internal/input/edit.inpage.ts +3 -9
  64. package/src/internal/input/evidence.inpage.ts +2 -20
  65. package/src/internal/input/guard.inpage.ts +9 -29
  66. package/src/internal/input/guard.ts +12 -1
  67. package/src/internal/input/targets.inpage.ts +4 -8
  68. package/src/internal/input/targets.ts +8 -11
  69. package/src/internal/page/context.ts +2 -2
  70. package/src/internal/pictures/capture.ts +4 -4
  71. package/src/internal/pictures/clock.ts +8 -3
  72. package/src/internal/pictures/pictures.ts +2 -1
  73. package/src/internal/reading/controls.inpage.ts +8 -1
  74. package/src/internal/reading/match.inpage.ts +2 -1
  75. package/src/internal/reading/outline.inpage.ts +7 -4
  76. package/src/internal/reading/reading.ts +5 -16
  77. package/src/internal/supervisor/lifecycle.ts +73 -20
  78. package/dist/Browser-BBSySyjT.mjs.map +0 -1
  79. package/dist/Page-B5cjaUp5.mjs.map +0 -1
  80. package/dist/Plan-CXA2BW-G.mjs.map +0 -1
  81. package/dist/Supervisor-BE2sGHBK.mjs.map +0 -1
  82. package/dist/context-BAjRj7Xo.mjs.map +0 -1
  83. package/dist/page-B92QnRfT.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"Supervisor-BE2sGHBK.mjs","names":["Lifecycle.GenerationState","Lifecycle.resolve","Lifecycle.lookup","Lifecycle.Settled","Lifecycle.Unconfirmed","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.\n */\nexport class Down extends Schema.TaggedClass<Down>()(\"Down\", {\n detail: Schema.String,\n cause: Schema.Defect(),\n}) {}\n\n/** It ended. `released` says how its release went; one retired while opening has none. */\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 /** One bounded predecessor survives release and failed acquisitions for admission. */\n readonly latest: Live<A> | undefined;\n};\n\nexport type Input<A, H = unknown> =\n | { readonly _tag: \"Opened\"; readonly live: Live<A> }\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; readonly after: Live<A> | undefined }\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(), latest: undefined },\n events: [[1, new Opening()]],\n commands: [{ _tag: \"Open\", number: 1, after: undefined }],\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 const after = change.state.latest;\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 latest: after,\n };\n change.events.push([number, reopen ? new Reopening() : new Opening()]);\n change.commands.push({ _tag: \"Open\", number, after });\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/** 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 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 latest: input.live,\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([number, new Down({ detail, cause })]);\n break;\n }\n case \"Abandoned\":\n change.events.push([input.number, new Closed({})]);\n break;\n case \"Released\": {\n const drain = state.draining.get(input.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(input.number);\n change.state = { ...state, draining };\n change.events.push([\n input.number,\n input.released === undefined ? new Kept() : new Closed({ released: input.released }),\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 = { _tag: \"Retired\", draining: change.state.draining, latest: undefined };\n }\n\n return change;\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 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 * The preceding generation's release once it stops serving. Undefined on the first open and\n * while a nonexclusive rotation keeps it serving; checked again before each retry.\n */\n readonly after: Effect.Effect<Lifecycle.Released> | undefined;\n}\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 Apply<A> = (\n input: Lifecycle.Input<Held<A>, Hold>,\n) => Effect.Effect<Lifecycle.Step<Held<A>, Hold>>;\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 unavailable = (\n resolution: Extract<Lifecycle.Resolution<unknown>, { readonly _tag: \"Unavailable\" }>,\n) =>\n new Unavailable({\n reason: resolution.reason,\n detail: resolution.detail,\n cause: resolution.cause,\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(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 = (hold: Hold, wait: Duration.Duration) =>\n Effect.gen(function* () {\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 changedUntil = <A>(\n state: SubscriptionRef.SubscriptionRef<State<A>>,\n predicate: (current: State<A>) => boolean,\n) => SubscriptionRef.changes(state).pipe(Stream.filter(predicate), Stream.runHead, Effect.asVoid);\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 = <A>(\n command: Extract<Lifecycle.Command<Held<A>>, { readonly _tag: \"Release\" | \"Leave\" }>,\n state: SubscriptionRef.SubscriptionRef<State<A>>,\n apply: Apply<A>,\n) =>\n Effect.gen(function* () {\n const { live } = command;\n const holds = Lifecycle.lookup(state.value, live.number)?.holds ?? [];\n\n const cleaned = yield* Effect.forEach(\n holds,\n (hold) =>\n Effect.exit(hold._tag === \"Retained\" ? Scope.close(hold.scope, Exit.void) : Effect.void),\n { concurrency: 8 },\n );\n\n yield* changedUntil(\n state,\n (current) => (Lifecycle.lookup(current, live.number)?.holds.size ?? 0) === 0,\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 openedInput = <A, E>(\n number: number,\n exit: Exit.Exit<Held<A>, E>,\n): Lifecycle.Input<Held<A>, Hold> =>\n Exit.isSuccess(exit)\n ? { _tag: \"Opened\", live: { number, value: exit.value } }\n : Cause.hasInterruptsOnly(exit.cause)\n ? { _tag: \"Abandoned\", number }\n : { _tag: \"Failed\", number, detail: describe(exit.cause), cause: Cause.squash(exit.cause) };\n\nconst admissionAfter = <A>(previous: Lifecycle.Live<Held<A>> | undefined, state: State<A>) =>\n previous === undefined || (state._tag !== \"Retired\" && state.serving?.number === previous.number)\n ? undefined\n : Deferred.await(previous.value.released);\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 const definite = options.definite ?? (() => 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 = (\n input: Lifecycle.Input<Held<A | void>, Hold>,\n ): Effect.Effect<Lifecycle.Step<Held<A | void>, Hold>> =>\n applying\n .withPermit(\n Effect.gen(function* () {\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 )\n .pipe(Effect.uninterruptible, Effect.provideService(Clock.Clock, clock));\n\n const perform = (step: Lifecycle.Step<Held<A | void>, Hold>): Effect.Effect<void> =>\n Effect.gen(function* () {\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, command.after));\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, previous: Lifecycle.Live<Held<A | void>> | undefined) => {\n const after = previous === undefined ? undefined : Deferred.await(previous.value.released);\n\n const openOnce = acquireGeneration(\n Effect.suspend(\n () =>\n options.admit?.({ number, after: admissionAfter(previous, state.value) }) ?? Effect.void,\n ).pipe(Effect.andThen(options.open)),\n own,\n ).pipe(Effect.provideContext(context));\n\n return Effect.uninterruptibleMask((restore) =>\n restore(\n (exclusive && after !== undefined ? after : Effect.void).pipe(\n Effect.andThen(\n Effect.retry(openOnce, { schedule: reopen, while: (error) => !definite(error) }),\n ),\n ),\n ).pipe(\n Effect.exit,\n Effect.flatMap((exit) => apply(openedInput(number, exit))),\n ),\n );\n };\n\n const use = leasing(state, apply, waitTimeout, now, clock);\n\n const end = yield* Effect.cached(PubSub.publish(events, Exit.void));\n\n const stop = (input: Lifecycle.Input<Held<A | void>, Hold>) =>\n apply(input).pipe(\n Effect.andThen(FiberHandle.clear(opening)),\n Effect.andThen(FiberMap.awaitEmpty(releases)),\n Effect.andThen(\n Effect.suspend(() =>\n Deferred.isDone(releases.deferred).pipe(\n Effect.flatMap((failed) => (failed ? FiberMap.join(releases) : Effect.void)),\n ),\n ),\n ),\n Effect.ensuring(end),\n Effect.asVoid,\n );\n\n const retire = yield* Effect.cached(stop({ _tag: \"Retire\" }));\n\n yield* Effect.addFinalizer(() => (options.keep === true ? stop({ _tag: \"Keep\" }) : retire));\n yield* perform(started);\n\n return {\n browser: Effect.map(waitFor(state, waitTimeout, clock), (live) => live.value.opened.browser),\n use,\n states: Stream.fromPubSubTake(events),\n rotate: apply({ _tag: \"Rotate\" }).pipe(\n Effect.flatMap(({ reply }) =>\n reply === undefined\n ? Effect.fail(retired())\n : Effect.map(\n waitFor(state, waitTimeout, clock, reply),\n (live) => live.value.opened.browser,\n ),\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,YA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;CAEF,MAAM,SAAS,OAAO,OAAO,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC,CAAC;CAE5D,OAAO,OAAO,mBAAoB,QAAQ,SAAS,OAAO,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,MAAO;CAC1F,OAAO,QAAQ,OAAO;CAEtB,OAAO;EACL,SAAS,OAAO,IAAI,QAAQ,OAAO,aAAa,KAAK,IAAI,SAAS,KAAK,MAAM,OAAO,OAAO;EAC3F;EACA,QAAQ,OAAO,eAAe,MAAM;EACpC,QAAQ,MAAM,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,KAChC,OAAO,SAAS,EAAE,YAChB,UAAU,KAAA,IACN,OAAO,KAAK,QAAQ,CAAC,IACrB,OAAO,IACL,QAAQ,OAAO,aAAa,OAAO,KAAK,IACvC,SAAS,KAAK,MAAM,OAAO,OAC9B,CACN,CACF;EACA;CACF;AACF,CAAC;AAWD,SAAgB,KAAc,SAA+B;CAC3D,OAAO,WAAW,OAAO;AAC3B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-BAjRj7Xo.mjs","names":["make","Url.redactWithin","Lane.make"],"sources":["../src/internal/input/replies.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 } 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 /** 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 let response: Promise<unknown>;\n\n try {\n response = command();\n } catch (cause) {\n failure ??= new InputFailure({ cause });\n\n return;\n }\n\n void track(response, true);\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 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 * 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 { BrowserError, Closed, Failed, type Reason, Timeout } 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 type * 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\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 = () => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;\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 owned,\n span,\n protocol,\n native,\n within,\n stopLoading,\n activity,\n noteInput,\n };\n};\n\nexport type PageContext = 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