dsh-builtin-browser 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +1 -1
  3. package/assets/browser-panel-locales.mjs +37 -5
  4. package/assets/browser-policy.d.mts +29 -0
  5. package/assets/browser-policy.mjs +40 -0
  6. package/desktop-bridge/desktop-discovery.d.mts +1 -1
  7. package/desktop-bridge/desktop-discovery.mjs +59 -9
  8. package/desktop-bridge/desktop-identity.json +12 -0
  9. package/desktop-bridge/install.mjs +14 -7
  10. package/desktop-bridge/plugin-browser-bridge.js +19 -7
  11. package/docs/acceptance-2026-11-27.md +67 -0
  12. package/docs/architecture.md +1 -1
  13. package/docs/development.md +33 -4
  14. package/docs/dsh-0.2.3-host-patch-task.md +34 -0
  15. package/docs/hardcoding-audit.md +28 -8
  16. package/docs/known-issues.md +26 -0
  17. package/docs/limitations.md +6 -2
  18. package/docs/pr64-maintenance.md +1 -1
  19. package/docs/tool-reference.md +1 -1
  20. package/docs/user-guide.md +1 -1
  21. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  22. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  23. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  24. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  25. package/dsh-host-patch/README.md +4 -0
  26. package/dsh-host-patch/apply.mjs +61 -13
  27. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  28. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  29. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  30. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  31. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  32. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  33. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  34. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  35. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  36. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  37. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  38. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  39. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  40. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  41. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  42. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  43. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  44. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  45. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  46. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  47. package/dsh-host-patch/sources/manifest.json +218 -0
  48. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  49. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  50. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  51. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  52. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  53. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  54. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  55. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  56. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  57. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  58. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  59. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  60. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  61. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  62. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  63. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  64. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  65. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  66. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  67. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  68. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  69. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  70. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  71. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  72. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  73. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  74. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  75. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  76. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  77. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  78. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  79. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  80. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  81. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  82. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  83. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  84. package/dsh-host-patch/sources/series.json +260 -0
  85. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  86. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  87. package/dsh-host-patch/tauri-revision1.json +39 -0
  88. package/dsh-host-patch/tauri.json +43 -0
  89. package/dsh-host-patch/v023-alpha2.json +153 -0
  90. package/lib/browser/anti-bot.js +215 -0
  91. package/lib/browser/deep-dom.js +39 -0
  92. package/lib/browser/runtime.js +15 -0
  93. package/lib/browser/takeover-target.js +13 -6
  94. package/lib/browser/types.js +30 -1
  95. package/lib/browser-electron/authenticated-route.js +16 -2
  96. package/lib/browser-electron/automatic-maintenance.js +16 -10
  97. package/lib/browser-electron/bridge-connection.js +3 -8
  98. package/lib/browser-electron/bridge-install.js +2 -1
  99. package/lib/browser-electron/bridge-status.js +55 -26
  100. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  101. package/lib/browser-electron/desktop-identity.js +28 -5
  102. package/lib/browser-electron/desktop-shell.js +64 -0
  103. package/lib/browser-electron/electron-provision.js +105 -18
  104. package/lib/browser-electron/entry.js +129 -46
  105. package/lib/browser-electron/extension-browser.js +4 -4
  106. package/lib/browser-electron/foreground-watch.js +134 -0
  107. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  108. package/lib/browser-electron/guest-route.js +181 -32
  109. package/lib/browser-electron/guest-runtime.js +61 -10
  110. package/lib/browser-electron/guest-storage.js +2 -2
  111. package/lib/browser-electron/history-store.js +1 -5
  112. package/lib/browser-electron/host-main.js +8 -4
  113. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  114. package/lib/browser-electron/maintenance-route.js +2 -1
  115. package/lib/browser-electron/missing-system-browser.js +5 -9
  116. package/lib/browser-electron/preferred-browser.js +7 -3
  117. package/lib/browser-electron/preview-route.js +9 -13
  118. package/lib/browser-electron/process-ownership.js +1 -1
  119. package/lib/browser-electron/profile-command.js +2 -1
  120. package/lib/browser-electron/profile-extension.js +5 -0
  121. package/lib/browser-electron/profile-lease.js +152 -47
  122. package/lib/browser-electron/provider-core.js +527 -0
  123. package/lib/browser-electron/provider-interaction.js +963 -0
  124. package/lib/browser-electron/provider-media.js +518 -0
  125. package/lib/browser-electron/provider-navigation.js +301 -0
  126. package/lib/browser-electron/provider-observation.js +623 -0
  127. package/lib/browser-electron/provider-tabs.js +372 -0
  128. package/lib/browser-electron/provider.js +150 -3301
  129. package/lib/browser-electron/reference-route.js +9 -18
  130. package/lib/browser-electron/remote-host.js +79 -34
  131. package/lib/browser-electron/runtime-status.js +56 -6
  132. package/lib/browser-electron/settings-store.js +3 -6
  133. package/lib/browser-electron/sidebar-only-host.js +1 -1
  134. package/lib/browser-electron/system-browser.js +539 -172
  135. package/lib/browser-electron/tauri-host.js +208 -0
  136. package/lib/browser-electron/virtual-cursor.js +23 -13
  137. package/lib/browser-reference/service.js +22 -4
  138. package/lib/browser-reference/web-sources.js +1 -1
  139. package/lib/client.js +43409 -0
  140. package/lib/compat/host-features.js +75 -0
  141. package/lib/reference-source.js +1 -1
  142. package/lib/reference-text.js +23 -1
  143. package/lib/takeover-protocol.js +1 -1
  144. package/lib/tool-browser/block-recovery.js +69 -0
  145. package/lib/tool-browser/code-tool.js +170 -19
  146. package/lib/tool-browser/code-worker.js +115 -20
  147. package/lib/tool-browser/errors.js +34 -0
  148. package/lib/tool-browser/index.js +66 -3593
  149. package/lib/tool-browser/page-probe.js +227 -28
  150. package/lib/tool-browser/panel-page.js +2 -1
  151. package/lib/tool-browser/probe-client.js +157 -0
  152. package/lib/tool-browser/screenshot-annotations.js +108 -0
  153. package/lib/tool-browser/state.js +337 -0
  154. package/lib/tool-browser/takeover.js +1 -1
  155. package/lib/tool-browser/tools-debug.js +862 -0
  156. package/lib/tool-browser/tools-interaction.js +993 -0
  157. package/lib/tool-browser/tools-navigation.js +807 -0
  158. package/lib/tool-browser/tools-observation.js +461 -0
  159. package/lib/tool-browser/tools-reference.js +293 -0
  160. package/lib/web-guest.js +1 -0
  161. package/package.json +16 -54
  162. package/README.en.md +0 -89
  163. package/browser-extension/constants.mjs +0 -20
  164. package/browser-extension/controller.mjs +0 -293
  165. package/browser-extension/locales.mjs +0 -15
  166. package/browser-extension/manifest.json +0 -12
  167. package/browser-extension/options.html +0 -14
  168. package/browser-extension/options.mjs +0 -9
  169. package/browser-extension/permission-guard.mjs +0 -13
  170. package/browser-extension/worker.mjs +0 -74
  171. package/dist/client.cjs +0 -43167
  172. package/lib/browser-electron/package-removal.js +0 -5
  173. package/lib/browser-reference/submission-receipts.js +0 -139
  174. package/scripts/build.mjs +0 -66
  175. package/scripts/bundle-host.mjs +0 -28
  176. package/scripts/fix-exports.mjs +0 -50
  177. package/scripts/install-electron.mjs +0 -51
  178. package/scripts/verify-exports.mjs +0 -47
  179. package/scripts/verify-preview-sdk.mjs +0 -93
  180. package/skills/dsh-builtin-browser/SKILL.md +0 -73
  181. package/skills/dsh-builtin-browser/references/batch.md +0 -53
  182. package/skills/dsh-builtin-browser/references/deliver.md +0 -31
  183. package/skills/dsh-builtin-browser/references/locate.md +0 -11
  184. package/skills/dsh-builtin-browser/references/recover.md +0 -11
  185. package/skills/dsh-builtin-browser/references/verify.md +0 -13
  186. package/skills/dsh-debug-host/SKILL.md +0 -56
  187. package/skills/dsh-debug-self/SKILL.md +0 -50
  188. package/src/bridge-compatibility.ts +0 -39
  189. package/src/browser/handles.ts +0 -89
  190. package/src/browser/runtime.ts +0 -560
  191. package/src/browser/takeover-target.ts +0 -36
  192. package/src/browser/types.ts +0 -817
  193. package/src/browser-electron/authenticated-route.ts +0 -84
  194. package/src/browser-electron/automatic-maintenance.ts +0 -726
  195. package/src/browser-electron/bridge-auto.ts +0 -159
  196. package/src/browser-electron/bridge-connection.ts +0 -385
  197. package/src/browser-electron/bridge-endpoint.ts +0 -129
  198. package/src/browser-electron/bridge-install.ts +0 -289
  199. package/src/browser-electron/bridge-maintenance.ts +0 -189
  200. package/src/browser-electron/bridge-status.ts +0 -347
  201. package/src/browser-electron/desktop-bridge-host.ts +0 -251
  202. package/src/browser-electron/desktop-identity.ts +0 -320
  203. package/src/browser-electron/document-readiness.ts +0 -45
  204. package/src/browser-electron/electron-provision.ts +0 -261
  205. package/src/browser-electron/entry.ts +0 -1301
  206. package/src/browser-electron/ephemeral-profile.ts +0 -189
  207. package/src/browser-electron/extension-browser.ts +0 -223
  208. package/src/browser-electron/extension-setup.ts +0 -67
  209. package/src/browser-electron/file-write.ts +0 -31
  210. package/src/browser-electron/guest-cookie-jar.ts +0 -176
  211. package/src/browser-electron/guest-cookie-store.ts +0 -59
  212. package/src/browser-electron/guest-css-runtime.ts +0 -76
  213. package/src/browser-electron/guest-css.ts +0 -68
  214. package/src/browser-electron/guest-route.ts +0 -568
  215. package/src/browser-electron/guest-runtime.ts +0 -357
  216. package/src/browser-electron/guest-storage-runtime.ts +0 -54
  217. package/src/browser-electron/guest-storage.ts +0 -117
  218. package/src/browser-electron/history-store.ts +0 -227
  219. package/src/browser-electron/host-main.ts +0 -1381
  220. package/src/browser-electron/host-patch-maintenance.ts +0 -112
  221. package/src/browser-electron/http-body.ts +0 -65
  222. package/src/browser-electron/json-reply.ts +0 -47
  223. package/src/browser-electron/maintenance-broker.ts +0 -166
  224. package/src/browser-electron/maintenance-lifecycle.ts +0 -91
  225. package/src/browser-electron/maintenance-route.ts +0 -67
  226. package/src/browser-electron/missing-system-browser.ts +0 -113
  227. package/src/browser-electron/open-slot.ts +0 -49
  228. package/src/browser-electron/package-removal.ts +0 -4
  229. package/src/browser-electron/paths.ts +0 -25
  230. package/src/browser-electron/preferred-browser.ts +0 -120
  231. package/src/browser-electron/preview-route.ts +0 -218
  232. package/src/browser-electron/process-ownership.ts +0 -168
  233. package/src/browser-electron/process.ts +0 -23
  234. package/src/browser-electron/profile-checkpoint.ts +0 -187
  235. package/src/browser-electron/profile-command.ts +0 -46
  236. package/src/browser-electron/profile-extension.ts +0 -124
  237. package/src/browser-electron/profile-lease.ts +0 -115
  238. package/src/browser-electron/profile-residue.ts +0 -49
  239. package/src/browser-electron/provider.ts +0 -4571
  240. package/src/browser-electron/reference-route.ts +0 -608
  241. package/src/browser-electron/remote-host.ts +0 -1462
  242. package/src/browser-electron/rpc-input.ts +0 -13
  243. package/src/browser-electron/rpc-ops.ts +0 -41
  244. package/src/browser-electron/runtime-diagnostics.ts +0 -38
  245. package/src/browser-electron/runtime-route.ts +0 -105
  246. package/src/browser-electron/runtime-status.ts +0 -242
  247. package/src/browser-electron/settings-route.ts +0 -64
  248. package/src/browser-electron/settings-store.ts +0 -589
  249. package/src/browser-electron/shortcuts-route.ts +0 -112
  250. package/src/browser-electron/sidebar-only-host.ts +0 -298
  251. package/src/browser-electron/startpage-shortcuts.ts +0 -213
  252. package/src/browser-electron/system-browser.ts +0 -1497
  253. package/src/browser-electron/timing.ts +0 -16
  254. package/src/browser-electron/virtual-cursor.ts +0 -152
  255. package/src/browser-electron/windows-system.ts +0 -24
  256. package/src/browser-reference/delivery.ts +0 -384
  257. package/src/browser-reference/entry.ts +0 -631
  258. package/src/browser-reference/export.ts +0 -339
  259. package/src/browser-reference/import.ts +0 -303
  260. package/src/browser-reference/page-script.ts +0 -1537
  261. package/src/browser-reference/service.ts +0 -1315
  262. package/src/browser-reference/store.ts +0 -172
  263. package/src/browser-reference/submission-receipts.ts +0 -122
  264. package/src/browser-reference/text-quote.ts +0 -219
  265. package/src/browser-reference/types.ts +0 -195
  266. package/src/browser-reference/visible.ts +0 -367
  267. package/src/browser-reference/web-sources.ts +0 -103
  268. package/src/client/browser/BrowserController.ts +0 -693
  269. package/src/client/browser/BrowserFrame.ts +0 -78
  270. package/src/client/browser/BrowserNavigation.ts +0 -169
  271. package/src/client/browser/BrowserPage.ts +0 -23
  272. package/src/client/browser/BrowserPersistence.ts +0 -44
  273. package/src/client/browser/IframeImpl.ts +0 -176
  274. package/src/client/browser/child-tabs.ts +0 -14
  275. package/src/client/browser/iframe-reference.ts +0 -67
  276. package/src/client/browser/initialization.ts +0 -262
  277. package/src/client/browser/omnibox.ts +0 -243
  278. package/src/client/browser/store.ts +0 -38
  279. package/src/client/browser/takeover-channel.ts +0 -72
  280. package/src/client/browser/url.ts +0 -46
  281. package/src/client/browser/web-reference-source.ts +0 -52
  282. package/src/client/css-modules.d.ts +0 -4
  283. package/src/client/definition.tsx +0 -30
  284. package/src/client/electron/ElectronWebViewImpl.ts +0 -364
  285. package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
  286. package/src/client/electron/NativeChildPresentation.ts +0 -45
  287. package/src/client/electron/NativeViewPage.ts +0 -251
  288. package/src/client/electron/pages.ts +0 -23
  289. package/src/client/electron/reference-overlay.ts +0 -53
  290. package/src/client/electron/workspace.ts +0 -33
  291. package/src/client/index.ts +0 -293
  292. package/src/client/locales.ts +0 -857
  293. package/src/client/pages.ts +0 -28
  294. package/src/client/reference/client/BrowserRefLink.tsx +0 -142
  295. package/src/client/reference/client/draft-reference.ts +0 -167
  296. package/src/client/reference/client/index.ts +0 -7
  297. package/src/client/reference/client/ordered-submission.ts +0 -108
  298. package/src/client/reference/client/pending-delivery.ts +0 -216
  299. package/src/client/reference/client/plugin.ts +0 -189
  300. package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
  301. package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
  302. package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
  303. package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
  304. package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
  305. package/src/client/reference/client/production/ReferenceText.tsx +0 -36
  306. package/src/client/reference/client/production/assembly.ts +0 -471
  307. package/src/client/reference/client/production/asset-store.ts +0 -144
  308. package/src/client/reference/client/production/availability.ts +0 -74
  309. package/src/client/reference/client/production/bytes.ts +0 -36
  310. package/src/client/reference/client/production/delivery-client.ts +0 -211
  311. package/src/client/reference/client/production/draft-adapter.ts +0 -508
  312. package/src/client/reference/client/production/http-transport.ts +0 -217
  313. package/src/client/reference/client/production/production-submission.ts +0 -310
  314. package/src/client/reference/client/production/protocol.ts +0 -231
  315. package/src/client/reference/client/production/reference-card.ts +0 -240
  316. package/src/client/reference/client/production/reference-labels.ts +0 -29
  317. package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
  318. package/src/client/reference/client/production/reveal.ts +0 -215
  319. package/src/client/reference/client/production/runtime.ts +0 -1101
  320. package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
  321. package/src/client/reference/client/production/source-marker.ts +0 -63
  322. package/src/client/reference/client/production/source-opener.ts +0 -55
  323. package/src/client/reference/client/production/styles.ts +0 -104
  324. package/src/client/reference/client/production/user-text-rule.ts +0 -58
  325. package/src/client/reference/client/reveal.ts +0 -107
  326. package/src/client/reference/client/scheme.ts +0 -114
  327. package/src/client/reference/client/types.ts +0 -168
  328. package/src/client/reference/css-modules.d.ts +0 -4
  329. package/src/client/reference/index.ts +0 -11
  330. package/src/client/reference-capture-owner.ts +0 -162
  331. package/src/client/reference-intents.ts +0 -36
  332. package/src/client/settings/index.ts +0 -34
  333. package/src/client/settings/panel.ts +0 -2657
  334. package/src/client/shortcut-open.ts +0 -30
  335. package/src/client/startpage/binding.ts +0 -99
  336. package/src/client/startpage/controller.ts +0 -303
  337. package/src/client/startpage/model.ts +0 -279
  338. package/src/client/view/Browser.module.css +0 -751
  339. package/src/client/view/BrowserBody.tsx +0 -314
  340. package/src/client/view/BrowserPresentation.ts +0 -9
  341. package/src/client/view/BrowserTitle.tsx +0 -17
  342. package/src/client/view/IframePresentation.ts +0 -344
  343. package/src/client/view/StartPage.tsx +0 -597
  344. package/src/client/view/TakeoverBanner.tsx +0 -21
  345. package/src/index.ts +0 -110
  346. package/src/reference-owner.ts +0 -5
  347. package/src/reference-page.ts +0 -9
  348. package/src/reference-source.ts +0 -3
  349. package/src/reference-text.ts +0 -197
  350. package/src/startpage-settings.ts +0 -103
  351. package/src/startpage.ts +0 -71
  352. package/src/takeover-protocol.ts +0 -19
  353. package/src/tool-browser/code-tool.ts +0 -401
  354. package/src/tool-browser/code-worker.ts +0 -639
  355. package/src/tool-browser/element-fields.ts +0 -167
  356. package/src/tool-browser/index.ts +0 -3733
  357. package/src/tool-browser/page-probe.ts +0 -474
  358. package/src/tool-browser/panel-page.ts +0 -124
  359. package/src/tool-browser/screenshot-image.ts +0 -49
  360. package/src/tool-browser/takeover.ts +0 -198
  361. package/src/types/electron-shim.d.ts +0 -144
  362. package/src/types.ts +0 -85
  363. package/src/web-guest.ts +0 -34
  364. package/tools/accept-desktop.mjs +0 -148
@@ -1,471 +0,0 @@
1
- /**
2
- * Cordis assembly entry (the `apply(ctx)` the standalone deploy patch loads).
3
- *
4
- * The host context is typed STRUCTURALLY: no `@deepseek-ai/cordis` runtime (or
5
- * type) import, so this package stays self-contained and compilable with
6
- * `types: []`. The real cordis Context satisfies this shape. `apply` wires:
7
- * - an HTTP client over the plugin's loopback surface (host cookie),
8
- * - the fully-injected production runtime,
9
- * - the dock card into `conversation.input.overlay` (scope: session), i.e. the
10
- * pill rail INSIDE the composer card, above the text surface,
11
- * - the reply-side link into `conversation.user.text.node`,
12
- * - the ordered submission seam exposed as `browserReferenceSubmission`,
13
- * - cancellable polling started once and disposed through `ctx.effect`.
14
- *
15
- * React renders the dock and feedback through the host's shared platform
16
- * modules. The conversation service invokes the ordered submission hooks.
17
- *
18
- * @module dsh-browser-reference/production/assembly
19
- */
20
- import { createMemoryStorage, type KeyValueStorage } from '../types.ts'
21
- import {
22
- createFetchRequest,
23
- createReferenceHttpClient,
24
- type RequestLike,
25
- } from './http-transport.ts'
26
- import {
27
- createCancellationSource,
28
- type PollerScheduler,
29
- } from './delivery-client.ts'
30
- import {
31
- createProductionRuntime,
32
- type AdmitAssetResult,
33
- type DockSnapshot,
34
- type ProductionRuntime,
35
- } from './runtime.ts'
36
- import type { HostInputFace } from './draft-adapter.ts'
37
- import type { AssetResponse } from './protocol.ts'
38
- import type { TextPosition } from '../ordered-submission.ts'
39
- import { ensureDockStyles } from './styles.ts'
40
- import { buildBrowserRefLinkProps } from '../BrowserRefLink.tsx'
41
- import { installReplyLinkBridge } from './reply-link-bridge.ts'
42
- import { createBrowserSourceRule } from './user-text-rule.ts'
43
- import { decodeBrowserRefUri } from '../scheme.ts'
44
- import { createElement as element, useSyncExternalStore } from 'react'
45
- import { createRoot } from 'react-dom/client'
46
- import { ReferenceDock } from './ReferenceDock.tsx'
47
- import { ReferenceCapsules } from './ReferenceCapsules.tsx'
48
- import { ReferenceFeedback } from './ReferenceFeedback.tsx'
49
- import { referenceCopy, referenceLabels, REFERENCE_LOCALE, type ReferenceLabels, type ReferenceLabelKey } from './reference-labels.ts'
50
-
51
- /** Services this plugin needs from the host context (cordis `inject`). */
52
- export const inject = [
53
- 'slots', 'sessions', 'uiConversation', 'conversation', 'uiSession', 'locale',
54
- ] as const
55
-
56
- /** Opaque element factory: the host passes its React.createElement. */
57
- export type HostElementFactory = (
58
- tag: string,
59
- props: Readonly<Record<string, unknown>>,
60
- ...children: readonly unknown[]
61
- ) => unknown
62
-
63
- export interface AssemblyConfig {
64
- /** Plugin loopback origin, e.g. `http://127.0.0.1:<port>`; '' = same origin. */
65
- readonly baseUrl?: string
66
- readonly storage?: KeyValueStorage
67
- readonly request?: RequestLike
68
- readonly fetchImpl?: Parameters<typeof createFetchRequest>[0]
69
- readonly initialSessionId?: string
70
- readonly hostInputFor?: (sessionId: string) => HostInputFace
71
- readonly admitAsset?: (asset: AssetResponse, sessionId: string) => Promise<AdmitAssetResult | undefined>
72
- readonly pollIntervalMs?: number
73
- readonly scheduler?: PollerScheduler
74
- readonly textPosition?: TextPosition
75
- /** Host React.createElement, used for the dock card and reply link. */
76
- readonly createElement?: HostElementFactory
77
- /**
78
- * Host `useSyncExternalStore`. When present the dock subscribes to the
79
- * runtime and repaints on its own; without it (SSR / unit calls) the dock
80
- * renders one static snapshot.
81
- */
82
- readonly useSnapshot?: SnapshotHook
83
- /**
84
- * Receives the dock's session-scope props on every render. The real
85
- * `conversation.input.chips` registration is handed `inputActions` for its
86
- * Session; this callback lets the plugin drive the host draft adapter from
87
- * those actions instead of requiring a separate `browserReferenceDeps`
88
- * service published by another package.
89
- */
90
- readonly onDockProps?: (props: unknown) => void
91
- }
92
-
93
- /**
94
- * Host-specific adapters that CANNOT live in a YAML `config` block (functions).
95
- * L01 publishes this bundle as a scope service before this plugin is applied,
96
- * e.g. `ctx.set('browserReferenceDeps', deps)` from ui-conversation's assembly,
97
- * or passes the same fields through `AssemblyConfig` in tests. Declaration of
98
- * this service on the host is an L01 wiring action, NOT done in this repo.
99
- */
100
- export interface BrowserReferenceDeps {
101
- readonly hostInputFor: (sessionId: string) => HostInputFace
102
- readonly admitAsset?: (asset: AssetResponse, sessionId: string) => Promise<AdmitAssetResult | undefined>
103
- readonly createElement?: HostElementFactory
104
- readonly baseUrl?: string
105
- }
106
-
107
- /** Minimal structural face of the cordis Context this plugin touches. */
108
- export interface HostContext {
109
- get(name: string): unknown
110
- /**
111
- * Declare AND publish a service in one call. Cordis rejects a bare `set()`
112
- * for a name that was never `provide()`d, so this is the primary path; the
113
- * value stays optional because declaring a name without a value is legal.
114
- */
115
- provide?(name: string, value?: unknown): unknown
116
- /** Fallback for a host that already provided the name. */
117
- set?(name: string, value: unknown): void
118
- effect(effect: () => void | (() => void), label: string): void
119
- readonly slots: {
120
- inject(name: string, producer: () => Iterable<unknown>): void
121
- register(registration: unknown, component: unknown): unknown
122
- }
123
- }
124
-
125
- function storageOrDefault(config: AssemblyConfig): KeyValueStorage {
126
- if (config.storage !== undefined) return config.storage
127
- if (typeof localStorage !== 'undefined') {
128
- return {
129
- getItem: (key) => { try { return localStorage.getItem(key) } catch { return null } },
130
- // A failed write (quota / disabled storage) MUST surface: the asset store
131
- // rolls its in-memory binding back and the draft's saveSucceeded becomes
132
- // false, so the delivery is retried instead of ACKed over a gap.
133
- setItem: (key, value) => { localStorage.setItem(key, value) },
134
- removeItem: (key) => { try { localStorage.removeItem(key) } catch { /* storage unavailable */ } },
135
- }
136
- }
137
- return createMemoryStorage()
138
- }
139
-
140
- function requestOrDefault(config: AssemblyConfig, cancellationSignal: () => AbortSignal | undefined): RequestLike {
141
- if (config.request !== undefined) return config.request
142
- if (config.fetchImpl !== undefined) return createFetchRequest(config.fetchImpl, cancellationSignal)
143
- if (typeof fetch !== 'undefined') {
144
- return createFetchRequest(
145
- (input, init) => fetch(input, init as unknown as RequestInit),
146
- cancellationSignal,
147
- )
148
- }
149
- throw new Error('ui-browser-reference: no HTTP request implementation provided')
150
- }
151
-
152
- /**
153
- * The registered dock component: it subscribes to the runtime through the
154
- * host's `useSyncExternalStore`, so a delivery that lands while the user is
155
- * idle repaints the rail by itself. `snapshot()` is a stable object identity, so
156
- * an unchanged poll does not re-render — which keeps the note editor's focus and
157
- * caret intact.
158
- */
159
- export function createLiveCardDockComponent(
160
- runtime: ProductionRuntime,
161
- _createElement: HostElementFactory,
162
- ): (props?: unknown) => unknown {
163
- return (props?: unknown) => {
164
- // The repaint channel is the HOST's, not ours: the registration publishes
165
- // `hooks.dockCards` and the slot runtime binds it into a `useDockCards`
166
- // selector hook rendered by its own React. Calling React's hook here instead
167
- // failed on the real desktop — the client bundle's `react` is a second module
168
- // instance, so every hook threw "invalid hook call" and the dock never mounted.
169
- const face = props as {
170
- readonly useDockCards?: (selector: (value: DockSnapshot) => DockSnapshot) => DockSnapshot
171
- readonly noteDockProps?: (props: unknown) => void
172
- readonly t?: (key: ReferenceLabelKey, args?: { count: number }) => string
173
- } | undefined
174
- face?.noteDockProps?.(props)
175
- const view = face?.useDockCards === undefined ? runtime.snapshot() : face.useDockCards(value => value)
176
- // 这里曾经在 render 里写 `document.documentElement.dataset.dshChips`,为的是让上游发送闸门能读到
177
- // 胶囊数量(那需要改上游,已弃)。这条写入现在没有任何读方,却在**每次渲染**时改 `<html>` 的属性:
178
- // 每次写入都让整篇文档的样式失效 → 布局重算 → 所有 ResizeObserver(上游输入区自适应、主视觉 canvas)
179
- // 收到通知。它们的回调若再改一次尺寸,浏览器就报
180
- // `ResizeObserver loop completed with undelivered notifications.`,dev 下直接红屏。
181
- // 读数走 dock 自己的 snapshot,不再经文档属性传递。
182
- return element(ReferenceDock, {
183
- key: view.sessionId,
184
- sessionId: view.sessionId,
185
- cards: view.cards,
186
- labels: referenceLabels(face?.t, view.cards.length),
187
- actions: {
188
- onEditComment: (referenceId, comment) => { runtime.setComment(referenceId, comment) },
189
- onRemove: (referenceId) => { void runtime.removeCard(referenceId) },
190
- onReveal: (referenceId) => { void runtime.revealReference(referenceId) },
191
- },
192
- ...(view.issue === undefined ? {} : { notice: view.issue }),
193
- })
194
- }
195
- }
196
-
197
- /** The subset of React's `useSyncExternalStore` this package needs. */
198
- export type SnapshotHook = <T>(subscribe: (listener: () => void) => () => void, getSnapshot: () => T) => T
199
-
200
- /**
201
- * Build the reply-side link component over the injected element factory.
202
- *
203
- * `conversation.user.text.node` is a KEYED slot: the host hands a component
204
- * `{ node, raw, interactive }`, never a bare `uri`. The installed desktop has
205
- * no `browser-ref` node rule, so this registration is defensive — it must never
206
- * render a disabled button over `undefined`. A props shape without a canonical
207
- * browser-ref URI yields `null`, which keeps the host's raw-text fallback.
208
- * Live reply-side links are handled by {@link installReplyLinkBridge}.
209
- */
210
- export function createReplyLinkComponent(
211
- runtime: ProductionRuntime,
212
- createElement: HostElementFactory,
213
- ): (props: unknown) => unknown {
214
- return (props: unknown) => {
215
- const typed = props as {
216
- readonly uri?: unknown
217
- readonly children?: string
218
- readonly raw?: unknown
219
- readonly node?: { readonly data?: { readonly uri?: unknown; readonly href?: unknown; readonly label?: string } }
220
- readonly useSourceReferences?: (selector: (value: DockSnapshot) => DockSnapshot) => DockSnapshot
221
- } | undefined
222
- typed?.useSourceReferences?.(value => value)
223
- // A bare `uri` is the documented programmatic shape (and what the existing
224
- // contract asserts). A keyed-slot owner has neither `uri` nor node data, so
225
- // it must fall back to the host's raw-text renderer instead of a disabled
226
- // button over `undefined`.
227
- const candidate = typed?.uri ?? typed?.node?.data?.uri ?? typed?.node?.data?.href
228
- if (typeof candidate !== 'string') return null
229
- // A plain https (or any non-canonical) URL must keep the host's raw-text
230
- // fallback; without this gate it was rendered as a disabled "来源不可用"
231
- // dead button. createBrowserRefRenderer applies the same scheme check.
232
- if (!candidate.startsWith(BROWSER_REF_SCHEME)) return null
233
- return renderSentCapsule(runtime, createElement, candidate, typed?.children ?? typed?.node?.data?.label)
234
- }
235
- }
236
-
237
- /**
238
- * Global key shared with `ui-primitives/src/markdown/render.tsx`'s
239
- * `registerBrowserRefRenderer`. The client plugin and the low-level markdown
240
- * library never import each other; they meet only through this optional hook.
241
- * When the renderer is absent the markdown renderer keeps its original
242
- * `sanitizeUrl`/anchor behavior (backwards compatible).
243
- */
244
- export const BROWSER_REF_RENDERER_GLOBAL = '__DSH_BROWSER_REF_RENDERER__'
245
- /** Live-DOM diagnostic handle for the deployment-compatible link bridge. */
246
- export const REPLY_LINK_BRIDGE_GLOBAL = '__DSH_BROWSER_REF_LINK_BRIDGE__'
247
- export const BROWSER_REF_SCHEME = 'dsh-browser-ref:'
248
-
249
- function SentReferenceCapsules(props: { readonly runtime: ProductionRuntime; readonly capsule: Parameters<typeof ReferenceCapsules>[0] }): ReturnType<typeof ReferenceCapsules> {
250
- const view = useSyncExternalStore(props.runtime.subscribe, props.runtime.snapshot, props.runtime.snapshot)
251
- const notice = view.reveal?.referenceId === props.capsule.cards[0]?.referenceId ? view.reveal?.message : undefined
252
- return element(ReferenceCapsules, { ...props.capsule, ...(notice === undefined ? {} : { notice }) })
253
- }
254
-
255
- function renderSentCapsule(runtime: ProductionRuntime, createElement: HostElementFactory, uri: string, label?: string, key?: unknown, anchor?: HTMLElement): unknown {
256
- let referenceId: string | undefined
257
- try { referenceId = decodeBrowserRefUri(uri).referenceId } catch { /* invalid URI */ }
258
- const detail = referenceId === undefined ? undefined : runtime.referenceDetail(referenceId)
259
- const owner = referenceId === undefined ? undefined : runtime.ownerFor(referenceId)
260
- if (detail !== undefined && owner?.sessionId === runtime.currentSessionId()) {
261
- const index = Number(/引用来源\s*(\d+)/u.exec(label ?? '')?.[1]) || detail.card.index
262
- return element(SentReferenceCapsules, {
263
- key: String(key ?? uri),
264
- runtime,
265
- capsule: {
266
- sessionId: runtime.currentSessionId(),
267
- cards: [{ ...detail.card, index }],
268
- labels: referenceLabels(),
269
- actions: { onReveal: () => { void runtime.activateUri(uri) } },
270
- ...(anchor === undefined ? {} : { anchor }),
271
- },
272
- })
273
- }
274
- if (anchor !== undefined) return null
275
- const dom = buildBrowserRefLinkProps(runtime.revealer.linkSpec(uri, label))
276
- return createElement('button', { ...dom, key }, dom.children)
277
- }
278
-
279
- /**
280
- * Build the reply-side `dsh-browser-ref:` link renderer. It is installed on
281
- * `globalThis` by `apply` so the host markdown renderer can divert only that
282
- * scheme to a dedicated button (never a system `href`), reusing the additive
283
- * `BrowserRefLink` contract through `buildBrowserRefLinkProps`.
284
- */
285
- export function createBrowserRefRenderer(
286
- runtime: ProductionRuntime,
287
- createElement: HostElementFactory,
288
- ): (url: string, children: readonly unknown[], key: unknown) => unknown {
289
- return (url, children, key) => {
290
- if (!url.startsWith(BROWSER_REF_SCHEME)) return undefined
291
- const first = children[0]
292
- return renderSentCapsule(runtime, createElement, url, typeof first === 'string' ? first : undefined, key)
293
- }
294
- }
295
-
296
- /**
297
- * Load the production feature into the host. Returns the runtime so the caller
298
- * (and unit tests) can drive/inspect it; also exposes the submission seam.
299
- */
300
- export function apply(ctx: HostContext, config: AssemblyConfig = {}): ProductionRuntime {
301
- ensureDockStyles()
302
- const locale = ctx.get('locale') as { register(namespace: string, copy: Readonly<Record<string, ReferenceLabels>>): void | (() => void) } | undefined
303
- if (typeof locale?.register === 'function') ctx.effect(() => locale.register(REFERENCE_LOCALE, referenceCopy), 'ui-browser-reference: copy')
304
- // Functions cannot come from the YAML config block, so L01 publishes them as
305
- // a scope service; explicit config (tests / programmatic wiring) wins.
306
- const deps = ctx.get('browserReferenceDeps') as BrowserReferenceDeps | undefined
307
- const hostInputFor = config.hostInputFor ?? deps?.hostInputFor
308
- const admitAsset = config.admitAsset ?? deps?.admitAsset
309
- const elementFactory: HostElementFactory = config.createElement ?? deps?.createElement
310
- ?? ((tag, props, ...children) => ({ tag, props, children }))
311
- const baseUrl = config.baseUrl ?? deps?.baseUrl
312
- const cancellation = createCancellationSource()
313
- const http = createReferenceHttpClient({
314
- ...(baseUrl === undefined ? {} : { baseUrl }),
315
- request: requestOrDefault(config, () => cancellation.signal()),
316
- })
317
- const runtime = createProductionRuntime({
318
- http,
319
- storage: storageOrDefault(config),
320
- initialSessionId: config.initialSessionId ?? '',
321
- cancellation,
322
- hostInputFor: hostInputFor ?? (() => ({
323
- captureInsertion: () => ({ start: 0, end: 0, draftRev: 0 }),
324
- insertText: () => true,
325
- persistDraft: () => {},
326
- readText: () => '',
327
- })),
328
- ...(admitAsset === undefined ? {} : { admitAsset }),
329
- ...(config.pollIntervalMs === undefined ? {} : { pollIntervalMs: config.pollIntervalMs }),
330
- ...(config.scheduler === undefined ? {} : { scheduler: config.scheduler }),
331
- ...(config.textPosition === undefined ? {} : { textPosition: config.textPosition }),
332
- })
333
-
334
- // Expose the ordered submission seam for the host's real send path. Cordis
335
- // requires `provide()` before `set()` for a service name; a bare set throws
336
- // "cannot set property without provide" and would leave R05 unwired.
337
- // cordis: provide() DECLARES a service, set() assigns it. Passing the value to provide() only declared
338
- // the name, so the conversation service's ctx.get('browserReferenceSubmission') returned undefined and
339
- // every send ignored its references — the message went out with the typed text alone while the chips
340
- // stayed in the composer.
341
- if (typeof ctx.provide === 'function') {
342
- ctx.provide('browserReferenceSubmission')
343
- ctx.set?.('browserReferenceSubmission', runtime.submission)
344
- } else {
345
- ctx.set?.('browserReferenceSubmission', runtime.submission)
346
- }
347
- const disposeSubmission = undefined as unknown
348
- // Cordis services are visible along a fiber's ancestor chain only; this plugin and the conversation
349
- // service are siblings, so `ctx.get` from the sender could not see the seam and every send ignored its
350
- // references. A global mirror is the same escape hatch this module already uses for the markdown
351
- // renderer and the reply-link bridge.
352
- const submissionHost = globalThis as unknown as Record<string, unknown>
353
- submissionHost.__DSH_BROWSER_REF_SUBMISSION__ = runtime.submission
354
- if (disposeSubmission !== undefined && typeof (disposeSubmission as { dispose?: unknown }).dispose === 'function') {
355
- // Some cordis shapes return a disposer object rather than a function.
356
- ctx.effect(() => () => { (disposeSubmission as { dispose: () => void }).dispose() }, 'ui-browser-reference: submission service')
357
- }
358
-
359
- const cardComponent = createLiveCardDockComponent(runtime, elementFactory)
360
- const replyComponent = createReplyLinkComponent(runtime, elementFactory)
361
-
362
- // Divert only `dsh-browser-ref:` markdown destinations to the dedicated
363
- // button; the global hook is optional so old messages / builds without this
364
- // plugin keep their exact previous rendering.
365
- const globalHost = globalThis as unknown as Record<string, unknown>
366
- const browserRefRenderer = createBrowserRefRenderer(runtime, elementFactory)
367
- globalHost[BROWSER_REF_RENDERER_GLOBAL] = browserRefRenderer
368
- ctx.effect(() => () => {
369
- if (globalHost[BROWSER_REF_RENDERER_GLOBAL] === browserRefRenderer) {
370
- delete globalHost.__DSH_BROWSER_REF_RENDERER__
371
- }
372
- }, 'ui-browser-reference: markdown link renderer')
373
-
374
- // The deployed markdown renderer predates the optional hook above. A
375
- // document-level bridge is what makes `dsh-browser-ref:` links clickable in
376
- // the installed desktop without downgrading its frontend bundle.
377
- const replyLinkBridge = installReplyLinkBridge({
378
- isAvailable: uri => runtime.revealer.linkSpec(uri).available,
379
- activate: (uri) => { void runtime.activateUri(uri) },
380
- mountCard: (uri, anchor) => {
381
- const card = renderSentCapsule(runtime, elementFactory, uri, anchor.textContent ?? undefined, undefined, anchor)
382
- if (card === null) return undefined
383
- const container = anchor.ownerDocument.createElement('span')
384
- anchor.ownerDocument.body.append(container)
385
- const root = createRoot(container)
386
- root.render(card as Parameters<typeof root.render>[0])
387
- return () => { root.unmount(); container.remove() }
388
- },
389
- })
390
- globalHost[REPLY_LINK_BRIDGE_GLOBAL] = replyLinkBridge
391
- ctx.effect(() => () => {
392
- if (globalHost[REPLY_LINK_BRIDGE_GLOBAL] === replyLinkBridge) {
393
- delete globalHost.__DSH_BROWSER_REF_LINK_BRIDGE__
394
- }
395
- replyLinkBridge.dispose()
396
- }, 'ui-browser-reference: reply link bridge')
397
-
398
- /**
399
- * Prefer the Session standard kit over stale owner snapshots.
400
- */
401
- const dockComponent = (props: unknown): unknown => {
402
- const face = props as {
403
- readonly sessionId?: string
404
- readonly session?: { readonly sessionId?: string }
405
- readonly input?: { readonly draft?: string }
406
- readonly useInput?: (
407
- selector: (state: { readonly draft?: string }) => { readonly draft?: string },
408
- ) => { readonly draft?: string }
409
- } | undefined
410
- const input = face?.useInput === undefined ? undefined : face.useInput(value => value)
411
- // Delegated by call rather than through an element so the seat renders the
412
- // dock itself: one React boundary, same hook order on every render.
413
- const dockProps = {
414
- ...(props as Readonly<Record<string, unknown>>),
415
- session: { sessionId: face?.sessionId ?? face?.session?.sessionId ?? '' },
416
- input: { draft: input?.draft ?? face?.input?.draft ?? '' },
417
- }
418
- config.onDockProps?.(dockProps)
419
- return cardComponent(dockProps)
420
- }
421
- ctx.slots.inject('conversation.input.dock', function* () {
422
- yield ctx.slots.register({
423
- name: 'conversation.input.dock', id: 'dsh-browser-reference', priority: 50,
424
- // The dictionary rides the same namespace `apply` registers with the host
425
- // locale service, so the rail's copy follows the active language.
426
- locale: REFERENCE_LOCALE,
427
- // `hooks.dockCards` becomes the host-bound selector hook.
428
- inject: () => ({
429
- hooks: { dockCards: { getSnapshot: () => runtime.snapshot(), subscribe: (listener: () => void) => runtime.subscribe(listener) } },
430
- }),
431
- }, dockComponent)
432
- })
433
- ctx.slots.inject('conversation.user.text.node', function* () {
434
- yield ctx.slots.register({
435
- name: 'conversation.user.text.node', key: 'browser-ref', priority: 100,
436
- inject: () => ({ hooks: { sourceReferences: {
437
- getSnapshot: () => runtime.snapshot(), subscribe: (listener: () => void) => runtime.subscribe(listener),
438
- } } }),
439
- }, replyComponent)
440
- })
441
- ctx.slots.inject('shell.overlay', function* () {
442
- yield ctx.slots.register({
443
- name: 'shell.overlay', id: 'dsh-browser-reference-feedback',
444
- inject: () => ({ hooks: { referenceFeedback: {
445
- getSnapshot: () => runtime.snapshot(), subscribe: (listener: () => void) => runtime.subscribe(listener),
446
- } } }),
447
- }, (props: { readonly useReferenceFeedback?: (selector: (value: DockSnapshot) => DockSnapshot) => DockSnapshot }) => {
448
- const view = props.useReferenceFeedback?.(value => value) ?? runtime.snapshot()
449
- return element(ReferenceFeedback, view.reveal === undefined ? {} : { notice: view.reveal })
450
- })
451
- })
452
-
453
- // 投递泵必须在**任何可选集成之前**启动。旧顺序把它放在最后,于是后面任何一步(可选的
454
- // `uiConversation.userText` 注册等)抛错时,dock 已经渲染、会话也绑好了,唯独轮询没起来:
455
- // 现象就是「引用卡片永远不出现、发送一直禁用」,而外层 try/catch 把它吞成静默失败。
456
- runtime.start()
457
- ctx.effect(() => () => { runtime.dispose() }, 'ui-browser-reference: production runtime')
458
-
459
- const sourceRule = createBrowserSourceRule(referenceId => runtime.referenceDetail(referenceId) !== undefined)
460
- const textOwner = ctx.get('uiConversation') as {
461
- readonly userText?: { register(rule: typeof sourceRule): () => void }
462
- } | undefined
463
- if (textOwner?.userText !== undefined) {
464
- try {
465
- ctx.effect(() => textOwner.userText?.register(sourceRule), 'ui-browser-reference: source text rule')
466
- } catch {
467
- // 文本来源高亮是可选的展示增强:注册失败不能拖垮引用投递。
468
- }
469
- }
470
- return runtime
471
- }
@@ -1,144 +0,0 @@
1
- /**
2
- * Session-scoped durable asset bindings.
3
- *
4
- * An image part is a content hash (`assetKey`), NOT a URL and NOT alt text.
5
- * Before a delivery may be ACKed, every required key must have real bytes from
6
- * `GET /reference/asset?encoding=base64` AND a durable host attachment
7
- * admission (`receiptId` from the host's createDrafts/serializeAttachments).
8
- * Both facts are persisted per session so a restart restores the exact bytes
9
- * and the receipt, and the card can render a real thumbnail without the page.
10
- *
11
- * All persistence goes through an injected `KeyValueStorage`; no globals.
12
- *
13
- * @module dsh-browser-reference/production/asset-store
14
- */
15
- import type { KeyValueStorage } from '../types.ts'
16
- import { decodeBase64 } from './bytes.ts'
17
- import type { AssetResponse } from './protocol.ts'
18
-
19
- export const ASSET_STORE_PREFIX = 'dsh.browser-reference.assets.'
20
-
21
- export function assetStoreKey(sessionId: string): string {
22
- return `${ASSET_STORE_PREFIX}${sessionId}`
23
- }
24
-
25
- /** One durably bound image asset. `data` is base64 of the real bytes. */
26
- export interface AssetBinding {
27
- readonly key: string
28
- readonly mime: string
29
- readonly bytes: number
30
- readonly sha256: string
31
- readonly data: string
32
- /** Opaque receipt from the host attachment admission service, when uploaded. */
33
- readonly receiptId?: string
34
- }
35
-
36
- export interface AssetStore {
37
- /** Bind one asset fetched from the plugin, optionally with a host receipt. */
38
- bind(asset: AssetResponse, receiptId?: string): AssetBinding
39
- get(key: string): AssetBinding | undefined
40
- /** Real bytes decoded from `data`, or undefined when unbound. */
41
- bytesOf(key: string): Uint8Array | undefined
42
- hasAll(keys: readonly string[]): boolean
43
- missing(keys: readonly string[]): readonly string[]
44
- keys(): readonly string[]
45
- values(): readonly AssetBinding[]
46
- restore(): void
47
- dispose(): void
48
- }
49
-
50
- const FORMAT_VERSION = 1
51
-
52
- interface SerializedAssets {
53
- readonly version: typeof FORMAT_VERSION
54
- readonly bindings: readonly AssetBinding[]
55
- }
56
-
57
- function isRecord(value: unknown): value is Record<string, unknown> {
58
- return typeof value === 'object' && value !== null && !Array.isArray(value)
59
- }
60
-
61
- function isBinding(value: unknown): value is AssetBinding {
62
- if (!isRecord(value)) return false
63
- return typeof value.key === 'string' && /^[0-9a-f]{64}$/u.test(value.key)
64
- && typeof value.mime === 'string'
65
- && typeof value.bytes === 'number' && Number.isInteger(value.bytes) && value.bytes >= 0
66
- && typeof value.sha256 === 'string'
67
- && typeof value.data === 'string'
68
- && (value.receiptId === undefined || typeof value.receiptId === 'string')
69
- }
70
-
71
- function parse(raw: string): Map<string, AssetBinding> | undefined {
72
- try {
73
- const parsed: unknown = JSON.parse(raw)
74
- if (!isRecord(parsed) || parsed.version !== FORMAT_VERSION || !Array.isArray(parsed.bindings)) return undefined
75
- const map = new Map<string, AssetBinding>()
76
- for (const entry of parsed.bindings as readonly unknown[]) {
77
- if (!isBinding(entry)) return undefined
78
- map.set(entry.key, entry)
79
- }
80
- return map
81
- } catch {
82
- return undefined
83
- }
84
- }
85
-
86
- /** Build the store for ONE DSH session; construction restores its persisted state. */
87
- export function createAssetStore(storage: KeyValueStorage, sessionId: string): AssetStore {
88
- const key = assetStoreKey(sessionId)
89
- let bindings = new Map<string, AssetBinding>()
90
- let disposed = false
91
-
92
- const persist = (): void => {
93
- const snapshot: SerializedAssets = { version: FORMAT_VERSION, bindings: [...bindings.values()] }
94
- storage.setItem(key, JSON.stringify(snapshot))
95
- }
96
-
97
- const load = (): void => {
98
- const raw = storage.getItem(key)
99
- bindings = raw === null ? new Map() : parse(raw) ?? new Map()
100
- }
101
-
102
- load()
103
-
104
- return {
105
- bind(asset, receiptId) {
106
- if (disposed) throw new Error('asset store is disposed')
107
- if (asset.sha256 !== asset.key) {
108
- throw new Error(`asset sha256 ${asset.sha256} does not match key ${asset.key}`)
109
- }
110
- const binding: AssetBinding = {
111
- key: asset.key,
112
- mime: asset.mime,
113
- bytes: asset.bytes,
114
- sha256: asset.sha256,
115
- data: asset.data,
116
- ...(receiptId === undefined ? {} : { receiptId }),
117
- }
118
- const previous = bindings.get(asset.key)
119
- bindings.set(asset.key, binding)
120
- try {
121
- persist()
122
- } catch (error: unknown) {
123
- // Never leave an in-memory "bound" asset when the durable write failed:
124
- // missing() would report it as present and the delivery would be ACKed
125
- // over an image that turns into a placeholder after a restart.
126
- if (previous === undefined) bindings.delete(asset.key)
127
- else bindings.set(asset.key, previous)
128
- throw error
129
- }
130
- return binding
131
- },
132
- get(assetKey) { return bindings.get(assetKey) },
133
- bytesOf(assetKey) {
134
- const binding = bindings.get(assetKey)
135
- return binding === undefined ? undefined : decodeBase64(binding.data)
136
- },
137
- hasAll(keys) { return keys.every(assetKey => bindings.has(assetKey)) },
138
- missing(keys) { return keys.filter(assetKey => !bindings.has(assetKey)) },
139
- keys() { return [...bindings.keys()] },
140
- values() { return [...bindings.values()] },
141
- restore() { load() },
142
- dispose() { disposed = true; bindings.clear() },
143
- }
144
- }