effect-browser 0.3.0-beta.24 → 0.3.0-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +333 -157
- package/dist/Action.d.mts +1 -1
- package/dist/Action.mjs +61 -9
- package/dist/Action.mjs.map +1 -1
- package/dist/Browser.d.mts +2 -2
- package/dist/Browser.mjs +2 -2
- package/dist/BrowserError.d.mts +2 -2
- package/dist/BrowserError.mjs +194 -41
- package/dist/BrowserError.mjs.map +1 -1
- package/dist/BrowserEvent.d.mts +1 -1
- package/dist/BrowserEvent.mjs +166 -35
- package/dist/BrowserEvent.mjs.map +1 -1
- package/dist/Cdp.d.mts +15 -0
- package/dist/Cdp.mjs +22 -0
- package/dist/Cdp.mjs.map +1 -0
- package/dist/Change.d.mts +2 -2
- package/dist/Change.mjs +33 -6
- package/dist/Change.mjs.map +1 -1
- package/dist/Frame.d.mts +2 -2
- package/dist/Frame.mjs +132 -14
- package/dist/Frame.mjs.map +1 -1
- package/dist/{Style.d.mts → InputStyle.d.mts} +93 -25
- package/dist/{Style.mjs → InputStyle.mjs} +1 -1
- package/dist/Layout.d.mts +2 -2
- package/dist/Layout.mjs +58 -16
- package/dist/Layout.mjs.map +1 -1
- package/dist/Overlay.d.mts +2 -2
- package/dist/Overlay.mjs +33 -5
- package/dist/Overlay.mjs.map +1 -1
- package/dist/Page.d.mts +2 -2
- package/dist/Page.mjs +2 -2
- package/dist/PageTime.d.mts +2 -2
- package/dist/PageTime.mjs +13 -3
- package/dist/PageTime.mjs.map +1 -1
- package/dist/Pose.d.mts +2 -2
- package/dist/Pose.mjs +30 -9
- package/dist/Pose.mjs.map +1 -1
- package/dist/Site.d.mts +288 -18
- package/dist/Site.mjs +11 -3
- package/dist/Site.mjs.map +1 -1
- package/dist/Snapshot.d.mts +2 -2
- package/dist/Snapshot.mjs +87 -6
- package/dist/Snapshot.mjs.map +1 -1
- package/dist/Text.d.mts +2 -0
- package/dist/Text.mjs +45 -0
- package/dist/Text.mjs.map +1 -0
- package/dist/Window.d.mts +2 -2
- package/dist/Window.mjs +31 -6
- package/dist/Window.mjs.map +1 -1
- package/dist/ai/BrowserTools.d.mts +4987 -0
- package/dist/ai/BrowserTools.mjs +3 -0
- package/dist/ai/PageControl.d.mts +286 -0
- package/dist/ai/PageControl.mjs +426 -0
- package/dist/ai/PageControl.mjs.map +1 -0
- package/dist/ai/PromptCache.d.mts +16 -0
- package/dist/ai/PromptCache.mjs +72 -0
- package/dist/ai/PromptCache.mjs.map +1 -0
- package/dist/ai/Tabs.d.mts +2 -0
- package/dist/ai/Tabs.mjs +72 -0
- package/dist/ai/Tabs.mjs.map +1 -0
- package/dist/ai/ToolError.d.mts +34 -0
- package/dist/ai/ToolError.mjs +2 -0
- package/dist/ai/index.d.mts +6 -0
- package/dist/ai/index.mjs +6 -0
- package/dist/index.d.mts +7 -18
- package/dist/index.mjs +6 -9
- package/dist/{Action-24sLOubi.d.mts → internal/Action-CkanNTUw.d.mts} +64 -4
- package/dist/{Browser-DGR6ZEYo.d.mts → internal/Browser-DD9Vm1c-.d.mts} +75 -11
- package/dist/{Browser-CAQFhTkM.mjs → internal/Browser-vzD7i2oj.mjs} +174 -237
- package/dist/internal/Browser-vzD7i2oj.mjs.map +1 -0
- package/dist/{BrowserError-BlcmLVzn.d.mts → internal/BrowserError-CsuRYcDX.d.mts} +187 -28
- package/dist/{BrowserEvent-C2p-NwuU.d.mts → internal/BrowserEvent-tGPYYf6R.d.mts} +168 -13
- package/dist/internal/BrowserTools-Yi3lOX4h.mjs +497 -0
- package/dist/internal/BrowserTools-Yi3lOX4h.mjs.map +1 -0
- package/dist/{Style-T3ezDYLI.mjs → internal/InputStyle-CPzxoN4g.mjs} +75 -20
- package/dist/internal/InputStyle-CPzxoN4g.mjs.map +1 -0
- package/dist/{moment/Moment.mjs → internal/Moment-CstaX1mR.mjs} +49 -16
- package/dist/internal/Moment-CstaX1mR.mjs.map +1 -0
- package/dist/{moment/Moment.d.mts → internal/Moment-DOcldBdf.d.mts} +53 -20
- package/dist/internal/Page-BfGxn7oN.d.mts +1553 -0
- package/dist/{Page-BaAOshxo.mjs → internal/Page-DqF-tuTx.mjs} +62 -74
- package/dist/internal/Page-DqF-tuTx.mjs.map +1 -0
- package/dist/internal/Release-CFONkPDP.d.mts +39 -0
- package/dist/internal/Stage-D5ymSXDT.mjs +298 -0
- package/dist/internal/Stage-D5ymSXDT.mjs.map +1 -0
- package/dist/internal/Stillness-DCPeAN1a.mjs +1124 -0
- package/dist/internal/Stillness-DCPeAN1a.mjs.map +1 -0
- package/dist/internal/Supervisor-BcY_QNIY.d.mts +108 -0
- package/dist/internal/Supervisor-BcglY23c.mjs +531 -0
- package/dist/internal/Supervisor-BcglY23c.mjs.map +1 -0
- package/dist/internal/Tabs-dXMscIUQ.d.mts +52 -0
- package/dist/internal/TestPage-CYiYbh63.d.mts +159 -0
- package/dist/internal/ToolError-DArsRS2m.mjs +117 -0
- package/dist/internal/ToolError-DArsRS2m.mjs.map +1 -0
- package/dist/{plan/index.d.mts → internal/Walk-BNXcfZ2z.d.mts} +59 -35
- package/dist/{plan/index.mjs → internal/Walk-C5ky7uSf.mjs} +83 -51
- package/dist/internal/Walk-C5ky7uSf.mjs.map +1 -0
- package/dist/{ActionPort.mjs → internal/action-port-B5EkeGOR.mjs} +6 -12
- package/dist/internal/action-port-B5EkeGOR.mjs.map +1 -0
- package/dist/internal/cdp/workerd.d.mts +13 -0
- package/dist/internal/cdp/workerd.mjs +19 -0
- package/dist/internal/cdp/workerd.mjs.map +1 -0
- package/dist/{Clock.mjs → internal/clock-BKSAEf00.mjs} +13 -13
- package/dist/internal/clock-BKSAEf00.mjs.map +1 -0
- package/dist/{connection-Db-YtlbE.d.mts → internal/connection-BaB0vp1o.d.mts} +6 -6
- package/dist/{connection-C_jWYIwe.mjs → internal/connection-C2X4GmXM.mjs} +19 -15
- package/dist/internal/connection-C2X4GmXM.mjs.map +1 -0
- package/dist/internal/events-DzCrww-y.mjs +72 -0
- package/dist/internal/events-DzCrww-y.mjs.map +1 -0
- package/dist/internal/fold.inpage-uhrT-dOB.mjs +49 -0
- package/dist/internal/fold.inpage-uhrT-dOB.mjs.map +1 -0
- package/dist/internal/functions-jBOs6GKv.mjs +27 -0
- package/dist/internal/functions-jBOs6GKv.mjs.map +1 -0
- package/dist/{Geometry-DJx9qrYy.d.mts → internal/geometry-Dhj_ztJs.d.mts} +3 -3
- package/dist/{Geometry.mjs → internal/geometry-Lxyflb9J.mjs} +3 -12
- package/dist/internal/geometry-Lxyflb9J.mjs.map +1 -0
- package/dist/{Matching.mjs → internal/matching-Cs-UeOY0.mjs} +3 -3
- package/dist/internal/matching-Cs-UeOY0.mjs.map +1 -0
- package/dist/internal/page-DFQb-YOK.mjs +436 -0
- package/dist/internal/page-DFQb-YOK.mjs.map +1 -0
- package/dist/{pose.inpage-CLq7Mfdr.mjs → internal/pose.inpage-CBFeWcVa.mjs} +2 -48
- package/dist/internal/pose.inpage-CBFeWcVa.mjs.map +1 -0
- package/dist/{Url.mjs → internal/url-DB0pQYk6.mjs} +3 -12
- package/dist/internal/url-DB0pQYk6.mjs.map +1 -0
- package/dist/policy/Policy.d.mts +60 -6
- package/dist/policy/Policy.mjs +52 -9
- package/dist/policy/Policy.mjs.map +1 -1
- package/dist/policy/index.d.mts +2 -0
- package/dist/policy/index.mjs +2 -0
- package/dist/{film → presentation}/Film.d.mts +83 -16
- package/dist/{film → presentation}/Film.mjs +82 -30
- package/dist/presentation/Film.mjs.map +1 -0
- package/dist/presentation/Motion.d.mts +5 -1
- package/dist/presentation/Motion.mjs +16 -2
- package/dist/presentation/Motion.mjs.map +1 -1
- package/dist/presentation/Presentation.d.mts +42 -7
- package/dist/presentation/Presentation.mjs +26 -9
- package/dist/presentation/Presentation.mjs.map +1 -1
- package/dist/presentation/Stage.d.mts +40 -6
- package/dist/presentation/Stage.mjs +1 -262
- package/dist/presentation/index.d.mts +5 -0
- package/dist/presentation/index.mjs +5 -0
- package/dist/supervisor/Release.d.mts +2 -0
- package/dist/supervisor/Release.mjs +40 -0
- package/dist/supervisor/Release.mjs.map +1 -0
- package/dist/supervisor/Supervisor.d.mts +2 -104
- package/dist/supervisor/Supervisor.mjs +2 -515
- package/dist/supervisor/index.d.mts +3 -0
- package/dist/supervisor/index.mjs +3 -0
- package/dist/testing/HttpCassette.d.mts +98 -0
- package/dist/testing/HttpCassette.mjs +146 -0
- package/dist/testing/HttpCassette.mjs.map +1 -0
- package/dist/testing/Story.d.mts +31 -0
- package/dist/testing/Story.mjs +76 -0
- package/dist/testing/Story.mjs.map +1 -0
- package/dist/testing/TestBrowser.d.mts +191 -0
- package/dist/testing/TestBrowser.mjs +105 -0
- package/dist/testing/TestBrowser.mjs.map +1 -0
- package/dist/testing/TestModel.d.mts +133 -0
- package/dist/testing/TestModel.mjs +209 -0
- package/dist/testing/TestModel.mjs.map +1 -0
- package/dist/testing/TestPage.d.mts +2 -0
- package/dist/testing/TestPage.mjs +47 -0
- package/dist/testing/TestPage.mjs.map +1 -0
- package/dist/testing/index.d.mts +6 -311
- package/dist/testing/index.mjs +6 -521
- package/dist/timeline/Moment.d.mts +3 -0
- package/dist/timeline/Moment.mjs +3 -0
- package/dist/timeline/Stillness.d.mts +34 -0
- package/dist/timeline/Stillness.mjs +2 -0
- package/dist/timeline/index.d.mts +3 -0
- package/dist/timeline/index.mjs +3 -0
- package/dist/walk/Walk.d.mts +2 -0
- package/dist/walk/Walk.mjs +2 -0
- package/dist/walk/index.d.mts +2 -0
- package/dist/walk/index.mjs +2 -0
- package/package.json +54 -163
- package/src/Action.ts +73 -8
- package/src/Browser.ts +75 -9
- package/src/BrowserError.ts +258 -63
- package/src/BrowserEvent.ts +252 -55
- package/src/Cdp.ts +42 -0
- package/src/Change.ts +68 -3
- package/src/Frame.ts +247 -14
- package/src/{Style.ts → InputStyle.ts} +98 -22
- package/src/Layout.ts +95 -24
- package/src/Overlay.ts +42 -3
- package/src/Page.ts +144 -320
- package/src/PageTime.ts +29 -4
- package/src/Pose.ts +38 -7
- package/src/Site.ts +15 -3
- package/src/Snapshot.ts +179 -3
- package/src/Text.ts +60 -0
- package/src/Window.ts +53 -3
- package/src/ai/BrowserTools.ts +778 -0
- package/src/ai/PageControl.ts +702 -0
- package/src/ai/PromptCache.ts +87 -0
- package/src/ai/Tabs.ts +84 -0
- package/src/ai/ToolError.ts +50 -0
- package/src/ai/index.ts +36 -0
- package/src/ai/internal/crops.ts +38 -0
- package/src/ai/internal/points.ts +57 -0
- package/src/ai/internal/receipts.ts +107 -0
- package/src/index.ts +83 -6
- package/src/{ActionPort.ts → internal/action-port.ts} +3 -3
- package/src/{providers → internal/cdp}/connection.ts +19 -12
- package/src/internal/cdp/workerd.ts +36 -0
- package/src/{Clock.ts → internal/clock.ts} +20 -0
- package/src/internal/input/actions.ts +1 -1
- package/src/internal/input/dispatch.ts +2 -2
- package/src/internal/input/guard.inpage.ts +1 -1
- package/src/internal/input/guard.ts +1 -1
- package/src/internal/input/perform.ts +5 -5
- package/src/internal/input/pointer.ts +2 -2
- package/src/internal/input/targets.inpage.ts +3 -3
- package/src/{Matching.ts → internal/matching.ts} +6 -6
- package/src/internal/page/bridge.ts +2 -2
- package/src/internal/page/clock.inpage.ts +1 -1
- package/src/internal/page/compose.inpage.ts +2 -2
- package/src/internal/page/context.ts +2 -2
- package/src/internal/page/functions.ts +84 -0
- package/src/internal/page/navigation.ts +1 -1
- package/src/internal/page/openings.ts +2 -2
- package/src/internal/page/page.ts +33 -35
- package/src/internal/page/port.ts +14 -8
- package/src/internal/page/replies.ts +1 -1
- package/src/internal/page/requests.ts +1 -1
- package/src/internal/page/scripts.ts +1 -1
- package/src/internal/page/time.ts +1 -1
- package/src/internal/pictures/capture.ts +1 -4
- package/src/internal/pictures/dimensions.ts +1 -1
- package/src/internal/pictures/frame.ts +1 -1
- package/src/internal/pictures/pictures.ts +53 -61
- package/src/internal/reading/context.inpage.ts +2 -2
- package/src/internal/reading/expect.inpage.ts +1 -1
- package/src/internal/reading/layout.inpage.ts +3 -3
- package/src/internal/reading/layout.ts +5 -5
- package/src/internal/reading/outline.inpage.ts +3 -3
- package/src/internal/reading/reading.ts +11 -19
- package/src/internal/reading/ready.inpage.ts +2 -2
- package/src/internal/reading/ready.ts +3 -2
- package/src/internal/reading/subjects.inpage.ts +3 -3
- package/src/internal/reading/text.inpage.ts +2 -2
- package/src/internal/reading/walk.inpage.ts +1 -1
- package/src/internal/timeline/changes.inpage.ts +2 -2
- package/src/internal/timeline/changes.ts +3 -4
- package/src/internal/timeline/sight.inpage.ts +2 -2
- package/src/internal/timeline/window.ts +3 -4
- package/src/policy/Policy.ts +70 -16
- package/src/policy/index.ts +12 -0
- package/src/{film → presentation}/Film.ts +104 -37
- package/src/presentation/Motion.ts +45 -3
- package/src/presentation/Presentation.ts +47 -14
- package/src/presentation/Stage.ts +73 -35
- package/src/presentation/index.ts +30 -0
- package/src/presentation/{feed.ts → internal/feed.ts} +1 -1
- package/src/supervisor/Release.ts +45 -0
- package/src/supervisor/Supervisor.ts +80 -5
- package/src/supervisor/index.ts +18 -0
- package/src/supervisor/{contract.ts → internal/contract.ts} +14 -10
- package/src/supervisor/{lifecycle.ts → internal/lifecycle.ts} +7 -7
- package/src/supervisor/{runtime.ts → internal/runtime.ts} +7 -7
- package/src/testing/HttpCassette.ts +260 -0
- package/src/testing/Story.ts +103 -0
- package/src/testing/TestBrowser.ts +14 -4
- package/src/testing/TestModel.ts +297 -0
- package/src/testing/TestPage.ts +92 -4
- package/src/testing/index.ts +35 -1
- package/src/testing/{evidence.ts → internal/evidence.ts} +19 -11
- package/src/testing/{model.ts → internal/model.ts} +14 -8
- package/src/testing/{page.ts → internal/page.ts} +55 -56
- package/src/{moment → timeline}/Moment.ts +79 -29
- package/src/{stillness → timeline}/Stillness.ts +61 -43
- package/src/timeline/index.ts +18 -0
- package/src/{stillness/Pixels.ts → timeline/internal/pixels.ts} +2 -2
- package/src/{moment → timeline/internal}/words.ts +2 -2
- package/src/walk/Walk.ts +165 -0
- package/src/walk/index.ts +12 -0
- package/src/{plan → walk/internal}/choose.ts +23 -14
- package/src/{plan → walk/internal}/data.ts +37 -14
- package/src/{plan → walk/internal}/execute.ts +79 -36
- package/src/{plan → walk/internal}/record.ts +6 -6
- package/src/{plan → walk/internal}/targets.ts +35 -25
- package/dist/ActionPort.d.mts +0 -15
- package/dist/ActionPort.mjs.map +0 -1
- package/dist/Browser-CAQFhTkM.mjs.map +0 -1
- package/dist/Change-CxT1mp2e.d.mts +0 -80
- package/dist/Clock-Du5nP-nK.d.mts +0 -57
- package/dist/Clock.d.mts +0 -2
- package/dist/Clock.mjs.map +0 -1
- package/dist/Frame-UEH2hO5T.d.mts +0 -124
- package/dist/Geometry.d.mts +0 -2
- package/dist/Geometry.mjs.map +0 -1
- package/dist/Matching-MtcWZ_hA.d.mts +0 -266
- package/dist/Matching.d.mts +0 -2
- package/dist/Matching.mjs.map +0 -1
- package/dist/Overlay-CoGw5tL_.d.mts +0 -27
- package/dist/Page-BaAOshxo.mjs.map +0 -1
- package/dist/Page-CLzh5E9w.d.mts +0 -718
- package/dist/PageTime-68UPUZpZ.d.mts +0 -29
- package/dist/Pose-2qqGzPvb.d.mts +0 -32
- package/dist/Released-tURbFmal.d.mts +0 -15
- package/dist/Snapshot-CtBVOtuu.d.mts +0 -73
- package/dist/Stillness-BwP0RdI4.mjs +0 -157
- package/dist/Stillness-BwP0RdI4.mjs.map +0 -1
- package/dist/Style-T3ezDYLI.mjs.map +0 -1
- package/dist/Url-B7P-TWwL.d.mts +0 -26
- package/dist/Url.d.mts +0 -2
- package/dist/Url.mjs.map +0 -1
- package/dist/Window-BDa8MtNP.d.mts +0 -34
- package/dist/connection-C_jWYIwe.mjs.map +0 -1
- package/dist/film/Film.mjs.map +0 -1
- package/dist/moment/Moment.mjs.map +0 -1
- package/dist/plan/index.mjs.map +0 -1
- package/dist/pose.inpage-CLq7Mfdr.mjs.map +0 -1
- package/dist/presentation/Stage.mjs.map +0 -1
- package/dist/presentation/feed.d.mts +0 -20
- package/dist/presentation/feed.mjs +0 -18
- package/dist/presentation/feed.mjs.map +0 -1
- package/dist/providers/Cdp.d.mts +0 -9
- package/dist/providers/Cdp.mjs +0 -15
- package/dist/providers/Cdp.mjs.map +0 -1
- package/dist/providers/Chromium.d.mts +0 -32
- package/dist/providers/Chromium.mjs +0 -55
- package/dist/providers/Chromium.mjs.map +0 -1
- package/dist/providers/Released.d.mts +0 -2
- package/dist/providers/Released.mjs +0 -12
- package/dist/providers/Released.mjs.map +0 -1
- package/dist/stillness/Stillness.d.mts +0 -12
- package/dist/stillness/Stillness.mjs +0 -2
- package/dist/supervisor/Supervisor.mjs.map +0 -1
- package/dist/testing/index.mjs.map +0 -1
- package/dist/workerd/Cdp.d.mts +0 -8
- package/dist/workerd/Cdp.mjs +0 -13
- package/dist/workerd/Cdp.mjs.map +0 -1
- package/src/plan/index.ts +0 -36
- package/src/providers/Cdp.ts +0 -16
- package/src/providers/Chromium.ts +0 -99
- package/src/providers/Released.ts +0 -13
- package/src/workerd/Cdp.ts +0 -11
- /package/dist/{fold.inpage-CyVZQHZL.d.mts → internal/fold.inpage-CyVZQHZL.d.mts} +0 -0
- /package/dist/{rolldown-runtime-D7D4PA-g.mjs → internal/rolldown-runtime-D7D4PA-g.mjs} +0 -0
- /package/src/{Geometry.ts → internal/geometry.ts} +0 -0
- /package/src/{Url.ts → internal/url.ts} +0 -0
- /package/src/{stillness → timeline/internal}/utilsBundle.d.ts +0 -0
package/src/testing/TestPage.ts
CHANGED
|
@@ -1,10 +1,98 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Seed a deterministic page without executing page code or inferring browser effects, or give a
|
|
3
|
+
* page pictures of a test's own.
|
|
4
|
+
*
|
|
5
|
+
* @stability stable
|
|
6
|
+
* @since 0.3.0
|
|
7
|
+
*/
|
|
8
|
+
import type { Effect, Scope } from "effect";
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
import type { BrowserError } from "../BrowserError.ts";
|
|
11
|
+
import type * as Frame from "../Frame.ts";
|
|
12
|
+
import { functionsOf, Implementation, key } from "../internal/page/functions.ts";
|
|
13
|
+
import type { Page } from "../Page.ts";
|
|
14
|
+
import type { Seed } from "./internal/model.ts";
|
|
15
|
+
import { makeIn } from "./internal/page.ts";
|
|
6
16
|
|
|
17
|
+
export type {
|
|
18
|
+
/**
|
|
19
|
+
* @stability stable
|
|
20
|
+
* @category models
|
|
21
|
+
* @since 0.3.0
|
|
22
|
+
*/
|
|
23
|
+
Seed,
|
|
24
|
+
/**
|
|
25
|
+
* @stability stable
|
|
26
|
+
* @category models
|
|
27
|
+
* @since 0.3.0
|
|
28
|
+
*/
|
|
29
|
+
Element,
|
|
30
|
+
/**
|
|
31
|
+
* @stability stable
|
|
32
|
+
* @category models
|
|
33
|
+
* @since 0.3.0
|
|
34
|
+
*/
|
|
35
|
+
ChangeTrack,
|
|
36
|
+
} from "./internal/model.ts";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @stability stable
|
|
40
|
+
* @category constructors
|
|
41
|
+
* @since 0.3.0
|
|
42
|
+
*/
|
|
7
43
|
export const make = (
|
|
8
44
|
seed: Seed = {},
|
|
9
45
|
options: { readonly id?: string; readonly session?: string; readonly connection?: string } = {},
|
|
10
46
|
) => makeIn(seed, options);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* What a page's `Frame` functions read, each under its function's name.
|
|
50
|
+
*
|
|
51
|
+
* @stability stable
|
|
52
|
+
* @category models
|
|
53
|
+
* @since 0.3.0
|
|
54
|
+
*/
|
|
55
|
+
export interface Pictures {
|
|
56
|
+
readonly read: (options?: Frame.FrameOptions) => Effect.Effect<Frame.Frame, BrowserError>;
|
|
57
|
+
readonly zoom: (
|
|
58
|
+
region: Frame.Region,
|
|
59
|
+
options?: Pick<Frame.FrameOptions, "quality" | "format" | "scale">,
|
|
60
|
+
) => Effect.Effect<Frame.Zoom, BrowserError>;
|
|
61
|
+
readonly capture: (
|
|
62
|
+
options?: Frame.ScreencastOptions,
|
|
63
|
+
) => Effect.Effect<Frame.Capture, BrowserError, Scope.Scope>;
|
|
64
|
+
readonly recent: Effect.Effect<ReadonlyArray<Frame.Frame>>;
|
|
65
|
+
readonly paint: (options: Frame.Paint) => Effect.Effect<void, BrowserError, Scope.Scope>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A copy of `page` whose `Frame` functions read what `pictures` makes of its own, so a test can
|
|
70
|
+
* watch what a reader took or give it pictures of its own making. The page's members are its own.
|
|
71
|
+
*
|
|
72
|
+
* @stability stable
|
|
73
|
+
* @category combinators
|
|
74
|
+
* @since 0.3.0
|
|
75
|
+
*/
|
|
76
|
+
export const withPictures = <P extends Page>(page: P, pictures: (own: Pictures) => Pictures): P => {
|
|
77
|
+
const functions = functionsOf(page);
|
|
78
|
+
|
|
79
|
+
const { read, zoom, capture, recent, paint } = pictures({
|
|
80
|
+
read: functions.frame,
|
|
81
|
+
zoom: functions.zoom,
|
|
82
|
+
capture: functions.capture,
|
|
83
|
+
recent: functions.recentFrames,
|
|
84
|
+
paint: functions.paint,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
...page,
|
|
89
|
+
[key]: new Implementation({
|
|
90
|
+
...functions,
|
|
91
|
+
frame: read,
|
|
92
|
+
zoom,
|
|
93
|
+
capture,
|
|
94
|
+
recentFrames: recent,
|
|
95
|
+
paint,
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
};
|
package/src/testing/index.ts
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic browser stories, seeded through data instead of page code, and scripted models,
|
|
3
|
+
* recorded model exchanges and the end checks that test an agent's tools.
|
|
4
|
+
*
|
|
5
|
+
* @stability stable
|
|
6
|
+
* @since 0.3.0
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @stability stable
|
|
11
|
+
* @since 0.3.0
|
|
12
|
+
*/
|
|
13
|
+
export * as HttpCassette from "./HttpCassette.ts";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @stability stable
|
|
17
|
+
* @since 0.3.0
|
|
18
|
+
*/
|
|
19
|
+
export * as Story from "./Story.ts";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @stability stable
|
|
23
|
+
* @since 0.3.0
|
|
24
|
+
*/
|
|
2
25
|
export * as TestBrowser from "./TestBrowser.ts";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @stability stable
|
|
29
|
+
* @since 0.3.0
|
|
30
|
+
*/
|
|
31
|
+
export * as TestModel from "./TestModel.ts";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @stability stable
|
|
35
|
+
* @since 0.3.0
|
|
36
|
+
*/
|
|
3
37
|
export * as TestPage from "./TestPage.ts";
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/** Explicit picture and change evidence; bounded delivery and the production change fold. */
|
|
2
|
-
import { Duration, Effect, Option, PubSub, Stream, type Take } from "effect";
|
|
3
|
-
|
|
4
|
-
import { type BrowserError, InvalidRequest, NotFound, undispatched } from "
|
|
5
|
-
import { Change, Changes } from "
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { Duration, Effect, Option, PubSub, type Scope, Stream, type Take } from "effect";
|
|
3
|
+
|
|
4
|
+
import { type BrowserError, InvalidRequest, NotFound, undispatched } from "../../BrowserError.ts";
|
|
5
|
+
import { Change, Changes, type ChangesOptions } from "../../Change.ts";
|
|
6
|
+
import {
|
|
7
|
+
type Capture,
|
|
8
|
+
type Frame,
|
|
9
|
+
type FrameOptions,
|
|
10
|
+
sameCapture,
|
|
11
|
+
type ScreencastOptions,
|
|
12
|
+
} from "../../Frame.ts";
|
|
13
|
+
import { fold } from "../../internal/timeline/fold.inpage.ts";
|
|
9
14
|
import * as Model from "./model.ts";
|
|
10
15
|
|
|
11
16
|
export const make = Effect.fnUntraced(function* (options: {
|
|
@@ -46,9 +51,12 @@ export const make = Effect.fnUntraced(function* (options: {
|
|
|
46
51
|
yield* PubSub.publish(feed, [frame]);
|
|
47
52
|
});
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
// A seeded page shows only the frames its story emits, so its newest current one is the frame
|
|
55
|
+
// after its latest input too; a new picture, as a PNG or in device pixels, it cannot take.
|
|
56
|
+
const frame = (asked?: FrameOptions): Effect.Effect<Frame, BrowserError> =>
|
|
50
57
|
Effect.suspend(() => {
|
|
51
|
-
if (asked?.
|
|
58
|
+
if (asked?.format === "png") return unsupported("frame:format");
|
|
59
|
+
if (asked?.scale === "device") return unsupported("frame:scale");
|
|
52
60
|
const age = Duration.fromInput(asked?.maxAge ?? Duration.millis(250));
|
|
53
61
|
|
|
54
62
|
const found = frames.findLast(
|
|
@@ -63,7 +71,7 @@ export const make = Effect.fnUntraced(function* (options: {
|
|
|
63
71
|
: Effect.as(model.check("frame"), found);
|
|
64
72
|
});
|
|
65
73
|
|
|
66
|
-
const changes
|
|
74
|
+
const changes = (asked?: ChangesOptions): Effect.Effect<Changes, BrowserError> =>
|
|
67
75
|
Effect.gen(function* () {
|
|
68
76
|
yield* model.check("changes");
|
|
69
77
|
const start = asked?.since;
|
|
@@ -118,7 +126,7 @@ export const make = Effect.fnUntraced(function* (options: {
|
|
|
118
126
|
});
|
|
119
127
|
});
|
|
120
128
|
|
|
121
|
-
const capture
|
|
129
|
+
const capture = (asked?: ScreencastOptions): Effect.Effect<Capture, BrowserError, Scope.Scope> =>
|
|
122
130
|
asked?.quality === undefined && asked?.size === undefined
|
|
123
131
|
? Effect.gen(function* () {
|
|
124
132
|
yield* model.check("capture");
|
|
@@ -7,14 +7,20 @@ import {
|
|
|
7
7
|
InvalidRequest,
|
|
8
8
|
StaleRef,
|
|
9
9
|
undispatched,
|
|
10
|
-
} from "
|
|
11
|
-
import type { Box, Subject, DisconnectCause } from "
|
|
12
|
-
import type { Frame } from "
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
17
|
-
|
|
10
|
+
} from "../../BrowserError.ts";
|
|
11
|
+
import type { Box, Subject, DisconnectCause } from "../../BrowserEvent.ts";
|
|
12
|
+
import type { Frame } from "../../Frame.ts";
|
|
13
|
+
import { match, request } from "../../internal/matching.ts";
|
|
14
|
+
import type { Sample, Shown, Track } from "../../internal/timeline/fold.inpage.ts";
|
|
15
|
+
import * as Url from "../../internal/url.ts";
|
|
16
|
+
import {
|
|
17
|
+
Control,
|
|
18
|
+
type ElementState,
|
|
19
|
+
type FindQuery,
|
|
20
|
+
Found,
|
|
21
|
+
Snapshot,
|
|
22
|
+
type SnapshotOptions,
|
|
23
|
+
} from "../../Snapshot.ts";
|
|
18
24
|
|
|
19
25
|
/** Unsupported browser mechanics stay typed failures instead of inferred successes. */
|
|
20
26
|
export const unsupported = (operation: string) =>
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/** A scoped, seeded Page for deterministic stories. Effects are explicit data, never page code. */
|
|
2
|
-
import { Clock, Deferred, Duration, Effect, Exit, Scope
|
|
3
|
-
|
|
4
|
-
import { type Action, nameOf, targetOf, recorded } from "
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { monotonicMillis } from "
|
|
9
|
-
import type { Gate } from "
|
|
10
|
-
import
|
|
11
|
-
import * as
|
|
12
|
-
import
|
|
13
|
-
import * as Url from "
|
|
2
|
+
import { Clock, Deferred, Duration, Effect, Exit, Scope } from "effect";
|
|
3
|
+
|
|
4
|
+
import { type Action, nameOf, targetOf, recorded } from "../../Action.ts";
|
|
5
|
+
import { type BrowserError, Closed, NotActionable, undispatched } from "../../BrowserError.ts";
|
|
6
|
+
import * as Events from "../../BrowserEvent.ts";
|
|
7
|
+
import { checked, methods } from "../../internal/action-port.ts";
|
|
8
|
+
import { monotonicMillis } from "../../internal/clock.ts";
|
|
9
|
+
import type { Gate } from "../../internal/input/gate.ts";
|
|
10
|
+
import { Implementation, key } from "../../internal/page/functions.ts";
|
|
11
|
+
import * as Lane from "../../internal/page/lane.ts";
|
|
12
|
+
import * as Timeline from "../../internal/timeline/events.ts";
|
|
13
|
+
import * as Url from "../../internal/url.ts";
|
|
14
|
+
import { type Page, ResolvedTarget, State } from "../../Page.ts";
|
|
15
|
+
import type { FindQuery, UntilResult, UntilWant } from "../../Snapshot.ts";
|
|
16
|
+
import { Text } from "../../Text.ts";
|
|
14
17
|
import * as Evidence from "./evidence.ts";
|
|
15
18
|
import * as Model from "./model.ts";
|
|
16
19
|
|
|
@@ -180,8 +183,8 @@ const execution = (
|
|
|
180
183
|
|
|
181
184
|
/** Wait admission follows preceding input, then releases the lane while observing new evidence. */
|
|
182
185
|
const untilFor =
|
|
183
|
-
(model: ReturnType<typeof Model.make>, lane: Lane.Lane, now: () => number)
|
|
184
|
-
(query, want, millis) =>
|
|
186
|
+
(model: ReturnType<typeof Model.make>, lane: Lane.Lane, now: () => number) =>
|
|
187
|
+
(query: FindQuery, want: UntilWant, millis: number) =>
|
|
185
188
|
lane
|
|
186
189
|
.read("until")(Effect.void)
|
|
187
190
|
.pipe(
|
|
@@ -263,11 +266,47 @@ export const makeIn = Effect.fnUntraced(function* (
|
|
|
263
266
|
const perform: Page["perform"] = checked((action) => own(run.perform(action)));
|
|
264
267
|
|
|
265
268
|
const page: Page = {
|
|
269
|
+
[key]: new Implementation({
|
|
270
|
+
until: (query, want, millis) => own(untilFor(model, lane, now)(query, want, millis)),
|
|
271
|
+
find: (query) =>
|
|
272
|
+
query?.selector !== undefined
|
|
273
|
+
? unsupported("find:selector")
|
|
274
|
+
: read("find", () => model.find(query)),
|
|
275
|
+
snapshot: (options) =>
|
|
276
|
+
options?.within !== undefined
|
|
277
|
+
? unsupported("snapshot:within")
|
|
278
|
+
: read("snapshot", () => model.snapshot(options)),
|
|
279
|
+
text: (options) =>
|
|
280
|
+
options?.scope !== undefined && options.scope !== "viewport"
|
|
281
|
+
? unsupported("text:scope")
|
|
282
|
+
: read("text", () => {
|
|
283
|
+
const snapshot = model.snapshot({ maxChars: options?.maxChars });
|
|
284
|
+
|
|
285
|
+
return new Text({
|
|
286
|
+
url: snapshot.url,
|
|
287
|
+
title: snapshot.title,
|
|
288
|
+
text: snapshot.text,
|
|
289
|
+
truncated: snapshot.truncated,
|
|
290
|
+
at: now(),
|
|
291
|
+
});
|
|
292
|
+
}),
|
|
293
|
+
layout: () => unsupported("layout"),
|
|
294
|
+
overlay: unsupported("overlay"),
|
|
295
|
+
drawn: Effect.succeedNone,
|
|
296
|
+
poses: unsupported("poses"),
|
|
297
|
+
hold: unsupported("hold"),
|
|
298
|
+
changes: evidence.changes,
|
|
299
|
+
window: () => unsupported("window"),
|
|
300
|
+
frame: evidence.frame,
|
|
301
|
+
zoom: () => unsupported("zoom"),
|
|
302
|
+
capture: evidence.capture,
|
|
303
|
+
recentFrames: evidence.recentFrames,
|
|
304
|
+
paint: () => unsupported("paint"),
|
|
305
|
+
}),
|
|
266
306
|
...methods(perform),
|
|
267
307
|
id,
|
|
268
|
-
clock,
|
|
308
|
+
hostClock: clock,
|
|
269
309
|
perform,
|
|
270
|
-
until: (query, want, millis) => own(untilFor(model, lane, now)(query, want, millis)),
|
|
271
310
|
afterInput: (effect) => own(lane.read("afterInput")(effect)),
|
|
272
311
|
read: () => unsupported("read"),
|
|
273
312
|
act: () => unsupported("act"),
|
|
@@ -281,28 +320,6 @@ export const makeIn = Effect.fnUntraced(function* (
|
|
|
281
320
|
}),
|
|
282
321
|
evidence.close,
|
|
283
322
|
),
|
|
284
|
-
find: (query) =>
|
|
285
|
-
query?.selector !== undefined
|
|
286
|
-
? unsupported("find:selector")
|
|
287
|
-
: read("find", () => model.find(query)),
|
|
288
|
-
snapshot: (options) =>
|
|
289
|
-
options?.within !== undefined
|
|
290
|
-
? unsupported("snapshot:within")
|
|
291
|
-
: read("snapshot", () => model.snapshot(options)),
|
|
292
|
-
text: (options) =>
|
|
293
|
-
options?.scope !== undefined && options.scope !== "viewport"
|
|
294
|
-
? unsupported("text:scope")
|
|
295
|
-
: read("text", () => {
|
|
296
|
-
const snapshot = model.snapshot({ maxChars: options?.maxChars });
|
|
297
|
-
|
|
298
|
-
return new Text({
|
|
299
|
-
url: snapshot.url,
|
|
300
|
-
title: snapshot.title,
|
|
301
|
-
text: snapshot.text,
|
|
302
|
-
truncated: snapshot.truncated,
|
|
303
|
-
at: now(),
|
|
304
|
-
});
|
|
305
|
-
}),
|
|
306
323
|
viewport: read("viewport", () => model.get().viewport ?? { width: 800, height: 600 }),
|
|
307
324
|
state: Effect.sync(
|
|
308
325
|
() =>
|
|
@@ -314,26 +331,8 @@ export const makeIn = Effect.fnUntraced(function* (
|
|
|
314
331
|
url: Url.redact(model.get().url ?? "about:blank"),
|
|
315
332
|
}),
|
|
316
333
|
),
|
|
317
|
-
screenshot: (options) =>
|
|
318
|
-
options === undefined
|
|
319
|
-
? Effect.map(evidence.frame(), (frame) => frame.image)
|
|
320
|
-
: unsupported("screenshot"),
|
|
321
|
-
frame: evidence.frame,
|
|
322
|
-
zoom: () => unsupported("zoom"),
|
|
323
|
-
layout: () => unsupported("layout"),
|
|
324
|
-
overlay: unsupported("overlay"),
|
|
325
|
-
poses: unsupported("poses"),
|
|
326
|
-
hold: unsupported("hold"),
|
|
327
|
-
paint: () => unsupported("paint"),
|
|
328
334
|
ready: () =>
|
|
329
335
|
model.get().ready === true ? read("ready", () => undefined) : unsupported("ready"),
|
|
330
|
-
capture: evidence.capture,
|
|
331
|
-
screencast: (options) =>
|
|
332
|
-
Stream.unwrap(Effect.map(evidence.capture(options), (capture) => capture.stream)),
|
|
333
|
-
captureStats: () => unsupported("captureStats"),
|
|
334
|
-
recentFrames: evidence.recentFrames,
|
|
335
|
-
changes: evidence.changes,
|
|
336
|
-
window: () => unsupported("window"),
|
|
337
336
|
recentEvents: Effect.map(timeline.recent, (records) =>
|
|
338
337
|
records
|
|
339
338
|
.filter((record) => "page" in record.event && record.event.page === id)
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A page's timeline has three tracks on its browser's host clock: its events, what visibly changed
|
|
5
5
|
* on it (`Change`), and its screencast frames. A `Window` holds the three from `since` to `until`,
|
|
6
|
-
* and says why a part it could not read is missing rather than fail. `
|
|
6
|
+
* and says why a part it could not read is missing rather than fail. `Window.read` takes one, which
|
|
7
7
|
* can end in the past, at a frame a delayed consumer airs late, so that a line written now tells
|
|
8
8
|
* what its viewers will see. Its `account` says what was so at its end: how long the page had been
|
|
9
9
|
* still, which of its changes were still under way, and which had settled.
|
|
10
10
|
*
|
|
11
|
-
* A `Moment` is a window that ends at a picture of the page now: `
|
|
11
|
+
* A `Moment` is a window that ends at a picture of the page now: `read` takes the picture, then
|
|
12
12
|
* the window up to it, and on request the page's outline. `toPrompt` turns a moment into one user
|
|
13
13
|
* message for any `effect/ai` call: a structured answer from `LanguageModel.generateObject`, a
|
|
14
14
|
* caption from `generateText`, or one turn of a `Chat` that follows moment after moment. It leads
|
|
@@ -22,38 +22,55 @@
|
|
|
22
22
|
* A moment's picture is the newest frame if it was painted after the page's latest input and
|
|
23
23
|
* completed action, at most 250 ms ago, else a new screenshot timed by its capture.
|
|
24
24
|
*
|
|
25
|
+
* @stability stable
|
|
25
26
|
* @since 0.3.0
|
|
26
27
|
*/
|
|
27
|
-
import { Duration, Effect, Option, Result, Schema } from "effect";
|
|
28
|
+
import { Duration, Effect, Function, Option, Result, Schema } from "effect";
|
|
28
29
|
import { Prompt } from "effect/ai";
|
|
29
30
|
|
|
30
|
-
import { refuse } from "../BrowserError.ts";
|
|
31
|
+
import { type BrowserError, refuse } from "../BrowserError.ts";
|
|
31
32
|
import { type Action } from "../BrowserEvent.ts";
|
|
32
33
|
import { type Change, type Changes } from "../Change.ts";
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import { describe, named, quoted, where } from "./words.ts";
|
|
34
|
+
import * as Frame from "../Frame.ts";
|
|
35
|
+
import * as Page from "../Page.ts";
|
|
36
|
+
import * as Snapshot from "../Snapshot.ts";
|
|
37
|
+
import { describe, named, quoted, where } from "./internal/words.ts";
|
|
37
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @stability stable
|
|
41
|
+
* @category schemas
|
|
42
|
+
* @since 0.3.0
|
|
43
|
+
*/
|
|
38
44
|
export { Window } from "../Window.ts";
|
|
39
|
-
import
|
|
45
|
+
import * as Window from "../Window.ts";
|
|
40
46
|
|
|
41
47
|
/**
|
|
42
48
|
* A window that ends at a picture of the page, its last frame, unless `missing` says why it has
|
|
43
49
|
* none. Its frames are a few, spread over the window, so that it still begins where it starts.
|
|
50
|
+
*
|
|
51
|
+
* @stability stable
|
|
52
|
+
* @category schemas
|
|
53
|
+
* @since 0.3.0
|
|
44
54
|
*/
|
|
45
|
-
export class Moment extends Window.extend<Moment>("effect-browser/Moment")({
|
|
46
|
-
/** The page's outline at the end of the window, when the
|
|
47
|
-
snapshot: Schema.optional(Snapshot),
|
|
55
|
+
export class Moment extends Window.Window.extend<Moment>("effect-browser/timeline/Moment")({
|
|
56
|
+
/** The page's outline at the end of the window, when the read asked for it. */
|
|
57
|
+
snapshot: Schema.optional(Snapshot.Snapshot),
|
|
48
58
|
}) {}
|
|
49
59
|
|
|
50
|
-
|
|
60
|
+
/**
|
|
61
|
+
* What `read` reads: where its window starts, how many frames it keeps, and the outline.
|
|
62
|
+
*
|
|
63
|
+
* @stability stable
|
|
64
|
+
* @category options
|
|
65
|
+
* @since 0.3.0
|
|
66
|
+
*/
|
|
67
|
+
export interface MomentOptions {
|
|
51
68
|
/**
|
|
52
|
-
* Where the window starts, as for `
|
|
69
|
+
* Where the window starts, as for `Window.read`: a previous window or moment, so that consecutive
|
|
53
70
|
* ones neither repeat nor miss an event or a change, or a `Duration` back from the picture.
|
|
54
71
|
* Defaults to 5 seconds.
|
|
55
72
|
*/
|
|
56
|
-
readonly since?:
|
|
73
|
+
readonly since?: Window.WindowOptions["since"] | undefined;
|
|
57
74
|
/** Frames to keep, at least 1, spread over the window and ending with the picture. Defaults to 2. */
|
|
58
75
|
readonly frames?: number | undefined;
|
|
59
76
|
/**
|
|
@@ -61,36 +78,36 @@ export interface CaptureOptions {
|
|
|
61
78
|
* Defaults to `false`: the frames and the timeline carry most moments, while an outline costs a
|
|
62
79
|
* round trip to the page and can double a moment's tokens.
|
|
63
80
|
*/
|
|
64
|
-
readonly snapshot?: SnapshotOptions | boolean | undefined;
|
|
81
|
+
readonly snapshot?: Snapshot.SnapshotOptions | boolean | undefined;
|
|
65
82
|
/** Show what fields hold in the moment's changes; a secret field still reads `••••`. */
|
|
66
83
|
readonly unmask?: boolean | undefined;
|
|
67
84
|
}
|
|
68
85
|
|
|
69
86
|
/** Pick `count` frames spread evenly over `frames`, always including the last. */
|
|
70
|
-
const spread = (frames: ReadonlyArray<Frame>, count: number): ReadonlyArray<Frame> => {
|
|
87
|
+
const spread = (frames: ReadonlyArray<Frame.Frame>, count: number): ReadonlyArray<Frame.Frame> => {
|
|
71
88
|
if (frames.length <= count) return frames;
|
|
72
89
|
if (count <= 1) return frames.slice(-1);
|
|
73
90
|
const step = (frames.length - 1) / (count - 1);
|
|
74
91
|
|
|
75
92
|
return Array.from({ length: count }, (_, index) => frames[Math.round(index * step)]).filter(
|
|
76
|
-
(frame): frame is Frame => frame !== undefined,
|
|
93
|
+
(frame): frame is Frame.Frame => frame !== undefined,
|
|
77
94
|
);
|
|
78
95
|
};
|
|
79
96
|
|
|
80
97
|
// An action ends after its navigation settles, which can follow the last paint. A fresh picture
|
|
81
98
|
// keeps that completed action inside the moment without moving events between adjacent windows.
|
|
82
99
|
const pictureOf = Effect.fnUntraced(function* (page: Page.Page) {
|
|
83
|
-
const frame = yield*
|
|
100
|
+
const frame = yield* Frame.read(page, { after: "input" });
|
|
84
101
|
const events = yield* page.recentEvents;
|
|
85
102
|
|
|
86
103
|
return events.some((event) => event._tag === "Action" && event.at > frame.hostTime)
|
|
87
|
-
? yield*
|
|
104
|
+
? yield* Frame.read(page, { maxAge: 0 })
|
|
88
105
|
: frame;
|
|
89
106
|
});
|
|
90
107
|
|
|
91
|
-
|
|
108
|
+
const readMoment = Effect.fn("Moment.read")(function* (
|
|
92
109
|
page: Page.Page,
|
|
93
|
-
options:
|
|
110
|
+
options: MomentOptions = {},
|
|
94
111
|
) {
|
|
95
112
|
const count = options.frames ?? 2;
|
|
96
113
|
|
|
@@ -106,7 +123,7 @@ export const capture = Effect.fn("Moment.capture")(function* (
|
|
|
106
123
|
pictured: Effect.result(pictureOf(page)).pipe(
|
|
107
124
|
Effect.flatMap((picture) =>
|
|
108
125
|
Effect.map(
|
|
109
|
-
|
|
126
|
+
Window.read(page, {
|
|
110
127
|
since: options.since ?? Duration.seconds(5),
|
|
111
128
|
until: Result.getOrUndefined(picture),
|
|
112
129
|
unmask: options.unmask,
|
|
@@ -118,7 +135,7 @@ export const capture = Effect.fn("Moment.capture")(function* (
|
|
|
118
135
|
outlined: Effect.result(
|
|
119
136
|
outline === false
|
|
120
137
|
? Effect.void
|
|
121
|
-
:
|
|
138
|
+
: Snapshot.read(page, { maxChars: 4000, ...(outline === true ? {} : outline) }),
|
|
122
139
|
),
|
|
123
140
|
},
|
|
124
141
|
{ concurrency: 2 },
|
|
@@ -144,11 +161,30 @@ export const capture = Effect.fn("Moment.capture")(function* (
|
|
|
144
161
|
});
|
|
145
162
|
});
|
|
146
163
|
|
|
164
|
+
/**
|
|
165
|
+
* A moment of the page now: its picture, the window up to it, and the outline if asked. What
|
|
166
|
+
* cannot be read is missing from the moment, with why, rather than failing it.
|
|
167
|
+
*
|
|
168
|
+
* @stability stable
|
|
169
|
+
* @category constructors
|
|
170
|
+
* @since 0.3.0
|
|
171
|
+
*/
|
|
172
|
+
export const read: {
|
|
173
|
+
(options?: MomentOptions): (page: Page.Page) => Effect.Effect<Moment, BrowserError>;
|
|
174
|
+
(page: Page.Page, options?: MomentOptions): Effect.Effect<Moment, BrowserError>;
|
|
175
|
+
} = Function.dual((args) => Page.isPage(args[0]), readMoment);
|
|
176
|
+
|
|
147
177
|
/** A window's record of changes, if it saw any of the window: a page's first has none. */
|
|
148
|
-
const recordOf = ({ changes }: Window) =>
|
|
178
|
+
const recordOf = ({ changes }: Window.Window) =>
|
|
149
179
|
changes !== undefined && changes.from < changes.until ? changes : undefined;
|
|
150
180
|
|
|
151
|
-
/**
|
|
181
|
+
/**
|
|
182
|
+
* What a window says of its page at its end: what was still in flux, and what had settled.
|
|
183
|
+
*
|
|
184
|
+
* @stability stable
|
|
185
|
+
* @category models
|
|
186
|
+
* @since 0.3.0
|
|
187
|
+
*/
|
|
152
188
|
export interface Account {
|
|
153
189
|
/**
|
|
154
190
|
* How long, in milliseconds, the page had been still at the end: since the last change in view
|
|
@@ -184,8 +220,12 @@ const underWay = (change: Change, until: number) => {
|
|
|
184
220
|
* An account of the window's page at its end: how long it had been still, and which of its
|
|
185
221
|
* changes were still under way and which had settled. A window whose record saw none of it has
|
|
186
222
|
* neither.
|
|
223
|
+
*
|
|
224
|
+
* @stability stable
|
|
225
|
+
* @category combinators
|
|
226
|
+
* @since 0.3.0
|
|
187
227
|
*/
|
|
188
|
-
export const account = (window: Window): Account => {
|
|
228
|
+
export const account = (window: Window.Window): Account => {
|
|
189
229
|
const record = recordOf(window);
|
|
190
230
|
const changes = record?.changes ?? [];
|
|
191
231
|
|
|
@@ -426,6 +466,10 @@ const happened = (moment: Moment): ReadonlyArray<string> => {
|
|
|
426
466
|
* frames captioned with their times, the last one "the moment" where it is the picture at its end.
|
|
427
467
|
* Give a model its task with `Prompt.setSystem`, and add what the caller knows about the page as
|
|
428
468
|
* more text.
|
|
469
|
+
*
|
|
470
|
+
* @stability stable
|
|
471
|
+
* @category combinators
|
|
472
|
+
* @since 0.3.0
|
|
429
473
|
*/
|
|
430
474
|
export const toPrompt = (moment: Moment): Prompt.Prompt => {
|
|
431
475
|
const count = moment.frames.length;
|
|
@@ -465,5 +509,11 @@ export const toPrompt = (moment: Moment): Prompt.Prompt => {
|
|
|
465
509
|
]);
|
|
466
510
|
};
|
|
467
511
|
|
|
468
|
-
/**
|
|
469
|
-
|
|
512
|
+
/**
|
|
513
|
+
* Describe one change using the same prose as moment prompts.
|
|
514
|
+
*
|
|
515
|
+
* @stability stable
|
|
516
|
+
* @category combinators
|
|
517
|
+
* @since 0.3.0
|
|
518
|
+
*/
|
|
519
|
+
export { describe as describeChange } from "./internal/words.ts";
|