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/policy/Policy.ts
CHANGED
|
@@ -14,15 +14,22 @@
|
|
|
14
14
|
* whatever the judge reads. A judge that fails or runs out of time leaves the input unjudged,
|
|
15
15
|
* which `make` refuses.
|
|
16
16
|
*
|
|
17
|
+
* @stability stable
|
|
17
18
|
* @since 0.3.0
|
|
18
19
|
*/
|
|
19
|
-
import { Cause, Context, Duration, Effect, Record, Result, Schema } from "effect";
|
|
20
|
+
import { Cause, Context, Duration, Effect, Function, Record, Result, Schema } from "effect";
|
|
20
21
|
import { type AiError, Decision, DecisionModel, LanguageModel, Prompt } from "effect/ai";
|
|
21
22
|
|
|
22
23
|
import { PolicyDenied } from "../BrowserError.ts";
|
|
23
24
|
import { Fact, type InputGuard, InputRequest } from "../Page.ts";
|
|
24
25
|
|
|
25
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* What an input means. Only a judge reading the evidence can recognise these.
|
|
28
|
+
*
|
|
29
|
+
* @stability stable
|
|
30
|
+
* @category schemas
|
|
31
|
+
* @since 0.3.0
|
|
32
|
+
*/
|
|
26
33
|
export const Risk = Schema.Literals([
|
|
27
34
|
"financial",
|
|
28
35
|
"account",
|
|
@@ -32,6 +39,11 @@ export const Risk = Schema.Literals([
|
|
|
32
39
|
"secret",
|
|
33
40
|
]);
|
|
34
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @stability stable
|
|
44
|
+
* @category models
|
|
45
|
+
* @since 0.3.0
|
|
46
|
+
*/
|
|
35
47
|
export type Risk = typeof Risk.Type;
|
|
36
48
|
|
|
37
49
|
// What each risk covers, in the words both judges are given.
|
|
@@ -48,8 +60,14 @@ const covers: { readonly [K in Risk]: string } = {
|
|
|
48
60
|
|
|
49
61
|
const Probability = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 1 }));
|
|
50
62
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
63
|
+
/**
|
|
64
|
+
* A judge's reading of one input.
|
|
65
|
+
*
|
|
66
|
+
* @stability stable
|
|
67
|
+
* @category schemas
|
|
68
|
+
* @since 0.3.0
|
|
69
|
+
*/
|
|
70
|
+
export class Judgement extends Schema.Class<Judgement>("effect-browser/policy/Policy/Judgement")({
|
|
53
71
|
/** For each risk, the probability that the input does it. */
|
|
54
72
|
risks: Schema.Struct({
|
|
55
73
|
financial: Probability,
|
|
@@ -68,12 +86,22 @@ export class Judgement extends Schema.Class<Judgement>("effect-browser/Judgement
|
|
|
68
86
|
/**
|
|
69
87
|
* The user's task: what authorizes a risky input. `PageControl` provides its task to every input it
|
|
70
88
|
* makes; provide one around other calls with `Effect.provideService`.
|
|
89
|
+
*
|
|
90
|
+
* @stability stable
|
|
91
|
+
* @category services
|
|
92
|
+
* @since 0.3.0
|
|
71
93
|
*/
|
|
72
|
-
export const Task = Context.Reference<string | undefined>("effect-browser/Policy/Task", {
|
|
94
|
+
export const Task = Context.Reference<string | undefined>("effect-browser/policy/Policy/Task", {
|
|
73
95
|
defaultValue: () => undefined,
|
|
74
96
|
});
|
|
75
97
|
|
|
76
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Reads what an input means, with the user's task from `Task`.
|
|
100
|
+
*
|
|
101
|
+
* @stability stable
|
|
102
|
+
* @category models
|
|
103
|
+
* @since 0.3.0
|
|
104
|
+
*/
|
|
77
105
|
export type Judge = (request: InputRequest) => Effect.Effect<Judgement, AiError.AiError>;
|
|
78
106
|
|
|
79
107
|
/** What a judge is shown. Everything under `evidence` is the page's to write. */
|
|
@@ -148,6 +176,10 @@ const unit = (value: number) => Math.min(1, Math.max(0, value));
|
|
|
148
176
|
/**
|
|
149
177
|
* A judge that asks the `LanguageModel` in context for a structured review. `rules` adds the
|
|
150
178
|
* user's own policy in plain words, such as "Purchases under $20 are fine".
|
|
179
|
+
*
|
|
180
|
+
* @stability stable
|
|
181
|
+
* @category constructors
|
|
182
|
+
* @since 0.3.0
|
|
151
183
|
*/
|
|
152
184
|
export const reviewer = Effect.fnUntraced(function* (
|
|
153
185
|
options: { readonly rules?: string | undefined } = {},
|
|
@@ -196,6 +228,10 @@ const decisions = Decision.make({
|
|
|
196
228
|
* A judge that answers one probability per risk from the `DecisionModel` in context, all in one
|
|
197
229
|
* call. Jev is one: `TypeSafeDecisionModel.layer({ model: "jev-1.13.0" })` from
|
|
198
230
|
* `@effect/ai-typesafe` provides it.
|
|
231
|
+
*
|
|
232
|
+
* @stability stable
|
|
233
|
+
* @category constructors
|
|
234
|
+
* @since 0.3.0
|
|
199
235
|
*/
|
|
200
236
|
export const decider: Effect.Effect<Judge, never, DecisionModel.DecisionModel> = Effect.gen(
|
|
201
237
|
function* () {
|
|
@@ -219,19 +255,33 @@ const unsure = (value: number) => value > 0.2 && value < 0.8;
|
|
|
219
255
|
/**
|
|
220
256
|
* `first`'s judgement, or `second`'s when `first` is unsure: a risk between 0.2 and 0.8, or a
|
|
221
257
|
* likely risk whose request is. A confident mistake by `first` stands.
|
|
258
|
+
*
|
|
259
|
+
* @stability stable
|
|
260
|
+
* @category combinators
|
|
261
|
+
* @since 0.3.0
|
|
222
262
|
*/
|
|
223
|
-
export const escalate
|
|
263
|
+
export const escalate: {
|
|
264
|
+
(second: Judge): (first: Judge) => Judge;
|
|
265
|
+
(first: Judge, second: Judge): Judge;
|
|
266
|
+
} = Function.dual(
|
|
267
|
+
2,
|
|
224
268
|
(first: Judge, second: Judge): Judge =>
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
269
|
+
(request) =>
|
|
270
|
+
Effect.flatMap(first(request), (judgement) => {
|
|
271
|
+
const risks = Object.values(judgement.risks);
|
|
272
|
+
|
|
273
|
+
return risks.some(unsure) ||
|
|
274
|
+
(risks.some((value) => value >= 0.5) && unsure(judgement.requested ?? 0))
|
|
275
|
+
? second(request)
|
|
276
|
+
: Effect.succeed(judgement);
|
|
277
|
+
}),
|
|
278
|
+
);
|
|
234
279
|
|
|
280
|
+
/**
|
|
281
|
+
* @stability stable
|
|
282
|
+
* @category options
|
|
283
|
+
* @since 0.3.0
|
|
284
|
+
*/
|
|
235
285
|
export interface Options {
|
|
236
286
|
/** Reads what an input means. Without one, only origins and facts decide. */
|
|
237
287
|
readonly judge?: Judge | undefined;
|
|
@@ -260,6 +310,10 @@ const originOf = (url: string) => {
|
|
|
260
310
|
* input on a page or towards a destination outside `origins`, input with a fact in `deny`, and,
|
|
261
311
|
* when a judge finds a risk, input the task does not ask for. An input the judge could not judge
|
|
262
312
|
* in time is denied with the judge's failure as the denial's cause.
|
|
313
|
+
*
|
|
314
|
+
* @stability stable
|
|
315
|
+
* @category constructors
|
|
316
|
+
* @since 0.3.0
|
|
263
317
|
*/
|
|
264
318
|
export const make = (options: Options = {}): InputGuard => {
|
|
265
319
|
const threshold = options.threshold ?? 0.5;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Filming a page as a function of time: a new screenshot at each time a caller asks for, of the
|
|
3
3
|
* page as it is at that film time, with what the caller draws over it then. Film time comes from
|
|
4
|
-
* a held page (`
|
|
4
|
+
* a held page (`PageTime.hold`), which steps to each frame however long the last one took, so a
|
|
5
5
|
* frame costs one call to step the page and one screenshot; from a page that seeks itself; or
|
|
6
6
|
* from real time. The frames are pictures; encoding them is the caller's.
|
|
7
7
|
*
|
|
@@ -9,27 +9,38 @@
|
|
|
9
9
|
* first frame that finds one waits for it to be ready, measures its layout, and says so as a
|
|
10
10
|
* `Passage`, which `at` sees from then on. On real time the film's start moves on by the wait.
|
|
11
11
|
*
|
|
12
|
+
* @stability experimental
|
|
12
13
|
* @since 0.3.0
|
|
13
14
|
*/
|
|
14
|
-
import { Clock, Duration, Effect, Schema, Stream } from "effect";
|
|
15
|
+
import { Clock, Duration, Effect, Function, Schema, Stream } from "effect";
|
|
15
16
|
|
|
16
17
|
import { Action } from "../Action.ts";
|
|
17
18
|
import { type BrowserError, refuse } from "../BrowserError.ts";
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import { Point } from "../
|
|
21
|
-
import
|
|
19
|
+
import * as Frame from "../Frame.ts";
|
|
20
|
+
import { monotonicMillis } from "../internal/clock.ts";
|
|
21
|
+
import { Point } from "../internal/geometry.ts";
|
|
22
|
+
import * as Layout from "../Layout.ts";
|
|
22
23
|
import type { Content, Overlay } from "../Overlay.ts";
|
|
23
|
-
import { type Page, ResolvedTarget
|
|
24
|
+
import { type Page, ResolvedTarget } from "../Page.ts";
|
|
24
25
|
import type { Held, Step } from "../PageTime.ts";
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* What a frame shows over the page, and, on held time, where the page is scrolled to then and how
|
|
28
29
|
* its elements are posed, with the page's poses open.
|
|
30
|
+
*
|
|
31
|
+
* @stability experimental
|
|
32
|
+
* @category models
|
|
33
|
+
* @since 0.3.0
|
|
29
34
|
*/
|
|
30
35
|
export type At = Step;
|
|
31
36
|
|
|
32
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Frames at `fps` from `from` (0 by default) until before `to`, or at these times, in ms.
|
|
39
|
+
*
|
|
40
|
+
* @stability experimental
|
|
41
|
+
* @category models
|
|
42
|
+
* @since 0.3.0
|
|
43
|
+
*/
|
|
33
44
|
export type Times =
|
|
34
45
|
| { readonly fps: number; readonly from?: number | undefined; readonly to: number }
|
|
35
46
|
| ReadonlyArray<number>;
|
|
@@ -37,12 +48,21 @@ export type Times =
|
|
|
37
48
|
/**
|
|
38
49
|
* Where film time comes from: a held page, stepped to each frame; a page's own seek, given each
|
|
39
50
|
* frame's time; or real time from the film's start, each frame taken when its time comes.
|
|
51
|
+
*
|
|
52
|
+
* @stability experimental
|
|
53
|
+
* @category models
|
|
54
|
+
* @since 0.3.0
|
|
40
55
|
*/
|
|
41
56
|
export type Time =
|
|
42
57
|
| Held
|
|
43
58
|
| { readonly seek: (t: number) => Effect.Effect<void, BrowserError> }
|
|
44
59
|
| "real";
|
|
45
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @stability experimental
|
|
63
|
+
* @category options
|
|
64
|
+
* @since 0.3.0
|
|
65
|
+
*/
|
|
46
66
|
export interface Options<E = never> {
|
|
47
67
|
readonly times: Times;
|
|
48
68
|
readonly time: Time;
|
|
@@ -51,7 +71,7 @@ export interface Options<E = never> {
|
|
|
51
71
|
| ((t: number, film: { readonly passages: ReadonlyArray<Passage> }) => Effect.Effect<At, E>)
|
|
52
72
|
| undefined;
|
|
53
73
|
/** What to measure in each new document the film arrives in. */
|
|
54
|
-
readonly picks?: Picks | undefined;
|
|
74
|
+
readonly picks?: Layout.Picks | undefined;
|
|
55
75
|
/**
|
|
56
76
|
* Inputs sent at their film times, in time order, each before the first frame at or after it:
|
|
57
77
|
* the page is moved to its time, and on held time it answers as its time is stepped on. One that
|
|
@@ -62,9 +82,9 @@ export interface Options<E = never> {
|
|
|
62
82
|
readonly overlay?: Overlay | undefined;
|
|
63
83
|
/**
|
|
64
84
|
* How each frame is taken. For frames with more pixels than the layout, paint the page first
|
|
65
|
-
* (`
|
|
85
|
+
* (`Frame.paint`) and take them at `scale: "device"`.
|
|
66
86
|
*/
|
|
67
|
-
readonly image?: Pick<
|
|
87
|
+
readonly image?: Pick<Frame.FrameOptions, "format" | "quality" | "scale"> | undefined;
|
|
68
88
|
/** How many times a frame's screenshot is taken again after it times out. Defaults to 2. */
|
|
69
89
|
readonly retries?: number | undefined;
|
|
70
90
|
}
|
|
@@ -72,17 +92,34 @@ export interface Options<E = never> {
|
|
|
72
92
|
const Count = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
73
93
|
const Millis = Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0));
|
|
74
94
|
|
|
75
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* An input to send at film time `t`, in ms, with the caller's name for it.
|
|
97
|
+
*
|
|
98
|
+
* @stability experimental
|
|
99
|
+
* @category schemas
|
|
100
|
+
* @since 0.3.0
|
|
101
|
+
*/
|
|
76
102
|
export const Contact = Schema.Struct({
|
|
77
103
|
t: Millis,
|
|
78
104
|
action: Action,
|
|
79
105
|
label: Schema.optional(Schema.String),
|
|
80
106
|
});
|
|
81
107
|
|
|
108
|
+
/**
|
|
109
|
+
* @stability experimental
|
|
110
|
+
* @category models
|
|
111
|
+
* @since 0.3.0
|
|
112
|
+
*/
|
|
82
113
|
export type Contact = typeof Contact.Type;
|
|
83
114
|
|
|
84
|
-
/**
|
|
85
|
-
|
|
115
|
+
/**
|
|
116
|
+
* An input as it was sent, at its film time.
|
|
117
|
+
*
|
|
118
|
+
* @stability experimental
|
|
119
|
+
* @category schemas
|
|
120
|
+
* @since 0.3.0
|
|
121
|
+
*/
|
|
122
|
+
export class Sent extends Schema.Class<Sent>("effect-browser/presentation/Film/Sent")({
|
|
86
123
|
t: Millis,
|
|
87
124
|
label: Schema.optional(Schema.String),
|
|
88
125
|
action: Action,
|
|
@@ -92,8 +129,14 @@ export class Sent extends Schema.Class<Sent>("effect-browser/Sent")({
|
|
|
92
129
|
document: Count,
|
|
93
130
|
}) {}
|
|
94
131
|
|
|
95
|
-
/**
|
|
96
|
-
|
|
132
|
+
/**
|
|
133
|
+
* The page's move to a new document, at the film time of the first frame that found it.
|
|
134
|
+
*
|
|
135
|
+
* @stability experimental
|
|
136
|
+
* @category schemas
|
|
137
|
+
* @since 0.3.0
|
|
138
|
+
*/
|
|
139
|
+
export class Passage extends Schema.Class<Passage>("effect-browser/presentation/Film/Passage")({
|
|
97
140
|
t: Millis,
|
|
98
141
|
/** The address of the document it left. */
|
|
99
142
|
left: Schema.String,
|
|
@@ -102,14 +145,20 @@ export class Passage extends Schema.Class<Passage>("effect-browser/Passage")({
|
|
|
102
145
|
/** Real milliseconds from the film's last step on the page before to the document's being ready. */
|
|
103
146
|
loadedAfter: Millis,
|
|
104
147
|
/** The new document's layout, ready, with the film's `picks`. */
|
|
105
|
-
layout: Layout,
|
|
148
|
+
layout: Layout.Layout,
|
|
106
149
|
}) {}
|
|
107
150
|
|
|
108
|
-
/**
|
|
109
|
-
|
|
151
|
+
/**
|
|
152
|
+
* One frame: its picture at film time `t`, in ms, and what taking it cost in real time.
|
|
153
|
+
*
|
|
154
|
+
* @stability experimental
|
|
155
|
+
* @category schemas
|
|
156
|
+
* @since 0.3.0
|
|
157
|
+
*/
|
|
158
|
+
export class Shot extends Schema.Class<Shot>("effect-browser/presentation/Film/Shot")({
|
|
110
159
|
index: Count,
|
|
111
160
|
t: Millis,
|
|
112
|
-
image: Image,
|
|
161
|
+
image: Frame.Image,
|
|
113
162
|
/** The page's document and address after the picture, as `Page.state` gives them. */
|
|
114
163
|
document: Count,
|
|
115
164
|
url: Schema.String,
|
|
@@ -131,8 +180,14 @@ export class Shot extends Schema.Class<Shot>("effect-browser/Shot")({
|
|
|
131
180
|
at: Schema.Finite,
|
|
132
181
|
}) {}
|
|
133
182
|
|
|
134
|
-
/**
|
|
135
|
-
|
|
183
|
+
/**
|
|
184
|
+
* What a film cost, from its shots.
|
|
185
|
+
*
|
|
186
|
+
* @stability experimental
|
|
187
|
+
* @category schemas
|
|
188
|
+
* @since 0.3.0
|
|
189
|
+
*/
|
|
190
|
+
export class Summary extends Schema.Class<Summary>("effect-browser/presentation/Film/Summary")({
|
|
136
191
|
frames: Count,
|
|
137
192
|
retries: Count,
|
|
138
193
|
/** Real milliseconds, all frames' and the slowest one's. */
|
|
@@ -209,12 +264,12 @@ const mover = (page: Page, time: Time, overlay: Overlay | undefined): Mover => {
|
|
|
209
264
|
time === "real"
|
|
210
265
|
? (t: number) =>
|
|
211
266
|
Effect.suspend(() => {
|
|
212
|
-
const now = monotonicMillis(page.
|
|
267
|
+
const now = monotonicMillis(page.hostClock);
|
|
213
268
|
|
|
214
269
|
start ??= now;
|
|
215
270
|
|
|
216
271
|
return Effect.sleep(Duration.millis(Math.max(0, start + t - now))).pipe(
|
|
217
|
-
Effect.provideService(Clock.Clock, page.
|
|
272
|
+
Effect.provideService(Clock.Clock, page.hostClock),
|
|
218
273
|
);
|
|
219
274
|
})
|
|
220
275
|
: time.seek;
|
|
@@ -244,27 +299,20 @@ const picture = (page: Page, image: Options["image"], retries: number) =>
|
|
|
244
299
|
Effect.gen(function* () {
|
|
245
300
|
let timedOut = 0;
|
|
246
301
|
|
|
247
|
-
const taken = yield*
|
|
302
|
+
const taken = yield* Frame.read(page, { ...image, maxAge: 0 }).pipe(
|
|
248
303
|
Effect.tapError((error) =>
|
|
249
304
|
Effect.sync(() => (timedOut += error.reason._tag === "Timeout" ? 1 : 0)),
|
|
250
305
|
),
|
|
251
306
|
Effect.retry({ times: retries, while: (error) => error.reason._tag === "Timeout" }),
|
|
252
307
|
);
|
|
253
308
|
|
|
254
|
-
return { image: taken, retries: timedOut };
|
|
309
|
+
return { image: taken.image, retries: timedOut };
|
|
255
310
|
});
|
|
256
311
|
|
|
257
312
|
const keyOf = (content: Content | undefined) =>
|
|
258
313
|
content === undefined ? undefined : content._tag === "Svg" ? `svg:${content.markup}` : "empty";
|
|
259
314
|
|
|
260
|
-
|
|
261
|
-
* Frames of `page` at `times`, one at a time: each moves the page to its film time, draws what
|
|
262
|
-
* `at` gives there when it changed, and takes a new screenshot, again after one that times out.
|
|
263
|
-
*/
|
|
264
|
-
export const frames = <E = never>(
|
|
265
|
-
page: Page,
|
|
266
|
-
options: Options<E>,
|
|
267
|
-
): Stream.Stream<Shot, BrowserError | E> =>
|
|
315
|
+
const film = <E = never>(page: Page, options: Options<E>): Stream.Stream<Shot, BrowserError | E> =>
|
|
268
316
|
Stream.unwrap(
|
|
269
317
|
Effect.gen(function* () {
|
|
270
318
|
const times = yield* timesOf(options.times);
|
|
@@ -278,7 +326,7 @@ export const frames = <E = never>(
|
|
|
278
326
|
return yield* refuse(operation, "an input's time is finite and nonnegative");
|
|
279
327
|
let next = 0;
|
|
280
328
|
const { move, skip } = mover(page, options.time, options.overlay);
|
|
281
|
-
const now = () => monotonicMillis(page.
|
|
329
|
+
const now = () => monotonicMillis(page.hostClock);
|
|
282
330
|
const passages: Array<Passage> = [];
|
|
283
331
|
|
|
284
332
|
const at = (t: number) =>
|
|
@@ -299,7 +347,7 @@ export const frames = <E = never>(
|
|
|
299
347
|
|
|
300
348
|
if (document === seen) return undefined;
|
|
301
349
|
yield* page.ready();
|
|
302
|
-
const layout = yield*
|
|
350
|
+
const layout = yield* Layout.measure(page, options.picks ?? {});
|
|
303
351
|
const loadedAfter = now() - stepped;
|
|
304
352
|
|
|
305
353
|
skip(loadedAfter);
|
|
@@ -367,7 +415,26 @@ export const frames = <E = never>(
|
|
|
367
415
|
}),
|
|
368
416
|
);
|
|
369
417
|
|
|
370
|
-
/**
|
|
418
|
+
/**
|
|
419
|
+
* Frames of `page` at `times`, one at a time: each moves the page to its film time, draws what
|
|
420
|
+
* `at` gives there when it changed, and takes a new screenshot, again after one that times out.
|
|
421
|
+
*
|
|
422
|
+
* @stability experimental
|
|
423
|
+
* @category constructors
|
|
424
|
+
* @since 0.3.0
|
|
425
|
+
*/
|
|
426
|
+
export const frames: {
|
|
427
|
+
<E = never>(options: Options<E>): (page: Page) => Stream.Stream<Shot, BrowserError | E>;
|
|
428
|
+
<E = never>(page: Page, options: Options<E>): Stream.Stream<Shot, BrowserError | E>;
|
|
429
|
+
} = Function.dual(2, film);
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Run a film's shots, which a caller has usually written out on the way, to what they cost.
|
|
433
|
+
*
|
|
434
|
+
* @stability experimental
|
|
435
|
+
* @category combinators
|
|
436
|
+
* @since 0.3.0
|
|
437
|
+
*/
|
|
371
438
|
export const summary = <E, R>(shots: Stream.Stream<Shot, E, R>): Effect.Effect<Summary, E, R> =>
|
|
372
439
|
Stream.runFold(
|
|
373
440
|
shots,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Pointer motion as a complete, bounded schedule, independent of browser input and transport. A
|
|
3
3
|
* presenter takes a planner as a value: `lognormal` here, or another, such as recorded strokes.
|
|
4
4
|
*
|
|
5
|
+
* @stability stable
|
|
5
6
|
* @since 0.3.0
|
|
6
7
|
*/
|
|
7
8
|
import { Effect, Random } from "effect";
|
|
@@ -12,10 +13,47 @@ import {
|
|
|
12
13
|
type Point,
|
|
13
14
|
type Sample,
|
|
14
15
|
maximumDurationMillis,
|
|
15
|
-
} from "../
|
|
16
|
+
} from "../internal/geometry.ts";
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
/**
|
|
20
|
+
* @stability stable
|
|
21
|
+
* @category schemas
|
|
22
|
+
* @since 0.3.0
|
|
23
|
+
*/
|
|
24
|
+
Point,
|
|
25
|
+
/**
|
|
26
|
+
* @stability stable
|
|
27
|
+
* @category schemas
|
|
28
|
+
* @since 0.3.0
|
|
29
|
+
*/
|
|
30
|
+
Sample,
|
|
31
|
+
/**
|
|
32
|
+
* @stability stable
|
|
33
|
+
* @category schemas
|
|
34
|
+
* @since 0.3.0
|
|
35
|
+
*/
|
|
36
|
+
Plan,
|
|
37
|
+
/**
|
|
38
|
+
* @stability stable
|
|
39
|
+
* @category constants
|
|
40
|
+
* @since 0.3.0
|
|
41
|
+
*/
|
|
42
|
+
maximumSamples,
|
|
43
|
+
/**
|
|
44
|
+
* @stability stable
|
|
45
|
+
* @category constants
|
|
46
|
+
* @since 0.3.0
|
|
47
|
+
*/
|
|
48
|
+
maximumDurationMillis,
|
|
49
|
+
} from "../internal/geometry.ts";
|
|
16
50
|
|
|
17
|
-
|
|
18
|
-
|
|
51
|
+
/**
|
|
52
|
+
* @stability stable
|
|
53
|
+
* @category models
|
|
54
|
+
* @since 0.3.0
|
|
55
|
+
*/
|
|
56
|
+
export type { Planner } from "../internal/geometry.ts";
|
|
19
57
|
|
|
20
58
|
// These are the research's tuned two-stroke parameters. Width scaling was not evaluated, so the
|
|
21
59
|
// model keeps its 40px reference width rather than implying measured target-size behavior.
|
|
@@ -127,5 +165,9 @@ const plan: Planner["plan"] = Effect.fnUntraced(function* (from, to) {
|
|
|
127
165
|
/**
|
|
128
166
|
* The research's tuned two-stroke sigma-lognormal model: a fast stroke toward the target and a
|
|
129
167
|
* slower one that homes in on it, with a little bend, drawn from `Random`.
|
|
168
|
+
*
|
|
169
|
+
* @stability stable
|
|
170
|
+
* @category constants
|
|
171
|
+
* @since 0.3.0
|
|
130
172
|
*/
|
|
131
173
|
export const lognormal: Planner = { plan };
|
|
@@ -2,19 +2,26 @@
|
|
|
2
2
|
* Input performed for viewers. A presenter owns one pointer and pace. Its public page view applies
|
|
3
3
|
* a style to input after approval, so policy holds leave the hand free. Hand acquisition is bounded
|
|
4
4
|
* by the page's action wait and honours failFast; reactions and input use the page owner's clock.
|
|
5
|
+
* @stability stable
|
|
5
6
|
* @since 0.3.0
|
|
6
7
|
*/
|
|
7
8
|
import { type Clock, Deferred, Duration, Effect, MutableRef, Option, Semaphore } from "effect";
|
|
8
9
|
|
|
9
|
-
import { methods } from "../ActionPort.ts";
|
|
10
10
|
import { Busy, refuse, undispatched } from "../BrowserError.ts";
|
|
11
11
|
import type { ActionAnnounced } from "../BrowserEvent.ts";
|
|
12
|
-
import
|
|
12
|
+
import * as InputStyle from "../InputStyle.ts";
|
|
13
|
+
import { methods } from "../internal/action-port.ts";
|
|
14
|
+
import { monotonicMillis } from "../internal/clock.ts";
|
|
13
15
|
import type { Page, Point } from "../Page.ts";
|
|
14
|
-
import * as Style from "../Style.ts";
|
|
15
16
|
import * as Motion from "./Motion.ts";
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* How long a person waits before acting, and how fast they type.
|
|
20
|
+
*
|
|
21
|
+
* @stability stable
|
|
22
|
+
* @category models
|
|
23
|
+
* @since 0.3.0
|
|
24
|
+
*/
|
|
18
25
|
export interface Pacing {
|
|
19
26
|
readonly expected: Duration.Input;
|
|
20
27
|
readonly surprise: Duration.Input;
|
|
@@ -23,6 +30,11 @@ export interface Pacing {
|
|
|
23
30
|
readonly wordsPerMinute: number;
|
|
24
31
|
}
|
|
25
32
|
|
|
33
|
+
/**
|
|
34
|
+
* @stability stable
|
|
35
|
+
* @category constants
|
|
36
|
+
* @since 0.3.0
|
|
37
|
+
*/
|
|
26
38
|
export const human: Pacing = {
|
|
27
39
|
expected: "280 millis",
|
|
28
40
|
surprise: "600 millis",
|
|
@@ -30,6 +42,11 @@ export const human: Pacing = {
|
|
|
30
42
|
wordsPerMinute: 70,
|
|
31
43
|
};
|
|
32
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @stability stable
|
|
47
|
+
* @category options
|
|
48
|
+
* @since 0.3.0
|
|
49
|
+
*/
|
|
33
50
|
export interface Options {
|
|
34
51
|
readonly pacing?: Pacing | undefined;
|
|
35
52
|
readonly motion?: Motion.Planner | undefined;
|
|
@@ -41,8 +58,18 @@ export interface Options {
|
|
|
41
58
|
readonly lead?: ((announced: ActionAnnounced) => Effect.Effect<void>) | undefined;
|
|
42
59
|
}
|
|
43
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @stability stable
|
|
63
|
+
* @category models
|
|
64
|
+
* @since 0.3.0
|
|
65
|
+
*/
|
|
44
66
|
export type View = Page;
|
|
45
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @stability stable
|
|
70
|
+
* @category models
|
|
71
|
+
* @since 0.3.0
|
|
72
|
+
*/
|
|
46
73
|
export interface Presenter {
|
|
47
74
|
/** The same public page view for the same page. */
|
|
48
75
|
readonly view: (page: Page) => View;
|
|
@@ -50,7 +77,13 @@ export interface Presenter {
|
|
|
50
77
|
|
|
51
78
|
const spread = { expected: 0.3, surprise: 0.4, unrelated: 0.4 };
|
|
52
79
|
|
|
53
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* One hand for the scope; input effects keep their page's authority and failure evidence.
|
|
82
|
+
*
|
|
83
|
+
* @stability stable
|
|
84
|
+
* @category constructors
|
|
85
|
+
* @since 0.3.0
|
|
86
|
+
*/
|
|
54
87
|
export const make = Effect.fn("Presentation.make")(function* (options: Options = {}) {
|
|
55
88
|
const pacing = options.pacing ?? human;
|
|
56
89
|
const medians = { expected: 0, surprise: 0, unrelated: 0 };
|
|
@@ -69,14 +102,14 @@ export const make = Effect.fn("Presentation.make")(function* (options: Options =
|
|
|
69
102
|
if (
|
|
70
103
|
!Number.isFinite(pacing.wordsPerMinute) ||
|
|
71
104
|
pacing.wordsPerMinute <= 0 ||
|
|
72
|
-
|
|
105
|
+
InputStyle.keyGap(pacing.wordsPerMinute) < 0
|
|
73
106
|
)
|
|
74
107
|
return yield* refuse("presentation", "wordsPerMinute must be positive and at most 1200");
|
|
75
108
|
|
|
76
109
|
const pointer = MutableRef.make(Option.none<Point>());
|
|
77
110
|
const hand = yield* Semaphore.make(1);
|
|
78
111
|
|
|
79
|
-
const planned =
|
|
112
|
+
const planned = InputStyle.performed({
|
|
80
113
|
pointer,
|
|
81
114
|
motion: options.motion ?? Motion.lognormal,
|
|
82
115
|
wordsPerMinute: pacing.wordsPerMinute,
|
|
@@ -99,9 +132,9 @@ export const make = Effect.fn("Presentation.make")(function* (options: Options =
|
|
|
99
132
|
const known = views.get(page);
|
|
100
133
|
|
|
101
134
|
if (known !== undefined) return known;
|
|
102
|
-
const now = () => monotonicMillis(page.
|
|
135
|
+
const now = () => monotonicMillis(page.hostClock);
|
|
103
136
|
|
|
104
|
-
const style:
|
|
137
|
+
const style: InputStyle.InputStyle = {
|
|
105
138
|
...planned,
|
|
106
139
|
lead:
|
|
107
140
|
lead === undefined
|
|
@@ -125,15 +158,15 @@ export const make = Effect.fn("Presentation.make")(function* (options: Options =
|
|
|
125
158
|
const document = (yield* page.state).document;
|
|
126
159
|
|
|
127
160
|
const kind =
|
|
128
|
-
last === undefined || last.page !== page.id || last.clock !== page.
|
|
161
|
+
last === undefined || last.page !== page.id || last.clock !== page.hostClock
|
|
129
162
|
? "unrelated"
|
|
130
163
|
: last.document === document
|
|
131
164
|
? "expected"
|
|
132
165
|
: "surprise";
|
|
133
166
|
|
|
134
167
|
const left =
|
|
135
|
-
(last?.clock === page.
|
|
136
|
-
(yield*
|
|
168
|
+
(last?.clock === page.hostClock ? last.at : now()) +
|
|
169
|
+
(yield* InputStyle.pause(medians[kind], spread[kind])) -
|
|
137
170
|
now();
|
|
138
171
|
|
|
139
172
|
if (left > 0)
|
|
@@ -144,7 +177,7 @@ export const make = Effect.fn("Presentation.make")(function* (options: Options =
|
|
|
144
177
|
return yield* effect.pipe(
|
|
145
178
|
Effect.ensuring(
|
|
146
179
|
Effect.sync(() => {
|
|
147
|
-
last = { page: page.id, document, clock: page.
|
|
180
|
+
last = { page: page.id, document, clock: page.hostClock, at: now() };
|
|
148
181
|
}),
|
|
149
182
|
),
|
|
150
183
|
);
|
|
@@ -168,7 +201,7 @@ export const make = Effect.fn("Presentation.make")(function* (options: Options =
|
|
|
168
201
|
}).pipe(Effect.withSpan("Presentation.hand")),
|
|
169
202
|
};
|
|
170
203
|
|
|
171
|
-
const styled =
|
|
204
|
+
const styled = InputStyle.provide(style);
|
|
172
205
|
const perform: Page["perform"] = (action) => styled(page.perform(action));
|
|
173
206
|
|
|
174
207
|
const performed: View = {
|