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
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt caching for OpenRouter chat completions whose turns end in a picture. `BrowserTools` shows
|
|
3
|
+
* the screenshot before a turn as context the next call drops. A provider that caches at
|
|
4
|
+
* breakpoints, as OpenAI's models do on OpenRouter, sets its own at the end of the prompt, inside
|
|
5
|
+
* that picture, so no later call matches it and every call writes the whole conversation again.
|
|
6
|
+
* `layer` marks the end of each request's history instead, with OpenRouter's `cache_control`: its
|
|
7
|
+
* last tool result or, before there is one, its system message. A loop such as Yielded's builds
|
|
8
|
+
* the prompt with no cache options, and `@effect/ai-openrouter` before 4.0.6 drops them on tool results, so the
|
|
9
|
+
* mark is made on the request's JSON, in the HTTP client beneath the OpenRouter client:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* OpenRouterClient.layerConfig({ apiKey }).pipe(
|
|
13
|
+
* Layer.provide(PromptCache.layer),
|
|
14
|
+
* Layer.provide(FetchHttpClient.layer),
|
|
15
|
+
* )
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @stability stable
|
|
19
|
+
* @since 0.3.0
|
|
20
|
+
*/
|
|
21
|
+
import { Effect, Layer, Option, Predicate, Schema } from "effect";
|
|
22
|
+
import { HttpBody, HttpClient, HttpClientRequest } from "effect/http";
|
|
23
|
+
|
|
24
|
+
const ephemeral = { type: "ephemeral" } as const;
|
|
25
|
+
|
|
26
|
+
// The content with a breakpoint after its last text, or undefined where it does not end in text.
|
|
27
|
+
const marked = (content: unknown) => {
|
|
28
|
+
if (typeof content === "string")
|
|
29
|
+
return [{ type: "text", text: content, cache_control: ephemeral }];
|
|
30
|
+
if (!Array.isArray(content)) return undefined;
|
|
31
|
+
|
|
32
|
+
const last: unknown = content.at(-1);
|
|
33
|
+
|
|
34
|
+
return Predicate.hasProperty(last, "type") && last.type === "text"
|
|
35
|
+
? content.with(-1, { ...last, cache_control: ephemeral })
|
|
36
|
+
: undefined;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const markHistory = (messages: ReadonlyArray<unknown>) => {
|
|
40
|
+
const at = messages.findLastIndex(
|
|
41
|
+
(message) =>
|
|
42
|
+
Predicate.hasProperty(message, "role") &&
|
|
43
|
+
(message.role === "tool" || message.role === "system"),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const message = messages[at];
|
|
47
|
+
|
|
48
|
+
if (!Predicate.hasProperty(message, "content")) return messages;
|
|
49
|
+
|
|
50
|
+
const content = marked(message.content);
|
|
51
|
+
|
|
52
|
+
return content === undefined ? messages : messages.with(at, { ...message, content });
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const Completion = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown));
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Marks the chat completions sent through the `HttpClient` it is given; other requests pass.
|
|
59
|
+
*
|
|
60
|
+
* @stability stable
|
|
61
|
+
* @category layers
|
|
62
|
+
* @since 0.3.0
|
|
63
|
+
*/
|
|
64
|
+
export const layer: Layer.Layer<HttpClient.HttpClient, never, HttpClient.HttpClient> = Layer.effect(
|
|
65
|
+
HttpClient.HttpClient,
|
|
66
|
+
Effect.map(HttpClient.HttpClient, (http) =>
|
|
67
|
+
HttpClient.mapRequest(http, (request) => {
|
|
68
|
+
const { body } = request;
|
|
69
|
+
|
|
70
|
+
if (body._tag !== "Uint8Array" || !request.url.endsWith("/chat/completions")) return request;
|
|
71
|
+
|
|
72
|
+
return Option.match(Schema.decodeOption(Completion)(new TextDecoder().decode(body.body)), {
|
|
73
|
+
onNone: () => request,
|
|
74
|
+
onSome: (completion) =>
|
|
75
|
+
Array.isArray(completion["messages"])
|
|
76
|
+
? HttpClientRequest.setBody(
|
|
77
|
+
request,
|
|
78
|
+
HttpBody.jsonUnsafe({
|
|
79
|
+
...completion,
|
|
80
|
+
messages: markHistory(completion["messages"]),
|
|
81
|
+
}),
|
|
82
|
+
)
|
|
83
|
+
: request,
|
|
84
|
+
});
|
|
85
|
+
}),
|
|
86
|
+
),
|
|
87
|
+
);
|
package/src/ai/Tabs.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tabs the tools follow in a browser, as data to save and resume: which one is shown, which
|
|
3
|
+
* were seen, and each one's stable ref. Independent of browser effects.
|
|
4
|
+
*
|
|
5
|
+
* @stability stable
|
|
6
|
+
* @since 0.3.0
|
|
7
|
+
*/
|
|
8
|
+
import { Function, Schema } from "effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @stability stable
|
|
12
|
+
* @category schemas
|
|
13
|
+
* @since 0.3.0
|
|
14
|
+
*/
|
|
15
|
+
export class Tabs extends Schema.Class<Tabs>("effect-browser/ai/Tabs")({
|
|
16
|
+
shown: Schema.optional(Schema.String),
|
|
17
|
+
seen: Schema.Array(Schema.String),
|
|
18
|
+
refs: Schema.Record(Schema.String, Schema.String),
|
|
19
|
+
}) {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @stability stable
|
|
23
|
+
* @category constructors
|
|
24
|
+
* @since 0.3.0
|
|
25
|
+
*/
|
|
26
|
+
export const make = (seen: ReadonlyArray<string> = []): Tabs => new Tabs({ seen, refs: {} });
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The newest unseen tab wins unless following is disabled; a closed selection falls back.
|
|
30
|
+
*
|
|
31
|
+
* @stability stable
|
|
32
|
+
* @category combinators
|
|
33
|
+
* @since 0.3.0
|
|
34
|
+
*/
|
|
35
|
+
export const follow: {
|
|
36
|
+
(
|
|
37
|
+
open: ReadonlyArray<string>,
|
|
38
|
+
policy: "select" | "front" | "never",
|
|
39
|
+
): (state: Tabs) => { readonly selected: string | undefined; readonly state: Tabs };
|
|
40
|
+
(
|
|
41
|
+
state: Tabs,
|
|
42
|
+
open: ReadonlyArray<string>,
|
|
43
|
+
policy: "select" | "front" | "never",
|
|
44
|
+
): { readonly selected: string | undefined; readonly state: Tabs };
|
|
45
|
+
} = Function.dual(
|
|
46
|
+
3,
|
|
47
|
+
(state: Tabs, open: ReadonlyArray<string>, policy: "select" | "front" | "never") => {
|
|
48
|
+
const newest = open.filter((id) => !state.seen.includes(id)).at(-1);
|
|
49
|
+
|
|
50
|
+
const selected =
|
|
51
|
+
policy !== "never" && newest !== undefined
|
|
52
|
+
? newest
|
|
53
|
+
: (open.find((id) => id === state.shown) ?? open[0]);
|
|
54
|
+
|
|
55
|
+
const refs = { ...state.refs };
|
|
56
|
+
|
|
57
|
+
for (const id of open)
|
|
58
|
+
if (refs[id] === undefined) {
|
|
59
|
+
let next = Object.keys(refs).length + 1;
|
|
60
|
+
|
|
61
|
+
while (Object.values(refs).includes(`tab${next}`)) next++;
|
|
62
|
+
refs[id] = `tab${next}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
selected,
|
|
67
|
+
state: new Tabs({ shown: selected, seen: [...new Set([...state.seen, ...open])], refs }),
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The open tab that `ref` names, if any.
|
|
74
|
+
*
|
|
75
|
+
* @stability stable
|
|
76
|
+
* @category combinators
|
|
77
|
+
* @since 0.3.0
|
|
78
|
+
*/
|
|
79
|
+
export const selected: {
|
|
80
|
+
(open: ReadonlyArray<string>, ref: string): (state: Tabs) => string | undefined;
|
|
81
|
+
(state: Tabs, open: ReadonlyArray<string>, ref: string): string | undefined;
|
|
82
|
+
} = Function.dual(3, (state: Tabs, open: ReadonlyArray<string>, ref: string) =>
|
|
83
|
+
open.find((id) => state.refs[id] === ref),
|
|
84
|
+
);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The failure every browser tool returns to the model, and its controller fails with: what
|
|
3
|
+
* happened and what it leaves, with what to do about it, and whether the input reached the
|
|
4
|
+
* browser. `code` is `"invalid"` for a request the tools refused before acting, and `"browser"`
|
|
5
|
+
* for a browser operation that failed. The tools return it as their result (`failureMode:
|
|
6
|
+
* "return"`), so the model reads it and the run goes on.
|
|
7
|
+
*
|
|
8
|
+
* @stability stable
|
|
9
|
+
* @since 0.3.0
|
|
10
|
+
*/
|
|
11
|
+
import { Schema } from "effect";
|
|
12
|
+
|
|
13
|
+
import type { BrowserError } from "../BrowserError.ts";
|
|
14
|
+
import { dispatchOf, told } from "./internal/receipts.ts";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @stability stable
|
|
18
|
+
* @category errors
|
|
19
|
+
* @since 0.3.0
|
|
20
|
+
*/
|
|
21
|
+
export class ToolError extends Schema.TaggedError<ToolError>("effect-browser/ai/ToolError")(
|
|
22
|
+
"ToolError",
|
|
23
|
+
{
|
|
24
|
+
code: Schema.Literals(["invalid", "browser"]),
|
|
25
|
+
message: Schema.String,
|
|
26
|
+
/** Whether the input went: never replay one that is not `not-dispatched`. */
|
|
27
|
+
dispatch: Schema.optionalKey(Schema.Literals(["not-dispatched", "possibly-dispatched"])),
|
|
28
|
+
},
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @stability stable
|
|
33
|
+
* @category guards
|
|
34
|
+
* @since 0.3.0
|
|
35
|
+
*/
|
|
36
|
+
export const isToolError = Schema.is(ToolError);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A browser operation's failure as the tools report it.
|
|
40
|
+
*
|
|
41
|
+
* @stability stable
|
|
42
|
+
* @category constructors
|
|
43
|
+
* @since 0.3.0
|
|
44
|
+
*/
|
|
45
|
+
export const fromBrowserError = (error: BrowserError) =>
|
|
46
|
+
new ToolError({
|
|
47
|
+
code: error.reason._tag === "InvalidRequest" ? "invalid" : "browser",
|
|
48
|
+
message: told(error),
|
|
49
|
+
dispatch: dispatchOf(error),
|
|
50
|
+
});
|
package/src/ai/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser tools for an agent in any `effect/ai` loop, and the controller they act through.
|
|
3
|
+
*
|
|
4
|
+
* @stability stable
|
|
5
|
+
* @since 0.3.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @stability stable
|
|
10
|
+
* @since 0.3.0
|
|
11
|
+
*/
|
|
12
|
+
export * as BrowserTools from "./BrowserTools.ts";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @stability stable
|
|
16
|
+
* @since 0.3.0
|
|
17
|
+
*/
|
|
18
|
+
export * as PageControl from "./PageControl.ts";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @stability stable
|
|
22
|
+
* @since 0.3.0
|
|
23
|
+
*/
|
|
24
|
+
export * as PromptCache from "./PromptCache.ts";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @stability stable
|
|
28
|
+
* @since 0.3.0
|
|
29
|
+
*/
|
|
30
|
+
export * as Tabs from "./Tabs.ts";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @stability stable
|
|
34
|
+
* @since 0.3.0
|
|
35
|
+
*/
|
|
36
|
+
export * as ToolError from "./ToolError.ts";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** The crops `zoom` took, as the model is shown them before its next turn. */
|
|
2
|
+
import { Prompt } from "effect/ai";
|
|
3
|
+
|
|
4
|
+
import type { Zoom } from "../../Frame.ts";
|
|
5
|
+
|
|
6
|
+
/** At most this many crops are shown at once: the latest. */
|
|
7
|
+
const maxZooms = 8;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The crops of `page` taken since the last turn: the latest, each with its origin, in pictures of
|
|
11
|
+
* `scale` pixels to a CSS pixel.
|
|
12
|
+
*/
|
|
13
|
+
export const cropped = (
|
|
14
|
+
crops: ReadonlyArray<Zoom>,
|
|
15
|
+
page: string,
|
|
16
|
+
scale = 1,
|
|
17
|
+
): ReadonlyArray<Prompt.UserMessagePart> => {
|
|
18
|
+
const current = crops.filter((crop) => crop.page === page);
|
|
19
|
+
const kept = current.slice(-maxZooms);
|
|
20
|
+
const at = (value: number) => Math.round(value * scale);
|
|
21
|
+
const unit = scale === 1 ? "CSS pixels" : "screenshot pixels";
|
|
22
|
+
|
|
23
|
+
return [
|
|
24
|
+
...kept.flatMap(({ region, image }) => [
|
|
25
|
+
Prompt.makePart("text", {
|
|
26
|
+
text: `Zoom: viewport origin (${at(region.x)}, ${at(region.y)}), ${at(region.width)}x${at(region.height)} ${unit}. Add this origin to a point in the crop for a viewport click.`,
|
|
27
|
+
}),
|
|
28
|
+
Prompt.makePart("file", { mediaType: image.mediaType, data: image.data }),
|
|
29
|
+
]),
|
|
30
|
+
...(current.length > kept.length
|
|
31
|
+
? [
|
|
32
|
+
Prompt.makePart("text", {
|
|
33
|
+
text: `${current.length - kept.length} earlier crops were left out.`,
|
|
34
|
+
}),
|
|
35
|
+
]
|
|
36
|
+
: []),
|
|
37
|
+
];
|
|
38
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the pointer tools act: a model's point or ref as a target, points and regions read from a
|
|
3
|
+
* picture of another scale on the viewport, and the crops that placement by crop shows.
|
|
4
|
+
*/
|
|
5
|
+
import { Option } from "effect";
|
|
6
|
+
|
|
7
|
+
import { Region, type Zoom } from "../../Frame.ts";
|
|
8
|
+
import type * as Page from "../../Page.ts";
|
|
9
|
+
|
|
10
|
+
// A point is the more specific of the two, such as a spot on a canvas a ref names.
|
|
11
|
+
export const target = (place: {
|
|
12
|
+
readonly ref?: string | undefined;
|
|
13
|
+
readonly x?: number | undefined;
|
|
14
|
+
readonly y?: number | undefined;
|
|
15
|
+
}): Option.Option<Page.Target> =>
|
|
16
|
+
place.x !== undefined && place.y !== undefined
|
|
17
|
+
? Option.some({ x: place.x, y: place.y })
|
|
18
|
+
: place.ref === undefined
|
|
19
|
+
? Option.none()
|
|
20
|
+
: Option.some(place.ref);
|
|
21
|
+
|
|
22
|
+
// A target the model read from a picture of `scale` pixels to a CSS pixel, on the viewport.
|
|
23
|
+
export const viewportTarget = (to: Page.Target, scale: number): Page.Target =>
|
|
24
|
+
typeof to === "string" ? to : { x: to.x / scale, y: to.y / scale };
|
|
25
|
+
|
|
26
|
+
// A region read from such a picture, in the whole CSS pixels that hold it within the viewport.
|
|
27
|
+
export const viewportRegion = (region: Region, scale: number) => {
|
|
28
|
+
const x = Math.floor(region.x / scale);
|
|
29
|
+
const y = Math.floor(region.y / scale);
|
|
30
|
+
|
|
31
|
+
return new Region({
|
|
32
|
+
x,
|
|
33
|
+
y,
|
|
34
|
+
width: Math.max(1, Math.floor((region.x + region.width) / scale) - x),
|
|
35
|
+
height: Math.max(1, Math.floor((region.y + region.height) / scale) - y),
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const named = (to: Page.Target) => (typeof to === "string" ? to : `(${to.x}, ${to.y})`);
|
|
40
|
+
|
|
41
|
+
// The 200x120 region around a point, within a viewport at least that size.
|
|
42
|
+
export const around = (
|
|
43
|
+
point: Page.Point,
|
|
44
|
+
viewport: { readonly width: number; readonly height: number },
|
|
45
|
+
) =>
|
|
46
|
+
new Region({
|
|
47
|
+
x: Math.round(Math.min(Math.max(point.x - 100, 0), Math.max(viewport.width - 200, 0))),
|
|
48
|
+
y: Math.round(Math.min(Math.max(point.y - 60, 0), Math.max(viewport.height - 120, 0))),
|
|
49
|
+
width: 200,
|
|
50
|
+
height: 120,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const holds = ({ region }: Zoom, point: Page.Point) =>
|
|
54
|
+
point.x >= region.x &&
|
|
55
|
+
point.y >= region.y &&
|
|
56
|
+
point.x <= region.x + region.width &&
|
|
57
|
+
point.y <= region.y + region.height;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a model is told of a call: a failure, with what it leaves and what to do about it, and what
|
|
3
|
+
* followed an action on its page while it ran, from the page's own record: a dialog and how the
|
|
4
|
+
* browser answered it, a navigation, a tab it opened and what its input visibly changed.
|
|
5
|
+
*/
|
|
6
|
+
import { Effect, Option, Result, Schema } from "effect";
|
|
7
|
+
|
|
8
|
+
import { BrowserError, consequence, InvalidRequest } from "../../BrowserError.ts";
|
|
9
|
+
import { DialogShown, Navigated, PageOpened } from "../../BrowserEvent.ts";
|
|
10
|
+
import * as Change from "../../Change.ts";
|
|
11
|
+
import type * as Page from "../../Page.ts";
|
|
12
|
+
import * as Moment from "../../timeline/Moment.ts";
|
|
13
|
+
|
|
14
|
+
/** A failure as a model is told it: what happened, then what to do about it. */
|
|
15
|
+
export const told = (error: BrowserError): string => {
|
|
16
|
+
const { lost, repeat } = consequence(error);
|
|
17
|
+
|
|
18
|
+
return [
|
|
19
|
+
`${error.message}.`,
|
|
20
|
+
lost === "session" ? "The browser is gone." : lost === "page" ? "The tab is gone." : "",
|
|
21
|
+
error.reason._tag === "StaleRef" ? "Observe the page again for current refs." : "",
|
|
22
|
+
error.reason._tag === "Busy" && repeat === "safe"
|
|
23
|
+
? "Nothing was done while other work held the page: try it again."
|
|
24
|
+
: "",
|
|
25
|
+
error.reason._tag === "Suspended"
|
|
26
|
+
? "Nothing was sent. Wait for the input suspension to end before acting again."
|
|
27
|
+
: "",
|
|
28
|
+
repeat === "check" ? "It may have taken effect: look at the page before you repeat it." : "",
|
|
29
|
+
]
|
|
30
|
+
.filter((sentence) => sentence !== "")
|
|
31
|
+
.join(" ");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Whether a failed operation's input may have reached the browser. */
|
|
35
|
+
export const dispatchOf = (error: BrowserError) =>
|
|
36
|
+
error.dispatched ? ("possibly-dispatched" as const) : ("not-dispatched" as const);
|
|
37
|
+
|
|
38
|
+
/** A refusal before anything reached the browser, as a page's own refusals are. */
|
|
39
|
+
const refused = (operation: string, detail: string) =>
|
|
40
|
+
Effect.fail(
|
|
41
|
+
new BrowserError({ operation, reason: new InvalidRequest({ detail }), dispatched: false }),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
/** Where a model may go: web addresses, inline data and a blank page, never local files. */
|
|
45
|
+
export const destination = (operation: string, input: string) => {
|
|
46
|
+
const url = URL.parse(input);
|
|
47
|
+
|
|
48
|
+
return url !== null &&
|
|
49
|
+
(url.protocol === "http:" ||
|
|
50
|
+
url.protocol === "https:" ||
|
|
51
|
+
url.protocol === "data:" ||
|
|
52
|
+
url.href === "about:blank")
|
|
53
|
+
? Effect.succeed(url.href)
|
|
54
|
+
: refused(
|
|
55
|
+
operation,
|
|
56
|
+
`${JSON.stringify(input)} was not opened: the browser opens http and https addresses, data: URLs and about:blank`,
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** At most this many of the changes an action caused are told. */
|
|
61
|
+
const maxChanges = 3;
|
|
62
|
+
|
|
63
|
+
const isDialog = Schema.is(DialogShown);
|
|
64
|
+
const isNavigated = Schema.is(Navigated);
|
|
65
|
+
const isOpened = Schema.is(PageOpened);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* What followed on `page` since host time `since`, a line each: the dialogs that opened and how
|
|
69
|
+
* each was answered, where the page went, the tabs it opened, and up to three changes its input
|
|
70
|
+
* caused, read in one call. What could not be read is told as such.
|
|
71
|
+
*/
|
|
72
|
+
export const followed = (page: Page.Page, since: number) =>
|
|
73
|
+
Effect.gen(function* () {
|
|
74
|
+
const events = (yield* page.recentEvents).filter((event) => event.at > since);
|
|
75
|
+
const changes = yield* Effect.result(Change.read(page, { since }));
|
|
76
|
+
const navigated = events.findLast(isNavigated);
|
|
77
|
+
|
|
78
|
+
const caused = Option.match(Result.getSuccess(changes), {
|
|
79
|
+
onNone: () => [],
|
|
80
|
+
onSome: (read) => read.changes.filter((change) => change.cause !== undefined),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const more = caused.length - maxChanges;
|
|
84
|
+
|
|
85
|
+
return [
|
|
86
|
+
...events
|
|
87
|
+
.filter(isDialog)
|
|
88
|
+
.map(
|
|
89
|
+
({ kind, message, answer }) =>
|
|
90
|
+
`A ${kind} dialog said ${JSON.stringify(message)}, and it was ${answer}.`,
|
|
91
|
+
),
|
|
92
|
+
...(navigated === undefined ? [] : [`The page went to ${navigated.url}.`]),
|
|
93
|
+
...events.filter(isOpened).map(({ url }) => `A tab opened at ${url}.`),
|
|
94
|
+
...(caused.length === 0
|
|
95
|
+
? []
|
|
96
|
+
: [
|
|
97
|
+
`It changed: ${caused
|
|
98
|
+
.slice(0, maxChanges)
|
|
99
|
+
.map((change) => Moment.describeChange(change))
|
|
100
|
+
.join("; ")}${more > 0 ? `; and ${more} more` : ""}.`,
|
|
101
|
+
]),
|
|
102
|
+
...Option.match(Result.getFailure(changes), {
|
|
103
|
+
onNone: () => [],
|
|
104
|
+
onSome: (error) => [`What changed could not be read: ${error.reason.message}.`],
|
|
105
|
+
}),
|
|
106
|
+
];
|
|
107
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,19 +1,96 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* The browser kernel. `Cdp`, `Site` and the features have their own subpaths.
|
|
3
|
+
*
|
|
4
|
+
* @stability stable
|
|
5
|
+
* @since 0.3.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @stability stable
|
|
10
|
+
* @since 0.3.0
|
|
11
|
+
*/
|
|
2
12
|
export * as Action from "./Action.ts";
|
|
3
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @stability stable
|
|
16
|
+
* @since 0.3.0
|
|
17
|
+
*/
|
|
4
18
|
export * as Browser from "./Browser.ts";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @stability stable
|
|
22
|
+
* @since 0.3.0
|
|
23
|
+
*/
|
|
5
24
|
export * as BrowserError from "./BrowserError.ts";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @stability stable
|
|
28
|
+
* @since 0.3.0
|
|
29
|
+
*/
|
|
6
30
|
export * as BrowserEvent from "./BrowserEvent.ts";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @stability stable
|
|
34
|
+
* @since 0.3.0
|
|
35
|
+
*/
|
|
7
36
|
export * as Change from "./Change.ts";
|
|
8
|
-
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @stability stable
|
|
40
|
+
* @since 0.3.0
|
|
41
|
+
*/
|
|
9
42
|
export * as Frame from "./Frame.ts";
|
|
10
|
-
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @stability stable
|
|
46
|
+
* @since 0.3.0
|
|
47
|
+
*/
|
|
48
|
+
export * as InputStyle from "./InputStyle.ts";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @stability stable
|
|
52
|
+
* @since 0.3.0
|
|
53
|
+
*/
|
|
11
54
|
export * as Layout from "./Layout.ts";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @stability stable
|
|
58
|
+
* @since 0.3.0
|
|
59
|
+
*/
|
|
12
60
|
export * as Overlay from "./Overlay.ts";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @stability stable
|
|
64
|
+
* @since 0.3.0
|
|
65
|
+
*/
|
|
13
66
|
export * as Page from "./Page.ts";
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @stability stable
|
|
70
|
+
* @since 0.3.0
|
|
71
|
+
*/
|
|
14
72
|
export * as PageTime from "./PageTime.ts";
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @stability stable
|
|
76
|
+
* @since 0.3.0
|
|
77
|
+
*/
|
|
15
78
|
export * as Pose from "./Pose.ts";
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @stability stable
|
|
82
|
+
* @since 0.3.0
|
|
83
|
+
*/
|
|
16
84
|
export * as Snapshot from "./Snapshot.ts";
|
|
17
|
-
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @stability stable
|
|
88
|
+
* @since 0.3.0
|
|
89
|
+
*/
|
|
90
|
+
export * as Text from "./Text.ts";
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @stability stable
|
|
94
|
+
* @since 0.3.0
|
|
95
|
+
*/
|
|
18
96
|
export * as Window from "./Window.ts";
|
|
19
|
-
export * as Url from "./Url.ts";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Assemble named Page methods and canonical action execution over one concrete input port. */
|
|
2
2
|
import { Effect, Schema, type SchemaIssue } from "effect";
|
|
3
3
|
|
|
4
|
-
import { Action, nameOf } from "
|
|
5
|
-
import { InvalidRequest, undispatched } from "
|
|
6
|
-
import { type Page, ResolvedTarget } from "
|
|
4
|
+
import { Action, nameOf } from "../Action.ts";
|
|
5
|
+
import { InvalidRequest, undispatched } from "../BrowserError.ts";
|
|
6
|
+
import { type Page, ResolvedTarget } from "../Page.ts";
|
|
7
7
|
|
|
8
8
|
type Port = Pick<
|
|
9
9
|
Page,
|
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @since 0.3.0
|
|
8
8
|
*/
|
|
9
|
-
import { type DateTime, Effect, Layer, Redacted } from "effect";
|
|
9
|
+
import { Config, type DateTime, Duration, Effect, Layer, Redacted } from "effect";
|
|
10
10
|
import type { Browser as PlaywrightBrowser } from "playwright-core";
|
|
11
11
|
|
|
12
|
-
import * as Browser from "
|
|
13
|
-
import * as Errors from "
|
|
14
|
-
import { reasonOf, undispatched } from "
|
|
15
|
-
import
|
|
12
|
+
import * as Browser from "../../Browser.ts";
|
|
13
|
+
import * as Errors from "../../BrowserError.ts";
|
|
14
|
+
import { reasonOf, undispatched } from "../../BrowserError.ts";
|
|
15
|
+
import { millisOf } from "../clock.ts";
|
|
16
|
+
import * as Url from "../url.ts";
|
|
16
17
|
|
|
17
18
|
/** The runtime connector receives the bound and cancellation signal owned by the opening scope. */
|
|
18
19
|
export interface ConnectOptions {
|
|
@@ -40,7 +41,7 @@ export interface Options extends Browser.Options, Pick<ConnectOptions, "headers"
|
|
|
40
41
|
readonly id?: string | undefined;
|
|
41
42
|
readonly provider?: string | undefined;
|
|
42
43
|
/** Bound on connecting. Defaults to 30 seconds. */
|
|
43
|
-
readonly
|
|
44
|
+
readonly connectTimeout?: Duration.Input | undefined;
|
|
44
45
|
/** When the provider ends the session on its own, as a hosted session's timeout does. */
|
|
45
46
|
readonly expiresAt?: DateTime.Utc | undefined;
|
|
46
47
|
/**
|
|
@@ -51,13 +52,13 @@ export interface Options extends Browser.Options, Pick<ConnectOptions, "headers"
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/** Runtime facades supply the default transport; the shared lifetime imports no Node transport. */
|
|
54
|
-
export const
|
|
55
|
-
const
|
|
55
|
+
export const forRuntime = (defaultConnect?: Connector) => {
|
|
56
|
+
const make = Effect.fn("Cdp.make")(function* (options: Options) {
|
|
56
57
|
const endpoint = Redacted.isRedacted(options.endpoint)
|
|
57
58
|
? Redacted.value(options.endpoint)
|
|
58
59
|
: options.endpoint;
|
|
59
60
|
|
|
60
|
-
const timeout = options.
|
|
61
|
+
const timeout = millisOf(options.connectTimeout ?? Duration.seconds(30));
|
|
61
62
|
const connector = options.connect ?? defaultConnect;
|
|
62
63
|
const headers = options.headers === undefined ? undefined : { ...options.headers };
|
|
63
64
|
|
|
@@ -65,7 +66,7 @@ export const make = (defaultConnect?: Connector) => {
|
|
|
65
66
|
undispatched("connect", new Errors.InvalidRequest({ detail }));
|
|
66
67
|
|
|
67
68
|
if (!Number.isFinite(timeout) || timeout <= 0)
|
|
68
|
-
return yield* invalid("
|
|
69
|
+
return yield* invalid("connectTimeout must be finite and greater than zero");
|
|
69
70
|
if (connector === undefined)
|
|
70
71
|
return yield* invalid("This runtime requires a CDP connect callback");
|
|
71
72
|
|
|
@@ -128,7 +129,13 @@ export const make = (defaultConnect?: Connector) => {
|
|
|
128
129
|
});
|
|
129
130
|
|
|
130
131
|
const layer = (options: Options): Layer.Layer<Browser.Browser, Errors.BrowserError> =>
|
|
131
|
-
Layer.effect(Browser.Browser,
|
|
132
|
+
Layer.effect(Browser.Browser, make(options));
|
|
132
133
|
|
|
133
|
-
|
|
134
|
+
/** The options as `Config` values, such as the endpoint as a `Config.Redacted`. */
|
|
135
|
+
const layerConfig = (
|
|
136
|
+
config: Config.Wrap<Options>,
|
|
137
|
+
): Layer.Layer<Browser.Browser, Errors.BrowserError | Config.ConfigError> =>
|
|
138
|
+
Layer.effect(Browser.Browser, Config.unwrap(config).pipe(Effect.flatMap(make)));
|
|
139
|
+
|
|
140
|
+
return { make, layer, layerConfig };
|
|
134
141
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP lifetime for Workers. The consumer supplies a runtime-compatible Playwright connector;
|
|
3
|
+
* this entry imports no Playwright Node transport.
|
|
4
|
+
*
|
|
5
|
+
* @stability stable
|
|
6
|
+
* @since 0.3.0
|
|
7
|
+
*/
|
|
8
|
+
import { forRuntime } from "./connection.ts";
|
|
9
|
+
|
|
10
|
+
export type {
|
|
11
|
+
/**
|
|
12
|
+
* @stability stable
|
|
13
|
+
* @category models
|
|
14
|
+
* @since 0.3.0
|
|
15
|
+
*/
|
|
16
|
+
Connector,
|
|
17
|
+
/**
|
|
18
|
+
* @stability stable
|
|
19
|
+
* @category options
|
|
20
|
+
* @since 0.3.0
|
|
21
|
+
*/
|
|
22
|
+
ConnectOptions,
|
|
23
|
+
/**
|
|
24
|
+
* @stability stable
|
|
25
|
+
* @category options
|
|
26
|
+
* @since 0.3.0
|
|
27
|
+
*/
|
|
28
|
+
Options,
|
|
29
|
+
} from "./connection.ts";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @stability stable
|
|
33
|
+
* @category constructors
|
|
34
|
+
* @since 0.3.0
|
|
35
|
+
*/
|
|
36
|
+
export const { make, layer, layerConfig } = forRuntime();
|