dsh-builtin-browser 1.0.3 → 1.1.0

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 (305) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.en.md +89 -0
  3. package/browser-extension/constants.mjs +20 -0
  4. package/browser-extension/controller.mjs +293 -0
  5. package/browser-extension/locales.mjs +15 -0
  6. package/browser-extension/manifest.json +12 -0
  7. package/browser-extension/options.html +14 -0
  8. package/browser-extension/options.mjs +9 -0
  9. package/browser-extension/permission-guard.mjs +13 -0
  10. package/browser-extension/worker.mjs +74 -0
  11. package/desktop-bridge/desktop-identity.json +10 -2
  12. package/desktop-bridge/install.mjs +28 -2
  13. package/docs/issue-replies-2026-11-28.md +141 -0
  14. package/dsh-host-patch/apply.mjs +1 -1
  15. package/dsh-host-patch/rc3.json +4 -4
  16. package/dsh-host-patch/rc5.json +4 -4
  17. package/dsh-host-patch/v023-alpha2.json +2 -2
  18. package/lib/browser-electron/bridge-status.js +24 -1
  19. package/lib/browser-electron/desktop-identity.js +47 -8
  20. package/lib/client.js +2 -1
  21. package/native-host/install.mjs +5 -0
  22. package/package.json +20 -2
  23. package/scripts/build-client.mjs +305 -0
  24. package/scripts/build.mjs +69 -0
  25. package/scripts/bundle-host.mjs +28 -0
  26. package/scripts/fix-exports.mjs +40 -0
  27. package/scripts/install-electron.mjs +101 -0
  28. package/scripts/pack.mjs +99 -0
  29. package/scripts/publish-manifest.mjs +56 -0
  30. package/scripts/verify-exports.mjs +58 -0
  31. package/scripts/verify-preview-sdk.mjs +93 -0
  32. package/skills/dsh-builtin-browser/SKILL.md +98 -0
  33. package/skills/dsh-builtin-browser/references/batch.md +68 -0
  34. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  35. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  36. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  37. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  38. package/skills/dsh-debug-host/SKILL.md +56 -0
  39. package/skills/dsh-debug-self/SKILL.md +50 -0
  40. package/src/bridge-compatibility.ts +39 -0
  41. package/src/browser/anti-bot.ts +251 -0
  42. package/src/browser/deep-dom.ts +40 -0
  43. package/src/browser/handles.ts +89 -0
  44. package/src/browser/runtime.ts +578 -0
  45. package/src/browser/takeover-target.ts +45 -0
  46. package/src/browser/types.ts +870 -0
  47. package/src/browser-electron/authenticated-route.ts +109 -0
  48. package/src/browser-electron/automatic-maintenance.ts +736 -0
  49. package/src/browser-electron/bridge-auto.ts +159 -0
  50. package/src/browser-electron/bridge-connection.ts +386 -0
  51. package/src/browser-electron/bridge-endpoint.ts +129 -0
  52. package/src/browser-electron/bridge-install.ts +290 -0
  53. package/src/browser-electron/bridge-maintenance.ts +189 -0
  54. package/src/browser-electron/bridge-status.ts +412 -0
  55. package/src/browser-electron/desktop-bridge-host.ts +253 -0
  56. package/src/browser-electron/desktop-identity.ts +400 -0
  57. package/src/browser-electron/desktop-shell.ts +100 -0
  58. package/src/browser-electron/document-readiness.ts +45 -0
  59. package/src/browser-electron/electron-provision.ts +347 -0
  60. package/src/browser-electron/entry.ts +1378 -0
  61. package/src/browser-electron/ephemeral-profile.ts +189 -0
  62. package/src/browser-electron/extension-browser.ts +230 -0
  63. package/src/browser-electron/extension-setup.ts +67 -0
  64. package/src/browser-electron/file-write.ts +31 -0
  65. package/src/browser-electron/foreground-watch.ts +142 -0
  66. package/src/browser-electron/guest-cookie-jar.ts +177 -0
  67. package/src/browser-electron/guest-cookie-store.ts +59 -0
  68. package/src/browser-electron/guest-css-runtime.ts +76 -0
  69. package/src/browser-electron/guest-css.ts +68 -0
  70. package/src/browser-electron/guest-route.ts +716 -0
  71. package/src/browser-electron/guest-runtime.ts +408 -0
  72. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  73. package/src/browser-electron/guest-storage.ts +120 -0
  74. package/src/browser-electron/history-store.ts +224 -0
  75. package/src/browser-electron/host-main.ts +1385 -0
  76. package/src/browser-electron/host-patch-maintenance.ts +121 -0
  77. package/src/browser-electron/http-body.ts +65 -0
  78. package/src/browser-electron/json-reply.ts +47 -0
  79. package/src/browser-electron/maintenance-broker.ts +166 -0
  80. package/src/browser-electron/maintenance-lifecycle.ts +91 -0
  81. package/src/browser-electron/maintenance-route.ts +68 -0
  82. package/src/browser-electron/missing-system-browser.ts +114 -0
  83. package/src/browser-electron/open-slot.ts +49 -0
  84. package/src/browser-electron/paths.ts +25 -0
  85. package/src/browser-electron/preferred-browser.ts +130 -0
  86. package/src/browser-electron/preview-route.ts +215 -0
  87. package/src/browser-electron/process-ownership.ts +174 -0
  88. package/src/browser-electron/process.ts +23 -0
  89. package/src/browser-electron/profile-checkpoint.ts +187 -0
  90. package/src/browser-electron/profile-command.ts +47 -0
  91. package/src/browser-electron/profile-extension.ts +129 -0
  92. package/src/browser-electron/profile-lease.ts +211 -0
  93. package/src/browser-electron/profile-residue.ts +49 -0
  94. package/src/browser-electron/provider-core.ts +1107 -0
  95. package/src/browser-electron/provider-interaction.ts +1034 -0
  96. package/src/browser-electron/provider-media.ts +589 -0
  97. package/src/browser-electron/provider-navigation.ts +323 -0
  98. package/src/browser-electron/provider-observation.ts +664 -0
  99. package/src/browser-electron/provider-tabs.ts +372 -0
  100. package/src/browser-electron/provider.ts +666 -0
  101. package/src/browser-electron/reference-route.ts +598 -0
  102. package/src/browser-electron/remote-host.ts +1538 -0
  103. package/src/browser-electron/rpc-input.ts +13 -0
  104. package/src/browser-electron/rpc-ops.ts +41 -0
  105. package/src/browser-electron/runtime-diagnostics.ts +38 -0
  106. package/src/browser-electron/runtime-route.ts +105 -0
  107. package/src/browser-electron/runtime-status.ts +309 -0
  108. package/src/browser-electron/settings-route.ts +64 -0
  109. package/src/browser-electron/settings-store.ts +593 -0
  110. package/src/browser-electron/shortcuts-route.ts +112 -0
  111. package/src/browser-electron/sidebar-only-host.ts +300 -0
  112. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  113. package/src/browser-electron/system-browser.ts +1850 -0
  114. package/src/browser-electron/tauri-host.ts +194 -0
  115. package/src/browser-electron/timing.ts +16 -0
  116. package/src/browser-electron/virtual-cursor.ts +162 -0
  117. package/src/browser-electron/windows-system.ts +24 -0
  118. package/src/browser-reference/delivery.ts +384 -0
  119. package/src/browser-reference/entry.ts +631 -0
  120. package/src/browser-reference/export.ts +339 -0
  121. package/src/browser-reference/import.ts +303 -0
  122. package/src/browser-reference/page-script.ts +1537 -0
  123. package/src/browser-reference/service.ts +1346 -0
  124. package/src/browser-reference/store.ts +172 -0
  125. package/src/browser-reference/text-quote.ts +219 -0
  126. package/src/browser-reference/types.ts +195 -0
  127. package/src/browser-reference/visible.ts +367 -0
  128. package/src/browser-reference/web-sources.ts +106 -0
  129. package/src/client/apply-guard.ts +22 -0
  130. package/src/client/browser/BrowserController.ts +693 -0
  131. package/src/client/browser/BrowserFrame.ts +78 -0
  132. package/src/client/browser/BrowserNavigation.ts +169 -0
  133. package/src/client/browser/BrowserPage.ts +23 -0
  134. package/src/client/browser/BrowserPersistence.ts +44 -0
  135. package/src/client/browser/IframeImpl.ts +182 -0
  136. package/src/client/browser/child-tabs.ts +14 -0
  137. package/src/client/browser/frame-history.ts +125 -0
  138. package/src/client/browser/frame-state.ts +27 -0
  139. package/src/client/browser/iframe-reference.ts +67 -0
  140. package/src/client/browser/initialization.ts +262 -0
  141. package/src/client/browser/omnibox.ts +243 -0
  142. package/src/client/browser/store.ts +38 -0
  143. package/src/client/browser/takeover-channel.ts +72 -0
  144. package/src/client/browser/url.ts +46 -0
  145. package/src/client/browser/web-reference-source.ts +56 -0
  146. package/src/client/css-modules.d.ts +4 -0
  147. package/src/client/definition.tsx +36 -0
  148. package/src/client/electron/ElectronWebViewImpl.ts +371 -0
  149. package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
  150. package/src/client/electron/NativeChildPresentation.ts +53 -0
  151. package/src/client/electron/NativeViewPage.ts +265 -0
  152. package/src/client/electron/pages.ts +23 -0
  153. package/src/client/electron/reference-overlay.ts +53 -0
  154. package/src/client/electron/workspace.ts +33 -0
  155. package/src/client/index.ts +333 -0
  156. package/src/client/locales.ts +860 -0
  157. package/src/client/pages.ts +28 -0
  158. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  159. package/src/client/reference/client/draft-reference.ts +167 -0
  160. package/src/client/reference/client/index.ts +7 -0
  161. package/src/client/reference/client/ordered-submission.ts +108 -0
  162. package/src/client/reference/client/pending-delivery.ts +216 -0
  163. package/src/client/reference/client/plugin.ts +208 -0
  164. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  165. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  166. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  167. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  168. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  169. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  170. package/src/client/reference/client/production/assembly.ts +447 -0
  171. package/src/client/reference/client/production/asset-store.ts +144 -0
  172. package/src/client/reference/client/production/availability.ts +72 -0
  173. package/src/client/reference/client/production/bytes.ts +36 -0
  174. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  175. package/src/client/reference/client/production/delivery-client.ts +211 -0
  176. package/src/client/reference/client/production/draft-adapter.ts +512 -0
  177. package/src/client/reference/client/production/http-transport.ts +212 -0
  178. package/src/client/reference/client/production/production-submission.ts +70 -0
  179. package/src/client/reference/client/production/protocol.ts +234 -0
  180. package/src/client/reference/client/production/reference-card.ts +240 -0
  181. package/src/client/reference/client/production/reference-labels.ts +29 -0
  182. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  183. package/src/client/reference/client/production/reveal.ts +215 -0
  184. package/src/client/reference/client/production/runtime.ts +1056 -0
  185. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  186. package/src/client/reference/client/production/source-marker.ts +99 -0
  187. package/src/client/reference/client/production/source-opener.ts +55 -0
  188. package/src/client/reference/client/production/styles.ts +104 -0
  189. package/src/client/reference/client/production/user-text-rule.ts +67 -0
  190. package/src/client/reference/client/reveal.ts +109 -0
  191. package/src/client/reference/client/scheme.ts +114 -0
  192. package/src/client/reference/client/session-schedule.ts +36 -0
  193. package/src/client/reference/client/types.ts +168 -0
  194. package/src/client/reference/css-modules.d.ts +4 -0
  195. package/src/client/reference/index.ts +11 -0
  196. package/src/client/reference-capture-owner.ts +162 -0
  197. package/src/client/reference-intents.ts +36 -0
  198. package/src/client/settings/index.ts +42 -0
  199. package/src/client/settings/mount-guard.ts +31 -0
  200. package/src/client/settings/panel.ts +2773 -0
  201. package/src/client/shortcut-open.ts +30 -0
  202. package/src/client/startpage/binding.ts +99 -0
  203. package/src/client/startpage/controller.ts +300 -0
  204. package/src/client/startpage/model.ts +279 -0
  205. package/src/client/view/Browser.module.css +751 -0
  206. package/src/client/view/BrowserBody.tsx +315 -0
  207. package/src/client/view/BrowserPresentation.ts +9 -0
  208. package/src/client/view/BrowserTitle.tsx +17 -0
  209. package/src/client/view/IframePresentation.ts +365 -0
  210. package/src/client/view/StartPage.tsx +598 -0
  211. package/src/client/view/TakeoverBanner.tsx +21 -0
  212. package/src/compat/host-features.ts +92 -0
  213. package/src/index.ts +110 -0
  214. package/src/reference-owner.ts +5 -0
  215. package/src/reference-page.ts +9 -0
  216. package/src/reference-source.ts +3 -0
  217. package/src/reference-text.ts +219 -0
  218. package/src/startpage-settings.ts +103 -0
  219. package/src/startpage.ts +71 -0
  220. package/src/takeover-protocol.ts +28 -0
  221. package/src/tool-browser/block-recovery.ts +85 -0
  222. package/src/tool-browser/code-tool.ts +555 -0
  223. package/src/tool-browser/code-worker.ts +725 -0
  224. package/src/tool-browser/element-fields.ts +167 -0
  225. package/src/tool-browser/errors.ts +40 -0
  226. package/src/tool-browser/index.ts +265 -0
  227. package/src/tool-browser/page-probe.ts +675 -0
  228. package/src/tool-browser/panel-page.ts +126 -0
  229. package/src/tool-browser/probe-client.ts +183 -0
  230. package/src/tool-browser/screenshot-annotations.ts +131 -0
  231. package/src/tool-browser/screenshot-image.ts +49 -0
  232. package/src/tool-browser/state.ts +375 -0
  233. package/src/tool-browser/takeover.ts +199 -0
  234. package/src/tool-browser/tools-debug.ts +806 -0
  235. package/src/tool-browser/tools-interaction.ts +956 -0
  236. package/src/tool-browser/tools-navigation.ts +786 -0
  237. package/src/tool-browser/tools-observation.ts +474 -0
  238. package/src/tool-browser/tools-reference.ts +294 -0
  239. package/src/types/electron-shim.d.ts +144 -0
  240. package/src/types.ts +85 -0
  241. package/src/web-guest.ts +35 -0
  242. package/tools/accept-desktop.mjs +148 -0
  243. package/dist/client.d.cts +0 -516
  244. package/dist/client.d.mts +0 -516
  245. package/dist/index.cjs +0 -92
  246. package/dist/index.d.mts +0 -2960
  247. package/dist/index.mjs +0 -24
  248. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  249. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  250. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  251. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  252. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  253. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  254. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  255. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  256. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  257. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  258. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  259. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  260. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  261. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  262. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  263. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  264. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  265. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  266. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  267. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  268. package/dsh-host-patch/sources/manifest.json +0 -218
  269. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  270. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  271. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  272. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  273. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  274. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  275. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  276. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  277. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  278. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  279. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  280. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  281. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  282. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  283. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  284. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  285. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  286. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  287. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  288. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  289. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  290. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  291. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  292. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  293. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  294. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  295. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  296. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  297. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  298. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  299. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  300. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  301. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  302. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  303. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  304. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  305. package/dsh-host-patch/sources/series.json +0 -260
@@ -0,0 +1,294 @@
1
+ /**
2
+ * Reference tools: capture, reveal and list what the human selected in the page.
3
+ * @module dsh-browser/tool-browser/tools-reference
4
+ */
5
+
6
+ import { defineTool } from '@deepseek-ai/dsh-tools'
7
+ import { createReferenceService, summarizeReference, type BrowserReferenceService } from '../browser-reference/service.ts'
8
+ import type { BrowserReferenceCarrier } from '../browser-reference/types.ts'
9
+ import { resolveSessionHandle, sessionWireId } from '../browser/handles.ts'
10
+ import { agentOf, taskKey, ensureSession, panelBound, type ToolScope, type ToolDefinition } from './state.ts'
11
+
12
+ /**
13
+ * Define this module's tools for one apply.
14
+ * @param scope - the apply's context, settings and per-apply state.
15
+ * @returns the tool definitions, for the entry to register.
16
+ */
17
+ export function referenceTools(scope: ToolScope): ToolDefinition[] {
18
+ const { ctx, state, settingsStore, timeoutMs } = scope
19
+ const tools: ToolDefinition[] = []
20
+
21
+ // Built on first use, not at apply time: the provider is registered by another plugin's apply,
22
+ // and a tool registered before the browser exists must still work once it does.
23
+ let referenceService: BrowserReferenceService | undefined
24
+ const references = (): BrowserReferenceService => {
25
+ if (referenceService !== undefined) return referenceService
26
+ const browser = ctx.get('browser')
27
+ if (browser === undefined) throw new Error('tool-browser: browser service unavailable')
28
+ // Keep the SAME image fallback as the floating bar and the HTTP capture
29
+ // (browser-electron/entry.ts): a clipped visible-region read lets an image
30
+ // whose source URL cannot be downloaded still become a real reference.
31
+ referenceService = createReferenceService(browser, {
32
+ visibleCapture: async (sessionId, clip, signal) => {
33
+ const shot = await browser.screenshot(sessionWireId(resolveSessionHandle(sessionId)), { clip, format: 'png' }, signal)
34
+ return { dataUrl: shot.dataUrl, mime: 'image/png' }
35
+ },
36
+ })
37
+ return referenceService
38
+ }
39
+ const referenceCarrier = (): BrowserReferenceCarrier => {
40
+ const channel = settingsStore.get().browser.channel
41
+ return channel === 'sidebar' || channel === 'chrome' || channel === 'edge' ? channel : 'bundled'
42
+ }
43
+
44
+ tools.push(defineTool({
45
+ name: 'dsh_browser_reference_capture',
46
+ description: 'Capture what the human has selected in the shared-browser page as a durable reference, so it can be quoted and found again later. The reference keeps the selected text with enough surrounding context to relocate it, any images selected with their real bytes, and any table as a structural snapshot. Tool-only captures are stored for later dsh_browser_reference_reveal or export and do not create a chat capsule; do not emit dsh-browser-ref: URIs, reference markers, or synthetic source links in the reply. Re-capturing the same region creates a NEW reference, because a stored reference is an immutable snapshot.',
47
+ parameters: {
48
+ allowPartial: { type: 'boolean', description: 'Commit the fragments that succeeded when another fragment failed (default false: a group with a broken image or oversized table is refused as a whole).' },
49
+ tableSelector: { type: 'string', description: 'Capture this table whole (CSS selector) even when the selection does not touch it.' },
50
+ excerptText: { type: 'string', description: 'With no live selection, register the first occurrence of this exact page text as an agent excerpt. Two occurrences make it ambiguous and are refused.' },
51
+ },
52
+ output: {
53
+ schema: {
54
+ type: 'object',
55
+ additionalProperties: false,
56
+ properties: {
57
+ ok: { type: 'boolean', required: true },
58
+ referenceId: { type: 'string' },
59
+ pageUrl: { type: 'string' },
60
+ title: { type: 'string' },
61
+ parts: {
62
+ type: 'array',
63
+ required: true,
64
+ items: {
65
+ type: 'object',
66
+ additionalProperties: false,
67
+ properties: {
68
+ partId: { type: 'string', required: true },
69
+ type: { type: 'string', required: true },
70
+ preview: { type: 'string', required: true },
71
+ },
72
+ },
73
+ },
74
+ failures: {
75
+ type: 'array',
76
+ required: true,
77
+ items: {
78
+ type: 'object',
79
+ additionalProperties: false,
80
+ properties: {
81
+ kind: { type: 'string', required: true },
82
+ reason: { type: 'string', required: true },
83
+ },
84
+ },
85
+ },
86
+ },
87
+ },
88
+ render: (_args, value) => {
89
+ if (value.ok !== true) {
90
+ const reasons = value.failures.map(failure => `${failure.kind}: ${failure.reason}`).join('; ')
91
+ return [{ type: 'text', text: `Nothing was captured. ${reasons}` }]
92
+ }
93
+ const lines = [
94
+ `Reference ${value.referenceId} captured from ${value.title !== undefined && value.title !== '' ? value.title : value.pageUrl}.`,
95
+ 'Stored in the reference library for dsh_browser_reference_reveal or export (tool-only captures do not create a chat capsule). Do not emit dsh-browser-ref: URIs or reference markers in the reply.',
96
+ ...value.parts.map(part => ` ${part.partId} (${part.type}): ${part.preview}`),
97
+ ]
98
+ if (value.failures.length > 0) lines.push(`(${value.failures.length} fragment(s) failed and were left out: ${value.failures.map(failure => failure.reason).join('; ')})`)
99
+ return [{ type: 'text', text: lines.join('\n') }]
100
+ },
101
+ },
102
+ timeoutMs,
103
+ isConcurrencySafe: () => false,
104
+ async execute(args, exec) {
105
+ const browser = ctx.get('browser')
106
+ if (browser === undefined) throw new Error('tool-browser: browser service unavailable')
107
+ const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec))
108
+ const outcome = await references().capture({
109
+ // The DSH session owns the reference; the provider session holds the page. They are
110
+ // different ids, and reveal needs the second one even after the first is long gone.
111
+ sessionId: taskKey(exec),
112
+ browserSessionId: session,
113
+ origin: args.excerptText !== undefined ? 'agent-excerpt' : 'user-selection',
114
+ entry: 'agent-tool',
115
+ carrier: panelBound(state, taskKey(exec)) ? 'sidebar' : referenceCarrier(),
116
+ ...args.allowPartial !== undefined ? { allowPartial: args.allowPartial } : {},
117
+ ...args.tableSelector !== undefined ? { tableSelector: args.tableSelector } : {},
118
+ ...args.excerptText !== undefined ? { excerptText: args.excerptText } : {},
119
+ }, exec.signal)
120
+ const failures = outcome.failures.map(failure => ({ kind: failure.kind, reason: failure.reason }))
121
+ if (outcome.reference === undefined) return { ok: false, parts: [], failures }
122
+ const summary = summarizeReference(outcome.reference)
123
+ return {
124
+ ok: true,
125
+ referenceId: summary.referenceId,
126
+ pageUrl: summary.pageUrl,
127
+ title: summary.title,
128
+ // The summary's arrays are readonly; the schema declares a mutable array,
129
+ // so the parts are projected into plain objects rather than cast away.
130
+ parts: summary.parts.map(part => ({ partId: part.partId, type: part.type, preview: part.preview })),
131
+ failures,
132
+ }
133
+ },
134
+ }))
135
+
136
+ tools.push(defineTool({
137
+ name: 'dsh_browser_reference_reveal',
138
+ description: 'Return to a stored browser reference: select the browser session that captured it, verify the page is still the same one, then scroll to and highlight the part. Without partId the reference\'s first part is located; pass a partId to locate one specific fragment. A result status of page-mismatch means the session is showing another page (open the stored pageUrl first); ambiguous means several candidates matched equally and the exact one cannot be chosen; session-unavailable means the browser that captured it is gone.',
139
+ parameters: {
140
+ referenceId: { type: 'string', required: true, description: 'The reference id, with or without the dsh-browser-ref: prefix.' },
141
+ partId: { type: 'string', description: 'Locate this fragment instead of the whole reference\'s first part.' },
142
+ },
143
+ output: {
144
+ schema: {
145
+ type: 'object',
146
+ additionalProperties: false,
147
+ properties: {
148
+ status: { type: 'string', required: true },
149
+ pageUrl: { type: 'string', required: true },
150
+ currentUrl: { type: 'string' },
151
+ note: { type: 'string' },
152
+ parts: {
153
+ type: 'array',
154
+ required: true,
155
+ items: {
156
+ type: 'object',
157
+ additionalProperties: false,
158
+ properties: {
159
+ partId: { type: 'string', required: true },
160
+ type: { type: 'string', required: true },
161
+ status: { type: 'string', required: true },
162
+ matches: { type: 'number' },
163
+ collapsed: { type: 'boolean' },
164
+ note: { type: 'string' },
165
+ },
166
+ },
167
+ },
168
+ },
169
+ },
170
+ render: (_args, value) => {
171
+ const head = value.status === 'revealed'
172
+ ? 'Located the reference in the page.'
173
+ : `Could not locate the reference: ${value.status}${value.note !== undefined ? ` — ${value.note}` : ''}`
174
+ const lines = [head, ...value.parts.map(part => ` ${part.partId} (${part.type}): ${part.status}${part.matches !== undefined ? `, ${part.matches} match(es)` : ''}${part.collapsed === true ? ', whitespace-collapsed' : ''}${part.note !== undefined ? ` — ${part.note}` : ''}`)]
175
+ return [{ type: 'text', text: lines.join('\n') }]
176
+ },
177
+ },
178
+ timeoutMs,
179
+ isConcurrencySafe: () => false,
180
+ async execute(args, exec) {
181
+ // The documented citation form is `dsh-browser-ref:<referenceId>/<partId?>`; accept it
182
+ // whole so a model can paste what it wrote instead of splitting the id by hand.
183
+ let referenceId = args.referenceId.startsWith('dsh-browser-ref:') ? args.referenceId.slice('dsh-browser-ref:'.length) : args.referenceId
184
+ let partId = args.partId
185
+ const slash = referenceId.indexOf('/')
186
+ if (slash !== -1) {
187
+ if (partId === undefined) partId = referenceId.slice(slash + 1)
188
+ referenceId = referenceId.slice(0, slash)
189
+ }
190
+ const outcome = await references().reveal(referenceId, {
191
+ ownerSessionId: taskKey(exec),
192
+ ...partId !== undefined && partId !== '' ? { partId } : {},
193
+ }, exec.signal)
194
+ return {
195
+ status: outcome.status,
196
+ pageUrl: outcome.pageUrl,
197
+ ...outcome.currentUrl !== undefined ? { currentUrl: outcome.currentUrl } : {},
198
+ ...outcome.note !== undefined ? { note: outcome.note } : {},
199
+ parts: outcome.parts.map(part => ({
200
+ partId: part.partId,
201
+ type: part.type,
202
+ status: part.status,
203
+ ...part.matches !== undefined ? { matches: part.matches } : {},
204
+ ...part.collapsed !== undefined ? { collapsed: part.collapsed } : {},
205
+ ...part.note !== undefined ? { note: part.note } : {},
206
+ })),
207
+ }
208
+ },
209
+ }))
210
+
211
+ tools.push(defineTool({
212
+ name: 'dsh_browser_reference_list',
213
+ description: 'List the browser references stored for this task, newest first: id, page, capture time, and one preview line per fragment. Use it to identify a reference from earlier in the conversation. Source navigation is provided by reference capsules; do not repeat reference URIs, source URLs, markers, or source/citation links in the reply.',
214
+ parameters: {
215
+ limit: { type: 'number', description: 'Most references to return (default 20, maximum 100).' },
216
+ },
217
+ output: {
218
+ schema: {
219
+ type: 'object',
220
+ additionalProperties: false,
221
+ properties: {
222
+ references: {
223
+ type: 'array',
224
+ required: true,
225
+ items: {
226
+ type: 'object',
227
+ additionalProperties: false,
228
+ properties: {
229
+ referenceId: { type: 'string', required: true },
230
+ title: { type: 'string', required: true },
231
+ pageUrl: { type: 'string', required: true },
232
+ capturedAt: { type: 'string', required: true },
233
+ carrier: { type: 'string', required: true },
234
+ origin: { type: 'string', required: true },
235
+ entry: { type: 'string', required: true },
236
+ partCount: { type: 'number', required: true },
237
+ parts: {
238
+ type: 'array',
239
+ required: true,
240
+ items: {
241
+ type: 'object',
242
+ additionalProperties: false,
243
+ properties: {
244
+ partId: { type: 'string', required: true },
245
+ type: { type: 'string', required: true },
246
+ preview: { type: 'string', required: true },
247
+ },
248
+ },
249
+ },
250
+ },
251
+ },
252
+ },
253
+ },
254
+ },
255
+ render: (_args, value) => {
256
+ if (value.references.length === 0) return [{ type: 'text', text: 'No browser references are stored for this task.' }]
257
+ return [{
258
+ type: 'text',
259
+ text: value.references.map(reference => [
260
+ `Reference ${reference.referenceId} — ${reference.title !== '' ? reference.title : reference.pageUrl} (${reference.capturedAt}); source navigation is in its capsule, not a reply link.`,
261
+ ...reference.parts.map(part => ` ${part.partId} (${part.type}): ${part.preview}`),
262
+ ].join('\n')).join('\n\n'),
263
+ }]
264
+ },
265
+ },
266
+ timeoutMs,
267
+ isConcurrencySafe: () => true,
268
+ async execute(args, exec) {
269
+ const key = taskKey(exec)
270
+ const limit = Math.min(Math.max(Math.trunc(args.limit ?? 20), 1), 100)
271
+ // Always scoped: with no agent the key is `default`, and an unfiltered read
272
+ // would hand this task every conversation's references.
273
+ const stored = references().list({ sessionId: key, limit })
274
+ return {
275
+ references: stored.slice().reverse().map(reference => {
276
+ const summary = summarizeReference(reference)
277
+ return {
278
+ referenceId: summary.referenceId,
279
+ title: summary.title,
280
+ pageUrl: summary.pageUrl,
281
+ capturedAt: summary.capturedAt,
282
+ carrier: summary.carrier,
283
+ origin: summary.origin,
284
+ entry: summary.entry,
285
+ partCount: summary.partCount,
286
+ parts: summary.parts.map(part => ({ partId: part.partId, type: part.type, preview: part.preview })),
287
+ }
288
+ }),
289
+ }
290
+ },
291
+ }))
292
+
293
+ return tools
294
+ }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Ambient declaration for the `electron` module used by the self-hosted
3
+ * browser host (`host-main.ts`). The electron package is a bundled runtime
4
+ * dependency, but its type definitions can be absent when the published
5
+ * `src/` is typechecked standalone; this shim keeps typechecking
6
+ * self-contained.
7
+ * @module dsh-browser/types/electron-shim
8
+ */
9
+
10
+ declare module 'electron' {
11
+ export interface WebContentsDebugger {
12
+ attach(version: string): void
13
+ detach(): void
14
+ sendCommand(method: string, params?: Record<string, unknown>): Promise<unknown>
15
+ }
16
+ export interface DownloadItem {
17
+ setSavePath(path: string): void
18
+ }
19
+ export interface Cookie {
20
+ domain: string
21
+ path: string
22
+ secure: boolean
23
+ httpOnly: boolean
24
+ name: string
25
+ value: string
26
+ expirationDate?: number
27
+ }
28
+ export interface CookieSetter {
29
+ url: string
30
+ name: string
31
+ value: string
32
+ domain?: string
33
+ path?: string
34
+ secure?: boolean
35
+ httpOnly?: boolean
36
+ expirationDate?: number
37
+ }
38
+ export interface Session {
39
+ getPreloads(): string[]
40
+ setPreloads(preloads: string[]): void
41
+ once(event: 'will-download', listener: (event: Event, item: DownloadItem) => void): void
42
+ readonly cookies: {
43
+ get(filter: Record<string, unknown>): Promise<Cookie[]>
44
+ set(details: CookieSetter): Promise<void>
45
+ }
46
+ }
47
+ export interface NativeImage {
48
+ toPNG(): Buffer
49
+ toJPEG(quality: number): Buffer
50
+ getSize(): { width: number; height: number }
51
+ resize(options: { width?: number; height?: number }): NativeImage
52
+ }
53
+ export interface WebContents {
54
+ readonly id: number
55
+ readonly debugger: WebContentsDebugger
56
+ readonly session: Session
57
+ close(): void
58
+ downloadURL(url: string): void
59
+ capturePage(): Promise<NativeImage>
60
+ loadURL(url: string): Promise<void>
61
+ loadFile(path: string): Promise<void>
62
+ send(channel: string, payload: unknown): void
63
+ focus(): void
64
+ isFocused(): boolean
65
+ executeJavaScript(code: string): Promise<unknown>
66
+ setWindowOpenHandler(handler: (details: { url: string }) => { action: 'deny' } | { action: 'allow' }): void
67
+ getTitle(): string
68
+ getURL(): string
69
+ on(event: 'ipc-message', listener: (event: unknown, channel: string, ...args: unknown[]) => void): this
70
+ on(event: 'context-menu', listener: (event: unknown, params: { selectionText: string; mediaType: string; srcURL: string; x: number; y: number }) => void): this
71
+ // Windows keyboard focus routing: clicks reach any view, but keyboard
72
+ // events go only to the focused webContents (electron#28163). `input` is
73
+ // the raw input event; only its `type` is consumed here.
74
+ on(event: 'input-event', listener: (event: unknown, input: { type: string }) => void): this
75
+ on(event: 'page-title-updated' | 'did-navigate' | 'did-navigate-in-page' | 'dom-ready', listener: (event: unknown, ...args: unknown[]) => void): this
76
+ }
77
+ export interface WebContentsView {
78
+ readonly webContents: WebContents
79
+ setBounds(bounds: { x: number; y: number; width: number; height: number }): void
80
+ setVisible(visible: boolean): void
81
+ getVisible(): boolean
82
+ getBounds(): { x: number; y: number; width: number; height: number }
83
+ }
84
+ export interface BrowserWindow {
85
+ readonly webContents: WebContents
86
+ readonly contentView: {
87
+ addChildView(view: WebContentsView): void
88
+ removeChildView(view: WebContentsView): void
89
+ readonly children: WebContentsView[]
90
+ }
91
+ getContentSize(): [number, number]
92
+ isVisible(): boolean
93
+ isMinimized(): boolean
94
+ isFocused(): boolean
95
+ show(): void
96
+ /**
97
+ * Show the window without activating the application or taking keyboard focus.
98
+ *
99
+ * Not in the type definitions of older Electron releases, but present since Electron 2 —
100
+ * quiet mode (`ui.quiet`) depends on it to give a view a display surface without stealing
101
+ * the foreground.
102
+ */
103
+ showInactive(): void
104
+ restore(): void
105
+ focus(): void
106
+ moveTop(): void
107
+ close(): void
108
+ setTitle(title: string): void
109
+ getOpacity(): number
110
+ setOpacity(opacity: number): void
111
+ setSkipTaskbar(skip: boolean): void
112
+ setFocusable(focusable: boolean): void
113
+ on(event: 'closed', listener: () => void): this
114
+ on(event: 'resize', listener: () => void): this
115
+ on(event: 'focus', listener: () => void): this
116
+ off(event: 'closed', listener: () => void): this
117
+ off(event: 'resize', listener: () => void): this
118
+ off(event: 'focus', listener: () => void): this
119
+ }
120
+ export const app: {
121
+ readonly commandLine: {
122
+ getSwitchValue(name: string): string
123
+ appendSwitch(name: string, value?: string): void
124
+ }
125
+ on(event: 'web-contents-created', listener: (event: unknown, contents: WebContents) => void): void
126
+ quit(): void
127
+ whenReady(): Promise<void>
128
+ exit(code?: number): void
129
+ getPath(name: string): string
130
+ setPath(name: string, path: string): void
131
+ }
132
+ export const session: { readonly defaultSession: Session }
133
+ export const Menu: {
134
+ buildFromTemplate(template: Array<{ type?: 'separator'; role?: string; label?: string; id?: string; click?: () => void }>): { popup(): void }
135
+ }
136
+ export interface BrowserWindowConstructor {
137
+ new(options?: Record<string, unknown>): BrowserWindow
138
+ }
139
+ export interface WebContentsViewConstructor {
140
+ new(options?: Record<string, unknown>): WebContentsView
141
+ }
142
+ export const BrowserWindow: BrowserWindowConstructor
143
+ export const WebContentsView: WebContentsViewConstructor
144
+ }
package/src/types.ts ADDED
@@ -0,0 +1,85 @@
1
+ /** Type-only Electron bridge declarations shared by the desktop shell and browser provider. */
2
+ import type { Branded } from '@deepseek-ai/dsh-brand'
3
+
4
+ export type DesktopNativeLease = Branded<'DesktopNativeLease'>
5
+ export type SidebarNativeSlot = Branded<'SidebarNativeSlot'>
6
+
7
+ export interface DesktopNativeState {
8
+ readonly stage: 'attached' | 'document' | 'closed' | 'failed'
9
+ readonly generation: string
10
+ readonly frameId?: string
11
+ readonly loaderId?: string
12
+ readonly code?: string
13
+ }
14
+
15
+ export interface DesktopNativeViews {
16
+ readonly protocolVersion: 1
17
+ readonly persistentSession?: true
18
+ acquire(scope: string, workspace: string, persistent?: boolean): Promise<{ readonly lease: DesktopNativeLease }>
19
+ attach(lease: DesktopNativeLease, slot: SidebarNativeSlot): Promise<void>
20
+ command(lease: DesktopNativeLease, method: string, params?: object): Promise<object>
21
+ onState(lease: DesktopNativeLease, listener: (state: DesktopNativeState) => void): () => void
22
+ release(lease: DesktopNativeLease): Promise<void>
23
+ }
24
+
25
+ /** Main-issued identity of one guest reservation. */
26
+ export type DesktopBrowserLeaseId = Branded<'DesktopBrowserLeaseId'>
27
+
28
+ /** A guest's approved, process-local storage partition. */
29
+ export interface DesktopBrowserReservation {
30
+ readonly lease: DesktopBrowserLeaseId
31
+ readonly partition: string
32
+ }
33
+
34
+ /** Main-approved request to open an HTTP(S) page from an existing guest. */
35
+ export interface DesktopBrowserOpenRequest {
36
+ readonly lease: DesktopBrowserLeaseId
37
+ readonly url: string
38
+ }
39
+
40
+ export interface BrowserChildTabRequest {
41
+ readonly mode: 'url-only' | 'native-opener'
42
+ readonly url: string
43
+ }
44
+
45
+ export type BrowserChildTabResult =
46
+ | { readonly status: 'url-only-dispatched' }
47
+ | { readonly status: 'unsupported'; readonly code: 'BROWSER_NATIVE_CHILD_UNAVAILABLE' | 'invalid-child-url' | 'guest-disposed' | 'sidebar-tab-dispatch-failed' }
48
+
49
+ export interface DesktopBrowserChildTabs {
50
+ readonly protocolVersion: 1
51
+ /** Native opener requests must wait for the decision; denial must never create a window. */
52
+ onRequested(lease: DesktopBrowserLeaseId, listener: (request: BrowserChildTabRequest) => BrowserChildTabResult): () => void
53
+ }
54
+
55
+ export interface DesktopNativeChild {
56
+ readonly request: string
57
+ readonly opener: string
58
+ readonly child: string
59
+ readonly lease: DesktopNativeLease
60
+ readonly target: string
61
+ readonly url: string
62
+ readonly disposition: string
63
+ }
64
+
65
+ export interface DesktopNativeChildTabs {
66
+ readonly protocolVersion: 2
67
+ registerOwner(parent: string, slot: SidebarNativeSlot): Promise<() => void>
68
+ onCreated(parent: string, listener: (child: DesktopNativeChild) => void): () => void
69
+ onClosed(parent: string, listener: (child: DesktopNativeChild) => void): () => void
70
+ adopt(request: string, slot: SidebarNativeSlot): Promise<{ child: string; lease: DesktopNativeLease }>
71
+ }
72
+
73
+ /** Origin-scoped operations; no Electron objects or arbitrary IPC cross this interface. */
74
+ export interface DesktopBrowserBridge {
75
+ readonly persistentSession?: true
76
+ readonly nativeViews?: DesktopNativeViews
77
+ /** Version 1 supports URL-only requests; version 2 adopts native WindowProxy children. */
78
+ readonly childTabs?: DesktopBrowserChildTabs | DesktopNativeChildTabs
79
+ /** @param workspace - resolved storage account. @returns one approved guest reservation. */
80
+ acquire(workspace: string, persistent?: boolean): Promise<DesktopBrowserReservation>
81
+ /** @param lease - the caller's reservation. @returns after its guest has been destroyed. */
82
+ release(lease: DesktopBrowserLeaseId): Promise<void>
83
+ /** Legacy URL-only notifications. These do not promise a child WindowProxy or opener. */
84
+ onOpenRequested(lease: DesktopBrowserLeaseId, listener: (url: string) => void): () => void
85
+ }
@@ -0,0 +1,35 @@
1
+ /** Register only the CSP-sandboxed opaque-origin guest endpoint. */
2
+ import type { Context } from '@deepseek-ai/cordis'
3
+ import { overlayScript } from './browser-reference/entry.ts'
4
+ import { GUEST_ROUTE, handleGuest } from './browser-electron/guest-route.ts'
5
+
6
+ /**
7
+ * 浮条安装脚本;链接和表单由 guest runtime 统一处理。
8
+ * @returns 注入到每个代理 HTML 末尾的 `<script>`。
9
+ */
10
+ function overlayTag(): string {
11
+ const source = overlayScript().replace(/<\/script/giu, '<\\/script')
12
+ return `<script data-dsh-ref-overlay-inline="1">(function(){\n${source}\n})()</script>`
13
+ }
14
+
15
+ /**
16
+ * 在宿主侧注册 guest 代理路由(需要 `webServer`;没有该服务的环境安静跳过)。
17
+ * @param ctx - 插件容器。
18
+ */
19
+ export function registerWebGuest(ctx: Context): void {
20
+ const inject = (ctx as unknown as {
21
+ inject?: (names: readonly string[], callback: (host: {
22
+ readonly webServer: { register(route: { kind: string; path: string; auth?: 'anonymous' | 'required' | 'deny'; handler: (request: unknown, response: unknown) => void }, label?: string): () => void }
23
+ effect(callback: () => () => void, label?: string): void
24
+ }) => void) => void
25
+ }).inject
26
+ if (typeof inject !== 'function') return
27
+ inject(['webServer'], (host) => {
28
+ host.effect(() => host.webServer.register({
29
+ kind: 'exact',
30
+ path: GUEST_ROUTE,
31
+ auth: 'anonymous',
32
+ handler: (request, response) => handleGuest(request as never, response as never, overlayTag(), ''),
33
+ }, 'dsh-builtin-browser: web guest proxy (root row)'))
34
+ })
35
+ }