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

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 (248) 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-Cq2K1FEA.mjs +4075 -0
  10. package/dist/Browser-Cq2K1FEA.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-BTeO0Hiz.mjs} +5 -6
  64. package/dist/connection-BTeO0Hiz.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 +513 -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 +86 -36
  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/lane.ts +14 -15
  139. package/src/internal/page/navigation.ts +50 -42
  140. package/src/internal/page/openings.ts +11 -5
  141. package/src/internal/page/page.ts +44 -81
  142. package/src/internal/page/port.ts +125 -0
  143. package/src/internal/{input → page}/replies.ts +1 -1
  144. package/src/internal/page/request-owner.ts +269 -0
  145. package/src/internal/page/requests.ts +357 -0
  146. package/src/internal/page/scripts.ts +124 -0
  147. package/src/internal/pictures/capture.ts +255 -332
  148. package/src/internal/pictures/dimensions.ts +162 -0
  149. package/src/internal/pictures/frame.ts +68 -0
  150. package/src/internal/pictures/pictures.ts +57 -23
  151. package/src/internal/pictures/quiescence.ts +1 -1
  152. package/src/internal/pictures/state.ts +26 -0
  153. package/src/internal/pictures/transport.ts +21 -4
  154. package/src/internal/reading/controls.inpage.ts +5 -70
  155. package/src/internal/reading/expect.inpage.ts +13 -17
  156. package/src/internal/reading/names.inpage.ts +89 -45
  157. package/src/internal/reading/outline.inpage.ts +6 -7
  158. package/src/internal/reading/reading.ts +144 -176
  159. package/src/internal/reading/ready.inpage.ts +6 -17
  160. package/src/internal/reading/ready.ts +13 -135
  161. package/src/internal/reading/subjects.inpage.ts +83 -43
  162. package/src/internal/reading/walk.inpage.ts +33 -13
  163. package/src/internal/timeline/changes.ts +55 -6
  164. package/src/internal/timeline/events.ts +15 -5
  165. package/src/internal/timeline/history.inpage.ts +1 -1
  166. package/src/internal/timeline/record.inpage.ts +4 -1
  167. package/src/internal/timeline/window.ts +2 -1
  168. package/src/{Moment.ts → moment/Moment.ts} +13 -31
  169. package/src/{internal/timeline → moment}/words.ts +2 -2
  170. package/src/{internal/reading → plan}/choose.ts +3 -3
  171. package/src/plan/data.ts +117 -0
  172. package/src/plan/execute.ts +411 -0
  173. package/src/plan/index.ts +36 -0
  174. package/src/plan/record.ts +71 -0
  175. package/src/plan/targets.ts +71 -0
  176. package/src/{Policy.ts → policy/Policy.ts} +13 -10
  177. package/src/{Motion.ts → presentation/Motion.ts} +12 -46
  178. package/src/presentation/Presentation.ts +176 -0
  179. package/src/{Stage.ts → presentation/Stage.ts} +147 -112
  180. package/src/presentation/feed.ts +21 -0
  181. package/src/{Cdp.ts → providers/Cdp.ts} +2 -2
  182. package/src/{Chromium.ts → providers/Chromium.ts} +7 -10
  183. package/src/providers/Released.ts +13 -0
  184. package/src/{internal/cdp.ts → providers/connection.ts} +2 -2
  185. package/src/{internal/pictures/motion.ts → stillness/Pixels.ts} +1 -1
  186. package/src/stillness/Stillness.ts +166 -0
  187. package/src/supervisor/Supervisor.ts +170 -0
  188. package/src/supervisor/contract.ts +105 -0
  189. package/src/supervisor/lifecycle.ts +272 -0
  190. package/src/supervisor/runtime.ts +234 -0
  191. package/src/testing/TestBrowser.ts +115 -0
  192. package/src/testing/TestPage.ts +10 -0
  193. package/src/testing/evidence.ts +154 -0
  194. package/src/testing/index.ts +3 -0
  195. package/src/testing/model.ts +222 -0
  196. package/src/testing/page.ts +360 -0
  197. package/src/workerd/Cdp.ts +2 -2
  198. package/dist/Browser-CxXUjxOp.mjs +0 -619
  199. package/dist/Browser-CxXUjxOp.mjs.map +0 -1
  200. package/dist/Cdp-CzCRnMlM.d.mts +0 -10
  201. package/dist/Cdp.d.mts +0 -11
  202. package/dist/Cdp.mjs.map +0 -1
  203. package/dist/Change-DNvztNLu.mjs +0 -138
  204. package/dist/Change-DNvztNLu.mjs.map +0 -1
  205. package/dist/Chromium.mjs.map +0 -1
  206. package/dist/Expect-u3P_ENLX.d.mts +0 -62
  207. package/dist/Expect.d.mts +0 -2
  208. package/dist/Expect.mjs +0 -114
  209. package/dist/Expect.mjs.map +0 -1
  210. package/dist/Moment.d.mts +0 -2
  211. package/dist/Moment.mjs.map +0 -1
  212. package/dist/Motion.d.mts +0 -2
  213. package/dist/Motion.mjs.map +0 -1
  214. package/dist/Page-BP02bmNv.mjs +0 -264
  215. package/dist/Page-BP02bmNv.mjs.map +0 -1
  216. package/dist/Plan-BG1WifW2.mjs.map +0 -1
  217. package/dist/Plan.d.mts +0 -2
  218. package/dist/Plan.mjs +0 -2
  219. package/dist/Policy.d.mts +0 -2
  220. package/dist/Policy.mjs.map +0 -1
  221. package/dist/Presentation-DxVikn9_.d.mts +0 -48
  222. package/dist/Presentation.d.mts +0 -2
  223. package/dist/Presentation.mjs +0 -118
  224. package/dist/Presentation.mjs.map +0 -1
  225. package/dist/Stage.d.mts +0 -2
  226. package/dist/Stage.mjs.map +0 -1
  227. package/dist/Supervisor-2mPjIYYs.mjs +0 -676
  228. package/dist/Supervisor-2mPjIYYs.mjs.map +0 -1
  229. package/dist/Supervisor-CfRxbaso.d.mts +0 -317
  230. package/dist/Supervisor.d.mts +0 -2
  231. package/dist/Supervisor.mjs +0 -2
  232. package/dist/cdp-BMpYMWYe.mjs.map +0 -1
  233. package/dist/context-EGhOqjNN.mjs +0 -335
  234. package/dist/context-EGhOqjNN.mjs.map +0 -1
  235. package/dist/page-PTM8m5wC.mjs +0 -4057
  236. package/dist/page-PTM8m5wC.mjs.map +0 -1
  237. package/dist/url-Bsp2y55M.mjs +0 -264
  238. package/dist/url-Bsp2y55M.mjs.map +0 -1
  239. package/dist/workerd/index.d.mts +0 -16
  240. package/dist/workerd/index.mjs +0 -17
  241. package/src/Expect.ts +0 -180
  242. package/src/Plan.ts +0 -674
  243. package/src/Presentation.ts +0 -196
  244. package/src/Supervisor.ts +0 -632
  245. package/src/internal/supervisor/lifecycle.ts +0 -484
  246. package/src/workerd/index.ts +0 -17
  247. /package/src/{internal/page/url.ts → Url.ts} +0 -0
  248. /package/src/{internal/pictures → stillness}/utilsBundle.d.ts +0 -0
@@ -1,196 +0,0 @@
1
- /**
2
- * Input performed for viewers. A presenter owns one drawn pointer and a pace; `view(page)` is the
3
- * page with its actions performed: each waits as long as a person reacts, the pointer glides from
4
- * where viewers last saw it, on whichever page, a field is clicked before typing, keys go at the
5
- * pace's words a minute and the wheel turns in bursts, out to a target out of view. One view acts at
6
- * a time, as one hand moves one pointer, and its presentation time is outside `actionTimeout`. The
7
- * page itself stays plain, and plain input never waits for a view.
8
- *
9
- * ```ts
10
- * const presenter = yield* Presentation.make({ motion: yield* HumanStrokes.motion })
11
- * const performed = presenter.view(page)
12
- * yield* performed.aim("e12") // as the target appears in a streamed tool call
13
- * yield* performed.click("e12") // completes the glide, then clicks
14
- * ```
15
- *
16
- * @since 0.3.0
17
- */
18
- import { Clock, Duration, Effect, Fiber, MutableRef, Option, Semaphore } from "effect";
19
-
20
- import type { BrowserError } from "./BrowserError.ts";
21
- import * as Style from "./internal/input/style.ts";
22
- import { type Internals, internalsOf, viewOf } from "./internal/page/page.ts";
23
- import { monotonicMillis } from "./internal/pictures/clock.ts";
24
- import * as Motion from "./Motion.ts";
25
- import type { Page, Point, Target } from "./Page.ts";
26
-
27
- /** How long a person waits before acting, and how fast they type. */
28
- export interface Pacing {
29
- /** The usual wait before an action that follows an expected change, as the next field of a form. */
30
- readonly expected: Duration.Input;
31
- /** The usual wait after the page moved to a new document. */
32
- readonly surprise: Duration.Input;
33
- /** The usual wait before a page's first action, or one after an action on another page. */
34
- readonly unrelated: Duration.Input;
35
- /** Typing speed, a word being five characters. */
36
- readonly wordsPerMinute: number;
37
- }
38
-
39
- /**
40
- * The research's medians: 280 ms to react to an expected change, 600 ms to a surprise and 1 second
41
- * between unrelated actions, each drawn around its median, and typing at 70 words per minute.
42
- */
43
- export const human: Pacing = {
44
- expected: "280 millis",
45
- surprise: "600 millis",
46
- unrelated: "1 second",
47
- wordsPerMinute: 70,
48
- };
49
-
50
- export interface Options {
51
- /** Defaults to `human`. */
52
- readonly pacing?: Pacing | undefined;
53
- /** The pointer's paths. Defaults to `Motion.lognormal`. */
54
- readonly motion?: Motion.Service | undefined;
55
- }
56
-
57
- /** A page whose actions are performed, which can also start the pointer toward a target early. */
58
- export interface View extends Page {
59
- /**
60
- * Start the glide toward `target` as soon as it is known, as in a model's streamed tool call. The
61
- * next action waits for it when it acts on the same target, and otherwise stops it where it is.
62
- * An aim presses nothing and records no action; under an input guard it does nothing.
63
- */
64
- readonly aim: (target: Target) => Effect.Effect<void>;
65
- }
66
-
67
- export interface Presenter {
68
- /** `page`, a page a `Browser` opened, with its actions performed: the same view for the same page. */
69
- readonly view: (page: Page) => View;
70
- }
71
-
72
- // Reactions spread as the research measured them: an expected change least.
73
- const spread = { expected: 0.3, surprise: 0.4, unrelated: 0.4 };
74
-
75
- const sameTarget = (left: Target, right: Target | undefined) =>
76
- typeof left === "string" || typeof right !== "object"
77
- ? left === right
78
- : left.x === right.x && left.y === right.y;
79
-
80
- /** A presenter, for the scope: its pointer, its pace and the aims it has started. */
81
- export const make = Effect.fn("Presentation.make")(function* (options: Options = {}) {
82
- const pacing = options.pacing ?? human;
83
- const clock = yield* Clock.Clock;
84
- const scope = yield* Effect.scope;
85
- const now = () => monotonicMillis(clock);
86
- const pointer = MutableRef.make(Option.none<Point>());
87
- const hand = yield* Semaphore.make(1);
88
-
89
- const style = Style.performed({
90
- pointer,
91
- motion: options.motion ?? Motion.lognormal,
92
- wordsPerMinute: pacing.wordsPerMinute,
93
- });
94
-
95
- const medians = {
96
- expected: Duration.toMillis(Duration.fromInputUnsafe(pacing.expected)),
97
- surprise: Duration.toMillis(Duration.fromInputUnsafe(pacing.surprise)),
98
- unrelated: Duration.toMillis(Duration.fromInputUnsafe(pacing.unrelated)),
99
- };
100
-
101
- // The latest performed action: its page, the document it began in, and when it ended.
102
- let last: { readonly page: string; readonly document: number; readonly at: number } | undefined;
103
-
104
- // A person reacts to what the last action left: an expected change, a new document, as a link
105
- // opens, or another page altogether. Time already spent since it ended counts toward the wait.
106
- const react = (page: Page, internals: Internals) =>
107
- Effect.gen(function* () {
108
- const kind =
109
- last === undefined || last.page !== page.id
110
- ? "unrelated"
111
- : last.document === internals.document()
112
- ? "expected"
113
- : "surprise";
114
-
115
- const left = (last?.at ?? now()) + (yield* Style.pause(medians[kind], spread[kind])) - now();
116
-
117
- if (left > 0) yield* Effect.sleep(Duration.millis(left));
118
- }).pipe(Effect.provideService(Clock.Clock, clock));
119
-
120
- const views = new WeakMap<Page, View>();
121
-
122
- const view = (page: Page): View => {
123
- const known = views.get(page);
124
-
125
- if (known !== undefined) return known;
126
- const internals = internalsOf(page);
127
-
128
- if (internals === undefined)
129
- throw new TypeError("only a page that a Browser opened can be presented");
130
- const { input } = internals;
131
-
132
- let aiming:
133
- | { readonly target: Target; readonly fiber: Fiber.Fiber<void, BrowserError> }
134
- | undefined;
135
-
136
- // An aim at the action's own target is completed; any other is stopped where it is.
137
- const completeAim = (target: Target | undefined) =>
138
- Effect.suspend(() => {
139
- const current = aiming;
140
-
141
- aiming = undefined;
142
- if (current === undefined) return Effect.void;
143
-
144
- return sameTarget(current.target, target)
145
- ? Effect.asVoid(Fiber.await(current.fiber))
146
- : Fiber.interrupt(current.fiber);
147
- });
148
-
149
- const perform =
150
- (target: Target | undefined) =>
151
- <A, E>(action: Effect.Effect<A, E>): Effect.Effect<A, E> =>
152
- completeAim(target).pipe(
153
- Effect.andThen(
154
- hand.withPermits(1)(
155
- Effect.gen(function* () {
156
- yield* react(page, internals);
157
- const document = internals.document();
158
-
159
- return yield* action.pipe(
160
- Effect.ensuring(
161
- Effect.sync(() => {
162
- last = { page: page.id, document, at: now() };
163
- }),
164
- ),
165
- );
166
- }),
167
- ),
168
- ),
169
- );
170
-
171
- const performed: View = viewOf(page, {
172
- ...page,
173
- click: (target, clickOptions) => perform(target)(input.click(target, clickOptions, style)),
174
- hover: (target) => perform(target)(input.hover(target, style)),
175
- drag: (from, to) => perform(from)(input.drag(from, to, style)),
176
- type: (text, typeOptions) => perform(typeOptions?.into)(input.type(text, typeOptions, style)),
177
- press: (keys, pressOptions) => perform(undefined)(input.press(keys, pressOptions, style)),
178
- scroll: (scrollOptions) => perform(scrollOptions?.at)(input.scroll(scrollOptions, style)),
179
- select: (ref, values) => perform(ref)(input.select(ref, values)),
180
- aim: (target) =>
181
- Effect.gen(function* () {
182
- yield* completeAim(undefined);
183
- aiming = {
184
- target,
185
- fiber: yield* hand.withPermits(1)(input.aim(target, style)).pipe(Effect.forkIn(scope)),
186
- };
187
- }),
188
- });
189
-
190
- views.set(page, performed);
191
-
192
- return performed;
193
- };
194
-
195
- return { view } satisfies Presenter;
196
- });