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,260 @@
1
+ /**
2
+ * HTTP record/replay keeps provider codecs in the test and reserves every live request.
3
+ *
4
+ * @stability stable
5
+ * @since 0.3.0
6
+ */
7
+ import { Config, Context, Effect, Layer, Ref, Schema } from "effect";
8
+ import {
9
+ HttpClient,
10
+ HttpClientError,
11
+ type HttpClientRequest,
12
+ HttpClientResponse,
13
+ } from "effect/http";
14
+
15
+ import { canonical, isScriptError, ScriptError } from "./TestModel.ts";
16
+
17
+ /**
18
+ * Request identities contain hashes only; credentials and prompt text are never written.
19
+ *
20
+ * @stability stable
21
+ * @category schemas
22
+ * @since 0.3.0
23
+ */
24
+ export const Exchange = Schema.Struct({
25
+ key: Schema.String,
26
+ response: Schema.Struct({
27
+ status: Schema.Int,
28
+ headers: Schema.Record(Schema.String, Schema.String),
29
+ body: Schema.String,
30
+ }),
31
+ });
32
+
33
+ /**
34
+ * @stability stable
35
+ * @category models
36
+ * @since 0.3.0
37
+ */
38
+ export type Exchange = typeof Exchange.Type;
39
+
40
+ type Paid = {
41
+ readonly http: HttpClient.HttpClient;
42
+ /** A finite positive budget, in the same units as the reservation returned below. */
43
+ readonly cap: number;
44
+ /** Reserve an upper bound before dispatch, using the caller's existing admission ledger. */
45
+ readonly reserve: (
46
+ request: HttpClientRequest.HttpClientRequest,
47
+ ) => Effect.Effect<number, ScriptError>;
48
+ };
49
+
50
+ /**
51
+ * @stability stable
52
+ * @category options
53
+ * @since 0.3.0
54
+ */
55
+ export type Options =
56
+ | {
57
+ readonly mode: "replay";
58
+ readonly exchanges: ReadonlyArray<Exchange>;
59
+ readonly recordCommand?: string;
60
+ }
61
+ | (Paid & { readonly mode: "live" })
62
+ | (Paid & {
63
+ readonly mode: "record";
64
+ readonly append: (exchange: Exchange) => Effect.Effect<void, ScriptError>;
65
+ /**
66
+ * The charge a recorded response shows. The cap then counts it instead of the request's
67
+ * reservation, so the cap bounds spend rather than requests. Undefined keeps the reservation.
68
+ */
69
+ readonly settle?: (response: Exchange["response"]) => number | undefined;
70
+ });
71
+
72
+ const problem = (detail: string) => new ScriptError({ detail });
73
+
74
+ const transport = (request: HttpClientRequest.HttpClientRequest, error: ScriptError) =>
75
+ new HttpClientError.HttpClientError({
76
+ reason: new HttpClientError.TransportError({ request, description: error.detail }),
77
+ });
78
+
79
+ const identity = (request: HttpClientRequest.HttpClientRequest, url: URL) =>
80
+ Effect.gen(function* () {
81
+ if (request.body._tag !== "Empty" && request.body._tag !== "Uint8Array") {
82
+ return yield* problem("cassette requests require a finite encoded body");
83
+ }
84
+ const text = request.body._tag === "Empty" ? "" : new TextDecoder().decode(request.body.body);
85
+ let body: unknown = text;
86
+
87
+ if (text !== "") {
88
+ const decoded = Schema.decodeOption(Schema.fromJsonString(Schema.Unknown))(text);
89
+
90
+ if (decoded._tag === "Some") body = decoded.value;
91
+ }
92
+ const normalized = new URL(url);
93
+
94
+ normalized.searchParams.sort();
95
+ normalized.hash = "";
96
+
97
+ const bytes = new TextEncoder().encode(
98
+ canonical({ method: request.method, url: normalized.href, body }),
99
+ );
100
+
101
+ const digest = yield* Effect.promise(() => crypto.subtle.digest("SHA-256", bytes));
102
+
103
+ return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(
104
+ "",
105
+ );
106
+ });
107
+
108
+ // Fetch forbids even an empty-string body for these status codes.
109
+ const responseOf = (request: HttpClientRequest.HttpClientRequest, response: Exchange["response"]) =>
110
+ HttpClientResponse.fromWeb(
111
+ request,
112
+ new Response([204, 205, 304].includes(response.status) ? null : response.body, response),
113
+ );
114
+
115
+ /**
116
+ * Construct the same HTTP seam for replay, recording, or explicitly admitted live runs.
117
+ *
118
+ * @stability stable
119
+ * @category constructors
120
+ * @since 0.3.0
121
+ */
122
+ export const make = (options: Options) =>
123
+ Effect.gen(function* () {
124
+ if (options.mode !== "replay") {
125
+ const optIn = yield* Config.String("EFFECT_BROWSER_BENCH_LIVE").pipe(
126
+ Config.withDefault(""),
127
+ Effect.mapError(() => problem("live HTTP opt-in could not be read")),
128
+ );
129
+
130
+ if (optIn !== "1")
131
+ return yield* problem("live HTTP requires EFFECT_BROWSER_BENCH_LIVE exactly 1");
132
+ if (!(Number.isFinite(options.cap) && options.cap > 0))
133
+ return yield* problem("live HTTP requires a finite positive cap");
134
+ }
135
+ const remaining = yield* Ref.make(options.mode === "replay" ? options.exchanges : []);
136
+ const used = yield* Ref.make(0);
137
+ const failures = yield* Ref.make(0);
138
+
139
+ const refuse = (detail: string) =>
140
+ Effect.andThen(
141
+ Ref.update(failures, (count) => count + 1),
142
+ Effect.fail(problem(detail)),
143
+ );
144
+
145
+ const http = HttpClient.make((request, url) =>
146
+ Effect.gen(function* () {
147
+ const key = yield* identity(request, url);
148
+
149
+ if (options.mode === "replay") {
150
+ const exchange = yield* Ref.modify(remaining, (rows) =>
151
+ rows[0]?.key === key ? [rows[0], rows.slice(1)] : [undefined, rows],
152
+ );
153
+
154
+ if (exchange === undefined)
155
+ return yield* refuse(
156
+ `cassette request changed or ran out; re-record with ${options.recordCommand ?? "the scenario's record command"}`,
157
+ );
158
+
159
+ return responseOf(request, exchange.response);
160
+ }
161
+ const bound = yield* options.reserve(request);
162
+
163
+ if (!(Number.isFinite(bound) && bound >= 0))
164
+ return yield* refuse("request reservation must be a finite non-negative upper bound");
165
+
166
+ const admitted = yield* Ref.modify(used, (total) =>
167
+ total + bound <= options.cap ? [true, total + bound] : [false, total],
168
+ );
169
+
170
+ if (!admitted) return yield* refuse("request reservation exceeds the live HTTP cap");
171
+ const response = yield* options.http.execute(request);
172
+
173
+ if (options.mode === "live") return response;
174
+ const body = yield* response.text;
175
+
176
+ const headers = Object.fromEntries(
177
+ Object.entries(response.headers).filter(([name]) =>
178
+ ["content-type", "retry-after"].includes(name),
179
+ ),
180
+ );
181
+
182
+ const exchange: Exchange = { key, response: { status: response.status, headers, body } };
183
+ const charge = options.settle?.(exchange.response);
184
+
185
+ if (charge !== undefined && Number.isFinite(charge) && charge >= 0)
186
+ yield* Ref.update(used, (total) => total - bound + charge);
187
+ yield* options.append(exchange);
188
+
189
+ return responseOf(request, exchange.response);
190
+ }).pipe(
191
+ Effect.mapError((error) => (isScriptError(error) ? transport(request, error) : error)),
192
+ ),
193
+ );
194
+
195
+ return {
196
+ http,
197
+ assertExhausted: Effect.gen(function* () {
198
+ const unused = (yield* Ref.get(remaining)).length;
199
+ const unexpected = yield* Ref.get(failures);
200
+
201
+ if (unused > 0 || unexpected > 0)
202
+ return yield* problem(
203
+ `cassette end check: ${unused} unused responses, ${unexpected} unexpected requests`,
204
+ );
205
+ }),
206
+ };
207
+ });
208
+
209
+ /**
210
+ * Provide this HTTP layer beneath an actual provider model layer in every mode.
211
+ *
212
+ * @stability stable
213
+ * @category services
214
+ * @since 0.3.0
215
+ */
216
+ export class Cassette extends Context.Service<Cassette, Effect.Success<ReturnType<typeof make>>>()(
217
+ "effect-browser/testing/HttpCassette",
218
+ ) {}
219
+
220
+ /**
221
+ * @stability stable
222
+ * @category layers
223
+ * @since 0.3.0
224
+ */
225
+ export const layer = (options: Options) =>
226
+ Layer.unwrap(
227
+ Effect.map(make(options), (cassette) =>
228
+ Layer.merge(
229
+ Layer.succeed(HttpClient.HttpClient, cassette.http),
230
+ Layer.succeed(Cassette, cassette),
231
+ ),
232
+ ),
233
+ );
234
+
235
+ /**
236
+ * A scenario chooses its mode through Config while retaining the same provider and assertions.
237
+ *
238
+ * @stability stable
239
+ * @category layers
240
+ * @since 0.3.0
241
+ */
242
+ export const configured = (
243
+ options: Paid & {
244
+ readonly exchanges: ReadonlyArray<Exchange>;
245
+ readonly append: (exchange: Exchange) => Effect.Effect<void, ScriptError>;
246
+ readonly recordCommand: string;
247
+ },
248
+ ) =>
249
+ Layer.unwrap(
250
+ Effect.gen(function* () {
251
+ const mode = yield* Config.String("EFFECT_BROWSER_TEST_MODEL_MODE").pipe(
252
+ Config.withDefault("replay"),
253
+ );
254
+
255
+ if (mode !== "replay" && mode !== "record" && mode !== "live")
256
+ return yield* problem("EFFECT_BROWSER_TEST_MODEL_MODE must be replay, record, or live");
257
+
258
+ return layer({ ...options, mode });
259
+ }),
260
+ );
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Suspended test ports expose unfinished work and error logs in one explicit end check.
3
+ *
4
+ * @stability stable
5
+ * @since 0.3.0
6
+ */
7
+ import { Effect, Logger, Ref } from "effect";
8
+
9
+ import { ScriptError } from "./TestModel.ts";
10
+
11
+ /**
12
+ * @stability stable
13
+ * @category models
14
+ * @since 0.3.0
15
+ */
16
+ export interface ErrorLog {
17
+ readonly id: number;
18
+ readonly options: Logger.Options<unknown>;
19
+ }
20
+
21
+ /**
22
+ * One story owns its ports and logger; interruption still removes the held invocation.
23
+ *
24
+ * @stability stable
25
+ * @category constructors
26
+ * @since 0.3.0
27
+ */
28
+ export const make = Effect.gen(function* () {
29
+ const checks = yield* Ref.make<ReadonlyArray<Effect.Effect<ReadonlyArray<string>>>>([]);
30
+ const logged: Array<ErrorLog> = [];
31
+ const asserted = yield* Ref.make<ReadonlyArray<number>>([]);
32
+
33
+ const logger = Logger.layer([
34
+ Logger.make((options) => {
35
+ if (options.logLevel === "Error" || options.logLevel === "Fatal")
36
+ logged.push({ id: logged.length + 1, options });
37
+ }),
38
+ ]);
39
+
40
+ const port = <I, A, E = never>(
41
+ name: string,
42
+ steps: ReadonlyArray<(input: I) => Effect.Effect<A, E>>,
43
+ ) =>
44
+ Effect.gen(function* () {
45
+ const state = yield* Ref.make({ next: 0, active: 0, unexpected: 0 });
46
+
47
+ yield* Ref.update(checks, (known) => [
48
+ ...known,
49
+ Effect.map(Ref.get(state), (current) => [
50
+ ...(current.active === 0 ? [] : [`${current.active} held ${name}`]),
51
+ ...(current.next >= steps.length
52
+ ? []
53
+ : [`${steps.length - current.next} unused ${name}`]),
54
+ ...(current.unexpected === 0 ? [] : [`${current.unexpected} unexpected ${name}`]),
55
+ ]),
56
+ ]);
57
+
58
+ return (input: I) =>
59
+ Effect.gen(function* () {
60
+ const step = yield* Ref.modify(state, (current) => {
61
+ const step = steps[current.next];
62
+
63
+ return [
64
+ step,
65
+ {
66
+ next: current.next + 1,
67
+ active: current.active + (step === undefined ? 0 : 1),
68
+ unexpected: current.unexpected + (step === undefined ? 1 : 0),
69
+ },
70
+ ];
71
+ });
72
+
73
+ if (step === undefined)
74
+ return yield* new ScriptError({ detail: `unexpected ${name} call` });
75
+
76
+ return yield* step(input).pipe(
77
+ Effect.ensuring(
78
+ Ref.update(state, (current) => ({ ...current, active: current.active - 1 })),
79
+ ),
80
+ );
81
+ });
82
+ });
83
+
84
+ return {
85
+ port,
86
+ logger,
87
+ logs: Effect.sync(() => [...logged]),
88
+ assertLog: (id: number) =>
89
+ Effect.gen(function* () {
90
+ if (!logged.some((log) => log.id === id))
91
+ return yield* new ScriptError({ detail: `unknown error log ${id}` });
92
+ yield* Ref.update(asserted, (known) => [...known, id]);
93
+ }),
94
+ assertFinished: Effect.gen(function* () {
95
+ const messages = (yield* Effect.all(yield* Ref.get(checks))).flat();
96
+ const known = yield* Ref.get(asserted);
97
+ const unseen = logged.filter((log) => !known.includes(log.id));
98
+
99
+ if (unseen.length > 0) messages.push(`${unseen.length} unasserted error log`);
100
+ if (messages.length > 0) return yield* new ScriptError({ detail: messages.join("; ") });
101
+ }),
102
+ };
103
+ });
@@ -1,17 +1,27 @@
1
- /** A seeded browser whose pages use the production lane, suspension gate and event timeline. */
1
+ /**
2
+ * A seeded browser whose pages use the production lane, suspension gate and event timeline.
3
+ *
4
+ * @stability stable
5
+ * @since 0.3.0
6
+ */
2
7
  import { Clock, Deferred, Duration, Effect, Option, Scope, Semaphore } from "effect";
3
8
 
4
9
  import { type Service, Suspension } from "../Browser.ts";
5
10
  import { Closed, InvalidRequest, undispatched } from "../BrowserError.ts";
6
11
  import { type DisconnectCause, Disconnected, PageOpened } from "../BrowserEvent.ts";
7
- import { monotonicMillis } from "../Clock.ts";
12
+ import { monotonicMillis } from "../internal/clock.ts";
8
13
  import * as Gate from "../internal/input/gate.ts";
9
14
  import * as Timeline from "../internal/timeline/events.ts";
10
15
  import type { Page } from "../Page.ts";
11
- import { unsupported } from "./model.ts";
12
- import { makeIn } from "./page.ts";
16
+ import { unsupported } from "./internal/model.ts";
17
+ import { makeIn } from "./internal/page.ts";
13
18
  import type * as TestPage from "./TestPage.ts";
14
19
 
20
+ /**
21
+ * @stability stable
22
+ * @category constructors
23
+ * @since 0.3.0
24
+ */
15
25
  export const make = Effect.fnUntraced(function* (
16
26
  seeds: ReadonlyArray<TestPage.Seed> = [],
17
27
  options: {
@@ -0,0 +1,297 @@
1
+ /**
2
+ * Prompt-aware model scripts with per-layer request evidence and explicit exhaustion.
3
+ *
4
+ * @stability stable
5
+ * @since 0.3.0
6
+ */
7
+ import { Context, Effect, Layer, Predicate, Ref, Schema, Stream } from "effect";
8
+ import { AiError, LanguageModel, Model, type Prompt, type Response, type Tool } from "effect/ai";
9
+
10
+ /**
11
+ * @stability stable
12
+ * @category errors
13
+ * @since 0.3.0
14
+ */
15
+ export class ScriptError extends Schema.TaggedError<ScriptError>(
16
+ "effect-browser/testing/TestModel/ScriptError",
17
+ )("ScriptError", {
18
+ detail: Schema.String,
19
+ }) {}
20
+
21
+ /**
22
+ * @stability stable
23
+ * @category guards
24
+ * @since 0.3.0
25
+ */
26
+ export const isScriptError = Schema.is(ScriptError);
27
+
28
+ const normalized = (value: unknown): unknown =>
29
+ Array.isArray(value)
30
+ ? value.map(normalized)
31
+ : Predicate.isObject(value)
32
+ ? Object.fromEntries(
33
+ Object.keys(value)
34
+ .toSorted()
35
+ .map((key) => [key, normalized(Reflect.get(value, key))]),
36
+ )
37
+ : (value ?? null);
38
+
39
+ /**
40
+ * Canonical JSON for request identity; object key order never changes a match.
41
+ *
42
+ * @stability stable
43
+ * @category combinators
44
+ * @since 0.3.0
45
+ */
46
+ export const canonical = (value: unknown): string => JSON.stringify(normalized(value));
47
+
48
+ /**
49
+ * @stability stable
50
+ * @category combinators
51
+ * @since 0.3.0
52
+ */
53
+ export const fingerprint = (tools: ReadonlyArray<Tool.Any>): string =>
54
+ canonical(
55
+ tools
56
+ .map((tool) => ({
57
+ name: String(tool.name),
58
+ description: tool.description,
59
+ parameters: Schema.toJsonSchemaDocument(tool.parametersSchema),
60
+ }))
61
+ .toSorted((left, right) => left.name.localeCompare(right.name)),
62
+ );
63
+
64
+ /**
65
+ * @stability stable
66
+ * @category models
67
+ * @since 0.3.0
68
+ */
69
+ export interface Request {
70
+ readonly turn: number;
71
+ readonly options: LanguageModel.ProviderOptions;
72
+ readonly prompt: Prompt.Prompt;
73
+ readonly tools: ReadonlyArray<Tool.Any>;
74
+ readonly toolsFingerprint: string;
75
+ }
76
+
77
+ /**
78
+ * @stability stable
79
+ * @category models
80
+ * @since 0.3.0
81
+ */
82
+ export interface Reply {
83
+ readonly parts: ReadonlyArray<Response.PartEncoded>;
84
+ /** Override delivery to model pacing, stalls, or a broken-off stream without changing generation. */
85
+ readonly stream?: Stream.Stream<Response.StreamPartEncoded, AiError.AiError> | undefined;
86
+ }
87
+
88
+ /**
89
+ * @stability stable
90
+ * @category models
91
+ * @since 0.3.0
92
+ */
93
+ export type Turn = (request: Request) => Effect.Effect<Reply, ScriptError | AiError.AiError>;
94
+
95
+ /**
96
+ * @stability stable
97
+ * @category services
98
+ * @since 0.3.0
99
+ */
100
+ export class TestModel extends Context.Service<
101
+ TestModel,
102
+ {
103
+ readonly requests: Effect.Effect<ReadonlyArray<Request>>;
104
+ readonly assertExhausted: Effect.Effect<void, ScriptError>;
105
+ }
106
+ >()("effect-browser/testing/TestModel") {}
107
+
108
+ const failed = (error: ScriptError) =>
109
+ AiError.make({
110
+ module: "TestModel",
111
+ method: "request",
112
+ reason: new AiError.InvalidRequestError({ description: error.detail }),
113
+ });
114
+
115
+ /**
116
+ * Translate the finite response vocabulary at the streaming provider boundary.
117
+ *
118
+ * @stability stable
119
+ * @category constructors
120
+ * @since 0.3.0
121
+ */
122
+ export const streamed = (
123
+ parts: ReadonlyArray<Response.PartEncoded>,
124
+ ): ReadonlyArray<Response.StreamPartEncoded> =>
125
+ parts.flatMap((part, index): ReadonlyArray<Response.StreamPartEncoded> => {
126
+ if (part.type === "text" || part.type === "reasoning") {
127
+ const id = `${part.type}-${index}`;
128
+
129
+ return part.type === "text"
130
+ ? [
131
+ { type: "text-start", id },
132
+ { type: "text-delta", id, delta: part.text },
133
+ { type: "text-end", id },
134
+ ]
135
+ : [
136
+ { type: "reasoning-start", id },
137
+ { type: "reasoning-delta", id, delta: part.text },
138
+ { type: "reasoning-end", id },
139
+ ];
140
+ }
141
+
142
+ return [part];
143
+ });
144
+
145
+ /**
146
+ * @stability stable
147
+ * @category constructors
148
+ * @since 0.3.0
149
+ */
150
+ export const finish = (reason: "stop" | "tool-calls" = "stop"): Response.PartEncoded => ({
151
+ type: "finish",
152
+ reason,
153
+ usage: { inputTokens: { total: 100 }, outputTokens: { total: 10 } },
154
+ });
155
+
156
+ /**
157
+ * @stability stable
158
+ * @category constructors
159
+ * @since 0.3.0
160
+ */
161
+ export const text = (value: string): ReadonlyArray<Response.PartEncoded> => [
162
+ { type: "text", text: value },
163
+ finish(),
164
+ ];
165
+
166
+ /**
167
+ * @stability stable
168
+ * @category constructors
169
+ * @since 0.3.0
170
+ */
171
+ export const reply = (
172
+ parts: ReadonlyArray<Response.PartEncoded>,
173
+ stream?: Reply["stream"],
174
+ ): Reply => ({ parts, stream });
175
+
176
+ /**
177
+ * Call ids are explicit or local to a scripted turn; there is no process-global counter.
178
+ *
179
+ * @stability stable
180
+ * @category constructors
181
+ * @since 0.3.0
182
+ */
183
+ export const call = (name: string, params: unknown, id = ""): Response.PartEncoded => ({
184
+ type: "tool-call",
185
+ id,
186
+ name,
187
+ params,
188
+ });
189
+
190
+ /**
191
+ * @stability stable
192
+ * @category constructors
193
+ * @since 0.3.0
194
+ */
195
+ export const calling = (
196
+ ...calls: ReadonlyArray<Response.PartEncoded>
197
+ ): ReadonlyArray<Response.PartEncoded> => [...calls, finish("tool-calls")];
198
+
199
+ /**
200
+ * @stability stable
201
+ * @category combinators
202
+ * @since 0.3.0
203
+ */
204
+ export const textOf = (prompt: Prompt.Prompt): string =>
205
+ prompt.content
206
+ .flatMap((message) =>
207
+ message.role === "system"
208
+ ? [message.content]
209
+ : message.content.flatMap((part) =>
210
+ part.type === "text"
211
+ ? [part.text]
212
+ : part.type === "tool-result"
213
+ ? [JSON.stringify(part.result)]
214
+ : [],
215
+ ),
216
+ )
217
+ .join("\n");
218
+
219
+ /**
220
+ * Ref allocation belongs to Layer construction, so rebuilding the layer starts the script afresh.
221
+ *
222
+ * @stability stable
223
+ * @category layers
224
+ * @since 0.3.0
225
+ */
226
+ export const layer = (
227
+ turns: ReadonlyArray<Turn> | { readonly respond: Turn },
228
+ options: {
229
+ readonly onRequest?: ((request: Request) => Effect.Effect<void>) | undefined;
230
+ } = {},
231
+ ) =>
232
+ Layer.unwrap(
233
+ Effect.gen(function* () {
234
+ const requests = yield* Ref.make<ReadonlyArray<Request>>([]);
235
+
236
+ const next = (options: LanguageModel.ProviderOptions) =>
237
+ Effect.gen(function* () {
238
+ const request = yield* Ref.modify(requests, (seen) => {
239
+ const request: Request = {
240
+ turn: seen.length + 1,
241
+ options,
242
+ prompt: options.prompt,
243
+ tools: options.tools,
244
+ toolsFingerprint: fingerprint(options.tools),
245
+ };
246
+
247
+ return [request, [...seen, request]];
248
+ });
249
+
250
+ yield* optionsOnRequest(request);
251
+ const turn = "respond" in turns ? turns.respond : turns[request.turn - 1];
252
+
253
+ return turn === undefined
254
+ ? yield* new ScriptError({ detail: `script exhausted at request ${request.turn}` })
255
+ : yield* Effect.map(turn(request), (reply) => ({
256
+ ...reply,
257
+ parts: reply.parts.map((part, index) =>
258
+ part.type === "tool-call" && part.id === ""
259
+ ? { ...part, id: `call-${request.turn}-${index}` }
260
+ : part,
261
+ ),
262
+ }));
263
+ }).pipe(Effect.mapError((error) => (isScriptError(error) ? failed(error) : error)));
264
+
265
+ const optionsOnRequest = options.onRequest ?? (() => Effect.void);
266
+
267
+ const model = yield* LanguageModel.make({
268
+ generateText: (request) => Effect.map(next(request), ({ parts }) => [...parts]),
269
+ streamText: (request) =>
270
+ Stream.unwrap(
271
+ Effect.map(
272
+ next(request),
273
+ (reply) => reply.stream ?? Stream.fromIterable(streamed(reply.parts)),
274
+ ),
275
+ ),
276
+ });
277
+
278
+ return Layer.merge(
279
+ Model.make("scripted", "test-model", Layer.succeed(LanguageModel.LanguageModel, model)),
280
+ Layer.succeed(TestModel, {
281
+ requests: Ref.get(requests),
282
+ assertExhausted: Effect.flatMap(Ref.get(requests), (seen) =>
283
+ "respond" in turns || seen.length === turns.length
284
+ ? Effect.void
285
+ : Effect.fail(
286
+ new ScriptError({
287
+ detail:
288
+ seen.length > turns.length
289
+ ? `${seen.length - turns.length} unexpected scripted requests`
290
+ : `${turns.length - seen.length} unused scripted turns`,
291
+ }),
292
+ ),
293
+ ),
294
+ }),
295
+ );
296
+ }),
297
+ );