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,474 +0,0 @@
1
- /**
2
- * The page-side probe: one script that makes a page observable without touching the host.
3
- *
4
- * WHY THIS EXISTS
5
- * Three capabilities the model needs are not tools here yet: what the console said, which network
6
- * responses arrived, and what happened to a JavaScript dialog. All three live *inside* the page, and
7
- * a dialog blocks the page until someone answers it — which is why a `confirm()` used to hang a whole
8
- * tool call with no explanation.
9
- *
10
- * The obvious implementation is CDP event capture (`Runtime.consoleAPICalled`, `Network.*`,
11
- * `Page.javascriptDialogOpening`) inside the host. That would mean a new capability in all three
12
- * carriers — the self-hosted child, the driven Chrome and the sidebar bridge — plus a protocol
13
- * version for the bridge. This probe instead installs itself with the `execute` path every carrier
14
- * already has, so it works everywhere on day one and cannot drift per carrier.
15
- *
16
- * What it costs, stated plainly:
17
- * - `console` and `network` see what the PAGE can see. A response that never reached `fetch`/`XHR`
18
- * (a document navigation, an `<img>` failure the browser handled internally) appears only as a
19
- * resource-timing entry, with no status code. CDP would know more.
20
- * - Dialog capture works by replacing `window.alert/confirm/prompt` BEFORE they are called. A dialog
21
- * produced by the browser itself (`beforeunload`, HTTP auth, permission prompts) is not covered.
22
- * - It is an override, so a page that captured `window.fetch` earlier keeps its own copy. Installed
23
- * at first use, which is early enough for every ordinary page and honest about the rest.
24
- *
25
- * Idempotent by version: installing twice keeps the buffers that already exist.
26
- * @module dsh-browser/tool-browser/page-probe
27
- */
28
-
29
- import type { BrowserPageOperationRequest, BrowserProbeMethod } from '../browser/types.ts'
30
-
31
- /** Bumped when the probe's shape changes; an older probe is replaced rather than trusted. */
32
- export const PROBE_VERSION = 5
33
-
34
- /** Where the probe keeps itself, and the only global it adds. */
35
- const PROBE_KEY = '__dshProbe'
36
-
37
- /**
38
- * The installer, as one expression that returns the installed version.
39
- *
40
- * Written as a string because it runs in the page, not here. Keep it dependency-free and ES5-safe:
41
- * a page may be older than the harness.
42
- */
43
- export const PROBE_INSTALL_SCRIPT = `(() => {
44
- const KEY = ${JSON.stringify(PROBE_KEY)}
45
- const VERSION = ${PROBE_VERSION}
46
- const previous = globalThis[KEY]
47
- if (previous && previous.version === VERSION) return VERSION
48
- if (previous) {
49
- if (typeof previous.dispose !== 'function') throw new Error('reload this page to replace the older browser probe')
50
- previous.dispose()
51
- }
52
- const restore = []
53
- const replace = (target, key, value) => {
54
- const original = target[key]
55
- target[key] = value
56
- restore.push(() => { if (target[key] === value) target[key] = original })
57
- }
58
-
59
- const state = {
60
- version: VERSION,
61
- startedAt: Date.now(),
62
- console: [],
63
- network: [],
64
- dialogs: [],
65
- dialogPolicy: 'native',
66
- networkSequence: 0,
67
- pending: 0,
68
- lastNetworkAt: Date.now(),
69
- lastMutationAt: Date.now(),
70
- }
71
- const cap = (list, item, limit) => { list.push(item); if (list.length > limit) list.splice(0, list.length - limit) }
72
- const asText = (value) => {
73
- try { return typeof value === 'string' ? value : JSON.stringify(value) } catch (error) { return String(value) }
74
- }
75
- const short = (value, limit) => { const text = String(value == null ? '' : value); return text.length > limit ? text.slice(0, limit) + '…' : text }
76
-
77
- for (const level of ['log', 'info', 'warn', 'error', 'debug']) {
78
- const original = console[level]
79
- if (typeof original !== 'function') continue
80
- replace(console, level, function () {
81
- const parts = []
82
- for (let i = 0; i < arguments.length; i += 1) parts.push(asText(arguments[i]))
83
- cap(state.console, { at: Date.now(), level: level, text: short(parts.join(' '), 500) }, 200)
84
- return original.apply(this, arguments)
85
- })
86
- }
87
-
88
- const note = (entry) => { state.lastNetworkAt = Date.now(); entry.receivedAt = state.lastNetworkAt; entry.sequence = ++state.networkSequence; cap(state.network, entry, 300) }
89
- const nativeFetch = globalThis.fetch
90
- if (typeof nativeFetch === 'function') {
91
- replace(globalThis, 'fetch', function (input, init) {
92
- const url = typeof input === 'string' ? input : (input && input.url) || String(input)
93
- const method = String((init && init.method) || (input && input.method) || 'GET').toUpperCase()
94
- const started = Date.now()
95
- state.pending += 1
96
- const settle = (status) => {
97
- state.pending = Math.max(0, state.pending - 1)
98
- note({ at: started, kind: 'fetch', method: method, url: short(url, 300), status: status, ms: Date.now() - started })
99
- }
100
- return nativeFetch.apply(this, arguments).then(
101
- (response) => { settle(response.status); return response },
102
- (error) => { settle(0); throw error },
103
- )
104
- })
105
- }
106
-
107
- const XHR = globalThis.XMLHttpRequest
108
- if (XHR && XHR.prototype && typeof XHR.prototype.send === 'function') {
109
- const open = XHR.prototype.open
110
- const send = XHR.prototype.send
111
- replace(XHR.prototype, 'open', function (method, url) {
112
- this.__dshNetwork = { method: String(method || 'GET').toUpperCase(), url: String(url || ''), at: Date.now() }
113
- return open.apply(this, arguments)
114
- })
115
- replace(XHR.prototype, 'send', function () {
116
- const meta = this.__dshNetwork || { method: 'GET', url: '', at: Date.now() }
117
- state.pending += 1
118
- const done = () => {
119
- state.pending = Math.max(0, state.pending - 1)
120
- note({ at: meta.at, kind: 'xhr', method: meta.method, url: short(meta.url, 300), status: this.status || 0, ms: Date.now() - meta.at })
121
- this.removeEventListener('loadend', done)
122
- }
123
- this.addEventListener('loadend', done)
124
- return send.apply(this, arguments)
125
- })
126
- }
127
-
128
- if (typeof PerformanceObserver === 'function') {
129
- try {
130
- const seen = new Set()
131
- const observer = new PerformanceObserver((list) => {
132
- const entries = list.getEntries()
133
- for (let i = 0; i < entries.length; i += 1) {
134
- const entry = entries[i]
135
- const key = entry.name + '|' + entry.startTime
136
- if (seen.has(key)) continue
137
- seen.add(key)
138
- note({ at: Math.round((performance.timeOrigin || Date.now()) + entry.startTime), kind: 'resource', method: 'GET', url: short(entry.name, 300), status: 0, ms: Math.round(entry.duration), bytes: entry.transferSize || 0 })
139
- }
140
- })
141
- observer.observe({ type: 'resource', buffered: true })
142
- restore.push(() => observer.disconnect())
143
- } catch (error) { /* a page with no resource timing still has fetch and XHR */ }
144
- }
145
-
146
- const nativeDialogs = {}
147
- const dialogWrappers = {}
148
- for (const kind of ['alert', 'confirm', 'prompt']) {
149
- const original = globalThis[kind]
150
- if (typeof original !== 'function') continue
151
- nativeDialogs[kind] = original
152
- const wrapper = function (message, value) {
153
- const accept = state.dialogPolicy === 'accept'
154
- cap(state.dialogs, { at: Date.now(), kind: kind, message: short(message, 300), policy: state.dialogPolicy, answered: accept ? 'accepted' : 'dismissed' }, 50)
155
- if (!accept) return kind === 'confirm' ? false : kind === 'prompt' ? null : undefined
156
- return kind === 'prompt' ? String(value == null ? '' : value) : kind === 'confirm' ? true : undefined
157
- }
158
- dialogWrappers[kind] = wrapper
159
- restore.push(() => { if (globalThis[kind] === wrapper) globalThis[kind] = nativeDialogs[kind] })
160
- }
161
-
162
- try {
163
- const observer = new MutationObserver(() => { state.lastMutationAt = Date.now() })
164
- observer.observe(document.documentElement || document, { subtree: true, childList: true, attributes: true })
165
- restore.push(() => observer.disconnect())
166
- } catch (error) { /* no observer: quiet time falls back to network only */ }
167
-
168
- const describe = (node) => {
169
- if (!node || !node.tagName) return 'unknown'
170
- const name = (node.getAttribute && (node.getAttribute('aria-label') || node.getAttribute('name'))) || ''
171
- const text = short((node.innerText || '').trim().replace(/\\s+/g, ' '), 60)
172
- return node.tagName.toLowerCase() + (name ? '[' + name + ']' : '') + (text ? ' "' + text + '"' : '')
173
- }
174
-
175
- state.settle = function () {
176
- const quietFrom = Math.max(state.lastNetworkAt, state.lastMutationAt)
177
- return { pending: state.pending, quietMs: Date.now() - quietFrom, readyState: String(document.readyState) }
178
- }
179
-
180
- state.find = function (target, scroll) {
181
- if (!target) return null
182
- let node = null
183
- try {
184
- if (target.css) node = document.querySelector(String(target.css))
185
- else if (target.xpath) node = document.evaluate(String(target.xpath), document, null, 9, null).singleNodeValue
186
- else if (target.text) {
187
- const wanted = String(target.text).trim().toLowerCase()
188
- const nodes = document.querySelectorAll('button, a, [role=button], input, label, [role=tab], [role=option], [role=link]')
189
- for (let i = 0; i < nodes.length; i += 1) {
190
- const value = ((nodes[i].innerText || nodes[i].getAttribute('aria-label') || nodes[i].value || '') + '').trim().toLowerCase()
191
- if (value && value.indexOf(wanted) !== -1) { node = nodes[i]; break }
192
- }
193
- }
194
- } catch (error) { return null }
195
- if (!node) return null
196
- if (scroll === true && typeof node.scrollIntoView === 'function') node.scrollIntoView({ block: 'center', inline: 'center', behavior: 'instant' })
197
- const rect = node.getBoundingClientRect()
198
- return { x: Math.round(rect.left + rect.width / 2), y: Math.round(rect.top + rect.height / 2), w: Math.round(rect.width), h: Math.round(rect.height), described: describe(node) }
199
- }
200
-
201
- const DISMISS = /(accept|agree|allow|continue|close|got it|dismiss|ok|agree|同意|接受|允许|继续|关闭|知道了|我知道了|我同意)/i
202
-
203
- state.overlayAt = function (x, y) {
204
- const top = document.elementFromPoint(Number(x), Number(y))
205
- if (!top) return { covers: null, dismiss: null }
206
- let node = top
207
- let depth = 0
208
- while (node && depth < 8) {
209
- let style = null
210
- try { style = getComputedStyle(node) } catch (error) { style = null }
211
- const floating = style && (style.position === 'fixed' || style.position === 'sticky' || Number(style.zIndex) >= 100)
212
- if (floating) {
213
- const buttons = node.querySelectorAll('button, [role=button], a')
214
- for (let i = 0; i < buttons.length && i < 60; i += 1) {
215
- const label = ((buttons[i].innerText || '') + ' ' + (buttons[i].getAttribute('aria-label') || '')).trim()
216
- if (DISMISS.test(label)) {
217
- const rect = buttons[i].getBoundingClientRect()
218
- return { covers: describe(top), dismiss: { label: short(label, 40), x: Math.round(rect.left + rect.width / 2), y: Math.round(rect.top + rect.height / 2) } }
219
- }
220
- }
221
- return { covers: describe(top), dismiss: null }
222
- }
223
- node = node.parentElement
224
- depth += 1
225
- }
226
- return { covers: describe(top), dismiss: null }
227
- }
228
-
229
- state.read = function (kind, filter, limit) {
230
- const list = kind === 'console' ? state.console : kind === 'network' ? state.network : state.dialogs
231
- const needle = filter ? String(filter).toLowerCase() : ''
232
- const rows = needle === '' ? list : list.filter((row) => ((row.url || '') + ' ' + (row.text || '') + ' ' + (row.message || '')).toLowerCase().indexOf(needle) !== -1)
233
- const max = Math.max(0, Math.min(Number(limit) || 20, 100))
234
- return rows.slice(Math.max(0, rows.length - max))
235
- }
236
-
237
- state.clear = function (kind) {
238
- if (kind === 'console') state.console.length = 0
239
- else if (kind === 'network') state.network.length = 0
240
- else if (kind === 'dialogs') state.dialogs.length = 0
241
- return true
242
- }
243
-
244
- state.setDialogPolicy = function (policy) {
245
- if (policy !== 'native' && policy !== 'accept' && policy !== 'dismiss') return state.dialogPolicy
246
- const previousPolicy = state.dialogPolicy
247
- state.dialogPolicy = policy
248
- for (const kind of Object.keys(nativeDialogs)) {
249
- if (policy === 'native') {
250
- if (globalThis[kind] === dialogWrappers[kind]) globalThis[kind] = nativeDialogs[kind]
251
- } else {
252
- if (previousPolicy === 'native' && globalThis[kind] !== dialogWrappers[kind]) nativeDialogs[kind] = globalThis[kind]
253
- globalThis[kind] = dialogWrappers[kind]
254
- }
255
- }
256
- return state.dialogPolicy
257
- }
258
-
259
- state.dialogStatus = function () { return state.dialogPolicy }
260
- state.networkCursor = function () { return { startedAt: state.startedAt, sequence: state.networkSequence } }
261
- state.dispose = function () {
262
- for (const undo of restore.reverse()) { try { undo() } catch (error) {} }
263
- if (globalThis[KEY] === state) delete globalThis[KEY]
264
- }
265
-
266
- state.findText = function (text, all) {
267
- const needle = String(text || '')
268
- const out = []
269
- if (needle === '') return out
270
- const wanted = needle.toLowerCase()
271
- const root = document.body || document.documentElement
272
- if (!root || typeof document.createTreeWalker !== 'function') return out
273
- const walker = document.createTreeWalker(root, 4, null) // 4 = SHOW_TEXT
274
- let node = walker.nextNode()
275
- while (node) {
276
- const value = node.nodeValue || ''
277
- let at = value.toLowerCase().indexOf(wanted)
278
- while (at !== -1) {
279
- const range = document.createRange()
280
- range.setStart(node, at)
281
- range.setEnd(node, at + needle.length)
282
- const rect = range.getBoundingClientRect()
283
- out.push({
284
- text: short(value.slice(Math.max(0, at - 20), at + needle.length + 20).replace(/\\s+/g, ' ').trim(), 80),
285
- x: Math.round(rect.left + rect.width / 2),
286
- y: Math.round(rect.top + rect.height / 2),
287
- host: node.parentElement ? describe(node.parentElement) : 'text',
288
- })
289
- if (out.length >= (all ? 50 : 5)) return out
290
- at = value.toLowerCase().indexOf(wanted, at + 1)
291
- }
292
- node = walker.nextNode()
293
- }
294
- return out
295
- }
296
-
297
- const hoverEvent = (type, node, x, y) => {
298
- const init = { bubbles: type.indexOf('enter') === -1, cancelable: true, composed: true, clientX: x, clientY: y, button: 0, buttons: 0 }
299
- try {
300
- if (type.indexOf('pointer') === 0 && typeof PointerEvent === 'function') return new PointerEvent(type, Object.assign({ pointerId: 1, pointerType: 'mouse', isPrimary: true }, init))
301
- if (typeof MouseEvent === 'function') return new MouseEvent(type.replace('pointer', 'mouse'), init)
302
- } catch (error) { return null }
303
- return null
304
- }
305
-
306
- state.hoverAt = function (x, y) {
307
- const node = document.elementFromPoint(Number(x), Number(y))
308
- if (!node) return false
309
- const types = ['pointerover', 'pointerenter', 'mouseover', 'mouseenter', 'mousemove']
310
- let fired = 0
311
- for (let i = 0; i < types.length; i += 1) {
312
- const event = hoverEvent(types[i], node, Number(x), Number(y))
313
- if (event && typeof node.dispatchEvent === 'function') { node.dispatchEvent(event); fired += 1 }
314
- }
315
- return fired > 0
316
- }
317
-
318
- state.summary = function () {
319
- const body = document.body ? document.body.innerText : ''
320
- const query = (selector) => { try { return document.querySelectorAll(selector).length } catch (error) { return 0 } }
321
- const settled = state.settle()
322
- return {
323
- url: String(location.href),
324
- title: String(document.title || ''),
325
- readyState: settled.readyState,
326
- pending: settled.pending,
327
- quietMs: settled.quietMs,
328
- inputs: query('input, textarea, select'),
329
- buttons: query('button, [role=button]'),
330
- links: query('a[href]'),
331
- scrollX: Math.round(globalThis.scrollX || 0),
332
- scrollY: Math.round(globalThis.scrollY || 0),
333
- selection: short(globalThis.getSelection ? String(globalThis.getSelection()) : '', 120),
334
- text: short(String(body || '').replace(/\\s+/g, ' ').trim(), 400),
335
- }
336
- }
337
- globalThis[KEY] = state
338
- return VERSION
339
- })()`
340
-
341
- /**
342
- * One probe call, evaluated in the page, with its result serialised as JSON.
343
- *
344
- * JSON in, JSON out, because that is the only shape every carrier's `execute` can carry reliably.
345
- * @param method - the probe function to call (`read`, `settle`, `find`, `overlayAt`, `clear`, …).
346
- * @param args - arguments, already JSON-serialisable.
347
- * @returns a script whose value is the JSON text of the result (or an error object).
348
- */
349
- export function probeCallScript(method: string, args: readonly unknown[] = []): string {
350
- return `(() => {
351
- const probe = globalThis[${JSON.stringify(PROBE_KEY)}]
352
- if (!probe) return JSON.stringify({ error: 'probe-not-installed' })
353
- if (typeof probe[${JSON.stringify(method)}] !== 'function') return JSON.stringify({ error: 'probe-method-missing' })
354
- try { return JSON.stringify(probe[${JSON.stringify(method)}].apply(probe, ${JSON.stringify(args)})) } catch (error) { return JSON.stringify({ error: String(error) }) }
355
- })()`
356
- }
357
-
358
- /**
359
- * Dispatch a pointer drag in the page, for elements that accept synthetic pointer events.
360
- *
361
- * Uses `PointerEvent` when the page has it and `MouseEvent` otherwise, because a canvas app that
362
- * listens for `mousedown` never sees a pointer event. This is a page-level gesture: a page that
363
- * demands trusted input (some canvas editors) ignores it, exactly like `click_sequence`'s
364
- * coordinate clicks are the trusted counterpart.
365
- * @param from - start point in viewport CSS pixels.
366
- * @param to - end point.
367
- * @param steps - intermediate moves; more steps make a slider or a canvas app follow the path.
368
- * @returns a script value: `{ ok: true, moved, at }` or `{ ok: false, reason }`.
369
- */
370
- export function dragScript(
371
- from: { readonly x: number; readonly y: number },
372
- to: { readonly x: number; readonly y: number },
373
- steps = 12,
374
- ): string {
375
- const points = JSON.stringify({ from, to, steps })
376
- return `(() => {
377
- const spec = ${points}
378
- const at = (x, y) => document.elementFromPoint(x, y)
379
- const start = at(spec.from.x, spec.from.y)
380
- if (!start) return JSON.stringify({ ok: false, reason: 'nothing at the start point' })
381
- const make = (type, x, y, extra) => {
382
- const init = Object.assign({ bubbles: true, cancelable: true, composed: true, clientX: x, clientY: y, button: 0, buttons: type === 'pointerup' || type === 'mouseup' ? 0 : 1 }, extra || {})
383
- try {
384
- if (type.indexOf('pointer') === 0 && typeof PointerEvent === 'function') return new PointerEvent(type, Object.assign({ pointerId: 1, pointerType: 'mouse', isPrimary: true }, init))
385
- if (typeof MouseEvent === 'function') return new MouseEvent(type.replace('pointer', 'mouse'), init)
386
- } catch (error) { /* fall through to the null below */ }
387
- return null
388
- }
389
- const fire = (node, type, x, y, extra) => {
390
- const event = make(type, x, y, extra)
391
- if (event !== null && node && typeof node.dispatchEvent === 'function') { node.dispatchEvent(event); return true }
392
- return false
393
- }
394
- if (!fire(start, 'pointerdown', spec.from.x, spec.from.y)) {
395
- return JSON.stringify({ ok: false, reason: 'this page exposes no event constructors to dispatch a drag' })
396
- }
397
- fire(start, 'mousedown', spec.from.x, spec.from.y)
398
- const total = Math.max(1, Math.min(Number(spec.steps) || 12, 60))
399
- for (let i = 1; i <= total; i += 1) {
400
- const x = Math.round(spec.from.x + (spec.to.x - spec.from.x) * (i / total))
401
- const y = Math.round(spec.from.y + (spec.to.y - spec.from.y) * (i / total))
402
- const node = at(x, y) || start
403
- fire(node, 'pointermove', x, y)
404
- fire(node, 'mousemove', x, y)
405
- }
406
- const end = at(spec.to.x, spec.to.y) || start
407
- fire(end, 'pointerup', spec.to.x, spec.to.y)
408
- fire(end, 'mouseup', spec.to.x, spec.to.y)
409
- return JSON.stringify({ ok: true, moved: total, at: spec.to })
410
- })()`
411
- }
412
-
413
- /**
414
- * Put a local file into an `<input type=file>`, without CDP.
415
- *
416
- * The page cannot read a disk path, so the bytes travel in as base64 and are rebuilt as a `File`
417
- * in page context, then attached through a `DataTransfer`. That is what a drag-and-drop handler
418
- * sees, so frameworks that read `input.files` or a drop event both work. The admission decision
419
- * (which path may be read at all) belongs to the caller; this only carries the bytes.
420
- * @param target - how to find the input: a CSS selector or visible text near it.
421
- * @param file - name, MIME type and base64 of the bytes.
422
- * @returns a script value: `{ ok: true, name, size }` or `{ ok: false, reason }`.
423
- */
424
- export function uploadScript(
425
- target: { readonly by: 'css' | 'text' | 'xpath'; readonly value: string },
426
- file: { readonly name: string; readonly mime: string; readonly base64: string },
427
- ): string {
428
- const spec = JSON.stringify({ target, file })
429
- return `(() => {
430
- const spec = ${spec}
431
- const probe = globalThis[${JSON.stringify(PROBE_KEY)}]
432
- const where = probe ? probe.find(spec.target) : null
433
- let node = null
434
- try {
435
- if (spec.target.by === 'css') node = document.querySelector(spec.target.value)
436
- else if (spec.target.by === 'xpath') node = document.evaluate(spec.target.value, document, null, 9, null).singleNodeValue
437
- else if (where) node = document.elementFromPoint(where.x, where.y)
438
- } catch (error) { node = null }
439
- if (node && node.tagName !== 'INPUT' && node.querySelector) {
440
- const nested = node.querySelector('input[type=file]')
441
- if (nested) node = nested
442
- }
443
- if (!node || node.tagName !== 'INPUT' || String(node.type).toLowerCase() !== 'file') {
444
- return JSON.stringify({ ok: false, reason: 'no file input at that target (' + (where ? where.described : 'nothing matched') + ')' })
445
- }
446
- const binary = atob(spec.file.base64)
447
- const bytes = new Uint8Array(binary.length)
448
- for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i)
449
- const blob = new File([bytes], spec.file.name, { type: spec.file.mime || 'application/octet-stream' })
450
- const transfer = new DataTransfer()
451
- transfer.items.add(blob)
452
- node.files = transfer.files
453
- node.dispatchEvent(new Event('input', { bubbles: true }))
454
- node.dispatchEvent(new Event('change', { bubbles: true }))
455
- return JSON.stringify({ ok: true, name: blob.name, size: blob.size, files: node.files ? node.files.length : 0 })
456
- })()`
457
- }
458
- /** Build a fixed page operation, rejecting unknown operations before any code runs. */
459
- export function pageOperationScript(request: BrowserPageOperationRequest): string {
460
- switch (request.operation) {
461
- case 'install': return PROBE_INSTALL_SCRIPT
462
- case 'url': return 'JSON.stringify(location.href)'
463
- case 'text': return 'JSON.stringify((document.body ? document.body.innerText : "").indexOf(' + JSON.stringify(request.text) + ') !== -1)'
464
- case 'drag': return dragScript(request.from, request.to, request.steps)
465
- case 'upload': return uploadScript(request.target, request.file)
466
- case 'probe': {
467
- const methods: readonly BrowserProbeMethod[] = ['read', 'clear', 'settle', 'find', 'overlayAt', 'summary',
468
- 'findText', 'hoverAt', 'setDialogPolicy', 'dialogStatus', 'networkCursor']
469
- if (!methods.includes(request.method)) throw new Error('browser: unsupported fixed page operation')
470
- return probeCallScript(request.method, request.args)
471
- }
472
- default: throw new Error('browser: unsupported fixed page operation')
473
- }
474
- }
@@ -1,124 +0,0 @@
1
- /**
2
- * Panel-surface page reader.
3
- *
4
- * The Web sidebar renders pages through the plugin's own same-origin proxy, so there is no CDP
5
- * target behind it. `dsh_browser_open` on the panel surface therefore only hands the address to the
6
- * sidebar, and every read tool afterwards answered "nothing is open in this task yet" — the model
7
- * could open a page but never look at it.
8
- *
9
- * This module gives those tools something real to read: it fetches the proxied document from
10
- * loopback (the proxy route is same-origin and loopback-authorized) and parses the parts a snapshot
11
- * needs — title, text, and the interactive nodes with their labels. It cannot run page script, so
12
- * actions that need JS still belong to the `builtin` surface; reads do not.
13
- *
14
- * @module dsh-builtin-browser/tool-browser/panel-page
15
- */
16
-
17
- /** One interactive node found in the proxied document. */
18
- export interface PanelElement {
19
- readonly index: number
20
- /** `link` | `button` | `input` | `select` | `textarea` */
21
- readonly kind: string
22
- /** Accessible-ish name: text content, aria-label, placeholder or value. */
23
- readonly name: string
24
- /** Destination for links, or the control's type. */
25
- readonly detail?: string
26
- }
27
-
28
- /** What a panel read returns. */
29
- export interface PanelPage {
30
- readonly url: string
31
- readonly title: string
32
- readonly text: string
33
- readonly elements: readonly PanelElement[]
34
- readonly truncated: boolean
35
- }
36
-
37
- /** Decode the handful of entities that matter for labels. */
38
- function decodeEntities(raw: string): string {
39
- return raw
40
- .replace(/&nbsp;/gu, ' ')
41
- .replace(/&amp;/gu, '&')
42
- .replace(/&lt;/gu, '<')
43
- .replace(/&gt;/gu, '>')
44
- .replace(/&quot;/gu, '"')
45
- .replace(/&#(\d+);/gu, (_match, code: string) => String.fromCodePoint(Number(code)))
46
- }
47
-
48
- /** Strip tags and collapse whitespace. */
49
- function plain(raw: string): string {
50
- return decodeEntities(raw.replace(/<[^>]*>/gu, ' ')).replace(/\s+/gu, ' ').trim()
51
- }
52
-
53
- /**
54
- * Read one attribute out of a tag's source text.
55
- * @param tag - the tag source (e.g. `<a href="x" aria-label="y">`).
56
- * @param name - attribute name.
57
- * @returns the attribute value, or undefined.
58
- */
59
- function attribute(tag: string, name: string): string | undefined {
60
- const match = new RegExp(`\\s${name}\\s*=\\s*("([^"]*)"|'([^']*)'|([^\\s>]+))`, 'iu').exec(tag)
61
- if (match === null) return undefined
62
- const value = match[2] ?? match[3] ?? match[4] ?? ''
63
- return decodeEntities(value).trim()
64
- }
65
-
66
- /**
67
- * Fetch the proxied document for an address and parse it.
68
- * @param pageUrl - the real page address (what the sidebar is showing).
69
- * @param origin - this host's origin, used to reach the proxy.
70
- * @param options - optional element cap.
71
- * @returns the parsed page.
72
- */
73
- export async function readPanelPage(
74
- pageUrl: string,
75
- origin: string,
76
- options: { readonly limit?: number; readonly signal?: AbortSignal } = {},
77
- ): Promise<PanelPage> {
78
- const limit = options.limit ?? 120
79
- const proxied = `${origin}/dsh-builtin-browser/browser-view/isolated-guest?u=${encodeURIComponent(pageUrl)}`
80
- const response = await fetch(proxied, {
81
- headers: {
82
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
83
- 'accept': 'text/html,application/xhtml+xml',
84
- 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
85
- },
86
- ...options.signal === undefined ? {} : { signal: options.signal },
87
- })
88
- const html = await response.text()
89
- if (!response.ok) {
90
- throw new Error(`panel read failed: HTTP ${response.status} for ${pageUrl}`)
91
- }
92
-
93
- const titleMatch = /<title[^>]*>([\s\S]*?)<\/title>/iu.exec(html)
94
- const title = titleMatch === null ? '' : plain(titleMatch[1] ?? '')
95
- const withoutScripts = html
96
- .replace(/<script[\s\S]*?<\/script>/giu, ' ')
97
- .replace(/<style[\s\S]*?<\/style>/giu, ' ')
98
- const text = plain(withoutScripts).slice(0, 4000)
99
-
100
- const elements: PanelElement[] = []
101
- const pattern = /<(a|button|input|select|textarea)\b([^>]*)>/giu
102
- let match: RegExpExecArray | null
103
- while ((match = pattern.exec(html)) !== null && elements.length < limit) {
104
- const tagName = (match[1] ?? '').toLowerCase()
105
- const tag = match[0]
106
- if (tagName === 'a') {
107
- const href = attribute(tag, 'href')
108
- const label = attribute(tag, 'aria-label') ?? ''
109
- if (href === undefined || href.startsWith('javascript:')) continue
110
- elements.push({ index: elements.length + 1, kind: 'link', name: label === '' ? href : label, detail: href })
111
- continue
112
- }
113
- if (tagName === 'button') {
114
- const label = attribute(tag, 'aria-label') ?? attribute(tag, 'title') ?? ''
115
- elements.push({ index: elements.length + 1, kind: 'button', name: label === '' ? '(button)' : label })
116
- continue
117
- }
118
- const type = attribute(tag, 'type') ?? tagName
119
- const label = attribute(tag, 'aria-label') ?? attribute(tag, 'placeholder') ?? attribute(tag, 'name') ?? ''
120
- elements.push({ index: elements.length + 1, kind: tagName, name: label === '' ? `(${tagName})` : label, detail: type })
121
- }
122
-
123
- return { url: pageUrl, title, text, elements, truncated: elements.length >= limit || text.length >= 4000 }
124
- }
@@ -1,49 +0,0 @@
1
- import type { ImageBlock } from '@deepseek-ai/dsh-llm'
2
-
3
- export const SCREENSHOT_MAX_WIDTH = 1280
4
- export const SCREENSHOT_MAX_HEIGHT = 960
5
- export const SCREENSHOT_MAX_BYTES = 4 * 1024 * 1024
6
-
7
- export function screenshotDimension(value: number | undefined, limit: number): number {
8
- if (value === undefined) return limit
9
- if (!Number.isFinite(value) || value < 1) throw new Error('Screenshot dimensions must be positive finite numbers.')
10
- return Math.min(Math.floor(value), limit)
11
- }
12
-
13
- export function screenshotBytes(dataUrl: string): { data: Buffer; mediaType: 'image/png' | 'image/jpeg' } {
14
- if (dataUrl.length > 64 + Math.ceil(SCREENSHOT_MAX_BYTES / 3) * 4) {
15
- throw new Error('Screenshot exceeds the 4 MiB image limit; retry with smaller maxWidth/maxHeight.')
16
- }
17
- const match = /^data:(image\/png|image\/jpeg);base64,([A-Za-z0-9+/]+={0,2})$/.exec(dataUrl)
18
- if (!match) throw new Error('Screenshot must contain a PNG or JPEG base64 image.')
19
- const data = Buffer.from(match[2]!, 'base64')
20
- if (data.length === 0 || data.toString('base64') !== match[2]) throw new Error('Screenshot contains invalid base64.')
21
- if (data.length > SCREENSHOT_MAX_BYTES) throw new Error('Screenshot exceeds the 4 MiB image limit; retry with smaller maxWidth/maxHeight.')
22
- return { data, mediaType: match[1] as 'image/png' | 'image/jpeg' }
23
- }
24
-
25
- export async function screenshotVisionEnabled(context: unknown, execution: unknown, signal?: AbortSignal): Promise<boolean> {
26
- const ctx = context as { llm?: { resolveModelInfo(provider: string, model: string, signal?: AbortSignal): Promise<{ inputModalities?: readonly string[] }> } }
27
- const exec = execution as { agent?: { model?: { current(): { provider: string; model: string } | undefined } } }
28
- signal?.throwIfAborted()
29
- try {
30
- const selection = exec.agent?.model?.current()
31
- if (!selection || !ctx.llm) return false
32
- const info = await ctx.llm.resolveModelInfo(selection.provider, selection.model, signal)
33
- signal?.throwIfAborted()
34
- return info.inputModalities?.includes('image') === true
35
- } catch (error) {
36
- signal?.throwIfAborted()
37
- return false
38
- }
39
- }
40
-
41
- export async function saveScreenshotImage(context: unknown, image: ReturnType<typeof screenshotBytes>, maxWidth: number, maxHeight: number): Promise<ImageBlock['attachment']> {
42
- const ctx = context as { attachments?: { saveImage(input: { data: Uint8Array; mediaType: 'image/png' | 'image/jpeg' }): Promise<ImageBlock['attachment']> } }
43
- if (!ctx.attachments) throw new Error('Screenshot image delivery requires the host attachment service.')
44
- const ref = await ctx.attachments.saveImage(image)
45
- if (!(ref.bytes > 0 && ref.bytes <= SCREENSHOT_MAX_BYTES && ref.width > 0 && ref.width <= maxWidth && ref.height > 0 && ref.height <= maxHeight)) {
46
- throw new Error('Screenshot encoder exceeded the image size/dimension limits; retry with smaller maxWidth/maxHeight.')
47
- }
48
- return { attachmentId: ref.attachmentId, mediaType: ref.mediaType, bytes: ref.bytes, width: ref.width, height: ref.height }
49
- }