dsh-builtin-browser 0.5.8 → 1.0.1
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 +410 -1
- package/README.en.md +16 -64
- package/README.md +33 -64
- package/assets/browser-carriers.svg +20 -0
- package/assets/browser-extension-identity.d.mts +2 -0
- package/assets/browser-extension-identity.mjs +2 -0
- package/assets/browser-messages.d.mts +5 -0
- package/assets/browser-messages.mjs +64 -0
- package/assets/browser-panel-locales.d.mts +2 -0
- package/assets/browser-panel-locales.mjs +380 -0
- package/assets/browser-policy.d.mts +37 -0
- package/assets/browser-policy.mjs +37 -0
- package/assets/browser-products.d.mts +6 -0
- package/assets/browser-products.mjs +76 -0
- package/assets/screenshots/1-main.png +0 -0
- package/assets/screenshots/2-form-fill.png +0 -0
- package/assets/screenshots/3-challenge.png +0 -0
- package/browser-extension/constants.mjs +20 -0
- package/browser-extension/controller.mjs +293 -0
- package/browser-extension/locales.mjs +15 -0
- package/browser-extension/manifest.json +12 -0
- package/browser-extension/options.html +14 -0
- package/browser-extension/options.mjs +9 -0
- package/browser-extension/permission-guard.mjs +13 -0
- package/browser-extension/worker.mjs +74 -0
- package/cordis.patch.yml +23 -48
- package/desktop-bridge/desktop-discovery.d.mts +2 -0
- package/desktop-bridge/desktop-discovery.mjs +36 -0
- package/desktop-bridge/desktop-identity.json +17 -1
- package/desktop-bridge/desktop-processes.d.mts +1 -0
- package/desktop-bridge/desktop-processes.mjs +15 -0
- package/desktop-bridge/guest-proxy.mjs +109 -0
- package/desktop-bridge/install.mjs +197 -74
- package/desktop-bridge/main.mjs +11 -0
- package/desktop-bridge/maintenance-files.d.mts +8 -0
- package/desktop-bridge/maintenance-files.mjs +28 -0
- package/desktop-bridge/maintenance-progress.ps1 +2 -2
- package/desktop-bridge/native-guests.mjs +41 -0
- package/desktop-bridge/plugin-browser-bridge.js +618 -370
- package/desktop-bridge/profile-loader.mjs +26 -0
- package/dist/client.cjs +43167 -0
- package/dist/client.d.cts +516 -0
- package/dist/client.d.mts +516 -0
- package/dist/index.cjs +92 -0
- package/dist/index.d.mts +2960 -0
- package/dist/index.mjs +24 -0
- package/docs/HANDOVER-2026-11-15.md +178 -0
- package/docs/README.md +10 -19
- package/docs/architecture.md +17 -145
- package/docs/child-tabs.md +13 -0
- package/docs/desktop-acceptance.md +9 -0
- package/docs/development.md +88 -18
- package/docs/extension-browser.md +44 -0
- package/docs/hardcoding-audit.md +64 -0
- package/docs/limitations.md +23 -73
- package/docs/pr64-extension-status.md +46 -0
- package/docs/pr64-maintenance.md +25 -0
- package/docs/pr64-native-children.md +52 -0
- package/docs/pr64-native-views.md +60 -0
- package/docs/tool-reference.md +87 -11
- package/docs/user-guide.md +47 -255
- package/docs/why-browser.md +6 -39
- package/dsh-host-patch/README.md +60 -0
- package/dsh-host-patch/apply.mjs +194 -0
- package/dsh-host-patch/legacy-bridge.mjs +53 -0
- package/dsh-host-patch/rc3-revision1.json +90 -0
- package/dsh-host-patch/rc3-revision2.json +112 -0
- package/dsh-host-patch/rc3-revision3.json.gz +0 -0
- package/dsh-host-patch/rc3-revision4.json.gz +0 -0
- package/dsh-host-patch/rc3-revision5.json.gz +0 -0
- package/dsh-host-patch/rc3-revision6.json.gz +0 -0
- package/dsh-host-patch/rc3-revision7.json.gz +0 -0
- package/dsh-host-patch/rc3-revision8.json.gz +0 -0
- package/dsh-host-patch/rc3.json +148 -0
- package/dsh-host-patch/rc5-revision1.json +90 -0
- package/dsh-host-patch/rc5-revision2.json +112 -0
- package/dsh-host-patch/rc5-revision3.json.gz +0 -0
- package/dsh-host-patch/rc5-revision4.json.gz +0 -0
- package/dsh-host-patch/rc5-revision5.json.gz +0 -0
- package/dsh-host-patch/rc5-revision6.json.gz +0 -0
- package/dsh-host-patch/rc5-revision7.json.gz +0 -0
- package/dsh-host-patch/rc5-revision8.json.gz +0 -0
- package/dsh-host-patch/rc5.json +148 -0
- package/lib/bridge-compatibility.js +38 -0
- package/lib/browser/handles.js +78 -0
- package/lib/browser/runtime.js +155 -43
- package/lib/browser/takeover-target.js +24 -0
- package/lib/browser-electron/authenticated-route.js +23 -0
- package/lib/browser-electron/automatic-maintenance.js +394 -51
- package/lib/browser-electron/bridge-auto.js +2 -1
- package/lib/browser-electron/bridge-connection.js +8 -1
- package/lib/browser-electron/bridge-install.js +27 -2
- package/lib/browser-electron/bridge-maintenance.js +35 -10
- package/lib/browser-electron/bridge-status.js +98 -27
- package/lib/browser-electron/desktop-bridge-host.js +193 -560
- package/lib/browser-electron/desktop-identity.js +40 -2
- package/lib/browser-electron/document-readiness.js +34 -0
- package/lib/browser-electron/electron-provision.js +14 -44
- package/lib/browser-electron/entry.js +659 -252
- package/lib/browser-electron/extension-browser.js +234 -0
- package/lib/browser-electron/extension-setup.js +69 -0
- package/lib/browser-electron/guest-cookie-jar.LICENSE.txt +32 -0
- package/lib/browser-electron/guest-cookie-jar.js +10559 -0
- package/lib/browser-electron/guest-cookie-store.js +74 -0
- package/lib/browser-electron/guest-css-runtime.js +75 -0
- package/lib/browser-electron/guest-css.js +106 -0
- package/lib/browser-electron/guest-route.js +603 -0
- package/lib/browser-electron/guest-runtime.js +356 -0
- package/lib/browser-electron/guest-storage-runtime.js +52 -0
- package/lib/browser-electron/guest-storage.js +163 -0
- package/lib/browser-electron/history-store.js +2 -1
- package/lib/browser-electron/host-main.js +162 -7
- package/lib/browser-electron/host-patch-maintenance.js +141 -0
- package/lib/browser-electron/http-body.js +22 -0
- package/lib/browser-electron/maintenance-broker.js +35 -5
- package/lib/browser-electron/maintenance-lifecycle.js +7 -5
- package/lib/browser-electron/maintenance-route.js +9 -6
- package/lib/browser-electron/open-slot.js +47 -0
- package/lib/browser-electron/paths.js +4 -1
- package/lib/browser-electron/preferred-browser.js +144 -0
- package/lib/browser-electron/preview-route.js +11 -8
- package/lib/browser-electron/process-ownership.js +198 -0
- package/lib/browser-electron/profile-checkpoint.js +222 -0
- package/lib/browser-electron/profile-command.js +60 -0
- package/lib/browser-electron/profile-extension.js +126 -0
- package/lib/browser-electron/profile-lease.js +157 -0
- package/lib/browser-electron/profile-residue.js +61 -0
- package/lib/browser-electron/provider.js +719 -262
- package/lib/browser-electron/reference-route.js +635 -0
- package/lib/browser-electron/remote-host.js +12 -13
- package/lib/browser-electron/runtime-route.js +6 -5
- package/lib/browser-electron/runtime-status.js +30 -29
- package/lib/browser-electron/settings-store.js +10 -5
- package/lib/browser-electron/shortcuts-route.js +108 -0
- package/lib/browser-electron/sidebar-only-host.js +119 -18
- package/lib/browser-electron/startpage-shortcuts.js +172 -0
- package/lib/browser-electron/system-browser.js +352 -371
- package/lib/browser-electron/windows-system.js +2 -1
- package/lib/browser-reference/delivery.js +326 -0
- package/lib/browser-reference/entry.js +597 -0
- package/lib/browser-reference/export.js +298 -0
- package/lib/browser-reference/import.js +295 -0
- package/lib/browser-reference/page-script.js +1406 -0
- package/lib/browser-reference/service.js +1062 -0
- package/lib/browser-reference/store.js +177 -0
- package/lib/browser-reference/submission-receipts.js +139 -0
- package/lib/browser-reference/text-quote.js +167 -0
- package/lib/browser-reference/types.js +11 -0
- package/lib/browser-reference/visible.js +311 -0
- package/lib/browser-reference/web-sources.js +97 -0
- package/lib/index.js +10 -3
- package/lib/reference-owner.js +5 -0
- package/lib/reference-page.js +12 -0
- package/lib/reference-source.js +2 -0
- package/lib/reference-text.js +188 -0
- package/lib/startpage-settings.js +63 -0
- package/lib/startpage.js +44 -0
- package/lib/takeover-protocol.js +2 -0
- package/lib/tool-browser/code-tool.js +416 -0
- package/lib/tool-browser/code-worker.js +872 -0
- package/lib/tool-browser/index.js +940 -76
- package/lib/tool-browser/page-probe.js +3 -3
- package/lib/tool-browser/panel-page.js +95 -0
- package/lib/tool-browser/screenshot-image.js +51 -0
- package/lib/tool-browser/takeover.js +205 -0
- package/lib/types.js +1 -0
- package/lib/web-guest.js +26 -0
- package/native-host/client.d.mts +17 -0
- package/native-host/client.mjs +100 -0
- package/native-host/host.mjs +150 -0
- package/native-host/identity.d.mts +2 -0
- package/native-host/identity.mjs +1 -0
- package/native-host/install.mjs +168 -0
- package/native-host/protocol.mjs +75 -0
- package/package.json +80 -92
- package/scripts/build.mjs +66 -0
- package/scripts/bundle-host.mjs +28 -0
- package/scripts/fix-exports.mjs +50 -0
- package/scripts/install-electron.mjs +11 -26
- package/scripts/verify-exports.mjs +47 -0
- package/scripts/verify-preview-sdk.mjs +93 -0
- package/skills/dsh-builtin-browser/SKILL.md +56 -47
- package/skills/dsh-builtin-browser/references/batch.md +31 -1
- package/skills/dsh-debug-host/SKILL.md +56 -0
- package/skills/dsh-debug-self/SKILL.md +50 -0
- package/src/bridge-compatibility.ts +39 -0
- package/src/browser/handles.ts +89 -0
- package/src/browser/runtime.ts +146 -50
- package/src/browser/takeover-target.ts +36 -0
- package/src/browser/types.ts +19 -7
- package/src/browser-electron/authenticated-route.ts +29 -1
- package/src/browser-electron/automatic-maintenance.ts +368 -56
- package/src/browser-electron/bridge-auto.ts +5 -4
- package/src/browser-electron/bridge-connection.ts +20 -2
- package/src/browser-electron/bridge-endpoint.ts +3 -3
- package/src/browser-electron/bridge-install.ts +40 -4
- package/src/browser-electron/bridge-maintenance.ts +42 -14
- package/src/browser-electron/bridge-status.ts +94 -23
- package/src/browser-electron/desktop-bridge-host.ts +185 -585
- package/src/browser-electron/desktop-identity.ts +53 -2
- package/src/browser-electron/document-readiness.ts +45 -0
- package/src/browser-electron/electron-provision.ts +12 -45
- package/src/browser-electron/entry.ts +1299 -882
- package/src/browser-electron/ephemeral-profile.ts +1 -1
- package/src/browser-electron/extension-browser.ts +223 -0
- package/src/browser-electron/extension-setup.ts +67 -0
- package/src/browser-electron/guest-cookie-jar.ts +176 -0
- package/src/browser-electron/guest-cookie-store.ts +59 -0
- package/src/browser-electron/guest-css-runtime.ts +76 -0
- package/src/browser-electron/guest-css.ts +68 -0
- package/src/browser-electron/guest-route.ts +568 -0
- package/src/browser-electron/guest-runtime.ts +357 -0
- package/src/browser-electron/guest-storage-runtime.ts +54 -0
- package/src/browser-electron/guest-storage.ts +117 -0
- package/src/browser-electron/history-store.ts +5 -4
- package/src/browser-electron/host-main.ts +156 -11
- package/src/browser-electron/host-patch-maintenance.ts +112 -0
- package/src/browser-electron/http-body.ts +23 -0
- package/src/browser-electron/maintenance-broker.ts +29 -5
- package/src/browser-electron/maintenance-lifecycle.ts +14 -9
- package/src/browser-electron/maintenance-route.ts +17 -14
- package/src/browser-electron/missing-system-browser.ts +2 -2
- package/src/browser-electron/open-slot.ts +49 -0
- package/src/browser-electron/paths.ts +5 -1
- package/src/browser-electron/preferred-browser.ts +120 -0
- package/src/browser-electron/preview-route.ts +18 -11
- package/src/browser-electron/process-ownership.ts +168 -0
- package/src/browser-electron/profile-checkpoint.ts +187 -0
- package/src/browser-electron/profile-command.ts +46 -0
- package/src/browser-electron/profile-extension.ts +124 -0
- package/src/browser-electron/profile-lease.ts +115 -0
- package/src/browser-electron/profile-residue.ts +49 -0
- package/src/browser-electron/provider.ts +771 -289
- package/src/browser-electron/reference-route.ts +608 -0
- package/src/browser-electron/remote-host.ts +15 -15
- package/src/browser-electron/runtime-route.ts +11 -10
- package/src/browser-electron/runtime-status.ts +51 -32
- package/src/browser-electron/settings-store.ts +27 -7
- package/src/browser-electron/shortcuts-route.ts +112 -0
- package/src/browser-electron/sidebar-only-host.ts +118 -19
- package/src/browser-electron/startpage-shortcuts.ts +213 -0
- package/src/browser-electron/system-browser.ts +309 -338
- package/src/browser-electron/windows-system.ts +2 -1
- package/src/browser-reference/delivery.ts +384 -0
- package/src/browser-reference/entry.ts +631 -0
- package/src/browser-reference/export.ts +339 -0
- package/src/browser-reference/import.ts +303 -0
- package/src/browser-reference/page-script.ts +1537 -0
- package/src/browser-reference/service.ts +1315 -0
- package/src/browser-reference/store.ts +172 -0
- package/src/browser-reference/submission-receipts.ts +122 -0
- package/src/browser-reference/text-quote.ts +219 -0
- package/src/browser-reference/types.ts +195 -0
- package/src/browser-reference/visible.ts +367 -0
- package/src/browser-reference/web-sources.ts +103 -0
- package/src/client/browser/BrowserController.ts +693 -0
- package/src/client/browser/BrowserFrame.ts +78 -0
- package/src/client/browser/BrowserNavigation.ts +169 -0
- package/src/client/browser/BrowserPage.ts +23 -0
- package/src/client/browser/BrowserPersistence.ts +44 -0
- package/src/client/browser/IframeImpl.ts +176 -0
- package/src/client/browser/child-tabs.ts +14 -0
- package/src/client/browser/iframe-reference.ts +67 -0
- package/src/client/browser/initialization.ts +262 -0
- package/src/client/browser/omnibox.ts +243 -0
- package/src/client/browser/store.ts +38 -0
- package/src/client/browser/takeover-channel.ts +72 -0
- package/src/client/browser/url.ts +46 -0
- package/src/client/browser/web-reference-source.ts +52 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/definition.tsx +30 -0
- package/src/client/electron/ElectronWebViewImpl.ts +364 -0
- package/src/client/electron/ElectronWebviewPresentation.ts +138 -0
- package/src/client/electron/NativeChildPresentation.ts +45 -0
- package/src/client/electron/NativeViewPage.ts +251 -0
- package/src/client/electron/pages.ts +23 -0
- package/src/client/electron/reference-overlay.ts +53 -0
- package/src/client/electron/workspace.ts +33 -0
- package/src/client/index.ts +293 -0
- package/src/client/locales.ts +857 -0
- package/src/client/pages.ts +28 -0
- package/src/client/reference/client/BrowserRefLink.tsx +142 -0
- package/src/client/reference/client/draft-reference.ts +167 -0
- package/src/client/reference/client/index.ts +7 -0
- package/src/client/reference/client/ordered-submission.ts +108 -0
- package/src/client/reference/client/pending-delivery.ts +216 -0
- package/src/client/reference/client/plugin.ts +189 -0
- package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
- package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
- package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
- package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
- package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
- package/src/client/reference/client/production/ReferenceText.tsx +36 -0
- package/src/client/reference/client/production/assembly.ts +471 -0
- package/src/client/reference/client/production/asset-store.ts +144 -0
- package/src/client/reference/client/production/availability.ts +74 -0
- package/src/client/reference/client/production/bytes.ts +36 -0
- package/src/client/reference/client/production/delivery-client.ts +211 -0
- package/src/client/reference/client/production/draft-adapter.ts +508 -0
- package/src/client/reference/client/production/http-transport.ts +217 -0
- package/src/client/reference/client/production/production-submission.ts +310 -0
- package/src/client/reference/client/production/protocol.ts +231 -0
- package/src/client/reference/client/production/reference-card.ts +240 -0
- package/src/client/reference/client/production/reference-labels.ts +29 -0
- package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
- package/src/client/reference/client/production/reveal.ts +215 -0
- package/src/client/reference/client/production/runtime.ts +1101 -0
- package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
- package/src/client/reference/client/production/source-marker.ts +63 -0
- package/src/client/reference/client/production/source-opener.ts +55 -0
- package/src/client/reference/client/production/styles.ts +104 -0
- package/src/client/reference/client/production/user-text-rule.ts +58 -0
- package/src/client/reference/client/reveal.ts +107 -0
- package/src/client/reference/client/scheme.ts +114 -0
- package/src/client/reference/client/types.ts +168 -0
- package/src/client/reference/css-modules.d.ts +4 -0
- package/src/client/reference/index.ts +11 -0
- package/src/client/reference-capture-owner.ts +162 -0
- package/src/client/reference-intents.ts +36 -0
- package/src/client/settings/index.ts +34 -0
- package/{client.js → src/client/settings/panel.ts} +2657 -2231
- package/src/client/shortcut-open.ts +30 -0
- package/src/client/startpage/binding.ts +99 -0
- package/src/client/startpage/controller.ts +303 -0
- package/src/client/startpage/model.ts +279 -0
- package/src/client/view/Browser.module.css +751 -0
- package/src/client/view/BrowserBody.tsx +314 -0
- package/src/client/view/BrowserPresentation.ts +9 -0
- package/src/client/view/BrowserTitle.tsx +17 -0
- package/src/client/view/IframePresentation.ts +344 -0
- package/src/client/view/StartPage.tsx +597 -0
- package/src/client/view/TakeoverBanner.tsx +21 -0
- package/src/index.ts +110 -73
- package/src/reference-owner.ts +5 -0
- package/src/reference-page.ts +9 -0
- package/src/reference-source.ts +3 -0
- package/src/reference-text.ts +197 -0
- package/src/startpage-settings.ts +103 -0
- package/src/startpage.ts +71 -0
- package/src/takeover-protocol.ts +19 -0
- package/src/tool-browser/code-tool.ts +401 -0
- package/src/tool-browser/code-worker.ts +639 -0
- package/src/tool-browser/index.ts +908 -77
- package/src/tool-browser/page-probe.ts +4 -4
- package/src/tool-browser/panel-page.ts +124 -0
- package/src/tool-browser/screenshot-image.ts +49 -0
- package/src/tool-browser/takeover.ts +198 -0
- package/src/types/electron-shim.d.ts +20 -0
- package/src/types.ts +85 -0
- package/src/web-guest.ts +34 -0
- package/tools/accept-desktop.mjs +148 -0
- package/lib/browser/runtime.d.ts +0 -175
- package/lib/browser/types.d.ts +0 -797
- package/lib/browser-electron/authenticated-route.d.ts +0 -27
- package/lib/browser-electron/automatic-maintenance.d.ts +0 -41
- package/lib/browser-electron/bridge-auto.d.ts +0 -93
- package/lib/browser-electron/bridge-connection.d.ts +0 -93
- package/lib/browser-electron/bridge-endpoint.d.ts +0 -30
- package/lib/browser-electron/bridge-install.d.ts +0 -85
- package/lib/browser-electron/bridge-maintenance.d.ts +0 -24
- package/lib/browser-electron/bridge-status.d.ts +0 -50
- package/lib/browser-electron/desktop-bridge-host.d.ts +0 -248
- package/lib/browser-electron/desktop-identity.d.ts +0 -58
- package/lib/browser-electron/electron-provision.d.ts +0 -92
- package/lib/browser-electron/entry.d.ts +0 -64
- package/lib/browser-electron/ephemeral-profile.d.ts +0 -37
- package/lib/browser-electron/file-write.d.ts +0 -2
- package/lib/browser-electron/history-store.d.ts +0 -98
- package/lib/browser-electron/host-main.d.ts +0 -26
- package/lib/browser-electron/http-body.d.ts +0 -24
- package/lib/browser-electron/json-reply.d.ts +0 -33
- package/lib/browser-electron/maintenance-broker.d.ts +0 -35
- package/lib/browser-electron/maintenance-lifecycle.d.ts +0 -32
- package/lib/browser-electron/maintenance-route.d.ts +0 -18
- package/lib/browser-electron/missing-system-browser.d.ts +0 -54
- package/lib/browser-electron/paths.d.ts +0 -4
- package/lib/browser-electron/preview-route.d.ts +0 -89
- package/lib/browser-electron/process.d.ts +0 -14
- package/lib/browser-electron/provider.d.ts +0 -959
- package/lib/browser-electron/remote-host.d.ts +0 -256
- package/lib/browser-electron/rpc-input.d.ts +0 -4
- package/lib/browser-electron/rpc-ops.d.ts +0 -18
- package/lib/browser-electron/runtime-diagnostics.d.ts +0 -12
- package/lib/browser-electron/runtime-route.d.ts +0 -55
- package/lib/browser-electron/runtime-status.d.ts +0 -116
- package/lib/browser-electron/settings-route.d.ts +0 -15
- package/lib/browser-electron/settings-store.d.ts +0 -224
- package/lib/browser-electron/sidebar-only-host.d.ts +0 -36
- package/lib/browser-electron/system-browser.d.ts +0 -367
- package/lib/browser-electron/timing.d.ts +0 -8
- package/lib/browser-electron/virtual-cursor.d.ts +0 -67
- package/lib/browser-electron/windows-system.d.ts +0 -3
- package/lib/index.d.ts +0 -30
- package/lib/tool-browser/element-fields.d.ts +0 -145
- package/lib/tool-browser/index.d.ts +0 -53
- package/lib/tool-browser/page-probe.d.ts +0 -86
- package/scripts/consumer-install-check.mjs +0 -72
- package/scripts/run-tests.mjs +0 -32
- package/scripts/verify-host-compat.mjs +0 -195
- package/scripts/verify-preview-route.mjs +0 -168
- package/scripts/verify-runtime-status.mjs +0 -179
|
@@ -1,651 +1,251 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
* sidebar, instead of spawning a second, parallel Electron window.
|
|
4
|
-
*
|
|
5
|
-
* WHY
|
|
6
|
-
* The plugin runs inside the desktop's Node-mode host, where there is no Electron
|
|
7
|
-
* API — which is why it self-hosts a whole browser today. The shell, however, can
|
|
8
|
-
* own views, and its sidebar already displays real web pages. This host borrows
|
|
9
|
-
* that page over the shell's bridge (see apps/desktop/bridge/plugin-browser-bridge.js),
|
|
10
|
-
* so the agent and the human end up on ONE page instead of two.
|
|
11
|
-
*
|
|
12
|
-
* CONTRACT
|
|
13
|
-
* It implements the same `ElectronBrowserViewHost` seam the self-hosted host does,
|
|
14
|
-
* so the provider, the tools, browsing history, the synthetic cursor and the
|
|
15
|
-
* teardown rules are all unchanged: only the carrier differs. Everything is
|
|
16
|
-
* lazily materialized — a fresh shell has no sidebar guest until something asks
|
|
17
|
-
* for a page, and the bridge creates one on demand.
|
|
18
|
-
*
|
|
19
|
-
* FALLBACK
|
|
20
|
-
* `discover()` returns undefined whenever the shell offers no usable bridge
|
|
21
|
-
* (older desktop build, plain `dsh web`, bridge not started), and the entry point
|
|
22
|
-
* then keeps the self-hosted Electron it has always used.
|
|
23
|
-
* @module dsh-browser/browser-electron/desktop-bridge-host
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import { BridgeConnection, type BridgeEndpoint } from './bridge-connection.js'
|
|
1
|
+
/** Drive the visible sidebar guest through canonical, bridge-bound handles. */
|
|
2
|
+
import { BridgeConnection, type BridgeEndpoint } from './bridge-connection.ts'
|
|
27
3
|
import { readFileSync } from 'node:fs'
|
|
28
|
-
import { bridgeEndpointPath } from './paths.
|
|
4
|
+
import { bridgeEndpointPath } from './paths.ts'
|
|
29
5
|
import { randomUUID } from 'node:crypto'
|
|
30
|
-
import
|
|
31
|
-
import type { BrowserUserAction } from './provider.
|
|
32
|
-
import type { CarrierPage, CarrierLossReason } from '../browser/types.
|
|
33
|
-
|
|
6
|
+
import { readTabHandle, resolveSessionHandle, resolveTabHandle, sessionWireId, tabWireId, type BrowserSessionWireId, type BrowserTabWireId } from '../browser/handles.ts'
|
|
7
|
+
import type { CommandOptions, ElectronBrowserViewHost, ElectronViewHandle, BrowserUserAction } from './provider.ts'
|
|
8
|
+
import type { CarrierPage, CarrierLossReason } from '../browser/types.ts'
|
|
9
|
+
import { BridgeVersionError, bridgePackageError, isBridgeVersionMismatch } from '../bridge-compatibility.ts'
|
|
34
10
|
|
|
35
|
-
/** Absolute path of the endpoint file the shell writes. */
|
|
36
11
|
export { bridgeEndpointPath }
|
|
37
12
|
|
|
38
|
-
/**
|
|
39
|
-
* The error code the bridge uses when the conversation's panel exists but the shell is not showing
|
|
40
|
-
* that conversation, so no webview has attached yet (issue #37).
|
|
41
|
-
*
|
|
42
|
-
* A display state, not a dead carrier. It must never reach `reportLost`, and it must never be
|
|
43
|
-
* retried as though a guest had vanished: retrying cannot attach a webview the shell has not
|
|
44
|
-
* rendered, and treating it as loss swapped the surface to a fresh self-hosted window whose page was
|
|
45
|
-
* blank — losing the page the user had open.
|
|
46
|
-
*/
|
|
47
13
|
const PANEL_NOT_DISPLAYED = 'panel-not-displayed'
|
|
48
14
|
const PANEL_INITIALIZING = 'panel-initializing'
|
|
49
15
|
|
|
50
|
-
/**
|
|
51
|
-
* How many times a display-state refusal is retried, and how long each retry waits.
|
|
52
|
-
*
|
|
53
|
-
* The retry exists because the same call now asks the shell to SHOW the conversation (the client
|
|
54
|
-
* half's `openSession` step). React renders that on the next pass, so the refusal the first call
|
|
55
|
-
* sees is true-but-stale. 4 x 400 ms is ~1.6 s: long enough for a render on a busy conversation,
|
|
56
|
-
* short enough that a shell which genuinely cannot render a panel still fails inside one tool call
|
|
57
|
-
* instead of stalling for the bridge's own 20 s budget.
|
|
58
|
-
*/
|
|
59
|
-
const PANEL_DISPLAY_RETRIES = 4
|
|
60
|
-
const PANEL_DISPLAY_RETRY_MS = 400
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* A failure worth showing as-is: the carrier is alive and this is a condition the shell can change.
|
|
64
|
-
*
|
|
65
|
-
* Thrown instead of a plain Error so callers can distinguish "the panel did not render" from "the
|
|
66
|
-
* browser broke", which is exactly the distinction issue #37 says was missing. The plugin no longer
|
|
67
|
-
* waits for a human to show the conversation — the client half asks the shell to (`openSession`) and
|
|
68
|
-
* this host retries while it renders — so reaching here means the shell did not render it at all.
|
|
69
|
-
*/
|
|
70
16
|
export class BrowserPanelNotDisplayedError extends Error {
|
|
71
17
|
readonly code: string
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @param detail - the bridge's own explanation, appended so the message says why.
|
|
75
|
-
*/
|
|
76
18
|
constructor(detail: string, code = PANEL_NOT_DISPLAYED) {
|
|
77
|
-
super(
|
|
78
|
-
'dsh-builtin-browser: this conversation\'s sidebar page did not attach — the shell was asked to '
|
|
79
|
-
+ 'show this conversation and its panel still did not render. Nothing was lost, and the page '
|
|
80
|
-
+ 'appears as soon as the panel mounts. '
|
|
81
|
-
+ `(${detail})`,
|
|
82
|
-
)
|
|
19
|
+
super(`dsh-builtin-browser: this conversation's sidebar page did not attach (${detail})`)
|
|
83
20
|
this.name = 'BrowserPanelNotDisplayedError'
|
|
84
21
|
this.code = code
|
|
85
22
|
}
|
|
86
23
|
}
|
|
87
24
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*/
|
|
93
|
-
function isGuestGone(error: unknown): boolean {
|
|
94
|
-
// "The conversation is not displayed" is NOT a vanished guest. It is listed here as a negative
|
|
95
|
-
// because retrying it wastes the only thing it can produce: the same answer, slower. Issue #37 was
|
|
96
|
-
// this classification being too broad.
|
|
97
|
-
if (error instanceof BrowserPanelNotDisplayedError) return false
|
|
98
|
-
const message = error instanceof Error ? error.message : String(error)
|
|
99
|
-
// The panel path reports its own failure when the renderer never produced a page, and that is the
|
|
100
|
-
// same class as a vanished guest — worth one retry on a fresh panel — so it is listed here too.
|
|
101
|
-
return /guest \d+ is not available|sidebar unavailable|produced no page/i.test(message)
|
|
25
|
+
interface View {
|
|
26
|
+
readonly scope: BrowserSessionWireId
|
|
27
|
+
bound: boolean
|
|
28
|
+
adopted?: boolean
|
|
102
29
|
}
|
|
103
30
|
|
|
104
|
-
/**
|
|
105
|
-
* The desktop sidebar, presented as a browser view host.
|
|
106
|
-
*
|
|
107
|
-
* One sidebar exists per shell window, so every view this host hands out refers
|
|
108
|
-
* to the same guest: the provider keeps its tab bookkeeping, and the tabs simply
|
|
109
|
-
* share the visible page. That is the intended behaviour for this carrier — the
|
|
110
|
-
* point is a single page both parties can see.
|
|
111
|
-
*/
|
|
112
31
|
export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
32
|
+
readonly referenceOverlayOwner = 'client' as const
|
|
113
33
|
private readonly connection: BridgeConnection
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
* conversation — DSH runs them all through one host instance — so an owner held on the host
|
|
119
|
-
* would be one conversation's id applied to all of them, and a page could still land in
|
|
120
|
-
* another's sidebar however carefully the bridge checked it.
|
|
121
|
-
*/
|
|
122
|
-
private readonly views = new Map<string, { guest?: number; owner: string }>()
|
|
123
|
-
/**
|
|
124
|
-
* This process's identity with the bridge, for tab ownership.
|
|
125
|
-
*
|
|
126
|
-
* Every DSH session is its own plugin process, and the sidebar is one surface they all share.
|
|
127
|
-
* A session can only see its own `views` map, so before the bridge kept a ledger it adopted
|
|
128
|
-
* whichever tab it found — including one another session had opened, which is how a URL from
|
|
129
|
-
* one session appeared in another's sidebar. The id is per process, so two sessions never
|
|
130
|
-
* collide and one session's tabs are never handed to another; it is deliberately not the DSH
|
|
131
|
-
* session id, which this layer has no access to and does not need.
|
|
132
|
-
*
|
|
133
|
-
* The whole ledger rests on that premise, so it was measured rather than assumed: with two
|
|
134
|
-
* sessions running, the desktop had TWO host processes (plus one main, two renderers and a
|
|
135
|
-
* gpu/utility pair). If sessions ever shared a process, every owner check in the bridge would
|
|
136
|
-
* compare equal and the bleed would return in a new shape — so a change to how DSH spawns
|
|
137
|
-
* sessions invalidates this file, not just this comment.
|
|
138
|
-
*
|
|
139
|
-
* It is now the CONVERSATION id rather than an invented uuid, read from the plugin's ctx by the
|
|
140
|
-
* same path DSH's own desktop host uses. That matters because the shell keeps one sidebar per
|
|
141
|
-
* conversation and writes its session id onto each sidebar container (on the React fiber,
|
|
142
|
-
* measured on the running app) — so the bridge can only answer "is this sidebar mine" if it has
|
|
143
|
-
* a comparable id. With an invented uuid it never could, which is how a command came to be typed
|
|
144
|
-
* into another conversation's address bar.
|
|
145
|
-
*
|
|
146
|
-
* Falls back to a random uuid when the host cannot supply one — an older DSH, or a non-desktop
|
|
147
|
-
* composition. That is no worse than before: the bridge then knows only "this process", and it
|
|
148
|
-
* refuses to operate on a sidebar it cannot prove is its own.
|
|
149
|
-
*/
|
|
150
|
-
private readonly owner: string
|
|
151
|
-
/**
|
|
152
|
-
* Guests whose view is gone but whose page may still be open in the sidebar, with the
|
|
153
|
-
* conversation each belongs to.
|
|
154
|
-
*
|
|
155
|
-
* The provider destroys its view handles before it asks for a release, so the mapping is dropped
|
|
156
|
-
* by then — keeping the guest ids here is what lets us close only our own tabs when several
|
|
157
|
-
* conversations are running (requirements 搂4: each session gets its own page). The owner rides
|
|
158
|
-
* along for the same reason it does in {@link views}: a release names one conversation.
|
|
159
|
-
*/
|
|
160
|
-
private readonly orphaned = new Map<number, string>()
|
|
161
|
-
/**
|
|
162
|
-
* Registered by the provider, and deliberately never invoked on this carrier.
|
|
163
|
-
*
|
|
164
|
-
* The sidebar is the shell's own interface: a human clicking inside that page is an
|
|
165
|
-
* event the shell owns, and the bridge exposes no operation that reports it. The
|
|
166
|
-
* handler is stored anyway so the interface contract holds (a caller may register
|
|
167
|
-
* one and must not be surprised) and so a future bridge operation can deliver it
|
|
168
|
-
* without changing the provider. Consequently no user-action event is emitted while
|
|
169
|
-
* the desktop sidebar is the carrier — by design, not by omission.
|
|
170
|
-
*/
|
|
171
|
-
private userActionHandler: ((action: BrowserUserAction) => void) | undefined
|
|
172
|
-
/** Told when the shell behind this bridge exits; see `onLost`. */
|
|
34
|
+
private readonly views = new Map<string, View>()
|
|
35
|
+
private readonly orphaned = new Map<BrowserTabWireId, BrowserSessionWireId>()
|
|
36
|
+
private activeScope: BrowserSessionWireId | undefined
|
|
37
|
+
private readonly retiredSessions = new Set<BrowserSessionWireId>()
|
|
173
38
|
private lostListener: ((reason: CarrierLossReason) => void) | undefined
|
|
39
|
+
private static refuseIframe = false
|
|
40
|
+
private static versionError: string | undefined
|
|
174
41
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
*/
|
|
178
|
-
private constructor(endpoint: BridgeEndpoint, sessionId?: string, private readonly _isQuiet: () => boolean = () => false,
|
|
179
|
-
private readonly protocol = 2) {
|
|
180
|
-
this.owner = sessionId !== undefined && sessionId !== String.fromCharCode(39,39) ? sessionId : randomUUID()
|
|
181
|
-
// The transport reaches this only by concluding the shell stopped refreshing its endpoint, which
|
|
182
|
-
// is `shell-exited`.
|
|
183
|
-
this.connection = new BridgeConnection(endpoint, bridgeEndpointPath(), () => this.reportLost('shell-exited'))
|
|
42
|
+
private constructor(endpoint: BridgeEndpoint, private readonly isQuiet: () => boolean = () => false) {
|
|
43
|
+
this.connection = new BridgeConnection(endpoint, bridgeEndpointPath(), () => this.lostListener?.('shell-exited'))
|
|
184
44
|
}
|
|
185
45
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
* browser, and a host that tried to replace itself would be reaching outside its own contract.
|
|
191
|
-
* @param reason - which failure this was, so the fallback can say so accurately.
|
|
192
|
-
*/
|
|
193
|
-
private reportLost(reason: CarrierLossReason): void {
|
|
194
|
-
try {
|
|
195
|
-
this.lostListener?.(reason)
|
|
196
|
-
} catch {
|
|
197
|
-
// The listener's failure is not the transport's problem.
|
|
198
|
-
}
|
|
199
|
-
}
|
|
46
|
+
onLost(listener: (reason: CarrierLossReason) => void): void { this.lostListener = listener }
|
|
47
|
+
available(): boolean { return true }
|
|
48
|
+
static refusedIframePanel(): boolean { return this.refuseIframe }
|
|
49
|
+
static compatibilityError(): string | undefined { return this.versionError }
|
|
200
50
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
this.
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Find a usable desktop bridge, if this surface has one.
|
|
208
|
-
*
|
|
209
|
-
* A stale endpoint (a shell that already exited, leaving its file behind) is
|
|
210
|
-
* rejected here rather than surfacing later as a mysterious ECONNREFUSED: the
|
|
211
|
-
* caller falls back to self-hosting, which always works.
|
|
212
|
-
* @returns the host, or undefined when no bridge is available.
|
|
213
|
-
*/
|
|
214
|
-
static async discover(sessionId?: string, isQuiet?: () => boolean): Promise<DesktopBridgeViewHost | undefined> {
|
|
51
|
+
static async discover(_owner?: string, isQuiet?: () => boolean): Promise<DesktopBridgeViewHost | undefined> {
|
|
52
|
+
this.refuseIframe = false
|
|
53
|
+
this.versionError = undefined
|
|
215
54
|
let endpoint: BridgeEndpoint
|
|
216
55
|
try {
|
|
217
56
|
const raw = JSON.parse(readFileSync(bridgeEndpointPath(), 'utf8')) as Partial<BridgeEndpoint>
|
|
218
57
|
if (typeof raw.port !== 'number' || typeof raw.token !== 'string' || typeof raw.pid !== 'number') return undefined
|
|
219
|
-
endpoint = { port: raw.port, token: raw.token, pid: raw.pid, ...raw.updatedAt
|
|
220
|
-
} catch {
|
|
221
|
-
|
|
222
|
-
}
|
|
58
|
+
endpoint = { port: raw.port, token: raw.token, pid: raw.pid, ...raw.updatedAt === undefined ? {} : { updatedAt: raw.updatedAt } }
|
|
59
|
+
} catch { return undefined }
|
|
60
|
+
const probe = new BridgeConnection(endpoint, bridgeEndpointPath())
|
|
223
61
|
try {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
// built on CDP, so adopting it means failing every call, with no path back to a carrier
|
|
236
|
-
// that works. Reported on DSH Desktop 2.0.17 with both conditions measured.
|
|
237
|
-
//
|
|
238
|
-
// Read here WITHOUT an owner on purpose, because the question is not about a conversation:
|
|
239
|
-
// whether the panel is a webview is decided by the shell's preload and window options, so
|
|
240
|
-
// it is the same answer for every conversation and needs no session context.
|
|
241
|
-
//
|
|
242
|
-
// `none` and `unknown` are NOT refusals: a panel that does not exist yet is created by the
|
|
243
|
-
// first open, and a probe that could not read the attribute has learned nothing.
|
|
244
|
-
if (String(answer.frame ?? 'unknown') === 'iframe') {
|
|
245
|
-
DesktopBridgeViewHost.refuseIframe = true
|
|
246
|
-
return undefined
|
|
247
|
-
}
|
|
248
|
-
return new DesktopBridgeViewHost(endpoint, sessionId, isQuiet, Number(answer.protocol ?? 2))
|
|
249
|
-
} finally {
|
|
250
|
-
probe.close()
|
|
62
|
+
const answer = await probe.call({ op: 'list' }, 5_000)
|
|
63
|
+
if (isBridgeVersionMismatch(answer)) throw new BridgeVersionError()
|
|
64
|
+
if (answer.ok !== true) return undefined
|
|
65
|
+
if (typeof answer.protocol !== 'number' || !Number.isInteger(answer.protocol)) throw new BridgeVersionError()
|
|
66
|
+
if (answer.frame === 'iframe') { this.refuseIframe = true; return undefined }
|
|
67
|
+
return new DesktopBridgeViewHost(endpoint, isQuiet)
|
|
68
|
+
} catch (error) {
|
|
69
|
+
const versionError = bridgePackageError(error) ?? (error instanceof BridgeVersionError ? error : undefined)
|
|
70
|
+
if (versionError !== undefined) {
|
|
71
|
+
this.versionError = versionError.message
|
|
72
|
+
throw versionError
|
|
251
73
|
}
|
|
252
|
-
} catch {
|
|
253
|
-
// Dead endpoint or an older bridge: self-hosting remains the answer.
|
|
254
74
|
return undefined
|
|
255
75
|
}
|
|
76
|
+
finally { probe.close() }
|
|
256
77
|
}
|
|
257
78
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
* Recorded so the entry point can say WHY the plugin is self-hosting on a shell that does have a
|
|
262
|
-
* bridge. Otherwise the user sees a second browser window and no explanation, on a machine where
|
|
263
|
-
* they just followed instructions to install the bridge.
|
|
264
|
-
*/
|
|
265
|
-
private static refuseIframe = false
|
|
266
|
-
|
|
267
|
-
/** Whether discovery refused a bridge for an undrivable sidebar panel (see {@link discover}). */
|
|
268
|
-
static refusedIframePanel(): boolean {
|
|
269
|
-
return this.refuseIframe
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/** Whether this host can back views: the bridge already answered `list`. */
|
|
273
|
-
available(): boolean {
|
|
274
|
-
return true
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Every page this conversation's sidebar panel currently holds.
|
|
279
|
-
*
|
|
280
|
-
* The shell owns page creation inside the panel: a link the user or the agent clicks may open a
|
|
281
|
-
* new page, and nothing tells the provider. Those pages are real — they are what the human sees
|
|
282
|
-
* — but without this the tab model reports only the ones the provider created, so the rest are
|
|
283
|
-
* invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
|
|
284
|
-
*
|
|
285
|
-
* The bridge's `list` already answers with the sidebar guests, which is the same information, so
|
|
286
|
-
* this asks for it rather than reaching into the shell again.
|
|
287
|
-
* @returns the panel's pages, or an empty list when the bridge cannot answer.
|
|
288
|
-
*/
|
|
289
|
-
/**
|
|
290
|
-
* Every sidebar page this conversation holds that THIS HOST did not open.
|
|
291
|
-
*
|
|
292
|
-
* The shell owns page creation inside the panel: a link the user or the agent clicks may open a
|
|
293
|
-
* new page, and nothing tells the provider. Those pages are real — they are what the human sees
|
|
294
|
-
* — but without this the tab model reports only the ones the provider created, so the rest are
|
|
295
|
-
* invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
|
|
296
|
-
*
|
|
297
|
-
* Pages this host opened are EXCLUDED here rather than deduplicated by the caller, because the
|
|
298
|
-
* caller cannot do it: the provider knows a tab by its own id and the carrier knows a page by the
|
|
299
|
-
* guest id, and the two never match. The first version returned everything and relied on the
|
|
300
|
-
* caller to filter, which reported the same page twice — the mapping that makes the match
|
|
301
|
-
* possible exists only here.
|
|
302
|
-
* @returns the panel's pages that are not ours, or an empty list when the bridge cannot answer.
|
|
303
|
-
*/
|
|
304
|
-
async listPages(owner: string = this.owner): Promise<readonly CarrierPage[]> {
|
|
305
|
-
const answer = await this.connection.call({ op: 'list', owner }, 5_000)
|
|
79
|
+
async listPages(scope: BrowserSessionWireId, _options: { readonly requireRunning?: boolean } = {}): Promise<readonly CarrierPage[]> {
|
|
80
|
+
resolveSessionHandle(scope)
|
|
81
|
+
const answer = await this.connection.call({ op: 'list', handle: scope }, 5_000)
|
|
306
82
|
if (answer.ok !== true) throw new Error(String(answer.error ?? 'sidebar page listing failed'))
|
|
307
|
-
|
|
308
|
-
const
|
|
309
|
-
for (const
|
|
310
|
-
if (typeof
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* The guest backing a view, materialized on first use.
|
|
341
|
-
*
|
|
342
|
-
* The conversation that called owns exactly one sidebar page on this carrier — a human and the
|
|
343
|
-
* agent look at the same page — so every view resolves to that conversation's own guest, and the
|
|
344
|
-
* page does not multiply behind the provider's own tab bookkeeping.
|
|
345
|
-
*
|
|
346
|
-
* A cached guest is used as-is: probing it first cost a round-trip on every command, so liveness
|
|
347
|
-
* is established by the command failing instead.
|
|
348
|
-
* @param viewId - the view whose guest is wanted.
|
|
349
|
-
* @param url - address to use when this conversation has no page yet.
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
private async guestFor(viewId: string, url?: string, options?: CommandOptions): Promise<number> {
|
|
353
|
-
const entry = this.views.get(viewId)
|
|
83
|
+
if (!Array.isArray(answer.sidebar)) throw new Error('invalid sidebar page listing')
|
|
84
|
+
const pages: CarrierPage[] = []
|
|
85
|
+
for (const page of answer.sidebar) {
|
|
86
|
+
if (typeof page?.id !== 'string') throw new Error('invalid sidebar page handle')
|
|
87
|
+
resolveTabHandle(resolveSessionHandle(scope), page.id)
|
|
88
|
+
if (!this.views.has(page.id)) pages.push({ id: page.id, url: String(page.url ?? ''), title: String(page.title ?? '') })
|
|
89
|
+
}
|
|
90
|
+
return pages
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async adoptPage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))): Promise<ElectronViewHandle> {
|
|
94
|
+
const identity = tabWireId(resolveTabHandle(resolveSessionHandle(scope), id))
|
|
95
|
+
const answer = await this.connection.call({ op: 'adoptPage', handle: identity })
|
|
96
|
+
if (answer.ok !== true || answer.id !== id) throw new Error(String(answer.error ?? 'sidebar page adoption failed'))
|
|
97
|
+
const handle = this.createView(identity)
|
|
98
|
+
const entry = this.views.get(handle.id)!
|
|
99
|
+
entry.bound = true
|
|
100
|
+
entry.adopted = true
|
|
101
|
+
return handle
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async closePage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))): Promise<void> {
|
|
105
|
+
const identity = tabWireId(resolveTabHandle(resolveSessionHandle(scope), id))
|
|
106
|
+
const blank = this.views.get(id)?.bound === false
|
|
107
|
+
const answer = await this.connection.call({ op: blank ? 'releaseTab' : 'closePage', handle: identity }, 10_000)
|
|
108
|
+
if (answer.ok !== true || (!blank && answer.closed !== 1)) throw new Error(`dsh-builtin-browser: could not close sidebar page: ${String(answer.error ?? 'close not acknowledged')}`)
|
|
109
|
+
this.views.delete(id)
|
|
110
|
+
this.orphaned.delete(id)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private async guestFor(id: BrowserTabWireId, url?: string, options?: CommandOptions, checkNavigation?: () => void): Promise<Record<string, unknown> | undefined> {
|
|
114
|
+
const entry = this.views.get(id)
|
|
354
115
|
if (entry === undefined) throw new Error('dsh-builtin-browser: sidebar view was released')
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (entry?.guest !== undefined && url === undefined) return entry.guest
|
|
364
|
-
if (options?.initialize === false) {
|
|
116
|
+
const check = (): void => {
|
|
117
|
+
options?.signal?.throwIfAborted()
|
|
118
|
+
checkNavigation?.()
|
|
119
|
+
if (this.views.get(id) !== entry) throw new Error('dsh-builtin-browser: sidebar view was released')
|
|
120
|
+
}
|
|
121
|
+
check()
|
|
122
|
+
if (entry.bound) return undefined
|
|
123
|
+
if (options?.initialize === false || options?.present === false) {
|
|
365
124
|
throw new BrowserPanelNotDisplayedError('this view has no attached guest yet', PANEL_INITIALIZING)
|
|
366
125
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
// shortcut or clicking its card, both of which the shell delivers to whatever it displays.
|
|
379
|
-
const owner = entry?.owner ?? this.owner
|
|
380
|
-
if (url !== undefined && this.protocol < 3
|
|
381
|
-
&& [...this.views.entries()].some(([id, view]) => id !== viewId && view.owner === owner && view.guest !== undefined)) {
|
|
382
|
-
throw new Error('dsh-builtin-browser: this desktop bridge needs an update for separate sidebar tabs; use Repair and restart in Browser settings')
|
|
383
|
-
}
|
|
384
|
-
// A command that must not present anything (issue #46: the live preview) takes a read-only path.
|
|
385
|
-
// 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
|
|
386
|
-
// and wrong for "let me look at it". A page that is not on screen therefore reports as a display
|
|
387
|
-
// state, and the preview route turns that into the panel's paused state.
|
|
388
|
-
if (options?.present === false) {
|
|
389
|
-
// A logical view without a binding cannot borrow a neighbouring tab for a preview.
|
|
390
|
-
if (this.protocol >= 3) {
|
|
391
|
-
throw new BrowserPanelNotDisplayedError('this view has no attached guest yet', PANEL_INITIALIZING)
|
|
392
|
-
}
|
|
393
|
-
// `list` and NOT `ensureSidebar`. This is deliberate and it is the whole fix: every version of
|
|
394
|
-
// `ensureSidebar` can drive the shell — the current one asks the renderer to display the
|
|
395
|
-
// conversation, and the pre-#37 one literally pressed the sidebar shortcut and typed into the
|
|
396
|
-
// address bar. `list` is a pure read on every version, so a preview cannot move anything even
|
|
397
|
-
// when the installed bridge is old (which is exactly the reporter's environment: the symptom
|
|
398
|
-
// appears only once a bridge is installed).
|
|
399
|
-
const listed = await this.connection.call({ op: 'list', owner }, 8_000)
|
|
400
|
-
const pages = Array.isArray(listed.sidebar)
|
|
401
|
-
? listed.sidebar.filter(page => page !== null && typeof page === 'object' && page.type === 'webview')
|
|
402
|
-
: []
|
|
403
|
-
const wanted = url !== undefined && url !== '' ? url : undefined
|
|
404
|
-
const samePage = (url: string, wanted: string): boolean => url === wanted || url.startsWith(`${wanted}?`) || url.startsWith(`${wanted}#`)
|
|
405
|
-
const match = pages.find(page => wanted !== undefined && typeof page.url === 'string' && samePage(page.url, wanted)) ?? pages[0]
|
|
406
|
-
const id = match !== undefined ? Number(match.id) : Number.NaN
|
|
407
|
-
if (!Number.isFinite(id) || id <= 0) {
|
|
408
|
-
throw new BrowserPanelNotDisplayedError(
|
|
409
|
-
'the preview asked for this conversation\'s page without presenting it, and no page is attached '
|
|
410
|
-
+ `(the shell holds ${pages.length})`,
|
|
411
|
-
)
|
|
412
|
-
}
|
|
413
|
-
stillOwned()
|
|
414
|
-
entry.guest = id
|
|
415
|
-
return id
|
|
416
|
-
}
|
|
417
|
-
const ask = (): Promise<Record<string, unknown>> => this.connection.call({
|
|
418
|
-
op: 'ensureSidebar',
|
|
419
|
-
owner,
|
|
420
|
-
viewId,
|
|
421
|
-
...entry?.guest === undefined ? {} : { guestId: entry.guest },
|
|
422
|
-
...url !== undefined && url !== '' ? { url } : {},
|
|
423
|
-
}, 30_000)
|
|
424
|
-
let answer = await ask()
|
|
425
|
-
// A refusal is retried when it describes a DISPLAY state rather than a dead carrier, because the
|
|
426
|
-
// plugin's client half asks the shell to show this conversation inside the very call that
|
|
427
|
-
// produced it. Two shapes come back from that first round:
|
|
428
|
-
// panel-not-displayed - the conversation exists but is not the one on screen;
|
|
429
|
-
// "is not mounted" - its surface store was not minted when the tab was placed.
|
|
430
|
-
// Both are gone one render later. Measured, this is the whole difference between "the sidebar
|
|
431
|
-
// works once I click over to that conversation" and "it works" — the page is real either way,
|
|
432
|
-
// and failing the call while the shell is already switching away from it just reported a
|
|
433
|
-
// problem the plugin had already fixed.
|
|
434
|
-
const displayRefusal = (value: Record<string, unknown>): boolean =>
|
|
435
|
-
value.ok !== true
|
|
436
|
-
&& (String(value.code ?? '') === PANEL_NOT_DISPLAYED
|
|
437
|
-
|| String(value.error ?? '').includes('not mounted')
|
|
438
|
-
// Bridges installed before issue #37 send the same refusal with NO code — the installed copy
|
|
439
|
-
// on this machine is one of them (`panel-not-displayed` appears nowhere in it). Reading only
|
|
440
|
-
// the code therefore turned a retryable display state into a hard failure for exactly the
|
|
441
|
-
// users who had the old bridge, which is the majority until it is reinstalled. The wording
|
|
442
|
-
// is stable across both versions; the code is not.
|
|
443
|
-
|| String(value.error ?? '').includes('can only attach'))
|
|
444
|
-
for (let attempt = 0; attempt < PANEL_DISPLAY_RETRIES && displayRefusal(answer); attempt += 1) {
|
|
445
|
-
await new Promise(resolve => setTimeout(resolve, PANEL_DISPLAY_RETRY_MS))
|
|
446
|
-
stillOwned()
|
|
447
|
-
answer = await ask()
|
|
448
|
-
}
|
|
449
|
-
stillOwned()
|
|
126
|
+
if (entry.adopted) throw new Error('dsh-builtin-browser: the sidebar page this view was adopted from is gone')
|
|
127
|
+
const deadline = options?.deadline ?? Date.now() + 30_000
|
|
128
|
+
const transactionId = randomUUID()
|
|
129
|
+
const cancel = (): void => { void this.connection.call({ op: 'cancelSidebar', handle: id, transactionId }, 2_000).catch(() => {}) }
|
|
130
|
+
options?.signal?.addEventListener('abort', cancel, { once: true })
|
|
131
|
+
let answer: Record<string, unknown>
|
|
132
|
+
try {
|
|
133
|
+
answer = await this.connection.call({ op: 'ensureSidebar', handle: id, deadline, transactionId,
|
|
134
|
+
...url ? { url, attachOnly: true } : {} }, Math.max(1, deadline - Date.now()))
|
|
135
|
+
} finally { options?.signal?.removeEventListener('abort', cancel) }
|
|
136
|
+
check()
|
|
450
137
|
if (answer.ok !== true) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
if (
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
entry.guest = id
|
|
471
|
-
return id
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* @param owner - the conversation this view serves. Recorded WITH the view: one host instance
|
|
476
|
-
* serves every conversation, so the owner cannot live on the host.
|
|
477
|
-
*/
|
|
478
|
-
createView(owner?: string): ElectronViewHandle {
|
|
479
|
-
const viewId = randomUUID()
|
|
480
|
-
this.views.set(viewId, { owner: owner !== undefined && owner !== '' ? owner : this.owner })
|
|
481
|
-
const navigateUrl = (method: string, params?: Record<string, unknown>): string | undefined =>
|
|
482
|
-
method === 'Page.navigate' ? String((params as { url?: unknown })?.url ?? '') : undefined
|
|
483
|
-
const run = async (guest: number, method: string, params?: Record<string, unknown>): Promise<Record<string, unknown>> => {
|
|
484
|
-
const owner = this.views.get(viewId)?.owner ?? this.owner
|
|
485
|
-
const answer = await this.connection.call({ op: 'cdp', id: guest, method, params, owner })
|
|
486
|
-
if (answer.ok !== true) throw new Error(`dsh-builtin-browser: sidebar command failed: ${String(answer.error)}`)
|
|
487
|
-
// The bridge forwards whatever CDP answered; the seam expects an object.
|
|
488
|
-
return (answer.result ?? {}) as Record<string, unknown>
|
|
489
|
-
}
|
|
138
|
+
const code = String(answer.code ?? 'panel-initialization-failed')
|
|
139
|
+
const detail = String(answer.error ?? 'sidebar unavailable')
|
|
140
|
+
if (code === PANEL_NOT_DISPLAYED || code === PANEL_INITIALIZING) throw new BrowserPanelNotDisplayedError(detail, code)
|
|
141
|
+
if (code === 'panel-unusable') this.lostListener?.('panel-unusable')
|
|
142
|
+
throw Object.assign(new Error(`dsh-builtin-browser: sidebar unavailable (${detail})`), { code, initialization: answer.initialization })
|
|
143
|
+
}
|
|
144
|
+
if (answer.id !== id) throw new Error('dsh-builtin-browser: sidebar returned a different tab handle')
|
|
145
|
+
entry.bound = true
|
|
146
|
+
return answer.navigation && typeof answer.navigation === 'object' ? answer.navigation as Record<string, unknown> : undefined
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
createView(identity: BrowserTabWireId): ElectronViewHandle {
|
|
150
|
+
const scope = sessionWireId(readTabHandle(identity))
|
|
151
|
+
if (this.retiredSessions.has(scope)) throw new Error('dsh-builtin-browser: sidebar session was released')
|
|
152
|
+
const id = identity
|
|
153
|
+
this.activeScope = scope
|
|
154
|
+
if (this.views.has(id)) throw new Error('dsh-builtin-browser: sidebar view is already bound')
|
|
155
|
+
this.views.set(id, { scope, bound: false })
|
|
156
|
+
let latestNavigation = 0
|
|
490
157
|
return {
|
|
491
|
-
id
|
|
492
|
-
download: async (url
|
|
493
|
-
|
|
494
|
-
const
|
|
495
|
-
const owner = this.views.get(viewId)?.owner ?? this.owner
|
|
496
|
-
const answer = await this.connection.call({ op: 'download', id: guest, owner, url, savePath }, 60_000)
|
|
158
|
+
id,
|
|
159
|
+
download: async (url, savePath) => {
|
|
160
|
+
await this.guestFor(id)
|
|
161
|
+
const answer = await this.connection.call({ op: 'download', handle: id, url, savePath }, 60_000)
|
|
497
162
|
if (answer.ok !== true) throw new Error(`dsh-builtin-browser: sidebar download failed: ${String(answer.error)}`)
|
|
498
163
|
},
|
|
499
|
-
sendCommand: async (method
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const url = navigateUrl(method, params)
|
|
505
|
-
let guest = await this.guestFor(viewId, url, options)
|
|
506
|
-
try {
|
|
507
|
-
return await run(guest, method, params)
|
|
508
|
-
} catch (error) {
|
|
509
|
-
if (!isGuestGone(error)) throw error
|
|
510
|
-
// The human closed the tab: the page is gone, so take a fresh one and
|
|
511
|
-
// replay the command once. This is the "closing the interface ends the
|
|
512
|
-
// session" rule, now paid for only when it actually happens.
|
|
513
|
-
// Drop the guest but keep the entry: the conversation it serves is what the retry needs,
|
|
514
|
-
// and removing the entry would lose it back to the process-wide fallback owner.
|
|
515
|
-
const lost = this.views.get(viewId)
|
|
516
|
-
if (lost !== undefined) delete lost.guest
|
|
517
|
-
guest = await this.guestFor(viewId, url, options)
|
|
518
|
-
return await run(guest, method, params)
|
|
164
|
+
sendCommand: async (method, params, options) => {
|
|
165
|
+
const url = method === 'Page.navigate' ? String(params?.url ?? '') : undefined
|
|
166
|
+
const sequence = url === undefined ? latestNavigation : ++latestNavigation
|
|
167
|
+
const check = (): void => {
|
|
168
|
+
if (sequence !== latestNavigation) throw Object.assign(new Error('a newer navigation was requested for this sidebar view'), { code: 'panel-navigation-superseded' })
|
|
519
169
|
}
|
|
170
|
+
const navigation = await this.guestFor(id, url, options, check)
|
|
171
|
+
check()
|
|
172
|
+
if (navigation !== undefined) return navigation
|
|
173
|
+
const answer = await this.connection.call({ op: 'cdp', handle: id, method, params })
|
|
174
|
+
if (answer.ok !== true) throw Object.assign(new Error(`dsh-builtin-browser: sidebar command failed: ${String(answer.error)}`), { code: answer.code })
|
|
175
|
+
return (answer.result ?? {}) as Record<string, unknown>
|
|
520
176
|
},
|
|
521
177
|
}
|
|
522
178
|
}
|
|
523
179
|
|
|
524
180
|
destroyView(handle: ElectronViewHandle): void {
|
|
525
181
|
const entry = this.views.get(handle.id)
|
|
526
|
-
if (entry
|
|
527
|
-
|
|
528
|
-
// exactly the tabs this conversation's views opened. The owner comes along so a release
|
|
529
|
-
// naming one conversation does not sweep up another's.
|
|
530
|
-
if (entry.guest !== undefined) this.orphaned.set(entry.guest, entry.owner)
|
|
531
|
-
this.views.delete(handle.id)
|
|
532
|
-
}
|
|
182
|
+
if (entry?.bound && !entry.adopted) this.orphaned.set(tabWireId(readTabHandle(handle.id)), entry.scope)
|
|
183
|
+
this.views.delete(handle.id)
|
|
533
184
|
}
|
|
534
185
|
|
|
535
|
-
/**
|
|
536
|
-
* Bring this view's tab to the front in the sidebar.
|
|
537
|
-
*
|
|
538
|
-
* This used to be empty, on the reasoning that the sidebar is already on screen so there is
|
|
539
|
-
* nothing to show. That confused "the sidebar is visible" with "this page is the one being
|
|
540
|
-
* looked at": opening a page left it behind whatever the human had in front, which is issue
|
|
541
|
-
* #23. The other two carriers both do this — the self-hosted window re-adds the view and the
|
|
542
|
-
* system browser calls `Page.bringToFront` — so this carrier was the odd one out.
|
|
543
|
-
*
|
|
544
|
-
* Best-effort by design: the tab strip belongs to the shell's renderer, and failing to raise
|
|
545
|
-
* it must not fail the navigation that has already happened.
|
|
546
|
-
* @param handle - the view to bring forward.
|
|
547
|
-
*/
|
|
548
186
|
showView(handle: ElectronViewHandle, _label?: string, options?: { readonly quiet?: boolean; readonly select?: boolean }): void {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
this.
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
this.views.delete(viewId)
|
|
591
|
-
}
|
|
592
|
-
// A view destroyed before the release still owns its page; its guest is collected here.
|
|
593
|
-
for (const [guest, holder] of [...this.orphaned]) {
|
|
594
|
-
if (owner !== undefined && holder !== owner) continue
|
|
595
|
-
mine.push(guest)
|
|
596
|
-
this.orphaned.delete(guest)
|
|
597
|
-
}
|
|
598
|
-
// Nothing of ours is open: release nothing. Falling through to an unfiltered
|
|
599
|
-
// release here would close tabs a human opened, or another session's page.
|
|
600
|
-
if (mine.length === 0) return
|
|
601
|
-
let titles: string[]
|
|
602
|
-
try {
|
|
603
|
-
// `owner` is REQUIRED here now that the bridge filters `list` by it. Without it the bridge
|
|
604
|
-
// falls back to a different owner, so the guests this session holds are filtered out of the
|
|
605
|
-
// answer, `mine.includes(...)` matches nothing, the title list comes back empty and this
|
|
606
|
-
// returns without closing anything — the page stayed open and the human had to close it by
|
|
607
|
-
// hand. Adding the ledger to the bridge without updating this call site is exactly the kind
|
|
608
|
-
// of half-change that made the ownership work take four rounds.
|
|
609
|
-
const answer = await this.connection.call({ op: 'list', owner: owner ?? this.owner }, 5_000)
|
|
610
|
-
const sidebar = Array.isArray(answer.sidebar) ? answer.sidebar as Array<{ id?: unknown; title?: unknown }> : []
|
|
611
|
-
titles = sidebar
|
|
612
|
-
.filter(guest => mine.includes(Number(guest.id)))
|
|
613
|
-
.map(guest => String(guest.title ?? ''))
|
|
614
|
-
.filter(title => title !== '')
|
|
615
|
-
} catch {
|
|
616
|
-
// Could not read the titles back; releasing nothing is safer than closing
|
|
617
|
-
// tabs that belong to somebody else.
|
|
618
|
-
return
|
|
619
|
-
}
|
|
620
|
-
if (titles.length === 0) return
|
|
187
|
+
if ((options?.quiet ?? this.isQuiet()) && options?.select !== true) return
|
|
188
|
+
if (!this.views.get(handle.id)?.bound) return
|
|
189
|
+
void this.connection.call({ op: 'showTab', handle: tabWireId(readTabHandle(handle.id)) }, 5_000).catch(() => {})
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
onUserAction(_handler: (action: BrowserUserAction) => void): void {}
|
|
193
|
+
|
|
194
|
+
async presentView(handle: ElectronViewHandle, _label?: string, options?: { readonly quiet?: boolean; readonly select?: boolean }): Promise<void> {
|
|
195
|
+
if ((options?.quiet ?? this.isQuiet()) && options?.select !== true) return
|
|
196
|
+
const id = tabWireId(readTabHandle(handle.id))
|
|
197
|
+
await this.guestFor(id)
|
|
198
|
+
const answer = await this.connection.call({ op: 'showTab', handle: id })
|
|
199
|
+
if (answer.ok !== true) throw Object.assign(new Error(String(answer.error ?? 'sidebar selection failed')), { code: answer.code })
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async retireSession(scope: BrowserSessionWireId): Promise<void> {
|
|
203
|
+
resolveSessionHandle(scope)
|
|
204
|
+
if (this.retiredSessions.has(scope)) return
|
|
205
|
+
this.retiredSessions.add(scope)
|
|
206
|
+
const answer = await this.connection.call({ op: 'releaseSession', handle: scope })
|
|
207
|
+
if (answer.ok !== true) throw new Error(String(answer.error ?? 'sidebar release failed'))
|
|
208
|
+
for (const [id, held] of this.orphaned) if (held === scope) this.orphaned.delete(id)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async releasePage(scope?: BrowserSessionWireId): Promise<void> {
|
|
212
|
+
if (scope !== undefined) resolveSessionHandle(scope)
|
|
213
|
+
const mine = new Set<BrowserTabWireId>()
|
|
214
|
+
const scopes = new Set<BrowserSessionWireId>()
|
|
215
|
+
for (const [id, entry] of this.views) {
|
|
216
|
+
if (scope !== undefined && entry.scope !== scope) continue
|
|
217
|
+
scopes.add(entry.scope)
|
|
218
|
+
if (entry.bound && !entry.adopted) mine.add(tabWireId(readTabHandle(id)))
|
|
219
|
+
this.views.delete(id)
|
|
220
|
+
}
|
|
221
|
+
for (const [id, held] of this.orphaned) {
|
|
222
|
+
if (scope !== undefined && held !== scope) continue
|
|
223
|
+
scopes.add(sessionWireId(readTabHandle(id)))
|
|
224
|
+
mine.add(tabWireId(readTabHandle(id)))
|
|
225
|
+
this.orphaned.delete(id)
|
|
226
|
+
}
|
|
227
|
+
if (scope !== undefined) scopes.add(scope)
|
|
621
228
|
try {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
229
|
+
const results = await Promise.allSettled([...mine].map(async id => {
|
|
230
|
+
const answer = await this.connection.call({ op: 'closePage', handle: id }, 10_000)
|
|
231
|
+
if (answer.ok !== true || answer.closed !== 1) throw new Error(String(answer.error ?? 'sidebar close not acknowledged'))
|
|
232
|
+
}))
|
|
233
|
+
const failure = results.find(result => result.status === 'rejected')
|
|
234
|
+
if (failure?.status === 'rejected') throw failure.reason
|
|
235
|
+
} finally {
|
|
236
|
+
await Promise.all([...scopes].map(handle => this.retireSession(handle)))
|
|
628
237
|
}
|
|
629
238
|
}
|
|
630
239
|
|
|
631
|
-
/**
|
|
632
|
-
* Fold the sidebar away without ending the page (`ui.autoExpandOnce` is off, or
|
|
633
|
-
* the caller wants the screen back while work continues).
|
|
634
|
-
* @returns a promise that settles once the shell has been asked.
|
|
635
|
-
*/
|
|
636
240
|
async collapse(): Promise<void> {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
} catch {
|
|
640
|
-
// Presentation only; failing to fold is never worth an error.
|
|
641
|
-
}
|
|
241
|
+
if (this.activeScope === undefined) return
|
|
242
|
+
await this.connection.call({ op: 'collapseSidebar', handle: this.activeScope }, 10_000).catch(() => {})
|
|
642
243
|
}
|
|
643
244
|
|
|
644
|
-
/** No child process of our own to stop; close the shared connection instead. */
|
|
645
245
|
dispose(): void {
|
|
646
246
|
this.connection.close()
|
|
647
247
|
this.views.clear()
|
|
648
248
|
this.orphaned.clear()
|
|
649
|
-
this.
|
|
249
|
+
this.activeScope = undefined
|
|
650
250
|
}
|
|
651
251
|
}
|