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
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2960 @@
|
|
|
1
|
+
import { HarnessError } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import { Context, Service } from "@deepseek-ai/cordis";
|
|
3
|
+
import z from "@deepseek-ai/schemastery";
|
|
4
|
+
import "node:child_process";
|
|
5
|
+
/**
|
|
6
|
+
* Stable identity of one browser session, resolved by the Host through a
|
|
7
|
+
* Typert `LookupMap` to the live session object (the same mechanism
|
|
8
|
+
* `Agent → agentId` uses). The id is opaque to the wire; only the provider
|
|
9
|
+
* and its host binding can interpret it.
|
|
10
|
+
*/
|
|
11
|
+
type BrowserSessionId = string;
|
|
12
|
+
/**
|
|
13
|
+
* What one browser-capable backend is asked to do. Navigation is the minimal
|
|
14
|
+
* operation every provider shares; the seam deliberately keeps the request
|
|
15
|
+
* minimal so a provider swap never changes how the model asks.
|
|
16
|
+
*/
|
|
17
|
+
interface BrowserNavigateRequest {
|
|
18
|
+
/**
|
|
19
|
+
* The URL to open. Admission (HTTP(S) only) is provider-owned; the seam
|
|
20
|
+
* itself does not police credentials or private/localhost targets — a
|
|
21
|
+
* shared real browser legitimately reaches local dev servers.
|
|
22
|
+
*/
|
|
23
|
+
readonly url: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Click at viewport coordinates. Coordinates are viewport-relative pixels in
|
|
27
|
+
* the session's own coordinate space — the same space the human interacts
|
|
28
|
+
* with, so a real view and a relay agree without scaling.
|
|
29
|
+
*/
|
|
30
|
+
interface BrowserClickRequest {
|
|
31
|
+
/** Viewport-relative x in CSS pixels. */
|
|
32
|
+
readonly x: number;
|
|
33
|
+
/** Viewport-relative y in CSS pixels. */
|
|
34
|
+
readonly y: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A run of coordinate clicks in one call.
|
|
38
|
+
*
|
|
39
|
+
* Each point is clicked in order with the same real CDP sequence the single click uses. Between
|
|
40
|
+
* points the call waits `intervalMs`, because a canvas that receives two presses inside one frame
|
|
41
|
+
* treats them as a double click — or drops the second entirely, which looks like a silently wrong
|
|
42
|
+
* board rather than an error.
|
|
43
|
+
*/
|
|
44
|
+
interface BrowserClickSequenceRequest {
|
|
45
|
+
/** Points to click, in order, in viewport CSS pixels. */
|
|
46
|
+
readonly points: readonly {
|
|
47
|
+
readonly x: number;
|
|
48
|
+
readonly y: number;
|
|
49
|
+
}[];
|
|
50
|
+
/** Milliseconds to wait between points; defaults to 40. */
|
|
51
|
+
readonly intervalMs?: number;
|
|
52
|
+
}
|
|
53
|
+
/** Result of a click run: how many landed, and where it stopped if it did not finish. */
|
|
54
|
+
interface BrowserClickSequenceResult {
|
|
55
|
+
/** Points that were clicked successfully. */
|
|
56
|
+
readonly clicked: number;
|
|
57
|
+
/** Index of the point that failed, when one did. */
|
|
58
|
+
readonly failedAt?: number;
|
|
59
|
+
/** Why that point failed. */
|
|
60
|
+
readonly error?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Type text into the focused element. */
|
|
63
|
+
interface BrowserTypeRequest {
|
|
64
|
+
/** The text to insert. */
|
|
65
|
+
readonly text: string;
|
|
66
|
+
}
|
|
67
|
+
/** Scroll the page: by pixel deltas, to an element, or to top/bottom. */
|
|
68
|
+
interface BrowserScrollRequest {
|
|
69
|
+
/** Horizontal delta in CSS pixels. */
|
|
70
|
+
readonly deltaX?: number;
|
|
71
|
+
/** Vertical delta in CSS pixels. */
|
|
72
|
+
readonly deltaY?: number;
|
|
73
|
+
/** Scroll the given selector's element into view (top document; same-origin iframes reachable via execute). */
|
|
74
|
+
readonly selector?: string;
|
|
75
|
+
/** Scroll to the top of the page. */
|
|
76
|
+
readonly toTop?: boolean;
|
|
77
|
+
/** Scroll to the bottom of the page. */
|
|
78
|
+
readonly toBottom?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/** Press one named key (Enter, Tab, arrows, …). */
|
|
81
|
+
interface BrowserKeyRequest {
|
|
82
|
+
/** Key name from the supported set (see the dsh_browser_key tool). */
|
|
83
|
+
readonly key: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* How to find one element for a targeted interaction (form controls, clicks,
|
|
87
|
+
* typing). `text` matches an element's own visible text — exact first, then
|
|
88
|
+
* contains, deepest element preferred (so a button inside a card wins over
|
|
89
|
+
* the card itself).
|
|
90
|
+
*/
|
|
91
|
+
interface BrowserElementTarget {
|
|
92
|
+
/** Locator kind. */
|
|
93
|
+
readonly by: 'css' | 'text' | 'xpath';
|
|
94
|
+
/** The CSS selector / visible text / XPath expression. */
|
|
95
|
+
readonly value: string;
|
|
96
|
+
/** 0-based index of the match to use. Default 0. */
|
|
97
|
+
readonly index?: number;
|
|
98
|
+
}
|
|
99
|
+
/** Set the value of one input/textarea/select/contenteditable. */
|
|
100
|
+
interface BrowserSetValueRequest {
|
|
101
|
+
/** The element to set (css/text/xpath). */
|
|
102
|
+
readonly target: BrowserElementTarget;
|
|
103
|
+
/** The value to set (string, number, or boolean). */
|
|
104
|
+
readonly value: string | number | boolean;
|
|
105
|
+
/** Element-lookup budget in ms. Default 5000. */
|
|
106
|
+
readonly timeoutMs?: number;
|
|
107
|
+
}
|
|
108
|
+
/** Result of a single setValue. */
|
|
109
|
+
interface BrowserSetValueResult {
|
|
110
|
+
/** How the value was applied: input | textarea | select | contenteditable. */
|
|
111
|
+
readonly method: string;
|
|
112
|
+
/** The value as applied. */
|
|
113
|
+
readonly value: string;
|
|
114
|
+
}
|
|
115
|
+
/** Check/uncheck one checkbox or radio. */
|
|
116
|
+
interface BrowserCheckRequest {
|
|
117
|
+
/** The element to toggle (css/text/xpath). */
|
|
118
|
+
readonly target: BrowserElementTarget;
|
|
119
|
+
/** Desired state. Default true (check). */
|
|
120
|
+
readonly checked?: boolean;
|
|
121
|
+
/** Element-lookup budget in ms. Default 5000. */
|
|
122
|
+
readonly timeoutMs?: number;
|
|
123
|
+
}
|
|
124
|
+
/** Select one option of a `<select>`, by value, visible text, or index. */
|
|
125
|
+
interface BrowserSelectRequest {
|
|
126
|
+
/** The `<select>` element (css/text/xpath). */
|
|
127
|
+
readonly target: BrowserElementTarget;
|
|
128
|
+
/** Match the option by its value attribute. */
|
|
129
|
+
readonly optionValue?: string;
|
|
130
|
+
/** Match the option by its visible text. */
|
|
131
|
+
readonly optionText?: string;
|
|
132
|
+
/** Match the option by its 0-based index. */
|
|
133
|
+
readonly optionIndex?: number;
|
|
134
|
+
/** Element-lookup budget in ms. Default 5000. */
|
|
135
|
+
readonly timeoutMs?: number;
|
|
136
|
+
}
|
|
137
|
+
/** Result of a single select. */
|
|
138
|
+
interface BrowserSelectResult {
|
|
139
|
+
/** The selected option's value attribute. */
|
|
140
|
+
readonly value: string;
|
|
141
|
+
/** The selected option's visible text. */
|
|
142
|
+
readonly text: string;
|
|
143
|
+
}
|
|
144
|
+
/** Clear one input/textarea/contenteditable (or uncheck a checkbox/radio). */
|
|
145
|
+
interface BrowserClearRequest {
|
|
146
|
+
/** The element to clear (css/text/xpath). */
|
|
147
|
+
readonly target: BrowserElementTarget;
|
|
148
|
+
/** Element-lookup budget in ms. Default 5000. */
|
|
149
|
+
readonly timeoutMs?: number;
|
|
150
|
+
}
|
|
151
|
+
/** Read one element's current value (for verification). */
|
|
152
|
+
interface BrowserGetValueRequest {
|
|
153
|
+
/** The element to read (css/text/xpath). */
|
|
154
|
+
readonly target: BrowserElementTarget;
|
|
155
|
+
/** Element-lookup budget in ms. Default 5000. */
|
|
156
|
+
readonly timeoutMs?: number;
|
|
157
|
+
}
|
|
158
|
+
/** Result of a getValue. */
|
|
159
|
+
interface BrowserGetValueResult {
|
|
160
|
+
/** The element's value; null when the element has none (e.g. a checkbox). */
|
|
161
|
+
readonly value: string | null;
|
|
162
|
+
/** For checkbox/radio: the checked state. */
|
|
163
|
+
readonly checked?: boolean;
|
|
164
|
+
/** For `<select>`: the selected option's visible text. */
|
|
165
|
+
readonly selectedText?: string;
|
|
166
|
+
}
|
|
167
|
+
/** One field of a scrape: a name plus a selector (optionally `selector@attr`). */
|
|
168
|
+
interface BrowserScrapeField {
|
|
169
|
+
/** Output key. */
|
|
170
|
+
readonly name: string;
|
|
171
|
+
/**
|
|
172
|
+
* CSS selector relative to each item; append `@attr` to take an attribute
|
|
173
|
+
* instead of text (`a@href` returns an absolute URL for links).
|
|
174
|
+
*/
|
|
175
|
+
readonly selector: string;
|
|
176
|
+
}
|
|
177
|
+
/** Extract structured data from repeated DOM items (static, CSP-safe). */
|
|
178
|
+
interface BrowserScrapeRequest {
|
|
179
|
+
/** Required: CSS selector of each result container (e.g. `div.card`). */
|
|
180
|
+
readonly item: string;
|
|
181
|
+
/** Field map: name -> selector[@attr]. */
|
|
182
|
+
readonly fields: readonly BrowserScrapeField[];
|
|
183
|
+
/** Wait budget for the item selector to appear. Default 5000. */
|
|
184
|
+
readonly timeoutMs?: number;
|
|
185
|
+
}
|
|
186
|
+
/** Structured extraction result. */
|
|
187
|
+
interface BrowserScrapeResult {
|
|
188
|
+
/** Number of items extracted. */
|
|
189
|
+
readonly count: number;
|
|
190
|
+
/** One object per item; missing fields are null. */
|
|
191
|
+
readonly items: readonly Record<string, string | null>[];
|
|
192
|
+
}
|
|
193
|
+
/** One field of a batch form fill. Match by selector, or by name/label/placeholder. */
|
|
194
|
+
interface BrowserFillField {
|
|
195
|
+
/** CSS selector; when present, candidates are scoped to it. */
|
|
196
|
+
readonly selector?: string;
|
|
197
|
+
/** Match by the field's `name` attribute. */
|
|
198
|
+
readonly name?: string;
|
|
199
|
+
/** Match by associated `<label>` text or `aria-label`. */
|
|
200
|
+
readonly label?: string;
|
|
201
|
+
/** Match by `placeholder` text. */
|
|
202
|
+
readonly placeholder?: string;
|
|
203
|
+
/** Field kind; defaults to text. */
|
|
204
|
+
readonly kind?: 'text' | 'textarea' | 'checkbox' | 'radio' | 'select';
|
|
205
|
+
/** Value to set: string, number, or boolean (checkbox/radio). For a
|
|
206
|
+
* multi-select or radio group, the option value (or visible text). */
|
|
207
|
+
readonly value: string | number | boolean;
|
|
208
|
+
}
|
|
209
|
+
/** Batch form fill: set several fields, optionally submitting the form. */
|
|
210
|
+
interface BrowserFillRequest {
|
|
211
|
+
/** The fields to fill, in order. */
|
|
212
|
+
readonly fields: readonly BrowserFillField[];
|
|
213
|
+
/** Submit the containing form after filling. Default false. */
|
|
214
|
+
readonly submit?: boolean;
|
|
215
|
+
/** Per-field evaluation budget in ms. Default 30000. */
|
|
216
|
+
readonly timeoutMs?: number;
|
|
217
|
+
}
|
|
218
|
+
/** One field's outcome in a batch fill. */
|
|
219
|
+
interface BrowserFillFieldResult {
|
|
220
|
+
readonly ok: boolean;
|
|
221
|
+
/** The field description matched (selector/name/label/placeholder). */
|
|
222
|
+
readonly target: string;
|
|
223
|
+
/** How the value was applied: input | textarea | select | checkbox | radio | contenteditable. */
|
|
224
|
+
readonly method?: string;
|
|
225
|
+
/** Error text when the field could not be filled. */
|
|
226
|
+
readonly error?: string;
|
|
227
|
+
}
|
|
228
|
+
/** Outcome of a batch form fill. */
|
|
229
|
+
interface BrowserFillResult {
|
|
230
|
+
/** Per-field outcomes, in request order. */
|
|
231
|
+
readonly fields: readonly BrowserFillFieldResult[];
|
|
232
|
+
/** Whether the containing form was submitted. */
|
|
233
|
+
readonly submitted: boolean;
|
|
234
|
+
}
|
|
235
|
+
/** Wait request: poll until the page is ready (and optional URL/selector). */
|
|
236
|
+
interface BrowserWaitRequest {
|
|
237
|
+
/** Maximum wait in ms. Default 30000. */
|
|
238
|
+
readonly timeoutMs?: number;
|
|
239
|
+
/**
|
|
240
|
+
* Optional URL the top document must show (exact or prefix match). Pass the
|
|
241
|
+
* URL you navigated to — this distinguishes the NEW document from the old
|
|
242
|
+
* one still on screen while navigation is in flight.
|
|
243
|
+
*/
|
|
244
|
+
readonly url?: string;
|
|
245
|
+
/** Optional CSS selector that must exist (top document or same-origin frames). */
|
|
246
|
+
readonly selector?: string;
|
|
247
|
+
/** Wait for the page load (readyState complete). Default true. */
|
|
248
|
+
readonly loaded?: boolean;
|
|
249
|
+
}
|
|
250
|
+
/** Outcome of a wait: whether the condition was met before the budget ran out. */
|
|
251
|
+
interface BrowserWaitResult {
|
|
252
|
+
readonly ready: boolean;
|
|
253
|
+
/** Why the wait ended: 'condition met' or a short explanation of the miss. */
|
|
254
|
+
readonly reason: string;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* A screenshot of the current page state. `dataUrl` is a base64 data URL the
|
|
258
|
+
* tool layer renders directly; the live view itself never crosses the wire
|
|
259
|
+
* (the human watches the real view in the desktop shape).
|
|
260
|
+
*/
|
|
261
|
+
interface BrowserScreenshotResult {
|
|
262
|
+
/** Base64 data URL of the capture (PNG or JPEG per the request). */
|
|
263
|
+
readonly dataUrl: string;
|
|
264
|
+
/** Pixel size of the image in `dataUrl`, when the capture was measured and scaled.
|
|
265
|
+
*
|
|
266
|
+
* Present when the request carried `maxWidth`/`maxHeight` and the layout metrics were
|
|
267
|
+
* readable: the scaling happens inside CDP through a clip, and without this the only way to
|
|
268
|
+
* learn what came back was to decode the data URL. Undefined means "not measured", which is
|
|
269
|
+
* also what an unscaled capture reports. */
|
|
270
|
+
readonly width?: number;
|
|
271
|
+
readonly height?: number;
|
|
272
|
+
/** File path the capture was also saved to, when the request asked for it. */
|
|
273
|
+
readonly path?: string;
|
|
274
|
+
}
|
|
275
|
+
/** Screenshot capture options. */
|
|
276
|
+
interface BrowserScreenshotRequest {
|
|
277
|
+
/** Capture the full scrollable page instead of the viewport. Default false. */
|
|
278
|
+
readonly fullPage?: boolean;
|
|
279
|
+
/** Absolute file path to also save the image to (for vision-tool reads). */
|
|
280
|
+
readonly savePath?: string;
|
|
281
|
+
/**
|
|
282
|
+
* Image format. Default 'png'. JPEG is only available on the self-hosted
|
|
283
|
+
* native capture path; the desktop-shell CDP fallback always returns PNG
|
|
284
|
+
* (CDP JPEG hangs on Electron 43 — a documented platform defect).
|
|
285
|
+
*/
|
|
286
|
+
readonly format?: 'png' | 'jpeg';
|
|
287
|
+
/** JPEG quality 1-100 (default 80); ignored for PNG. */
|
|
288
|
+
readonly quality?: number;
|
|
289
|
+
/** Downscale to fit within this width (aspect preserved). */
|
|
290
|
+
readonly maxWidth?: number;
|
|
291
|
+
/** Downscale to fit within this height (aspect preserved). */
|
|
292
|
+
readonly maxHeight?: number;
|
|
293
|
+
/**
|
|
294
|
+
* Capture only this region, in document CSS pixels. Used by the reference
|
|
295
|
+
* service for a masked visible-region snapshot; the tool layer does not
|
|
296
|
+
* expose it, so ordinary screenshots keep their existing behaviour.
|
|
297
|
+
*/
|
|
298
|
+
readonly clip?: {
|
|
299
|
+
readonly x: number;
|
|
300
|
+
readonly y: number;
|
|
301
|
+
readonly width: number;
|
|
302
|
+
readonly height: number;
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
/** Download options: fetch a URL into a local file, keeping the session's cookies. */
|
|
306
|
+
interface BrowserDownloadRequest {
|
|
307
|
+
/** The URL to download. */
|
|
308
|
+
readonly url: string;
|
|
309
|
+
/** Absolute path of the file to write. */
|
|
310
|
+
readonly savePath: string;
|
|
311
|
+
}
|
|
312
|
+
/** A serializable cookie, exported from or imported into the browser session. */
|
|
313
|
+
interface ExportedCookie {
|
|
314
|
+
/** Cookie URL (scheme + domain + path), as accepted by cookies.set. */
|
|
315
|
+
readonly url: string;
|
|
316
|
+
readonly name: string;
|
|
317
|
+
readonly value: string;
|
|
318
|
+
readonly domain?: string;
|
|
319
|
+
readonly path?: string;
|
|
320
|
+
readonly secure?: boolean;
|
|
321
|
+
readonly httpOnly?: boolean;
|
|
322
|
+
readonly expirationDate?: number;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Execute arbitrary JavaScript in the session's page context. This is the
|
|
326
|
+
* primary interaction path — DOM-referenced, not screen-coordinate-based:
|
|
327
|
+
* focus/input/click go through the page's own JS (native setters for
|
|
328
|
+
* framework-controlled inputs), matching how a human-driven agent operates.
|
|
329
|
+
*/
|
|
330
|
+
interface BrowserExecuteRequest {
|
|
331
|
+
/** The JavaScript expression to evaluate in the page context. */
|
|
332
|
+
readonly script: string;
|
|
333
|
+
/** Optional arguments injected into the script scope as `arguments[0..n]`. */
|
|
334
|
+
readonly args?: readonly unknown[];
|
|
335
|
+
/** Evaluation budget in ms; a wedged page rejects with a timeout. Default 30000. */
|
|
336
|
+
readonly timeoutMs?: number;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Fixed page operations implemented by the provider. Strings are serialized as data.
|
|
340
|
+
* Arbitrary JavaScript is handled only by BrowserExecuteRequest.
|
|
341
|
+
*/
|
|
342
|
+
type BrowserPageOperationRequest = {
|
|
343
|
+
readonly operation: 'install';
|
|
344
|
+
} | {
|
|
345
|
+
readonly operation: 'probe';
|
|
346
|
+
readonly method: BrowserProbeMethod;
|
|
347
|
+
readonly args?: readonly unknown[];
|
|
348
|
+
} | {
|
|
349
|
+
readonly operation: 'text';
|
|
350
|
+
readonly text: string;
|
|
351
|
+
} | {
|
|
352
|
+
readonly operation: 'url';
|
|
353
|
+
} | {
|
|
354
|
+
readonly operation: 'drag';
|
|
355
|
+
readonly from: {
|
|
356
|
+
x: number;
|
|
357
|
+
y: number;
|
|
358
|
+
};
|
|
359
|
+
readonly to: {
|
|
360
|
+
x: number;
|
|
361
|
+
y: number;
|
|
362
|
+
};
|
|
363
|
+
readonly steps: number;
|
|
364
|
+
} | {
|
|
365
|
+
readonly operation: 'upload';
|
|
366
|
+
readonly target: {
|
|
367
|
+
by: 'css' | 'text' | 'xpath';
|
|
368
|
+
value: string;
|
|
369
|
+
};
|
|
370
|
+
readonly file: {
|
|
371
|
+
name: string;
|
|
372
|
+
mime: string;
|
|
373
|
+
base64: string;
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
/** Provider-owned probe operations; JavaScript properties such as constructor are excluded. */
|
|
377
|
+
type BrowserProbeMethod = 'read' | 'clear' | 'settle' | 'find' | 'overlayAt' | 'summary' | 'findText' | 'hoverAt' | 'setDialogPolicy' | 'dialogStatus' | 'networkCursor';
|
|
378
|
+
/**
|
|
379
|
+
* Result of an execute. Mirrors CDP `Runtime.evaluate` semantics: either a
|
|
380
|
+
* value (by value, not by reference) or the exception thrown.
|
|
381
|
+
*/
|
|
382
|
+
type BrowserExecuteResult = {
|
|
383
|
+
readonly ok: true;
|
|
384
|
+
readonly value: unknown;
|
|
385
|
+
} | {
|
|
386
|
+
readonly ok: false;
|
|
387
|
+
readonly exception: string;
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* One interactive element in a snapshot, with a stable reference number the
|
|
391
|
+
* tool layer (and the model) can cite to target the element.
|
|
392
|
+
*/
|
|
393
|
+
interface BrowserSnapshotElement {
|
|
394
|
+
/** 1-based reference number, stable for the lifetime of one snapshot. */
|
|
395
|
+
readonly ref: number;
|
|
396
|
+
/** Element kind: 'input' | 'button' | 'link' | 'textarea' | 'select' | 'checkbox' | 'other'. */
|
|
397
|
+
readonly kind: string;
|
|
398
|
+
/** Text content or placeholder/label, truncated for the snapshot. */
|
|
399
|
+
readonly label: string;
|
|
400
|
+
/** Best-effort CSS selector; may be empty when none is derivable. */
|
|
401
|
+
readonly selector: string;
|
|
402
|
+
/** Viewport-relative center, for coordinate fallbacks. */
|
|
403
|
+
readonly x: number;
|
|
404
|
+
readonly y: number;
|
|
405
|
+
/**
|
|
406
|
+
* True when the element lives inside an (same-origin) iframe: coordinates
|
|
407
|
+
* are still top-document, but DOM selectors are frame-scoped — reach the
|
|
408
|
+
* element via `iframe.contentDocument` in dsh_browser_execute.
|
|
409
|
+
*/
|
|
410
|
+
readonly frame?: boolean;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* AI-friendly page snapshot: a compact, numbered inventory of interactive
|
|
414
|
+
* elements plus page facts. Not raw HTML — the model dialogues with this.
|
|
415
|
+
*/
|
|
416
|
+
interface BrowserSnapshotResult {
|
|
417
|
+
/** Final page URL. */
|
|
418
|
+
readonly url: string;
|
|
419
|
+
/** Page title, if any. */
|
|
420
|
+
readonly title?: string;
|
|
421
|
+
/** Numbered interactive elements. */
|
|
422
|
+
readonly elements: readonly BrowserSnapshotElement[];
|
|
423
|
+
/** True when the snapshot was truncated (element cap reached). */
|
|
424
|
+
readonly truncated: boolean;
|
|
425
|
+
/** Human-verification challenge blocking the page, when one is detected. */
|
|
426
|
+
readonly challenge?: BrowserChallenge;
|
|
427
|
+
/**
|
|
428
|
+
* True when this is a blank page — no document to read, nothing to drive.
|
|
429
|
+
*
|
|
430
|
+
* Zero elements means two very different things: a page that genuinely has nothing interactive,
|
|
431
|
+
* and a browser that has not opened anything at all. Without this flag they look identical, so a
|
|
432
|
+
* caller can act on a blank page and get a success value back — reported as issue #37, where every
|
|
433
|
+
* tool after a carrier swap answered against `about:blank` while appearing to work.
|
|
434
|
+
*
|
|
435
|
+
* Set for `about:blank` and for a view that has never navigated. A caller seeing it should treat
|
|
436
|
+
* the page as absent, not as empty.
|
|
437
|
+
*/
|
|
438
|
+
readonly blank?: boolean;
|
|
439
|
+
/** A sentence a caller can show instead of reporting an empty page as a successful read. */
|
|
440
|
+
readonly note?: string;
|
|
441
|
+
/**
|
|
442
|
+
* True when the page draws its interface on a canvas, so no DOM element exists to collect.
|
|
443
|
+
*
|
|
444
|
+
* Distinct from `blank`: the page is fully rendered and interactive, just not as elements. A
|
|
445
|
+
* caller must switch to a screenshot and coordinate input rather than conclude the page is empty.
|
|
446
|
+
*/
|
|
447
|
+
readonly canvas?: boolean;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* One node of the accessibility tree, with a stable reference number the
|
|
451
|
+
* model can cite. Roles/names prefer Chrome's `computedRole`/`computedName`
|
|
452
|
+
* with tag/attribute inference as fallback; coordinates are top-document
|
|
453
|
+
* viewport-relative so the node can also be driven by click/type.
|
|
454
|
+
*/
|
|
455
|
+
interface BrowserA11yNode {
|
|
456
|
+
/** 1-based reference number, stable for the lifetime of one a11y call. */
|
|
457
|
+
readonly ref: number;
|
|
458
|
+
/** ARIA role: button | link | textbox | checkbox | radio | combobox | … */
|
|
459
|
+
readonly role: string;
|
|
460
|
+
/** Accessible name (aria-label, label text, placeholder, own text, …). */
|
|
461
|
+
readonly name: string;
|
|
462
|
+
/**
|
|
463
|
+
* Current value of input-like nodes; absent when the node has none.
|
|
464
|
+
*
|
|
465
|
+
* The provider produces `null` for "not applicable" and the tool layer drops it, so absence
|
|
466
|
+
* and null mean the same thing here — which is what the output schema declares (`string`,
|
|
467
|
+
* not nullable). Saying `string | null` described the provider's internal shape rather than
|
|
468
|
+
* the contract, and the two disagreed at every call.
|
|
469
|
+
*/
|
|
470
|
+
readonly value?: string;
|
|
471
|
+
/** ARIA/DOM states: enabled/disabled/checked/unchecked/expanded/… */
|
|
472
|
+
readonly states: readonly string[];
|
|
473
|
+
/** DOM depth (within its document), for reconstructing the tree. */
|
|
474
|
+
readonly depth: number;
|
|
475
|
+
/** Element tag name (lowercase). */
|
|
476
|
+
readonly tag: string;
|
|
477
|
+
/**
|
|
478
|
+
* A CSS selector for this node, when one can be derived from its id or name.
|
|
479
|
+
*
|
|
480
|
+
* Empty for the many elements that have neither. Present because a role and a name are not
|
|
481
|
+
* always enough to target a node: `{by: 'text'}` matches an accessible name only loosely,
|
|
482
|
+
* and this is what lets a caller point at the exact element it was shown.
|
|
483
|
+
*/
|
|
484
|
+
readonly selector: string;
|
|
485
|
+
/** Viewport-relative center, for coordinate fallbacks. */
|
|
486
|
+
readonly x: number;
|
|
487
|
+
readonly y: number;
|
|
488
|
+
/** True when the node lives inside a same-origin iframe. */
|
|
489
|
+
readonly frame?: boolean;
|
|
490
|
+
}
|
|
491
|
+
/** A11y tree request: what to include and how many nodes to return. */
|
|
492
|
+
interface BrowserA11yRequest {
|
|
493
|
+
/** Include hidden elements (display:none, hidden, aria-hidden). Default false. */
|
|
494
|
+
readonly includeHidden?: boolean;
|
|
495
|
+
/** Maximum nodes returned. Default 500; clamped to 10-5000. */
|
|
496
|
+
readonly maxNodes?: number;
|
|
497
|
+
}
|
|
498
|
+
/** The page's accessibility tree, flattened into a numbered node list. */
|
|
499
|
+
interface BrowserA11yResult {
|
|
500
|
+
/** Final page URL. */
|
|
501
|
+
readonly url: string;
|
|
502
|
+
/** Page title, if any. */
|
|
503
|
+
readonly title?: string;
|
|
504
|
+
/** Number of nodes returned. */
|
|
505
|
+
readonly count: number;
|
|
506
|
+
/** Flattened a11y nodes (depth restores the tree). */
|
|
507
|
+
readonly nodes: readonly BrowserA11yNode[];
|
|
508
|
+
/** True when the result was truncated (maxNodes reached). */
|
|
509
|
+
readonly truncated: boolean;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* A detected human-verification (bot-detection / CAPTCHA) challenge blocking
|
|
513
|
+
* the page. Detection is best-effort and marker-based; a clean result is not a
|
|
514
|
+
* guarantee that no challenge exists.
|
|
515
|
+
*/
|
|
516
|
+
interface BrowserChallenge {
|
|
517
|
+
/** Whether a challenge currently blocks the page. */
|
|
518
|
+
readonly blocked: boolean;
|
|
519
|
+
/** Machine-readable kind: cloudflare | hcaptcha | recaptcha | turnstile | generic. */
|
|
520
|
+
readonly kind?: string;
|
|
521
|
+
/** Short human-readable description, e.g. 'Cloudflare "Just a moment" interstitial'. */
|
|
522
|
+
readonly reason?: string;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Content fetch formats. `html` is the raw DOM; `markdown` is a structured
|
|
526
|
+
* reading view; `txt` is plain text (smallest); `json` is structured data.
|
|
527
|
+
*/
|
|
528
|
+
type BrowserContentFormat = 'html' | 'markdown' | 'txt' | 'json';
|
|
529
|
+
/** Content fetch request: format, optional selector scoping, and caps. */
|
|
530
|
+
interface BrowserContentRequest {
|
|
531
|
+
/** Desired format. */
|
|
532
|
+
readonly format: BrowserContentFormat;
|
|
533
|
+
/** Optional CSS selector limiting the fetch to one region (e.g. `#main`). */
|
|
534
|
+
readonly selector?: string;
|
|
535
|
+
/** Maximum characters of the returned content. */
|
|
536
|
+
readonly maxChars?: number;
|
|
537
|
+
/** Evaluation timeout in ms; the fetch aborts after this. Default 30000. */
|
|
538
|
+
readonly timeoutMs?: number;
|
|
539
|
+
}
|
|
540
|
+
/** A fetched page content in the requested format. */
|
|
541
|
+
interface BrowserContentResult {
|
|
542
|
+
/** The content in the requested format, capped at `maxChars`. */
|
|
543
|
+
readonly content: string;
|
|
544
|
+
/** True when the content was truncated. */
|
|
545
|
+
readonly truncated: boolean;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* A tab inside a browser session. Tabs share the session's profile/cookies
|
|
549
|
+
* and are switchable without losing state.
|
|
550
|
+
*/
|
|
551
|
+
interface BrowserTab {
|
|
552
|
+
/** Stable tab id within the session. */
|
|
553
|
+
readonly id: string;
|
|
554
|
+
/** Current URL, or empty for a blank tab. */
|
|
555
|
+
readonly url: string;
|
|
556
|
+
/** Page title, if any. */
|
|
557
|
+
readonly title?: string;
|
|
558
|
+
/** Whether this tab is the active one. */
|
|
559
|
+
readonly active: boolean;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* One passive preview frame: an encoded image plus its dimensions.
|
|
563
|
+
*
|
|
564
|
+
* The image is a data URL so it travels the existing JSON seam unchanged; the media type is part of
|
|
565
|
+
* the URL rather than a separate field because every consumer needs them together.
|
|
566
|
+
*/
|
|
567
|
+
interface BrowserPreviewFrame {
|
|
568
|
+
readonly dataUrl: string;
|
|
569
|
+
readonly width?: number;
|
|
570
|
+
readonly height?: number;
|
|
571
|
+
}
|
|
572
|
+
/** One page a carrier holds, whether or not this plugin created it. */
|
|
573
|
+
interface CarrierPage {
|
|
574
|
+
/** Stable within one carrier session; used to address the page. */
|
|
575
|
+
readonly id: string;
|
|
576
|
+
readonly url: string;
|
|
577
|
+
readonly title?: string;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Why a carrier reported that it can no longer be used.
|
|
581
|
+
*
|
|
582
|
+
* Two different failures reach the same fallback, and saying which one is the difference between a
|
|
583
|
+
* message a user can act on and one that misleads them:
|
|
584
|
+
*
|
|
585
|
+
* - `shell-exited`: the shell process behind the carrier is gone. Its published endpoint stops
|
|
586
|
+
* being refreshed, which is the condition the fallback was originally written for.
|
|
587
|
+
* - `panel-unusable`: the shell is alive and answering, but its sidebar panel cannot provide a page
|
|
588
|
+
* — on a shell that renders that panel as an iframe there is no webContents and no CDP endpoint,
|
|
589
|
+
* so the carrier is undrivable rather than merely unready.
|
|
590
|
+
*
|
|
591
|
+
* The fallback announced the first of these unconditionally, so a `panel-unusable` fallback told
|
|
592
|
+
* the user their desktop shell had exited while it was running normally. Reported as such.
|
|
593
|
+
*/
|
|
594
|
+
type CarrierLossReason = 'shell-exited' | 'panel-unusable';
|
|
595
|
+
/** Request to open a URL: into the active tab or a new tab. */ interface BrowserOpenRequest {
|
|
596
|
+
/** The URL to open. */
|
|
597
|
+
readonly url: string;
|
|
598
|
+
/** Open in a new tab (parallel). Default false (reuse the active tab). */
|
|
599
|
+
readonly newTab?: boolean;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* A browser-capable backend. Registered with `ctx.browser.registerBrowserProvider`.
|
|
603
|
+
* `id` is a stable string, unique across the seam.
|
|
604
|
+
*/
|
|
605
|
+
interface BrowserProvider {
|
|
606
|
+
readonly id: string;
|
|
607
|
+
/** Cheap local usability check; must not make network calls. */
|
|
608
|
+
available(): boolean;
|
|
609
|
+
/**
|
|
610
|
+
* Open a new session. The provider mints the session id and prepares its
|
|
611
|
+
* backing surface (a view, a headless page, and so on). Sessions are isolated from
|
|
612
|
+
* each other in what they OWN — tabs, the active tab, history, the view — so one
|
|
613
|
+
* session must not be visible to any other session's caller.
|
|
614
|
+
*
|
|
615
|
+
* That isolation stops at the browser's own state, and is not meant to go further:
|
|
616
|
+
* cookies, logins and site storage are deliberately shared by every session, because
|
|
617
|
+
* every session drives the same browser and "sign in once, use it everywhere" is the
|
|
618
|
+
* point of using a real one. Reads that hand that state to a caller (see
|
|
619
|
+
* `flushAuth`) are scoped to the page in question, which is least exposure rather
|
|
620
|
+
* than a claim that the jar is per-session.
|
|
621
|
+
* @param label - optional human-readable label (e.g. the calling DSH task
|
|
622
|
+
* id) the provider may surface on the visible surface (window title) so a
|
|
623
|
+
* human can tell which task's page is currently shown.
|
|
624
|
+
*/
|
|
625
|
+
open(label?: string): Promise<BrowserSessionId>;
|
|
626
|
+
/** Open a URL, optionally in a new tab. Honor `signal` for cancellation. */
|
|
627
|
+
openUrl(session: BrowserSessionId, request: BrowserOpenRequest, signal?: AbortSignal): Promise<void>;
|
|
628
|
+
/** List the session's tabs. */
|
|
629
|
+
listTabs(session: BrowserSessionId): Promise<readonly BrowserTab[]>;
|
|
630
|
+
/** Switch to a tab by id. Unknown id -> `BROWSER_TAB_UNKNOWN`. */
|
|
631
|
+
switchTab(session: BrowserSessionId, tabId: string): Promise<void>;
|
|
632
|
+
/** Close one tab. Closing the active tab activates the next. */
|
|
633
|
+
closeTab(session: BrowserSessionId, tabId: string): Promise<void>;
|
|
634
|
+
/** Close every tab and reset the session's state. */
|
|
635
|
+
reset(session: BrowserSessionId): Promise<void>;
|
|
636
|
+
/** Navigate the active tab. Honor `signal` for cancellation. */
|
|
637
|
+
navigate(session: BrowserSessionId, request: BrowserNavigateRequest, signal?: AbortSignal): Promise<void>;
|
|
638
|
+
/** Execute JS in the active tab's page context. */
|
|
639
|
+
execute(session: BrowserSessionId, request: BrowserExecuteRequest, signal?: AbortSignal): Promise<BrowserExecuteResult>;
|
|
640
|
+
/** Execute one fixed browser operation without granting arbitrary page scripting. */
|
|
641
|
+
pageOperation?(session: BrowserSessionId, request: BrowserPageOperationRequest, signal?: AbortSignal): Promise<BrowserExecuteResult>;
|
|
642
|
+
/** Wait until the page is ready (and optional URL/selector match). Honor `signal` for cancellation. */
|
|
643
|
+
waitFor(session: BrowserSessionId, request: BrowserWaitRequest, signal?: AbortSignal): Promise<BrowserWaitResult>;
|
|
644
|
+
/** Produce an AI-friendly snapshot of the active tab. */
|
|
645
|
+
snapshot(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserSnapshotResult>;
|
|
646
|
+
/** Read the active tab's accessibility tree (semantic, interactive nodes). */
|
|
647
|
+
a11y(session: BrowserSessionId, request: BrowserA11yRequest, signal?: AbortSignal): Promise<BrowserA11yResult>;
|
|
648
|
+
/** Reload the active tab. Honor `signal` for cancellation. */
|
|
649
|
+
reload(session: BrowserSessionId, signal?: AbortSignal): Promise<void>;
|
|
650
|
+
/** Check whether a human-verification challenge is blocking the active tab. */
|
|
651
|
+
detectChallenge(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserChallenge>;
|
|
652
|
+
/** Fetch page content in a requested format. */
|
|
653
|
+
content(session: BrowserSessionId, request: BrowserContentRequest, signal?: AbortSignal): Promise<BrowserContentResult>;
|
|
654
|
+
/**
|
|
655
|
+
* Click at viewport coordinates, or at a located element's center when the
|
|
656
|
+
* request carries a `target`. Honor `signal` for cancellation.
|
|
657
|
+
*/
|
|
658
|
+
click(session: BrowserSessionId, request: BrowserClickRequest | {
|
|
659
|
+
readonly target: BrowserElementTarget;
|
|
660
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
661
|
+
/**
|
|
662
|
+
* Click several points in order, in one round trip.
|
|
663
|
+
*
|
|
664
|
+
* Exists because a canvas page accepts only genuine input: one click per call meant two calls
|
|
665
|
+
* per cell on a 9x9 board. Stops at the first point that fails rather than pressing through a
|
|
666
|
+
* page that has moved under it, and reports how far it got.
|
|
667
|
+
* @param session - the session to click in.
|
|
668
|
+
* @param request - the points and the interval between them.
|
|
669
|
+
* @param signal - cancellation between points.
|
|
670
|
+
*/
|
|
671
|
+
clickSequence(session: BrowserSessionId, request: BrowserClickSequenceRequest, signal?: AbortSignal): Promise<BrowserClickSequenceResult>;
|
|
672
|
+
/**
|
|
673
|
+
* Type into the focused element, or focus a located element first when the
|
|
674
|
+
* request carries a `target`. Honor `signal` for cancellation.
|
|
675
|
+
*/
|
|
676
|
+
type(session: BrowserSessionId, request: BrowserTypeRequest | {
|
|
677
|
+
readonly target: BrowserElementTarget;
|
|
678
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
679
|
+
/** Set one element's value (native setter + input/change events). */
|
|
680
|
+
setValue(session: BrowserSessionId, request: BrowserSetValueRequest, signal?: AbortSignal): Promise<BrowserSetValueResult>;
|
|
681
|
+
/** Check or uncheck one checkbox/radio. */
|
|
682
|
+
check(session: BrowserSessionId, request: BrowserCheckRequest, signal?: AbortSignal): Promise<{
|
|
683
|
+
readonly checked: boolean;
|
|
684
|
+
}>;
|
|
685
|
+
/** Select one option of a `<select>`. */
|
|
686
|
+
selectOption(session: BrowserSessionId, request: BrowserSelectRequest, signal?: AbortSignal): Promise<BrowserSelectResult>;
|
|
687
|
+
/** Clear one input/textarea/contenteditable (or uncheck). */
|
|
688
|
+
clearField(session: BrowserSessionId, request: BrowserClearRequest, signal?: AbortSignal): Promise<{
|
|
689
|
+
readonly cleared: boolean;
|
|
690
|
+
}>;
|
|
691
|
+
/** Read one element's current value (for verification). */
|
|
692
|
+
getValue(session: BrowserSessionId, request: BrowserGetValueRequest, signal?: AbortSignal): Promise<BrowserGetValueResult>;
|
|
693
|
+
/** Extract structured data from repeated DOM items (static CSS, CSP-safe). */
|
|
694
|
+
scrape(session: BrowserSessionId, request: BrowserScrapeRequest, signal?: AbortSignal): Promise<BrowserScrapeResult>;
|
|
695
|
+
/** Scroll the active tab. Honor `signal` for cancellation. */
|
|
696
|
+
scroll(session: BrowserSessionId, request: BrowserScrollRequest, signal?: AbortSignal): Promise<void>;
|
|
697
|
+
/** Go back in the active tab's history. Honor `signal` for cancellation. */
|
|
698
|
+
back(session: BrowserSessionId, signal?: AbortSignal): Promise<void>;
|
|
699
|
+
/** Go forward in the active tab's history. Honor `signal` for cancellation. */
|
|
700
|
+
forward(session: BrowserSessionId, signal?: AbortSignal): Promise<void>;
|
|
701
|
+
/** Press one named key (Enter/Tab/arrows/…). Honor `signal` for cancellation. */
|
|
702
|
+
key(session: BrowserSessionId, request: BrowserKeyRequest, signal?: AbortSignal): Promise<void>;
|
|
703
|
+
/** Fill a form's fields in one batch. Honor `signal` for cancellation. */
|
|
704
|
+
fillForm(session: BrowserSessionId, request: BrowserFillRequest, signal?: AbortSignal): Promise<BrowserFillResult>;
|
|
705
|
+
/** Capture the current page. Honor `signal` for cancellation. */
|
|
706
|
+
screenshot(session: BrowserSessionId, request?: BrowserScreenshotRequest, signal?: AbortSignal): Promise<BrowserScreenshotResult>;
|
|
707
|
+
/**
|
|
708
|
+
* Capture the active page WITHOUT presenting it, for a remote live view (issue #34).
|
|
709
|
+
*
|
|
710
|
+
* Optional, and it must stay optional: a third-party provider that cannot do this simply does not
|
|
711
|
+
* offer watching, while every existing tool keeps working. That is the design's requirement, not
|
|
712
|
+
* a convenience — a mandatory member would make every provider implement a feature most never
|
|
713
|
+
* need.
|
|
714
|
+
*
|
|
715
|
+
* The contract is narrower than {@link screenshot} in every direction: viewport only, no save
|
|
716
|
+
* path, no full page, and no side effects on what the host displays. A provider that would have to
|
|
717
|
+
* focus, restore, expand or recreate anything to produce a frame must throw
|
|
718
|
+
* BROWSER_PREVIEW_UNAVAILABLE instead — the viewer shows a paused state, it does not rearrange the
|
|
719
|
+
* host's screen.
|
|
720
|
+
*/
|
|
721
|
+
capturePassive?(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserPreviewFrame>;
|
|
722
|
+
/**
|
|
723
|
+
* The sessions a viewer may watch. Only meaningful alongside {@link capturePassive}.
|
|
724
|
+
*
|
|
725
|
+
* Exists because the provider names its sessions and the browser page cannot know one; served as
|
|
726
|
+
* ids only, so the panel can address a session without being told what is in it.
|
|
727
|
+
*/
|
|
728
|
+
watchableSessions?(): readonly BrowserSessionId[];
|
|
729
|
+
/** Download a URL to a local file. Honor `signal` for cancellation. */
|
|
730
|
+
download(session: BrowserSessionId, request: BrowserDownloadRequest, signal?: AbortSignal): Promise<{
|
|
731
|
+
readonly path: string;
|
|
732
|
+
}>;
|
|
733
|
+
/** Export the session's cookies (login state). */
|
|
734
|
+
flushAuth(session: BrowserSessionId): Promise<readonly ExportedCookie[]>;
|
|
735
|
+
/** Import cookies into the session (restore login state). */
|
|
736
|
+
restoreAuth(session: BrowserSessionId, cookies: readonly ExportedCookie[]): Promise<number>;
|
|
737
|
+
/** Return the session's chronological operation log. */
|
|
738
|
+
history(session: BrowserSessionId): Promise<readonly BrowserHistoryEntry[]>;
|
|
739
|
+
/**
|
|
740
|
+
* Persisted visits, newest first: what survives the browser process, so a
|
|
741
|
+
* human or an Agent can find a page again after the interface was closed.
|
|
742
|
+
* @param options - result cap and an optional hostname filter.
|
|
743
|
+
* @returns the retained visits (empty when history is disabled).
|
|
744
|
+
*/
|
|
745
|
+
visited(options?: {
|
|
746
|
+
readonly limit?: number;
|
|
747
|
+
readonly domain?: string;
|
|
748
|
+
}): readonly VisitedPage[];
|
|
749
|
+
/**
|
|
750
|
+
* Optional: whether a session is still live. A session can end outside the
|
|
751
|
+
* tool layer — the human closed the browser window — so a cached id must be
|
|
752
|
+
* checked before it is reused. Providers that never end a session on their own
|
|
753
|
+
* can omit this, and callers treat absence as "still live".
|
|
754
|
+
* @param session - the session id to test.
|
|
755
|
+
*/
|
|
756
|
+
exists?(session: BrowserSessionId): boolean;
|
|
757
|
+
/** Replay one recorded operation by sequence number. */
|
|
758
|
+
replay(session: BrowserSessionId, seq: number): Promise<void>;
|
|
759
|
+
/** Close the session and destroy its backing surface. Idempotent. */
|
|
760
|
+
close(session: BrowserSessionId): Promise<void>;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* One visited page in the persistent browsing history — the durable record that
|
|
764
|
+
* outlives sessions, unlike {@link BrowserHistoryEntry}, which is a
|
|
765
|
+
* session-scoped operation log (navigate/click/type/…).
|
|
766
|
+
*/
|
|
767
|
+
interface VisitedPage {
|
|
768
|
+
/** Epoch milliseconds when the visit was recorded. */
|
|
769
|
+
readonly at: number;
|
|
770
|
+
/** Absolute URL of the visited document. */
|
|
771
|
+
readonly url: string;
|
|
772
|
+
/** Document title at visit time, when the page exposed one. */
|
|
773
|
+
readonly title?: string;
|
|
774
|
+
/** Session/task label that drove the visit, when the provider knows it. */
|
|
775
|
+
readonly session?: string;
|
|
776
|
+
}
|
|
777
|
+
/** One recorded browser operation, in chronological order (seq 1, 2, 3…). */
|
|
778
|
+
interface BrowserHistoryEntry {
|
|
779
|
+
/** Monotonic sequence number within the session. */
|
|
780
|
+
readonly seq: number;
|
|
781
|
+
/** The operation name. Replayable: navigate | execute | click | type.
|
|
782
|
+
* Also recorded (non-replayable): fill | download | flushAuth | restoreAuth. */
|
|
783
|
+
readonly action: string;
|
|
784
|
+
/** The operation's arguments. */
|
|
785
|
+
readonly params: Record<string, unknown>;
|
|
786
|
+
/** Whether the operation succeeded. */
|
|
787
|
+
readonly ok: boolean;
|
|
788
|
+
/** Truncated result text, when the operation returned one. */
|
|
789
|
+
readonly result?: string;
|
|
790
|
+
/** Error text, when the operation failed. */
|
|
791
|
+
readonly error?: string;
|
|
792
|
+
/** Epoch millis of the operation. */
|
|
793
|
+
readonly at: number;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Typed browser error with a machine-routable, open-string `code` and chained
|
|
797
|
+
* `cause`. Consumers must tolerate provider-specific codes. Shared codes cover
|
|
798
|
+
* unavailable, missing, unusable, ambiguous, or duplicate providers, unknown
|
|
799
|
+
* or closed sessions, cancellation, and provider failure; a provider adds its
|
|
800
|
+
* own (e.g. `BROWSER_CDP_ATTACH_FAILED`).
|
|
801
|
+
*/
|
|
802
|
+
export declare class BrowserError extends HarnessError {}
|
|
803
|
+
declare module '@deepseek-ai/cordis' {
|
|
804
|
+
interface Context {
|
|
805
|
+
browser: BrowserRuntime;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Config for the browser seam. `browserProvider` pins which provider wins;
|
|
810
|
+
* it is optional (a single registered usable provider auto-selects).
|
|
811
|
+
*/
|
|
812
|
+
interface BrowserRuntimeConfig {
|
|
813
|
+
/** Explicit browser provider id. Omitted = auto-select when exactly one usable. */
|
|
814
|
+
readonly browserProvider?: string;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* The browser access service. Registered as `ctx.browser` (one instance per
|
|
818
|
+
* context).
|
|
819
|
+
*
|
|
820
|
+
* Selection semantics (resolved at execution time, never order-dependent):
|
|
821
|
+
* - A configured id that is registered and `available()` → that provider.
|
|
822
|
+
* - A configured id not registered → `BROWSER_PROVIDER_CONFIGURED_MISSING`.
|
|
823
|
+
* - A configured id registered but unavailable → `BROWSER_PROVIDER_CONFIGURED_UNAVAILABLE`.
|
|
824
|
+
* - No id configured, exactly one registered usable provider → that provider.
|
|
825
|
+
* - No id configured, multiple usable providers → `BROWSER_PROVIDER_AMBIGUOUS`.
|
|
826
|
+
* - No id configured, no usable provider → `BROWSER_PROVIDER_UNAVAILABLE`.
|
|
827
|
+
*/
|
|
828
|
+
export declare class BrowserRuntime extends Service {
|
|
829
|
+
/** Provider selection config. */
|
|
830
|
+
static Config: z<BrowserRuntimeConfig>;
|
|
831
|
+
private providers;
|
|
832
|
+
private readonly providerId;
|
|
833
|
+
constructor(ctx: Context, config?: BrowserRuntimeConfig);
|
|
834
|
+
/**
|
|
835
|
+
* Register a browser provider. Throws {@link BrowserError}
|
|
836
|
+
* `BROWSER_DUPLICATE_PROVIDER` if its id is already registered. Returns a
|
|
837
|
+
* disposer; disposed with the calling fiber.
|
|
838
|
+
* @param provider - the provider; its `id` is the registry key.
|
|
839
|
+
* @returns the disposer that unregisters the provider.
|
|
840
|
+
*/
|
|
841
|
+
registerBrowserProvider(provider: BrowserProvider): () => void;
|
|
842
|
+
/** Resolve the selected provider or throw the matching {@link BrowserError}. */
|
|
843
|
+
private resolveProvider;
|
|
844
|
+
/** Open a new browser session through the selected provider. */
|
|
845
|
+
open(label?: string): Promise<BrowserSessionId>;
|
|
846
|
+
/** Open a URL through the selected provider, optionally in a new tab. */
|
|
847
|
+
openUrl(session: BrowserSessionId, request: BrowserOpenRequest, signal?: AbortSignal): Promise<void>;
|
|
848
|
+
/** List the session's tabs through the selected provider. */
|
|
849
|
+
listTabs(session: BrowserSessionId): Promise<readonly BrowserTab[]>;
|
|
850
|
+
/** Switch to a tab through the selected provider. */
|
|
851
|
+
switchTab(session: BrowserSessionId, tabId: string): Promise<void>;
|
|
852
|
+
/** Close one tab through the selected provider. */
|
|
853
|
+
closeTab(session: BrowserSessionId, tabId: string): Promise<void>;
|
|
854
|
+
/** Close every tab and reset the session through the selected provider. */
|
|
855
|
+
reset(session: BrowserSessionId): Promise<void>;
|
|
856
|
+
/** Navigate the session's page through the selected provider. */
|
|
857
|
+
navigate(session: BrowserSessionId, request: BrowserNavigateRequest, signal?: AbortSignal): Promise<void>;
|
|
858
|
+
/** Execute JS in the session's page context through the selected provider. */
|
|
859
|
+
execute(session: BrowserSessionId, request: BrowserExecuteRequest, signal?: AbortSignal): Promise<BrowserExecuteResult>;
|
|
860
|
+
/** Execute one provider-owned page operation with validated operation names. */
|
|
861
|
+
pageOperation(session: BrowserSessionId, request: BrowserPageOperationRequest, signal?: AbortSignal): Promise<BrowserExecuteResult>;
|
|
862
|
+
/** Wait until the session's page is ready (and optional URL/selector match). */
|
|
863
|
+
waitFor(session: BrowserSessionId, request: BrowserWaitRequest, signal?: AbortSignal): Promise<BrowserWaitResult>;
|
|
864
|
+
/** Produce an AI-friendly snapshot of the session's page. */
|
|
865
|
+
snapshot(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserSnapshotResult>;
|
|
866
|
+
/** Read the session's page accessibility tree through the selected provider. */
|
|
867
|
+
a11y(session: BrowserSessionId, request: BrowserA11yRequest, signal?: AbortSignal): Promise<BrowserA11yResult>;
|
|
868
|
+
/** Reload the session's active tab through the selected provider. */
|
|
869
|
+
reload(session: BrowserSessionId, signal?: AbortSignal): Promise<void>;
|
|
870
|
+
/** Fetch page content in a requested format. */
|
|
871
|
+
content(session: BrowserSessionId, request: BrowserContentRequest, signal?: AbortSignal): Promise<BrowserContentResult>;
|
|
872
|
+
/** Click at viewport coordinates (or a located element) through the selected provider. */
|
|
873
|
+
click(session: BrowserSessionId, request: BrowserClickRequest | {
|
|
874
|
+
readonly target: BrowserElementTarget;
|
|
875
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
876
|
+
/** Click several points in order through the selected provider. */
|
|
877
|
+
clickSequence(session: BrowserSessionId, request: BrowserClickSequenceRequest, signal?: AbortSignal): Promise<BrowserClickSequenceResult>;
|
|
878
|
+
/** Type into the focused element (or a located one) through the selected provider. */
|
|
879
|
+
type(session: BrowserSessionId, request: BrowserTypeRequest | {
|
|
880
|
+
readonly target: BrowserElementTarget;
|
|
881
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
882
|
+
/** Scroll the session's page through the selected provider. */
|
|
883
|
+
scroll(session: BrowserSessionId, request: BrowserScrollRequest, signal?: AbortSignal): Promise<void>;
|
|
884
|
+
/** Go back in the session's page history through the selected provider. */
|
|
885
|
+
back(session: BrowserSessionId, signal?: AbortSignal): Promise<void>;
|
|
886
|
+
/** Go forward in the session's page history through the selected provider. */
|
|
887
|
+
forward(session: BrowserSessionId, signal?: AbortSignal): Promise<void>;
|
|
888
|
+
/** Press one named key through the selected provider. */
|
|
889
|
+
key(session: BrowserSessionId, request: BrowserKeyRequest, signal?: AbortSignal): Promise<void>;
|
|
890
|
+
/** Fill a form's fields in one batch through the selected provider. */
|
|
891
|
+
fillForm(session: BrowserSessionId, request: BrowserFillRequest, signal?: AbortSignal): Promise<BrowserFillResult>;
|
|
892
|
+
/** Set one element's value through the selected provider. */
|
|
893
|
+
setValue(session: BrowserSessionId, request: BrowserSetValueRequest, signal?: AbortSignal): Promise<BrowserSetValueResult>;
|
|
894
|
+
/** Check or uncheck one checkbox/radio through the selected provider. */
|
|
895
|
+
check(session: BrowserSessionId, request: BrowserCheckRequest, signal?: AbortSignal): Promise<{
|
|
896
|
+
readonly checked: boolean;
|
|
897
|
+
}>;
|
|
898
|
+
/** Select one option of a `<select>` through the selected provider. */
|
|
899
|
+
selectOption(session: BrowserSessionId, request: BrowserSelectRequest, signal?: AbortSignal): Promise<BrowserSelectResult>;
|
|
900
|
+
/** Clear one element through the selected provider. */
|
|
901
|
+
clearField(session: BrowserSessionId, request: BrowserClearRequest, signal?: AbortSignal): Promise<{
|
|
902
|
+
readonly cleared: boolean;
|
|
903
|
+
}>;
|
|
904
|
+
/** Read one element's value through the selected provider. */
|
|
905
|
+
getValue(session: BrowserSessionId, request: BrowserGetValueRequest, signal?: AbortSignal): Promise<BrowserGetValueResult>;
|
|
906
|
+
/** Extract structured data through the selected provider. */
|
|
907
|
+
scrape(session: BrowserSessionId, request: BrowserScrapeRequest, signal?: AbortSignal): Promise<BrowserScrapeResult>;
|
|
908
|
+
/** Capture the current page through the selected provider. */
|
|
909
|
+
screenshot(session: BrowserSessionId, request?: BrowserScreenshotRequest, signal?: AbortSignal): Promise<BrowserScreenshotResult>;
|
|
910
|
+
/**
|
|
911
|
+
* Capture the active page without presenting it, through the selected provider.
|
|
912
|
+
*
|
|
913
|
+
* Optional throughout: a provider that cannot do this keeps working for every other tool, and the
|
|
914
|
+
* caller gets exactly one error code meaning "watching is not available here" — which the viewer
|
|
915
|
+
* renders as paused rather than as a failure of the browser.
|
|
916
|
+
* @param session - the session whose active page to capture.
|
|
917
|
+
* @param signal - cancellation for the wait, never for the capture itself.
|
|
918
|
+
* @returns the encoded frame.
|
|
919
|
+
*/
|
|
920
|
+
capturePassive(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserPreviewFrame>;
|
|
921
|
+
/** Check for a human-verification challenge on the active tab. */
|
|
922
|
+
detectChallenge(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserChallenge>;
|
|
923
|
+
/** Return the session's chronological operation log through the provider. */
|
|
924
|
+
history(session: BrowserSessionId): Promise<readonly BrowserHistoryEntry[]>;
|
|
925
|
+
/**
|
|
926
|
+
* Persisted visits, newest first — the record that outlives the browser
|
|
927
|
+
* process, as opposed to {@link history}'s session-scoped operation log.
|
|
928
|
+
* @param options - result cap and an optional hostname filter.
|
|
929
|
+
* @returns the retained visits (empty when history recording is disabled).
|
|
930
|
+
*/
|
|
931
|
+
visited(options?: {
|
|
932
|
+
readonly limit?: number;
|
|
933
|
+
readonly domain?: string;
|
|
934
|
+
}): readonly VisitedPage[];
|
|
935
|
+
/**
|
|
936
|
+
* Whether a session is still live. Sessions can end outside the tool layer
|
|
937
|
+
* (the human closed its window), so a cached id must be re-checked before
|
|
938
|
+
* reuse; a provider that does not implement the check counts as live.
|
|
939
|
+
* @param session - the session id to test.
|
|
940
|
+
*/
|
|
941
|
+
exists(session: BrowserSessionId): boolean;
|
|
942
|
+
/**
|
|
943
|
+
* The sessions a viewer may watch, through the selected provider.
|
|
944
|
+
*
|
|
945
|
+
* Empty when the provider cannot preview at all: a viewer then has nothing to offer, which is the
|
|
946
|
+
* honest answer rather than an error.
|
|
947
|
+
* @returns the live session ids.
|
|
948
|
+
*/
|
|
949
|
+
watchableSessions(): readonly BrowserSessionId[];
|
|
950
|
+
/** Replay one recorded operation by sequence number through the provider. */
|
|
951
|
+
replay(session: BrowserSessionId, seq: number): Promise<void>;
|
|
952
|
+
/** Download a URL to a local file through the provider. */
|
|
953
|
+
download(session: BrowserSessionId, request: BrowserDownloadRequest, signal?: AbortSignal): Promise<{
|
|
954
|
+
readonly path: string;
|
|
955
|
+
}>;
|
|
956
|
+
/** Export the session's cookies through the provider. */
|
|
957
|
+
flushAuth(session: BrowserSessionId): Promise<readonly ExportedCookie[]>;
|
|
958
|
+
/** Import cookies into the session through the provider. */
|
|
959
|
+
restoreAuth(session: BrowserSessionId, cookies: readonly ExportedCookie[]): Promise<number>;
|
|
960
|
+
/** Close the session through the selected provider. Idempotent; a missing
|
|
961
|
+
* provider is treated as already-closed so teardown paths stay no-ops. */
|
|
962
|
+
close(session: BrowserSessionId): Promise<void>;
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Browser reference records: what the user pointed at in a page, in a form a
|
|
966
|
+
* later reveal can verify. One reference is an immutable snapshot of ordered
|
|
967
|
+
* parts; re-capturing the same region produces a new reference instead of
|
|
968
|
+
* mutating this one.
|
|
969
|
+
*
|
|
970
|
+
* The protocol is deliberately provider-scoped (`dsh-browser`) so other plugins
|
|
971
|
+
* can own their own reference namespaces without sharing this schema.
|
|
972
|
+
* @module dsh-browser/browser-reference/types
|
|
973
|
+
*/
|
|
974
|
+
/** Where the capture happened; reveal routes back to the same carrier. */
|
|
975
|
+
type BrowserReferenceCarrier = 'sidebar' | 'bundled' | 'chrome' | 'edge';
|
|
976
|
+
/** How the user asked for the reference. */
|
|
977
|
+
type BrowserReferenceEntry = 'native-menu' | 'extension-action' | 'page-overlay' | 'agent-tool';
|
|
978
|
+
/** Who selected the content: a human in the page, or the agent's own read. */
|
|
979
|
+
type BrowserReferenceOrigin = 'user-selection' | 'agent-excerpt';
|
|
980
|
+
/** A text quote selector: the selected text plus enough context to be unique. */
|
|
981
|
+
interface TextQuoteAnchor {
|
|
982
|
+
/** The selected text itself, original whitespace preserved. */
|
|
983
|
+
readonly exact: string;
|
|
984
|
+
/** Up to N characters immediately before the selection, for disambiguation. */
|
|
985
|
+
readonly prefix: string;
|
|
986
|
+
/** Up to N characters immediately after the selection. */
|
|
987
|
+
readonly suffix: string;
|
|
988
|
+
}
|
|
989
|
+
/** One ordered piece of a reference. */
|
|
990
|
+
interface TextReferencePart {
|
|
991
|
+
readonly partId: string;
|
|
992
|
+
readonly type: 'text';
|
|
993
|
+
readonly text: string;
|
|
994
|
+
readonly anchor: TextQuoteAnchor;
|
|
995
|
+
}
|
|
996
|
+
/** How an image element was found when the reference was captured. */
|
|
997
|
+
interface ImageAnchor {
|
|
998
|
+
/** The resolved source the browser was showing. */
|
|
999
|
+
readonly src?: string;
|
|
1000
|
+
/** `HTMLImageElement.currentSrc`, when the browser exposed one. */
|
|
1001
|
+
readonly currentSrc?: string;
|
|
1002
|
+
readonly alt?: string;
|
|
1003
|
+
/** Best-effort CSS selector, a hint only. */
|
|
1004
|
+
readonly selector?: string;
|
|
1005
|
+
/** Viewport geometry at capture time, a hint only. */
|
|
1006
|
+
readonly geometry?: {
|
|
1007
|
+
readonly x: number;
|
|
1008
|
+
readonly y: number;
|
|
1009
|
+
readonly w: number;
|
|
1010
|
+
readonly h: number;
|
|
1011
|
+
};
|
|
1012
|
+
/** Present only for a visible-region snapshot: how the region was masked and clipped. */
|
|
1013
|
+
readonly visible?: {
|
|
1014
|
+
readonly rects: number;
|
|
1015
|
+
readonly partiallyVisible: boolean;
|
|
1016
|
+
readonly clip: {
|
|
1017
|
+
readonly x: number;
|
|
1018
|
+
readonly y: number;
|
|
1019
|
+
readonly width: number;
|
|
1020
|
+
readonly height: number;
|
|
1021
|
+
};
|
|
1022
|
+
readonly dpr: number;
|
|
1023
|
+
readonly visualScale: number;
|
|
1024
|
+
readonly viewport: {
|
|
1025
|
+
readonly width: number;
|
|
1026
|
+
readonly height: number;
|
|
1027
|
+
};
|
|
1028
|
+
readonly scroll: {
|
|
1029
|
+
readonly x: number;
|
|
1030
|
+
readonly y: number;
|
|
1031
|
+
};
|
|
1032
|
+
};
|
|
1033
|
+
/** Whether the saved bytes could be checked against the page session's own copy. */
|
|
1034
|
+
readonly versionStatus?: 'verified' | 'changed' | 'unverifiable';
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* An image part. `representation` says what was actually saved, never what the
|
|
1038
|
+
* page claimed: a source image, a rasterised vector, or a visible-region snapshot.
|
|
1039
|
+
*/
|
|
1040
|
+
interface ImageReferencePart {
|
|
1041
|
+
readonly partId: string;
|
|
1042
|
+
readonly type: 'image';
|
|
1043
|
+
readonly assetKey: string;
|
|
1044
|
+
readonly representation: 'source-image' | 'rasterized-image' | 'visible-snapshot';
|
|
1045
|
+
readonly alt?: string;
|
|
1046
|
+
readonly caption?: string;
|
|
1047
|
+
readonly anchor: ImageAnchor;
|
|
1048
|
+
}
|
|
1049
|
+
/** One inline run of a table cell, in reading order. */
|
|
1050
|
+
type TableCellRun = {
|
|
1051
|
+
readonly type: 'text';
|
|
1052
|
+
readonly text: string;
|
|
1053
|
+
} | {
|
|
1054
|
+
readonly type: 'image';
|
|
1055
|
+
readonly partId: string;
|
|
1056
|
+
readonly assetKey: string;
|
|
1057
|
+
};
|
|
1058
|
+
/** One cell of a table snapshot, including its merge and selection facts. */
|
|
1059
|
+
interface TableCellSnapshot {
|
|
1060
|
+
readonly row: number;
|
|
1061
|
+
readonly column: number;
|
|
1062
|
+
readonly rowSpan: number;
|
|
1063
|
+
readonly columnSpan: number;
|
|
1064
|
+
readonly role: 'header' | 'data';
|
|
1065
|
+
readonly text: string;
|
|
1066
|
+
readonly includedAs: 'selection' | 'header-context';
|
|
1067
|
+
readonly partialText: boolean;
|
|
1068
|
+
/** Text and image runs in reading order; images carry their own partId/assetKey. */
|
|
1069
|
+
readonly inlineContent?: readonly TableCellRun[];
|
|
1070
|
+
}
|
|
1071
|
+
/** How a table was found when the reference was captured. */
|
|
1072
|
+
interface TableAnchor {
|
|
1073
|
+
readonly selector?: string;
|
|
1074
|
+
readonly caption?: string;
|
|
1075
|
+
/** Header texts, used to recognise the same table after re-sorting. */
|
|
1076
|
+
readonly headers: readonly string[];
|
|
1077
|
+
/** First-row cell texts, a weaker hint than the headers. */
|
|
1078
|
+
readonly firstCells: readonly string[];
|
|
1079
|
+
/** Which cell was selected, for highlighting the exact cell. */
|
|
1080
|
+
readonly cell?: {
|
|
1081
|
+
readonly row: number;
|
|
1082
|
+
readonly column: number;
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
/** A structural table snapshot; Markdown/TSV are projections of this, not replacements. */
|
|
1086
|
+
interface TableSnapshot {
|
|
1087
|
+
readonly rowCount: number;
|
|
1088
|
+
readonly columnCount: number;
|
|
1089
|
+
readonly cells: readonly TableCellSnapshot[];
|
|
1090
|
+
readonly caption?: string;
|
|
1091
|
+
readonly completeness: 'selected-cells' | 'dom-table' | 'visible-rows' | 'aria-grid';
|
|
1092
|
+
readonly normalizationVersion: string;
|
|
1093
|
+
}
|
|
1094
|
+
/** One ordered piece of a reference. */
|
|
1095
|
+
interface TableReferencePart {
|
|
1096
|
+
readonly partId: string;
|
|
1097
|
+
readonly type: 'table';
|
|
1098
|
+
readonly table: TableSnapshot;
|
|
1099
|
+
readonly anchor: TableAnchor;
|
|
1100
|
+
}
|
|
1101
|
+
/** Any part; `mixed` is derived from a parts array with more than one kind. */
|
|
1102
|
+
type BrowserReferencePart = TextReferencePart | ImageReferencePart | TableReferencePart;
|
|
1103
|
+
/** Where the content came from. */
|
|
1104
|
+
interface BrowserReferenceSource {
|
|
1105
|
+
readonly pageUrl: string;
|
|
1106
|
+
readonly title: string;
|
|
1107
|
+
/** ISO timestamp taken when the snapshot was confirmed, not when capture started. */
|
|
1108
|
+
readonly capturedAt: string;
|
|
1109
|
+
readonly frameUrl?: string;
|
|
1110
|
+
/** The frame that owned the selection. Defaults to 'main'; 'frame' carries a selector. */
|
|
1111
|
+
readonly frameRoute?: 'main' | 'frame';
|
|
1112
|
+
/** Best-effort selector of the owning same-origin iframe, a hint only. */
|
|
1113
|
+
readonly frameSelector?: string;
|
|
1114
|
+
readonly carrier: BrowserReferenceCarrier;
|
|
1115
|
+
}
|
|
1116
|
+
/** One immutable capture, addressed by `dsh-browser-ref:<referenceId>/<partId?>`. */
|
|
1117
|
+
interface BrowserReference {
|
|
1118
|
+
/** Protocol version for this provider's records. */
|
|
1119
|
+
readonly version: 1;
|
|
1120
|
+
readonly provider: 'dsh-browser';
|
|
1121
|
+
readonly referenceId: string;
|
|
1122
|
+
/** Session that received the reference; absent only for an unbound agent excerpt. */
|
|
1123
|
+
readonly owner: {
|
|
1124
|
+
readonly sessionId?: string;
|
|
1125
|
+
/**
|
|
1126
|
+
* The plugin's browser session holding the page. A DSH session and a browser
|
|
1127
|
+
* session are different ids; reveal needs the runtime handle, and it can
|
|
1128
|
+
* outlive the conversation that first asked for the page.
|
|
1129
|
+
*/
|
|
1130
|
+
readonly browserSessionId?: string;
|
|
1131
|
+
};
|
|
1132
|
+
readonly provenance: {
|
|
1133
|
+
readonly origin: BrowserReferenceOrigin;
|
|
1134
|
+
readonly entry: BrowserReferenceEntry;
|
|
1135
|
+
};
|
|
1136
|
+
readonly source: BrowserReferenceSource;
|
|
1137
|
+
readonly parts: readonly BrowserReferencePart[];
|
|
1138
|
+
/**
|
|
1139
|
+
* The user's own note, captured with the reference (three-state §3). It is a
|
|
1140
|
+
* separate field from the page snapshot: editing it later never rewrites the
|
|
1141
|
+
* quoted original, and `manifestHashOf` deliberately excludes it so an edit
|
|
1142
|
+
* does not invalidate the capture.
|
|
1143
|
+
*/
|
|
1144
|
+
readonly comment?: string;
|
|
1145
|
+
/** SHA-256 over the canonical snapshot fields; detects tampering and duplicate conflicts. */
|
|
1146
|
+
readonly manifestHash: string;
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* An explicit right-click target. A selection may collapse while the native
|
|
1150
|
+
* menu is open, so the action names the object it was invoked on instead of
|
|
1151
|
+
* re-reading the selection (§3.2 / §3.3).
|
|
1152
|
+
*/
|
|
1153
|
+
interface BrowserReferenceTarget {
|
|
1154
|
+
readonly kind: 'text' | 'image' | 'table';
|
|
1155
|
+
/** Source URL reported by the browser for an image target. */
|
|
1156
|
+
readonly srcUrl?: string;
|
|
1157
|
+
/** View-relative pointer position, a DOM hint only. */
|
|
1158
|
+
readonly x?: number;
|
|
1159
|
+
readonly y?: number;
|
|
1160
|
+
}
|
|
1161
|
+
/** Retention limits; whichever is hit first starts trimming. */
|
|
1162
|
+
interface ReferenceLimits {
|
|
1163
|
+
/** Maximum retained references. Default 2000. */
|
|
1164
|
+
readonly maxEntries?: number;
|
|
1165
|
+
}
|
|
1166
|
+
/** Absolute path of the reference file, beside the browser profile. */
|
|
1167
|
+
export declare function referenceStorePath(): string;
|
|
1168
|
+
/**
|
|
1169
|
+
* Hash the immutable fields of a reference.
|
|
1170
|
+
* @param reference - a reference with or without its `manifestHash`.
|
|
1171
|
+
* @returns the SHA-256 hex digest.
|
|
1172
|
+
*/
|
|
1173
|
+
export declare function manifestHashOf(reference: Omit<BrowserReference, 'manifestHash'> | BrowserReference): string;
|
|
1174
|
+
/** Result of one append attempt. */
|
|
1175
|
+
type AppendResult = 'added' | 'duplicate';
|
|
1176
|
+
/** The reference store for one file. */
|
|
1177
|
+
export declare class ReferenceStore {
|
|
1178
|
+
private readonly limits;
|
|
1179
|
+
private readonly path;
|
|
1180
|
+
constructor(path?: string, limits?: ReferenceLimits);
|
|
1181
|
+
private get maxEntries();
|
|
1182
|
+
/**
|
|
1183
|
+
* Append one immutable reference.
|
|
1184
|
+
* @param reference - the snapshot to store.
|
|
1185
|
+
* @returns `added`, or `duplicate` when the identical snapshot is already stored.
|
|
1186
|
+
* @throws Error when the same `referenceId` exists with different content.
|
|
1187
|
+
*/
|
|
1188
|
+
append(reference: BrowserReference): AppendResult;
|
|
1189
|
+
/** Read one reference by id. */
|
|
1190
|
+
get(referenceId: string): BrowserReference | undefined;
|
|
1191
|
+
/**
|
|
1192
|
+
* List references, newest last.
|
|
1193
|
+
* @param filter - optional session and page filters.
|
|
1194
|
+
* @returns the matching references.
|
|
1195
|
+
*/
|
|
1196
|
+
list(filter?: {
|
|
1197
|
+
readonly sessionId?: string;
|
|
1198
|
+
readonly pageUrl?: string;
|
|
1199
|
+
readonly limit?: number;
|
|
1200
|
+
}): BrowserReference[];
|
|
1201
|
+
/** Number of readable records. */
|
|
1202
|
+
count(): number;
|
|
1203
|
+
/** Rewrite the file keeping only the newest `maxEntries` records. */
|
|
1204
|
+
prune(): void;
|
|
1205
|
+
}
|
|
1206
|
+
/** Output shapes the local library can produce without a conversation host. */
|
|
1207
|
+
type ReferenceExportFormat = 'jsonl' | 'markdown' | 'zip' | 'markdown-zip';
|
|
1208
|
+
/** CDP `Page.captureScreenshot` clip, in document CSS pixels. */
|
|
1209
|
+
interface VisibleClip {
|
|
1210
|
+
readonly x: number;
|
|
1211
|
+
readonly y: number;
|
|
1212
|
+
readonly width: number;
|
|
1213
|
+
readonly height: number;
|
|
1214
|
+
readonly scale: 1;
|
|
1215
|
+
}
|
|
1216
|
+
/** What a host must return for one visible-region screenshot. */
|
|
1217
|
+
interface VisibleCaptureResult {
|
|
1218
|
+
readonly dataUrl: string;
|
|
1219
|
+
readonly mime: string;
|
|
1220
|
+
}
|
|
1221
|
+
/** One raw reference part as the page produced it, before host validation. */
|
|
1222
|
+
interface RawCaptureEvent {
|
|
1223
|
+
readonly kind?: string;
|
|
1224
|
+
readonly exact?: string;
|
|
1225
|
+
readonly prefix?: string;
|
|
1226
|
+
readonly suffix?: string;
|
|
1227
|
+
readonly src?: string;
|
|
1228
|
+
readonly currentSrc?: string;
|
|
1229
|
+
readonly attributeSrc?: string;
|
|
1230
|
+
readonly alt?: string;
|
|
1231
|
+
readonly caption?: string;
|
|
1232
|
+
readonly selector?: string;
|
|
1233
|
+
readonly path?: readonly number[];
|
|
1234
|
+
readonly svg?: boolean;
|
|
1235
|
+
readonly canvas?: boolean;
|
|
1236
|
+
/** Canvas pixels captured in the page; validated and hashed host-side. */
|
|
1237
|
+
readonly dataUrl?: string;
|
|
1238
|
+
readonly width?: number;
|
|
1239
|
+
readonly height?: number;
|
|
1240
|
+
readonly geometry?: {
|
|
1241
|
+
readonly x: number;
|
|
1242
|
+
readonly y: number;
|
|
1243
|
+
readonly w: number;
|
|
1244
|
+
readonly h: number;
|
|
1245
|
+
};
|
|
1246
|
+
readonly table?: RawTable;
|
|
1247
|
+
}
|
|
1248
|
+
/** Raw table snapshot; cell shapes are validated host-side. */
|
|
1249
|
+
interface RawTable {
|
|
1250
|
+
readonly rowCount?: number;
|
|
1251
|
+
readonly columnCount?: number;
|
|
1252
|
+
readonly caption?: string;
|
|
1253
|
+
readonly completeness?: string;
|
|
1254
|
+
readonly truncated?: boolean;
|
|
1255
|
+
readonly cells?: readonly RawCell[];
|
|
1256
|
+
}
|
|
1257
|
+
/** Raw cell snapshot, including inline runs. */
|
|
1258
|
+
interface RawCell {
|
|
1259
|
+
readonly row?: number;
|
|
1260
|
+
readonly column?: number;
|
|
1261
|
+
readonly rowSpan?: number;
|
|
1262
|
+
readonly columnSpan?: number;
|
|
1263
|
+
readonly role?: string;
|
|
1264
|
+
readonly text?: string;
|
|
1265
|
+
readonly includedAs?: string;
|
|
1266
|
+
readonly partialText?: boolean;
|
|
1267
|
+
readonly inlineContent?: readonly RawCellRun[];
|
|
1268
|
+
}
|
|
1269
|
+
/** One inline run inside a cell: text, or an image the host will materialise. */
|
|
1270
|
+
interface RawCellRun {
|
|
1271
|
+
readonly type?: string;
|
|
1272
|
+
readonly text?: string;
|
|
1273
|
+
readonly src?: string;
|
|
1274
|
+
readonly currentSrc?: string;
|
|
1275
|
+
readonly alt?: string;
|
|
1276
|
+
}
|
|
1277
|
+
/** Capture result. A refusal is a status, not an exception. */
|
|
1278
|
+
interface RawCaptureResult {
|
|
1279
|
+
readonly ok: boolean;
|
|
1280
|
+
readonly reason?: string;
|
|
1281
|
+
readonly url?: string;
|
|
1282
|
+
readonly frameUrl?: string;
|
|
1283
|
+
readonly title?: string;
|
|
1284
|
+
readonly multipleRanges?: boolean;
|
|
1285
|
+
readonly truncated?: boolean;
|
|
1286
|
+
readonly ambiguousExcerpt?: boolean;
|
|
1287
|
+
readonly events?: readonly RawCaptureEvent[];
|
|
1288
|
+
}
|
|
1289
|
+
/** One call into the page; the host supplies this from its carrier. */
|
|
1290
|
+
interface ReferenceEvaluateRequest {
|
|
1291
|
+
readonly script: string;
|
|
1292
|
+
readonly args?: readonly unknown[];
|
|
1293
|
+
readonly timeoutMs?: number;
|
|
1294
|
+
}
|
|
1295
|
+
/** The browser capabilities the service needs, and nothing else. */
|
|
1296
|
+
interface ReferenceHost {
|
|
1297
|
+
/** Evaluate a page script; the value may be the script's JSON string. */
|
|
1298
|
+
evaluate(sessionId: string, request: ReferenceEvaluateRequest, signal?: AbortSignal): Promise<unknown>;
|
|
1299
|
+
/** Whether the owning browser session is still alive. */
|
|
1300
|
+
exists(sessionId: string): boolean;
|
|
1301
|
+
/** Save one URL to a local file with the session's cookies, when the carrier can. */
|
|
1302
|
+
download?(sessionId: string, url: string, savePath: string, signal?: AbortSignal): Promise<void>;
|
|
1303
|
+
/**
|
|
1304
|
+
* Capture a clipped, read-only visible-region screenshot. Optional: a host
|
|
1305
|
+
* without this capability keeps the source-image / rasterised-image paths.
|
|
1306
|
+
*/
|
|
1307
|
+
captureVisible?(sessionId: string, clip: VisibleClip, signal?: AbortSignal): Promise<VisibleCaptureResult>;
|
|
1308
|
+
now?(): Date;
|
|
1309
|
+
newId?(): string;
|
|
1310
|
+
}
|
|
1311
|
+
/** One piece of a capture that could not be committed. */
|
|
1312
|
+
interface CaptureFailure {
|
|
1313
|
+
readonly kind: 'text' | 'image' | 'table' | 'reference';
|
|
1314
|
+
readonly reason: string;
|
|
1315
|
+
/** Anything a caller can show without reading the page again. */
|
|
1316
|
+
readonly detail?: Readonly<Record<string, unknown>>;
|
|
1317
|
+
}
|
|
1318
|
+
/** Result of a capture attempt. `reference` is absent when the group was refused. */
|
|
1319
|
+
interface CaptureOutcome {
|
|
1320
|
+
readonly reference?: BrowserReference;
|
|
1321
|
+
readonly failures: readonly CaptureFailure[];
|
|
1322
|
+
}
|
|
1323
|
+
/** What the caller wants captured. */
|
|
1324
|
+
interface CaptureRequest {
|
|
1325
|
+
/** The DSH session that owns the reference. */
|
|
1326
|
+
readonly sessionId: string;
|
|
1327
|
+
/** The browser session holding the page; defaults to `sessionId`. */
|
|
1328
|
+
readonly browserSessionId?: string;
|
|
1329
|
+
readonly origin?: BrowserReferenceOrigin;
|
|
1330
|
+
readonly entry?: BrowserReferenceEntry;
|
|
1331
|
+
readonly carrier?: BrowserReferenceCarrier;
|
|
1332
|
+
/**
|
|
1333
|
+
* Commit the parts that succeeded even when some failed. The default is the
|
|
1334
|
+
* design's rule: a reference is an ordered whole, so a broken image does not
|
|
1335
|
+
* silently become a missing one.
|
|
1336
|
+
*/
|
|
1337
|
+
readonly allowPartial?: boolean;
|
|
1338
|
+
/** Capture this table even when the selection does not touch it. */
|
|
1339
|
+
readonly tableSelector?: string;
|
|
1340
|
+
/** With no live selection, register this text as an agent excerpt. */
|
|
1341
|
+
readonly excerptText?: string;
|
|
1342
|
+
/**
|
|
1343
|
+
* A complete capture the page bar froze while the selection still existed.
|
|
1344
|
+
* Used verbatim; the page is only re-read to confirm it is still the same
|
|
1345
|
+
* document, so a changed page is reported instead of capturing other text.
|
|
1346
|
+
*/
|
|
1347
|
+
readonly frozenCapture?: RawCaptureResult;
|
|
1348
|
+
/** Capture a same-origin iframe's selection instead of the top document. */
|
|
1349
|
+
readonly frameSelector?: string;
|
|
1350
|
+
/** Capture THIS image/table/text even when the selection has collapsed. */
|
|
1351
|
+
readonly target?: BrowserReferenceTarget;
|
|
1352
|
+
/** The user's own note, stored with the reference and never hashed. */
|
|
1353
|
+
readonly comment?: string;
|
|
1354
|
+
/**
|
|
1355
|
+
* Prove that a downloaded image is the version the page had loaded. Default
|
|
1356
|
+
* true; a page that cannot be probed is reported as unverifiable, not as a
|
|
1357
|
+
* verified match, but does not by itself invalidate the capture.
|
|
1358
|
+
*/
|
|
1359
|
+
readonly verifyImageVersion?: boolean;
|
|
1360
|
+
/** Allow a masked visible-region snapshot when no trustworthy source bytes exist. */
|
|
1361
|
+
readonly allowVisibleSnapshot?: boolean;
|
|
1362
|
+
}
|
|
1363
|
+
/** Per-part reveal result. */
|
|
1364
|
+
interface RevealPartResult {
|
|
1365
|
+
readonly partId: string;
|
|
1366
|
+
readonly type: 'text' | 'image' | 'table';
|
|
1367
|
+
readonly status: 'revealed' | 'ambiguous' | 'missing';
|
|
1368
|
+
readonly matches?: number;
|
|
1369
|
+
/** True when the literal text missed and whitespace-collapsed matching found it. */
|
|
1370
|
+
readonly collapsed?: boolean;
|
|
1371
|
+
readonly note?: string;
|
|
1372
|
+
}
|
|
1373
|
+
/** How a reveal call ended. */
|
|
1374
|
+
interface RevealOutcome {
|
|
1375
|
+
readonly referenceId: string;
|
|
1376
|
+
readonly status: 'revealed' | 'partial' | 'ambiguous' | 'missing' | 'not-found' | 'page-mismatch' | 'session-unavailable' | 'unavailable';
|
|
1377
|
+
readonly pageUrl: string;
|
|
1378
|
+
/** Where the browser is now, when it could be read. */
|
|
1379
|
+
readonly currentUrl?: string;
|
|
1380
|
+
readonly parts: readonly RevealPartResult[];
|
|
1381
|
+
readonly note?: string;
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* The reserved seam for putting a reference into a DSH draft.
|
|
1385
|
+
*
|
|
1386
|
+
* The host has no plugin-facing draft API today (the composer is package
|
|
1387
|
+
* internal), so this plugin captures and stores references and leaves delivery
|
|
1388
|
+
* to whoever implements this interface. When a host adapter is registered the
|
|
1389
|
+
* same service can deliver; until then `insertIntoDraft` answers honestly that
|
|
1390
|
+
* no adapter exists.
|
|
1391
|
+
*/
|
|
1392
|
+
interface BrowserReferenceDraftAdapter {
|
|
1393
|
+
insertReference(reference: BrowserReference, options: {
|
|
1394
|
+
readonly sessionId: string;
|
|
1395
|
+
readonly focus?: boolean;
|
|
1396
|
+
}): Promise<{
|
|
1397
|
+
readonly applied: boolean;
|
|
1398
|
+
readonly reason?: string;
|
|
1399
|
+
}>;
|
|
1400
|
+
}
|
|
1401
|
+
/** Tunables; every default is a cap the caller can only tighten. */
|
|
1402
|
+
interface BrowserReferenceServiceOptions {
|
|
1403
|
+
/** Characters of context on each side of a text anchor. Default 32. */
|
|
1404
|
+
readonly context?: number;
|
|
1405
|
+
/** Longest single text part. Default 20000 characters. */
|
|
1406
|
+
readonly maxTextPartLength?: number;
|
|
1407
|
+
/** Most parts in one reference. Default 64. */
|
|
1408
|
+
readonly maxParts?: number;
|
|
1409
|
+
/** Most cells captured per table. Default 2000. */
|
|
1410
|
+
readonly maxTableCells?: number;
|
|
1411
|
+
/** Page text budget for capture/reveal. Default 2 000 000 characters. */
|
|
1412
|
+
readonly maxPageText?: number;
|
|
1413
|
+
/** Largest image kept. Default 20 MiB. */
|
|
1414
|
+
readonly maxImageBytes?: number;
|
|
1415
|
+
/** Where image bytes live. Default `reference-assets` beside the store. */
|
|
1416
|
+
readonly assetDir?: string;
|
|
1417
|
+
/** Page evaluation budget. Default 20 s. */
|
|
1418
|
+
readonly timeoutMs?: number;
|
|
1419
|
+
/**
|
|
1420
|
+
* The browser session the person has open right now.
|
|
1421
|
+
*
|
|
1422
|
+
* Read only by `reveal`, and only when the session that captured the
|
|
1423
|
+
* reference no longer exists: the sidebar page is re-adopted under a new id
|
|
1424
|
+
* after a restart, and this is what lets an older reference still find it.
|
|
1425
|
+
*/
|
|
1426
|
+
readonly currentSession?: () => string | undefined;
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Capture and reveal browser references for one host.
|
|
1430
|
+
*
|
|
1431
|
+
* One instance per plugin context; the store is the only shared state.
|
|
1432
|
+
*/
|
|
1433
|
+
export declare class BrowserReferenceService {
|
|
1434
|
+
private adapter;
|
|
1435
|
+
private readonly assetDir;
|
|
1436
|
+
private readonly host;
|
|
1437
|
+
private readonly options;
|
|
1438
|
+
private readonly store;
|
|
1439
|
+
/** Live-page lookup used by `reveal` when the capture session is gone. */
|
|
1440
|
+
private readonly currentSession;
|
|
1441
|
+
constructor(host: ReferenceHost, store?: ReferenceStore, options?: BrowserReferenceServiceOptions);
|
|
1442
|
+
/** Register the host's draft adapter; `undefined` removes it. */
|
|
1443
|
+
setDraftAdapter(adapter: BrowserReferenceDraftAdapter | undefined): void;
|
|
1444
|
+
/** The store, for listings. */
|
|
1445
|
+
get references(): ReferenceStore;
|
|
1446
|
+
/** Read one reference. */
|
|
1447
|
+
get(referenceId: string): BrowserReference | undefined;
|
|
1448
|
+
/** List references, newest last. */
|
|
1449
|
+
list(filter?: {
|
|
1450
|
+
readonly sessionId?: string;
|
|
1451
|
+
readonly pageUrl?: string;
|
|
1452
|
+
readonly limit?: number;
|
|
1453
|
+
}): BrowserReference[];
|
|
1454
|
+
/** Absolute path of one stored asset, or undefined when it is absent. */
|
|
1455
|
+
assetPath(assetKey: string): string | undefined;
|
|
1456
|
+
/**
|
|
1457
|
+
* Export stored records and the image bytes they bind.
|
|
1458
|
+
* @param options - output shape and an optional owning-session filter.
|
|
1459
|
+
* @returns the encoded file.
|
|
1460
|
+
*/
|
|
1461
|
+
exportBundle(options: {
|
|
1462
|
+
readonly format: ReferenceExportFormat;
|
|
1463
|
+
readonly sessionId?: string;
|
|
1464
|
+
}): {
|
|
1465
|
+
readonly fileName: string;
|
|
1466
|
+
readonly mime: string;
|
|
1467
|
+
readonly body: Buffer;
|
|
1468
|
+
};
|
|
1469
|
+
/**
|
|
1470
|
+
* Deliver one stored reference into a draft through the registered adapter.
|
|
1471
|
+
* @param referenceId - the stored reference.
|
|
1472
|
+
* @returns `ok: false` with a reason when no adapter exists or it refused.
|
|
1473
|
+
*/
|
|
1474
|
+
insertIntoDraft(referenceId: string): Promise<{
|
|
1475
|
+
readonly ok: boolean;
|
|
1476
|
+
readonly reason?: string;
|
|
1477
|
+
}>;
|
|
1478
|
+
/**
|
|
1479
|
+
* Capture the page's current selection (or one table / one excerpt).
|
|
1480
|
+
* @param request - what to capture and which session owns it.
|
|
1481
|
+
* @param signal - cancels the page evaluations.
|
|
1482
|
+
* @returns the stored reference, or the failures that prevented one.
|
|
1483
|
+
*/
|
|
1484
|
+
capture(request: CaptureRequest, signal?: AbortSignal): Promise<CaptureOutcome>;
|
|
1485
|
+
/**
|
|
1486
|
+
* Tell the page that its capture did not become a reference.
|
|
1487
|
+
*
|
|
1488
|
+
* A refused capture used to be stderr-only: the bar closed and the reader had
|
|
1489
|
+
* no idea why nothing appeared. This is best-effort — a page that navigated
|
|
1490
|
+
* away or a carrier without an evaluate path must not fail the capture.
|
|
1491
|
+
*
|
|
1492
|
+
* @param sessionId - the browser view the bar lives in.
|
|
1493
|
+
* @param text - one sentence for the reader.
|
|
1494
|
+
*/
|
|
1495
|
+
notify(sessionId: string, text: string): Promise<void>;
|
|
1496
|
+
/**
|
|
1497
|
+
* Locate one stored reference in its page. Without a `partId` the group's
|
|
1498
|
+
* first part is located, which is the group's reading position.
|
|
1499
|
+
* @param referenceId - the stored reference.
|
|
1500
|
+
* @param request - optional specific part.
|
|
1501
|
+
* @param signal - cancels the page evaluations.
|
|
1502
|
+
*/
|
|
1503
|
+
reveal(referenceId: string, request?: {
|
|
1504
|
+
readonly partId?: string;
|
|
1505
|
+
readonly navigate?: boolean;
|
|
1506
|
+
}, signal?: AbortSignal): Promise<RevealOutcome>;
|
|
1507
|
+
/**
|
|
1508
|
+
* Point the session's page at a URL and wait until it is there.
|
|
1509
|
+
*
|
|
1510
|
+
* The navigation itself destroys the page's execution context, so its reply
|
|
1511
|
+
* is expected to be lost; arrival is proven by reading the URL afterwards.
|
|
1512
|
+
*/
|
|
1513
|
+
private navigateTo;
|
|
1514
|
+
private revealElement;
|
|
1515
|
+
/** Validate one text event into a part, or a failure. */
|
|
1516
|
+
private textPart;
|
|
1517
|
+
/** Validate one image event, materialise its bytes, or fail it. */
|
|
1518
|
+
private imagePart;
|
|
1519
|
+
/**
|
|
1520
|
+
* Try the page's real bytes first, then a page-side raster, then — only when
|
|
1521
|
+
* the host can take a read-only clipped screenshot — a masked visible-region
|
|
1522
|
+
* snapshot. Remember which one the stored asset actually is.
|
|
1523
|
+
*
|
|
1524
|
+
* B33/B57: a URL may serve a newer asset between selection and download.
|
|
1525
|
+
* When the page session can still be probed and its digest disagrees with the
|
|
1526
|
+
* downloaded bytes, those bytes are NEVER advertised as 'source-image'.
|
|
1527
|
+
* An unprobeable page is reported as unverifiable, not as a verified match.
|
|
1528
|
+
*/
|
|
1529
|
+
private materializeImage;
|
|
1530
|
+
/**
|
|
1531
|
+
* B58/B12/B10: mask every rectangle outside the selection, capture only the
|
|
1532
|
+
* visible intersection, then remove the mask even when the capture fails.
|
|
1533
|
+
* The mask (not an oversized clip) is what keeps a multi-column selection
|
|
1534
|
+
* free of the neighbouring column's content.
|
|
1535
|
+
*/
|
|
1536
|
+
private tryVisibleSnapshot;
|
|
1537
|
+
/** Write content-addressed bytes plus a metadata sidecar. */
|
|
1538
|
+
private saveAsset;
|
|
1539
|
+
/** Validate one table event into a part plus the image parts its cells carry. */
|
|
1540
|
+
private tablePart;
|
|
1541
|
+
private run;
|
|
1542
|
+
}
|
|
1543
|
+
/** What a list row or tool answer carries; the full parts stay in the store. */
|
|
1544
|
+
interface ReferenceSummary {
|
|
1545
|
+
readonly referenceId: string;
|
|
1546
|
+
readonly title: string;
|
|
1547
|
+
readonly pageUrl: string;
|
|
1548
|
+
readonly capturedAt: string;
|
|
1549
|
+
readonly carrier: BrowserReferenceCarrier;
|
|
1550
|
+
readonly origin: BrowserReferenceOrigin;
|
|
1551
|
+
readonly entry: BrowserReferenceEntry;
|
|
1552
|
+
readonly partCount: number;
|
|
1553
|
+
readonly parts: readonly {
|
|
1554
|
+
readonly partId: string;
|
|
1555
|
+
readonly type: string;
|
|
1556
|
+
readonly preview: string;
|
|
1557
|
+
}[];
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* Project one reference into the compact shape a list or a tool answer shows.
|
|
1561
|
+
* @param reference - the stored snapshot.
|
|
1562
|
+
*/
|
|
1563
|
+
export declare function summarizeReference(reference: BrowserReference): ReferenceSummary;
|
|
1564
|
+
/** The browser surface the service needs; `BrowserRuntime` satisfies it structurally. */
|
|
1565
|
+
interface BrowserRuntimeLike {
|
|
1566
|
+
execute(session: string, request: {
|
|
1567
|
+
readonly script: string;
|
|
1568
|
+
readonly args?: readonly unknown[];
|
|
1569
|
+
readonly timeoutMs?: number;
|
|
1570
|
+
}, signal?: AbortSignal): Promise<{
|
|
1571
|
+
readonly ok: true;
|
|
1572
|
+
readonly value: unknown;
|
|
1573
|
+
} | {
|
|
1574
|
+
readonly ok: false;
|
|
1575
|
+
readonly exception: string;
|
|
1576
|
+
}>;
|
|
1577
|
+
exists(session: string): boolean;
|
|
1578
|
+
download(session: string, request: {
|
|
1579
|
+
readonly url: string;
|
|
1580
|
+
readonly savePath: string;
|
|
1581
|
+
}, signal?: AbortSignal): Promise<{
|
|
1582
|
+
readonly path: string;
|
|
1583
|
+
}>;
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Build the service against the plugin's browser runtime.
|
|
1587
|
+
* @param browser - the `ctx.browser` runtime.
|
|
1588
|
+
* @param options - optional caps and store overrides.
|
|
1589
|
+
*/
|
|
1590
|
+
export declare function createReferenceService(browser: BrowserRuntimeLike, options?: BrowserReferenceServiceOptions & {
|
|
1591
|
+
readonly store?: ReferenceStore;
|
|
1592
|
+
/** Optional: a read-only clipped screenshot for masked visible snapshots. */
|
|
1593
|
+
readonly visibleCapture?: (sessionId: string, clip: VisibleClip, signal?: AbortSignal) => Promise<VisibleCaptureResult>;
|
|
1594
|
+
}): BrowserReferenceService;
|
|
1595
|
+
/** Half-open [start, end) range in the scanned text. */
|
|
1596
|
+
interface TextRange {
|
|
1597
|
+
readonly start: number;
|
|
1598
|
+
readonly end: number;
|
|
1599
|
+
}
|
|
1600
|
+
/** How a locate attempt ended. Ambiguity is a result, not an exception. */
|
|
1601
|
+
type LocateStatus = 'found' | 'ambiguous' | 'missing';
|
|
1602
|
+
/** One locate attempt. `range` is present only when the status is `found`. */
|
|
1603
|
+
interface LocateResult {
|
|
1604
|
+
readonly status: LocateStatus;
|
|
1605
|
+
readonly range?: TextRange;
|
|
1606
|
+
readonly matches: readonly TextRange[];
|
|
1607
|
+
/** True when the literal text missed and the whitespace-collapsed form matched. */
|
|
1608
|
+
readonly collapsed: boolean;
|
|
1609
|
+
}
|
|
1610
|
+
/** Context sizes, in UTF-16 code units, kept on each side of the selection. */
|
|
1611
|
+
interface AnchorContext {
|
|
1612
|
+
readonly before?: number;
|
|
1613
|
+
readonly after?: number;
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Build the anchor for one selection.
|
|
1617
|
+
*
|
|
1618
|
+
* @param pageText - the text the selection was taken from.
|
|
1619
|
+
* @param start - selection start, UTF-16 index.
|
|
1620
|
+
* @param end - selection end, UTF-16 index.
|
|
1621
|
+
* @param context - how much surrounding text to keep (default 32 each side).
|
|
1622
|
+
* @returns the anchor, with context clipped at the text boundaries.
|
|
1623
|
+
* @throws TypeError when the range is not a non-empty subrange of `pageText`.
|
|
1624
|
+
*/
|
|
1625
|
+
export declare function buildTextAnchor(pageText: string, start: number, end: number, context?: AnchorContext): TextQuoteAnchor;
|
|
1626
|
+
/**
|
|
1627
|
+
* Find one anchor in a page's text.
|
|
1628
|
+
*
|
|
1629
|
+
* A literal hit is preferred; only when the literal text is absent does the
|
|
1630
|
+
* search retry with whitespace collapsed on both sides. Among hits, the one
|
|
1631
|
+
* whose surrounding text agrees most with `prefix`/`suffix` wins; a tie is
|
|
1632
|
+
* reported as `ambiguous` instead of guessing.
|
|
1633
|
+
*
|
|
1634
|
+
* @param pageText - the text to search, as captured from the page.
|
|
1635
|
+
* @param anchor - the stored selector.
|
|
1636
|
+
* @returns the locate result; never throws for malformed anchors.
|
|
1637
|
+
*/
|
|
1638
|
+
export declare function findTextQuote(pageText: string, anchor: TextQuoteAnchor): LocateResult;
|
|
1639
|
+
/** Which browser the user asked for. */
|
|
1640
|
+
type BrowserChannel = 'bundled' | 'chrome' | 'edge' | 'auto' | 'sidebar';
|
|
1641
|
+
/** Vision/operation strategy the provider prefers when the model can see. */
|
|
1642
|
+
type VisionStrategy = 'auto' | 'nonVisual';
|
|
1643
|
+
/**
|
|
1644
|
+
* Whether a launched browser gets a window.
|
|
1645
|
+
*
|
|
1646
|
+
* Split from {@link VisionStrategy} because these answer different questions: that one is how the
|
|
1647
|
+
* agent examines a page, this one is whether the browser has anywhere to draw.
|
|
1648
|
+
*/
|
|
1649
|
+
type HeadlessMode = 'auto' | 'headless' | 'windowed';
|
|
1650
|
+
/** The full settings document, with every field resolved. */
|
|
1651
|
+
interface BrowserSettings {
|
|
1652
|
+
/** Persistent browsing history (visited pages). */
|
|
1653
|
+
readonly history: {
|
|
1654
|
+
readonly enabled: boolean;
|
|
1655
|
+
readonly maxEntries: number;
|
|
1656
|
+
readonly maxAgeDays: number;
|
|
1657
|
+
};
|
|
1658
|
+
/** Login-state retention: cookies and the browser profile. */
|
|
1659
|
+
readonly cookies: {
|
|
1660
|
+
readonly persist: boolean;
|
|
1661
|
+
};
|
|
1662
|
+
/** Presentation behaviour. */
|
|
1663
|
+
readonly ui: {
|
|
1664
|
+
/** Auto-expand the side panel once per task, then leave the user alone. */
|
|
1665
|
+
readonly autoExpandOnce: boolean;
|
|
1666
|
+
/** Release the browser when its session ends, instead of waiting for a close. */
|
|
1667
|
+
readonly closeWithSession: boolean;
|
|
1668
|
+
/** Show the synthetic cursor/click feedback while the agent operates. */
|
|
1669
|
+
readonly virtualCursor: boolean;
|
|
1670
|
+
/**
|
|
1671
|
+
* Quiet mode: drive the page without taking over the screen.
|
|
1672
|
+
*
|
|
1673
|
+
* Off (the default) keeps the contract this plugin is built on — human and agent share one
|
|
1674
|
+
* window, so an operation raises it and the user can see what is being driven. On, the
|
|
1675
|
+
* carrier never activates the application and never steals keyboard focus:
|
|
1676
|
+
* - screenshots of a minimized or hidden window go through CDP `Page.captureScreenshot`
|
|
1677
|
+
* instead of `capturePage()`, so grabbing an image stops being a reason to show a window;
|
|
1678
|
+
* - navigation and tab switching only change which view is visible INSIDE the window; a
|
|
1679
|
+
* minimized window stays minimized;
|
|
1680
|
+
* - synthesized input still needs a display surface (Chromium drops `Input.*` for a view
|
|
1681
|
+
* without one), so that one barrier may restore a minimized window — with
|
|
1682
|
+
* `showInactive()`, which shows it without becoming the key window, and without
|
|
1683
|
+
* `moveTop()`.
|
|
1684
|
+
*
|
|
1685
|
+
* Reported as issue #35: a minimized browser window was restored and focused by the next
|
|
1686
|
+
* screenshot or click, pulling the user out of whatever they were typing in.
|
|
1687
|
+
*/
|
|
1688
|
+
readonly quiet: boolean;
|
|
1689
|
+
};
|
|
1690
|
+
/** Visual vs non-visual operation strategy. */
|
|
1691
|
+
readonly vision: {
|
|
1692
|
+
readonly strategy: VisionStrategy;
|
|
1693
|
+
};
|
|
1694
|
+
/** Which browser binary carries the agent's pages. */
|
|
1695
|
+
readonly browser: {
|
|
1696
|
+
readonly channel: BrowserChannel;
|
|
1697
|
+
/**
|
|
1698
|
+
* Whether the browser gets a window.
|
|
1699
|
+
*
|
|
1700
|
+
* `auto` (the default) launches headless when the process has no display — no `DISPLAY` and no
|
|
1701
|
+
* `WAYLAND_DISPLAY` — and with a window otherwise. That combination is what makes the plugin
|
|
1702
|
+
* work under systemd, in a container, or on an SSH-only server while leaving desktop users
|
|
1703
|
+
* with the visible window they expect. `true` forces headless (CI, screenshot-only servers);
|
|
1704
|
+
* `false` forces a window, so a misconfigured display fails loudly instead of silently
|
|
1705
|
+
* degrading into a browser nobody can see.
|
|
1706
|
+
*
|
|
1707
|
+
* Reported as issue #32: as a systemd service there is no display, Chromium exits with
|
|
1708
|
+
* "could not connect to display", and every `dsh_browser_*` call failed with "exited
|
|
1709
|
+
* immediately after launch".
|
|
1710
|
+
*/
|
|
1711
|
+
readonly headless: HeadlessMode;
|
|
1712
|
+
};
|
|
1713
|
+
/** Whether the agent may read cookies / export login state. */
|
|
1714
|
+
readonly credentials: {
|
|
1715
|
+
readonly allowRead: boolean;
|
|
1716
|
+
};
|
|
1717
|
+
/**
|
|
1718
|
+
* Live view of the browser for a remote operator (issue #34).
|
|
1719
|
+
*
|
|
1720
|
+
* OFF by default, and that default is the feature's main safety property: a live browser frame can
|
|
1721
|
+
* contain a CAPTCHA, an account name, or logged-in content, so nobody should be able to watch
|
|
1722
|
+
* without the host having said yes first. The remote side also cannot turn it on: this file is
|
|
1723
|
+
* written through the plugin's own settings route, which admits only same-origin requests from the
|
|
1724
|
+
* host's own UI, and the frame endpoint refuses everything when this is false.
|
|
1725
|
+
*/
|
|
1726
|
+
readonly remoteView: {
|
|
1727
|
+
/** Serve browser frames to a remote viewer. */
|
|
1728
|
+
readonly enabled: boolean;
|
|
1729
|
+
};
|
|
1730
|
+
/**
|
|
1731
|
+
* What the agent is allowed to DO, as opposed to what it may look at.
|
|
1732
|
+
*
|
|
1733
|
+
* These are OPERATOR switches: the settings panel is not reachable from the model, so a
|
|
1734
|
+
* value here refuses whatever the model asks for, and no tool can lift it. That is what
|
|
1735
|
+
* separates them from `dsh_browser_restrict`, which is the model's own soft guardrail. All
|
|
1736
|
+
* three default to on, which is the documented out-of-the-box behaviour.
|
|
1737
|
+
*/
|
|
1738
|
+
readonly actions: {
|
|
1739
|
+
/** Run arbitrary page scripts in the active tab (`dsh_browser_execute`). */
|
|
1740
|
+
readonly allowExecute: boolean;
|
|
1741
|
+
/** Download a URL to disk (`dsh_browser_download`). */
|
|
1742
|
+
readonly allowDownload: boolean;
|
|
1743
|
+
/** Write cookies — importing login state (`dsh_browser_auth` restore). */
|
|
1744
|
+
readonly allowCredentialWrite: boolean;
|
|
1745
|
+
};
|
|
1746
|
+
/**
|
|
1747
|
+
* Where a downloaded file goes after it lands on disk.
|
|
1748
|
+
*
|
|
1749
|
+
* An ATTRIBUTE of a download, not a new concept: an empty `tool` means the behaviour is exactly
|
|
1750
|
+
* what it was before this existed. The user owns the field, can point it at any MCP tool that
|
|
1751
|
+
* takes a path (Feishu drive, Baidu Netdisk), and can empty it again at any time.
|
|
1752
|
+
*/
|
|
1753
|
+
/**
|
|
1754
|
+
* Desktop bridge handled without asking.
|
|
1755
|
+
*
|
|
1756
|
+
* Historical automatic-install preference retained when reading existing settings documents.
|
|
1757
|
+
* Runtime automatic installation is disabled; bridge maintenance is an explicit action after
|
|
1758
|
+
* DSH Desktop is closed, even when an older document contains autoInstall=true.
|
|
1759
|
+
*/
|
|
1760
|
+
readonly bridge: {
|
|
1761
|
+
/** Legacy preference; it does not trigger installation at runtime. Default false. */
|
|
1762
|
+
readonly autoInstall: boolean;
|
|
1763
|
+
};
|
|
1764
|
+
readonly delivery: {
|
|
1765
|
+
/** MCP tool that receives the saved file. Empty = save locally and stop there. */
|
|
1766
|
+
readonly tool: string;
|
|
1767
|
+
/** Flat argument template; {path}, {name} and {size} are substituted into string values. */
|
|
1768
|
+
readonly args: Readonly<Record<string, string>>;
|
|
1769
|
+
/** `keep-local` reports both outcomes; `stop` reports the handoff failure as the result. */
|
|
1770
|
+
readonly onFail: 'keep-local' | 'stop';
|
|
1771
|
+
/** Per-site override: page host → tool name. */
|
|
1772
|
+
readonly sites: Readonly<Record<string, string>>;
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* The minimal Electron surface this provider needs. Implemented by the
|
|
1777
|
+
* desktop shell with a real `WebContentsView`; a fake implements it in tests.
|
|
1778
|
+
*/
|
|
1779
|
+
interface ElectronBrowserViewHost {
|
|
1780
|
+
/**
|
|
1781
|
+
* Create a new browser view and return a handle to its webContents-like
|
|
1782
|
+
* surface. The host owns windowing (adding the view to the window, sizing,
|
|
1783
|
+
* removal); the provider owns CDP-driven behavior.
|
|
1784
|
+
* @param owner - the conversation this view serves. A host shared by several conversations
|
|
1785
|
+
* needs it to keep one conversation's page out of another's; a host with one conversation per
|
|
1786
|
+
* process may ignore it. It is per VIEW and not per host on purpose: the desktop's host is a
|
|
1787
|
+
* single instance that every conversation runs through, so an owner held there would be one
|
|
1788
|
+
* conversation's id applied to all of them.
|
|
1789
|
+
*/
|
|
1790
|
+
createView(owner?: string): ElectronViewHandle;
|
|
1791
|
+
/**
|
|
1792
|
+
* Destroy a view created by this host. Called on session close; idempotent
|
|
1793
|
+
* for an already-destroyed view.
|
|
1794
|
+
* @param handle - the handle returned by {@link createView}.
|
|
1795
|
+
*/
|
|
1796
|
+
destroyView(handle: ElectronViewHandle, options?: {
|
|
1797
|
+
readonly keepPage?: boolean;
|
|
1798
|
+
}): void;
|
|
1799
|
+
/**
|
|
1800
|
+
* Show one view as the session's visible surface. The host keeps exactly
|
|
1801
|
+
* one visible; switching tabs reorders visibility without losing state.
|
|
1802
|
+
* Optional: a host without visible-tab switching treats every view as
|
|
1803
|
+
* always present (acceptable for headless/probe hosts).
|
|
1804
|
+
* @param handle - the handle to make visible.
|
|
1805
|
+
* @param label - human-readable session/task label, when the provider knows
|
|
1806
|
+
* one; the host may surface it (e.g. in the window title) so a human can
|
|
1807
|
+
* tell which task's page is currently visible.
|
|
1808
|
+
* @param options - presentation policy; `quiet` asks for a surface without taking
|
|
1809
|
+
* over the screen (see {@link PresentOptions}).
|
|
1810
|
+
*/
|
|
1811
|
+
showView?(handle: ElectronViewHandle, label?: string, options?: PresentOptions): void;
|
|
1812
|
+
/**
|
|
1813
|
+
* Optional: (re)present a view and WAIT until the host confirms it. Chromium
|
|
1814
|
+
* silently drops CDP-synthesized input (`Input.*`) for a view that has no
|
|
1815
|
+
* display surface, which made clicks/typing report success while the page
|
|
1816
|
+
* received nothing (and made the first input after a navigation vanish,
|
|
1817
|
+
* because the replaced renderer has no surface yet). Unlike
|
|
1818
|
+
* {@link showView}, this round-trips an RPC barrier that is ordered AFTER
|
|
1819
|
+
* the show on the same socket, so its reply means the view is on screen.
|
|
1820
|
+
* Rejects when the view cannot be presented; a host without this method is
|
|
1821
|
+
* assumed to present every view (headless/probe hosts).
|
|
1822
|
+
* @param handle - the handle to present.
|
|
1823
|
+
* @param label - human-readable session/task label, as in {@link showView}.
|
|
1824
|
+
* @param options - presentation policy, as in {@link showView}.
|
|
1825
|
+
*/
|
|
1826
|
+
presentView?(handle: ElectronViewHandle, label?: string, options?: PresentOptions): Promise<void>;
|
|
1827
|
+
/**
|
|
1828
|
+
* Optional: pages this carrier holds that the provider never created.
|
|
1829
|
+
*
|
|
1830
|
+
* A sidebar panel and an installed browser both own their own page creation. Clicking a link
|
|
1831
|
+
* that opens a new page — or any `window.open` the page performs — produces a page the provider
|
|
1832
|
+
* did not ask for and therefore never recorded. Those pages are real: they are what the human
|
|
1833
|
+
* sees, they hold memory, and they persist until something closes them. Without this the tab
|
|
1834
|
+
* model reports only what the provider itself made, so the extras are invisible to
|
|
1835
|
+
* `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`, accumulating for the
|
|
1836
|
+
* life of the browser.
|
|
1837
|
+
*
|
|
1838
|
+
* Views the host itself opened are NOT included. That exclusion belongs to the host, which is the
|
|
1839
|
+
* only side that can make it: a provider tab is identified by the provider's own id and a carrier
|
|
1840
|
+
* page by the carrier's, so a caller comparing the two matches nothing and reports every page
|
|
1841
|
+
* twice. Measured on the sidebar carrier: three clicks produced three webview guests while
|
|
1842
|
+
* `dsh_browser_list_tabs` reported one tab; on the installed-browser carrier the window held four
|
|
1843
|
+
* pages and the tool reported one.
|
|
1844
|
+
* @param owner - the calling task/conversation; shared sidebar hosts must scope to it.
|
|
1845
|
+
* @param options - `requireRunning` lists only from a carrier that is already
|
|
1846
|
+
* running. A background scan (the reference-bar pump) must use it: opening
|
|
1847
|
+
* the human's installed browser just to look for a page is a side effect
|
|
1848
|
+
* nobody asked for.
|
|
1849
|
+
* @returns every page this conversation's carrier holds that this host did not open.
|
|
1850
|
+
*/
|
|
1851
|
+
listPages?(owner?: string, options?: {
|
|
1852
|
+
readonly requireRunning?: boolean;
|
|
1853
|
+
}): Promise<readonly CarrierPage[]>;
|
|
1854
|
+
/**
|
|
1855
|
+
* Optional: take over one page reported by {@link listPages}, so it becomes a page this provider
|
|
1856
|
+
* drives rather than one it can only see.
|
|
1857
|
+
*
|
|
1858
|
+
* Reported as a defect: opening a window by hand, navigating it, and then asking a tool to read it
|
|
1859
|
+
* produced a SECOND page — the human's own tab was listed (under `page:`) and closable, but not
|
|
1860
|
+
* readable, which is the opposite of "the page you are looking at". A carrier that cannot do this
|
|
1861
|
+
* must leave it undefined rather than pretend: a switch that reported success and then read
|
|
1862
|
+
* nothing is the failure this removes.
|
|
1863
|
+
* @param viewId - the view to bind the page to.
|
|
1864
|
+
* @param id - the carrier's own page id, as {@link listPages} reported it.
|
|
1865
|
+
* @returns a handle for that page, usable for commands like any other view's.
|
|
1866
|
+
*/
|
|
1867
|
+
adoptPage?(id: string, owner?: string): Promise<ElectronViewHandle>;
|
|
1868
|
+
/** Adopt the conversation id when it becomes known after construction. */
|
|
1869
|
+
setOwner?(owner: string): void;
|
|
1870
|
+
/**
|
|
1871
|
+
* Optional: close one page reported by {@link listPages}.
|
|
1872
|
+
*
|
|
1873
|
+
* The pair exists because listing a page the caller cannot close is worse than not listing it:
|
|
1874
|
+
* `dsh_browser_list_tabs` would report pages that `dsh_browser_close_tab` answers "not open in
|
|
1875
|
+
* this session" about, which reads as a contradiction rather than a boundary.
|
|
1876
|
+
* @param id - the carrier's own page id, as {@link listPages} reported it.
|
|
1877
|
+
* @param owner - the same task/conversation used for listing; never a global fallback.
|
|
1878
|
+
*/
|
|
1879
|
+
closePage?(id: string, owner?: string): Promise<void>;
|
|
1880
|
+
/**
|
|
1881
|
+
* Optional cheap usability probe (no network): whether the host can back
|
|
1882
|
+
* views at all right now. The self-hosted host checks for a usable Electron
|
|
1883
|
+
* binary; a host without the probe is assumed usable. Lets the seam's
|
|
1884
|
+
* provider selection (BROWSER_PROVIDER_UNAVAILABLE etc.) be real instead
|
|
1885
|
+
* of failing only at first use.
|
|
1886
|
+
*/
|
|
1887
|
+
available?(): boolean;
|
|
1888
|
+
/**
|
|
1889
|
+
* Tell the human that a toolbar action the agent could not complete has failed.
|
|
1890
|
+
*
|
|
1891
|
+
* Optional. Declared rather than reached through a cast because this is what issue #16 was:
|
|
1892
|
+
* the call used to be unbound, so `this` inside the host's implementation was undefined and
|
|
1893
|
+
* its first statement threw — inside an async catch, which turned it into an unhandled
|
|
1894
|
+
* rejection that took the whole DSH process down. A declared member is checkable; a cast is
|
|
1895
|
+
* not.
|
|
1896
|
+
* @param windowId - the window the action came from.
|
|
1897
|
+
* @param message - what to show the human.
|
|
1898
|
+
*/
|
|
1899
|
+
notifyUserActionError?(windowId: string, message: string): void;
|
|
1900
|
+
/**
|
|
1901
|
+
* Optional: associate a view with a window group. Views grouped under the
|
|
1902
|
+
* same `windowId` share one window (one window per browser session); a host
|
|
1903
|
+
* without this keeps a single shared window. Called right after
|
|
1904
|
+
* `createView`, so the host may route the view to its own window even
|
|
1905
|
+
* before the first command materializes it.
|
|
1906
|
+
* @param handle - the view to group.
|
|
1907
|
+
* @param windowId - the group (session) key.
|
|
1908
|
+
* @param label - human-readable label for the window title.
|
|
1909
|
+
*/
|
|
1910
|
+
groupView?(handle: ElectronViewHandle, windowId: string, label?: string): void;
|
|
1911
|
+
/**
|
|
1912
|
+
* Optional: receive user-initiated browser actions from the host's own UI
|
|
1913
|
+
* (e.g. a toolbar address bar, back/forward buttons, tab strip). The
|
|
1914
|
+
* provider routes them into the session model so the agent and the human
|
|
1915
|
+
* always see the same tabs and navigation state.
|
|
1916
|
+
* @param handler - called for every user action; must not throw.
|
|
1917
|
+
*/
|
|
1918
|
+
onUserAction?(handler: (action: BrowserUserAction) => void): void;
|
|
1919
|
+
/**
|
|
1920
|
+
* Optional: receive notice that the human closed a browser window. Closing the
|
|
1921
|
+
* interface ends the session it showed — the next call opens a clean one —
|
|
1922
|
+
* while browsing history and login state survive on disk.
|
|
1923
|
+
* @param handler - called with the group (session) key; must not throw.
|
|
1924
|
+
*/
|
|
1925
|
+
onViewClosed?(handler: (windowId: string) => void): void;
|
|
1926
|
+
/**
|
|
1927
|
+
* Release the service's page(s) without ending the plugin's own lifetime.
|
|
1928
|
+
*
|
|
1929
|
+
* Only carriers that outlive a browser session need this. A self-hosted window
|
|
1930
|
+
* dies with its view, but the desktop shell's sidebar keeps running no matter
|
|
1931
|
+
* what the plugin does — so "release the browser when the session ends"
|
|
1932
|
+
* (settings: ui.closeWithSession) has to be asked for explicitly there.
|
|
1933
|
+
* @returns a promise that settles once the release was attempted.
|
|
1934
|
+
*/
|
|
1935
|
+
/**
|
|
1936
|
+
* Release this carrier's browser pages for one conversation.
|
|
1937
|
+
* @param owner - the conversation whose pages to close. Omit to close every conversation's,
|
|
1938
|
+
* which is only correct from a teardown that is itself global.
|
|
1939
|
+
*/
|
|
1940
|
+
releasePage?(owner?: string): Promise<void>;
|
|
1941
|
+
/**
|
|
1942
|
+
* Report that this carrier can no longer serve anything, so its owner may replace it.
|
|
1943
|
+
*
|
|
1944
|
+
* A carrier that borrows an outside process can lose it: the desktop shell exits, and every call
|
|
1945
|
+
* after that would dial a port nobody owns. Without this signal the swap happens only at
|
|
1946
|
+
* startup, so the choice made then is final for the process's life — which is what a user
|
|
1947
|
+
* experiences as "the browser stopped working until I restart DSH". Optional: a carrier that
|
|
1948
|
+
* owns its own lifetime has nothing to report.
|
|
1949
|
+
*
|
|
1950
|
+
* The listener receives WHY, because the fallback's message has to match what happened: a shell
|
|
1951
|
+
* that exited and a shell whose panel cannot provide a page both reach the same fallback, and
|
|
1952
|
+
* announcing "the shell has exited" for the second tells the user their desktop crashed when it
|
|
1953
|
+
* did not.
|
|
1954
|
+
* @param listener - called once, when the carrier concludes it is gone.
|
|
1955
|
+
*/
|
|
1956
|
+
onLost?(listener: (reason: CarrierLossReason) => void): void;
|
|
1957
|
+
/**
|
|
1958
|
+
* Fold the carrier's presentation away while keeping the page alive.
|
|
1959
|
+
*
|
|
1960
|
+
* The desktop sidebar keeps running regardless of the plugin, so "do not take
|
|
1961
|
+
* over the screen" (settings: ui.autoExpandOnce = false) can only be honoured by
|
|
1962
|
+
* asking the shell to fold it. A self-hosted window has no such state and simply
|
|
1963
|
+
* does not implement this.
|
|
1964
|
+
* @returns a promise that settles once the fold was attempted.
|
|
1965
|
+
*/
|
|
1966
|
+
collapse?(): Promise<void>;
|
|
1967
|
+
/**
|
|
1968
|
+
* Release everything the carrier owns (a spawned browser, a socket, a child).
|
|
1969
|
+
* Called when the plugin stops using it, never while it is still in service.
|
|
1970
|
+
*/
|
|
1971
|
+
dispose?(): void;
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* A user-initiated browser action from the host's own UI (toolbar). The
|
|
1975
|
+
* `windowId` is the session id the view was grouped under, so the provider
|
|
1976
|
+
* can route the action to the right session.
|
|
1977
|
+
*/
|
|
1978
|
+
type BrowserUserAction = {
|
|
1979
|
+
readonly type: 'navigate';
|
|
1980
|
+
readonly windowId: string;
|
|
1981
|
+
readonly url: string;
|
|
1982
|
+
} | {
|
|
1983
|
+
readonly type: 'newTab';
|
|
1984
|
+
readonly windowId: string;
|
|
1985
|
+
readonly url?: string;
|
|
1986
|
+
} | {
|
|
1987
|
+
readonly type: 'activateTab';
|
|
1988
|
+
readonly windowId: string;
|
|
1989
|
+
readonly viewId: string;
|
|
1990
|
+
} | {
|
|
1991
|
+
readonly type: 'closeTab';
|
|
1992
|
+
readonly windowId: string;
|
|
1993
|
+
readonly viewId: string;
|
|
1994
|
+
} | {
|
|
1995
|
+
readonly type: 'back';
|
|
1996
|
+
readonly windowId: string;
|
|
1997
|
+
} | {
|
|
1998
|
+
readonly type: 'forward';
|
|
1999
|
+
readonly windowId: string;
|
|
2000
|
+
} | {
|
|
2001
|
+
readonly type: 'reload';
|
|
2002
|
+
readonly windowId: string;
|
|
2003
|
+
} | {
|
|
2004
|
+
readonly type: 'capture-reference';
|
|
2005
|
+
readonly windowId: string;
|
|
2006
|
+
readonly entry: 'native-menu' | 'page-overlay';
|
|
2007
|
+
readonly frameSelector?: string;
|
|
2008
|
+
/** The exact image/table the human right-clicked, if any. */
|
|
2009
|
+
readonly target?: BrowserReferenceTarget;
|
|
2010
|
+
/** The note typed in the selection bar. */
|
|
2011
|
+
readonly comment?: string;
|
|
2012
|
+
/**
|
|
2013
|
+
* The selection text the bar froze before its comment field took focus.
|
|
2014
|
+
* Used to locate the capture again when the live selection is gone.
|
|
2015
|
+
*/
|
|
2016
|
+
readonly selectionText?: string;
|
|
2017
|
+
/**
|
|
2018
|
+
* The complete ordered capture the bar froze at that same moment (text
|
|
2019
|
+
* runs, assets, table ranges, anchors). Preferred over `selectionText`.
|
|
2020
|
+
*/
|
|
2021
|
+
readonly capture?: RawCaptureResult;
|
|
2022
|
+
};
|
|
2023
|
+
/**
|
|
2024
|
+
* A CDP-capable view handle. This is the subset of Electron's
|
|
2025
|
+
* `WebContents`/`WebContentsView` the provider drives; the shell's real
|
|
2026
|
+
* implementation adapts `webContents.debugger` to it.
|
|
2027
|
+
*/
|
|
2028
|
+
interface ElectronViewHandle {
|
|
2029
|
+
/** Unique id of the backing view, used for diagnostics. */
|
|
2030
|
+
readonly id: string;
|
|
2031
|
+
/**
|
|
2032
|
+
* Send one CDP command and resolve with its result. Rejects when the
|
|
2033
|
+
* debugger is not attached or the command fails.
|
|
2034
|
+
* @param method - CDP method, e.g. `Page.navigate`.
|
|
2035
|
+
* @param params - CDP command parameters.
|
|
2036
|
+
* @returns the CDP `result` object.
|
|
2037
|
+
*/
|
|
2038
|
+
sendCommand(method: string, params?: Record<string, unknown>, options?: CommandOptions): Promise<Record<string, unknown>>;
|
|
2039
|
+
/**
|
|
2040
|
+
* Whether this view's CDP can encode JPEG and honour a quality setting.
|
|
2041
|
+
*
|
|
2042
|
+
* Electron 43's CDP hangs on `Page.captureScreenshot` with `format: 'jpeg'`, so a view
|
|
2043
|
+
* backed by Electron must leave this unset and the provider keeps to PNG. A view backed
|
|
2044
|
+
* by an installed Chrome or Edge is the real browser, where JPEG works, and sets it so
|
|
2045
|
+
* the requested format is not silently downgraded.
|
|
2046
|
+
*/
|
|
2047
|
+
readonly supportsCdpJpeg?: boolean;
|
|
2048
|
+
/**
|
|
2049
|
+
* Give the backing view web focus so keyboard input reaches its page.
|
|
2050
|
+
* Optional: an adapter that cannot focus a view omits it, and the provider
|
|
2051
|
+
* then behaves exactly as before.
|
|
2052
|
+
*/
|
|
2053
|
+
focus?(options?: PresentOptions): Promise<void>;
|
|
2054
|
+
/**
|
|
2055
|
+
* Save a URL straight to disk, when the backing view can do that itself.
|
|
2056
|
+
*
|
|
2057
|
+
* Optional. Declared here rather than reached through a structural cast at the call site:
|
|
2058
|
+
* a cast tells the compiler nothing, so a host that implements the interface without this
|
|
2059
|
+
* method compiles and then silently does nothing.
|
|
2060
|
+
* @param url - the URL to fetch.
|
|
2061
|
+
* @param savePath - where to write it.
|
|
2062
|
+
*/
|
|
2063
|
+
download?(url: string, savePath: string): Promise<void>;
|
|
2064
|
+
/**
|
|
2065
|
+
* Export this view's cookies. Optional; see {@link download} for why it is declared.
|
|
2066
|
+
* @returns the cookies, scoped to the view's own page.
|
|
2067
|
+
*/
|
|
2068
|
+
flushAuth?(): Promise<readonly ExportedCookie[]>;
|
|
2069
|
+
/**
|
|
2070
|
+
* Import cookies into this view. Optional.
|
|
2071
|
+
* @param cookies - the cookies to write.
|
|
2072
|
+
* @returns how many were accepted.
|
|
2073
|
+
*/
|
|
2074
|
+
restoreAuth?(cookies: readonly ExportedCookie[]): Promise<number>;
|
|
2075
|
+
/**
|
|
2076
|
+
* Capture this view natively, returning the image and its measured size.
|
|
2077
|
+
*
|
|
2078
|
+
* Optional. The size is part of the contract because the caller's own tool schema declares
|
|
2079
|
+
* `width`/`height`; a host that can measure the image should say so here rather than leaving
|
|
2080
|
+
* the provider to guess.
|
|
2081
|
+
* @param opts - format, quality and downscale bounds.
|
|
2082
|
+
* @returns the encoded image and the pixel size the caller will receive.
|
|
2083
|
+
*/
|
|
2084
|
+
capture?(opts?: ScreenshotOptions): Promise<{
|
|
2085
|
+
base64: string;
|
|
2086
|
+
mime: string;
|
|
2087
|
+
width?: number;
|
|
2088
|
+
height?: number;
|
|
2089
|
+
}>;
|
|
2090
|
+
}
|
|
2091
|
+
/** Provider config: navigation admission defaults and snapshot caps. */
|
|
2092
|
+
interface ElectronBrowserProviderConfig {
|
|
2093
|
+
/** Allow navigation only to HTTP(S) URLs; reject anything else. Default true. */
|
|
2094
|
+
readonly httpOnly?: boolean;
|
|
2095
|
+
/**
|
|
2096
|
+
* Persistent browsing history (visited pages), independent of session
|
|
2097
|
+
* lifetime. `enabled: false` keeps the browser working but records nothing;
|
|
2098
|
+
* the retained limits ride along so a user's choice from the settings panel
|
|
2099
|
+
* reaches the store without a second configuration path.
|
|
2100
|
+
*/
|
|
2101
|
+
readonly history?: {
|
|
2102
|
+
readonly enabled?: boolean;
|
|
2103
|
+
readonly maxEntries?: number;
|
|
2104
|
+
readonly maxAgeDays?: number;
|
|
2105
|
+
/**
|
|
2106
|
+
* Explicit history file path. Default: beside the browser profile
|
|
2107
|
+
* (`$DSH_HOME/dsh-builtin-browser-host/history.jsonl`).
|
|
2108
|
+
*/
|
|
2109
|
+
readonly file?: string;
|
|
2110
|
+
};
|
|
2111
|
+
/**
|
|
2112
|
+
* Live settings source (the settings panel's document). When present it wins
|
|
2113
|
+
* over the static `history` config, so a switch flipped in the UI takes effect
|
|
2114
|
+
* without restarting DSH.
|
|
2115
|
+
*/
|
|
2116
|
+
readonly settings?: () => BrowserSettings;
|
|
2117
|
+
/** Maximum snapshot elements before truncation. Default 60. */
|
|
2118
|
+
readonly snapshotMaxElements?: number;
|
|
2119
|
+
/**
|
|
2120
|
+
* Explicit content cap, overriding the per-format default when set.
|
|
2121
|
+
*
|
|
2122
|
+
* Honoured again, and it is worth saying why that is a fix rather than a feature: this was
|
|
2123
|
+
* `config.contentMaxChars ?? 100_000`, one number for every format, and when the caps became
|
|
2124
|
+
* per-format (html and json 50 000, otherwise 20 000) the field was left assigned and never
|
|
2125
|
+
* read. A configuration knob that silently does nothing is worse than no knob — it is an
|
|
2126
|
+
* operator's decision that quietly went nowhere. Leaving it unset means the per-format
|
|
2127
|
+
* default; setting it means the operator meant it.
|
|
2128
|
+
*/
|
|
2129
|
+
readonly contentMaxChars?: number;
|
|
2130
|
+
/**
|
|
2131
|
+
* Directory `dsh_browser_download` save paths must resolve inside (prevents a
|
|
2132
|
+
* prompt-injected agent from writing arbitrary machine paths). Default:
|
|
2133
|
+
* `~/Downloads`. NOTE: this default is a convenience, not a security
|
|
2134
|
+
* boundary — on Windows it may resolve to OneDrive/redirected paths;
|
|
2135
|
+
* a production deployment should set an explicit, verified path.
|
|
2136
|
+
*/
|
|
2137
|
+
readonly downloadDir?: string;
|
|
2138
|
+
/**
|
|
2139
|
+
* The conversation this process serves, when the composition knows it.
|
|
2140
|
+
*
|
|
2141
|
+
* The reference entry needs it to find the page the human has open in THIS
|
|
2142
|
+
* conversation's sidebar: the shell exposes a panel's pages by conversation id,
|
|
2143
|
+
* and a page bound under the wrong id would either be refused or wired into
|
|
2144
|
+
* another conversation's draft. Absent on hosts that do not name it (a plain
|
|
2145
|
+
* `dsh web`), where the sidebar entry simply does not apply.
|
|
2146
|
+
*/
|
|
2147
|
+
readonly referenceLabel?: string | (() => string | undefined);
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* How the carrier should present a view before it is used.
|
|
2151
|
+
*
|
|
2152
|
+
* `quiet` is the resolved `ui.quiet` switch. It does not mean "invisible": Chromium drops
|
|
2153
|
+
* synthesized `Input.*` for a view without a display surface, so input still needs one. It means
|
|
2154
|
+
* the carrier must get that surface without taking the screen over — no application activation
|
|
2155
|
+
* and no operating-system keyboard focus. New windows open inactive; a minimized window and the
|
|
2156
|
+
* foreground window's selected page remain under the operator's control. DOM focus and CDP input
|
|
2157
|
+
* still target the task's page. Explicit sidebar navigation can select the task's pane.
|
|
2158
|
+
*/
|
|
2159
|
+
interface PresentOptions {
|
|
2160
|
+
readonly quiet?: boolean;
|
|
2161
|
+
/** Explicit navigation or tab selection may change the task's sidebar tab without OS activation. */
|
|
2162
|
+
readonly select?: boolean;
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* How a command should reach its page.
|
|
2166
|
+
*
|
|
2167
|
+
* Reported as issue #46: opening the live preview pushed the conversation's sidebar browser panel
|
|
2168
|
+
* to the front — a read-only "look at it" action changing the reader's layout. The chain was
|
|
2169
|
+
* `capturePassive` → `sendCommand('Page.captureScreenshot')` → the host's guest lookup → the bridge's
|
|
2170
|
+
* `ensureSidebar` → a retry that asked the client half to `openSession`, which is exactly what a tool
|
|
2171
|
+
* call is allowed to do and a preview is not.
|
|
2172
|
+
*
|
|
2173
|
+
* `present: false` says "this command must not make anything visible": use the page this
|
|
2174
|
+
* conversation already has, and treat "not displayed" as a state to report rather than a condition
|
|
2175
|
+
* to fix.
|
|
2176
|
+
*/
|
|
2177
|
+
interface CommandOptions {
|
|
2178
|
+
/** Present the view first (default), or only use a page that is already there. */
|
|
2179
|
+
readonly present?: boolean;
|
|
2180
|
+
/** Only use a guest already attached to this handle, without sidebar initialization. */
|
|
2181
|
+
readonly initialize?: boolean;
|
|
2182
|
+
}
|
|
2183
|
+
/** Native capture options the self-hosted view handle understands. */
|
|
2184
|
+
interface ScreenshotOptions {
|
|
2185
|
+
readonly format?: 'png' | 'jpeg';
|
|
2186
|
+
readonly quality?: number;
|
|
2187
|
+
readonly maxWidth?: number;
|
|
2188
|
+
readonly maxHeight?: number;
|
|
2189
|
+
/**
|
|
2190
|
+
* Capture without presenting the window first (`ui.quiet`).
|
|
2191
|
+
*
|
|
2192
|
+
* The self-hosted host answers this by skipping its restore/show/focus step: a visible window
|
|
2193
|
+
* still captures through `capturePage()`, and a minimized or hidden one falls through to the
|
|
2194
|
+
* CDP path, which needs no display surface.
|
|
2195
|
+
*/
|
|
2196
|
+
readonly quiet?: boolean;
|
|
2197
|
+
}
|
|
2198
|
+
/**
|
|
2199
|
+
* Browser provider over Electron views. Sessions hold an ordered list of
|
|
2200
|
+
* tabs; each tab is one view created by the host. The active tab receives
|
|
2201
|
+
* every operation; switching tabs calls the host's optional `showView` and
|
|
2202
|
+
* never loses state. Navigation is admitted only for HTTP(S) targets unless
|
|
2203
|
+
* {@link ElectronBrowserProviderConfig.httpOnly} is disabled.
|
|
2204
|
+
*/
|
|
2205
|
+
export declare class ElectronBrowserProvider implements BrowserProvider {
|
|
2206
|
+
private readonly host;
|
|
2207
|
+
private readonly config;
|
|
2208
|
+
readonly id = "electron";
|
|
2209
|
+
private readonly sessions;
|
|
2210
|
+
/**
|
|
2211
|
+
* Tick that installs the selection bar in every live tab and collects what the
|
|
2212
|
+
* human confirmed. The Desktop sidebar carrier is the shell's own <webview>:
|
|
2213
|
+
* the page has no preload bridge and the bridge protocol carries no user-action
|
|
2214
|
+
* channel, so the bar leaves its intent in `window.__dshRefIntents` and this
|
|
2215
|
+
* pump takes it over CDP. Without it the sidebar has no reference entry.
|
|
2216
|
+
*/
|
|
2217
|
+
private referencePump;
|
|
2218
|
+
/** Guards against overlapping pump runs (setInterval keeps firing while one is slow). */
|
|
2219
|
+
private referencePumping;
|
|
2220
|
+
/**
|
|
2221
|
+
* Set once the carrier swapped to a newer provider. `onUserAction` and
|
|
2222
|
+
* `onViewClosed` return void and cannot be unsubscribed, so the callbacks
|
|
2223
|
+
* themselves must go inert: otherwise one human click is handled by every
|
|
2224
|
+
* old provider still retained by the view host, producing duplicate cards.
|
|
2225
|
+
*/
|
|
2226
|
+
private disposed;
|
|
2227
|
+
/**
|
|
2228
|
+
* The session bound to the page the human has open, created on first sight.
|
|
2229
|
+
*
|
|
2230
|
+
* A reference is captured from a browser SESSION, and a page the human opened from
|
|
2231
|
+
* the sidebar's own address bar belongs to no session of ours. Adopting it into one
|
|
2232
|
+
* is what makes the selection bar appear there at all — and it is done here, inside
|
|
2233
|
+
* the pump, so it needs nothing from the human and nothing from the agent.
|
|
2234
|
+
*/
|
|
2235
|
+
private referenceSession;
|
|
2236
|
+
/** Ticks between sidebar page scans while nothing is adopted yet. */
|
|
2237
|
+
private referenceScanCountdown;
|
|
2238
|
+
/** Last scan's diagnosis, surfaced by {@link referenceStatus}. */
|
|
2239
|
+
private readonly referenceScan;
|
|
2240
|
+
private readonly httpOnly;
|
|
2241
|
+
private readonly snapshotMaxElements;
|
|
2242
|
+
private readonly contentMaxChars;
|
|
2243
|
+
private readonly downloadDir;
|
|
2244
|
+
/**
|
|
2245
|
+
* Persistent browsing history, or `undefined` when the user turned it off.
|
|
2246
|
+
* Sessions come and go; this record outlives all of them.
|
|
2247
|
+
*/
|
|
2248
|
+
private readonly historyStore;
|
|
2249
|
+
/** Live settings source; absent when nothing owns a settings document. */
|
|
2250
|
+
private readonly settingsSource;
|
|
2251
|
+
constructor(host: ElectronBrowserViewHost, config?: ElectronBrowserProviderConfig);
|
|
2252
|
+
/** Retire a provider after a carrier swap; its listeners must not act again. */
|
|
2253
|
+
dispose(): void;
|
|
2254
|
+
/** Start the page-bar pump; idempotent, unref'd so it never holds the process. */
|
|
2255
|
+
private startReferenceEntryPump;
|
|
2256
|
+
/** Stop the pump (session teardown / tests). */
|
|
2257
|
+
stopReferenceEntryPump(): void;
|
|
2258
|
+
/**
|
|
2259
|
+
* Install the bar where it is missing and forward one confirmed intent.
|
|
2260
|
+
*
|
|
2261
|
+
* Re-injection is what makes this survive navigation: a new document has no
|
|
2262
|
+
* `__dshRefOverlayInstalled`, so the next tick installs the bar again.
|
|
2263
|
+
*
|
|
2264
|
+
* One run at a time: `setInterval` fires again whether or not the previous
|
|
2265
|
+
* run finished, and a page that stopped answering would otherwise stack CDP
|
|
2266
|
+
* commands behind the wedged renderer on every tick.
|
|
2267
|
+
*/
|
|
2268
|
+
private pumpReferenceEntry;
|
|
2269
|
+
/**
|
|
2270
|
+
* Install or collect on one tab.
|
|
2271
|
+
* @returns false when the page failed enough consecutive times to be gone.
|
|
2272
|
+
*/
|
|
2273
|
+
private pumpOneTab;
|
|
2274
|
+
/** Forget one dead adopted tab; the conversation's next page starts a fresh session. */
|
|
2275
|
+
/**
|
|
2276
|
+
* Bind the page the human has open in this conversation's sidebar into a session.
|
|
2277
|
+
*
|
|
2278
|
+
* Why this is the whole entry: the sidebar page is the shell's, opened by a person
|
|
2279
|
+
* through the address bar, so no session of ours names it and nothing injects the
|
|
2280
|
+
* selection bar into it. The shell DOES expose the panel's pages by conversation id
|
|
2281
|
+
* (`listPages`), and can hand one over (`adoptPage`) — the same pair the tools use
|
|
2282
|
+
* for `dsh_browser_list_tabs`. Doing it on a timer means the bar appears on a page
|
|
2283
|
+
* the human opened themselves, which is the only entry they actually take.
|
|
2284
|
+
*
|
|
2285
|
+
* Rescans are spaced by one idle tick, not five: the listing crosses the
|
|
2286
|
+
* bridge, and a page the human just opened must get its entry within a
|
|
2287
|
+
* couple of seconds rather than five.
|
|
2288
|
+
*/
|
|
2289
|
+
private adoptSidebarPageForReference;
|
|
2290
|
+
/**
|
|
2291
|
+
* What the sidebar reference entry is doing right now.
|
|
2292
|
+
*
|
|
2293
|
+
* Served on the reference route so "there is no selection bar on my page" has an
|
|
2294
|
+
* answer that is not a guess: which conversation this process thinks it serves,
|
|
2295
|
+
* whether a page was adopted, how many the shell reported, and the last refusal.
|
|
2296
|
+
*/
|
|
2297
|
+
referenceStatus(): {
|
|
2298
|
+
readonly label?: string;
|
|
2299
|
+
readonly session?: string;
|
|
2300
|
+
readonly pages: number;
|
|
2301
|
+
readonly lastError?: string;
|
|
2302
|
+
};
|
|
2303
|
+
/**
|
|
2304
|
+
* Evaluate one expression in a tab and return its value.
|
|
2305
|
+
*
|
|
2306
|
+
* Bounded on purpose: the pump runs on a timer, and an unresponsive renderer
|
|
2307
|
+
* would otherwise hold the whole tick (and every later one) forever.
|
|
2308
|
+
* @param tab - the tab to evaluate in.
|
|
2309
|
+
* @param expression - the JS expression.
|
|
2310
|
+
* @param timeoutMs - how long to wait before treating the page as not answering.
|
|
2311
|
+
*/
|
|
2312
|
+
private evaluateInTab;
|
|
2313
|
+
/**
|
|
2314
|
+
* Usable when the host says it can back views (the self-hosted host probes
|
|
2315
|
+
* for a usable Electron binary; the desktop shell is assumed usable).
|
|
2316
|
+
*/
|
|
2317
|
+
available(): boolean;
|
|
2318
|
+
/**
|
|
2319
|
+
* Open a NEW browser session with its own view. Every call mints a fresh
|
|
2320
|
+
* session id and backing view; per-task reuse is owned by the caller (the
|
|
2321
|
+
* tool layer caches one session per DSH task). Sessions are isolated from
|
|
2322
|
+
* each other: each keeps its own tabs, active tab, and history, and only
|
|
2323
|
+
* the active tab of a session is made visible.
|
|
2324
|
+
* @param label - optional human-readable label (e.g. the DSH task id) shown
|
|
2325
|
+
* in the window title so a human can tell which task's page is visible.
|
|
2326
|
+
*/
|
|
2327
|
+
open(label?: string): Promise<BrowserSessionId>;
|
|
2328
|
+
/** Open a URL in the active tab (default) or a new tab. */
|
|
2329
|
+
/**
|
|
2330
|
+
* The most recent open request, for the Web sidebar.
|
|
2331
|
+
*
|
|
2332
|
+
* On the desktop shell the host half tells the shell to place a tab (`__dshBuiltinBrowser.openPanel`)
|
|
2333
|
+
* through the bridge. The Web shell has no such channel, so a tool-opened page lived only in the
|
|
2334
|
+
* plugin's own browser while the panel stayed empty — and "open it in the sidebar" took several manual
|
|
2335
|
+
* steps. The client polls this one slot and places the tab itself.
|
|
2336
|
+
* @returns the last request and when it arrived, or undefined when nothing was opened yet.
|
|
2337
|
+
*/
|
|
2338
|
+
lastOpenRequest(): {
|
|
2339
|
+
readonly url: string;
|
|
2340
|
+
readonly at: number;
|
|
2341
|
+
} | undefined;
|
|
2342
|
+
/** Set by {@link openUrl}; read by the client through the HTTP surface. */
|
|
2343
|
+
private lastOpen;
|
|
2344
|
+
openUrl(session: BrowserSessionId, request: BrowserOpenRequest, signal?: AbortSignal): Promise<void>;
|
|
2345
|
+
/**
|
|
2346
|
+
* Bind the carrier page that already shows this URL, if there is one.
|
|
2347
|
+
*
|
|
2348
|
+
* Compare the part of a URL that says WHICH page it is: scheme, host, path and query. A hash is a
|
|
2349
|
+
* position inside a document, and a trailing slash is spelling, so neither makes a different page.
|
|
2350
|
+
* @param s - the session to bind the page into.
|
|
2351
|
+
* @param url - the URL being opened.
|
|
2352
|
+
* @returns whether an existing page was taken over.
|
|
2353
|
+
*/
|
|
2354
|
+
private adoptMatchingPage;
|
|
2355
|
+
/** The parts of a URL that decide identity, or undefined when it cannot be parsed. */
|
|
2356
|
+
private comparableUrl;
|
|
2357
|
+
/** List the session's tabs with their titles. */
|
|
2358
|
+
listTabs(session: BrowserSessionId): Promise<readonly BrowserTab[]>;
|
|
2359
|
+
/** Switch to a tab by id, making its view visible. */
|
|
2360
|
+
switchTab(session: BrowserSessionId, tabId: string): Promise<void>;
|
|
2361
|
+
/** Close one tab; closing the active tab activates the next. */
|
|
2362
|
+
closeTab(session: BrowserSessionId, tabId: string): Promise<void>;
|
|
2363
|
+
/**
|
|
2364
|
+
* Find a tab by id, preferring the calling session. Tab ids are globally
|
|
2365
|
+
* unique UUIDs, so when the calling session does not hold the tab (the tool
|
|
2366
|
+
* layer's session resolution can drift from the session that opened it),
|
|
2367
|
+
* fall back to locating it in any other session instead of failing — the
|
|
2368
|
+
* caller explicitly named a tab, so acting on it is what they want. Throws
|
|
2369
|
+
* BROWSER_TAB_UNKNOWN with the session's actual tabs when the id exists
|
|
2370
|
+
* nowhere.
|
|
2371
|
+
*/
|
|
2372
|
+
private locateTab;
|
|
2373
|
+
/** Close every tab and reset to one blank tab. */
|
|
2374
|
+
reset(session: BrowserSessionId): Promise<void>;
|
|
2375
|
+
/** Navigate the active tab's view to a URL, honoring HTTP(S)-only admission. */
|
|
2376
|
+
navigate(session: BrowserSessionId, request: {
|
|
2377
|
+
readonly url: string;
|
|
2378
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
2379
|
+
private checkNavigation;
|
|
2380
|
+
private navigateTab;
|
|
2381
|
+
/**
|
|
2382
|
+
* A per-document stamp: `performance.timeOrigin` is unique per document load,
|
|
2383
|
+
* so it tells a same-URL reload and an A→B→A redirect apart from the document
|
|
2384
|
+
* that was current before the navigation. Empty string when unreadable.
|
|
2385
|
+
*/
|
|
2386
|
+
private documentStamp;
|
|
2387
|
+
/**
|
|
2388
|
+
* One cheap in-page reading of the document's identity and parse state.
|
|
2389
|
+
*
|
|
2390
|
+
* Returns null when the page did NOT answer (mid-commit, execution context
|
|
2391
|
+
* destroyed) — the caller keeps waiting. A page that answered with an
|
|
2392
|
+
* unexpected shape (an override or a non-conforming host; the production
|
|
2393
|
+
* expression always yields a string) is reported as `unknown` rather than as
|
|
2394
|
+
* "no answer": blocking the navigation for the whole budget on a page that
|
|
2395
|
+
* demonstrably responded has no upside.
|
|
2396
|
+
*/
|
|
2397
|
+
private documentProbe;
|
|
2398
|
+
/**
|
|
2399
|
+
* Page.navigate resolves at navigation COMMIT, not at load: the new document
|
|
2400
|
+
* is already current (so location.href and document.title are the new page's)
|
|
2401
|
+
* while its DOM is still being parsed. dsh_browser_open snapshots immediately
|
|
2402
|
+
* after navigating, which is why it could report the right title with zero
|
|
2403
|
+
* interactive elements — and why a separate dsh_browser_snapshot right after
|
|
2404
|
+
* always found them.
|
|
2405
|
+
*
|
|
2406
|
+
* Wait — bounded, best-effort — for the new document to settle: readyState
|
|
2407
|
+
* must reach interactive/complete AND the document identity must have
|
|
2408
|
+
* changed. A page that never settles must not fail a navigation that already
|
|
2409
|
+
* succeeded, so a timeout here is swallowed.
|
|
2410
|
+
*/
|
|
2411
|
+
private settleDocument;
|
|
2412
|
+
/**
|
|
2413
|
+
* Make sure the active tab's view can actually receive synthesized input.
|
|
2414
|
+
* Chromium drops `Input.*` events for a view with no display surface, so this
|
|
2415
|
+
* runs before click/type/key and fails loudly (BROWSER_VIEW_NOT_PRESENTED)
|
|
2416
|
+
* rather than reporting a success the page never saw.
|
|
2417
|
+
* @param s - the session whose active view must be presented.
|
|
2418
|
+
* @param signal - optional cancellation.
|
|
2419
|
+
* @returns the view the session's active tab has AFTER the presentation barrier.
|
|
2420
|
+
*/
|
|
2421
|
+
private present;
|
|
2422
|
+
/**
|
|
2423
|
+
* Refuse to send synthesized input to a view that is no longer the one it was located
|
|
2424
|
+
* against.
|
|
2425
|
+
*
|
|
2426
|
+
* `locateHandle` was captured before a page-side locate that can consume its whole
|
|
2427
|
+
* 10s budget; the session's active tab is re-read afterwards. If they differ, the human
|
|
2428
|
+
* switched tabs mid-flight (the product's whole point is that they can take over), and
|
|
2429
|
+
* the coordinates belong to one page while the dispatch would go to another. Comparing
|
|
2430
|
+
* the handles turns that into a loud, retryable error instead of input the caller
|
|
2431
|
+
* believes landed.
|
|
2432
|
+
* @param session - the session id, for the message.
|
|
2433
|
+
* @param locateHandle - the view the locate ran in.
|
|
2434
|
+
* @param liveHandle - the view that is active now.
|
|
2435
|
+
*/
|
|
2436
|
+
private assertSameView;
|
|
2437
|
+
/**
|
|
2438
|
+
* Give the view web focus before synthesizing keyboard input.
|
|
2439
|
+
*
|
|
2440
|
+
* A renderer only delivers key events to the view that holds web focus. A
|
|
2441
|
+
* view that was created but never clicked holds none — and `Input` events
|
|
2442
|
+
* injected over CDP do not grant it — so the FIRST `dsh_browser_key` of a fresh
|
|
2443
|
+
* session vanished inside the renderer while the command still answered
|
|
2444
|
+
* success. Hosts that cannot focus a view (a test double, a different shell
|
|
2445
|
+
* adapter) simply have no `focus`, and nothing changes for them.
|
|
2446
|
+
*/
|
|
2447
|
+
private focusView;
|
|
2448
|
+
/** Execute JS in the active tab's page context. */
|
|
2449
|
+
execute(session: BrowserSessionId, request: BrowserExecuteRequest, signal?: AbortSignal): Promise<BrowserExecuteResult>;
|
|
2450
|
+
/** Run a fixed browser operation; the request cannot contain a script. */
|
|
2451
|
+
pageOperation(session: BrowserSessionId, request: BrowserPageOperationRequest, signal?: AbortSignal): Promise<BrowserExecuteResult>;
|
|
2452
|
+
/** Send page pointer input through CDP while preserving presentation and cancellation policy. */
|
|
2453
|
+
private dispatchPointer;
|
|
2454
|
+
private evaluatePage;
|
|
2455
|
+
/**
|
|
2456
|
+
* Poll until the active tab's page is ready (and optional URL/selector
|
|
2457
|
+
* match), or the budget runs out. Returns a verdict instead of throwing on
|
|
2458
|
+
* timeout — the caller (model) decides what a miss means. Polling evaluates
|
|
2459
|
+
* in the CURRENT document, so after a navigation the old document may
|
|
2460
|
+
* briefly answer; pass the expected `url` to disambiguate.
|
|
2461
|
+
*/
|
|
2462
|
+
waitFor(session: BrowserSessionId, request: BrowserWaitRequest, signal?: AbortSignal): Promise<BrowserWaitResult>;
|
|
2463
|
+
/** Produce an AI-friendly snapshot of the active tab. */
|
|
2464
|
+
snapshot(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserSnapshotResult>;
|
|
2465
|
+
/**
|
|
2466
|
+
* Read the active tab's accessibility tree: semantic roles/names/states for
|
|
2467
|
+
* every interactive node (Chrome's `computedRole`/`computedName` when
|
|
2468
|
+
* available, tag/attribute inference otherwise). Pierces same-origin
|
|
2469
|
+
* iframes and shadow roots like the snapshot; cross-origin frames stay
|
|
2470
|
+
* opaque. Coordinates are top-document viewport-relative, so a node can
|
|
2471
|
+
* also be driven by click/type.
|
|
2472
|
+
*/
|
|
2473
|
+
a11y(session: BrowserSessionId, request: BrowserA11yRequest, signal?: AbortSignal): Promise<BrowserA11yResult>;
|
|
2474
|
+
/** Check whether a human-verification challenge is blocking the active tab. */
|
|
2475
|
+
detectChallenge(session: BrowserSessionId, signal?: AbortSignal): Promise<BrowserChallenge>;
|
|
2476
|
+
/** Fetch page content in a requested format. */
|
|
2477
|
+
content(session: BrowserSessionId, request: BrowserContentRequest, signal?: AbortSignal): Promise<BrowserContentResult>;
|
|
2478
|
+
/**
|
|
2479
|
+
* Click at viewport coordinates, or at a located element's center when a
|
|
2480
|
+
* `target` (css/text/xpath) is given. CDP mousePressed + mouseReleased.
|
|
2481
|
+
*/
|
|
2482
|
+
click(session: BrowserSessionId, request: BrowserClickRequest | {
|
|
2483
|
+
readonly target: BrowserElementTarget;
|
|
2484
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
2485
|
+
/**
|
|
2486
|
+
* Click many points in order, once.
|
|
2487
|
+
*
|
|
2488
|
+
* The same wire sequence as {@link click}, looped — only the round-trip count changes. Presenting
|
|
2489
|
+
* happens ONCE: the display-surface barrier is per view, not per press, and paying it for every
|
|
2490
|
+
* point is what made an 86-cell board expensive.
|
|
2491
|
+
*
|
|
2492
|
+
* Stops at the first point that fails and reports where: a run that pressed through a page which
|
|
2493
|
+
* had navigated or lost its surface would fill the wrong cells and still answer success.
|
|
2494
|
+
* @param session - the session to click in.
|
|
2495
|
+
* @param request - the points and the interval between them.
|
|
2496
|
+
* @param signal - cancellation between points.
|
|
2497
|
+
* @returns how many points landed, and where it stopped if it did not finish.
|
|
2498
|
+
*/
|
|
2499
|
+
clickSequence(session: BrowserSessionId, request: BrowserClickSequenceRequest, signal?: AbortSignal): Promise<BrowserClickSequenceResult>;
|
|
2500
|
+
/**
|
|
2501
|
+
* Type into the focused element, or focus a located element (css/text/xpath)
|
|
2502
|
+
* first and then insert the text.
|
|
2503
|
+
*/
|
|
2504
|
+
type(session: BrowserSessionId, request: BrowserTypeRequest | {
|
|
2505
|
+
readonly target: BrowserElementTarget;
|
|
2506
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
2507
|
+
/** Scroll the page: by deltas, to a selector, or to top/bottom. */
|
|
2508
|
+
scroll(session: BrowserSessionId, request: BrowserScrollRequest, signal?: AbortSignal): Promise<void>;
|
|
2509
|
+
/** Go back (-1) or forward (+1) in the active tab's navigation history. */
|
|
2510
|
+
private historyStep;
|
|
2511
|
+
/** Go back in the active tab's history. */
|
|
2512
|
+
back(session: BrowserSessionId, signal?: AbortSignal): Promise<void>;
|
|
2513
|
+
/** Go forward in the active tab's history. */
|
|
2514
|
+
forward(session: BrowserSessionId, signal?: AbortSignal): Promise<void>;
|
|
2515
|
+
/** Reload the active tab. */
|
|
2516
|
+
reload(session: BrowserSessionId, signal?: AbortSignal): Promise<void>;
|
|
2517
|
+
/** Press one named key (Enter/Tab/arrows/…) via CDP key events. */
|
|
2518
|
+
key(session: BrowserSessionId, request: BrowserKeyRequest, signal?: AbortSignal): Promise<void>;
|
|
2519
|
+
/**
|
|
2520
|
+
* Fill a form's fields in one batch. Runs one page-context script that
|
|
2521
|
+
* resolves each field (selector, or name/label/placeholder among visible
|
|
2522
|
+
* controls), sets its value with the native prototype setter (React/Vue
|
|
2523
|
+
* controlled inputs included) plus input/change events, handles
|
|
2524
|
+
* select/checkbox/radio/contenteditable, and optionally submits the form.
|
|
2525
|
+
*/
|
|
2526
|
+
fillForm(session: BrowserSessionId, request: BrowserFillRequest, signal?: AbortSignal): Promise<BrowserFillResult>;
|
|
2527
|
+
/**
|
|
2528
|
+
* Build an in-page async IIFE that locates ONE element by css/text/xpath
|
|
2529
|
+
* (polling until it appears or the budget runs out) and then runs `body`
|
|
2530
|
+
* with `el` in scope. Shared by the target-based tools: click/type (②),
|
|
2531
|
+
* setValue/check/select/clear/getValue (③), and the scrape item wait.
|
|
2532
|
+
* A selector that fails to PARSE is reported immediately instead of being
|
|
2533
|
+
* polled until the budget expires — see the comment in `match`.
|
|
2534
|
+
*/
|
|
2535
|
+
private buildTargetScript;
|
|
2536
|
+
/**
|
|
2537
|
+
* Shared evaluate wrapper for the target-based tools. Runs the in-page
|
|
2538
|
+
* script and returns its result object; throws a typed BrowserError on
|
|
2539
|
+
* evaluation failure or an in-page `{ ok: false, error }` verdict.
|
|
2540
|
+
*/
|
|
2541
|
+
private runTargetScript;
|
|
2542
|
+
/** Set one element's value (native setter + input/change, React-friendly). */
|
|
2543
|
+
setValue(session: BrowserSessionId, request: BrowserSetValueRequest, signal?: AbortSignal): Promise<BrowserSetValueResult>;
|
|
2544
|
+
/** Check or uncheck one checkbox/radio. */
|
|
2545
|
+
check(session: BrowserSessionId, request: BrowserCheckRequest, signal?: AbortSignal): Promise<{
|
|
2546
|
+
readonly checked: boolean;
|
|
2547
|
+
}>;
|
|
2548
|
+
/** Select one option of a <select>, by value, visible text, or index. */
|
|
2549
|
+
selectOption(session: BrowserSessionId, request: BrowserSelectRequest, signal?: AbortSignal): Promise<BrowserSelectResult>;
|
|
2550
|
+
/** Clear one input/textarea/contenteditable (or uncheck a checkbox/radio). */
|
|
2551
|
+
clearField(session: BrowserSessionId, request: BrowserClearRequest, signal?: AbortSignal): Promise<{
|
|
2552
|
+
readonly cleared: boolean;
|
|
2553
|
+
}>;
|
|
2554
|
+
/** Read one element's current value (for verification). */
|
|
2555
|
+
getValue(session: BrowserSessionId, request: BrowserGetValueRequest, signal?: AbortSignal): Promise<BrowserGetValueResult>;
|
|
2556
|
+
/**
|
|
2557
|
+
* Extract structured data from repeated DOM items (static CSS, CSP-safe —
|
|
2558
|
+
* no arbitrary code runs). Waits for the item selector, then maps each item
|
|
2559
|
+
* through the field selectors; `selector@attr` reads an attribute instead
|
|
2560
|
+
* of text (`a@href` yields an absolute URL).
|
|
2561
|
+
*/
|
|
2562
|
+
scrape(session: BrowserSessionId, request: BrowserScrapeRequest, signal?: AbortSignal): Promise<BrowserScrapeResult>;
|
|
2563
|
+
/**
|
|
2564
|
+
* Refuse an action the settings have switched off.
|
|
2565
|
+
*
|
|
2566
|
+
* These switches belong to the OPERATOR. The settings document is written through the
|
|
2567
|
+
* plugin's own panel and no tool can reach it, so — unlike `dsh_browser_restrict`, which the
|
|
2568
|
+
* model owns and can lift at will — a refusal here stands for as long as the setting does.
|
|
2569
|
+
* That is the point of them: a deployment can take page-script execution, downloads, or
|
|
2570
|
+
* login-state writes off the table without relying on the model's cooperation.
|
|
2571
|
+
*
|
|
2572
|
+
* Read through `settingsSource` on every call rather than captured at construction, so
|
|
2573
|
+
* flipping a switch applies to the next command instead of the next restart — the same
|
|
2574
|
+
* rule the credentials gate follows.
|
|
2575
|
+
* @param action - which switch to consult.
|
|
2576
|
+
* @throws BrowserError when that switch is off.
|
|
2577
|
+
*/
|
|
2578
|
+
private assertActionAllowed;
|
|
2579
|
+
/**
|
|
2580
|
+
* Admit a caller-supplied save path for a file the browser writes to disk.
|
|
2581
|
+
* ONE gate for both `dsh_browser_download` and `dsh_browser_screenshot`: the path
|
|
2582
|
+
* must be absolute, must resolve inside `downloadDir`, and must not already
|
|
2583
|
+
* exist. Without it a prompt-injected agent could write — or silently
|
|
2584
|
+
* replace — any file the DSH process can reach, which also escapes the file
|
|
2585
|
+
* sandbox every other tool in the set runs under.
|
|
2586
|
+
* @param savePath - the caller's target path.
|
|
2587
|
+
* @param kind - the operation, used in the error code and message.
|
|
2588
|
+
* @returns the resolved absolute target path.
|
|
2589
|
+
* @throws BrowserError when the path is relative, outside the directory, or occupied.
|
|
2590
|
+
*/
|
|
2591
|
+
private admitSavePath;
|
|
2592
|
+
/**
|
|
2593
|
+
* Download an HTTP(S) URL with the session's cookies to a local file.
|
|
2594
|
+
* Admission is the shared {@link admitSavePath} gate. The carrier downloads
|
|
2595
|
+
* with its own authenticated browser session. Both admitted paths and screenshots are confined
|
|
2596
|
+
* to `downloadDir`, so a prompt-injected agent cannot write arbitrary
|
|
2597
|
+
* machine paths.
|
|
2598
|
+
* @param session - the session whose cookies are used.
|
|
2599
|
+
* @param request - the URL plus the absolute target path.
|
|
2600
|
+
* @param signal - optional cancellation.
|
|
2601
|
+
* @returns the path the file was written to.
|
|
2602
|
+
*/
|
|
2603
|
+
download(session: BrowserSessionId, request: {
|
|
2604
|
+
readonly url: string;
|
|
2605
|
+
readonly savePath: string;
|
|
2606
|
+
}, signal?: AbortSignal): Promise<{
|
|
2607
|
+
readonly path: string;
|
|
2608
|
+
}>;
|
|
2609
|
+
/**
|
|
2610
|
+
* Export the session's cookies (login state) as serializable objects.
|
|
2611
|
+
* Self-hosted only; the desktop shell's embedded views use the real profile.
|
|
2612
|
+
*/
|
|
2613
|
+
flushAuth(session: BrowserSessionId): Promise<readonly ExportedCookie[]>;
|
|
2614
|
+
/** Import cookies into the session (restore login state). Self-hosted only. */
|
|
2615
|
+
restoreAuth(session: BrowserSessionId, cookies: readonly ExportedCookie[]): Promise<number>;
|
|
2616
|
+
/**
|
|
2617
|
+
* Capture the active page WITHOUT presenting it.
|
|
2618
|
+
*
|
|
2619
|
+
* `screenshot` calls `showActive()` before capturing, and that is right for a tool whose point is
|
|
2620
|
+
* that the human sees what the model just captured. It is also what makes that path unusable for a
|
|
2621
|
+
* live preview: presenting on every frame would move focus, switch tabs and expand windows on the
|
|
2622
|
+
* host's screen — exactly the side effects a viewer must not cause (issue #34).
|
|
2623
|
+
*
|
|
2624
|
+
* So this does the capture and nothing else. Deliberately narrow: viewport only, JPEG at the
|
|
2625
|
+
* preview defaults, a short timeout, no save path, no history entry, no carrier recovery. A
|
|
2626
|
+
* preview that rebuilt a vanished carrier would make watching a way to start a browser, which the
|
|
2627
|
+
* design forbids: no page means "nothing to watch", not "open one".
|
|
2628
|
+
* @param session - the session whose active page to capture.
|
|
2629
|
+
* @returns the encoded image and its dimensions; throws BROWSER_PREVIEW_UNAVAILABLE when the page
|
|
2630
|
+
* is not painted, which the caller turns into a "paused" state rather than an error.
|
|
2631
|
+
*/
|
|
2632
|
+
capturePassive(session: BrowserSessionId): Promise<{
|
|
2633
|
+
readonly dataUrl: string;
|
|
2634
|
+
readonly width?: number;
|
|
2635
|
+
readonly height?: number;
|
|
2636
|
+
}>;
|
|
2637
|
+
/** Capture the current page, optionally full-page, PNG or JPEG, scalable. */
|
|
2638
|
+
screenshot(session: BrowserSessionId, request?: BrowserScreenshotRequest, signal?: AbortSignal): Promise<{
|
|
2639
|
+
readonly dataUrl: string;
|
|
2640
|
+
readonly path?: string;
|
|
2641
|
+
readonly width?: number;
|
|
2642
|
+
readonly height?: number;
|
|
2643
|
+
}>;
|
|
2644
|
+
/**
|
|
2645
|
+
* Build the data URL and optionally write the image to disk. The caller's
|
|
2646
|
+
* path goes through the SAME {@link admitSavePath} gate as a download — it
|
|
2647
|
+
* must be absolute, resolve inside `downloadDir`, and not be an existing
|
|
2648
|
+
* file — so a screenshot cannot be used to write to, or silently replace,
|
|
2649
|
+
* files anywhere the DSH process happens to have permission (issue #13).
|
|
2650
|
+
*/
|
|
2651
|
+
private saveScreenshot;
|
|
2652
|
+
/** Append one operation to the session's history. */
|
|
2653
|
+
private record;
|
|
2654
|
+
/** Return the session's chronological operation log (newest last). */
|
|
2655
|
+
history(session: BrowserSessionId): Promise<readonly BrowserHistoryEntry[]>;
|
|
2656
|
+
/**
|
|
2657
|
+
* Record one page visit in the persistent browsing history. Fire-and-forget by
|
|
2658
|
+
* design: a visit must never delay or fail the navigation that produced it,
|
|
2659
|
+
* and the title is only worth reading once the document has settled.
|
|
2660
|
+
* @param s - the session that drove the visit.
|
|
2661
|
+
* @param handle - the view whose document just loaded.
|
|
2662
|
+
*/
|
|
2663
|
+
private recordVisit;
|
|
2664
|
+
/**
|
|
2665
|
+
* List persisted visits, newest first — what `dsh_browser_visited` reads back.
|
|
2666
|
+
* @param options - result cap and an optional hostname filter.
|
|
2667
|
+
* @returns the matching visits, or an empty list when history is disabled.
|
|
2668
|
+
*/
|
|
2669
|
+
visited(options?: {
|
|
2670
|
+
readonly limit?: number;
|
|
2671
|
+
readonly domain?: string;
|
|
2672
|
+
readonly query?: string;
|
|
2673
|
+
readonly session?: string;
|
|
2674
|
+
}): readonly VisitedPage[];
|
|
2675
|
+
/**
|
|
2676
|
+
* Show the synthetic pointer on a view, unless the user switched it off. The
|
|
2677
|
+
* cursor is the "the agent has taken over this tab" signal, so it is painted
|
|
2678
|
+
* for every operation that has a landing point — including DOM-level ones that
|
|
2679
|
+
* move no real pointer.
|
|
2680
|
+
* @param handle - the view to paint into.
|
|
2681
|
+
* @param x - viewport x in CSS pixels.
|
|
2682
|
+
* @param y - viewport y in CSS pixels.
|
|
2683
|
+
* @param action - click pulses a ripple; move only relocates.
|
|
2684
|
+
* @param label - short description of the operation, shown beside the pointer.
|
|
2685
|
+
* @param force - paint even when the pointer is already there (a click ripple must
|
|
2686
|
+
* always play; a bare move need not repeat).
|
|
2687
|
+
*/
|
|
2688
|
+
private showCursor;
|
|
2689
|
+
/**
|
|
2690
|
+
* Replay one recorded operation by sequence number. Navigate/click/type are
|
|
2691
|
+
* re-issued against the current page; execute re-runs its script. The
|
|
2692
|
+
* replayed step is appended to history as a new entry.
|
|
2693
|
+
* @param session - the session id.
|
|
2694
|
+
* @param seq - the recorded entry's sequence number to replay.
|
|
2695
|
+
*/
|
|
2696
|
+
replay(session: BrowserSessionId, seq: number): Promise<void>;
|
|
2697
|
+
/** Close the session and destroy all its views. Idempotent. */
|
|
2698
|
+
close(session: BrowserSessionId): Promise<void>;
|
|
2699
|
+
/** Look up a session or throw the unknown-session error. */
|
|
2700
|
+
private session;
|
|
2701
|
+
/** The active tab of a session. */
|
|
2702
|
+
private activeTab;
|
|
2703
|
+
/** Append a fresh tab and make it active. */
|
|
2704
|
+
private newTab;
|
|
2705
|
+
/**
|
|
2706
|
+
* Swap a wedged view for a fresh blank one, keeping the tab's public id.
|
|
2707
|
+
*
|
|
2708
|
+
* A view whose renderer never commits cannot be read again: every evaluate into it runs out its
|
|
2709
|
+
* whole budget. Replacing it is what turns that from permanent into one bad call — the tab id
|
|
2710
|
+
* callers hold stays valid, and the next `dsh_browser_open` with the real URL re-populates it.
|
|
2711
|
+
*
|
|
2712
|
+
* The old view is destroyed AFTER the new one is in place, so a failure here cannot leave the
|
|
2713
|
+
* session holding a handle that is already gone.
|
|
2714
|
+
* @param s - the session owning the tab.
|
|
2715
|
+
* @param tab - the tab to reset.
|
|
2716
|
+
*/
|
|
2717
|
+
private replaceTabWithBlank;
|
|
2718
|
+
/** Find a session's tab by its backing view id (toolbar actions carry view ids). */
|
|
2719
|
+
private tabByViewId;
|
|
2720
|
+
/**
|
|
2721
|
+
* Whether a session is still live. The human closing a window ends its session
|
|
2722
|
+
* (see {@link handleViewClosed}), so callers that cache ids must ask first.
|
|
2723
|
+
* @param session - the session id to test.
|
|
2724
|
+
*/
|
|
2725
|
+
exists(session: BrowserSessionId): boolean;
|
|
2726
|
+
/**
|
|
2727
|
+
* The sessions a viewer may watch, which is exactly the sessions that exist.
|
|
2728
|
+
*
|
|
2729
|
+
* Served so the browser page can build a frame URL without guessing: the provider names its
|
|
2730
|
+
* sessions, and an id invented by a client is refused at the route. Ids only — no URL, no title,
|
|
2731
|
+
* no target handle — because the point is to let the panel address a session, not to describe
|
|
2732
|
+
* what is in it.
|
|
2733
|
+
* @returns the live session ids.
|
|
2734
|
+
*/
|
|
2735
|
+
watchableSessions(): readonly BrowserSessionId[];
|
|
2736
|
+
/**
|
|
2737
|
+
* The human closed a browser window: the session that window showed is over.
|
|
2738
|
+
* Ending it here is what makes the next call a clean start rather than a
|
|
2739
|
+
* resurrection of an invisible window. Browsing history and login state live
|
|
2740
|
+
* on disk, so nothing the human cares about is lost with it.
|
|
2741
|
+
* @param windowId - the group key the host reported, which is the session id.
|
|
2742
|
+
*/
|
|
2743
|
+
private handleViewClosed;
|
|
2744
|
+
/**
|
|
2745
|
+
* Route a user-initiated action from the host's UI into the session model.
|
|
2746
|
+
* Fire-and-forget by design: a user action failing (e.g. an unreachable
|
|
2747
|
+
* URL typed into the address bar) must never crash the host UI loop — it
|
|
2748
|
+
* is reported to the host (toolbar) when the host supports it, else logged.
|
|
2749
|
+
*/
|
|
2750
|
+
private handleUserAction;
|
|
2751
|
+
/**
|
|
2752
|
+
* Report a failed user action to the host UI (toolbar), when supported.
|
|
2753
|
+
*
|
|
2754
|
+
* Two properties matter here, because this runs inside the catch of an async
|
|
2755
|
+
* handler (issue #16):
|
|
2756
|
+
* - the receiver must be preserved. Reading the method off the host and calling
|
|
2757
|
+
* it unbound runs the host's implementation with `this === undefined`, so its
|
|
2758
|
+
* very first statement (`void this.ready()`) throws, the throw escapes the
|
|
2759
|
+
* async catch as an unhandled rejection, and the whole DSH host exits;
|
|
2760
|
+
* - this method must be incapable of throwing. Reporting a failed action is
|
|
2761
|
+
* diagnostics: it can never be allowed to become the failure.
|
|
2762
|
+
*/
|
|
2763
|
+
private notifyUserActionError;
|
|
2764
|
+
/**
|
|
2765
|
+
* Whether the operator asked for quiet mode (`ui.quiet`).
|
|
2766
|
+
*
|
|
2767
|
+
* Read live on every call rather than captured at construction: the panel writes the document
|
|
2768
|
+
* and the next operation is expected to honour it, without a restart.
|
|
2769
|
+
* @returns true when the carrier must present views without taking the screen over.
|
|
2770
|
+
*/
|
|
2771
|
+
private isQuiet;
|
|
2772
|
+
/**
|
|
2773
|
+
* Ask the host to show the active tab's view, carrying the session label.
|
|
2774
|
+
*
|
|
2775
|
+
* The two halves are sequential, not alternatives. `showView` makes the view the
|
|
2776
|
+
* visible one — which is what keeps what the human sees in step with what the agent
|
|
2777
|
+
* drives, and what lets `capturePage` return an image at all (a hidden view captures
|
|
2778
|
+
* empty) — while `collapse` folds the carrier's own chrome away when the user asked
|
|
2779
|
+
* for no auto-expand. Making them exclusive meant that with auto-expand off this
|
|
2780
|
+
* method did nothing at all on carriers without `collapse` (the self-hosted one),
|
|
2781
|
+
* silently desynchronising the two and failing every screenshot.
|
|
2782
|
+
*/
|
|
2783
|
+
private showActive;
|
|
2784
|
+
/** Read the current URL of a view through CDP. */
|
|
2785
|
+
private currentUrl;
|
|
2786
|
+
}
|
|
2787
|
+
/**
|
|
2788
|
+
* Self-hosted view host: spawns the plugin's Electron child on first use and
|
|
2789
|
+
* keeps it alive until dispose(). Fallback when no desktop shell provides
|
|
2790
|
+
* ctx.electronViewHost.
|
|
2791
|
+
*/
|
|
2792
|
+
export declare class RemoteElectronViewHost implements ElectronBrowserViewHost {
|
|
2793
|
+
private readonly hostMainPath;
|
|
2794
|
+
/** Test seam: the executable to spawn instead of the resolved Electron
|
|
2795
|
+
* binary. Absent -> resolveElectronPath() (production behavior). */
|
|
2796
|
+
private readonly spawnExecutable?;
|
|
2797
|
+
/** Test seam: the binary probe behind `available()`. Absent ->
|
|
2798
|
+
* resolveElectronPath(). */
|
|
2799
|
+
private readonly probe;
|
|
2800
|
+
private client;
|
|
2801
|
+
private server;
|
|
2802
|
+
private pendingSocket;
|
|
2803
|
+
private readonly views;
|
|
2804
|
+
private readyPromise;
|
|
2805
|
+
private disposed;
|
|
2806
|
+
/** Last probe result. A success is kept for the host's lifetime; a failure
|
|
2807
|
+
* is retried after `PROBE_RETRY_MS` (see `available()`). */
|
|
2808
|
+
private electronAvailable;
|
|
2809
|
+
/** Earliest time the next probe may run after a negative one. */
|
|
2810
|
+
private nextProbeAt;
|
|
2811
|
+
/** Consecutive child starts that did not survive; drives {@link startRetryAt}. */
|
|
2812
|
+
private startFailures;
|
|
2813
|
+
/** Earliest time `ready()` may spawn another child after a failed start. */
|
|
2814
|
+
private startRetryAt;
|
|
2815
|
+
/** When the last start failure was reported, used to keep one death to one log line. */
|
|
2816
|
+
private lastStartFailureAt;
|
|
2817
|
+
/** Window groups (windowId per view), re-sent on every materialization so
|
|
2818
|
+
* a restarted child still places views in the right windows. */
|
|
2819
|
+
private readonly groups;
|
|
2820
|
+
/** The provider's user-action handler; routes toolbar actions into sessions. */
|
|
2821
|
+
private userActionHandler;
|
|
2822
|
+
/**
|
|
2823
|
+
* The provider's handler for a window the human closed. Closing the interface
|
|
2824
|
+
* ends the session it showed: history and login state stay on disk, so the
|
|
2825
|
+
* next open starts clean instead of resuming a window nobody can see.
|
|
2826
|
+
*/
|
|
2827
|
+
private viewClosedHandler;
|
|
2828
|
+
constructor(hostMainPath: string,
|
|
2829
|
+
/** Test seam: the executable to spawn instead of the resolved Electron
|
|
2830
|
+
* binary. Absent -> resolveElectronPath() (production behavior). */
|
|
2831
|
+
spawnExecutable?: string | undefined,
|
|
2832
|
+
/** Test seam: the binary probe behind `available()`. Absent ->
|
|
2833
|
+
* resolveElectronPath(). */
|
|
2834
|
+
probe?: () => void);
|
|
2835
|
+
/**
|
|
2836
|
+
* Cheap usability probe: can we find an Electron binary to spawn? The scan
|
|
2837
|
+
* is filesystem-only (no network), per the seam's contract, so a missing
|
|
2838
|
+
* binary surfaces as `BROWSER_PROVIDER_UNAVAILABLE` at provider selection
|
|
2839
|
+
* instead of a confusing spawn failure on first use.
|
|
2840
|
+
*
|
|
2841
|
+
* A success is cached for the host's lifetime. A failure is NOT: an install
|
|
2842
|
+
* (`npm i electron`, or the postinstall that fetches the binary) can land
|
|
2843
|
+
* long after DSH started, and provider selection happens once per process —
|
|
2844
|
+
* caching "no" permanently reported "no usable browser provider is
|
|
2845
|
+
* registered" until DSH restarted, with no way back short of that. Retrying
|
|
2846
|
+
* on a cooldown heals it by itself while keeping the scan off the hot path.
|
|
2847
|
+
*/
|
|
2848
|
+
available(): boolean;
|
|
2849
|
+
/**
|
|
2850
|
+
* Retire the cached "an Electron binary is here" answer.
|
|
2851
|
+
*
|
|
2852
|
+
* A success is cached for the host's lifetime because rescanning on every tool call was
|
|
2853
|
+
* the original bug — but the probe reads the FILESYSTEM, so it cannot see a binary that
|
|
2854
|
+
* stops being usable afterwards. Only a real spawn attempt can observe that, which is why
|
|
2855
|
+
* the two failure paths in {@link RemoteElectronViewHost.start} call this: the next
|
|
2856
|
+
* `available()` rescans and reports what is actually on disk, instead of advertising a
|
|
2857
|
+
* provider that cannot start.
|
|
2858
|
+
*/
|
|
2859
|
+
private forgetBinary;
|
|
2860
|
+
/**
|
|
2861
|
+
* Whether the binary the host would spawn — or the entry it needs — is no longer there.
|
|
2862
|
+
*
|
|
2863
|
+
* Only asked after a launch actually failed, so a healthy path never pays for it. The
|
|
2864
|
+
* entry script counts because Electron exits 1 with empty stderr when it cannot load it,
|
|
2865
|
+
* and resolution itself throws exactly when it can find nothing, which is the same answer.
|
|
2866
|
+
* @returns true when the next `available()` must rescan instead of reusing its cache.
|
|
2867
|
+
*/
|
|
2868
|
+
private binaryIsGone;
|
|
2869
|
+
/**
|
|
2870
|
+
* Ensure the child is up and ready (lazy on first use; restarts after a crash).
|
|
2871
|
+
*
|
|
2872
|
+
* Never throws synchronously. Callers are fire-and-forget
|
|
2873
|
+
* (`void this.ready().then(…).catch(…)`), and a synchronous throw escapes their
|
|
2874
|
+
* `.catch` entirely — the shape that let a failed toolbar report take the whole
|
|
2875
|
+
* DSH host down (issue #16). A disposed host is reported as a rejected promise
|
|
2876
|
+
* instead, which those callers already handle.
|
|
2877
|
+
*/
|
|
2878
|
+
private ready;
|
|
2879
|
+
/**
|
|
2880
|
+
* Record one child that did not survive, and set the earliest retry time.
|
|
2881
|
+
*
|
|
2882
|
+
* `available()` answers "is there a binary to spawn" from the FILESYSTEM, and a success
|
|
2883
|
+
* there is cached for the host's lifetime (correctly — rescanning on every tool call was
|
|
2884
|
+
* the bug). That probe therefore cannot see the failure mode where the binary exists and
|
|
2885
|
+
* crashes on every launch: the signature `code=1` with empty stderr that host-log.test.mjs
|
|
2886
|
+
* asserts. Each browser call then spawned a child that died within milliseconds, with no
|
|
2887
|
+
* backoff and nothing that ever gives up — an endless crash loop, each iteration a window
|
|
2888
|
+
* flashing on screen.
|
|
2889
|
+
*
|
|
2890
|
+
* The first retry is immediate, so the ordinary transient death (the DSH restart in
|
|
2891
|
+
* remote-host-recovery.test.mjs) still heals on the very next call. After that the delay
|
|
2892
|
+
* grows: once {@link START_FAILURES_MAX} attempts have failed, every later attempt is
|
|
2893
|
+
* spaced by the table's last entry — the host keeps trying, but a permanently broken
|
|
2894
|
+
* install now costs one spawn per 30s instead of one per tool call. Nothing is marked
|
|
2895
|
+
* dead for good: a repaired installation heals on the next attempt, and `dispose()`
|
|
2896
|
+
* still stops everything immediately.
|
|
2897
|
+
* @param error - what the failed attempt reported.
|
|
2898
|
+
*/
|
|
2899
|
+
private noteStartFailure;
|
|
2900
|
+
private start;
|
|
2901
|
+
/** The child died: tear down so the next use starts a fresh child. */
|
|
2902
|
+
private onChildExit;
|
|
2903
|
+
createView(): ElectronViewHandle;
|
|
2904
|
+
private ensureView;
|
|
2905
|
+
showView(handle: ElectronViewHandle, label?: string, options?: PresentOptions): void;
|
|
2906
|
+
/**
|
|
2907
|
+
* (Re)present a view and WAIT for the child to confirm it, so the provider
|
|
2908
|
+
* can dispatch CDP `Input.*` knowing the view has a display surface.
|
|
2909
|
+
*
|
|
2910
|
+
* Two things this fixes, both silent before:
|
|
2911
|
+
* - showing a view that does not exist yet is a no-op in the child, so the
|
|
2912
|
+
* view must be materialized first (a fresh tab's createView races the
|
|
2913
|
+
* provider's showActive);
|
|
2914
|
+
* - a view whose renderer was replaced by a navigation is \"already\n * visible\" and therefore skipped by the child's flicker-avoidance fast
|
|
2915
|
+
* path, leaving the new renderer without a surface.
|
|
2916
|
+
*
|
|
2917
|
+
* The barrier ping is meaningful because the child handles messages strictly
|
|
2918
|
+
* in order: its reply is queued behind the showView and so only arrives once
|
|
2919
|
+
* the visibility change has been applied.
|
|
2920
|
+
*/
|
|
2921
|
+
presentView(handle: ElectronViewHandle, label?: string, options?: PresentOptions): Promise<void>;
|
|
2922
|
+
/** Route a view into its session's own window (one window per session). */
|
|
2923
|
+
groupView(handle: ElectronViewHandle, windowId: string, label?: string): void;
|
|
2924
|
+
/** Register the provider's handler for user-initiated toolbar actions. */
|
|
2925
|
+
onUserAction(handler: (action: BrowserUserAction) => void): void;
|
|
2926
|
+
/** Register the provider's handler for windows the human closed. */
|
|
2927
|
+
onViewClosed(handler: (windowId: string) => void): void;
|
|
2928
|
+
/** Surface a failed user action to the child's toolbar (address bar etc.). */
|
|
2929
|
+
notifyUserActionError(windowId: string, message: string): void;
|
|
2930
|
+
destroyView(handle: ElectronViewHandle): void;
|
|
2931
|
+
/** Shut the child and the RPC server down. */
|
|
2932
|
+
dispose(): void;
|
|
2933
|
+
}
|
|
2934
|
+
/** Default host-main path relative to this module's build output. */
|
|
2935
|
+
export declare function defaultHostMainPath(): string;
|
|
2936
|
+
/**
|
|
2937
|
+
* dsh-builtin-browser plugin entry: aggregates the shared-browser capability
|
|
2938
|
+
* pieces. The cordis.patch.yml rows reference subpath exports:
|
|
2939
|
+
* - `dsh-builtin-browser/browser` -> the ctx.browser seam (Service)
|
|
2940
|
+
* - `dsh-builtin-browser/browser-electron` -> the Electron CDP provider
|
|
2941
|
+
* - `dsh-builtin-browser/tool-browser` -> the model-facing dsh_browser_* tools
|
|
2942
|
+
* The capability itself is composed by those rows; this root entry exists for
|
|
2943
|
+
* programmatic imports AND because the host's client-module scan identifies a
|
|
2944
|
+
* package's browser half through a loader row whose specifier resolves to the
|
|
2945
|
+
* PACKAGE ROOT. A row named after a subpath (`dsh-builtin-browser/browser`) is
|
|
2946
|
+
* not a package specifier and is skipped by design, which is why the patch also
|
|
2947
|
+
* registers a row under the bare package name — see cordis.patch.yml.
|
|
2948
|
+
* @module dsh-builtin-browser
|
|
2949
|
+
*/
|
|
2950
|
+
/** Plugin identity for the root row (the composition surface is the subpath rows). */
|
|
2951
|
+
export declare const name = "dsh-builtin-browser";
|
|
2952
|
+
/**
|
|
2953
|
+
* Inert application for the root row: the browser seam, the Electron provider and
|
|
2954
|
+
* the tools are mounted by the subpath rows, so this one only exists to give the
|
|
2955
|
+
* package a loader row named after the package itself. Without it the host's
|
|
2956
|
+
* client scan finds no row to resolve `dsh.client` from, and the settings panel
|
|
2957
|
+
* never reaches the browser (the plugin works, its client half is invisible).
|
|
2958
|
+
*/
|
|
2959
|
+
export declare function apply(): void;
|
|
2960
|
+
export type { BrowserA11yNode, BrowserA11yRequest, BrowserA11yResult, BrowserChallenge, BrowserCheckRequest, BrowserClearRequest, BrowserClickRequest, BrowserContentFormat, BrowserContentRequest, BrowserContentResult, BrowserElementTarget, BrowserExecuteRequest, BrowserExecuteResult, BrowserFillField, BrowserFillRequest, BrowserFillResult, BrowserGetValueRequest, BrowserGetValueResult, BrowserNavigateRequest, BrowserOpenRequest, BrowserProvider, BrowserReference, BrowserReferenceCarrier, BrowserReferenceDraftAdapter, BrowserReferenceEntry, BrowserReferenceOrigin, BrowserReferencePart, BrowserScrapeField, BrowserScrapeRequest, BrowserScrapeResult, BrowserScreenshotRequest, BrowserScreenshotResult, BrowserSelectRequest, BrowserSelectResult, BrowserSessionId, BrowserSetValueRequest, BrowserSetValueResult, BrowserSnapshotElement, BrowserSnapshotResult, BrowserTab, BrowserTypeRequest, CaptureFailure, CaptureOutcome, CaptureRequest, ElectronBrowserViewHost, ElectronViewHandle, ExportedCookie, ImageAnchor, ImageReferencePart, ReferenceHost, ReferenceSummary, RevealOutcome, RevealPartResult, TableAnchor, TableCellRun, TableCellSnapshot, TableReferencePart, TableSnapshot, TextQuoteAnchor, TextReferencePart };
|