dsh-builtin-browser 1.0.1 → 1.0.3
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 +55 -0
- package/README.md +1 -1
- package/assets/browser-panel-locales.mjs +37 -5
- package/assets/browser-policy.d.mts +29 -0
- package/assets/browser-policy.mjs +40 -0
- package/desktop-bridge/desktop-discovery.d.mts +1 -1
- package/desktop-bridge/desktop-discovery.mjs +59 -9
- package/desktop-bridge/desktop-identity.json +12 -0
- package/desktop-bridge/install.mjs +14 -7
- package/desktop-bridge/plugin-browser-bridge.js +19 -7
- package/docs/acceptance-2026-11-27.md +67 -0
- package/docs/architecture.md +1 -1
- package/docs/development.md +33 -4
- package/docs/dsh-0.2.3-host-patch-task.md +34 -0
- package/docs/hardcoding-audit.md +28 -8
- package/docs/known-issues.md +26 -0
- package/docs/limitations.md +6 -2
- package/docs/tool-reference.md +1 -1
- package/docs/v1.1.0-bu-data-batching-task.md +66 -0
- package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
- package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
- package/dsh-builtin-browser-1.0.3.tgz +0 -0
- package/dsh-host-patch/README.md +4 -0
- package/dsh-host-patch/apply.mjs +61 -13
- package/dsh-host-patch/rc3-revision9.json.gz +0 -0
- package/dsh-host-patch/rc5-revision9.json.gz +0 -0
- package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/manifest.json +218 -0
- package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/series.json +260 -0
- package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
- package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
- package/dsh-host-patch/tauri-revision1.json +39 -0
- package/dsh-host-patch/tauri.json +43 -0
- package/dsh-host-patch/v023-alpha2.json +153 -0
- package/lib/browser/anti-bot.js +215 -0
- package/lib/browser/deep-dom.js +39 -0
- package/lib/browser/runtime.js +15 -0
- package/lib/browser/takeover-target.js +13 -6
- package/lib/browser/types.js +30 -1
- package/lib/browser-electron/authenticated-route.js +16 -2
- package/lib/browser-electron/automatic-maintenance.js +16 -10
- package/lib/browser-electron/bridge-connection.js +3 -8
- package/lib/browser-electron/bridge-install.js +2 -1
- package/lib/browser-electron/bridge-status.js +55 -26
- package/lib/browser-electron/desktop-bridge-host.js +7 -6
- package/lib/browser-electron/desktop-identity.js +28 -5
- package/lib/browser-electron/desktop-shell.js +64 -0
- package/lib/browser-electron/electron-provision.js +105 -18
- package/lib/browser-electron/entry.js +129 -44
- package/lib/browser-electron/extension-browser.js +4 -4
- package/lib/browser-electron/foreground-watch.js +134 -0
- package/lib/browser-electron/guest-cookie-jar.js +13 -13
- package/lib/browser-electron/guest-route.js +181 -32
- package/lib/browser-electron/guest-runtime.js +61 -10
- package/lib/browser-electron/guest-storage.js +2 -2
- package/lib/browser-electron/history-store.js +1 -5
- package/lib/browser-electron/host-main.js +8 -4
- package/lib/browser-electron/host-patch-maintenance.js +14 -8
- package/lib/browser-electron/maintenance-route.js +2 -1
- package/lib/browser-electron/missing-system-browser.js +5 -9
- package/lib/browser-electron/preferred-browser.js +7 -3
- package/lib/browser-electron/preview-route.js +9 -13
- package/lib/browser-electron/process-ownership.js +1 -1
- package/lib/browser-electron/profile-command.js +2 -1
- package/lib/browser-electron/profile-extension.js +5 -0
- package/lib/browser-electron/profile-lease.js +152 -47
- package/lib/browser-electron/provider-core.js +527 -0
- package/lib/browser-electron/provider-interaction.js +963 -0
- package/lib/browser-electron/provider-media.js +518 -0
- package/lib/browser-electron/provider-navigation.js +301 -0
- package/lib/browser-electron/provider-observation.js +623 -0
- package/lib/browser-electron/provider-tabs.js +372 -0
- package/lib/browser-electron/provider.js +150 -3301
- package/lib/browser-electron/reference-route.js +9 -18
- package/lib/browser-electron/remote-host.js +79 -34
- package/lib/browser-electron/runtime-status.js +56 -6
- package/lib/browser-electron/settings-store.js +3 -6
- package/lib/browser-electron/sidebar-only-host.js +1 -1
- package/lib/browser-electron/system-browser.js +539 -172
- package/lib/browser-electron/tauri-host.js +208 -0
- package/lib/browser-electron/virtual-cursor.js +23 -13
- package/lib/browser-reference/service.js +22 -4
- package/lib/browser-reference/web-sources.js +1 -1
- package/lib/client.js +43409 -0
- package/lib/compat/host-features.js +75 -0
- package/lib/reference-source.js +1 -1
- package/lib/reference-text.js +23 -1
- package/lib/takeover-protocol.js +1 -1
- package/lib/tool-browser/block-recovery.js +69 -0
- package/lib/tool-browser/code-tool.js +170 -19
- package/lib/tool-browser/code-worker.js +115 -20
- package/lib/tool-browser/errors.js +34 -0
- package/lib/tool-browser/index.js +66 -3593
- package/lib/tool-browser/page-probe.js +227 -28
- package/lib/tool-browser/panel-page.js +2 -1
- package/lib/tool-browser/probe-client.js +157 -0
- package/lib/tool-browser/screenshot-annotations.js +108 -0
- package/lib/tool-browser/state.js +337 -0
- package/lib/tool-browser/takeover.js +1 -1
- package/lib/tool-browser/tools-debug.js +862 -0
- package/lib/tool-browser/tools-interaction.js +993 -0
- package/lib/tool-browser/tools-navigation.js +807 -0
- package/lib/tool-browser/tools-observation.js +461 -0
- package/lib/tool-browser/tools-reference.js +293 -0
- package/lib/web-guest.js +1 -0
- package/package.json +15 -53
- package/README.en.md +0 -89
- package/browser-extension/constants.mjs +0 -20
- package/browser-extension/controller.mjs +0 -293
- package/browser-extension/locales.mjs +0 -15
- package/browser-extension/manifest.json +0 -12
- package/browser-extension/options.html +0 -14
- package/browser-extension/options.mjs +0 -9
- package/browser-extension/permission-guard.mjs +0 -13
- package/browser-extension/worker.mjs +0 -74
- package/dist/client.cjs +0 -43167
- package/lib/browser-reference/submission-receipts.js +0 -139
- package/scripts/build.mjs +0 -66
- package/scripts/bundle-host.mjs +0 -28
- package/scripts/fix-exports.mjs +0 -50
- package/scripts/install-electron.mjs +0 -51
- package/scripts/verify-exports.mjs +0 -47
- package/scripts/verify-preview-sdk.mjs +0 -93
- package/skills/dsh-builtin-browser/SKILL.md +0 -73
- package/skills/dsh-builtin-browser/references/batch.md +0 -53
- package/skills/dsh-builtin-browser/references/deliver.md +0 -31
- package/skills/dsh-builtin-browser/references/locate.md +0 -11
- package/skills/dsh-builtin-browser/references/recover.md +0 -11
- package/skills/dsh-builtin-browser/references/verify.md +0 -13
- package/skills/dsh-debug-host/SKILL.md +0 -56
- package/skills/dsh-debug-self/SKILL.md +0 -50
- package/src/bridge-compatibility.ts +0 -39
- package/src/browser/handles.ts +0 -89
- package/src/browser/runtime.ts +0 -560
- package/src/browser/takeover-target.ts +0 -36
- package/src/browser/types.ts +0 -817
- package/src/browser-electron/authenticated-route.ts +0 -84
- package/src/browser-electron/automatic-maintenance.ts +0 -726
- package/src/browser-electron/bridge-auto.ts +0 -159
- package/src/browser-electron/bridge-connection.ts +0 -385
- package/src/browser-electron/bridge-endpoint.ts +0 -129
- package/src/browser-electron/bridge-install.ts +0 -289
- package/src/browser-electron/bridge-maintenance.ts +0 -189
- package/src/browser-electron/bridge-status.ts +0 -347
- package/src/browser-electron/desktop-bridge-host.ts +0 -251
- package/src/browser-electron/desktop-identity.ts +0 -320
- package/src/browser-electron/document-readiness.ts +0 -45
- package/src/browser-electron/electron-provision.ts +0 -261
- package/src/browser-electron/entry.ts +0 -1299
- package/src/browser-electron/ephemeral-profile.ts +0 -189
- package/src/browser-electron/extension-browser.ts +0 -223
- package/src/browser-electron/extension-setup.ts +0 -67
- package/src/browser-electron/file-write.ts +0 -31
- package/src/browser-electron/guest-cookie-jar.ts +0 -176
- package/src/browser-electron/guest-cookie-store.ts +0 -59
- package/src/browser-electron/guest-css-runtime.ts +0 -76
- package/src/browser-electron/guest-css.ts +0 -68
- package/src/browser-electron/guest-route.ts +0 -568
- package/src/browser-electron/guest-runtime.ts +0 -357
- package/src/browser-electron/guest-storage-runtime.ts +0 -54
- package/src/browser-electron/guest-storage.ts +0 -117
- package/src/browser-electron/history-store.ts +0 -227
- package/src/browser-electron/host-main.ts +0 -1381
- package/src/browser-electron/host-patch-maintenance.ts +0 -112
- package/src/browser-electron/http-body.ts +0 -65
- package/src/browser-electron/json-reply.ts +0 -47
- package/src/browser-electron/maintenance-broker.ts +0 -166
- package/src/browser-electron/maintenance-lifecycle.ts +0 -91
- package/src/browser-electron/maintenance-route.ts +0 -67
- package/src/browser-electron/missing-system-browser.ts +0 -113
- package/src/browser-electron/open-slot.ts +0 -49
- package/src/browser-electron/paths.ts +0 -25
- package/src/browser-electron/preferred-browser.ts +0 -120
- package/src/browser-electron/preview-route.ts +0 -218
- package/src/browser-electron/process-ownership.ts +0 -168
- package/src/browser-electron/process.ts +0 -23
- package/src/browser-electron/profile-checkpoint.ts +0 -187
- package/src/browser-electron/profile-command.ts +0 -46
- package/src/browser-electron/profile-extension.ts +0 -124
- package/src/browser-electron/profile-lease.ts +0 -115
- package/src/browser-electron/profile-residue.ts +0 -49
- package/src/browser-electron/provider.ts +0 -4571
- package/src/browser-electron/reference-route.ts +0 -608
- package/src/browser-electron/remote-host.ts +0 -1462
- package/src/browser-electron/rpc-input.ts +0 -13
- package/src/browser-electron/rpc-ops.ts +0 -41
- package/src/browser-electron/runtime-diagnostics.ts +0 -38
- package/src/browser-electron/runtime-route.ts +0 -105
- package/src/browser-electron/runtime-status.ts +0 -242
- package/src/browser-electron/settings-route.ts +0 -64
- package/src/browser-electron/settings-store.ts +0 -589
- package/src/browser-electron/shortcuts-route.ts +0 -112
- package/src/browser-electron/sidebar-only-host.ts +0 -298
- package/src/browser-electron/startpage-shortcuts.ts +0 -213
- package/src/browser-electron/system-browser.ts +0 -1497
- package/src/browser-electron/timing.ts +0 -16
- package/src/browser-electron/virtual-cursor.ts +0 -152
- package/src/browser-electron/windows-system.ts +0 -24
- package/src/browser-reference/delivery.ts +0 -384
- package/src/browser-reference/entry.ts +0 -631
- package/src/browser-reference/export.ts +0 -339
- package/src/browser-reference/import.ts +0 -303
- package/src/browser-reference/page-script.ts +0 -1537
- package/src/browser-reference/service.ts +0 -1315
- package/src/browser-reference/store.ts +0 -172
- package/src/browser-reference/submission-receipts.ts +0 -122
- package/src/browser-reference/text-quote.ts +0 -219
- package/src/browser-reference/types.ts +0 -195
- package/src/browser-reference/visible.ts +0 -367
- package/src/browser-reference/web-sources.ts +0 -103
- package/src/client/browser/BrowserController.ts +0 -693
- package/src/client/browser/BrowserFrame.ts +0 -78
- package/src/client/browser/BrowserNavigation.ts +0 -169
- package/src/client/browser/BrowserPage.ts +0 -23
- package/src/client/browser/BrowserPersistence.ts +0 -44
- package/src/client/browser/IframeImpl.ts +0 -176
- package/src/client/browser/child-tabs.ts +0 -14
- package/src/client/browser/iframe-reference.ts +0 -67
- package/src/client/browser/initialization.ts +0 -262
- package/src/client/browser/omnibox.ts +0 -243
- package/src/client/browser/store.ts +0 -38
- package/src/client/browser/takeover-channel.ts +0 -72
- package/src/client/browser/url.ts +0 -46
- package/src/client/browser/web-reference-source.ts +0 -52
- package/src/client/css-modules.d.ts +0 -4
- package/src/client/definition.tsx +0 -30
- package/src/client/electron/ElectronWebViewImpl.ts +0 -364
- package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
- package/src/client/electron/NativeChildPresentation.ts +0 -45
- package/src/client/electron/NativeViewPage.ts +0 -251
- package/src/client/electron/pages.ts +0 -23
- package/src/client/electron/reference-overlay.ts +0 -53
- package/src/client/electron/workspace.ts +0 -33
- package/src/client/index.ts +0 -293
- package/src/client/locales.ts +0 -857
- package/src/client/pages.ts +0 -28
- package/src/client/reference/client/BrowserRefLink.tsx +0 -142
- package/src/client/reference/client/draft-reference.ts +0 -167
- package/src/client/reference/client/index.ts +0 -7
- package/src/client/reference/client/ordered-submission.ts +0 -108
- package/src/client/reference/client/pending-delivery.ts +0 -216
- package/src/client/reference/client/plugin.ts +0 -189
- package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
- package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
- package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
- package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
- package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
- package/src/client/reference/client/production/ReferenceText.tsx +0 -36
- package/src/client/reference/client/production/assembly.ts +0 -471
- package/src/client/reference/client/production/asset-store.ts +0 -144
- package/src/client/reference/client/production/availability.ts +0 -74
- package/src/client/reference/client/production/bytes.ts +0 -36
- package/src/client/reference/client/production/delivery-client.ts +0 -211
- package/src/client/reference/client/production/draft-adapter.ts +0 -508
- package/src/client/reference/client/production/http-transport.ts +0 -217
- package/src/client/reference/client/production/production-submission.ts +0 -310
- package/src/client/reference/client/production/protocol.ts +0 -231
- package/src/client/reference/client/production/reference-card.ts +0 -240
- package/src/client/reference/client/production/reference-labels.ts +0 -29
- package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
- package/src/client/reference/client/production/reveal.ts +0 -215
- package/src/client/reference/client/production/runtime.ts +0 -1101
- package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
- package/src/client/reference/client/production/source-marker.ts +0 -63
- package/src/client/reference/client/production/source-opener.ts +0 -55
- package/src/client/reference/client/production/styles.ts +0 -104
- package/src/client/reference/client/production/user-text-rule.ts +0 -58
- package/src/client/reference/client/reveal.ts +0 -107
- package/src/client/reference/client/scheme.ts +0 -114
- package/src/client/reference/client/types.ts +0 -168
- package/src/client/reference/css-modules.d.ts +0 -4
- package/src/client/reference/index.ts +0 -11
- package/src/client/reference-capture-owner.ts +0 -162
- package/src/client/reference-intents.ts +0 -36
- package/src/client/settings/index.ts +0 -34
- package/src/client/settings/panel.ts +0 -2657
- package/src/client/shortcut-open.ts +0 -30
- package/src/client/startpage/binding.ts +0 -99
- package/src/client/startpage/controller.ts +0 -303
- package/src/client/startpage/model.ts +0 -279
- package/src/client/view/Browser.module.css +0 -751
- package/src/client/view/BrowserBody.tsx +0 -314
- package/src/client/view/BrowserPresentation.ts +0 -9
- package/src/client/view/BrowserTitle.tsx +0 -17
- package/src/client/view/IframePresentation.ts +0 -344
- package/src/client/view/StartPage.tsx +0 -597
- package/src/client/view/TakeoverBanner.tsx +0 -21
- package/src/index.ts +0 -110
- package/src/reference-owner.ts +0 -5
- package/src/reference-page.ts +0 -9
- package/src/reference-source.ts +0 -3
- package/src/reference-text.ts +0 -197
- package/src/startpage-settings.ts +0 -103
- package/src/startpage.ts +0 -71
- package/src/takeover-protocol.ts +0 -19
- package/src/tool-browser/code-tool.ts +0 -401
- package/src/tool-browser/code-worker.ts +0 -639
- package/src/tool-browser/element-fields.ts +0 -167
- package/src/tool-browser/index.ts +0 -3733
- package/src/tool-browser/page-probe.ts +0 -474
- package/src/tool-browser/panel-page.ts +0 -124
- package/src/tool-browser/screenshot-image.ts +0 -49
- package/src/tool-browser/takeover.ts +0 -198
- package/src/types/electron-shim.d.ts +0 -144
- package/src/types.ts +0 -85
- package/src/web-guest.ts +0 -34
- package/tools/accept-desktop.mjs +0 -148
|
@@ -0,0 +1,862 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug and control tools: console, network, dialogs, assertions, doctor, help, batches, restriction, auth and human takeover.
|
|
3
|
+
* @module dsh-browser/tool-browser/tools-debug
|
|
4
|
+
*/
|
|
5
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
6
|
+
import { TAKEOVER_TOOL } from '../takeover-protocol.js';
|
|
7
|
+
import { clearLastOpen, getLastOpen } from '../browser-electron/open-slot.js';
|
|
8
|
+
import { assertAllowed, agentOf, taskKey, ensureSession } from './state.js';
|
|
9
|
+
import { pageValue, pageOperationValue, installProbe, probe, probeLive, pause, poll, runChecks } from './probe-client.js';
|
|
10
|
+
import { formatSnapshot } from './tools-observation.js';
|
|
11
|
+
/**
|
|
12
|
+
* Define this module's tools for one apply.
|
|
13
|
+
* @param scope - the apply's context, settings and per-apply state.
|
|
14
|
+
* @returns the tool definitions, for the entry to register.
|
|
15
|
+
*/
|
|
16
|
+
const DO_STEP_KINDS = ['open', 'tap', 'field', 'type', 'key', 'scroll', 'sleep_ms', 'wait_text', 'wait_gone', 'wait_url', 'wait_idle', 'wait_js', 'eval', 'check'];
|
|
17
|
+
const DO_STEP_SCHEMAS = [
|
|
18
|
+
{ type: 'object', additionalProperties: false, properties: { open: { type: 'json', required: true } } },
|
|
19
|
+
{ type: 'object', additionalProperties: false, properties: { tap: { type: 'json', required: true } } },
|
|
20
|
+
{ type: 'object', additionalProperties: false, properties: { field: { type: 'json', required: true } } },
|
|
21
|
+
{ type: 'object', additionalProperties: false, properties: { type: { type: 'json', required: true } } },
|
|
22
|
+
{ type: 'object', additionalProperties: false, properties: { key: { type: 'json', required: true } } },
|
|
23
|
+
{ type: 'object', additionalProperties: false, properties: { scroll: { type: 'json', required: true } } },
|
|
24
|
+
{ type: 'object', additionalProperties: false, properties: { sleep_ms: { type: 'json', required: true } } },
|
|
25
|
+
{ type: 'object', additionalProperties: false, properties: { wait_text: { type: 'json', required: true } } },
|
|
26
|
+
{ type: 'object', additionalProperties: false, properties: { wait_gone: { type: 'json', required: true } } },
|
|
27
|
+
{ type: 'object', additionalProperties: false, properties: { wait_url: { type: 'json', required: true } } },
|
|
28
|
+
{ type: 'object', additionalProperties: false, properties: { wait_idle: { type: 'json', required: true } } },
|
|
29
|
+
{ type: 'object', additionalProperties: false, properties: { wait_js: { type: 'json', required: true } } },
|
|
30
|
+
{ type: 'object', additionalProperties: false, properties: { eval: { type: 'json', required: true } } },
|
|
31
|
+
{ type: 'object', additionalProperties: false, properties: { check: { type: 'json', required: true } } },
|
|
32
|
+
];
|
|
33
|
+
export function debugTools(scope) {
|
|
34
|
+
const { ctx, state, takeovers, timeoutMs, maxWaitMs } = scope;
|
|
35
|
+
const tools = [];
|
|
36
|
+
tools.push(defineTool({
|
|
37
|
+
name: 'dsh_browser_request_takeover',
|
|
38
|
+
description: 'Hand the selected visible sidebar browser tab in this conversation to the human for a CAPTCHA/slider, login, 2FA or payment. Works on the Web iframe without CDP, including user-opened tabs: adopts the selected tab for this request only, without granting agent control. Never solve CAPTCHAs automatically. Requires an active turn; waits for the sidebar connection and the native card or sidebar Confirm/Skip. Repeated calls on the same tab share one request. Returns done/skipped/cancelled/unavailable plus a fresh page summary; inspect it before resuming. Never treat skipped/cancelled as success. unavailable means this host cannot reach a person at all: take the CHALLENGE banner fallback routes and report the block instead of retrying takeover or solving it yourself.',
|
|
39
|
+
parameters: {
|
|
40
|
+
reason: { type: 'string', required: true, description: 'Why the human must take over (1–1000 characters).' },
|
|
41
|
+
instructions: { type: 'string', description: 'Optional concise instructions for the human (up to 2000 characters).' },
|
|
42
|
+
},
|
|
43
|
+
output: { schema: { type: 'object', additionalProperties: false, properties: {
|
|
44
|
+
outcome: { type: 'string', required: true, enum: ['done', 'skipped', 'cancelled', 'unavailable'] },
|
|
45
|
+
page: { type: 'object', required: true, additionalProperties: false, properties: {
|
|
46
|
+
url: { type: 'string', required: true }, title: { type: 'string', required: true },
|
|
47
|
+
snapshotHint: { type: 'string', required: true }, fresh: { type: 'boolean', required: true },
|
|
48
|
+
} },
|
|
49
|
+
} }, render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }] },
|
|
50
|
+
async execute(args, exec) {
|
|
51
|
+
if (!exec.agent?.session)
|
|
52
|
+
throw new Error('Browser takeover requires an active agent turn.');
|
|
53
|
+
if (!args.reason.trim())
|
|
54
|
+
throw new Error('Browser takeover reason must not be empty.');
|
|
55
|
+
if (args.reason.length > 1000 || (args.instructions?.length ?? 0) > 2000)
|
|
56
|
+
throw new Error('Browser takeover reason or instructions are too long.');
|
|
57
|
+
const owner = taskKey(exec);
|
|
58
|
+
const opening = state.pendingPanelOpens.get(owner);
|
|
59
|
+
if (opening)
|
|
60
|
+
await opening;
|
|
61
|
+
const open = getLastOpen();
|
|
62
|
+
const navigationUrl = open?.owner === owner && Date.now() - open.at < 10000 ? open.url : undefined;
|
|
63
|
+
const page = await takeovers.adopt(owner, exec.signal, navigationUrl);
|
|
64
|
+
if (navigationUrl !== undefined && getLastOpen()?.owner === owner)
|
|
65
|
+
clearLastOpen(open.at);
|
|
66
|
+
const takeoverEnded = new AbortController();
|
|
67
|
+
await page.reveal?.(takeoverEnded.signal).catch(() => false);
|
|
68
|
+
return takeovers.run(page, args.reason.trim(), args.instructions, exec.signal, async (pending) => {
|
|
69
|
+
const approval = ctx.get('approval');
|
|
70
|
+
let decision = 'unavailable';
|
|
71
|
+
try {
|
|
72
|
+
if (approval)
|
|
73
|
+
decision = await approval.request({ agent: exec.agent, toolName: TAKEOVER_TOOL, callId: exec.callId,
|
|
74
|
+
reason: pending.reason, displayReason: {
|
|
75
|
+
en: `Please take over the browser: ${pending.reason}. When finished, click Allow once or Confirm completion in the sidebar.${pending.instructions ? '\n' + pending.instructions : ''}`,
|
|
76
|
+
zh: `请接管浏览器:${pending.reason}(完成后点「允许一次」或侧栏「确认完成」)${pending.instructions ? '\n' + pending.instructions : ''}`,
|
|
77
|
+
}, signal: pending.controller.signal });
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
pending.controller.abort();
|
|
81
|
+
}
|
|
82
|
+
// `unavailable` stays its own outcome: it says this host cannot reach a person at all (no
|
|
83
|
+
// approval service and no sidebar card), which is not a decision anyone made. It used to
|
|
84
|
+
// collapse into `cancelled`, and because the guidance forbids solving a challenge alone,
|
|
85
|
+
// the only reachable answer became "not success" — a dead end rather than a result.
|
|
86
|
+
const outcome = decision === 'allowed-once' ? 'done'
|
|
87
|
+
: decision === 'rejected' ? 'skipped'
|
|
88
|
+
: decision === 'unavailable' ? 'unavailable'
|
|
89
|
+
: 'cancelled';
|
|
90
|
+
const unavailable = (error) => ({ url: page.url, title: '', snapshotHint: `Live page summary unavailable: ${String(error).slice(0, 300)}. Re-read the page before continuing.`, fresh: false });
|
|
91
|
+
if (exec.signal.aborted)
|
|
92
|
+
return { outcome: 'cancelled', page: unavailable('turn stopped') };
|
|
93
|
+
pending.phase = 'summary';
|
|
94
|
+
let fresh;
|
|
95
|
+
try {
|
|
96
|
+
if (!page.pageId.startsWith('iframe:')) {
|
|
97
|
+
const browser = ctx.get('browser');
|
|
98
|
+
const session = await browser.bindPanelPage(`session-${page.owner}`, page.pageId);
|
|
99
|
+
const snapshot = await browser.snapshot(session, AbortSignal.any([exec.signal, AbortSignal.timeout(5000)]));
|
|
100
|
+
fresh = { url: snapshot.url, title: (snapshot.title ?? '').slice(0, 1000), snapshotHint: formatSnapshot(snapshot, {}).slice(0, 1500), fresh: true };
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
fresh = await new Promise((resolve, reject) => {
|
|
104
|
+
const finish = (value, error) => {
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
exec.signal.removeEventListener('abort', abort);
|
|
107
|
+
if (error !== undefined)
|
|
108
|
+
reject(error);
|
|
109
|
+
else
|
|
110
|
+
resolve(value);
|
|
111
|
+
};
|
|
112
|
+
const abort = () => { finish(undefined, exec.signal.reason); };
|
|
113
|
+
const timer = setTimeout(() => { finish(undefined, new Error('sidebar summary timed out')); }, 8000);
|
|
114
|
+
exec.signal.addEventListener('abort', abort, { once: true });
|
|
115
|
+
void pending.summary.then(value => { finish(value); });
|
|
116
|
+
if (exec.signal.aborted)
|
|
117
|
+
abort();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
fresh = unavailable(error);
|
|
123
|
+
}
|
|
124
|
+
return { outcome: exec.signal.aborted ? 'cancelled' : outcome, page: fresh };
|
|
125
|
+
}).finally(() => takeoverEnded.abort());
|
|
126
|
+
},
|
|
127
|
+
}));
|
|
128
|
+
tools.push(defineTool({
|
|
129
|
+
name: 'dsh_browser_restrict',
|
|
130
|
+
description: 'Allow only the listed browser tools; any other dsh_browser_* call is refused. Empty list or omitted lifts it. Never blocked whatever the list says — the observing tools (snapshot/a11y/content/scrape/screenshot/get_value/wait/challenge/list_tabs/session/history/visited) and restrict/reset/reset_session — so a restriction can always be read around and undone. A SOFT guardrail against stray clicks, NOT a security boundary: you can lift it with an empty list.',
|
|
131
|
+
parameters: {
|
|
132
|
+
allowed: {
|
|
133
|
+
type: 'array',
|
|
134
|
+
items: { type: 'string' },
|
|
135
|
+
description: 'Allow-list of browser tool names; empty clears the restriction.',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
output: {
|
|
139
|
+
schema: { type: 'object', additionalProperties: false, properties: { restrictedTo: { type: 'array', required: true, items: { type: 'string' } } } },
|
|
140
|
+
render: (_args, value) => [{ type: 'text', text: value.restrictedTo.length > 0 ? `Restricted to: ${value.restrictedTo.join(', ')}` : 'Restriction lifted.' }],
|
|
141
|
+
},
|
|
142
|
+
timeoutMs,
|
|
143
|
+
isConcurrencySafe: () => false,
|
|
144
|
+
async execute(args, exec) {
|
|
145
|
+
// Always allowed so the guard can be lifted.
|
|
146
|
+
const allowed = args.allowed ?? [];
|
|
147
|
+
const unknown = allowed.filter((t) => !t.startsWith('dsh_browser_'));
|
|
148
|
+
if (unknown.length > 0) {
|
|
149
|
+
throw new Error(`dsh_browser_restrict: unknown tool name(s) ${unknown.map(t => `"${t}"`).join(', ')} (must start with "dsh_browser_")`);
|
|
150
|
+
}
|
|
151
|
+
// Empty list (or omitted) lifts this task's restriction; a non-empty list is its
|
|
152
|
+
// new allow-list. Per task, not per plugin: this state object is shared by every
|
|
153
|
+
// agent, so one value here used to lock every other task's browser tools.
|
|
154
|
+
//
|
|
155
|
+
if (allowed.length === 0)
|
|
156
|
+
state.restrictedByTask.delete(taskKey(exec));
|
|
157
|
+
else
|
|
158
|
+
state.restrictedByTask.set(taskKey(exec), [...allowed]);
|
|
159
|
+
const current = state.restrictedByTask.get(taskKey(exec));
|
|
160
|
+
return { restrictedTo: current === undefined ? [] : [...current] };
|
|
161
|
+
},
|
|
162
|
+
}));
|
|
163
|
+
tools.push(defineTool({
|
|
164
|
+
name: 'dsh_browser_auth',
|
|
165
|
+
description: 'Export or restore the session\'s cookies (login state): "flush" returns a JSON cookie list, "restore" takes that list back (e.g. after the host restarted). Works on all carriers. Refused when the credential switch is off. Exported cookies are LIVE CREDENTIALS: never echo them into the conversation or logs; keep the list in a private file.',
|
|
166
|
+
parameters: {
|
|
167
|
+
action: { type: 'string', required: true, enum: ['flush', 'restore'], description: 'flush = export cookies; restore = import cookies.' },
|
|
168
|
+
cookies: { type: 'array', items: { type: 'object', additionalProperties: true }, description: 'Cookie list to restore (required when action=restore).' },
|
|
169
|
+
},
|
|
170
|
+
output: {
|
|
171
|
+
schema: {
|
|
172
|
+
type: 'object',
|
|
173
|
+
additionalProperties: false,
|
|
174
|
+
properties: {
|
|
175
|
+
cookies: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
176
|
+
restored: { type: 'number' },
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
render: (_args, value) => [{ type: 'text', text: value.cookies !== undefined ? `Exported ${value.cookies.length} cookies — LIVE CREDENTIALS; store privately and never echo them.` : `Restored ${value.restored} cookies.` }],
|
|
180
|
+
},
|
|
181
|
+
timeoutMs,
|
|
182
|
+
isConcurrencySafe: () => false,
|
|
183
|
+
async execute(args, exec) {
|
|
184
|
+
assertAllowed(state, 'dsh_browser_auth', taskKey(exec));
|
|
185
|
+
const browser = ctx.get('browser');
|
|
186
|
+
if (browser === undefined)
|
|
187
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
188
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
189
|
+
if (args.action === 'flush') {
|
|
190
|
+
const cookies = await browser.flushAuth(session);
|
|
191
|
+
return { cookies: cookies.map(c => ({ ...c })) };
|
|
192
|
+
}
|
|
193
|
+
// The description says cookies are required for restore; without this check an
|
|
194
|
+
// empty call returned {restored: 0} and rendered 'Restored 0 cookies.', which
|
|
195
|
+
// reads as success and would leave the caller believing the login was restored.
|
|
196
|
+
if (!Array.isArray(args.cookies) || args.cookies.length === 0) {
|
|
197
|
+
throw new Error('dsh_browser_auth: action "restore" needs a non-empty "cookies" array (get one from action "flush" on the same profile)');
|
|
198
|
+
}
|
|
199
|
+
const list = args.cookies;
|
|
200
|
+
const restored = await browser.restoreAuth(session, list);
|
|
201
|
+
return { restored };
|
|
202
|
+
},
|
|
203
|
+
}));
|
|
204
|
+
// ===========================================================================
|
|
205
|
+
// Observation, assertion and batch work (0.5.7).
|
|
206
|
+
//
|
|
207
|
+
// Five capabilities were missing against the other browser plugins in this market: what the
|
|
208
|
+
// console said, which responses arrived, what happened to a JavaScript dialog (an unanswered
|
|
209
|
+
// `confirm()` used to hang a whole call), a way to assert a result instead of eyeballing a
|
|
210
|
+
// screenshot, and a way to run several steps in one call. All of them come from one page-side
|
|
211
|
+
// probe installed through `execute`, so they work identically on the self-hosted window, a driven
|
|
212
|
+
// Chrome/Edge and the desktop sidebar — no host change, no bridge protocol version.
|
|
213
|
+
// ===========================================================================
|
|
214
|
+
tools.push(defineTool({
|
|
215
|
+
name: 'dsh_browser_console',
|
|
216
|
+
description: 'Read what the page has logged (console.log/info/warn/error/debug), newest last, capped at 200 lines. Use it when the screen does not explain a failure: a red toast, a form that silently refuses, a page that "just does nothing". Set clear:true first when you only want what happens next. A page that logs objects shows their JSON.',
|
|
217
|
+
parameters: {
|
|
218
|
+
limit: { type: 'number', description: 'How many lines, newest last (default 20, max 100).' },
|
|
219
|
+
filter: { type: 'string', description: 'Only lines containing this text (case-insensitive).' },
|
|
220
|
+
clear: { type: 'boolean', description: 'Clear the buffer before reading.' },
|
|
221
|
+
},
|
|
222
|
+
output: {
|
|
223
|
+
schema: {
|
|
224
|
+
type: 'object',
|
|
225
|
+
additionalProperties: false,
|
|
226
|
+
properties: { entries: { type: 'array', items: { type: 'object', additionalProperties: true }, required: true } },
|
|
227
|
+
},
|
|
228
|
+
render: (_args, value) => {
|
|
229
|
+
const rows = value.entries;
|
|
230
|
+
if (rows.length === 0)
|
|
231
|
+
return [{ type: 'text', text: 'No console lines yet (nothing logged since the page probe was installed).' }];
|
|
232
|
+
return [{ type: 'text', text: rows.map(row => `[${String(row.level)}] ${String(row.text)}`).join('\n') }];
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
timeoutMs,
|
|
236
|
+
isConcurrencySafe: () => true,
|
|
237
|
+
async execute(args, exec) {
|
|
238
|
+
const browser = ctx.get('browser');
|
|
239
|
+
if (browser === undefined)
|
|
240
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
241
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
242
|
+
await installProbe(browser, session, exec.signal);
|
|
243
|
+
if (args.clear === true)
|
|
244
|
+
await probe(browser, session, 'clear', ['console'], exec.signal);
|
|
245
|
+
const entries = await probe(browser, session, 'read', ['console', args.filter ?? '', args.limit ?? 20], exec.signal);
|
|
246
|
+
return { entries };
|
|
247
|
+
},
|
|
248
|
+
}));
|
|
249
|
+
tools.push(defineTool({
|
|
250
|
+
name: 'dsh_browser_network',
|
|
251
|
+
description: 'List the responses the page has received, newest last: method, status, type and address, for fetch, XHR and resource-timing entries. Use it when a page fills itself from the network and the screen does not say why, or to confirm a submit actually reached the server. onlyFailures keeps status 0 (blocked/aborted) and 4xx/5xx. Resource-timing rows carry no status (the browser never exposed it to the page) and show status 0.',
|
|
252
|
+
parameters: {
|
|
253
|
+
limit: { type: 'number', description: 'How many rows, newest last (default 20, max 100).' },
|
|
254
|
+
filter: { type: 'string', description: 'Only rows whose address contains this text.' },
|
|
255
|
+
onlyFailures: { type: 'boolean', description: 'Only rows with status 0, or status >= 400.' },
|
|
256
|
+
clear: { type: 'boolean', description: 'Clear the buffer before reading.' },
|
|
257
|
+
},
|
|
258
|
+
output: {
|
|
259
|
+
schema: {
|
|
260
|
+
type: 'object',
|
|
261
|
+
additionalProperties: false,
|
|
262
|
+
properties: { entries: { type: 'array', items: { type: 'object', additionalProperties: true }, required: true } },
|
|
263
|
+
},
|
|
264
|
+
render: (_args, value) => {
|
|
265
|
+
const rows = value.entries;
|
|
266
|
+
if (rows.length === 0)
|
|
267
|
+
return [{ type: 'text', text: 'No responses recorded yet.' }];
|
|
268
|
+
return [{ type: 'text', text: rows.map(row => `${String(row.method)} ${String(row.status)} ${String(row.kind)} ${String(row.ms)}ms ${String(row.url)}`).join('\n') }];
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
timeoutMs,
|
|
272
|
+
isConcurrencySafe: () => true,
|
|
273
|
+
async execute(args, exec) {
|
|
274
|
+
const browser = ctx.get('browser');
|
|
275
|
+
if (browser === undefined)
|
|
276
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
277
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
278
|
+
await installProbe(browser, session, exec.signal);
|
|
279
|
+
if (args.clear === true)
|
|
280
|
+
await probe(browser, session, 'clear', ['network'], exec.signal);
|
|
281
|
+
const rows = await probe(browser, session, 'read', ['network', args.filter ?? '', args.limit ?? 20], exec.signal);
|
|
282
|
+
const entries = args.onlyFailures === true
|
|
283
|
+
? rows.filter(row => Number(row.status) === 0 || Number(row.status) >= 400)
|
|
284
|
+
: rows;
|
|
285
|
+
return { entries };
|
|
286
|
+
},
|
|
287
|
+
}));
|
|
288
|
+
tools.push(defineTool({
|
|
289
|
+
name: 'dsh_browser_data_sources',
|
|
290
|
+
description: 'Find where the page keeps its data before reading the DOM: embedded state (__NEXT_DATA__, __NUXT_DATA__, window.__INITIAL_STATE__/__APOLLO_STATE__, application/json and ld+json scripts) with size, top-level keys and the largest arrays; the fetch/XHR APIs the page called (method, status, content type); data-like resources it fetched before the probe was installed; and endpoints it declares (preload as=fetch, data-api, data-endpoint). Shapes only, never bodies. Use it before scraping a list, directory, paginated or lazy-loaded data: a JSON source is usually complete where the DOM is not.',
|
|
291
|
+
parameters: {},
|
|
292
|
+
output: {
|
|
293
|
+
schema: {
|
|
294
|
+
type: 'object',
|
|
295
|
+
additionalProperties: false,
|
|
296
|
+
properties: {
|
|
297
|
+
url: { type: 'string', required: true },
|
|
298
|
+
embedded: { type: 'array', items: { type: 'object', additionalProperties: true }, required: true },
|
|
299
|
+
apis: { type: 'array', items: { type: 'object', additionalProperties: true }, required: true },
|
|
300
|
+
resources: { type: 'array', items: { type: 'object', additionalProperties: true }, required: true },
|
|
301
|
+
declared: { type: 'array', items: { type: 'object', additionalProperties: true }, required: true },
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
render: (_args, value) => [{ type: 'text', text: formatDataSources(value) }],
|
|
305
|
+
},
|
|
306
|
+
timeoutMs,
|
|
307
|
+
isConcurrencySafe: () => true,
|
|
308
|
+
async execute(_args, exec) {
|
|
309
|
+
const browser = ctx.get('browser');
|
|
310
|
+
if (browser === undefined)
|
|
311
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
312
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
313
|
+
const found = await probeLive(browser, session, 'dataSources', [], exec.signal);
|
|
314
|
+
return { url: found.url, embedded: found.embedded, apis: found.apis, resources: found.resources, declared: found.declared };
|
|
315
|
+
},
|
|
316
|
+
}));
|
|
317
|
+
tools.push(defineTool({
|
|
318
|
+
name: 'dsh_browser_fetch_json',
|
|
319
|
+
description: 'Fetch a URL from inside the page (so it carries the site\'s same-origin cookies) and return its JSON. A non-2xx status or a body that is not JSON is an error naming the status and the start of the body. Use it to read an API found with dsh_browser_data_sources instead of paging through the DOM; GET requests may run in parallel.',
|
|
320
|
+
parameters: {
|
|
321
|
+
url: { type: 'string', required: true, description: 'Absolute, or relative to the current page.' },
|
|
322
|
+
method: { type: 'string', description: 'HTTP method (default GET).' },
|
|
323
|
+
headers: { type: 'object', additionalProperties: true, description: 'Request headers, as string values.' },
|
|
324
|
+
body: { type: 'string', description: 'Request body (e.g. JSON.stringify(payload)).' },
|
|
325
|
+
maxChars: { type: 'number', description: 'Maximum characters of the body shown (default 50000); the returned value always holds the whole body.' },
|
|
326
|
+
},
|
|
327
|
+
output: {
|
|
328
|
+
schema: {
|
|
329
|
+
type: 'object',
|
|
330
|
+
additionalProperties: false,
|
|
331
|
+
properties: {
|
|
332
|
+
status: { type: 'number', required: true },
|
|
333
|
+
url: { type: 'string', required: true },
|
|
334
|
+
bytes: { type: 'number', required: true },
|
|
335
|
+
body: { type: 'string', required: true },
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
render: (args, value) => {
|
|
339
|
+
const body = String(value.body);
|
|
340
|
+
const limit = args.maxChars ?? 50_000;
|
|
341
|
+
const shown = body.length > limit ? `${body.slice(0, limit)}\n(body truncated at ${limit} of ${body.length} characters — raise maxChars)` : body;
|
|
342
|
+
return [{ type: 'text', text: `${String(value.status)} ${String(value.url)} (${String(value.bytes)} bytes)\n${shown}` }];
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
timeoutMs,
|
|
346
|
+
isConcurrencySafe: args => isReadMethod(args.method),
|
|
347
|
+
async execute(args, exec) {
|
|
348
|
+
assertAllowed(state, 'dsh_browser_fetch_json', taskKey(exec));
|
|
349
|
+
const browser = ctx.get('browser');
|
|
350
|
+
if (browser === undefined)
|
|
351
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
352
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
353
|
+
const headers = {};
|
|
354
|
+
for (const [key, raw] of Object.entries(args.headers ?? {}))
|
|
355
|
+
headers[key] = String(raw);
|
|
356
|
+
const init = {
|
|
357
|
+
...args.method !== undefined ? { method: args.method } : {},
|
|
358
|
+
...Object.keys(headers).length > 0 ? { headers } : {},
|
|
359
|
+
...args.body !== undefined ? { body: args.body } : {},
|
|
360
|
+
};
|
|
361
|
+
const text = await pageOperationValue(browser, session, { operation: 'fetch', url: args.url, init }, exec.signal);
|
|
362
|
+
const out = JSON.parse(text);
|
|
363
|
+
const head = out.body.slice(0, 200);
|
|
364
|
+
if (!out.ok)
|
|
365
|
+
throw new Error(`fetch_json: HTTP ${out.status}${out.statusText ? ` ${out.statusText}` : ''} from ${out.url || args.url}: ${head}`);
|
|
366
|
+
try {
|
|
367
|
+
JSON.parse(out.body);
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
throw new Error(`fetch_json: ${out.url || args.url} answered ${out.status} with ${out.type || 'no content type'}, not JSON: ${head}`);
|
|
371
|
+
}
|
|
372
|
+
return { status: out.status, url: out.url || args.url, bytes: out.body.length, body: out.body };
|
|
373
|
+
},
|
|
374
|
+
}));
|
|
375
|
+
tools.push(defineTool({
|
|
376
|
+
name: 'dsh_browser_dialog',
|
|
377
|
+
description: 'Report JavaScript dialogs (alert/confirm/prompt) the page raised, and choose how they are answered. Dialogs use the native browser UI by default. Setting policy "dismiss" answers alert/prompt with nothing and confirm with false, "accept" answers confirm with true and prompt with its current text. Policy "native" restores the original dialog functions. Reading preserves the current policy; changing it is an action. A dialog raised by the browser itself (beforeunload, HTTP auth) is not covered.',
|
|
378
|
+
parameters: {
|
|
379
|
+
policy: { type: 'string', enum: ['native', 'accept', 'dismiss'], description: 'Answer future dialogs this way.' },
|
|
380
|
+
limit: { type: 'number', description: 'How many recent dialogs to return (default 10).' },
|
|
381
|
+
},
|
|
382
|
+
output: {
|
|
383
|
+
schema: {
|
|
384
|
+
type: 'object',
|
|
385
|
+
additionalProperties: false,
|
|
386
|
+
properties: {
|
|
387
|
+
policy: { type: 'string', required: true },
|
|
388
|
+
dialogs: { type: 'array', items: { type: 'object', additionalProperties: true }, required: true },
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
render: (_args, value) => {
|
|
392
|
+
const rows = value.dialogs;
|
|
393
|
+
const head = `Dialog policy: ${String(value.policy)} (${String(value.policy) === 'accept' ? 'confirm→true, prompt→its text' : 'confirm→false, prompt→null'}).`;
|
|
394
|
+
if (rows.length === 0)
|
|
395
|
+
return [{ type: 'text', text: `${head} No dialogs seen yet.` }];
|
|
396
|
+
return [{ type: 'text', text: [head, ...rows.map(row => `${String(row.kind)} "${String(row.message)}" → ${String(row.answered)}`)].join('\n') }];
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
timeoutMs,
|
|
400
|
+
isConcurrencySafe: () => false, // the policy is task-wide state
|
|
401
|
+
async execute(args, exec) {
|
|
402
|
+
assertAllowed(state, 'dsh_browser_dialog', taskKey(exec));
|
|
403
|
+
const browser = ctx.get('browser');
|
|
404
|
+
if (browser === undefined)
|
|
405
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
406
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
407
|
+
await installProbe(browser, session, exec.signal);
|
|
408
|
+
const policy = args.policy === undefined
|
|
409
|
+
? await probe(browser, session, 'dialogStatus', [], exec.signal)
|
|
410
|
+
: await probe(browser, session, 'setDialogPolicy', [args.policy], exec.signal);
|
|
411
|
+
const dialogs = await probe(browser, session, 'read', ['dialogs', '', args.limit ?? 10], exec.signal);
|
|
412
|
+
return { policy, dialogs };
|
|
413
|
+
},
|
|
414
|
+
}));
|
|
415
|
+
tools.push(defineTool({
|
|
416
|
+
name: 'dsh_browser_wait_for_response',
|
|
417
|
+
description: 'Wait until a response whose address contains `urlContains` has arrived AFTER this call started: optional status (e.g. 200, or 4xx), bounded by timeoutMs. Use it instead of sleeping before a snapshot when a click submits a form or starts a fetch — it returns as soon as the server answered, and says what arrived when it did not. This is the "did the submit reach the server" question that a screenshot cannot answer.',
|
|
418
|
+
parameters: {
|
|
419
|
+
urlContains: { type: 'string', required: true, description: 'Substring of the request address.' },
|
|
420
|
+
status: { type: 'number', description: 'Require this exact status (a non-zero status is required to match).' },
|
|
421
|
+
timeoutMs: { type: 'number', description: 'How long to wait (default 15000, capped by the tool timeout).' },
|
|
422
|
+
},
|
|
423
|
+
output: {
|
|
424
|
+
schema: {
|
|
425
|
+
type: 'object',
|
|
426
|
+
additionalProperties: false,
|
|
427
|
+
properties: {
|
|
428
|
+
matched: { type: 'boolean', required: true },
|
|
429
|
+
reason: { type: 'string', required: true },
|
|
430
|
+
entry: { type: 'object', additionalProperties: true },
|
|
431
|
+
},
|
|
432
|
+
},
|
|
433
|
+
render: (_args, value) => {
|
|
434
|
+
const entry = value.entry;
|
|
435
|
+
if (!value.matched)
|
|
436
|
+
return [{ type: 'text', text: `No matching response: ${String(value.reason)}` }];
|
|
437
|
+
return [{ type: 'text', text: `Matched: ${String(entry?.method)} ${String(entry?.status)} ${String(entry?.url)} (${String(entry?.ms)}ms)` }];
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
timeoutMs,
|
|
441
|
+
isConcurrencySafe: () => true,
|
|
442
|
+
async execute(args, exec) {
|
|
443
|
+
const browser = ctx.get('browser');
|
|
444
|
+
if (browser === undefined)
|
|
445
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
446
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
447
|
+
await installProbe(browser, session, exec.signal);
|
|
448
|
+
const cursor = await probe(browser, session, 'networkCursor', [], exec.signal);
|
|
449
|
+
exec.armed?.();
|
|
450
|
+
const budget = Math.min(args.timeoutMs ?? 15_000, maxWaitMs);
|
|
451
|
+
const found = await poll(async () => {
|
|
452
|
+
const current = await probe(browser, session, 'networkCursor', [], exec.signal);
|
|
453
|
+
if (current.startedAt !== cursor.startedAt)
|
|
454
|
+
throw new Error('the page changed while waiting for a response; start a new wait on the current page');
|
|
455
|
+
const rows = await probe(browser, session, 'read', ['network', args.urlContains, 100], exec.signal);
|
|
456
|
+
const fresh = rows.filter(row => Number(row.sequence) > cursor.sequence && Number(row.status) > 0);
|
|
457
|
+
const exact = args.status === undefined ? fresh : fresh.filter(row => Number(row.status) === args.status);
|
|
458
|
+
return exact.length > 0 ? exact[exact.length - 1] : undefined;
|
|
459
|
+
}, budget);
|
|
460
|
+
if (found === undefined) {
|
|
461
|
+
const rows = await probe(browser, session, 'read', ['network', args.urlContains, 60], exec.signal);
|
|
462
|
+
const seen = rows.length === 0 ? 'nothing matched the address' : `${rows.length} older row(s) matched but none arrived after this call started`;
|
|
463
|
+
return { matched: false, reason: `${seen} within ${Math.round(budget / 1000)}s` };
|
|
464
|
+
}
|
|
465
|
+
return { matched: true, reason: 'response arrived', entry: found };
|
|
466
|
+
},
|
|
467
|
+
}));
|
|
468
|
+
tools.push(defineTool({
|
|
469
|
+
name: 'dsh_browser_assert',
|
|
470
|
+
description: 'Assert facts about the page in one call and get a pass/fail per assertion with the evidence: a CSS selector exists, the body text contains something, the URL contains something, or a JavaScript expression is truthy. Use it to verify a step actually worked — "clicked" and "the form accepted it" are different claims — and before retrying anything that might have already taken effect.',
|
|
471
|
+
parameters: {
|
|
472
|
+
selector: { type: 'string', description: 'CSS selector that must match an element.' },
|
|
473
|
+
text: { type: 'string', description: 'Text that must appear in the page body.' },
|
|
474
|
+
url: { type: 'string', description: 'Substring the URL must contain.' },
|
|
475
|
+
js: { type: 'string', description: 'Expression that must be truthy, e.g. document.querySelector("#ok") !== null.' },
|
|
476
|
+
},
|
|
477
|
+
output: {
|
|
478
|
+
schema: {
|
|
479
|
+
type: 'object',
|
|
480
|
+
additionalProperties: false,
|
|
481
|
+
properties: {
|
|
482
|
+
pass: { type: 'boolean', required: true },
|
|
483
|
+
checks: { type: 'array', items: { type: 'object', additionalProperties: true }, required: true },
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
render: (_args, value) => {
|
|
487
|
+
const rows = value.checks;
|
|
488
|
+
const lines = rows.map(row => `${row.pass === true ? 'PASS' : 'FAIL'} ${String(row.kind)}: ${String(row.expected)} → ${String(row.actual)}`);
|
|
489
|
+
return [{ type: 'text', text: `${value.pass === true ? 'All checks passed.' : 'A check failed.'}\n${lines.join('\n')}` }];
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
timeoutMs,
|
|
493
|
+
isConcurrencySafe: () => true,
|
|
494
|
+
async execute(args, exec) {
|
|
495
|
+
const browser = ctx.get('browser');
|
|
496
|
+
if (browser === undefined)
|
|
497
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
498
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
499
|
+
await installProbe(browser, session, exec.signal);
|
|
500
|
+
const spec = {
|
|
501
|
+
...args.selector !== undefined ? { selector: args.selector } : {},
|
|
502
|
+
...args.text !== undefined ? { text: args.text } : {},
|
|
503
|
+
...args.url !== undefined ? { url: args.url } : {},
|
|
504
|
+
...args.js !== undefined ? { js: args.js } : {},
|
|
505
|
+
};
|
|
506
|
+
if (Object.keys(spec).length === 0)
|
|
507
|
+
throw new Error('dsh_browser_assert: give at least one of selector, text, url or js');
|
|
508
|
+
return await runChecks(browser, session, spec, exec.signal);
|
|
509
|
+
},
|
|
510
|
+
}));
|
|
511
|
+
tools.push(defineTool({
|
|
512
|
+
name: 'dsh_browser_doctor',
|
|
513
|
+
description: 'Report the state of this task\'s browser: page URL, which tools the task restricted away, whether the page probe is installed, and what it has recorded (console lines, responses, dialogs, and how "settled" the page looks). Use it when something behaves oddly and the cause is not visible in the page — before guessing, or before telling the user the browser is broken.',
|
|
514
|
+
parameters: {},
|
|
515
|
+
output: {
|
|
516
|
+
schema: { type: 'object', additionalProperties: false, properties: { report: { type: 'string', required: true } } },
|
|
517
|
+
render: (_args, value) => [{ type: 'text', text: String(value.report) }],
|
|
518
|
+
},
|
|
519
|
+
timeoutMs,
|
|
520
|
+
isConcurrencySafe: () => true,
|
|
521
|
+
async execute(_args, exec) {
|
|
522
|
+
const browser = ctx.get('browser');
|
|
523
|
+
if (browser === undefined)
|
|
524
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
525
|
+
const task = taskKey(exec);
|
|
526
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
527
|
+
await installProbe(browser, session, exec.signal);
|
|
528
|
+
const url = await pageOperationValue(browser, session, { operation: 'url' }, exec.signal).then(text => text.replace(/^"|"$/g, ''));
|
|
529
|
+
const settle = await probe(browser, session, 'settle', [], exec.signal);
|
|
530
|
+
const consoleRows = await probe(browser, session, 'read', ['console', '', 100], exec.signal);
|
|
531
|
+
const networkRows = await probe(browser, session, 'read', ['network', '', 100], exec.signal);
|
|
532
|
+
const dialogRows = await probe(browser, session, 'read', ['dialogs', '', 5], exec.signal);
|
|
533
|
+
const restricted = state.restrictedByTask.get(task);
|
|
534
|
+
const lines = [
|
|
535
|
+
`session ${session}`,
|
|
536
|
+
`url ${url || '(unknown)'}`,
|
|
537
|
+
`page ${String(settle?.readyState ?? '?')}, ${String(settle?.pending ?? 0)} request(s) in flight, quiet for ${String(settle?.quietMs ?? 0)}ms`,
|
|
538
|
+
`probe installed (console ${consoleRows.length}/100, network ${networkRows.length}/100, dialogs ${dialogRows.length}/5)`,
|
|
539
|
+
restricted === undefined ? 'restricted: no (this task restricted nothing)' : `restricted: ${restricted.length === 0 ? 'everything' : restricted.join(', ')}`,
|
|
540
|
+
state.configRestrictedTo === undefined ? 'deployment allow-list: none' : `deployment allow-list: ${state.configRestrictedTo.join(', ')}`,
|
|
541
|
+
];
|
|
542
|
+
return { report: lines.join('\n') };
|
|
543
|
+
},
|
|
544
|
+
}));
|
|
545
|
+
tools.push(defineTool({
|
|
546
|
+
name: 'dsh_browser_help',
|
|
547
|
+
description: 'Look up how to use this browser: a short topic index (locate, wait, batch, dialogs, network, verify, recovery, limits) or one topic\'s text. Use it instead of guessing when a call failed for a reason the error message explains only briefly.',
|
|
548
|
+
parameters: {
|
|
549
|
+
topic: { type: 'string', description: 'One topic name; omit for the index.' },
|
|
550
|
+
},
|
|
551
|
+
output: {
|
|
552
|
+
schema: { type: 'object', additionalProperties: false, properties: { text: { type: 'string', required: true } } },
|
|
553
|
+
render: (_args, value) => [{ type: 'text', text: String(value.text) }],
|
|
554
|
+
},
|
|
555
|
+
timeoutMs,
|
|
556
|
+
isConcurrencySafe: () => true,
|
|
557
|
+
async execute(args) {
|
|
558
|
+
const topics = {
|
|
559
|
+
locate: 'Prefer dsh_browser_a11y (roles, names, states) or dsh_browser_snapshot (numbered elements), then click with {target:{by:"text"|css|xpath, value}}. Elements carry a stable CSS selector, so a click re-resolves the element instead of trusting an index that a re-render invalidates.',
|
|
560
|
+
wait: 'dsh_browser_wait waits for load + an optional URL/selector. dsh_browser_wait_for_response waits for a server answer (that is the "did it submit" wait). dsh_browser_console/network then explain what the page did.',
|
|
561
|
+
batch: 'dsh_browser_do runs several steps in one call: open/tap/field/type/key/scroll/sleep_ms/wait_text/wait_gone/wait_url/wait_idle/wait_js/eval/check. It stops at the first step that cannot proceed and reports which one; a tap whose target is covered by a cookie banner dismisses the banner first.',
|
|
562
|
+
dialogs: 'JavaScript dialogs are answered automatically (default: dismiss). dsh_browser_dialog reports them and can switch to "accept". A dialog from the browser itself (beforeunload, HTTP auth) is not covered — expect a stalled call there and reload.',
|
|
563
|
+
network: 'dsh_browser_network lists fetch/XHR/resource rows. Status 0 means the page never saw a status (aborted, blocked, or a resource-timing row). Only fetch/XHR rows carry a real status.',
|
|
564
|
+
verify: 'dsh_browser_assert asserts selector/text/url/js and returns evidence per assertion. Prefer it over reading a screenshot: "clicked" and "the form accepted it" are different claims, and a retry of an unverified submit can double it.',
|
|
565
|
+
recovery: 'dsh_browser_reset_session closes this task\'s browser session without touching others. dsh_browser_refresh reloads the page. If a carrier was lost, the page context is gone: re-read the page before continuing, and never re-submit something whose result you did not verify.',
|
|
566
|
+
limits: 'There is no CDP escape hatch and no network interception: the probe sees what the page sees. Downloads go through dsh_browser_download and a directory admission gate. Executing page JavaScript is a settings switch the model cannot lift.',
|
|
567
|
+
deliver: 'The browser saves a file and returns an absolute path; sending it to Feishu drive, Baidu Netdisk or any MCP-connected storage is a separate tool call with that path. Report where it sits locally AND what the upload tool answered, never just one. If the upload tool is missing or fails, keep the local file and say so — do not retry somewhere else silently.',
|
|
568
|
+
};
|
|
569
|
+
if (args.topic === undefined) {
|
|
570
|
+
return { text: `Topics: ${Object.keys(topics).join(', ')}\nAsk for one with topic=<name>.` };
|
|
571
|
+
}
|
|
572
|
+
const text = topics[args.topic];
|
|
573
|
+
if (text === undefined)
|
|
574
|
+
throw new Error(`dsh_browser_help: unknown topic "${args.topic}" (${Object.keys(topics).join(', ')})`);
|
|
575
|
+
return { text };
|
|
576
|
+
},
|
|
577
|
+
}));
|
|
578
|
+
tools.push(defineTool({
|
|
579
|
+
name: 'dsh_browser_do',
|
|
580
|
+
description: 'Run several steps in ONE call and report one compact result: "click search, type a query, press Enter, wait for results" is one call instead of five. Steps run in order and stop at the first that cannot proceed. Each step is an object with exactly one key: open {url} | tap {target} | field {target, text} | type {text} | key {key} | scroll {deltaY} | sleep_ms {ms} | wait_text {text} | wait_gone {text} | wait_url {url} | wait_idle {} | wait_js {script, intervalMs?} | eval {script} | check {selector|text|url|js}. A tap whose target is covered by a cookie banner or modal dismisses it first. Waits know when the page has settled and return as soon as the condition holds. A field step: {"field": {"target": {"by": "css", "value": "#username"}, "text": "tomsmith"}}. A tap step: {"tap": {"target": {"by": "css", "value": "button[type=submit]"}}}. The kind is the key, never a "type" value: "type" is the step that types text into the focused element. A cancelled or timed-out run still reports the steps that already ran.',
|
|
581
|
+
parameters: {
|
|
582
|
+
steps: { type: 'array', items: { oneOf: DO_STEP_SCHEMAS }, required: true, description: 'Steps, in order (max 40). Each step is an object whose only key is its kind.' },
|
|
583
|
+
timeoutMs: { type: 'number', description: 'Budget for the whole batch (default 60000, capped by the tool timeout).' },
|
|
584
|
+
autoDismiss: { type: 'boolean', description: 'Clear a covering banner before a tap (default true).' },
|
|
585
|
+
},
|
|
586
|
+
output: {
|
|
587
|
+
schema: {
|
|
588
|
+
type: 'object',
|
|
589
|
+
additionalProperties: false,
|
|
590
|
+
properties: {
|
|
591
|
+
completed: { type: 'number', required: true },
|
|
592
|
+
total: { type: 'number', required: true },
|
|
593
|
+
ok: { type: 'boolean', required: true },
|
|
594
|
+
stoppedAt: { type: 'number' },
|
|
595
|
+
reason: { type: 'string' },
|
|
596
|
+
sideEffectMayHaveHappened: { type: 'boolean' },
|
|
597
|
+
log: { type: 'array', items: { type: 'object', additionalProperties: true }, required: true },
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
render: (_args, value) => {
|
|
601
|
+
const rows = value.log;
|
|
602
|
+
const head = value.ok === true
|
|
603
|
+
? `${String(value.completed)}/${String(value.total)} steps done.`
|
|
604
|
+
: `Stopped at step ${String(value.stoppedAt)} (${String(value.completed)}/${String(value.total)} done): ${String(value.reason)}`;
|
|
605
|
+
const warning = value.ok === false && value.sideEffectMayHaveHappened === true
|
|
606
|
+
? '\nA step that can change the page already ran: the site may have acted on it. Read the site\'s own record before retrying — do not repeat it on the assumption that it failed.'
|
|
607
|
+
: '';
|
|
608
|
+
return [{ type: 'text', text: [head + warning, ...rows.map(row => ` ${String(row.index)} ${String(row.kind)}: ${String(row.detail)}`)].join('\n') }];
|
|
609
|
+
},
|
|
610
|
+
},
|
|
611
|
+
timeoutMs,
|
|
612
|
+
isConcurrencySafe: () => false, // drives the page; exclusive within a task
|
|
613
|
+
async execute(args, exec) {
|
|
614
|
+
assertAllowed(state, 'dsh_browser_do', taskKey(exec));
|
|
615
|
+
const browser = ctx.get('browser');
|
|
616
|
+
if (browser === undefined)
|
|
617
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
618
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
619
|
+
const steps = Array.isArray(args.steps) ? args.steps : [];
|
|
620
|
+
if (steps.length === 0)
|
|
621
|
+
throw new Error('dsh_browser_do: "steps" must be a non-empty array');
|
|
622
|
+
if (steps.length > 40)
|
|
623
|
+
throw new Error('dsh_browser_do: at most 40 steps per call — split the work');
|
|
624
|
+
await installProbe(browser, session, exec.signal);
|
|
625
|
+
const autoDismiss = args.autoDismiss !== false;
|
|
626
|
+
const budget = Math.min(args.timeoutMs ?? timeoutMs, maxWaitMs);
|
|
627
|
+
const deadline = Date.now() + budget;
|
|
628
|
+
const log = [];
|
|
629
|
+
// Set once a step that can change server state has run. A failure after that point must not
|
|
630
|
+
// read like a failure before it: measured on the first real benchmark run, where a batch died
|
|
631
|
+
// after the form had already been submitted and the message said nothing about it.
|
|
632
|
+
let dispatched = false;
|
|
633
|
+
const dispatchable = new Set(['tap', 'key', 'eval']);
|
|
634
|
+
const kinds = DO_STEP_KINDS;
|
|
635
|
+
/** Resolve a target: a string is visible text; an object passes through. */
|
|
636
|
+
const asTarget = (value) => {
|
|
637
|
+
if (typeof value === 'string' && value !== '')
|
|
638
|
+
return { by: 'text', value };
|
|
639
|
+
if (value !== null && typeof value === 'object') {
|
|
640
|
+
const raw = value;
|
|
641
|
+
if (typeof raw.value === 'string' && raw.value !== '') {
|
|
642
|
+
const by = raw.by === 'css' || raw.by === 'xpath' || raw.by === 'text' ? raw.by : 'text';
|
|
643
|
+
return { by, value: raw.value };
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return undefined;
|
|
647
|
+
};
|
|
648
|
+
for (let index = 0; index < steps.length; index += 1) {
|
|
649
|
+
const step = steps[index] ?? {};
|
|
650
|
+
const keys = Object.keys(step);
|
|
651
|
+
if (keys.length !== 1 || !kinds.includes(keys[0])) {
|
|
652
|
+
return { ok: false, completed: index, total: steps.length, stoppedAt: index + 1, reason: `step ${index + 1} must have exactly one of: ${kinds.join(', ')}`, log };
|
|
653
|
+
}
|
|
654
|
+
const kind = keys[0];
|
|
655
|
+
const value = step[kind];
|
|
656
|
+
if (Date.now() > deadline) {
|
|
657
|
+
return { ok: false, completed: index, total: steps.length, stoppedAt: index + 1, reason: `budget of ${Math.round(budget / 1000)}s exhausted`, log };
|
|
658
|
+
}
|
|
659
|
+
try {
|
|
660
|
+
let detail = 'ok';
|
|
661
|
+
if (kind === 'open') {
|
|
662
|
+
const url = typeof value === 'string' ? value : value?.url;
|
|
663
|
+
if (typeof url !== 'string')
|
|
664
|
+
throw new Error('open needs a URL string or {url}');
|
|
665
|
+
await browser.openUrl(session, { url }, exec.signal);
|
|
666
|
+
detail = url;
|
|
667
|
+
}
|
|
668
|
+
else if (kind === 'tap') {
|
|
669
|
+
const target = asTarget(value?.target ?? value);
|
|
670
|
+
if (target === undefined)
|
|
671
|
+
throw new Error('tap needs a target (text, or {by, value})');
|
|
672
|
+
if (autoDismiss) {
|
|
673
|
+
const rect = await probeLive(browser, session, 'find', [{ [target.by]: target.value }], exec.signal);
|
|
674
|
+
if (rect && typeof rect.x === 'number' && typeof rect.y === 'number') {
|
|
675
|
+
const cover = await probeLive(browser, session, 'overlayAt', [rect.x, rect.y], exec.signal);
|
|
676
|
+
if (cover?.dismiss && typeof cover.dismiss.x === 'number' && typeof cover.dismiss.y === 'number') {
|
|
677
|
+
await browser.click(session, { x: cover.dismiss.x, y: cover.dismiss.y }, exec.signal);
|
|
678
|
+
detail = `dismissed "${String(cover.dismiss.label)}" first`;
|
|
679
|
+
await pause(150);
|
|
680
|
+
}
|
|
681
|
+
else if (cover?.covers !== null && cover?.covers !== undefined && cover.covers !== rect.described) {
|
|
682
|
+
// Measured on the fixture's human gate: a hidden form left the tap hitting `<html>`,
|
|
683
|
+
// the step reported "ok", and nothing was submitted. A click that cannot land is a
|
|
684
|
+
// FAILURE, not a note — a silent no-op is the worst result this tool can return.
|
|
685
|
+
throw new Error(`the target is not reachable: ${String(cover.covers)} is at that point, not ${String(rect.described)} (hidden, or covered by an overlay that cannot be dismissed)`);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
await browser.click(session, { target }, exec.signal);
|
|
690
|
+
}
|
|
691
|
+
else if (kind === 'field') {
|
|
692
|
+
const spec = value;
|
|
693
|
+
const target = asTarget(spec?.target);
|
|
694
|
+
if (target === undefined || typeof spec?.text !== 'string')
|
|
695
|
+
throw new Error('field needs {target, text}');
|
|
696
|
+
await browser.setValue(session, { target, value: spec.text }, exec.signal);
|
|
697
|
+
detail = `${target.value} ← ${spec.text.slice(0, 40)}`;
|
|
698
|
+
}
|
|
699
|
+
else if (kind === 'type') {
|
|
700
|
+
const text = typeof value === 'string' ? value : value?.text;
|
|
701
|
+
if (typeof text !== 'string')
|
|
702
|
+
throw new Error('type needs a text string or {text}');
|
|
703
|
+
await browser.type(session, { text }, exec.signal);
|
|
704
|
+
detail = text.slice(0, 40);
|
|
705
|
+
}
|
|
706
|
+
else if (kind === 'key') {
|
|
707
|
+
const key = typeof value === 'string' ? value : value?.key;
|
|
708
|
+
if (typeof key !== 'string')
|
|
709
|
+
throw new Error('key needs a key name or {key}');
|
|
710
|
+
await browser.key(session, { key: key }, exec.signal);
|
|
711
|
+
detail = key;
|
|
712
|
+
}
|
|
713
|
+
else if (kind === 'scroll') {
|
|
714
|
+
const deltaY = typeof value === 'number' ? value : Number(value?.deltaY ?? Number.NaN);
|
|
715
|
+
if (!Number.isFinite(deltaY))
|
|
716
|
+
throw new Error('scroll needs a number or {deltaY}');
|
|
717
|
+
await browser.scroll(session, { deltaY }, exec.signal);
|
|
718
|
+
detail = String(deltaY);
|
|
719
|
+
}
|
|
720
|
+
else if (kind === 'sleep_ms') {
|
|
721
|
+
const requestedMs = typeof value === 'number' ? value : value?.ms;
|
|
722
|
+
if (typeof requestedMs !== 'number' || !Number.isFinite(requestedMs) || requestedMs < 0)
|
|
723
|
+
throw new Error('sleep_ms needs a non-negative number or {ms}');
|
|
724
|
+
const ms = Math.min(requestedMs, 10_000);
|
|
725
|
+
await pause(ms);
|
|
726
|
+
detail = `${ms}ms`;
|
|
727
|
+
}
|
|
728
|
+
else if (kind === 'wait_text' || kind === 'wait_gone') {
|
|
729
|
+
const want = typeof value === 'string' ? value : value?.text;
|
|
730
|
+
if (typeof want !== 'string')
|
|
731
|
+
throw new Error('wait_text/wait_gone need text or {text}');
|
|
732
|
+
const found = await poll(async () => {
|
|
733
|
+
const present = (await pageOperationValue(browser, session, { operation: 'text', text: want }, exec.signal)) === 'true';
|
|
734
|
+
return (kind === 'wait_text' ? present : !present) ? true : undefined;
|
|
735
|
+
}, Math.max(1_000, Math.min(deadline - Date.now(), 30_000)));
|
|
736
|
+
if (found === undefined)
|
|
737
|
+
throw new Error(`timed out waiting for "${want}" to be ${kind === 'wait_text' ? 'present' : 'gone'}`);
|
|
738
|
+
detail = want;
|
|
739
|
+
}
|
|
740
|
+
else if (kind === 'wait_url') {
|
|
741
|
+
const want = typeof value === 'string' ? value : value?.url;
|
|
742
|
+
if (typeof want !== 'string')
|
|
743
|
+
throw new Error('wait_url needs a URL fragment or {url}');
|
|
744
|
+
const budget = Math.max(1_000, Math.min(deadline - Date.now(), 30_000));
|
|
745
|
+
const hit = await poll(async () => {
|
|
746
|
+
const href = (await pageOperationValue(browser, session, { operation: 'url' }, exec.signal)).replace(/^"|"$/g, '');
|
|
747
|
+
return href.includes(want) ? href : undefined;
|
|
748
|
+
}, budget);
|
|
749
|
+
if (hit === undefined)
|
|
750
|
+
throw new Error(`timed out waiting for the URL to contain "${want}"`);
|
|
751
|
+
detail = hit;
|
|
752
|
+
}
|
|
753
|
+
else if (kind === 'wait_idle') {
|
|
754
|
+
const idle = await poll(async () => {
|
|
755
|
+
const settle = await probeLive(browser, session, 'settle', [], exec.signal);
|
|
756
|
+
const quiet = Number(settle?.quietMs ?? 0);
|
|
757
|
+
return Number(settle?.pending ?? 0) === 0 && quiet >= 300 ? settle : undefined;
|
|
758
|
+
}, Math.max(1_000, Math.min(deadline - Date.now(), 30_000)));
|
|
759
|
+
if (idle === undefined)
|
|
760
|
+
throw new Error('timed out waiting for the page to go quiet');
|
|
761
|
+
detail = `quiet for ${String(idle.quietMs)}ms`;
|
|
762
|
+
}
|
|
763
|
+
else if (kind === 'wait_js') {
|
|
764
|
+
const spec = typeof value === 'string' ? { script: value } : value;
|
|
765
|
+
if (typeof spec?.script !== 'string')
|
|
766
|
+
throw new Error('wait_js needs a script string or {script, intervalMs}');
|
|
767
|
+
const script = spec.script;
|
|
768
|
+
const interval = Math.min(Math.max(Number(spec.intervalMs ?? 200) || 200, 50), 5_000);
|
|
769
|
+
let last = 'nothing yet';
|
|
770
|
+
const started = Date.now();
|
|
771
|
+
const hit = await poll(async () => {
|
|
772
|
+
let raw;
|
|
773
|
+
try {
|
|
774
|
+
raw = await pageValue(browser, session, script, exec.signal);
|
|
775
|
+
}
|
|
776
|
+
catch (error) {
|
|
777
|
+
last = error instanceof Error ? error.message : String(error);
|
|
778
|
+
return undefined;
|
|
779
|
+
}
|
|
780
|
+
last = raw;
|
|
781
|
+
let parsed;
|
|
782
|
+
try {
|
|
783
|
+
parsed = JSON.parse(raw);
|
|
784
|
+
}
|
|
785
|
+
catch {
|
|
786
|
+
parsed = raw;
|
|
787
|
+
}
|
|
788
|
+
return parsed ? raw : undefined;
|
|
789
|
+
}, Math.max(0, deadline - Date.now()), interval);
|
|
790
|
+
if (hit === undefined)
|
|
791
|
+
throw new Error(`timed out after ${Date.now() - started}ms waiting for the script to return a truthy value; last result: ${last.slice(0, 200)}`);
|
|
792
|
+
log.push({ index: index + 1, kind, detail: hit.slice(0, 80), value: hit });
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
else if (kind === 'eval') {
|
|
796
|
+
const script = typeof value === 'string' ? value : value?.script;
|
|
797
|
+
if (typeof script !== 'string')
|
|
798
|
+
throw new Error('eval needs a script string or {script}');
|
|
799
|
+
const text = await pageValue(browser, session, script, exec.signal);
|
|
800
|
+
detail = text.slice(0, 80);
|
|
801
|
+
}
|
|
802
|
+
else if (kind === 'check') {
|
|
803
|
+
const result = await runChecks(browser, session, value, exec.signal);
|
|
804
|
+
if (!result.pass) {
|
|
805
|
+
const failed = result.checks.filter(check => !check.pass).map(check => `${check.kind}: ${check.expected} → ${check.actual}`);
|
|
806
|
+
throw new Error(`check failed (${failed.join('; ')})`);
|
|
807
|
+
}
|
|
808
|
+
detail = `${result.checks.length} check(s) passed`;
|
|
809
|
+
}
|
|
810
|
+
if (dispatchable.has(kind))
|
|
811
|
+
dispatched = true;
|
|
812
|
+
log.push({ index: index + 1, kind, detail });
|
|
813
|
+
}
|
|
814
|
+
catch (error) {
|
|
815
|
+
return {
|
|
816
|
+
ok: false,
|
|
817
|
+
completed: index,
|
|
818
|
+
total: steps.length,
|
|
819
|
+
stoppedAt: index + 1,
|
|
820
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
821
|
+
sideEffectMayHaveHappened: dispatched,
|
|
822
|
+
log: [...log, { index: index + 1, kind, detail: `failed: ${error instanceof Error ? error.message : String(error)}` }],
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return { ok: true, completed: steps.length, total: steps.length, log };
|
|
827
|
+
},
|
|
828
|
+
}));
|
|
829
|
+
return tools;
|
|
830
|
+
}
|
|
831
|
+
const isReadMethod = (method) => method === undefined || /^(GET|HEAD)$/i.test(String(method));
|
|
832
|
+
/** The compact text form: one line per source, so the answer stays around 1-2 KB. */
|
|
833
|
+
export function formatDataSources(found) {
|
|
834
|
+
const kb = (bytes) => bytes === undefined || bytes <= 0 ? '' : bytes < 1024 ? ` ${bytes} B` : ` ${(bytes / 1024).toFixed(1)} KB`;
|
|
835
|
+
const lines = [];
|
|
836
|
+
if (found.embedded.length > 0) {
|
|
837
|
+
lines.push('Embedded state:');
|
|
838
|
+
for (const item of found.embedded) {
|
|
839
|
+
const keys = item.keys !== undefined && item.keys.length > 0 ? ` keys: ${item.keys.join(', ')}` : item.parsed === false ? ' (not JSON)' : '';
|
|
840
|
+
const arrays = item.arrays !== undefined && item.arrays.length > 0 ? `; arrays: ${item.arrays.map(row => `${row.path} (${row.length})`).join(', ')}` : '';
|
|
841
|
+
lines.push(` ${item.name}${kb(item.bytes)}${keys}${arrays}`);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
if (found.apis.length > 0) {
|
|
845
|
+
lines.push('APIs the page called:');
|
|
846
|
+
for (const row of found.apis)
|
|
847
|
+
lines.push(` ${row.method} ${row.status}${row.type ? ` ${row.type}` : ''}${row.calls !== undefined && row.calls > 1 ? ` ×${row.calls}` : ''} ${row.url}`);
|
|
848
|
+
}
|
|
849
|
+
if (found.resources.length > 0) {
|
|
850
|
+
lines.push('Data-like resources (resource timing, includes requests before the probe):');
|
|
851
|
+
for (const row of found.resources)
|
|
852
|
+
lines.push(` ${row.initiator ?? ''}${kb(row.bytes)} ${row.url}`.replace(/^ {2} /, ' '));
|
|
853
|
+
}
|
|
854
|
+
if (found.declared.length > 0) {
|
|
855
|
+
lines.push('Declared endpoints:');
|
|
856
|
+
for (const row of found.declared)
|
|
857
|
+
lines.push(` ${row.from} ${row.url}`);
|
|
858
|
+
}
|
|
859
|
+
return lines.length === 0
|
|
860
|
+
? `No embedded state, JSON APIs or declared endpoints found on ${found.url}; read the DOM.`
|
|
861
|
+
: lines.join('\n');
|
|
862
|
+
}
|