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.
Files changed (96) hide show
  1. package/README.md +18 -6
  2. package/dist/{Browser-BBSySyjT.mjs → Browser-H63wiekr.mjs} +5 -5
  3. package/dist/Browser-H63wiekr.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 +3 -3
  18. package/dist/Moment.mjs.map +1 -1
  19. package/dist/Motion-DND6I-64.d.mts +40 -0
  20. package/dist/Motion.d.mts +2 -40
  21. package/dist/Motion.mjs +1 -2
  22. package/dist/Motion.mjs.map +1 -1
  23. package/dist/{Page-B5cjaUp5.mjs → Page-CfB6Zn1p.mjs} +7 -15
  24. package/dist/Page-CfB6Zn1p.mjs.map +1 -0
  25. package/dist/{Page-DL9eylp3.d.mts → Page-ku6j5t-v.d.mts} +23 -25
  26. package/dist/Page.d.mts +1 -1
  27. package/dist/Page.mjs +1 -1
  28. package/dist/{Plan-CXA2BW-G.mjs → Plan-C-d5QYS8.mjs} +6 -9
  29. package/dist/Plan-C-d5QYS8.mjs.map +1 -0
  30. package/dist/{Plan-6As6vcwT.d.mts → Plan-DJ4hEEna.d.mts} +3 -3
  31. package/dist/Plan.d.mts +1 -1
  32. package/dist/Plan.mjs +1 -1
  33. package/dist/Policy.d.mts +1 -1
  34. package/dist/Policy.mjs +1 -1
  35. package/dist/Presentation.d.mts +2 -2
  36. package/dist/Presentation.mjs +3 -2
  37. package/dist/Presentation.mjs.map +1 -1
  38. package/dist/Stage.d.mts +1 -1
  39. package/dist/Stage.mjs +8 -7
  40. package/dist/Stage.mjs.map +1 -1
  41. package/dist/{Supervisor-DaGlQVjv.mjs → Supervisor-2mPjIYYs.mjs} +44 -19
  42. package/dist/Supervisor-2mPjIYYs.mjs.map +1 -0
  43. package/dist/{Supervisor-5tZ47hR5.d.mts → Supervisor-mVPeEUp8.d.mts} +12 -5
  44. package/dist/Supervisor.d.mts +1 -1
  45. package/dist/Supervisor.mjs +1 -1
  46. package/dist/{context-BAjRj7Xo.mjs → context-w3NJPRLo.mjs} +81 -9
  47. package/dist/context-w3NJPRLo.mjs.map +1 -0
  48. package/dist/index.d.mts +6 -6
  49. package/dist/index.mjs +4 -4
  50. package/dist/match.inpage-xOe9LNO0.mjs.map +1 -1
  51. package/dist/{page-B92QnRfT.mjs → page-BKwfF6z-.mjs} +213 -218
  52. package/dist/page-BKwfF6z-.mjs.map +1 -0
  53. package/package.json +1 -1
  54. package/src/Browser.ts +1 -1
  55. package/src/BrowserEvent.ts +7 -12
  56. package/src/Moment.ts +3 -6
  57. package/src/Motion.ts +1 -2
  58. package/src/Page.ts +18 -20
  59. package/src/Plan.ts +1 -2
  60. package/src/Presentation.ts +2 -1
  61. package/src/Stage.ts +10 -17
  62. package/src/Supervisor.ts +9 -9
  63. package/src/internal/input/actions.ts +53 -97
  64. package/src/internal/input/dispatch.ts +25 -11
  65. package/src/internal/input/edit.inpage.ts +26 -11
  66. package/src/internal/input/evidence.inpage.ts +1 -21
  67. package/src/internal/input/guard.inpage.ts +9 -29
  68. package/src/internal/input/guard.ts +15 -10
  69. package/src/internal/input/perform.ts +14 -10
  70. package/src/internal/input/pointer.ts +3 -6
  71. package/src/internal/input/replies.ts +19 -8
  72. package/src/internal/input/settle.ts +3 -2
  73. package/src/internal/input/targets.inpage.ts +6 -13
  74. package/src/internal/input/targets.ts +13 -32
  75. package/src/internal/page/bridge.ts +2 -2
  76. package/src/internal/page/context.ts +15 -3
  77. package/src/internal/page/navigation.ts +3 -12
  78. package/src/internal/pictures/capture.ts +11 -4
  79. package/src/internal/pictures/clock.ts +8 -3
  80. package/src/internal/pictures/motion.ts +65 -0
  81. package/src/internal/pictures/pictures.ts +22 -17
  82. package/src/internal/pictures/utilsBundle.d.ts +9 -0
  83. package/src/internal/reading/controls.inpage.ts +8 -1
  84. package/src/internal/reading/match.inpage.ts +2 -1
  85. package/src/internal/reading/outline.inpage.ts +7 -4
  86. package/src/internal/reading/reading.ts +10 -25
  87. package/src/internal/reading/ready.ts +66 -14
  88. package/src/internal/supervisor/lifecycle.ts +56 -13
  89. package/src/internal/timeline/events.ts +5 -8
  90. package/src/internal/timeline/window.ts +3 -8
  91. package/dist/Browser-BBSySyjT.mjs.map +0 -1
  92. package/dist/Page-B5cjaUp5.mjs.map +0 -1
  93. package/dist/Plan-CXA2BW-G.mjs.map +0 -1
  94. package/dist/Supervisor-DaGlQVjv.mjs.map +0 -1
  95. package/dist/context-BAjRj7Xo.mjs.map +0 -1
  96. package/dist/page-B92QnRfT.mjs.map +0 -1
package/dist/Page.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as TypeOptions, D as correlate, E as Zoom, O as failFast, S as TextOptions, T as WindowOptions, _ as ScreenshotOptions, a as FindQuery, b as Target, c as InputGuard, f as Point, g as ResolvedTarget, h as Region, i as Fact, k as redacted, l as InputRequest, m as ReadyOptions, n as ClickOptions, o as Found, p as PressOptions, r as ElementState, s as FrameOptions, t as ChangesOptions, u as Page, v as ScrollOptions, w as WaitCondition, x as Text, y as State } from "./Page-DL9eylp3.mjs";
1
+ import { C as TypeOptions, D as correlate, E as Zoom, O as failFast, S as TextOptions, T as WindowOptions, _ as ScreenshotOptions, a as FindQuery, b as Target, c as InputGuard, f as Point, g as ResolvedTarget, h as Region, i as Fact, k as redacted, l as InputRequest, m as ReadyOptions, n as ClickOptions, o as Found, p as PressOptions, r as ElementState, s as FrameOptions, t as ChangesOptions, u as Page, v as ScrollOptions, w as WaitCondition, x as Text, y as State } from "./Page-ku6j5t-v.mjs";
2
2
  export { ChangesOptions, ClickOptions, ElementState, Fact, FindQuery, Found, FrameOptions, InputGuard, InputRequest, Page, Point, PressOptions, ReadyOptions, Region, ResolvedTarget, ScreenshotOptions, ScrollOptions, State, Target, Text, TextOptions, TypeOptions, WaitCondition, WindowOptions, Zoom, correlate, failFast, redacted };
package/dist/Page.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { c as State, d as correlate, f as failFast, i as InputRequest, l as Text, n as Fact, o as Region, p as redacted, r as Found, s as ResolvedTarget, t as ElementState, u as Zoom } from "./Page-B5cjaUp5.mjs";
1
+ import { c as State, d as correlate, f as failFast, i as InputRequest, l as Text, n as Fact, o as Region, p as redacted, r as Found, s as ResolvedTarget, t as ElementState, u as Zoom } from "./Page-CfB6Zn1p.mjs";
2
2
  export { ElementState, Fact, Found, InputRequest, Region, ResolvedTarget, State, Text, Zoom, correlate, failFast, redacted };
@@ -1,8 +1,9 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Point } from "./Motion.mjs";
2
3
  import { ActionOptions, Box, Subject } from "./BrowserEvent.mjs";
3
4
  import { BrowserError, InvalidRequest } from "./BrowserError.mjs";
4
- import { s as undispatched } from "./context-BAjRj7Xo.mjs";
5
- import { p as redacted } from "./Page-B5cjaUp5.mjs";
5
+ import { c as undispatched } from "./context-w3NJPRLo.mjs";
6
+ import { p as redacted } from "./Page-CfB6Zn1p.mjs";
6
7
  import { t as match } from "./match.inpage-xOe9LNO0.mjs";
7
8
  import { Duration, Effect, Exit, Option, Schedule, Schema } from "effect";
8
9
  //#region src/internal/reading/choose.ts
@@ -120,10 +121,6 @@ var Plan_exports = /* @__PURE__ */ __exportAll({
120
121
  restore: () => restore,
121
122
  take: () => take
122
123
  });
123
- const ViewportPoint = Schema.Struct({
124
- x: Schema.Finite,
125
- y: Schema.Finite
126
- });
127
124
  const StepAction = Schema.Literals([
128
125
  "navigate",
129
126
  "back",
@@ -180,8 +177,8 @@ var Step = class extends Schema.Class("effect-browser/Plan/Step")({
180
177
  /** Where a drag ended. */
181
178
  to: Schema.optional(Subject),
182
179
  /** The viewport point a step aimed at, when it aimed at a point, and a drag's end point. */
183
- point: Schema.optional(ViewportPoint),
184
- toPoint: Schema.optional(ViewportPoint),
180
+ point: Schema.optional(Point),
181
+ toPoint: Schema.optional(Point),
185
182
  /** The box of what a step aimed at by point found there, so replay aims at the same place in it. */
186
183
  box: Schema.optional(Box),
187
184
  /**
@@ -512,4 +509,4 @@ const restore = (page, plan, options = {}) => run(page, plan, options, 0, option
512
509
  //#endregion
513
510
  export { Drifted as _, ReplayError as a, Stopped as c, locate as d, repeatable as f, Ambiguous as g, take as h, Receipt as i, Uncertain as l, restore as m, Plan as n, Step as o, replay as p, Plan_exports as r, StepAction as s, Expected as t, fromEvents as u, Missing as v };
514
511
 
515
- //# sourceMappingURL=Plan-CXA2BW-G.mjs.map
512
+ //# sourceMappingURL=Plan-C-d5QYS8.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plan-C-d5QYS8.mjs","names":["ViewportPoint"],"sources":["../src/internal/reading/choose.ts","../src/Plan.ts"],"sourcesContent":["/**\n * Choosing the one element a recorded subject names, among those `find` gives for its role and\n * name. Context tells them apart, and an element that does not repeat every part of the recorded\n * context is another subject, so a sole element left once its own has gone, such as Alice's\n * \"Remove\" after Bob has left, drifts rather than stands in:\n *\n * - a row is read whole: a row named \"Wrapped BTC\" is not the row \"BTC\". Laid out again without\n * rows, as cards, one of the element's fields must start with the row's words;\n * - a column counts where the element is under one;\n * - a label or heading must read the same, or its words appear, whole and in order, in one of the\n * element's fields, as `near` reads them.\n *\n * The rest are ranked by how much of the recorded context they read the same. There is no\n * ordinal, so a tie stays a tie.\n */\nimport { Effect, Schema } from \"effect\";\n\nimport type { Subject, SubjectContext } from \"../../BrowserEvent.ts\";\nimport type { Found } from \"../../Page.ts\";\nimport { match } from \"./match.inpage.ts\";\n\n/** Nothing on the page has the step's role and name. */\nexport class Missing extends Schema.TaggedError<Missing>()(\"Missing\", {}) {\n override get message() {\n return \"nothing on the page has the recorded role and name\";\n }\n}\n\n/** Several elements match the step's subject equally well, and nothing tells them apart. */\nexport class Ambiguous extends Schema.TaggedError<Ambiguous>()(\"Ambiguous\", {\n count: Schema.Int,\n}) {\n override get message() {\n return `${this.count} elements match the recorded subject equally well`;\n }\n}\n\n/** The page is not where the recording was: another site, or no element with its context. */\nexport class Drifted extends Schema.TaggedError<Drifted>()(\"Drifted\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\nconst { holds, normalize } = match();\nconst fields = [\"row\", \"column\", \"label\", \"heading\"] as const;\n\nconst said = (context: SubjectContext) =>\n Object.values(context).filter((value) => typeof value === \"string\");\n\n/** How an element repeats one recorded field: 2 read the same, 1 found as words, 0 not at all. */\nconst repeats = (field: (typeof fields)[number], value: string, context: SubjectContext) => {\n const own = context[field];\n\n if (own !== undefined && normalize(own) === normalize(value)) return 2;\n if (field === \"column\") return own === undefined ? 1 : 0;\n if (field === \"row\")\n return own === undefined &&\n said(context).some((other) => `${normalize(other)} `.startsWith(`${normalize(value)} `))\n ? 1\n : 0;\n\n return said(context).some((other) => holds(other, value)) ? 1 : 0;\n};\n\nexport const choose = (\n subject: Subject,\n found: ReadonlyArray<Found>,\n): Effect.Effect<Found, Missing | Ambiguous | Drifted> => {\n // `find` matched the role; a subject without one only matches elements without one.\n const named = found.filter((one) => subject.role !== null || one.subject.role === null);\n\n const kept = named.flatMap((one) => {\n let score = 0;\n\n for (const field of fields) {\n const value = subject.context[field];\n const repeated = value === undefined ? 0 : repeats(field, value, one.subject.context);\n\n if (value !== undefined && repeated === 0) return [];\n score += repeated;\n }\n\n return [{ one, score }];\n });\n\n const best = Math.max(...kept.map(({ score }) => score));\n const top = kept.filter(({ score }) => score === best);\n const [only] = top;\n\n if (named.length === 0) return Effect.fail(new Missing());\n if (kept.length === 0)\n return Effect.fail(new Drifted({ detail: \"no element named so repeats the recorded context\" }));\n\n return top.length === 1 && only !== undefined\n ? Effect.succeed(only.one)\n : Effect.fail(new Ambiguous({ count: top.length }));\n};\n","/**\n * A walk recorded once from a page's events and replayed later, on a fresh page, with no model\n * call.\n *\n * `fromEvents` keeps one page's completed actions with their subjects and the options they were\n * given, its navigations with both the address asked for and the one reached, and what was typed\n * as a named input slot, never the text itself. A navigation to an address whose credentials the\n * events withheld is an input slot too, so replay goes where the caller says, or nowhere, and\n * never to the address without them. `replay` takes the steps in turn. Before a step\n * except an opening navigate, back or reload, it waits for `Page.ready`; then it finds the element its\n * subject names, by role and name among those that repeat all its recorded context, and acts on\n * it. Text typed into focus was typed into the focused field, which replay finds the same way, and\n * text typed into a secret field goes into nothing else. An element step never falls back to\n * coordinates, and a step recorded at a point acts there only while the element found for it still\n * covers that point. `take` and `replay` return receipts; failure preserves a stopping point and\n * earlier receipts. Unknown consequential input is never resent. Only a positive durable read-back\n * can reconcile it; restoration follows the same rule. The consumer journals begun steps before\n * calling, treating interruption or a missing receipt as unknown. Plain recordings use version 1;\n * authored expected effects use version 2. Old 0.2 plans and unknown versions do not decode.\n *\n * @since 0.3.0\n */\nimport { Duration, Effect, Exit, Option, Schedule, Schema } from \"effect\";\n\nimport { BrowserError, InvalidRequest } from \"./BrowserError.ts\";\nimport {\n type Action,\n ActionOptions,\n Box,\n type BrowserEvent,\n type Navigated,\n Subject,\n} from \"./BrowserEvent.ts\";\nimport { undispatched } from \"./internal/page/context.ts\";\nimport { Ambiguous, choose, Drifted, Missing } from \"./internal/reading/choose.ts\";\nimport { Point as ViewportPoint } from \"./Motion.ts\";\nimport {\n type Found,\n type Page,\n type Point,\n type ReadyOptions,\n redacted,\n type Target,\n} from \"./Page.ts\";\n\nexport { Ambiguous, Drifted, Missing } from \"./internal/reading/choose.ts\";\n\nexport const StepAction = Schema.Literals([\n \"navigate\",\n \"back\",\n \"reload\",\n \"click\",\n \"hover\",\n \"drag\",\n \"type\",\n \"press\",\n \"scroll\",\n \"select\",\n]);\n\nexport type StepAction = typeof StepAction.Type;\n\nconst Query = Schema.Struct({\n role: Schema.optional(Schema.String),\n name: Schema.optional(Schema.String),\n text: Schema.optional(Schema.String),\n});\n\n/**\n * What a step leaves. `durable` asserts an author-chosen, lasting read-back of this operation,\n * such as its uniquely named saved receipt or exact operation URL. Only Appeared and an exact\n * Navigated URL allow it; a toast, absence or relative navigation cannot establish recovery.\n * Relative navigation measures observed change from dispatch, without asserting causality.\n */\nexport const Expected = Schema.Union([\n Schema.TaggedStruct(\"Checked\", { checked: Schema.Boolean }),\n Schema.TaggedStruct(\"Appeared\", {\n query: Query,\n durable: Schema.optional(Schema.Literal(true)),\n }),\n Schema.TaggedStruct(\"Gone\", {\n query: Query,\n durable: Schema.optional(Schema.Never),\n }),\n Schema.TaggedStruct(\"Navigated\", {\n url: Schema.String,\n durable: Schema.optional(Schema.Literal(true)),\n }),\n Schema.TaggedStruct(\"Navigated\", {\n url: Schema.optional(Schema.Never),\n durable: Schema.optional(Schema.Never),\n }),\n]);\n\nexport type Expected = typeof Expected.Type;\n\n/** One recorded step: the action, what it acted on, and what else it was asked. */\nexport class Step extends Schema.Class<Step>(\"effect-browser/Plan/Step\")({\n action: StepAction,\n /**\n * The ending address, or a later recorded navigation before the next action began. Empty when\n * unknown; a delayed navigation can be stronger arrival evidence than the action's ending URL.\n */\n url: Schema.String,\n /** A navigation's requested address, or the keys a press pressed. */\n target: Schema.optional(Schema.String),\n subject: Schema.optional(Subject),\n /** Where a drag ended. */\n to: Schema.optional(Subject),\n /** The viewport point a step aimed at, when it aimed at a point, and a drag's end point. */\n point: Schema.optional(ViewportPoint),\n toPoint: Schema.optional(ViewportPoint),\n /** The box of what a step aimed at by point found there, so replay aims at the same place in it. */\n box: Schema.optional(Box),\n /**\n * The input slot whose text a `type` step types, or whose address a `navigate` step goes to, as\n * its recorded address had a credential withheld.\n */\n input: Schema.optional(Schema.String),\n /** The slot's text went into a secret field, so replay types it into nothing else. */\n secret: Schema.optional(Schema.Literal(true)),\n options: Schema.optional(ActionOptions),\n expect: Schema.optional(Expected),\n}) {}\n\nconst PlanData = Schema.Struct({\n version: Schema.Literals([1, 2]),\n steps: Schema.Array(Step),\n}).check(\n Schema.makeFilter((plan) =>\n plan.version === (plan.steps.some((step) => step.expect !== undefined) ? 2 : 1)\n ? undefined\n : \"only plans with expected effects use version 2\",\n ),\n);\n\nexport class Plan extends Schema.Class<Plan>(\"effect-browser/Plan\")(PlanData) {\n /** Choose the encoding version from the steps; simple recordings remain version 1. */\n static new(steps: ReadonlyArray<Step>): Plan {\n return new Plan({ version: steps.some((step) => step.expect !== undefined) ? 2 : 1, steps });\n }\n\n /** The input slots its steps type, in order; replay needs text for each. */\n get inputs(): ReadonlyArray<string> {\n return this.steps.flatMap((step) => (step.input === undefined ? [] : [step.input]));\n }\n}\n\n/** One completed step, on the page's host clock. `verified` means its expected effect was seen. */\nexport class Receipt extends Schema.Class<Receipt>(\"effect-browser/Plan/Receipt\")({\n step: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n outcome: Schema.Literals([\"taken\", \"verified\", \"skipped\"]),\n startedAt: Schema.Finite,\n at: Schema.Finite,\n}) {}\n\n/** Durable stopping data. A begun step without a receipt must be restored as `unknown`. */\nexport class Stopped extends Schema.Class<Stopped>(\"effect-browser/Plan/Stopped\")({\n step: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n input: Schema.Literals([\"unsent\", \"unknown\"]),\n}) {}\n\n/** Repeating this step could repeat an unresolved effect; the consumer must reconcile it. */\nexport class Uncertain extends Schema.TaggedError<Uncertain>()(\"Uncertain\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\n/** Where replay stopped, counting steps from 0, why, and the steps that completed before it. */\nexport class ReplayError extends Schema.TaggedError<ReplayError>()(\"ReplayError\", {\n step: Schema.Int,\n reason: Schema.Union([Missing, Ambiguous, Drifted, BrowserError, Uncertain]),\n input: Schema.Literals([\"unsent\", \"unknown\"]),\n receipts: Schema.Array(Receipt),\n}) {\n get stopped(): Stopped {\n return new Stopped({ step: this.step, input: this.input });\n }\n\n override get message() {\n return `step ${this.step} failed: ${this.reason.message}`;\n }\n}\n\nconst isStep = (event: BrowserEvent): event is Action & { readonly name: StepAction } =>\n event._tag === \"Action\" &&\n event.ok &&\n (StepAction.literals as ReadonlyArray<string>).includes(event.name);\n\n// A point target reads `x,y`, as `{\"x\":…,\"y\":…}` inside a drag's; a ref reads like e12.\nconst pointIn = (target: string | undefined): Point | undefined => {\n const parsed = /^\\{?(?:\"x\":)?(-?[\\d.]+),(?:\"y\":)?(-?[\\d.]+)\\}?$/.exec(target ?? \"\");\n\n return parsed === null ? undefined : { x: Number(parsed[1]), y: Number(parsed[2]) };\n};\n\n/** A slot named for the field it fills, such as `email`, unique within the plan. */\nconst slotFor = (taken: Set<string>, field: string | undefined) => {\n const base =\n field\n ?.toLowerCase()\n .match(/[\\p{L}\\p{N}]+/gu)\n ?.join(\"-\") ?? \"input\";\n\n let slot = base;\n\n for (let count = 2; taken.has(slot); count++) slot = `${base}-${count}`;\n taken.add(slot);\n\n return slot;\n};\n\n/**\n * The walk one page's events record: the completed actions of the page that acted first, in\n * order. `page.recentEvents` gives them, or `browser.events()` read until the walk ends.\n */\nexport const fromEvents = (events: Iterable<BrowserEvent>): Plan => {\n const all = Array.from(events);\n const page = all.find((event) => event._tag === \"Action\")?.page;\n const mine = all.filter((event) => \"page\" in event && event.page === page);\n const steps = mine.filter(isStep);\n const opened = mine.find((event) => event._tag === \"PageOpened\")?.url ?? \"\";\n const moves = mine.filter((event): event is Navigated => event._tag === \"Navigated\");\n const taken = new Set<string>();\n\n // Where the page was just before a time: the last address it reached by then.\n const before = (time: number) => moves.findLast((move) => move.at <= time)?.url ?? opened;\n\n return new Plan({\n version: 1,\n steps: steps.map((action, index) => {\n const drag = action.name === \"drag\" ? (action.target ?? \"\").split(\" -> \") : undefined;\n const point = pointIn(drag === undefined ? action.target : drag[0]);\n const until = steps[index + 1]?.startedAt ?? Number.POSITIVE_INFINITY;\n const arrival = moves.findLast((move) => move.at > action.at && move.at <= until);\n\n // Only a navigation and a press keep their target: an address, or keys.\n return new Step({\n action: action.name,\n url: arrival?.url ?? action.url ?? before(until),\n target: action.name === \"navigate\" || action.name === \"press\" ? action.target : undefined,\n subject: action.subject,\n to: action.to,\n point,\n toPoint: pointIn(drag?.[1]),\n box: point === undefined ? undefined : action.box,\n input:\n action.name === \"type\"\n ? slotFor(taken, action.subject?.name)\n : action.name === \"navigate\" && action.target?.includes(redacted) === true\n ? slotFor(taken, \"address\")\n : undefined,\n secret: action.name === \"type\" && action.text === redacted ? true : undefined,\n options: action.options,\n });\n }),\n });\n};\n\n/**\n * The one element on the page that a subject names, by role, name and context (see `Plan`),\n * looking again for two seconds while the page may still be drawing it.\n */\nexport const locate = (page: Page, subject: Subject) =>\n page\n .find({\n name: subject.name,\n scope: \"document\",\n ...(subject.role === null ? {} : { role: subject.role }),\n })\n .pipe(\n Effect.flatMap((found) => choose(subject, found)),\n Effect.retry({\n schedule: Schedule.spaced(Duration.millis(250)),\n times: 8,\n while: (error) => error._tag !== \"BrowserError\",\n }),\n Effect.withSpan(\"Plan.locate\", { attributes: { role: subject.role ?? \"\" } }),\n );\n\nconst invalid = (detail: string) => undispatched(\"replay\", new InvalidRequest({ detail }));\n\n/**\n * Where the step acts: the element its subject names, or, for a step recorded at a point, the same\n * place within that element, as long as a press there reaches that element and not one over it.\n * An element out of view is first brought into it, by hovering it, as a press by ref would be.\n */\nconst aim = (page: Page, subject: Subject | undefined, point?: Point, recorded?: Box) => {\n if (subject === undefined) return Effect.fail(invalid(\"the step names no element\"));\n if (point === undefined) return Effect.map(locate(page, subject), ({ ref }): Target => ref);\n\n const reach = ({ ref, box }: Found) => {\n const at =\n recorded === undefined || recorded.width <= 0 || recorded.height <= 0\n ? point\n : {\n x: box.x + ((point.x - recorded.x) / recorded.width) * box.width,\n y: box.y + ((point.y - recorded.y) / recorded.height) * box.height,\n };\n\n return Effect.map(page.find({ at }), ([reached]) => (reached?.ref === ref ? at : undefined));\n };\n\n const missed = new Drifted({ detail: \"a press at the subject's point reaches another element\" });\n\n return locate(page, subject).pipe(\n Effect.flatMap((found) =>\n Effect.flatMap(reach(found), (at) =>\n at !== undefined\n ? Effect.succeed<Target>(at)\n : page.hover(found.ref).pipe(\n Effect.andThen(locate(page, subject)),\n Effect.flatMap(reach),\n Effect.flatMap((again) =>\n again === undefined ? Effect.fail(missed) : Effect.succeed<Target>(again),\n ),\n ),\n ),\n ),\n );\n};\n\nconst dispatch = (\n page: Page,\n step: Step,\n text: string,\n): Effect.Effect<void, Missing | Ambiguous | Drifted | BrowserError> => {\n const options = step.options ?? {};\n\n switch (step.action) {\n case \"navigate\":\n return page.goto(step.input === undefined ? (step.target ?? step.url) : text);\n case \"back\":\n return page.back;\n case \"reload\":\n return page.reload;\n case \"press\":\n return step.subject === undefined\n ? page.press(step.target ?? \"\", options)\n : Effect.flatMap(locate(page, step.subject), ({ ref }) =>\n page.press(step.target ?? \"\", { ...options, on: ref }),\n );\n case \"click\":\n return aim(page, step.subject, step.point, step.box).pipe(\n Effect.flatMap((at) => page.click(at, options)),\n Effect.asVoid,\n );\n case \"hover\":\n return Effect.flatMap(aim(page, step.subject, step.point, step.box), page.hover);\n case \"drag\":\n return Effect.all([\n aim(page, step.subject, step.point),\n aim(page, step.to, step.toPoint),\n ]).pipe(Effect.flatMap(([from, to]) => page.drag(from, to)));\n case \"select\":\n return aim(page, step.subject).pipe(\n Effect.flatMap((at) => page.select(typeof at === \"string\" ? at : \"\", options.values ?? [])),\n Effect.asVoid,\n );\n // A scroll or a typing step may name no element: the page, or whatever has focus.\n case \"scroll\":\n return step.subject === undefined\n ? page.scroll(options)\n : Effect.flatMap(aim(page, step.subject, step.point, step.box), (at) =>\n page.scroll({ ...options, at }),\n );\n case \"type\":\n return step.subject === undefined\n ? page.type(text, { ...options, secret: step.secret })\n : Effect.flatMap(aim(page, step.subject), (into) =>\n page.type(text, {\n ...options,\n into: typeof into === \"string\" ? into : undefined,\n secret: step.secret,\n }),\n );\n }\n};\n\nexport interface TakeOptions {\n /** How each step waits first, except an opening navigation, or false. No final-step wait. */\n readonly settle?: ReadyOptions | false | undefined;\n readonly inputs?: Readonly<Record<string, string>> | undefined;\n /**\n * Bound for recorded arrival and expected effect, each. Defaults to 5 seconds. Zero makes one\n * read without polling; that read retains the page operation's timeout.\n */\n readonly arrival?: Duration.Input | undefined;\n}\n\nexport interface ReplayOptions extends TakeOptions {\n readonly from?: number | Stopped | undefined;\n}\n\n/**\n * Input that can be repeated without repeating a commitment. `take` also validates a Checked\n * target's boolean state before input. Back/reload can resubmit a form.\n */\nexport const repeatable = (step: Step): boolean =>\n [\"navigate\", \"hover\", \"scroll\", \"select\"].includes(step.action) ||\n (step.action === \"type\" &&\n step.subject !== undefined &&\n step.options?.replace !== false &&\n step.options?.submit !== true) ||\n (step.action === \"click\" && step.expect?._tag === \"Checked\");\n\ntype StepError = Missing | Ambiguous | Drifted | BrowserError | Uncertain;\n\n// Zero waits make one read; positive waits bound all reads and never repeat input.\nconst within = (check: Effect.Effect<boolean, StepError>, millis: number) =>\n millis === 0\n ? check\n : check.pipe(\n Effect.repeat({ until: (held) => held, schedule: Schedule.spaced(Duration.millis(25)) }),\n Effect.timeoutOrElse({\n duration: Duration.millis(millis),\n orElse: () => Effect.succeed(false),\n }),\n );\n\nconst sameSite = (url: string, recorded: string) => {\n const origin = URL.parse(recorded)?.origin;\n\n return (\n recorded === \"\" ||\n (origin === undefined || origin === \"null\"\n ? url === recorded\n : URL.parse(url)?.origin === origin)\n );\n};\n\nconst arrived = (page: Page, urls: ReadonlyArray<string>, millis: number) =>\n within(\n Effect.map(page.url, (url) => urls.some((recorded) => sameSite(url, recorded))),\n millis,\n ).pipe(\n Effect.filterOrFail(\n (held) => held,\n () =>\n new Drifted({ detail: \"the page did not reach the recorded site within the arrival wait\" }),\n ),\n Effect.asVoid,\n );\n\nconst checkEffect = (\n page: Page,\n step: Step,\n first?: { readonly url: string; readonly document: number },\n) => {\n const expected = step.expect;\n\n if (expected === undefined) return Effect.succeed(false);\n switch (expected._tag) {\n case \"Checked\":\n return step.subject === undefined\n ? Effect.fail(invalid(\"a checked effect needs a subject\"))\n : Effect.flatMap(locate(page, step.subject), (found) =>\n found.state.checked === undefined\n ? Effect.fail(invalid(\"a checked effect needs a checkable subject\"))\n : Effect.succeed(found.state.checked === expected.checked),\n );\n case \"Navigated\":\n if (expected.url === undefined && first === undefined) return Effect.succeed(false);\n\n return Effect.map(page.state, (now) =>\n expected.url === undefined\n ? now.url !== first?.url || now.document !== first?.document\n : now.url === expected.url,\n );\n case \"Appeared\":\n case \"Gone\":\n return Effect.map(page.find({ ...expected.query, scope: \"document\" }), (found) =>\n expected._tag === \"Appeared\" ? found.length > 0 : found.length === 0,\n );\n }\n};\n\n/**\n * Take one step. Unknown non-repeatable input is never resent: only positive durable read-back\n * can skip it. An interrupted call remains interrupted; persist begun-before-call in the consumer\n * and treat a missing receipt as Stopped{input: \"unknown\"}, including after process restart.\n */\nexport const take = Effect.fn(\"Plan.take\")(function* (\n page: Page,\n plan: Plan,\n at: number | Stopped,\n options: TakeOptions = {},\n): Effect.fn.Return<Receipt, ReplayError> {\n const index = typeof at === \"number\" ? at : at.step;\n let input: Stopped[\"input\"] = typeof at === \"number\" ? \"unsent\" : at.input;\n\n const work = Effect.gen(function* (): Effect.fn.Return<Receipt, StepError> {\n const step = plan.steps[index];\n\n if (!Number.isInteger(index) || index < 0 || step === undefined)\n return yield* invalid(\"the step index is outside the plan\");\n const duration = Duration.fromInput(options.arrival ?? Duration.seconds(5));\n\n if (\n Option.isNone(duration) ||\n Duration.isNegative(duration.value) ||\n !Duration.isFinite(duration.value)\n )\n return yield* invalid(\"arrival must be a finite nonnegative duration\");\n const millis = Duration.toMillis(duration.value);\n const first = yield* page.state;\n\n const uncertain = new Uncertain({\n detail: \"the step may have been sent; reconcile its durable effect before continuing\",\n });\n\n const unresolved = input === \"unknown\" && !repeatable(step);\n const expected = step.expect;\n\n const durable =\n expected !== undefined &&\n (expected._tag === \"Appeared\" ||\n (expected._tag === \"Navigated\" && typeof expected.url === \"string\")) &&\n expected.durable === true;\n\n if (\n !durable &&\n (unresolved || (expected !== undefined && \"durable\" in expected && expected.durable === true))\n )\n return yield* uncertain;\n if (\n options.settle !== false &&\n (index > 0 || ![\"navigate\", \"back\", \"reload\"].includes(step.action))\n )\n yield* page.ready(options.settle);\n const before = plan.steps[index - 1]?.url;\n\n if (before !== undefined)\n yield* arrived(page, unresolved ? [before, step.url] : [before], millis);\n const check = checkEffect(page, step);\n\n const read =\n millis === 0\n ? check\n : check.pipe(\n Effect.timeoutOrElse({\n duration: Duration.millis(millis),\n orElse: () =>\n Effect.fail(new Drifted({ detail: \"the expected-effect read timed out\" })),\n }),\n );\n\n const held = yield* read.pipe(Effect.mapError((error) => (unresolved ? uncertain : error)));\n\n const receipt = (outcome: Receipt[\"outcome\"]) =>\n Effect.gen(function* () {\n yield* arrived(page, [step.url], millis);\n const now = yield* page.state;\n\n return new Receipt({ step: index, outcome, startedAt: first.at, at: now.at });\n });\n\n if (held) return yield* receipt(\"skipped\");\n if (unresolved) return yield* uncertain;\n const text = step.input === undefined ? \"\" : options.inputs?.[step.input];\n\n if (text === undefined) return yield* invalid(`no text for the input \"${step.input ?? \"\"}\"`);\n const verify = checkEffect(page, step, yield* page.state);\n const acted = yield* Effect.exit(dispatch(page, step, text));\n\n if (Exit.isFailure(acted)) {\n const error = Exit.findErrorOption(acted);\n\n if (Option.isSome(error) && error.value._tag === \"BrowserError\" && error.value.dispatched) {\n input = \"unknown\";\n if (expected !== undefined && (repeatable(step) || durable)) {\n const observed = yield* Effect.exit(within(verify, millis));\n\n if (Exit.isSuccess(observed) && observed.value) return yield* receipt(\"verified\");\n }\n }\n\n return yield* Effect.failCause(acted.cause);\n }\n input = \"unknown\";\n if (expected !== undefined && !(yield* within(verify, millis)))\n return yield* new Drifted({ detail: \"the step's expected effect did not arrive\" });\n\n return yield* receipt(expected === undefined ? \"taken\" : \"verified\");\n });\n\n return yield* work.pipe(\n Effect.mapError(\n (reason) =>\n new ReplayError({\n step: index,\n reason,\n input,\n receipts: [],\n }),\n ),\n );\n});\n\nconst run = Effect.fnUntraced(function* (\n page: Page,\n plan: Plan,\n options: TakeOptions,\n from: number | Stopped,\n until: number,\n restoring: boolean,\n) {\n const receipts: Array<Receipt> = [];\n const start = typeof from === \"number\" ? from : from.step;\n\n if (\n !Number.isInteger(start) ||\n start < 0 ||\n start > plan.steps.length ||\n !Number.isInteger(until) ||\n until < start ||\n until > plan.steps.length\n )\n return yield* new ReplayError({\n step: start,\n input: \"unsent\",\n receipts,\n reason: invalid(\"the run bounds are outside the plan\"),\n });\n // Fresh runs still ask for all input slots before changing the page. Restoration checks first.\n if (!restoring && typeof from === \"number\") {\n const unfilled = plan.steps.findIndex(\n (step, index) =>\n index >= start && step.input !== undefined && options.inputs?.[step.input] === undefined,\n );\n\n if (unfilled !== -1)\n return yield* new ReplayError({\n step: start,\n input: \"unsent\",\n receipts,\n reason: invalid(`no text for the input \"${plan.steps[unfilled]?.input ?? \"\"}\"`),\n });\n }\n for (let index = start; index < until; index++) {\n const at = restoring\n ? new Stopped({ step: index, input: \"unknown\" })\n : index === start\n ? from\n : index;\n\n const receipt = yield* take(page, plan, at, options).pipe(\n Effect.mapError((error) => new ReplayError({ ...error, receipts: [...receipts] })),\n );\n\n receipts.push(receipt);\n }\n\n return receipts;\n});\n\n/** Take a plan's steps from a fresh index or durable stopping point, returning completed receipts. */\nexport const replay = (page: Page, plan: Plan, options: ReplayOptions = {}) =>\n run(page, plan, options, options.from ?? 0, plan.steps.length, false).pipe(\n Effect.withSpan(\"Plan.replay\"),\n );\n\n/** Restore prior steps on a fresh page; unresolved commitments require positive durable evidence. */\nexport const restore = (\n page: Page,\n plan: Plan,\n options: TakeOptions & { readonly upTo?: number | undefined } = {},\n) =>\n run(page, plan, options, 0, options.upTo ?? plan.steps.length, true).pipe(\n Effect.withSpan(\"Plan.restore\"),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CACxE,IAAa,UAAU;EACrB,OAAO;CACT;AACF;;AAGA,IAAa,YAAb,cAA+B,OAAO,YAAuB,CAAC,CAAC,aAAa,EAC1E,OAAO,OAAO,IAChB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,GAAG,KAAK,MAAM;CACvB;AACF;;AAGA,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,WAAW,EACpE,QAAQ,OAAO,OACjB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,KAAK;CACd;AACF;AAEA,MAAM,EAAE,OAAO,cAAc,MAAM;AACnC,MAAM,SAAS;CAAC;CAAO;CAAU;CAAS;AAAS;AAEnD,MAAM,QAAQ,YACZ,OAAO,OAAO,OAAO,CAAC,CAAC,QAAQ,UAAU,OAAO,UAAU,QAAQ;;AAGpE,MAAM,WAAW,OAAgC,OAAe,YAA4B;CAC1F,MAAM,MAAM,QAAQ;CAEpB,IAAI,QAAQ,KAAA,KAAa,UAAU,GAAG,MAAM,UAAU,KAAK,GAAG,OAAO;CACrE,IAAI,UAAU,UAAU,OAAO,QAAQ,KAAA,IAAY,IAAI;CACvD,IAAI,UAAU,OACZ,OAAO,QAAQ,KAAA,KACb,KAAK,OAAO,CAAC,CAAC,MAAM,UAAU,GAAG,UAAU,KAAK,EAAE,GAAG,WAAW,GAAG,UAAU,KAAK,EAAE,EAAE,CAAC,IACrF,IACA;CAEN,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,UAAU,MAAM,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CAAC,KACnE,OAAO,SAAS,cAAc,CAChC"}
@@ -1,6 +1,6 @@
1
1
  import { t as BrowserError } from "./BrowserError-Coy7EW1N.mjs";
2
- import { b as Subject, i as BrowserEvent } from "./BrowserEvent-BRu2juEz.mjs";
3
- import { m as ReadyOptions, o as Found, u as Page } from "./Page-DL9eylp3.mjs";
2
+ import { b as Subject, i as BrowserEvent } from "./BrowserEvent-dq6FRT8w.mjs";
3
+ import { m as ReadyOptions, o as Found, u as Page } from "./Page-ku6j5t-v.mjs";
4
4
  import { Duration, Effect, Schema } from "effect";
5
5
  //#region src/internal/reading/choose.d.ts
6
6
  declare const Missing_base: Schema.Class<Missing, Schema.TaggedStruct<"Missing", {}>, import("effect/Cause").YieldableError>;
@@ -213,4 +213,4 @@ declare const restore: (page: Page, plan: Plan, options?: TakeOptions & {
213
213
  }) => Effect.Effect<Receipt[], ReplayError, never>;
214
214
  //#endregion
215
215
  export { take as _, ReplayError as a, Missing as b, StepAction as c, Uncertain as d, fromEvents as f, restore as g, replay as h, Receipt as i, Stopped as l, repeatable as m, Plan as n, ReplayOptions as o, locate as p, Plan_d_exports as r, Step as s, Expected as t, TakeOptions as u, Ambiguous as v, Drifted as y };
216
- //# sourceMappingURL=Plan-6As6vcwT.d.mts.map
216
+ //# sourceMappingURL=Plan-DJ4hEEna.d.mts.map
package/dist/Plan.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as take, a as ReplayError, b as Missing, c as StepAction, d as Uncertain, f as fromEvents, g as restore, h as replay, i as Receipt, l as Stopped, m as repeatable, n as Plan, o as ReplayOptions, p as locate, s as Step, t as Expected, u as TakeOptions, v as Ambiguous, y as Drifted } from "./Plan-6As6vcwT.mjs";
1
+ import { _ as take, a as ReplayError, b as Missing, c as StepAction, d as Uncertain, f as fromEvents, g as restore, h as replay, i as Receipt, l as Stopped, m as repeatable, n as Plan, o as ReplayOptions, p as locate, s as Step, t as Expected, u as TakeOptions, v as Ambiguous, y as Drifted } from "./Plan-DJ4hEEna.mjs";
2
2
  export { Ambiguous, Drifted, Expected, Missing, Plan, Receipt, ReplayError, ReplayOptions, Step, StepAction, Stopped, TakeOptions, Uncertain, fromEvents, locate, repeatable, replay, restore, take };
package/dist/Plan.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as Drifted, a as ReplayError, c as Stopped, d as locate, f as repeatable, g as Ambiguous, h as take, i as Receipt, l as Uncertain, m as restore, n as Plan, o as Step, p as replay, s as StepAction, t as Expected, u as fromEvents, v as Missing } from "./Plan-CXA2BW-G.mjs";
1
+ import { _ as Drifted, a as ReplayError, c as Stopped, d as locate, f as repeatable, g as Ambiguous, h as take, i as Receipt, l as Uncertain, m as restore, n as Plan, o as Step, p as replay, s as StepAction, t as Expected, u as fromEvents, v as Missing } from "./Plan-C-d5QYS8.mjs";
2
2
  export { Ambiguous, Drifted, Expected, Missing, Plan, Receipt, ReplayError, Step, StepAction, Stopped, Uncertain, fromEvents, locate, repeatable, replay, restore, take };
package/dist/Policy.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as InputGuard, i as Fact, l as InputRequest } from "./Page-DL9eylp3.mjs";
1
+ import { c as InputGuard, i as Fact, l as InputRequest } from "./Page-ku6j5t-v.mjs";
2
2
  import { Context, Duration, Effect, Schema } from "effect";
3
3
  import { AiError, DecisionModel, LanguageModel } from "effect/ai";
4
4
  declare namespace Policy_d_exports {
package/dist/Policy.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { PolicyDenied } from "./BrowserError.mjs";
3
- import { i as InputRequest, n as Fact } from "./Page-B5cjaUp5.mjs";
3
+ import { i as InputRequest, n as Fact } from "./Page-CfB6Zn1p.mjs";
4
4
  import { Cause, Context, Duration, Effect, Record, Result, Schema } from "effect";
5
5
  import { Decision, DecisionModel, LanguageModel, Prompt } from "effect/ai";
6
6
  //#region src/Policy.ts
@@ -1,5 +1,5 @@
1
- import { b as Target, u as Page } from "./Page-DL9eylp3.mjs";
2
- import { Service, t as Motion_d_exports } from "./Motion.mjs";
1
+ import { b as Target, u as Page } from "./Page-ku6j5t-v.mjs";
2
+ import { a as Service, t as Motion_d_exports } from "./Motion-DND6I-64.mjs";
3
3
  import { Duration, Effect } from "effect";
4
4
  declare namespace Presentation_d_exports {
5
5
  export { Options, Pacing, Presenter, View, human, make };
@@ -1,6 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { lognormal } from "./Motion.mjs";
3
- import { a as performed, i as pause, r as viewOf, t as internalsOf } from "./page-B92QnRfT.mjs";
3
+ import { d as monotonicMillis } from "./context-w3NJPRLo.mjs";
4
+ import { a as performed, i as pause, r as viewOf, t as internalsOf } from "./page-BKwfF6z-.mjs";
4
5
  import { Clock, Duration, Effect, Fiber, MutableRef, Option, Semaphore } from "effect";
5
6
  //#region src/Presentation.ts
6
7
  /**
@@ -45,7 +46,7 @@ const make = Effect.fn("Presentation.make")(function* (options = {}) {
45
46
  const pacing = options.pacing ?? human;
46
47
  const clock = yield* Clock.Clock;
47
48
  const scope = yield* Effect.scope;
48
- const now = () => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;
49
+ const now = () => monotonicMillis(clock);
49
50
  const pointer = MutableRef.make(Option.none());
50
51
  const hand = yield* Semaphore.make(1);
51
52
  const style = performed({
@@ -1 +1 @@
1
- {"version":3,"file":"Presentation.mjs","names":["Style.performed","Motion.lognormal","Style.pause"],"sources":["../src/Presentation.ts"],"sourcesContent":["/**\n * Input performed for viewers. A presenter owns one drawn pointer and a pace; `view(page)` is the\n * page with its actions performed: each waits as long as a person reacts, the pointer glides from\n * where viewers last saw it, on whichever page, a field is clicked before typing, keys go at the\n * pace's words a minute and the wheel turns in bursts, out to a target out of view. One view acts at\n * a time, as one hand moves one pointer, and its presentation time is outside `actionTimeout`. The\n * page itself stays plain, and plain input never waits for a view.\n *\n * ```ts\n * const presenter = yield* Presentation.make({ motion: yield* HumanStrokes.motion })\n * const performed = presenter.view(page)\n * yield* performed.aim(\"e12\") // as the target appears in a streamed tool call\n * yield* performed.click(\"e12\") // completes the glide, then clicks\n * ```\n *\n * @since 0.3.0\n */\nimport { Clock, Duration, Effect, Fiber, MutableRef, Option, Semaphore } from \"effect\";\n\nimport type { BrowserError } from \"./BrowserError.ts\";\nimport * as Style from \"./internal/input/style.ts\";\nimport { type Internals, internalsOf, viewOf } from \"./internal/page/page.ts\";\nimport * as Motion from \"./Motion.ts\";\nimport type { Page, Point, Target } from \"./Page.ts\";\n\n/** How long a person waits before acting, and how fast they type. */\nexport interface Pacing {\n /** The usual wait before an action that follows an expected change, as the next field of a form. */\n readonly expected: Duration.Input;\n /** The usual wait after the page moved to a new document. */\n readonly surprise: Duration.Input;\n /** The usual wait before a page's first action, or one after an action on another page. */\n readonly unrelated: Duration.Input;\n /** Typing speed, a word being five characters. */\n readonly wordsPerMinute: number;\n}\n\n/**\n * The research's medians: 280 ms to react to an expected change, 600 ms to a surprise and 1 second\n * between unrelated actions, each drawn around its median, and typing at 70 words per minute.\n */\nexport const human: Pacing = {\n expected: \"280 millis\",\n surprise: \"600 millis\",\n unrelated: \"1 second\",\n wordsPerMinute: 70,\n};\n\nexport interface Options {\n /** Defaults to `human`. */\n readonly pacing?: Pacing | undefined;\n /** The pointer's paths. Defaults to `Motion.lognormal`. */\n readonly motion?: Motion.Service | undefined;\n}\n\n/** A page whose actions are performed, which can also start the pointer toward a target early. */\nexport interface View extends Page {\n /**\n * Start the glide toward `target` as soon as it is known, as in a model's streamed tool call. The\n * next action waits for it when it acts on the same target, and otherwise stops it where it is.\n * An aim presses nothing and records no action; under an input guard it does nothing.\n */\n readonly aim: (target: Target) => Effect.Effect<void>;\n}\n\nexport interface Presenter {\n /** `page`, a page a `Browser` opened, with its actions performed: the same view for the same page. */\n readonly view: (page: Page) => View;\n}\n\n// Reactions spread as the research measured them: an expected change least.\nconst spread = { expected: 0.3, surprise: 0.4, unrelated: 0.4 };\n\nconst sameTarget = (left: Target, right: Target | undefined) =>\n typeof left === \"string\" || typeof right !== \"object\"\n ? left === right\n : left.x === right.x && left.y === right.y;\n\n/** A presenter, for the scope: its pointer, its pace and the aims it has started. */\nexport const make = Effect.fn(\"Presentation.make\")(function* (options: Options = {}) {\n const pacing = options.pacing ?? human;\n const clock = yield* Clock.Clock;\n const scope = yield* Effect.scope;\n const now = () => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;\n const pointer = MutableRef.make(Option.none<Point>());\n const hand = yield* Semaphore.make(1);\n\n const style = Style.performed({\n pointer,\n motion: options.motion ?? Motion.lognormal,\n wordsPerMinute: pacing.wordsPerMinute,\n });\n\n const medians = {\n expected: Duration.toMillis(Duration.fromInputUnsafe(pacing.expected)),\n surprise: Duration.toMillis(Duration.fromInputUnsafe(pacing.surprise)),\n unrelated: Duration.toMillis(Duration.fromInputUnsafe(pacing.unrelated)),\n };\n\n // The latest performed action: its page, the document it began in, and when it ended.\n let last: { readonly page: string; readonly document: number; readonly at: number } | undefined;\n\n // A person reacts to what the last action left: an expected change, a new document, as a link\n // opens, or another page altogether. Time already spent since it ended counts toward the wait.\n const react = (page: Page, internals: Internals) =>\n Effect.gen(function* () {\n const kind =\n last === undefined || last.page !== page.id\n ? \"unrelated\"\n : last.document === internals.document()\n ? \"expected\"\n : \"surprise\";\n\n const left = (last?.at ?? now()) + (yield* Style.pause(medians[kind], spread[kind])) - now();\n\n if (left > 0) yield* Effect.sleep(Duration.millis(left));\n }).pipe(Effect.provideService(Clock.Clock, clock));\n\n const views = new WeakMap<Page, View>();\n\n const view = (page: Page): View => {\n const known = views.get(page);\n\n if (known !== undefined) return known;\n const internals = internalsOf(page);\n\n if (internals === undefined)\n throw new TypeError(\"only a page that a Browser opened can be presented\");\n const { input } = internals;\n\n let aiming:\n | { readonly target: Target; readonly fiber: Fiber.Fiber<void, BrowserError> }\n | undefined;\n\n // An aim at the action's own target is completed; any other is stopped where it is.\n const completeAim = (target: Target | undefined) =>\n Effect.suspend(() => {\n const current = aiming;\n\n aiming = undefined;\n if (current === undefined) return Effect.void;\n\n return sameTarget(current.target, target)\n ? Effect.asVoid(Fiber.await(current.fiber))\n : Fiber.interrupt(current.fiber);\n });\n\n const perform =\n (target: Target | undefined) =>\n <A, E>(action: Effect.Effect<A, E>): Effect.Effect<A, E> =>\n completeAim(target).pipe(\n Effect.andThen(\n hand.withPermits(1)(\n Effect.gen(function* () {\n yield* react(page, internals);\n const document = internals.document();\n\n return yield* action.pipe(\n Effect.ensuring(\n Effect.sync(() => {\n last = { page: page.id, document, at: now() };\n }),\n ),\n );\n }),\n ),\n ),\n );\n\n const performed: View = viewOf(page, {\n ...page,\n click: (target, clickOptions) => perform(target)(input.click(target, clickOptions, style)),\n hover: (target) => perform(target)(input.hover(target, style)),\n drag: (from, to) => perform(from)(input.drag(from, to, style)),\n type: (text, typeOptions) => perform(typeOptions?.into)(input.type(text, typeOptions, style)),\n press: (keys, pressOptions) => perform(undefined)(input.press(keys, pressOptions, style)),\n scroll: (scrollOptions) => perform(scrollOptions?.at)(input.scroll(scrollOptions, style)),\n select: (ref, values) => perform(ref)(input.select(ref, values)),\n aim: (target) =>\n Effect.gen(function* () {\n yield* completeAim(undefined);\n aiming = {\n target,\n fiber: yield* hand.withPermits(1)(input.aim(target, style)).pipe(Effect.forkIn(scope)),\n };\n }),\n });\n\n views.set(page, performed);\n\n return performed;\n };\n\n return { view } satisfies Presenter;\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,QAAgB;CAC3B,UAAU;CACV,UAAU;CACV,WAAW;CACX,gBAAgB;AAClB;AAyBA,MAAM,SAAS;CAAE,UAAU;CAAK,UAAU;CAAK,WAAW;AAAI;AAE9D,MAAM,cAAc,MAAc,UAChC,OAAO,SAAS,YAAY,OAAO,UAAU,WACzC,SAAS,QACT,KAAK,MAAM,MAAM,KAAK,KAAK,MAAM,MAAM;;AAG7C,MAAa,OAAO,OAAO,GAAG,mBAAmB,CAAC,C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AO,IAAI,aAAa;IACtB,OAAO,YAAY,KAAA,CAAS;IAC5B,SAAS;KACP;KACA,OAAO,OAAO,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,IAAI,QAAQ,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,OAAO,KAAK,CAAC;IACvF;GACF,CAAC;EACL,CAAC;EAED,MAAM,IAAI,MAAM,SAAS;EAEzB,OAAO;CACT;CAEA,OAAO,EAAE,KAAK;AAChB,CAAC"}
1
+ {"version":3,"file":"Presentation.mjs","names":["Style.performed","Motion.lognormal","Style.pause"],"sources":["../src/Presentation.ts"],"sourcesContent":["/**\n * Input performed for viewers. A presenter owns one drawn pointer and a pace; `view(page)` is the\n * page with its actions performed: each waits as long as a person reacts, the pointer glides from\n * where viewers last saw it, on whichever page, a field is clicked before typing, keys go at the\n * pace's words a minute and the wheel turns in bursts, out to a target out of view. One view acts at\n * a time, as one hand moves one pointer, and its presentation time is outside `actionTimeout`. The\n * page itself stays plain, and plain input never waits for a view.\n *\n * ```ts\n * const presenter = yield* Presentation.make({ motion: yield* HumanStrokes.motion })\n * const performed = presenter.view(page)\n * yield* performed.aim(\"e12\") // as the target appears in a streamed tool call\n * yield* performed.click(\"e12\") // completes the glide, then clicks\n * ```\n *\n * @since 0.3.0\n */\nimport { Clock, Duration, Effect, Fiber, MutableRef, Option, Semaphore } from \"effect\";\n\nimport type { BrowserError } from \"./BrowserError.ts\";\nimport * as Style from \"./internal/input/style.ts\";\nimport { type Internals, internalsOf, viewOf } from \"./internal/page/page.ts\";\nimport { monotonicMillis } from \"./internal/pictures/clock.ts\";\nimport * as Motion from \"./Motion.ts\";\nimport type { Page, Point, Target } from \"./Page.ts\";\n\n/** How long a person waits before acting, and how fast they type. */\nexport interface Pacing {\n /** The usual wait before an action that follows an expected change, as the next field of a form. */\n readonly expected: Duration.Input;\n /** The usual wait after the page moved to a new document. */\n readonly surprise: Duration.Input;\n /** The usual wait before a page's first action, or one after an action on another page. */\n readonly unrelated: Duration.Input;\n /** Typing speed, a word being five characters. */\n readonly wordsPerMinute: number;\n}\n\n/**\n * The research's medians: 280 ms to react to an expected change, 600 ms to a surprise and 1 second\n * between unrelated actions, each drawn around its median, and typing at 70 words per minute.\n */\nexport const human: Pacing = {\n expected: \"280 millis\",\n surprise: \"600 millis\",\n unrelated: \"1 second\",\n wordsPerMinute: 70,\n};\n\nexport interface Options {\n /** Defaults to `human`. */\n readonly pacing?: Pacing | undefined;\n /** The pointer's paths. Defaults to `Motion.lognormal`. */\n readonly motion?: Motion.Service | undefined;\n}\n\n/** A page whose actions are performed, which can also start the pointer toward a target early. */\nexport interface View extends Page {\n /**\n * Start the glide toward `target` as soon as it is known, as in a model's streamed tool call. The\n * next action waits for it when it acts on the same target, and otherwise stops it where it is.\n * An aim presses nothing and records no action; under an input guard it does nothing.\n */\n readonly aim: (target: Target) => Effect.Effect<void>;\n}\n\nexport interface Presenter {\n /** `page`, a page a `Browser` opened, with its actions performed: the same view for the same page. */\n readonly view: (page: Page) => View;\n}\n\n// Reactions spread as the research measured them: an expected change least.\nconst spread = { expected: 0.3, surprise: 0.4, unrelated: 0.4 };\n\nconst sameTarget = (left: Target, right: Target | undefined) =>\n typeof left === \"string\" || typeof right !== \"object\"\n ? left === right\n : left.x === right.x && left.y === right.y;\n\n/** A presenter, for the scope: its pointer, its pace and the aims it has started. */\nexport const make = Effect.fn(\"Presentation.make\")(function* (options: Options = {}) {\n const pacing = options.pacing ?? human;\n const clock = yield* Clock.Clock;\n const scope = yield* Effect.scope;\n const now = () => monotonicMillis(clock);\n const pointer = MutableRef.make(Option.none<Point>());\n const hand = yield* Semaphore.make(1);\n\n const style = Style.performed({\n pointer,\n motion: options.motion ?? Motion.lognormal,\n wordsPerMinute: pacing.wordsPerMinute,\n });\n\n const medians = {\n expected: Duration.toMillis(Duration.fromInputUnsafe(pacing.expected)),\n surprise: Duration.toMillis(Duration.fromInputUnsafe(pacing.surprise)),\n unrelated: Duration.toMillis(Duration.fromInputUnsafe(pacing.unrelated)),\n };\n\n // The latest performed action: its page, the document it began in, and when it ended.\n let last: { readonly page: string; readonly document: number; readonly at: number } | undefined;\n\n // A person reacts to what the last action left: an expected change, a new document, as a link\n // opens, or another page altogether. Time already spent since it ended counts toward the wait.\n const react = (page: Page, internals: Internals) =>\n Effect.gen(function* () {\n const kind =\n last === undefined || last.page !== page.id\n ? \"unrelated\"\n : last.document === internals.document()\n ? \"expected\"\n : \"surprise\";\n\n const left = (last?.at ?? now()) + (yield* Style.pause(medians[kind], spread[kind])) - now();\n\n if (left > 0) yield* Effect.sleep(Duration.millis(left));\n }).pipe(Effect.provideService(Clock.Clock, clock));\n\n const views = new WeakMap<Page, View>();\n\n const view = (page: Page): View => {\n const known = views.get(page);\n\n if (known !== undefined) return known;\n const internals = internalsOf(page);\n\n if (internals === undefined)\n throw new TypeError(\"only a page that a Browser opened can be presented\");\n const { input } = internals;\n\n let aiming:\n | { readonly target: Target; readonly fiber: Fiber.Fiber<void, BrowserError> }\n | undefined;\n\n // An aim at the action's own target is completed; any other is stopped where it is.\n const completeAim = (target: Target | undefined) =>\n Effect.suspend(() => {\n const current = aiming;\n\n aiming = undefined;\n if (current === undefined) return Effect.void;\n\n return sameTarget(current.target, target)\n ? Effect.asVoid(Fiber.await(current.fiber))\n : Fiber.interrupt(current.fiber);\n });\n\n const perform =\n (target: Target | undefined) =>\n <A, E>(action: Effect.Effect<A, E>): Effect.Effect<A, E> =>\n completeAim(target).pipe(\n Effect.andThen(\n hand.withPermits(1)(\n Effect.gen(function* () {\n yield* react(page, internals);\n const document = internals.document();\n\n return yield* action.pipe(\n Effect.ensuring(\n Effect.sync(() => {\n last = { page: page.id, document, at: now() };\n }),\n ),\n );\n }),\n ),\n ),\n );\n\n const performed: View = viewOf(page, {\n ...page,\n click: (target, clickOptions) => perform(target)(input.click(target, clickOptions, style)),\n hover: (target) => perform(target)(input.hover(target, style)),\n drag: (from, to) => perform(from)(input.drag(from, to, style)),\n type: (text, typeOptions) => perform(typeOptions?.into)(input.type(text, typeOptions, style)),\n press: (keys, pressOptions) => perform(undefined)(input.press(keys, pressOptions, style)),\n scroll: (scrollOptions) => perform(scrollOptions?.at)(input.scroll(scrollOptions, style)),\n select: (ref, values) => perform(ref)(input.select(ref, values)),\n aim: (target) =>\n Effect.gen(function* () {\n yield* completeAim(undefined);\n aiming = {\n target,\n fiber: yield* hand.withPermits(1)(input.aim(target, style)).pipe(Effect.forkIn(scope)),\n };\n }),\n });\n\n views.set(page, performed);\n\n return performed;\n };\n\n return { view } satisfies Presenter;\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,QAAgB;CAC3B,UAAU;CACV,UAAU;CACV,WAAW;CACX,gBAAgB;AAClB;AAyBA,MAAM,SAAS;CAAE,UAAU;CAAK,UAAU;CAAK,WAAW;AAAI;AAE9D,MAAM,cAAc,MAAc,UAChC,OAAO,SAAS,YAAY,OAAO,UAAU,WACzC,SAAS,QACT,KAAK,MAAM,MAAM,KAAK,KAAK,MAAM,MAAM;;AAG7C,MAAa,OAAO,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,UAAmB,CAAC,GAAG;CACnF,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,QAAQ,OAAO,OAAO;CAC5B,MAAM,YAAY,gBAAgB,KAAK;CACvC,MAAM,UAAU,WAAW,KAAK,OAAO,KAAY,CAAC;CACpD,MAAM,OAAO,OAAO,UAAU,KAAK,CAAC;CAEpC,MAAM,QAAQA,UAAgB;EAC5B;EACA,QAAQ,QAAQ,UAAUC;EAC1B,gBAAgB,OAAO;CACzB,CAAC;CAED,MAAM,UAAU;EACd,UAAU,SAAS,SAAS,SAAS,gBAAgB,OAAO,QAAQ,CAAC;EACrE,UAAU,SAAS,SAAS,SAAS,gBAAgB,OAAO,QAAQ,CAAC;EACrE,WAAW,SAAS,SAAS,SAAS,gBAAgB,OAAO,SAAS,CAAC;CACzE;CAGA,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EJ,MAAM,YAAkB,OAAO,MAAM;GACnC,GAAG;GACH,QAAQ,QAAQ,iBAAiB,QAAQ,MAAM,CAAC,CAAC,MAAM,MAAM,QAAQ,cAAc,KAAK,CAAC;GACzF,QAAQ,WAAW,QAAQ,MAAM,CAAC,CAAC,MAAM,MAAM,QAAQ,KAAK,CAAC;GAC7D,OAAO,MAAM,OAAO,QAAQ,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,KAAK,CAAC;GAC7D,OAAO,MAAM,gBAAgB,QAAQ,aAAa,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,aAAa,KAAK,CAAC;GAC5F,QAAQ,MAAM,iBAAiB,QAAQ,KAAA,CAAS,CAAC,CAAC,MAAM,MAAM,MAAM,cAAc,KAAK,CAAC;GACxF,SAAS,kBAAkB,QAAQ,eAAe,EAAE,CAAC,CAAC,MAAM,OAAO,eAAe,KAAK,CAAC;GACxF,SAAS,KAAK,WAAW,QAAQ,GAAG,CAAC,CAAC,MAAM,OAAO,KAAK,MAAM,CAAC;GAC/D,MAAM,WACJ,OAAO,IAAI,aAAa;IACtB,OAAO,YAAY,KAAA,CAAS;IAC5B,SAAS;KACP;KACA,OAAO,OAAO,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,IAAI,QAAQ,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,OAAO,KAAK,CAAC;IACvF;GACF,CAAC;EACL,CAAC;EAED,MAAM,IAAI,MAAM,SAAS;EAEzB,OAAO;CACT;CAEA,OAAO,EAAE,KAAK;AAChB,CAAC"}
package/dist/Stage.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as BrowserError } from "./BrowserError-Coy7EW1N.mjs";
2
2
  import { n as CaptureStats, o as ScreencastOptions, r as Frame } from "./Frame-DkNdjjjr.mjs";
3
- import { u as Page } from "./Page-DL9eylp3.mjs";
3
+ import { u as Page } from "./Page-ku6j5t-v.mjs";
4
4
  import { Duration, Effect, Option, Schema, Scope, Stream } from "effect";
5
5
  declare namespace Stage_d_exports {
6
6
  export { Cue, Options, Presented, Shown, Stage, make };
package/dist/Stage.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { Closed, InvalidRequest, Timeout, consequence } from "./BrowserError.mjs";
3
- import { i as failWith, s as undispatched } from "./context-BAjRj7Xo.mjs";
4
- import { t as internalsOf } from "./page-B92QnRfT.mjs";
3
+ import { c as undispatched, d as monotonicMillis, i as failWith, s as refuse } from "./context-w3NJPRLo.mjs";
4
+ import { t as internalsOf } from "./page-BKwfF6z-.mjs";
5
5
  import { Cause, Clock, Deferred, Duration, Effect, Exit, Fiber, Option, PubSub, Result, Schedule, Schema, Scope, Stream } from "effect";
6
6
  //#region src/Stage.ts
7
7
  /**
@@ -91,10 +91,11 @@ const evidence = (output, current, now, hold) => Stream.unwrap(Effect.sync(() =>
91
91
  let gone;
92
92
  const probe = Effect.gen(function* () {
93
93
  yield* until(Math.max(checkedAt, current()?.changedAt ?? checkedAt) + millis, now);
94
- checkedAt = now();
95
94
  const before = current();
96
95
  const frame = before?.frame;
97
- if (before === void 0 || frame === void 0 || gone === before.feed || checkedAt - before.changedAt < millis) return Option.none();
96
+ if (before !== void 0 && now() - before.changedAt < millis) return Option.none();
97
+ checkedAt = now();
98
+ if (before === void 0 || frame === void 0 || gone === before.feed) return Option.none();
98
99
  const { feed } = before;
99
100
  const confirmed = yield* Effect.result(confirm(feed, frame));
100
101
  if (current()?.feed !== feed || current()?.frame !== frame) return Option.none();
@@ -193,9 +194,9 @@ const openFeed = (page, owner, clock, settings, current, publish) => Effect.gen(
193
194
  const make = Effect.fn("Stage.make")(function* (options = {}) {
194
195
  const clock = yield* Clock.Clock;
195
196
  const owner = yield* Effect.scope;
196
- const now = () => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;
197
+ const now = () => monotonicMillis(clock);
197
198
  const waited = Duration.fromInput(options.firstFrame ?? Duration.seconds(5));
198
- if (Option.isNone(waited) || !Duration.isFinite(waited.value) || !Duration.isPositive(waited.value)) return yield* failWith("stage", new InvalidRequest({ detail: "firstFrame must be a finite positive duration" }));
199
+ if (Option.isNone(waited) || !Duration.isFinite(waited.value) || !Duration.isPositive(waited.value)) return yield* refuse("stage", "firstFrame must be a finite positive duration");
199
200
  const firstFrame = waited.value;
200
201
  const settings = {
201
202
  quality: options.quality,
@@ -221,7 +222,7 @@ const make = Effect.fn("Stage.make")(function* (options = {}) {
221
222
  const commit = (feed, options = {}) => Effect.suspend(() => {
222
223
  const asked = options.at ?? now();
223
224
  return switching(Effect.gen(function* () {
224
- if (!Number.isFinite(asked)) return yield* failWith("cue", new InvalidRequest({ detail: "at must be finite host milliseconds" }));
225
+ if (!Number.isFinite(asked)) return yield* refuse("cue", "at must be finite host milliseconds");
225
226
  yield* firstOf(feed, firstFrame);
226
227
  const old = showing;
227
228
  if (old?.feed === feed) return old.presented;
@@ -1 +1 @@
1
- {"version":3,"file":"Stage.mjs","names":[],"sources":["../src/Stage.ts"],"sourcesContent":["/**\n * An output's capture ownership. Cue a page while preparing an event; commit when that event\n * happens. A prepared cue belongs to its caller's scope, and a committed one to the stage.\n * Commits serialize, drain old-page input and refuse stale first frames. `shown` distinguishes\n * confirmed silence, uncertain silence and loss without treating capture silence as evidence.\n * @since 0.3.0\n */\nimport {\n Cause,\n Clock,\n Deferred,\n Duration,\n Effect,\n Exit,\n Fiber,\n Option,\n PubSub,\n Result,\n Schedule,\n Schema,\n Scope,\n Stream,\n} from \"effect\";\n\nimport { type BrowserError, Closed, consequence, InvalidRequest, Timeout } from \"./BrowserError.ts\";\nimport type { CaptureStats, Frame, ScreencastOptions } from \"./Frame.ts\";\nimport { failWith, undispatched } from \"./internal/page/context.ts\";\nimport { internalsOf } from \"./internal/page/page.ts\";\nimport type { Page } from \"./Page.ts\";\n\nexport interface Options extends ScreencastOptions {\n /** Bound for each first-frame wait. Defaults to 5 seconds. */\n readonly firstFrame?: Duration.Input | undefined;\n}\n\n/** A switch that took effect, on the clock shared by browser events and frames. */\nexport class Presented extends Schema.Class<Presented>(\"effect-browser/Presented\")({\n page: Schema.String,\n at: Schema.Finite,\n latency: Schema.Finite,\n}) {}\n\nexport interface Cue {\n readonly page: Page;\n /** A frame of the current document, or the capture's failure or first-frame timeout. */\n readonly ready: Effect.Effect<void, BrowserError>;\n /** Commit on the event's host time, or now. Interruption before switching leaves the cue usable. */\n readonly commit: (options?: {\n readonly at?: number | undefined;\n }) => Effect.Effect<Presented, BrowserError>;\n}\n\n/** What the output establishes at nondecreasing host times; frames retain their capture times. */\nexport type Shown =\n | { readonly _tag: \"Painted\"; readonly frame: Frame; readonly at: number }\n | { readonly _tag: \"Still\"; readonly frame: Frame; readonly at: number }\n | { readonly _tag: \"Stalled\"; readonly frame: Frame; readonly at: number }\n | { readonly _tag: \"Gone\"; readonly page: string; readonly at: number };\n\nexport interface Stage {\n readonly present: (\n page: Page,\n options?: { readonly at?: number | undefined },\n ) => Effect.Effect<Presented, BrowserError>;\n readonly cue: (page: Page) => Effect.Effect<Cue, BrowserError, Scope.Scope>;\n /** Paint and, after every finite positive hold without paint, current evidence or loss. */\n readonly shown: (options: { readonly hold: Duration.Input }) => Stream.Stream<Shown>;\n /** Capture-timed current-page paint; use `shown` for output time. Readers retain 16 frames. */\n readonly frames: Stream.Stream<Frame>;\n readonly current: Effect.Effect<Option.Option<Page>>;\n readonly stats: (options?: {\n readonly window?: Duration.Input | undefined;\n }) => Effect.Effect<Option.Option<CaptureStats>, BrowserError>;\n}\n\ntype FeedState =\n | { readonly _tag: \"Warming\" }\n | { readonly _tag: \"Ready\"; readonly latest: Frame | undefined }\n | { readonly _tag: \"Stopped\" };\ninterface Feed {\n readonly page: Page;\n readonly scope: Scope.Closeable;\n readonly changed: PubSub.PubSub<Frame>;\n state: FeedState;\n fiber: Fiber.Fiber<void, BrowserError> | undefined;\n}\ninterface Paint {\n readonly feed: Feed;\n readonly frame: Frame;\n readonly at: number;\n}\n\ninterface Evidence {\n readonly feed: Feed;\n readonly frame: Frame;\n readonly value: Shown;\n}\n\nconst unavailable = () =>\n undispatched(\"cue\", new InvalidRequest({ detail: \"the cue's capture is no longer available\" }));\n\n/** The sole writer of a cue's capture lifecycle; presentation ownership belongs to the stage. */\nconst update = (\n feed: Feed,\n input: { readonly _tag: \"Paint\"; readonly frame: Frame } | { readonly _tag: \"Reset\" | \"Stop\" },\n) => {\n if (feed.state._tag === \"Stopped\") return;\n if (input._tag === \"Stop\") feed.state = { _tag: \"Stopped\" };\n else if (input._tag === \"Paint\") feed.state = { _tag: \"Ready\", latest: input.frame };\n else if (feed.state._tag === \"Ready\") feed.state = { _tag: \"Ready\", latest: undefined };\n};\n\nconst restartable = (error: BrowserError) => {\n const { lost, repeat } = consequence(error);\n\n return lost === \"nothing\" && repeat !== \"pointless\";\n};\n\nconst stop = (feed: Feed) =>\n Effect.suspend(() => {\n update(feed, { _tag: \"Stop\" });\n\n return Scope.close(feed.scope, Exit.void);\n });\n\nconst frameOf = (feed: Feed) => {\n const frame = feed.state._tag === \"Ready\" ? feed.state.latest : undefined;\n const internals = internalsOf(feed.page);\n\n return frame !== undefined && (internals === undefined || internals.current(frame))\n ? frame\n : undefined;\n};\n\nconst ended = (feed: Feed): Effect.Effect<never, BrowserError> =>\n feed.fiber === undefined\n ? Effect.never\n : Fiber.await(feed.fiber).pipe(\n Effect.flatMap((exit) =>\n Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)\n ? Effect.failCause(exit.cause)\n : Effect.fail(unavailable()),\n ),\n );\n\nconst firstOf = (feed: Feed, wait: Duration.Duration) =>\n Effect.suspend(() => {\n if (feed.state._tag === \"Stopped\") return Effect.fail(unavailable());\n if (feed.page.playwright.isClosed()) return failWith(\"cue\", new Closed({ cause: \"page\" }));\n if (frameOf(feed) !== undefined) return Effect.void;\n\n return Effect.raceFirst(\n Stream.fromPubSub(feed.changed).pipe(\n Stream.filter(() => frameOf(feed) !== undefined),\n Stream.runHead,\n Effect.asVoid,\n ),\n ended(feed),\n ).pipe(\n Effect.timeoutOrElse({\n duration: wait,\n orElse: () => failWith(\"cue\", new Timeout({ millis: Duration.toMillis(wait) })),\n }),\n );\n });\n\n// A timer can wake a fraction early; a commit never precedes its event.\nconst until = (at: number, now: () => number): Effect.Effect<void> =>\n Effect.suspend(() =>\n at > now()\n ? Effect.sleep(Duration.millis(Math.ceil(at - now()))).pipe(Effect.andThen(until(at, now)))\n : Effect.void,\n );\n\n/** Reserve the next turn before waking it; a fresh caller cannot overtake a queued commit. */\nconst ordered = () => {\n const waiting: Array<Deferred.Deferred<void>> = [];\n\n return <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n Effect.acquireUseRelease(\n Effect.sync(() => {\n const turn = Deferred.makeUnsafe<void>();\n\n waiting.push(turn);\n if (waiting.length === 1) Deferred.doneUnsafe(turn, Exit.void);\n\n return turn;\n }),\n (turn) => Deferred.await(turn).pipe(Effect.andThen(effect)),\n (turn) =>\n Effect.sync(() => {\n const at = waiting.indexOf(turn);\n\n waiting.splice(at, 1);\n if (at === 0 && waiting[0] !== undefined) Deferred.doneUnsafe(waiting[0], Exit.void);\n }),\n );\n};\n\n/** A terminal capture can know the connection is gone before the page receives its close event. */\nconst confirm = (feed: Feed, frame: Frame) => {\n const exit = feed.fiber?.pollUnsafe();\n\n const failure =\n exit !== undefined && Exit.isFailure(exit) ? Cause.findErrorOption(exit.cause) : Option.none();\n\n if (Option.isSome(failure) && consequence(failure.value).lost !== \"nothing\")\n return Effect.fail(failure.value);\n\n return feed.page.playwright.isClosed()\n ? failWith(\"shown\", new Closed({ cause: \"page\" }))\n : (internalsOf(feed.page)?.confirm(frame) ?? Effect.succeed(false));\n};\n\n/** Each subscriber confirms silence; a new frame or commit invalidates a probe. */\nconst evidence = (\n output: PubSub.PubSub<Paint>,\n current: () =>\n | { readonly feed: Feed; readonly frame: Frame; readonly changedAt: number }\n | undefined,\n now: () => number,\n hold: Duration.Input,\n): Stream.Stream<Shown> =>\n Stream.unwrap(\n Effect.sync(() => {\n const parsed = Duration.fromInput(hold);\n\n if (\n Option.isNone(parsed) ||\n !Duration.isFinite(parsed.value) ||\n !Duration.isPositive(parsed.value)\n )\n throw new RangeError(\"shown hold must be a finite positive duration\");\n const millis = Duration.toMillis(parsed.value);\n let checkedAt = now();\n let shownAt = Number.NEGATIVE_INFINITY;\n let seen: Pick<Paint, \"feed\" | \"frame\"> | undefined = current();\n let gone: Feed | undefined;\n\n const probe = Effect.gen(function* () {\n yield* until(Math.max(checkedAt, current()?.changedAt ?? checkedAt) + millis, now);\n checkedAt = now();\n const before = current();\n const frame = before?.frame;\n\n if (\n before === undefined ||\n frame === undefined ||\n gone === before.feed ||\n checkedAt - before.changedAt < millis\n )\n return Option.none<Evidence>();\n const { feed } = before;\n\n const confirmed = yield* Effect.result(confirm(feed, frame));\n\n if (current()?.feed !== feed || current()?.frame !== frame) return Option.none<Evidence>();\n const at = now();\n\n checkedAt = at;\n if (Result.isFailure(confirmed) && consequence(confirmed.failure).lost !== \"nothing\") {\n return Option.some<Evidence>({\n feed,\n frame,\n value: { _tag: \"Gone\", page: feed.page.id, at },\n });\n }\n\n return Option.some<Evidence>({\n feed,\n frame,\n value: {\n _tag: Result.isSuccess(confirmed) && confirmed.success ? \"Still\" : \"Stalled\",\n frame,\n at,\n },\n });\n });\n\n return Stream.merge(\n Stream.fromPubSub(output).pipe(\n Stream.map(({ feed, frame, at }): Evidence => ({\n feed,\n frame,\n value: { _tag: \"Painted\", frame, at },\n })),\n ),\n Stream.fromEffectRepeat(probe).pipe(\n Stream.filter(Option.isSome),\n Stream.map(({ value }) => value),\n ),\n ).pipe(\n // A probe can overtake queued paint while its reader is paused. It establishes nothing\n // about that reader's output until the matching frame has reached it.\n Stream.filter(({ feed, frame, value }) => {\n if (value._tag === \"Painted\" && gone !== feed) {\n seen = { feed, frame };\n\n return true;\n }\n // The subscription may have begun after its first publication.\n seen ??= { feed, frame };\n\n return value._tag !== \"Painted\" && seen?.feed === feed && seen.frame === frame;\n }),\n Stream.map(({ feed, value }) => {\n if (value._tag === \"Gone\") gone = feed;\n // A frame captured before a silence probe can arrive after the probe's evidence.\n shownAt = Math.max(shownAt, value.at);\n\n return value.at === shownAt ? value : { ...value, at: shownAt };\n }),\n );\n }),\n );\n\nconst openFeed = (\n page: Page,\n owner: Scope.Scope,\n clock: Clock.Clock,\n settings: ScreencastOptions,\n current: () => Feed | undefined,\n publish: (feed: Feed, frame: Frame) => Effect.Effect<unknown>,\n) =>\n Effect.gen(function* () {\n const scope = yield* Scope.fork(owner);\n const started = yield* Deferred.make<void>();\n\n const feed: Feed = {\n page,\n scope,\n changed: yield* PubSub.sliding<Frame>({ capacity: 1, replay: 1 }),\n state: { _tag: \"Warming\" },\n fiber: undefined,\n };\n\n yield* Scope.addFinalizer(\n scope,\n Effect.sync(() => {\n update(feed, { _tag: \"Stop\" });\n }),\n );\n yield* Effect.addFinalizer(() => (current() === feed ? Effect.void : stop(feed)));\n\n const accept = (frame: Frame) =>\n Effect.suspend(() => {\n update(feed, { _tag: \"Paint\", frame });\n\n return (current() === feed ? publish(feed, frame) : Effect.void).pipe(\n Effect.andThen(PubSub.publish(feed.changed, frame)),\n );\n });\n\n const capture = Effect.scoped(\n Effect.gen(function* () {\n update(feed, { _tag: \"Reset\" });\n\n const internals = internalsOf(page);\n\n const { stream, current: frame } = yield* (\n internals?.capture(settings) ??\n Effect.succeed({ stream: page.screencast(settings), current: undefined })\n );\n\n if (frame !== undefined && internals?.current(frame)) yield* accept(frame);\n yield* Deferred.succeed(started, undefined);\n yield* Stream.runForEach(stream, accept);\n }),\n ).pipe(\n Effect.ensuring(Effect.sync(() => update(feed, { _tag: \"Reset\" }))),\n Effect.retry({\n while: (error) => feed.state._tag === \"Ready\" && restartable(error),\n schedule: Schedule.spaced(\"500 millis\"),\n }),\n );\n\n feed.fiber = yield* capture.pipe(\n Effect.provideService(Clock.Clock, clock),\n Effect.forkIn(scope),\n );\n yield* Effect.raceFirst(Deferred.await(started), ended(feed)).pipe(\n Effect.onError(() => stop(feed)),\n );\n\n return feed;\n });\n\nexport const make = Effect.fn(\"Stage.make\")(function* (\n options: Options = {},\n): Effect.fn.Return<Stage, BrowserError, Scope.Scope> {\n const clock = yield* Clock.Clock;\n const owner = yield* Effect.scope;\n const now = () => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;\n const waited = Duration.fromInput(options.firstFrame ?? Duration.seconds(5));\n\n if (\n Option.isNone(waited) ||\n !Duration.isFinite(waited.value) ||\n !Duration.isPositive(waited.value)\n )\n return yield* failWith(\n \"stage\",\n new InvalidRequest({ detail: \"firstFrame must be a finite positive duration\" }),\n );\n const firstFrame = waited.value;\n const settings = { quality: options.quality, size: options.size };\n const output = yield* PubSub.sliding<Paint>(16);\n const switching = ordered();\n\n let showing:\n | { readonly feed: Feed; readonly presented: Presented; frame: Frame; changedAt: number }\n | undefined;\n\n let painted = Number.NEGATIVE_INFINITY;\n\n yield* Effect.addFinalizer(() => PubSub.shutdown(output));\n\n const publish = (feed: Feed, frame: Frame, at = frame.hostTime) =>\n Effect.suspend(() => {\n painted = Math.max(painted, at);\n if (showing !== undefined) {\n showing.changedAt = now();\n showing.frame = frame;\n }\n\n return PubSub.publish(output, { feed, frame, at: painted });\n });\n\n const commit = (feed: Feed, options: { readonly at?: number | undefined } = {}) =>\n Effect.suspend(() => {\n const asked = options.at ?? now();\n\n return switching(\n Effect.gen(function* () {\n if (!Number.isFinite(asked))\n return yield* failWith(\n \"cue\",\n new InvalidRequest({ detail: \"at must be finite host milliseconds\" }),\n );\n yield* firstOf(feed, firstFrame);\n const old = showing;\n\n if (old?.feed === feed) return old.presented;\n\n yield* Effect.raceFirst(until(asked, now), ended(feed));\n\n const switchTo = Effect.suspend(() => {\n const frame = frameOf(feed);\n\n if (frame === undefined) return Effect.fail(unavailable());\n const at = Math.max(now(), asked, frame.hostTime, painted);\n\n showing = {\n feed,\n frame,\n presented: new Presented({ page: feed.page.id, at, latency: at - asked }),\n changedAt: at,\n };\n\n return publish(feed, frame, at).pipe(Effect.as(showing.presented));\n }).pipe(Effect.uninterruptible);\n\n const readyToSwitch = firstOf(feed, firstFrame).pipe(\n Effect.andThen(switchTo),\n Effect.provideService(Clock.Clock, clock),\n );\n\n const before = old === undefined ? undefined : internalsOf(old.feed.page);\n\n return yield* (\n before === undefined ? readyToSwitch : before.afterInput(readyToSwitch)\n ).pipe(\n // The cut owns old-page input through publication. Capture cleanup has its own bound\n // and must finish even if the caller leaves, without turning a completed cut into Timeout.\n Effect.ensuring(\n Effect.suspend(() =>\n showing?.feed === feed && old !== undefined ? stop(old.feed) : Effect.void,\n ),\n ),\n );\n }).pipe(Effect.provideService(Clock.Clock, clock)),\n );\n });\n\n const cue: Stage[\"cue\"] = (page) =>\n Effect.map(\n openFeed(page, owner, clock, settings, () => showing?.feed, publish),\n (feed) => ({\n page,\n ready: firstOf(feed, firstFrame).pipe(Effect.provideService(Clock.Clock, clock)),\n commit: (options) => commit(feed, options),\n }),\n );\n\n return {\n cue,\n present: (page, options) =>\n Effect.suspend(() => {\n const asked = options?.at ?? now();\n\n return showing?.feed.page === page\n ? Effect.as(firstOf(showing.feed, firstFrame), showing.presented)\n : Effect.scoped(Effect.flatMap(cue(page), (prepared) => prepared.commit({ at: asked })));\n }),\n shown: ({ hold }) =>\n evidence(output, () => showing, now, hold).pipe(Stream.provideService(Clock.Clock, clock)),\n frames: Stream.fromPubSub(output).pipe(Stream.map(({ frame }) => frame)),\n current: Effect.sync(() => Option.fromNullishOr(showing?.feed.page)),\n stats: (options = {}) =>\n showing === undefined\n ? Effect.succeedNone\n : Effect.asSome(showing.feed.page.captureStats({ window: options.window ?? \"1 second\" })),\n } satisfies Stage;\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoCA,IAAa,YAAb,cAA+B,OAAO,MAAiB,0BAA0B,CAAC,CAAC;CACjF,MAAM,OAAO;CACb,IAAI,OAAO;CACX,SAAS,OAAO;AAClB,CAAC,CAAC,CAAC,CAAC;AA0DJ,M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AAK,CAAC,CACnD;CACF,CAAC;CAEH,MAAM,OAAqB,SACzB,OAAO,IACL,SAAS,MAAM,OAAO,OAAO,gBAAgB,SAAS,MAAM,OAAO,IAClE,UAAU;EACT;EACA,OAAO,QAAQ,MAAM,UAAU,CAAC,CAAC,KAAK,OAAO,eAAe,MAAM,OAAO,KAAK,CAAC;EAC/E,SAAS,YAAY,OAAO,MAAM,OAAO;CAC3C,EACF;CAEF,OAAO;EACL;EACA,UAAU,MAAM,YACd,OAAO,cAAc;GACnB,MAAM,QAAQ,SAAS,MAAM,IAAI;GAEjC,OAAO,SAAS,KAAK,SAAS,OAC1B,OAAO,GAAG,QAAQ,QAAQ,MAAM,UAAU,GAAG,QAAQ,SAAS,IAC9D,OAAO,OAAO,OAAO,QAAQ,IAAI,IAAI,IAAI,aAAa,SAAS,OAAO,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC;EAC3F,CAAC;EACH,QAAQ,EAAE,WACR,SAAS,cAAc,SAAS,KAAK,IAAI,CAAC,CAAC,KAAK,OAAO,eAAe,MAAM,OAAO,KAAK,CAAC;EAC3F,QAAQ,OAAO,WAAW,MAAM,CAAC,CAAC,KAAK,OAAO,KAAK,EAAE,YAAY,KAAK,CAAC;EACvE,SAAS,OAAO,WAAW,OAAO,cAAc,SAAS,KAAK,IAAI,CAAC;EACnE,QAAQ,UAAU,CAAC,MACjB,YAAY,KAAA,IACR,OAAO,cACP,OAAO,OAAO,QAAQ,KAAK,KAAK,aAAa,EAAE,QAAQ,QAAQ,UAAU,WAAW,CAAC,CAAC;CAC9F;AACF,CAAC"}
1
+ {"version":3,"file":"Stage.mjs","names":[],"sources":["../src/Stage.ts"],"sourcesContent":["/**\n * An output's capture ownership. Cue a page while preparing an event; commit when that event\n * happens. A prepared cue belongs to its caller's scope, and a committed one to the stage.\n * Commits serialize, drain old-page input and refuse stale first frames. `shown` distinguishes\n * confirmed silence, uncertain silence and loss without treating capture silence as evidence.\n * @since 0.3.0\n */\nimport {\n Cause,\n Clock,\n Deferred,\n Duration,\n Effect,\n Exit,\n Fiber,\n Option,\n PubSub,\n Result,\n Schedule,\n Schema,\n Scope,\n Stream,\n} from \"effect\";\n\nimport { type BrowserError, Closed, consequence, InvalidRequest, Timeout } from \"./BrowserError.ts\";\nimport type { CaptureStats, Frame, ScreencastOptions } from \"./Frame.ts\";\nimport { failWith, refuse, undispatched } from \"./internal/page/context.ts\";\nimport { internalsOf } from \"./internal/page/page.ts\";\nimport { monotonicMillis } from \"./internal/pictures/clock.ts\";\nimport type { Page } from \"./Page.ts\";\n\nexport interface Options extends ScreencastOptions {\n /** Bound for each first-frame wait. Defaults to 5 seconds. */\n readonly firstFrame?: Duration.Input | undefined;\n}\n\n/** A switch that took effect, on the clock shared by browser events and frames. */\nexport class Presented extends Schema.Class<Presented>(\"effect-browser/Presented\")({\n page: Schema.String,\n at: Schema.Finite,\n latency: Schema.Finite,\n}) {}\n\nexport interface Cue {\n readonly page: Page;\n /** A frame of the current document, or the capture's failure or first-frame timeout. */\n readonly ready: Effect.Effect<void, BrowserError>;\n /** Commit on the event's host time, or now. Interruption before switching leaves the cue usable. */\n readonly commit: (options?: {\n readonly at?: number | undefined;\n }) => Effect.Effect<Presented, BrowserError>;\n}\n\n/** What the output establishes at nondecreasing host times; frames retain their capture times. */\nexport type Shown =\n | { readonly _tag: \"Painted\"; readonly frame: Frame; readonly at: number }\n | { readonly _tag: \"Still\"; readonly frame: Frame; readonly at: number }\n | { readonly _tag: \"Stalled\"; readonly frame: Frame; readonly at: number }\n | { readonly _tag: \"Gone\"; readonly page: string; readonly at: number };\n\nexport interface Stage {\n readonly present: (\n page: Page,\n options?: { readonly at?: number | undefined },\n ) => Effect.Effect<Presented, BrowserError>;\n readonly cue: (page: Page) => Effect.Effect<Cue, BrowserError, Scope.Scope>;\n /** Paint and, after every finite positive hold without paint, current evidence or loss. */\n readonly shown: (options: { readonly hold: Duration.Input }) => Stream.Stream<Shown>;\n /** Capture-timed current-page paint; use `shown` for output time. Readers retain 16 frames. */\n readonly frames: Stream.Stream<Frame>;\n readonly current: Effect.Effect<Option.Option<Page>>;\n readonly stats: (options?: {\n readonly window?: Duration.Input | undefined;\n }) => Effect.Effect<Option.Option<CaptureStats>, BrowserError>;\n}\n\ntype FeedState =\n | { readonly _tag: \"Warming\" }\n | { readonly _tag: \"Ready\"; readonly latest: Frame | undefined }\n | { readonly _tag: \"Stopped\" };\ninterface Feed {\n readonly page: Page;\n readonly scope: Scope.Closeable;\n readonly changed: PubSub.PubSub<Frame>;\n state: FeedState;\n fiber: Fiber.Fiber<void, BrowserError> | undefined;\n}\ninterface Paint {\n readonly feed: Feed;\n readonly frame: Frame;\n readonly at: number;\n}\n\ninterface Evidence {\n readonly feed: Feed;\n readonly frame: Frame;\n readonly value: Shown;\n}\n\nconst unavailable = () =>\n undispatched(\"cue\", new InvalidRequest({ detail: \"the cue's capture is no longer available\" }));\n\n/** The sole writer of a cue's capture lifecycle; presentation ownership belongs to the stage. */\nconst update = (\n feed: Feed,\n input: { readonly _tag: \"Paint\"; readonly frame: Frame } | { readonly _tag: \"Reset\" | \"Stop\" },\n) => {\n if (feed.state._tag === \"Stopped\") return;\n if (input._tag === \"Stop\") feed.state = { _tag: \"Stopped\" };\n else if (input._tag === \"Paint\") feed.state = { _tag: \"Ready\", latest: input.frame };\n else if (feed.state._tag === \"Ready\") feed.state = { _tag: \"Ready\", latest: undefined };\n};\n\nconst restartable = (error: BrowserError) => {\n const { lost, repeat } = consequence(error);\n\n return lost === \"nothing\" && repeat !== \"pointless\";\n};\n\nconst stop = (feed: Feed) =>\n Effect.suspend(() => {\n update(feed, { _tag: \"Stop\" });\n\n return Scope.close(feed.scope, Exit.void);\n });\n\nconst frameOf = (feed: Feed) => {\n const frame = feed.state._tag === \"Ready\" ? feed.state.latest : undefined;\n const internals = internalsOf(feed.page);\n\n return frame !== undefined && (internals === undefined || internals.current(frame))\n ? frame\n : undefined;\n};\n\nconst ended = (feed: Feed): Effect.Effect<never, BrowserError> =>\n feed.fiber === undefined\n ? Effect.never\n : Fiber.await(feed.fiber).pipe(\n Effect.flatMap((exit) =>\n Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)\n ? Effect.failCause(exit.cause)\n : Effect.fail(unavailable()),\n ),\n );\n\nconst firstOf = (feed: Feed, wait: Duration.Duration) =>\n Effect.suspend(() => {\n if (feed.state._tag === \"Stopped\") return Effect.fail(unavailable());\n if (feed.page.playwright.isClosed()) return failWith(\"cue\", new Closed({ cause: \"page\" }));\n if (frameOf(feed) !== undefined) return Effect.void;\n\n return Effect.raceFirst(\n Stream.fromPubSub(feed.changed).pipe(\n Stream.filter(() => frameOf(feed) !== undefined),\n Stream.runHead,\n Effect.asVoid,\n ),\n ended(feed),\n ).pipe(\n Effect.timeoutOrElse({\n duration: wait,\n orElse: () => failWith(\"cue\", new Timeout({ millis: Duration.toMillis(wait) })),\n }),\n );\n });\n\n// A timer can wake a fraction early; a commit never precedes its event.\nconst until = (at: number, now: () => number): Effect.Effect<void> =>\n Effect.suspend(() =>\n at > now()\n ? Effect.sleep(Duration.millis(Math.ceil(at - now()))).pipe(Effect.andThen(until(at, now)))\n : Effect.void,\n );\n\n/** Reserve the next turn before waking it; a fresh caller cannot overtake a queued commit. */\nconst ordered = () => {\n const waiting: Array<Deferred.Deferred<void>> = [];\n\n return <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n Effect.acquireUseRelease(\n Effect.sync(() => {\n const turn = Deferred.makeUnsafe<void>();\n\n waiting.push(turn);\n if (waiting.length === 1) Deferred.doneUnsafe(turn, Exit.void);\n\n return turn;\n }),\n (turn) => Deferred.await(turn).pipe(Effect.andThen(effect)),\n (turn) =>\n Effect.sync(() => {\n const at = waiting.indexOf(turn);\n\n waiting.splice(at, 1);\n if (at === 0 && waiting[0] !== undefined) Deferred.doneUnsafe(waiting[0], Exit.void);\n }),\n );\n};\n\n/** A terminal capture can know the connection is gone before the page receives its close event. */\nconst confirm = (feed: Feed, frame: Frame) => {\n const exit = feed.fiber?.pollUnsafe();\n\n const failure =\n exit !== undefined && Exit.isFailure(exit) ? Cause.findErrorOption(exit.cause) : Option.none();\n\n if (Option.isSome(failure) && consequence(failure.value).lost !== \"nothing\")\n return Effect.fail(failure.value);\n\n return feed.page.playwright.isClosed()\n ? failWith(\"shown\", new Closed({ cause: \"page\" }))\n : (internalsOf(feed.page)?.confirm(frame) ?? Effect.succeed(false));\n};\n\n/** Each subscriber confirms silence; a new frame or commit invalidates a probe. */\nconst evidence = (\n output: PubSub.PubSub<Paint>,\n current: () =>\n | { readonly feed: Feed; readonly frame: Frame; readonly changedAt: number }\n | undefined,\n now: () => number,\n hold: Duration.Input,\n): Stream.Stream<Shown> =>\n Stream.unwrap(\n Effect.sync(() => {\n const parsed = Duration.fromInput(hold);\n\n if (\n Option.isNone(parsed) ||\n !Duration.isFinite(parsed.value) ||\n !Duration.isPositive(parsed.value)\n )\n throw new RangeError(\"shown hold must be a finite positive duration\");\n const millis = Duration.toMillis(parsed.value);\n let checkedAt = now();\n let shownAt = Number.NEGATIVE_INFINITY;\n let seen: Pick<Paint, \"feed\" | \"frame\"> | undefined = current();\n let gone: Feed | undefined;\n\n const probe = Effect.gen(function* () {\n yield* until(Math.max(checkedAt, current()?.changedAt ?? checkedAt) + millis, now);\n const before = current();\n const frame = before?.frame;\n\n // Paint during the wait moves the deadline; an early wake is not a silence check.\n if (before !== undefined && now() - before.changedAt < millis)\n return Option.none<Evidence>();\n checkedAt = now();\n if (before === undefined || frame === undefined || gone === before.feed)\n return Option.none<Evidence>();\n const { feed } = before;\n\n const confirmed = yield* Effect.result(confirm(feed, frame));\n\n if (current()?.feed !== feed || current()?.frame !== frame) return Option.none<Evidence>();\n const at = now();\n\n checkedAt = at;\n if (Result.isFailure(confirmed) && consequence(confirmed.failure).lost !== \"nothing\") {\n return Option.some<Evidence>({\n feed,\n frame,\n value: { _tag: \"Gone\", page: feed.page.id, at },\n });\n }\n\n return Option.some<Evidence>({\n feed,\n frame,\n value: {\n _tag: Result.isSuccess(confirmed) && confirmed.success ? \"Still\" : \"Stalled\",\n frame,\n at,\n },\n });\n });\n\n return Stream.merge(\n Stream.fromPubSub(output).pipe(\n Stream.map(({ feed, frame, at }): Evidence => ({\n feed,\n frame,\n value: { _tag: \"Painted\", frame, at },\n })),\n ),\n Stream.fromEffectRepeat(probe).pipe(\n Stream.filter(Option.isSome),\n Stream.map(({ value }) => value),\n ),\n ).pipe(\n // A probe can overtake queued paint while its reader is paused. It establishes nothing\n // about that reader's output until the matching frame has reached it.\n Stream.filter(({ feed, frame, value }) => {\n if (value._tag === \"Painted\" && gone !== feed) {\n seen = { feed, frame };\n\n return true;\n }\n // The subscription may have begun after its first publication.\n seen ??= { feed, frame };\n\n return value._tag !== \"Painted\" && seen?.feed === feed && seen.frame === frame;\n }),\n Stream.map(({ feed, value }) => {\n if (value._tag === \"Gone\") gone = feed;\n // A frame captured before a silence probe can arrive after the probe's evidence.\n shownAt = Math.max(shownAt, value.at);\n\n return value.at === shownAt ? value : { ...value, at: shownAt };\n }),\n );\n }),\n );\n\nconst openFeed = (\n page: Page,\n owner: Scope.Scope,\n clock: Clock.Clock,\n settings: ScreencastOptions,\n current: () => Feed | undefined,\n publish: (feed: Feed, frame: Frame) => Effect.Effect<unknown>,\n) =>\n Effect.gen(function* () {\n const scope = yield* Scope.fork(owner);\n const started = yield* Deferred.make<void>();\n\n const feed: Feed = {\n page,\n scope,\n changed: yield* PubSub.sliding<Frame>({ capacity: 1, replay: 1 }),\n state: { _tag: \"Warming\" },\n fiber: undefined,\n };\n\n yield* Scope.addFinalizer(\n scope,\n Effect.sync(() => {\n update(feed, { _tag: \"Stop\" });\n }),\n );\n yield* Effect.addFinalizer(() => (current() === feed ? Effect.void : stop(feed)));\n\n const accept = (frame: Frame) =>\n Effect.suspend(() => {\n update(feed, { _tag: \"Paint\", frame });\n\n return (current() === feed ? publish(feed, frame) : Effect.void).pipe(\n Effect.andThen(PubSub.publish(feed.changed, frame)),\n );\n });\n\n const capture = Effect.scoped(\n Effect.gen(function* () {\n update(feed, { _tag: \"Reset\" });\n\n const internals = internalsOf(page);\n\n const { stream, current: frame } = yield* (\n internals?.capture(settings) ??\n Effect.succeed({ stream: page.screencast(settings), current: undefined })\n );\n\n if (frame !== undefined && internals?.current(frame)) yield* accept(frame);\n yield* Deferred.succeed(started, undefined);\n yield* Stream.runForEach(stream, accept);\n }),\n ).pipe(\n Effect.ensuring(Effect.sync(() => update(feed, { _tag: \"Reset\" }))),\n Effect.retry({\n while: (error) => feed.state._tag === \"Ready\" && restartable(error),\n schedule: Schedule.spaced(\"500 millis\"),\n }),\n );\n\n feed.fiber = yield* capture.pipe(\n Effect.provideService(Clock.Clock, clock),\n Effect.forkIn(scope),\n );\n yield* Effect.raceFirst(Deferred.await(started), ended(feed)).pipe(\n Effect.onError(() => stop(feed)),\n );\n\n return feed;\n });\n\nexport const make = Effect.fn(\"Stage.make\")(function* (\n options: Options = {},\n): Effect.fn.Return<Stage, BrowserError, Scope.Scope> {\n const clock = yield* Clock.Clock;\n const owner = yield* Effect.scope;\n const now = () => monotonicMillis(clock);\n const waited = Duration.fromInput(options.firstFrame ?? Duration.seconds(5));\n\n if (\n Option.isNone(waited) ||\n !Duration.isFinite(waited.value) ||\n !Duration.isPositive(waited.value)\n )\n return yield* refuse(\"stage\", \"firstFrame must be a finite positive duration\");\n const firstFrame = waited.value;\n const settings = { quality: options.quality, size: options.size };\n const output = yield* PubSub.sliding<Paint>(16);\n const switching = ordered();\n\n let showing:\n | { readonly feed: Feed; readonly presented: Presented; frame: Frame; changedAt: number }\n | undefined;\n\n let painted = Number.NEGATIVE_INFINITY;\n\n yield* Effect.addFinalizer(() => PubSub.shutdown(output));\n\n const publish = (feed: Feed, frame: Frame, at = frame.hostTime) =>\n Effect.suspend(() => {\n painted = Math.max(painted, at);\n if (showing !== undefined) {\n showing.changedAt = now();\n showing.frame = frame;\n }\n\n return PubSub.publish(output, { feed, frame, at: painted });\n });\n\n const commit = (feed: Feed, options: { readonly at?: number | undefined } = {}) =>\n Effect.suspend(() => {\n const asked = options.at ?? now();\n\n return switching(\n Effect.gen(function* () {\n if (!Number.isFinite(asked))\n return yield* refuse(\"cue\", \"at must be finite host milliseconds\");\n yield* firstOf(feed, firstFrame);\n const old = showing;\n\n if (old?.feed === feed) return old.presented;\n\n yield* Effect.raceFirst(until(asked, now), ended(feed));\n\n const switchTo = Effect.suspend(() => {\n const frame = frameOf(feed);\n\n if (frame === undefined) return Effect.fail(unavailable());\n const at = Math.max(now(), asked, frame.hostTime, painted);\n\n showing = {\n feed,\n frame,\n presented: new Presented({ page: feed.page.id, at, latency: at - asked }),\n changedAt: at,\n };\n\n return publish(feed, frame, at).pipe(Effect.as(showing.presented));\n }).pipe(Effect.uninterruptible);\n\n const readyToSwitch = firstOf(feed, firstFrame).pipe(\n Effect.andThen(switchTo),\n Effect.provideService(Clock.Clock, clock),\n );\n\n const before = old === undefined ? undefined : internalsOf(old.feed.page);\n\n return yield* (\n before === undefined ? readyToSwitch : before.afterInput(readyToSwitch)\n ).pipe(\n // The cut owns old-page input through publication. Capture cleanup has its own bound\n // and must finish even if the caller leaves, without turning a completed cut into Timeout.\n Effect.ensuring(\n Effect.suspend(() =>\n showing?.feed === feed && old !== undefined ? stop(old.feed) : Effect.void,\n ),\n ),\n );\n }).pipe(Effect.provideService(Clock.Clock, clock)),\n );\n });\n\n const cue: Stage[\"cue\"] = (page) =>\n Effect.map(\n openFeed(page, owner, clock, settings, () => showing?.feed, publish),\n (feed) => ({\n page,\n ready: firstOf(feed, firstFrame).pipe(Effect.provideService(Clock.Clock, clock)),\n commit: (options) => commit(feed, options),\n }),\n );\n\n return {\n cue,\n present: (page, options) =>\n Effect.suspend(() => {\n const asked = options?.at ?? now();\n\n return showing?.feed.page === page\n ? Effect.as(firstOf(showing.feed, firstFrame), showing.presented)\n : Effect.scoped(Effect.flatMap(cue(page), (prepared) => prepared.commit({ at: asked })));\n }),\n shown: ({ hold }) =>\n evidence(output, () => showing, now, hold).pipe(Stream.provideService(Clock.Clock, clock)),\n frames: Stream.fromPubSub(output).pipe(Stream.map(({ frame }) => frame)),\n current: Effect.sync(() => Option.fromNullishOr(showing?.feed.page)),\n stats: (options = {}) =>\n showing === undefined\n ? Effect.succeedNone\n : Effect.asSome(showing.feed.page.captureStats({ window: options.window ?? \"1 second\" })),\n } satisfies Stage;\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqCA,IAAa,YAAb,cAA+B,OAAO,MAAiB,0BAA0B,CAAC,CAAC;CACjF,MAAM,OAAO;CACb,IAAI,OAAO;CACX,SAAS,OAAO;AAClB,CAAC,CAAC,CAAC,CAAC;AA0DJ,MAAM,oBACJ,aAAa,OAAO,IAAI,eAAe,EAAE,QAAQ,2CAA2C,CAAC,CAAC;;AAGhG,MAAM,UACJ,MACA,UACG;CACH,IAAI,KAAK,MAAM,SAAS,WAAW;CACnC,IAAI,MAAM,SAAS,QAAQ,KAAK,QAAQ,EAAE,MAAM,UAAU;MACrD,IAAI,MAAM,SAAS,SAAS,KAAK,QAAQ;EAAE,MAAM;EAAS,QAAQ,MAAM;CAAM;MAC9E,IAAI,KAAK,MAAM,SAAS,SAAS,KAAK,QAAQ;EAAE,MAAM;EAAS,QAAQ,KAAA;CAAU;AACxF;AAEA,MAAM,eAAe,UAAwB;CAC3C,MAAM,EAAE,MAAM,WAAW,YAAY,KAAK;CAE1C,OAAO,SAAS,aAAa,WAAW;AAC1C;AAEA,MAAM,QAAQ,SACZ,OAAO,cAAc;CACnB,OAAO,MAAM,EAAE,MAAM,OAAO,CAAC;CAE7B,OAAO,MAAM,MAAM,KAAK,OAAO,KAAK,IAAI;AAC1C,CAAC;AAEH,MAAM,WAAW,SAAe;CAC9B,MAAM,QAAQ,KAAK,MAAM,SAAS,UAAU,KAAK,MAAM,SAAS,KAAA;CAChE,MAAM,YAAY,YAAY,KAAK,IAAI;CAEvC,OAAO,UAAU,KAAA,MAAc,cAAc,KAAA,KAAa,UAAU,QAAQ,KAAK,KAC7E,QACA,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