@nordhavnhq/runner 0.0.0-stage → 0.95.0
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/bin/cliclick +0 -0
- package/dist/brand.d.ts +5 -0
- package/dist/brand.js +18 -0
- package/dist/cli/agent.d.ts +9 -0
- package/dist/cli/agent.js +80 -0
- package/dist/cli/folder.d.ts +2 -0
- package/dist/cli/folder.js +103 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.js +67 -0
- package/dist/cli/lifecycle.d.ts +3 -0
- package/dist/cli/lifecycle.js +149 -0
- package/dist/cli/link.d.ts +42 -0
- package/dist/cli/link.js +314 -0
- package/dist/cli/logs.d.ts +2 -0
- package/dist/cli/logs.js +147 -0
- package/dist/cli/prompts.d.ts +7 -0
- package/dist/cli/prompts.js +13 -0
- package/dist/cli/ps.d.ts +2 -0
- package/dist/cli/ps.js +81 -0
- package/dist/cli/relay.d.ts +4 -0
- package/dist/cli/relay.js +29 -0
- package/dist/cli/update.d.ts +6 -0
- package/dist/cli/update.js +131 -0
- package/dist/config.d.ts +166 -0
- package/dist/config.js +383 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +145 -0
- package/dist/legacy-env.d.ts +4 -0
- package/dist/legacy-env.js +32 -0
- package/dist/paths.d.ts +37 -0
- package/dist/paths.js +92 -0
- package/dist/runtime/daemon.d.ts +57 -0
- package/dist/runtime/daemon.js +159 -0
- package/dist/runtime/dev-start.d.ts +31 -0
- package/dist/runtime/dev-start.js +110 -0
- package/dist/runtime/file-claims.d.ts +58 -0
- package/dist/runtime/file-claims.js +174 -0
- package/dist/runtime/fs-browse.d.ts +18 -0
- package/dist/runtime/fs-browse.js +104 -0
- package/dist/runtime/fs-checkout.d.ts +154 -0
- package/dist/runtime/fs-checkout.js +1049 -0
- package/dist/runtime/fs-git-index.d.ts +22 -0
- package/dist/runtime/fs-git-index.js +133 -0
- package/dist/runtime/fs-git.d.ts +16 -0
- package/dist/runtime/fs-git.js +424 -0
- package/dist/runtime/git-relay.d.ts +46 -0
- package/dist/runtime/git-relay.js +259 -0
- package/dist/runtime/git-unpushed.d.ts +36 -0
- package/dist/runtime/git-unpushed.js +93 -0
- package/dist/runtime/node-version.d.ts +12 -0
- package/dist/runtime/node-version.js +39 -0
- package/dist/runtime/preview-tunnel.d.ts +16 -0
- package/dist/runtime/preview-tunnel.js +135 -0
- package/dist/runtime/processes.d.ts +61 -0
- package/dist/runtime/processes.js +408 -0
- package/dist/runtime/project-node-download.d.ts +17 -0
- package/dist/runtime/project-node-download.js +137 -0
- package/dist/runtime/project-node.d.ts +65 -0
- package/dist/runtime/project-node.js +223 -0
- package/dist/runtime/reap-scratch.d.ts +22 -0
- package/dist/runtime/reap-scratch.js +112 -0
- package/dist/runtime/spill-tool-output.d.ts +14 -0
- package/dist/runtime/spill-tool-output.js +84 -0
- package/dist/runtime/up.d.ts +6 -0
- package/dist/runtime/up.js +1325 -0
- package/dist/tools/_coerce.d.ts +2 -0
- package/dist/tools/_coerce.js +26 -0
- package/dist/tools/_commit-scope.d.ts +14 -0
- package/dist/tools/_commit-scope.js +70 -0
- package/dist/tools/_jail.d.ts +68 -0
- package/dist/tools/_jail.js +209 -0
- package/dist/tools/_output.d.ts +24 -0
- package/dist/tools/_output.js +48 -0
- package/dist/tools/_ripgrep.d.ts +46 -0
- package/dist/tools/_ripgrep.js +148 -0
- package/dist/tools/_run-worktree.d.ts +10 -0
- package/dist/tools/_run-worktree.js +27 -0
- package/dist/tools/_shell-words.d.ts +15 -0
- package/dist/tools/_shell-words.js +43 -0
- package/dist/tools/_sonar/astro.d.ts +6 -0
- package/dist/tools/_sonar/astro.js +45 -0
- package/dist/tools/_sonar/blade.d.ts +3 -0
- package/dist/tools/_sonar/blade.js +53 -0
- package/dist/tools/_sonar/build.d.ts +44 -0
- package/dist/tools/_sonar/build.js +147 -0
- package/dist/tools/_sonar/changed.d.ts +21 -0
- package/dist/tools/_sonar/changed.js +230 -0
- package/dist/tools/_sonar/diagnose/delta.d.ts +27 -0
- package/dist/tools/_sonar/diagnose/delta.js +64 -0
- package/dist/tools/_sonar/diagnose/detect.d.ts +39 -0
- package/dist/tools/_sonar/diagnose/detect.js +117 -0
- package/dist/tools/_sonar/diagnose/index.d.ts +13 -0
- package/dist/tools/_sonar/diagnose/index.js +217 -0
- package/dist/tools/_sonar/diagnose/lint-worker.d.ts +1 -0
- package/dist/tools/_sonar/diagnose/lint-worker.js +48 -0
- package/dist/tools/_sonar/diagnose/pool.d.ts +22 -0
- package/dist/tools/_sonar/diagnose/pool.js +149 -0
- package/dist/tools/_sonar/diagnose/rules.d.ts +23 -0
- package/dist/tools/_sonar/diagnose/rules.js +131 -0
- package/dist/tools/_sonar/diagnose/types-worker.d.ts +1 -0
- package/dist/tools/_sonar/diagnose/types-worker.js +183 -0
- package/dist/tools/_sonar/files.d.ts +14 -0
- package/dist/tools/_sonar/files.js +121 -0
- package/dist/tools/_sonar/graph.d.ts +34 -0
- package/dist/tools/_sonar/graph.js +164 -0
- package/dist/tools/_sonar/hints.d.ts +116 -0
- package/dist/tools/_sonar/hints.js +545 -0
- package/dist/tools/_sonar/imports.d.ts +38 -0
- package/dist/tools/_sonar/imports.js +275 -0
- package/dist/tools/_sonar/index.d.ts +79 -0
- package/dist/tools/_sonar/index.js +462 -0
- package/dist/tools/_sonar/keys.d.ts +5 -0
- package/dist/tools/_sonar/keys.js +248 -0
- package/dist/tools/_sonar/laravel-routes.d.ts +15 -0
- package/dist/tools/_sonar/laravel-routes.js +263 -0
- package/dist/tools/_sonar/laravel.d.ts +64 -0
- package/dist/tools/_sonar/laravel.js +326 -0
- package/dist/tools/_sonar/location.d.ts +33 -0
- package/dist/tools/_sonar/location.js +137 -0
- package/dist/tools/_sonar/map.d.ts +43 -0
- package/dist/tools/_sonar/map.js +212 -0
- package/dist/tools/_sonar/parse.d.ts +3 -0
- package/dist/tools/_sonar/parse.js +76 -0
- package/dist/tools/_sonar/prewarm.d.ts +9 -0
- package/dist/tools/_sonar/prewarm.js +96 -0
- package/dist/tools/_sonar/prisma.d.ts +9 -0
- package/dist/tools/_sonar/prisma.js +51 -0
- package/dist/tools/_sonar/refs.d.ts +7 -0
- package/dist/tools/_sonar/refs.js +273 -0
- package/dist/tools/_sonar/render.d.ts +66 -0
- package/dist/tools/_sonar/render.js +498 -0
- package/dist/tools/_sonar/resolve.d.ts +63 -0
- package/dist/tools/_sonar/resolve.js +402 -0
- package/dist/tools/_sonar/roots.d.ts +4 -0
- package/dist/tools/_sonar/roots.js +42 -0
- package/dist/tools/_sonar/routes.d.ts +5 -0
- package/dist/tools/_sonar/routes.js +247 -0
- package/dist/tools/_sonar/serve.d.ts +12 -0
- package/dist/tools/_sonar/serve.js +104 -0
- package/dist/tools/_sonar/suggest.d.ts +23 -0
- package/dist/tools/_sonar/suggest.js +114 -0
- package/dist/tools/_sonar/tests.d.ts +21 -0
- package/dist/tools/_sonar/tests.js +134 -0
- package/dist/tools/_sonar/tsconfig.d.ts +34 -0
- package/dist/tools/_sonar/tsconfig.js +188 -0
- package/dist/tools/_sonar/types.d.ts +81 -0
- package/dist/tools/_sonar/types.js +6 -0
- package/dist/tools/_symbols.d.ts +27 -0
- package/dist/tools/_symbols.js +461 -0
- package/dist/tools/_test-report.d.ts +47 -0
- package/dist/tools/_test-report.js +203 -0
- package/dist/tools/_touched.d.ts +44 -0
- package/dist/tools/_touched.js +195 -0
- package/dist/tools/_upload.d.ts +26 -0
- package/dist/tools/_upload.js +132 -0
- package/dist/tools/_worktree-setup.d.ts +29 -0
- package/dist/tools/_worktree-setup.js +204 -0
- package/dist/tools/browser.d.ts +2 -0
- package/dist/tools/browser.js +8 -0
- package/dist/tools/commit-guard.d.ts +44 -0
- package/dist/tools/commit-guard.js +165 -0
- package/dist/tools/computer.d.ts +13 -0
- package/dist/tools/computer.js +952 -0
- package/dist/tools/console.d.ts +44 -0
- package/dist/tools/console.js +739 -0
- package/dist/tools/database.d.ts +28 -0
- package/dist/tools/database.js +152 -0
- package/dist/tools/filesystem.d.ts +36 -0
- package/dist/tools/filesystem.js +506 -0
- package/dist/tools/git-tag.d.ts +10 -0
- package/dist/tools/git-tag.js +164 -0
- package/dist/tools/git.d.ts +52 -0
- package/dist/tools/git.js +1272 -0
- package/dist/tools/http.d.ts +12 -0
- package/dist/tools/http.js +119 -0
- package/dist/tools/image.d.ts +8 -0
- package/dist/tools/image.js +551 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.js +58 -0
- package/dist/tools/outline.d.ts +20 -0
- package/dist/tools/outline.js +98 -0
- package/dist/tools/search.d.ts +17 -0
- package/dist/tools/search.js +391 -0
- package/dist/tools/sonar.d.ts +17 -0
- package/dist/tools/sonar.js +231 -0
- package/dist/tools/testing.d.ts +36 -0
- package/dist/tools/testing.js +273 -0
- package/dist/tools/upload.d.ts +8 -0
- package/dist/tools/upload.js +106 -0
- package/dist/tools/webcam.d.ts +28 -0
- package/dist/tools/webcam.js +967 -0
- package/dist/update/install-kind.d.ts +35 -0
- package/dist/update/install-kind.js +109 -0
- package/dist/update/install.d.ts +32 -0
- package/dist/update/install.js +187 -0
- package/dist/update/manifest.d.ts +18 -0
- package/dist/update/manifest.js +73 -0
- package/dist/update/peers.d.ts +18 -0
- package/dist/update/peers.js +43 -0
- package/dist/update/policy.d.ts +20 -0
- package/dist/update/policy.js +49 -0
- package/dist/update/supervisor.d.ts +25 -0
- package/dist/update/supervisor.js +83 -0
- package/dist/update/updater.d.ts +44 -0
- package/dist/update/updater.js +116 -0
- package/dist/utils/format.d.ts +50 -0
- package/dist/utils/format.js +190 -0
- package/dist/version.d.ts +17 -0
- package/dist/version.js +63 -0
- package/dist/version.json +5 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/act-tools.d.ts +15 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/act-tools.js +541 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/cast-hub.d.ts +25 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/cast-hub.js +137 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/guard.d.ts +21 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/guard.js +104 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/host-protocol.d.ts +47 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/host-protocol.js +41 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/host.d.ts +18 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/host.js +15 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/index.d.ts +13 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/index.js +28 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live-input.d.ts +74 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live-input.js +93 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live-open.d.ts +4 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live-open.js +57 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live.d.ts +148 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live.js +179 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/local-live.d.ts +31 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/local-live.js +262 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/marks.d.ts +36 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/marks.js +173 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/page-events.d.ts +27 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/page-events.js +82 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/page-tools.d.ts +13 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/page-tools.js +526 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/params.d.ts +12 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/params.js +32 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/pick.d.ts +24 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/pick.js +76 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/session.d.ts +225 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/session.js +507 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/shots.d.ts +11 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/shots.js +103 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/show.d.ts +10 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/show.js +190 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/target.d.ts +37 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/target.js +82 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/tour.d.ts +19 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/tour.js +178 -0
- package/node_modules/@nordhavnhq/runner-browser/package.json +18 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/config.d.ts +96 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/config.js +25 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/connection.d.ts +276 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/connection.js +507 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/constants.d.ts +48 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/constants.js +95 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.d.ts +94 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.js +219 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.d.ts +136 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.js +214 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/fs.d.ts +735 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/fs.js +40 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.d.ts +362 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.js +703 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/own-files.d.ts +105 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/own-files.js +202 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.d.ts +204 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.js +497 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.d.ts +45 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.js +176 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/processes.d.ts +74 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/processes.js +72 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/release-tag.d.ts +59 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/release-tag.js +117 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/replay.d.ts +62 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/replay.js +84 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.d.ts +27 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.js +80 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.d.ts +22 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.js +22 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.d.ts +595 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.js +85 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/index.d.ts +43 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/index.js +50 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/inference.d.ts +135 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/inference.js +945 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/mcp.d.ts +67 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/mcp.js +47 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/platform.d.ts +21 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/platform.js +25 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.d.ts +39 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.js +67 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/background-commands.d.ts +61 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/background-commands.js +58 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/chat-run-ends.d.ts +23 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/chat-run-ends.js +42 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/duration.d.ts +6 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/duration.js +12 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/events.d.ts +150 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/events.js +36 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.d.ts +14 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.js +49 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-chat.d.ts +109 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-chat.js +894 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-task.d.ts +73 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-task.js +765 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.d.ts +246 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.js +621 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/messages.d.ts +88 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/messages.js +188 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/pending-steers.d.ts +15 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/pending-steers.js +10 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/phased-loop.d.ts +16 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/phased-loop.js +97 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/project-instructions.d.ts +22 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/project-instructions.js +47 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.d.ts +26 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.js +48 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/scratch-prompt.d.ts +8 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/scratch-prompt.js +19 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/side-question.d.ts +76 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/side-question.js +155 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.d.ts +43 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.js +37 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.d.ts +49 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.js +104 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/write-scope.d.ts +16 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/write-scope.js +6 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.d.ts +86 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.js +141 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/index.d.ts +179 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/index.js +35 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.d.ts +21 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.js +179 -0
- package/node_modules/@nordhavnhq/runner-runtime/package.json +18 -0
- package/package.json +33 -4
- package/README.md +0 -3
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { resolveForRead } from './host.js';
|
|
3
|
+
import { NO_SESSION, activePage, currentSession, emit } from './session.js';
|
|
4
|
+
import { attachScreenshot } from './shots.js';
|
|
5
|
+
import { describeTarget, enterSubmits, resolveAttachedTarget, staleHint } from './target.js';
|
|
6
|
+
import { checkGate, checkScriptGate } from './guard.js';
|
|
7
|
+
import { errorLine, readEnum, readStringList } from './params.js';
|
|
8
|
+
import { liveUrlOf } from './show.js';
|
|
9
|
+
import { takeEvents } from './page-events.js';
|
|
10
|
+
const EVAL_MAX = 10_000;
|
|
11
|
+
const shotProps = {
|
|
12
|
+
screenshot: { type: 'boolean', description: 'Return an inline screenshot afterwards. Default: true.' },
|
|
13
|
+
full_page: { type: 'boolean', description: 'Full-page screenshot instead of the viewport. Default: false.' },
|
|
14
|
+
};
|
|
15
|
+
const targetProps = {
|
|
16
|
+
ref: { type: 'string', description: 'Element ref from the latest runner_browser_snapshot (e.g. e12). Preferred.' },
|
|
17
|
+
selector: { type: 'string', description: 'Playwright selector instead of a ref: CSS, text=, role=..., :has-text().' },
|
|
18
|
+
};
|
|
19
|
+
const confirmedProp = {
|
|
20
|
+
confirmed: {
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
description: 'Only after the person explicitly said yes in this chat to exactly this action (it publishes, pays or can start spending). Never in a task run.',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
/** The active tab when an action started, to tell when it opened another. */
|
|
26
|
+
const tabAtStart = new WeakMap();
|
|
27
|
+
/** The session for an agent action: the agent takes the wheel back. */
|
|
28
|
+
function sessionForAction(context) {
|
|
29
|
+
const session = currentSession(context);
|
|
30
|
+
if (session)
|
|
31
|
+
tabAtStart.set(session, activePage(session));
|
|
32
|
+
if (session && session.handoff) {
|
|
33
|
+
session.handoff = null;
|
|
34
|
+
emit({ type: 'changed', session });
|
|
35
|
+
}
|
|
36
|
+
return session;
|
|
37
|
+
}
|
|
38
|
+
async function settle(page) {
|
|
39
|
+
try {
|
|
40
|
+
await page.waitForLoadState('domcontentloaded', { timeout: 5_000 });
|
|
41
|
+
}
|
|
42
|
+
catch { }
|
|
43
|
+
}
|
|
44
|
+
async function finish(session, params, context, hint, extra = {}) {
|
|
45
|
+
const page = activePage(session);
|
|
46
|
+
await settle(page);
|
|
47
|
+
emit({ type: 'changed', session });
|
|
48
|
+
const base = { success: true, url: page.url(), title: await page.title().catch(() => ''), tab: session.active, ...extra };
|
|
49
|
+
const before = tabAtStart.get(session);
|
|
50
|
+
if (before && before !== page) {
|
|
51
|
+
base.tabChange = session.pages.includes(before)
|
|
52
|
+
? `The action opened tab ${session.active}, which is the active tab now (runner_browser_tabs to switch back).`
|
|
53
|
+
: `The tab closed; tab ${session.active} is the active tab now.`;
|
|
54
|
+
}
|
|
55
|
+
Object.assign(base, await takeEvents(session));
|
|
56
|
+
if (params.screenshot === false)
|
|
57
|
+
return JSON.stringify(base);
|
|
58
|
+
return JSON.stringify(await attachScreenshot(page, params, context, base, hint));
|
|
59
|
+
}
|
|
60
|
+
// ─── click ──────────────────────────────────────────────────────────────────
|
|
61
|
+
const clickDefinition = {
|
|
62
|
+
name: 'runner_browser_click',
|
|
63
|
+
description: 'Click (or hover, or double-click) an element by ref or selector, or a point x,y in the viewport. Returns an inline screenshot of the result by default. ' +
|
|
64
|
+
'Clicks that publish, pay or can start spending are blocked until the person confirmed (see `confirmed`).',
|
|
65
|
+
parameters: {
|
|
66
|
+
type: 'object',
|
|
67
|
+
properties: {
|
|
68
|
+
...targetProps,
|
|
69
|
+
x: { type: 'number', description: 'Viewport x in CSS px (canvas, maps), with y, instead of ref/selector.' },
|
|
70
|
+
y: { type: 'number', description: 'Viewport y in CSS px.' },
|
|
71
|
+
button: { type: 'string', enum: ['left', 'right', 'middle'], description: 'Default: left.' },
|
|
72
|
+
double: { type: 'boolean', description: 'Double-click. Default: false.' },
|
|
73
|
+
hover: { type: 'boolean', description: 'Only hover (menus, tooltips), no click. Default: false.' },
|
|
74
|
+
...confirmedProp,
|
|
75
|
+
...shotProps,
|
|
76
|
+
},
|
|
77
|
+
required: [],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
const MOUSE_BUTTONS = ['left', 'right', 'middle'];
|
|
81
|
+
/** A viewport point to click, only when no ref/selector is given. */
|
|
82
|
+
function readPoint(params) {
|
|
83
|
+
if (typeof params.x !== 'number' || typeof params.y !== 'number')
|
|
84
|
+
return null;
|
|
85
|
+
if (params.ref || params.selector)
|
|
86
|
+
return null;
|
|
87
|
+
return { x: params.x, y: params.y };
|
|
88
|
+
}
|
|
89
|
+
/** The label of the clickable element under a point: input for the gate. */
|
|
90
|
+
async function labelAtPoint(page, x, y) {
|
|
91
|
+
return page.evaluate(([px, py]) => {
|
|
92
|
+
const el = document.elementFromPoint(px, py);
|
|
93
|
+
const btn = (el?.closest('button, a, [role=button], input[type=submit]') ?? el);
|
|
94
|
+
return String(btn?.getAttribute('aria-label') || btn?.innerText || btn?.value || '').trim().slice(0, 200);
|
|
95
|
+
}, [x, y]).catch(() => '');
|
|
96
|
+
}
|
|
97
|
+
async function clickAtPoint(call, x, y) {
|
|
98
|
+
const { session, page, options, params, context } = call;
|
|
99
|
+
if (!options.hover) {
|
|
100
|
+
const blocked = checkGate({ url: page.url(), label: await labelAtPoint(page, x, y) }, params.confirmed, context);
|
|
101
|
+
if (blocked)
|
|
102
|
+
return blocked;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
if (options.hover)
|
|
106
|
+
await page.mouse.move(x, y);
|
|
107
|
+
else
|
|
108
|
+
await page.mouse.click(x, y, { button: options.button, clickCount: options.clickCount });
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
return `Error: Could not click at ${x},${y}: ${errorLine(err)}`;
|
|
112
|
+
}
|
|
113
|
+
return finish(session, params, context, 'after-click');
|
|
114
|
+
}
|
|
115
|
+
async function clickTarget(call) {
|
|
116
|
+
const { session, page, options, params, context } = call;
|
|
117
|
+
const target = await resolveAttachedTarget(page, params);
|
|
118
|
+
if (!target || 'error' in target)
|
|
119
|
+
return target?.error ?? 'Error: No target.';
|
|
120
|
+
if (options.hover) {
|
|
121
|
+
try {
|
|
122
|
+
await target.locator.hover();
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
return `Error: Could not hover ${target.name}: ${errorLine(err)}`;
|
|
126
|
+
}
|
|
127
|
+
return finish(session, params, context, 'after-hover');
|
|
128
|
+
}
|
|
129
|
+
const blocked = checkGate({ url: page.url(), ...(await describeTarget(target.locator)) }, params.confirmed, context);
|
|
130
|
+
if (blocked)
|
|
131
|
+
return blocked;
|
|
132
|
+
try {
|
|
133
|
+
if (options.clickCount === 2)
|
|
134
|
+
await target.locator.dblclick({ button: options.button });
|
|
135
|
+
else
|
|
136
|
+
await target.locator.click({ button: options.button });
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
return `Error: Could not click ${target.name}: ${errorLine(err)}.${staleHint(target)}`;
|
|
140
|
+
}
|
|
141
|
+
return finish(session, params, context, 'after-click');
|
|
142
|
+
}
|
|
143
|
+
const executeClick = async (params, context) => {
|
|
144
|
+
const session = sessionForAction(context);
|
|
145
|
+
if (!session)
|
|
146
|
+
return NO_SESSION;
|
|
147
|
+
const options = {
|
|
148
|
+
button: readEnum(params.button, MOUSE_BUTTONS, 'left'),
|
|
149
|
+
clickCount: params.double === true ? 2 : 1,
|
|
150
|
+
hover: params.hover === true,
|
|
151
|
+
};
|
|
152
|
+
const call = { session, page: activePage(session), options, params, context };
|
|
153
|
+
const point = readPoint(params);
|
|
154
|
+
return point ? clickAtPoint(call, point.x, point.y) : clickTarget(call);
|
|
155
|
+
};
|
|
156
|
+
// ─── type ───────────────────────────────────────────────────────────────────
|
|
157
|
+
const typeDefinition = {
|
|
158
|
+
name: 'runner_browser_type',
|
|
159
|
+
description: 'Type text into an input, textarea or contenteditable (ref or selector). Replaces the value unless append:true. Optionally press Enter afterwards (submit).',
|
|
160
|
+
parameters: {
|
|
161
|
+
type: 'object',
|
|
162
|
+
properties: {
|
|
163
|
+
...targetProps,
|
|
164
|
+
text: { type: 'string', description: 'The text to enter.' },
|
|
165
|
+
submit: { type: 'boolean', description: 'Press Enter afterwards. Default: false.' },
|
|
166
|
+
append: { type: 'boolean', description: 'Keep the current value and type after it. Default: false.' },
|
|
167
|
+
slowly: { type: 'boolean', description: 'Type key by key (fields that react per key: autocomplete, masks). Default: false.' },
|
|
168
|
+
...confirmedProp,
|
|
169
|
+
...shotProps,
|
|
170
|
+
},
|
|
171
|
+
required: ['text'],
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
const executeType = async (params, context) => {
|
|
175
|
+
const session = sessionForAction(context);
|
|
176
|
+
if (!session)
|
|
177
|
+
return NO_SESSION;
|
|
178
|
+
const page = activePage(session);
|
|
179
|
+
const target = await resolveAttachedTarget(page, params);
|
|
180
|
+
if (!target || 'error' in target)
|
|
181
|
+
return target?.error ?? 'Error: No target.';
|
|
182
|
+
const text = String(params.text ?? '');
|
|
183
|
+
if (params.submit === true) {
|
|
184
|
+
const blocked = checkGate({ url: page.url(), ...(await enterSubmits(target.locator)) }, params.confirmed, context);
|
|
185
|
+
if (blocked)
|
|
186
|
+
return blocked;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
await enterText(target.locator, text, params);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
return `Error: Could not type into ${target.name}: ${errorLine(err)}`;
|
|
193
|
+
}
|
|
194
|
+
return finish(session, params, context, 'after-type');
|
|
195
|
+
};
|
|
196
|
+
/** Fill (or append to) a field, key by key when asked, then submit when asked. */
|
|
197
|
+
async function enterText(locator, text, params) {
|
|
198
|
+
const slowly = params.slowly === true;
|
|
199
|
+
const append = params.append === true;
|
|
200
|
+
if (slowly || append) {
|
|
201
|
+
if (append)
|
|
202
|
+
await caretToEnd(locator);
|
|
203
|
+
else
|
|
204
|
+
await locator.fill('');
|
|
205
|
+
await locator.pressSequentially(text, { delay: slowly ? 40 : 0 });
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
await locator.fill(text);
|
|
209
|
+
}
|
|
210
|
+
if (params.submit === true)
|
|
211
|
+
await locator.press('Enter');
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Focus the field with the caret after its text. Typing into a field that was
|
|
215
|
+
* not focused yet puts the caret at the start, so append would prepend.
|
|
216
|
+
*/
|
|
217
|
+
async function caretToEnd(locator) {
|
|
218
|
+
const placed = await locator.evaluate((el) => {
|
|
219
|
+
el.focus();
|
|
220
|
+
const field = el;
|
|
221
|
+
if (typeof field.value === 'string' && typeof field.setSelectionRange === 'function') {
|
|
222
|
+
// Inputs like email and number have no selection API: End does it there.
|
|
223
|
+
try {
|
|
224
|
+
field.setSelectionRange(field.value.length, field.value.length);
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const range = document.createRange();
|
|
232
|
+
range.selectNodeContents(el);
|
|
233
|
+
range.collapse(false);
|
|
234
|
+
const selection = window.getSelection();
|
|
235
|
+
selection?.removeAllRanges();
|
|
236
|
+
selection?.addRange(range);
|
|
237
|
+
return true;
|
|
238
|
+
});
|
|
239
|
+
if (!placed)
|
|
240
|
+
await locator.press('End');
|
|
241
|
+
}
|
|
242
|
+
// ─── press ──────────────────────────────────────────────────────────────────
|
|
243
|
+
const pressDefinition = {
|
|
244
|
+
name: 'runner_browser_press',
|
|
245
|
+
description: 'Press a key or chord ("Enter", "Escape", "Tab", "ArrowDown", "Control+A", "Meta+K") on the focused element, or on a ref/selector.',
|
|
246
|
+
parameters: {
|
|
247
|
+
type: 'object',
|
|
248
|
+
properties: {
|
|
249
|
+
key: { type: 'string', description: 'Key or chord, Playwright names.' },
|
|
250
|
+
...targetProps,
|
|
251
|
+
...confirmedProp,
|
|
252
|
+
...shotProps,
|
|
253
|
+
},
|
|
254
|
+
required: ['key'],
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
const executePress = async (params, context) => {
|
|
258
|
+
const session = sessionForAction(context);
|
|
259
|
+
if (!session)
|
|
260
|
+
return NO_SESSION;
|
|
261
|
+
const page = activePage(session);
|
|
262
|
+
const key = String(params.key ?? '').trim();
|
|
263
|
+
if (!key)
|
|
264
|
+
return 'Error: Pass `key`.';
|
|
265
|
+
const target = await resolveAttachedTarget(page, params, false);
|
|
266
|
+
if (target && 'error' in target)
|
|
267
|
+
return target.error;
|
|
268
|
+
const blocked = await gateKey(page, target?.locator ?? page.locator(':focus'), key, params.confirmed, context);
|
|
269
|
+
if (blocked)
|
|
270
|
+
return blocked;
|
|
271
|
+
try {
|
|
272
|
+
if (target)
|
|
273
|
+
await target.locator.press(key);
|
|
274
|
+
else
|
|
275
|
+
await page.keyboard.press(key);
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
return `Error: Could not press ${key}: ${errorLine(err)}`;
|
|
279
|
+
}
|
|
280
|
+
return finish(session, params, context, 'after-key');
|
|
281
|
+
};
|
|
282
|
+
/** The confirm-first gate for a key that can submit or activate (Enter, Space). */
|
|
283
|
+
async function gateKey(page, locator, key, confirmed, context) {
|
|
284
|
+
if (!/(^|\+)(Enter|NumpadEnter)$/.test(key) && key !== ' ' && key !== 'Space')
|
|
285
|
+
return null;
|
|
286
|
+
const info = key === 'Enter' || key.endsWith('+Enter') ? await enterSubmits(locator) : { label: '', submits: false };
|
|
287
|
+
const own = await describeTarget(locator);
|
|
288
|
+
return checkGate({ url: page.url(), label: own.label || info.label, submits: info.submits || own.submits }, confirmed, context);
|
|
289
|
+
}
|
|
290
|
+
// ─── select ─────────────────────────────────────────────────────────────────
|
|
291
|
+
const selectDefinition = {
|
|
292
|
+
name: 'runner_browser_select',
|
|
293
|
+
description: 'Choose option(s) in a <select> by value or visible label (ref or selector). For custom dropdowns click them instead.',
|
|
294
|
+
parameters: {
|
|
295
|
+
type: 'object',
|
|
296
|
+
properties: {
|
|
297
|
+
...targetProps,
|
|
298
|
+
values: { type: 'array', items: { type: 'string' }, description: 'Option values or labels. Several for a multi-select.' },
|
|
299
|
+
...shotProps,
|
|
300
|
+
},
|
|
301
|
+
required: ['values'],
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
const executeSelect = async (params, context) => {
|
|
305
|
+
const session = sessionForAction(context);
|
|
306
|
+
if (!session)
|
|
307
|
+
return NO_SESSION;
|
|
308
|
+
const page = activePage(session);
|
|
309
|
+
const target = await resolveAttachedTarget(page, params);
|
|
310
|
+
if (!target || 'error' in target)
|
|
311
|
+
return target?.error ?? 'Error: No target.';
|
|
312
|
+
const values = readStringList(params.values);
|
|
313
|
+
if (values.length === 0)
|
|
314
|
+
return 'Error: Pass `values`.';
|
|
315
|
+
let selected;
|
|
316
|
+
try {
|
|
317
|
+
try {
|
|
318
|
+
selected = await target.locator.selectOption(values.map(v => ({ value: v })));
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
selected = await target.locator.selectOption(values.map(v => ({ label: v })));
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
catch (err) {
|
|
325
|
+
return `Error: Could not select ${values.join(', ')} in ${target.name}: ${errorLine(err)}`;
|
|
326
|
+
}
|
|
327
|
+
return finish(session, params, context, 'after-select', { selected });
|
|
328
|
+
};
|
|
329
|
+
// ─── scroll ─────────────────────────────────────────────────────────────────
|
|
330
|
+
const scrollDefinition = {
|
|
331
|
+
name: 'runner_browser_scroll',
|
|
332
|
+
description: 'Scroll an element into view (ref/selector), or scroll the page (or the element under ref) in a direction. Lazy-loaded content appears after a scroll.',
|
|
333
|
+
parameters: {
|
|
334
|
+
type: 'object',
|
|
335
|
+
properties: {
|
|
336
|
+
...targetProps,
|
|
337
|
+
direction: { type: 'string', enum: ['down', 'up', 'left', 'right', 'top', 'bottom'], description: 'Scroll the page this way instead of to an element.' },
|
|
338
|
+
amount: { type: 'number', description: 'Pixels for down/up/left/right. Default: 80% of the viewport.' },
|
|
339
|
+
...shotProps,
|
|
340
|
+
},
|
|
341
|
+
required: [],
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
const executeScroll = async (params, context) => {
|
|
345
|
+
const session = sessionForAction(context);
|
|
346
|
+
if (!session)
|
|
347
|
+
return NO_SESSION;
|
|
348
|
+
const page = activePage(session);
|
|
349
|
+
const target = await resolveAttachedTarget(page, params, false);
|
|
350
|
+
if (target && 'error' in target)
|
|
351
|
+
return target.error;
|
|
352
|
+
const direction = params.direction;
|
|
353
|
+
try {
|
|
354
|
+
if (target && !direction) {
|
|
355
|
+
await target.locator.scrollIntoViewIfNeeded();
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
const dir = direction ?? 'down';
|
|
359
|
+
const amount = typeof params.amount === 'number' ? params.amount : Math.round(session.viewport.height * 0.8);
|
|
360
|
+
await page.evaluate(([d, a]) => {
|
|
361
|
+
const el = document.scrollingElement || document.documentElement;
|
|
362
|
+
if (d === 'top')
|
|
363
|
+
el.scrollTo({ top: 0 });
|
|
364
|
+
else if (d === 'bottom')
|
|
365
|
+
el.scrollTo({ top: el.scrollHeight });
|
|
366
|
+
else
|
|
367
|
+
window.scrollBy({ top: d === 'down' ? a : d === 'up' ? -a : 0, left: d === 'right' ? a : d === 'left' ? -a : 0 });
|
|
368
|
+
}, [dir, amount]);
|
|
369
|
+
await page.waitForTimeout(250);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
catch (err) {
|
|
373
|
+
return `Error: Could not scroll: ${errorLine(err)}`;
|
|
374
|
+
}
|
|
375
|
+
const pos = await page.evaluate(() => ({ y: Math.round(window.scrollY), height: document.documentElement.scrollHeight })).catch(() => null);
|
|
376
|
+
return finish(session, params, context, 'after-scroll', pos ? { scrollY: pos.y, pageHeight: pos.height } : {});
|
|
377
|
+
};
|
|
378
|
+
// ─── upload ─────────────────────────────────────────────────────────────────
|
|
379
|
+
const uploadDefinition = {
|
|
380
|
+
name: 'runner_browser_upload',
|
|
381
|
+
description: 'Put files into a file input (ref or selector of the <input type=file>, or the button that opens the file chooser). Paths relative to the project, or in your home/scratch.',
|
|
382
|
+
parameters: {
|
|
383
|
+
type: 'object',
|
|
384
|
+
properties: {
|
|
385
|
+
...targetProps,
|
|
386
|
+
paths: { type: 'array', items: { type: 'string' }, description: 'Files to upload.' },
|
|
387
|
+
...shotProps,
|
|
388
|
+
},
|
|
389
|
+
required: ['paths'],
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
const executeUpload = async (params, context) => {
|
|
393
|
+
const session = sessionForAction(context);
|
|
394
|
+
if (!session)
|
|
395
|
+
return NO_SESSION;
|
|
396
|
+
const page = activePage(session);
|
|
397
|
+
const target = await resolveAttachedTarget(page, params);
|
|
398
|
+
if (!target || 'error' in target)
|
|
399
|
+
return target?.error ?? 'Error: No target.';
|
|
400
|
+
const raw = readStringList(params.paths);
|
|
401
|
+
if (raw.length === 0)
|
|
402
|
+
return 'Error: Pass `paths`.';
|
|
403
|
+
let files;
|
|
404
|
+
try {
|
|
405
|
+
files = raw.map(p => resolveForRead(p, context));
|
|
406
|
+
}
|
|
407
|
+
catch (err) {
|
|
408
|
+
return `Error: ${errorLine(err)}`;
|
|
409
|
+
}
|
|
410
|
+
const missing = files.filter(f => !existsSync(f));
|
|
411
|
+
if (missing.length)
|
|
412
|
+
return `Error: Not found: ${missing.join(', ')}`;
|
|
413
|
+
try {
|
|
414
|
+
const isInput = await target.locator.evaluate(el => el.tagName === 'INPUT' && el.type === 'file').catch(() => false);
|
|
415
|
+
if (isInput) {
|
|
416
|
+
await target.locator.setInputFiles(files);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
const chooser = page.waitForEvent('filechooser', { timeout: 5_000 });
|
|
420
|
+
await target.locator.click();
|
|
421
|
+
await (await chooser).setFiles(files);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
catch (err) {
|
|
425
|
+
return `Error: Could not upload to ${target.name}: ${errorLine(err)}`;
|
|
426
|
+
}
|
|
427
|
+
return finish(session, params, context, 'after-upload', { uploaded: raw });
|
|
428
|
+
};
|
|
429
|
+
// ─── eval ───────────────────────────────────────────────────────────────────
|
|
430
|
+
const evalDefinition = {
|
|
431
|
+
name: 'runner_browser_eval',
|
|
432
|
+
description: 'Run JavaScript in the current page and return the JSON result: an expression ("document.title", "[...document.links].length"), or with ref/selector a function that gets the element ("el => el.getBoundingClientRect()"). ' +
|
|
433
|
+
'For reading state and debugging; act through the click/type tools so the confirm-first gate applies.',
|
|
434
|
+
parameters: {
|
|
435
|
+
type: 'object',
|
|
436
|
+
properties: {
|
|
437
|
+
expression: { type: 'string', description: 'JS expression, or a function of the element when ref/selector is given. Promises are awaited.' },
|
|
438
|
+
...targetProps,
|
|
439
|
+
...confirmedProp,
|
|
440
|
+
},
|
|
441
|
+
required: ['expression'],
|
|
442
|
+
},
|
|
443
|
+
};
|
|
444
|
+
const executeEval = async (params, context) => {
|
|
445
|
+
const session = sessionForAction(context);
|
|
446
|
+
if (!session)
|
|
447
|
+
return NO_SESSION;
|
|
448
|
+
const page = activePage(session);
|
|
449
|
+
const expression = String(params.expression ?? '').trim();
|
|
450
|
+
if (!expression)
|
|
451
|
+
return 'Error: Pass `expression`.';
|
|
452
|
+
// A script can click anything: on ad and payment hosts, and when it clicks
|
|
453
|
+
// or submits itself, it falls under the gate.
|
|
454
|
+
const blocked = checkScriptGate(page.url(), expression, params.confirmed, context);
|
|
455
|
+
if (blocked)
|
|
456
|
+
return blocked;
|
|
457
|
+
const target = await resolveAttachedTarget(page, params, false);
|
|
458
|
+
if (target && 'error' in target)
|
|
459
|
+
return target.error;
|
|
460
|
+
let value;
|
|
461
|
+
try {
|
|
462
|
+
const fn = evalFunction(expression, !!target);
|
|
463
|
+
value = target ? await target.locator.evaluate(fn) : await page.evaluate(fn ?? expression);
|
|
464
|
+
}
|
|
465
|
+
catch (err) {
|
|
466
|
+
return `Error: ${errorLine(err)}`;
|
|
467
|
+
}
|
|
468
|
+
let json;
|
|
469
|
+
try {
|
|
470
|
+
json = JSON.stringify(value ?? null) ?? 'null';
|
|
471
|
+
}
|
|
472
|
+
catch {
|
|
473
|
+
json = JSON.stringify(String(value));
|
|
474
|
+
}
|
|
475
|
+
if (json.length > EVAL_MAX)
|
|
476
|
+
json = JSON.stringify(`${json.slice(0, EVAL_MAX)}... (truncated)`);
|
|
477
|
+
return `{"success":true,"result":${json}}`;
|
|
478
|
+
};
|
|
479
|
+
const LOOKS_LIKE_FUNCTION = /^(async\s+)?(function\b|\([^)]*\)\s*=>|[\w$]+\s*=>)/;
|
|
480
|
+
/**
|
|
481
|
+
* Playwright runs a string as an expression, so "el => el.tagName" came back
|
|
482
|
+
* as the function itself (serialised to null). A function expression becomes
|
|
483
|
+
* a real function here, called with the element; with an element any other
|
|
484
|
+
* expression sees it as `el`. Null: run the string as it is (page scripts with
|
|
485
|
+
* statements). Throws a SyntaxError for code that does not parse.
|
|
486
|
+
*/
|
|
487
|
+
export function evalFunction(expression, withElement) {
|
|
488
|
+
const isFn = LOOKS_LIKE_FUNCTION.test(expression);
|
|
489
|
+
if (!isFn && !withElement)
|
|
490
|
+
return null;
|
|
491
|
+
const body = isFn ? `return (${expression}\n)(el)` : `return (${expression}\n)`;
|
|
492
|
+
return new Function('el', body);
|
|
493
|
+
}
|
|
494
|
+
// ─── handoff ────────────────────────────────────────────────────────────────
|
|
495
|
+
const handoffDefinition = {
|
|
496
|
+
name: 'runner_browser_handoff',
|
|
497
|
+
description: 'Hand the browser to a person: a login with 2FA, a CAPTCHA, a choice only they can make, or the final publish/pay click. ' +
|
|
498
|
+
'They take over in the live view and give it back there; your next browser action takes it back too. ' +
|
|
499
|
+
'In a chat the live view opens for them in a window of its own: tell them what to do and end your turn. In a task: report the link (`liveUrl`) in your result.',
|
|
500
|
+
parameters: {
|
|
501
|
+
type: 'object',
|
|
502
|
+
properties: {
|
|
503
|
+
reason: { type: 'string', description: 'What the person should do, in one sentence, in their language.' },
|
|
504
|
+
},
|
|
505
|
+
required: ['reason'],
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
const executeHandoff = async (params, context) => {
|
|
509
|
+
const session = currentSession(context);
|
|
510
|
+
if (!session)
|
|
511
|
+
return NO_SESSION;
|
|
512
|
+
const reason = String(params.reason ?? '').trim().slice(0, 300) || 'Take over the browser.';
|
|
513
|
+
const at = Date.now();
|
|
514
|
+
session.handoff = { reason, at };
|
|
515
|
+
// In a chat the studio opens the live view for the person on a new show, as
|
|
516
|
+
// for runner_browser_show; a task has its own notice for a handoff.
|
|
517
|
+
if (!context?.taskUid)
|
|
518
|
+
session.shown = { note: reason, at };
|
|
519
|
+
emit({ type: 'changed', session });
|
|
520
|
+
return JSON.stringify({
|
|
521
|
+
success: true,
|
|
522
|
+
session: session.id,
|
|
523
|
+
liveUrl: liveUrlOf(session, context),
|
|
524
|
+
url: activePage(session).url(),
|
|
525
|
+
note: session.headed
|
|
526
|
+
? 'The window is also visible on the runner machine: the person can use it there.'
|
|
527
|
+
: context?.taskUid
|
|
528
|
+
? 'Give the person the live link. Take a runner_browser_snapshot when they say they are done.'
|
|
529
|
+
: 'The live view opened for the person in a window of its own. Tell them what to do; take a runner_browser_snapshot when they say they are done.',
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
export const actTools = [
|
|
533
|
+
{ definition: clickDefinition, execute: executeClick },
|
|
534
|
+
{ definition: typeDefinition, execute: executeType },
|
|
535
|
+
{ definition: pressDefinition, execute: executePress },
|
|
536
|
+
{ definition: selectDefinition, execute: executeSelect },
|
|
537
|
+
{ definition: scrollDefinition, execute: executeScroll },
|
|
538
|
+
{ definition: uploadDefinition, execute: executeUpload },
|
|
539
|
+
{ definition: evalDefinition, execute: executeEval },
|
|
540
|
+
{ definition: handoffDefinition, execute: executeHandoff },
|
|
541
|
+
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type BrowserSession } from './session.js';
|
|
2
|
+
export interface CastOptions {
|
|
3
|
+
fps: number;
|
|
4
|
+
/** Frame width cap in px; Infinity for the viewport's own width. */
|
|
5
|
+
maxWidth: number;
|
|
6
|
+
/** JPEG quality, 0..100. */
|
|
7
|
+
quality: number;
|
|
8
|
+
}
|
|
9
|
+
export interface CastFrame {
|
|
10
|
+
data: Buffer;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
ts: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Receive the frames of a session's active tab. The first subscriber starts
|
|
17
|
+
* the screencast; the returned function unsubscribes and resolves once the
|
|
18
|
+
* cast has adapted (stopped after the last one).
|
|
19
|
+
*/
|
|
20
|
+
export declare function subscribeCast(session: BrowserSession, opts: CastOptions, onFrame: (frame: CastFrame) => void, onError: (message: string) => void): () => Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Follow a change of the session: another active tab, a new viewport. Call it
|
|
23
|
+
* on every session event; it resolves once the cast matches the session again.
|
|
24
|
+
*/
|
|
25
|
+
export declare function refreshCast(session: BrowserSession): Promise<void>;
|