dsh-builtin-browser 1.0.1 → 1.0.4

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 (222) 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-host-patch/README.md +4 -0
  22. package/dsh-host-patch/apply.mjs +61 -13
  23. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  24. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  25. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  26. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  27. package/dsh-host-patch/tauri-revision1.json +39 -0
  28. package/dsh-host-patch/tauri.json +43 -0
  29. package/dsh-host-patch/v023-alpha2.json +153 -0
  30. package/lib/browser/anti-bot.js +215 -0
  31. package/lib/browser/deep-dom.js +39 -0
  32. package/lib/browser/runtime.js +15 -0
  33. package/lib/browser/takeover-target.js +13 -6
  34. package/lib/browser/types.js +30 -1
  35. package/lib/browser-electron/authenticated-route.js +16 -2
  36. package/lib/browser-electron/automatic-maintenance.js +16 -10
  37. package/lib/browser-electron/bridge-connection.js +3 -8
  38. package/lib/browser-electron/bridge-install.js +2 -1
  39. package/lib/browser-electron/bridge-status.js +55 -26
  40. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  41. package/lib/browser-electron/desktop-identity.js +28 -5
  42. package/lib/browser-electron/desktop-shell.js +64 -0
  43. package/lib/browser-electron/electron-provision.js +105 -18
  44. package/lib/browser-electron/entry.js +129 -44
  45. package/lib/browser-electron/extension-browser.js +4 -4
  46. package/lib/browser-electron/foreground-watch.js +134 -0
  47. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  48. package/lib/browser-electron/guest-route.js +181 -32
  49. package/lib/browser-electron/guest-runtime.js +61 -10
  50. package/lib/browser-electron/guest-storage.js +2 -2
  51. package/lib/browser-electron/history-store.js +1 -5
  52. package/lib/browser-electron/host-main.js +8 -4
  53. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  54. package/lib/browser-electron/maintenance-route.js +2 -1
  55. package/lib/browser-electron/missing-system-browser.js +5 -9
  56. package/lib/browser-electron/preferred-browser.js +7 -3
  57. package/lib/browser-electron/preview-route.js +9 -13
  58. package/lib/browser-electron/process-ownership.js +1 -1
  59. package/lib/browser-electron/profile-command.js +2 -1
  60. package/lib/browser-electron/profile-extension.js +5 -0
  61. package/lib/browser-electron/profile-lease.js +152 -47
  62. package/lib/browser-electron/provider-core.js +527 -0
  63. package/lib/browser-electron/provider-interaction.js +963 -0
  64. package/lib/browser-electron/provider-media.js +518 -0
  65. package/lib/browser-electron/provider-navigation.js +301 -0
  66. package/lib/browser-electron/provider-observation.js +623 -0
  67. package/lib/browser-electron/provider-tabs.js +372 -0
  68. package/lib/browser-electron/provider.js +150 -3301
  69. package/lib/browser-electron/reference-route.js +9 -18
  70. package/lib/browser-electron/remote-host.js +79 -34
  71. package/lib/browser-electron/runtime-status.js +56 -6
  72. package/lib/browser-electron/settings-store.js +3 -6
  73. package/lib/browser-electron/sidebar-only-host.js +1 -1
  74. package/lib/browser-electron/system-browser.js +539 -172
  75. package/lib/browser-electron/tauri-host.js +208 -0
  76. package/lib/browser-electron/virtual-cursor.js +23 -13
  77. package/lib/browser-reference/service.js +22 -4
  78. package/lib/browser-reference/web-sources.js +1 -1
  79. package/lib/client.js +43409 -0
  80. package/lib/compat/host-features.js +75 -0
  81. package/lib/reference-source.js +1 -1
  82. package/lib/reference-text.js +23 -1
  83. package/lib/takeover-protocol.js +1 -1
  84. package/lib/tool-browser/block-recovery.js +69 -0
  85. package/lib/tool-browser/code-tool.js +170 -19
  86. package/lib/tool-browser/code-worker.js +115 -20
  87. package/lib/tool-browser/errors.js +34 -0
  88. package/lib/tool-browser/index.js +66 -3593
  89. package/lib/tool-browser/page-probe.js +227 -28
  90. package/lib/tool-browser/panel-page.js +2 -1
  91. package/lib/tool-browser/probe-client.js +157 -0
  92. package/lib/tool-browser/screenshot-annotations.js +108 -0
  93. package/lib/tool-browser/state.js +337 -0
  94. package/lib/tool-browser/takeover.js +1 -1
  95. package/lib/tool-browser/tools-debug.js +862 -0
  96. package/lib/tool-browser/tools-interaction.js +993 -0
  97. package/lib/tool-browser/tools-navigation.js +807 -0
  98. package/lib/tool-browser/tools-observation.js +461 -0
  99. package/lib/tool-browser/tools-reference.js +293 -0
  100. package/lib/web-guest.js +1 -0
  101. package/package.json +16 -36
  102. package/scripts/build-client.mjs +305 -0
  103. package/scripts/build.mjs +15 -12
  104. package/scripts/fix-exports.mjs +6 -16
  105. package/scripts/install-electron.mjs +55 -5
  106. package/scripts/pack.mjs +99 -0
  107. package/scripts/publish-manifest.mjs +56 -0
  108. package/scripts/verify-exports.mjs +26 -15
  109. package/skills/dsh-builtin-browser/SKILL.md +27 -2
  110. package/skills/dsh-builtin-browser/references/batch.md +15 -0
  111. package/src/browser/anti-bot.ts +251 -0
  112. package/src/browser/deep-dom.ts +40 -0
  113. package/src/browser/runtime.ts +18 -0
  114. package/src/browser/takeover-target.ts +16 -7
  115. package/src/browser/types.ts +56 -3
  116. package/src/browser-electron/authenticated-route.ts +29 -4
  117. package/src/browser-electron/automatic-maintenance.ts +23 -13
  118. package/src/browser-electron/bridge-connection.ts +11 -10
  119. package/src/browser-electron/bridge-install.ts +2 -1
  120. package/src/browser-electron/bridge-status.ts +61 -22
  121. package/src/browser-electron/desktop-bridge-host.ts +9 -7
  122. package/src/browser-electron/desktop-identity.ts +38 -5
  123. package/src/browser-electron/desktop-shell.ts +100 -0
  124. package/src/browser-electron/electron-provision.ts +104 -18
  125. package/src/browser-electron/entry.ts +1378 -1299
  126. package/src/browser-electron/extension-browser.ts +11 -4
  127. package/src/browser-electron/foreground-watch.ts +142 -0
  128. package/src/browser-electron/guest-cookie-jar.ts +3 -2
  129. package/src/browser-electron/guest-route.ts +180 -32
  130. package/src/browser-electron/guest-runtime.ts +61 -10
  131. package/src/browser-electron/guest-storage.ts +5 -2
  132. package/src/browser-electron/history-store.ts +3 -6
  133. package/src/browser-electron/host-main.ts +8 -4
  134. package/src/browser-electron/host-patch-maintenance.ts +18 -9
  135. package/src/browser-electron/maintenance-route.ts +2 -1
  136. package/src/browser-electron/missing-system-browser.ts +11 -10
  137. package/src/browser-electron/preferred-browser.ts +13 -3
  138. package/src/browser-electron/preview-route.ts +9 -12
  139. package/src/browser-electron/process-ownership.ts +9 -3
  140. package/src/browser-electron/profile-command.ts +2 -1
  141. package/src/browser-electron/profile-extension.ts +5 -0
  142. package/src/browser-electron/profile-lease.ts +131 -35
  143. package/src/browser-electron/provider-core.ts +1107 -0
  144. package/src/browser-electron/provider-interaction.ts +1034 -0
  145. package/src/browser-electron/provider-media.ts +589 -0
  146. package/src/browser-electron/provider-navigation.ts +323 -0
  147. package/src/browser-electron/provider-observation.ts +664 -0
  148. package/src/browser-electron/provider-tabs.ts +372 -0
  149. package/src/browser-electron/provider.ts +158 -4063
  150. package/src/browser-electron/reference-route.ts +598 -608
  151. package/src/browser-electron/remote-host.ts +118 -42
  152. package/src/browser-electron/runtime-status.ts +80 -13
  153. package/src/browser-electron/settings-store.ts +10 -6
  154. package/src/browser-electron/sidebar-only-host.ts +4 -2
  155. package/src/browser-electron/system-browser.ts +537 -184
  156. package/src/browser-electron/tauri-host.ts +194 -0
  157. package/src/browser-electron/virtual-cursor.ts +24 -14
  158. package/src/browser-reference/service.ts +38 -7
  159. package/src/browser-reference/web-sources.ts +4 -1
  160. package/src/client/apply-guard.ts +22 -0
  161. package/src/client/browser/BrowserController.ts +3 -3
  162. package/src/client/browser/IframeImpl.ts +182 -176
  163. package/src/client/browser/frame-history.ts +125 -0
  164. package/src/client/browser/frame-state.ts +27 -0
  165. package/src/client/browser/web-reference-source.ts +5 -1
  166. package/src/client/definition.tsx +36 -30
  167. package/src/client/electron/ElectronWebViewImpl.ts +20 -13
  168. package/src/client/electron/ElectronWebviewPresentation.ts +4 -2
  169. package/src/client/electron/NativeChildPresentation.ts +11 -3
  170. package/src/client/electron/NativeViewPage.ts +19 -5
  171. package/src/client/index.ts +333 -293
  172. package/src/client/locales.ts +9 -6
  173. package/src/client/reference/client/plugin.ts +21 -2
  174. package/src/client/reference/client/production/ReferenceCapsules.tsx +3 -3
  175. package/src/client/reference/client/production/assembly.ts +4 -28
  176. package/src/client/reference/client/production/availability.ts +0 -2
  177. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  178. package/src/client/reference/client/production/draft-adapter.ts +4 -0
  179. package/src/client/reference/client/production/http-transport.ts +0 -5
  180. package/src/client/reference/client/production/production-submission.ts +50 -290
  181. package/src/client/reference/client/production/protocol.ts +7 -4
  182. package/src/client/reference/client/production/runtime.ts +41 -86
  183. package/src/client/reference/client/production/source-marker.ts +49 -13
  184. package/src/client/reference/client/production/user-text-rule.ts +10 -1
  185. package/src/client/reference/client/reveal.ts +3 -1
  186. package/src/client/reference/client/session-schedule.ts +36 -0
  187. package/src/client/settings/index.ts +8 -0
  188. package/src/client/settings/mount-guard.ts +31 -0
  189. package/src/client/settings/panel.ts +163 -52
  190. package/src/client/startpage/controller.ts +3 -6
  191. package/src/client/view/BrowserBody.tsx +2 -1
  192. package/src/client/view/IframePresentation.ts +37 -16
  193. package/src/client/view/StartPage.tsx +2 -1
  194. package/src/compat/host-features.ts +92 -0
  195. package/src/reference-source.ts +1 -1
  196. package/src/reference-text.ts +23 -1
  197. package/src/takeover-protocol.ts +11 -2
  198. package/src/tool-browser/block-recovery.ts +85 -0
  199. package/src/tool-browser/code-tool.ts +173 -19
  200. package/src/tool-browser/code-worker.ts +101 -15
  201. package/src/tool-browser/errors.ts +40 -0
  202. package/src/tool-browser/index.ts +66 -3534
  203. package/src/tool-browser/page-probe.ts +229 -28
  204. package/src/tool-browser/panel-page.ts +3 -1
  205. package/src/tool-browser/probe-client.ts +183 -0
  206. package/src/tool-browser/screenshot-annotations.ts +131 -0
  207. package/src/tool-browser/state.ts +375 -0
  208. package/src/tool-browser/takeover.ts +3 -2
  209. package/src/tool-browser/tools-debug.ts +806 -0
  210. package/src/tool-browser/tools-interaction.ts +956 -0
  211. package/src/tool-browser/tools-navigation.ts +786 -0
  212. package/src/tool-browser/tools-observation.ts +474 -0
  213. package/src/tool-browser/tools-reference.ts +294 -0
  214. package/src/web-guest.ts +35 -34
  215. package/dist/client.cjs +0 -43167
  216. package/dist/client.d.cts +0 -516
  217. package/dist/client.d.mts +0 -516
  218. package/dist/index.cjs +0 -92
  219. package/dist/index.d.mts +0 -2960
  220. package/dist/index.mjs +0 -24
  221. package/lib/browser-reference/submission-receipts.js +0 -139
  222. package/src/browser-reference/submission-receipts.ts +0 -122
@@ -1,3 +1,6 @@
1
+ /** Plugin-owned locale namespace so DSH's built-in `sidebarBrowser` namespace never collides (issue #107). */
2
+ export const SIDEBAR_BROWSER_LOCALE_NS = 'dshBuiltinBrowser.sidebar' as const
3
+
1
4
  /** Locale-owned Browser tab copy. */
2
5
  export const zh = {
3
6
  'type.label': '浏览器',
@@ -215,8 +218,8 @@ export const en = {
215
218
 
216
219
  declare module '@deepseek-ai/dsh-client-ui-slots' {
217
220
  interface LocaleNamespaceMap {
218
- /** Sidebar Browser labels, navigation controls, and failures. */
219
- sidebarBrowser: SidebarBrowserKey
221
+ /** Sidebar Browser labels, navigation controls, and failures (plugin-owned namespace). */
222
+ 'dshBuiltinBrowser.sidebar': SidebarBrowserKey
220
223
  }
221
224
  }
222
225
 
@@ -451,7 +454,7 @@ export const fr = {
451
454
  external: 'Ouvrir dans le navigateur système',
452
455
  'sandbox.disable': 'Désactiver les restrictions du bac à sable',
453
456
  'sandbox.enable': 'Restaurer les restrictions du bac à sable',
454
- 'sandbox.warning': "Les restrictions du bac à sable sont désactivées ; la page peut naviguer dans l'application de niveau supérieur et utiliser les téléchargements, les boîtes de dialogue modales et les verrous de saisie.",
457
+ 'sandbox.warning': "Les restrictions du bac à sable sont désactivées ; la page peut naviguer dans l'application de niveau supérieur et utiliser les téléchargements, les boîtes de dialogue modales et les verrous de saisie.",
455
458
  start: 'Entrez une adresse HTTP(S) pour commencer la navigation',
456
459
  loading: 'Ouverture…',
457
460
  'restore.previous': 'Déjà ouvert',
@@ -461,8 +464,8 @@ export const fr = {
461
464
  'error.protocol': "Seules les adresses HTTP et HTTPS sont prises en charge ; utilisez l'aperçu du document pour les fichiers locaux.",
462
465
  'error.credentials': "Les adresses ne peuvent pas contenir de nom d'utilisateur ou de mot de passe.",
463
466
  'error.application-origin': "Le navigateur intégré ne peut pas ouvrir l'application DSH elle-même.",
464
- 'load.failed': "La page n'a pas pu se charger ; rechargez-le ou ouvrez-le dans le navigateur système.",
465
- 'load.failed.detail': 'Échec du chargement de la page ({code}) : {description}',
467
+ 'load.failed': "La page n'a pas pu se charger ; rechargez-le ou ouvrez-le dans le navigateur système.",
468
+ 'load.failed.detail': 'Échec du chargement de la page ({code}) : {description}',
466
469
  'init.failed.occurrence-aborted': 'The tab was closed; initialization was cancelled.',
467
470
  'init.failed.controller-missing': 'The browser controller was not created; retry or reopen the tab.',
468
471
  'init.failed.workspace-unavailable': 'The browser storage workspace is unavailable; retry once it is ready.',
@@ -471,7 +474,7 @@ export const fr = {
471
474
  'init.failed.navigation-failed': 'The page failed to load; reload or open it in the system browser.',
472
475
  'init.failed.navigation-rejected': 'The address was rejected; correct it and retry.',
473
476
  'init.failed.timeout': 'Page initialization timed out; try again.',
474
- 'address.unknown': 'La page parcourue ; cet opérateur ne peut pas lire sa nouvelle URL.',
477
+ 'address.unknown': 'La page parcourue ; cet opérateur ne peut pas lire sa nouvelle URL.',
475
478
  'address.openHint': 'Ouvrir {url}',
476
479
  'address.searchHint': 'Rechercher « {query} » avec {engine}',
477
480
  'address.searchThis': 'Rechercher ceci',
@@ -18,6 +18,7 @@ import { createElement } from 'react'
18
18
  import { referenceOwnerKey } from '../../../reference-owner.ts'
19
19
  import type { BrowserInitializationReader } from '../../browser/initialization.ts'
20
20
  import { openReferenceSource, type SourceSidebar } from './production/source-opener.ts'
21
+ import { createSessionScheduler } from './session-schedule.ts'
21
22
  import {
22
23
  apply as applyProduction,
23
24
  type AssemblyConfig,
@@ -25,6 +26,8 @@ import {
25
26
  type HostElementFactory,
26
27
  } from './production/assembly.ts'
27
28
  import type { HostInputFace } from './production/draft-adapter.ts'
29
+ import type { ComposerImage } from './production/production-submission.ts'
30
+ import { attachImages } from './production/composer-attachments.ts'
28
31
  import type { ProductionRuntime } from './production/runtime.ts'
29
32
  import type { ReferenceChipInsert } from './types.ts'
30
33
 
@@ -51,6 +54,7 @@ interface SlotInputActions {
51
54
  */
52
55
  insertReference?(ref: ReferenceChipInsert, span: CaretSpan): boolean
53
56
  insertQuote?(text: string, summary?: string): boolean
57
+ addAttachments?(ids: readonly string[]): boolean
54
58
  }
55
59
 
56
60
  /** Session-scope props the `conversation.input.dock` registration receives. */
@@ -91,6 +95,15 @@ export function apply(ctx: HostContext, config: AssemblyConfig = {}): Production
91
95
  const bindingFor = (sessionId: string): HostInputFace =>
92
96
  (sessionId === '' ? undefined : bindings.get(sessionId)?.face) ?? inertFace
93
97
 
98
+ // Two dock components can be mounted at once (one per kept-alive conversation), and each one's
99
+ // render reported its own Session here. Switching the runtime synchronously during render
100
+ // notified the other dock, which rendered and switched back — an unbounded render↔publish cycle
101
+ // that React reports as "Maximum update depth exceeded" (issue #127). The switch is deferred and
102
+ // only the last report of a tick survives (see session-schedule.ts).
103
+ const scheduleSession = createSessionScheduler(
104
+ sessionId => runtime.setSession(sessionId),
105
+ task => queueMicrotask(task),
106
+ )
94
107
  const runtime: ProductionRuntime = applyProduction(ctx, {
95
108
  ...config,
96
109
  createElement: (config.createElement ?? createElement) as unknown as HostElementFactory,
@@ -101,12 +114,12 @@ export function apply(ctx: HostContext, config: AssemblyConfig = {}): Production
101
114
  const rawSession = dock?.sessionId ?? dock?.session?.sessionId
102
115
  const sessionId = typeof rawSession === 'string' ? referenceOwnerKey(rawSession) : undefined
103
116
  const actions = dock?.inputActions
104
- if (typeof rawSession !== 'string' || typeof sessionId !== 'string' || sessionId === '') { runtime.setSession(''); return }
117
+ if (typeof rawSession !== 'string' || typeof sessionId !== 'string' || sessionId === '') { scheduleSession(''); return }
105
118
  hostSessions.set(sessionId, rawSession.trim())
106
119
  // The visible Session becomes the active one: this is what makes the
107
120
  // default entry poll a real conversation instead of the empty id, and it
108
121
  // keeps an async delivery bound to the Session it belongs to.
109
- runtime.setSession(sessionId)
122
+ scheduleSession(sessionId)
110
123
  if (actions === undefined) return
111
124
  const readDraft = (): string => {
112
125
  const text = dock?.input?.draft
@@ -134,6 +147,12 @@ export function apply(ctx: HostContext, config: AssemblyConfig = {}): Production
134
147
  ...(typeof actions.insertQuote === 'function'
135
148
  ? { insertQuote: (text: string, summary?: string) => actions.insertQuote?.(text, summary) === true }
136
149
  : {}),
150
+ ...(typeof actions.addAttachments === 'function'
151
+ ? { attachImages: (images: readonly ComposerImage[]) => attachImages(ctx, rawSession.trim(), images, actions) }
152
+ : {}),
153
+ ...(typeof actions.removeAttachment === 'function'
154
+ ? { removeAttachments: (ids: readonly string[]) => { for (const id of ids) actions.removeAttachment?.(id) } }
155
+ : {}),
137
156
  ...(typeof actions.insertReference === 'function'
138
157
  ? { insertReference: (ref: ReferenceChipInsert, span: CaretSpan) => actions.insertReference?.(ref, span) === true }
139
158
  : {}),
@@ -242,7 +242,7 @@ export function ReferenceCapsules({ sessionId, cards, actions, labels, notice, r
242
242
  <span className={css.badge} aria-hidden>{card.index}</span>
243
243
  <span className={css.label}>{card.excerpt || card.source.title || card.source.host}</span>
244
244
  {/* 这个位置原来是装饰性灰点:直接换成可点的删除键(交叉线由 CSS 画,避免字形缺失渲染成圆点)。 */}
245
- {!readOnly && <span
245
+ {!readOnly && actions.onRemove !== undefined && <span
246
246
  role="button"
247
247
  tabIndex={0}
248
248
  className={css.chipRemove}
@@ -307,8 +307,8 @@ export function ReferenceCapsules({ sessionId, cards, actions, labels, notice, r
307
307
  ? undefined
308
308
  : { id: active.referenceId, value: active.comment ?? '' })
309
309
  }}><IconEditOutlineRegular size={14} /></button></Tooltip>
310
- <Tooltip label={labels.remove} portal><button type="button" aria-label={labels.remove} className={css.icon}
311
- onClick={() => { close(); actions.onRemove?.(active.referenceId) }}><IconTrashOutlineRegular size={14} /></button></Tooltip>
310
+ {actions.onRemove !== undefined && <Tooltip label={labels.remove} portal><button type="button" aria-label={labels.remove} className={css.icon}
311
+ onClick={() => { close(); actions.onRemove?.(active.referenceId) }}><IconTrashOutlineRegular size={14} /></button></Tooltip>}
312
312
  </div>}
313
313
  </div>
314
314
  <div className={css.parts}>{active.parts.map((part, index) => <Part key={`${part.kind}:${index}`} part={part} labels={labels} />)}</div>
@@ -9,11 +9,10 @@
9
9
  * - the dock card into `conversation.input.overlay` (scope: session), i.e. the
10
10
  * pill rail INSIDE the composer card, above the text surface,
11
11
  * - the reply-side link into `conversation.user.text.node`,
12
- * - the ordered submission seam exposed as `browserReferenceSubmission`,
13
12
  * - cancellable polling started once and disposed through `ctx.effect`.
14
13
  *
15
14
  * React renders the dock and feedback through the host's shared platform
16
- * modules. The conversation service invokes the ordered submission hooks.
15
+ * modules. A reference reaches the model through the composer: its quote and its image attachments.
17
16
  *
18
17
  * @module dsh-browser-reference/production/assembly
19
18
  */
@@ -186,8 +185,10 @@ export function createLiveCardDockComponent(
186
185
  labels: referenceLabels(face?.t, view.cards.length),
187
186
  actions: {
188
187
  onEditComment: (referenceId, comment) => { runtime.setComment(referenceId, comment) },
189
- onRemove: (referenceId) => { void runtime.removeCard(referenceId) },
190
188
  onReveal: (referenceId) => { void runtime.revealReference(referenceId) },
189
+ // The dock chip keeps its remove affordance. Dropping this in the submission-seam rework left
190
+ // the chip unremovable even though the capsules still render the button when it exists.
191
+ onRemove: (referenceId) => { void runtime.removeCard(referenceId) },
191
192
  },
192
193
  ...(view.issue === undefined ? {} : { notice: view.issue }),
193
194
  })
@@ -331,31 +332,6 @@ export function apply(ctx: HostContext, config: AssemblyConfig = {}): Production
331
332
  ...(config.textPosition === undefined ? {} : { textPosition: config.textPosition }),
332
333
  })
333
334
 
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
335
  const cardComponent = createLiveCardDockComponent(runtime, elementFactory)
360
336
  const replyComponent = createReplyLinkComponent(runtime, elementFactory)
361
337
 
@@ -55,8 +55,6 @@ export function isDeliveriesResponse(value: unknown): value is DeliveriesRespons
55
55
  const record = value as Record<string, unknown>
56
56
  if (record.ok !== true || typeof record.sequence !== 'number' || !Number.isFinite(record.sequence)) return false
57
57
  if (!Array.isArray(record.deliveries)) return false
58
- if (record.tracksSubmissions !== undefined && typeof record.tracksSubmissions !== 'boolean') return false
59
- if (record.unverified !== undefined && (!Array.isArray(record.unverified) || !record.unverified.every(id => typeof id === 'string'))) return false
60
58
  for (const entry of record.deliveries as readonly unknown[]) {
61
59
  if (typeof entry !== 'object' || entry === null) return false
62
60
  const delivery = entry as Record<string, unknown>
@@ -0,0 +1,44 @@
1
+ import type { ComposerImage } from './production-submission.ts'
2
+
3
+ /** The part of the host conversation service that turns files into composer attachments. */
4
+ interface DraftAttachmentService {
5
+ createDrafts(sessionId: string, files: readonly File[], uploadImages: boolean): readonly { readonly id: string }[]
6
+ releaseDraftAttachments?(attachments: readonly { readonly id: string }[]): void
7
+ }
8
+
9
+ interface AttachmentContext {
10
+ get(name: string): unknown
11
+ }
12
+
13
+ interface AttachmentActions {
14
+ addAttachments?(ids: readonly string[]): boolean
15
+ removeAttachment?(id: string): void
16
+ }
17
+
18
+ /**
19
+ * Put captured images into the composer attachments through the host's own drop path
20
+ * (`conversation.createDrafts` + `inputActions.addAttachments`), so the send serializes them
21
+ * ahead of the text exactly like a pasted image. Returns the ids it attached (none when refused).
22
+ */
23
+ export function attachImages(
24
+ ctx: AttachmentContext,
25
+ sessionId: string,
26
+ images: readonly ComposerImage[],
27
+ actions: AttachmentActions,
28
+ ): readonly string[] {
29
+ const conversation = ctx.get('conversation') as Partial<DraftAttachmentService> | undefined
30
+ if (typeof conversation?.createDrafts !== 'function' || typeof actions.addAttachments !== 'function') return []
31
+ const files = images.map(({ partId, binding }) => {
32
+ const bytes = Uint8Array.from(atob(binding.data), char => char.charCodeAt(0))
33
+ const extension = binding.mime.split('/')[1]?.replace(/[^a-z0-9]/giu, '') || 'bin'
34
+ return new File([bytes], `${partId}.${extension}`, { type: binding.mime })
35
+ })
36
+ const binding = (ctx.get('sessions') as { binding?(id: string): { session?: { getSnapshot?(): { subagent?: unknown } } } | undefined } | undefined)
37
+ ?.binding?.(sessionId)
38
+ const uploadImages = (binding?.session?.getSnapshot?.().subagent ?? null) === null
39
+ const drafts = conversation.createDrafts(sessionId, files, uploadImages)
40
+ const ids = drafts.map(draft => draft.id)
41
+ if (actions.addAttachments(ids)) return ids
42
+ conversation.releaseDraftAttachments?.(drafts)
43
+ return []
44
+ }
@@ -27,6 +27,7 @@ import {
27
27
  removeGroup,
28
28
  } from '../draft-reference.ts'
29
29
  import type { DeliveryFailure, DeliveryRecord, FrozenSnapshot } from './protocol.ts'
30
+ import type { ComposerImage } from './production-submission.ts'
30
31
 
31
32
  export const DRAFT_STORE_PREFIX = 'dsh.browser-reference.draft.'
32
33
 
@@ -67,6 +68,9 @@ export interface HostInputFace {
67
68
  insertQuote?(text: string, summary?: string): boolean
68
69
  /** 把光标放回编辑器(确认按钮在侧栏里点击时焦点不在输入框)。 */
69
70
  focusEditor?(): void
71
+ /** Add captured images to the composer attachments, which the host sends ahead of the text. */
72
+ attachImages?(images: readonly ComposerImage[]): readonly string[]
73
+ removeAttachments?(ids: readonly string[]): void
70
74
  }
71
75
 
72
76
  export interface PreservationSnapshot {
@@ -56,7 +56,6 @@ export interface ReferenceHttpClient {
56
56
  ack(request: AckRequest): Promise<AckResponse>
57
57
  /** Persist an accepted message's consumption independently of browser storage. */
58
58
  consume?(sessionId: string, intentId: string): Promise<void>
59
- bindSubmission?(sessionId: string, requestId: string, intentIds: readonly string[]): Promise<void>
60
59
  remove(intentId: string): Promise<RemoveResponse>
61
60
  reveal(referenceId: string, partId?: string, navigate?: boolean, sourcePageId?: string): Promise<RevealResultWire>
62
61
  exportBundle(format: ExportFormat, sessionId: string): Promise<Uint8Array>
@@ -148,10 +147,6 @@ export function createReferenceHttpClient(options: HttpClientOptions): Reference
148
147
  const result = await writeJson(`${base}${ROUTES.ack}`, { phase: 'consumed', sessionId, intentId }) as { state?: unknown }
149
148
  if (result.state !== 'consumed') throw new Error('reference consumption was not persisted')
150
149
  },
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
150
  async remove(intentId) {
156
151
  return await writeJson(`${base}${ROUTES.remove}`, { intentId }) as RemoveResponse
157
152
  },