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