dsh-builtin-browser 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +1 -1
  3. package/assets/browser-panel-locales.mjs +37 -5
  4. package/assets/browser-policy.d.mts +29 -0
  5. package/assets/browser-policy.mjs +40 -0
  6. package/desktop-bridge/desktop-discovery.d.mts +1 -1
  7. package/desktop-bridge/desktop-discovery.mjs +59 -9
  8. package/desktop-bridge/desktop-identity.json +12 -0
  9. package/desktop-bridge/install.mjs +14 -7
  10. package/desktop-bridge/plugin-browser-bridge.js +19 -7
  11. package/docs/acceptance-2026-11-27.md +67 -0
  12. package/docs/architecture.md +1 -1
  13. package/docs/development.md +33 -4
  14. package/docs/dsh-0.2.3-host-patch-task.md +34 -0
  15. package/docs/hardcoding-audit.md +28 -8
  16. package/docs/known-issues.md +26 -0
  17. package/docs/limitations.md +6 -2
  18. package/docs/tool-reference.md +1 -1
  19. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  20. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  21. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  22. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  23. package/dsh-host-patch/README.md +4 -0
  24. package/dsh-host-patch/apply.mjs +61 -13
  25. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  26. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  27. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  28. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  29. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  30. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  31. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  32. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  33. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  34. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  35. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  36. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  37. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  38. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  39. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  40. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  41. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  42. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  43. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  44. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  45. package/dsh-host-patch/sources/manifest.json +218 -0
  46. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  47. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  48. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  49. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  50. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  51. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  52. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  53. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  54. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  55. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  56. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  57. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  58. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  59. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  60. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  61. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  62. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  63. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  64. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  65. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  66. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  67. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  68. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  69. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  70. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  71. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  72. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  73. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  74. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  75. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  76. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  77. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  78. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  79. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  80. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  81. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  82. package/dsh-host-patch/sources/series.json +260 -0
  83. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  84. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  85. package/dsh-host-patch/tauri-revision1.json +39 -0
  86. package/dsh-host-patch/tauri.json +43 -0
  87. package/dsh-host-patch/v023-alpha2.json +153 -0
  88. package/lib/browser/anti-bot.js +215 -0
  89. package/lib/browser/deep-dom.js +39 -0
  90. package/lib/browser/runtime.js +15 -0
  91. package/lib/browser/takeover-target.js +13 -6
  92. package/lib/browser/types.js +30 -1
  93. package/lib/browser-electron/authenticated-route.js +16 -2
  94. package/lib/browser-electron/automatic-maintenance.js +16 -10
  95. package/lib/browser-electron/bridge-connection.js +3 -8
  96. package/lib/browser-electron/bridge-install.js +2 -1
  97. package/lib/browser-electron/bridge-status.js +55 -26
  98. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  99. package/lib/browser-electron/desktop-identity.js +28 -5
  100. package/lib/browser-electron/desktop-shell.js +64 -0
  101. package/lib/browser-electron/electron-provision.js +105 -18
  102. package/lib/browser-electron/entry.js +129 -44
  103. package/lib/browser-electron/extension-browser.js +4 -4
  104. package/lib/browser-electron/foreground-watch.js +134 -0
  105. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  106. package/lib/browser-electron/guest-route.js +181 -32
  107. package/lib/browser-electron/guest-runtime.js +61 -10
  108. package/lib/browser-electron/guest-storage.js +2 -2
  109. package/lib/browser-electron/history-store.js +1 -5
  110. package/lib/browser-electron/host-main.js +8 -4
  111. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  112. package/lib/browser-electron/maintenance-route.js +2 -1
  113. package/lib/browser-electron/missing-system-browser.js +5 -9
  114. package/lib/browser-electron/preferred-browser.js +7 -3
  115. package/lib/browser-electron/preview-route.js +9 -13
  116. package/lib/browser-electron/process-ownership.js +1 -1
  117. package/lib/browser-electron/profile-command.js +2 -1
  118. package/lib/browser-electron/profile-extension.js +5 -0
  119. package/lib/browser-electron/profile-lease.js +152 -47
  120. package/lib/browser-electron/provider-core.js +527 -0
  121. package/lib/browser-electron/provider-interaction.js +963 -0
  122. package/lib/browser-electron/provider-media.js +518 -0
  123. package/lib/browser-electron/provider-navigation.js +301 -0
  124. package/lib/browser-electron/provider-observation.js +623 -0
  125. package/lib/browser-electron/provider-tabs.js +372 -0
  126. package/lib/browser-electron/provider.js +150 -3301
  127. package/lib/browser-electron/reference-route.js +9 -18
  128. package/lib/browser-electron/remote-host.js +79 -34
  129. package/lib/browser-electron/runtime-status.js +56 -6
  130. package/lib/browser-electron/settings-store.js +3 -6
  131. package/lib/browser-electron/sidebar-only-host.js +1 -1
  132. package/lib/browser-electron/system-browser.js +539 -172
  133. package/lib/browser-electron/tauri-host.js +208 -0
  134. package/lib/browser-electron/virtual-cursor.js +23 -13
  135. package/lib/browser-reference/service.js +22 -4
  136. package/lib/browser-reference/web-sources.js +1 -1
  137. package/lib/client.js +43409 -0
  138. package/lib/compat/host-features.js +75 -0
  139. package/lib/reference-source.js +1 -1
  140. package/lib/reference-text.js +23 -1
  141. package/lib/takeover-protocol.js +1 -1
  142. package/lib/tool-browser/block-recovery.js +69 -0
  143. package/lib/tool-browser/code-tool.js +170 -19
  144. package/lib/tool-browser/code-worker.js +115 -20
  145. package/lib/tool-browser/errors.js +34 -0
  146. package/lib/tool-browser/index.js +66 -3593
  147. package/lib/tool-browser/page-probe.js +227 -28
  148. package/lib/tool-browser/panel-page.js +2 -1
  149. package/lib/tool-browser/probe-client.js +157 -0
  150. package/lib/tool-browser/screenshot-annotations.js +108 -0
  151. package/lib/tool-browser/state.js +337 -0
  152. package/lib/tool-browser/takeover.js +1 -1
  153. package/lib/tool-browser/tools-debug.js +862 -0
  154. package/lib/tool-browser/tools-interaction.js +993 -0
  155. package/lib/tool-browser/tools-navigation.js +807 -0
  156. package/lib/tool-browser/tools-observation.js +461 -0
  157. package/lib/tool-browser/tools-reference.js +293 -0
  158. package/lib/web-guest.js +1 -0
  159. package/package.json +15 -53
  160. package/README.en.md +0 -89
  161. package/browser-extension/constants.mjs +0 -20
  162. package/browser-extension/controller.mjs +0 -293
  163. package/browser-extension/locales.mjs +0 -15
  164. package/browser-extension/manifest.json +0 -12
  165. package/browser-extension/options.html +0 -14
  166. package/browser-extension/options.mjs +0 -9
  167. package/browser-extension/permission-guard.mjs +0 -13
  168. package/browser-extension/worker.mjs +0 -74
  169. package/dist/client.cjs +0 -43167
  170. package/lib/browser-reference/submission-receipts.js +0 -139
  171. package/scripts/build.mjs +0 -66
  172. package/scripts/bundle-host.mjs +0 -28
  173. package/scripts/fix-exports.mjs +0 -50
  174. package/scripts/install-electron.mjs +0 -51
  175. package/scripts/verify-exports.mjs +0 -47
  176. package/scripts/verify-preview-sdk.mjs +0 -93
  177. package/skills/dsh-builtin-browser/SKILL.md +0 -73
  178. package/skills/dsh-builtin-browser/references/batch.md +0 -53
  179. package/skills/dsh-builtin-browser/references/deliver.md +0 -31
  180. package/skills/dsh-builtin-browser/references/locate.md +0 -11
  181. package/skills/dsh-builtin-browser/references/recover.md +0 -11
  182. package/skills/dsh-builtin-browser/references/verify.md +0 -13
  183. package/skills/dsh-debug-host/SKILL.md +0 -56
  184. package/skills/dsh-debug-self/SKILL.md +0 -50
  185. package/src/bridge-compatibility.ts +0 -39
  186. package/src/browser/handles.ts +0 -89
  187. package/src/browser/runtime.ts +0 -560
  188. package/src/browser/takeover-target.ts +0 -36
  189. package/src/browser/types.ts +0 -817
  190. package/src/browser-electron/authenticated-route.ts +0 -84
  191. package/src/browser-electron/automatic-maintenance.ts +0 -726
  192. package/src/browser-electron/bridge-auto.ts +0 -159
  193. package/src/browser-electron/bridge-connection.ts +0 -385
  194. package/src/browser-electron/bridge-endpoint.ts +0 -129
  195. package/src/browser-electron/bridge-install.ts +0 -289
  196. package/src/browser-electron/bridge-maintenance.ts +0 -189
  197. package/src/browser-electron/bridge-status.ts +0 -347
  198. package/src/browser-electron/desktop-bridge-host.ts +0 -251
  199. package/src/browser-electron/desktop-identity.ts +0 -320
  200. package/src/browser-electron/document-readiness.ts +0 -45
  201. package/src/browser-electron/electron-provision.ts +0 -261
  202. package/src/browser-electron/entry.ts +0 -1299
  203. package/src/browser-electron/ephemeral-profile.ts +0 -189
  204. package/src/browser-electron/extension-browser.ts +0 -223
  205. package/src/browser-electron/extension-setup.ts +0 -67
  206. package/src/browser-electron/file-write.ts +0 -31
  207. package/src/browser-electron/guest-cookie-jar.ts +0 -176
  208. package/src/browser-electron/guest-cookie-store.ts +0 -59
  209. package/src/browser-electron/guest-css-runtime.ts +0 -76
  210. package/src/browser-electron/guest-css.ts +0 -68
  211. package/src/browser-electron/guest-route.ts +0 -568
  212. package/src/browser-electron/guest-runtime.ts +0 -357
  213. package/src/browser-electron/guest-storage-runtime.ts +0 -54
  214. package/src/browser-electron/guest-storage.ts +0 -117
  215. package/src/browser-electron/history-store.ts +0 -227
  216. package/src/browser-electron/host-main.ts +0 -1381
  217. package/src/browser-electron/host-patch-maintenance.ts +0 -112
  218. package/src/browser-electron/http-body.ts +0 -65
  219. package/src/browser-electron/json-reply.ts +0 -47
  220. package/src/browser-electron/maintenance-broker.ts +0 -166
  221. package/src/browser-electron/maintenance-lifecycle.ts +0 -91
  222. package/src/browser-electron/maintenance-route.ts +0 -67
  223. package/src/browser-electron/missing-system-browser.ts +0 -113
  224. package/src/browser-electron/open-slot.ts +0 -49
  225. package/src/browser-electron/paths.ts +0 -25
  226. package/src/browser-electron/preferred-browser.ts +0 -120
  227. package/src/browser-electron/preview-route.ts +0 -218
  228. package/src/browser-electron/process-ownership.ts +0 -168
  229. package/src/browser-electron/process.ts +0 -23
  230. package/src/browser-electron/profile-checkpoint.ts +0 -187
  231. package/src/browser-electron/profile-command.ts +0 -46
  232. package/src/browser-electron/profile-extension.ts +0 -124
  233. package/src/browser-electron/profile-lease.ts +0 -115
  234. package/src/browser-electron/profile-residue.ts +0 -49
  235. package/src/browser-electron/provider.ts +0 -4571
  236. package/src/browser-electron/reference-route.ts +0 -608
  237. package/src/browser-electron/remote-host.ts +0 -1462
  238. package/src/browser-electron/rpc-input.ts +0 -13
  239. package/src/browser-electron/rpc-ops.ts +0 -41
  240. package/src/browser-electron/runtime-diagnostics.ts +0 -38
  241. package/src/browser-electron/runtime-route.ts +0 -105
  242. package/src/browser-electron/runtime-status.ts +0 -242
  243. package/src/browser-electron/settings-route.ts +0 -64
  244. package/src/browser-electron/settings-store.ts +0 -589
  245. package/src/browser-electron/shortcuts-route.ts +0 -112
  246. package/src/browser-electron/sidebar-only-host.ts +0 -298
  247. package/src/browser-electron/startpage-shortcuts.ts +0 -213
  248. package/src/browser-electron/system-browser.ts +0 -1497
  249. package/src/browser-electron/timing.ts +0 -16
  250. package/src/browser-electron/virtual-cursor.ts +0 -152
  251. package/src/browser-electron/windows-system.ts +0 -24
  252. package/src/browser-reference/delivery.ts +0 -384
  253. package/src/browser-reference/entry.ts +0 -631
  254. package/src/browser-reference/export.ts +0 -339
  255. package/src/browser-reference/import.ts +0 -303
  256. package/src/browser-reference/page-script.ts +0 -1537
  257. package/src/browser-reference/service.ts +0 -1315
  258. package/src/browser-reference/store.ts +0 -172
  259. package/src/browser-reference/submission-receipts.ts +0 -122
  260. package/src/browser-reference/text-quote.ts +0 -219
  261. package/src/browser-reference/types.ts +0 -195
  262. package/src/browser-reference/visible.ts +0 -367
  263. package/src/browser-reference/web-sources.ts +0 -103
  264. package/src/client/browser/BrowserController.ts +0 -693
  265. package/src/client/browser/BrowserFrame.ts +0 -78
  266. package/src/client/browser/BrowserNavigation.ts +0 -169
  267. package/src/client/browser/BrowserPage.ts +0 -23
  268. package/src/client/browser/BrowserPersistence.ts +0 -44
  269. package/src/client/browser/IframeImpl.ts +0 -176
  270. package/src/client/browser/child-tabs.ts +0 -14
  271. package/src/client/browser/iframe-reference.ts +0 -67
  272. package/src/client/browser/initialization.ts +0 -262
  273. package/src/client/browser/omnibox.ts +0 -243
  274. package/src/client/browser/store.ts +0 -38
  275. package/src/client/browser/takeover-channel.ts +0 -72
  276. package/src/client/browser/url.ts +0 -46
  277. package/src/client/browser/web-reference-source.ts +0 -52
  278. package/src/client/css-modules.d.ts +0 -4
  279. package/src/client/definition.tsx +0 -30
  280. package/src/client/electron/ElectronWebViewImpl.ts +0 -364
  281. package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
  282. package/src/client/electron/NativeChildPresentation.ts +0 -45
  283. package/src/client/electron/NativeViewPage.ts +0 -251
  284. package/src/client/electron/pages.ts +0 -23
  285. package/src/client/electron/reference-overlay.ts +0 -53
  286. package/src/client/electron/workspace.ts +0 -33
  287. package/src/client/index.ts +0 -293
  288. package/src/client/locales.ts +0 -857
  289. package/src/client/pages.ts +0 -28
  290. package/src/client/reference/client/BrowserRefLink.tsx +0 -142
  291. package/src/client/reference/client/draft-reference.ts +0 -167
  292. package/src/client/reference/client/index.ts +0 -7
  293. package/src/client/reference/client/ordered-submission.ts +0 -108
  294. package/src/client/reference/client/pending-delivery.ts +0 -216
  295. package/src/client/reference/client/plugin.ts +0 -189
  296. package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
  297. package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
  298. package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
  299. package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
  300. package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
  301. package/src/client/reference/client/production/ReferenceText.tsx +0 -36
  302. package/src/client/reference/client/production/assembly.ts +0 -471
  303. package/src/client/reference/client/production/asset-store.ts +0 -144
  304. package/src/client/reference/client/production/availability.ts +0 -74
  305. package/src/client/reference/client/production/bytes.ts +0 -36
  306. package/src/client/reference/client/production/delivery-client.ts +0 -211
  307. package/src/client/reference/client/production/draft-adapter.ts +0 -508
  308. package/src/client/reference/client/production/http-transport.ts +0 -217
  309. package/src/client/reference/client/production/production-submission.ts +0 -310
  310. package/src/client/reference/client/production/protocol.ts +0 -231
  311. package/src/client/reference/client/production/reference-card.ts +0 -240
  312. package/src/client/reference/client/production/reference-labels.ts +0 -29
  313. package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
  314. package/src/client/reference/client/production/reveal.ts +0 -215
  315. package/src/client/reference/client/production/runtime.ts +0 -1101
  316. package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
  317. package/src/client/reference/client/production/source-marker.ts +0 -63
  318. package/src/client/reference/client/production/source-opener.ts +0 -55
  319. package/src/client/reference/client/production/styles.ts +0 -104
  320. package/src/client/reference/client/production/user-text-rule.ts +0 -58
  321. package/src/client/reference/client/reveal.ts +0 -107
  322. package/src/client/reference/client/scheme.ts +0 -114
  323. package/src/client/reference/client/types.ts +0 -168
  324. package/src/client/reference/css-modules.d.ts +0 -4
  325. package/src/client/reference/index.ts +0 -11
  326. package/src/client/reference-capture-owner.ts +0 -162
  327. package/src/client/reference-intents.ts +0 -36
  328. package/src/client/settings/index.ts +0 -34
  329. package/src/client/settings/panel.ts +0 -2657
  330. package/src/client/shortcut-open.ts +0 -30
  331. package/src/client/startpage/binding.ts +0 -99
  332. package/src/client/startpage/controller.ts +0 -303
  333. package/src/client/startpage/model.ts +0 -279
  334. package/src/client/view/Browser.module.css +0 -751
  335. package/src/client/view/BrowserBody.tsx +0 -314
  336. package/src/client/view/BrowserPresentation.ts +0 -9
  337. package/src/client/view/BrowserTitle.tsx +0 -17
  338. package/src/client/view/IframePresentation.ts +0 -344
  339. package/src/client/view/StartPage.tsx +0 -597
  340. package/src/client/view/TakeoverBanner.tsx +0 -21
  341. package/src/index.ts +0 -110
  342. package/src/reference-owner.ts +0 -5
  343. package/src/reference-page.ts +0 -9
  344. package/src/reference-source.ts +0 -3
  345. package/src/reference-text.ts +0 -197
  346. package/src/startpage-settings.ts +0 -103
  347. package/src/startpage.ts +0 -71
  348. package/src/takeover-protocol.ts +0 -19
  349. package/src/tool-browser/code-tool.ts +0 -401
  350. package/src/tool-browser/code-worker.ts +0 -639
  351. package/src/tool-browser/element-fields.ts +0 -167
  352. package/src/tool-browser/index.ts +0 -3733
  353. package/src/tool-browser/page-probe.ts +0 -474
  354. package/src/tool-browser/panel-page.ts +0 -124
  355. package/src/tool-browser/screenshot-image.ts +0 -49
  356. package/src/tool-browser/takeover.ts +0 -198
  357. package/src/types/electron-shim.d.ts +0 -144
  358. package/src/types.ts +0 -85
  359. package/src/web-guest.ts +0 -34
  360. package/tools/accept-desktop.mjs +0 -148
@@ -1,217 +0,0 @@
1
- /**
2
- * Injected HTTP client for the built-in browser reference endpoints.
3
- *
4
- * No `fetch` global and no host transport is imported: a `RequestLike` function
5
- * is injected. The concrete `createReferenceHttpClient` builds the exact paths,
6
- * query strings and JSON bodies the plugin router expects, so a unit test can
7
- * assert on the real URL/params rather than on "fetch was called".
8
- *
9
- * Reads rely on the host cookie (the plugin's `requireRead`); writes add the
10
- * same-origin + loopback boundaries server-side, so the client only needs to
11
- * send credentials and a JSON content type.
12
- *
13
- * The plugin routes are EXACT paths registered on DSH's OWN webServer, so the
14
- * client uses SAME-ORIGIN RELATIVE paths (`/dsh-builtin-browser/reference/...`)
15
- * and NEVER hardcodes a port. `baseUrl` defaults to '' on purpose: a 3080 (or
16
- * any other) fallback would disguise "plugin version too old" as a routing
17
- * problem. A missing route (404) is surfaced as `plugin-too-old`, never retried
18
- * against another origin.
19
- *
20
- * @module dsh-browser-reference/production/http-transport
21
- */
22
- import {
23
- ROUTES,
24
- ReferenceHttpError,
25
- type AckRequest,
26
- type AckResponse,
27
- type AssetResponse,
28
- type DeliveriesResponse,
29
- type ExportFormat,
30
- type RemoveResponse,
31
- type RevealResultWire,
32
- } from './protocol.ts'
33
- import { isDeliveriesResponse } from './availability.ts'
34
-
35
- /** Minimal response face; `json` and `bytes` cover every route we consume. */
36
- export interface RawResponse {
37
- readonly status: number
38
- readonly ok: boolean
39
- json(): Promise<unknown>
40
- bytes(): Promise<Uint8Array>
41
- }
42
-
43
- export interface RequestInitLike {
44
- readonly method?: string
45
- readonly headers?: Readonly<Record<string, string>>
46
- readonly body?: string | Uint8Array
47
- }
48
-
49
- /** Injected request function (a thin `fetch` adapter in the host assembly). */
50
- export type RequestLike = (url: string, init?: RequestInitLike) => Promise<RawResponse>
51
-
52
- export interface ReferenceHttpClient {
53
- deliveries(sessionId: string, since: number): Promise<DeliveriesResponse>
54
- assetBase64(key: string): Promise<AssetResponse>
55
- assetBytes(key: string): Promise<Uint8Array>
56
- ack(request: AckRequest): Promise<AckResponse>
57
- /** Persist an accepted message's consumption independently of browser storage. */
58
- consume?(sessionId: string, intentId: string): Promise<void>
59
- bindSubmission?(sessionId: string, requestId: string, intentIds: readonly string[]): Promise<void>
60
- remove(intentId: string): Promise<RemoveResponse>
61
- reveal(referenceId: string, partId?: string, navigate?: boolean, sourcePageId?: string): Promise<RevealResultWire>
62
- exportBundle(format: ExportFormat, sessionId: string): Promise<Uint8Array>
63
- importBundle(zip: Uint8Array): Promise<unknown>
64
- }
65
-
66
- export interface HttpClientOptions {
67
- /** Origin of the plugin HTTP surface, e.g. `http://127.0.0.1:<port>`. No trailing slash. */
68
- readonly baseUrl?: string
69
- readonly request: RequestLike
70
- /** Abort signal forwarded per request for cancellable polling. */
71
- readonly signal?: () => AbortSignal | undefined
72
- }
73
-
74
- function query(params: Readonly<Record<string, string | number | undefined>>): string {
75
- const parts: string[] = []
76
- for (const [key, value] of Object.entries(params)) {
77
- if (value === undefined) continue
78
- parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
79
- }
80
- return parts.length === 0 ? '' : `?${parts.join('&')}`
81
- }
82
-
83
- function jsonHeaders(): Readonly<Record<string, string>> {
84
- return { 'content-type': 'application/json' }
85
- }
86
-
87
- /** Build the typed client over one injected request function. */
88
- export function createReferenceHttpClient(options: HttpClientOptions): ReferenceHttpClient {
89
- const base = (options.baseUrl ?? '').replace(/\/+$/u, '')
90
- const request = options.request
91
-
92
- const readJson = async (url: string): Promise<unknown> => {
93
- const response = await request(url)
94
- if (!response.ok) {
95
- let body: unknown
96
- try { body = await response.json() } catch { /* error bodies are best-effort */ }
97
- throw new ReferenceHttpError(`GET ${url} failed with ${response.status}`, response.status, body)
98
- }
99
- return response.json()
100
- }
101
-
102
- const writeJson = async (url: string, payload: unknown): Promise<unknown> => {
103
- const response = await request(url, {
104
- method: 'POST',
105
- headers: jsonHeaders(),
106
- body: JSON.stringify(payload),
107
- })
108
- if (!response.ok) {
109
- let body: unknown
110
- try { body = await response.json() } catch { /* error bodies are best-effort */ }
111
- throw new ReferenceHttpError(`POST ${url} failed with ${response.status}`, response.status, body)
112
- }
113
- return response.json()
114
- }
115
-
116
- return {
117
- async deliveries(sessionId, since) {
118
- const url = `${base}${ROUTES.deliveries}${query({ sessionId, since: since > 0 ? since : undefined, includeConsumed: 1 })}`
119
- const body: unknown = await readJson(url)
120
- // A 200 with an unexpected shape is a real failure (old/incompatible
121
- // plugin), not an empty delivery list. Status 0 is the shape-mismatch
122
- // sentinel consumed by availabilityOf().
123
- if (!isDeliveriesResponse(body)) {
124
- throw new ReferenceHttpError('invalid /reference/deliveries payload shape', 0, body)
125
- }
126
- return body
127
- },
128
- async assetBase64(key) {
129
- const url = `${base}${ROUTES.asset}${query({ key, encoding: 'base64' })}`
130
- return await readJson(url) as AssetResponse
131
- },
132
- async assetBytes(key) {
133
- const url = `${base}${ROUTES.asset}${query({ key })}`
134
- const response = await request(url)
135
- if (!response.ok) throw new ReferenceHttpError(`asset ${key} failed with ${response.status}`, response.status)
136
- return response.bytes()
137
- },
138
- async ack(ack) {
139
- const body: Record<string, unknown> = {
140
- intentId: ack.intentId,
141
- draftRev: ack.draftRev,
142
- assetKeys: [...ack.assetKeys],
143
- }
144
- if (ack.phase !== undefined) body.phase = ack.phase
145
- return await writeJson(`${base}${ROUTES.ack}`, body) as AckResponse
146
- },
147
- async consume(sessionId, intentId) {
148
- const result = await writeJson(`${base}${ROUTES.ack}`, { phase: 'consumed', sessionId, intentId }) as { state?: unknown }
149
- if (result.state !== 'consumed') throw new Error('reference consumption was not persisted')
150
- },
151
- async bindSubmission(sessionId, requestId, intentIds) {
152
- const result = await writeJson(`${base}${ROUTES.ack}`, { phase: 'submitting', sessionId, requestId, intentIds }) as { state?: unknown }
153
- if (result.state !== 'submitting') throw new Error('reference submission was not recorded')
154
- },
155
- async remove(intentId) {
156
- return await writeJson(`${base}${ROUTES.remove}`, { intentId }) as RemoveResponse
157
- },
158
- async reveal(referenceId, partId, navigate, sourcePageId) {
159
- const body: Record<string, unknown> = { referenceId }
160
- if (sourcePageId !== undefined) body.sourcePageId = sourcePageId
161
- if (partId !== undefined) body.partId = partId
162
- // The page is moved to the source by the plugin, which owns it.
163
- if (navigate === true) body.navigate = true
164
- return await writeJson(`${base}${ROUTES.reveal}`, body) as RevealResultWire
165
- },
166
- async exportBundle(format, sessionId) {
167
- const url = `${base}${ROUTES.export}${query({ format, sessionId })}`
168
- const response = await request(url)
169
- if (!response.ok) throw new ReferenceHttpError(`export failed with ${response.status}`, response.status)
170
- return response.bytes()
171
- },
172
- async importBundle(zip) {
173
- const response = await request(`${base}${ROUTES.import}`, {
174
- method: 'POST',
175
- headers: { 'content-type': 'application/zip' },
176
- body: zip,
177
- })
178
- if (!response.ok) throw new ReferenceHttpError(`import failed with ${response.status}`, response.status)
179
- return response.json()
180
- },
181
- }
182
- }
183
-
184
- /** Wrap the host's real `fetch` into the injected `RequestLike` shape. */
185
- export function createFetchRequest(
186
- fetchImpl: (input: string, init?: {
187
- method?: string
188
- headers?: Record<string, string>
189
- body?: string | Uint8Array
190
- credentials?: RequestCredentials
191
- signal?: AbortSignal
192
- }) => Promise<{
193
- ok: boolean
194
- status: number
195
- json(): Promise<unknown>
196
- arrayBuffer(): Promise<ArrayBuffer>
197
- }>,
198
- signal?: () => AbortSignal | undefined,
199
- ): RequestLike {
200
- return async (url, init) => {
201
- const activeSignal = signal?.()
202
- const fetchInit = {
203
- ...(init?.method === undefined ? {} : { method: init.method }),
204
- ...(init?.headers === undefined ? {} : { headers: { ...init.headers } }),
205
- ...(init?.body === undefined ? {} : { body: init.body }),
206
- credentials: 'include' as const,
207
- ...(activeSignal === undefined ? {} : { signal: activeSignal }),
208
- }
209
- const response = await fetchImpl(url, fetchInit)
210
- return {
211
- ok: response.ok,
212
- status: response.status,
213
- json: () => response.json(),
214
- bytes: async () => new Uint8Array(await response.arrayBuffer()),
215
- }
216
- }
217
- }
@@ -1,310 +0,0 @@
1
- /**
2
- * Ordered submission projection into the HOST's real prompt content blocks.
3
- *
4
- * The host's `service.ts:302` currently builds
5
- * `content = [...uploaded, ...(text === '' ? [] : [{ type: 'text', text }])]`
6
- * where `uploaded` are already-serialized `PromptContentPart`s from the host's
7
- * image/file attachment admission. We REUSE `createSubmissionProjector` (the
8
- * additive contract) to interleave the captured groups in capture order, then
9
- * map its `text`/`image`/`table` parts into the host's content vocabulary:
10
- * - `text` / `table` -> `{ type: 'text', text }` (verbatim / structural text);
11
- * - `image` -> `admitImage(assetKey)` -> a REAL `{ type: 'image', data }` or
12
- * `{ type: 'file', receiptId }` from the host attachment service. NEVER a
13
- * URL and NEVER alt text; an unbound image keeps its slot as a placeholder.
14
- *
15
- * Host attachments (`uploaded`) stay first and the plain composer text stays
16
- * last, matching `service.ts:302` ("附件在前文字在后"); group parts are inserted
17
- * between them in order.
18
- *
19
- * This module does NOT import or modify `service.ts`. `wireSubmissionContent`
20
- * is the injectable seam the host calls at line 302 (see deploy/README.md).
21
- *
22
- * @module dsh-browser-reference/production/production-submission
23
- */
24
- import { renderReferenceMarkdownTable } from '../../../../reference-text.ts'
25
- import { referenceOwnerKey } from '../../../../reference-owner.ts'
26
- import type { OrderedReferenceGroup } from '../types.ts'
27
- import { createSubmissionProjector, type TextPosition } from '../ordered-submission.ts'
28
- import { composerText, sourceMarker, submissionQuote } from './source-marker.ts'
29
- import type { AssetStore } from './asset-store.ts'
30
-
31
- /** Mirror of `session-controller/src/types.ts:78` (no cross-package import). */
32
- export type HostPromptContentPart =
33
- | { readonly type: 'text'; readonly text: string }
34
- | { readonly type: 'image'; readonly mediaType: string; readonly data: string; readonly name?: string }
35
- | { readonly type: 'file'; readonly receiptId: string }
36
-
37
- /**
38
- * Resolve one captured image asset into a host-admitted content block.
39
- * Returns undefined when the asset is not durably bound yet.
40
- */
41
- export type AdmitImage = (assetKey: string, partId: string) => HostPromptContentPart | undefined
42
-
43
- /**
44
- * Default admission backed by the durable asset store: inline real bytes, or a
45
- * file receipt when the host uploaded the asset. This is the "宿主已有的
46
- * 图片/文件附件准入与持久服务" output, not a page URL.
47
- */
48
- export function createAdmitImage(assets: AssetStore): AdmitImage {
49
- return (assetKey, partId) => {
50
- const binding = assets.get(assetKey)
51
- if (binding === undefined) return undefined
52
- if (binding.receiptId !== undefined) {
53
- return { type: 'file', receiptId: binding.receiptId }
54
- }
55
- return {
56
- type: 'image',
57
- mediaType: binding.mime,
58
- data: binding.data,
59
- name: partId,
60
- }
61
- }
62
- }
63
-
64
- export interface WireSubmissionInput {
65
- /** Host-serialized attachments, kept verbatim at the front. */
66
- readonly uploaded: readonly HostPromptContentPart[]
67
- /** Plain composer text; kept last (matching service.ts:302). */
68
- readonly text: string
69
- /** Ordered captured groups for this session. */
70
- readonly groups: readonly OrderedReferenceGroup[]
71
- readonly admitImage: AdmitImage
72
- readonly textPosition?: TextPosition
73
- /**
74
- * The user's note per reference. It is submitted as its OWN labelled block so
75
- * the model never confuses the human's words with the quoted page text
76
- * (three-state §6).
77
- */
78
- readonly comments?: ReadonlyMap<string, string>
79
- /**
80
- * Emit one clickable `dsh-browser-ref:` source marker per group. Defaults to
81
- * TRUE so the real send path always produces a locatable source. Setting it
82
- * to false restores the exact pre-marker projection (byte-identical to the
83
- * old output), which is the comparison/rollback lever for A/B tests and for
84
- * diagnosing a bad link without changing what the model received.
85
- */
86
- readonly sourceLinks?: boolean
87
- /**
88
- * Optional page title per reference, used ONLY as the marker's visible text
89
- * (never inside the URI). When absent a stable `引用来源 N` label is used.
90
- * `toOrderedGroup` drops `source.title`, so production currently takes the
91
- * fallback; the callback is the seam a host can wire to surface real titles.
92
- */
93
- readonly sourceTitleFor?: (referenceId: string) => string | undefined
94
- }
95
-
96
- /** The prefix that keeps a note distinguishable from the quoted original. */
97
- export const COMMENT_LABEL = '引用评论'
98
- /** Stable visible label for one attached reference's source marker. */
99
- export { SOURCE_LINK_LABEL } from './source-marker.ts'
100
-
101
- /**
102
- * Build the `content` array for `Session.prompt`. With `groups === []` the
103
- * result is byte-identical to the host's current `[...uploaded, ...text]`.
104
- */
105
- export function wireSubmissionContent(input: WireSubmissionInput): readonly HostPromptContentPart[] {
106
- const perGroup = createSubmissionProjector({ mode: 'ordered' })
107
- const text = composerText(input.text, new Set(input.groups.map(group => group.referenceId)))
108
- const quoteText = (text: string): string => input.sourceLinks === false ? text : submissionQuote(text)
109
- const projectedBlocks = (groups: readonly OrderedReferenceGroup[]): HostPromptContentPart[] =>
110
- perGroup.project({ text: '', uploaded: [], groups }).map(part => {
111
- const mapped = mapProjected(part, input.admitImage)
112
- return mapped.type === 'text' ? { type: 'text', text: quoteText(`${mapped.text}\n`) } : mapped
113
- })
114
- const placeUserText = (blocks: HostPromptContentPart[]): void => {
115
- if (text === '') return
116
- const block: HostPromptContentPart = { type: 'text', text }
117
- if (input.textPosition === 'leading') blocks.unshift(block)
118
- else blocks.push(block)
119
- }
120
- // Source markers are ONE extra independent text block appended AFTER every
121
- // projected group (and after every note), BEFORE the user's own question.
122
- // They never touch a projected block, so quoted text stays verbatim and keeps
123
- // its trailing newline (the fifth-round fix). With no groups nothing is added,
124
- // so `groups === []` stays byte-identical to service.ts:302.
125
- const appendSourceMarkers = (blocks: HostPromptContentPart[]): void => {
126
- if (input.sourceLinks === false || input.groups.length === 0) return
127
- const markers: string[] = []
128
- input.groups.forEach((group, index) => {
129
- try {
130
- markers.push(sourceMarker(group.referenceId, index, input.sourceTitleFor?.(group.referenceId)))
131
- } catch {
132
- // A referenceId that cannot be canonicalized must not break the whole
133
- // send: that single group simply has no marker (B20 partial visibility).
134
- }
135
- })
136
- if (markers.length === 0) return
137
- blocks.push({ type: 'text', text: `${markers.join('\n')}\n${submissionQuote('Browser reference presentation: the attached references are already displayed as interactive capsules. Do not repeat their markers, reference URIs, source URLs, or source/citation links in the reply. Answer using the quoted content; the capsules provide source navigation.')}` })
138
- }
139
- const noted = input.comments === undefined
140
- ? undefined
141
- : input.groups.filter(group => (input.comments?.get(group.referenceId) ?? '') !== '')
142
- if (noted !== undefined && noted.length > 0 && input.comments !== undefined) {
143
- // Project group by group so each note lands immediately before the content
144
- // it annotates, while the parts inside a group keep their captured order.
145
- const withNotes: HostPromptContentPart[] = []
146
- for (const group of input.groups) {
147
- const note = input.comments.get(group.referenceId)
148
- if (note !== undefined && note !== '') {
149
- // A plain label, not markdown: the user's own message text is rendered as text, so asterisks showed
150
- // up literally ("**引用评论**:123"). Brackets looked like page content; a bare label reads as a
151
- // label in every renderer.
152
- withNotes.push({ type: 'text', text: quoteText(`${COMMENT_LABEL}:${note}\n`) })
153
- }
154
- withNotes.push(...projectedBlocks([group]))
155
- }
156
- appendSourceMarkers(withNotes)
157
- placeUserText(withNotes)
158
- return [...input.uploaded, ...withNotes]
159
- }
160
- const blocks: HostPromptContentPart[] = projectedBlocks(input.groups)
161
- appendSourceMarkers(blocks)
162
- placeUserText(blocks)
163
- return [...input.uploaded, ...blocks]
164
- }
165
-
166
- /** Map one projected part into the host's content vocabulary. */
167
- function mapProjected(
168
- part: ReturnType<ReturnType<typeof createSubmissionProjector>['project']>[number],
169
- admitImage: AdmitImage,
170
- ): HostPromptContentPart {
171
- switch (part.type) {
172
- case 'text':
173
- return { type: 'text', text: part.text }
174
- case 'table':
175
- return { type: 'text', text: part.table === undefined ? part.text : renderReferenceMarkdownTable(part.table) }
176
- case 'image': {
177
- const admitted = admitImage(part.assetKey, part.partId ?? part.assetKey)
178
- return admitted ?? { type: 'text', text: `[image unavailable: ${part.partId ?? part.assetKey}]` }
179
- }
180
- default: {
181
- const exhaustive: never = part
182
- throw new Error(`unhandled projected part: ${JSON.stringify(exhaustive)}`)
183
- }
184
- }
185
- }
186
-
187
- /**
188
- * Injection seam the host registers; binds a session id to its stored groups.
189
- * `requestId` is OPTIONAL everywhere, so implementations/tests that omit it
190
- * keep working through a FIFO fallback.
191
- */
192
- export interface SubmissionSeam {
193
- /** Reconcile durable consumption before projecting a restored draft. */
194
- prepare?(sessionId: string): Promise<void>
195
- bind?(sessionId: string, requestId: string, hostRequestId: string): Promise<void>
196
- /** Replacement for the `content = [...uploaded, ...text]` line at service.ts:302. */
197
- buildContent(input: {
198
- readonly sessionId: string
199
- readonly uploaded: readonly HostPromptContentPart[]
200
- readonly text: string
201
- /** Stable per-send id; lets concurrent sends keep separate frozen sets. */
202
- readonly requestId?: string
203
- }): readonly HostPromptContentPart[]
204
- /**
205
- * Consume the exact set frozen by this send's `buildContent`.
206
- *
207
- * The host calls this only after `Session.prompt` ACCEPTED the content. A
208
- * projection alone must never clear the draft: a refused send would drop the
209
- * references the user still sees, and a footnote would no longer point at the
210
- * message it came with. References added while the send was in flight are not
211
- * part of the frozen set and stay in the draft.
212
- */
213
- commit(sessionId: string, requestId?: string): void | Promise<void>
214
- /**
215
- * Drop the frozen set without consuming anything (refused or thrown send).
216
- *
217
- * The draft keeps every reference, so the user can fix the problem and send
218
- * again with the same quotes.
219
- */
220
- rollback(sessionId: string, requestId?: string): void
221
- }
222
-
223
- export interface CreateSubmissionSeamOptions {
224
- readonly bind?: (sessionId: string, hostRequestId: string, intentIds: readonly string[]) => Promise<void>
225
- /** Resolve the ordered groups for one session (from the session draft store). */
226
- readonly groupsFor: (sessionId: string) => readonly OrderedReferenceGroup[]
227
- /** Resolve the durable asset store for one session. */
228
- readonly assetsFor: (sessionId: string) => AssetStore
229
- /** The draft's notes per reference, submitted as labelled blocks. */
230
- readonly commentsFor?: (sessionId: string) => ReadonlyMap<string, string>
231
- /**
232
- * Called with the exact reference ids a now-accepted send carried, so the
233
- * draft stops holding them while the sent message keeps their provenance.
234
- *
235
- * Without this the next message re-attaches the same quote: the card survived the
236
- * send, and a restart rebuilt it from its acknowledged delivery.
237
- */
238
- readonly submitted?: (sessionId: string, referenceIds: readonly string[]) => void | Promise<void>
239
- readonly textPosition?: TextPosition
240
- /** Passed through to `wireSubmissionContent`; omitted => source links ON. */
241
- readonly sourceLinks?: boolean
242
- /** Optional visible page title per reference for the source markers. */
243
- readonly sourceTitleFor?: (referenceId: string) => string | undefined
244
- }
245
-
246
- /** Build the seam the assembly registers into the host context. */
247
- export function createSubmissionSeam(options: CreateSubmissionSeamOptions): SubmissionSeam {
248
- /** One frozen set per requestId — never a single overwritable per-session key. */
249
- const tokenized = new Map<string, readonly string[]>()
250
- /** Untagged sends (older hosts / tests) fall back to a per-session FIFO queue. */
251
- const untagged = new Map<string, string[][]>()
252
-
253
- const consume = (sessionId: string, requestId?: string): readonly string[] | undefined => {
254
- if (requestId !== undefined) {
255
- const ids = tokenized.get(requestId)
256
- tokenized.delete(requestId)
257
- if (ids !== undefined) return ids
258
- }
259
- const queue = untagged.get(sessionId)
260
- const ids = queue?.shift()
261
- if (queue !== undefined && queue.length === 0) untagged.delete(sessionId)
262
- return ids
263
- }
264
-
265
- return {
266
- async bind(sessionId, requestId, hostRequestId) {
267
- sessionId = referenceOwnerKey(sessionId)
268
- const ids = tokenized.get(requestId)
269
- if (ids !== undefined && ids.length > 0) await options.bind?.(sessionId, hostRequestId, ids)
270
- },
271
- buildContent({ sessionId: rawSessionId, uploaded, text, requestId }) {
272
- // The send path passes the shell's "session-<uuid>"; the draft store, the comments and the asset
273
- // bindings are all keyed on the bare id. Without this the chips were visible in the composer while
274
- // buildContent saw ZERO groups, so the message went out with the typed text alone and the model
275
- // answered "there is nothing attached".
276
- const sessionId = referenceOwnerKey(rawSessionId)
277
- const groups = options.groupsFor(sessionId)
278
- const content = wireSubmissionContent({
279
- uploaded,
280
- text,
281
- groups,
282
- admitImage: createAdmitImage(options.assetsFor(sessionId)),
283
- ...options.commentsFor === undefined ? {} : { comments: options.commentsFor(sessionId) },
284
- ...(options.textPosition === undefined ? {} : { textPosition: options.textPosition }),
285
- ...(options.sourceLinks === undefined ? {} : { sourceLinks: options.sourceLinks }),
286
- ...(options.sourceTitleFor === undefined ? {} : { sourceTitleFor: options.sourceTitleFor }),
287
- })
288
- const ids = groups.map(group => group.referenceId)
289
- // Pure read: remember what this projection used, decide nothing yet.
290
- if (requestId !== undefined) tokenized.set(requestId, ids)
291
- else {
292
- const queue = untagged.get(sessionId) ?? []
293
- queue.push(ids)
294
- untagged.set(sessionId, queue)
295
- }
296
- return content
297
- },
298
- commit(sessionId, requestId) {
299
- sessionId = referenceOwnerKey(sessionId)
300
- const referenceIds = consume(sessionId, requestId)
301
- if (referenceIds !== undefined && referenceIds.length > 0) {
302
- return options.submitted?.(sessionId, referenceIds)
303
- }
304
- },
305
- rollback(sessionId, requestId) {
306
- sessionId = referenceOwnerKey(sessionId)
307
- consume(sessionId, requestId)
308
- },
309
- }
310
- }