dsh-builtin-browser 1.0.0 → 1.0.3

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 (364) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +1 -1
  3. package/assets/browser-panel-locales.mjs +37 -5
  4. package/assets/browser-policy.d.mts +29 -0
  5. package/assets/browser-policy.mjs +40 -0
  6. package/desktop-bridge/desktop-discovery.d.mts +1 -1
  7. package/desktop-bridge/desktop-discovery.mjs +59 -9
  8. package/desktop-bridge/desktop-identity.json +12 -0
  9. package/desktop-bridge/install.mjs +14 -7
  10. package/desktop-bridge/plugin-browser-bridge.js +19 -7
  11. package/docs/acceptance-2026-11-27.md +67 -0
  12. package/docs/architecture.md +1 -1
  13. package/docs/development.md +33 -4
  14. package/docs/dsh-0.2.3-host-patch-task.md +34 -0
  15. package/docs/hardcoding-audit.md +28 -8
  16. package/docs/known-issues.md +26 -0
  17. package/docs/limitations.md +6 -2
  18. package/docs/pr64-maintenance.md +1 -1
  19. package/docs/tool-reference.md +1 -1
  20. package/docs/user-guide.md +1 -1
  21. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  22. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  23. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  24. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  25. package/dsh-host-patch/README.md +4 -0
  26. package/dsh-host-patch/apply.mjs +61 -13
  27. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  28. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  29. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  30. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  31. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  32. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  33. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  34. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  35. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  36. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  37. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  38. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  39. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  40. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  41. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  42. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  43. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  44. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  45. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  46. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  47. package/dsh-host-patch/sources/manifest.json +218 -0
  48. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  49. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  50. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  51. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  52. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  53. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  54. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  55. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  56. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  57. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  58. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  59. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  60. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  61. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  62. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  63. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  64. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  65. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  66. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  67. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  68. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  69. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  70. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  71. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  72. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  73. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  74. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  75. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  76. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  77. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  78. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  79. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  80. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  81. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  82. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  83. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  84. package/dsh-host-patch/sources/series.json +260 -0
  85. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  86. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  87. package/dsh-host-patch/tauri-revision1.json +39 -0
  88. package/dsh-host-patch/tauri.json +43 -0
  89. package/dsh-host-patch/v023-alpha2.json +153 -0
  90. package/lib/browser/anti-bot.js +215 -0
  91. package/lib/browser/deep-dom.js +39 -0
  92. package/lib/browser/runtime.js +15 -0
  93. package/lib/browser/takeover-target.js +13 -6
  94. package/lib/browser/types.js +30 -1
  95. package/lib/browser-electron/authenticated-route.js +16 -2
  96. package/lib/browser-electron/automatic-maintenance.js +16 -10
  97. package/lib/browser-electron/bridge-connection.js +3 -8
  98. package/lib/browser-electron/bridge-install.js +2 -1
  99. package/lib/browser-electron/bridge-status.js +55 -26
  100. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  101. package/lib/browser-electron/desktop-identity.js +28 -5
  102. package/lib/browser-electron/desktop-shell.js +64 -0
  103. package/lib/browser-electron/electron-provision.js +105 -18
  104. package/lib/browser-electron/entry.js +129 -46
  105. package/lib/browser-electron/extension-browser.js +4 -4
  106. package/lib/browser-electron/foreground-watch.js +134 -0
  107. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  108. package/lib/browser-electron/guest-route.js +181 -32
  109. package/lib/browser-electron/guest-runtime.js +61 -10
  110. package/lib/browser-electron/guest-storage.js +2 -2
  111. package/lib/browser-electron/history-store.js +1 -5
  112. package/lib/browser-electron/host-main.js +8 -4
  113. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  114. package/lib/browser-electron/maintenance-route.js +2 -1
  115. package/lib/browser-electron/missing-system-browser.js +5 -9
  116. package/lib/browser-electron/preferred-browser.js +7 -3
  117. package/lib/browser-electron/preview-route.js +9 -13
  118. package/lib/browser-electron/process-ownership.js +1 -1
  119. package/lib/browser-electron/profile-command.js +2 -1
  120. package/lib/browser-electron/profile-extension.js +5 -0
  121. package/lib/browser-electron/profile-lease.js +152 -47
  122. package/lib/browser-electron/provider-core.js +527 -0
  123. package/lib/browser-electron/provider-interaction.js +963 -0
  124. package/lib/browser-electron/provider-media.js +518 -0
  125. package/lib/browser-electron/provider-navigation.js +301 -0
  126. package/lib/browser-electron/provider-observation.js +623 -0
  127. package/lib/browser-electron/provider-tabs.js +372 -0
  128. package/lib/browser-electron/provider.js +150 -3301
  129. package/lib/browser-electron/reference-route.js +9 -18
  130. package/lib/browser-electron/remote-host.js +79 -34
  131. package/lib/browser-electron/runtime-status.js +56 -6
  132. package/lib/browser-electron/settings-store.js +3 -6
  133. package/lib/browser-electron/sidebar-only-host.js +1 -1
  134. package/lib/browser-electron/system-browser.js +539 -172
  135. package/lib/browser-electron/tauri-host.js +208 -0
  136. package/lib/browser-electron/virtual-cursor.js +23 -13
  137. package/lib/browser-reference/service.js +22 -4
  138. package/lib/browser-reference/web-sources.js +1 -1
  139. package/lib/client.js +43409 -0
  140. package/lib/compat/host-features.js +75 -0
  141. package/lib/reference-source.js +1 -1
  142. package/lib/reference-text.js +23 -1
  143. package/lib/takeover-protocol.js +1 -1
  144. package/lib/tool-browser/block-recovery.js +69 -0
  145. package/lib/tool-browser/code-tool.js +170 -19
  146. package/lib/tool-browser/code-worker.js +115 -20
  147. package/lib/tool-browser/errors.js +34 -0
  148. package/lib/tool-browser/index.js +66 -3593
  149. package/lib/tool-browser/page-probe.js +227 -28
  150. package/lib/tool-browser/panel-page.js +2 -1
  151. package/lib/tool-browser/probe-client.js +157 -0
  152. package/lib/tool-browser/screenshot-annotations.js +108 -0
  153. package/lib/tool-browser/state.js +337 -0
  154. package/lib/tool-browser/takeover.js +1 -1
  155. package/lib/tool-browser/tools-debug.js +862 -0
  156. package/lib/tool-browser/tools-interaction.js +993 -0
  157. package/lib/tool-browser/tools-navigation.js +807 -0
  158. package/lib/tool-browser/tools-observation.js +461 -0
  159. package/lib/tool-browser/tools-reference.js +293 -0
  160. package/lib/web-guest.js +1 -0
  161. package/package.json +16 -54
  162. package/README.en.md +0 -89
  163. package/browser-extension/constants.mjs +0 -20
  164. package/browser-extension/controller.mjs +0 -293
  165. package/browser-extension/locales.mjs +0 -15
  166. package/browser-extension/manifest.json +0 -12
  167. package/browser-extension/options.html +0 -14
  168. package/browser-extension/options.mjs +0 -9
  169. package/browser-extension/permission-guard.mjs +0 -13
  170. package/browser-extension/worker.mjs +0 -74
  171. package/dist/client.cjs +0 -43167
  172. package/lib/browser-electron/package-removal.js +0 -5
  173. package/lib/browser-reference/submission-receipts.js +0 -139
  174. package/scripts/build.mjs +0 -66
  175. package/scripts/bundle-host.mjs +0 -28
  176. package/scripts/fix-exports.mjs +0 -50
  177. package/scripts/install-electron.mjs +0 -51
  178. package/scripts/verify-exports.mjs +0 -47
  179. package/scripts/verify-preview-sdk.mjs +0 -93
  180. package/skills/dsh-builtin-browser/SKILL.md +0 -73
  181. package/skills/dsh-builtin-browser/references/batch.md +0 -53
  182. package/skills/dsh-builtin-browser/references/deliver.md +0 -31
  183. package/skills/dsh-builtin-browser/references/locate.md +0 -11
  184. package/skills/dsh-builtin-browser/references/recover.md +0 -11
  185. package/skills/dsh-builtin-browser/references/verify.md +0 -13
  186. package/skills/dsh-debug-host/SKILL.md +0 -56
  187. package/skills/dsh-debug-self/SKILL.md +0 -50
  188. package/src/bridge-compatibility.ts +0 -39
  189. package/src/browser/handles.ts +0 -89
  190. package/src/browser/runtime.ts +0 -560
  191. package/src/browser/takeover-target.ts +0 -36
  192. package/src/browser/types.ts +0 -817
  193. package/src/browser-electron/authenticated-route.ts +0 -84
  194. package/src/browser-electron/automatic-maintenance.ts +0 -726
  195. package/src/browser-electron/bridge-auto.ts +0 -159
  196. package/src/browser-electron/bridge-connection.ts +0 -385
  197. package/src/browser-electron/bridge-endpoint.ts +0 -129
  198. package/src/browser-electron/bridge-install.ts +0 -289
  199. package/src/browser-electron/bridge-maintenance.ts +0 -189
  200. package/src/browser-electron/bridge-status.ts +0 -347
  201. package/src/browser-electron/desktop-bridge-host.ts +0 -251
  202. package/src/browser-electron/desktop-identity.ts +0 -320
  203. package/src/browser-electron/document-readiness.ts +0 -45
  204. package/src/browser-electron/electron-provision.ts +0 -261
  205. package/src/browser-electron/entry.ts +0 -1301
  206. package/src/browser-electron/ephemeral-profile.ts +0 -189
  207. package/src/browser-electron/extension-browser.ts +0 -223
  208. package/src/browser-electron/extension-setup.ts +0 -67
  209. package/src/browser-electron/file-write.ts +0 -31
  210. package/src/browser-electron/guest-cookie-jar.ts +0 -176
  211. package/src/browser-electron/guest-cookie-store.ts +0 -59
  212. package/src/browser-electron/guest-css-runtime.ts +0 -76
  213. package/src/browser-electron/guest-css.ts +0 -68
  214. package/src/browser-electron/guest-route.ts +0 -568
  215. package/src/browser-electron/guest-runtime.ts +0 -357
  216. package/src/browser-electron/guest-storage-runtime.ts +0 -54
  217. package/src/browser-electron/guest-storage.ts +0 -117
  218. package/src/browser-electron/history-store.ts +0 -227
  219. package/src/browser-electron/host-main.ts +0 -1381
  220. package/src/browser-electron/host-patch-maintenance.ts +0 -112
  221. package/src/browser-electron/http-body.ts +0 -65
  222. package/src/browser-electron/json-reply.ts +0 -47
  223. package/src/browser-electron/maintenance-broker.ts +0 -166
  224. package/src/browser-electron/maintenance-lifecycle.ts +0 -91
  225. package/src/browser-electron/maintenance-route.ts +0 -67
  226. package/src/browser-electron/missing-system-browser.ts +0 -113
  227. package/src/browser-electron/open-slot.ts +0 -49
  228. package/src/browser-electron/package-removal.ts +0 -4
  229. package/src/browser-electron/paths.ts +0 -25
  230. package/src/browser-electron/preferred-browser.ts +0 -120
  231. package/src/browser-electron/preview-route.ts +0 -218
  232. package/src/browser-electron/process-ownership.ts +0 -168
  233. package/src/browser-electron/process.ts +0 -23
  234. package/src/browser-electron/profile-checkpoint.ts +0 -187
  235. package/src/browser-electron/profile-command.ts +0 -46
  236. package/src/browser-electron/profile-extension.ts +0 -124
  237. package/src/browser-electron/profile-lease.ts +0 -115
  238. package/src/browser-electron/profile-residue.ts +0 -49
  239. package/src/browser-electron/provider.ts +0 -4571
  240. package/src/browser-electron/reference-route.ts +0 -608
  241. package/src/browser-electron/remote-host.ts +0 -1462
  242. package/src/browser-electron/rpc-input.ts +0 -13
  243. package/src/browser-electron/rpc-ops.ts +0 -41
  244. package/src/browser-electron/runtime-diagnostics.ts +0 -38
  245. package/src/browser-electron/runtime-route.ts +0 -105
  246. package/src/browser-electron/runtime-status.ts +0 -242
  247. package/src/browser-electron/settings-route.ts +0 -64
  248. package/src/browser-electron/settings-store.ts +0 -589
  249. package/src/browser-electron/shortcuts-route.ts +0 -112
  250. package/src/browser-electron/sidebar-only-host.ts +0 -298
  251. package/src/browser-electron/startpage-shortcuts.ts +0 -213
  252. package/src/browser-electron/system-browser.ts +0 -1497
  253. package/src/browser-electron/timing.ts +0 -16
  254. package/src/browser-electron/virtual-cursor.ts +0 -152
  255. package/src/browser-electron/windows-system.ts +0 -24
  256. package/src/browser-reference/delivery.ts +0 -384
  257. package/src/browser-reference/entry.ts +0 -631
  258. package/src/browser-reference/export.ts +0 -339
  259. package/src/browser-reference/import.ts +0 -303
  260. package/src/browser-reference/page-script.ts +0 -1537
  261. package/src/browser-reference/service.ts +0 -1315
  262. package/src/browser-reference/store.ts +0 -172
  263. package/src/browser-reference/submission-receipts.ts +0 -122
  264. package/src/browser-reference/text-quote.ts +0 -219
  265. package/src/browser-reference/types.ts +0 -195
  266. package/src/browser-reference/visible.ts +0 -367
  267. package/src/browser-reference/web-sources.ts +0 -103
  268. package/src/client/browser/BrowserController.ts +0 -693
  269. package/src/client/browser/BrowserFrame.ts +0 -78
  270. package/src/client/browser/BrowserNavigation.ts +0 -169
  271. package/src/client/browser/BrowserPage.ts +0 -23
  272. package/src/client/browser/BrowserPersistence.ts +0 -44
  273. package/src/client/browser/IframeImpl.ts +0 -176
  274. package/src/client/browser/child-tabs.ts +0 -14
  275. package/src/client/browser/iframe-reference.ts +0 -67
  276. package/src/client/browser/initialization.ts +0 -262
  277. package/src/client/browser/omnibox.ts +0 -243
  278. package/src/client/browser/store.ts +0 -38
  279. package/src/client/browser/takeover-channel.ts +0 -72
  280. package/src/client/browser/url.ts +0 -46
  281. package/src/client/browser/web-reference-source.ts +0 -52
  282. package/src/client/css-modules.d.ts +0 -4
  283. package/src/client/definition.tsx +0 -30
  284. package/src/client/electron/ElectronWebViewImpl.ts +0 -364
  285. package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
  286. package/src/client/electron/NativeChildPresentation.ts +0 -45
  287. package/src/client/electron/NativeViewPage.ts +0 -251
  288. package/src/client/electron/pages.ts +0 -23
  289. package/src/client/electron/reference-overlay.ts +0 -53
  290. package/src/client/electron/workspace.ts +0 -33
  291. package/src/client/index.ts +0 -293
  292. package/src/client/locales.ts +0 -857
  293. package/src/client/pages.ts +0 -28
  294. package/src/client/reference/client/BrowserRefLink.tsx +0 -142
  295. package/src/client/reference/client/draft-reference.ts +0 -167
  296. package/src/client/reference/client/index.ts +0 -7
  297. package/src/client/reference/client/ordered-submission.ts +0 -108
  298. package/src/client/reference/client/pending-delivery.ts +0 -216
  299. package/src/client/reference/client/plugin.ts +0 -189
  300. package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
  301. package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
  302. package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
  303. package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
  304. package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
  305. package/src/client/reference/client/production/ReferenceText.tsx +0 -36
  306. package/src/client/reference/client/production/assembly.ts +0 -471
  307. package/src/client/reference/client/production/asset-store.ts +0 -144
  308. package/src/client/reference/client/production/availability.ts +0 -74
  309. package/src/client/reference/client/production/bytes.ts +0 -36
  310. package/src/client/reference/client/production/delivery-client.ts +0 -211
  311. package/src/client/reference/client/production/draft-adapter.ts +0 -508
  312. package/src/client/reference/client/production/http-transport.ts +0 -217
  313. package/src/client/reference/client/production/production-submission.ts +0 -310
  314. package/src/client/reference/client/production/protocol.ts +0 -231
  315. package/src/client/reference/client/production/reference-card.ts +0 -240
  316. package/src/client/reference/client/production/reference-labels.ts +0 -29
  317. package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
  318. package/src/client/reference/client/production/reveal.ts +0 -215
  319. package/src/client/reference/client/production/runtime.ts +0 -1101
  320. package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
  321. package/src/client/reference/client/production/source-marker.ts +0 -63
  322. package/src/client/reference/client/production/source-opener.ts +0 -55
  323. package/src/client/reference/client/production/styles.ts +0 -104
  324. package/src/client/reference/client/production/user-text-rule.ts +0 -58
  325. package/src/client/reference/client/reveal.ts +0 -107
  326. package/src/client/reference/client/scheme.ts +0 -114
  327. package/src/client/reference/client/types.ts +0 -168
  328. package/src/client/reference/css-modules.d.ts +0 -4
  329. package/src/client/reference/index.ts +0 -11
  330. package/src/client/reference-capture-owner.ts +0 -162
  331. package/src/client/reference-intents.ts +0 -36
  332. package/src/client/settings/index.ts +0 -34
  333. package/src/client/settings/panel.ts +0 -2657
  334. package/src/client/shortcut-open.ts +0 -30
  335. package/src/client/startpage/binding.ts +0 -99
  336. package/src/client/startpage/controller.ts +0 -303
  337. package/src/client/startpage/model.ts +0 -279
  338. package/src/client/view/Browser.module.css +0 -751
  339. package/src/client/view/BrowserBody.tsx +0 -314
  340. package/src/client/view/BrowserPresentation.ts +0 -9
  341. package/src/client/view/BrowserTitle.tsx +0 -17
  342. package/src/client/view/IframePresentation.ts +0 -344
  343. package/src/client/view/StartPage.tsx +0 -597
  344. package/src/client/view/TakeoverBanner.tsx +0 -21
  345. package/src/index.ts +0 -110
  346. package/src/reference-owner.ts +0 -5
  347. package/src/reference-page.ts +0 -9
  348. package/src/reference-source.ts +0 -3
  349. package/src/reference-text.ts +0 -197
  350. package/src/startpage-settings.ts +0 -103
  351. package/src/startpage.ts +0 -71
  352. package/src/takeover-protocol.ts +0 -19
  353. package/src/tool-browser/code-tool.ts +0 -401
  354. package/src/tool-browser/code-worker.ts +0 -639
  355. package/src/tool-browser/element-fields.ts +0 -167
  356. package/src/tool-browser/index.ts +0 -3733
  357. package/src/tool-browser/page-probe.ts +0 -474
  358. package/src/tool-browser/panel-page.ts +0 -124
  359. package/src/tool-browser/screenshot-image.ts +0 -49
  360. package/src/tool-browser/takeover.ts +0 -198
  361. package/src/types/electron-shim.d.ts +0 -144
  362. package/src/types.ts +0 -85
  363. package/src/web-guest.ts +0 -34
  364. package/tools/accept-desktop.mjs +0 -148
@@ -1,639 +0,0 @@
1
- /**
2
- * The dsh_browser_code REPL worker: one child process per task, like Browser Use 1.0's
3
- * repl/worker.py. It keeps one vm context alive across calls (variables and functions survive),
4
- * prints the last expression, and reaches the browser only by asking the parent to run a
5
- * registered dsh_browser_* tool. A runaway cell is stopped by killing this process; the browser
6
- * and the parent are never blocked by it.
7
- */
8
- import { Script, createContext, runInContext } from 'node:vm'
9
- import { inspect } from 'node:util'
10
-
11
- type Reply = { readonly type: 'reply'; readonly id: number; readonly value?: unknown; readonly text?: string; readonly error?: string }
12
- type Run = { readonly type: 'run'; readonly code: string }
13
-
14
- const send = (message: unknown): void => { process.send?.(message) }
15
- const pending = new Map<number, { resolve: (reply: Reply) => void }>()
16
- let seq = 0
17
-
18
- function format(value: unknown): string {
19
- if (typeof value === 'string') return value
20
- if (value === undefined) return 'undefined'
21
- if (typeof value === 'function') return inspect(value)
22
- try { return JSON.stringify(value) ?? String(value) } catch { return inspect(value, { depth: 4 }) }
23
- }
24
- const log = (...values: unknown[]): void => { send({ type: 'log', text: values.map(format).join(' ') }) }
25
-
26
- async function ask(name: string, args: Record<string, unknown> = {}): Promise<Reply> {
27
- const id = ++seq
28
- const reply = await new Promise<Reply>(resolve => { pending.set(id, { resolve }); send({ type: 'call', id, name, args }) })
29
- if (reply.error !== undefined) throw new Error(reply.error)
30
- return reply
31
- }
32
- const value = async (name: string, args?: Record<string, unknown>): Promise<unknown> => (await ask(name, args)).value
33
-
34
- /** A failed `tools.*` call, named after the tool, like DSH run_code's ToolCallError. */
35
- class ToolCallError extends Error {
36
- readonly toolName: string
37
- constructor(toolName: string, message: string) {
38
- super(message)
39
- this.name = 'ToolCallError'
40
- this.toolName = toolName
41
- }
42
- }
43
-
44
- /** DSH run_code-style bindings: `await tools.dsh_browser_snapshot({})` resolves to the tool's JSON value. */
45
- const tools: Record<string, (args?: Record<string, unknown>) => Promise<unknown>> = new Proxy(Object.create(null), {
46
- get: (_target, name) => typeof name !== 'string' || name === 'then' ? undefined : async (args: Record<string, unknown> = {}) => {
47
- try { return (await ask(name, args)).value } catch (error) { throw new ToolCallError(name, error instanceof Error ? error.message : String(error)) }
48
- },
49
- })
50
- const text = async (name: string, args?: Record<string, unknown>): Promise<string> => (await ask(name, args)).text ?? ''
51
-
52
- export type Target = string | { css?: string; text?: string; xpath?: string; by?: string; value?: string; index?: number; x?: number; y?: number }
53
-
54
- const HTML_TAGS = new Set(['a', 'button', 'input', 'select', 'textarea', 'form', 'div', 'span', 'li', 'ul', 'ol', 'table', 'tr', 'td', 'th', 'tbody', 'thead', 'img', 'label', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'nav', 'main', 'header', 'footer', 'section', 'article', 'aside', 'option', 'summary', 'details', 'iframe', 'body', 'svg', 'dialog'])
55
-
56
- function looksLikeSelector(raw: string): boolean {
57
- if (/^[#.[]\S/.test(raw)) return true
58
- const tag = /^[a-z][a-z0-9-]*/.exec(raw)?.[0]
59
- if (tag === undefined || !HTML_TAGS.has(tag)) return false
60
- const rest = raw.slice(tag.length)
61
- return rest === '' || /^[#.[:]/.test(rest) || /^\s*>/.test(rest)
62
- }
63
-
64
- /**
65
- * Turn a helper target into click/type arguments. A string is visible text unless it reads as a
66
- * CSS selector or an XPath expression.
67
- * @param target - text, selector, {css|text|xpath, index}, {by, value} or {x, y}.
68
- */
69
- export function targetArgs(target: Target): Record<string, unknown> {
70
- if (typeof target === 'string') {
71
- if (target.startsWith('//') || target.startsWith('(//')) return { target: { by: 'xpath', value: target } }
72
- return { target: { by: looksLikeSelector(target) ? 'css' : 'text', value: target } }
73
- }
74
- if (target === null || typeof target !== 'object') throw new Error(`invalid target ${JSON.stringify(target)}`)
75
- if (typeof target.x === 'number' && typeof target.y === 'number') return { x: target.x, y: target.y }
76
- const index = target.index !== undefined ? { index: target.index } : {}
77
- if (target.css !== undefined) return { target: { by: 'css', value: target.css, ...index } }
78
- if (target.text !== undefined) return { target: { by: 'text', value: target.text, ...index } }
79
- if (target.xpath !== undefined) return { target: { by: 'xpath', value: target.xpath, ...index } }
80
- if (target.value !== undefined) return { target: { by: target.by ?? 'css', value: target.value, ...index } }
81
- throw new Error(`invalid target ${JSON.stringify(target)}`)
82
- }
83
-
84
- const NOT_EXPRESSION = /^(return|if|for|while|do|switch|try|catch|finally|throw|const|let|var|function|async\s+function|class|import|export|break|continue|else|\}|\)|\]|\/\/|\/\*|\*)/
85
- const CONTINUES = /[([{,+\-*/%=&|?:.<>!^~]$|=>$/
86
- const REGEX_BEFORE = new Set(['', '(', '[', '{', ',', ';', ':', '=', '!', '&', '|', '?', '+', '-', '*', '%', '^', '~', '<', '>', '\n'])
87
- const REGEX_KEYWORDS = new Set(['return', 'throw', 'case', 'in', 'instanceof', 'typeof', 'void', 'delete', 'new', 'await', 'yield', 'else', 'do', 'of'])
88
-
89
- interface ScanResult {
90
- readonly rewritten: string
91
- readonly varNames: readonly string[]
92
- readonly fnNames: readonly string[]
93
- readonly hasTopReturn: boolean
94
- }
95
-
96
- /**
97
- * Dedent top-level lines while leaving multiline template literal bodies untouched, so unindented
98
- * lines inside a template literal do not prevent dedenting the surrounding cell (and trailing
99
- * parenthesized expressions still get turned into `return (...)` instead of triggering ASI calls).
100
- */
101
- function dedentTopLevel(code: string): { readonly dedented: string; readonly inTemplateStart: readonly boolean[] } {
102
- const trimmed = code.replace(/\s+$/, '')
103
- const lines = trimmed.split('\n')
104
- const inTemplateStart = new Array<boolean>(lines.length).fill(false)
105
- let lineIdx = 0
106
- let i = 0
107
- let prevChar = ''
108
- let prevWord = ''
109
- const n = trimmed.length
110
-
111
- const isIdentStart = (ch: string): boolean => /[A-Za-z_$]/.test(ch)
112
- const isIdentPart = (ch: string): boolean => /[\w$]/.test(ch)
113
- const advance = (ch: string): void => { if (ch === '\n') lineIdx++ }
114
-
115
- const skipRegex = (): void => {
116
- i++
117
- let inClass = false
118
- while (i < n) {
119
- const ch = trimmed[i]!
120
- if (ch === '\\') { advance(trimmed[i + 1] ?? ''); i += 2; continue }
121
- if (ch === '[') inClass = true
122
- else if (ch === ']') inClass = false
123
- else if (ch === '/' && !inClass) {
124
- i++
125
- while (i < n && /[a-z]/i.test(trimmed[i]!)) i++
126
- return
127
- } else if (ch === '\n') return
128
- i++
129
- }
130
- }
131
-
132
- const skipQuoted = (quote: string): void => {
133
- i++
134
- while (i < n) {
135
- const ch = trimmed[i]!
136
- if (ch === '\\') { advance(trimmed[i + 1] ?? ''); i += 2; continue }
137
- if (quote === '`' && ch === '$' && trimmed[i + 1] === '{') {
138
- i += 2
139
- let exprDepth = 1
140
- let exprPrev = '{'
141
- let exprWord = ''
142
- while (i < n && exprDepth > 0) {
143
- const c = trimmed[i]!
144
- if (c === "'" || c === '"' || c === '`') { skipQuoted(c); exprPrev = '"'; exprWord = ''; continue }
145
- if (c === '/' && trimmed[i + 1] === '/') { while (i < n && trimmed[i] !== '\n') i++; continue }
146
- if (c === '/' && trimmed[i + 1] === '*') {
147
- i += 2
148
- while (i < n && !(trimmed[i] === '*' && trimmed[i + 1] === '/')) { advance(trimmed[i]!); i++ }
149
- if (i < n) i += 2
150
- continue
151
- }
152
- if (c === '/' && (REGEX_BEFORE.has(exprPrev) || REGEX_KEYWORDS.has(exprWord))) { skipRegex(); exprPrev = '/'; exprWord = ''; continue }
153
- if (isIdentStart(c)) {
154
- const start = i
155
- i++
156
- while (i < n && isIdentPart(trimmed[i]!)) i++
157
- exprPrev = 'a'; exprWord = trimmed.slice(start, i)
158
- continue
159
- }
160
- if (c === '{') exprDepth++
161
- else if (c === '}') exprDepth--
162
- if (c === '\n') { lineIdx++; exprPrev = '\n'; exprWord = '' }
163
- else if (!/\s/.test(c)) { exprPrev = c; exprWord = '' }
164
- i++
165
- }
166
- continue
167
- }
168
- if (ch === quote) { i++; return }
169
- if (ch === '\n') {
170
- lineIdx++
171
- if (quote === '`' && lineIdx < lines.length) inTemplateStart[lineIdx] = true
172
- }
173
- i++
174
- }
175
- }
176
-
177
- while (i < n) {
178
- const ch = trimmed[i]!
179
- if (ch === "'" || ch === '"' || ch === '`') { skipQuoted(ch); prevChar = '"'; prevWord = ''; continue }
180
- if (ch === '/' && trimmed[i + 1] === '/') { while (i < n && trimmed[i] !== '\n') i++; continue }
181
- if (ch === '/' && trimmed[i + 1] === '*') {
182
- i += 2
183
- while (i < n && !(trimmed[i] === '*' && trimmed[i + 1] === '/')) { advance(trimmed[i]!); i++ }
184
- if (i < n) i += 2
185
- continue
186
- }
187
- if (ch === '/' && (REGEX_BEFORE.has(prevChar) || REGEX_KEYWORDS.has(prevWord))) { skipRegex(); prevChar = '/'; prevWord = ''; continue }
188
- if (isIdentStart(ch)) {
189
- const start = i
190
- i++
191
- while (i < n && isIdentPart(trimmed[i]!)) i++
192
- prevChar = 'a'; prevWord = trimmed.slice(start, i)
193
- continue
194
- }
195
- if (ch === '\n') { lineIdx++; prevChar = '\n'; prevWord = '' }
196
- else if (!/\s/.test(ch)) { prevChar = ch; prevWord = '' }
197
- i++
198
- }
199
-
200
- const indents = lines
201
- .filter((line, idx) => !inTemplateStart[idx] && line.trim() !== '')
202
- .map(line => /^[ \t]*/.exec(line)?.[0].length ?? 0)
203
- const indent = indents.length > 0 ? Math.min(...indents) : 0
204
- const dedented = indent === 0
205
- ? trimmed
206
- : lines.map((line, idx) => inTemplateStart[idx] ? line : line.slice(indent)).join('\n')
207
- return { dedented, inTemplateStart }
208
- }
209
-
210
- /**
211
- * Lexically scan top-level declarations (skipping comments, strings, nested template literals,
212
- * regex literals and nested blocks) so destructuring, multiline template strings and hoisted
213
- * functions all persist cleanly across REPL cells.
214
- */
215
- function scanTopLevel(code: string): ScanResult {
216
- const varNames = new Set<string>()
217
- const fnNames = new Set<string>()
218
- const replacements: { readonly start: number; readonly end: number; readonly text: string }[] = []
219
- let hasTopReturn = false
220
- let depth = 0
221
- let i = 0
222
- let prevChar = ''
223
- let prevWord = ''
224
- const n = code.length
225
-
226
- const isIdentStart = (ch: string): boolean => /[A-Za-z_$]/.test(ch)
227
- const isIdentPart = (ch: string): boolean => /[\w$]/.test(ch)
228
-
229
- const skipSpacesAndComments = (allowNewline = true): void => {
230
- while (i < n) {
231
- const ch = code[i]!
232
- if (ch === ' ' || ch === '\t' || ch === '\r' || (allowNewline && ch === '\n')) { i++; continue }
233
- if (ch === '/' && code[i + 1] === '/') { while (i < n && code[i] !== '\n') i++; continue }
234
- if (ch === '/' && code[i + 1] === '*') {
235
- const end = code.indexOf('*/', i + 2)
236
- i = end === -1 ? n : end + 2
237
- continue
238
- }
239
- break
240
- }
241
- }
242
-
243
- const skipQuoted = (quote: string): void => {
244
- i++
245
- while (i < n) {
246
- const ch = code[i]!
247
- if (ch === '\\') { i += 2; continue }
248
- if (quote === '`' && ch === '$' && code[i + 1] === '{') {
249
- i += 2
250
- let exprDepth = 1
251
- while (i < n && exprDepth > 0) {
252
- const c = code[i]!
253
- if (c === "'" || c === '"' || c === '`') skipQuoted(c)
254
- else if (c === '/' && code[i + 1] === '/') { while (i < n && code[i] !== '\n') i++ }
255
- else if (c === '/' && code[i + 1] === '*') { const end = code.indexOf('*/', i + 2); i = end === -1 ? n : end + 2 }
256
- else { if (c === '{') exprDepth++; else if (c === '}') exprDepth--; i++ }
257
- }
258
- continue
259
- }
260
- if (ch === quote) { i++; return }
261
- i++
262
- }
263
- }
264
-
265
- const skipRegex = (): void => {
266
- i++
267
- let inClass = false
268
- while (i < n) {
269
- const ch = code[i]!
270
- if (ch === '\\') { i += 2; continue }
271
- if (ch === '[') inClass = true
272
- else if (ch === ']') inClass = false
273
- else if (ch === '/' && !inClass) {
274
- i++
275
- while (i < n && /[a-z]/i.test(code[i]!)) i++
276
- return
277
- } else if (ch === '\n') return
278
- i++
279
- }
280
- }
281
-
282
- const readIdent = (): string | undefined => {
283
- if (i >= n || !isIdentStart(code[i]!)) return undefined
284
- const start = i
285
- i++
286
- while (i < n && isIdentPart(code[i]!)) i++
287
- return code.slice(start, i)
288
- }
289
-
290
- const skipBalancedExpr = (stopChars: string): void => {
291
- let exprDepth = 0
292
- let localPrev = '='
293
- let localWord = ''
294
- while (i < n) {
295
- const ch = code[i]!
296
- if (ch === "'" || ch === '"' || ch === '`') { skipQuoted(ch); localPrev = '"'; localWord = ''; continue }
297
- if (ch === '/' && code[i + 1] === '/') { while (i < n && code[i] !== '\n') i++; continue }
298
- if (ch === '/' && code[i + 1] === '*') { const end = code.indexOf('*/', i + 2); i = end === -1 ? n : end + 2; continue }
299
- if (ch === '/' && (REGEX_BEFORE.has(localPrev) || REGEX_KEYWORDS.has(localWord))) { skipRegex(); localPrev = '/'; localWord = ''; continue }
300
- if (ch === '(' || ch === '[' || ch === '{') { exprDepth++; i++; localPrev = ch; localWord = ''; continue }
301
- if (ch === ')' || ch === ']' || ch === '}') {
302
- if (exprDepth === 0 && stopChars.includes(ch)) return
303
- exprDepth = Math.max(0, exprDepth - 1); i++; localPrev = ch; localWord = ''; continue
304
- }
305
- if (exprDepth === 0 && stopChars.includes(ch)) return
306
- if (isIdentStart(ch)) {
307
- const w = readIdent() ?? ''
308
- localPrev = 'a'; localWord = w; continue
309
- }
310
- if (!/\s/.test(ch)) { localPrev = ch; localWord = '' }
311
- else if (ch === '\n' && exprDepth === 0 && stopChars.includes('\n')) return
312
- i++
313
- }
314
- }
315
-
316
- const parseBindingPattern = (): void => {
317
- skipSpacesAndComments()
318
- if (i >= n) return
319
- if (code.startsWith('...', i)) {
320
- i += 3
321
- skipSpacesAndComments()
322
- const name = readIdent()
323
- if (name !== undefined) varNames.add(name)
324
- return
325
- }
326
- if (code[i] === '[') {
327
- i++
328
- while (i < n) {
329
- skipSpacesAndComments()
330
- if (code[i] === ']') { i++; return }
331
- if (code[i] === ',') { i++; continue }
332
- parseBindingPattern()
333
- skipSpacesAndComments()
334
- if (code[i] === '=') { i++; skipBalancedExpr(',]') }
335
- skipSpacesAndComments()
336
- if (code[i] === ',') i++
337
- else if (code[i] === ']') { i++; return }
338
- else break
339
- }
340
- return
341
- }
342
- if (code[i] === '{') {
343
- i++
344
- while (i < n) {
345
- skipSpacesAndComments()
346
- if (code[i] === '}') { i++; return }
347
- if (code.startsWith('...', i)) {
348
- i += 3
349
- skipSpacesAndComments()
350
- const rest = readIdent()
351
- if (rest !== undefined) varNames.add(rest)
352
- } else {
353
- let keyIdent: string | undefined
354
- if (code[i] === '[') {
355
- i++; skipBalancedExpr(']'); if (code[i] === ']') i++
356
- } else if (code[i] === "'" || code[i] === '"') {
357
- skipQuoted(code[i]!)
358
- } else if (isIdentStart(code[i]!)) {
359
- keyIdent = readIdent()
360
- } else {
361
- while (i < n && !/[\s:,=}]/.test(code[i]!)) i++
362
- }
363
- skipSpacesAndComments()
364
- if (code[i] === ':') {
365
- i++
366
- parseBindingPattern()
367
- } else if (keyIdent !== undefined) {
368
- varNames.add(keyIdent)
369
- }
370
- }
371
- skipSpacesAndComments()
372
- if (code[i] === '=') { i++; skipBalancedExpr(',}') }
373
- skipSpacesAndComments()
374
- if (code[i] === ',') i++
375
- else if (code[i] === '}') { i++; return }
376
- else break
377
- }
378
- return
379
- }
380
- const name = readIdent()
381
- if (name !== undefined) varNames.add(name)
382
- }
383
-
384
- while (i < n) {
385
- const ch = code[i]!
386
- if (ch === "'" || ch === '"' || ch === '`') { skipQuoted(ch); prevChar = '"'; prevWord = ''; continue }
387
- if (ch === '/' && code[i + 1] === '/') { while (i < n && code[i] !== '\n') i++; continue }
388
- if (ch === '/' && code[i + 1] === '*') { const end = code.indexOf('*/', i + 2); i = end === -1 ? n : end + 2; continue }
389
- if (ch === '/' && (REGEX_BEFORE.has(prevChar) || REGEX_KEYWORDS.has(prevWord))) { skipRegex(); prevChar = '/'; prevWord = ''; continue }
390
- if (ch === '{' || ch === '(' || ch === '[') { depth++; i++; prevChar = ch; prevWord = ''; continue }
391
- if (ch === '}' || ch === ')' || ch === ']') { depth = Math.max(0, depth - 1); i++; prevChar = ch; prevWord = ''; continue }
392
-
393
- if (depth === 0 && isIdentStart(ch) && prevChar !== '.') {
394
- const wordStart = i
395
- const word = readIdent()!
396
- if (word === 'const' || word === 'let' || word === 'var') {
397
- if (word !== 'var') replacements.push({ start: wordStart, end: i, text: 'var' })
398
- while (i < n) {
399
- parseBindingPattern()
400
- skipSpacesAndComments(false)
401
- if (code[i] === '=') {
402
- i++
403
- skipSpacesAndComments(true)
404
- skipBalancedExpr(',;\n')
405
- }
406
- skipSpacesAndComments(false)
407
- if (code[i] === ',') { i++; continue }
408
- break
409
- }
410
- prevChar = 'a'; prevWord = ''
411
- continue
412
- }
413
- if (word === 'async') {
414
- const saved = i
415
- skipSpacesAndComments(false)
416
- if (code.startsWith('function', i) && !isIdentPart(code[i + 8] ?? '')) {
417
- i += 8
418
- skipSpacesAndComments()
419
- if (code[i] === '*') { i++; skipSpacesAndComments() }
420
- const fn = readIdent()
421
- if (fn !== undefined) fnNames.add(fn)
422
- prevChar = 'a'; prevWord = 'function'
423
- continue
424
- }
425
- i = saved
426
- }
427
- if (word === 'function') {
428
- skipSpacesAndComments()
429
- if (code[i] === '*') { i++; skipSpacesAndComments() }
430
- const fn = readIdent()
431
- if (fn !== undefined) fnNames.add(fn)
432
- prevChar = 'a'; prevWord = 'function'
433
- continue
434
- }
435
- if (word === 'class') {
436
- skipSpacesAndComments()
437
- const cls = readIdent()
438
- if (cls !== undefined) {
439
- varNames.add(cls)
440
- replacements.push({ start: wordStart, end: wordStart + 5, text: `var ${cls} = class` })
441
- }
442
- prevChar = 'a'; prevWord = 'class'
443
- continue
444
- }
445
- if (word === 'return') hasTopReturn = true
446
- prevChar = 'a'; prevWord = word
447
- continue
448
- }
449
-
450
- if (ch === '\n') { prevChar = '\n'; prevWord = '' }
451
- else if (!/\s/.test(ch)) { prevChar = ch; prevWord = '' }
452
- i++
453
- }
454
-
455
- let rewritten = code
456
- for (let idx = replacements.length - 1; idx >= 0; idx--) {
457
- const rep = replacements[idx]!
458
- rewritten = rewritten.slice(0, rep.start) + rep.text + rewritten.slice(rep.end)
459
- }
460
- return { rewritten, varNames: [...varNames], fnNames: [...fnNames], hasTopReturn }
461
- }
462
-
463
- /**
464
- * Make a cell behave like a REPL cell: top-level declarations land on the context (so they
465
- * survive the call) and a trailing expression is the cell's value.
466
- * @param code - the model's cell.
467
- * @returns an async function body.
468
- */
469
- export function prepare(code: string): string {
470
- const { dedented, inTemplateStart } = dedentTopLevel(code)
471
- const { rewritten, varNames, fnNames, hasTopReturn } = scanTopLevel(dedented)
472
- const prelude = fnNames.length === 0 ? '' : fnNames.map(name => `globalThis.${name} = ${name};`).join(' ') + '\n'
473
- const persist = varNames.length === 0
474
- ? ''
475
- : varNames.map(name => `try { if (typeof ${name} !== 'undefined' || !(${JSON.stringify(name)} in globalThis)) globalThis.${name} = ${name}; } catch {}`).join(' ')
476
- const wrap = (body: string): string => {
477
- if (persist !== '') return `try {\n${prelude}${body}\n} finally {\n${persist}\n}`
478
- return `${prelude}${body}`
479
- }
480
-
481
- if (hasTopReturn) return wrap(rewritten)
482
- const lines = rewritten.split('\n')
483
- const last = lines.length - 1
484
- const line = lines[last] ?? ''
485
- const previous = lines.slice(0, last).reverse().find(l => l.trim() !== '')?.trimEnd() ?? ''
486
- if (inTemplateStart[last] || line === '' || /^\s/.test(line) || NOT_EXPRESSION.test(line) || CONTINUES.test(previous) || /[{,]$/.test(line)) {
487
- return wrap(rewritten)
488
- }
489
- // A one-line cell of several statements returns its last one.
490
- const split = line.lastIndexOf(';', line.replace(/;\s*$/, '').length - 1)
491
- const head = split > 0 ? line.slice(0, split + 1) + '\n' : ''
492
- const tail = (split > 0 ? line.slice(split + 1) : line).trim().replace(/^;\s*/, '').replace(/;\s*$/, '')
493
- for (const candidate of [`${head}return (${tail})`, `return (${line.replace(/^;\s*/, '').replace(/;\s*$/, '')})`]) {
494
- const transformed = [...lines.slice(0, last), candidate].join('\n')
495
- if (tail !== '' && compiles(wrap(transformed))) return wrap(transformed)
496
- }
497
- return wrap(rewritten)
498
- }
499
-
500
- function compiles(body: string): boolean {
501
- try { new Script(`(async () => {\n${body}\n})`); return true } catch { return false }
502
- }
503
-
504
- /**
505
- * Wrap a page expression so its value comes back as JSON text that keeps strings strings and
506
- * numbers exact; a script with a top-level `return` runs as a function body.
507
- * @param script - an expression, or statements with `return`.
508
- */
509
- function pageScript(script: string): string {
510
- const expression = `return (${script.replace(/;\s*$/, '')})`
511
- const body = compiles(expression) ? expression : script
512
- return `(async () => { const v = await (async () => {\n${body}\n})(); return JSON.stringify(v === undefined ? null : v) })()`
513
- }
514
-
515
- const helpers = {
516
- // Browser Use 1.0 / browser-harness names.
517
- goto_url: (url: string) => text('open', { url }),
518
- new_tab: (url: string) => text('open', { url, newTab: true }),
519
- wait_for_load: async (timeoutMs?: number) => {
520
- const out = await value('wait', timeoutMs !== undefined ? { timeoutMs } : {}) as { ready: boolean; reason: string }
521
- if (!out.ready) throw new Error(`page did not finish loading: ${out.reason}`)
522
- return true
523
- },
524
- page_info: () => js('({ url: location.href, title: document.title, w: innerWidth, h: innerHeight, sx: scrollX, sy: scrollY, pw: document.documentElement.scrollWidth, ph: document.documentElement.scrollHeight })'),
525
- list_tabs: () => value('list_tabs'),
526
- switch_tab: (tabId: string) => text('switch_tab', { tabId }),
527
- close_tab: (tabId: string) => text('close_tab', { tabId }),
528
- js: (script: string) => js(script),
529
- click_at_xy: (x: number, y: number) => text('click', { x, y }),
530
- type_text: (input: string) => text('type', { text: input }),
531
- fill_input: (target: Target, input: string) => text('set_value', { ...targetArgs(target), value: input }),
532
- press_key: (key: string) => text('key', { key }),
533
- scroll: async (...args: unknown[]) => {
534
- if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null) return text('scroll', args[0] as Record<string, unknown>)
535
- if (args.length >= 3) {
536
- const [x, y, dy] = [Number(args[0]), Number(args[1]), Number(args[2])]
537
- if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(dy)) {
538
- throw new Error('scroll(x, y, dy): coordinates and deltaY must be finite numbers')
539
- }
540
- return await js(`(() => {
541
- let el = document.elementFromPoint(${JSON.stringify(x)}, ${JSON.stringify(y)});
542
- while (el && el !== document.documentElement && el !== document.body) {
543
- const st = getComputedStyle(el);
544
- if (/(auto|scroll)/.test(st.overflowY) && el.scrollHeight > el.clientHeight) {
545
- el.scrollBy({ top: ${JSON.stringify(dy)} });
546
- return 'Scrolled element.';
547
- }
548
- el = el.parentElement;
549
- }
550
- window.scrollBy({ top: ${JSON.stringify(dy)} });
551
- return 'Scrolled window.';
552
- })()`)
553
- }
554
- const deltaY = args.length === 1 ? Number(args[0]) : 600
555
- return text('scroll', { deltaY })
556
- },
557
- screenshot: (opts: Record<string, unknown> = {}) => text('screenshot', opts),
558
- wait_for_element: async (selector: string, timeoutMs?: number) => {
559
- const out = await value('wait', { selector, ...timeoutMs !== undefined ? { timeoutMs } : {} }) as { ready: boolean; reason: string }
560
- if (!out.ready) throw new Error(`wait_for_element: ${out.reason}`)
561
- return true
562
- },
563
- wait_for_network_idle: async (timeoutMs?: number) => {
564
- const out = await value('do', { steps: [{ wait_idle: {} }], ...timeoutMs !== undefined ? { timeoutMs } : {} }) as { ok: boolean; reason?: string }
565
- if (!out.ok) throw new Error(`wait_for_network_idle: ${out.reason ?? 'not idle'}`)
566
- return true
567
- },
568
- upload_file: (selector: string, path: string) => text('upload', { target: { by: 'css', value: selector }, path }),
569
- // Semantic helpers over the dsh tools.
570
- click: (target: Target) => text('click', targetArgs(target)),
571
- type: async (target: Target, input?: string | { submit?: boolean }, opts: { submit?: boolean } = {}) => {
572
- if (typeof input !== 'string' && typeof target !== 'string') {
573
- throw new Error('type(target, text): text must be a string when target is an object')
574
- }
575
- const toolArgs = typeof input === 'string' ? { ...targetArgs(target), text: input } : { text: target as string }
576
- if (typeof input === 'object' && input !== null) opts = input
577
- let out = await text('type', toolArgs)
578
- if (opts.submit === true) out += '\n' + await text('key', { key: 'Enter' })
579
- return out
580
- },
581
- select: (target: Target, optionText: string) => text('select', { ...targetArgs(target), optionText }),
582
- fill: async (fields: readonly Record<string, unknown>[], opts: { submit?: boolean } = {}) => {
583
- const out = await value('fill', { fields, ...opts.submit === true ? { submit: true } : {} }) as { fields: { ok: boolean; target?: string; error?: string }[]; submitted?: boolean }
584
- const failed = out.fields.filter(field => !field.ok)
585
- if (failed.length > 0) throw new Error(`fill: ${failed.length} field(s) failed: ${failed.map(field => `${field.target ?? '?'}: ${field.error ?? 'failed'}`).join('; ')}`)
586
- return out
587
- },
588
- back: () => text('back'),
589
- forward: () => text('forward'),
590
- refresh: () => text('refresh'),
591
- read: async (opts: Record<string, unknown> = {}) => {
592
- const out = await value('content', { format: 'markdown', maxChars: 20000, ...opts }) as { content?: string; truncated?: boolean }
593
- return (out.content ?? '') + (out.truncated === true ? '\n[truncated; pass selector or maxChars]' : '')
594
- },
595
- snapshot: (opts: Record<string, unknown> = {}) => text('snapshot', opts),
596
- find: (needle: string, opts: Record<string, unknown> = {}) => text('find', { text: needle, ...opts }),
597
- state: () => text('state'),
598
- refs: {
599
- capture: (opts: Record<string, unknown> = {}) => text('reference_capture', opts),
600
- list: (opts: Record<string, unknown> = {}) => text('reference_list', opts),
601
- reveal: (opts: Record<string, unknown>) => text('reference_reveal', opts),
602
- },
603
- call: (name: string, args: Record<string, unknown> = {}) => value(name, args),
604
- help: (name?: string) => value('__help', name === undefined ? {} : { name }),
605
- sleep: (ms: number) => new Promise<void>(done => setTimeout(done, Math.min(Math.max(Number(ms) || 0, 0), 60_000))),
606
- print: log,
607
- log,
608
- console: { log, info: log, warn: log, error: log, debug: log },
609
- }
610
-
611
- async function js(script: string): Promise<unknown> {
612
- const out = await value('execute', { script: pageScript(script) }) as { ok: boolean; value?: string; exception?: string }
613
- if (!out.ok) throw new Error(`js: ${out.exception ?? 'page script failed'}`)
614
- return out.value === undefined ? undefined : JSON.parse(out.value)
615
- }
616
-
617
- const context = createContext({ ...helpers, open: helpers.goto_url, press: helpers.press_key, tools, ToolCallError })
618
-
619
- process.on('message', (message: Reply | Run) => {
620
- if (message.type === 'reply') {
621
- const entry = pending.get(message.id)
622
- pending.delete(message.id)
623
- entry?.resolve(message)
624
- return
625
- }
626
- if (message.type === 'run') {
627
- void (async () => {
628
- try {
629
- const result = await (runInContext(`(async () => {\n${prepare(message.code)}\n})()`, context, { filename: 'cell.js' }) as Promise<unknown>)
630
- if (result !== undefined) log(result)
631
- send({ type: 'done', ok: true })
632
- } catch (error) {
633
- send({ type: 'done', ok: false, error: error instanceof Error ? `${error.name === 'Error' ? '' : `${error.name}: `}${error.message}` : String(error) })
634
- }
635
- })()
636
- }
637
- })
638
- process.on('disconnect', () => process.exit(0))
639
- send({ type: 'ready' })