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,807 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation, tab, history, session and start-page shortcut tools.
|
|
3
|
+
* @module dsh-browser/tool-browser/tools-navigation
|
|
4
|
+
*/
|
|
5
|
+
import { setLastOpen } from '../browser-electron/open-slot.js';
|
|
6
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
7
|
+
import { CHALLENGE_SCHEMA, reportChallenge } from './block-recovery.js';
|
|
8
|
+
import { createShortcutStore } from '../browser-electron/startpage-shortcuts.js';
|
|
9
|
+
import { browserSessionHandle, resolveTabHandle, scopedTabs, sessionWireId, tabWireId } from '../browser/handles.js';
|
|
10
|
+
import { ELEMENT_ITEM_SCHEMA, projectElement } from './element-fields.js';
|
|
11
|
+
import { readSurface, enforceSurface, assertSurfaceCanHost, assertAllowed, agentOf, taskKey, rememberSession, ensureSession, panelBound } from './state.js';
|
|
12
|
+
import { formatSnapshot } from './tools-observation.js';
|
|
13
|
+
import { blockRetryDelayMs } from '../browser/anti-bot.js';
|
|
14
|
+
/** Sleep, cut short by the call's cancellation. */
|
|
15
|
+
function pause(ms, signal) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
if (signal?.aborted === true) {
|
|
18
|
+
reject(signal.reason);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const timer = setTimeout(() => { signal?.removeEventListener('abort', abort); resolve(); }, ms);
|
|
22
|
+
const abort = () => { clearTimeout(timer); reject(signal?.reason); };
|
|
23
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Refuse the bare DSH web root, which answers 401 and looks like a real page.
|
|
28
|
+
*
|
|
29
|
+
* The address comes from `DSH_WEB_URL`, which the harness exports to its children — NOT from a
|
|
30
|
+
* hardcoded port. This machine's GUI has run on 3080 and on 19387, so a number would stop matching
|
|
31
|
+
* exactly when the guard is needed, and the trap is not a port anyway: it is the SHAPE. A loopback
|
|
32
|
+
* address at its root with no token renders as an unauthenticated 401 page, which an agent reads
|
|
33
|
+
* as the site it meant to open.
|
|
34
|
+
* @param rawUrl - the address a caller asked to open.
|
|
35
|
+
*/
|
|
36
|
+
export function assertNotBareDshWebUrl(rawUrl) {
|
|
37
|
+
const advertised = process.env.DSH_WEB_URL;
|
|
38
|
+
if (typeof advertised !== 'string' || advertised === '')
|
|
39
|
+
return;
|
|
40
|
+
let target;
|
|
41
|
+
let dsh;
|
|
42
|
+
try {
|
|
43
|
+
target = new URL(rawUrl);
|
|
44
|
+
dsh = new URL(advertised);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return; // not a URL this guard can judge; the provider's own admission is the next gate
|
|
48
|
+
}
|
|
49
|
+
if (target.origin !== dsh.origin)
|
|
50
|
+
return;
|
|
51
|
+
if (target.pathname !== '/')
|
|
52
|
+
return;
|
|
53
|
+
// The authenticated URL printed by `dsh web` carries a token; the bare root does not.
|
|
54
|
+
if (target.searchParams.has('token'))
|
|
55
|
+
return;
|
|
56
|
+
throw new Error('dsh_browser_open: refusing the bare DSH web root (' + dsh.origin + '/) because it carries no '
|
|
57
|
+
+ 'authentication token, so it answers with a 401 page that reads like a real site. Open the '
|
|
58
|
+
+ 'target site instead; to open DSH itself, use the authenticated URL printed by `dsh web`.');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Define this module's tools for one apply.
|
|
62
|
+
* @param scope - the apply's context, settings and per-apply state.
|
|
63
|
+
* @returns the tool definitions, for the entry to register.
|
|
64
|
+
*/
|
|
65
|
+
export function navigationTools(scope) {
|
|
66
|
+
const { ctx, config, state, timeoutMs, maxWaitMs, surface } = scope;
|
|
67
|
+
const tools = [];
|
|
68
|
+
// The start page's shared shortcut list, reached through the settings section the
|
|
69
|
+
// sidebar edits. Built lazily for the same reason `references()` is: the settings
|
|
70
|
+
// service is registered by another entry and may not exist yet at apply time.
|
|
71
|
+
const startpageShortcuts = createShortcutStore(() => ctx.get('settings'));
|
|
72
|
+
tools.push(defineTool({
|
|
73
|
+
name: 'dsh_browser_shortcuts',
|
|
74
|
+
description: 'Read or edit the Sidebar Browser start page shortcuts — the shared website entries a human sees on an empty tab. action=list returns them, action=add appends one (title + http(s) url required, http:// or https:// only, at most 48 entries), action=remove drops one by id. The list is shared with the sidebar UI: an entry added here appears on the next empty tab for every conversation, and one a human adds appears here.',
|
|
75
|
+
parameters: {
|
|
76
|
+
action: { type: 'string', required: true, enum: ['list', 'add', 'remove'], description: 'list the shortcuts, add one, or remove one by id.' },
|
|
77
|
+
title: { type: 'string', description: 'Display title (add). At most 80 characters.' },
|
|
78
|
+
url: { type: 'string', description: 'Destination (add): a full http:// or https:// address.' },
|
|
79
|
+
id: { type: 'string', description: 'Shortcut id (remove), as returned by list or add.' },
|
|
80
|
+
},
|
|
81
|
+
output: {
|
|
82
|
+
schema: {
|
|
83
|
+
type: 'object',
|
|
84
|
+
additionalProperties: false,
|
|
85
|
+
properties: {
|
|
86
|
+
shortcuts: {
|
|
87
|
+
type: 'array',
|
|
88
|
+
required: true,
|
|
89
|
+
items: {
|
|
90
|
+
type: 'object',
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
properties: {
|
|
93
|
+
id: { type: 'string', required: true },
|
|
94
|
+
title: { type: 'string', required: true },
|
|
95
|
+
url: { type: 'string', required: true },
|
|
96
|
+
iconKey: { type: 'string' },
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
changed: { type: 'string', description: 'What the call changed: added <id>, removed <id>, or empty for list.' },
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
render: (_args, value) => {
|
|
104
|
+
const rows = value.shortcuts;
|
|
105
|
+
const changed = typeof value.changed === 'string' && value.changed !== '' ? `${value.changed}\n` : '';
|
|
106
|
+
const body = rows.length === 0
|
|
107
|
+
? '(the start page has no shortcuts)'
|
|
108
|
+
: rows.map(row => `- ${row.title} -> ${row.url} [${row.id}]`).join('\n');
|
|
109
|
+
return [{ type: 'text', text: `${changed}${rows.length} shortcut(s):\n${body}` }];
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
timeoutMs,
|
|
113
|
+
isConcurrencySafe: () => false,
|
|
114
|
+
async execute(args, exec) {
|
|
115
|
+
assertAllowed(state, 'dsh_browser_shortcuts', taskKey(exec));
|
|
116
|
+
try {
|
|
117
|
+
if (args.action === 'list') {
|
|
118
|
+
const reading = startpageShortcuts.list();
|
|
119
|
+
return { shortcuts: reading.shortcuts.map(row => ({ ...row })), changed: '' };
|
|
120
|
+
}
|
|
121
|
+
if (args.action === 'add') {
|
|
122
|
+
const result = await startpageShortcuts.add({ title: args.title, url: args.url });
|
|
123
|
+
return { shortcuts: result.shortcuts.map(row => ({ ...row })), changed: `added ${result.shortcut.id}` };
|
|
124
|
+
}
|
|
125
|
+
if (typeof args.id !== 'string' || args.id === '')
|
|
126
|
+
throw new Error('remove needs the shortcut id');
|
|
127
|
+
const result = await startpageShortcuts.remove(args.id);
|
|
128
|
+
return {
|
|
129
|
+
shortcuts: result.shortcuts.map(row => ({ ...row })),
|
|
130
|
+
changed: result.removed ? `removed ${args.id}` : `${args.id} was not in the list`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
// The store reports refusals as typed errors; a tool must not answer with a stack.
|
|
135
|
+
throw new Error(`start page shortcuts: ${error instanceof Error ? error.message : String(error)}`);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
}));
|
|
139
|
+
tools.push(defineTool({
|
|
140
|
+
name: 'dsh_browser_open',
|
|
141
|
+
description: 'Open a URL on the selected controllable surface (default: panel). Success returns a live snapshot and supports subsequent browser tools on that same page. A Web iframe or unavailable desktop bridge is refused; no manual-only navigation is queued. Reading tools never start another browser. newTab is optional on CDP surfaces. Never treat the bare DSH host (e.g. http://127.0.0.1:<port>/) as the target — it needs the authenticated URL printed by `dsh web`, and the bare root is refused. On a blocked page (403, access denied, bot wall), follow any CHALLENGE banner or try the site\'s JSON/API, sitemap, search results, or archives before reporting a blocker.',
|
|
142
|
+
parameters: {
|
|
143
|
+
url: { type: 'string', required: true, description: 'The URL to open (HTTP/HTTPS).' },
|
|
144
|
+
newTab: { type: 'boolean', description: 'Open in a new tab instead of the active one.' },
|
|
145
|
+
// Explicit per-call surface. "panel" (default) places the page in the DSH sidebar and opens no
|
|
146
|
+
// window; "builtin" drives the plugin's own browser, which is what debugging DSH itself needs.
|
|
147
|
+
surface: { type: 'string', enum: ['panel', 'builtin'], description: 'panel (default): the DSH sidebar only; builtin: the plugin browser, for debugging DSH itself.' },
|
|
148
|
+
},
|
|
149
|
+
output: {
|
|
150
|
+
schema: {
|
|
151
|
+
type: 'object',
|
|
152
|
+
additionalProperties: false,
|
|
153
|
+
properties: {
|
|
154
|
+
url: { type: 'string', required: true },
|
|
155
|
+
title: { type: 'string' },
|
|
156
|
+
carrier: { type: 'string' },
|
|
157
|
+
truncated: { type: 'boolean' },
|
|
158
|
+
elements: {
|
|
159
|
+
type: 'array',
|
|
160
|
+
required: true,
|
|
161
|
+
// Same shared item schema as dsh_browser_open's, so the two cannot drift apart.
|
|
162
|
+
items: ELEMENT_ITEM_SCHEMA,
|
|
163
|
+
},
|
|
164
|
+
challenge: CHALLENGE_SCHEMA,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
// dsh_browser_open is an overview of what just loaded, not a locator: it has no
|
|
168
|
+
// `coords` parameter, so coordinates stay off here (dsh_browser_snapshot owns
|
|
169
|
+
// that switch for callers that actually target pixels).
|
|
170
|
+
render: (_args, value) => [{ type: 'text', text: formatSnapshot(value, {}) }],
|
|
171
|
+
},
|
|
172
|
+
timeoutMs,
|
|
173
|
+
isConcurrencySafe: () => false, // opens tabs / navigates; exclusive within a task
|
|
174
|
+
async execute(args, exec) {
|
|
175
|
+
assertAllowed(state, 'dsh_browser_open', taskKey(exec));
|
|
176
|
+
assertNotBareDshWebUrl(args.url);
|
|
177
|
+
// ONE surface per open. On the Web shell the reader's sidebar is the browsing surface; opening the
|
|
178
|
+
// plugin's own browser as well produced two live views of the same page (reported as "you opened the
|
|
179
|
+
// built-in browser AND the sidebar at once"). `browser.surface` decides: "panel" (default on Web)
|
|
180
|
+
// places the page in the sidebar and opens no window; "builtin" is the debugging surface.
|
|
181
|
+
const surfaceHint = args.surface;
|
|
182
|
+
const surface = enforceSurface(surfaceHint ?? readSurface(), args.url);
|
|
183
|
+
const browser = ctx.get('browser');
|
|
184
|
+
if (browser === undefined)
|
|
185
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
186
|
+
const key = taskKey(exec);
|
|
187
|
+
if (surface === 'panel') {
|
|
188
|
+
const preceding = state.pendingPanelOpens.get(key);
|
|
189
|
+
let previous;
|
|
190
|
+
let session;
|
|
191
|
+
const opening = (async () => {
|
|
192
|
+
await preceding;
|
|
193
|
+
await state.pendingOpens.get(key);
|
|
194
|
+
previous = state.sessionsByTask.get(key);
|
|
195
|
+
const target = new URL(args.url);
|
|
196
|
+
if (target.protocol !== 'http:' && target.protocol !== 'https:')
|
|
197
|
+
throw new Error('dsh_browser_open: panel requires an HTTP/HTTPS URL');
|
|
198
|
+
exec.signal?.throwIfAborted();
|
|
199
|
+
session = panelBound(state, key) && previous !== undefined && browser.exists(previous)
|
|
200
|
+
? previous : await browser.openPanel?.(key);
|
|
201
|
+
if (session === undefined) {
|
|
202
|
+
assertSurfaceCanHost(surface, args.url);
|
|
203
|
+
exec.signal?.throwIfAborted();
|
|
204
|
+
setLastOpen(args.url, Date.now(), key);
|
|
205
|
+
rememberSession(browser, state, key, agentOf(exec), undefined, args.url);
|
|
206
|
+
return { url: args.url, carrier: 'panel-iframe-navigation-requested', title: '', elements: [], truncated: false };
|
|
207
|
+
}
|
|
208
|
+
await browser.openUrl(session, { url: args.url, ...args.newTab === true ? { newTab: true } : {} }, exec.signal);
|
|
209
|
+
const snapshot = await browser.snapshot(session, exec.signal);
|
|
210
|
+
exec.signal?.throwIfAborted();
|
|
211
|
+
rememberSession(browser, state, key, agentOf(exec), session, args.url);
|
|
212
|
+
return {
|
|
213
|
+
url: snapshot.url,
|
|
214
|
+
...snapshot.title !== undefined ? { title: snapshot.title } : {},
|
|
215
|
+
elements: snapshot.elements.map(el => projectElement(el)),
|
|
216
|
+
truncated: snapshot.truncated,
|
|
217
|
+
...snapshot.challenge !== undefined ? { challenge: reportChallenge(snapshot.challenge, snapshot.url) } : {},
|
|
218
|
+
};
|
|
219
|
+
})();
|
|
220
|
+
const pending = opening.then(() => { });
|
|
221
|
+
state.pendingPanelOpens.set(key, pending);
|
|
222
|
+
void pending.catch(() => { });
|
|
223
|
+
try {
|
|
224
|
+
return await opening;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
if (session !== undefined && session !== previous)
|
|
228
|
+
await browser.close(session).catch(() => { });
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
if (state.pendingPanelOpens.get(key) === pending)
|
|
233
|
+
state.pendingPanelOpens.delete(key);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
await state.pendingPanelOpens.get(key);
|
|
237
|
+
await state.pendingOpens.get(key);
|
|
238
|
+
if (panelBound(state, key)) {
|
|
239
|
+
const previous = state.sessionsByTask.get(key);
|
|
240
|
+
state.sessionsByTask.delete(key);
|
|
241
|
+
state.panelUrlByTask.delete(key);
|
|
242
|
+
if (previous !== undefined)
|
|
243
|
+
await browser.close(previous);
|
|
244
|
+
}
|
|
245
|
+
const existing = state.sessionsByTask.get(key);
|
|
246
|
+
const fresh = args.newTab !== true && (existing === undefined || !browser.exists(existing));
|
|
247
|
+
let session = await ensureSession(browser, state, key, agentOf(exec), true);
|
|
248
|
+
try {
|
|
249
|
+
await browser.openUrl(session, {
|
|
250
|
+
url: args.url,
|
|
251
|
+
...args.newTab === true ? { newTab: true } : {},
|
|
252
|
+
}, exec.signal);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
// The human's browser is already running on its own profile: the launch hands the request over and
|
|
256
|
+
// exits with code 0. A new window opened inside THEIR browser with their logins — what "use my
|
|
257
|
+
// Edge" means — it is simply not driveable, because their instance has no debugging port.
|
|
258
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
259
|
+
if (!/exited immediately after launch \(exit code 0\)/u.test(message))
|
|
260
|
+
throw error;
|
|
261
|
+
return { url: args.url, carrier: 'launched-user-profile', title: '', elements: [], truncated: false };
|
|
262
|
+
}
|
|
263
|
+
// Hand the page to the Web sidebar as well, except when the user explicitly selected an
|
|
264
|
+
// installed Chrome/Edge channel (issue #106: do not double-open the page in the sidebar).
|
|
265
|
+
const selectedChannel = scope.settingsStore.get().browser.channel;
|
|
266
|
+
if (selectedChannel !== 'chrome' && selectedChannel !== 'edge') {
|
|
267
|
+
try {
|
|
268
|
+
setLastOpen(args.url, Date.now());
|
|
269
|
+
}
|
|
270
|
+
catch { /* best effort */ }
|
|
271
|
+
}
|
|
272
|
+
let snapshot;
|
|
273
|
+
try {
|
|
274
|
+
snapshot = await browser.snapshot(session, exec.signal);
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
// The human's browser is ALREADY running on its own profile, so a launch hands the request over
|
|
278
|
+
// and the launcher exits with code 0. That is not a failure: a new window opened inside THEIR
|
|
279
|
+
// browser, with their logins, which is exactly what "use my Edge" means. It is only undriveable,
|
|
280
|
+
// because their instance has no debugging port. Report the page, not an error.
|
|
281
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
282
|
+
if (!/exited immediately after launch \(exit code 0\)/u.test(message))
|
|
283
|
+
throw error;
|
|
284
|
+
return {
|
|
285
|
+
url: args.url,
|
|
286
|
+
carrier: 'launched-user-profile',
|
|
287
|
+
title: '',
|
|
288
|
+
elements: [],
|
|
289
|
+
truncated: false,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
// A refusal (access denied, 429, empty 403) gets exactly one more try: after a pause, and in a
|
|
293
|
+
// fresh session when this open started the task's browser, so nothing the first attempt left
|
|
294
|
+
// behind rides along. Human verifications and network blocks are never retried — the first
|
|
295
|
+
// goes to the human, the second is an environment limit — and a second refusal is reported
|
|
296
|
+
// with the fallback routes instead of being tried again.
|
|
297
|
+
let retried = false;
|
|
298
|
+
if (snapshot.challenge?.blocked === true && snapshot.challenge.recovery === 'retry') {
|
|
299
|
+
retried = true;
|
|
300
|
+
if (fresh) {
|
|
301
|
+
// The refused page goes too: a closed session leaves its pages to the browser, and the
|
|
302
|
+
// retry must not leave a second copy of the wall behind in the human's window.
|
|
303
|
+
for (const tab of await browser.listTabs(session).catch(() => []))
|
|
304
|
+
await browser.closeTab(session, tab.id).catch(() => { });
|
|
305
|
+
await browser.close(session).catch(() => { });
|
|
306
|
+
state.sessionsByTask.delete(key);
|
|
307
|
+
}
|
|
308
|
+
await pause(blockRetryDelayMs(), exec.signal);
|
|
309
|
+
if (fresh)
|
|
310
|
+
session = await ensureSession(browser, state, key, agentOf(exec), true);
|
|
311
|
+
// `navigate`, not `openUrl`: an open adopts a page already showing this URL, which here is
|
|
312
|
+
// the refused page itself, and the retry would read it again without asking the site.
|
|
313
|
+
await browser.navigate(session, { url: args.url }, exec.signal);
|
|
314
|
+
snapshot = await browser.snapshot(session, exec.signal);
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
url: snapshot.url,
|
|
318
|
+
carrier: String(globalThis.__dshBrowserCarrier ?? 'bundled'),
|
|
319
|
+
...snapshot.title !== undefined ? { title: snapshot.title } : {},
|
|
320
|
+
elements: snapshot.elements.map(el => projectElement(el)),
|
|
321
|
+
truncated: snapshot.truncated,
|
|
322
|
+
...snapshot.challenge !== undefined ? { challenge: reportChallenge(snapshot.challenge, snapshot.url, retried) } : {},
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
}));
|
|
326
|
+
tools.push(defineTool({
|
|
327
|
+
name: 'dsh_browser_wait',
|
|
328
|
+
description: 'Wait until the shared-browser page is ready: load complete, and optionally the expected URL and/or a CSS selector present (top document or same-origin iframes). Use after dsh_browser_open on slow sites instead of snapshotting a white page — wait for the URL you navigated to first. Returns ready=true/false with a short reason; a miss is not an error.',
|
|
329
|
+
parameters: {
|
|
330
|
+
timeoutMs: { type: 'number', description: 'Maximum wait in ms (default 30000).' },
|
|
331
|
+
url: { type: 'string', description: 'Expected page URL (exact or prefix), e.g. the URL you opened.' },
|
|
332
|
+
selector: { type: 'string', description: 'CSS selector that must exist.' },
|
|
333
|
+
},
|
|
334
|
+
output: {
|
|
335
|
+
schema: {
|
|
336
|
+
type: 'object',
|
|
337
|
+
additionalProperties: false,
|
|
338
|
+
properties: {
|
|
339
|
+
ready: { type: 'boolean', required: true },
|
|
340
|
+
reason: { type: 'string', required: true },
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
render: (_args, value) => [{ type: 'text', text: value.ready ? 'Page ready.' : `Wait timed out: ${value.reason}` }],
|
|
344
|
+
},
|
|
345
|
+
timeoutMs,
|
|
346
|
+
isConcurrencySafe: () => true,
|
|
347
|
+
async execute(args, exec) {
|
|
348
|
+
const browser = ctx.get('browser');
|
|
349
|
+
if (browser === undefined)
|
|
350
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
351
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
352
|
+
const result = await browser.waitFor(session, {
|
|
353
|
+
// Capped so an over-budget argument returns the documented verdict (see maxWaitMs)
|
|
354
|
+
// rather than aborting the whole tool call.
|
|
355
|
+
...args.timeoutMs !== undefined ? { timeoutMs: Math.min(args.timeoutMs, maxWaitMs) } : {},
|
|
356
|
+
...args.url !== undefined ? { url: args.url } : {},
|
|
357
|
+
...args.selector !== undefined ? { selector: args.selector } : {},
|
|
358
|
+
}, exec.signal);
|
|
359
|
+
return { ready: result.ready, reason: result.reason };
|
|
360
|
+
},
|
|
361
|
+
}));
|
|
362
|
+
tools.push(defineTool({
|
|
363
|
+
name: 'dsh_browser_back',
|
|
364
|
+
description: 'Go back one step in the shared-browser page history. A no-op when there is no previous entry.',
|
|
365
|
+
parameters: {},
|
|
366
|
+
output: {
|
|
367
|
+
schema: { type: 'object', additionalProperties: false, properties: { back: { type: 'boolean', required: true } } },
|
|
368
|
+
render: (_args, value) => [{ type: 'text', text: value.back ? 'Went back.' : 'Failed.' }],
|
|
369
|
+
},
|
|
370
|
+
timeoutMs,
|
|
371
|
+
isConcurrencySafe: () => false, // mutates page state; exclusive within a task
|
|
372
|
+
async execute(_args, exec) {
|
|
373
|
+
assertAllowed(state, 'dsh_browser_back', taskKey(exec));
|
|
374
|
+
const browser = ctx.get('browser');
|
|
375
|
+
if (browser === undefined)
|
|
376
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
377
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
378
|
+
await browser.back(session, exec.signal);
|
|
379
|
+
return { back: true };
|
|
380
|
+
},
|
|
381
|
+
}));
|
|
382
|
+
tools.push(defineTool({
|
|
383
|
+
name: 'dsh_browser_forward',
|
|
384
|
+
description: 'Go forward one step in the shared-browser page history. A no-op when there is no next entry.',
|
|
385
|
+
parameters: {},
|
|
386
|
+
output: {
|
|
387
|
+
schema: { type: 'object', additionalProperties: false, properties: { forward: { type: 'boolean', required: true } } },
|
|
388
|
+
render: (_args, value) => [{ type: 'text', text: value.forward ? 'Went forward.' : 'Failed.' }],
|
|
389
|
+
},
|
|
390
|
+
timeoutMs,
|
|
391
|
+
isConcurrencySafe: () => false, // mutates page state; exclusive within a task
|
|
392
|
+
async execute(_args, exec) {
|
|
393
|
+
assertAllowed(state, 'dsh_browser_forward', taskKey(exec));
|
|
394
|
+
const browser = ctx.get('browser');
|
|
395
|
+
if (browser === undefined)
|
|
396
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
397
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
398
|
+
await browser.forward(session, exec.signal);
|
|
399
|
+
return { forward: true };
|
|
400
|
+
},
|
|
401
|
+
}));
|
|
402
|
+
tools.push(defineTool({
|
|
403
|
+
name: 'dsh_browser_refresh',
|
|
404
|
+
description: 'Reload the current page in the shared browser (like a browser\'s refresh button). Use after a page got stuck, to apply script changes, or to re-fetch a page.',
|
|
405
|
+
parameters: {},
|
|
406
|
+
output: {
|
|
407
|
+
schema: { type: 'object', additionalProperties: false, properties: { refreshed: { type: 'boolean', required: true } } },
|
|
408
|
+
render: (_args, value) => [{ type: 'text', text: value.refreshed ? 'Page reloaded.' : 'Failed.' }],
|
|
409
|
+
},
|
|
410
|
+
timeoutMs,
|
|
411
|
+
isConcurrencySafe: () => false, // reloads the page; exclusive within a task
|
|
412
|
+
async execute(_args, exec) {
|
|
413
|
+
assertAllowed(state, 'dsh_browser_refresh', taskKey(exec));
|
|
414
|
+
const browser = ctx.get('browser');
|
|
415
|
+
if (browser === undefined)
|
|
416
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
417
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
418
|
+
await browser.reload(session, exec.signal);
|
|
419
|
+
return { refreshed: true };
|
|
420
|
+
},
|
|
421
|
+
}));
|
|
422
|
+
if (config.tabTools !== false) {
|
|
423
|
+
tools.push(defineTool({
|
|
424
|
+
name: 'dsh_browser_list_tabs',
|
|
425
|
+
description: 'List the shared-browser session\'s tabs with their URLs and which is active.',
|
|
426
|
+
parameters: {},
|
|
427
|
+
output: {
|
|
428
|
+
schema: {
|
|
429
|
+
type: 'object',
|
|
430
|
+
additionalProperties: false,
|
|
431
|
+
properties: {
|
|
432
|
+
tabs: {
|
|
433
|
+
type: 'array',
|
|
434
|
+
required: true,
|
|
435
|
+
items: {
|
|
436
|
+
type: 'object',
|
|
437
|
+
additionalProperties: false,
|
|
438
|
+
properties: {
|
|
439
|
+
id: { type: 'string', required: true },
|
|
440
|
+
url: { type: 'string', required: true },
|
|
441
|
+
active: { type: 'boolean', required: true },
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
render: (_args, value) => [{
|
|
448
|
+
type: 'text',
|
|
449
|
+
text: value.tabs
|
|
450
|
+
.map(t => `${t.active ? '*' : ' '} ${t.id} ${t.url}`).join('\n'),
|
|
451
|
+
}],
|
|
452
|
+
},
|
|
453
|
+
timeoutMs,
|
|
454
|
+
isConcurrencySafe: () => true,
|
|
455
|
+
async execute(_args, exec) {
|
|
456
|
+
const browser = ctx.get('browser');
|
|
457
|
+
if (browser === undefined)
|
|
458
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
459
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
460
|
+
const tabs = await browser.listTabs(session);
|
|
461
|
+
return { tabs: scopedTabs(browserSessionHandle(taskKey(exec), session), tabs).map(t => ({ id: t.id, url: t.url, active: t.active })) };
|
|
462
|
+
},
|
|
463
|
+
}));
|
|
464
|
+
tools.push(defineTool({
|
|
465
|
+
name: 'dsh_browser_switch_tab',
|
|
466
|
+
description: 'Switch the shared browser to a tab by id (from dsh_browser_list_tabs).',
|
|
467
|
+
parameters: {
|
|
468
|
+
tabId: { type: 'string', required: true, description: 'The tab id to switch to.' },
|
|
469
|
+
},
|
|
470
|
+
output: {
|
|
471
|
+
schema: { type: 'object', additionalProperties: false, properties: { switched: { type: 'boolean', required: true } } },
|
|
472
|
+
render: (_args, value) => [{ type: 'text', text: value.switched ? 'Switched.' : 'Tab not found.' }],
|
|
473
|
+
},
|
|
474
|
+
timeoutMs,
|
|
475
|
+
isConcurrencySafe: () => false, // mutates the active tab; exclusive within a task
|
|
476
|
+
async execute(args, exec) {
|
|
477
|
+
assertAllowed(state, 'dsh_browser_switch_tab', taskKey(exec));
|
|
478
|
+
const browser = ctx.get('browser');
|
|
479
|
+
if (browser === undefined)
|
|
480
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
481
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
482
|
+
const handle = resolveTabHandle(browserSessionHandle(taskKey(exec), session), args.tabId);
|
|
483
|
+
await browser.switchTab(session, tabWireId(handle));
|
|
484
|
+
return { switched: true };
|
|
485
|
+
},
|
|
486
|
+
}));
|
|
487
|
+
tools.push(defineTool({
|
|
488
|
+
name: 'dsh_browser_close_tab',
|
|
489
|
+
description: 'Close a tab in the shared browser by id. Closing the active tab activates the next.',
|
|
490
|
+
parameters: {
|
|
491
|
+
tabId: { type: 'string', required: true, description: 'The tab id to close.' },
|
|
492
|
+
},
|
|
493
|
+
output: {
|
|
494
|
+
schema: { type: 'object', additionalProperties: false, properties: { closed: { type: 'boolean', required: true } } },
|
|
495
|
+
render: (_args, value) => [{ type: 'text', text: value.closed ? 'Closed.' : 'Tab not found.' }],
|
|
496
|
+
},
|
|
497
|
+
timeoutMs,
|
|
498
|
+
isConcurrencySafe: () => false, // mutates the tab list; exclusive within a task
|
|
499
|
+
async execute(args, exec) {
|
|
500
|
+
assertAllowed(state, 'dsh_browser_close_tab', taskKey(exec));
|
|
501
|
+
const browser = ctx.get('browser');
|
|
502
|
+
if (browser === undefined)
|
|
503
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
504
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
505
|
+
const handle = resolveTabHandle(browserSessionHandle(taskKey(exec), session), args.tabId);
|
|
506
|
+
await browser.closeTab(session, tabWireId(handle));
|
|
507
|
+
return { closed: true };
|
|
508
|
+
},
|
|
509
|
+
}));
|
|
510
|
+
tools.push(defineTool({
|
|
511
|
+
name: 'dsh_browser_reset',
|
|
512
|
+
description: 'Close every tab in the shared browser and start fresh with one blank tab.',
|
|
513
|
+
parameters: {},
|
|
514
|
+
output: {
|
|
515
|
+
schema: { type: 'object', additionalProperties: false, properties: { reset: { type: 'boolean', required: true } } },
|
|
516
|
+
render: (_args, value) => [{ type: 'text', text: value.reset ? 'Browser reset.' : 'Failed.' }],
|
|
517
|
+
},
|
|
518
|
+
timeoutMs,
|
|
519
|
+
isConcurrencySafe: () => false, // closes every tab; exclusive within a task
|
|
520
|
+
async execute(_args, exec) {
|
|
521
|
+
assertAllowed(state, 'dsh_browser_reset', taskKey(exec));
|
|
522
|
+
const browser = ctx.get('browser');
|
|
523
|
+
if (browser === undefined)
|
|
524
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
525
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
526
|
+
await browser.reset(session);
|
|
527
|
+
return { reset: true };
|
|
528
|
+
},
|
|
529
|
+
}));
|
|
530
|
+
}
|
|
531
|
+
tools.push(defineTool({
|
|
532
|
+
name: 'dsh_browser_history',
|
|
533
|
+
description: 'List the shared browser session\'s recorded operation history (navigate/execute/click/type), newest last, with per-step success/error. Use to understand what the agent did and to pick a step to replay.',
|
|
534
|
+
parameters: {
|
|
535
|
+
verbose: { type: 'boolean', description: "Include each operation's parameters (default false). They are what you just sent, so they are omitted unless asked for." },
|
|
536
|
+
},
|
|
537
|
+
output: {
|
|
538
|
+
schema: {
|
|
539
|
+
type: 'object',
|
|
540
|
+
additionalProperties: false,
|
|
541
|
+
properties: {
|
|
542
|
+
entries: {
|
|
543
|
+
type: 'array',
|
|
544
|
+
required: true,
|
|
545
|
+
items: {
|
|
546
|
+
type: 'object',
|
|
547
|
+
additionalProperties: false,
|
|
548
|
+
properties: {
|
|
549
|
+
seq: { type: 'number', required: true },
|
|
550
|
+
action: { type: 'string', required: true },
|
|
551
|
+
ok: { type: 'boolean', required: true },
|
|
552
|
+
params: { type: 'object', additionalProperties: true, required: true },
|
|
553
|
+
result: { type: 'string' },
|
|
554
|
+
error: { type: 'string' },
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
render: (args, value) => {
|
|
561
|
+
const entries = value.entries;
|
|
562
|
+
if (entries.length === 0)
|
|
563
|
+
return [{ type: 'text', text: '(no recorded operations yet)' }];
|
|
564
|
+
// The parameters are what the caller itself just sent, so echoing them back is cost
|
|
565
|
+
// without information — measured at 18,162 characters for 200 operations, of which the
|
|
566
|
+
// per-entry params dominated. Only the tail is shown by default: the recent steps are
|
|
567
|
+
// what a caller reasons about, and the count leads so the tail is not mistaken for all.
|
|
568
|
+
const recent = entries.slice(-20);
|
|
569
|
+
const omitted = entries.length - recent.length;
|
|
570
|
+
const lines = recent.map(e => `#${e.seq} ${e.action} ${e.ok ? 'ok' : 'FAIL'}${e.result !== undefined ? ` -> ${e.result}` : ''}${e.error !== undefined ? ` !! ${e.error}` : ''}${args.verbose === true ? ` ${JSON.stringify(e.params)}` : ''}`);
|
|
571
|
+
const header = omitted > 0
|
|
572
|
+
? `${entries.length} operations recorded; showing the last ${recent.length} (${args.verbose === true ? '' : ' (pass verbose: true for parameters)'}):`
|
|
573
|
+
: `${entries.length} operation(s):`;
|
|
574
|
+
return [{ type: 'text', text: `${header}\n${lines.join('\n')}` }];
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
timeoutMs,
|
|
578
|
+
isConcurrencySafe: () => true,
|
|
579
|
+
async execute(_args, exec) {
|
|
580
|
+
const browser = ctx.get('browser');
|
|
581
|
+
if (browser === undefined)
|
|
582
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
583
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
584
|
+
const entries = await browser.history(session);
|
|
585
|
+
const rendered = entries.map(e => {
|
|
586
|
+
const params = JSON.parse(JSON.stringify(e.params));
|
|
587
|
+
// Typed text / set values (possibly passwords) are kept verbatim in
|
|
588
|
+
// the provider's history so replay can re-issue them, but must not be
|
|
589
|
+
// echoed back to the model: mask them in the tool output, preserving
|
|
590
|
+
// the length.
|
|
591
|
+
if (e.action === 'type' && typeof params.text === 'string') {
|
|
592
|
+
params.text = '*'.repeat(Math.min(params.text.length, 64)) + ` (${params.text.length} chars)`;
|
|
593
|
+
}
|
|
594
|
+
if (e.action === 'setValue' && typeof params.value === 'string') {
|
|
595
|
+
params.value = '*'.repeat(Math.min(params.value.length, 64)) + ` (${params.value.length} chars)`;
|
|
596
|
+
}
|
|
597
|
+
// Replay of type/setValue carries the same sensitive fields.
|
|
598
|
+
if (e.action === 'replay' && params.of === 'type' && typeof params.text === 'string') {
|
|
599
|
+
params.text = '*'.repeat(Math.min(params.text.length, 64)) + ` (${params.text.length} chars)`;
|
|
600
|
+
}
|
|
601
|
+
// Execute scripts may embed form tokens / credentials; mask script,
|
|
602
|
+
// args, and result for both direct execute and replay-of-execute.
|
|
603
|
+
const isExecute = e.action === 'execute' || (e.action === 'replay' && params.of === 'execute');
|
|
604
|
+
if (isExecute) {
|
|
605
|
+
if (typeof params.script === 'string') {
|
|
606
|
+
params.script = `/* ${params.script.length} chars redacted */`;
|
|
607
|
+
}
|
|
608
|
+
if (Array.isArray(params.args)) {
|
|
609
|
+
params.args = params.args.map(() => '***');
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
const row = {
|
|
613
|
+
seq: e.seq,
|
|
614
|
+
action: e.action,
|
|
615
|
+
ok: e.ok,
|
|
616
|
+
params,
|
|
617
|
+
};
|
|
618
|
+
if (isExecute && typeof e.result === 'string') {
|
|
619
|
+
row.result = `[${e.result.length} chars redacted]`;
|
|
620
|
+
}
|
|
621
|
+
else if (e.result !== undefined) {
|
|
622
|
+
row.result = e.result;
|
|
623
|
+
}
|
|
624
|
+
if (e.error !== undefined)
|
|
625
|
+
row.error = e.error;
|
|
626
|
+
return row;
|
|
627
|
+
});
|
|
628
|
+
return { entries: rendered };
|
|
629
|
+
},
|
|
630
|
+
}));
|
|
631
|
+
tools.push(defineTool({
|
|
632
|
+
name: 'dsh_browser_visited',
|
|
633
|
+
description: 'List pages the shared browser has visited, newest first, from the PERSISTENT browsing history: it survives closing the browser and restarting DSH, so it is how you (or the human) find a page again afterwards. Reopen one by passing its url to dsh_browser_open. Not to be confused with dsh_browser_history, which is only the current session\'s operation log (navigate/click/type) and disappears with the session.',
|
|
634
|
+
parameters: {
|
|
635
|
+
limit: { type: 'number', description: 'Maximum entries to return (default 30, capped at 200).' },
|
|
636
|
+
domain: { type: 'string', description: 'Only visits whose hostname contains this text (case-insensitive).' },
|
|
637
|
+
query: { type: 'string', description: 'Only visits whose URL or title contains this text (case-insensitive).' },
|
|
638
|
+
session: { type: 'string', description: 'Only visits recorded by this task/session label — use it to separate your own pages from another session\'s or the human\'s.' },
|
|
639
|
+
},
|
|
640
|
+
output: {
|
|
641
|
+
schema: {
|
|
642
|
+
type: 'object',
|
|
643
|
+
additionalProperties: false,
|
|
644
|
+
properties: {
|
|
645
|
+
count: { type: 'number', required: true },
|
|
646
|
+
entries: {
|
|
647
|
+
type: 'array',
|
|
648
|
+
required: true,
|
|
649
|
+
items: {
|
|
650
|
+
type: 'object',
|
|
651
|
+
additionalProperties: false,
|
|
652
|
+
properties: {
|
|
653
|
+
at: { type: 'number', required: true },
|
|
654
|
+
url: { type: 'string', required: true },
|
|
655
|
+
title: { type: 'string' },
|
|
656
|
+
session: { type: 'string' },
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
render: (_args, value) => {
|
|
663
|
+
const entries = value.entries;
|
|
664
|
+
let lastSession;
|
|
665
|
+
if (entries.length === 0) {
|
|
666
|
+
return [{ type: 'text', text: '(no recorded visits — nothing has been browsed yet, or history recording is turned off in settings)' }];
|
|
667
|
+
}
|
|
668
|
+
return [{
|
|
669
|
+
type: 'text',
|
|
670
|
+
text: entries.map(entry => {
|
|
671
|
+
const when = new Date(entry.at).toISOString().replace('T', ' ').slice(0, 16);
|
|
672
|
+
const title = entry.title !== undefined ? `${entry.title} — ` : '';
|
|
673
|
+
const tag = entry.session !== undefined && entry.session !== lastSession
|
|
674
|
+
? ` [session ${entry.session.slice(0, 8)}]`
|
|
675
|
+
: '';
|
|
676
|
+
lastSession = entry.session;
|
|
677
|
+
return `${when} ${title}${entry.url}${tag}`;
|
|
678
|
+
}).join('\n'),
|
|
679
|
+
}];
|
|
680
|
+
},
|
|
681
|
+
},
|
|
682
|
+
timeoutMs,
|
|
683
|
+
isConcurrencySafe: () => true,
|
|
684
|
+
async execute(args, _exec) {
|
|
685
|
+
const browser = ctx.get('browser');
|
|
686
|
+
if (browser === undefined)
|
|
687
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
688
|
+
const rawLimit = typeof args.limit === 'number' && Number.isFinite(args.limit) ? args.limit : 30;
|
|
689
|
+
const limit = Math.max(1, Math.min(200, Math.floor(rawLimit)));
|
|
690
|
+
const domain = typeof args.domain === 'string' && args.domain.trim() !== '' ? args.domain.trim() : undefined;
|
|
691
|
+
const query = typeof args.query === 'string' && args.query.trim() !== '' ? args.query.trim() : undefined;
|
|
692
|
+
const session = typeof args.session === 'string' && args.session.trim() !== '' ? args.session.trim() : undefined;
|
|
693
|
+
const entries = browser.visited({
|
|
694
|
+
limit,
|
|
695
|
+
...domain !== undefined ? { domain } : {},
|
|
696
|
+
...query !== undefined ? { query } : {},
|
|
697
|
+
...session !== undefined ? { session } : {},
|
|
698
|
+
});
|
|
699
|
+
return {
|
|
700
|
+
count: entries.length,
|
|
701
|
+
entries: entries.map(entry => ({
|
|
702
|
+
at: entry.at,
|
|
703
|
+
url: entry.url,
|
|
704
|
+
...entry.title !== undefined ? { title: entry.title } : {},
|
|
705
|
+
...entry.session !== undefined ? { session: entry.session } : {},
|
|
706
|
+
})),
|
|
707
|
+
};
|
|
708
|
+
},
|
|
709
|
+
}));
|
|
710
|
+
tools.push(defineTool({
|
|
711
|
+
name: 'dsh_browser_replay',
|
|
712
|
+
description: 'Replay one recorded browser operation by its history sequence number (from dsh_browser_history). Navigate/click/type are re-issued against the current page; execute re-runs its script. The replayed step is appended to history as a new entry.',
|
|
713
|
+
parameters: {
|
|
714
|
+
seq: { type: 'number', required: true, description: 'The history entry sequence number to replay.' },
|
|
715
|
+
},
|
|
716
|
+
output: {
|
|
717
|
+
schema: { type: 'object', additionalProperties: false, properties: { replayed: { type: 'boolean', required: true } } },
|
|
718
|
+
render: (_args, value) => [{ type: 'text', text: value.replayed ? 'Replayed.' : 'Replay failed.' }],
|
|
719
|
+
},
|
|
720
|
+
timeoutMs,
|
|
721
|
+
isConcurrencySafe: () => false,
|
|
722
|
+
async execute(args, exec) {
|
|
723
|
+
assertAllowed(state, 'dsh_browser_replay', taskKey(exec));
|
|
724
|
+
const browser = ctx.get('browser');
|
|
725
|
+
if (browser === undefined)
|
|
726
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
727
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
728
|
+
await browser.replay(session, args.seq);
|
|
729
|
+
return { replayed: true };
|
|
730
|
+
},
|
|
731
|
+
}));
|
|
732
|
+
tools.push(defineTool({
|
|
733
|
+
name: 'dsh_browser_session',
|
|
734
|
+
description: 'Show THIS task\'s browser session: its id and open tabs. Each task (DSH session) has its own browser session, so this reflects what your task drives. The window is shared with the human and other tasks, but tab sets and history are isolated per task.',
|
|
735
|
+
parameters: {},
|
|
736
|
+
output: {
|
|
737
|
+
schema: {
|
|
738
|
+
type: 'object',
|
|
739
|
+
additionalProperties: false,
|
|
740
|
+
properties: {
|
|
741
|
+
session: { type: 'string', required: true },
|
|
742
|
+
tabs: {
|
|
743
|
+
type: 'array',
|
|
744
|
+
required: true,
|
|
745
|
+
items: {
|
|
746
|
+
type: 'object',
|
|
747
|
+
additionalProperties: false,
|
|
748
|
+
properties: {
|
|
749
|
+
id: { type: 'string', required: true },
|
|
750
|
+
url: { type: 'string', required: true },
|
|
751
|
+
active: { type: 'boolean', required: true },
|
|
752
|
+
},
|
|
753
|
+
},
|
|
754
|
+
},
|
|
755
|
+
},
|
|
756
|
+
},
|
|
757
|
+
render: (_args, value) => [{
|
|
758
|
+
type: 'text',
|
|
759
|
+
text: `Session ${value.session}\n${value.tabs.map(t => `${t.active ? '*' : ' '} ${t.id} ${t.url}`).join('\n')}`,
|
|
760
|
+
}],
|
|
761
|
+
},
|
|
762
|
+
timeoutMs,
|
|
763
|
+
isConcurrencySafe: () => true,
|
|
764
|
+
async execute(_args, exec) {
|
|
765
|
+
const browser = ctx.get('browser');
|
|
766
|
+
if (browser === undefined)
|
|
767
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
768
|
+
const session = await ensureSession(browser, state, taskKey(exec), agentOf(exec));
|
|
769
|
+
const tabs = await browser.listTabs(session);
|
|
770
|
+
const scope = browserSessionHandle(taskKey(exec), session);
|
|
771
|
+
return { session: sessionWireId(scope), tabs: scopedTabs(scope, tabs).map(t => ({ id: t.id, url: t.url, active: t.active })) };
|
|
772
|
+
},
|
|
773
|
+
}));
|
|
774
|
+
tools.push(defineTool({
|
|
775
|
+
name: 'dsh_browser_reset_session',
|
|
776
|
+
description: 'Reset THIS task\'s browser session: close it entirely so the next dsh_browser_* call starts a fresh session with one blank tab. Other tasks\' sessions are untouched. Use when a session is in a bad state or you want a clean slate.',
|
|
777
|
+
parameters: {},
|
|
778
|
+
output: {
|
|
779
|
+
schema: { type: 'object', additionalProperties: false, properties: { reset: { type: 'boolean', required: true } } },
|
|
780
|
+
render: (_args, value) => [{ type: 'text', text: value.reset ? 'This task\'s browser session was closed; the next call starts fresh.' : 'Failed.' }],
|
|
781
|
+
},
|
|
782
|
+
timeoutMs,
|
|
783
|
+
isConcurrencySafe: () => false, // closes the whole session; exclusive within a task
|
|
784
|
+
async execute(_args, exec) {
|
|
785
|
+
assertAllowed(state, 'dsh_browser_reset_session', taskKey(exec));
|
|
786
|
+
const browser = ctx.get('browser');
|
|
787
|
+
if (browser === undefined)
|
|
788
|
+
throw new Error('tool-browser: browser service unavailable');
|
|
789
|
+
const key = taskKey(exec);
|
|
790
|
+
await state.pendingPanelOpens.get(key);
|
|
791
|
+
state.panelUrlByTask.delete(key);
|
|
792
|
+
const session = state.sessionsByTask.get(key);
|
|
793
|
+
if (session !== undefined) {
|
|
794
|
+
try {
|
|
795
|
+
await browser.close(session);
|
|
796
|
+
}
|
|
797
|
+
finally {
|
|
798
|
+
// Always forget the mapping so the next call opens a fresh session,
|
|
799
|
+
// even if the provider close threw (the session is half-closed).
|
|
800
|
+
state.sessionsByTask.delete(key);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return { reset: true };
|
|
804
|
+
},
|
|
805
|
+
}));
|
|
806
|
+
return tools;
|
|
807
|
+
}
|