@myrialabs/clopen 0.4.47 → 0.4.49
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/README.md +11 -11
- package/backend/artifacts/project/sources.ts +1 -1
- package/backend/auth/auth-service.ts +52 -358
- package/backend/auth/onboarding.test.ts +2 -3
- package/backend/auth/permissions.test.ts +10 -20
- package/backend/auth/permissions.ts +4 -290
- package/backend/auth/rate-limiter.test.ts +8 -9
- package/backend/auth/rate-limiter.ts +0 -2
- package/backend/auth/tokens.ts +1 -8
- package/backend/bootstrap.ts +7 -0
- package/backend/chat/attachments.test.ts +88 -0
- package/backend/chat/attachments.ts +159 -0
- package/backend/chat/engine-handoff.test.ts +0 -2
- package/backend/chat/message-pages.test.ts +163 -0
- package/backend/chat/message-pages.ts +233 -0
- package/backend/chat/stream-manager.ts +91 -67
- package/backend/chat/turn-answer.test.ts +64 -0
- package/backend/chat/turn-answer.ts +125 -0
- package/backend/chat-apps/awaiting.test.ts +39 -0
- package/backend/chat-apps/awaiting.ts +49 -0
- package/backend/chat-apps/conversation.ts +746 -0
- package/backend/chat-apps/inbound.ts +324 -0
- package/backend/chat-apps/index.ts +309 -0
- package/backend/chat-apps/link-events.ts +20 -0
- package/backend/chat-apps/media.test.ts +62 -0
- package/backend/chat-apps/media.ts +208 -0
- package/backend/chat-apps/messages.test.ts +229 -0
- package/backend/chat-apps/messages.ts +365 -0
- package/backend/chat-apps/outbound.ts +243 -0
- package/backend/chat-apps/pairing.test.ts +45 -0
- package/backend/chat-apps/pairing.ts +74 -0
- package/backend/chat-apps/platforms/index.ts +20 -0
- package/backend/chat-apps/platforms/telegram.test.ts +35 -0
- package/backend/chat-apps/platforms/telegram.ts +191 -0
- package/backend/chat-apps/platforms/types.ts +114 -0
- package/backend/chat-apps/questions.ts +133 -0
- package/backend/chat-apps/runtime.ts +572 -0
- package/backend/chat-apps/storage.test.ts +201 -0
- package/backend/chat-apps/turns.test.ts +45 -0
- package/backend/chat-apps/turns.ts +208 -0
- package/backend/containers/pty.ts +3 -11
- package/backend/control/actions/accounts.ts +89 -0
- package/backend/control/actions/files.ts +116 -0
- package/backend/control/actions/models.ts +188 -0
- package/backend/control/actions/projects.ts +272 -0
- package/backend/control/actions/sessions.ts +280 -0
- package/backend/control/actions/skills.ts +111 -0
- package/backend/control/control.test.ts +169 -0
- package/backend/control/define.ts +20 -0
- package/backend/control/folders.test.ts +67 -0
- package/backend/control/index.ts +213 -0
- package/backend/control/invoke.ts +44 -0
- package/backend/control/links.ts +35 -0
- package/backend/control/paging.ts +26 -0
- package/backend/control/types.ts +117 -0
- package/backend/control/workspace.ts +127 -0
- package/backend/database/migrations/084_create_channel_links.ts +71 -0
- package/backend/database/migrations/085_add_home_projects.ts +36 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/087_create_blob_line_stats.ts +37 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- package/backend/database/queries/blob-line-stats-queries.ts +48 -0
- package/backend/database/queries/channel-queries.ts +270 -0
- package/backend/database/queries/db-client-connection-queries.ts +18 -56
- package/backend/database/queries/file-share-queries.ts +5 -23
- package/backend/database/queries/git-identity-queries.ts +31 -42
- package/backend/database/queries/graph-queries.ts +1 -1
- package/backend/database/queries/index.ts +15 -1
- package/backend/database/queries/message-queries.test.ts +146 -0
- package/backend/database/queries/message-queries.ts +42 -1
- package/backend/database/queries/permission-set-queries.ts +1 -1
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
- package/backend/database/queries/project-queries.ts +50 -63
- package/backend/database/queries/session-queries.ts +28 -56
- package/backend/database/queries/ssh-connection-queries.ts +18 -41
- package/backend/db-client/env/diff.ts +9 -33
- package/backend/db-client/env/env.test.ts +8 -8
- package/backend/db-client/env/service.ts +1 -1
- package/backend/db-client/integrations/projector.ts +0 -5
- package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
- package/backend/engine/adapters/claude/message-converter.ts +25 -2
- package/backend/engine/adapters/cline/message-converter.ts +0 -1
- package/backend/engine/adapters/cline/stream.ts +11 -15
- package/backend/engine/adapters/codex/message-converter.ts +0 -2
- package/backend/engine/adapters/copilot/message-converter.ts +1 -2
- package/backend/engine/adapters/cursor/message-converter.ts +0 -1
- package/backend/engine/adapters/opencode/message-converter.ts +2 -4
- package/backend/engine/adapters/opencode/stream.ts +11 -0
- package/backend/engine/adapters/parent-scope.test.ts +38 -0
- package/backend/engine/adapters/parent-scope.ts +44 -0
- package/backend/engine/adapters/pi/message-converter.ts +0 -1
- package/backend/engine/adapters/pi/stream.ts +4 -5
- package/backend/engine/adapters/qwen/message-converter.ts +0 -2
- package/backend/engine/bootstrap-default-engine.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +8 -1
- package/backend/engine/install-runner.ts +8 -17
- package/backend/files/file-shares.ts +20 -44
- package/backend/files/file-size-limit.ts +3 -3
- package/backend/files/file-watcher.ts +19 -0
- package/backend/files/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- package/backend/git/contributors.test.ts +35 -0
- package/backend/git/contributors.ts +46 -0
- package/backend/git/git-executor.ts +25 -5
- package/backend/git/git-service.ts +420 -19
- package/backend/git/identity/credential-helper.test.ts +2 -7
- package/backend/git/identity/import-local.test.ts +11 -16
- package/backend/git/identity/import-local.ts +12 -12
- package/backend/git/identity/index.ts +10 -24
- package/backend/git/identity/resolve.ts +13 -14
- package/backend/git/identity/scope-config.ts +33 -28
- package/backend/git/identity/service.ts +44 -47
- package/backend/git/op-lock.test.ts +111 -0
- package/backend/git/op-lock.ts +180 -0
- package/backend/git/remote-sync.test.ts +249 -0
- package/backend/host/metrics.ts +1 -1
- package/backend/http/bearer-auth.ts +1 -2
- package/backend/http/files-download.test.ts +8 -9
- package/backend/http/files-download.ts +2 -2
- package/backend/http/files-shared.test.ts +62 -89
- package/backend/http/files-shared.ts +2 -2
- package/backend/http/files-upload.test.ts +3 -7
- package/backend/http/files-upload.ts +3 -3
- package/backend/http/notes-images.test.ts +15 -38
- package/backend/http/notes-images.ts +6 -8
- package/backend/http/ssh-sftp.ts +5 -10
- package/backend/http/static-assets.test.ts +78 -0
- package/backend/http/static-assets.ts +104 -0
- package/backend/index.ts +32 -16
- package/backend/integrations/accounts.ts +61 -3
- package/backend/integrations/index.ts +2 -2
- package/backend/integrations/registry/define.ts +15 -0
- package/backend/integrations/registry/index.ts +2 -0
- package/backend/integrations/registry/providers/telegram.ts +54 -0
- package/backend/integrations/registry/types.ts +21 -1
- package/backend/integrations/webhooks/gateway.ts +7 -6
- package/backend/integrations/webhooks/verify.test.ts +30 -0
- package/backend/integrations/webhooks/verify.ts +4 -0
- package/backend/mcp/external/project.ts +1 -1
- package/backend/mcp/internal/remote-server.test.ts +1 -3
- package/backend/mcp/internal/remote-server.ts +4 -4
- package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
- package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
- package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
- package/backend/memory/redact.ts +1 -1
- package/backend/notes/access.test.ts +28 -29
- package/backend/notes/access.ts +6 -11
- package/backend/permissions/service.ts +1 -1
- package/backend/preview/browser/browser-clipboard.test.ts +46 -0
- package/backend/preview/browser/browser-clipboard.ts +67 -0
- package/backend/preview/browser/browser-dialog-handler.ts +95 -6
- package/backend/preview/browser/browser-host-bridge.ts +9 -0
- package/backend/preview/browser/browser-interaction-handler.ts +316 -86
- package/backend/preview/browser/browser-mcp-control.ts +34 -0
- package/backend/preview/browser/browser-pool.ts +67 -6
- package/backend/preview/browser/browser-preview-service.ts +383 -29
- package/backend/preview/browser/browser-tab-manager.ts +66 -23
- package/backend/preview/browser/browser-video-capture.ts +92 -5
- package/backend/preview/browser/element-locator.ts +190 -17
- package/backend/preview/browser/keyboard-chords.test.ts +68 -0
- package/backend/preview/browser/keyboard-chords.ts +132 -0
- package/backend/preview/browser/paste.ts +81 -0
- package/backend/preview/browser/process-usage.ts +142 -0
- package/backend/preview/browser/profile-lock.ts +209 -0
- package/backend/preview/browser/scripts/host-bridge.ts +59 -0
- package/backend/preview/browser/scripts/video-stream.ts +58 -0
- package/backend/preview/browser/types.ts +40 -2
- package/backend/preview/browser/viewport.test.ts +45 -0
- package/backend/preview/browser/viewport.ts +96 -0
- package/backend/profiles/service.ts +2 -2
- package/backend/project/status-manager.ts +43 -172
- package/backend/projects/home.ts +61 -0
- package/backend/projects/project-cleanup.integration.test.ts +2 -2
- package/backend/projects/project-cleanup.ts +0 -8
- package/backend/skills/service.ts +2 -3
- package/backend/snapshot/blob-store.ts +9 -1
- package/backend/snapshot/helpers.ts +3 -11
- package/backend/snapshot/line-stats.test.ts +80 -0
- package/backend/snapshot/line-stats.ts +64 -0
- package/backend/snapshot/restore.ts +252 -0
- package/backend/snapshot/snapshot-service.ts +14 -27
- package/backend/snapshot/turn-changes.test.ts +10 -5
- package/backend/snapshot/turn-changes.ts +78 -40
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +10 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws-wire.test.ts +87 -0
- package/backend/utils/ws-wire.ts +189 -0
- package/backend/utils/ws.ts +101 -192
- package/backend/worktrees/branching/engine.ts +3 -16
- package/backend/worktrees/branching/index.ts +1 -1
- package/backend/worktrees/branching/projector.ts +1 -1
- package/backend/worktrees/branching/service.ts +13 -25
- package/backend/ws/access.ts +12 -21
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/auth/device.ts +16 -71
- package/backend/ws/auth/index.ts +4 -22
- package/backend/ws/auth/login.test.ts +14 -60
- package/backend/ws/auth/login.ts +24 -124
- package/backend/ws/auth/status.ts +0 -1
- package/backend/ws/chat/composer.ts +118 -118
- package/backend/ws/chat/stream.ts +105 -57
- package/backend/ws/chat-apps/index.ts +117 -0
- package/backend/ws/containers/actions.ts +11 -25
- package/backend/ws/containers/index.ts +3 -4
- package/backend/ws/containers/list.ts +10 -36
- package/backend/ws/containers/logs.ts +2 -2
- package/backend/ws/containers/tunnel.ts +1 -2
- package/backend/ws/db-client/access.ts +2 -16
- package/backend/ws/db-client/accounts.ts +5 -15
- package/backend/ws/db-client/connections.ts +17 -25
- package/backend/ws/db-client/context.ts +1 -1
- package/backend/ws/db-client/env.ts +7 -10
- package/backend/ws/db-client/index.ts +2 -2
- package/backend/ws/db-client/io.ts +5 -5
- package/backend/ws/db-client/query-history-retention.test.ts +8 -8
- package/backend/ws/db-client/query.ts +18 -17
- package/backend/ws/db-client/schema.ts +13 -13
- package/backend/ws/db-client/structure.ts +35 -35
- package/backend/ws/db-client/supabase.ts +4 -21
- package/backend/ws/deployments/context.ts +1 -1
- package/backend/ws/deployments/crud.ts +0 -5
- package/backend/ws/engine/access.ts +7 -20
- package/backend/ws/engine/claude/accounts.ts +4 -4
- package/backend/ws/engine/cline/accounts.ts +5 -5
- package/backend/ws/engine/codex/accounts.ts +3 -3
- package/backend/ws/engine/pi/accounts.ts +5 -5
- package/backend/ws/files/clipboard.ts +8 -27
- package/backend/ws/files/image-edit.ts +6 -6
- package/backend/ws/files/index.ts +1 -1
- package/backend/ws/files/path-access.test.ts +32 -131
- package/backend/ws/files/path-access.ts +8 -87
- package/backend/ws/files/read.ts +45 -19
- package/backend/ws/files/reveal.ts +3 -3
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/share.ts +9 -13
- package/backend/ws/files/state.ts +9 -12
- package/backend/ws/files/watch.ts +3 -3
- package/backend/ws/files/write.ts +30 -31
- package/backend/ws/git/branch.ts +80 -59
- package/backend/ws/git/commit.ts +63 -44
- package/backend/ws/git/conflict.ts +16 -18
- package/backend/ws/git/identity-context.ts +8 -17
- package/backend/ws/git/identity.ts +17 -27
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/log.ts +52 -0
- package/backend/ws/git/op-state.ts +139 -0
- package/backend/ws/git/remote.ts +241 -141
- package/backend/ws/git/repo-context.ts +67 -0
- package/backend/ws/git/staging.ts +18 -28
- package/backend/ws/git/status.ts +5 -2
- package/backend/ws/index.ts +5 -1
- package/backend/ws/instructions/crud.ts +1 -1
- package/backend/ws/integrations/crud.ts +1 -3
- package/backend/ws/mcp/crud.ts +3 -5
- package/backend/ws/mcp/tools.ts +1 -1
- package/backend/ws/memory/crud.ts +14 -46
- package/backend/ws/memory/index.ts +2 -2
- package/backend/ws/messages/crud.ts +78 -8
- package/backend/ws/notes/index.ts +33 -39
- package/backend/ws/permissions/crud.ts +3 -4
- package/backend/ws/ports/index.ts +1 -2
- package/backend/ws/ports/kill.ts +5 -10
- package/backend/ws/ports/list.ts +4 -10
- package/backend/ws/preview/access.ts +1 -1
- package/backend/ws/preview/browser/interact.ts +52 -79
- package/backend/ws/preview/browser/native-ui.ts +24 -0
- package/backend/ws/preview/browser/stats.ts +98 -1
- package/backend/ws/preview/browser/tab-info.ts +15 -0
- package/backend/ws/preview/browser/tab.ts +19 -4
- package/backend/ws/preview/index.ts +29 -0
- package/backend/ws/preview/watchers.ts +84 -0
- package/backend/ws/profiles/crud.ts +6 -8
- package/backend/ws/project-artifacts/index.ts +30 -31
- package/backend/ws/projects/crud.ts +33 -35
- package/backend/ws/projects/index.ts +3 -8
- package/backend/ws/projects/info.ts +3 -3
- package/backend/ws/projects/overview.ts +19 -30
- package/backend/ws/projects/status.ts +17 -57
- package/backend/ws/sessions/crud.ts +42 -57
- package/backend/ws/sessions/index.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/skills/crud.ts +3 -4
- package/backend/ws/skills/index.ts +1 -1
- package/backend/ws/snapshot/changes.ts +12 -13
- package/backend/ws/snapshot/restore.ts +11 -295
- package/backend/ws/snapshot/timeline.ts +2 -4
- package/backend/ws/ssh/access.ts +6 -21
- package/backend/ws/ssh/connections.ts +21 -31
- package/backend/ws/ssh/forwards.ts +12 -12
- package/backend/ws/ssh/sftp.ts +34 -34
- package/backend/ws/ssh/tunnel.ts +1 -2
- package/backend/ws/stack/install.ts +7 -17
- package/backend/ws/subagents/crud.ts +1 -1
- package/backend/ws/terminal/tunnel.ts +2 -2
- package/backend/ws/tunnel/share.ts +0 -2
- package/backend/ws/user/crud.ts +1 -59
- package/backend/ws/user/index.ts +1 -1
- package/backend/ws/work/context.ts +1 -1
- package/backend/ws/work/crud.ts +0 -5
- package/backend/ws/workspace/state.ts +10 -13
- package/backend/ws/worktrees/branching.ts +7 -36
- package/backend/ws/worktrees/crud.ts +2 -2
- package/bin/clopen.ts +46 -41
- package/dist/assets/addon-clipboard-wHJhZAA4.js.br +0 -0
- package/dist/assets/addon-clipboard-wHJhZAA4.js.gz +0 -0
- package/dist/assets/addon-fit-DX4qG4td.js.br +1 -0
- package/dist/assets/addon-fit-DX4qG4td.js.gz +0 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js.br +0 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js.gz +0 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js.br +0 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js.gz +0 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js.br +0 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js.gz +0 -0
- package/dist/assets/diff.worker-BoHLxmr2.js +7 -0
- package/dist/assets/diff.worker-BoHLxmr2.js.br +0 -0
- package/dist/assets/diff.worker-BoHLxmr2.js.gz +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
- package/dist/assets/{index-CwuKQelV.js → index-CrVWZH_D.js} +1 -1
- package/dist/assets/index-CrVWZH_D.js.br +0 -0
- package/dist/assets/index-CrVWZH_D.js.gz +0 -0
- package/dist/assets/{index-BTcR1byF.js → index-DD0-3EWg.js} +1 -1
- package/dist/assets/index-DD0-3EWg.js.br +0 -0
- package/dist/assets/index-DD0-3EWg.js.gz +0 -0
- package/dist/assets/main-D2_TmcwQ.js +1240 -0
- package/dist/assets/main-D2_TmcwQ.js.br +0 -0
- package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
- package/dist/assets/main-Yucigcmf.css +1 -0
- package/dist/assets/main-Yucigcmf.css.br +0 -0
- package/dist/assets/main-Yucigcmf.css.gz +0 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js.br +0 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js.gz +0 -0
- package/dist/assets/xterm-B-qIQCd3.js.br +0 -0
- package/dist/assets/xterm-B-qIQCd3.js.gz +0 -0
- package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.br +0 -0
- package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.gz +0 -0
- package/dist/fonts/dm-sans.css.br +0 -0
- package/dist/fonts/dm-sans.css.gz +0 -0
- package/dist/index.html +2 -2
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/dist/sw.js.br +0 -0
- package/dist/sw.js.gz +0 -0
- package/package.json +3 -3
- package/shared/constants/attachments.ts +14 -0
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/preview.test.ts +259 -0
- package/shared/constants/preview.ts +1018 -57
- package/shared/constants/tool-icons.ts +5 -0
- package/shared/types/containers/container.ts +1 -1
- package/shared/types/database/schema.ts +9 -6
- package/shared/types/git-identity.ts +1 -1
- package/shared/types/git.ts +116 -0
- package/shared/types/integrations.ts +7 -0
- package/shared/types/stores/settings.ts +1 -1
- package/shared/types/unified/index.ts +1 -1
- package/shared/types/unified/message.ts +0 -7
- package/shared/types/unified/stream.ts +13 -5
- package/shared/types/unified/tool.ts +15 -1
- package/shared/utils/ask-user-question.test.ts +319 -0
- package/shared/utils/ask-user-question.ts +154 -0
- package/shared/utils/diff-calculator.test.ts +178 -41
- package/shared/utils/diff-calculator.ts +383 -100
- package/shared/utils/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/process-supervisor.test.ts +172 -0
- package/shared/utils/process-supervisor.ts +251 -0
- package/shared/utils/ws-chunk.test.ts +33 -0
- package/shared/utils/ws-chunk.ts +73 -0
- package/shared/utils/ws-client-chunks.test.ts +45 -0
- package/shared/utils/ws-client.ts +43 -0
- package/shared/utils/ws-server.ts +49 -21
- package/backend/auth/session-invalidation.test.ts +0 -112
- package/backend/auth/session-invalidation.ts +0 -77
- package/backend/project/status-manager.test.ts +0 -32
- package/backend/ws/auth/invites.ts +0 -94
- package/backend/ws/auth/users.ts +0 -112
- package/backend/ws/projects/presence.ts +0 -46
- package/backend/ws/stack/access.ts +0 -31
- package/dist/assets/main-BiDNMWb3.css +0 -1
- package/dist/assets/main-BlhKWz2B.js +0 -1241
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { EventEmitter } from 'events';
|
|
21
|
-
import type { CDPSession, ElementHandle, KeyInput, Page } from 'puppeteer';
|
|
21
|
+
import type { CDPSession, ElementHandle, Frame, KeyInput, Page } from 'puppeteer';
|
|
22
22
|
import type {
|
|
23
23
|
BrowserActionResult,
|
|
24
24
|
BrowserActionTarget,
|
|
@@ -29,33 +29,71 @@ import { debug } from '$shared/utils/logger';
|
|
|
29
29
|
import { sleep } from '$shared/utils/async';
|
|
30
30
|
import { browserMcpControl } from './browser-mcp-control';
|
|
31
31
|
import { isNativeDraggable, resolveHandle, resolveTarget } from './element-locator';
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
ctrl: 'Control',
|
|
36
|
-
control: 'Control',
|
|
37
|
-
shift: 'Shift',
|
|
38
|
-
alt: 'Alt',
|
|
39
|
-
option: 'Alt',
|
|
40
|
-
meta: 'Meta',
|
|
41
|
-
cmd: 'Meta',
|
|
42
|
-
command: 'Meta',
|
|
43
|
-
super: 'Meta',
|
|
44
|
-
win: 'Meta'
|
|
45
|
-
};
|
|
32
|
+
import { isPasteChord, parseChord, pressChord, selectAll } from './keyboard-chords';
|
|
33
|
+
import { pasteText } from './paste';
|
|
34
|
+
import type { PendingDialogInfo } from './browser-dialog-handler';
|
|
46
35
|
|
|
47
36
|
export interface AutonomousRunOutcome {
|
|
48
37
|
results: BrowserActionResult[];
|
|
49
38
|
/** True when the run stopped early because the tab or the stream went away. */
|
|
50
39
|
aborted: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* The dialog that stopped the run. A page with a dialog open runs no script,
|
|
42
|
+
* so nothing after it could have worked — the agent has to answer it first.
|
|
43
|
+
*/
|
|
44
|
+
blockedBy?: PendingDialogInfo;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface InteractionDeps {
|
|
48
|
+
/** The workspace clipboard — what a paste pastes. */
|
|
49
|
+
readClipboard(): string;
|
|
50
|
+
getPendingDialog(tabId: string): PendingDialogInfo | null;
|
|
51
|
+
waitForDialog(tabId: string): { promise: Promise<PendingDialogInfo>; dispose: () => void };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Thrown inside an action that a dialog cut short, so its loops stop. */
|
|
55
|
+
class DialogInterrupt extends Error {
|
|
56
|
+
constructor() {
|
|
57
|
+
super('interrupted by a dialog');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* How long a new batch waits for the previous one's interrupted action to
|
|
63
|
+
* unwind. That action is parked inside a CDP call the dialog blocked; once the
|
|
64
|
+
* dialog is answered it resumes, hits its next checkpoint and stops — but it
|
|
65
|
+
* must finish doing so before new input starts, or the two would interleave.
|
|
66
|
+
*/
|
|
67
|
+
const INFLIGHT_SETTLE_MS = 5_000;
|
|
68
|
+
|
|
69
|
+
/** What a focused editable reads, and where it lives. */
|
|
70
|
+
interface FocusedField {
|
|
71
|
+
frame: Frame;
|
|
72
|
+
kind: 'input' | 'textarea' | 'editable';
|
|
73
|
+
value: string;
|
|
74
|
+
secret: boolean;
|
|
51
75
|
}
|
|
52
76
|
|
|
53
77
|
export class BrowserInteractionHandler extends EventEmitter {
|
|
54
78
|
// Track cursor positions per session
|
|
55
79
|
private sessionCursorPositions: Map<string, { x: number; y: number }> = new Map();
|
|
56
80
|
|
|
57
|
-
|
|
81
|
+
/** Per tab: whether the batch running on it was cut short by a dialog. */
|
|
82
|
+
private runTokens = new Map<string, { interrupted: boolean }>();
|
|
83
|
+
|
|
84
|
+
/** Per tab: the action still unwinding from an interrupted batch. */
|
|
85
|
+
private inflight = new Map<string, Promise<unknown>>();
|
|
86
|
+
|
|
87
|
+
private deps: InteractionDeps;
|
|
88
|
+
|
|
89
|
+
constructor(deps: InteractionDeps) {
|
|
58
90
|
super();
|
|
91
|
+
this.deps = deps;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Stop here if a dialog has cut this tab's batch short. */
|
|
95
|
+
private checkpoint(sessionId: string): void {
|
|
96
|
+
if (this.runTokens.get(sessionId)?.interrupted) throw new DialogInterrupt();
|
|
59
97
|
}
|
|
60
98
|
|
|
61
99
|
// ========================================================================
|
|
@@ -78,6 +116,39 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
78
116
|
browserMcpControl.emitCursorClick(sessionId, x, y, button);
|
|
79
117
|
}
|
|
80
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Announce a whole pointer movement at once.
|
|
121
|
+
*
|
|
122
|
+
* The overlay used to be fed one event per interpolation step, 16ms apart,
|
|
123
|
+
* and drew whatever arrived. Any delay on the way — a busy event loop, a
|
|
124
|
+
* congested socket — bunched those events up, and the pointer stuttered
|
|
125
|
+
* across the page. The viewer now gets the path and its duration and
|
|
126
|
+
* animates it locally, so the motion is smooth whatever the server is
|
|
127
|
+
* doing; the position the pointer comes to rest at still follows as a
|
|
128
|
+
* normal cursor event.
|
|
129
|
+
*/
|
|
130
|
+
private publishGlide(
|
|
131
|
+
sessionId: string,
|
|
132
|
+
glide: {
|
|
133
|
+
from: { x: number; y: number };
|
|
134
|
+
control: { x: number; y: number };
|
|
135
|
+
to: { x: number; y: number };
|
|
136
|
+
durationMs: number;
|
|
137
|
+
pressed?: boolean;
|
|
138
|
+
easing?: 'out' | 'linear';
|
|
139
|
+
}
|
|
140
|
+
) {
|
|
141
|
+
this.updateCursorPosition(sessionId, glide.to.x, glide.to.y);
|
|
142
|
+
browserMcpControl.emitCursorGlide(sessionId, {
|
|
143
|
+
from: glide.from,
|
|
144
|
+
control: glide.control,
|
|
145
|
+
to: glide.to,
|
|
146
|
+
durationMs: Math.max(0, Math.round(glide.durationMs)),
|
|
147
|
+
pressed: !!glide.pressed,
|
|
148
|
+
easing: glide.easing ?? 'out'
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
81
152
|
/**
|
|
82
153
|
* A few words for the caption beside the agent's pointer.
|
|
83
154
|
*
|
|
@@ -143,9 +214,21 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
143
214
|
|
|
144
215
|
// Get session for emitting cursor position
|
|
145
216
|
const sessionId = (page as any).__sessionId;
|
|
146
|
-
const
|
|
217
|
+
const stepDelay = opts.totalMs ? Math.max(0, opts.totalMs / Math.max(1, steps)) : 20;
|
|
218
|
+
|
|
219
|
+
// One announcement for the whole path; the viewer animates it.
|
|
220
|
+
if (sessionId) {
|
|
221
|
+
this.publishGlide(sessionId, {
|
|
222
|
+
from: { x: fromX, y: fromY },
|
|
223
|
+
control: { x: controlPointX, y: controlPointY },
|
|
224
|
+
to: { x: toX, y: toY },
|
|
225
|
+
durationMs: steps * stepDelay,
|
|
226
|
+
pressed: opts.pressed
|
|
227
|
+
});
|
|
228
|
+
}
|
|
147
229
|
|
|
148
230
|
for (let i = 0; i <= steps; i++) {
|
|
231
|
+
if (sessionId) this.checkpoint(sessionId);
|
|
149
232
|
const t = i / steps;
|
|
150
233
|
|
|
151
234
|
// Apply ease-out cubic easing: starts fast, ends slow
|
|
@@ -157,17 +240,16 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
157
240
|
|
|
158
241
|
await page.mouse.move(x, y);
|
|
159
242
|
|
|
160
|
-
// Emit cursor position for visual tracking
|
|
161
|
-
if (sessionId) this.publishCursor(sessionId, x, y, opts.pressed);
|
|
162
|
-
|
|
163
243
|
// Smooth delay between movements (15-25ms) for MCP automation
|
|
164
|
-
await sleep(
|
|
244
|
+
await sleep(opts.totalMs ? stepDelay : 15 + Math.random() * 10);
|
|
165
245
|
}
|
|
166
246
|
}
|
|
167
247
|
|
|
168
248
|
// MCP-optimized typing with fast, consistent speed
|
|
169
249
|
private async mcpType(page: Page, text: string, baseDelay: number = 30) {
|
|
250
|
+
const sessionId = (page as any).__sessionId;
|
|
170
251
|
for (let i = 0; i < text.length; i++) {
|
|
252
|
+
if (sessionId) this.checkpoint(sessionId);
|
|
171
253
|
const char = text[i];
|
|
172
254
|
|
|
173
255
|
// Fast typing with slight variance (20-40ms) for MCP automation
|
|
@@ -288,16 +370,16 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
288
370
|
return;
|
|
289
371
|
}
|
|
290
372
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
373
|
+
// Same ease-out as the real glide, so the two read as one pointer.
|
|
374
|
+
const durationMs = steps * 16;
|
|
375
|
+
this.publishGlide(sessionId, {
|
|
376
|
+
from,
|
|
377
|
+
control: { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 },
|
|
378
|
+
to,
|
|
379
|
+
durationMs
|
|
380
|
+
});
|
|
381
|
+
await sleep(durationMs);
|
|
382
|
+
this.checkpoint(sessionId);
|
|
301
383
|
|
|
302
384
|
this.publishCursor(sessionId, to.x, to.y);
|
|
303
385
|
}
|
|
@@ -376,24 +458,6 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
376
458
|
if (opts.pulse) this.publishClick(sessionId, point.x, point.y);
|
|
377
459
|
}
|
|
378
460
|
|
|
379
|
-
/** "Control+Shift+K" → modifiers to hold plus the key to press. */
|
|
380
|
-
private parseChord(chord: string): { modifiers: Array<'Control' | 'Shift' | 'Alt' | 'Meta'>; key: string } {
|
|
381
|
-
const parts = chord.split('+').map((p) => p.trim()).filter(Boolean);
|
|
382
|
-
const modifiers: Array<'Control' | 'Shift' | 'Alt' | 'Meta'> = [];
|
|
383
|
-
let key = '';
|
|
384
|
-
|
|
385
|
-
for (const part of parts) {
|
|
386
|
-
const modifier = MODIFIER_ALIASES[part.toLowerCase()];
|
|
387
|
-
if (modifier) {
|
|
388
|
-
if (!modifiers.includes(modifier)) modifiers.push(modifier);
|
|
389
|
-
} else {
|
|
390
|
-
key = part;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return { modifiers, key };
|
|
395
|
-
}
|
|
396
|
-
|
|
397
461
|
/**
|
|
398
462
|
* Touch has to be turned on before it can be dispatched: without emulation
|
|
399
463
|
* the renderer drops touch events and the page's own feature detection
|
|
@@ -402,15 +466,128 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
402
466
|
*/
|
|
403
467
|
private async withTouch<T>(page: Page, fn: (client: CDPSession) => Promise<T>): Promise<T> {
|
|
404
468
|
const client = await page.createCDPSession();
|
|
469
|
+
// A phone or tablet tab has touch on for good — its page was built
|
|
470
|
+
// around it. Switching it off after the gesture would leave that page
|
|
471
|
+
// believing it had lost its touchscreen.
|
|
472
|
+
const touchIsPermanent = page.viewport()?.hasTouch === true;
|
|
405
473
|
try {
|
|
406
|
-
|
|
474
|
+
if (!touchIsPermanent) {
|
|
475
|
+
await client.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 2 });
|
|
476
|
+
}
|
|
407
477
|
return await fn(client);
|
|
408
478
|
} finally {
|
|
409
|
-
|
|
479
|
+
if (!touchIsPermanent) {
|
|
480
|
+
await client.send('Emulation.setTouchEmulationEnabled', { enabled: false }).catch(() => {});
|
|
481
|
+
}
|
|
410
482
|
await client.detach().catch(() => {});
|
|
411
483
|
}
|
|
412
484
|
}
|
|
413
485
|
|
|
486
|
+
// ========================================================================
|
|
487
|
+
// Field verification
|
|
488
|
+
// ========================================================================
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* The focused editable field and what it reads, in whichever frame has it.
|
|
492
|
+
* Null when focus is on something that is not a text field.
|
|
493
|
+
*/
|
|
494
|
+
private async readFocusedField(page: Page): Promise<FocusedField | null> {
|
|
495
|
+
const frames = page.frames().filter((frame) => !frame.isDetached());
|
|
496
|
+
// Child frames first: when focus is inside one, the main frame only
|
|
497
|
+
// reports the <iframe> element.
|
|
498
|
+
for (const frame of [...frames.slice(1), frames[0]].filter(Boolean)) {
|
|
499
|
+
try {
|
|
500
|
+
const field = await frame.evaluate(() => {
|
|
501
|
+
let active: Element | null = document.activeElement;
|
|
502
|
+
while (active && (active as HTMLElement).shadowRoot?.activeElement) {
|
|
503
|
+
active = (active as HTMLElement).shadowRoot!.activeElement;
|
|
504
|
+
}
|
|
505
|
+
if (!active || active === document.body || active.tagName === 'IFRAME') return null;
|
|
506
|
+
|
|
507
|
+
if (active.tagName === 'INPUT') {
|
|
508
|
+
const type = ((active as HTMLInputElement).type || 'text').toLowerCase();
|
|
509
|
+
const nonText = ['checkbox', 'radio', 'button', 'submit', 'reset', 'file', 'range', 'color', 'image'];
|
|
510
|
+
if (nonText.includes(type)) return null;
|
|
511
|
+
return { kind: 'input' as const, value: (active as HTMLInputElement).value, secret: type === 'password' };
|
|
512
|
+
}
|
|
513
|
+
if (active.tagName === 'TEXTAREA') {
|
|
514
|
+
return { kind: 'textarea' as const, value: (active as HTMLTextAreaElement).value, secret: false };
|
|
515
|
+
}
|
|
516
|
+
if ((active as HTMLElement).isContentEditable) {
|
|
517
|
+
return { kind: 'editable' as const, value: (active as HTMLElement).innerText, secret: false };
|
|
518
|
+
}
|
|
519
|
+
return null;
|
|
520
|
+
});
|
|
521
|
+
if (field) return { frame, ...field };
|
|
522
|
+
} catch {
|
|
523
|
+
// Frame navigated away mid-read.
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Confirm a fill replaced what was there, and make it so if it did not.
|
|
531
|
+
*
|
|
532
|
+
* Select-all is a keyboard shortcut, and a page can swallow it — a
|
|
533
|
+
* controlled React input that re-renders between the keystrokes, a widget
|
|
534
|
+
* that binds Ctrl/⌘+A to something else. When that happens the new text
|
|
535
|
+
* lands beside the old ("ABC" + "DEF" = "ABCDEF"), and the agent, told it
|
|
536
|
+
* typed six characters, carried on with a corrupted form. So the field is
|
|
537
|
+
* read back: if the old text is still in it, the value is set through the
|
|
538
|
+
* native setter with an input event (which is what frameworks bind to), and
|
|
539
|
+
* if even that does not hold, the action fails with what the field reads.
|
|
540
|
+
*
|
|
541
|
+
* A field that reformats its input (a phone mask, thousands separators) is
|
|
542
|
+
* not a failure: the agent is simply told what the field now reads.
|
|
543
|
+
*/
|
|
544
|
+
private async settleFill(page: Page, text: string, before: FocusedField | null, label?: string): Promise<string> {
|
|
545
|
+
const done = label ?? `typed ${text.length} char(s)`;
|
|
546
|
+
const after = await this.readFocusedField(page);
|
|
547
|
+
if (!after || after.value === text) return done;
|
|
548
|
+
|
|
549
|
+
const show = (field: FocusedField) =>
|
|
550
|
+
field.secret ? '(hidden: password field)' : `"${field.value.length > 120 ? `${field.value.slice(0, 120)}…` : field.value}"`;
|
|
551
|
+
|
|
552
|
+
const leftover = !!before?.value && after.value.includes(before.value);
|
|
553
|
+
if (!leftover) return `${done} → the field reads ${show(after)}`;
|
|
554
|
+
|
|
555
|
+
await after.frame
|
|
556
|
+
.evaluate((value: string) => {
|
|
557
|
+
let active: Element | null = document.activeElement;
|
|
558
|
+
while (active && (active as HTMLElement).shadowRoot?.activeElement) {
|
|
559
|
+
active = (active as HTMLElement).shadowRoot!.activeElement;
|
|
560
|
+
}
|
|
561
|
+
if (!active) return;
|
|
562
|
+
|
|
563
|
+
if (active.tagName === 'INPUT' || active.tagName === 'TEXTAREA') {
|
|
564
|
+
const proto = active.tagName === 'INPUT' ? HTMLInputElement.prototype : HTMLTextAreaElement.prototype;
|
|
565
|
+
// The prototype's setter, not the element's: React shadows `value`
|
|
566
|
+
// on the instance and would otherwise swallow the change.
|
|
567
|
+
Object.getOwnPropertyDescriptor(proto, 'value')?.set?.call(active, value);
|
|
568
|
+
active.dispatchEvent(new Event('input', { bubbles: true }));
|
|
569
|
+
active.dispatchEvent(new Event('change', { bubbles: true }));
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if ((active as HTMLElement).isContentEditable) {
|
|
574
|
+
window.getSelection()?.selectAllChildren(active);
|
|
575
|
+
if (value) document.execCommand('insertText', false, value);
|
|
576
|
+
else document.execCommand('delete');
|
|
577
|
+
}
|
|
578
|
+
}, text)
|
|
579
|
+
.catch(() => {});
|
|
580
|
+
|
|
581
|
+
const fixed = await this.readFocusedField(page);
|
|
582
|
+
if (!fixed || fixed.value === text) {
|
|
583
|
+
return `${done} (select-all did not take in this field, so the value was set directly)`;
|
|
584
|
+
}
|
|
585
|
+
if (before?.value && fixed.value.includes(before.value)) {
|
|
586
|
+
throw new Error(`could not replace the field's previous text — it reads ${show(fixed)}`);
|
|
587
|
+
}
|
|
588
|
+
return `${done} (value set directly) → the field reads ${show(fixed)}`;
|
|
589
|
+
}
|
|
590
|
+
|
|
414
591
|
// ========================================================================
|
|
415
592
|
// Batch execution
|
|
416
593
|
// ========================================================================
|
|
@@ -453,6 +630,21 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
453
630
|
const parked = this.getCurrentMousePosition(sessionId);
|
|
454
631
|
this.publishCursor(sessionId, parked.x, parked.y);
|
|
455
632
|
|
|
633
|
+
// While the dialog is still open there is nothing to wait for: the
|
|
634
|
+
// interrupted action stays parked behind it, so say so straight away.
|
|
635
|
+
const stillOpen = this.deps.getPendingDialog(sessionId);
|
|
636
|
+
if (stillOpen) return { results, aborted: false, blockedBy: stillOpen };
|
|
637
|
+
|
|
638
|
+
// The previous batch's interrupted action has to have stopped before
|
|
639
|
+
// this one moves the pointer or types anything.
|
|
640
|
+
const previous = this.inflight.get(sessionId);
|
|
641
|
+
if (previous) {
|
|
642
|
+
await Promise.race([previous, sleep(INFLIGHT_SETTLE_MS)]);
|
|
643
|
+
this.inflight.delete(sessionId);
|
|
644
|
+
}
|
|
645
|
+
const token = { interrupted: false };
|
|
646
|
+
this.runTokens.set(sessionId, token);
|
|
647
|
+
|
|
456
648
|
for (let i = 0; i < actions.length; i++) {
|
|
457
649
|
// Check if session is still valid before each action
|
|
458
650
|
if (!isValidSession()) {
|
|
@@ -460,11 +652,40 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
460
652
|
return { results, aborted: true };
|
|
461
653
|
}
|
|
462
654
|
|
|
655
|
+
// A page with a dialog open runs nothing: no click lands, no read
|
|
656
|
+
// returns. Saying so now beats every later action hanging on it.
|
|
657
|
+
const open = this.deps.getPendingDialog(sessionId);
|
|
658
|
+
if (open) return { results, aborted: false, blockedBy: open };
|
|
659
|
+
|
|
463
660
|
const action = actions[i];
|
|
464
661
|
browserMcpControl.emitActivity(sessionId, this.describeActivity(action));
|
|
465
662
|
|
|
663
|
+
const run = this.runAction(sessionId, session, action);
|
|
664
|
+
const dialog = this.deps.waitForDialog(sessionId);
|
|
665
|
+
|
|
466
666
|
try {
|
|
467
|
-
const
|
|
667
|
+
const winner = await Promise.race([
|
|
668
|
+
run.then((outcome) => ({ kind: 'done' as const, outcome })),
|
|
669
|
+
dialog.promise.then((info) => ({ kind: 'dialog' as const, info }))
|
|
670
|
+
]);
|
|
671
|
+
|
|
672
|
+
if (winner.kind === 'dialog') {
|
|
673
|
+
// The action is parked inside a call the dialog blocked. Tell its
|
|
674
|
+
// loops to stop at their next checkpoint, and remember it so the
|
|
675
|
+
// next batch waits for it to unwind.
|
|
676
|
+
token.interrupted = true;
|
|
677
|
+
this.inflight.set(sessionId, run.catch(() => {}));
|
|
678
|
+
|
|
679
|
+
results.push({
|
|
680
|
+
action: action.type,
|
|
681
|
+
ok: true,
|
|
682
|
+
detail: `a ${winner.info.type} dialog opened during this action`,
|
|
683
|
+
timestamp: Date.now()
|
|
684
|
+
});
|
|
685
|
+
return { results, aborted: false, blockedBy: winner.info };
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
const outcome = winner.outcome;
|
|
468
689
|
results.push({
|
|
469
690
|
action: action.type,
|
|
470
691
|
ok: true,
|
|
@@ -490,6 +711,8 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
490
711
|
debug.warn('preview', `⚠️ Browser/page closed during action ${i + 1}/${actions.length}, stopping autonomous actions`);
|
|
491
712
|
return { results, aborted: true };
|
|
492
713
|
}
|
|
714
|
+
} finally {
|
|
715
|
+
dialog.dispose();
|
|
493
716
|
}
|
|
494
717
|
|
|
495
718
|
// Fast delay between actions for MCP automation (50-100ms)
|
|
@@ -699,17 +922,19 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
699
922
|
}
|
|
700
923
|
|
|
701
924
|
const shouldClear = action.clearFirst !== false;
|
|
702
|
-
if (shouldClear && action.text) {
|
|
703
|
-
// Select all, then typing overwrites the selection.
|
|
704
|
-
await page.keyboard.down('Control');
|
|
705
|
-
await page.keyboard.press('KeyA');
|
|
706
|
-
await page.keyboard.up('Control');
|
|
707
|
-
await sleep(30);
|
|
708
|
-
}
|
|
709
925
|
|
|
710
|
-
if (action.text) {
|
|
926
|
+
if (action.text !== undefined) {
|
|
927
|
+
const before = shouldClear ? await this.readFocusedField(page) : null;
|
|
928
|
+
if (shouldClear) {
|
|
929
|
+
// Select all, then typing overwrites the selection.
|
|
930
|
+
await selectAll(page);
|
|
931
|
+
await sleep(30);
|
|
932
|
+
}
|
|
933
|
+
|
|
711
934
|
await this.mcpType(page, action.text, action.delay ?? 30);
|
|
712
|
-
|
|
935
|
+
|
|
936
|
+
if (!shouldClear) return `typed ${action.text.length} char(s)`;
|
|
937
|
+
return this.settleFill(page, action.text, before);
|
|
713
938
|
}
|
|
714
939
|
if (action.key) {
|
|
715
940
|
await page.keyboard.press(action.key as KeyInput);
|
|
@@ -722,39 +947,37 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
722
947
|
const chord = action.keys || action.key;
|
|
723
948
|
if (!chord) throw new Error('press needs `keys`');
|
|
724
949
|
|
|
725
|
-
const { modifiers, key } =
|
|
950
|
+
const { modifiers, key } = parseChord(chord);
|
|
726
951
|
if (!key) throw new Error(`press could not find a key in "${chord}"`);
|
|
727
952
|
|
|
728
953
|
await this.showFocused(sessionId, page, { pulse: true });
|
|
729
954
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
}
|
|
955
|
+
// A paste chord pastes the workspace clipboard: the headless
|
|
956
|
+
// browser's own is not the one anything was copied into.
|
|
957
|
+
if (isPasteChord(modifiers, key)) {
|
|
958
|
+
const text = this.deps.readClipboard();
|
|
959
|
+
if (!text) return `pressed ${chord} — the clipboard is empty, nothing pasted`;
|
|
960
|
+
const how = await pasteText(page, text);
|
|
961
|
+
return `pressed ${chord} → pasted ${text.length} char(s) from the clipboard${how === 'handled-by-page' ? ' (handled by the page)' : ''}`;
|
|
737
962
|
}
|
|
738
963
|
|
|
964
|
+
await pressChord(page, modifiers, key);
|
|
739
965
|
return `pressed ${chord}`;
|
|
740
966
|
}
|
|
741
967
|
|
|
742
968
|
case 'paste': {
|
|
743
|
-
|
|
969
|
+
// No text means "paste the clipboard" — what Ctrl/⌘+V does.
|
|
970
|
+
const text = typeof action.text === 'string' ? action.text : this.deps.readClipboard();
|
|
971
|
+
if (!text) throw new Error('paste needs `text`, and the clipboard is empty');
|
|
744
972
|
|
|
745
973
|
await this.showFocused(sessionId, page, { pulse: true });
|
|
746
974
|
|
|
747
|
-
//
|
|
748
|
-
//
|
|
749
|
-
//
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
} finally {
|
|
754
|
-
await client.detach().catch(() => {});
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
return `pasted ${action.text.length} char(s)`;
|
|
975
|
+
// A real paste: the `paste` event first (spreadsheets and rich
|
|
976
|
+
// editors only listen for that), then the text at the caret if the
|
|
977
|
+
// page did not take care of it.
|
|
978
|
+
const how = await pasteText(page, text);
|
|
979
|
+
const origin = typeof action.text === 'string' ? '' : ' from the clipboard';
|
|
980
|
+
return `pasted ${text.length} char(s)${origin}${how === 'handled-by-page' ? ' (handled by the page)' : ''}`;
|
|
758
981
|
}
|
|
759
982
|
|
|
760
983
|
case 'focus': {
|
|
@@ -785,12 +1008,11 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
785
1008
|
await this.showFocused(sessionId, page, { pulse: true });
|
|
786
1009
|
}
|
|
787
1010
|
|
|
788
|
-
await
|
|
789
|
-
await page
|
|
790
|
-
await page.keyboard.up('Control');
|
|
1011
|
+
const before = await this.readFocusedField(page);
|
|
1012
|
+
await selectAll(page);
|
|
791
1013
|
await page.keyboard.press('Backspace');
|
|
792
1014
|
|
|
793
|
-
return 'cleared field';
|
|
1015
|
+
return this.settleFill(page, '', before, 'cleared field');
|
|
794
1016
|
}
|
|
795
1017
|
|
|
796
1018
|
case 'select_option': {
|
|
@@ -896,16 +1118,24 @@ export class BrowserInteractionHandler extends EventEmitter {
|
|
|
896
1118
|
type: 'touchStart',
|
|
897
1119
|
touchPoints: [{ x: from.x, y: from.y, id: 1 }]
|
|
898
1120
|
});
|
|
1121
|
+
this.publishGlide(sessionId, {
|
|
1122
|
+
from,
|
|
1123
|
+
control: { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 },
|
|
1124
|
+
to,
|
|
1125
|
+
durationMs: totalMs,
|
|
1126
|
+
pressed: true,
|
|
1127
|
+
easing: 'linear'
|
|
1128
|
+
});
|
|
899
1129
|
|
|
900
1130
|
for (let s = 1; s <= steps; s++) {
|
|
901
1131
|
const t = s / steps;
|
|
902
1132
|
const x = Math.round(from.x + (to.x - from.x) * t);
|
|
903
1133
|
const y = Math.round(from.y + (to.y - from.y) * t);
|
|
1134
|
+
this.checkpoint(sessionId);
|
|
904
1135
|
await client.send('Input.dispatchTouchEvent', {
|
|
905
1136
|
type: 'touchMove',
|
|
906
1137
|
touchPoints: [{ x, y, id: 1 }]
|
|
907
1138
|
});
|
|
908
|
-
this.publishCursor(sessionId, x, y, true);
|
|
909
1139
|
await sleep(totalMs / steps);
|
|
910
1140
|
}
|
|
911
1141
|
|
|
@@ -80,6 +80,23 @@ export interface McpCursorEvent {
|
|
|
80
80
|
source: 'mcp';
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* A whole pointer movement, announced once and animated by the viewer.
|
|
85
|
+
* Quadratic Bezier from `from` through `control` to `to` over `durationMs`.
|
|
86
|
+
*/
|
|
87
|
+
export interface McpGlideEvent {
|
|
88
|
+
tabId: string;
|
|
89
|
+
projectId?: string;
|
|
90
|
+
from: { x: number; y: number };
|
|
91
|
+
control: { x: number; y: number };
|
|
92
|
+
to: { x: number; y: number };
|
|
93
|
+
durationMs: number;
|
|
94
|
+
pressed: boolean;
|
|
95
|
+
easing: 'out' | 'linear';
|
|
96
|
+
timestamp: number;
|
|
97
|
+
source: 'mcp';
|
|
98
|
+
}
|
|
99
|
+
|
|
83
100
|
export interface McpClickEvent {
|
|
84
101
|
tabId: string;
|
|
85
102
|
projectId?: string;
|
|
@@ -631,6 +648,23 @@ export class BrowserMcpControl extends EventEmitter {
|
|
|
631
648
|
this.emit('cursor-position', event);
|
|
632
649
|
}
|
|
633
650
|
|
|
651
|
+
/** Announce a pointer movement for the viewer to animate locally. */
|
|
652
|
+
emitCursorGlide(
|
|
653
|
+
tabId: string,
|
|
654
|
+
glide: Omit<McpGlideEvent, 'tabId' | 'projectId' | 'timestamp' | 'source'>
|
|
655
|
+
): void {
|
|
656
|
+
const ownership = this.tabOwnership.get(tabId);
|
|
657
|
+
if (!ownership) return;
|
|
658
|
+
|
|
659
|
+
this.emit('cursor-glide', {
|
|
660
|
+
tabId,
|
|
661
|
+
projectId: ownership.projectId,
|
|
662
|
+
...glide,
|
|
663
|
+
timestamp: Date.now(),
|
|
664
|
+
source: 'mcp'
|
|
665
|
+
} satisfies McpGlideEvent);
|
|
666
|
+
}
|
|
667
|
+
|
|
634
668
|
/**
|
|
635
669
|
* Emit cursor click event with MCP source. Silent after release — see
|
|
636
670
|
* `emitCursorPosition`.
|