effect-browser 0.3.0-beta.21 → 0.3.0-beta.23

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 (249) hide show
  1. package/README.md +130 -159
  2. package/dist/Action-24sLOubi.d.mts +110 -0
  3. package/dist/Action.d.mts +2 -0
  4. package/dist/Action.mjs +141 -0
  5. package/dist/Action.mjs.map +1 -0
  6. package/dist/ActionPort.d.mts +15 -0
  7. package/dist/ActionPort.mjs +101 -0
  8. package/dist/ActionPort.mjs.map +1 -0
  9. package/dist/Browser-BKPAbyys.mjs +4076 -0
  10. package/dist/Browser-BKPAbyys.mjs.map +1 -0
  11. package/dist/{Browser-CiXHT1yO.d.mts → Browser-wZhwZSlG.d.mts} +51 -13
  12. package/dist/Browser.d.mts +2 -2
  13. package/dist/Browser.mjs +1 -1
  14. package/dist/{BrowserError-Coy7EW1N.d.mts → BrowserError-BlcmLVzn.d.mts} +22 -7
  15. package/dist/BrowserError.d.mts +2 -2
  16. package/dist/BrowserError.mjs +46 -9
  17. package/dist/BrowserError.mjs.map +1 -1
  18. package/dist/{BrowserEvent-dq6FRT8w.d.mts → BrowserEvent-lLqJ3GJS.d.mts} +93 -37
  19. package/dist/BrowserEvent.d.mts +2 -2
  20. package/dist/BrowserEvent.mjs +29 -24
  21. package/dist/BrowserEvent.mjs.map +1 -1
  22. package/dist/{Change-DqING3tr.d.mts → Change-Ba7INmay.d.mts} +4 -6
  23. package/dist/Change.d.mts +2 -2
  24. package/dist/Change.mjs +97 -2
  25. package/dist/Change.mjs.map +1 -0
  26. package/dist/Clock.d.mts +57 -0
  27. package/dist/Clock.mjs +80 -0
  28. package/dist/Clock.mjs.map +1 -0
  29. package/dist/{Frame-DkNdjjjr.d.mts → Frame-UEH2hO5T.d.mts} +10 -3
  30. package/dist/Frame.d.mts +2 -2
  31. package/dist/Frame.mjs +10 -2
  32. package/dist/Frame.mjs.map +1 -1
  33. package/dist/{Motion-DND6I-64.d.mts → Geometry-DJx9qrYy.d.mts} +7 -10
  34. package/dist/Geometry.d.mts +2 -0
  35. package/dist/Geometry.mjs +32 -0
  36. package/dist/Geometry.mjs.map +1 -0
  37. package/dist/Matching.d.mts +37 -0
  38. package/dist/Matching.mjs +72 -0
  39. package/dist/Matching.mjs.map +1 -0
  40. package/dist/Page-BF5izr8R.mjs +795 -0
  41. package/dist/Page-BF5izr8R.mjs.map +1 -0
  42. package/dist/{Page-ku6j5t-v.d.mts → Page-CvsOEorc.d.mts} +158 -185
  43. package/dist/Page.d.mts +2 -2
  44. package/dist/Page.mjs +1 -1
  45. package/dist/Released-tURbFmal.d.mts +15 -0
  46. package/dist/{Snapshot-B34hZ4Jl.d.mts → Snapshot-CtBVOtuu.d.mts} +6 -1
  47. package/dist/Snapshot.d.mts +1 -1
  48. package/dist/Snapshot.mjs.map +1 -1
  49. package/dist/Stillness-CNlvayIo.mjs +136 -0
  50. package/dist/Stillness-CNlvayIo.mjs.map +1 -0
  51. package/dist/Style-AO4V7Czt.mjs +357 -0
  52. package/dist/Style-AO4V7Czt.mjs.map +1 -0
  53. package/dist/Style.d.mts +72 -0
  54. package/dist/Style.mjs +2 -0
  55. package/dist/Url.d.mts +26 -0
  56. package/dist/Url.mjs +74 -0
  57. package/dist/Url.mjs.map +1 -0
  58. package/dist/Window-CMddGMt1.d.mts +34 -0
  59. package/dist/Window.d.mts +2 -0
  60. package/dist/Window.mjs +35 -0
  61. package/dist/Window.mjs.map +1 -0
  62. package/dist/{cdp-DL7XfEj5.d.mts → connection-2KHI4_KN.d.mts} +4 -4
  63. package/dist/{cdp-BMpYMWYe.mjs → connection-CK83pvqP.mjs} +5 -6
  64. package/dist/connection-CK83pvqP.mjs.map +1 -0
  65. package/dist/index.d.mts +15 -18
  66. package/dist/index.mjs +11 -15
  67. package/dist/moment/Moment.d.mts +86 -0
  68. package/dist/{Moment.mjs → moment/Moment.mjs} +44 -38
  69. package/dist/moment/Moment.mjs.map +1 -0
  70. package/dist/{Plan-DJ4hEEna.d.mts → plan/index.d.mts} +169 -64
  71. package/dist/{Plan-BG1WifW2.mjs → plan/index.mjs} +122 -199
  72. package/dist/plan/index.mjs.map +1 -0
  73. package/dist/{Policy-BGWjbqCl.d.mts → policy/Policy.d.mts} +16 -20
  74. package/dist/{Policy.mjs → policy/Policy.mjs} +11 -21
  75. package/dist/policy/Policy.mjs.map +1 -0
  76. package/dist/presentation/Motion.d.mts +12 -0
  77. package/dist/{Motion.mjs → presentation/Motion.mjs} +4 -27
  78. package/dist/presentation/Motion.mjs.map +1 -0
  79. package/dist/presentation/Presentation.d.mts +30 -0
  80. package/dist/presentation/Presentation.mjs +105 -0
  81. package/dist/presentation/Presentation.mjs.map +1 -0
  82. package/dist/{Stage-NHp8N81k.d.mts → presentation/Stage.d.mts} +12 -15
  83. package/dist/{Stage.mjs → presentation/Stage.mjs} +68 -76
  84. package/dist/presentation/Stage.mjs.map +1 -0
  85. package/dist/presentation/feed.d.mts +20 -0
  86. package/dist/presentation/feed.mjs +18 -0
  87. package/dist/presentation/feed.mjs.map +1 -0
  88. package/dist/providers/Cdp.d.mts +9 -0
  89. package/dist/{Cdp.mjs → providers/Cdp.mjs} +3 -8
  90. package/dist/providers/Cdp.mjs.map +1 -0
  91. package/dist/{Chromium.d.mts → providers/Chromium.d.mts} +6 -7
  92. package/dist/{Chromium.mjs → providers/Chromium.mjs} +6 -15
  93. package/dist/providers/Chromium.mjs.map +1 -0
  94. package/dist/providers/Released.d.mts +2 -0
  95. package/dist/providers/Released.mjs +12 -0
  96. package/dist/providers/Released.mjs.map +1 -0
  97. package/dist/stillness/Stillness.d.mts +12 -0
  98. package/dist/stillness/Stillness.mjs +2 -0
  99. package/dist/supervisor/Supervisor.d.mts +104 -0
  100. package/dist/supervisor/Supervisor.mjs +515 -0
  101. package/dist/supervisor/Supervisor.mjs.map +1 -0
  102. package/dist/testing/index.d.mts +337 -0
  103. package/dist/testing/index.mjs +515 -0
  104. package/dist/testing/index.mjs.map +1 -0
  105. package/dist/workerd/Cdp.d.mts +8 -3
  106. package/dist/workerd/Cdp.mjs +2 -7
  107. package/dist/workerd/Cdp.mjs.map +1 -1
  108. package/package.json +89 -39
  109. package/src/Action.ts +127 -0
  110. package/src/ActionPort.ts +128 -0
  111. package/src/Browser.ts +352 -201
  112. package/src/BrowserError.ts +63 -6
  113. package/src/BrowserEvent.ts +26 -25
  114. package/src/Change.ts +0 -2
  115. package/src/{internal/pictures/clock.ts → Clock.ts} +17 -6
  116. package/src/Frame.ts +14 -0
  117. package/src/Geometry.ts +48 -0
  118. package/src/{internal/reading/match.inpage.ts → Matching.ts} +34 -4
  119. package/src/Page.ts +111 -92
  120. package/src/Snapshot.ts +5 -0
  121. package/src/{internal/input/style.ts → Style.ts} +121 -14
  122. package/src/Window.ts +30 -0
  123. package/src/index.ts +15 -6
  124. package/src/internal/input/actions.ts +61 -119
  125. package/src/internal/input/dispatch.ts +3 -3
  126. package/src/internal/input/gate.ts +21 -18
  127. package/src/internal/input/guard.inpage.ts +25 -58
  128. package/src/internal/input/guard.ts +11 -20
  129. package/src/internal/input/keyboard.ts +12 -3
  130. package/src/internal/input/perform.ts +78 -60
  131. package/src/internal/input/pointer.ts +4 -2
  132. package/src/internal/input/settle.ts +7 -5
  133. package/src/internal/input/targets.inpage.ts +1 -1
  134. package/src/internal/input/targets.ts +4 -9
  135. package/src/internal/page/bridge.ts +209 -113
  136. package/src/internal/page/context.ts +12 -59
  137. package/src/internal/page/dialogs.ts +58 -0
  138. package/src/internal/page/identity.ts +6 -5
  139. package/src/internal/page/lane.ts +14 -15
  140. package/src/internal/page/navigation.ts +50 -42
  141. package/src/internal/page/openings.ts +11 -5
  142. package/src/internal/page/page.ts +44 -81
  143. package/src/internal/page/port.ts +125 -0
  144. package/src/internal/{input → page}/replies.ts +1 -1
  145. package/src/internal/page/request-owner.ts +269 -0
  146. package/src/internal/page/requests.ts +357 -0
  147. package/src/internal/page/scripts.ts +124 -0
  148. package/src/internal/pictures/capture.ts +255 -332
  149. package/src/internal/pictures/dimensions.ts +162 -0
  150. package/src/internal/pictures/frame.ts +68 -0
  151. package/src/internal/pictures/pictures.ts +57 -23
  152. package/src/internal/pictures/quiescence.ts +1 -1
  153. package/src/internal/pictures/state.ts +26 -0
  154. package/src/internal/pictures/transport.ts +21 -4
  155. package/src/internal/reading/controls.inpage.ts +5 -70
  156. package/src/internal/reading/expect.inpage.ts +13 -17
  157. package/src/internal/reading/names.inpage.ts +89 -45
  158. package/src/internal/reading/outline.inpage.ts +6 -7
  159. package/src/internal/reading/reading.ts +144 -176
  160. package/src/internal/reading/ready.inpage.ts +6 -17
  161. package/src/internal/reading/ready.ts +13 -135
  162. package/src/internal/reading/subjects.inpage.ts +83 -43
  163. package/src/internal/reading/walk.inpage.ts +33 -13
  164. package/src/internal/timeline/changes.ts +55 -6
  165. package/src/internal/timeline/events.ts +15 -5
  166. package/src/internal/timeline/history.inpage.ts +1 -1
  167. package/src/internal/timeline/record.inpage.ts +4 -1
  168. package/src/internal/timeline/window.ts +2 -1
  169. package/src/{Moment.ts → moment/Moment.ts} +13 -31
  170. package/src/{internal/timeline → moment}/words.ts +2 -2
  171. package/src/{internal/reading → plan}/choose.ts +3 -3
  172. package/src/plan/data.ts +117 -0
  173. package/src/plan/execute.ts +411 -0
  174. package/src/plan/index.ts +36 -0
  175. package/src/plan/record.ts +71 -0
  176. package/src/plan/targets.ts +71 -0
  177. package/src/{Policy.ts → policy/Policy.ts} +13 -10
  178. package/src/{Motion.ts → presentation/Motion.ts} +12 -46
  179. package/src/presentation/Presentation.ts +176 -0
  180. package/src/{Stage.ts → presentation/Stage.ts} +147 -112
  181. package/src/presentation/feed.ts +21 -0
  182. package/src/{Cdp.ts → providers/Cdp.ts} +2 -2
  183. package/src/{Chromium.ts → providers/Chromium.ts} +7 -10
  184. package/src/providers/Released.ts +13 -0
  185. package/src/{internal/cdp.ts → providers/connection.ts} +2 -2
  186. package/src/{internal/pictures/motion.ts → stillness/Pixels.ts} +1 -1
  187. package/src/stillness/Stillness.ts +166 -0
  188. package/src/supervisor/Supervisor.ts +170 -0
  189. package/src/supervisor/contract.ts +105 -0
  190. package/src/supervisor/lifecycle.ts +272 -0
  191. package/src/supervisor/runtime.ts +238 -0
  192. package/src/testing/TestBrowser.ts +115 -0
  193. package/src/testing/TestPage.ts +10 -0
  194. package/src/testing/evidence.ts +154 -0
  195. package/src/testing/index.ts +3 -0
  196. package/src/testing/model.ts +222 -0
  197. package/src/testing/page.ts +360 -0
  198. package/src/workerd/Cdp.ts +2 -2
  199. package/dist/Browser-CxXUjxOp.mjs +0 -619
  200. package/dist/Browser-CxXUjxOp.mjs.map +0 -1
  201. package/dist/Cdp-CzCRnMlM.d.mts +0 -10
  202. package/dist/Cdp.d.mts +0 -11
  203. package/dist/Cdp.mjs.map +0 -1
  204. package/dist/Change-DNvztNLu.mjs +0 -138
  205. package/dist/Change-DNvztNLu.mjs.map +0 -1
  206. package/dist/Chromium.mjs.map +0 -1
  207. package/dist/Expect-u3P_ENLX.d.mts +0 -62
  208. package/dist/Expect.d.mts +0 -2
  209. package/dist/Expect.mjs +0 -114
  210. package/dist/Expect.mjs.map +0 -1
  211. package/dist/Moment.d.mts +0 -2
  212. package/dist/Moment.mjs.map +0 -1
  213. package/dist/Motion.d.mts +0 -2
  214. package/dist/Motion.mjs.map +0 -1
  215. package/dist/Page-BP02bmNv.mjs +0 -264
  216. package/dist/Page-BP02bmNv.mjs.map +0 -1
  217. package/dist/Plan-BG1WifW2.mjs.map +0 -1
  218. package/dist/Plan.d.mts +0 -2
  219. package/dist/Plan.mjs +0 -2
  220. package/dist/Policy.d.mts +0 -2
  221. package/dist/Policy.mjs.map +0 -1
  222. package/dist/Presentation-DxVikn9_.d.mts +0 -48
  223. package/dist/Presentation.d.mts +0 -2
  224. package/dist/Presentation.mjs +0 -118
  225. package/dist/Presentation.mjs.map +0 -1
  226. package/dist/Stage.d.mts +0 -2
  227. package/dist/Stage.mjs.map +0 -1
  228. package/dist/Supervisor-2mPjIYYs.mjs +0 -676
  229. package/dist/Supervisor-2mPjIYYs.mjs.map +0 -1
  230. package/dist/Supervisor-CfRxbaso.d.mts +0 -317
  231. package/dist/Supervisor.d.mts +0 -2
  232. package/dist/Supervisor.mjs +0 -2
  233. package/dist/cdp-BMpYMWYe.mjs.map +0 -1
  234. package/dist/context-EGhOqjNN.mjs +0 -335
  235. package/dist/context-EGhOqjNN.mjs.map +0 -1
  236. package/dist/page-PTM8m5wC.mjs +0 -4057
  237. package/dist/page-PTM8m5wC.mjs.map +0 -1
  238. package/dist/url-Bsp2y55M.mjs +0 -264
  239. package/dist/url-Bsp2y55M.mjs.map +0 -1
  240. package/dist/workerd/index.d.mts +0 -16
  241. package/dist/workerd/index.mjs +0 -17
  242. package/src/Expect.ts +0 -180
  243. package/src/Plan.ts +0 -674
  244. package/src/Presentation.ts +0 -196
  245. package/src/Supervisor.ts +0 -632
  246. package/src/internal/supervisor/lifecycle.ts +0 -484
  247. package/src/workerd/index.ts +0 -17
  248. /package/src/{internal/page/url.ts → Url.ts} +0 -0
  249. /package/src/{internal/pictures → stillness}/utilsBundle.d.ts +0 -0
@@ -5,11 +5,12 @@
5
5
  */
6
6
  import { Effect } from "effect";
7
7
 
8
+ import { recorded, nameOf, type Action } from "../../Action.ts";
8
9
  import { type BrowserError, InvalidRequest, NotActionable, StaleRef } from "../../BrowserError.ts";
9
- import { InputRequest, redacted } from "../../Page.ts";
10
+ import { InputRequest } from "../../Page.ts";
11
+ import * as Url from "../../Url.ts";
10
12
  import { type Bridge, scriptCall } from "../page/bridge.ts";
11
- import { contextGone, decodeWith, failWith, type PageContext, refuse } from "../page/context.ts";
12
- import * as Url from "../page/url.ts";
13
+ import { contextGone, decodeWith, failWith, type PageContext } from "../page/context.ts";
13
14
  import * as Script from "./guard.inpage.ts";
14
15
 
15
16
  export interface Approval {
@@ -62,7 +63,7 @@ export const make = (page: PageContext, bridge: Bridge) => {
62
63
  const { current, evaluateIn, evaluateWithContext } = bridge;
63
64
 
64
65
  const preparePolicy = (
65
- action: string,
66
+ asked: Action,
66
67
  info: { readonly target?: string | undefined; readonly text?: string | undefined },
67
68
  targets: Script.InputPlan["targets"],
68
69
  flags: {
@@ -72,16 +73,7 @@ export const make = (page: PageContext, bridge: Bridge) => {
72
73
  } = {},
73
74
  ): Effect.Effect<PolicyPlan, BrowserError> =>
74
75
  Effect.gen(function* () {
75
- for (const target of targets) {
76
- if (typeof target === "string" && !/^e\d+$/.test(target))
77
- return yield* refuse(action, `"${target}" is not a ref; refs look like e12`);
78
- if (
79
- target !== null &&
80
- typeof target !== "string" &&
81
- (!Number.isFinite(target.x) || !Number.isFinite(target.y))
82
- )
83
- return yield* refuse(action, "point coordinates must be finite");
84
- }
76
+ const action = nameOf(asked);
85
77
 
86
78
  const input: Script.InputPlan = {
87
79
  action,
@@ -103,17 +95,16 @@ export const make = (page: PageContext, bridge: Bridge) => {
103
95
  const target = targets[0];
104
96
  const { title, description, dialog, heading, nearby, form } = prepared.evidence;
105
97
 
98
+ const safe = recorded(asked, first?.secret !== true);
99
+
106
100
  // A guard may hand the request to a judge's model, so its addresses keep no secrets.
107
101
  const request = new InputRequest({
108
102
  page: id,
109
103
  url: Url.redact(prepared.url),
110
104
  title,
111
- action,
105
+ action: safe,
112
106
  target: info.target,
113
- text:
114
- info.text !== undefined && action === "type" && first?.secret === true
115
- ? redacted
116
- : info.text,
107
+ text: safe._tag === "Type" ? safe.text : info.text,
117
108
  element: first?.element,
118
109
  role: first?.role,
119
110
  name: first?.name,
@@ -124,7 +115,7 @@ export const make = (page: PageContext, bridge: Bridge) => {
124
115
  prepared.destination === undefined ? undefined : Url.redact(prepared.destination),
125
116
  facts: prepared.facts,
126
117
  context: { dialog, heading, nearby },
127
- form,
118
+ form: form === undefined ? undefined : { ...form, action: Url.redact(form.action) },
128
119
  });
129
120
 
130
121
  const check = (options: Script.ValidationOptions = {}) =>
@@ -7,12 +7,21 @@ import { Duration, Effect } from "effect";
7
7
  import { NotActionable } from "../../BrowserError.ts";
8
8
  import type { Bridge } from "../page/bridge.ts";
9
9
  import { failWith, type PageContext } from "../page/context.ts";
10
+ import type * as Replies from "../page/replies.ts";
10
11
  import type { Dispatch } from "./dispatch.ts";
11
12
  import * as Keys from "./keys.ts";
12
- import type * as Replies from "./replies.ts";
13
13
 
14
14
  export const make = (page: PageContext, bridge: Bridge, dispatch: Dispatch) => {
15
15
  const { playwright } = page;
16
+
17
+ const key = (direction: "down" | "up", part: string) => {
18
+ const run = () => playwright.keyboard[direction](part);
19
+
20
+ return page.nativePort === undefined
21
+ ? run()
22
+ : page.nativePort(page.id, `keyboard.${direction}`, { key: part }, run);
23
+ };
24
+
16
25
  const { send } = page.protocol;
17
26
  const { currentDocument } = bridge;
18
27
  const { stamp, inputCall, dispatchKey, dispatchText } = dispatch;
@@ -47,8 +56,8 @@ export const make = (page: PageContext, bridge: Bridge, dispatch: Dispatch) => {
47
56
  operation,
48
57
  run.down(
49
58
  `playwright:${part}`,
50
- () => dispatchKey(part, "down", () => playwright.keyboard.down(part), run),
51
- () => dispatchKey(part, "up", () => playwright.keyboard.up(part), run),
59
+ () => dispatchKey(part, "down", () => key("down", part), run),
60
+ () => dispatchKey(part, "up", () => key("up", part), run),
52
61
  ),
53
62
  );
54
63
  if (holdMillis > 0) yield* Effect.sleep(Duration.millis(holdMillis));
@@ -4,17 +4,18 @@
4
4
  */
5
5
  import { Deferred, Duration, Effect, Exit, Option, Ref } from "effect";
6
6
 
7
+ import { recorded, nameOf, type Action as ActionValue } from "../../Action.ts";
7
8
  import { BrowserError, PolicyTimeout, Timeout } from "../../BrowserError.ts";
8
- import { Action, type ActionOptions, Subject } from "../../BrowserEvent.ts";
9
+ import { Action, Subject } from "../../BrowserEvent.ts";
10
+ import type * as BrowserClock from "../../Clock.ts";
9
11
  import { type Point, redacted, type ResolvedTarget } from "../../Page.ts";
12
+ import { Current, type Style, validated } from "../../Style.ts";
13
+ import { redact } from "../../Url.ts";
10
14
  import { failWith, type PageContext, undispatched } from "../page/context.ts";
11
- import { Correlation } from "../page/lane.ts";
12
- import { redact } from "../page/url.ts";
13
- import type * as BrowserClock from "../pictures/clock.ts";
15
+ import { Correlation, FailFast } from "../page/lane.ts";
16
+ import * as Replies from "../page/replies.ts";
14
17
  import type { Dispatch } from "./dispatch.ts";
15
18
  import type { Approval, PolicyPlan } from "./guard.ts";
16
- import * as Replies from "./replies.ts";
17
- import { plain, type Style } from "./style.ts";
18
19
 
19
20
  export interface InputMarks {
20
21
  /** How the action's input is sent: plainly, or performed for viewers. */
@@ -62,20 +63,34 @@ const subjectAttributes = (prefix: string, subject: Subject | undefined) =>
62
63
  /** What an action's record keeps of its call. */
63
64
  export interface Call {
64
65
  readonly target?: string | undefined;
65
- /** The rest of what the caller asked, recorded so a plan can ask it again. */
66
- readonly options?: ActionOptions | undefined;
67
66
  readonly text?: string | undefined;
68
- /** The text may be a secret: it is recorded only once the action reveals that it is not. */
69
- readonly secret?: boolean | undefined;
70
- /** False for navigation, which sends no input. */
71
- readonly input?: boolean | undefined;
72
- /** False for the pointer's travel ahead of an action, which is no action of its own. */
73
- readonly recorded?: boolean | undefined;
74
67
  }
75
68
 
76
69
  const timedOut = (operation: string, timeout: Duration.Duration) =>
77
70
  failWith(operation, new Timeout({ millis: Duration.toMillis(timeout) }));
78
71
 
72
+ /** Trace summaries carry lengths and subjects, never typed text. */
73
+ const annotate = (
74
+ dispatched: boolean,
75
+ queuedMillis: number | undefined,
76
+ info: Call,
77
+ revealed: boolean,
78
+ subject: Subject | undefined,
79
+ to: Subject | undefined,
80
+ failure: Option.Option<BrowserError>,
81
+ ) =>
82
+ Effect.annotateCurrentSpan({
83
+ dispatched,
84
+ ...(queuedMillis === undefined ? {} : { queuedMillis }),
85
+ ...(info.text !== undefined && revealed ? { chars: info.text.length } : {}),
86
+ ...subjectAttributes("subject", subject),
87
+ ...subjectAttributes("to", to),
88
+ ...Option.match(failure, {
89
+ onNone: () => ({}),
90
+ onSome: (error) => ({ "error.type": error.reason._tag }),
91
+ }),
92
+ });
93
+
79
94
  /**
80
95
  * Fail `effect` with `Timeout` once `timeout` has passed, and as much later again as `presented`
81
96
  * says presentation has planned meanwhile.
@@ -140,7 +155,11 @@ const useRun = <A>(
140
155
  canStop: Effect.Effect<boolean>,
141
156
  ) =>
142
157
  action.pipe(
143
- Effect.tapError(() => run.close.pipe(Effect.andThen(sender.flush(name, run)), Effect.ignore)),
158
+ Effect.tapError((error) =>
159
+ error.reason._tag === "Closed"
160
+ ? run.close
161
+ : run.close.pipe(Effect.andThen(sender.flush(name, run)), Effect.ignore),
162
+ ),
144
163
  Effect.tap(() => run.close.pipe(Effect.andThen(sender.flush(name, run)))),
145
164
  // Cleanup submits missing releases; the page retains replies after caller interruption.
146
165
  Effect.ensuring(run.close.pipe(Effect.andThen(page.openings.clear))),
@@ -157,14 +176,23 @@ export const make = (page: PageContext, sender: Dispatch) => {
157
176
  // Record the whole operation, but never hold the page's turn or spend its action timeout while
158
177
  // a policy is waiting. Validation binds approval to the document and targets it saw.
159
178
  const perform = <A>(
160
- name: string,
179
+ value: ActionValue,
161
180
  info: Call,
162
181
  timeout: Duration.Duration,
163
- prepare: Effect.Effect<PolicyPlan, BrowserError>,
182
+ prepare: (action: ActionValue) => Effect.Effect<PolicyPlan, BrowserError>,
164
183
  body: (marks: InputMarks, approval: Approval | undefined) => Effect.Effect<A, BrowserError>,
165
- style: Style = plain,
166
- ): Effect.Effect<A, BrowserError> =>
167
- Effect.gen(function* () {
184
+ ): Effect.Effect<A, BrowserError> => {
185
+ const name = nameOf(value);
186
+ const sendsInput = value._tag !== "Goto" && value._tag !== "Back" && value._tag !== "Reload";
187
+
188
+ return Effect.gen(function* () {
189
+ const style = validated(yield* Current);
190
+ const failFast = yield* FailFast;
191
+
192
+ const styled =
193
+ style.withInput?.({ operation: name, wait: timeout, failFast }) ??
194
+ (<Value, Error, Requirements>(effect: Effect.Effect<Value, Error, Requirements>) => effect);
195
+
168
196
  const startedAt = now();
169
197
  const sent = yield* Ref.make(false);
170
198
  const at = yield* Ref.make(Option.none<Point>());
@@ -176,7 +204,7 @@ export const make = (page: PageContext, sender: Dispatch) => {
176
204
  const touch = Effect.sync(noteInput);
177
205
 
178
206
  // A failure before the action checks its field, a denial included, records no text.
179
- let revealed = info.secret !== true;
207
+ let revealed = value._tag !== "Type";
180
208
  // The time the style has planned to show the input, which the deadline leaves out.
181
209
  let presented = 0;
182
210
  const ticket = admission(page, admitted, name);
@@ -204,7 +232,7 @@ export const make = (page: PageContext, sender: Dispatch) => {
204
232
  const admit = input.idle.pipe(
205
233
  Effect.tap(() =>
206
234
  Effect.sync(() => {
207
- estimate = (info.input ?? true) ? mapping.latest() : undefined;
235
+ estimate = sendsInput ? mapping.latest() : undefined;
208
236
  }),
209
237
  ),
210
238
  );
@@ -226,7 +254,7 @@ export const make = (page: PageContext, sender: Dispatch) => {
226
254
  name,
227
255
  run,
228
256
  action(run),
229
- info.input === false ? Effect.succeed(false) : Ref.get(sent),
257
+ sendsInput ? Ref.get(sent) : Effect.succeed(false),
230
258
  ),
231
259
  ),
232
260
  );
@@ -242,29 +270,31 @@ export const make = (page: PageContext, sender: Dispatch) => {
242
270
  Effect.suspend(() => {
243
271
  const asked = now();
244
272
 
245
- return lane.write(
246
- name,
247
- timeout,
248
- )(
249
- ticket.enter.pipe(
250
- Effect.andThen(
251
- Effect.suspend(() =>
252
- admit.pipe(
253
- Effect.timeoutOrElse({
254
- duration: Duration.millis(
255
- Math.max(0, Duration.toMillis(timeout) - (now() - asked)),
256
- ),
257
- orElse: () => timedOut(name, timeout),
258
- }),
273
+ return styled(
274
+ lane.write(
275
+ name,
276
+ timeout,
277
+ )(
278
+ ticket.enter.pipe(
279
+ Effect.andThen(
280
+ Effect.suspend(() =>
281
+ admit.pipe(
282
+ Effect.timeoutOrElse({
283
+ duration: Duration.millis(
284
+ Math.max(0, Duration.toMillis(timeout) - (now() - asked)),
285
+ ),
286
+ orElse: () => timedOut(name, timeout),
287
+ }),
288
+ ),
259
289
  ),
260
290
  ),
291
+ Effect.tap(() =>
292
+ Effect.sync(() => {
293
+ queuedMillis = Math.round(now() - asked);
294
+ }),
295
+ ),
296
+ Effect.andThen(deadline(name, timeout, now, () => presented)(action)),
261
297
  ),
262
- Effect.tap(() =>
263
- Effect.sync(() => {
264
- queuedMillis = Math.round(now() - asked);
265
- }),
266
- ),
267
- Effect.andThen(deadline(name, timeout, now, () => presented)(action)),
268
298
  ),
269
299
  );
270
300
  });
@@ -277,7 +307,7 @@ export const make = (page: PageContext, sender: Dispatch) => {
277
307
  ? dispatch(useInput((run) => body({ ...marks, input: run }, undefined)))
278
308
  : Effect.gen(function* () {
279
309
  const plan = yield* lane
280
- .read(name)(deadline(name, settings.actionTimeout, now, () => 0)(prepare))
310
+ .read(name)(deadline(name, settings.actionTimeout, now, () => 0)(prepare(value)))
281
311
  .pipe(span("Page.prepare", {}, "Debug"));
282
312
 
283
313
  // A hold lasts as long as this span; a judge's model call is its child.
@@ -303,8 +333,6 @@ export const make = (page: PageContext, sender: Dispatch) => {
303
333
  );
304
334
  });
305
335
 
306
- const record = info.recorded === false ? () => 0 : publish;
307
-
308
336
  // Record the outcome even when the caller interrupts: its input may already be in the page.
309
337
  return yield* Effect.uninterruptibleMask((restore) =>
310
338
  Effect.gen(function* () {
@@ -317,29 +345,18 @@ export const make = (page: PageContext, sender: Dispatch) => {
317
345
  const { subject, to, box } = yield* Ref.get(acted);
318
346
  const failure = Exit.isFailure(exit) ? Exit.findErrorOption(exit) : Option.none();
319
347
 
320
- // What the Action records, less its text: only a revealed text's length.
321
- yield* Effect.annotateCurrentSpan({
322
- dispatched,
323
- ...(queuedMillis === undefined ? {} : { queuedMillis }),
324
- ...(info.text !== undefined && revealed ? { chars: info.text.length } : {}),
325
- ...subjectAttributes("subject", subject),
326
- ...subjectAttributes("to", to),
327
- ...Option.match(failure, {
328
- onNone: () => ({}),
329
- onSome: (error) => ({ "error.type": error.reason._tag }),
330
- }),
331
- });
348
+ yield* annotate(dispatched, queuedMillis, info, revealed, subject, to, failure);
332
349
 
333
- record(
350
+ publish(
334
351
  new Action({
335
352
  at: now(),
336
353
  startedAt,
337
354
  page: id,
338
355
  name,
356
+ value: recorded(value, revealed),
339
357
  url: redact(page.playwright.url()),
340
358
  correlation: yield* Correlation,
341
359
  target: info.target,
342
- options: Exit.isSuccess(exit) ? info.options : undefined,
343
360
  subject,
344
361
  to,
345
362
  box,
@@ -371,6 +388,7 @@ export const make = (page: PageContext, sender: Dispatch) => {
371
388
  }),
372
389
  ).pipe(Effect.ensuring(ticket.end));
373
390
  }).pipe(span(`Page.${name}`, info.target === undefined ? {} : { target: info.target }), owned);
391
+ };
374
392
 
375
393
  return Object.assign(perform, {
376
394
  idle: Effect.suspend(() => Effect.forEach(admitted, Deferred.await, { discard: true })),
@@ -6,8 +6,9 @@
6
6
  import { Duration, Effect, MutableRef, Option, Schema } from "effect";
7
7
 
8
8
  import { CursorChanged, TrackPerformed, TrackPlanned } from "../../BrowserEvent.ts";
9
- import * as Motion from "../../Motion.ts";
9
+ import * as Motion from "../../Geometry.ts";
10
10
  import type { Point } from "../../Page.ts";
11
+ import type { WheelStep } from "../../Style.ts";
11
12
  import { type PageContext, refuse } from "../page/context.ts";
12
13
  import type { Viewport } from "../page/viewport.ts";
13
14
  import type { Dispatch } from "./dispatch.ts";
@@ -126,8 +127,9 @@ export const make = (page: PageContext, dispatch: Dispatch, viewport: Viewport)
126
127
  point: Point,
127
128
  dx: number,
128
129
  dy: number,
130
+ planned?: ReadonlyArray<WheelStep>,
129
131
  ) {
130
- const steps = yield* marks.style.wheel(dx, dy);
132
+ const steps = planned ?? (yield* marks.style.wheel(dx, dy));
131
133
  const at = now();
132
134
 
133
135
  yield* marks.present(steps.at(-1)?.afterMillis ?? 0);
@@ -6,11 +6,11 @@
6
6
  * `pushState` asks for no document, and a navigation a handler starts after a fetch answers is the
7
7
  * next look's to see. A tab the input opened waits for the browser's registration too.
8
8
  */
9
- import { Deferred, Duration, Effect, Exit } from "effect";
9
+ import { Deferred, Duration, Effect, Exit, Option } from "effect";
10
10
 
11
11
  import { type Bridge, scriptCall } from "../page/bridge.ts";
12
12
  import { contextGone, type PageContext } from "../page/context.ts";
13
- import { Current } from "./replies.ts";
13
+ import { Current } from "../page/replies.ts";
14
14
 
15
15
  // A document still loading after this, or a closed page, is the next look's to show.
16
16
  const settling = Duration.seconds(5);
@@ -42,9 +42,11 @@ export const make = (page: PageContext, bridge: Bridge) => {
42
42
  );
43
43
  while (document() > before.document && parsed < document()) yield* Deferred.await(changed);
44
44
  }).pipe(
45
- Effect.timeoutOrElse({ duration: settling, orElse: () => Effect.fail("unsettled") }),
46
- Effect.catch(() =>
47
- page.stopLoading.pipe(Effect.andThen(Effect.annotateCurrentSpan("settled", false))),
45
+ Effect.timeoutOption(settling),
46
+ Effect.flatMap((result) =>
47
+ Option.isSome(result)
48
+ ? Effect.void
49
+ : page.stopLoading.pipe(Effect.andThen(Effect.annotateCurrentSpan("settled", false))),
48
50
  ),
49
51
  Effect.andThen(page.openings.settle(before.openings)),
50
52
  page.span("Page.settle", {}, "Debug"),
@@ -6,7 +6,7 @@
6
6
  import { Schema } from "effect";
7
7
 
8
8
  import { Box, Subject } from "../../BrowserEvent.ts";
9
- import { Point } from "../../Motion.ts";
9
+ import { Point } from "../../Geometry.ts";
10
10
  import type { ContextReader } from "../reading/context.inpage.ts";
11
11
  import type { Names } from "../reading/names.inpage.ts";
12
12
  import type { Walk } from "../reading/walk.inpage.ts";
@@ -8,7 +8,7 @@ import { Effect } from "effect";
8
8
  import { InvalidRequest, NotActionable, StaleRef } from "../../BrowserError.ts";
9
9
  import { ResolvedTarget, type Target } from "../../Page.ts";
10
10
  import { scriptCall } from "../page/bridge.ts";
11
- import { decodeWith, failWith, refuse } from "../page/context.ts";
11
+ import { decodeWith, failWith } from "../page/context.ts";
12
12
  import type { Viewport } from "../page/viewport.ts";
13
13
  import type { Dispatch } from "./dispatch.ts";
14
14
  import { type Approval, check, type Guard } from "./guard.ts";
@@ -55,20 +55,15 @@ export const make = (
55
55
  Effect.flatMap(decodeWith(operation, Script.PointResultSchema)),
56
56
  );
57
57
 
58
- const resolve = (operation: string, target: Target, approval?: Approval, scroll = true) => {
59
- if (typeof target === "string" && !/^e\d+$/.test(target))
60
- return refuse(operation, target + " is not a ref; refs look like e12");
61
- if (typeof target !== "string" && (!Number.isFinite(target.x) || !Number.isFinite(target.y)))
62
- return refuse(operation, "point coordinates must be finite");
63
-
64
- return readPoint(operation, target, approval, scroll).pipe(
58
+ // Every input reaches this phase through ActionPort's decoded Target schema.
59
+ const resolve = (operation: string, target: Target, approval?: Approval, scroll = true) =>
60
+ readPoint(operation, target, approval, scroll).pipe(
65
61
  Effect.flatMap((result) =>
66
62
  "error" in result
67
63
  ? pointFailure(operation, target, result)
68
64
  : Effect.succeed(resolvedTarget(result)),
69
65
  ),
70
66
  );
71
- };
72
67
 
73
68
  const targetFor = Effect.fnUntraced(function* (
74
69
  operation: string,