dsh-builtin-browser 0.5.3 → 0.5.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.
- package/CHANGELOG.md +42 -0
- package/README.en.md +9 -0
- package/README.md +9 -0
- package/client.js +68 -5
- package/desktop-bridge/plugin-browser-bridge.js +5 -0
- package/lib/browser-electron/bridge-status.js +28 -1
- package/lib/browser-electron/desktop-bridge-host.d.ts +25 -25
- package/lib/browser-electron/desktop-bridge-host.js +67 -40
- package/lib/browser-electron/electron-provision.js +13 -1
- package/lib/browser-electron/provider.d.ts +18 -1
- package/lib/browser-electron/provider.js +7 -1
- package/package.json +1 -1
- package/src/browser-electron/bridge-status.ts +28 -1
- package/src/browser-electron/desktop-bridge-host.ts +70 -41
- package/src/browser-electron/electron-provision.ts +14 -1
- package/src/browser-electron/provider.ts +26 -2
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* WHY
|
|
6
6
|
* The plugin runs inside the desktop's Node-mode host, where there is no Electron
|
|
7
|
-
* API
|
|
7
|
+
* API 鈥?which is why it self-hosts a whole browser today. The shell, however, can
|
|
8
8
|
* own views, and its sidebar already displays real web pages. This host borrows
|
|
9
9
|
* that page over the shell's bridge (see apps/desktop/bridge/plugin-browser-bridge.js),
|
|
10
10
|
* so the agent and the human end up on ONE page instead of two.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* It implements the same `ElectronBrowserViewHost` seam the self-hosted host does,
|
|
14
14
|
* so the provider, the tools, browsing history, the synthetic cursor and the
|
|
15
15
|
* teardown rules are all unchanged: only the carrier differs. Everything is
|
|
16
|
-
* lazily materialized
|
|
16
|
+
* lazily materialized 鈥?a fresh shell has no sidebar guest until something asks
|
|
17
17
|
* for a page, and the bridge creates one on demand.
|
|
18
18
|
*
|
|
19
19
|
* FALLBACK
|
|
@@ -28,7 +28,7 @@ import { readFileSync } from 'node:fs'
|
|
|
28
28
|
import { homedir } from 'node:os'
|
|
29
29
|
import { join } from 'node:path'
|
|
30
30
|
import { randomUUID } from 'node:crypto'
|
|
31
|
-
import type { ElectronBrowserViewHost, ElectronViewHandle } from './provider.js'
|
|
31
|
+
import type { CommandOptions, ElectronBrowserViewHost, ElectronViewHandle } from './provider.js'
|
|
32
32
|
import type { BrowserUserAction } from './provider.js'
|
|
33
33
|
import type { CarrierPage, CarrierLossReason } from '../browser/types.js'
|
|
34
34
|
|
|
@@ -46,7 +46,7 @@ export function bridgeEndpointPath(): string {
|
|
|
46
46
|
* A display state, not a dead carrier. It must never reach `reportLost`, and it must never be
|
|
47
47
|
* retried as though a guest had vanished: retrying cannot attach a webview the shell has not
|
|
48
48
|
* rendered, and treating it as loss swapped the surface to a fresh self-hosted window whose page was
|
|
49
|
-
* blank
|
|
49
|
+
* blank 鈥?losing the page the user had open.
|
|
50
50
|
*/
|
|
51
51
|
const PANEL_NOT_DISPLAYED = 'panel-not-displayed'
|
|
52
52
|
|
|
@@ -67,8 +67,8 @@ const PANEL_DISPLAY_RETRY_MS = 400
|
|
|
67
67
|
*
|
|
68
68
|
* Thrown instead of a plain Error so callers can distinguish "the panel did not render" from "the
|
|
69
69
|
* browser broke", which is exactly the distinction issue #37 says was missing. The plugin no longer
|
|
70
|
-
* waits for a human to show the conversation
|
|
71
|
-
* this host retries while it renders
|
|
70
|
+
* waits for a human to show the conversation 鈥?the client half asks the shell to (`openSession`) and
|
|
71
|
+
* this host retries while it renders 鈥?so reaching here means the shell did not render it at all.
|
|
72
72
|
*/
|
|
73
73
|
export class BrowserPanelNotDisplayedError extends Error {
|
|
74
74
|
readonly code = PANEL_NOT_DISPLAYED
|
|
@@ -78,7 +78,7 @@ export class BrowserPanelNotDisplayedError extends Error {
|
|
|
78
78
|
*/
|
|
79
79
|
constructor(detail: string) {
|
|
80
80
|
super(
|
|
81
|
-
'dsh-builtin-browser: this conversation\'s sidebar page did not attach
|
|
81
|
+
'dsh-builtin-browser: this conversation\'s sidebar page did not attach 鈥?the shell was asked to '
|
|
82
82
|
+ 'show this conversation and its panel still did not render. Nothing was lost, and the page '
|
|
83
83
|
+ 'appears as soon as the panel mounts. '
|
|
84
84
|
+ `(${detail})`,
|
|
@@ -99,7 +99,7 @@ function isGuestGone(error: unknown): boolean {
|
|
|
99
99
|
if (error instanceof BrowserPanelNotDisplayedError) return false
|
|
100
100
|
const message = error instanceof Error ? error.message : String(error)
|
|
101
101
|
// The panel path reports its own failure when the renderer never produced a page, and that is the
|
|
102
|
-
// same class as a vanished guest
|
|
102
|
+
// same class as a vanished guest 鈥?worth one retry on a fresh panel 鈥?so it is listed here too.
|
|
103
103
|
return /guest \d+ is not available|sidebar unavailable|produced no page/i.test(message)
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -108,7 +108,7 @@ function isGuestGone(error: unknown): boolean {
|
|
|
108
108
|
*
|
|
109
109
|
* One sidebar exists per shell window, so every view this host hands out refers
|
|
110
110
|
* to the same guest: the provider keeps its tab bookkeeping, and the tabs simply
|
|
111
|
-
* share the visible page. That is the intended behaviour for this carrier
|
|
111
|
+
* share the visible page. That is the intended behaviour for this carrier 鈥?the
|
|
112
112
|
* point is a single page both parties can see.
|
|
113
113
|
*/
|
|
114
114
|
export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
@@ -117,7 +117,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
117
117
|
* One entry per view this host handed out: the conversation it serves, and the guest backing it.
|
|
118
118
|
*
|
|
119
119
|
* The conversation belongs to the ENTRY, not to this host. A single plugin process serves every
|
|
120
|
-
* conversation
|
|
120
|
+
* conversation 鈥?DSH runs them all through one host instance 鈥?so an owner held on the host
|
|
121
121
|
* would be one conversation's id applied to all of them, and a page could still land in
|
|
122
122
|
* another's sidebar however carefully the bridge checked it.
|
|
123
123
|
*/
|
|
@@ -127,7 +127,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
127
127
|
*
|
|
128
128
|
* Every DSH session is its own plugin process, and the sidebar is one surface they all share.
|
|
129
129
|
* A session can only see its own `views` map, so before the bridge kept a ledger it adopted
|
|
130
|
-
* whichever tab it found
|
|
130
|
+
* whichever tab it found 鈥?including one another session had opened, which is how a URL from
|
|
131
131
|
* one session appeared in another's sidebar. The id is per process, so two sessions never
|
|
132
132
|
* collide and one session's tabs are never handed to another; it is deliberately not the DSH
|
|
133
133
|
* session id, which this layer has no access to and does not need.
|
|
@@ -135,17 +135,17 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
135
135
|
* The whole ledger rests on that premise, so it was measured rather than assumed: with two
|
|
136
136
|
* sessions running, the desktop had TWO host processes (plus one main, two renderers and a
|
|
137
137
|
* gpu/utility pair). If sessions ever shared a process, every owner check in the bridge would
|
|
138
|
-
* compare equal and the bleed would return in a new shape
|
|
138
|
+
* compare equal and the bleed would return in a new shape 鈥?so a change to how DSH spawns
|
|
139
139
|
* sessions invalidates this file, not just this comment.
|
|
140
140
|
*
|
|
141
141
|
* It is now the CONVERSATION id rather than an invented uuid, read from the plugin's ctx by the
|
|
142
142
|
* same path DSH's own desktop host uses. That matters because the shell keeps one sidebar per
|
|
143
143
|
* conversation and writes its session id onto each sidebar container (on the React fiber,
|
|
144
|
-
* measured on the running app)
|
|
144
|
+
* measured on the running app) 鈥?so the bridge can only answer "is this sidebar mine" if it has
|
|
145
145
|
* a comparable id. With an invented uuid it never could, which is how a command came to be typed
|
|
146
146
|
* into another conversation's address bar.
|
|
147
147
|
*
|
|
148
|
-
* Falls back to a random uuid when the host cannot supply one
|
|
148
|
+
* Falls back to a random uuid when the host cannot supply one 鈥?an older DSH, or a non-desktop
|
|
149
149
|
* composition. That is no worse than before: the bridge then knows only "this process", and it
|
|
150
150
|
* refuses to operate on a sidebar it cannot prove is its own.
|
|
151
151
|
*/
|
|
@@ -155,8 +155,8 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
155
155
|
* conversation each belongs to.
|
|
156
156
|
*
|
|
157
157
|
* The provider destroys its view handles before it asks for a release, so the mapping is dropped
|
|
158
|
-
* by then
|
|
159
|
-
* conversations are running (requirements
|
|
158
|
+
* by then 鈥?keeping the guest ids here is what lets us close only our own tabs when several
|
|
159
|
+
* conversations are running (requirements 搂4: each session gets its own page). The owner rides
|
|
160
160
|
* along for the same reason it does in {@link views}: a release names one conversation.
|
|
161
161
|
*/
|
|
162
162
|
private readonly orphaned = new Map<number, string>()
|
|
@@ -168,7 +168,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
168
168
|
* handler is stored anyway so the interface contract holds (a caller may register
|
|
169
169
|
* one and must not be surprised) and so a future bridge operation can deliver it
|
|
170
170
|
* without changing the provider. Consequently no user-action event is emitted while
|
|
171
|
-
* the desktop sidebar is the carrier
|
|
171
|
+
* the desktop sidebar is the carrier 鈥?by design, not by omission.
|
|
172
172
|
*/
|
|
173
173
|
private userActionHandler: ((action: BrowserUserAction) => void) | undefined
|
|
174
174
|
/** Told when the shell behind this bridge exits; see `onLost`. */
|
|
@@ -232,7 +232,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
232
232
|
//
|
|
233
233
|
// The sidebar browser renders as a <webview> only where the shell exposes
|
|
234
234
|
// `dshDesktop.browser` and enables `webviewTag`. Where it renders as an <iframe> there is
|
|
235
|
-
// no webContents, no `getWebContentsId()` and no CDP endpoint
|
|
235
|
+
// no webContents, no `getWebContentsId()` and no CDP endpoint 鈥?and every tool here is
|
|
236
236
|
// built on CDP, so adopting it means failing every call, with no path back to a carrier
|
|
237
237
|
// that works. Reported on DSH Desktop 2.0.17 with both conditions measured.
|
|
238
238
|
//
|
|
@@ -279,8 +279,8 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
279
279
|
* Every page this conversation's sidebar panel currently holds.
|
|
280
280
|
*
|
|
281
281
|
* The shell owns page creation inside the panel: a link the user or the agent clicks may open a
|
|
282
|
-
* new page, and nothing tells the provider. Those pages are real
|
|
283
|
-
*
|
|
282
|
+
* new page, and nothing tells the provider. Those pages are real 鈥?they are what the human sees
|
|
283
|
+
* 鈥?but without this the tab model reports only the ones the provider created, so the rest are
|
|
284
284
|
* invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
|
|
285
285
|
*
|
|
286
286
|
* The bridge's `list` already answers with the sidebar guests, which is the same information, so
|
|
@@ -291,14 +291,14 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
291
291
|
* Every sidebar page this conversation holds that THIS HOST did not open.
|
|
292
292
|
*
|
|
293
293
|
* The shell owns page creation inside the panel: a link the user or the agent clicks may open a
|
|
294
|
-
* new page, and nothing tells the provider. Those pages are real
|
|
295
|
-
*
|
|
294
|
+
* new page, and nothing tells the provider. Those pages are real 鈥?they are what the human sees
|
|
295
|
+
* 鈥?but without this the tab model reports only the ones the provider created, so the rest are
|
|
296
296
|
* invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
|
|
297
297
|
*
|
|
298
298
|
* Pages this host opened are EXCLUDED here rather than deduplicated by the caller, because the
|
|
299
299
|
* caller cannot do it: the provider knows a tab by its own id and the carrier knows a page by the
|
|
300
300
|
* guest id, and the two never match. The first version returned everything and relied on the
|
|
301
|
-
* caller to filter, which reported the same page twice
|
|
301
|
+
* caller to filter, which reported the same page twice 鈥?the mapping that makes the match
|
|
302
302
|
* possible exists only here.
|
|
303
303
|
* @returns the panel's pages that are not ours, or an empty list when the bridge cannot answer.
|
|
304
304
|
*/
|
|
@@ -322,7 +322,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
322
322
|
/**
|
|
323
323
|
* Close one sidebar page by the id {@link listPages} reported.
|
|
324
324
|
*
|
|
325
|
-
* The bridge closes sidebar pages by TITLE, and only the ones the caller owns
|
|
325
|
+
* The bridge closes sidebar pages by TITLE, and only the ones the caller owns 鈥?that is what
|
|
326
326
|
* stopped one conversation's teardown from destroying another's page. So the title is looked up
|
|
327
327
|
* through the same listing, and a page that no longer appears is treated as already gone rather
|
|
328
328
|
* than as an error: the caller asked for it to be closed, and it is.
|
|
@@ -340,8 +340,8 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
340
340
|
/**
|
|
341
341
|
* The guest backing a view, materialized on first use.
|
|
342
342
|
*
|
|
343
|
-
* The conversation that called owns exactly one sidebar page on this carrier
|
|
344
|
-
* agent look at the same page
|
|
343
|
+
* The conversation that called owns exactly one sidebar page on this carrier 鈥?a human and the
|
|
344
|
+
* agent look at the same page 鈥?so every view resolves to that conversation's own guest, and the
|
|
345
345
|
* page does not multiply behind the provider's own tab bookkeeping.
|
|
346
346
|
*
|
|
347
347
|
* A cached guest is used as-is: probing it first cost a round-trip on every command, so liveness
|
|
@@ -350,14 +350,14 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
350
350
|
* @param url - address to use when this conversation has no page yet.
|
|
351
351
|
*/
|
|
352
352
|
|
|
353
|
-
private async guestFor(viewId: string, url?: string): Promise<number> {
|
|
353
|
+
private async guestFor(viewId: string, url?: string, options?: CommandOptions): Promise<number> {
|
|
354
354
|
const entry = this.views.get(viewId)
|
|
355
355
|
// No liveness check here: verifying the cached guest cost a round-trip on every
|
|
356
356
|
// command. A guest that has gone away is detected by the command itself failing,
|
|
357
357
|
// and `createView`'s sendCommand then discards the cache and calls back in here.
|
|
358
358
|
if (entry?.guest !== undefined) return entry.guest
|
|
359
359
|
|
|
360
|
-
// The conversation THIS VIEW serves
|
|
360
|
+
// The conversation THIS VIEW serves 鈥?read from the view, never from the process.
|
|
361
361
|
//
|
|
362
362
|
// The difference is the whole bug. This host is one instance shared by every conversation, so
|
|
363
363
|
// `this.owner` alone can only be "whichever conversation this process happens to name", and
|
|
@@ -369,6 +369,35 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
369
369
|
// conversation's own panel by id through the renderer, rather than by pressing the shell's
|
|
370
370
|
// shortcut or clicking its card, both of which the shell delivers to whatever it displays.
|
|
371
371
|
const owner = entry?.owner ?? this.owner
|
|
372
|
+
// A command that must not present anything (issue #46: the live preview) takes a read-only path.
|
|
373
|
+
// It asks the bridge what this conversation ALREADY has and never enters the retry loop below 鈥? // that loop is what asks the shell to display the conversation, which is right for a tool call
|
|
374
|
+
// and wrong for "let me look at it". A page that is not on screen therefore reports as a display
|
|
375
|
+
// state, and the preview route turns that into the panel's paused state.
|
|
376
|
+
if (options?.present === false) {
|
|
377
|
+
// `list` and NOT `ensureSidebar`. This is deliberate and it is the whole fix: every version of
|
|
378
|
+
// `ensureSidebar` can drive the shell — the current one asks the renderer to display the
|
|
379
|
+
// conversation, and the pre-#37 one literally pressed the sidebar shortcut and typed into the
|
|
380
|
+
// address bar. `list` is a pure read on every version, so a preview cannot move anything even
|
|
381
|
+
// when the installed bridge is old (which is exactly the reporter's environment: the symptom
|
|
382
|
+
// appears only once a bridge is installed).
|
|
383
|
+
const listed = await this.connection.call({ op: 'list', owner }, 8_000)
|
|
384
|
+
const pages = Array.isArray(listed.sidebar)
|
|
385
|
+
? listed.sidebar.filter(page => page !== null && typeof page === 'object' && page.type === 'webview')
|
|
386
|
+
: []
|
|
387
|
+
const wanted = url !== undefined && url !== '' ? url : undefined
|
|
388
|
+
const match = wanted === undefined
|
|
389
|
+
? pages[0]
|
|
390
|
+
: pages.find(page => typeof page.url === 'string' && (page.url === wanted || page.url.startsWith(wanted))) ?? pages[0]
|
|
391
|
+
const id = match !== undefined ? Number(match.id) : Number.NaN
|
|
392
|
+
if (!Number.isFinite(id) || id <= 0) {
|
|
393
|
+
throw new BrowserPanelNotDisplayedError(
|
|
394
|
+
'the preview asked for this conversation\'s page without presenting it, and no page is attached '
|
|
395
|
+
+ `(the shell holds ${pages.length})`,
|
|
396
|
+
)
|
|
397
|
+
}
|
|
398
|
+
this.views.set(viewId, { guest: id, owner })
|
|
399
|
+
return id
|
|
400
|
+
}
|
|
372
401
|
const ask = (): Promise<Record<string, unknown>> => this.connection.call({
|
|
373
402
|
op: 'ensureSidebar',
|
|
374
403
|
owner,
|
|
@@ -381,14 +410,14 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
381
410
|
// panel-not-displayed - the conversation exists but is not the one on screen;
|
|
382
411
|
// "is not mounted" - its surface store was not minted when the tab was placed.
|
|
383
412
|
// Both are gone one render later. Measured, this is the whole difference between "the sidebar
|
|
384
|
-
// works once I click over to that conversation" and "it works"
|
|
413
|
+
// works once I click over to that conversation" and "it works" 鈥?the page is real either way,
|
|
385
414
|
// and failing the call while the shell is already switching away from it just reported a
|
|
386
415
|
// problem the plugin had already fixed.
|
|
387
416
|
const displayRefusal = (value: Record<string, unknown>): boolean =>
|
|
388
417
|
value.ok !== true
|
|
389
418
|
&& (String(value.code ?? '') === PANEL_NOT_DISPLAYED
|
|
390
419
|
|| String(value.error ?? '').includes('not mounted')
|
|
391
|
-
// Bridges installed before issue #37 send the same refusal with NO code
|
|
420
|
+
// Bridges installed before issue #37 send the same refusal with NO code 鈥?the installed copy
|
|
392
421
|
// on this machine is one of them (`panel-not-displayed` appears nowhere in it). Reading only
|
|
393
422
|
// the code therefore turned a retryable display state into a hard failure for exactly the
|
|
394
423
|
// users who had the old bridge, which is the majority until it is reinstalled. The wording
|
|
@@ -399,7 +428,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
399
428
|
answer = await ask()
|
|
400
429
|
}
|
|
401
430
|
if (answer.ok !== true) {
|
|
402
|
-
// Reachable only after the retries above have run out, and the code still decides
|
|
431
|
+
// Reachable only after the retries above have run out, and the code still decides 鈥?not the
|
|
403
432
|
// wording:
|
|
404
433
|
// panel-not-displayed -> the shell was asked to show the conversation (client half's
|
|
405
434
|
// `openSession`) and did not render it in ~1.6 s: no loss, no swap.
|
|
@@ -436,13 +465,13 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
436
465
|
}
|
|
437
466
|
return {
|
|
438
467
|
id: viewId,
|
|
439
|
-
sendCommand: async (method: string, params?: Record<string, unknown
|
|
468
|
+
sendCommand: async (method: string, params?: Record<string, unknown>, options?: CommandOptions) => {
|
|
440
469
|
// No liveness probe up front. Checking first cost a whole round-trip on
|
|
441
470
|
// every command; instead the command runs and its failure is what triggers
|
|
442
471
|
// recovery. Only a genuinely missing guest is retried, so a real error (a
|
|
443
472
|
// bad selector, a timeout) still surfaces unchanged.
|
|
444
473
|
const url = navigateUrl(method, params)
|
|
445
|
-
let guest = await this.guestFor(viewId, url)
|
|
474
|
+
let guest = await this.guestFor(viewId, url, options)
|
|
446
475
|
try {
|
|
447
476
|
return await run(guest, method, params)
|
|
448
477
|
} catch (error) {
|
|
@@ -454,7 +483,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
454
483
|
// and removing the entry would lose it back to the process-wide fallback owner.
|
|
455
484
|
const lost = this.views.get(viewId)
|
|
456
485
|
if (lost !== undefined) delete lost.guest
|
|
457
|
-
guest = await this.guestFor(viewId, url)
|
|
486
|
+
guest = await this.guestFor(viewId, url, options)
|
|
458
487
|
return await run(guest, method, params)
|
|
459
488
|
}
|
|
460
489
|
},
|
|
@@ -478,8 +507,8 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
478
507
|
* This used to be empty, on the reasoning that the sidebar is already on screen so there is
|
|
479
508
|
* nothing to show. That confused "the sidebar is visible" with "this page is the one being
|
|
480
509
|
* looked at": opening a page left it behind whatever the human had in front, which is issue
|
|
481
|
-
* #23. The other two carriers both do this
|
|
482
|
-
* system browser calls `Page.bringToFront`
|
|
510
|
+
* #23. The other two carriers both do this 鈥?the self-hosted window re-adds the view and the
|
|
511
|
+
* system browser calls `Page.bringToFront` 鈥?so this carrier was the odd one out.
|
|
483
512
|
*
|
|
484
513
|
* Best-effort by design: the tab strip belongs to the shell's renderer, and failing to raise
|
|
485
514
|
* it must not fail the navigation that has already happened.
|
|
@@ -487,7 +516,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
487
516
|
*/
|
|
488
517
|
showView(handle: ElectronViewHandle): void {
|
|
489
518
|
// `owner` is required: the bridge refuses to bring forward a guest held by another session.
|
|
490
|
-
// It comes from the view, not the process
|
|
519
|
+
// It comes from the view, not the process 鈥?with several conversations live, a process-wide
|
|
491
520
|
// owner would raise the wrong conversation's tab.
|
|
492
521
|
const owner = this.views.get(handle.id)?.owner ?? this.owner
|
|
493
522
|
const guest = this.views.get(handle.id)?.guest
|
|
@@ -506,11 +535,11 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
506
535
|
|
|
507
536
|
|
|
508
537
|
/**
|
|
509
|
-
* Release the sidebar's browser pages (requirements
|
|
538
|
+
* Release the sidebar's browser pages (requirements 搂3, `ui.closeWithSession`).
|
|
510
539
|
*
|
|
511
540
|
* Destroying our own view handles is not enough on this carrier: the sidebar
|
|
512
541
|
* belongs to the shell and would happily keep the page (and its renderer) alive.
|
|
513
|
-
* Closing the tabs is what actually ends the page
|
|
542
|
+
* Closing the tabs is what actually ends the page 鈥?and only the page: cookies
|
|
514
543
|
* live in the partition, history on disk, so both survive.
|
|
515
544
|
* @param owner - the conversation whose pages to close. Omit to close every conversation's,
|
|
516
545
|
* which is only correct from a teardown that is itself global.
|
|
@@ -518,7 +547,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
518
547
|
*/
|
|
519
548
|
async releasePage(owner?: string): Promise<void> {
|
|
520
549
|
// Only this conversation's tabs. The host is ONE instance shared by every conversation, so a
|
|
521
|
-
// release that named none would close pages other conversations are still driving
|
|
550
|
+
// release that named none would close pages other conversations are still driving 鈥?"every
|
|
522
551
|
// webview currently visible" is precisely what must never be used here.
|
|
523
552
|
const mine: number[] = []
|
|
524
553
|
for (const [viewId, entry] of [...this.views]) {
|
|
@@ -540,7 +569,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
540
569
|
// `owner` is REQUIRED here now that the bridge filters `list` by it. Without it the bridge
|
|
541
570
|
// falls back to a different owner, so the guests this session holds are filtered out of the
|
|
542
571
|
// answer, `mine.includes(...)` matches nothing, the title list comes back empty and this
|
|
543
|
-
// returns without closing anything
|
|
572
|
+
// returns without closing anything 鈥?the page stayed open and the human had to close it by
|
|
544
573
|
// hand. Adding the ledger to the bridge without updating this call site is exactly the kind
|
|
545
574
|
// of half-change that made the ownership work take four rounds.
|
|
546
575
|
const answer = await this.connection.call({ op: 'list', owner: owner ?? this.owner }, 5_000)
|
|
@@ -147,14 +147,27 @@ export async function ensureElectronRuntime(deps: ProvisionDeps = defaultDeps())
|
|
|
147
147
|
return { status: 'failed', detail: 'the installed electron package has no install.js; reinstall the plugin in this profile' }
|
|
148
148
|
}
|
|
149
149
|
deps.log(`preparing Electron ${electronVersion()} in the background (a missing runtime needs a download)`)
|
|
150
|
+
// The bound has to be a REFERENCED timer, and it has to be cleared when the race finishes.
|
|
151
|
+
//
|
|
152
|
+
// A first version unref'd it — "do not keep the process alive for a download" — which is exactly
|
|
153
|
+
// backwards: with nothing else on the loop the timer never fires, the promise never settles, and a
|
|
154
|
+
// caller waiting on it hangs with no error at all. CI caught it before a user could: the test for
|
|
155
|
+
// this path failed with "Promise resolution is still pending but the event loop has already
|
|
156
|
+
// resolved". Keep it referenced, and clear it so a success does not leave a 180 s handle behind.
|
|
157
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
150
158
|
const timeout = new Promise<{ code: number | null; detail: string }>(resolve => {
|
|
151
|
-
|
|
159
|
+
timer = setTimeout(
|
|
160
|
+
() => resolve({ code: null, detail: `gave up after ${Math.round(deps.timeoutMs / 1000)}s` }),
|
|
161
|
+
deps.timeoutMs,
|
|
162
|
+
)
|
|
152
163
|
})
|
|
153
164
|
let outcome: { code: number | null; detail?: string }
|
|
154
165
|
try {
|
|
155
166
|
outcome = await Promise.race([deps.run(script), timeout])
|
|
156
167
|
} catch (error) {
|
|
157
168
|
return { status: 'failed', detail: `the download failed: ${String(error)}` }
|
|
169
|
+
} finally {
|
|
170
|
+
if (timer !== undefined) clearTimeout(timer)
|
|
158
171
|
}
|
|
159
172
|
if (outcome.code !== 0) {
|
|
160
173
|
return {
|
|
@@ -331,7 +331,7 @@ export interface ElectronViewHandle {
|
|
|
331
331
|
* @param params - CDP command parameters.
|
|
332
332
|
* @returns the CDP `result` object.
|
|
333
333
|
*/
|
|
334
|
-
sendCommand(method: string, params?: Record<string, unknown
|
|
334
|
+
sendCommand(method: string, params?: Record<string, unknown>, options?: CommandOptions): Promise<Record<string, unknown>>
|
|
335
335
|
/**
|
|
336
336
|
* Whether this view's CDP can encode JPEG and honour a quality setting.
|
|
337
337
|
*
|
|
@@ -628,6 +628,24 @@ export interface PresentOptions {
|
|
|
628
628
|
readonly quiet?: boolean
|
|
629
629
|
}
|
|
630
630
|
|
|
631
|
+
/**
|
|
632
|
+
* How a command should reach its page.
|
|
633
|
+
*
|
|
634
|
+
* Reported as issue #46: opening the live preview pushed the conversation's sidebar browser panel
|
|
635
|
+
* to the front — a read-only "look at it" action changing the reader's layout. The chain was
|
|
636
|
+
* `capturePassive` → `sendCommand('Page.captureScreenshot')` → the host's guest lookup → the bridge's
|
|
637
|
+
* `ensureSidebar` → a retry that asked the client half to `openSession`, which is exactly what a tool
|
|
638
|
+
* call is allowed to do and a preview is not.
|
|
639
|
+
*
|
|
640
|
+
* `present: false` says "this command must not make anything visible": use the page this
|
|
641
|
+
* conversation already has, and treat "not displayed" as a state to report rather than a condition
|
|
642
|
+
* to fix.
|
|
643
|
+
*/
|
|
644
|
+
export interface CommandOptions {
|
|
645
|
+
/** Present the view first (default), or only use a page that is already there. */
|
|
646
|
+
readonly present?: boolean
|
|
647
|
+
}
|
|
648
|
+
|
|
631
649
|
/** Native capture options the self-hosted view handle understands. */
|
|
632
650
|
export interface ScreenshotOptions {
|
|
633
651
|
readonly format?: 'png' | 'jpeg'
|
|
@@ -3251,13 +3269,19 @@ export class ElectronBrowserProvider implements BrowserProvider {
|
|
|
3251
3269
|
}
|
|
3252
3270
|
// Real Chrome/Edge (and the sidebar): CDP. Viewport only — `captureBeyondViewport` would pull
|
|
3253
3271
|
// the whole document, which is neither what a viewer shows nor bounded in size.
|
|
3272
|
+
//
|
|
3273
|
+
// `present: false` is load-bearing (issue #46): a preview is read-only, so it must not reach the
|
|
3274
|
+
// carrier's present path, which for the sidebar asks the shell to display this conversation —
|
|
3275
|
+
// the reported symptom was the sidebar browser panel jumping to the front when someone opened
|
|
3276
|
+
// the preview. A page that is not displayed now reads as "unavailable", which the route already
|
|
3277
|
+
// turns into the panel's paused state.
|
|
3254
3278
|
const result = await withTimeout(
|
|
3255
3279
|
handle.sendCommand(CDP_PAGE_CAPTURE_SCREENSHOT, {
|
|
3256
3280
|
format: 'jpeg',
|
|
3257
3281
|
quality: PREVIEW_QUALITY,
|
|
3258
3282
|
fromSurface: true,
|
|
3259
3283
|
captureBeyondViewport: false,
|
|
3260
|
-
}),
|
|
3284
|
+
}, { present: false }),
|
|
3261
3285
|
timeoutMs,
|
|
3262
3286
|
undefined,
|
|
3263
3287
|
timeoutMessage,
|