dsh-builtin-browser 0.5.7 → 0.5.8

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 (94) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.en.md +48 -22
  3. package/README.md +48 -22
  4. package/client.js +469 -81
  5. package/desktop-bridge/install-and-start.cmd +4 -5
  6. package/desktop-bridge/install.mjs +251 -159
  7. package/desktop-bridge/maintenance-progress.ps1 +166 -0
  8. package/desktop-bridge/plugin-browser-bridge.js +151 -18
  9. package/desktop-bridge/request-desktop-quit.ps1 +170 -0
  10. package/docs/user-guide.md +28 -4
  11. package/lib/browser-electron/automatic-maintenance.d.ts +41 -0
  12. package/lib/browser-electron/automatic-maintenance.js +426 -0
  13. package/lib/browser-electron/bridge-auto.d.ts +93 -0
  14. package/lib/browser-electron/bridge-auto.js +113 -0
  15. package/lib/browser-electron/bridge-connection.d.ts +0 -2
  16. package/lib/browser-electron/bridge-connection.js +2 -4
  17. package/lib/browser-electron/bridge-endpoint.js +1 -19
  18. package/lib/browser-electron/bridge-install.d.ts +41 -4
  19. package/lib/browser-electron/bridge-install.js +131 -18
  20. package/lib/browser-electron/bridge-maintenance.d.ts +24 -0
  21. package/lib/browser-electron/bridge-maintenance.js +125 -0
  22. package/lib/browser-electron/bridge-status.d.ts +10 -3
  23. package/lib/browser-electron/bridge-status.js +76 -45
  24. package/lib/browser-electron/desktop-bridge-host.d.ts +5 -2
  25. package/lib/browser-electron/desktop-bridge-host.js +54 -33
  26. package/lib/browser-electron/desktop-identity.js +21 -9
  27. package/lib/browser-electron/electron-provision.js +5 -2
  28. package/lib/browser-electron/entry.js +104 -74
  29. package/lib/browser-electron/ephemeral-profile.js +67 -26
  30. package/lib/browser-electron/history-store.js +2 -2
  31. package/lib/browser-electron/host-main.js +26 -37
  32. package/lib/browser-electron/http-body.d.ts +24 -0
  33. package/lib/browser-electron/http-body.js +33 -0
  34. package/lib/browser-electron/json-reply.d.ts +13 -1
  35. package/lib/browser-electron/json-reply.js +16 -2
  36. package/lib/browser-electron/maintenance-broker.d.ts +35 -0
  37. package/lib/browser-electron/maintenance-broker.js +114 -0
  38. package/lib/browser-electron/maintenance-lifecycle.d.ts +32 -0
  39. package/lib/browser-electron/maintenance-lifecycle.js +67 -0
  40. package/lib/browser-electron/maintenance-route.d.ts +18 -0
  41. package/lib/browser-electron/maintenance-route.js +75 -0
  42. package/lib/browser-electron/paths.d.ts +4 -0
  43. package/lib/browser-electron/paths.js +19 -0
  44. package/lib/browser-electron/process.d.ts +14 -0
  45. package/lib/browser-electron/process.js +24 -0
  46. package/lib/browser-electron/provider.d.ts +7 -7
  47. package/lib/browser-electron/provider.js +13 -14
  48. package/lib/browser-electron/remote-host.js +18 -16
  49. package/lib/browser-electron/runtime-status.d.ts +27 -13
  50. package/lib/browser-electron/runtime-status.js +24 -4
  51. package/lib/browser-electron/settings-store.d.ts +11 -0
  52. package/lib/browser-electron/settings-store.js +8 -2
  53. package/lib/browser-electron/sidebar-only-host.d.ts +36 -0
  54. package/lib/browser-electron/sidebar-only-host.js +192 -0
  55. package/lib/browser-electron/system-browser.d.ts +1 -9
  56. package/lib/browser-electron/system-browser.js +19 -22
  57. package/lib/browser-electron/timing.d.ts +8 -0
  58. package/lib/browser-electron/timing.js +13 -0
  59. package/lib/browser-electron/windows-system.d.ts +3 -0
  60. package/lib/browser-electron/windows-system.js +19 -0
  61. package/lib/tool-browser/index.js +5 -4
  62. package/package.json +2 -2
  63. package/scripts/run-tests.mjs +32 -0
  64. package/scripts/verify-preview-route.mjs +19 -1
  65. package/src/browser-electron/automatic-maintenance.ts +414 -0
  66. package/src/browser-electron/bridge-auto.ts +158 -0
  67. package/src/browser-electron/bridge-connection.ts +2 -4
  68. package/src/browser-electron/bridge-endpoint.ts +1 -18
  69. package/src/browser-electron/bridge-install.ts +151 -20
  70. package/src/browser-electron/bridge-maintenance.ts +161 -0
  71. package/src/browser-electron/bridge-status.ts +78 -48
  72. package/src/browser-electron/desktop-bridge-host.ts +48 -32
  73. package/src/browser-electron/desktop-identity.ts +18 -9
  74. package/src/browser-electron/electron-provision.ts +5 -2
  75. package/src/browser-electron/entry.ts +91 -69
  76. package/src/browser-electron/ephemeral-profile.ts +65 -28
  77. package/src/browser-electron/history-store.ts +2 -2
  78. package/src/browser-electron/host-main.ts +23 -36
  79. package/src/browser-electron/http-body.ts +42 -0
  80. package/src/browser-electron/json-reply.ts +18 -3
  81. package/src/browser-electron/maintenance-broker.ts +142 -0
  82. package/src/browser-electron/maintenance-lifecycle.ts +86 -0
  83. package/src/browser-electron/maintenance-route.ts +64 -0
  84. package/src/browser-electron/paths.ts +21 -0
  85. package/src/browser-electron/process.ts +23 -0
  86. package/src/browser-electron/provider.ts +18 -18
  87. package/src/browser-electron/remote-host.ts +19 -19
  88. package/src/browser-electron/runtime-status.ts +52 -17
  89. package/src/browser-electron/settings-store.ts +20 -3
  90. package/src/browser-electron/sidebar-only-host.ts +199 -0
  91. package/src/browser-electron/system-browser.ts +19 -22
  92. package/src/browser-electron/timing.ts +16 -0
  93. package/src/browser-electron/windows-system.ts +23 -0
  94. package/src/tool-browser/index.ts +5 -4
package/client.js CHANGED
@@ -26,6 +26,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
26
26
  const NS = "settings.dsh-builtin-browser"
27
27
  const ROUTE = "/dsh-builtin-browser/settings"
28
28
  let translate = (key) => key
29
+ let currentLocale = "zh"
30
+ function updateCurrentLocale(locale) {
31
+ let active
32
+ try { active = locale.getSnapshot?.().active ?? locale.getLocale?.().active } catch { /* Older hosts may only expose bind. */ }
33
+ const language = typeof active === "string" ? active : typeof document === "undefined" ? "" : document.documentElement?.lang
34
+ currentLocale = typeof language === "string" && /^en(?:-|$)/i.test(language) ? "en" : "zh"
35
+ }
29
36
  /**
30
37
  * Re-evaluate the floating watch entry.
31
38
  *
@@ -46,6 +53,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
46
53
  nav: "浏览器",
47
54
  "watch.open": "观看浏览器",
48
55
  "watch.title": "实时画面",
56
+ "watch.session": "选择会话",
49
57
  "watch.readOnly": "只读,不转发点击与输入",
50
58
  "watch.stop": "停止",
51
59
  "watch.live": "直播",
@@ -62,6 +70,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
62
70
  "settings.saving": "正在保存…",
63
71
  "settings.details": "配置文件",
64
72
  "browser.profile": "保留登录状态",
73
+ "browser.profile.hint": "重启 DSH 后生效",
65
74
  "browser.headless": "窗口模式",
66
75
  "browser.headless.hint": "重启 DSH 后生效",
67
76
  "browser.headless.auto": "自动检测显示环境",
@@ -80,9 +89,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
80
89
  "ui.virtualCursor": "显示 Agent 光标",
81
90
  "ui.quiet": "安静模式",
82
91
  "ui.quiet.hint": "保留当前窗口和标签。新启动的 Chrome / Edge 在后台运行。",
83
- "vision.strategy": "页面定位",
84
- "vision.auto": "自动",
85
- "vision.nonVisual": "仅按页面结构",
92
+ "vision.strategy": "坐标点击与拖拽",
93
+ "vision.auto": "允许",
94
+ "vision.nonVisual": "禁止",
86
95
  "credentials.allowRead": "允许 Agent 读取 cookies / 导出登录状态",
87
96
  "browser.channel": "默认浏览器",
88
97
  "browser.sidebar": "DSH 侧栏",
@@ -97,24 +106,38 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
97
106
  "actions.allowCredentialWrite.hint": "可向任意域写入 cookies。",
98
107
  "remoteView.enabled": "允许远程观看",
99
108
  "remoteView.enabled.hint": "共享只读画面,可能包含敏感信息。",
100
- "readiness.title": "就绪状态",
109
+ "readiness.title": "环境检查",
101
110
  "readiness.loading": "检测中…",
102
111
  "readiness.failed": "读取就绪状态失败:",
103
112
  "readiness.channel": "配置的载体",
113
+ "readiness.resolvedCarrier": "当前载体",
114
+ "readiness.system": "本机浏览器",
104
115
  "readiness.details": "诊断",
105
116
  "readiness.electron": "内置浏览器运行时",
106
117
  "readiness.bridge": "桌面侧栏 bridge",
107
118
  "readiness.recheck": "重新检测",
108
119
  "readiness.prepare": "准备内置浏览器",
109
120
  "readiness.preparing": "正在准备…",
110
- "readiness.fix": "修复命令",
121
+ "readiness.fix": "外部终端命令",
111
122
  "readiness.carrier.sidebar": "桌面侧栏",
112
123
  "readiness.carrier.bundled": "内置 Electron",
113
124
  "readiness.carrier.system": "本机 Chrome / Edge",
114
125
  "readiness.carrier.auto": "自动",
115
126
  "readiness.state.ready": "可用",
116
127
  "readiness.state.blocked": "尚不可用",
117
- "readiness.state.unknown": "需实际启动才能确定",
128
+ "readiness.status.checkPending": "等待环境检测",
129
+ "readiness.status.systemReady": "已找到 {browser}",
130
+ "readiness.status.systemMissing": "未找到 {browser}",
131
+ "readiness.status.bundledReady": "内置运行环境可用",
132
+ "readiness.status.bundledMissing": "内置运行环境待安装",
133
+ "readiness.status.bundledPreparing": "正在下载内置运行环境",
134
+ "readiness.status.bundledFailed": "内置运行环境准备失败",
135
+ "readiness.status.bridgeReady": "侧栏桥可用",
136
+ "readiness.status.bridgeMissing": "侧栏桥待安装",
137
+ "readiness.status.bridgeStale": "侧栏桥待修复",
138
+ "readiness.status.bridgeStopped": "等待桌面端启动",
139
+ "readiness.status.bridgeInstalled": "侧栏桥已安装",
140
+ "readiness.status.desktopMissing": "未检测到桌面端",
118
141
  "readiness.electron.present": "已就绪",
119
142
  "readiness.electron.ready": "已就绪",
120
143
  "readiness.electron.preparing": "正在下载",
@@ -127,6 +150,27 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
127
150
  "readiness.bridge.missing": "未安装",
128
151
  "readiness.bridge.stale": "已失效(桌面端升级后需重装)",
129
152
  "readiness.bridge.absent": "本机没有桌面端",
153
+ "readiness.bridge.install": "安装并重启",
154
+ "readiness.bridge.repair": "修复并重启",
155
+ "readiness.bridge.reinstall": "重装并重启",
156
+ "readiness.bridge.uninstall": "卸载并重启",
157
+ "readiness.bridge.working": "正在准备维护…",
158
+ "readiness.bridge.inProgress": "维护进行中…",
159
+ "readiness.bridge.maintenanceHint": "点击后将正常退出并重启 DSH。",
160
+ "readiness.bridge.progressHint": "维护期间将显示独立进度,完成后自动启动 DSH。",
161
+ "readiness.bridge.localOnly": "请在本机 DSH 桌面的设置中操作。",
162
+ "readiness.bridge.unsupported": "请更新并重启 DSH 后重试。",
163
+ "readiness.bridge.phase.armed": "正在准备退出 DSH…",
164
+ "readiness.bridge.phase.closing": "正在正常退出 DSH…",
165
+ "readiness.bridge.phase.installing": "正在安装桥接…",
166
+ "readiness.bridge.phase.uninstalling": "正在卸载桥接…",
167
+ "readiness.bridge.phase.restarting": "正在重启 DSH…",
168
+ "readiness.bridge.phase.verifying": "正在确认桥接状态…",
169
+ "readiness.bridge.failed": "桥接维护失败,请查看诊断后重试。",
170
+ "readiness.bridge.cancelled": "桥接维护已取消,可重试。",
171
+ "readiness.bridge.installedDone": "桥接安装完成",
172
+ "readiness.bridge.uninstalledDone": "桥接已卸载",
173
+ "readiness.bridge.actionFailed": "桥接维护未能开始,请查看诊断后重试。",
130
174
  "delivery.title": "交付",
131
175
  "delivery.tool": "接手下载的工具(MCP 工具名,留空=只存本地)",
132
176
  "delivery.args": "参数模板(JSON)",
@@ -141,6 +185,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
141
185
  nav: "Browser",
142
186
  "watch.open": "Watch browser",
143
187
  "watch.title": "Live view",
188
+ "watch.session": "Session",
144
189
  "watch.readOnly": "Read-only; clicks and typing are not forwarded",
145
190
  "watch.stop": "Stop",
146
191
  "watch.live": "Live",
@@ -157,6 +202,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
157
202
  "settings.saving": "Saving…",
158
203
  "settings.details": "Configuration file",
159
204
  "browser.profile": "Keep sign-ins",
205
+ "browser.profile.hint": "Requires restarting DSH",
160
206
  "browser.headless": "Window mode",
161
207
  "browser.headless.hint": "Requires restarting DSH",
162
208
  "browser.headless.auto": "Detect display automatically",
@@ -175,9 +221,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
175
221
  "ui.virtualCursor": "Show agent cursor",
176
222
  "ui.quiet": "Quiet mode",
177
223
  "ui.quiet.hint": "Keeps your current window and tab. New Chrome / Edge instances run in the background.",
178
- "vision.strategy": "Page targeting",
179
- "vision.auto": "Automatic",
180
- "vision.nonVisual": "Page structure only",
224
+ "vision.strategy": "Coordinate clicks and drags",
225
+ "vision.auto": "Allowed",
226
+ "vision.nonVisual": "Blocked",
181
227
  "credentials.allowRead": "Allow the agent to read cookies / export login state",
182
228
  "browser.channel": "Default browser",
183
229
  "browser.sidebar": "DSH sidebar",
@@ -192,24 +238,38 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
192
238
  "actions.allowCredentialWrite.hint": "Write cookies to any domain.",
193
239
  "remoteView.enabled": "Allow remote viewing",
194
240
  "remoteView.enabled.hint": "Shares a read-only view that may contain sensitive information.",
195
- "readiness.title": "Readiness",
241
+ "readiness.title": "Environment check",
196
242
  "readiness.loading": "Checking…",
197
243
  "readiness.failed": "Could not read readiness:",
198
244
  "readiness.channel": "Configured carrier",
245
+ "readiness.resolvedCarrier": "Current carrier",
246
+ "readiness.system": "Installed browser",
199
247
  "readiness.details": "Diagnostics",
200
248
  "readiness.electron": "Bundled browser runtime",
201
249
  "readiness.bridge": "Desktop sidebar bridge",
202
250
  "readiness.recheck": "Check again",
203
251
  "readiness.prepare": "Prepare the bundled browser",
204
252
  "readiness.preparing": "Preparing…",
205
- "readiness.fix": "Repair command",
253
+ "readiness.fix": "External-terminal command",
206
254
  "readiness.carrier.sidebar": "Desktop sidebar",
207
255
  "readiness.carrier.bundled": "Bundled Electron",
208
256
  "readiness.carrier.system": "Installed Chrome / Edge",
209
257
  "readiness.carrier.auto": "Automatic",
210
258
  "readiness.state.ready": "Ready",
211
259
  "readiness.state.blocked": "Not ready yet",
212
- "readiness.state.unknown": "Only a real launch can tell",
260
+ "readiness.status.checkPending": "Waiting for environment check",
261
+ "readiness.status.systemReady": "{browser} found",
262
+ "readiness.status.systemMissing": "{browser} not found",
263
+ "readiness.status.bundledReady": "Bundled runtime available",
264
+ "readiness.status.bundledMissing": "Bundled runtime needs installation",
265
+ "readiness.status.bundledPreparing": "Downloading bundled runtime",
266
+ "readiness.status.bundledFailed": "Bundled runtime preparation failed",
267
+ "readiness.status.bridgeReady": "Sidebar bridge available",
268
+ "readiness.status.bridgeMissing": "Sidebar bridge needs installation",
269
+ "readiness.status.bridgeStale": "Sidebar bridge needs repair",
270
+ "readiness.status.bridgeStopped": "Waiting for DSH Desktop to start",
271
+ "readiness.status.bridgeInstalled": "Sidebar bridge installed",
272
+ "readiness.status.desktopMissing": "DSH Desktop not found",
213
273
  "readiness.electron.present": "Ready",
214
274
  "readiness.electron.ready": "Ready",
215
275
  "readiness.electron.preparing": "Downloading",
@@ -222,6 +282,27 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
222
282
  "readiness.bridge.missing": "Not installed",
223
283
  "readiness.bridge.stale": "Stale (a desktop update needs a reinstall)",
224
284
  "readiness.bridge.absent": "No desktop install on this machine",
285
+ "readiness.bridge.install": "Install and restart",
286
+ "readiness.bridge.repair": "Repair and restart",
287
+ "readiness.bridge.reinstall": "Reinstall and restart",
288
+ "readiness.bridge.uninstall": "Uninstall and restart",
289
+ "readiness.bridge.working": "Preparing maintenance…",
290
+ "readiness.bridge.inProgress": "Maintenance in progress…",
291
+ "readiness.bridge.maintenanceHint": "DSH will exit normally and restart after you click.",
292
+ "readiness.bridge.progressHint": "A separate progress window will appear. DSH starts automatically when maintenance finishes.",
293
+ "readiness.bridge.localOnly": "Use settings in DSH Desktop on this computer.",
294
+ "readiness.bridge.unsupported": "Update and restart DSH, then try again.",
295
+ "readiness.bridge.phase.armed": "Preparing to exit DSH…",
296
+ "readiness.bridge.phase.closing": "Exiting DSH normally…",
297
+ "readiness.bridge.phase.installing": "Installing the bridge…",
298
+ "readiness.bridge.phase.uninstalling": "Uninstalling the bridge…",
299
+ "readiness.bridge.phase.restarting": "Restarting DSH…",
300
+ "readiness.bridge.phase.verifying": "Checking the bridge…",
301
+ "readiness.bridge.failed": "Bridge maintenance failed. Check diagnostics and try again.",
302
+ "readiness.bridge.cancelled": "Bridge maintenance was cancelled. You can try again.",
303
+ "readiness.bridge.installedDone": "Bridge installed",
304
+ "readiness.bridge.uninstalledDone": "Bridge uninstalled",
305
+ "readiness.bridge.actionFailed": "Bridge maintenance could not start. Check diagnostics and try again.",
225
306
  "delivery.title": "Delivery",
226
307
  "delivery.tool": "Tool that takes the download (MCP tool name; empty = local only)",
227
308
  "delivery.args": "Argument template (JSON)",
@@ -278,7 +359,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
278
359
  }
279
360
  .dsh-bb-settings { font-size: 14px; line-height: 22px; }
280
361
  .dsh-bb-settings .dsh-bb-diagnostics { margin-top: 4px; }
281
- .dsh-bb-diagnostics code { display: block; }
362
+ .dsh-bb-diagnostics code { display: block; max-height: 160px; overflow: auto; }
282
363
  .dsh-bb-toggle { justify-content: space-between; cursor: pointer; }
283
364
  .dsh-bb-toggle:has(:disabled) { cursor: default; }
284
365
  .dsh-bb-switch {
@@ -345,17 +426,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
345
426
  color: var(--dsw-alias-label-primary, inherit);
346
427
  transition: background-color .12s ease;
347
428
  }
348
- /* No resting background: a permanent grey block behind every row reads as a set of buttons
349
- rather than a list of settings. The highlight belongs to the pointer, not to the row. */
350
- .dsh-bb-row:hover {
429
+ /* Only the switch rows act as a single control; status and selector rows are plain text. */
430
+ .dsh-bb-toggle:hover:not(:has(:disabled)) {
351
431
  background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.15));
352
432
  }
353
- .dsh-bb-row:active {
433
+ .dsh-bb-toggle:active:not(:has(:disabled)) {
354
434
  background: var(--dsw-alias-interactive-bg-active, rgba(128,128,128,.22));
355
435
  }
356
- .dsh-bb-row:focus-within {
357
- border-color: var(--dsw-alias-border-l2, rgba(128,128,128,.4));
358
- }
359
436
  /* The dropdown is drawn here rather than by the OS.
360
437
  A native <select> paints its popup with system colours on Windows: the highlight overrides
361
438
  whatever the option sets (white text on a white bar), and the list carries a border no CSS
@@ -365,6 +442,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
365
442
  .dsh-bb-dd {
366
443
  position: relative;
367
444
  display: inline-block;
445
+ max-width: min(100%, calc(100vw - 32px));
368
446
  margin-top: 4px;
369
447
  }
370
448
  .dsh-bb-dd-btn {
@@ -385,14 +463,17 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
385
463
  background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.18));
386
464
  }
387
465
  .dsh-bb-dd-btn:disabled { opacity: .55; cursor: default; }
388
- .dsh-bb-dd-caret { opacity: .6; font-size: 10px; line-height: 1; }
466
+ .dsh-bb-dd-btn > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
467
+ .dsh-bb-dd-caret { flex-shrink: 0; opacity: .6; font-size: 10px; line-height: 1; }
389
468
  .dsh-bb-dd-list {
390
469
  position: absolute;
470
+ box-sizing: border-box;
391
471
  z-index: 20;
392
472
  top: calc(100% + 4px);
393
473
  left: 0;
474
+ width: max-content;
394
475
  min-width: 100%;
395
- max-width: 340px;
476
+ max-width: min(340px, calc(100vw - 32px));
396
477
  padding: 4px;
397
478
  border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.4));
398
479
  border-radius: 8px;
@@ -401,6 +482,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
401
482
  }
402
483
  .dsh-bb-dd-opt {
403
484
  display: block;
485
+ box-sizing: border-box;
404
486
  width: 100%;
405
487
  padding: 6px 9px;
406
488
  border: none;
@@ -409,6 +491,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
409
491
  color: var(--dsw-alias-label-primary, inherit);
410
492
  font: inherit;
411
493
  text-align: left;
494
+ white-space: nowrap;
495
+ overflow: hidden;
496
+ text-overflow: ellipsis;
412
497
  cursor: pointer;
413
498
  }
414
499
  /* The same ellipse the rows use, so the panel reads as one surface — and it is ours to draw,
@@ -453,6 +538,11 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
453
538
  .dsh-bw-watch-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 12px; }
454
539
  .dsh-bw-watch-title { font-weight: 600; }
455
540
  .dsh-bw-watch-state { opacity: .7; margin-left: auto; }
541
+ .dsh-bw-watch-session {
542
+ max-width: 40%; font-size: 11px; color: inherit; background: transparent; cursor: pointer;
543
+ border: 1px solid var(--dsw-alias-border, rgba(128,128,128,.45)); border-radius: 5px; padding: 2px 4px;
544
+ }
545
+ .dsh-bw-watch-session[hidden] { display: none; }
456
546
  .dsh-bw-watch-close {
457
547
  /* A visible control, not a hinted one: the old close was a 16px glyph at 70% opacity with no border
458
548
  * or background, in the same colour as the title — reported as 'no way out but a page refresh'
@@ -677,6 +767,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
677
767
  const [error, setError] = useState("")
678
768
  const [unsupported, setUnsupported] = useState(false)
679
769
  const [busy, setBusy] = useState(false)
770
+ const [bridgeBusy, setBridgeBusy] = useState(null)
771
+ const [bridgeJob, setBridgeJob] = useState(null)
772
+ const [bridgePollVersion, setBridgePollVersion] = useState(0)
773
+ const [bridgeError, setBridgeError] = useState(null)
774
+ const bridgePending = useRef(false)
775
+ const bridgeSubmitting = useRef(false)
776
+ const bridgeJobId = useRef(null)
680
777
  const alive = useRef(true)
681
778
 
682
779
  const read = useCallback(async () => {
@@ -705,11 +802,35 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
705
802
  }
706
803
  }, [])
707
804
 
805
+ const bridgeActivePhases = ["armed", "closing", "installing", "restarting", "verifying"]
806
+ const bridgeActive = bridgeJob !== null && bridgeActivePhases.includes(bridgeJob.phase)
807
+ const readBridgeJob = useCallback(async () => {
808
+ try {
809
+ const response = await fetch("/dsh-builtin-browser/bridge-maintenance", { headers: { accept: "application/json" } })
810
+ if (!response.ok) return
811
+ const data = await response.json()
812
+ if (!alive.current || bridgeSubmitting.current || data.ok !== true || data.protocol !== 1 || !data.job || typeof data.job.id !== "string") return
813
+ if (bridgePending.current && bridgeJobId.current !== null && bridgeJobId.current !== data.job.id) return
814
+ bridgeJobId.current = data.job.id
815
+ bridgePending.current = ["armed", "closing", "installing", "restarting", "verifying"].includes(data.job.phase)
816
+ setBridgeJob(data.job)
817
+ if (data.job.phase === "completed") void read()
818
+ } catch { /* The desktop is briefly offline while maintenance restarts it. Keep its job. */ }
819
+ finally { if (alive.current) setBridgePollVersion(version => version + 1) }
820
+ }, [read])
821
+
708
822
  useEffect(() => {
709
823
  alive.current = true
710
824
  void read()
825
+ void readBridgeJob()
711
826
  return () => { alive.current = false }
712
- }, [read, channel])
827
+ }, [read, readBridgeJob, channel])
828
+
829
+ useEffect(() => {
830
+ if (!bridgeActive) return undefined
831
+ const timer = setTimeout(() => { void readBridgeJob() }, 1000)
832
+ return () => clearTimeout(timer)
833
+ }, [bridgeActive, bridgeJob, bridgePollVersion, readBridgeJob])
713
834
 
714
835
  // Poll only while a download is running: that is the one state that changes on its own, and a
715
836
  // poll in any other state would be a background request per panel per two seconds forever.
@@ -739,6 +860,50 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
739
860
  }
740
861
  }
741
862
 
863
+ const bridgeAction = async action => {
864
+ if (bridgePending.current || busy || bridgeActive) return
865
+ const desktopMenu = () => typeof document.querySelector === "function"
866
+ ? document.querySelector("[data-windows-menu]")?.shadowRoot?.querySelector("button") : null
867
+ if (typeof desktopMenu()?.click !== "function") {
868
+ setBridgeError({ key: "readiness.bridge.localOnly" })
869
+ return
870
+ }
871
+ bridgePending.current = true
872
+ bridgeSubmitting.current = true
873
+ setBridgeBusy(action)
874
+ setBridgeJob(null)
875
+ setBridgeError(null)
876
+ let accepted = false
877
+ try {
878
+ const response = await fetch("/dsh-builtin-browser/bridge-maintenance", {
879
+ method: "POST",
880
+ headers: { accept: "application/json", "content-type": "application/json" },
881
+ body: JSON.stringify({ action, locale: currentLocale }),
882
+ })
883
+ const data = await response.json().catch(() => ({}))
884
+ if (response.status === 404) {
885
+ if (alive.current) setBridgeError({ key: "readiness.bridge.unsupported" })
886
+ return
887
+ }
888
+ if (!response.ok || data.ok !== true) throw new Error(data.error || data.output || `HTTP ${response.status}`)
889
+ if (data.protocol !== 1 || data.accepted !== true || typeof data.job?.id !== "string" || data.job.phase !== "armed" || data.job.action !== action) throw new Error("invalid bridge maintenance acknowledgement")
890
+ accepted = true
891
+ bridgeJobId.current = data.job.id
892
+ if (alive.current) setBridgeJob(data.job)
893
+ const menu = desktopMenu()
894
+ if (typeof menu?.click !== "function") throw new Error(t("readiness.bridge.localOnly"))
895
+ // The armed worker selects Exit in this official native menu. This opens that menu only
896
+ // after the new maintenance endpoint has acknowledged the handoff.
897
+ menu.click()
898
+ } catch (failure) {
899
+ if (alive.current) setBridgeError({ key: "readiness.bridge.actionFailed", detail: String(failure && failure.message ? failure.message : failure) })
900
+ } finally {
901
+ bridgeSubmitting.current = false
902
+ if (!accepted) bridgePending.current = false
903
+ if (alive.current) setBridgeBusy(null)
904
+ }
905
+ }
906
+
742
907
  if (unsupported) return null
743
908
  if (runtime === null) {
744
909
  return h("div", { style: styles.wrap }, [
@@ -763,24 +928,68 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
763
928
  : runtime.bridge.running === false
764
929
  ? t("readiness.bridge.installedNotRunning")
765
930
  : t("readiness.bridge.installed")
931
+ const resolvedCarrier = runtime.resolvedCarrier ?? (runtime.carrier === "auto"
932
+ ? runtime.bridge.state === "installed" && runtime.bridge.running === true ? "sidebar"
933
+ : runtime.systemBrowser?.present === true ? "system" : "bundled"
934
+ : runtime.carrier)
935
+ const systemName = ({ chrome: "Chrome", edge: "Edge", brave: "Brave" })[runtime.systemBrowser?.kind ?? runtime.channel] ?? t("readiness.system")
936
+ const systemLabel = runtime.systemBrowser?.checked === true
937
+ ? t(runtime.systemBrowser.present ? "readiness.status.systemReady" : "readiness.status.systemMissing").replace("{browser}", systemName)
938
+ : t("readiness.status.checkPending")
939
+ const stateLabel = resolvedCarrier === "system" ? systemLabel
940
+ : resolvedCarrier === "sidebar"
941
+ ? t(runtime.bridge.state === "installed"
942
+ ? runtime.bridge.running === true ? "readiness.status.bridgeReady"
943
+ : runtime.bridge.running === false ? "readiness.status.bridgeStopped" : "readiness.status.bridgeInstalled"
944
+ : runtime.bridge.state === "stale" ? "readiness.status.bridgeStale"
945
+ : runtime.bridge.state === "missing" ? "readiness.status.bridgeMissing" : "readiness.status.desktopMissing")
946
+ : t(runtime.electron.state === "present" || runtime.electron.state === "ready" ? "readiness.status.bundledReady"
947
+ : runtime.electron.state === "preparing" ? "readiness.status.bundledPreparing"
948
+ : runtime.electron.state === "failed" ? "readiness.status.bundledFailed" : "readiness.status.bundledMissing")
949
+ const controlsBusy = busy || bridgeBusy !== null || bridgeActive
950
+ const canManageBridge = runtime.bridge.present === true && runtime.bridge.state !== "absent"
951
+ const installLabel = runtime.bridge.state === "installed" ? "readiness.bridge.reinstall"
952
+ : runtime.bridge.state === "stale" ? "readiness.bridge.repair" : "readiness.bridge.install"
953
+ const bridgeButtonBusy = bridgeBusy !== null || bridgeActive
954
+ const bridgeButtonStyle = controlsBusy || preparing ? { ...styles.button, cursor: "default", opacity: .6 } : styles.button
955
+ const bridgeJobError = typeof bridgeJob?.error === "string" ? bridgeJob.error : ""
956
+ const bridgeJobOutput = typeof bridgeJob?.output === "string" ? bridgeJob.output : ""
957
+ const bridgeJobDiagnostic = bridgeJobOutput !== "" && bridgeJobError.includes(bridgeJobOutput)
958
+ ? bridgeJobError : [bridgeJobError, bridgeJobOutput].filter(Boolean).join("\n")
766
959
 
767
960
  return h("div", { style: styles.group }, [
768
961
  h("div", { key: "head", className: "dsh-bb-row", style: styles.row }, [
769
962
  h("span", { key: "title" }, t("readiness.title")),
770
- h("span", { key: "state", role: "status", style: { ...styles.badge, ...tone } }, t(`readiness.state.${runtime.readiness}`)),
963
+ h("span", { key: "state", role: "status", style: { ...styles.badge, ...tone } }, stateLabel),
771
964
  ]),
965
+ canManageBridge ? h("div", { key: "bridge-controls" }, [
966
+ h("div", { key: "row", className: "dsh-bb-row", style: styles.row }, [
967
+ h("span", { key: "title" }, t("readiness.bridge")),
968
+ h("button", { key: "install", type: "button", style: bridgeButtonStyle, disabled: controlsBusy || preparing, "aria-busy": bridgeButtonBusy ? "true" : undefined, onClick: () => bridgeAction("install") }, t(bridgeBusy !== null ? "readiness.bridge.working" : bridgeActive ? "readiness.bridge.inProgress" : installLabel)),
969
+ ]),
970
+ h("p", { key: "hint", role: bridgeBusy !== null || bridgeActive ? "status" : undefined, style: styles.hint }, t(bridgeBusy !== null ? "readiness.bridge.working" : bridgeActive ? "readiness.bridge.progressHint" : "readiness.bridge.maintenanceHint")),
971
+ ]) : null,
972
+ bridgeActive ? h("p", { key: "bridge-progress", role: "status", style: styles.hint }, t(`readiness.bridge.phase.${bridgeJob.phase === "installing" && bridgeJob.action === "uninstall" ? "uninstalling" : bridgeJob.phase}`)) : null,
973
+ bridgeJob?.phase === "completed" ? h("p", { key: "bridge-result", role: "status", style: styles.hint }, t(bridgeJob.action === "uninstall" ? "readiness.bridge.uninstalledDone" : "readiness.bridge.installedDone")) : null,
974
+ bridgeJob?.phase === "failed" || bridgeJob?.phase === "cancelled" ? h("p", { key: "bridge-job-error", role: "alert", style: styles.error }, t(`readiness.bridge.${bridgeJob.phase}`)) : null,
975
+ bridgeError !== null ? h("p", { key: "bridge-error", role: "alert", style: styles.error }, t(bridgeError.key)) : null,
772
976
  h("details", { key: "diagnostics", className: "dsh-bb-diagnostics" }, [
773
977
  h("summary", { key: "title", style: styles.hint }, t("readiness.details")),
774
978
  h("div", { key: "kv", style: styles.kv }, [
775
979
  ...row("carrier", t("readiness.channel"), t(`readiness.carrier.${runtime.carrier}`)),
980
+ runtime.resolvedCarrier ? row("resolved-carrier", t("readiness.resolvedCarrier"), t(`readiness.carrier.${runtime.resolvedCarrier}`)) : null,
981
+ runtime.systemBrowser?.checked === true ? row("system", t("readiness.system"), systemLabel) : null,
776
982
  ...row("electron", t("readiness.electron"), t(`readiness.electron.${runtime.electron.state}`)),
777
983
  ...row("bridge", t("readiness.bridge"), bridgeLabel),
778
984
  ]),
985
+ runtime.systemBrowser?.path ? h("code", { key: "system-path", style: styles.mono }, runtime.systemBrowser.path) : null,
986
+ bridgeError?.detail ? h("code", { key: "bridge-error-detail", style: styles.mono }, bridgeError.detail) : null,
987
+ bridgeJobDiagnostic !== "" ? h("code", { key: "bridge-job-detail", style: styles.mono }, bridgeJobDiagnostic) : null,
779
988
  runtime.electron.state === "failed" || runtime.electron.state === "skipped"
780
989
  ? h("p", { key: "edetail", style: styles.hint }, runtime.electron.detail) : null,
781
990
  runtime.bridge.state === "installed" && runtime.bridge.running === false
782
991
  ? h("p", { key: "bdetail", style: styles.hint }, runtime.bridge.runningDetail ?? runtime.bridge.detail) : null,
783
- runtime.bridge.command && runtime.bridge.state !== "installed"
992
+ runtime.bridge.command
784
993
  ? h("p", { key: "command", style: styles.hint }, [
785
994
  h("span", { key: "label" }, t("readiness.fix")),
786
995
  h("code", { key: "value", style: styles.mono }, runtime.bridge.command),
@@ -789,14 +998,18 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
789
998
  key: "recheck",
790
999
  type: "button",
791
1000
  style: styles.button,
792
- disabled: busy || preparing,
1001
+ disabled: controlsBusy || preparing,
793
1002
  onClick: () => { void read() },
794
1003
  }, t("readiness.recheck")),
1004
+ canManageBridge && runtime.bridge.state === "installed" ? h("button", {
1005
+ key: "uninstall", type: "button", style: bridgeButtonStyle, disabled: controlsBusy || preparing, "aria-busy": bridgeButtonBusy ? "true" : undefined,
1006
+ onClick: () => bridgeAction("uninstall"),
1007
+ }, t(bridgeBusy !== null ? "readiness.bridge.working" : bridgeActive ? "readiness.bridge.inProgress" : "readiness.bridge.uninstall")) : null,
795
1008
  ]),
796
1009
  runtime.canProvision || preparing
797
1010
  ? h("div", { key: "buttons", style: styles.buttons }, [
798
1011
  preparing ? h("span", { key: "progress", role: "status", style: styles.hint }, t("readiness.preparing")) : null,
799
- runtime.canProvision ? h("button", { key: "prepare", type: "button", style: styles.button, disabled: busy, onClick: () => { void prepare() } }, t("readiness.prepare")) : null,
1012
+ runtime.canProvision ? h("button", { key: "prepare", type: "button", style: styles.button, disabled: controlsBusy, onClick: () => { void prepare() } }, t("readiness.prepare")) : null,
800
1013
  ]) : null,
801
1014
  error !== "" ? h("p", { key: "error", role: "alert", style: styles.error }, t("readiness.failed") + " " + error) : null,
802
1015
  ])
@@ -867,16 +1080,22 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
867
1080
  const [saved, setSaved] = useState(false)
868
1081
  const saving = useRef(false)
869
1082
  const savedTimer = useRef(null)
1083
+ const alive = useRef(true)
870
1084
 
871
1085
  const load = useCallback(() => {
872
1086
  setError("")
873
1087
  callSettings().then(data => {
1088
+ if (!alive.current) return
874
1089
  setSettings(data.settings)
875
1090
  setMeta({ path: data.path || "" })
876
- }).catch(failure => setError(String(failure && failure.message ? failure.message : failure)))
1091
+ }).catch(failure => { if (alive.current) setError(String(failure && failure.message ? failure.message : failure)) })
877
1092
  }, [])
878
1093
 
879
- useEffect(() => { load() }, [load])
1094
+ useEffect(() => {
1095
+ alive.current = true
1096
+ load()
1097
+ return () => { alive.current = false }
1098
+ }, [load])
880
1099
  useEffect(() => () => clearTimeout(savedTimer.current), [])
881
1100
 
882
1101
  const patch = useCallback(next => {
@@ -887,13 +1106,14 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
887
1106
  setBusy(true)
888
1107
  setError("")
889
1108
  callSettings(next).then(data => {
1109
+ if (!alive.current) return
890
1110
  setSettings(data.settings)
891
1111
  setSaved(true)
892
1112
  savedTimer.current = setTimeout(() => setSaved(false), 1800)
893
- }).catch(failure => setError(String(failure && failure.message ? failure.message : failure)))
1113
+ }).catch(failure => { if (alive.current) setError(String(failure && failure.message ? failure.message : failure)) })
894
1114
  .finally(() => {
895
1115
  saving.current = false
896
- setBusy(false)
1116
+ if (alive.current) setBusy(false)
897
1117
  })
898
1118
  }, [])
899
1119
 
@@ -939,7 +1159,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
939
1159
  h("h3", { key: "title", style: styles.groupTitle }, t(titleKey)),
940
1160
  ...children,
941
1161
  ])
942
- const systemBrowser = settings.browser.channel === "chrome" || settings.browser.channel === "edge"
1162
+ const systemBrowser = ["chrome", "edge", "auto"].includes(settings.browser.channel)
943
1163
 
944
1164
  return h("div", { style: styles.wrap, className: "dsh-bb-settings" }, [
945
1165
  selector("browser.channel", settings.browser.channel,
@@ -966,7 +1186,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
966
1186
  { value: "auto", label: t("vision.auto") },
967
1187
  { value: "nonVisual", label: t("vision.nonVisual") },
968
1188
  ], strategy => patch({ vision: { strategy } })),
969
- systemBrowser ? toggle("cookies", "persist", "browser.profile") : null,
1189
+ systemBrowser ? toggle("cookies", "persist", "browser.profile", "browser.profile.hint") : null,
970
1190
  systemBrowser ? selector("browser.headless", settings.browser.headless ?? "auto",
971
1191
  options("browser.headless.", ["auto", "windowed", "headless"]),
972
1192
  headless => patch({ browser: { headless } }), "browser.headless.hint") : null,
@@ -1180,28 +1400,11 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1180
1400
  }, "dsh-builtin-browser: workspace binding")
1181
1401
  })
1182
1402
  }
1183
- /**
1184
- * Ask the shell to DISPLAY the conversation a page was requested for.
1185
- *
1186
- * The shell renders the sidebar of the conversation it shows and no other, so a request from a
1187
- * background conversation can place a tab but never grow a webview. The old answer was "show
1188
- * that conversation and the page appears" — true, and a dependency on the human's timing.
1189
- * `openSession` is the shell's own navigation for exactly this: the same call its own session
1190
- * list makes, aimed at a session id, with no input event and no DOM touched.
1191
- *
1192
- * Only called when this conversation's panel DOM is absent, so it never fires for the
1193
- * conversation the human is already reading, and never as a side effect of a read.
1194
- *
1195
- * @param sessionId - the conversation the page belongs to.
1196
- * @param state - the panel read taken just before; `panel: true` means nothing to claim.
1197
- * @returns whether the shell was asked to switch.
1198
- */
1199
1403
  /**
1200
1404
  * The conversation the shell is displaying, as the shell itself reports it.
1201
1405
  *
1202
1406
  * `undefined`/`null` means "the shell would not say" — an older shell, or one whose surface was
1203
- * never minted. Both callers treat that as "not this conversation", which is the fail-safe
1204
- * direction: no navigation, no expand, nothing that could move a view it cannot identify.
1407
+ * never minted. Expansion requires a known owner, because it acts on the displayed surface.
1205
1408
  * @returns the on-screen session id, or null.
1206
1409
  */
1207
1410
  function onScreenSession() {
@@ -1213,8 +1416,8 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1213
1416
  }
1214
1417
  }
1215
1418
 
1216
- function claimConversation(sessionId, state) {
1217
- if (state.panel === true) return false
1419
+ /** Display the owner of an explicit open request, including an already mounted hidden guest. */
1420
+ function claimConversation(sessionId) {
1218
1421
  if (uiWorkspace === null || typeof uiWorkspace.openSession !== "function") return false
1219
1422
  // Already displayed? Then the shell needs no navigation: the panel simply has not been opened
1220
1423
  // yet, and `revealPlacedPanel` opens it. Re-opening the conversation a human is reading would
@@ -1251,12 +1454,12 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1251
1454
  * so passing it a tab id from another conversation's list cannot move that view.
1252
1455
  *
1253
1456
  * @param sessionId - the conversation whose page was just placed.
1254
- * @param state - what the panel read before the placement; a live guest means nothing to do.
1457
+ * A live guest may remain mounted while its column is folded, so it still needs this step.
1255
1458
  * @returns what was asked for, so a caller can tell "expanded" from "already visible", and
1256
1459
  * `displayed` so it can tell "the shell is showing this conversation" from "it is not".
1257
1460
  */
1258
- function revealPlacedPanel(sessionId, state, tabId) {
1259
- if (state.guestId !== null || sidebarRight === null) return {}
1461
+ function revealPlacedPanel(sessionId, tabId) {
1462
+ if (sidebarRight === null) return {}
1260
1463
  const done = {}
1261
1464
  // Which conversation is the shell DISPLAYING? `screen()` answers it, and it is the question
1262
1465
  // that decides whether an expand call is safe: `toggleExpanded()` acts on the on-screen
@@ -1304,9 +1507,97 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1304
1507
  return done
1305
1508
  }
1306
1509
 
1510
+ function viewKey(sessionId, viewId) {
1511
+ return JSON.stringify([sessionId, viewId])
1512
+ }
1513
+
1514
+ /** Bind each logical view to one native tab; URLs can change without changing that identity. */
1515
+ function openViewPanel(sessionId, address, viewId, guestId) {
1516
+ const key = viewKey(sessionId, viewId)
1517
+ const switched = claimConversation(sessionId)
1518
+ let tabs
1519
+ try { tabs = Array.from(sidebarRight.tabsIn(sessionId)) }
1520
+ catch { return { ok: false, reason: "the shell cannot list this conversation's tabs", panel: false, guestId: null, ...switched ? { switched: true } : {} } }
1521
+ const browsers = tabs.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser" && typeof tab.id === "string")
1522
+ const allowed = new Set(browsers.map(tab => tab.id))
1523
+ const roots = panelRootsFor(sessionId)
1524
+ const owned = new Set(Array.from(pendingTabs.entries())
1525
+ .filter(([otherKey, binding]) => otherKey !== key && binding.sessionId === sessionId)
1526
+ .map(([, binding]) => binding.id))
1527
+ let binding = pendingTabs.get(key)
1528
+ if (binding !== undefined && !allowed.has(binding.id)) {
1529
+ // A missing store while the conversation mounts is temporary. Keep its identity until the
1530
+ // store is readable again; a nonempty store proves that the original tab actually closed.
1531
+ if (tabs.length === 0 && onScreenSession() !== sessionId) {
1532
+ return { ok: false, reason: "this conversation's sidebar is not mounted", panel: false, guestId: null, ...switched ? { switched: true } : {} }
1533
+ }
1534
+ pendingTabs.delete(key)
1535
+ binding = undefined
1536
+ }
1537
+ const guests = guestsInPanel(sessionId)
1538
+ const hasCachedGuest = Number.isInteger(guestId) && guestId > 0
1539
+ if (binding === undefined && hasCachedGuest) {
1540
+ const cached = guests.find(view => view.getWebContentsId() === guestId)
1541
+ if (cached !== undefined) {
1542
+ const id = tabIdOfElement(cached, allowed, roots)
1543
+ if (id === null || owned.has(id)) {
1544
+ return { ok: false, reason: "the requested guest cannot be assigned to this browser view", panel: true, guestId: null }
1545
+ }
1546
+ binding = { sessionId, id, url: address, scoped: true }
1547
+ }
1548
+ }
1549
+ if (binding === undefined && !hasCachedGuest) {
1550
+ // Adopt only an unclaimed guest whose native tab can be proved. Multiple visible guests
1551
+ // are ambiguous (split panes); creating a tab is safer than choosing by list order.
1552
+ const candidates = guests.map(view => ({ view, id: tabIdOfElement(view, allowed, roots) }))
1553
+ .filter(candidate => candidate.id !== null && !owned.has(candidate.id))
1554
+ const drawn = candidates.filter(({ view }) => {
1555
+ const rect = view.getBoundingClientRect()
1556
+ return rect.width > 0 && rect.height > 0
1557
+ })
1558
+ const candidate = drawn.length === 1 ? drawn[0] : candidates.length === 1 ? candidates[0] : undefined
1559
+ if (candidate !== undefined) binding = { sessionId, id: candidate.id, url: address, scoped: true }
1560
+ }
1561
+ let created = false
1562
+ if (binding === undefined) {
1563
+ const before = new Set(tabs.map(tab => tab.id))
1564
+ try { sidebarRight.openTabIn(sessionId, "browser", address ? { params: { url: address } } : {}) }
1565
+ catch (error) { return { ok: false, reason: String(error?.message ?? error), panel: roots === undefined ? tabStripFor(sessionId) !== null : roots.length > 0, guestId: null } }
1566
+ let placed
1567
+ try { placed = Array.from(sidebarRight.tabsIn(sessionId)) }
1568
+ catch { placed = [] }
1569
+ const added = placed.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser"
1570
+ && typeof tab.id === "string" && !before.has(tab.id) && !owned.has(tab.id))
1571
+ if (added.length !== 1) {
1572
+ return {
1573
+ ok: false,
1574
+ reason: placed.length === 0 ? "this conversation's sidebar is not mounted" : "the shell did not identify a new browser tab for this view",
1575
+ panel: roots === undefined ? tabStripFor(sessionId) !== null : roots.length > 0,
1576
+ guestId: null,
1577
+ ...switched ? { switched: true } : {},
1578
+ }
1579
+ }
1580
+ binding = { sessionId, id: added[0].id, url: address, scoped: true }
1581
+ created = true
1582
+ }
1583
+ pendingTabs.set(key, binding)
1584
+ const state = guestStateFor(sessionId, binding.id)
1585
+ return {
1586
+ ok: true,
1587
+ created,
1588
+ panel: state.panel,
1589
+ guestId: state.guestId,
1590
+ url: state.url,
1591
+ tabId: binding.id,
1592
+ ...switched ? { switched: true } : {},
1593
+ ...revealPlacedPanel(sessionId, binding.id),
1594
+ }
1595
+ }
1596
+
1307
1597
  const api = {
1598
+ panelProtocol: 3,
1308
1599
  /** @returns what happened: an existing guest, a newly opened tab, or a named refusal. */
1309
- openPanel(sessionId, url) {
1600
+ openPanel(sessionId, url, options) {
1310
1601
  const wanted = typeof sessionId === "string" ? sessionId : ""
1311
1602
  if (!/^session-/.test(wanted)) {
1312
1603
  return { ok: false, reason: "not a conversation id: " + JSON.stringify(sessionId), panel: false, guestId: null }
@@ -1315,10 +1606,25 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1315
1606
  return { ok: false, reason: "the shell's sidebar service is not available", panel: false, guestId: null }
1316
1607
  }
1317
1608
  const address = url ? String(url) : ""
1609
+ if (typeof options?.viewId === "string" && options.viewId !== "") {
1610
+ return openViewPanel(wanted, address, options.viewId, options.guestId)
1611
+ }
1318
1612
  const pending = pendingTabs.get(wanted)
1319
1613
  const state = guestStateFor(wanted, pending?.url === address && pending.scoped ? pending.id : undefined)
1614
+ // Explicit opening also reveals a guest kept mounted in a collapsed or hidden sidebar.
1615
+ // Passive panelGuest/panelGuests reads never call either presentation helper.
1616
+ const switched = claimConversation(wanted)
1320
1617
  if (state.guestId !== null) {
1321
- return { ok: true, created: false, panel: true, guestId: state.guestId, url: state.url }
1618
+ const revealed = revealPlacedPanel(wanted, pending?.url === address ? pending.id : undefined)
1619
+ return {
1620
+ ok: true,
1621
+ created: false,
1622
+ panel: true,
1623
+ guestId: state.guestId,
1624
+ url: state.url,
1625
+ ...switched ? { switched: true } : {},
1626
+ ...revealed,
1627
+ }
1322
1628
  }
1323
1629
  // No panel DOM for this conversation means the shell is not DISPLAYING it, and no tab placed
1324
1630
  // here can ever grow a webview: the shell renders one sidebar, for the conversation it shows.
@@ -1326,7 +1632,6 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1326
1632
  // their timing. Ask the shell instead — `openSession` is its own navigation, one call on its
1327
1633
  // own workspace service, no input events — and report `switched` so the caller can retry one
1328
1634
  // render later instead of reporting a dead carrier.
1329
- const switched = claimConversation(wanted, state)
1330
1635
  // A mounted panel is NOT required to place a tab.
1331
1636
  //
1332
1637
  // `openTabIn` acts on the conversation's own surface store, and the sidebar-right service
@@ -1401,7 +1706,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1401
1706
  // Placing is not showing: ask the shell to expand the column and focus that tab, so the
1402
1707
  // body (and with it the `<webview>`) actually gets created. Without this the caller polls
1403
1708
  // a panel that can never answer, which is exactly what "produced no page" used to mean.
1404
- const revealed = revealPlacedPanel(wanted, state, page?.id)
1709
+ const revealed = revealPlacedPanel(wanted, page?.id)
1405
1710
  return {
1406
1711
  ok: true,
1407
1712
  created: placed > before,
@@ -1414,7 +1719,16 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1414
1719
  }
1415
1720
  },
1416
1721
  /** Read-only: this conversation's current guest, if it has one. */
1417
- panelGuest(sessionId, tabId) {
1722
+ panelGuest(sessionId, tabId, options) {
1723
+ if (typeof options?.viewId === "string" && options.viewId !== "") {
1724
+ const bound = pendingTabs.get(viewKey(sessionId, options.viewId))
1725
+ const intended = typeof tabId === "string" && tabId !== "" ? tabId : bound?.id
1726
+ if (intended === undefined || (bound !== undefined && bound.id !== intended)) {
1727
+ const roots = panelRootsFor(sessionId)
1728
+ return { panel: roots === undefined ? tabStripFor(sessionId) !== null : roots.length > 0, guestId: null, url: "" }
1729
+ }
1730
+ return guestStateFor(sessionId, intended)
1731
+ }
1418
1732
  return guestStateFor(
1419
1733
  typeof sessionId === "string" ? sessionId : "",
1420
1734
  typeof tabId === "string" && tabId !== "" ? tabId : undefined,
@@ -1513,9 +1827,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1513
1827
  const head = make("header", "dsh-bw-watch-head")
1514
1828
  const title = make("span", "dsh-bw-watch-title")
1515
1829
  const state = make("span", "dsh-bw-watch-state")
1830
+ /** Only visible when the host reports more than one session to watch. */
1831
+ const sessionSelect = make("select", "dsh-bw-watch-session")
1832
+ sessionSelect.hidden = true
1516
1833
  const closeButton = make("button", "dsh-bw-watch-close", "×")
1517
1834
  closeButton.setAttribute("type", "button")
1518
1835
  head.appendChild(title)
1836
+ head.appendChild(sessionSelect)
1519
1837
  head.appendChild(state)
1520
1838
  head.appendChild(closeButton)
1521
1839
 
@@ -1567,6 +1885,8 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1567
1885
  readonlyLabel.textContent = say("watch.readOnly")
1568
1886
  stopButton.textContent = say("watch.stop")
1569
1887
  openButton.title = say("watch.open")
1888
+ sessionSelect.title = say("watch.session")
1889
+ sessionSelect.setAttribute("aria-label", say("watch.session"))
1570
1890
  }
1571
1891
  relabel()
1572
1892
  // A runtime language switch must reach labels that are already on screen. `subscribe` fires on
@@ -1589,8 +1909,17 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1589
1909
  layer.remove()
1590
1910
  }
1591
1911
 
1592
- /** One running view: a session, its frames, and whether it should keep pulling. */
1593
- const view = { session: undefined, timer: undefined, running: false, lastAt: 0, objectUrl: undefined }
1912
+ /**
1913
+ * One running view. `generation` is the identity of a single watching run: a stop, a session
1914
+ * switch and a reopen all advance it, so a request already in flight can never paint into the
1915
+ * new run or resurrect a second scheduling chain.
1916
+ */
1917
+ const view = {
1918
+ session: undefined, timer: undefined, running: false, lastAt: 0, objectUrl: undefined,
1919
+ generation: 0, controller: undefined,
1920
+ }
1921
+ /** Guards the async probe: two clicks in the same tick must not both reach start(). */
1922
+ let starting = false
1594
1923
 
1595
1924
  const setState = text => { state.textContent = text }
1596
1925
  const showNote = text => {
@@ -1605,12 +1934,21 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1605
1934
  view.objectUrl = undefined
1606
1935
  }
1607
1936
  }
1608
- const stop = () => {
1937
+ /** End one generation: cancel its request, timer and frame, without touching the panel chrome. */
1938
+ const cancelLoop = () => {
1609
1939
  view.running = false
1940
+ view.generation += 1
1941
+ if (view.controller !== undefined) {
1942
+ try { view.controller.abort() } catch { /* an already settled controller is harmless */ }
1943
+ view.controller = undefined
1944
+ }
1610
1945
  if (view.timer !== undefined) { clearTimeout(view.timer); view.timer = undefined }
1611
1946
  dropFrame()
1612
1947
  img.removeAttribute("src")
1613
1948
  img.hidden = true
1949
+ }
1950
+ const stop = () => {
1951
+ cancelLoop()
1614
1952
  setState(say("watch.stopped"))
1615
1953
  showNote(say("watch.stopped"))
1616
1954
  panel.hidden = true
@@ -1628,34 +1966,55 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1628
1966
  }
1629
1967
  }
1630
1968
 
1969
+ /** Show the sessions the host handed out, so a later-created one can actually be chosen. */
1970
+ const fillSessions = sessions => {
1971
+ // Clearing via innerHTML is the one exception to "build element by element": it removes
1972
+ // options, it does not parse markup, and a stale option list would keep a dead session on screen.
1973
+ sessionSelect.innerHTML = ""
1974
+ for (let index = 0; index < sessions.length; index += 1) {
1975
+ const id = String(sessions[index])
1976
+ const option = make("option")
1977
+ option.setAttribute("value", id)
1978
+ const short = id.length > 24 ? `${id.slice(0, 15)}…${id.slice(-6)}` : id
1979
+ option.textContent = `#${index + 1} ${short}`
1980
+ sessionSelect.appendChild(option)
1981
+ }
1982
+ sessionSelect.hidden = sessions.length < 2
1983
+ }
1984
+
1631
1985
  /**
1632
1986
  * Pull frames until stopped. One request in flight at a time, and the next one is scheduled only
1633
1987
  * after the current image has painted — that is what makes a slow link degrade into fewer
1634
- * frames rather than a growing queue.
1988
+ * frames rather than a growing queue. `gen` is captured once per run and re-checked after every
1989
+ * await: a frame belonging to a superseded run is dropped instead of painted.
1635
1990
  */
1636
- const pump = async () => {
1637
- if (!view.running) return
1991
+ const pump = async gen => {
1992
+ if (!view.running || gen !== view.generation) return
1638
1993
  if (document.visibilityState === "hidden") {
1639
1994
  // The design's rule: a hidden panel stops pulling immediately. Resuming is the user's
1640
1995
  // action, not a timer's.
1641
1996
  setState(say("watch.paused"))
1642
1997
  showNote(say("watch.paused"))
1643
- view.timer = setTimeout(pump, MIN_INTERVAL_MS * 4)
1998
+ view.timer = setTimeout(() => pump(gen), MIN_INTERVAL_MS * 4)
1644
1999
  return
1645
2000
  }
1646
2001
  const waited = Date.now() - view.lastAt
1647
2002
  if (waited < MIN_INTERVAL_MS) {
1648
- view.timer = setTimeout(pump, MIN_INTERVAL_MS - waited)
2003
+ view.timer = setTimeout(() => pump(gen), MIN_INTERVAL_MS - waited)
1649
2004
  return
1650
2005
  }
1651
2006
  view.lastAt = Date.now()
1652
2007
  let nextDelay = MIN_INTERVAL_MS
2008
+ const controller = view.controller
1653
2009
  try {
1654
2010
  const url = `${FRAME}?session=${encodeURIComponent(String(view.session))}`
1655
- const response = await fetch(url, { headers: { accept: "image/jpeg" } })
1656
- if (!view.running) return
2011
+ const init = { headers: { accept: "image/jpeg" } }
2012
+ if (controller !== undefined) init.signal = controller.signal
2013
+ const response = await fetch(url, init)
2014
+ if (!view.running || gen !== view.generation) return
1657
2015
  if (!response.ok) {
1658
2016
  const body = await response.json().catch(() => undefined)
2017
+ if (!view.running || gen !== view.generation) return
1659
2018
  setState(say("watch.paused"))
1660
2019
  showNote(body?.error === "remote-view-disabled"
1661
2020
  ? say("watch.disabled")
@@ -1666,7 +2025,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1666
2025
  nextDelay = MIN_INTERVAL_MS * 4
1667
2026
  } else {
1668
2027
  const blob = await response.blob()
1669
- if (!view.running) return
2028
+ if (!view.running || gen !== view.generation) return
1670
2029
  const painted = new Promise(resolve => {
1671
2030
  img.onload = () => resolve()
1672
2031
  img.onerror = () => resolve()
@@ -1677,43 +2036,70 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1677
2036
  img.hidden = false
1678
2037
  note.hidden = true
1679
2038
  await painted
1680
- if (!view.running) return
2039
+ if (!view.running || gen !== view.generation) return
1681
2040
  setState(say("watch.live"))
1682
2041
  }
1683
2042
  } catch {
1684
- if (!view.running) return
2043
+ if (!view.running || gen !== view.generation) return
1685
2044
  setState(say("watch.disconnected"))
1686
2045
  showNote(say("watch.disconnected"))
1687
2046
  nextDelay = MIN_INTERVAL_MS * 4
1688
2047
  }
1689
- if (view.running) view.timer = setTimeout(pump, nextDelay)
2048
+ if (view.running && gen === view.generation) view.timer = setTimeout(() => pump(gen), nextDelay)
1690
2049
  }
1691
2050
 
1692
2051
  const start = async session => {
2052
+ cancelLoop()
1693
2053
  view.session = session
1694
2054
  view.running = true
1695
2055
  view.lastAt = 0
2056
+ view.controller = typeof AbortController === "function" ? new AbortController() : undefined
2057
+ const gen = view.generation
1696
2058
  panel.hidden = false
1697
2059
  setState(say("watch.connecting"))
1698
2060
  showNote(say("watch.connecting"))
1699
- await pump()
2061
+ await pump(gen)
1700
2062
  }
1701
2063
 
2064
+ /**
2065
+ * The session a viewer most likely means when the host cannot name the current conversation:
2066
+ * the newest session it created, rather than always the first entry of the map.
2067
+ */
2068
+ const preferredSession = sessions => sessions[sessions.length - 1]
2069
+
1702
2070
  openButton.addEventListener("click", () => {
1703
2071
  void (async () => {
1704
- const found = await probe()
1705
- if (!found.enabled) { showNote(say("watch.disabled")); panel.hidden = false; return }
1706
- if (found.sessions.length === 0) { showNote(say("watch.noPage")); panel.hidden = false; return }
1707
- await start(found.sessions[0])
2072
+ if (view.running || starting) return
2073
+ starting = true
2074
+ try {
2075
+ const found = await probe()
2076
+ if (!found.enabled) { showNote(say("watch.disabled")); panel.hidden = false; return }
2077
+ if (found.sessions.length === 0) { showNote(say("watch.noPage")); panel.hidden = false; return }
2078
+ fillSessions(found.sessions)
2079
+ sessionSelect.value = String(preferredSession(found.sessions))
2080
+ const chosen = sessionSelect.value
2081
+ // Release before start(): the first frame may take a long time (or never arrive), and
2082
+ // holding the guard until then would also block a legitimate stop-then-reopen.
2083
+ // There is no await between here and start(), whose synchronous part sets view.running.
2084
+ starting = false
2085
+ await start(chosen)
2086
+ } finally { starting = false }
1708
2087
  })()
1709
2088
  })
2089
+ // Switching sessions replaces the run; it never adds a second loop alongside the live one.
2090
+ sessionSelect.addEventListener("change", () => {
2091
+ if (!view.running) return
2092
+ const chosen = sessionSelect.value
2093
+ if (typeof chosen === "string" && chosen !== "") void start(chosen)
2094
+ })
1710
2095
  closeButton.addEventListener("click", stop)
1711
2096
  stopButton.addEventListener("click", stop)
1712
2097
  // A panel hidden by a closed button must not keep pulling frames.
1713
2098
  document.addEventListener("visibilitychange", () => {
1714
2099
  if (document.visibilityState === "hidden" && view.running) {
1715
2100
  if (view.timer !== undefined) { clearTimeout(view.timer); view.timer = undefined }
1716
- view.timer = setTimeout(pump, MIN_INTERVAL_MS)
2101
+ const gen = view.generation
2102
+ view.timer = setTimeout(() => pump(gen), MIN_INTERVAL_MS)
1717
2103
  }
1718
2104
  })
1719
2105
 
@@ -1799,6 +2185,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1799
2185
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-builtin-browser: dictionaries")
1800
2186
  const t = ctx.locale.bind(NS)
1801
2187
  translate = t
2188
+ updateCurrentLocale(ctx.locale)
1802
2189
  // A language switch has to reach text that is already on screen. `subscribe` fires on every
1803
2190
  // locale snapshot change (switch, and late dictionary registration); guarded, because a host
1804
2191
  // without it must still get the panel — the labels then simply keep their first language.
@@ -1806,6 +2193,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1806
2193
  ctx.effect(() => {
1807
2194
  const off = ctx.locale.subscribe(() => {
1808
2195
  translate = ctx.locale.bind(NS)
2196
+ updateCurrentLocale(ctx.locale)
1809
2197
  // Two audiences, one notification: the vanilla watch panel rewrites its own text, and the
1810
2198
  // React settings section re-renders (see `useLocaleVersion`). Bumping the counter here is
1811
2199
  // what makes `t()` inside a mounted component return the new language at all.