dsh-builtin-browser 1.0.3 → 1.0.4

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 (293) hide show
  1. package/README.en.md +89 -0
  2. package/browser-extension/constants.mjs +20 -0
  3. package/browser-extension/controller.mjs +293 -0
  4. package/browser-extension/locales.mjs +15 -0
  5. package/browser-extension/manifest.json +12 -0
  6. package/browser-extension/options.html +14 -0
  7. package/browser-extension/options.mjs +9 -0
  8. package/browser-extension/permission-guard.mjs +13 -0
  9. package/browser-extension/worker.mjs +74 -0
  10. package/package.json +20 -2
  11. package/scripts/build-client.mjs +305 -0
  12. package/scripts/build.mjs +69 -0
  13. package/scripts/bundle-host.mjs +28 -0
  14. package/scripts/fix-exports.mjs +40 -0
  15. package/scripts/install-electron.mjs +101 -0
  16. package/scripts/pack.mjs +99 -0
  17. package/scripts/publish-manifest.mjs +56 -0
  18. package/scripts/verify-exports.mjs +58 -0
  19. package/scripts/verify-preview-sdk.mjs +93 -0
  20. package/skills/dsh-builtin-browser/SKILL.md +98 -0
  21. package/skills/dsh-builtin-browser/references/batch.md +68 -0
  22. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  23. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  24. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  25. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  26. package/skills/dsh-debug-host/SKILL.md +56 -0
  27. package/skills/dsh-debug-self/SKILL.md +50 -0
  28. package/src/bridge-compatibility.ts +39 -0
  29. package/src/browser/anti-bot.ts +251 -0
  30. package/src/browser/deep-dom.ts +40 -0
  31. package/src/browser/handles.ts +89 -0
  32. package/src/browser/runtime.ts +578 -0
  33. package/src/browser/takeover-target.ts +45 -0
  34. package/src/browser/types.ts +870 -0
  35. package/src/browser-electron/authenticated-route.ts +109 -0
  36. package/src/browser-electron/automatic-maintenance.ts +736 -0
  37. package/src/browser-electron/bridge-auto.ts +159 -0
  38. package/src/browser-electron/bridge-connection.ts +386 -0
  39. package/src/browser-electron/bridge-endpoint.ts +129 -0
  40. package/src/browser-electron/bridge-install.ts +290 -0
  41. package/src/browser-electron/bridge-maintenance.ts +189 -0
  42. package/src/browser-electron/bridge-status.ts +386 -0
  43. package/src/browser-electron/desktop-bridge-host.ts +253 -0
  44. package/src/browser-electron/desktop-identity.ts +353 -0
  45. package/src/browser-electron/desktop-shell.ts +100 -0
  46. package/src/browser-electron/document-readiness.ts +45 -0
  47. package/src/browser-electron/electron-provision.ts +347 -0
  48. package/src/browser-electron/entry.ts +1378 -0
  49. package/src/browser-electron/ephemeral-profile.ts +189 -0
  50. package/src/browser-electron/extension-browser.ts +230 -0
  51. package/src/browser-electron/extension-setup.ts +67 -0
  52. package/src/browser-electron/file-write.ts +31 -0
  53. package/src/browser-electron/foreground-watch.ts +142 -0
  54. package/src/browser-electron/guest-cookie-jar.ts +177 -0
  55. package/src/browser-electron/guest-cookie-store.ts +59 -0
  56. package/src/browser-electron/guest-css-runtime.ts +76 -0
  57. package/src/browser-electron/guest-css.ts +68 -0
  58. package/src/browser-electron/guest-route.ts +716 -0
  59. package/src/browser-electron/guest-runtime.ts +408 -0
  60. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  61. package/src/browser-electron/guest-storage.ts +120 -0
  62. package/src/browser-electron/history-store.ts +224 -0
  63. package/src/browser-electron/host-main.ts +1385 -0
  64. package/src/browser-electron/host-patch-maintenance.ts +121 -0
  65. package/src/browser-electron/http-body.ts +65 -0
  66. package/src/browser-electron/json-reply.ts +47 -0
  67. package/src/browser-electron/maintenance-broker.ts +166 -0
  68. package/src/browser-electron/maintenance-lifecycle.ts +91 -0
  69. package/src/browser-electron/maintenance-route.ts +68 -0
  70. package/src/browser-electron/missing-system-browser.ts +114 -0
  71. package/src/browser-electron/open-slot.ts +49 -0
  72. package/src/browser-electron/paths.ts +25 -0
  73. package/src/browser-electron/preferred-browser.ts +130 -0
  74. package/src/browser-electron/preview-route.ts +215 -0
  75. package/src/browser-electron/process-ownership.ts +174 -0
  76. package/src/browser-electron/process.ts +23 -0
  77. package/src/browser-electron/profile-checkpoint.ts +187 -0
  78. package/src/browser-electron/profile-command.ts +47 -0
  79. package/src/browser-electron/profile-extension.ts +129 -0
  80. package/src/browser-electron/profile-lease.ts +211 -0
  81. package/src/browser-electron/profile-residue.ts +49 -0
  82. package/src/browser-electron/provider-core.ts +1107 -0
  83. package/src/browser-electron/provider-interaction.ts +1034 -0
  84. package/src/browser-electron/provider-media.ts +589 -0
  85. package/src/browser-electron/provider-navigation.ts +323 -0
  86. package/src/browser-electron/provider-observation.ts +664 -0
  87. package/src/browser-electron/provider-tabs.ts +372 -0
  88. package/src/browser-electron/provider.ts +666 -0
  89. package/src/browser-electron/reference-route.ts +598 -0
  90. package/src/browser-electron/remote-host.ts +1538 -0
  91. package/src/browser-electron/rpc-input.ts +13 -0
  92. package/src/browser-electron/rpc-ops.ts +41 -0
  93. package/src/browser-electron/runtime-diagnostics.ts +38 -0
  94. package/src/browser-electron/runtime-route.ts +105 -0
  95. package/src/browser-electron/runtime-status.ts +309 -0
  96. package/src/browser-electron/settings-route.ts +64 -0
  97. package/src/browser-electron/settings-store.ts +593 -0
  98. package/src/browser-electron/shortcuts-route.ts +112 -0
  99. package/src/browser-electron/sidebar-only-host.ts +300 -0
  100. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  101. package/src/browser-electron/system-browser.ts +1850 -0
  102. package/src/browser-electron/tauri-host.ts +194 -0
  103. package/src/browser-electron/timing.ts +16 -0
  104. package/src/browser-electron/virtual-cursor.ts +162 -0
  105. package/src/browser-electron/windows-system.ts +24 -0
  106. package/src/browser-reference/delivery.ts +384 -0
  107. package/src/browser-reference/entry.ts +631 -0
  108. package/src/browser-reference/export.ts +339 -0
  109. package/src/browser-reference/import.ts +303 -0
  110. package/src/browser-reference/page-script.ts +1537 -0
  111. package/src/browser-reference/service.ts +1346 -0
  112. package/src/browser-reference/store.ts +172 -0
  113. package/src/browser-reference/text-quote.ts +219 -0
  114. package/src/browser-reference/types.ts +195 -0
  115. package/src/browser-reference/visible.ts +367 -0
  116. package/src/browser-reference/web-sources.ts +106 -0
  117. package/src/client/apply-guard.ts +22 -0
  118. package/src/client/browser/BrowserController.ts +693 -0
  119. package/src/client/browser/BrowserFrame.ts +78 -0
  120. package/src/client/browser/BrowserNavigation.ts +169 -0
  121. package/src/client/browser/BrowserPage.ts +23 -0
  122. package/src/client/browser/BrowserPersistence.ts +44 -0
  123. package/src/client/browser/IframeImpl.ts +182 -0
  124. package/src/client/browser/child-tabs.ts +14 -0
  125. package/src/client/browser/frame-history.ts +125 -0
  126. package/src/client/browser/frame-state.ts +27 -0
  127. package/src/client/browser/iframe-reference.ts +67 -0
  128. package/src/client/browser/initialization.ts +262 -0
  129. package/src/client/browser/omnibox.ts +243 -0
  130. package/src/client/browser/store.ts +38 -0
  131. package/src/client/browser/takeover-channel.ts +72 -0
  132. package/src/client/browser/url.ts +46 -0
  133. package/src/client/browser/web-reference-source.ts +56 -0
  134. package/src/client/css-modules.d.ts +4 -0
  135. package/src/client/definition.tsx +36 -0
  136. package/src/client/electron/ElectronWebViewImpl.ts +371 -0
  137. package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
  138. package/src/client/electron/NativeChildPresentation.ts +53 -0
  139. package/src/client/electron/NativeViewPage.ts +265 -0
  140. package/src/client/electron/pages.ts +23 -0
  141. package/src/client/electron/reference-overlay.ts +53 -0
  142. package/src/client/electron/workspace.ts +33 -0
  143. package/src/client/index.ts +333 -0
  144. package/src/client/locales.ts +860 -0
  145. package/src/client/pages.ts +28 -0
  146. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  147. package/src/client/reference/client/draft-reference.ts +167 -0
  148. package/src/client/reference/client/index.ts +7 -0
  149. package/src/client/reference/client/ordered-submission.ts +108 -0
  150. package/src/client/reference/client/pending-delivery.ts +216 -0
  151. package/src/client/reference/client/plugin.ts +208 -0
  152. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  153. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  154. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  155. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  156. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  157. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  158. package/src/client/reference/client/production/assembly.ts +447 -0
  159. package/src/client/reference/client/production/asset-store.ts +144 -0
  160. package/src/client/reference/client/production/availability.ts +72 -0
  161. package/src/client/reference/client/production/bytes.ts +36 -0
  162. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  163. package/src/client/reference/client/production/delivery-client.ts +211 -0
  164. package/src/client/reference/client/production/draft-adapter.ts +512 -0
  165. package/src/client/reference/client/production/http-transport.ts +212 -0
  166. package/src/client/reference/client/production/production-submission.ts +70 -0
  167. package/src/client/reference/client/production/protocol.ts +234 -0
  168. package/src/client/reference/client/production/reference-card.ts +240 -0
  169. package/src/client/reference/client/production/reference-labels.ts +29 -0
  170. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  171. package/src/client/reference/client/production/reveal.ts +215 -0
  172. package/src/client/reference/client/production/runtime.ts +1056 -0
  173. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  174. package/src/client/reference/client/production/source-marker.ts +99 -0
  175. package/src/client/reference/client/production/source-opener.ts +55 -0
  176. package/src/client/reference/client/production/styles.ts +104 -0
  177. package/src/client/reference/client/production/user-text-rule.ts +67 -0
  178. package/src/client/reference/client/reveal.ts +109 -0
  179. package/src/client/reference/client/scheme.ts +114 -0
  180. package/src/client/reference/client/session-schedule.ts +36 -0
  181. package/src/client/reference/client/types.ts +168 -0
  182. package/src/client/reference/css-modules.d.ts +4 -0
  183. package/src/client/reference/index.ts +11 -0
  184. package/src/client/reference-capture-owner.ts +162 -0
  185. package/src/client/reference-intents.ts +36 -0
  186. package/src/client/settings/index.ts +42 -0
  187. package/src/client/settings/mount-guard.ts +31 -0
  188. package/src/client/settings/panel.ts +2768 -0
  189. package/src/client/shortcut-open.ts +30 -0
  190. package/src/client/startpage/binding.ts +99 -0
  191. package/src/client/startpage/controller.ts +300 -0
  192. package/src/client/startpage/model.ts +279 -0
  193. package/src/client/view/Browser.module.css +751 -0
  194. package/src/client/view/BrowserBody.tsx +315 -0
  195. package/src/client/view/BrowserPresentation.ts +9 -0
  196. package/src/client/view/BrowserTitle.tsx +17 -0
  197. package/src/client/view/IframePresentation.ts +365 -0
  198. package/src/client/view/StartPage.tsx +598 -0
  199. package/src/client/view/TakeoverBanner.tsx +21 -0
  200. package/src/compat/host-features.ts +92 -0
  201. package/src/index.ts +110 -0
  202. package/src/reference-owner.ts +5 -0
  203. package/src/reference-page.ts +9 -0
  204. package/src/reference-source.ts +3 -0
  205. package/src/reference-text.ts +219 -0
  206. package/src/startpage-settings.ts +103 -0
  207. package/src/startpage.ts +71 -0
  208. package/src/takeover-protocol.ts +28 -0
  209. package/src/tool-browser/block-recovery.ts +85 -0
  210. package/src/tool-browser/code-tool.ts +555 -0
  211. package/src/tool-browser/code-worker.ts +725 -0
  212. package/src/tool-browser/element-fields.ts +167 -0
  213. package/src/tool-browser/errors.ts +40 -0
  214. package/src/tool-browser/index.ts +265 -0
  215. package/src/tool-browser/page-probe.ts +675 -0
  216. package/src/tool-browser/panel-page.ts +126 -0
  217. package/src/tool-browser/probe-client.ts +183 -0
  218. package/src/tool-browser/screenshot-annotations.ts +131 -0
  219. package/src/tool-browser/screenshot-image.ts +49 -0
  220. package/src/tool-browser/state.ts +375 -0
  221. package/src/tool-browser/takeover.ts +199 -0
  222. package/src/tool-browser/tools-debug.ts +806 -0
  223. package/src/tool-browser/tools-interaction.ts +956 -0
  224. package/src/tool-browser/tools-navigation.ts +786 -0
  225. package/src/tool-browser/tools-observation.ts +474 -0
  226. package/src/tool-browser/tools-reference.ts +294 -0
  227. package/src/types/electron-shim.d.ts +144 -0
  228. package/src/types.ts +85 -0
  229. package/src/web-guest.ts +35 -0
  230. package/tools/accept-desktop.mjs +148 -0
  231. package/dist/client.d.cts +0 -516
  232. package/dist/client.d.mts +0 -516
  233. package/dist/index.cjs +0 -92
  234. package/dist/index.d.mts +0 -2960
  235. package/dist/index.mjs +0 -24
  236. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  237. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  238. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  239. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  240. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  241. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  242. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  243. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  244. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  245. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  246. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  247. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  248. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  249. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  250. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  251. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  252. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  253. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  254. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  255. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  256. package/dsh-host-patch/sources/manifest.json +0 -218
  257. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  258. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  259. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  260. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  261. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  262. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  263. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  264. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  265. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  266. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  267. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  268. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  269. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  270. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  271. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  272. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  273. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  274. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  275. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  276. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  277. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  278. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  279. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  280. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  281. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  282. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  283. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  284. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  285. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  286. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  287. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  288. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  289. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  290. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  291. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  292. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  293. package/dsh-host-patch/sources/series.json +0 -260
@@ -0,0 +1,870 @@
1
+ /**
2
+ * Vocabulary for the browser capability seam (`ctx.browser`). One seam owns
3
+ * provider registration, session lifecycle, cancellation, errors, and product
4
+ * configuration; providers differ only in what backs a session (an Electron
5
+ * `WebContentsView` in the desktop shell, a headless Chromium relay for
6
+ * remote deployments, and so on).
7
+ * @module dsh-browser/browser/types
8
+ */
9
+
10
+ import { HarnessError } from '@deepseek-ai/dsh-error'
11
+
12
+ /**
13
+ * Stable identity of one browser session, resolved by the Host through a
14
+ * Typert `LookupMap` to the live session object (the same mechanism
15
+ * `Agent → agentId` uses). The id is opaque to the wire; only the provider
16
+ * and its host binding can interpret it.
17
+ */
18
+ export type BrowserSessionId = import('./handles.ts').BrowserSessionWireId
19
+
20
+ /**
21
+ * What one browser-capable backend is asked to do. Navigation is the minimal
22
+ * operation every provider shares; the seam deliberately keeps the request
23
+ * minimal so a provider swap never changes how the model asks.
24
+ */
25
+ export interface BrowserNavigateRequest {
26
+ /**
27
+ * The URL to open. Admission (HTTP(S) only) is provider-owned; the seam
28
+ * itself does not police credentials or private/localhost targets — a
29
+ * shared real browser legitimately reaches local dev servers.
30
+ */
31
+ readonly url: string
32
+ }
33
+
34
+ /**
35
+ * Click at viewport coordinates. Coordinates are viewport-relative pixels in
36
+ * the session's own coordinate space — the same space the human interacts
37
+ * with, so a real view and a relay agree without scaling.
38
+ */
39
+ export interface BrowserClickRequest {
40
+ /** Viewport-relative x in CSS pixels. */
41
+ readonly x: number
42
+ /** Viewport-relative y in CSS pixels. */
43
+ readonly y: number
44
+ }
45
+
46
+ /**
47
+ * A run of coordinate clicks in one call.
48
+ *
49
+ * Each point is clicked in order with the same real CDP sequence the single click uses. Between
50
+ * points the call waits `intervalMs`, because a canvas that receives two presses inside one frame
51
+ * treats them as a double click — or drops the second entirely, which looks like a silently wrong
52
+ * board rather than an error.
53
+ */
54
+ export interface BrowserClickSequenceRequest {
55
+ /** Points to click, in order, in viewport CSS pixels. */
56
+ readonly points: readonly { readonly x: number; readonly y: number }[]
57
+ /** Milliseconds to wait between points; defaults to 40. */
58
+ readonly intervalMs?: number
59
+ }
60
+
61
+ /** Result of a click run: how many landed, and where it stopped if it did not finish. */
62
+ export interface BrowserClickSequenceResult {
63
+ /** Points that were clicked successfully. */
64
+ readonly clicked: number
65
+ /** Index of the point that failed, when one did. */
66
+ readonly failedAt?: number
67
+ /** Why that point failed. */
68
+ readonly error?: string
69
+ }
70
+
71
+ /** Type text into the focused element. */
72
+ export interface BrowserTypeRequest {
73
+ /** The text to insert. */
74
+ readonly text: string
75
+ }
76
+
77
+ /** Scroll the page: by pixel deltas, to an element, or to top/bottom. */
78
+ export interface BrowserScrollRequest {
79
+ /** Horizontal delta in CSS pixels. */
80
+ readonly deltaX?: number
81
+ /** Vertical delta in CSS pixels. */
82
+ readonly deltaY?: number
83
+ /** Scroll the given selector's element into view (top document; same-origin iframes reachable via execute). */
84
+ readonly selector?: string
85
+ /** Scroll to the top of the page. */
86
+ readonly toTop?: boolean
87
+ /** Scroll to the bottom of the page. */
88
+ readonly toBottom?: boolean
89
+ }
90
+
91
+ /** Press one named key (Enter, Tab, arrows, …). */
92
+ export interface BrowserKeyRequest {
93
+ /** Key name from the supported set (see the dsh_browser_key tool). */
94
+ readonly key: string
95
+ }
96
+
97
+ /**
98
+ * How to find one element for a targeted interaction (form controls, clicks,
99
+ * typing). `text` matches an element's own visible text — exact first, then
100
+ * contains, deepest element preferred (so a button inside a card wins over
101
+ * the card itself).
102
+ */
103
+ export interface BrowserElementTarget {
104
+ /** Locator kind. */
105
+ readonly by: 'css' | 'text' | 'xpath'
106
+ /** The CSS selector / visible text / XPath expression. */
107
+ readonly value: string
108
+ /** 0-based index of the match to use. Default 0. */
109
+ readonly index?: number
110
+ }
111
+
112
+ /** Set the value of one input/textarea/select/contenteditable. */
113
+ export interface BrowserSetValueRequest {
114
+ /** The element to set (css/text/xpath). */
115
+ readonly target: BrowserElementTarget
116
+ /** The value to set (string, number, or boolean). */
117
+ readonly value: string | number | boolean
118
+ /** Element-lookup budget in ms. Default 5000. */
119
+ readonly timeoutMs?: number
120
+ }
121
+
122
+ /** Result of a single setValue. */
123
+ export interface BrowserSetValueResult {
124
+ /** How the value was applied: input | textarea | select | contenteditable. */
125
+ readonly method: string
126
+ /** The value as applied. */
127
+ readonly value: string
128
+ }
129
+
130
+ /** Check/uncheck one checkbox or radio. */
131
+ export interface BrowserCheckRequest {
132
+ /** The element to toggle (css/text/xpath). */
133
+ readonly target: BrowserElementTarget
134
+ /** Desired state. Default true (check). */
135
+ readonly checked?: boolean
136
+ /** Element-lookup budget in ms. Default 5000. */
137
+ readonly timeoutMs?: number
138
+ }
139
+
140
+ /** Select one option of a `<select>`, by value, visible text, or index. */
141
+ export interface BrowserSelectRequest {
142
+ /** The `<select>` element (css/text/xpath). */
143
+ readonly target: BrowserElementTarget
144
+ /** Match the option by its value attribute. */
145
+ readonly optionValue?: string
146
+ /** Match the option by its visible text. */
147
+ readonly optionText?: string
148
+ /** Match the option by its 0-based index. */
149
+ readonly optionIndex?: number
150
+ /** Element-lookup budget in ms. Default 5000. */
151
+ readonly timeoutMs?: number
152
+ }
153
+
154
+ /** Result of a single select. */
155
+ export interface BrowserSelectResult {
156
+ /** The selected option's value attribute. */
157
+ readonly value: string
158
+ /** The selected option's visible text. */
159
+ readonly text: string
160
+ }
161
+
162
+ /** Clear one input/textarea/contenteditable (or uncheck a checkbox/radio). */
163
+ export interface BrowserClearRequest {
164
+ /** The element to clear (css/text/xpath). */
165
+ readonly target: BrowserElementTarget
166
+ /** Element-lookup budget in ms. Default 5000. */
167
+ readonly timeoutMs?: number
168
+ }
169
+
170
+ /** Read one element's current value (for verification). */
171
+ export interface BrowserGetValueRequest {
172
+ /** The element to read (css/text/xpath). */
173
+ readonly target: BrowserElementTarget
174
+ /** Element-lookup budget in ms. Default 5000. */
175
+ readonly timeoutMs?: number
176
+ }
177
+
178
+ /** Result of a getValue. */
179
+ export interface BrowserGetValueResult {
180
+ /** The element's value; null when the element has none (e.g. a checkbox). */
181
+ readonly value: string | null
182
+ /** For checkbox/radio: the checked state. */
183
+ readonly checked?: boolean
184
+ /** For `<select>`: the selected option's visible text. */
185
+ readonly selectedText?: string
186
+ }
187
+
188
+ /** One field of a scrape: a name plus a selector (optionally `selector@attr`). */
189
+ export interface BrowserScrapeField {
190
+ /** Output key. */
191
+ readonly name: string
192
+ /**
193
+ * CSS selector relative to each item; append `@attr` to take an attribute
194
+ * instead of text (`a@href` returns an absolute URL for links).
195
+ */
196
+ readonly selector: string
197
+ }
198
+
199
+ /** Extract structured data from repeated DOM items (static, CSP-safe). */
200
+ export interface BrowserScrapeRequest {
201
+ /** Required: CSS selector of each result container (e.g. `div.card`). */
202
+ readonly item: string
203
+ /** Field map: name -> selector[@attr]. */
204
+ readonly fields: readonly BrowserScrapeField[]
205
+ /** Wait budget for the item selector to appear. Default 5000. */
206
+ readonly timeoutMs?: number
207
+ }
208
+
209
+ /** Structured extraction result. */
210
+ export interface BrowserScrapeResult {
211
+ /** Number of items extracted. */
212
+ readonly count: number
213
+ /** One object per item; missing fields are null. */
214
+ readonly items: readonly Record<string, string | null>[]
215
+ }
216
+
217
+ /** One field of a batch form fill. Match by selector, or by name/label/placeholder. */
218
+ export interface BrowserFillField {
219
+ /** CSS selector; when present, candidates are scoped to it. */
220
+ readonly selector?: string
221
+ /** Match by the field's `name` attribute. */
222
+ readonly name?: string
223
+ /** Match by associated `<label>` text or `aria-label`. */
224
+ readonly label?: string
225
+ /** Match by `placeholder` text. */
226
+ readonly placeholder?: string
227
+ /** Field kind; defaults to text. */
228
+ readonly kind?: 'text' | 'textarea' | 'checkbox' | 'radio' | 'select'
229
+ /** Value to set: string, number, or boolean (checkbox/radio). For a
230
+ * multi-select or radio group, the option value (or visible text). */
231
+ readonly value: string | number | boolean
232
+ }
233
+
234
+ /** Batch form fill: set several fields, optionally submitting the form. */
235
+ export interface BrowserFillRequest {
236
+ /** The fields to fill, in order. */
237
+ readonly fields: readonly BrowserFillField[]
238
+ /** Submit the containing form after filling. Default false. */
239
+ readonly submit?: boolean
240
+ /** Per-field evaluation budget in ms. Default 30000. */
241
+ readonly timeoutMs?: number
242
+ }
243
+
244
+ /** One field's outcome in a batch fill. */
245
+ export interface BrowserFillFieldResult {
246
+ readonly ok: boolean
247
+ /** The field description matched (selector/name/label/placeholder). */
248
+ readonly target: string
249
+ /** How the value was applied: input | textarea | select | checkbox | radio | contenteditable. */
250
+ readonly method?: string
251
+ /** Error text when the field could not be filled. */
252
+ readonly error?: string
253
+ }
254
+
255
+ /** Outcome of a batch form fill. */
256
+ export interface BrowserFillResult {
257
+ /** Per-field outcomes, in request order. */
258
+ readonly fields: readonly BrowserFillFieldResult[]
259
+ /** Whether the containing form was submitted. */
260
+ readonly submitted: boolean
261
+ }
262
+
263
+ /** Wait request: poll until the page is ready (and optional URL/selector). */
264
+ export interface BrowserWaitRequest {
265
+ /** Maximum wait in ms. Default 30000. */
266
+ readonly timeoutMs?: number
267
+ /**
268
+ * Optional URL the top document must show (exact or prefix match). Pass the
269
+ * URL you navigated to — this distinguishes the NEW document from the old
270
+ * one still on screen while navigation is in flight.
271
+ */
272
+ readonly url?: string
273
+ /** Optional CSS selector that must exist (top document or same-origin frames). */
274
+ readonly selector?: string
275
+ /** Wait for the page load (readyState complete). Default true. */
276
+ readonly loaded?: boolean
277
+ }
278
+
279
+ /** Outcome of a wait: whether the condition was met before the budget ran out. */
280
+ export interface BrowserWaitResult {
281
+ readonly ready: boolean
282
+ /** Why the wait ended: 'condition met' or a short explanation of the miss. */
283
+ readonly reason: string
284
+ }
285
+
286
+ /**
287
+ * A screenshot of the current page state. `dataUrl` is a base64 data URL the
288
+ * tool layer renders directly; the live view itself never crosses the wire
289
+ * (the human watches the real view in the desktop shape).
290
+ */
291
+ export interface BrowserScreenshotResult {
292
+ /** Base64 data URL of the capture (PNG or JPEG per the request). */
293
+ readonly dataUrl: string
294
+ /** Pixel size of the image in `dataUrl`, when the capture was measured and scaled.
295
+ *
296
+ * Present when the request carried `maxWidth`/`maxHeight` and the layout metrics were
297
+ * readable: the scaling happens inside CDP through a clip, and without this the only way to
298
+ * learn what came back was to decode the data URL. Undefined means "not measured", which is
299
+ * also what an unscaled capture reports. */
300
+ readonly width?: number
301
+ readonly height?: number
302
+ /** File path the capture was also saved to, when the request asked for it. */
303
+ readonly path?: string
304
+ }
305
+
306
+ /** Screenshot capture options. */
307
+ export interface BrowserScreenshotRequest {
308
+ /** Capture the full scrollable page instead of the viewport. Default false. */
309
+ readonly fullPage?: boolean
310
+ /** Absolute file path to also save the image to (for vision-tool reads). */
311
+ readonly savePath?: string
312
+ /**
313
+ * Image format. Default 'png'. JPEG is only available on the self-hosted
314
+ * native capture path; the desktop-shell CDP fallback always returns PNG
315
+ * (CDP JPEG hangs on Electron 43 — a documented platform defect).
316
+ */
317
+ readonly format?: 'png' | 'jpeg'
318
+ /** JPEG quality 1-100 (default 80); ignored for PNG. */
319
+ readonly quality?: number
320
+ /** Downscale to fit within this width (aspect preserved). */
321
+ readonly maxWidth?: number
322
+ /** Downscale to fit within this height (aspect preserved). */
323
+ readonly maxHeight?: number
324
+ /**
325
+ * Capture only this region, in document CSS pixels. Used by the reference
326
+ * service for a masked visible-region snapshot; the tool layer does not
327
+ * expose it, so ordinary screenshots keep their existing behaviour.
328
+ */
329
+ readonly clip?: {
330
+ readonly x: number
331
+ readonly y: number
332
+ readonly width: number
333
+ readonly height: number
334
+ }
335
+ }
336
+
337
+ /** Download options: fetch a URL into a local file, keeping the session's cookies. */
338
+ export interface BrowserDownloadRequest {
339
+ /** The URL to download. */
340
+ readonly url: string
341
+ /** Absolute path of the file to write. */
342
+ readonly savePath: string
343
+ }
344
+
345
+ /** A serializable cookie, exported from or imported into the browser session. */
346
+ export interface ExportedCookie {
347
+ /** Cookie URL (scheme + domain + path), as accepted by cookies.set. */
348
+ readonly url: string
349
+ readonly name: string
350
+ readonly value: string
351
+ readonly domain?: string
352
+ readonly path?: string
353
+ readonly secure?: boolean
354
+ readonly httpOnly?: boolean
355
+ readonly expirationDate?: number
356
+ }
357
+
358
+ /**
359
+ * Execute arbitrary JavaScript in the session's page context. This is the
360
+ * primary interaction path — DOM-referenced, not screen-coordinate-based:
361
+ * focus/input/click go through the page's own JS (native setters for
362
+ * framework-controlled inputs), matching how a human-driven agent operates.
363
+ */
364
+ export interface BrowserExecuteRequest {
365
+ /** The JavaScript expression to evaluate in the page context. */
366
+ readonly script: string
367
+ /** Optional arguments injected into the script scope as `arguments[0..n]`. */
368
+ readonly args?: readonly unknown[]
369
+ /** Evaluation budget in ms; a wedged page rejects with a timeout. Default 30000. */
370
+ readonly timeoutMs?: number
371
+ }
372
+
373
+ /**
374
+ * Fixed page operations implemented by the provider. Strings are serialized as data.
375
+ * Arbitrary JavaScript is handled only by BrowserExecuteRequest.
376
+ */
377
+ export type BrowserPageOperationRequest =
378
+ | { readonly operation: 'install' }
379
+ | { readonly operation: 'probe'; readonly method: BrowserProbeMethod; readonly args?: readonly unknown[] }
380
+ | { readonly operation: 'text'; readonly text: string }
381
+ | { readonly operation: 'url' }
382
+ | { readonly operation: 'pulse' }
383
+ | { readonly operation: 'fetch'; readonly url: string; readonly init: { readonly method?: string; readonly headers?: Readonly<Record<string, string>>; readonly body?: string } }
384
+ | { readonly operation: 'drag'; readonly from: { x: number; y: number }; readonly to: { x: number; y: number }; readonly steps: number }
385
+ | { readonly operation: 'upload'; readonly target: { by: 'css' | 'text' | 'xpath'; value: string }; readonly file: { name: string; mime: string; base64: string } }
386
+
387
+ /** Provider-owned probe operations; JavaScript properties such as constructor are excluded. */
388
+ export type BrowserProbeMethod = 'read' | 'clear' | 'settle' | 'find' | 'overlayAt' | 'summary'
389
+ | 'findText' | 'hoverAt' | 'setDialogPolicy' | 'dialogStatus' | 'networkCursor' | 'dataSources'
390
+
391
+ /**
392
+ * Result of an execute. Mirrors CDP `Runtime.evaluate` semantics: either a
393
+ * value (by value, not by reference) or the exception thrown.
394
+ */
395
+ export type BrowserExecuteResult =
396
+ | { readonly ok: true; readonly value: unknown }
397
+ | { readonly ok: false; readonly exception: string }
398
+
399
+ /**
400
+ * One interactive element in a snapshot, with a stable reference number the
401
+ * tool layer (and the model) can cite to target the element.
402
+ */
403
+ export interface BrowserSnapshotElement {
404
+ /** 1-based reference number, stable for the lifetime of one snapshot. */
405
+ readonly ref: number
406
+ /** Element kind: 'input' | 'button' | 'link' | 'textarea' | 'select' | 'checkbox' | 'other'. */
407
+ readonly kind: string
408
+ /** Text content or placeholder/label, truncated for the snapshot. */
409
+ readonly label: string
410
+ /** Best-effort CSS selector; may be empty when none is derivable. */
411
+ readonly selector: string
412
+ /** Viewport-relative center, for coordinate fallbacks. */
413
+ readonly x: number
414
+ readonly y: number
415
+ /**
416
+ * True when the element lives inside an (same-origin) iframe: coordinates
417
+ * are still top-document, but DOM selectors are frame-scoped — reach the
418
+ * element via `iframe.contentDocument` in dsh_browser_execute.
419
+ */
420
+ readonly frame?: boolean
421
+ }
422
+
423
+ /**
424
+ * AI-friendly page snapshot: a compact, numbered inventory of interactive
425
+ * elements plus page facts. Not raw HTML — the model dialogues with this.
426
+ */
427
+ export interface BrowserSnapshotResult {
428
+ /** Final page URL. */
429
+ readonly url: string
430
+ /** Page title, if any. */
431
+ readonly title?: string
432
+ /** Numbered interactive elements. */
433
+ readonly elements: readonly BrowserSnapshotElement[]
434
+ /** True when the snapshot was truncated (element cap reached). */
435
+ readonly truncated: boolean
436
+ /** Human-verification challenge blocking the page, when one is detected. */
437
+ readonly challenge?: BrowserChallenge
438
+ /**
439
+ * True when this is a blank page — no document to read, nothing to drive.
440
+ *
441
+ * Zero elements means two very different things: a page that genuinely has nothing interactive,
442
+ * and a browser that has not opened anything at all. Without this flag they look identical, so a
443
+ * caller can act on a blank page and get a success value back — reported as issue #37, where every
444
+ * tool after a carrier swap answered against `about:blank` while appearing to work.
445
+ *
446
+ * Set for `about:blank` and for a view that has never navigated. A caller seeing it should treat
447
+ * the page as absent, not as empty.
448
+ */
449
+ readonly blank?: boolean
450
+ /** A sentence a caller can show instead of reporting an empty page as a successful read. */
451
+ readonly note?: string
452
+ /**
453
+ * True when the page draws its interface on a canvas, so no DOM element exists to collect.
454
+ *
455
+ * Distinct from `blank`: the page is fully rendered and interactive, just not as elements. A
456
+ * caller must switch to a screenshot and coordinate input rather than conclude the page is empty.
457
+ */
458
+ readonly canvas?: boolean
459
+ }
460
+
461
+ /**
462
+ * One node of the accessibility tree, with a stable reference number the
463
+ * model can cite. Roles/names prefer Chrome's `computedRole`/`computedName`
464
+ * with tag/attribute inference as fallback; coordinates are top-document
465
+ * viewport-relative so the node can also be driven by click/type.
466
+ */
467
+ export interface BrowserA11yNode {
468
+ /** 1-based reference number, stable for the lifetime of one a11y call. */
469
+ readonly ref: number
470
+ /** ARIA role: button | link | textbox | checkbox | radio | combobox | … */
471
+ readonly role: string
472
+ /** Accessible name (aria-label, label text, placeholder, own text, …). */
473
+ readonly name: string
474
+ /**
475
+ * Current value of input-like nodes; absent when the node has none.
476
+ *
477
+ * The provider produces `null` for "not applicable" and the tool layer drops it, so absence
478
+ * and null mean the same thing here — which is what the output schema declares (`string`,
479
+ * not nullable). Saying `string | null` described the provider's internal shape rather than
480
+ * the contract, and the two disagreed at every call.
481
+ */
482
+ readonly value?: string
483
+ /** ARIA/DOM states: enabled/disabled/checked/unchecked/expanded/… */
484
+ readonly states: readonly string[]
485
+ /** DOM depth (within its document), for reconstructing the tree. */
486
+ readonly depth: number
487
+ /** Element tag name (lowercase). */
488
+ readonly tag: string
489
+ /**
490
+ * A CSS selector for this node, when one can be derived from its id or name.
491
+ *
492
+ * Empty for the many elements that have neither. Present because a role and a name are not
493
+ * always enough to target a node: `{by: 'text'}` matches an accessible name only loosely,
494
+ * and this is what lets a caller point at the exact element it was shown.
495
+ */
496
+ readonly selector: string
497
+ /** Viewport-relative center, for coordinate fallbacks. */
498
+ readonly x: number
499
+ readonly y: number
500
+ /** True when the node lives inside a same-origin iframe. */
501
+ readonly frame?: boolean
502
+ }
503
+
504
+ /** A11y tree request: what to include and how many nodes to return. */
505
+ export interface BrowserA11yRequest {
506
+ /** Include hidden elements (display:none, hidden, aria-hidden). Default false. */
507
+ readonly includeHidden?: boolean
508
+ /** Maximum nodes returned. Default 500; clamped to 10-5000. */
509
+ readonly maxNodes?: number
510
+ }
511
+
512
+ /** The page's accessibility tree, flattened into a numbered node list. */
513
+ export interface BrowserA11yResult {
514
+ /** Final page URL. */
515
+ readonly url: string
516
+ /** Page title, if any. */
517
+ readonly title?: string
518
+ /** Number of nodes returned. */
519
+ readonly count: number
520
+ /** Flattened a11y nodes (depth restores the tree). */
521
+ readonly nodes: readonly BrowserA11yNode[]
522
+ /** True when the result was truncated (maxNodes reached). */
523
+ readonly truncated: boolean
524
+ }
525
+
526
+ /**
527
+ * A detected human-verification (bot-detection / CAPTCHA) challenge blocking
528
+ * the page. Detection is best-effort and marker-based; a clean result is not a
529
+ * guarantee that no challenge exists.
530
+ */
531
+ export interface BrowserChallenge {
532
+ /** Whether a challenge currently blocks the page. */
533
+ readonly blocked: boolean
534
+ /** Machine-readable kind, e.g. cloudflare | hcaptcha | recaptcha | turnstile | slider | access-denied | ip-block. */
535
+ readonly kind?: string
536
+ /** Short human-readable description, e.g. 'Cloudflare "Just a moment" interstitial'. */
537
+ readonly reason?: string
538
+ /** What to do about it: takeover (human verification), wait, retry, or environment (network refused). */
539
+ readonly recovery?: 'takeover' | 'wait' | 'retry' | 'environment'
540
+ /** HTTP status of the main document, when known. */
541
+ readonly status?: number
542
+ }
543
+
544
+ /**
545
+ * Content fetch formats. `html` is the raw DOM; `markdown` is a structured
546
+ * reading view; `txt` is plain text (smallest); `json` is structured data.
547
+ */
548
+ export type BrowserContentFormat = 'html' | 'markdown' | 'txt' | 'json'
549
+
550
+ /** Content fetch request: format, optional selector scoping, and caps. */
551
+ export interface BrowserContentRequest {
552
+ /** Desired format. */
553
+ readonly format: BrowserContentFormat
554
+ /** Optional CSS selector limiting the fetch to one region (e.g. `#main`). */
555
+ readonly selector?: string
556
+ /** Maximum characters of the returned content. */
557
+ readonly maxChars?: number
558
+ /** Evaluation timeout in ms; the fetch aborts after this. Default 30000. */
559
+ readonly timeoutMs?: number
560
+ }
561
+
562
+ /** A fetched page content in the requested format. */
563
+ export interface BrowserContentResult {
564
+ /** The content in the requested format, capped at `maxChars`. */
565
+ readonly content: string
566
+ /** True when the content was truncated. */
567
+ readonly truncated: boolean
568
+ }
569
+
570
+ /**
571
+ * A tab inside a browser session. Tabs share the session's profile/cookies
572
+ * and are switchable without losing state.
573
+ */
574
+ export interface BrowserTab {
575
+ /** Stable tab id within the session. */
576
+ readonly id: import('./handles.ts').BrowserTabWireId
577
+ /** Current URL, or empty for a blank tab. */
578
+ readonly url: string
579
+ /** Page title, if any. */
580
+ readonly title?: string
581
+ /** Whether this tab is the active one. */
582
+ readonly active: boolean
583
+ }
584
+
585
+ /**
586
+ * One passive preview frame: an encoded image plus its dimensions.
587
+ *
588
+ * The image is a data URL so it travels the existing JSON seam unchanged; the media type is part of
589
+ * the URL rather than a separate field because every consumer needs them together.
590
+ */
591
+ export interface BrowserPreviewFrame {
592
+ readonly dataUrl: string
593
+ readonly width?: number
594
+ readonly height?: number
595
+ }
596
+
597
+ /** One page a carrier holds, whether or not this plugin created it. */
598
+ export interface CarrierPage {
599
+ /** Canonical owner/session/tab identity used to address the page. */
600
+ readonly id: import('./handles.ts').BrowserTabWireId
601
+ readonly url: string
602
+ readonly title?: string
603
+ }
604
+
605
+ /**
606
+ * Why a carrier reported that it can no longer be used.
607
+ *
608
+ * Two different failures reach the same fallback, and saying which one is the difference between a
609
+ * message a user can act on and one that misleads them:
610
+ *
611
+ * - `shell-exited`: the shell process behind the carrier is gone. Its published endpoint stops
612
+ * being refreshed, which is the condition the fallback was originally written for.
613
+ * - `panel-unusable`: the shell is alive and answering, but its sidebar panel cannot provide a page
614
+ * — on a shell that renders that panel as an iframe there is no webContents and no CDP endpoint,
615
+ * so the carrier is undrivable rather than merely unready.
616
+ *
617
+ * The fallback announced the first of these unconditionally, so a `panel-unusable` fallback told
618
+ * the user their desktop shell had exited while it was running normally. Reported as such.
619
+ */
620
+ export type CarrierLossReason = 'shell-exited' | 'panel-unusable'
621
+
622
+ /** Request to open a URL: into the active tab or a new tab. */export interface BrowserOpenRequest {
623
+ /** The URL to open. */
624
+ readonly url: string
625
+ /** Open in a new tab (parallel). Default false (reuse the active tab). */
626
+ readonly newTab?: boolean
627
+ }
628
+
629
+ /**
630
+ * A browser-capable backend. Registered with `ctx.browser.registerBrowserProvider`.
631
+ * `id` is a stable string, unique across the seam.
632
+ */
633
+ export interface BrowserProvider {
634
+ readonly id: string
635
+ /** Cheap local usability check; must not make network calls. */
636
+ available(): boolean
637
+ /**
638
+ * Open a new session. The provider mints the session id and prepares its
639
+ * backing surface (a view, a headless page, and so on). Sessions are isolated from
640
+ * each other in what they OWN — tabs, the active tab, history, the view — so one
641
+ * session must not be visible to any other session's caller.
642
+ *
643
+ * That isolation stops at the browser's own state, and is not meant to go further:
644
+ * cookies, logins and site storage are deliberately shared by every session, because
645
+ * every session drives the same browser and "sign in once, use it everywhere" is the
646
+ * point of using a real one. Reads that hand that state to a caller (see
647
+ * `flushAuth`) are scoped to the page in question, which is least exposure rather
648
+ * than a claim that the jar is per-session.
649
+ * @param label - optional human-readable label (e.g. the calling DSH task
650
+ * id) the provider may surface on the visible surface (window title) so a
651
+ * human can tell which task's page is currently shown.
652
+ */
653
+ open(label?: string): Promise<BrowserSessionId>
654
+ /** Bind an existing carrier page to this session without navigating or creating a page. */
655
+ bindPage?(session: BrowserSessionId, pageId: import('./handles.ts').BrowserTabWireId): Promise<void>
656
+ /** Open a URL, optionally in a new tab. Honor `signal` for cancellation. */
657
+ openUrl(session: BrowserSessionId, request: BrowserOpenRequest, signal?: AbortSignal): Promise<void>
658
+ /** List the session's tabs. */
659
+ listTabs(session: BrowserSessionId): Promise<readonly BrowserTab[]>
660
+ /** Switch to a tab by id. Unknown id -> `BROWSER_TAB_UNKNOWN`. */
661
+ switchTab(session: BrowserSessionId, tabId: import('./handles.ts').BrowserTabWireId): Promise<void>
662
+ /** Close one tab. Closing the active tab activates the next. */
663
+ closeTab(session: BrowserSessionId, tabId: import('./handles.ts').BrowserTabWireId): Promise<void>
664
+ /** Close every tab and reset the session's state. */
665
+ reset(session: BrowserSessionId): Promise<void>
666
+ /** Navigate the active tab. Honor `signal` for cancellation. */
667
+ navigate(session: BrowserSessionId, request: BrowserNavigateRequest, signal?: AbortSignal): Promise<void>
668
+ /** Execute JS in the active tab's page context. */
669
+ execute(session: BrowserSessionId, request: BrowserExecuteRequest, signal?: AbortSignal): Promise<BrowserExecuteResult>
670
+
671
+ /** Execute one fixed browser operation without granting arbitrary page scripting. */
672
+ pageOperation?(session: BrowserSessionId, request: BrowserPageOperationRequest, signal?: AbortSignal): Promise<BrowserExecuteResult>
673
+ /** Wait until the page is ready (and optional URL/selector match). Honor `signal` for cancellation. */
674
+ waitFor(session: BrowserSessionId, request: BrowserWaitRequest, signal?: AbortSignal): Promise<BrowserWaitResult>
675
+ /** Produce an AI-friendly snapshot of the active tab. */
676
+ snapshot(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserSnapshotResult>
677
+ /** Read the active tab's accessibility tree (semantic, interactive nodes). */
678
+ a11y(session: BrowserSessionId, request: BrowserA11yRequest, signal?: AbortSignal): Promise<BrowserA11yResult>
679
+ /** Reload the active tab. Honor `signal` for cancellation. */
680
+ reload(session: BrowserSessionId, signal?: AbortSignal): Promise<void>
681
+ /** Check whether a human-verification challenge is blocking the active tab. */
682
+ detectChallenge(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserChallenge>
683
+ /** Fetch page content in a requested format. */
684
+ content(session: BrowserSessionId, request: BrowserContentRequest, signal?: AbortSignal): Promise<BrowserContentResult>
685
+ /**
686
+ * Click at viewport coordinates, or at a located element's center when the
687
+ * request carries a `target`. Honor `signal` for cancellation.
688
+ */
689
+ click(session: BrowserSessionId, request: BrowserClickRequest | { readonly target: BrowserElementTarget }, signal?: AbortSignal): Promise<void>
690
+ /**
691
+ * Click several points in order, in one round trip.
692
+ *
693
+ * Exists because a canvas page accepts only genuine input: one click per call meant two calls
694
+ * per cell on a 9x9 board. Stops at the first point that fails rather than pressing through a
695
+ * page that has moved under it, and reports how far it got.
696
+ * @param session - the session to click in.
697
+ * @param request - the points and the interval between them.
698
+ * @param signal - cancellation between points.
699
+ */
700
+ clickSequence(session: BrowserSessionId, request: BrowserClickSequenceRequest, signal?: AbortSignal): Promise<BrowserClickSequenceResult>
701
+ /**
702
+ * Type into the focused element, or focus a located element first when the
703
+ * request carries a `target`. Honor `signal` for cancellation.
704
+ */
705
+ type(session: BrowserSessionId, request: BrowserTypeRequest | { readonly target: BrowserElementTarget }, signal?: AbortSignal): Promise<void>
706
+ /** Set one element's value (native setter + input/change events). */
707
+ setValue(session: BrowserSessionId, request: BrowserSetValueRequest, signal?: AbortSignal): Promise<BrowserSetValueResult>
708
+ /** Check or uncheck one checkbox/radio. */
709
+ check(session: BrowserSessionId, request: BrowserCheckRequest, signal?: AbortSignal): Promise<{ readonly checked: boolean }>
710
+ /** Select one option of a `<select>`. */
711
+ selectOption(session: BrowserSessionId, request: BrowserSelectRequest, signal?: AbortSignal): Promise<BrowserSelectResult>
712
+ /** Clear one input/textarea/contenteditable (or uncheck). */
713
+ clearField(session: BrowserSessionId, request: BrowserClearRequest, signal?: AbortSignal): Promise<{ readonly cleared: boolean }>
714
+ /** Read one element's current value (for verification). */
715
+ getValue(session: BrowserSessionId, request: BrowserGetValueRequest, signal?: AbortSignal): Promise<BrowserGetValueResult>
716
+ /** Extract structured data from repeated DOM items (static CSS, CSP-safe). */
717
+ scrape(session: BrowserSessionId, request: BrowserScrapeRequest, signal?: AbortSignal): Promise<BrowserScrapeResult>
718
+ /** Scroll the active tab. Honor `signal` for cancellation. */
719
+ scroll(session: BrowserSessionId, request: BrowserScrollRequest, signal?: AbortSignal): Promise<void>
720
+ /** Go back in the active tab's history. Honor `signal` for cancellation. */
721
+ back(session: BrowserSessionId, signal?: AbortSignal): Promise<void>
722
+ /** Go forward in the active tab's history. Honor `signal` for cancellation. */
723
+ forward(session: BrowserSessionId, signal?: AbortSignal): Promise<void>
724
+ /** Press one named key (Enter/Tab/arrows/…). Honor `signal` for cancellation. */
725
+ key(session: BrowserSessionId, request: BrowserKeyRequest, signal?: AbortSignal): Promise<void>
726
+ /** Fill a form's fields in one batch. Honor `signal` for cancellation. */
727
+ fillForm(session: BrowserSessionId, request: BrowserFillRequest, signal?: AbortSignal): Promise<BrowserFillResult>
728
+ /** Capture the current page. Honor `signal` for cancellation. */
729
+ screenshot(session: BrowserSessionId, request?: BrowserScreenshotRequest, signal?: AbortSignal): Promise<BrowserScreenshotResult>
730
+ /**
731
+ * Capture the active page WITHOUT presenting it, for a remote live view (issue #34).
732
+ *
733
+ * Optional, and it must stay optional: a third-party provider that cannot do this simply does not
734
+ * offer watching, while every existing tool keeps working. That is the design's requirement, not
735
+ * a convenience — a mandatory member would make every provider implement a feature most never
736
+ * need.
737
+ *
738
+ * The contract is narrower than {@link screenshot} in every direction: viewport only, no save
739
+ * path, no full page, and no side effects on what the host displays. A provider that would have to
740
+ * focus, restore, expand or recreate anything to produce a frame must throw
741
+ * BROWSER_PREVIEW_UNAVAILABLE instead — the viewer shows a paused state, it does not rearrange the
742
+ * host's screen.
743
+ */
744
+ capturePassive?(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserPreviewFrame>
745
+ /**
746
+ * The sessions a viewer may watch. Only meaningful alongside {@link capturePassive}.
747
+ *
748
+ * Exists because the provider names its sessions and the browser page cannot know one; served as
749
+ * ids only, so the panel can address a session without being told what is in it.
750
+ */
751
+ watchableSessions?(): readonly BrowserSessionId[]
752
+ /** Download a URL to a local file. Honor `signal` for cancellation. */
753
+ download(session: BrowserSessionId, request: BrowserDownloadRequest, signal?: AbortSignal): Promise<{ readonly path: string }>
754
+ /** Export the session's cookies (login state). */
755
+ flushAuth(session: BrowserSessionId): Promise<readonly ExportedCookie[]>
756
+ /** Import cookies into the session (restore login state). */
757
+ restoreAuth(session: BrowserSessionId, cookies: readonly ExportedCookie[]): Promise<number>
758
+ /** Return the session's chronological operation log. */
759
+ history(session: BrowserSessionId): Promise<readonly BrowserHistoryEntry[]>
760
+ /**
761
+ * Persisted visits, newest first: what survives the browser process, so a
762
+ * human or an Agent can find a page again after the interface was closed.
763
+ * @param options - result cap and an optional hostname filter.
764
+ * @returns the retained visits (empty when history is disabled).
765
+ */
766
+ visited(options?: { readonly limit?: number; readonly domain?: string }): readonly VisitedPage[]
767
+ /**
768
+ * Optional: whether a session is still live. A session can end outside the
769
+ * tool layer — the human closed the browser window — so a cached id must be
770
+ * checked before it is reused. Providers that never end a session on their own
771
+ * can omit this, and callers treat absence as "still live".
772
+ * @param session - the session id to test.
773
+ */
774
+ exists?(session: BrowserSessionId): boolean
775
+ /** Replay one recorded operation by sequence number. */
776
+ replay(session: BrowserSessionId, seq: number): Promise<void>
777
+ /** Close the session and destroy its backing surface. Idempotent. */
778
+ close(session: BrowserSessionId): Promise<void>
779
+ }
780
+
781
+ /**
782
+ * One visited page in the persistent browsing history — the durable record that
783
+ * outlives sessions, unlike {@link BrowserHistoryEntry}, which is a
784
+ * session-scoped operation log (navigate/click/type/…).
785
+ */
786
+ export interface VisitedPage {
787
+ /** Epoch milliseconds when the visit was recorded. */
788
+ readonly at: number
789
+ /** Absolute URL of the visited document. */
790
+ readonly url: string
791
+ /** Document title at visit time, when the page exposed one. */
792
+ readonly title?: string
793
+ /** Session/task label that drove the visit, when the provider knows it. */
794
+ readonly session?: string
795
+ }
796
+
797
+ /** One recorded browser operation, in chronological order (seq 1, 2, 3…). */
798
+ export interface BrowserHistoryEntry {
799
+ /** Monotonic sequence number within the session. */
800
+ readonly seq: number
801
+ /** The operation name. Replayable: navigate | execute | click | type.
802
+ * Also recorded (non-replayable): fill | download | flushAuth | restoreAuth. */
803
+ readonly action: string
804
+ /** The operation's arguments. */
805
+ readonly params: Record<string, unknown>
806
+ /** Whether the operation succeeded. */
807
+ readonly ok: boolean
808
+ /** Truncated result text, when the operation returned one. */
809
+ readonly result?: string
810
+ /** Error text, when the operation failed. */
811
+ readonly error?: string
812
+ /** Epoch millis of the operation. */
813
+ readonly at: number
814
+ }
815
+
816
+ /**
817
+ * Typed browser error with a machine-routable, open-string `code` and chained
818
+ * `cause`. Consumers must tolerate provider-specific codes. Shared codes cover
819
+ * unavailable, missing, unusable, ambiguous, or duplicate providers, unknown
820
+ * or closed sessions, cancellation, and provider failure; a provider adds its
821
+ * own (e.g. `BROWSER_CDP_ATTACH_FAILED`).
822
+ */
823
+ export class BrowserError extends HarnessError {}
824
+
825
+ /** What a browser carrier can do for a tool call; tools ask for one capability instead of naming carriers. */
826
+ export interface CarrierCapabilities {
827
+ /** A live Chrome DevTools Protocol session drives the page. */
828
+ readonly cdp: boolean
829
+ readonly liveSnapshot: boolean
830
+ readonly interaction: boolean
831
+ readonly screenshot: boolean
832
+ readonly nativeTabs: boolean
833
+ readonly backgroundRender: boolean
834
+ readonly takeover: boolean
835
+ readonly referenceCapture: boolean
836
+ }
837
+
838
+ export type CarrierCapability = keyof CarrierCapabilities
839
+
840
+ /** A CDP-backed page: the plugin browser, an attached system browser or the desktop sidebar. */
841
+ export const CDP_CARRIER_CAPABILITIES: CarrierCapabilities = Object.freeze({
842
+ cdp: true, liveSnapshot: true, interaction: true, screenshot: true,
843
+ nativeTabs: true, backgroundRender: true, takeover: true, referenceCapture: true,
844
+ })
845
+
846
+ /** The Web sidebar's iframe: it can be navigated, nothing else. */
847
+ export const WEB_PANEL_CAPABILITIES: CarrierCapabilities = Object.freeze({
848
+ cdp: false, liveSnapshot: false, interaction: false, screenshot: false,
849
+ nativeTabs: false, backgroundRender: false, takeover: false, referenceCapture: false,
850
+ })
851
+
852
+ /** A tool needed a capability the current carrier lacks. */
853
+ export class CarrierCapabilityError extends BrowserError {
854
+ readonly capability: CarrierCapability
855
+ constructor(capability: CarrierCapability, message: string) {
856
+ super(message, 'BROWSER_CARRIER_CAPABILITY_UNAVAILABLE')
857
+ this.name = 'CarrierCapabilityError'
858
+ this.capability = capability
859
+ }
860
+ }
861
+
862
+ /**
863
+ * Refuse an operation the carrier cannot perform.
864
+ * @param capabilities - the current carrier's capabilities.
865
+ * @param required - the one capability the operation needs.
866
+ * @param guidance - the refusal the model sees: what is missing and which carrier to switch to.
867
+ */
868
+ export function assertCapability(capabilities: CarrierCapabilities, required: CarrierCapability, guidance: string): void {
869
+ if (!capabilities[required]) throw new CarrierCapabilityError(required, guidance)
870
+ }