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,47 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* `ctx.electronViewHost`, that host is used (embedded, human-machine shared
|
|
6
|
-
* view). Otherwise the plugin self-hosts: it spawns its own Electron child
|
|
7
|
-
* (`host-main.js`) and drives it over a local TCP JSON-RPC socket, so
|
|
8
|
-
* installing the plugin is enough for `dsh_browser_*` tools to work on any
|
|
9
|
-
* surface.
|
|
10
|
-
* @module dsh-browser/browser-electron
|
|
11
|
-
*/
|
|
1
|
+
import { referenceCaptureMessages, referenceCaptureErrors } from '../../assets/browser-messages.mjs';
|
|
2
|
+
import { BROWSER_PROFILE_DIR, SETTINGS_ROUTE, EXTENSION_INSTALL_ROUTE } from '../../assets/browser-policy.mjs';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { statSync } from 'node:fs';
|
|
12
5
|
import z from '@deepseek-ai/schemastery';
|
|
13
6
|
import { ElectronBrowserProvider } from './provider.js';
|
|
14
7
|
import { provisionElectronInBackground, provisionSnapshot, hasElectronRuntime } from './electron-provision.js';
|
|
15
8
|
import { randomUUID } from 'node:crypto';
|
|
16
|
-
import { existsSync, mkdirSync, renameSync
|
|
9
|
+
import { existsSync, mkdirSync, renameSync } from 'node:fs';
|
|
17
10
|
import { homedir } from 'node:os';
|
|
18
11
|
import { dirname, join } from 'node:path';
|
|
19
12
|
import { dshHome } from './paths.js';
|
|
20
13
|
import { setTimeout as wait } from 'node:timers/promises';
|
|
21
|
-
import { defaultHostMainPath, RemoteElectronViewHost } from './remote-host.js';
|
|
22
14
|
import { DesktopBridgeViewHost } from './desktop-bridge-host.js';
|
|
23
15
|
import { SidebarOnlyHost } from './sidebar-only-host.js';
|
|
16
|
+
import { ExtensionBrowserViewHost, extensionInstallHelp } from './extension-browser.js';
|
|
17
|
+
import { PreferredBrowserViewHost } from './preferred-browser.js';
|
|
18
|
+
import { nativeRegistration, installExtension, registrationStatus, probeExtension } from './extension-setup.js';
|
|
19
|
+
import { registerCarrierTakeover } from '../browser/takeover-target.js';
|
|
24
20
|
import { detectBrowser, searchSummary, SystemBrowserViewHost } from './system-browser.js';
|
|
25
21
|
import { claimEphemeralProfile, ephemeralProfileName, sweepAbandonedEphemeralProfiles } from './ephemeral-profile.js';
|
|
26
22
|
import { MissingSystemBrowserHost } from './missing-system-browser.js';
|
|
27
23
|
import { SettingsStore, settingsPath } from './settings-store.js';
|
|
28
24
|
import { sameOrigin } from './settings-route.js';
|
|
29
|
-
import { authenticatedRoute, isDirectLoopback } from './authenticated-route.js';
|
|
25
|
+
import { authenticatedRoute, pairedRoute, isDirectLoopback } from './authenticated-route.js';
|
|
26
|
+
import { overlayScript } from '../browser-reference/entry.js';
|
|
27
|
+
import { getLastOpen } from './open-slot.js';
|
|
28
|
+
import { resolveSessionHandle, sessionWireId } from '../browser/handles.js';
|
|
30
29
|
import { handleBridgeStatus, handlePreviewFrame, handlePreviewSessions, BRIDGE_STATUS_ROUTE, PREVIEW_ROUTE, PREVIEW_SESSIONS_ROUTE } from './preview-route.js';
|
|
31
30
|
import { findDesktopInstall, readBridgeStatus } from './bridge-status.js';
|
|
31
|
+
import { readHostExtensionStatus } from './profile-extension.js';
|
|
32
32
|
import { readBridgeEndpoint } from './bridge-endpoint.js';
|
|
33
33
|
import { runBridgeAction } from './bridge-install.js';
|
|
34
34
|
import { prepareBridgeMaintenance } from './bridge-maintenance.js';
|
|
35
|
-
import { commitAutomaticMaintenance, readAutomaticMaintenance, startAutomaticMaintenance } from './automatic-maintenance.js';
|
|
35
|
+
import { automaticMaintenanceSupported, commitAutomaticMaintenance, readAutomaticMaintenance, startAutomaticMaintenance } from './automatic-maintenance.js';
|
|
36
36
|
import { AUTOMATIC_MAINTENANCE_ROUTE, createAutomaticMaintenanceHandler } from './maintenance-route.js';
|
|
37
|
+
import { HOST_PATCH_ROUTE, createHostPatchMaintenance, servedClientModules } from './host-patch-maintenance.js';
|
|
37
38
|
import { runWithManualBridgePreference } from './bridge-auto.js';
|
|
38
39
|
import { replyJson, writeJsonText } from './json-reply.js';
|
|
39
40
|
import { readJsonBody, readTextBody } from './http-body.js';
|
|
40
41
|
import { readRuntimeStatus } from './runtime-status.js';
|
|
41
42
|
import { handleRuntimeProvision, handleRuntimeStatus, RUNTIME_PROVISION_ROUTE, RUNTIME_STATUS_ROUTE } from './runtime-route.js';
|
|
43
|
+
import { createShortcutRouteHandlers, SHORTCUT_ADD_ROUTE, SHORTCUT_REMOVE_ROUTE, SHORTCUTS_ROUTE } from './shortcuts-route.js';
|
|
44
|
+
import { createShortcutStore } from './startpage-shortcuts.js';
|
|
45
|
+
import { createReferenceService, setReferenceCaptureActionHandler } from '../browser-reference/service.js';
|
|
46
|
+
import { WEB_SOURCE_ROUTE } from '../reference-source.js';
|
|
47
|
+
import { createDeliveryQueue, resolveReferenceOwner } from '../browser-reference/delivery.js';
|
|
48
|
+
import { createSubmissionReceipts } from '../browser-reference/submission-receipts.js';
|
|
49
|
+
import { createReferenceRouteHandlers, REFERENCE_CAPTURE_ROUTE, REFERENCE_EXPORT_ROUTE, REFERENCE_GET_ROUTE, REFERENCE_IMPORT_ROUTE, REFERENCE_INSERT_ROUTE, REFERENCE_LIST_ROUTE, REFERENCE_REVEAL_ROUTE, REFERENCE_DELIVERIES_ROUTE, REFERENCE_DELIVERY_ACK_ROUTE, REFERENCE_DELIVERY_REMOVE_ROUTE, REFERENCE_ASSET_ROUTE, CLIENT_VERSION_ROUTE, REFERENCE_STATUS_ROUTE, } from './reference-route.js';
|
|
50
|
+
function isPreferredCarrier(host) {
|
|
51
|
+
return host instanceof ExtensionBrowserViewHost || host instanceof PreferredBrowserViewHost;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The reference bar as a <script> element, for documents served through the Web guest proxy.
|
|
55
|
+
*
|
|
56
|
+
* The desktop shell evaluates the same source with `executeJavaScript`; a proxied document has no such
|
|
57
|
+
* handle, so it is injected inline. A literal `</script` inside the source would close the element, so
|
|
58
|
+
* it is escaped on the way in.
|
|
59
|
+
* @returns the inline script element.
|
|
60
|
+
*/
|
|
61
|
+
function overlayTag() {
|
|
62
|
+
const source = overlayScript().replace(/<\/script/giu, '<\\/script');
|
|
63
|
+
return `<script data-dsh-ref-overlay-src="guest">(function(){\n${source}\n})()</script>`;
|
|
64
|
+
}
|
|
65
|
+
/** Where the Web sidebar asks "what was just opened?". */
|
|
66
|
+
/**
|
|
67
|
+
* The surface this host would use for an open, echoed to the client.
|
|
68
|
+
*
|
|
69
|
+
* The client must not place a tab when the host is in "builtin" mode, or when it is an older build that
|
|
70
|
+
* always opens its own browser: that combination is the double-open.
|
|
71
|
+
* @returns "panel" or "builtin".
|
|
72
|
+
*/
|
|
73
|
+
function readSurfaceForRoute() {
|
|
74
|
+
try {
|
|
75
|
+
// `process.getBuiltinModule` avoids adding imports to this file, whose header order is load-bearing
|
|
76
|
+
// for the plugin's own module graph.
|
|
77
|
+
const fs = process.getBuiltinModule?.('fs');
|
|
78
|
+
if (fs === undefined)
|
|
79
|
+
return 'panel';
|
|
80
|
+
const parsed = JSON.parse(fs.readFileSync(settingsPath(), 'utf8'));
|
|
81
|
+
return parsed.browser?.surface === 'builtin' ? 'builtin' : 'panel';
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return 'panel';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export const OPEN_REQUEST_ROUTE = '/dsh-builtin-browser/browser/open-request';
|
|
88
|
+
/** open 记录的有效期:超过就不再重放。这是一次即时事件,客户端 2 秒轮询一次,10 秒足够送达;
|
|
89
|
+
* 留得越久,「关掉侧栏后刷新又被拉起来」的窗口越大(实测复现过)。 */
|
|
90
|
+
const OPEN_REQUEST_TTL_MS = 10_000;
|
|
91
|
+
/** The client declares which surface it can host, so the host needs no file sniffing. */
|
|
92
|
+
export const SURFACE_DECL_ROUTE = '/dsh-builtin-browser/browser/declare-surface';
|
|
42
93
|
export { ELECTRON_BROWSER_PROVIDER_ID, ElectronBrowserProvider, } from './provider.js';
|
|
43
|
-
export { RemoteElectronViewHost, defaultHostMainPath } from './remote-host.js';
|
|
44
94
|
/** Cordis plugin name used by loader diagnostics. */
|
|
95
|
+
function carrierSettingsKey(settings) {
|
|
96
|
+
return JSON.stringify([settings.browser.channel, settings.browser.systemProfile, settings.browser.headless,
|
|
97
|
+
settings.browser.systemProfile === 'plugin' ? settings.cookies.persist : undefined]);
|
|
98
|
+
}
|
|
45
99
|
export const name = 'browser-electron';
|
|
46
100
|
/** The browser seam this provider registers into. */
|
|
47
101
|
export const inject = ['browser'];
|
|
@@ -102,110 +156,158 @@ export function apply(ctx, config) {
|
|
|
102
156
|
// discarded value (a mistyped channel, most of all) is reported instead of being silently
|
|
103
157
|
// replaced by the default — "my setting did nothing" and "I misspelled it" must not look alike.
|
|
104
158
|
const settings = new SettingsStore(undefined, message => ctx.logger?.warn?.(message));
|
|
159
|
+
/**
|
|
160
|
+
* The provider currently serving `ctx.browser`, kept for diagnostics only.
|
|
161
|
+
*
|
|
162
|
+
* `referenceStatus` answers "why is there no selection bar on this page" with the
|
|
163
|
+
* conversation id this process believes it serves and what its last sidebar scan
|
|
164
|
+
* saw. A stale entry after a carrier swap is harmless: the status route only reads.
|
|
165
|
+
*/
|
|
166
|
+
let referenceProvider;
|
|
167
|
+
const trackProvider = (provider) => {
|
|
168
|
+
// A carrier swap builds a NEW provider; the previous one's pump would keep
|
|
169
|
+
// ticking against a view host that no longer serves anything, and its user
|
|
170
|
+
// action listeners would duplicate every capture. Retire it completely.
|
|
171
|
+
if (referenceProvider !== undefined && referenceProvider !== provider)
|
|
172
|
+
referenceProvider.dispose();
|
|
173
|
+
referenceProvider = provider;
|
|
174
|
+
return provider;
|
|
175
|
+
};
|
|
105
176
|
const providerConfig = {
|
|
177
|
+
// The conversation this process serves: the sidebar reference entry finds its
|
|
178
|
+
// page through this id (see `adoptSidebarPageForReference`).
|
|
179
|
+
referenceLabel: () => readSessionId(ctx),
|
|
106
180
|
httpOnly: config.httpOnly,
|
|
107
181
|
downloadDir: config.downloadDir,
|
|
108
182
|
snapshotMaxElements: config.snapshotMaxElements,
|
|
109
183
|
contentMaxChars: config.contentMaxChars,
|
|
110
184
|
settings: () => settings.get(),
|
|
111
185
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
186
|
+
let panelOpening;
|
|
187
|
+
let panelsDisposed = false;
|
|
188
|
+
const retirePanel = (panel, lost = false) => {
|
|
189
|
+
panel.provider.dispose();
|
|
190
|
+
void Promise.allSettled(panel.provider.watchableSessions().map(id => panel.provider.close(id)))
|
|
191
|
+
.finally(() => {
|
|
192
|
+
if (lost)
|
|
193
|
+
setImmediate(() => { panel.host.dispose(); });
|
|
194
|
+
else
|
|
195
|
+
panel.host.dispose();
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
const unregisterPanel = ctx.browser.registerPanelProvider(async () => {
|
|
199
|
+
const selected = settings.get().browser;
|
|
200
|
+
if ((selected.channel === 'edge' || selected.channel === 'chrome') && selected.systemProfile === 'user') {
|
|
201
|
+
if (!isPreferredCarrier(adoptedCarrier) || !referenceProvider)
|
|
202
|
+
throw new Error('Selected personal-browser carrier is unavailable; no sidebar fallback.');
|
|
203
|
+
return referenceProvider;
|
|
204
|
+
}
|
|
205
|
+
if (panelOpening === undefined) {
|
|
206
|
+
const opening = (async () => {
|
|
207
|
+
const host = await DesktopBridgeViewHost.discover(sessionId, () => settings.get().ui.quiet);
|
|
208
|
+
if (host === undefined)
|
|
209
|
+
return undefined;
|
|
210
|
+
if (panelsDisposed) {
|
|
211
|
+
host.dispose();
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
const provider = new ElectronBrowserProvider(host, providerConfig);
|
|
215
|
+
const panel = { host, provider };
|
|
216
|
+
host.onLost(() => {
|
|
217
|
+
if (panelOpening === opening)
|
|
218
|
+
panelOpening = undefined;
|
|
219
|
+
retirePanel(panel, true);
|
|
220
|
+
});
|
|
221
|
+
return panel;
|
|
222
|
+
})();
|
|
223
|
+
panelOpening = opening;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const panel = await panelOpening;
|
|
227
|
+
if (panel === undefined)
|
|
228
|
+
panelOpening = undefined;
|
|
229
|
+
return panel?.provider;
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
panelOpening = undefined;
|
|
233
|
+
throw error;
|
|
125
234
|
}
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
// Explicit sidebar selection stays on the desktop's carrier, including while its bridge
|
|
129
|
-
// reconnects. Other choices can use the independently hosted browser when appropriate.
|
|
130
|
-
const selfHosted = new RemoteElectronViewHost(defaultHostMainPath());
|
|
131
|
-
// The self-hosted carrier is the only one that needs Electron, and it is prepared HERE, lazily,
|
|
132
|
-
// rather than during package installation (issue #41: a `postinstall` download made a default
|
|
133
|
-
// pnpm 11 profile refuse the install outright, and a failed fetch failed the install too).
|
|
134
|
-
//
|
|
135
|
-
// Non-fatal by construction: this never rejects, never blocks a tool call, and its failure leaves
|
|
136
|
-
// the sidebar / Chrome / Edge carriers untouched. Only the two channels that can use the bundled
|
|
137
|
-
// runtime are worth the download; an explicit chrome/edge choice is not.
|
|
138
|
-
const wantedChannel = settings.get().browser.channel;
|
|
139
|
-
if (wantedChannel === 'bundled' || wantedChannel === 'auto') {
|
|
140
|
-
void provisionElectronInBackground(message => ctx.logger?.info?.(`dsh-builtin-browser: ${message}`));
|
|
141
|
-
}
|
|
142
|
-
const requiredSidebar = () => new SidebarOnlyHost(async () => {
|
|
143
|
-
for (const pause of [0, 1_000, 3_000, 8_000]) {
|
|
144
|
-
if (pause > 0)
|
|
145
|
-
await wait(pause);
|
|
146
|
-
const sidebar = await DesktopBridgeViewHost.discover(sessionId, () => settings.get().ui.quiet);
|
|
147
|
-
if (sidebar !== undefined)
|
|
148
|
-
return sidebar;
|
|
149
|
-
if (DesktopBridgeViewHost.refusedIframePanel())
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
throw new Error('dsh-builtin-browser: the selected DSH sidebar is not connected. Check or repair the desktop bridge in Browser settings, then retry the same operation.');
|
|
153
235
|
});
|
|
154
|
-
|
|
155
|
-
|
|
236
|
+
ctx.effect(() => () => {
|
|
237
|
+
panelsDisposed = true;
|
|
238
|
+
unregisterPanel();
|
|
239
|
+
void panelOpening?.then(panel => {
|
|
240
|
+
if (panel === undefined)
|
|
241
|
+
return;
|
|
242
|
+
retirePanel(panel);
|
|
243
|
+
}).catch(() => { });
|
|
244
|
+
});
|
|
245
|
+
const reportCarrierLoss = (reason) => {
|
|
246
|
+
const detail = reason === 'shell-exited'
|
|
247
|
+
? 'the desktop shell backed the sidebar browser and has exited'
|
|
248
|
+
: 'the desktop shell is running, but its sidebar browser panel cannot be driven';
|
|
249
|
+
ctx.logger?.warn?.(`dsh-builtin-browser: ${detail} (${reason}); the next operation requires the DSH sidebar. No standalone fallback will be opened.`);
|
|
250
|
+
};
|
|
251
|
+
const requiredSidebar = () => {
|
|
252
|
+
const host = new SidebarOnlyHost(async (signal) => {
|
|
253
|
+
for (const pause of [0, 1_000, 3_000, 8_000]) {
|
|
254
|
+
signal.throwIfAborted();
|
|
255
|
+
if (pause > 0)
|
|
256
|
+
await wait(pause, undefined, { signal });
|
|
257
|
+
const sidebar = await DesktopBridgeViewHost.discover(sessionId, () => settings.get().ui.quiet);
|
|
258
|
+
if (sidebar !== undefined)
|
|
259
|
+
return sidebar;
|
|
260
|
+
if (DesktopBridgeViewHost.refusedIframePanel())
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
const detail = DesktopBridgeViewHost.refusedIframePanel()
|
|
264
|
+
? 'the DSH sidebar is an iframe and cannot support CDP tools'
|
|
265
|
+
: 'no controllable DSH sidebar is available';
|
|
266
|
+
throw Object.assign(new Error(`dsh-builtin-browser: ${detail}. Use a host-provided sidebar/webview carrier or install the DSH native-view host patch, then retry. The Web panel supports manual browsing, not CDP tools. No standalone browser will be opened.`), { code: 'BROWSER_NATIVE_SURFACE_UNAVAILABLE' });
|
|
267
|
+
});
|
|
268
|
+
host.onLost(reportCarrierLoss);
|
|
269
|
+
return host;
|
|
270
|
+
};
|
|
271
|
+
const initialHost = requiredSidebar();
|
|
272
|
+
let unregister = ctx.browser.registerBrowserProvider(trackProvider(new ElectronBrowserProvider(initialHost, providerConfig)));
|
|
156
273
|
let disposed = false;
|
|
157
274
|
let carrierChoice = 0;
|
|
158
|
-
let discovery;
|
|
159
275
|
/** The carrier an `adopt` installed, so a later choice can release it. */
|
|
160
|
-
let adoptedCarrier = initialHost
|
|
276
|
+
let adoptedCarrier = initialHost;
|
|
277
|
+
let unregisterTakeover = () => { };
|
|
161
278
|
ctx.effect(() => () => {
|
|
162
279
|
disposed = true;
|
|
280
|
+
unregisterTakeover();
|
|
163
281
|
carrierChoice += 1;
|
|
164
|
-
discovery?.abort();
|
|
165
282
|
unregister();
|
|
166
|
-
|
|
167
|
-
|
|
283
|
+
// The reference pump is a real interval, not a one-shot: `unref` alone lets
|
|
284
|
+
// the process exit but leaves the tick running inside a live plugin, so it
|
|
285
|
+
// must stop with the provider it belongs to. Retiring also silences its
|
|
286
|
+
// user-action listeners, which the view host never unsubscribes.
|
|
287
|
+
referenceProvider?.dispose();
|
|
288
|
+
if (adoptedCarrier !== config.viewHost)
|
|
289
|
+
adoptedCarrier?.dispose?.();
|
|
168
290
|
});
|
|
169
291
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* This is the half the startup retries never covered: a bridge that was alive at apply time and
|
|
173
|
-
* exited later left every subsequent call dialling a port nobody owns, because the swap happened
|
|
174
|
-
* once and only in one direction. Reaching here means the carrier cannot serve anything more, so
|
|
175
|
-
* the choice made at startup is no longer a choice — the alternative to falling back is a browser
|
|
176
|
-
* surface that does nothing until DSH is restarted.
|
|
177
|
-
*
|
|
178
|
-
* Two failures arrive here and the message must distinguish them. The first draft announced an
|
|
179
|
-
* exiting shell unconditionally, so a fallback caused by an undrivable sidebar panel told the
|
|
180
|
-
* user their desktop shell had exited while it was running normally.
|
|
292
|
+
* Require the sidebar after a borrowed carrier is lost; never launch a fallback window.
|
|
181
293
|
* @param adopted - the carrier that reported the loss, disposed once its replacement is in place.
|
|
182
294
|
* @param reason - which failure this was; see {@link CarrierLossReason}.
|
|
183
295
|
*/
|
|
184
|
-
const
|
|
296
|
+
const restoreSidebar = (adopted, reason) => {
|
|
185
297
|
// A replaced carrier may finish an outstanding request after the new choice is installed.
|
|
186
298
|
if (disposed || adoptedCarrier !== adopted)
|
|
187
299
|
return;
|
|
188
300
|
try {
|
|
189
|
-
const
|
|
190
|
-
const restored = sidebarSelected ? requiredSidebar() : new RemoteElectronViewHost(defaultHostMainPath());
|
|
301
|
+
const restored = requiredSidebar();
|
|
191
302
|
unregister();
|
|
192
|
-
unregister = ctx.browser.registerBrowserProvider(new ElectronBrowserProvider(restored, providerConfig));
|
|
303
|
+
unregister = ctx.browser.registerBrowserProvider(trackProvider(new ElectronBrowserProvider(restored, providerConfig)));
|
|
193
304
|
adoptedCarrier = restored;
|
|
194
|
-
|
|
195
|
-
? 'dsh-builtin-browser: the selected DSH sidebar connection was lost; the next operation will reconnect to the sidebar.'
|
|
196
|
-
: reason === 'shell-exited'
|
|
197
|
-
? 'dsh-builtin-browser: the desktop shell backed the sidebar browser and has exited, so the '
|
|
198
|
-
+ 'browser this plugin hosts itself takes over. Pages from the sidebar are gone with it; '
|
|
199
|
-
+ 'open the page again.'
|
|
200
|
-
: 'dsh-builtin-browser: this desktop shell renders the sidebar browser panel in a way that '
|
|
201
|
-
+ 'cannot be driven (no webContents, so no CDP endpoint), so the browser this plugin hosts '
|
|
202
|
-
+ 'itself takes over. The shell is still running and nothing else is affected; the page '
|
|
203
|
-
+ 'opens in this plugin\'s own window. Set browser.channel to another value to silence this.');
|
|
305
|
+
reportCarrierLoss(reason);
|
|
204
306
|
}
|
|
205
307
|
catch (error) {
|
|
206
308
|
// Nothing better is available: the adopted carrier is gone and a provider that throws is
|
|
207
309
|
// worse than one that explains.
|
|
208
|
-
ctx.logger?.warn?.(`dsh-builtin-browser: could not
|
|
310
|
+
ctx.logger?.warn?.(`dsh-builtin-browser: could not restore the sidebar carrier: ${String(error)}`);
|
|
209
311
|
}
|
|
210
312
|
finally {
|
|
211
313
|
// Disposed on a LATER turn of the event loop, deliberately.
|
|
@@ -245,17 +347,24 @@ export function apply(ctx, config) {
|
|
|
245
347
|
const previous = adoptedCarrier;
|
|
246
348
|
try {
|
|
247
349
|
unregister();
|
|
248
|
-
unregister = ctx.browser.registerBrowserProvider(new ElectronBrowserProvider(host, providerConfig));
|
|
249
|
-
selfHosted.dispose();
|
|
350
|
+
unregister = ctx.browser.registerBrowserProvider(trackProvider(new ElectronBrowserProvider(host, providerConfig)));
|
|
250
351
|
adoptedCarrier = host;
|
|
352
|
+
unregisterTakeover();
|
|
353
|
+
if (isPreferredCarrier(host)) {
|
|
354
|
+
const provider = referenceProvider;
|
|
355
|
+
unregisterTakeover = registerCarrierTakeover(ctx.browser, owner => provider.takeoverTargets(owner).map(target => ({
|
|
356
|
+
...target, connected: () => adoptedCarrier === host && host.connectedView(target.tabId),
|
|
357
|
+
})));
|
|
358
|
+
void host.refreshStatus();
|
|
359
|
+
}
|
|
251
360
|
ctx.logger?.info?.(`dsh-builtin-browser: ${note}`);
|
|
252
361
|
// A borrowed carrier can lose the process behind it, and this is the only notification that
|
|
253
362
|
// will ever arrive. Registering AFTER the swap succeeded means a listener can never fire
|
|
254
363
|
// against a provider that was never installed.
|
|
255
364
|
if (!(host instanceof SidebarOnlyHost))
|
|
256
|
-
host.onLost?.(reason => {
|
|
365
|
+
host.onLost?.(reason => { restoreSidebar(host, reason); });
|
|
257
366
|
// Released AFTER the replacement is installed, so the surface is never without a provider.
|
|
258
|
-
if (previous !== undefined && previous !== host) {
|
|
367
|
+
if (previous !== undefined && previous !== host && previous !== config.viewHost) {
|
|
259
368
|
try {
|
|
260
369
|
previous.dispose?.();
|
|
261
370
|
}
|
|
@@ -271,6 +380,10 @@ export function apply(ctx, config) {
|
|
|
271
380
|
host.dispose?.();
|
|
272
381
|
}
|
|
273
382
|
catch { /* the fallback below matters more than this */ }
|
|
383
|
+
if (isPreferredCarrier(host)) {
|
|
384
|
+
ctx.logger?.warn?.(`dsh-builtin-browser: could not adopt the selected personal-browser extension (${String(error)}); no profile fallback`);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
274
387
|
// The fallback registration gets its own guard, because THIS is the path taken when the
|
|
275
388
|
// context is already gone — and then `ctx.browser` throws `cannot get required service
|
|
276
389
|
// "browser" in inactive context`. Unguarded, that second throw escaped the async retry
|
|
@@ -278,8 +391,8 @@ export function apply(ctx, config) {
|
|
|
278
391
|
// exit code 1: a failed upgrade, which should only ever cost a warning, took the whole
|
|
279
392
|
// session down instead. Observed 2026-10-05 (crash-…-host.log, phase: running).
|
|
280
393
|
try {
|
|
281
|
-
const fallback =
|
|
282
|
-
unregister = ctx.browser.registerBrowserProvider(new ElectronBrowserProvider(fallback, providerConfig));
|
|
394
|
+
const fallback = requiredSidebar();
|
|
395
|
+
unregister = ctx.browser.registerBrowserProvider(trackProvider(new ElectronBrowserProvider(fallback, providerConfig)));
|
|
283
396
|
adoptedCarrier = fallback;
|
|
284
397
|
if (previous !== undefined && previous !== host) {
|
|
285
398
|
try {
|
|
@@ -305,14 +418,12 @@ export function apply(ctx, config) {
|
|
|
305
418
|
* nothing. Re-entrant by design — changing the channel means replacing the carrier, which is
|
|
306
419
|
* exactly what a second call does.
|
|
307
420
|
*/
|
|
421
|
+
let chosenSettingsKey = '';
|
|
308
422
|
const chooseCarrier = () => {
|
|
309
423
|
if (disposed)
|
|
310
424
|
return;
|
|
425
|
+
chosenSettingsKey = carrierSettingsKey(settings.get());
|
|
311
426
|
const choice = ++carrierChoice;
|
|
312
|
-
discovery?.abort();
|
|
313
|
-
const controller = new AbortController();
|
|
314
|
-
discovery = controller;
|
|
315
|
-
const { signal } = controller;
|
|
316
427
|
// A browser the user explicitly asked for outranks every automatic choice: the
|
|
317
428
|
// whole point of the setting is that they know which browser they want. It is
|
|
318
429
|
// launched with a plugin-owned profile, so their own windows are untouched.
|
|
@@ -327,124 +438,55 @@ export function apply(ctx, config) {
|
|
|
327
438
|
// that choice real — otherwise a user who picked Chrome would silently get the sidebar,
|
|
328
439
|
// and a user who picked a browser that is not installed would never see the explanation
|
|
329
440
|
// written for exactly that case, because the sidebar would quietly replace it.
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
441
|
+
if (channel !== 'chrome' && channel !== 'edge') {
|
|
442
|
+
if (config.viewHost !== undefined) {
|
|
443
|
+
if (adoptedCarrier !== config.viewHost)
|
|
444
|
+
adopt(config.viewHost, 'using the composition-provided sidebar carrier', choice);
|
|
445
|
+
}
|
|
446
|
+
else if (!(adoptedCarrier instanceof SidebarOnlyHost))
|
|
333
447
|
adopt(requiredSidebar(), 'using only the selected DSH sidebar', choice);
|
|
334
448
|
return;
|
|
335
449
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
// asked for. Naming a browser is a specific request, and quietly satisfying it
|
|
341
|
-
// with a different one turns the real problem ("no Chrome here") into a
|
|
342
|
-
// confusing error about Electron later on. Report it instead.
|
|
343
|
-
if (channel === 'auto') {
|
|
344
|
-
ctx.logger?.warn?.('dsh-builtin-browser: no installed browser was found; using the bundled browser');
|
|
345
|
-
if (adoptedCarrier !== undefined) {
|
|
346
|
-
adopt(new RemoteElectronViewHost(defaultHostMainPath()), 'using the bundled browser', choice);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
else {
|
|
350
|
-
adopt(new MissingSystemBrowserHost(channel, searchSummary(channel)), `the selected ${channel} is not installed — commands will explain how to fix it`);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
// Same profile root as settings-store, history-store and desktop-bridge-host: the
|
|
355
|
-
// `?.dsh` component used to be missing HERE only, so a desktop launched from a
|
|
356
|
-
// shortcut (no DSH_HOME in the environment) put its browser profile in
|
|
357
|
-
// `C:\Users\<user>\dsh-builtin-browser-host\` while its settings and history lived in
|
|
358
|
-
// `~/.dsh/dsh-builtin-browser-host/` — two half-profiles that never met, and a
|
|
359
|
-
// settings panel whose switches appeared not to apply.
|
|
360
|
-
const home = dshHome();
|
|
361
|
-
// Login state lives in the browser profile, so the cookies setting decides where
|
|
362
|
-
// that profile goes: a stable directory keeps the user signed in across restarts
|
|
363
|
-
// (the point of using their own browser), while turning persistence off gets a
|
|
364
|
-
// throwaway directory that is removed when the browser is released.
|
|
365
|
-
const persist = settings.get().cookies.persist;
|
|
366
|
-
const profileRoot = join(home, BROWSER_PROFILE_DIR);
|
|
367
|
-
adoptLegacyProfileRoot(profileRoot);
|
|
368
|
-
const profileDir = persist
|
|
369
|
-
? join(profileRoot, `${detected.kind}-profile`)
|
|
370
|
-
: join(profileRoot, ephemeralProfileName(detected.kind, randomUUID()));
|
|
371
|
-
if (!persist) {
|
|
372
|
-
// A process killed outright never runs its own cleanup (see ephemeral-profile.ts),
|
|
373
|
-
// so the sweep happens HERE — at the only moment that can still act on a profile
|
|
374
|
-
// whose owner is gone — and before this run claims a directory of its own.
|
|
375
|
-
sweepAbandonedEphemeralProfiles(profileRoot, detected.kind);
|
|
376
|
-
claimEphemeralProfile(profileDir);
|
|
377
|
-
}
|
|
378
|
-
// The headless mode rides along so a display-less host (systemd, container, SSH-only server)
|
|
379
|
-
// still gets a working browser instead of "exited immediately after launch" — issue #32.
|
|
380
|
-
adopt(new SystemBrowserViewHost(detected, profileDir, [], persist ? undefined : profileDir, undefined, settings.get().browser.headless, () => settings.get().ui.quiet), `will drive the installed ${detected.kind} (${detected.path}${persist ? '' : ', ephemeral profile'})`);
|
|
381
|
-
}
|
|
450
|
+
const detected = detectBrowser(channel);
|
|
451
|
+
if (detected === undefined) {
|
|
452
|
+
const missing = new MissingSystemBrowserHost(channel, searchSummary(channel));
|
|
453
|
+
adopt(settings.get().browser.systemProfile === 'user' ? new PreferredBrowserViewHost(channel, missing) : missing, `the selected ${channel} is not installed — commands will explain how to fix it`);
|
|
382
454
|
}
|
|
383
|
-
else
|
|
384
|
-
//
|
|
385
|
-
//
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
catch {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
if (signal.aborted || disposed)
|
|
412
|
-
return;
|
|
413
|
-
let sidebar;
|
|
414
|
-
try {
|
|
415
|
-
sidebar = await DesktopBridgeViewHost.discover(sessionId, () => settings.get().ui.quiet);
|
|
416
|
-
}
|
|
417
|
-
catch {
|
|
418
|
-
sidebar = undefined; // discovery is documented not to throw; never let it stop the retries
|
|
419
|
-
}
|
|
420
|
-
if (signal.aborted || disposed) {
|
|
421
|
-
try {
|
|
422
|
-
sidebar?.dispose?.();
|
|
423
|
-
}
|
|
424
|
-
catch { /* the choice no longer owns this result */ }
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
if (sidebar === undefined)
|
|
428
|
-
continue;
|
|
429
|
-
adopt(sidebar, 'driving the desktop sidebar browser', choice);
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
// A bridge exists but its sidebar panel is an iframe. Saying nothing here would leave the user
|
|
433
|
-
// with a second browser window on a machine where they just followed the instructions to
|
|
434
|
-
// install the bridge, and no way to know the two facts are related. The carrier is not
|
|
435
|
-
// unavailable by accident: an iframe has no CDP endpoint, so adopting it would fail every call
|
|
436
|
-
// instead of falling back — see DesktopBridgeViewHost.discover.
|
|
437
|
-
if (DesktopBridgeViewHost.refusedIframePanel()) {
|
|
438
|
-
ctx.logger?.warn?.('dsh-builtin-browser: a desktop bridge is installed, but this shell renders the sidebar '
|
|
439
|
-
+ 'browser panel as an iframe rather than a webview, which exposes no CDP endpoint and '
|
|
440
|
-
+ 'cannot be driven. Using the browser this plugin hosts itself instead — that is the '
|
|
441
|
-
+ 'independent window, not the sidebar. A shell that exposes `dshDesktop.browser` and '
|
|
442
|
-
+ 'enables `webviewTag` would provide a drivable panel.');
|
|
443
|
-
return;
|
|
455
|
+
else {
|
|
456
|
+
// Same profile root as settings-store, history-store and desktop-bridge-host: the
|
|
457
|
+
// `?.dsh` component used to be missing HERE only, so a desktop launched from a
|
|
458
|
+
// shortcut (no DSH_HOME in the environment) put its browser profile in
|
|
459
|
+
// `C:\Users\<user>\dsh-builtin-browser-host\` while its settings and history lived in
|
|
460
|
+
// `~/.dsh/dsh-builtin-browser-host/` — two half-profiles that never met, and a
|
|
461
|
+
// settings panel whose switches appeared not to apply.
|
|
462
|
+
const home = dshHome();
|
|
463
|
+
// Login state lives in the browser profile, so the cookies setting decides where
|
|
464
|
+
// that profile goes: a stable directory keeps the user signed in across restarts
|
|
465
|
+
// (the point of using their own browser), while turning persistence off gets a
|
|
466
|
+
// throwaway directory that is removed when the browser is released.
|
|
467
|
+
const persist = settings.get().cookies.persist;
|
|
468
|
+
const profileRoot = join(home, BROWSER_PROFILE_DIR);
|
|
469
|
+
adoptLegacyProfileRoot(profileRoot);
|
|
470
|
+
const profileDir = persist
|
|
471
|
+
? join(profileRoot, `${detected.kind}-profile`)
|
|
472
|
+
: join(profileRoot, ephemeralProfileName(detected.kind, randomUUID()));
|
|
473
|
+
if (!persist) {
|
|
474
|
+
// A process killed outright never runs its own cleanup (see ephemeral-profile.ts),
|
|
475
|
+
// so the sweep happens HERE — at the only moment that can still act on a profile
|
|
476
|
+
// whose owner is gone — and before this run claims a directory of its own.
|
|
477
|
+
sweepAbandonedEphemeralProfiles(profileRoot, detected.kind);
|
|
478
|
+
claimEphemeralProfile(profileDir);
|
|
444
479
|
}
|
|
445
|
-
|
|
480
|
+
// The headless mode rides along so a display-less host (systemd, container, SSH-only server)
|
|
481
|
+
// still gets a working browser instead of "exited immediately after launch" — issue #32.
|
|
482
|
+
;
|
|
483
|
+
globalThis.__dshBrowserCarrier = 'launched-plugin-profile';
|
|
484
|
+
const managed = new SystemBrowserViewHost(detected, profileDir, [], !persist ? profileDir : undefined, undefined, settings.get().browser.headless, () => settings.get().ui.quiet, undefined, { managed: true });
|
|
485
|
+
adopt(settings.get().browser.systemProfile === 'user' ? new PreferredBrowserViewHost(channel, managed) : managed, `will drive the installed ${detected.kind} (${detected.path}${persist ? '' : ', ephemeral profile'})`);
|
|
486
|
+
}
|
|
446
487
|
};
|
|
447
488
|
chooseCarrier();
|
|
489
|
+
void nativeRegistration.ensure().catch(() => { });
|
|
448
490
|
// Wired AFTER the chooser exists, because the handler re-runs it: a settings write that changes
|
|
449
491
|
// `browser.channel` is a request to switch carriers, and answering `ok` without switching is the
|
|
450
492
|
// one thing a caller cannot tell apart from a write that worked.
|
|
@@ -470,13 +512,51 @@ export function apply(ctx, config) {
|
|
|
470
512
|
host.effect(() => host.webServer.register({
|
|
471
513
|
kind: 'exact',
|
|
472
514
|
path: PREVIEW_ROUTE,
|
|
473
|
-
handler:
|
|
515
|
+
handler: paired(ctx, (request, response) => handlePreviewFrame(request, response, settings, browser)),
|
|
474
516
|
}, 'dsh-builtin-browser: live view frame'));
|
|
517
|
+
// The Web sidebar's iframe has no handle into a cross-origin guest, so the guest is served
|
|
518
|
+
// through this prefix instead: same origin, readable, injectable. See guest-route.ts.
|
|
519
|
+
// The client is the authority on which surface exists in THIS shell: it either has a sidebar or not.
|
|
520
|
+
// Reading settings.json from the host was unreliable (a module instance can hold a stale home), and it
|
|
521
|
+
// needed a restart to take effect. A declaration rides recomposition instead.
|
|
522
|
+
host.effect(() => host.webServer.register({
|
|
523
|
+
kind: 'exact',
|
|
524
|
+
path: SURFACE_DECL_ROUTE,
|
|
525
|
+
handler: authenticated(ctx, (request, response) => {
|
|
526
|
+
readJsonBody(request).then((body) => {
|
|
527
|
+
const surface = body !== null && typeof body === 'object' && body.surface;
|
|
528
|
+
if (surface === 'panel' || surface === 'builtin') {
|
|
529
|
+
globalThis.__dshBrowserSurface = surface;
|
|
530
|
+
}
|
|
531
|
+
replyJson(response, 200, { ok: true });
|
|
532
|
+
}).catch(() => { replyJson(response, 200, { ok: false }); });
|
|
533
|
+
}),
|
|
534
|
+
}, 'dsh-builtin-browser: surface declaration'));
|
|
535
|
+
// One slot the Web sidebar polls: it cannot be told through a bridge, so it asks.
|
|
536
|
+
host.effect(() => host.webServer.register({
|
|
537
|
+
kind: 'exact',
|
|
538
|
+
path: OPEN_REQUEST_ROUTE,
|
|
539
|
+
handler: authenticated(ctx, (request, response) => {
|
|
540
|
+
// 这条记录**不能被第一个轮询到的客户端消费掉**:同一进程里可能有多个 DSH 窗口/标签页
|
|
541
|
+
// (人手一个、自动化又一个),先问的那个把记录清空后,另一个窗口就再也看不到这次 open,
|
|
542
|
+
// 表现成「工具说打开了、我这边没打开」。所以这里不清空,只按时间过期:
|
|
543
|
+
// 每个客户端各自用 sessionStorage 记住「这条处理过了」,既不重放,也不互相抢。
|
|
544
|
+
if ((request.method ?? 'GET').toUpperCase() === 'POST') {
|
|
545
|
+
request.resume();
|
|
546
|
+
request.on('end', () => { replyJson(response, 200, { ok: true, cleared: false }); });
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
const last = getLastOpen();
|
|
550
|
+
const fresh = last !== undefined && Date.now() - last.at <= OPEN_REQUEST_TTL_MS ? last : undefined;
|
|
551
|
+
replyJson(response, 200, { ok: true, surface: readSurfaceForRoute(), open: isPreferredCarrier(adoptedCarrier) ? null : fresh ?? null });
|
|
552
|
+
}),
|
|
553
|
+
}, 'dsh-builtin-browser: open request slot'));
|
|
554
|
+
// guest 代理由根行注册(见 src/web-guest.ts):web 上 Electron 行可能被关闭。
|
|
475
555
|
// The list the panel needs before it can build a frame URL at all: session ids only.
|
|
476
556
|
host.effect(() => host.webServer.register({
|
|
477
557
|
kind: 'exact',
|
|
478
558
|
path: PREVIEW_SESSIONS_ROUTE,
|
|
479
|
-
handler:
|
|
559
|
+
handler: paired(ctx, (request, response) => handlePreviewSessions(request, response, settings, browser)),
|
|
480
560
|
}, 'dsh-builtin-browser: live view sessions'));
|
|
481
561
|
});
|
|
482
562
|
}
|
|
@@ -574,8 +654,18 @@ export function apply(ctx, config) {
|
|
|
574
654
|
return;
|
|
575
655
|
try {
|
|
576
656
|
injectStatus(['webServer'], (host) => {
|
|
657
|
+
const hostPatchMaintenance = createHostPatchMaintenance({
|
|
658
|
+
modules: () => servedClientModules(ctx.get('clientModules')),
|
|
659
|
+
desktop: () => process.versions.electron !== undefined,
|
|
660
|
+
});
|
|
661
|
+
host.effect(() => host.webServer.register({
|
|
662
|
+
kind: 'exact', path: HOST_PATCH_ROUTE,
|
|
663
|
+
handler: authenticated(ctx, hostPatchMaintenance),
|
|
664
|
+
}, 'dsh-builtin-browser: Web host patch maintenance'));
|
|
577
665
|
const automaticMaintenance = createAutomaticMaintenanceHandler({
|
|
578
|
-
supported: () =>
|
|
666
|
+
supported: () => automaticMaintenanceSupported(),
|
|
667
|
+
// Windows quits through the Desktop's own menu, opened by the panel; macOS through its Quit Apple event.
|
|
668
|
+
quit: () => process.platform === 'win32' ? 'menu' : 'self',
|
|
579
669
|
busy: () => bridgeActionRunning,
|
|
580
670
|
read: () => readAutomaticMaintenance(),
|
|
581
671
|
commit: async (id) => { await commitAutomaticMaintenance(id); },
|
|
@@ -583,7 +673,7 @@ export function apply(ctx, config) {
|
|
|
583
673
|
const root = findDesktopInstall();
|
|
584
674
|
if (root === undefined)
|
|
585
675
|
throw new Error('no verified DSH Desktop installation was found');
|
|
586
|
-
return await runWithManualBridgePreference(
|
|
676
|
+
return await runWithManualBridgePreference('install', patch => settings.update(patch), async () => await startAutomaticMaintenance(action, root, options));
|
|
587
677
|
},
|
|
588
678
|
});
|
|
589
679
|
host.effect(() => host.webServer.register({
|
|
@@ -593,7 +683,7 @@ export function apply(ctx, config) {
|
|
|
593
683
|
host.effect(() => host.webServer.register({
|
|
594
684
|
kind: 'exact',
|
|
595
685
|
path: BRIDGE_STATUS_ROUTE,
|
|
596
|
-
handler: authenticated(ctx, (request, response) => handleBridgeStatus(request, response)),
|
|
686
|
+
handler: authenticated(ctx, async (request, response) => handleBridgeStatus(request, response, undefined, await readHostExtensionStatus(dshHome()))),
|
|
597
687
|
}, 'dsh-builtin-browser: bridge status'));
|
|
598
688
|
// The panel prepares a launcher without changing the running Desktop. Direct local
|
|
599
689
|
// maintenance remains available once Desktop has exited.
|
|
@@ -630,20 +720,32 @@ export function apply(ctx, config) {
|
|
|
630
720
|
if (typeof injectRuntime !== 'function')
|
|
631
721
|
return;
|
|
632
722
|
const deps = {
|
|
633
|
-
report: () =>
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
:
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
723
|
+
report: async () => {
|
|
724
|
+
const mainExtension = await readHostExtensionStatus(dshHome());
|
|
725
|
+
return readRuntimeStatus({
|
|
726
|
+
nativeHostRegistration: () => Object.fromEntries(registrationStatus),
|
|
727
|
+
channel: () => settings.get().browser.channel,
|
|
728
|
+
systemProfile: () => settings.get().browser.systemProfile,
|
|
729
|
+
extensionConnection: () => isPreferredCarrier(adoptedCarrier) ? {
|
|
730
|
+
...adoptedCarrier.connectionStatus(), install: extensionInstallHelp(adoptedCarrier.browser), registration: registrationStatus.get(adoptedCarrier.browser),
|
|
731
|
+
} : undefined,
|
|
732
|
+
selectedCarrier: () => adoptedCarrier instanceof DesktopBridgeViewHost || adoptedCarrier instanceof SidebarOnlyHost ? 'sidebar'
|
|
733
|
+
: adoptedCarrier instanceof PreferredBrowserViewHost ? adoptedCarrier.activeCarrier()
|
|
734
|
+
: adoptedCarrier instanceof ExtensionBrowserViewHost ? 'extension' : adoptedCarrier instanceof SystemBrowserViewHost ? 'system' : 'bundled',
|
|
735
|
+
fallbackReason: () => adoptedCarrier instanceof PreferredBrowserViewHost ? adoptedCarrier.fallbackReason : undefined,
|
|
736
|
+
systemConnection: () => adoptedCarrier instanceof PreferredBrowserViewHost ? adoptedCarrier.fallback.connectionStatus?.() : adoptedCarrier instanceof SystemBrowserViewHost ? adoptedCarrier.connectionStatus() : undefined,
|
|
737
|
+
hasBinary: hasElectronRuntime,
|
|
738
|
+
provision: provisionSnapshot,
|
|
739
|
+
bridgeError: () => DesktopBridgeViewHost.compatibilityError(),
|
|
740
|
+
bridge: () => {
|
|
741
|
+
const root = findDesktopInstall();
|
|
742
|
+
return root === undefined ? undefined : readBridgeStatus(root, mainExtension);
|
|
743
|
+
},
|
|
744
|
+
// Installed is not running: the install tree survives a reboot, the endpoint does not. Both
|
|
745
|
+
// readings are cheap and side-effect free — a file read and a signal-0 pid check.
|
|
746
|
+
endpoint: () => readBridgeEndpoint(),
|
|
747
|
+
});
|
|
748
|
+
},
|
|
647
749
|
// `force` is what makes the panel's retry button mean anything: without it the answer would be
|
|
648
750
|
// the settled failure the user is trying to replace. An attempt still running is joined.
|
|
649
751
|
provision: () => {
|
|
@@ -653,10 +755,39 @@ export function apply(ctx, config) {
|
|
|
653
755
|
};
|
|
654
756
|
try {
|
|
655
757
|
injectRuntime(['webServer'], (host) => {
|
|
758
|
+
host.effect(() => host.webServer.register({ kind: 'exact', path: EXTENSION_INSTALL_ROUTE, handler: authenticated(ctx, async (request, response) => {
|
|
759
|
+
if (request.method !== 'POST') {
|
|
760
|
+
response.writeHead(405);
|
|
761
|
+
response.end();
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
if (!sameOrigin(request, true)) {
|
|
765
|
+
response.writeHead(403);
|
|
766
|
+
response.end();
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
try {
|
|
770
|
+
const browser = settings.get().browser.channel === 'chrome' ? 'chrome' : 'edge';
|
|
771
|
+
if (isPreferredCarrier(adoptedCarrier))
|
|
772
|
+
await adoptedCarrier.refreshStatus();
|
|
773
|
+
const connected = isPreferredCarrier(adoptedCarrier) ? adoptedCarrier.connectionStatus().connected : await probeExtension(browser);
|
|
774
|
+
const result = await installExtension(browser, connected);
|
|
775
|
+
response.writeHead(200, { 'content-type': 'application/json' });
|
|
776
|
+
response.end(JSON.stringify(result));
|
|
777
|
+
}
|
|
778
|
+
catch (error) {
|
|
779
|
+
response.writeHead(200, { 'content-type': 'application/json' });
|
|
780
|
+
response.end(JSON.stringify({ ok: false, detail: String(error) }));
|
|
781
|
+
}
|
|
782
|
+
}) }, 'dsh-builtin-browser: install extension'));
|
|
656
783
|
host.effect(() => host.webServer.register({
|
|
657
784
|
kind: 'exact',
|
|
658
785
|
path: RUNTIME_STATUS_ROUTE,
|
|
659
|
-
handler: authenticated(ctx, (request, response) =>
|
|
786
|
+
handler: authenticated(ctx, async (request, response) => {
|
|
787
|
+
if (request.method === 'GET' && isPreferredCarrier(adoptedCarrier))
|
|
788
|
+
await adoptedCarrier.refreshStatus();
|
|
789
|
+
await handleRuntimeStatus(request, response, deps);
|
|
790
|
+
}),
|
|
660
791
|
}, 'dsh-builtin-browser: runtime status'));
|
|
661
792
|
host.effect(() => host.webServer.register({
|
|
662
793
|
kind: 'exact',
|
|
@@ -669,6 +800,109 @@ export function apply(ctx, config) {
|
|
|
669
800
|
// No web server: the panel is unreachable, and the readiness report has no reader.
|
|
670
801
|
}
|
|
671
802
|
}
|
|
803
|
+
/**
|
|
804
|
+
* Expose the shared start-page shortcut list on the host's web server.
|
|
805
|
+
*
|
|
806
|
+
* The sidebar edits the section through the settings RPC; this face exists for a
|
|
807
|
+
* caller that has no sidebar — an agent, a script, or a verification run — and it
|
|
808
|
+
* writes the SAME section through `ctx.settings`, so both paths see one list.
|
|
809
|
+
* @param host - the plugin context.
|
|
810
|
+
*/
|
|
811
|
+
function installShortcutRoutes(host) {
|
|
812
|
+
const injectRoutes = host.inject;
|
|
813
|
+
if (typeof injectRoutes !== 'function')
|
|
814
|
+
return;
|
|
815
|
+
const store = createShortcutStore(() => host.get?.('settings'));
|
|
816
|
+
const handlers = createShortcutRouteHandlers(store);
|
|
817
|
+
try {
|
|
818
|
+
injectRoutes(['webServer'], (scope) => {
|
|
819
|
+
const routes = [
|
|
820
|
+
[SHORTCUTS_ROUTE, handlers.list, 'dsh-builtin-browser: start-page shortcuts'],
|
|
821
|
+
[SHORTCUT_ADD_ROUTE, handlers.add, 'dsh-builtin-browser: start-page shortcut add'],
|
|
822
|
+
[SHORTCUT_REMOVE_ROUTE, handlers.remove, 'dsh-builtin-browser: start-page shortcut remove'],
|
|
823
|
+
];
|
|
824
|
+
for (const [path, handler, label] of routes) {
|
|
825
|
+
scope.effect(() => scope.webServer.register({
|
|
826
|
+
kind: 'exact',
|
|
827
|
+
path,
|
|
828
|
+
handler: authenticated(host, handler),
|
|
829
|
+
}, label));
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
catch {
|
|
834
|
+
// No web server: the shortcut seam stays available to the agent tool.
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Expose browser-reference capture, listing and reveal on the host's web server.
|
|
839
|
+
*
|
|
840
|
+
* The panel needs no browser session of its own: list and reveal act on the
|
|
841
|
+
* session recorded inside each reference, and capture takes the pair of ids
|
|
842
|
+
* from the caller. Skipped on a surface with no web server, exactly like the
|
|
843
|
+
* sibling routes.
|
|
844
|
+
* @param ctx - the plugin context.
|
|
845
|
+
* @param service - the shared reference service.
|
|
846
|
+
* @param carrier - the carrier recorded for captures that do not name one.
|
|
847
|
+
* @param queue - durable capture-to-draft hand-off.
|
|
848
|
+
*/
|
|
849
|
+
function installReferenceRoutes(ctx, service, carrier, queue, receipts) {
|
|
850
|
+
const injectRoutes = ctx.inject;
|
|
851
|
+
if (typeof injectRoutes !== 'function')
|
|
852
|
+
return;
|
|
853
|
+
try {
|
|
854
|
+
injectRoutes(['webServer'], (host) => {
|
|
855
|
+
const handlers = createReferenceRouteHandlers({ service, carrier, queue, receipts });
|
|
856
|
+
const routes = [
|
|
857
|
+
[CLIENT_VERSION_ROUTE, (_request, response) => {
|
|
858
|
+
// 客户端产物的版本指纹:内容变了,浏览器就应换到新 bundle。
|
|
859
|
+
const clientPath = fileURLToPath(new URL('../../dist/client.cjs', import.meta.url));
|
|
860
|
+
let version = "unknown";
|
|
861
|
+
try {
|
|
862
|
+
const stat = statSync(clientPath);
|
|
863
|
+
version = `${Math.round(stat.mtimeMs)}-${stat.size}`;
|
|
864
|
+
}
|
|
865
|
+
catch { /* 读不到就返回 unknown:客户端不会重载 */ }
|
|
866
|
+
response.writeHead(200, { "content-type": "application/json", "cache-control": "no-store" });
|
|
867
|
+
response.end(JSON.stringify({ ok: true, version }));
|
|
868
|
+
}, 'dsh-builtin-browser: client version'],
|
|
869
|
+
[REFERENCE_LIST_ROUTE, handlers.list, 'dsh-builtin-browser: reference list'],
|
|
870
|
+
[REFERENCE_GET_ROUTE, handlers.get, 'dsh-builtin-browser: reference detail'],
|
|
871
|
+
[REFERENCE_CAPTURE_ROUTE, handlers.capture, 'dsh-builtin-browser: reference capture'],
|
|
872
|
+
[REFERENCE_REVEAL_ROUTE, handlers.reveal, 'dsh-builtin-browser: reference reveal'],
|
|
873
|
+
[WEB_SOURCE_ROUTE, handlers.source, 'dsh-builtin-browser: web reference source'],
|
|
874
|
+
[REFERENCE_INSERT_ROUTE, handlers.insert, 'dsh-builtin-browser: reference draft insert'],
|
|
875
|
+
[REFERENCE_EXPORT_ROUTE, handlers.export, 'dsh-builtin-browser: reference export'],
|
|
876
|
+
[REFERENCE_IMPORT_ROUTE, handlers.importBundle, 'dsh-builtin-browser: reference import'],
|
|
877
|
+
[REFERENCE_DELIVERIES_ROUTE, handlers.deliveries, 'dsh-builtin-browser: reference deliveries'],
|
|
878
|
+
[REFERENCE_DELIVERY_ACK_ROUTE, handlers.ack, 'dsh-builtin-browser: reference delivery ack'],
|
|
879
|
+
[REFERENCE_DELIVERY_REMOVE_ROUTE, handlers.removeDelivery, 'dsh-builtin-browser: reference delivery remove'],
|
|
880
|
+
[REFERENCE_ASSET_ROUTE, handlers.asset, 'dsh-builtin-browser: reference asset bytes'],
|
|
881
|
+
];
|
|
882
|
+
for (const [path, handler, label] of routes) {
|
|
883
|
+
host.effect(() => host.webServer.register({
|
|
884
|
+
kind: 'exact',
|
|
885
|
+
path,
|
|
886
|
+
handler: authenticated(ctx, handler),
|
|
887
|
+
}, label));
|
|
888
|
+
}
|
|
889
|
+
host.effect(() => host.webServer.register({
|
|
890
|
+
kind: 'exact',
|
|
891
|
+
path: REFERENCE_STATUS_ROUTE,
|
|
892
|
+
handler: authenticated(ctx, (request, response) => {
|
|
893
|
+
if (request.method !== 'GET') {
|
|
894
|
+
replyJson(response, 405, { ok: false, error: 'method-not-allowed' });
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
replyJson(response, 200, { ok: true, entry: referenceProvider?.referenceStatus() ?? null });
|
|
898
|
+
}),
|
|
899
|
+
}, 'dsh-builtin-browser: reference entry status'));
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
catch {
|
|
903
|
+
// No web server: capture stays available through the agent tools.
|
|
904
|
+
}
|
|
905
|
+
}
|
|
672
906
|
/**
|
|
673
907
|
* Re-run the carrier choice when the settings FILE changes on disk.
|
|
674
908
|
*
|
|
@@ -677,13 +911,12 @@ export function apply(ctx, config) {
|
|
|
677
911
|
* unreachable or the user prefers the file. Measured: the document said `sidebar` and the plugin
|
|
678
912
|
* kept driving the self-hosted window built for the previous choice, because nothing re-read it.
|
|
679
913
|
*
|
|
680
|
-
* Change detection is on
|
|
914
|
+
* Change detection is on carrier settings, not the mtime: a poll that re-chose the carrier on
|
|
681
915
|
* every unrelated save would tear down and rebuild a working browser session for a switch that
|
|
682
916
|
* cannot affect it. mtime is only the cheap trigger to go and look.
|
|
683
917
|
*/
|
|
684
918
|
const watchSettingsFile = () => {
|
|
685
919
|
const file = settingsPath();
|
|
686
|
-
let lastChannel = settings.get().browser.channel;
|
|
687
920
|
let lastMtime = 0;
|
|
688
921
|
try {
|
|
689
922
|
lastMtime = statSync(file).mtimeMs;
|
|
@@ -704,11 +937,9 @@ export function apply(ctx, config) {
|
|
|
704
937
|
if (mtime === lastMtime)
|
|
705
938
|
return;
|
|
706
939
|
lastMtime = mtime;
|
|
707
|
-
|
|
708
|
-
if (channel === lastChannel)
|
|
940
|
+
if (carrierSettingsKey(settings.get()) === chosenSettingsKey)
|
|
709
941
|
return;
|
|
710
|
-
|
|
711
|
-
ctx.logger?.info?.(`dsh-builtin-browser: settings changed on disk, re-choosing the carrier for channel "${channel}"`);
|
|
942
|
+
ctx.logger?.info?.('dsh-builtin-browser: carrier settings changed on disk, re-choosing the carrier');
|
|
712
943
|
chooseCarrier();
|
|
713
944
|
}, 5_000);
|
|
714
945
|
// Unref-ed so a poll never holds the process open.
|
|
@@ -719,17 +950,187 @@ export function apply(ctx, config) {
|
|
|
719
950
|
installPreviewRoute(ctx, settings);
|
|
720
951
|
installBridgeStatusRoute(ctx);
|
|
721
952
|
installRuntimeStatusRoute(ctx, settings);
|
|
953
|
+
// One service for the panel's routes; the tool layer builds its own over the same store file.
|
|
954
|
+
const referenceService = createReferenceService(ctx.browser, {
|
|
955
|
+
sourceReady: async (owner) => { (await DesktopBridgeViewHost.discover(`session-${owner}`))?.dispose(); },
|
|
956
|
+
sourceSession: (owner, pageId) => ctx.browser.bindPanelPage(`session-${owner}`, pageId),
|
|
957
|
+
// A visible-region snapshot is a read: the clipped CDP path never presents
|
|
958
|
+
// the conversation, raises a window or moves the pointer.
|
|
959
|
+
visibleCapture: async (sessionId, clip, signal) => {
|
|
960
|
+
const shot = await ctx.browser.screenshot(sessionWireId(resolveSessionHandle(sessionId)), { clip, format: 'png' }, signal);
|
|
961
|
+
return { dataUrl: shot.dataUrl, mime: 'image/png' };
|
|
962
|
+
},
|
|
963
|
+
});
|
|
964
|
+
const referenceCarrier = () => {
|
|
965
|
+
const channel = settings.get().browser.channel;
|
|
966
|
+
return channel === 'chrome' || channel === 'edge' ? channel : 'sidebar';
|
|
967
|
+
};
|
|
968
|
+
/**
|
|
969
|
+
* The durable hand-off. A capture is frozen into the queue with the FULL
|
|
970
|
+
* snapshot, so the client can restore a draft after the page closed or DSH
|
|
971
|
+
* restarted without asking the browser for anything (§12.2).
|
|
972
|
+
*/
|
|
973
|
+
const deliveryQueue = createDeliveryQueue();
|
|
974
|
+
const receipts = createSubmissionReceipts(deliveryQueue, id => {
|
|
975
|
+
const sessions = ctx.get('sessions');
|
|
976
|
+
return sessions?.get(id);
|
|
977
|
+
});
|
|
978
|
+
ctx.on?.('session/event', (session, event) => {
|
|
979
|
+
try {
|
|
980
|
+
receipts.observe(session.id, event);
|
|
981
|
+
}
|
|
982
|
+
catch (error) {
|
|
983
|
+
ctx.logger?.warn?.(`dsh-builtin-browser: reference receipt pending: ${String(error)}`);
|
|
984
|
+
}
|
|
985
|
+
}, { global: true });
|
|
986
|
+
installReferenceRoutes(ctx, referenceService, referenceCarrier, deliveryQueue, receipts);
|
|
987
|
+
installShortcutRoutes(ctx);
|
|
988
|
+
/** Freeze a captured reference for its owning conversation. */
|
|
989
|
+
const prepareCaptured = (reference, failures, onFailure) => {
|
|
990
|
+
if (reference === undefined)
|
|
991
|
+
return false;
|
|
992
|
+
// `resolveReferenceOwner` falls back to `browser:<uuid>` when no real DSH
|
|
993
|
+
// conversation id can be read. queue.prepare would "succeed" under that
|
|
994
|
+
// id, but the client polls with the REAL session id and can never match it,
|
|
995
|
+
// so the card silently never appears. Refuse the enqueue instead of
|
|
996
|
+
// reporting a success that cannot be delivered, and let the page ask the
|
|
997
|
+
// human to retry once the session is ready.
|
|
998
|
+
if ((reference.owner.sessionId ?? '').startsWith('browser:')) {
|
|
999
|
+
process.stderr.write('[dsh-browser] reference delivery refused: browser-session-id-required\n');
|
|
1000
|
+
onFailure?.('browser-session-id-required');
|
|
1001
|
+
return false;
|
|
1002
|
+
}
|
|
1003
|
+
try {
|
|
1004
|
+
deliveryQueue.prepare(reference, {
|
|
1005
|
+
failures: failures.map(failure => ({
|
|
1006
|
+
kind: (failure.kind === 'text' || failure.kind === 'image' || failure.kind === 'table'
|
|
1007
|
+
? failure.kind : 'reference'),
|
|
1008
|
+
reason: failure.reason,
|
|
1009
|
+
})),
|
|
1010
|
+
});
|
|
1011
|
+
return true;
|
|
1012
|
+
}
|
|
1013
|
+
catch (error) {
|
|
1014
|
+
process.stderr.write(`[dsh-browser] reference delivery prepare failed: ${String(error)}\n`);
|
|
1015
|
+
onFailure?.('delivery-enqueue-failed');
|
|
1016
|
+
return false;
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
// The production draft adapter. `insertIntoDraft` used to answer
|
|
1020
|
+
// `draft-adapter-unavailable` because nothing ever registered one; now it
|
|
1021
|
+
// freezes the reference into the durable queue. The CLIENT decides when the
|
|
1022
|
+
// draft and assets are actually saved — only its ACK marks the delivery
|
|
1023
|
+
// acknowledged, never this enqueue (§12.1).
|
|
1024
|
+
//
|
|
1025
|
+
// NOTE: installReferenceRoutes always receives the queue, so `/reference/insert`
|
|
1026
|
+
// takes the `queue.prepare` branch and `insertIntoDraft` (hence this adapter)
|
|
1027
|
+
// is not reached in production. It is kept as the fallback for a caller that
|
|
1028
|
+
// constructs the routes WITHOUT a queue; removing it would make that path
|
|
1029
|
+
// silently lose the capture.
|
|
1030
|
+
referenceService.setDraftAdapter({
|
|
1031
|
+
insertReference: async (reference) => {
|
|
1032
|
+
const current = deliveryQueue.get(reference.referenceId);
|
|
1033
|
+
if (current?.state === 'removed')
|
|
1034
|
+
return { applied: false, reason: 'reference-was-removed' };
|
|
1035
|
+
// Only enqueue a capture that has no delivery yet, and HONOUR the result:
|
|
1036
|
+
// an unready session or a failed prepare must not report `applied: true`
|
|
1037
|
+
// for a card the client can never poll.
|
|
1038
|
+
if (current === undefined && !prepareCaptured(reference, [])) {
|
|
1039
|
+
return { applied: false, reason: 'delivery-enqueue-failed' };
|
|
1040
|
+
}
|
|
1041
|
+
return { applied: true };
|
|
1042
|
+
},
|
|
1043
|
+
});
|
|
1044
|
+
/**
|
|
1045
|
+
* The one sentence the page shows when a capture produced no reference.
|
|
1046
|
+
*
|
|
1047
|
+
* Ordered from most actionable to least: the reader is told what to DO, not
|
|
1048
|
+
* which internal step failed.
|
|
1049
|
+
*/
|
|
1050
|
+
const captureRefusalText = (failures) => {
|
|
1051
|
+
const copy = referenceCaptureMessages;
|
|
1052
|
+
for (const failure of failures) {
|
|
1053
|
+
const reason = failure.reason;
|
|
1054
|
+
const exact = copy[reason];
|
|
1055
|
+
if (exact !== undefined)
|
|
1056
|
+
return exact;
|
|
1057
|
+
// Machine-coded reasons carry a detail suffix. A reader still deserves an
|
|
1058
|
+
// actionable sentence instead of the generic fallback.
|
|
1059
|
+
if (reason.startsWith('capture-failed:'))
|
|
1060
|
+
return referenceCaptureErrors.captureFailed;
|
|
1061
|
+
if (reason.startsWith('store-refused:'))
|
|
1062
|
+
return referenceCaptureErrors.storeRefused;
|
|
1063
|
+
if (reason.startsWith('frame-capture-refused:'))
|
|
1064
|
+
return copy['frame-capture-refused'];
|
|
1065
|
+
if (reason.startsWith('cell-image:'))
|
|
1066
|
+
return referenceCaptureErrors.imageUnreadable;
|
|
1067
|
+
if (reason.startsWith('image-'))
|
|
1068
|
+
return referenceCaptureErrors.imageFailed;
|
|
1069
|
+
}
|
|
1070
|
+
return copy['capture-refused'];
|
|
1071
|
+
};
|
|
1072
|
+
// The self-hosted Electron host reports a right-click or a floating-button
|
|
1073
|
+
// press as a user action. Register the one handler that turns it into a
|
|
1074
|
+
// capture; the disposer keeps a plugin reload from leaving a stale closure.
|
|
1075
|
+
//
|
|
1076
|
+
// R01: `action.windowId` is `browser:<uuid>` — a BROWSER session / view, not a
|
|
1077
|
+
// DSH conversation. The real conversation id comes from `readSessionId(ctx)`
|
|
1078
|
+
// above (the same `ctx.get('agents').list()` the desktop host uses). Both are
|
|
1079
|
+
// recorded separately, and the owner is fixed at capture time, so switching
|
|
1080
|
+
// to another conversation later cannot move this reference.
|
|
1081
|
+
const disposeReferenceAction = setReferenceCaptureActionHandler(async (action) => {
|
|
1082
|
+
// Re-read: the agent list is empty while the plugin applies, so the id captured
|
|
1083
|
+
// at apply time can be missing exactly when the first capture arrives.
|
|
1084
|
+
const owner = resolveReferenceOwner(readSessionId(ctx) ?? sessionId, action.windowId);
|
|
1085
|
+
const outcome = await referenceService.capture({
|
|
1086
|
+
sessionId: owner.sessionId,
|
|
1087
|
+
browserSessionId: owner.browserSessionId,
|
|
1088
|
+
origin: 'user-selection',
|
|
1089
|
+
entry: action.entry,
|
|
1090
|
+
carrier: referenceCarrier(),
|
|
1091
|
+
...action.frameSelector !== undefined ? { frameSelector: action.frameSelector } : {},
|
|
1092
|
+
...action.target !== undefined ? { target: action.target } : {},
|
|
1093
|
+
...action.comment !== undefined ? { comment: action.comment } : {},
|
|
1094
|
+
// The bar froze the WHOLE capture before its comment field took focus.
|
|
1095
|
+
// Only when that is missing (an older page script, a context-menu entry)
|
|
1096
|
+
// do we fall back to locating the frozen wording.
|
|
1097
|
+
...action.capture !== undefined
|
|
1098
|
+
? { frozenCapture: action.capture }
|
|
1099
|
+
: action.selectionText !== undefined && action.selectionText !== ''
|
|
1100
|
+
? { excerptText: action.selectionText }
|
|
1101
|
+
: {},
|
|
1102
|
+
});
|
|
1103
|
+
if (outcome.reference === undefined) {
|
|
1104
|
+
process.stderr.write(`[dsh-browser] reference capture refused: ${outcome.failures.map(item => item.reason).join(', ')}\n`);
|
|
1105
|
+
// A refusal that is only logged looks like a dead button. Say it in the
|
|
1106
|
+
// page, where the click happened. `notify` MUST NOT be allowed to reject:
|
|
1107
|
+
// the provider's pump treats a thrown notification as an unreachable page
|
|
1108
|
+
// and retires the sidebar the human is still looking at after 5 strikes.
|
|
1109
|
+
try {
|
|
1110
|
+
await referenceService.notify(owner.browserSessionId, captureRefusalText(outcome.failures));
|
|
1111
|
+
}
|
|
1112
|
+
catch {
|
|
1113
|
+
// Best effort: the capture is already decided; a page that cannot be
|
|
1114
|
+
// notified must never escalate into tearing down the live sidebar.
|
|
1115
|
+
}
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
let prepareFailure = 'delivery-enqueue-failed';
|
|
1119
|
+
if (!prepareCaptured(outcome.reference, outcome.failures, code => { prepareFailure = code; })) {
|
|
1120
|
+
// The reference was saved but never entered the delivery queue. Without
|
|
1121
|
+
// this notice the button looks successful and no card EVER appears. The
|
|
1122
|
+
// code is short, stable and non-sensitive (no stack trace, no path).
|
|
1123
|
+
try {
|
|
1124
|
+
await referenceService.notify(owner.browserSessionId, `当前会话还没准备好,请稍后重新添加这条引用。(错误码:${prepareFailure})`);
|
|
1125
|
+
}
|
|
1126
|
+
catch {
|
|
1127
|
+
// Same as above: a failing notice must not reach the provider's pump.
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
});
|
|
1131
|
+
ctx.effect(() => disposeReferenceAction, 'dsh-builtin-browser: reference action handler');
|
|
1132
|
+
ctx.effect(() => () => deliveryQueue.dispose(), 'dsh-builtin-browser: reference delivery queue');
|
|
722
1133
|
}
|
|
723
|
-
/** Route the settings panel reads and writes. */
|
|
724
|
-
const SETTINGS_ROUTE = '/dsh-builtin-browser/settings';
|
|
725
|
-
/**
|
|
726
|
-
* The directory under the DSH home that holds this plugin's browser profile.
|
|
727
|
-
*
|
|
728
|
-
* Named once, because every consumer of it must agree: `settingsPath()` and the history
|
|
729
|
-
* store resolve their own copy from `$DSH_HOME`, and a profile written under a different
|
|
730
|
-
* root than the settings document is a pair that silently never meets.
|
|
731
|
-
*/
|
|
732
|
-
const BROWSER_PROFILE_DIR = 'dsh-builtin-browser-host';
|
|
733
1134
|
/**
|
|
734
1135
|
* Move a browser profile left behind by the old layout into the directory the plugin uses now.
|
|
735
1136
|
*
|
|
@@ -771,6 +1172,12 @@ function authenticated(ctx, handler) {
|
|
|
771
1172
|
return surface.get('connection');
|
|
772
1173
|
}, handler);
|
|
773
1174
|
}
|
|
1175
|
+
function paired(ctx, handler) {
|
|
1176
|
+
return pairedRoute(() => {
|
|
1177
|
+
const surface = ctx;
|
|
1178
|
+
return surface.get('connection');
|
|
1179
|
+
}, handler);
|
|
1180
|
+
}
|
|
774
1181
|
/**
|
|
775
1182
|
* Expose the settings document over the host's web server, which is how the
|
|
776
1183
|
* settings panel reads and writes it. A host without that service (headless /
|
|
@@ -802,7 +1209,7 @@ function installSettingsRoute(ctx, settings, onChannelChange) {
|
|
|
802
1209
|
* @param request - the incoming request.
|
|
803
1210
|
* @param response - the response to write.
|
|
804
1211
|
* @param settings - the settings document.
|
|
805
|
-
* @param onChannelChange - re-runs the carrier choice when this write changed
|
|
1212
|
+
* @param onChannelChange - re-runs the carrier choice when this write changed carrier settings.
|
|
806
1213
|
*/
|
|
807
1214
|
async function handleSettingsRequest(request, response, settings, onChannelChange) {
|
|
808
1215
|
const json = (status, body) => {
|
|
@@ -828,19 +1235,19 @@ async function handleSettingsRequest(request, response, settings, onChannelChang
|
|
|
828
1235
|
try {
|
|
829
1236
|
const text = await readTextBody(request);
|
|
830
1237
|
const patch = text.trim() === '' ? {} : JSON.parse(text);
|
|
831
|
-
const before = settings.get()
|
|
1238
|
+
const before = carrierSettingsKey(settings.get());
|
|
832
1239
|
const updated = settings.update(patch);
|
|
833
|
-
//
|
|
1240
|
+
// Changed carrier settings are a request to switch carriers, not just values to store. The
|
|
834
1241
|
// choice is re-run here so the write takes effect now — and the response says so, because a
|
|
835
1242
|
// caller that cannot tell "applied" from "stored for later" has no way to know what it got,
|
|
836
1243
|
// which is exactly how a write that did nothing read as a success.
|
|
837
|
-
const
|
|
838
|
-
if (
|
|
1244
|
+
const carrierChanged = carrierSettingsKey(updated) !== before;
|
|
1245
|
+
if (carrierChanged)
|
|
839
1246
|
onChannelChange?.();
|
|
840
1247
|
json(200, {
|
|
841
1248
|
ok: true,
|
|
842
1249
|
settings: updated,
|
|
843
|
-
...
|
|
1250
|
+
...carrierChanged ? { carrierRechosen: true } : {},
|
|
844
1251
|
});
|
|
845
1252
|
}
|
|
846
1253
|
catch (error) {
|