@nordhavnhq/runner 0.0.0-stage → 0.96.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 +39 -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 +20 -0
- package/dist/cli/link.js +312 -0
- package/dist/cli/logs.d.ts +2 -0
- package/dist/cli/logs.js +144 -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 +80 -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 +135 -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 +1324 -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,148 @@
|
|
|
1
|
+
import { type BrowserInput } from './live-input.js';
|
|
2
|
+
import { type BrowserPick } from './pick.js';
|
|
3
|
+
import { type BrowserSession } from './session.js';
|
|
4
|
+
/** How one connection wants its frames, and whether it may open windows. */
|
|
5
|
+
export interface LiveOptions {
|
|
6
|
+
/** Default 5. */
|
|
7
|
+
fps?: number;
|
|
8
|
+
/** Frame width cap in px, Infinity for none. Default 1280. */
|
|
9
|
+
maxWidth?: number;
|
|
10
|
+
/** JPEG quality. Default 60. */
|
|
11
|
+
quality?: number;
|
|
12
|
+
/** Accept `browser:open`. Default true. */
|
|
13
|
+
allowOpen?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface BrowserSessionSummary {
|
|
16
|
+
id: string;
|
|
17
|
+
agentSlug: string;
|
|
18
|
+
organisationSlug: string | null;
|
|
19
|
+
conversationId: string | null;
|
|
20
|
+
taskUid: string | null;
|
|
21
|
+
projectSlug: string | null;
|
|
22
|
+
openedByUserId: number | null;
|
|
23
|
+
profile: string | null;
|
|
24
|
+
headed: boolean;
|
|
25
|
+
viewport: string;
|
|
26
|
+
tabs: {
|
|
27
|
+
index: number;
|
|
28
|
+
active: boolean;
|
|
29
|
+
url: string;
|
|
30
|
+
title: string;
|
|
31
|
+
}[];
|
|
32
|
+
handoff: {
|
|
33
|
+
reason: string;
|
|
34
|
+
at: number;
|
|
35
|
+
} | null;
|
|
36
|
+
/** The agent showed it to a person (runner_browser_show). */
|
|
37
|
+
shown: {
|
|
38
|
+
note: string;
|
|
39
|
+
at: number;
|
|
40
|
+
} | null;
|
|
41
|
+
/** The agent's tour (runner_browser_tour): every stop's line, the one on screen. */
|
|
42
|
+
tour: BrowserTourSummary | null;
|
|
43
|
+
startedAt: number;
|
|
44
|
+
}
|
|
45
|
+
export interface BrowserTourSummary {
|
|
46
|
+
title: string;
|
|
47
|
+
at: number;
|
|
48
|
+
index: number;
|
|
49
|
+
stops: {
|
|
50
|
+
note: string;
|
|
51
|
+
url: string | null;
|
|
52
|
+
marks: number;
|
|
53
|
+
missed: number[];
|
|
54
|
+
}[];
|
|
55
|
+
}
|
|
56
|
+
export type { BrowserPick } from './pick.js';
|
|
57
|
+
export type LiveOutFrame = {
|
|
58
|
+
type: 'browser:sessions';
|
|
59
|
+
sessions: BrowserSessionSummary[];
|
|
60
|
+
} | {
|
|
61
|
+
type: 'browser:session';
|
|
62
|
+
session: BrowserSessionSummary;
|
|
63
|
+
} | {
|
|
64
|
+
type: 'browser:closed';
|
|
65
|
+
sessionId: string;
|
|
66
|
+
} | {
|
|
67
|
+
type: 'browser:frame';
|
|
68
|
+
sessionId: string;
|
|
69
|
+
data: string;
|
|
70
|
+
width: number;
|
|
71
|
+
height: number;
|
|
72
|
+
ts: number;
|
|
73
|
+
} | {
|
|
74
|
+
type: 'browser:error';
|
|
75
|
+
sessionId: string;
|
|
76
|
+
error: string;
|
|
77
|
+
} | {
|
|
78
|
+
type: 'browser:opened';
|
|
79
|
+
requestId: string;
|
|
80
|
+
sessionId?: string;
|
|
81
|
+
error?: string;
|
|
82
|
+
}
|
|
83
|
+
/** What the person pointed at (a `pick` input), or why nothing. */
|
|
84
|
+
| {
|
|
85
|
+
type: 'browser:picked';
|
|
86
|
+
sessionId: string;
|
|
87
|
+
pickId: string;
|
|
88
|
+
pick?: BrowserPick;
|
|
89
|
+
error?: string;
|
|
90
|
+
};
|
|
91
|
+
export type { BrowserInput } from './live-input.js';
|
|
92
|
+
export type LiveInFrame = {
|
|
93
|
+
type: 'browser:watch';
|
|
94
|
+
sessionId: string;
|
|
95
|
+
} | {
|
|
96
|
+
type: 'browser:unwatch';
|
|
97
|
+
sessionId: string;
|
|
98
|
+
} | {
|
|
99
|
+
type: 'browser:list';
|
|
100
|
+
} | {
|
|
101
|
+
type: 'browser:input';
|
|
102
|
+
sessionId: string;
|
|
103
|
+
input: BrowserInput;
|
|
104
|
+
by?: string;
|
|
105
|
+
} | {
|
|
106
|
+
type: 'browser:open';
|
|
107
|
+
requestId: string;
|
|
108
|
+
url?: string;
|
|
109
|
+
profile?: string;
|
|
110
|
+
headed?: boolean;
|
|
111
|
+
viewport?: string;
|
|
112
|
+
byUserId: number;
|
|
113
|
+
by: string;
|
|
114
|
+
};
|
|
115
|
+
/** Opens a session for a person (the runner wires it to this agent's context). */
|
|
116
|
+
export type OpenPersonSession = (frame: Extract<LiveInFrame, {
|
|
117
|
+
type: 'browser:open';
|
|
118
|
+
}>) => Promise<{
|
|
119
|
+
session: BrowserSession;
|
|
120
|
+
} | {
|
|
121
|
+
error: string;
|
|
122
|
+
}>;
|
|
123
|
+
export declare function summarise(session: BrowserSession): Promise<BrowserSessionSummary>;
|
|
124
|
+
export declare const OPEN_REFUSED = "Open a window through the studio.";
|
|
125
|
+
/** Whose sessions a live controller serves: an agent slug is unique only within its organisation. */
|
|
126
|
+
export interface LiveScope {
|
|
127
|
+
agentSlug: string;
|
|
128
|
+
/** Absent: any organisation (a runner holds one organisation per agent slug anyway). */
|
|
129
|
+
organisationSlug?: string | null;
|
|
130
|
+
}
|
|
131
|
+
export interface LiveController {
|
|
132
|
+
handle: (frame: LiveInFrame) => Promise<void>;
|
|
133
|
+
/** Stop every cast and the session listener (socket gone). */
|
|
134
|
+
dispose: () => Promise<void>;
|
|
135
|
+
/** Exported for tests. */
|
|
136
|
+
watching: () => string[];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Wire the live view to one studio connection. `send` delivers a frame to the
|
|
140
|
+
* studio; `closeSession` closes a session by its key (session.ts); `open`
|
|
141
|
+
* opens a window a person asked for from the Browser app. `scope` limits it
|
|
142
|
+
* to one agent's sessions: one process can hold the browsers of several
|
|
143
|
+
* agents (a runner with more than one, the browser host), and a socket only
|
|
144
|
+
* ever reports and drives the sessions of its own agent. `options` sets the
|
|
145
|
+
* frame rate, size and quality this connection wants, and whether it may open
|
|
146
|
+
* windows.
|
|
147
|
+
*/
|
|
148
|
+
export declare function createLiveController(send: (frame: LiveOutFrame) => void, closeSession: (key: string) => Promise<void>, open?: OpenPersonSession, scope?: LiveScope, options?: LiveOptions): LiveController;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { refreshCast, subscribeCast } from './cast-hub.js';
|
|
2
|
+
import { applyInput, toPixels } from './live-input.js';
|
|
3
|
+
import { errorLine, errorMessage } from './params.js';
|
|
4
|
+
import { pickAt } from './pick.js';
|
|
5
|
+
import { activePage, describeSession, listSessions, onSessionEvent, sessionById, } from './session.js';
|
|
6
|
+
// ─── Live view: screencast out, a person's input in ─────────────────────────
|
|
7
|
+
//
|
|
8
|
+
// The studio asks for a session's frames while somebody watches it
|
|
9
|
+
// (`browser:watch` / `browser:unwatch`) and forwards a person's input
|
|
10
|
+
// (`browser:input`). Frames are JPEG from Playwright's screencast of the active
|
|
11
|
+
// tab, only while there is a watcher, never stored. Input from a person is the
|
|
12
|
+
// person acting: it does not pass the agent's confirm-first gate.
|
|
13
|
+
//
|
|
14
|
+
// Transport-free: the connection hands in a `send` and routes the studio's
|
|
15
|
+
// browser:* frames to `handle`. Casts are shared per session (cast-hub.ts):
|
|
16
|
+
// the studio relay and a local viewer can watch the same session at once.
|
|
17
|
+
const FPS = 5;
|
|
18
|
+
const QUALITY = 60;
|
|
19
|
+
const MAX_WIDTH = 1280;
|
|
20
|
+
function tourSummary(session) {
|
|
21
|
+
const tour = session.tour;
|
|
22
|
+
if (!tour)
|
|
23
|
+
return null;
|
|
24
|
+
return {
|
|
25
|
+
title: tour.title,
|
|
26
|
+
at: tour.at,
|
|
27
|
+
index: tour.index,
|
|
28
|
+
stops: tour.stops.map(s => ({ note: s.note, url: s.url, marks: s.marks.length, missed: s.missed })),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export async function summarise(session) {
|
|
32
|
+
const d = await describeSession(session);
|
|
33
|
+
return {
|
|
34
|
+
id: session.id,
|
|
35
|
+
...session.owner,
|
|
36
|
+
profile: session.profile,
|
|
37
|
+
headed: session.headed,
|
|
38
|
+
viewport: d.viewport,
|
|
39
|
+
tabs: d.tabs,
|
|
40
|
+
handoff: session.handoff,
|
|
41
|
+
shown: session.shown,
|
|
42
|
+
tour: tourSummary(session),
|
|
43
|
+
startedAt: session.startedAt,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** The answer to a `pick`: the element at the point, described. */
|
|
47
|
+
async function answerPick(session, input) {
|
|
48
|
+
const base = { type: 'browser:picked', sessionId: session.id, pickId: input.pickId };
|
|
49
|
+
try {
|
|
50
|
+
const pick = await pickAt(activePage(session), ...toPixels({ session }, input));
|
|
51
|
+
return pick ? { ...base, pick } : { ...base, error: 'Nothing there to point at.' };
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
return { ...base, error: errorLine(err) };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export const OPEN_REFUSED = 'Open a window through the studio.';
|
|
58
|
+
async function openFor(frame, open, allowOpen) {
|
|
59
|
+
const { requestId } = frame;
|
|
60
|
+
if (!allowOpen)
|
|
61
|
+
return { type: 'browser:opened', requestId, error: OPEN_REFUSED };
|
|
62
|
+
if (!open)
|
|
63
|
+
return { type: 'browser:opened', requestId, error: 'This runner cannot open a browser window.' };
|
|
64
|
+
try {
|
|
65
|
+
const result = await open(frame);
|
|
66
|
+
if ('error' in result)
|
|
67
|
+
return { type: 'browser:opened', requestId, error: result.error.replace(/^Error: /, '') };
|
|
68
|
+
return { type: 'browser:opened', requestId, sessionId: result.session.id };
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
return { type: 'browser:opened', requestId, error: errorLine(err) };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function scopeFilter(scope) {
|
|
75
|
+
if (!scope)
|
|
76
|
+
return () => true;
|
|
77
|
+
return s => s.owner.agentSlug === scope.agentSlug
|
|
78
|
+
&& (scope.organisationSlug == null || s.owner.organisationSlug === scope.organisationSlug);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Wire the live view to one studio connection. `send` delivers a frame to the
|
|
82
|
+
* studio; `closeSession` closes a session by its key (session.ts); `open`
|
|
83
|
+
* opens a window a person asked for from the Browser app. `scope` limits it
|
|
84
|
+
* to one agent's sessions: one process can hold the browsers of several
|
|
85
|
+
* agents (a runner with more than one, the browser host), and a socket only
|
|
86
|
+
* ever reports and drives the sessions of its own agent. `options` sets the
|
|
87
|
+
* frame rate, size and quality this connection wants, and whether it may open
|
|
88
|
+
* windows.
|
|
89
|
+
*/
|
|
90
|
+
export function createLiveController(send, closeSession, open, scope, options) {
|
|
91
|
+
const owns = scopeFilter(scope);
|
|
92
|
+
const castOptions = {
|
|
93
|
+
fps: options?.fps ?? FPS,
|
|
94
|
+
maxWidth: options?.maxWidth ?? MAX_WIDTH,
|
|
95
|
+
quality: options?.quality ?? QUALITY,
|
|
96
|
+
};
|
|
97
|
+
const allowOpen = options?.allowOpen ?? true;
|
|
98
|
+
/** Unsubscribe per watched session id. */
|
|
99
|
+
const casts = new Map();
|
|
100
|
+
const watched = new Set();
|
|
101
|
+
async function stopCast(id) {
|
|
102
|
+
const unsubscribe = casts.get(id);
|
|
103
|
+
if (!unsubscribe)
|
|
104
|
+
return;
|
|
105
|
+
casts.delete(id);
|
|
106
|
+
await unsubscribe().catch(() => { });
|
|
107
|
+
}
|
|
108
|
+
async function startCast(session) {
|
|
109
|
+
if (!casts.has(session.id)) {
|
|
110
|
+
casts.set(session.id, subscribeCast(session, castOptions, ({ data, width, height, ts }) => {
|
|
111
|
+
if (!watched.has(session.id))
|
|
112
|
+
return;
|
|
113
|
+
send({ type: 'browser:frame', sessionId: session.id, data: data.toString('base64'), width, height, ts });
|
|
114
|
+
}, error => send({ type: 'browser:error', sessionId: session.id, error })));
|
|
115
|
+
}
|
|
116
|
+
await refreshCast(session);
|
|
117
|
+
}
|
|
118
|
+
const off = onSessionEvent((event) => {
|
|
119
|
+
const s = event.session;
|
|
120
|
+
if (!owns(s))
|
|
121
|
+
return;
|
|
122
|
+
if (event.type === 'closed') {
|
|
123
|
+
watched.delete(s.id);
|
|
124
|
+
void stopCast(s.id);
|
|
125
|
+
send({ type: 'browser:closed', sessionId: s.id });
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
void summarise(s).then(summary => send({ type: 'browser:session', session: summary })).catch(() => { });
|
|
129
|
+
// The active tab changed: follow it.
|
|
130
|
+
if (watched.has(s.id))
|
|
131
|
+
void startCast(s);
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
async handle(frame) {
|
|
135
|
+
if (frame.type === 'browser:list') {
|
|
136
|
+
send({ type: 'browser:sessions', sessions: await Promise.all(listSessions().filter(owns).map(summarise)) });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (frame.type === 'browser:open') {
|
|
140
|
+
send(await openFor(frame, open, allowOpen));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const found = sessionById(frame.sessionId);
|
|
144
|
+
const session = found && owns(found) ? found : undefined;
|
|
145
|
+
if (!session) {
|
|
146
|
+
send({ type: 'browser:closed', sessionId: frame.sessionId });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (frame.type === 'browser:watch') {
|
|
150
|
+
watched.add(session.id);
|
|
151
|
+
send({ type: 'browser:session', session: await summarise(session) });
|
|
152
|
+
await startCast(session);
|
|
153
|
+
}
|
|
154
|
+
else if (frame.type === 'browser:unwatch') {
|
|
155
|
+
watched.delete(session.id);
|
|
156
|
+
await stopCast(session.id);
|
|
157
|
+
}
|
|
158
|
+
else if (frame.type === 'browser:input') {
|
|
159
|
+
session.lastUsed = Date.now();
|
|
160
|
+
if (frame.input.kind === 'pick') {
|
|
161
|
+
send(await answerPick(session, frame.input));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
await applyInput(session, frame.input, closeSession);
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
send({ type: 'browser:error', sessionId: session.id, error: errorMessage(err).split('\n')[0] ?? 'input failed' });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
async dispose() {
|
|
173
|
+
off();
|
|
174
|
+
watched.clear();
|
|
175
|
+
await Promise.all([...casts.keys()].map(stopCast));
|
|
176
|
+
},
|
|
177
|
+
watching: () => [...watched],
|
|
178
|
+
};
|
|
179
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const LOCAL_LIVE_PROTOCOL = 1;
|
|
2
|
+
export declare const LOCAL_LIVE_MAX_CLIENTS = 8;
|
|
3
|
+
export declare const CLOSE_UNAUTHORISED = 4401;
|
|
4
|
+
export declare const CLOSE_TOO_MANY = 4429;
|
|
5
|
+
export interface LocalLiveAgent {
|
|
6
|
+
agentSlug: string;
|
|
7
|
+
organisationSlug: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface LocalLiveDeps {
|
|
10
|
+
closeSession: (key: string) => Promise<void>;
|
|
11
|
+
agents: LocalLiveAgent[];
|
|
12
|
+
/** Folder of the endpoint files. Default ~/.nordhavn-os/live. */
|
|
13
|
+
dir?: string;
|
|
14
|
+
/** Default process.pid. */
|
|
15
|
+
pid?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface LocalLiveServer {
|
|
18
|
+
port: number;
|
|
19
|
+
token: string;
|
|
20
|
+
/** Where the endpoint file is. */
|
|
21
|
+
file: string;
|
|
22
|
+
setAgents: (list: LocalLiveAgent[]) => void;
|
|
23
|
+
stop: () => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function defaultLocalLiveDir(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Serve the live view of this process's agent browsers to viewers on this
|
|
28
|
+
* machine (the desktop app). Resolves once it listens and the endpoint file is
|
|
29
|
+
* written.
|
|
30
|
+
*/
|
|
31
|
+
export declare function startLocalLiveServer(deps: LocalLiveDeps): Promise<LocalLiveServer>;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { chmodSync, mkdirSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { WebSocket, WebSocketServer } from 'ws';
|
|
6
|
+
import { createLiveController, OPEN_REFUSED } from './live.js';
|
|
7
|
+
// ─── Local live view: the desktop app on this machine, without the studio ───
|
|
8
|
+
//
|
|
9
|
+
// The desktop app shows an agent's browser live. Through the studio every
|
|
10
|
+
// frame travels runner -> server -> app; on the same machine that hop is
|
|
11
|
+
// waste. This server listens on 127.0.0.1 only and speaks the studio's own
|
|
12
|
+
// browser:* protocol (BrowserStudioMessage in, BrowserStudioFrame out), so the
|
|
13
|
+
// app's live view works on either transport.
|
|
14
|
+
//
|
|
15
|
+
// Discovery: an endpoint file `<pid>.json` (mode 0600, in a 0700 folder under
|
|
16
|
+
// the user's home) holds the port and a random token. Only this user can read
|
|
17
|
+
// it; a client without the token is closed with 4401. Opening a window stays a
|
|
18
|
+
// studio action (it needs the person's identity): browser:open is refused.
|
|
19
|
+
export const LOCAL_LIVE_PROTOCOL = 1;
|
|
20
|
+
export const LOCAL_LIVE_MAX_CLIENTS = 8;
|
|
21
|
+
export const CLOSE_UNAUTHORISED = 4401;
|
|
22
|
+
export const CLOSE_TOO_MANY = 4429;
|
|
23
|
+
/** Frames above this backlog are dropped for that client (a slow reader). */
|
|
24
|
+
const MAX_BUFFERED_BYTES = 8 * 1024 * 1024;
|
|
25
|
+
const agentKey = (a) => `${a.organisationSlug ?? ''}/${a.agentSlug}`;
|
|
26
|
+
export function defaultLocalLiveDir() {
|
|
27
|
+
return join(homedir(), '.nordhavn-os', 'live');
|
|
28
|
+
}
|
|
29
|
+
function tokenMatches(expected, req) {
|
|
30
|
+
let given;
|
|
31
|
+
try {
|
|
32
|
+
given = new URL(req.url ?? '/', 'http://127.0.0.1').searchParams.get('token');
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (!given)
|
|
38
|
+
return false;
|
|
39
|
+
const buf = Buffer.from(given);
|
|
40
|
+
return buf.length === expected.length && timingSafeEqual(buf, expected);
|
|
41
|
+
}
|
|
42
|
+
function isString(v) {
|
|
43
|
+
return typeof v === 'string' && v.length > 0;
|
|
44
|
+
}
|
|
45
|
+
function parseMessage(raw) {
|
|
46
|
+
let msg;
|
|
47
|
+
try {
|
|
48
|
+
msg = JSON.parse(raw);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (!msg || typeof msg !== 'object')
|
|
54
|
+
return null;
|
|
55
|
+
const m = msg;
|
|
56
|
+
if (m.type === 'browser:list')
|
|
57
|
+
return { type: 'browser:list' };
|
|
58
|
+
if (!isString(m.agentSlug))
|
|
59
|
+
return null;
|
|
60
|
+
const organisationSlug = typeof m.organisationSlug === 'string' ? m.organisationSlug : undefined;
|
|
61
|
+
const base = { agentSlug: m.agentSlug, organisationSlug };
|
|
62
|
+
if (m.type === 'browser:open')
|
|
63
|
+
return isString(m.requestId) ? { type: 'browser:open', ...base, requestId: m.requestId } : null;
|
|
64
|
+
if (!isString(m.sessionId))
|
|
65
|
+
return null;
|
|
66
|
+
if (m.type === 'browser:watch' || m.type === 'browser:unwatch')
|
|
67
|
+
return { type: m.type, ...base, sessionId: m.sessionId };
|
|
68
|
+
if (m.type === 'browser:input' && m.input && typeof m.input === 'object') {
|
|
69
|
+
return { type: 'browser:input', ...base, sessionId: m.sessionId, input: m.input };
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
function writeEndpointFile(file, body) {
|
|
74
|
+
const tmp = `${file}.tmp`;
|
|
75
|
+
writeFileSync(tmp, JSON.stringify(body), { mode: 0o600 });
|
|
76
|
+
chmodSync(tmp, 0o600);
|
|
77
|
+
renameSync(tmp, file);
|
|
78
|
+
}
|
|
79
|
+
/** One connected viewer: a live controller per agent, frames tagged with the agent. */
|
|
80
|
+
class LocalClient {
|
|
81
|
+
ws;
|
|
82
|
+
closeSession;
|
|
83
|
+
controllers = new Map();
|
|
84
|
+
constructor(ws, closeSession) {
|
|
85
|
+
this.ws = ws;
|
|
86
|
+
this.closeSession = closeSession;
|
|
87
|
+
}
|
|
88
|
+
send(frame) {
|
|
89
|
+
if (this.ws.readyState !== WebSocket.OPEN)
|
|
90
|
+
return;
|
|
91
|
+
try {
|
|
92
|
+
this.ws.send(JSON.stringify(frame));
|
|
93
|
+
}
|
|
94
|
+
catch { }
|
|
95
|
+
}
|
|
96
|
+
sendOut(agent, frame) {
|
|
97
|
+
if (frame.type === 'browser:frame' && this.ws.bufferedAmount > MAX_BUFFERED_BYTES)
|
|
98
|
+
return;
|
|
99
|
+
this.send({ ...frame, agentSlug: agent.agentSlug, organisationSlug: agent.organisationSlug });
|
|
100
|
+
}
|
|
101
|
+
setAgents(list) {
|
|
102
|
+
const wanted = new Map(list.map(a => [agentKey(a), a]));
|
|
103
|
+
for (const [key, entry] of this.controllers) {
|
|
104
|
+
if (wanted.has(key))
|
|
105
|
+
continue;
|
|
106
|
+
this.controllers.delete(key);
|
|
107
|
+
void entry.live.dispose();
|
|
108
|
+
}
|
|
109
|
+
for (const [key, agent] of wanted) {
|
|
110
|
+
if (this.controllers.has(key))
|
|
111
|
+
continue;
|
|
112
|
+
const live = createLiveController(frame => this.sendOut(agent, frame), this.closeSession, undefined, { agentSlug: agent.agentSlug, organisationSlug: agent.organisationSlug }, { fps: 15, maxWidth: Infinity, quality: 70, allowOpen: false });
|
|
113
|
+
this.controllers.set(key, { agent, live });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
find(agentSlug, organisationSlug) {
|
|
117
|
+
for (const entry of this.controllers.values()) {
|
|
118
|
+
if (entry.agent.agentSlug !== agentSlug)
|
|
119
|
+
continue;
|
|
120
|
+
if (organisationSlug !== undefined && entry.agent.organisationSlug !== organisationSlug)
|
|
121
|
+
continue;
|
|
122
|
+
return entry;
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
async handle(raw) {
|
|
127
|
+
const msg = parseMessage(raw);
|
|
128
|
+
if (!msg)
|
|
129
|
+
return;
|
|
130
|
+
if (msg.type === 'browser:list') {
|
|
131
|
+
await Promise.all([...this.controllers.values()].map(e => e.live.handle({ type: 'browser:list' })));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const entry = this.find(msg.agentSlug, msg.organisationSlug ?? undefined);
|
|
135
|
+
if (msg.type === 'browser:open') {
|
|
136
|
+
this.send({
|
|
137
|
+
type: 'browser:opened',
|
|
138
|
+
agentSlug: msg.agentSlug,
|
|
139
|
+
organisationSlug: entry?.agent.organisationSlug ?? msg.organisationSlug ?? null,
|
|
140
|
+
requestId: msg.requestId,
|
|
141
|
+
error: OPEN_REFUSED,
|
|
142
|
+
});
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (!entry)
|
|
146
|
+
return;
|
|
147
|
+
const frame = msg.type === 'browser:input'
|
|
148
|
+
? { type: 'browser:input', sessionId: msg.sessionId, input: msg.input, by: 'desktop' }
|
|
149
|
+
: { type: msg.type, sessionId: msg.sessionId };
|
|
150
|
+
await entry.live.handle(frame);
|
|
151
|
+
}
|
|
152
|
+
async dispose() {
|
|
153
|
+
const all = [...this.controllers.values()];
|
|
154
|
+
this.controllers.clear();
|
|
155
|
+
await Promise.all(all.map(e => e.live.dispose().catch(() => { })));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function listen(wss) {
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
wss.once('error', reject);
|
|
161
|
+
wss.once('listening', () => {
|
|
162
|
+
wss.off('error', reject);
|
|
163
|
+
const addr = wss.address();
|
|
164
|
+
if (addr && typeof addr === 'object')
|
|
165
|
+
resolve(addr.port);
|
|
166
|
+
else
|
|
167
|
+
reject(new Error('local live server has no port'));
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Serve the live view of this process's agent browsers to viewers on this
|
|
173
|
+
* machine (the desktop app). Resolves once it listens and the endpoint file is
|
|
174
|
+
* written.
|
|
175
|
+
*/
|
|
176
|
+
export async function startLocalLiveServer(deps) {
|
|
177
|
+
const pid = deps.pid ?? process.pid;
|
|
178
|
+
const dir = deps.dir ?? defaultLocalLiveDir();
|
|
179
|
+
const file = join(dir, `${pid}.json`);
|
|
180
|
+
const token = randomBytes(32).toString('hex');
|
|
181
|
+
const expected = Buffer.from(token);
|
|
182
|
+
// Epoch ms: the desktop's endpoint parser (apps/desktop browser-local.ts) only
|
|
183
|
+
// takes a number and skips the whole file otherwise.
|
|
184
|
+
const startedAt = Date.now();
|
|
185
|
+
let agents = [...deps.agents];
|
|
186
|
+
const clients = new Map();
|
|
187
|
+
const wss = new WebSocketServer({ host: '127.0.0.1', port: 0, maxPayload: 1024 * 1024 });
|
|
188
|
+
const port = await listen(wss);
|
|
189
|
+
const hello = () => ({ type: 'browser:hello', protocol: LOCAL_LIVE_PROTOCOL, pid, agents });
|
|
190
|
+
const writeFile = () => writeEndpointFile(file, { protocol: LOCAL_LIVE_PROTOCOL, pid, port, token, agents, startedAt });
|
|
191
|
+
const unlinkFile = () => {
|
|
192
|
+
try {
|
|
193
|
+
unlinkSync(file);
|
|
194
|
+
}
|
|
195
|
+
catch { }
|
|
196
|
+
};
|
|
197
|
+
wss.on('connection', (ws, req) => {
|
|
198
|
+
if (!tokenMatches(expected, req)) {
|
|
199
|
+
ws.close(CLOSE_UNAUTHORISED, 'unauthorised');
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (clients.size >= LOCAL_LIVE_MAX_CLIENTS) {
|
|
203
|
+
ws.close(CLOSE_TOO_MANY, 'too many clients');
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const client = new LocalClient(ws, deps.closeSession);
|
|
207
|
+
clients.set(ws, client);
|
|
208
|
+
client.setAgents(agents);
|
|
209
|
+
client.send(hello());
|
|
210
|
+
ws.on('message', (data) => {
|
|
211
|
+
void client.handle(data.toString()).catch(() => { });
|
|
212
|
+
});
|
|
213
|
+
ws.on('close', () => {
|
|
214
|
+
clients.delete(ws);
|
|
215
|
+
void client.dispose();
|
|
216
|
+
});
|
|
217
|
+
ws.on('error', () => { });
|
|
218
|
+
});
|
|
219
|
+
try {
|
|
220
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
221
|
+
writeFile();
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
await new Promise(resolve => wss.close(() => resolve()));
|
|
225
|
+
throw err;
|
|
226
|
+
}
|
|
227
|
+
process.on('exit', unlinkFile);
|
|
228
|
+
return {
|
|
229
|
+
port,
|
|
230
|
+
token,
|
|
231
|
+
file,
|
|
232
|
+
setAgents(list) {
|
|
233
|
+
agents = [...list];
|
|
234
|
+
try {
|
|
235
|
+
writeFile();
|
|
236
|
+
}
|
|
237
|
+
catch { }
|
|
238
|
+
for (const client of clients.values()) {
|
|
239
|
+
client.setAgents(agents);
|
|
240
|
+
client.send(hello());
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
async stop() {
|
|
244
|
+
unlinkFile();
|
|
245
|
+
process.off('exit', unlinkFile);
|
|
246
|
+
const open = [...clients.entries()];
|
|
247
|
+
clients.clear();
|
|
248
|
+
for (const [ws] of open) {
|
|
249
|
+
try {
|
|
250
|
+
ws.close(1001, 'runner stopping');
|
|
251
|
+
}
|
|
252
|
+
catch { }
|
|
253
|
+
// A client that never answers the close must not hold the server open.
|
|
254
|
+
const force = setTimeout(() => ws.terminate(), 500);
|
|
255
|
+
force.unref();
|
|
256
|
+
ws.once('close', () => clearTimeout(force));
|
|
257
|
+
}
|
|
258
|
+
await Promise.all(open.map(([, client]) => client.dispose()));
|
|
259
|
+
await new Promise(resolve => wss.close(() => resolve()));
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Page } from 'playwright-core';
|
|
2
|
+
export declare const MARKS_MAX = 12;
|
|
3
|
+
export declare const MARK_LABEL_MAX = 140;
|
|
4
|
+
/**
|
|
5
|
+
* Two layers: the agent's marks (show, tour) and the person's own pick in the
|
|
6
|
+
* live view, so a pick never wipes the marks of a tour stop.
|
|
7
|
+
*/
|
|
8
|
+
export type MarkLayer = 'marks' | 'pick';
|
|
9
|
+
/** What the agent thinks of the element: drawn in its own colour. */
|
|
10
|
+
export type MarkTone = 'issue' | 'good' | 'info';
|
|
11
|
+
export declare const MARK_TONES: readonly MarkTone[];
|
|
12
|
+
export interface MarkInput {
|
|
13
|
+
ref?: string;
|
|
14
|
+
selector?: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
tone?: MarkTone;
|
|
17
|
+
}
|
|
18
|
+
export interface MarksResult {
|
|
19
|
+
marked: number;
|
|
20
|
+
/** Marks that could not be placed, with why (1-based, as numbered). */
|
|
21
|
+
missed: Array<{
|
|
22
|
+
mark: number;
|
|
23
|
+
error: string;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
/** Validate the `marks` parameter: an array of { ref | selector, label?, tone? }. */
|
|
27
|
+
export declare function readMarks(raw: unknown): MarkInput[] | {
|
|
28
|
+
error: string;
|
|
29
|
+
} | undefined;
|
|
30
|
+
/** Remove a marks layer from a page. Never throws. */
|
|
31
|
+
export declare function clearMarks(page: Page, layer?: MarkLayer): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Draw the marks on the page, replacing any that are there. An empty list just
|
|
34
|
+
* clears. The first mark is scrolled into view.
|
|
35
|
+
*/
|
|
36
|
+
export declare function drawMarks(page: Page, marks: MarkInput[], layer?: MarkLayer): Promise<MarksResult>;
|