dsh-builtin-browser 1.0.1 → 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 (360) hide show
  1. package/CHANGELOG.md +55 -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/tool-reference.md +1 -1
  19. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  20. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  21. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  22. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  23. package/dsh-host-patch/README.md +4 -0
  24. package/dsh-host-patch/apply.mjs +61 -13
  25. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  26. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  27. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  28. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  29. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  30. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  31. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  32. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  33. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  34. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  35. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  36. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  37. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  38. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  39. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  40. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  41. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  42. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  43. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  44. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  45. package/dsh-host-patch/sources/manifest.json +218 -0
  46. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  47. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  48. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  49. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  50. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  51. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  52. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  53. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  54. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  55. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  56. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  57. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  58. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  59. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  60. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  61. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  62. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  63. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  64. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  65. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  66. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  67. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  68. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  69. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  70. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  71. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  72. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  73. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  74. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  75. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  76. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  77. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  78. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  79. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  80. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  81. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  82. package/dsh-host-patch/sources/series.json +260 -0
  83. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  84. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  85. package/dsh-host-patch/tauri-revision1.json +39 -0
  86. package/dsh-host-patch/tauri.json +43 -0
  87. package/dsh-host-patch/v023-alpha2.json +153 -0
  88. package/lib/browser/anti-bot.js +215 -0
  89. package/lib/browser/deep-dom.js +39 -0
  90. package/lib/browser/runtime.js +15 -0
  91. package/lib/browser/takeover-target.js +13 -6
  92. package/lib/browser/types.js +30 -1
  93. package/lib/browser-electron/authenticated-route.js +16 -2
  94. package/lib/browser-electron/automatic-maintenance.js +16 -10
  95. package/lib/browser-electron/bridge-connection.js +3 -8
  96. package/lib/browser-electron/bridge-install.js +2 -1
  97. package/lib/browser-electron/bridge-status.js +55 -26
  98. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  99. package/lib/browser-electron/desktop-identity.js +28 -5
  100. package/lib/browser-electron/desktop-shell.js +64 -0
  101. package/lib/browser-electron/electron-provision.js +105 -18
  102. package/lib/browser-electron/entry.js +129 -44
  103. package/lib/browser-electron/extension-browser.js +4 -4
  104. package/lib/browser-electron/foreground-watch.js +134 -0
  105. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  106. package/lib/browser-electron/guest-route.js +181 -32
  107. package/lib/browser-electron/guest-runtime.js +61 -10
  108. package/lib/browser-electron/guest-storage.js +2 -2
  109. package/lib/browser-electron/history-store.js +1 -5
  110. package/lib/browser-electron/host-main.js +8 -4
  111. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  112. package/lib/browser-electron/maintenance-route.js +2 -1
  113. package/lib/browser-electron/missing-system-browser.js +5 -9
  114. package/lib/browser-electron/preferred-browser.js +7 -3
  115. package/lib/browser-electron/preview-route.js +9 -13
  116. package/lib/browser-electron/process-ownership.js +1 -1
  117. package/lib/browser-electron/profile-command.js +2 -1
  118. package/lib/browser-electron/profile-extension.js +5 -0
  119. package/lib/browser-electron/profile-lease.js +152 -47
  120. package/lib/browser-electron/provider-core.js +527 -0
  121. package/lib/browser-electron/provider-interaction.js +963 -0
  122. package/lib/browser-electron/provider-media.js +518 -0
  123. package/lib/browser-electron/provider-navigation.js +301 -0
  124. package/lib/browser-electron/provider-observation.js +623 -0
  125. package/lib/browser-electron/provider-tabs.js +372 -0
  126. package/lib/browser-electron/provider.js +150 -3301
  127. package/lib/browser-electron/reference-route.js +9 -18
  128. package/lib/browser-electron/remote-host.js +79 -34
  129. package/lib/browser-electron/runtime-status.js +56 -6
  130. package/lib/browser-electron/settings-store.js +3 -6
  131. package/lib/browser-electron/sidebar-only-host.js +1 -1
  132. package/lib/browser-electron/system-browser.js +539 -172
  133. package/lib/browser-electron/tauri-host.js +208 -0
  134. package/lib/browser-electron/virtual-cursor.js +23 -13
  135. package/lib/browser-reference/service.js +22 -4
  136. package/lib/browser-reference/web-sources.js +1 -1
  137. package/lib/client.js +43409 -0
  138. package/lib/compat/host-features.js +75 -0
  139. package/lib/reference-source.js +1 -1
  140. package/lib/reference-text.js +23 -1
  141. package/lib/takeover-protocol.js +1 -1
  142. package/lib/tool-browser/block-recovery.js +69 -0
  143. package/lib/tool-browser/code-tool.js +170 -19
  144. package/lib/tool-browser/code-worker.js +115 -20
  145. package/lib/tool-browser/errors.js +34 -0
  146. package/lib/tool-browser/index.js +66 -3593
  147. package/lib/tool-browser/page-probe.js +227 -28
  148. package/lib/tool-browser/panel-page.js +2 -1
  149. package/lib/tool-browser/probe-client.js +157 -0
  150. package/lib/tool-browser/screenshot-annotations.js +108 -0
  151. package/lib/tool-browser/state.js +337 -0
  152. package/lib/tool-browser/takeover.js +1 -1
  153. package/lib/tool-browser/tools-debug.js +862 -0
  154. package/lib/tool-browser/tools-interaction.js +993 -0
  155. package/lib/tool-browser/tools-navigation.js +807 -0
  156. package/lib/tool-browser/tools-observation.js +461 -0
  157. package/lib/tool-browser/tools-reference.js +293 -0
  158. package/lib/web-guest.js +1 -0
  159. package/package.json +15 -53
  160. package/README.en.md +0 -89
  161. package/browser-extension/constants.mjs +0 -20
  162. package/browser-extension/controller.mjs +0 -293
  163. package/browser-extension/locales.mjs +0 -15
  164. package/browser-extension/manifest.json +0 -12
  165. package/browser-extension/options.html +0 -14
  166. package/browser-extension/options.mjs +0 -9
  167. package/browser-extension/permission-guard.mjs +0 -13
  168. package/browser-extension/worker.mjs +0 -74
  169. package/dist/client.cjs +0 -43167
  170. package/lib/browser-reference/submission-receipts.js +0 -139
  171. package/scripts/build.mjs +0 -66
  172. package/scripts/bundle-host.mjs +0 -28
  173. package/scripts/fix-exports.mjs +0 -50
  174. package/scripts/install-electron.mjs +0 -51
  175. package/scripts/verify-exports.mjs +0 -47
  176. package/scripts/verify-preview-sdk.mjs +0 -93
  177. package/skills/dsh-builtin-browser/SKILL.md +0 -73
  178. package/skills/dsh-builtin-browser/references/batch.md +0 -53
  179. package/skills/dsh-builtin-browser/references/deliver.md +0 -31
  180. package/skills/dsh-builtin-browser/references/locate.md +0 -11
  181. package/skills/dsh-builtin-browser/references/recover.md +0 -11
  182. package/skills/dsh-builtin-browser/references/verify.md +0 -13
  183. package/skills/dsh-debug-host/SKILL.md +0 -56
  184. package/skills/dsh-debug-self/SKILL.md +0 -50
  185. package/src/bridge-compatibility.ts +0 -39
  186. package/src/browser/handles.ts +0 -89
  187. package/src/browser/runtime.ts +0 -560
  188. package/src/browser/takeover-target.ts +0 -36
  189. package/src/browser/types.ts +0 -817
  190. package/src/browser-electron/authenticated-route.ts +0 -84
  191. package/src/browser-electron/automatic-maintenance.ts +0 -726
  192. package/src/browser-electron/bridge-auto.ts +0 -159
  193. package/src/browser-electron/bridge-connection.ts +0 -385
  194. package/src/browser-electron/bridge-endpoint.ts +0 -129
  195. package/src/browser-electron/bridge-install.ts +0 -289
  196. package/src/browser-electron/bridge-maintenance.ts +0 -189
  197. package/src/browser-electron/bridge-status.ts +0 -347
  198. package/src/browser-electron/desktop-bridge-host.ts +0 -251
  199. package/src/browser-electron/desktop-identity.ts +0 -320
  200. package/src/browser-electron/document-readiness.ts +0 -45
  201. package/src/browser-electron/electron-provision.ts +0 -261
  202. package/src/browser-electron/entry.ts +0 -1299
  203. package/src/browser-electron/ephemeral-profile.ts +0 -189
  204. package/src/browser-electron/extension-browser.ts +0 -223
  205. package/src/browser-electron/extension-setup.ts +0 -67
  206. package/src/browser-electron/file-write.ts +0 -31
  207. package/src/browser-electron/guest-cookie-jar.ts +0 -176
  208. package/src/browser-electron/guest-cookie-store.ts +0 -59
  209. package/src/browser-electron/guest-css-runtime.ts +0 -76
  210. package/src/browser-electron/guest-css.ts +0 -68
  211. package/src/browser-electron/guest-route.ts +0 -568
  212. package/src/browser-electron/guest-runtime.ts +0 -357
  213. package/src/browser-electron/guest-storage-runtime.ts +0 -54
  214. package/src/browser-electron/guest-storage.ts +0 -117
  215. package/src/browser-electron/history-store.ts +0 -227
  216. package/src/browser-electron/host-main.ts +0 -1381
  217. package/src/browser-electron/host-patch-maintenance.ts +0 -112
  218. package/src/browser-electron/http-body.ts +0 -65
  219. package/src/browser-electron/json-reply.ts +0 -47
  220. package/src/browser-electron/maintenance-broker.ts +0 -166
  221. package/src/browser-electron/maintenance-lifecycle.ts +0 -91
  222. package/src/browser-electron/maintenance-route.ts +0 -67
  223. package/src/browser-electron/missing-system-browser.ts +0 -113
  224. package/src/browser-electron/open-slot.ts +0 -49
  225. package/src/browser-electron/paths.ts +0 -25
  226. package/src/browser-electron/preferred-browser.ts +0 -120
  227. package/src/browser-electron/preview-route.ts +0 -218
  228. package/src/browser-electron/process-ownership.ts +0 -168
  229. package/src/browser-electron/process.ts +0 -23
  230. package/src/browser-electron/profile-checkpoint.ts +0 -187
  231. package/src/browser-electron/profile-command.ts +0 -46
  232. package/src/browser-electron/profile-extension.ts +0 -124
  233. package/src/browser-electron/profile-lease.ts +0 -115
  234. package/src/browser-electron/profile-residue.ts +0 -49
  235. package/src/browser-electron/provider.ts +0 -4571
  236. package/src/browser-electron/reference-route.ts +0 -608
  237. package/src/browser-electron/remote-host.ts +0 -1462
  238. package/src/browser-electron/rpc-input.ts +0 -13
  239. package/src/browser-electron/rpc-ops.ts +0 -41
  240. package/src/browser-electron/runtime-diagnostics.ts +0 -38
  241. package/src/browser-electron/runtime-route.ts +0 -105
  242. package/src/browser-electron/runtime-status.ts +0 -242
  243. package/src/browser-electron/settings-route.ts +0 -64
  244. package/src/browser-electron/settings-store.ts +0 -589
  245. package/src/browser-electron/shortcuts-route.ts +0 -112
  246. package/src/browser-electron/sidebar-only-host.ts +0 -298
  247. package/src/browser-electron/startpage-shortcuts.ts +0 -213
  248. package/src/browser-electron/system-browser.ts +0 -1497
  249. package/src/browser-electron/timing.ts +0 -16
  250. package/src/browser-electron/virtual-cursor.ts +0 -152
  251. package/src/browser-electron/windows-system.ts +0 -24
  252. package/src/browser-reference/delivery.ts +0 -384
  253. package/src/browser-reference/entry.ts +0 -631
  254. package/src/browser-reference/export.ts +0 -339
  255. package/src/browser-reference/import.ts +0 -303
  256. package/src/browser-reference/page-script.ts +0 -1537
  257. package/src/browser-reference/service.ts +0 -1315
  258. package/src/browser-reference/store.ts +0 -172
  259. package/src/browser-reference/submission-receipts.ts +0 -122
  260. package/src/browser-reference/text-quote.ts +0 -219
  261. package/src/browser-reference/types.ts +0 -195
  262. package/src/browser-reference/visible.ts +0 -367
  263. package/src/browser-reference/web-sources.ts +0 -103
  264. package/src/client/browser/BrowserController.ts +0 -693
  265. package/src/client/browser/BrowserFrame.ts +0 -78
  266. package/src/client/browser/BrowserNavigation.ts +0 -169
  267. package/src/client/browser/BrowserPage.ts +0 -23
  268. package/src/client/browser/BrowserPersistence.ts +0 -44
  269. package/src/client/browser/IframeImpl.ts +0 -176
  270. package/src/client/browser/child-tabs.ts +0 -14
  271. package/src/client/browser/iframe-reference.ts +0 -67
  272. package/src/client/browser/initialization.ts +0 -262
  273. package/src/client/browser/omnibox.ts +0 -243
  274. package/src/client/browser/store.ts +0 -38
  275. package/src/client/browser/takeover-channel.ts +0 -72
  276. package/src/client/browser/url.ts +0 -46
  277. package/src/client/browser/web-reference-source.ts +0 -52
  278. package/src/client/css-modules.d.ts +0 -4
  279. package/src/client/definition.tsx +0 -30
  280. package/src/client/electron/ElectronWebViewImpl.ts +0 -364
  281. package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
  282. package/src/client/electron/NativeChildPresentation.ts +0 -45
  283. package/src/client/electron/NativeViewPage.ts +0 -251
  284. package/src/client/electron/pages.ts +0 -23
  285. package/src/client/electron/reference-overlay.ts +0 -53
  286. package/src/client/electron/workspace.ts +0 -33
  287. package/src/client/index.ts +0 -293
  288. package/src/client/locales.ts +0 -857
  289. package/src/client/pages.ts +0 -28
  290. package/src/client/reference/client/BrowserRefLink.tsx +0 -142
  291. package/src/client/reference/client/draft-reference.ts +0 -167
  292. package/src/client/reference/client/index.ts +0 -7
  293. package/src/client/reference/client/ordered-submission.ts +0 -108
  294. package/src/client/reference/client/pending-delivery.ts +0 -216
  295. package/src/client/reference/client/plugin.ts +0 -189
  296. package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
  297. package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
  298. package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
  299. package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
  300. package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
  301. package/src/client/reference/client/production/ReferenceText.tsx +0 -36
  302. package/src/client/reference/client/production/assembly.ts +0 -471
  303. package/src/client/reference/client/production/asset-store.ts +0 -144
  304. package/src/client/reference/client/production/availability.ts +0 -74
  305. package/src/client/reference/client/production/bytes.ts +0 -36
  306. package/src/client/reference/client/production/delivery-client.ts +0 -211
  307. package/src/client/reference/client/production/draft-adapter.ts +0 -508
  308. package/src/client/reference/client/production/http-transport.ts +0 -217
  309. package/src/client/reference/client/production/production-submission.ts +0 -310
  310. package/src/client/reference/client/production/protocol.ts +0 -231
  311. package/src/client/reference/client/production/reference-card.ts +0 -240
  312. package/src/client/reference/client/production/reference-labels.ts +0 -29
  313. package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
  314. package/src/client/reference/client/production/reveal.ts +0 -215
  315. package/src/client/reference/client/production/runtime.ts +0 -1101
  316. package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
  317. package/src/client/reference/client/production/source-marker.ts +0 -63
  318. package/src/client/reference/client/production/source-opener.ts +0 -55
  319. package/src/client/reference/client/production/styles.ts +0 -104
  320. package/src/client/reference/client/production/user-text-rule.ts +0 -58
  321. package/src/client/reference/client/reveal.ts +0 -107
  322. package/src/client/reference/client/scheme.ts +0 -114
  323. package/src/client/reference/client/types.ts +0 -168
  324. package/src/client/reference/css-modules.d.ts +0 -4
  325. package/src/client/reference/index.ts +0 -11
  326. package/src/client/reference-capture-owner.ts +0 -162
  327. package/src/client/reference-intents.ts +0 -36
  328. package/src/client/settings/index.ts +0 -34
  329. package/src/client/settings/panel.ts +0 -2657
  330. package/src/client/shortcut-open.ts +0 -30
  331. package/src/client/startpage/binding.ts +0 -99
  332. package/src/client/startpage/controller.ts +0 -303
  333. package/src/client/startpage/model.ts +0 -279
  334. package/src/client/view/Browser.module.css +0 -751
  335. package/src/client/view/BrowserBody.tsx +0 -314
  336. package/src/client/view/BrowserPresentation.ts +0 -9
  337. package/src/client/view/BrowserTitle.tsx +0 -17
  338. package/src/client/view/IframePresentation.ts +0 -344
  339. package/src/client/view/StartPage.tsx +0 -597
  340. package/src/client/view/TakeoverBanner.tsx +0 -21
  341. package/src/index.ts +0 -110
  342. package/src/reference-owner.ts +0 -5
  343. package/src/reference-page.ts +0 -9
  344. package/src/reference-source.ts +0 -3
  345. package/src/reference-text.ts +0 -197
  346. package/src/startpage-settings.ts +0 -103
  347. package/src/startpage.ts +0 -71
  348. package/src/takeover-protocol.ts +0 -19
  349. package/src/tool-browser/code-tool.ts +0 -401
  350. package/src/tool-browser/code-worker.ts +0 -639
  351. package/src/tool-browser/element-fields.ts +0 -167
  352. package/src/tool-browser/index.ts +0 -3733
  353. package/src/tool-browser/page-probe.ts +0 -474
  354. package/src/tool-browser/panel-page.ts +0 -124
  355. package/src/tool-browser/screenshot-image.ts +0 -49
  356. package/src/tool-browser/takeover.ts +0 -198
  357. package/src/types/electron-shim.d.ts +0 -144
  358. package/src/types.ts +0 -85
  359. package/src/web-guest.ts +0 -34
  360. package/tools/accept-desktop.mjs +0 -148
@@ -1,347 +0,0 @@
1
- /**
2
- * Whether the desktop bridge is installed, and what state its files are in.
3
- *
4
- * Reported as issue #36: when the bridge is missing the plugin only logs a warning, so a user who
5
- * chose `channel: sidebar` sees "another window opened again" and has no way to connect that with
6
- * "the bridge is not installed". This module answers the question the panel needs to show, from the
7
- * install tree on disk rather than from anything the plugin remembers.
8
- *
9
- * The states are the three that actually occur:
10
- *
11
- * - `installed` — the loaded main.js carries our marker and its bridge matches this plugin.
12
- * - `missing` — no marker. Either never installed, or the shell was upgraded (which restores
13
- * `app.asar` and replaces `lib/main.js`) and the bridge went with it.
14
- * - `stale` — the archive is back, or the deployed bridge module is missing or outdated.
15
- * @module dsh-browser/browser-electron/bridge-status
16
- */
17
- import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs'
18
- import { homedir } from 'node:os'
19
- import { isAbsolute, join, relative } from 'node:path'
20
- import { fileURLToPath } from 'node:url'
21
- import { createRequire } from 'node:module'
22
-
23
- import { desktopPaths, readDesktopIdentity } from './desktop-identity.ts'
24
- import { MAIN_EXTENSION_UNSUPPORTED, type MainExtensionStatus } from './profile-extension.ts'
25
- import { BRIDGE_VERSION_MESSAGE } from '../bridge-compatibility.ts'
26
- import { conventionalInstallRoots, registeredInstallLocations } from '../../desktop-bridge/desktop-discovery.mjs'
27
-
28
- // A normal Electron existsSync(app.asar) caches the archive and keeps it locked on Windows.
29
- // Status inspection must leave maintenance free to rename it after Desktop exits.
30
- const rawExistsSync: typeof existsSync = (() => {
31
- try { return (createRequire(import.meta.url)('original-fs') as typeof import('node:fs')).existsSync }
32
- catch { return existsSync }
33
- })()
34
-
35
- /**
36
- * Find the desktop install to report on.
37
- *
38
- * Reported as issue #40: this used to probe for a *generic* Electron layout and return the first
39
- * directory that had one. Any Electron app has that layout, so a stranger's app was reported as
40
- * "DSH Desktop, bridge missing" — together with a ready-to-run installer command aimed at it. The
41
- * probe now verifies the same identity the installer does (see `desktop-identity.js`), so the
42
- * answer is about DSH Desktop and nothing else.
43
- * @param localAppData - the base directory; defaults to the environment's.
44
- * @returns the install directory, or undefined when nothing matches.
45
- */
46
- export function findDesktopInstall(
47
- localAppData?: string,
48
- registry: () => readonly string[] = registeredInstallLocations,
49
- conventions: () => readonly string[] = conventionalInstallRoots,
50
- ): string | undefined {
51
- // Not every install lives in %LOCALAPPDATA%\\Programs: people put the app on another drive, under
52
- // Program Files, or in their own folder. DSH_DESKTOP_PATH names one explicitly, and the usual roots
53
- // are all probed. A test or a caller that passes a base directory gets exactly that base, so the
54
- // behaviour stays pinnable.
55
- const isDesktop = (candidate: string): boolean => readDesktopIdentity(candidate).ok
56
- for (const explicit of [process.env.DSH_DESKTOP_PATH, process.env.DSH_DESKTOP_APP]) {
57
- if (explicit !== undefined && explicit !== '') {
58
- const named = explicit
59
- if (isDesktop(named)) return named
60
- // A parent directory is a reasonable thing to point at too: look one level down.
61
- try {
62
- for (const entry of readdirSync(named, { withFileTypes: true })) {
63
- if (entry.isDirectory() && isDesktop(join(named, entry.name))) return join(named, entry.name)
64
- }
65
- } catch {
66
- // Not a directory: fall through to the usual roots.
67
- }
68
- }
69
- }
70
- const roots = localAppData === undefined ? desktopInstallRoots() : [join(localAppData, 'Programs')]
71
- for (const base of roots) {
72
- for (const named of DESKTOP_INSTALL_NAMES) {
73
- const candidate = join(base, named)
74
- if (isDesktop(candidate)) return candidate
75
- }
76
- try {
77
- for (const entry of readdirSync(base, { withFileTypes: true })) {
78
- if (!entry.isDirectory()) continue
79
- const candidate = join(base, entry.name)
80
- if (isDesktop(candidate)) return candidate
81
- }
82
- } catch {
83
- // A root that does not exist is a state, not an error.
84
- }
85
- }
86
- for (const source of [registry, conventions]) {
87
- try {
88
- for (const candidate of source()) {
89
- if (isDesktop(candidate)) return candidate
90
- }
91
- } catch {}
92
- }
93
- return undefined
94
- }
95
-
96
- /** Directory names an install is given: a plain directory on Windows, an `.app` bundle on macOS. */
97
- const DESKTOP_INSTALL_NAMES = ['DSH Desktop', 'DeepSeek Harness', 'DSH Desktop.app', 'DeepSeek Harness.app']
98
-
99
- /**
100
- * Where this OS keeps installed applications, most specific first.
101
- * @returns the existing-or-not base directories to probe.
102
- */
103
- function desktopInstallRoots(): string[] {
104
- const windows = [process.env.LOCALAPPDATA ?? '', process.env['ProgramFiles'] ?? '', process.env['ProgramFiles(x86)'] ?? '', process.env.APPDATA ?? '', process.env.ProgramData ?? '']
105
- .filter(base => base !== '')
106
- .map(base => (base === process.env.LOCALAPPDATA ? join(base, 'Programs') : base))
107
- // The machine-wide macOS roots cannot be redirected, so a test process never reads them.
108
- const testing = process.env.DSH_BROWSER_TEST === '1' || process.env.NODE_TEST_CONTEXT !== undefined
109
- return process.platform === 'darwin' && !testing ? [...windows, '/Applications', join(homedir(), 'Applications')] : windows
110
- }
111
-
112
- /** The marker the installer inserts into the shell's main.js. */
113
- const MARKER = '// dsh-builtin-browser: hand the plugin a way to drive the sidebar'
114
-
115
- /** One reading of the install tree. */
116
- export interface BridgeStatus {
117
- readonly mainExtension?: MainExtensionStatus
118
- readonly code?: string
119
- /** `installed`, `missing` or `stale`; see the module comment for what each means. */
120
- readonly state: 'installed' | 'missing' | 'stale'
121
- /** Whether the loaded application passed DSH Desktop identity verification. */
122
- readonly present: boolean
123
- /**
124
- * The desktop build this reading belongs to, when the identity check could name one.
125
- *
126
- * The automatic install runs once per build: a desktop update is exactly when the bridge has to be
127
- * installed again, so the guard needs to tell the two apart.
128
- */
129
- readonly version?: string
130
- /** The directory that was inspected, when one was found. */
131
- readonly installRoot?: string
132
- /** Whether `resources/app.asar` exists — the archive the shell actually loads. */
133
- readonly archivePresent: boolean
134
- /** When the pre-bridge backup was written, if there is one. */
135
- readonly backupAt?: string
136
- /** A one-line explanation for the panel, in the plugin's own words. */
137
- readonly detail: string
138
- /**
139
- * The command that installs or repairs the bridge.
140
- *
141
- * The panel can show this command for manual use. Its install button calls the same packaged
142
- * installer through the separately authenticated local bridge-action route.
143
- */
144
- readonly command?: string
145
- }
146
-
147
- /**
148
- * The installer script inside THIS plugin package.
149
- *
150
- * Reported as issue #40, fourth item: the panel told users to run
151
- * `node desktop-bridge/install.mjs "<root>" --restart`, which assumes the reader is standing in a
152
- * source checkout. Anyone who installed the plugin from npm or the market has no such relative path —
153
- * the file lives inside the installed package, and there is nowhere sensible for them to run the
154
- * command from. Resolving it from this module's own location is the difference between a hint and an
155
- * instruction that works.
156
- * @returns the absolute path, or undefined when the package layout is unexpected.
157
- */
158
- function installerScriptPath(): string | undefined {
159
- try {
160
- // lib/browser-electron/bridge-status.js → <package>/desktop-bridge/install.mjs
161
- const url = new URL('../../desktop-bridge/install.mjs', import.meta.url)
162
- const path = fileURLToPath(url)
163
- return safeExists(path) ? path : undefined
164
- } catch {
165
- return undefined
166
- }
167
- }
168
-
169
- /**
170
- * The command a user should run for this state, quoted so it survives a path with spaces.
171
- * @param installRoot - the install directory, or undefined when none was found.
172
- * @returns the command line, or undefined when there is nothing useful to suggest.
173
- */
174
- function repairCommand(installRoot: string | undefined): string | undefined {
175
- if (installRoot === undefined) return undefined
176
- const script = installerScriptPath()
177
- // No absolute path means the package is laid out in a way this module cannot navigate; the bare
178
- // relative form is still better than nothing, but it is the fallback, not the default.
179
- const runner = script === undefined ? 'desktop-bridge/install.mjs' : `"${script}"`
180
- return `node ${runner} "${installRoot}"`
181
- }
182
-
183
- /**
184
- * Read the bridge's state from an install directory.
185
- *
186
- * Never throws: a caller showing this in a settings panel must get an answer even when the directory
187
- * is unreadable or the user pointed at something that is not an install.
188
- * @param installRoot - the desktop install directory.
189
- * @returns the current state.
190
- */
191
- export function readBridgeStatus(installRoot: string, mainExtension?: MainExtensionStatus): BridgeStatus {
192
- const disk = readBridgeInstallStatus(installRoot)
193
- if (mainExtension === undefined) return { ...disk, code: disk.code ?? MAIN_EXTENSION_UNSUPPORTED }
194
- return { ...disk, mainExtension, command: undefined, detail: `desktop main extension: ${mainExtension.state}`,
195
- state: mainExtension.state === 'loaded' ? 'installed' : mainExtension.state === 'not-installed' ? 'missing' : 'stale',
196
- code: mainExtension.code }
197
- }
198
-
199
- function readBridgeInstallStatus(installRoot: string): BridgeStatus {
200
- let resources: string
201
- try { resources = desktopPaths(installRoot).resources }
202
- catch (error) {
203
- return { state: 'missing', present: false, installRoot, archivePresent: false, detail: `not a DSH Desktop install: ${String(error)}` }
204
- }
205
- const appDir = join(resources, 'app')
206
- const mainPath = join(appDir, 'lib', 'main.js')
207
- const archivePath = join(resources, 'app.asar')
208
- const backupPath = `${mainPath}.before-bridge`
209
-
210
- // Identity first, and before any other reading. Two reasons, both measured in issue #40: a
211
- // stranger's app must not be reported as DSH Desktop, and this status also carries a *command* —
212
- // pointing that command at a directory whose identity was never verified is how the installer got
213
- // aimed at an application that merely looked like Electron.
214
- const identity = readDesktopIdentity(installRoot)
215
- if (!identity.ok) {
216
- return {
217
- state: 'missing',
218
- present: false,
219
- installRoot,
220
- archivePresent: safeExists(archivePath),
221
- detail: `not a DSH Desktop install: ${identity.reason}`,
222
- }
223
- }
224
-
225
- const archivePresent = safeExists(archivePath)
226
- const version = identity.version ?? 'unknown'
227
- const mainPresent = safeExists(mainPath)
228
- if (!mainPresent && !archivePresent) {
229
- // Unreachable once identity has passed (identity requires the loaded main entry), kept as the
230
- // fail-closed branch for a tree that changed between the two reads.
231
- return {
232
- state: 'missing',
233
- present: false,
234
- installRoot,
235
- archivePresent,
236
- version,
237
- detail: 'not a DSH Desktop install: no resources/app/lib/main.js and no resources/app.asar',
238
- }
239
- }
240
- if (!rawExistsSync(archivePath)
241
- && safeIncludes(mainPath, '//#region lib/types/main-extensions.js')
242
- && safeExists(fileURLToPath(new URL('../../desktop-bridge/main.mjs', import.meta.url)))) {
243
- return {
244
- state: 'installed', present: true, installRoot, archivePresent: false,
245
- detail: 'DSH Desktop main extension loads the bridge from the installed profile plugin',
246
- ...identity.version === undefined ? {} : { version: identity.version },
247
- command: repairCommand(installRoot),
248
- }
249
- }
250
- let backupAt
251
- try {
252
- if (existsSync(backupPath)) backupAt = statSync(backupPath).mtime.toISOString()
253
- } catch {
254
- // A backup we cannot stat is simply not reported; it does not change the state.
255
- }
256
- if (archivePresent && !safeIncludes(mainPath, MARKER)) {
257
- // The archive is what the shell loads, so an unpacked tree without our marker is not in effect
258
- // even if it were patched.
259
- return {
260
- state: 'missing',
261
- present: true,
262
- installRoot,
263
- archivePresent,
264
- version,
265
- ...backupAt === undefined ? {} : { backupAt },
266
- command: repairCommand(installRoot),
267
- detail: 'packed layout with no bridge in the loaded tree: the bridge is not installed',
268
- }
269
- }
270
- if (archivePresent) {
271
- return {
272
- state: 'stale',
273
- present: true,
274
- installRoot,
275
- archivePresent,
276
- version,
277
- ...backupAt === undefined ? {} : { backupAt },
278
- command: repairCommand(installRoot),
279
- detail: 'the archive is back alongside the patched tree, so the shell loads the archive: '
280
- + 'a desktop update restored it. Re-run the installer to repair.',
281
- }
282
- }
283
- if (!safeIncludes(mainPath, MARKER)) {
284
- return {
285
- state: 'missing',
286
- present: true,
287
- installRoot,
288
- archivePresent,
289
- version,
290
- ...backupAt === undefined ? {} : { backupAt },
291
- command: repairCommand(installRoot),
292
- detail: 'unpacked layout without the bridge patch: the bridge is not installed',
293
- }
294
- }
295
- const bridgePath = join(appDir, 'lib', 'plugin-browser-bridge.js')
296
- let bridgeDetail: string | undefined
297
- let bridgeCode: string | undefined
298
- try {
299
- const deployed = readFileSync(bridgePath)
300
- const shipped = readFileSync(new URL('../../desktop-bridge/plugin-browser-bridge.js', import.meta.url))
301
- const loader = readFileSync(new URL('../../desktop-bridge/profile-loader.mjs', import.meta.url))
302
- if (deployed.equals(loader)) {
303
- try {
304
- const profile = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'profiles', 'desktop')
305
- const manifest = JSON.parse(readFileSync(join(profile, 'package.json'), 'utf8'))
306
- if (!Object.hasOwn(manifest.dependencies ?? {}, 'dsh-builtin-browser')) throw new Error('not a direct profile dependency')
307
- const directory = realpathSync(join(profile, 'node_modules', 'dsh-builtin-browser'))
308
- const entry = realpathSync(join(directory, 'desktop-bridge', 'plugin-browser-bridge.js'))
309
- const child = relative(directory, entry)
310
- if (!child || isAbsolute(child) || child === '..' || child.startsWith('../') || child.startsWith('..\\')) {
311
- throw new Error('bridge entry resolves outside its package')
312
- }
313
- if (!readFileSync(entry).equals(shipped)) bridgeDetail = BRIDGE_VERSION_MESSAGE
314
- } catch {
315
- bridgeCode = 'DSH_BRIDGE_PACKAGE_UNAVAILABLE'
316
- bridgeDetail = `${bridgeCode}: the profile loader's package bridge is missing, unreadable or outside its package`
317
- }
318
- } else if (!deployed.equals(shipped)) bridgeDetail = BRIDGE_VERSION_MESSAGE
319
- } catch {
320
- bridgeDetail = 'the bridge module is missing or cannot be verified; reinstall the bridge to restore it'
321
- }
322
- return {
323
- state: bridgeDetail === undefined ? 'installed' : 'stale',
324
- ...bridgeCode === undefined ? {} : { code: bridgeCode },
325
- present: true,
326
- installRoot,
327
- archivePresent,
328
- version,
329
- ...backupAt === undefined ? {} : { backupAt },
330
- command: repairCommand(installRoot),
331
- detail: bridgeDetail ?? 'the shell loads the patched tree and its bridge module matches this plugin version',
332
- }
333
- }
334
-
335
- /** Whether a path exists, treating any error as absence. */
336
- function safeExists(path: string): boolean {
337
- try { return rawExistsSync(path) } catch { return false }
338
- }
339
-
340
- /** Whether a file contains a string, treating any error as absence. */
341
- function safeIncludes(path: string, needle: string): boolean {
342
- try {
343
- return existsSync(path) && statSync(path).isFile() && readFileSync(path, 'utf8').includes(needle)
344
- } catch {
345
- return false
346
- }
347
- }
@@ -1,251 +0,0 @@
1
- /** Drive the visible sidebar guest through canonical, bridge-bound handles. */
2
- import { BridgeConnection, type BridgeEndpoint } from './bridge-connection.ts'
3
- import { readFileSync } from 'node:fs'
4
- import { bridgeEndpointPath } from './paths.ts'
5
- import { randomUUID } from 'node:crypto'
6
- import { readTabHandle, resolveSessionHandle, resolveTabHandle, sessionWireId, tabWireId, type BrowserSessionWireId, type BrowserTabWireId } from '../browser/handles.ts'
7
- import type { CommandOptions, ElectronBrowserViewHost, ElectronViewHandle, BrowserUserAction } from './provider.ts'
8
- import type { CarrierPage, CarrierLossReason } from '../browser/types.ts'
9
- import { BridgeVersionError, bridgePackageError, isBridgeVersionMismatch } from '../bridge-compatibility.ts'
10
-
11
- export { bridgeEndpointPath }
12
-
13
- const PANEL_NOT_DISPLAYED = 'panel-not-displayed'
14
- const PANEL_INITIALIZING = 'panel-initializing'
15
-
16
- export class BrowserPanelNotDisplayedError extends Error {
17
- readonly code: string
18
- constructor(detail: string, code = PANEL_NOT_DISPLAYED) {
19
- super(`dsh-builtin-browser: this conversation's sidebar page did not attach (${detail})`)
20
- this.name = 'BrowserPanelNotDisplayedError'
21
- this.code = code
22
- }
23
- }
24
-
25
- interface View {
26
- readonly scope: BrowserSessionWireId
27
- bound: boolean
28
- adopted?: boolean
29
- }
30
-
31
- export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
32
- readonly referenceOverlayOwner = 'client' as const
33
- private readonly connection: BridgeConnection
34
- private readonly views = new Map<string, View>()
35
- private readonly orphaned = new Map<BrowserTabWireId, BrowserSessionWireId>()
36
- private activeScope: BrowserSessionWireId | undefined
37
- private readonly retiredSessions = new Set<BrowserSessionWireId>()
38
- private lostListener: ((reason: CarrierLossReason) => void) | undefined
39
- private static refuseIframe = false
40
- private static versionError: string | undefined
41
-
42
- private constructor(endpoint: BridgeEndpoint, private readonly isQuiet: () => boolean = () => false) {
43
- this.connection = new BridgeConnection(endpoint, bridgeEndpointPath(), () => this.lostListener?.('shell-exited'))
44
- }
45
-
46
- onLost(listener: (reason: CarrierLossReason) => void): void { this.lostListener = listener }
47
- available(): boolean { return true }
48
- static refusedIframePanel(): boolean { return this.refuseIframe }
49
- static compatibilityError(): string | undefined { return this.versionError }
50
-
51
- static async discover(_owner?: string, isQuiet?: () => boolean): Promise<DesktopBridgeViewHost | undefined> {
52
- this.refuseIframe = false
53
- this.versionError = undefined
54
- let endpoint: BridgeEndpoint
55
- try {
56
- const raw = JSON.parse(readFileSync(bridgeEndpointPath(), 'utf8')) as Partial<BridgeEndpoint>
57
- if (typeof raw.port !== 'number' || typeof raw.token !== 'string' || typeof raw.pid !== 'number') return undefined
58
- endpoint = { port: raw.port, token: raw.token, pid: raw.pid, ...raw.updatedAt === undefined ? {} : { updatedAt: raw.updatedAt } }
59
- } catch { return undefined }
60
- const probe = new BridgeConnection(endpoint, bridgeEndpointPath())
61
- try {
62
- const answer = await probe.call({ op: 'list' }, 5_000)
63
- if (isBridgeVersionMismatch(answer)) throw new BridgeVersionError()
64
- if (answer.ok !== true) return undefined
65
- if (typeof answer.protocol !== 'number' || !Number.isInteger(answer.protocol)) throw new BridgeVersionError()
66
- if (answer.frame === 'iframe') { this.refuseIframe = true; return undefined }
67
- return new DesktopBridgeViewHost(endpoint, isQuiet)
68
- } catch (error) {
69
- const versionError = bridgePackageError(error) ?? (error instanceof BridgeVersionError ? error : undefined)
70
- if (versionError !== undefined) {
71
- this.versionError = versionError.message
72
- throw versionError
73
- }
74
- return undefined
75
- }
76
- finally { probe.close() }
77
- }
78
-
79
- async listPages(scope: BrowserSessionWireId, _options: { readonly requireRunning?: boolean } = {}): Promise<readonly CarrierPage[]> {
80
- resolveSessionHandle(scope)
81
- const answer = await this.connection.call({ op: 'list', handle: scope }, 5_000)
82
- if (answer.ok !== true) throw new Error(String(answer.error ?? 'sidebar page listing failed'))
83
- if (!Array.isArray(answer.sidebar)) throw new Error('invalid sidebar page listing')
84
- const pages: CarrierPage[] = []
85
- for (const page of answer.sidebar) {
86
- if (typeof page?.id !== 'string') throw new Error('invalid sidebar page handle')
87
- resolveTabHandle(resolveSessionHandle(scope), page.id)
88
- if (!this.views.has(page.id)) pages.push({ id: page.id, url: String(page.url ?? ''), title: String(page.title ?? '') })
89
- }
90
- return pages
91
- }
92
-
93
- async adoptPage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))): Promise<ElectronViewHandle> {
94
- const identity = tabWireId(resolveTabHandle(resolveSessionHandle(scope), id))
95
- const answer = await this.connection.call({ op: 'adoptPage', handle: identity })
96
- if (answer.ok !== true || answer.id !== id) throw new Error(String(answer.error ?? 'sidebar page adoption failed'))
97
- const handle = this.createView(identity)
98
- const entry = this.views.get(handle.id)!
99
- entry.bound = true
100
- entry.adopted = true
101
- return handle
102
- }
103
-
104
- async closePage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))): Promise<void> {
105
- const identity = tabWireId(resolveTabHandle(resolveSessionHandle(scope), id))
106
- const blank = this.views.get(id)?.bound === false
107
- const answer = await this.connection.call({ op: blank ? 'releaseTab' : 'closePage', handle: identity }, 10_000)
108
- if (answer.ok !== true || (!blank && answer.closed !== 1)) throw new Error(`dsh-builtin-browser: could not close sidebar page: ${String(answer.error ?? 'close not acknowledged')}`)
109
- this.views.delete(id)
110
- this.orphaned.delete(id)
111
- }
112
-
113
- private async guestFor(id: BrowserTabWireId, url?: string, options?: CommandOptions, checkNavigation?: () => void): Promise<Record<string, unknown> | undefined> {
114
- const entry = this.views.get(id)
115
- if (entry === undefined) throw new Error('dsh-builtin-browser: sidebar view was released')
116
- const check = (): void => {
117
- options?.signal?.throwIfAborted()
118
- checkNavigation?.()
119
- if (this.views.get(id) !== entry) throw new Error('dsh-builtin-browser: sidebar view was released')
120
- }
121
- check()
122
- if (entry.bound) return undefined
123
- if (options?.initialize === false || options?.present === false) {
124
- throw new BrowserPanelNotDisplayedError('this view has no attached guest yet', PANEL_INITIALIZING)
125
- }
126
- if (entry.adopted) throw new Error('dsh-builtin-browser: the sidebar page this view was adopted from is gone')
127
- const deadline = options?.deadline ?? Date.now() + 30_000
128
- const transactionId = randomUUID()
129
- const cancel = (): void => { void this.connection.call({ op: 'cancelSidebar', handle: id, transactionId }, 2_000).catch(() => {}) }
130
- options?.signal?.addEventListener('abort', cancel, { once: true })
131
- let answer: Record<string, unknown>
132
- try {
133
- answer = await this.connection.call({ op: 'ensureSidebar', handle: id, deadline, transactionId,
134
- ...url ? { url, attachOnly: true } : {} }, Math.max(1, deadline - Date.now()))
135
- } finally { options?.signal?.removeEventListener('abort', cancel) }
136
- check()
137
- if (answer.ok !== true) {
138
- const code = String(answer.code ?? 'panel-initialization-failed')
139
- const detail = String(answer.error ?? 'sidebar unavailable')
140
- if (code === PANEL_NOT_DISPLAYED || code === PANEL_INITIALIZING) throw new BrowserPanelNotDisplayedError(detail, code)
141
- if (code === 'panel-unusable') this.lostListener?.('panel-unusable')
142
- throw Object.assign(new Error(`dsh-builtin-browser: sidebar unavailable (${detail})`), { code, initialization: answer.initialization })
143
- }
144
- if (answer.id !== id) throw new Error('dsh-builtin-browser: sidebar returned a different tab handle')
145
- entry.bound = true
146
- return answer.navigation && typeof answer.navigation === 'object' ? answer.navigation as Record<string, unknown> : undefined
147
- }
148
-
149
- createView(identity: BrowserTabWireId): ElectronViewHandle {
150
- const scope = sessionWireId(readTabHandle(identity))
151
- if (this.retiredSessions.has(scope)) throw new Error('dsh-builtin-browser: sidebar session was released')
152
- const id = identity
153
- this.activeScope = scope
154
- if (this.views.has(id)) throw new Error('dsh-builtin-browser: sidebar view is already bound')
155
- this.views.set(id, { scope, bound: false })
156
- let latestNavigation = 0
157
- return {
158
- id,
159
- download: async (url, savePath) => {
160
- await this.guestFor(id)
161
- const answer = await this.connection.call({ op: 'download', handle: id, url, savePath }, 60_000)
162
- if (answer.ok !== true) throw new Error(`dsh-builtin-browser: sidebar download failed: ${String(answer.error)}`)
163
- },
164
- sendCommand: async (method, params, options) => {
165
- const url = method === 'Page.navigate' ? String(params?.url ?? '') : undefined
166
- const sequence = url === undefined ? latestNavigation : ++latestNavigation
167
- const check = (): void => {
168
- if (sequence !== latestNavigation) throw Object.assign(new Error('a newer navigation was requested for this sidebar view'), { code: 'panel-navigation-superseded' })
169
- }
170
- const navigation = await this.guestFor(id, url, options, check)
171
- check()
172
- if (navigation !== undefined) return navigation
173
- const answer = await this.connection.call({ op: 'cdp', handle: id, method, params })
174
- if (answer.ok !== true) throw Object.assign(new Error(`dsh-builtin-browser: sidebar command failed: ${String(answer.error)}`), { code: answer.code })
175
- return (answer.result ?? {}) as Record<string, unknown>
176
- },
177
- }
178
- }
179
-
180
- destroyView(handle: ElectronViewHandle): void {
181
- const entry = this.views.get(handle.id)
182
- if (entry?.bound && !entry.adopted) this.orphaned.set(tabWireId(readTabHandle(handle.id)), entry.scope)
183
- this.views.delete(handle.id)
184
- }
185
-
186
- showView(handle: ElectronViewHandle, _label?: string, options?: { readonly quiet?: boolean; readonly select?: boolean }): void {
187
- if ((options?.quiet ?? this.isQuiet()) && options?.select !== true) return
188
- if (!this.views.get(handle.id)?.bound) return
189
- void this.connection.call({ op: 'showTab', handle: tabWireId(readTabHandle(handle.id)) }, 5_000).catch(() => {})
190
- }
191
-
192
- onUserAction(_handler: (action: BrowserUserAction) => void): void {}
193
-
194
- async presentView(handle: ElectronViewHandle, _label?: string, options?: { readonly quiet?: boolean; readonly select?: boolean }): Promise<void> {
195
- if ((options?.quiet ?? this.isQuiet()) && options?.select !== true) return
196
- const id = tabWireId(readTabHandle(handle.id))
197
- await this.guestFor(id)
198
- const answer = await this.connection.call({ op: 'showTab', handle: id })
199
- if (answer.ok !== true) throw Object.assign(new Error(String(answer.error ?? 'sidebar selection failed')), { code: answer.code })
200
- }
201
-
202
- async retireSession(scope: BrowserSessionWireId): Promise<void> {
203
- resolveSessionHandle(scope)
204
- if (this.retiredSessions.has(scope)) return
205
- this.retiredSessions.add(scope)
206
- const answer = await this.connection.call({ op: 'releaseSession', handle: scope })
207
- if (answer.ok !== true) throw new Error(String(answer.error ?? 'sidebar release failed'))
208
- for (const [id, held] of this.orphaned) if (held === scope) this.orphaned.delete(id)
209
- }
210
-
211
- async releasePage(scope?: BrowserSessionWireId): Promise<void> {
212
- if (scope !== undefined) resolveSessionHandle(scope)
213
- const mine = new Set<BrowserTabWireId>()
214
- const scopes = new Set<BrowserSessionWireId>()
215
- for (const [id, entry] of this.views) {
216
- if (scope !== undefined && entry.scope !== scope) continue
217
- scopes.add(entry.scope)
218
- if (entry.bound && !entry.adopted) mine.add(tabWireId(readTabHandle(id)))
219
- this.views.delete(id)
220
- }
221
- for (const [id, held] of this.orphaned) {
222
- if (scope !== undefined && held !== scope) continue
223
- scopes.add(sessionWireId(readTabHandle(id)))
224
- mine.add(tabWireId(readTabHandle(id)))
225
- this.orphaned.delete(id)
226
- }
227
- if (scope !== undefined) scopes.add(scope)
228
- try {
229
- const results = await Promise.allSettled([...mine].map(async id => {
230
- const answer = await this.connection.call({ op: 'closePage', handle: id }, 10_000)
231
- if (answer.ok !== true || answer.closed !== 1) throw new Error(String(answer.error ?? 'sidebar close not acknowledged'))
232
- }))
233
- const failure = results.find(result => result.status === 'rejected')
234
- if (failure?.status === 'rejected') throw failure.reason
235
- } finally {
236
- await Promise.all([...scopes].map(handle => this.retireSession(handle)))
237
- }
238
- }
239
-
240
- async collapse(): Promise<void> {
241
- if (this.activeScope === undefined) return
242
- await this.connection.call({ op: 'collapseSidebar', handle: this.activeScope }, 10_000).catch(() => {})
243
- }
244
-
245
- dispose(): void {
246
- this.connection.close()
247
- this.views.clear()
248
- this.orphaned.clear()
249
- this.activeScope = undefined
250
- }
251
- }