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.
Files changed (345) hide show
  1. package/README.md +333 -157
  2. package/dist/Action.d.mts +1 -1
  3. package/dist/Action.mjs +61 -9
  4. package/dist/Action.mjs.map +1 -1
  5. package/dist/Browser.d.mts +2 -2
  6. package/dist/Browser.mjs +2 -2
  7. package/dist/BrowserError.d.mts +2 -2
  8. package/dist/BrowserError.mjs +194 -41
  9. package/dist/BrowserError.mjs.map +1 -1
  10. package/dist/BrowserEvent.d.mts +1 -1
  11. package/dist/BrowserEvent.mjs +166 -35
  12. package/dist/BrowserEvent.mjs.map +1 -1
  13. package/dist/Cdp.d.mts +15 -0
  14. package/dist/Cdp.mjs +22 -0
  15. package/dist/Cdp.mjs.map +1 -0
  16. package/dist/Change.d.mts +2 -2
  17. package/dist/Change.mjs +33 -6
  18. package/dist/Change.mjs.map +1 -1
  19. package/dist/Frame.d.mts +2 -2
  20. package/dist/Frame.mjs +132 -14
  21. package/dist/Frame.mjs.map +1 -1
  22. package/dist/{Style.d.mts → InputStyle.d.mts} +93 -25
  23. package/dist/{Style.mjs → InputStyle.mjs} +1 -1
  24. package/dist/Layout.d.mts +2 -2
  25. package/dist/Layout.mjs +58 -16
  26. package/dist/Layout.mjs.map +1 -1
  27. package/dist/Overlay.d.mts +2 -2
  28. package/dist/Overlay.mjs +33 -5
  29. package/dist/Overlay.mjs.map +1 -1
  30. package/dist/Page.d.mts +2 -2
  31. package/dist/Page.mjs +2 -2
  32. package/dist/PageTime.d.mts +2 -2
  33. package/dist/PageTime.mjs +13 -3
  34. package/dist/PageTime.mjs.map +1 -1
  35. package/dist/Pose.d.mts +2 -2
  36. package/dist/Pose.mjs +30 -9
  37. package/dist/Pose.mjs.map +1 -1
  38. package/dist/Site.d.mts +288 -18
  39. package/dist/Site.mjs +11 -3
  40. package/dist/Site.mjs.map +1 -1
  41. package/dist/Snapshot.d.mts +2 -2
  42. package/dist/Snapshot.mjs +87 -6
  43. package/dist/Snapshot.mjs.map +1 -1
  44. package/dist/Text.d.mts +2 -0
  45. package/dist/Text.mjs +45 -0
  46. package/dist/Text.mjs.map +1 -0
  47. package/dist/Window.d.mts +2 -2
  48. package/dist/Window.mjs +31 -6
  49. package/dist/Window.mjs.map +1 -1
  50. package/dist/ai/BrowserTools.d.mts +4987 -0
  51. package/dist/ai/BrowserTools.mjs +3 -0
  52. package/dist/ai/PageControl.d.mts +286 -0
  53. package/dist/ai/PageControl.mjs +426 -0
  54. package/dist/ai/PageControl.mjs.map +1 -0
  55. package/dist/ai/PromptCache.d.mts +16 -0
  56. package/dist/ai/PromptCache.mjs +72 -0
  57. package/dist/ai/PromptCache.mjs.map +1 -0
  58. package/dist/ai/Tabs.d.mts +2 -0
  59. package/dist/ai/Tabs.mjs +72 -0
  60. package/dist/ai/Tabs.mjs.map +1 -0
  61. package/dist/ai/ToolError.d.mts +34 -0
  62. package/dist/ai/ToolError.mjs +2 -0
  63. package/dist/ai/index.d.mts +6 -0
  64. package/dist/ai/index.mjs +6 -0
  65. package/dist/index.d.mts +7 -18
  66. package/dist/index.mjs +6 -9
  67. package/dist/{Action-24sLOubi.d.mts → internal/Action-CkanNTUw.d.mts} +64 -4
  68. package/dist/{Browser-DGR6ZEYo.d.mts → internal/Browser-DD9Vm1c-.d.mts} +75 -11
  69. package/dist/{Browser-CAQFhTkM.mjs → internal/Browser-vzD7i2oj.mjs} +174 -237
  70. package/dist/internal/Browser-vzD7i2oj.mjs.map +1 -0
  71. package/dist/{BrowserError-BlcmLVzn.d.mts → internal/BrowserError-CsuRYcDX.d.mts} +187 -28
  72. package/dist/{BrowserEvent-C2p-NwuU.d.mts → internal/BrowserEvent-tGPYYf6R.d.mts} +168 -13
  73. package/dist/internal/BrowserTools-Yi3lOX4h.mjs +497 -0
  74. package/dist/internal/BrowserTools-Yi3lOX4h.mjs.map +1 -0
  75. package/dist/{Style-T3ezDYLI.mjs → internal/InputStyle-CPzxoN4g.mjs} +75 -20
  76. package/dist/internal/InputStyle-CPzxoN4g.mjs.map +1 -0
  77. package/dist/{moment/Moment.mjs → internal/Moment-CstaX1mR.mjs} +49 -16
  78. package/dist/internal/Moment-CstaX1mR.mjs.map +1 -0
  79. package/dist/{moment/Moment.d.mts → internal/Moment-DOcldBdf.d.mts} +53 -20
  80. package/dist/internal/Page-BfGxn7oN.d.mts +1553 -0
  81. package/dist/{Page-BaAOshxo.mjs → internal/Page-DqF-tuTx.mjs} +62 -74
  82. package/dist/internal/Page-DqF-tuTx.mjs.map +1 -0
  83. package/dist/internal/Release-CFONkPDP.d.mts +39 -0
  84. package/dist/internal/Stage-D5ymSXDT.mjs +298 -0
  85. package/dist/internal/Stage-D5ymSXDT.mjs.map +1 -0
  86. package/dist/internal/Stillness-DCPeAN1a.mjs +1124 -0
  87. package/dist/internal/Stillness-DCPeAN1a.mjs.map +1 -0
  88. package/dist/internal/Supervisor-BcY_QNIY.d.mts +108 -0
  89. package/dist/internal/Supervisor-BcglY23c.mjs +531 -0
  90. package/dist/internal/Supervisor-BcglY23c.mjs.map +1 -0
  91. package/dist/internal/Tabs-dXMscIUQ.d.mts +52 -0
  92. package/dist/internal/TestPage-CYiYbh63.d.mts +159 -0
  93. package/dist/internal/ToolError-DArsRS2m.mjs +117 -0
  94. package/dist/internal/ToolError-DArsRS2m.mjs.map +1 -0
  95. package/dist/{plan/index.d.mts → internal/Walk-BNXcfZ2z.d.mts} +59 -35
  96. package/dist/{plan/index.mjs → internal/Walk-C5ky7uSf.mjs} +83 -51
  97. package/dist/internal/Walk-C5ky7uSf.mjs.map +1 -0
  98. package/dist/{ActionPort.mjs → internal/action-port-B5EkeGOR.mjs} +6 -12
  99. package/dist/internal/action-port-B5EkeGOR.mjs.map +1 -0
  100. package/dist/internal/cdp/workerd.d.mts +13 -0
  101. package/dist/internal/cdp/workerd.mjs +19 -0
  102. package/dist/internal/cdp/workerd.mjs.map +1 -0
  103. package/dist/{Clock.mjs → internal/clock-BKSAEf00.mjs} +13 -13
  104. package/dist/internal/clock-BKSAEf00.mjs.map +1 -0
  105. package/dist/{connection-Db-YtlbE.d.mts → internal/connection-BaB0vp1o.d.mts} +6 -6
  106. package/dist/{connection-C_jWYIwe.mjs → internal/connection-C2X4GmXM.mjs} +19 -15
  107. package/dist/internal/connection-C2X4GmXM.mjs.map +1 -0
  108. package/dist/internal/events-DzCrww-y.mjs +72 -0
  109. package/dist/internal/events-DzCrww-y.mjs.map +1 -0
  110. package/dist/internal/fold.inpage-uhrT-dOB.mjs +49 -0
  111. package/dist/internal/fold.inpage-uhrT-dOB.mjs.map +1 -0
  112. package/dist/internal/functions-jBOs6GKv.mjs +27 -0
  113. package/dist/internal/functions-jBOs6GKv.mjs.map +1 -0
  114. package/dist/{Geometry-DJx9qrYy.d.mts → internal/geometry-Dhj_ztJs.d.mts} +3 -3
  115. package/dist/{Geometry.mjs → internal/geometry-Lxyflb9J.mjs} +3 -12
  116. package/dist/internal/geometry-Lxyflb9J.mjs.map +1 -0
  117. package/dist/{Matching.mjs → internal/matching-Cs-UeOY0.mjs} +3 -3
  118. package/dist/internal/matching-Cs-UeOY0.mjs.map +1 -0
  119. package/dist/internal/page-DFQb-YOK.mjs +436 -0
  120. package/dist/internal/page-DFQb-YOK.mjs.map +1 -0
  121. package/dist/{pose.inpage-CLq7Mfdr.mjs → internal/pose.inpage-CBFeWcVa.mjs} +2 -48
  122. package/dist/internal/pose.inpage-CBFeWcVa.mjs.map +1 -0
  123. package/dist/{Url.mjs → internal/url-DB0pQYk6.mjs} +3 -12
  124. package/dist/internal/url-DB0pQYk6.mjs.map +1 -0
  125. package/dist/policy/Policy.d.mts +60 -6
  126. package/dist/policy/Policy.mjs +52 -9
  127. package/dist/policy/Policy.mjs.map +1 -1
  128. package/dist/policy/index.d.mts +2 -0
  129. package/dist/policy/index.mjs +2 -0
  130. package/dist/{film → presentation}/Film.d.mts +83 -16
  131. package/dist/{film → presentation}/Film.mjs +82 -30
  132. package/dist/presentation/Film.mjs.map +1 -0
  133. package/dist/presentation/Motion.d.mts +5 -1
  134. package/dist/presentation/Motion.mjs +16 -2
  135. package/dist/presentation/Motion.mjs.map +1 -1
  136. package/dist/presentation/Presentation.d.mts +42 -7
  137. package/dist/presentation/Presentation.mjs +26 -9
  138. package/dist/presentation/Presentation.mjs.map +1 -1
  139. package/dist/presentation/Stage.d.mts +40 -6
  140. package/dist/presentation/Stage.mjs +1 -262
  141. package/dist/presentation/index.d.mts +5 -0
  142. package/dist/presentation/index.mjs +5 -0
  143. package/dist/supervisor/Release.d.mts +2 -0
  144. package/dist/supervisor/Release.mjs +40 -0
  145. package/dist/supervisor/Release.mjs.map +1 -0
  146. package/dist/supervisor/Supervisor.d.mts +2 -104
  147. package/dist/supervisor/Supervisor.mjs +2 -515
  148. package/dist/supervisor/index.d.mts +3 -0
  149. package/dist/supervisor/index.mjs +3 -0
  150. package/dist/testing/HttpCassette.d.mts +98 -0
  151. package/dist/testing/HttpCassette.mjs +146 -0
  152. package/dist/testing/HttpCassette.mjs.map +1 -0
  153. package/dist/testing/Story.d.mts +31 -0
  154. package/dist/testing/Story.mjs +76 -0
  155. package/dist/testing/Story.mjs.map +1 -0
  156. package/dist/testing/TestBrowser.d.mts +191 -0
  157. package/dist/testing/TestBrowser.mjs +105 -0
  158. package/dist/testing/TestBrowser.mjs.map +1 -0
  159. package/dist/testing/TestModel.d.mts +133 -0
  160. package/dist/testing/TestModel.mjs +209 -0
  161. package/dist/testing/TestModel.mjs.map +1 -0
  162. package/dist/testing/TestPage.d.mts +2 -0
  163. package/dist/testing/TestPage.mjs +47 -0
  164. package/dist/testing/TestPage.mjs.map +1 -0
  165. package/dist/testing/index.d.mts +6 -311
  166. package/dist/testing/index.mjs +6 -521
  167. package/dist/timeline/Moment.d.mts +3 -0
  168. package/dist/timeline/Moment.mjs +3 -0
  169. package/dist/timeline/Stillness.d.mts +34 -0
  170. package/dist/timeline/Stillness.mjs +2 -0
  171. package/dist/timeline/index.d.mts +3 -0
  172. package/dist/timeline/index.mjs +3 -0
  173. package/dist/walk/Walk.d.mts +2 -0
  174. package/dist/walk/Walk.mjs +2 -0
  175. package/dist/walk/index.d.mts +2 -0
  176. package/dist/walk/index.mjs +2 -0
  177. package/package.json +54 -163
  178. package/src/Action.ts +73 -8
  179. package/src/Browser.ts +75 -9
  180. package/src/BrowserError.ts +258 -63
  181. package/src/BrowserEvent.ts +252 -55
  182. package/src/Cdp.ts +42 -0
  183. package/src/Change.ts +68 -3
  184. package/src/Frame.ts +247 -14
  185. package/src/{Style.ts → InputStyle.ts} +98 -22
  186. package/src/Layout.ts +95 -24
  187. package/src/Overlay.ts +42 -3
  188. package/src/Page.ts +144 -320
  189. package/src/PageTime.ts +29 -4
  190. package/src/Pose.ts +38 -7
  191. package/src/Site.ts +15 -3
  192. package/src/Snapshot.ts +179 -3
  193. package/src/Text.ts +60 -0
  194. package/src/Window.ts +53 -3
  195. package/src/ai/BrowserTools.ts +778 -0
  196. package/src/ai/PageControl.ts +702 -0
  197. package/src/ai/PromptCache.ts +87 -0
  198. package/src/ai/Tabs.ts +84 -0
  199. package/src/ai/ToolError.ts +50 -0
  200. package/src/ai/index.ts +36 -0
  201. package/src/ai/internal/crops.ts +38 -0
  202. package/src/ai/internal/points.ts +57 -0
  203. package/src/ai/internal/receipts.ts +107 -0
  204. package/src/index.ts +83 -6
  205. package/src/{ActionPort.ts → internal/action-port.ts} +3 -3
  206. package/src/{providers → internal/cdp}/connection.ts +19 -12
  207. package/src/internal/cdp/workerd.ts +36 -0
  208. package/src/{Clock.ts → internal/clock.ts} +20 -0
  209. package/src/internal/input/actions.ts +1 -1
  210. package/src/internal/input/dispatch.ts +2 -2
  211. package/src/internal/input/guard.inpage.ts +1 -1
  212. package/src/internal/input/guard.ts +1 -1
  213. package/src/internal/input/perform.ts +5 -5
  214. package/src/internal/input/pointer.ts +2 -2
  215. package/src/internal/input/targets.inpage.ts +3 -3
  216. package/src/{Matching.ts → internal/matching.ts} +6 -6
  217. package/src/internal/page/bridge.ts +2 -2
  218. package/src/internal/page/clock.inpage.ts +1 -1
  219. package/src/internal/page/compose.inpage.ts +2 -2
  220. package/src/internal/page/context.ts +2 -2
  221. package/src/internal/page/functions.ts +84 -0
  222. package/src/internal/page/navigation.ts +1 -1
  223. package/src/internal/page/openings.ts +2 -2
  224. package/src/internal/page/page.ts +33 -35
  225. package/src/internal/page/port.ts +14 -8
  226. package/src/internal/page/replies.ts +1 -1
  227. package/src/internal/page/requests.ts +1 -1
  228. package/src/internal/page/scripts.ts +1 -1
  229. package/src/internal/page/time.ts +1 -1
  230. package/src/internal/pictures/capture.ts +1 -4
  231. package/src/internal/pictures/dimensions.ts +1 -1
  232. package/src/internal/pictures/frame.ts +1 -1
  233. package/src/internal/pictures/pictures.ts +53 -61
  234. package/src/internal/reading/context.inpage.ts +2 -2
  235. package/src/internal/reading/expect.inpage.ts +1 -1
  236. package/src/internal/reading/layout.inpage.ts +3 -3
  237. package/src/internal/reading/layout.ts +5 -5
  238. package/src/internal/reading/outline.inpage.ts +3 -3
  239. package/src/internal/reading/reading.ts +11 -19
  240. package/src/internal/reading/ready.inpage.ts +2 -2
  241. package/src/internal/reading/ready.ts +3 -2
  242. package/src/internal/reading/subjects.inpage.ts +3 -3
  243. package/src/internal/reading/text.inpage.ts +2 -2
  244. package/src/internal/reading/walk.inpage.ts +1 -1
  245. package/src/internal/timeline/changes.inpage.ts +2 -2
  246. package/src/internal/timeline/changes.ts +3 -4
  247. package/src/internal/timeline/sight.inpage.ts +2 -2
  248. package/src/internal/timeline/window.ts +3 -4
  249. package/src/policy/Policy.ts +70 -16
  250. package/src/policy/index.ts +12 -0
  251. package/src/{film → presentation}/Film.ts +104 -37
  252. package/src/presentation/Motion.ts +45 -3
  253. package/src/presentation/Presentation.ts +47 -14
  254. package/src/presentation/Stage.ts +73 -35
  255. package/src/presentation/index.ts +30 -0
  256. package/src/presentation/{feed.ts → internal/feed.ts} +1 -1
  257. package/src/supervisor/Release.ts +45 -0
  258. package/src/supervisor/Supervisor.ts +80 -5
  259. package/src/supervisor/index.ts +18 -0
  260. package/src/supervisor/{contract.ts → internal/contract.ts} +14 -10
  261. package/src/supervisor/{lifecycle.ts → internal/lifecycle.ts} +7 -7
  262. package/src/supervisor/{runtime.ts → internal/runtime.ts} +7 -7
  263. package/src/testing/HttpCassette.ts +260 -0
  264. package/src/testing/Story.ts +103 -0
  265. package/src/testing/TestBrowser.ts +14 -4
  266. package/src/testing/TestModel.ts +297 -0
  267. package/src/testing/TestPage.ts +92 -4
  268. package/src/testing/index.ts +35 -1
  269. package/src/testing/{evidence.ts → internal/evidence.ts} +19 -11
  270. package/src/testing/{model.ts → internal/model.ts} +14 -8
  271. package/src/testing/{page.ts → internal/page.ts} +55 -56
  272. package/src/{moment → timeline}/Moment.ts +79 -29
  273. package/src/{stillness → timeline}/Stillness.ts +61 -43
  274. package/src/timeline/index.ts +18 -0
  275. package/src/{stillness/Pixels.ts → timeline/internal/pixels.ts} +2 -2
  276. package/src/{moment → timeline/internal}/words.ts +2 -2
  277. package/src/walk/Walk.ts +165 -0
  278. package/src/walk/index.ts +12 -0
  279. package/src/{plan → walk/internal}/choose.ts +23 -14
  280. package/src/{plan → walk/internal}/data.ts +37 -14
  281. package/src/{plan → walk/internal}/execute.ts +79 -36
  282. package/src/{plan → walk/internal}/record.ts +6 -6
  283. package/src/{plan → walk/internal}/targets.ts +35 -25
  284. package/dist/ActionPort.d.mts +0 -15
  285. package/dist/ActionPort.mjs.map +0 -1
  286. package/dist/Browser-CAQFhTkM.mjs.map +0 -1
  287. package/dist/Change-CxT1mp2e.d.mts +0 -80
  288. package/dist/Clock-Du5nP-nK.d.mts +0 -57
  289. package/dist/Clock.d.mts +0 -2
  290. package/dist/Clock.mjs.map +0 -1
  291. package/dist/Frame-UEH2hO5T.d.mts +0 -124
  292. package/dist/Geometry.d.mts +0 -2
  293. package/dist/Geometry.mjs.map +0 -1
  294. package/dist/Matching-MtcWZ_hA.d.mts +0 -266
  295. package/dist/Matching.d.mts +0 -2
  296. package/dist/Matching.mjs.map +0 -1
  297. package/dist/Overlay-CoGw5tL_.d.mts +0 -27
  298. package/dist/Page-BaAOshxo.mjs.map +0 -1
  299. package/dist/Page-CLzh5E9w.d.mts +0 -718
  300. package/dist/PageTime-68UPUZpZ.d.mts +0 -29
  301. package/dist/Pose-2qqGzPvb.d.mts +0 -32
  302. package/dist/Released-tURbFmal.d.mts +0 -15
  303. package/dist/Snapshot-CtBVOtuu.d.mts +0 -73
  304. package/dist/Stillness-BwP0RdI4.mjs +0 -157
  305. package/dist/Stillness-BwP0RdI4.mjs.map +0 -1
  306. package/dist/Style-T3ezDYLI.mjs.map +0 -1
  307. package/dist/Url-B7P-TWwL.d.mts +0 -26
  308. package/dist/Url.d.mts +0 -2
  309. package/dist/Url.mjs.map +0 -1
  310. package/dist/Window-BDa8MtNP.d.mts +0 -34
  311. package/dist/connection-C_jWYIwe.mjs.map +0 -1
  312. package/dist/film/Film.mjs.map +0 -1
  313. package/dist/moment/Moment.mjs.map +0 -1
  314. package/dist/plan/index.mjs.map +0 -1
  315. package/dist/pose.inpage-CLq7Mfdr.mjs.map +0 -1
  316. package/dist/presentation/Stage.mjs.map +0 -1
  317. package/dist/presentation/feed.d.mts +0 -20
  318. package/dist/presentation/feed.mjs +0 -18
  319. package/dist/presentation/feed.mjs.map +0 -1
  320. package/dist/providers/Cdp.d.mts +0 -9
  321. package/dist/providers/Cdp.mjs +0 -15
  322. package/dist/providers/Cdp.mjs.map +0 -1
  323. package/dist/providers/Chromium.d.mts +0 -32
  324. package/dist/providers/Chromium.mjs +0 -55
  325. package/dist/providers/Chromium.mjs.map +0 -1
  326. package/dist/providers/Released.d.mts +0 -2
  327. package/dist/providers/Released.mjs +0 -12
  328. package/dist/providers/Released.mjs.map +0 -1
  329. package/dist/stillness/Stillness.d.mts +0 -12
  330. package/dist/stillness/Stillness.mjs +0 -2
  331. package/dist/supervisor/Supervisor.mjs.map +0 -1
  332. package/dist/testing/index.mjs.map +0 -1
  333. package/dist/workerd/Cdp.d.mts +0 -8
  334. package/dist/workerd/Cdp.mjs +0 -13
  335. package/dist/workerd/Cdp.mjs.map +0 -1
  336. package/src/plan/index.ts +0 -36
  337. package/src/providers/Cdp.ts +0 -16
  338. package/src/providers/Chromium.ts +0 -99
  339. package/src/providers/Released.ts +0 -13
  340. package/src/workerd/Cdp.ts +0 -11
  341. /package/dist/{fold.inpage-CyVZQHZL.d.mts → internal/fold.inpage-CyVZQHZL.d.mts} +0 -0
  342. /package/dist/{rolldown-runtime-D7D4PA-g.mjs → internal/rolldown-runtime-D7D4PA-g.mjs} +0 -0
  343. /package/src/{Geometry.ts → internal/geometry.ts} +0 -0
  344. /package/src/{Url.ts → internal/url.ts} +0 -0
  345. /package/src/{stillness → timeline/internal}/utilsBundle.d.ts +0 -0
@@ -0,0 +1,497 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Action } from "../Action.mjs";
3
+ import { Region, read, zoom } from "../Frame.mjs";
4
+ import { n as wait } from "./Stillness-DCPeAN1a.mjs";
5
+ import { r as fromBrowserError, t as ToolError } from "./ToolError-DArsRS2m.mjs";
6
+ import { Action as Action$1, ActionResult, Observation, Ref as Ref$1, make as make$1 } from "../ai/PageControl.mjs";
7
+ import { Context, Effect, Layer, Option, Predicate, Ref, Schema, SchemaTransformation } from "effect";
8
+ import { Prompt, Tool, Toolkit } from "effect/ai";
9
+ //#region src/ai/internal/crops.ts
10
+ /** The crops `zoom` took, as the model is shown them before its next turn. */
11
+ /**
12
+ * The crops of `page` taken since the last turn: the latest, each with its origin, in pictures of
13
+ * `scale` pixels to a CSS pixel.
14
+ */
15
+ const cropped = (crops, page, scale = 1) => {
16
+ const current = crops.filter((crop) => crop.page === page);
17
+ const kept = current.slice(-8);
18
+ const at = (value) => Math.round(value * scale);
19
+ const unit = scale === 1 ? "CSS pixels" : "screenshot pixels";
20
+ return [...kept.flatMap(({ region, image }) => [Prompt.makePart("text", { 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.` }), Prompt.makePart("file", {
21
+ mediaType: image.mediaType,
22
+ data: image.data
23
+ })]), ...current.length > kept.length ? [Prompt.makePart("text", { text: `${current.length - kept.length} earlier crops were left out.` })] : []];
24
+ };
25
+ //#endregion
26
+ //#region src/ai/internal/points.ts
27
+ /**
28
+ * Where the pointer tools act: a model's point or ref as a target, points and regions read from a
29
+ * picture of another scale on the viewport, and the crops that placement by crop shows.
30
+ */
31
+ const target = (place) => place.x !== void 0 && place.y !== void 0 ? Option.some({
32
+ x: place.x,
33
+ y: place.y
34
+ }) : place.ref === void 0 ? Option.none() : Option.some(place.ref);
35
+ const viewportTarget = (to, scale) => typeof to === "string" ? to : {
36
+ x: to.x / scale,
37
+ y: to.y / scale
38
+ };
39
+ const viewportRegion = (region, scale) => {
40
+ const x = Math.floor(region.x / scale);
41
+ const y = Math.floor(region.y / scale);
42
+ return new Region({
43
+ x,
44
+ y,
45
+ width: Math.max(1, Math.floor((region.x + region.width) / scale) - x),
46
+ height: Math.max(1, Math.floor((region.y + region.height) / scale) - y)
47
+ });
48
+ };
49
+ const named = (to) => typeof to === "string" ? to : `(${to.x}, ${to.y})`;
50
+ const around = (point, viewport) => new Region({
51
+ x: Math.round(Math.min(Math.max(point.x - 100, 0), Math.max(viewport.width - 200, 0))),
52
+ y: Math.round(Math.min(Math.max(point.y - 60, 0), Math.max(viewport.height - 120, 0))),
53
+ width: 200,
54
+ height: 120
55
+ });
56
+ const holds = ({ region }, point) => point.x >= region.x && point.y >= region.y && point.x <= region.x + region.width && point.y <= region.y + region.height;
57
+ //#endregion
58
+ //#region src/ai/BrowserTools.ts
59
+ /**
60
+ * Browser tools for an agent in any `effect/ai` loop, over `PageControl`'s controller: `observe`
61
+ * and `act` on the refs of an observed page; the `Control` tools, which inspect, navigate, scroll,
62
+ * wait, press keys and select tabs; and the `Pointer` tools for what has no ref, such as a canvas
63
+ * game or a chart: clicking, hovering and dragging at viewport points, typing and pressing keys
64
+ * into focus, zooming, waiting for the screen to go still, and going back. The ref and `Control`
65
+ * tools keep the names, parameters and descriptions Yielded Agent gave them before 0.1.0-beta.174
66
+ * replaced them with Code Mode over CDP, but that their optional parameters read null as left out.
67
+ * Every tool returns its failure to the model as a `ToolError`.
68
+ *
69
+ * With `vision`, the default, the model sees a screenshot of the current tab before each turn, and
70
+ * the crops `zoom` took since its last, as context the loop never keeps, so only the current picture
71
+ * is ever in a request. Its pixel coordinates are viewport coordinates, which the pointer tools
72
+ * take; with `pixels: "device"`, they are the screen's own, which the tools map back. The loop that
73
+ * runs the model adds `Pictures`' `next` to each request. With `vision: "ask"`, the screenshot comes
74
+ * only before a turn after the model called `look`; with `vision: "page"`, also after pointer input
75
+ * and while the viewport shows a canvas, a video or another site's frame. `Look` is that tool, for
76
+ * the agent's toolkit beside `make`'s.
77
+ *
78
+ * `make` gives the toolkit to put in an agent, and `layer`, which provides every tool's handler
79
+ * and the `Pictures` for one run, on a page or a browser's tabs, with the run's `Controller` for an
80
+ * application's own tools on the same tabs.
81
+ *
82
+ * @stability stable
83
+ * @since 0.3.0
84
+ */
85
+ var BrowserTools_exports = /* @__PURE__ */ __exportAll({
86
+ Control: () => Control,
87
+ Controller: () => Controller,
88
+ Find: () => Find,
89
+ Look: () => Look,
90
+ Pictures: () => Pictures,
91
+ Pointer: () => Pointer,
92
+ Receipt: () => Receipt,
93
+ make: () => make
94
+ });
95
+ const absent = (schema, annotations = {}) => Schema.optionalKey(Schema.NullOr(schema).annotate(annotations)).pipe(Schema.decodeTo(Schema.optional(Schema.toType(schema)), SchemaTransformation.transformOptional({
96
+ decode: (input) => Option.filter(input, Predicate.isNotNullish),
97
+ encode: (output) => Option.filter(output, Predicate.isNotUndefined)
98
+ })));
99
+ const pixel = (axis) => Schema.Finite.annotate({ description: `Viewport ${axis} in screenshot pixels` });
100
+ const ref = absent(Schema.String, { description: "A ref from the latest observation, such as e12" });
101
+ /**
102
+ * What a pointer tool did, and what followed on its page while it ran.
103
+ *
104
+ * @stability stable
105
+ * @category schemas
106
+ * @since 0.3.0
107
+ */
108
+ const Receipt = Schema.Struct({
109
+ did: Schema.String,
110
+ action: Schema.optional(Action),
111
+ followed: Schema.Array(Schema.String)
112
+ });
113
+ const pointerTool = (name, description, parameters) => Tool.make(name, {
114
+ description,
115
+ parameters: Schema.Struct(parameters),
116
+ success: Receipt,
117
+ failure: ToolError,
118
+ failureMode: "return"
119
+ });
120
+ /**
121
+ * Tools for what has no ref, by viewport point and by keyboard focus.
122
+ *
123
+ * @stability stable
124
+ * @category toolkits
125
+ * @since 0.3.0
126
+ */
127
+ const Pointer = Toolkit.make(pointerTool("click_at", "Click a point of the screenshot, such as on a canvas game or a chart.", {
128
+ x: pixel("x"),
129
+ y: pixel("y"),
130
+ double: absent(Schema.Boolean),
131
+ button: absent(Schema.Literals([
132
+ "left",
133
+ "right",
134
+ "middle"
135
+ ]))
136
+ }), pointerTool("hover", "Move the pointer over an observed ref, or to a point of the screenshot.", {
137
+ ref,
138
+ x: absent(pixel("x")),
139
+ y: absent(pixel("y"))
140
+ }), pointerTool("drag", "Drag from one ref or point to another, such as a slider or a chart's range.", {
141
+ fromRef: ref,
142
+ fromX: absent(pixel("x")),
143
+ fromY: absent(pixel("y")),
144
+ toRef: ref,
145
+ toX: absent(pixel("x")),
146
+ toY: absent(pixel("y"))
147
+ }), pointerTool("type_text", "Type text into whatever has focus, such as a field just clicked. To type into an observed field, act with fill.", {
148
+ text: Schema.String,
149
+ submit: absent(Schema.Boolean, { description: "Press Enter afterwards" })
150
+ }), pointerTool("press_keys", "Press a key or chord on whatever has focus, such as ArrowLeft, Space or Control+A, as a game control might need.", {
151
+ keys: Schema.String,
152
+ times: absent(Schema.Int, { description: "Press it this many times; defaults to 1" }),
153
+ holdMillis: absent(Schema.Finite, { description: "Hold the keys down this long" })
154
+ }), pointerTool("zoom", "Crop a small region of the viewport, shown on its own before your next turn at the viewport's own scale: a closer look at small text, not a magnification. Click coordinates stay in viewport space.", Region.fields), pointerTool("wait_still", "Wait for the screen to stop moving, as reels coming to rest or a chart that loads; what was already moving before your last input, such as an idle animation, does not count.", { seconds: absent(Schema.Finite, { description: "At most this long; defaults to 15" }) }), Tool.make("back", {
155
+ description: "Go back to the previous page in this tab.",
156
+ parameters: Tool.EmptyParams,
157
+ success: Receipt,
158
+ failure: ToolError,
159
+ failureMode: "return"
160
+ }));
161
+ /**
162
+ * The tool that asks for a screenshot before the next turn, for `vision: "ask"` and `"page"`, which
163
+ * otherwise show none on some turns. The layer serves it whether or not the agent has it.
164
+ *
165
+ * @stability stable
166
+ * @category toolkits
167
+ * @since 0.3.0
168
+ */
169
+ const Look = Toolkit.make(Tool.make("look", {
170
+ description: "See a screenshot of the current tab before your next turn.",
171
+ parameters: Tool.EmptyParams,
172
+ success: Receipt,
173
+ failure: ToolError,
174
+ failureMode: "return"
175
+ }));
176
+ const Selector = Schema.NonEmptyString.check(Schema.isMaxLength(1024));
177
+ const Delta = Schema.Int.check(Schema.isBetween({
178
+ minimum: -1e5,
179
+ maximum: 1e5
180
+ }));
181
+ const pageTool = (name, description, parameters, success) => Tool.make(name, {
182
+ description,
183
+ parameters: Schema.Struct(parameters),
184
+ success,
185
+ failure: ToolError,
186
+ failureMode: "return"
187
+ });
188
+ /**
189
+ * Tools that inspect, navigate, scroll, wait, press keys on refs and select tabs.
190
+ *
191
+ * @stability stable
192
+ * @category toolkits
193
+ * @since 0.3.0
194
+ */
195
+ const Control = Toolkit.make(pageTool("inspect", "Inspect the page or a CSS scope within it, including open shadow roots. Frames are read inline in the observation, so leave frame unset. Narrow a truncated observation with selector or optionFilter before acting.", {
196
+ selector: absent(Selector),
197
+ frame: absent(Ref$1),
198
+ optionFilter: absent(Schema.NonEmptyString.check(Schema.isMaxLength(300)))
199
+ }, Observation), pageTool("navigate", "Navigate the current browser to a host-authorized URL. Input receipt is independent of the returned observation; never replay uncertain navigation.", { url: Schema.String.check(Schema.isMaxLength(8192)) }, ActionResult), pageTool("scroll", "Scroll the viewport or an observed scroll container by CSS pixels and inspect the result.", {
200
+ ref: absent(Ref$1),
201
+ deltaX: Delta,
202
+ deltaY: Delta
203
+ }, ActionResult), pageTool("wait", "Wait for an asynchronous condition using standard CSS and observed DOM/attribute evidence in the current frame. Optional text qualifies every state, case-sensitively; hidden with text waits until no visible match contains that text. Control kinds are semantic roles, not necessarily HTML tags. Returns a fresh observation; do not wait for an already satisfied condition or use fixed sleeps.", {
204
+ selector: Selector,
205
+ frame: absent(Ref$1),
206
+ state: Schema.Literals([
207
+ "visible",
208
+ "hidden",
209
+ "enabled",
210
+ "text"
211
+ ]),
212
+ text: absent(Schema.String.check(Schema.isMaxLength(1024))),
213
+ timeoutMillis: Schema.Int.check(Schema.isBetween({
214
+ minimum: 1,
215
+ maximum: 15e3
216
+ }))
217
+ }, Observation), pageTool("press", "Press a bounded native keyboard key on an observed focusable control, including keyboard-only links with pointerEvents=none and tabindex=0. Revalidates identity, visible state and native focus; a pointer hit is not required. Never replay uncertain input.", {
218
+ ref: Ref$1,
219
+ key: Schema.Literals([
220
+ "Enter",
221
+ "Escape",
222
+ "Tab",
223
+ "ArrowDown",
224
+ "ArrowUp",
225
+ "ArrowLeft",
226
+ "ArrowRight",
227
+ "Home",
228
+ "End",
229
+ "Space",
230
+ "Backspace",
231
+ "Delete"
232
+ ])
233
+ }, ActionResult), pageTool("select_tab", "Select an observed tab or popup in this browser context and inspect it. References from the previous page expire.", { ref: Ref$1 }, Observation));
234
+ /**
235
+ * The tool that finds lines of the whole page's outline, in view or not. The layer serves it
236
+ * whether or not the agent has it.
237
+ *
238
+ * @stability stable
239
+ * @category toolkits
240
+ * @since 0.3.0
241
+ */
242
+ const Find = Toolkit.make(pageTool("find", "Find the lines of the whole page's outline, in view or not, that hold this text, ignoring case: controls with their refs, headings and text.", { text: Schema.NonEmptyString.check(Schema.isMaxLength(300)) }, Observation));
243
+ const observe = Tool.make("observe", {
244
+ description: "Read the visible page and controls. Only observed controls may receive actions.",
245
+ parameters: Tool.EmptyParams,
246
+ success: Observation,
247
+ failure: ToolError,
248
+ failureMode: "return"
249
+ });
250
+ const single = Toolkit.make(observe, pageTool("act", "Perform one action on an observed ref and return the next observation. Never repeat an acknowledged action because its observation failed.", { action: Action$1 }, ActionResult));
251
+ const batched = Toolkit.make(observe, pageTool("act", "Perform 1–8 sequential actions on already observed controls. Stop at page/dialog transitions. completed counts acknowledged actions; never replay them.", { actions: Schema.Array(Action$1).check(Schema.isMinLength(1), Schema.isMaxLength(8)) }, ActionResult));
252
+ /**
253
+ * The controller of the run `layer` serves, for an application's own tools beside these, such as a
254
+ * chart's: they act on the tab the model sees now, with the run's task, and say what followed.
255
+ *
256
+ * @stability stable
257
+ * @category services
258
+ * @since 0.3.0
259
+ */
260
+ var Controller = class extends Context.Service()("effect-browser/ai/BrowserTools/Controller") {};
261
+ /**
262
+ * What the model sees before its next turn, for the loop that runs it: `next`, the current tab's
263
+ * screenshot when `vision` says so, and the crops `zoom` took since the last turn, to add to the
264
+ * coming request and never keep. A loop that shows the page its own way takes the crops with
265
+ * `crops` instead, as the model is shown them for the tab `page`. Either hands each crop over once.
266
+ *
267
+ * @stability stable
268
+ * @category services
269
+ * @since 0.3.0
270
+ */
271
+ var Pictures = class extends Context.Service()("effect-browser/ai/BrowserTools/Pictures") {};
272
+ const text = (value) => ({
273
+ type: "text",
274
+ text: value
275
+ });
276
+ /**
277
+ * What the model sees before a turn: the current tab's screenshot if `screen` says so, and the crops
278
+ * since its last. A screenshot in device pixels sets `scale`, its pixels to a CSS pixel.
279
+ */
280
+ const pictures = (controller, zooms, screen, pixels, scale) => Effect.gen(function* () {
281
+ const parts = yield* Effect.flatMap(controller.look, (page) => Effect.gen(function* () {
282
+ const zoomed = yield* Ref.getAndSet(zooms, []);
283
+ if (!(yield* screen(page))) return cropped(zoomed, page.id, yield* Ref.get(scale));
284
+ const { image: shot } = yield* read(page, {
285
+ after: "input",
286
+ scale: pixels
287
+ });
288
+ if (pixels === "device") yield* Ref.set(scale, shot.width / (yield* page.viewport).width);
289
+ const crops = cropped(zoomed, page.id, yield* Ref.get(scale));
290
+ return [
291
+ text(`The current tab's viewport, ${shot.width}x${shot.height}. Its pixel coordinates are viewport coordinates.`),
292
+ {
293
+ type: "file",
294
+ mediaType: shot.mediaType,
295
+ data: shot.data
296
+ },
297
+ ...crops
298
+ ];
299
+ })).pipe(Effect.catch((error) => Effect.succeed([text(`(no screenshot of the current tab: ${error.message})`)])), controller.withTask);
300
+ return parts.length === 0 ? Prompt.empty : Prompt.make([{
301
+ role: "user",
302
+ content: parts
303
+ }]);
304
+ });
305
+ const pictorial = () => {
306
+ const shown = (element) => {
307
+ const box = element.getBoundingClientRect();
308
+ const width = Math.min(box.right, window.innerWidth) - Math.max(box.left, 0);
309
+ const height = Math.min(box.bottom, window.innerHeight) - Math.max(box.top, 0);
310
+ return width >= 64 && height >= 64;
311
+ };
312
+ return Array.from(document.querySelectorAll("canvas, video, iframe")).some((element) => shown(element) && (!(element instanceof HTMLIFrameElement) || element.contentDocument === null || element.contentDocument.querySelector("canvas, video, iframe") !== null));
313
+ };
314
+ const missing = (what) => Effect.fail(new ToolError({
315
+ code: "invalid",
316
+ message: `Give ${what} a ref from the observation, or x and y from the screenshot.`
317
+ }));
318
+ /** The `zoom` tool's handler: a crop of the current tab, shown before the next turn. */
319
+ const cropping = (controller, zooms, vision, scale, zoomed) => (region) => vision !== false ? Effect.all([controller.current, Ref.get(scale)]).pipe(Effect.flatMap(([page, scale]) => zoom(page, viewportRegion(new Region(region), scale), zoomed)), Effect.tap((zoom) => Ref.update(zooms, (crops) => [...crops, zoom])), Effect.map(() => ({
320
+ did: `Cropped (${region.x}, ${region.y}), ${region.width}x${region.height}: it is shown before your next turn if this tab is still current.`,
321
+ followed: []
322
+ })), Effect.mapError(fromBrowserError), controller.withTask) : Effect.fail(new ToolError({
323
+ code: "invalid",
324
+ message: "These tools show no pictures, so a crop cannot be shown."
325
+ }));
326
+ /**
327
+ * The pointer tools' handlers over the controller's current tab. Each sets `pointed` once its input
328
+ * reaches the page, but going back. Points and crops are in the pictures' pixels, `scale` to a
329
+ * CSS pixel. With placement by crop, `framed` holds the crops around the points last asked.
330
+ */
331
+ const pointing = (controller, zooms, vision, pointed, pixels, scale, framed) => {
332
+ const zoomed = pixels === "device" ? { scale: "device" } : void 0;
333
+ const act = (run, did, action) => controller.perform(run).pipe(Effect.tap(() => action === void 0 || action._tag === "Back" ? Effect.void : Ref.set(pointed, true)), Effect.map(({ value, followed }) => action === void 0 ? {
334
+ did: did(value),
335
+ followed
336
+ } : {
337
+ did: did(value),
338
+ followed,
339
+ action
340
+ }), Effect.mapError(fromBrowserError));
341
+ const placed = (targets, asked, run) => Effect.gen(function* () {
342
+ const points = targets.filter((to) => typeof to !== "string");
343
+ if (framed === void 0 || vision === false || points.length === 0) return yield* run;
344
+ const pending = yield* Ref.get(zooms);
345
+ const shown = (yield* Ref.get(framed)).filter((crop) => !pending.includes(crop));
346
+ if (points.every((point) => shown.some((crop) => holds(crop, point)))) {
347
+ yield* Ref.set(framed, []);
348
+ return yield* run;
349
+ }
350
+ const crops = yield* Effect.gen(function* () {
351
+ const page = yield* controller.current;
352
+ const viewport = yield* page.viewport;
353
+ return yield* Effect.forEach(points, (point) => zoom(page, around(point, viewport), zoomed));
354
+ }).pipe(Effect.mapError(fromBrowserError), controller.withTask);
355
+ yield* Ref.set(framed, crops);
356
+ yield* Ref.update(zooms, (all) => [...all, ...crops]);
357
+ return {
358
+ did: `Not done yet: a crop around ${asked} is shown before your next turn. Call again at the points you mean, inside the crops, to act.`,
359
+ followed: []
360
+ };
361
+ });
362
+ return Pointer.of({
363
+ click_at: ({ x, y, double, button }) => Effect.flatMap(Ref.get(scale), (scale) => {
364
+ const options = {
365
+ clickCount: double === true ? 2 : 1,
366
+ ...button === void 0 ? {} : { button }
367
+ };
368
+ const at = {
369
+ x: x / scale,
370
+ y: y / scale
371
+ };
372
+ return placed([at], `(${x}, ${y})`, act((page) => page.click(at, options), ({ element }) => `Clicked ${element} at (${x}, ${y}).`, {
373
+ _tag: "Click",
374
+ target: at,
375
+ options
376
+ }));
377
+ }),
378
+ hover: (place) => Option.match(target(place), {
379
+ onNone: () => missing("hover"),
380
+ onSome: (to) => Effect.flatMap(Ref.get(scale), (scale) => {
381
+ const at = viewportTarget(to, scale);
382
+ return act((page) => page.hover(at), () => `Hovered over ${named(to)}.`, {
383
+ _tag: "Hover",
384
+ target: at
385
+ });
386
+ })
387
+ }),
388
+ drag: (drag) => {
389
+ const from = target({
390
+ ref: drag.fromRef,
391
+ x: drag.fromX,
392
+ y: drag.fromY
393
+ });
394
+ const to = target({
395
+ ref: drag.toRef,
396
+ x: drag.toX,
397
+ y: drag.toY
398
+ });
399
+ return Option.isNone(from) || Option.isNone(to) ? missing("each end of a drag") : Effect.flatMap(Ref.get(scale), (scale) => {
400
+ const start = viewportTarget(from.value, scale);
401
+ const end = viewportTarget(to.value, scale);
402
+ return placed([start, end], `each end, ${named(from.value)} and ${named(to.value)},`, act((page) => page.drag(start, end), () => `Dragged from ${named(from.value)} to ${named(to.value)}.`, {
403
+ _tag: "Drag",
404
+ from: start,
405
+ to: end
406
+ }));
407
+ });
408
+ },
409
+ type_text: ({ text: typed, submit }) => act((page) => page.type(typed, { submit }), () => `Typed ${JSON.stringify(typed)}${submit === true ? " and pressed Enter" : ""}.`, {
410
+ _tag: "Type",
411
+ text: typed,
412
+ ...submit === void 0 ? {} : { options: { submit } }
413
+ }),
414
+ press_keys: ({ keys, times, holdMillis }) => act((page) => page.press(keys, {
415
+ times,
416
+ holdMillis
417
+ }), () => `Pressed ${keys}${times === void 0 || times === 1 ? "" : ` ${times} times`}.`, {
418
+ _tag: "Press",
419
+ keys,
420
+ options: {
421
+ ...times === void 0 ? {} : { times },
422
+ ...holdMillis === void 0 ? {} : { holdMillis }
423
+ }
424
+ }),
425
+ zoom: cropping(controller, zooms, vision, scale, zoomed),
426
+ wait_still: ({ seconds }) => act((page) => wait(page, {
427
+ still: "foreground",
428
+ quiet: "600 millis",
429
+ timeout: `${Math.min(Math.max(seconds ?? 15, 0), 30)} seconds`
430
+ }), () => "The screen is still."),
431
+ back: () => act((page) => page.back, () => "Went back.", { _tag: "Back" })
432
+ });
433
+ };
434
+ /** One mode's tools and the layer that serves them for a run. */
435
+ const tooling = (refs, serve) => {
436
+ const toolkit = Toolkit.merge(refs, Control, Pointer);
437
+ /** Every tool's handler, and the `Pictures` and `Controller` of one run on `target`. */
438
+ const layer = (target, options = {}) => Layer.unwrap(Effect.gen(function* () {
439
+ const controller = yield* make$1(target, options);
440
+ const zooms = yield* Ref.make([...options.initialZooms ?? []]);
441
+ const vision = options.vision ?? true;
442
+ const pixels = options.pixels ?? "css";
443
+ const scale = yield* Ref.make(1);
444
+ const { control } = controller;
445
+ const asked = yield* Ref.make(false);
446
+ const pointed = yield* Ref.make(false);
447
+ const framed = options.placement === "crop" ? yield* Ref.make([]) : void 0;
448
+ const wanted = (page) => Effect.gen(function* () {
449
+ const looked = yield* Ref.getAndSet(asked, false);
450
+ const input = yield* Ref.getAndSet(pointed, false);
451
+ if (vision === true || looked) return true;
452
+ if (vision !== "page") return false;
453
+ return input || (yield* page.read(pictorial, {
454
+ arg: void 0,
455
+ result: Schema.Boolean
456
+ })).value;
457
+ });
458
+ const handlers = Layer.mergeAll(serve(controller.actions), Control.toLayer({
459
+ inspect: control.inspect,
460
+ navigate: control.navigate,
461
+ scroll: control.scroll,
462
+ wait: control.wait,
463
+ press: control.press,
464
+ select_tab: control.selectTab
465
+ }), Pointer.toLayer(pointing(controller, zooms, vision, pointed, pixels, scale, framed)), Find.toLayer({ find: control.find }), Look.toLayer({ look: () => vision === false ? Effect.fail(new ToolError({
466
+ code: "invalid",
467
+ message: "These tools show no pictures."
468
+ })) : Ref.set(asked, true).pipe(Effect.as({
469
+ did: vision === "ask" || vision === "page" ? "A screenshot of the current tab is shown before your next turn." : "A screenshot is shown before every turn already.",
470
+ followed: []
471
+ })) }));
472
+ const shown = Pictures.of({
473
+ next: vision === false ? Effect.succeed(Prompt.empty) : pictures(controller, zooms, wanted, pixels, scale),
474
+ crops: (page) => Effect.zipWith(Ref.getAndSet(zooms, []), Ref.get(scale), (crops, scale) => cropped(crops, page, scale))
475
+ });
476
+ return Layer.mergeAll(handlers, Layer.succeed(Pictures, shown), Layer.succeed(Controller, controller));
477
+ }));
478
+ return {
479
+ toolkit,
480
+ layer
481
+ };
482
+ };
483
+ const singleTools = tooling(single, (actions) => single.toLayer({
484
+ observe: () => actions.observe,
485
+ act: ({ action }) => actions.act([action])
486
+ }));
487
+ const batchedTools = tooling(batched, (actions) => batched.toLayer({
488
+ observe: () => actions.observe,
489
+ act: ({ actions: steps }) => actions.act(steps)
490
+ }));
491
+ function make(options = {}) {
492
+ return options.mode === "single" ? singleTools : batchedTools;
493
+ }
494
+ //#endregion
495
+ export { Look as a, Receipt as c, Find as i, make as l, Control as n, Pictures as o, Controller as r, Pointer as s, BrowserTools_exports as t };
496
+
497
+ //# sourceMappingURL=BrowserTools-Yi3lOX4h.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowserTools-Yi3lOX4h.mjs","names":["PageControl.Ref","PageControl.Observation","PageControl.ActionResult","PageControl.Action","Frame.read","Frame.zoom","Points.viewportRegion","Frame.Region","Points.holds","Points.around","Points.target","Points.viewportTarget","Points.named","Stillness.wait","PageControl.make"],"sources":["../../src/ai/internal/crops.ts","../../src/ai/internal/points.ts","../../src/ai/BrowserTools.ts"],"sourcesContent":["/** The crops `zoom` took, as the model is shown them before its next turn. */\nimport { Prompt } from \"effect/ai\";\n\nimport type { Zoom } from \"../../Frame.ts\";\n\n/** At most this many crops are shown at once: the latest. */\nconst maxZooms = 8;\n\n/**\n * The crops of `page` taken since the last turn: the latest, each with its origin, in pictures of\n * `scale` pixels to a CSS pixel.\n */\nexport const cropped = (\n crops: ReadonlyArray<Zoom>,\n page: string,\n scale = 1,\n): ReadonlyArray<Prompt.UserMessagePart> => {\n const current = crops.filter((crop) => crop.page === page);\n const kept = current.slice(-maxZooms);\n const at = (value: number) => Math.round(value * scale);\n const unit = scale === 1 ? \"CSS pixels\" : \"screenshot pixels\";\n\n return [\n ...kept.flatMap(({ region, image }) => [\n Prompt.makePart(\"text\", {\n 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.`,\n }),\n Prompt.makePart(\"file\", { mediaType: image.mediaType, data: image.data }),\n ]),\n ...(current.length > kept.length\n ? [\n Prompt.makePart(\"text\", {\n text: `${current.length - kept.length} earlier crops were left out.`,\n }),\n ]\n : []),\n ];\n};\n","/**\n * Where the pointer tools act: a model's point or ref as a target, points and regions read from a\n * picture of another scale on the viewport, and the crops that placement by crop shows.\n */\nimport { Option } from \"effect\";\n\nimport { Region, type Zoom } from \"../../Frame.ts\";\nimport type * as Page from \"../../Page.ts\";\n\n// A point is the more specific of the two, such as a spot on a canvas a ref names.\nexport const target = (place: {\n readonly ref?: string | undefined;\n readonly x?: number | undefined;\n readonly y?: number | undefined;\n}): Option.Option<Page.Target> =>\n place.x !== undefined && place.y !== undefined\n ? Option.some({ x: place.x, y: place.y })\n : place.ref === undefined\n ? Option.none()\n : Option.some(place.ref);\n\n// A target the model read from a picture of `scale` pixels to a CSS pixel, on the viewport.\nexport const viewportTarget = (to: Page.Target, scale: number): Page.Target =>\n typeof to === \"string\" ? to : { x: to.x / scale, y: to.y / scale };\n\n// A region read from such a picture, in the whole CSS pixels that hold it within the viewport.\nexport const viewportRegion = (region: Region, scale: number) => {\n const x = Math.floor(region.x / scale);\n const y = Math.floor(region.y / scale);\n\n return new Region({\n x,\n y,\n width: Math.max(1, Math.floor((region.x + region.width) / scale) - x),\n height: Math.max(1, Math.floor((region.y + region.height) / scale) - y),\n });\n};\n\nexport const named = (to: Page.Target) => (typeof to === \"string\" ? to : `(${to.x}, ${to.y})`);\n\n// The 200x120 region around a point, within a viewport at least that size.\nexport const around = (\n point: Page.Point,\n viewport: { readonly width: number; readonly height: number },\n) =>\n new Region({\n x: Math.round(Math.min(Math.max(point.x - 100, 0), Math.max(viewport.width - 200, 0))),\n y: Math.round(Math.min(Math.max(point.y - 60, 0), Math.max(viewport.height - 120, 0))),\n width: 200,\n height: 120,\n });\n\nexport const holds = ({ region }: Zoom, point: Page.Point) =>\n point.x >= region.x &&\n point.y >= region.y &&\n point.x <= region.x + region.width &&\n point.y <= region.y + region.height;\n","/**\n * Browser tools for an agent in any `effect/ai` loop, over `PageControl`'s controller: `observe`\n * and `act` on the refs of an observed page; the `Control` tools, which inspect, navigate, scroll,\n * wait, press keys and select tabs; and the `Pointer` tools for what has no ref, such as a canvas\n * game or a chart: clicking, hovering and dragging at viewport points, typing and pressing keys\n * into focus, zooming, waiting for the screen to go still, and going back. The ref and `Control`\n * tools keep the names, parameters and descriptions Yielded Agent gave them before 0.1.0-beta.174\n * replaced them with Code Mode over CDP, but that their optional parameters read null as left out.\n * Every tool returns its failure to the model as a `ToolError`.\n *\n * With `vision`, the default, the model sees a screenshot of the current tab before each turn, and\n * the crops `zoom` took since its last, as context the loop never keeps, so only the current picture\n * is ever in a request. Its pixel coordinates are viewport coordinates, which the pointer tools\n * take; with `pixels: \"device\"`, they are the screen's own, which the tools map back. The loop that\n * runs the model adds `Pictures`' `next` to each request. With `vision: \"ask\"`, the screenshot comes\n * only before a turn after the model called `look`; with `vision: \"page\"`, also after pointer input\n * and while the viewport shows a canvas, a video or another site's frame. `Look` is that tool, for\n * the agent's toolkit beside `make`'s.\n *\n * `make` gives the toolkit to put in an agent, and `layer`, which provides every tool's handler\n * and the `Pictures` for one run, on a page or a browser's tabs, with the run's `Controller` for an\n * application's own tools on the same tabs.\n *\n * @stability stable\n * @since 0.3.0\n */\nimport {\n Context,\n Effect,\n Layer,\n Option,\n Predicate,\n Ref,\n Schema,\n SchemaTransformation,\n} from \"effect\";\nimport { Prompt, Tool, Toolkit } from \"effect/ai\";\n\nimport { Action } from \"../Action.ts\";\nimport type { BrowserError } from \"../BrowserError.ts\";\nimport * as Frame from \"../Frame.ts\";\nimport type * as Page from \"../Page.ts\";\nimport * as Stillness from \"../timeline/Stillness.ts\";\nimport { cropped } from \"./internal/crops.ts\";\nimport * as Points from \"./internal/points.ts\";\nimport * as PageControl from \"./PageControl.ts\";\nimport { fromBrowserError, ToolError } from \"./ToolError.ts\";\n\n// A parameter a model may leave out. Its JSON Schema allows null, as an optional one's does, and\n// models send null for one they mean to leave out, so null reads as absent rather than refused.\nconst absent = <S extends Schema.Top>(\n schema: S,\n annotations: { readonly description?: string } = {},\n) =>\n Schema.optionalKey(Schema.NullOr(schema).annotate(annotations)).pipe(\n Schema.decodeTo(\n Schema.optional(Schema.toType(schema)),\n SchemaTransformation.transformOptional<S[\"Type\"] | undefined, S[\"Type\"] | null>({\n decode: (input) => Option.filter(input, Predicate.isNotNullish),\n encode: (output) => Option.filter(output, Predicate.isNotUndefined),\n }),\n ),\n );\n\nconst pixel = (axis: \"x\" | \"y\") =>\n Schema.Finite.annotate({ description: `Viewport ${axis} in screenshot pixels` });\n\nconst ref = absent(Schema.String, {\n description: \"A ref from the latest observation, such as e12\",\n});\n\n/**\n * What a pointer tool did, and what followed on its page while it ran.\n *\n * @stability stable\n * @category schemas\n * @since 0.3.0\n */\nexport const Receipt = Schema.Struct({\n did: Schema.String,\n action: Schema.optional(Action),\n followed: Schema.Array(Schema.String),\n});\n\nconst pointerTool = <const Name extends string, Parameters extends Schema.Struct.Fields>(\n name: Name,\n description: string,\n parameters: Parameters,\n) =>\n Tool.make(name, {\n description,\n parameters: Schema.Struct(parameters),\n success: Receipt,\n failure: ToolError,\n failureMode: \"return\",\n });\n\n/**\n * Tools for what has no ref, by viewport point and by keyboard focus.\n *\n * @stability stable\n * @category toolkits\n * @since 0.3.0\n */\nexport const Pointer = Toolkit.make(\n pointerTool(\"click_at\", \"Click a point of the screenshot, such as on a canvas game or a chart.\", {\n x: pixel(\"x\"),\n y: pixel(\"y\"),\n double: absent(Schema.Boolean),\n button: absent(Schema.Literals([\"left\", \"right\", \"middle\"])),\n }),\n pointerTool(\"hover\", \"Move the pointer over an observed ref, or to a point of the screenshot.\", {\n ref,\n x: absent(pixel(\"x\")),\n y: absent(pixel(\"y\")),\n }),\n pointerTool(\n \"drag\",\n \"Drag from one ref or point to another, such as a slider or a chart's range.\",\n {\n fromRef: ref,\n fromX: absent(pixel(\"x\")),\n fromY: absent(pixel(\"y\")),\n toRef: ref,\n toX: absent(pixel(\"x\")),\n toY: absent(pixel(\"y\")),\n },\n ),\n pointerTool(\n \"type_text\",\n \"Type text into whatever has focus, such as a field just clicked. To type into an observed field, act with fill.\",\n {\n text: Schema.String,\n submit: absent(Schema.Boolean, { description: \"Press Enter afterwards\" }),\n },\n ),\n pointerTool(\n \"press_keys\",\n \"Press a key or chord on whatever has focus, such as ArrowLeft, Space or Control+A, as a game control might need.\",\n {\n keys: Schema.String,\n times: absent(Schema.Int, { description: \"Press it this many times; defaults to 1\" }),\n holdMillis: absent(Schema.Finite, { description: \"Hold the keys down this long\" }),\n },\n ),\n pointerTool(\n \"zoom\",\n \"Crop a small region of the viewport, shown on its own before your next turn at the viewport's own scale: a closer look at small text, not a magnification. Click coordinates stay in viewport space.\",\n Frame.Region.fields,\n ),\n pointerTool(\n \"wait_still\",\n \"Wait for the screen to stop moving, as reels coming to rest or a chart that loads; what was already moving before your last input, such as an idle animation, does not count.\",\n { seconds: absent(Schema.Finite, { description: \"At most this long; defaults to 15\" }) },\n ),\n // Without parameters, not with an empty struct: an empty struct's JSON Schema has no object root,\n // which OpenAI's structured outputs reject for the whole request.\n Tool.make(\"back\", {\n description: \"Go back to the previous page in this tab.\",\n parameters: Tool.EmptyParams,\n success: Receipt,\n failure: ToolError,\n failureMode: \"return\",\n }),\n);\n\n/**\n * The tool that asks for a screenshot before the next turn, for `vision: \"ask\"` and `\"page\"`, which\n * otherwise show none on some turns. The layer serves it whether or not the agent has it.\n *\n * @stability stable\n * @category toolkits\n * @since 0.3.0\n */\nexport const Look = Toolkit.make(\n Tool.make(\"look\", {\n description: \"See a screenshot of the current tab before your next turn.\",\n parameters: Tool.EmptyParams,\n success: Receipt,\n failure: ToolError,\n failureMode: \"return\",\n }),\n);\n\nconst Selector = Schema.NonEmptyString.check(Schema.isMaxLength(1_024));\n\nconst Delta = Schema.Int.check(Schema.isBetween({ minimum: -100_000, maximum: 100_000 }));\n\nconst pageTool = <\n const Name extends string,\n Parameters extends Schema.Struct.Fields,\n Success extends Schema.Top,\n>(\n name: Name,\n description: string,\n parameters: Parameters,\n success: Success,\n) =>\n Tool.make(name, {\n description,\n parameters: Schema.Struct(parameters),\n success,\n failure: ToolError,\n failureMode: \"return\",\n });\n\n/**\n * Tools that inspect, navigate, scroll, wait, press keys on refs and select tabs.\n *\n * @stability stable\n * @category toolkits\n * @since 0.3.0\n */\nexport const Control = Toolkit.make(\n pageTool(\n \"inspect\",\n \"Inspect the page or a CSS scope within it, including open shadow roots. Frames are read inline in the observation, so leave frame unset. Narrow a truncated observation with selector or optionFilter before acting.\",\n {\n selector: absent(Selector),\n frame: absent(PageControl.Ref),\n optionFilter: absent(Schema.NonEmptyString.check(Schema.isMaxLength(300))),\n },\n PageControl.Observation,\n ),\n pageTool(\n \"navigate\",\n \"Navigate the current browser to a host-authorized URL. Input receipt is independent of the returned observation; never replay uncertain navigation.\",\n { url: Schema.String.check(Schema.isMaxLength(8_192)) },\n PageControl.ActionResult,\n ),\n pageTool(\n \"scroll\",\n \"Scroll the viewport or an observed scroll container by CSS pixels and inspect the result.\",\n { ref: absent(PageControl.Ref), deltaX: Delta, deltaY: Delta },\n PageControl.ActionResult,\n ),\n pageTool(\n \"wait\",\n \"Wait for an asynchronous condition using standard CSS and observed DOM/attribute evidence in the current frame. Optional text qualifies every state, case-sensitively; hidden with text waits until no visible match contains that text. Control kinds are semantic roles, not necessarily HTML tags. Returns a fresh observation; do not wait for an already satisfied condition or use fixed sleeps.\",\n {\n selector: Selector,\n frame: absent(PageControl.Ref),\n state: Schema.Literals([\"visible\", \"hidden\", \"enabled\", \"text\"]),\n text: absent(Schema.String.check(Schema.isMaxLength(1_024))),\n timeoutMillis: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 15_000 })),\n },\n PageControl.Observation,\n ),\n pageTool(\n \"press\",\n \"Press a bounded native keyboard key on an observed focusable control, including keyboard-only links with pointerEvents=none and tabindex=0. Revalidates identity, visible state and native focus; a pointer hit is not required. Never replay uncertain input.\",\n {\n ref: PageControl.Ref,\n key: Schema.Literals([\n \"Enter\",\n \"Escape\",\n \"Tab\",\n \"ArrowDown\",\n \"ArrowUp\",\n \"ArrowLeft\",\n \"ArrowRight\",\n \"Home\",\n \"End\",\n \"Space\",\n \"Backspace\",\n \"Delete\",\n ]),\n },\n PageControl.ActionResult,\n ),\n pageTool(\n \"select_tab\",\n \"Select an observed tab or popup in this browser context and inspect it. References from the previous page expire.\",\n { ref: PageControl.Ref },\n PageControl.Observation,\n ),\n);\n\n/**\n * The tool that finds lines of the whole page's outline, in view or not. The layer serves it\n * whether or not the agent has it.\n *\n * @stability stable\n * @category toolkits\n * @since 0.3.0\n */\nexport const Find = Toolkit.make(\n pageTool(\n \"find\",\n \"Find the lines of the whole page's outline, in view or not, that hold this text, ignoring case: controls with their refs, headings and text.\",\n { text: Schema.NonEmptyString.check(Schema.isMaxLength(300)) },\n PageControl.Observation,\n ),\n);\n\nconst observe = Tool.make(\"observe\", {\n description: \"Read the visible page and controls. Only observed controls may receive actions.\",\n parameters: Tool.EmptyParams,\n success: PageControl.Observation,\n failure: ToolError,\n failureMode: \"return\",\n});\n\n// `act` takes one action, or up to eight in order.\nconst single = Toolkit.make(\n observe,\n pageTool(\n \"act\",\n \"Perform one action on an observed ref and return the next observation. Never repeat an acknowledged action because its observation failed.\",\n { action: PageControl.Action },\n PageControl.ActionResult,\n ),\n);\n\nconst batched = Toolkit.make(\n observe,\n pageTool(\n \"act\",\n \"Perform 1–8 sequential actions on already observed controls. Stop at page/dialog transitions. completed counts acknowledged actions; never replay them.\",\n {\n actions: Schema.Array(PageControl.Action).check(Schema.isMinLength(1), Schema.isMaxLength(8)),\n },\n PageControl.ActionResult,\n ),\n);\n\n/**\n * The controller of the run `layer` serves, for an application's own tools beside these, such as a\n * chart's: they act on the tab the model sees now, with the run's task, and say what followed.\n *\n * @stability stable\n * @category services\n * @since 0.3.0\n */\nexport class Controller extends Context.Service<Controller, PageControl.Controller>()(\n \"effect-browser/ai/BrowserTools/Controller\",\n) {}\n\n/**\n * What the model sees before its next turn, for the loop that runs it: `next`, the current tab's\n * screenshot when `vision` says so, and the crops `zoom` took since the last turn, to add to the\n * coming request and never keep. A loop that shows the page its own way takes the crops with\n * `crops` instead, as the model is shown them for the tab `page`. Either hands each crop over once.\n *\n * @stability stable\n * @category services\n * @since 0.3.0\n */\nexport class Pictures extends Context.Service<\n Pictures,\n {\n readonly next: Effect.Effect<Prompt.Prompt>;\n readonly crops: (page: string) => Effect.Effect<ReadonlyArray<Prompt.UserMessagePart>>;\n }\n>()(\"effect-browser/ai/BrowserTools/Pictures\") {}\n\n/**\n * What the model sees of the page; see `LayerOptions`.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Vision = boolean | \"ask\" | \"page\";\n\n/**\n * @stability stable\n * @category options\n * @since 0.3.0\n */\nexport interface LayerOptions extends PageControl.Options {\n readonly initialZooms?: ReadonlyArray<Frame.Zoom> | undefined;\n /**\n * What the model sees of the page: `true`, the default, a screenshot of the current tab before\n * each turn; `\"ask\"`, one only before a turn after `look`; `\"page\"`, one also after pointer input\n * and while the viewport shows a canvas, a video or another site's frame; `false`, no pictures.\n */\n readonly vision?: Vision | undefined;\n /**\n * The pixels of the screenshots and crops the model sees, and of the points it gives back:\n * `\"css\"`, the default, or `\"device\"`, the screen's own, as many to a CSS pixel as the browser's\n * device scale factor, so smaller below 1 and sharper above.\n */\n readonly pixels?: \"css\" | \"device\" | undefined;\n /**\n * How `click_at` and `drag` place a point: `\"point\"`, the default, at once; `\"crop\"`, first\n * showing a crop of the viewport around each point, then placing once called at points inside\n * crops already shown. A ref needs no crop.\n */\n readonly placement?: \"point\" | \"crop\" | undefined;\n}\n\nconst text = (value: string) => ({ type: \"text\" as const, text: value });\n\n/**\n * What the model sees before a turn: the current tab's screenshot if `screen` says so, and the crops\n * since its last. A screenshot in device pixels sets `scale`, its pixels to a CSS pixel.\n */\nconst pictures = (\n controller: PageControl.Controller,\n zooms: Ref.Ref<Array<Frame.Zoom>>,\n screen: (page: Page.Page) => Effect.Effect<boolean, BrowserError>,\n pixels: \"css\" | \"device\",\n scale: Ref.Ref<number>,\n) =>\n Effect.gen(function* () {\n // A look before a turn shows a tab an action opened, as `follow` says.\n const parts = yield* Effect.flatMap(controller.look, (page) =>\n Effect.gen(function* () {\n const zoomed = yield* Ref.getAndSet(zooms, []);\n\n if (!(yield* screen(page))) return cropped(zoomed, page.id, yield* Ref.get(scale));\n const { image: shot } = yield* Frame.read(page, { after: \"input\", scale: pixels });\n\n if (pixels === \"device\") yield* Ref.set(scale, shot.width / (yield* page.viewport).width);\n const crops = cropped(zoomed, page.id, yield* Ref.get(scale));\n\n return [\n text(\n `The current tab's viewport, ${shot.width}x${shot.height}. Its pixel coordinates are viewport coordinates.`,\n ),\n { type: \"file\" as const, mediaType: shot.mediaType, data: shot.data },\n ...crops,\n ];\n }),\n ).pipe(\n Effect.catch((error) =>\n Effect.succeed([text(`(no screenshot of the current tab: ${error.message})`)]),\n ),\n controller.withTask,\n );\n\n return parts.length === 0 ? Prompt.empty : Prompt.make([{ role: \"user\", content: parts }]);\n });\n\n// Whether the viewport shows what an outline cannot: a canvas, a video, or a frame from another\n// site or holding either, at least 64 pixels square. Page-side code: it stands alone.\nconst pictorial = () => {\n const shown = (element: Element) => {\n const box = element.getBoundingClientRect();\n const width = Math.min(box.right, window.innerWidth) - Math.max(box.left, 0);\n const height = Math.min(box.bottom, window.innerHeight) - Math.max(box.top, 0);\n\n return width >= 64 && height >= 64;\n };\n\n return Array.from(document.querySelectorAll(\"canvas, video, iframe\")).some(\n (element) =>\n shown(element) &&\n (!(element instanceof HTMLIFrameElement) ||\n element.contentDocument === null ||\n element.contentDocument.querySelector(\"canvas, video, iframe\") !== null),\n );\n};\n\nconst missing = (what: string) =>\n Effect.fail(\n new ToolError({\n code: \"invalid\",\n message: `Give ${what} a ref from the observation, or x and y from the screenshot.`,\n }),\n );\n\n/** The `zoom` tool's handler: a crop of the current tab, shown before the next turn. */\nconst cropping =\n (\n controller: PageControl.Controller,\n zooms: Ref.Ref<Array<Frame.Zoom>>,\n vision: Vision,\n scale: Ref.Ref<number>,\n zoomed: { readonly scale: \"device\" } | undefined,\n ) =>\n (region: ConstructorParameters<typeof Frame.Region>[0]) =>\n vision !== false\n ? Effect.all([controller.current, Ref.get(scale)]).pipe(\n Effect.flatMap(([page, scale]) =>\n Frame.zoom(page, Points.viewportRegion(new Frame.Region(region), scale), zoomed),\n ),\n Effect.tap((zoom) => Ref.update(zooms, (crops) => [...crops, zoom])),\n Effect.map(() => ({\n did: `Cropped (${region.x}, ${region.y}), ${region.width}x${region.height}: it is shown before your next turn if this tab is still current.`,\n followed: [],\n })),\n Effect.mapError(fromBrowserError),\n controller.withTask,\n )\n : Effect.fail(\n new ToolError({\n code: \"invalid\",\n message: \"These tools show no pictures, so a crop cannot be shown.\",\n }),\n );\n\n/**\n * The pointer tools' handlers over the controller's current tab. Each sets `pointed` once its input\n * reaches the page, but going back. Points and crops are in the pictures' pixels, `scale` to a\n * CSS pixel. With placement by crop, `framed` holds the crops around the points last asked.\n */\nconst pointing = (\n controller: PageControl.Controller,\n zooms: Ref.Ref<Array<Frame.Zoom>>,\n vision: Vision,\n pointed: Ref.Ref<boolean>,\n pixels: \"css\" | \"device\",\n scale: Ref.Ref<number>,\n framed: Ref.Ref<Array<Frame.Zoom>> | undefined,\n) => {\n const zoomed = pixels === \"device\" ? ({ scale: \"device\" } as const) : undefined;\n\n const act = <A>(\n run: (page: Page.Page) => Effect.Effect<A, BrowserError>,\n did: (value: A) => string,\n action?: Action,\n ) =>\n controller.perform(run).pipe(\n Effect.tap(() =>\n action === undefined || action._tag === \"Back\" ? Effect.void : Ref.set(pointed, true),\n ),\n // A program reads a receipt as JSON, which has no undefined, so absent fields are left out.\n Effect.map(({ value, followed }) =>\n action === undefined\n ? { did: did(value), followed }\n : { did: did(value), followed, action },\n ),\n Effect.mapError(fromBrowserError),\n );\n\n // Act once crops shown since the model asked hold every point; otherwise show crops around them.\n const placed = <A>(\n targets: ReadonlyArray<Page.Target>,\n asked: string,\n run: Effect.Effect<A, ToolError>,\n ) =>\n Effect.gen(function* () {\n const points = targets.filter((to) => typeof to !== \"string\");\n\n if (framed === undefined || vision === false || points.length === 0) return yield* run;\n const pending = yield* Ref.get(zooms);\n const shown = (yield* Ref.get(framed)).filter((crop) => !pending.includes(crop));\n\n if (points.every((point) => shown.some((crop) => Points.holds(crop, point)))) {\n yield* Ref.set(framed, []);\n\n return yield* run;\n }\n\n const crops = yield* Effect.gen(function* () {\n const page = yield* controller.current;\n const viewport = yield* page.viewport;\n\n return yield* Effect.forEach(points, (point) =>\n Frame.zoom(page, Points.around(point, viewport), zoomed),\n );\n }).pipe(Effect.mapError(fromBrowserError), controller.withTask);\n\n yield* Ref.set(framed, crops);\n yield* Ref.update(zooms, (all) => [...all, ...crops]);\n\n return {\n did: `Not done yet: a crop around ${asked} is shown before your next turn. Call again at the points you mean, inside the crops, to act.`,\n followed: [],\n };\n });\n\n return Pointer.of({\n click_at: ({ x, y, double, button }) =>\n Effect.flatMap(Ref.get(scale), (scale) => {\n const options = {\n clickCount: double === true ? 2 : 1,\n ...(button === undefined ? {} : { button }),\n };\n\n const at = { x: x / scale, y: y / scale };\n\n return placed(\n [at],\n `(${x}, ${y})`,\n act(\n (page) => page.click(at, options),\n ({ element }) => `Clicked ${element} at (${x}, ${y}).`,\n { _tag: \"Click\", target: at, options },\n ),\n );\n }),\n hover: (place) =>\n Option.match(Points.target(place), {\n onNone: () => missing(\"hover\"),\n onSome: (to) =>\n Effect.flatMap(Ref.get(scale), (scale) => {\n const at = Points.viewportTarget(to, scale);\n\n return act(\n (page) => page.hover(at),\n () => `Hovered over ${Points.named(to)}.`,\n { _tag: \"Hover\", target: at },\n );\n }),\n }),\n drag: (drag) => {\n const from = Points.target({ ref: drag.fromRef, x: drag.fromX, y: drag.fromY });\n const to = Points.target({ ref: drag.toRef, x: drag.toX, y: drag.toY });\n\n return Option.isNone(from) || Option.isNone(to)\n ? missing(\"each end of a drag\")\n : Effect.flatMap(Ref.get(scale), (scale) => {\n const start = Points.viewportTarget(from.value, scale);\n const end = Points.viewportTarget(to.value, scale);\n\n return placed(\n [start, end],\n `each end, ${Points.named(from.value)} and ${Points.named(to.value)},`,\n act(\n (page) => page.drag(start, end),\n () => `Dragged from ${Points.named(from.value)} to ${Points.named(to.value)}.`,\n { _tag: \"Drag\", from: start, to: end },\n ),\n );\n });\n },\n type_text: ({ text: typed, submit }) =>\n act(\n (page) => page.type(typed, { submit }),\n () => `Typed ${JSON.stringify(typed)}${submit === true ? \" and pressed Enter\" : \"\"}.`,\n { _tag: \"Type\", text: typed, ...(submit === undefined ? {} : { options: { submit } }) },\n ),\n press_keys: ({ keys, times, holdMillis }) =>\n act(\n (page) => page.press(keys, { times, holdMillis }),\n () => `Pressed ${keys}${times === undefined || times === 1 ? \"\" : ` ${times} times`}.`,\n {\n _tag: \"Press\",\n keys,\n options: {\n ...(times === undefined ? {} : { times }),\n ...(holdMillis === undefined ? {} : { holdMillis }),\n },\n },\n ),\n zoom: cropping(controller, zooms, vision, scale, zoomed),\n wait_still: ({ seconds }) =>\n act(\n (page) =>\n // What was already moving before the input, such as a game's idle animation, is not\n // what the model waits for.\n Stillness.wait(page, {\n still: \"foreground\",\n quiet: \"600 millis\",\n timeout: `${Math.min(Math.max(seconds ?? 15, 0), 30)} seconds`,\n }),\n () => \"The screen is still.\",\n ),\n back: () =>\n act(\n (page) => page.back,\n () => \"Went back.\",\n { _tag: \"Back\" },\n ),\n });\n};\n\n/** One mode's tools and the layer that serves them for a run. */\nconst tooling = <Refs extends Record<string, Tool.Any>>(\n refs: Toolkit.Toolkit<Refs>,\n serve: (actions: PageControl.Controller[\"actions\"]) => Layer.Layer<Tool.HandlersFor<Refs>>,\n) => {\n const toolkit = Toolkit.merge(refs, Control, Pointer);\n\n /** Every tool's handler, and the `Pictures` and `Controller` of one run on `target`. */\n const layer = (target: PageControl.Target, options: LayerOptions = {}) =>\n Layer.unwrap(\n Effect.gen(function* () {\n const controller = yield* PageControl.make(target, options);\n const zooms = yield* Ref.make<Array<Frame.Zoom>>([...(options.initialZooms ?? [])]);\n const vision = options.vision ?? true;\n const pixels = options.pixels ?? \"css\";\n // The pictures' pixels to a CSS pixel, as the latest screenshot showed them.\n const scale = yield* Ref.make(1);\n const { control } = controller;\n // Since the last turn: whether the model called `look`, and whether pointer input ran.\n const asked = yield* Ref.make(false);\n const pointed = yield* Ref.make(false);\n\n const framed =\n options.placement === \"crop\" ? yield* Ref.make<Array<Frame.Zoom>>([]) : undefined;\n\n // Whether the screen is shown before a turn: always with `true`, after `look` with `\"ask\"`,\n // and with `\"page\"` also after pointer input or while the viewport shows a picture.\n const wanted = (page: Page.Page) =>\n Effect.gen(function* () {\n const looked = yield* Ref.getAndSet(asked, false);\n const input = yield* Ref.getAndSet(pointed, false);\n\n if (vision === true || looked) return true;\n if (vision !== \"page\") return false;\n\n return (\n input ||\n (yield* page.read(pictorial, { arg: undefined, result: Schema.Boolean })).value\n );\n });\n\n const handlers = Layer.mergeAll(\n serve(controller.actions),\n Control.toLayer({\n inspect: control.inspect,\n navigate: control.navigate,\n scroll: control.scroll,\n wait: control.wait,\n press: control.press,\n select_tab: control.selectTab,\n }),\n Pointer.toLayer(pointing(controller, zooms, vision, pointed, pixels, scale, framed)),\n Find.toLayer({ find: control.find }),\n Look.toLayer({\n look: () =>\n vision === false\n ? Effect.fail(\n new ToolError({ code: \"invalid\", message: \"These tools show no pictures.\" }),\n )\n : Ref.set(asked, true).pipe(\n Effect.as({\n did:\n vision === \"ask\" || vision === \"page\"\n ? \"A screenshot of the current tab is shown before your next turn.\"\n : \"A screenshot is shown before every turn already.\",\n followed: [],\n }),\n ),\n }),\n );\n\n const shown = Pictures.of({\n next:\n vision === false\n ? Effect.succeed(Prompt.empty)\n : pictures(controller, zooms, wanted, pixels, scale),\n crops: (page) =>\n Effect.zipWith(Ref.getAndSet(zooms, []), Ref.get(scale), (crops, scale) =>\n cropped(crops, page, scale),\n ),\n });\n\n return Layer.mergeAll(\n handlers,\n Layer.succeed(Pictures, shown),\n Layer.succeed(Controller, controller),\n );\n }),\n );\n\n return { toolkit, layer };\n};\n\nconst singleTools = tooling(single, (actions) =>\n single.toLayer({ observe: () => actions.observe, act: ({ action }) => actions.act([action]) }),\n);\n\nconst batchedTools = tooling(batched, (actions) =>\n batched.toLayer({\n observe: () => actions.observe,\n act: ({ actions: steps }) => actions.act(steps),\n }),\n);\n\n/**\n * The tools and their layer. `\"batched\"`, the default, lets `act` take up to eight actions; with\n * `\"single\"`, it takes one.\n *\n * @stability stable\n * @category constructors\n * @since 0.3.0\n */\nexport function make(options?: { readonly mode?: \"batched\" }): typeof batchedTools;\nexport function make(options: { readonly mode: \"single\" }): typeof singleTools;\n\nexport function make(options: { readonly mode?: \"single\" | \"batched\" } = {}) {\n return options.mode === \"single\" ? singleTools : batchedTools;\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAa,WACX,OACA,MACA,QAAQ,MACkC;CAC1C,MAAM,UAAU,MAAM,QAAQ,SAAS,KAAK,SAAS,IAAI;CACzD,MAAM,OAAO,QAAQ,MAAM,EAAS;CACpC,MAAM,MAAM,UAAkB,KAAK,MAAM,QAAQ,KAAK;CACtD,MAAM,OAAO,UAAU,IAAI,eAAe;CAE1C,OAAO,CACL,GAAG,KAAK,SAAS,EAAE,QAAQ,YAAY,CACrC,OAAO,SAAS,QAAQ,EACtB,MAAM,0BAA0B,GAAG,OAA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