@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
|
@@ -5,15 +5,19 @@ import { BrowserConsoleManager } from './browser-console-manager.js';
|
|
|
5
5
|
import { BrowserInteractionHandler, type AutonomousRunOutcome } from './browser-interaction-handler.js';
|
|
6
6
|
import { BrowserNavigationTracker } from './browser-navigation-tracker.js';
|
|
7
7
|
import { BrowserVideoCapture } from './browser-video-capture.js';
|
|
8
|
-
import { BrowserDialogHandler } from './browser-dialog-handler.js';
|
|
8
|
+
import { BrowserDialogHandler, type PendingDialogInfo } from './browser-dialog-handler.js';
|
|
9
9
|
import { BrowserNativeUIHandler } from './browser-native-ui-handler.js';
|
|
10
10
|
import { BrowserHostBridge, type HostResponse } from './browser-host-bridge.js';
|
|
11
11
|
import { BrowserTabLifecycle } from './browser-tab-lifecycle.js';
|
|
12
|
+
import { WorkspaceClipboard, type ClipboardSource } from './browser-clipboard.js';
|
|
12
13
|
import { browserMcpControl } from './browser-mcp-control.js';
|
|
13
14
|
import { browserPool } from './browser-pool.js';
|
|
14
15
|
import { ws } from '$backend/utils/ws';
|
|
15
|
-
import {
|
|
16
|
+
import { defaultRotation, type DeviceRequest } from '$shared/constants/preview.js';
|
|
17
|
+
import { applyViewport, type EmulationPatch } from './viewport';
|
|
16
18
|
import { debug } from '$shared/utils/logger';
|
|
19
|
+
import { emitToPreviewWatchers, forgetAgentCursor, rememberAgentCursor } from '../../ws/preview/watchers';
|
|
20
|
+
import { sleep } from '$shared/utils/async';
|
|
17
21
|
import { scopeProjectId } from '$shared/utils/workspace-scope';
|
|
18
22
|
import type {
|
|
19
23
|
BrowserSiteData,
|
|
@@ -23,6 +27,8 @@ import type {
|
|
|
23
27
|
BrowserAutonomousAction,
|
|
24
28
|
DeviceSize,
|
|
25
29
|
Rotation,
|
|
30
|
+
ViewportSize,
|
|
31
|
+
PageColors,
|
|
26
32
|
BrowserDialogResponse,
|
|
27
33
|
BrowserSelectResponse,
|
|
28
34
|
BrowserContextMenuResponse,
|
|
@@ -34,6 +40,17 @@ import type {
|
|
|
34
40
|
ClientStreamFeedback
|
|
35
41
|
} from './types';
|
|
36
42
|
|
|
43
|
+
/**
|
|
44
|
+
* How often a watched phone or tablet tab has its colours re-read. A page can
|
|
45
|
+
* change them without navigating — a theme toggle, an agent's colorScheme —
|
|
46
|
+
* and the bands around it would otherwise keep the old ones until the next
|
|
47
|
+
* load. One small evaluate per watched tab; most rounds emit nothing.
|
|
48
|
+
*/
|
|
49
|
+
const PAGE_COLORS_POLL_MS = 1500;
|
|
50
|
+
|
|
51
|
+
/** Time a window needs after leaving fullscreen before an override sticks. */
|
|
52
|
+
const WINDOW_SETTLE_MS = 150;
|
|
53
|
+
|
|
37
54
|
/**
|
|
38
55
|
* Browser Preview Service
|
|
39
56
|
*
|
|
@@ -57,6 +74,8 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
57
74
|
private nativeUIHandler: BrowserNativeUIHandler;
|
|
58
75
|
private hostBridge: BrowserHostBridge;
|
|
59
76
|
private lifecycle: BrowserTabLifecycle;
|
|
77
|
+
/** What was copied last in this workspace — see browser-clipboard.ts. */
|
|
78
|
+
private clipboard = new WorkspaceClipboard();
|
|
60
79
|
|
|
61
80
|
// Store context menu info for later action execution
|
|
62
81
|
private contextMenus = new Map<string, BrowserContextMenuInfo>();
|
|
@@ -95,17 +114,28 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
95
114
|
this.consoleManager = new BrowserConsoleManager({
|
|
96
115
|
isWatched: (tabId) => this.lifecycle.hasViewers(tabId)
|
|
97
116
|
});
|
|
98
|
-
this.interactionHandler = new BrowserInteractionHandler(
|
|
117
|
+
this.interactionHandler = new BrowserInteractionHandler({
|
|
118
|
+
readClipboard: () => this.clipboard.read(),
|
|
119
|
+
getPendingDialog: (tabId) => this.dialogHandler.getPendingDialog(tabId),
|
|
120
|
+
waitForDialog: (tabId) => this.dialogHandler.waitForDialog(tabId)
|
|
121
|
+
});
|
|
99
122
|
this.navigationTracker = new BrowserNavigationTracker();
|
|
100
123
|
this.videoCapture = new BrowserVideoCapture();
|
|
101
|
-
this.dialogHandler = new BrowserDialogHandler(
|
|
124
|
+
this.dialogHandler = new BrowserDialogHandler({
|
|
125
|
+
isAgentHeld: (tabId) => browserMcpControl.isTabControlled(tabId, this.projectId)
|
|
126
|
+
});
|
|
102
127
|
this.nativeUIHandler = new BrowserNativeUIHandler();
|
|
103
128
|
this.hostBridge = new BrowserHostBridge();
|
|
104
129
|
|
|
105
130
|
// Forward events from handlers to main service
|
|
106
131
|
this.setupEventForwarding();
|
|
132
|
+
|
|
133
|
+
this.pageColorsTimer = setInterval(() => void this.pollPageColors(), PAGE_COLORS_POLL_MS);
|
|
107
134
|
}
|
|
108
135
|
|
|
136
|
+
/** Re-reads the page colours of streaming handheld tabs; see `pollPageColors`. */
|
|
137
|
+
private pageColorsTimer: ReturnType<typeof setInterval> | null = null;
|
|
138
|
+
|
|
109
139
|
/**
|
|
110
140
|
* Tabs that must keep running even though nobody is watching them.
|
|
111
141
|
*
|
|
@@ -262,6 +292,12 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
262
292
|
this.videoCapture.on('connection-state', (data) => {
|
|
263
293
|
this.emit('preview:browser-webcodecs-connection-state', data);
|
|
264
294
|
});
|
|
295
|
+
// The captured surface lost the page's shape (Chrome's own fullscreen
|
|
296
|
+
// stranded it). Detected from the frames themselves, so it is caught
|
|
297
|
+
// whatever caused it — not only when the page's shim saw the fullscreen.
|
|
298
|
+
this.videoCapture.on('surface-drift', (data: { sessionId: string }) => {
|
|
299
|
+
void this.restoreEmulatedViewport(data.sessionId, null);
|
|
300
|
+
});
|
|
265
301
|
this.videoCapture.on('cursor-change', (data) => {
|
|
266
302
|
this.emit('preview:browser-cursor-change', data);
|
|
267
303
|
});
|
|
@@ -293,8 +329,18 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
293
329
|
this.applyFullscreenState(data.tabId, data.requestId, data.payload);
|
|
294
330
|
return;
|
|
295
331
|
}
|
|
332
|
+
if (this.answerClipboardRequest(data.tabId, data.requestId, data.kind, data.payload)) return;
|
|
296
333
|
this.emit('preview:browser-host-request', data);
|
|
297
334
|
});
|
|
335
|
+
// A clipboard read the viewer answered tells us what their device holds.
|
|
336
|
+
this.hostBridge.on('clipboard-observed', (data: { text: string }) => {
|
|
337
|
+
this.clipboard.write(data.text, 'device');
|
|
338
|
+
});
|
|
339
|
+
// Everything copied anywhere but on the device goes down to the devices,
|
|
340
|
+
// which is what keeps the user's clipboard and the workspace's in step.
|
|
341
|
+
this.clipboard.on('changed', (data) => {
|
|
342
|
+
this.emit('preview:browser-clipboard-sync', data);
|
|
343
|
+
});
|
|
298
344
|
this.hostBridge.on('download', (data) => {
|
|
299
345
|
this.emit('preview:browser-download', data);
|
|
300
346
|
});
|
|
@@ -304,6 +350,9 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
304
350
|
|
|
305
351
|
// Forward native UI events
|
|
306
352
|
this.nativeUIHandler.on('copy-to-clipboard', (data) => {
|
|
353
|
+
// Into the workspace clipboard, which mirrors it to the devices; the
|
|
354
|
+
// event itself is only the viewer's confirmation that it happened.
|
|
355
|
+
this.clipboard.write(data.text, 'menu');
|
|
307
356
|
this.emit('preview:browser-copy-to-clipboard', data);
|
|
308
357
|
});
|
|
309
358
|
this.nativeUIHandler.on('open-url-new-tab', (data) => {
|
|
@@ -351,10 +400,12 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
351
400
|
url?: string,
|
|
352
401
|
deviceSize: DeviceSize = 'laptop',
|
|
353
402
|
rotation?: Rotation,
|
|
354
|
-
launchId?: string
|
|
403
|
+
launchId?: string,
|
|
404
|
+
viewport?: ViewportSize | null,
|
|
405
|
+
device?: { deviceModel?: string | null; emulation?: EmulationPatch | null }
|
|
355
406
|
): Promise<BrowserTab> {
|
|
356
407
|
// Use device-appropriate default rotation if not specified
|
|
357
|
-
const actualRotation = rotation || (
|
|
408
|
+
const actualRotation = rotation || defaultRotation(deviceSize);
|
|
358
409
|
|
|
359
410
|
// Dialog interception and the capability shims both have to be in place
|
|
360
411
|
// before the first navigation: a page can call alert() or getUserMedia()
|
|
@@ -369,7 +420,10 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
369
420
|
const tab = await this.tabManager.createTab(url, deviceSize, actualRotation, {
|
|
370
421
|
setActive: true,
|
|
371
422
|
preNavigationSetup,
|
|
372
|
-
launchId
|
|
423
|
+
launchId,
|
|
424
|
+
viewport,
|
|
425
|
+
deviceModel: device?.deviceModel,
|
|
426
|
+
emulation: device?.emulation
|
|
373
427
|
});
|
|
374
428
|
|
|
375
429
|
// Setup console, navigation tracking, and pre-inject streaming scripts in parallel
|
|
@@ -610,11 +664,89 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
610
664
|
};
|
|
611
665
|
|
|
612
666
|
this.emit('preview:browser-tab-meta', meta);
|
|
667
|
+
await this.refreshPageColors(tabId);
|
|
613
668
|
} catch (error) {
|
|
614
669
|
debug.warn('preview', `⚠️ Failed to refresh tab meta for ${tabId}:`, error);
|
|
615
670
|
}
|
|
616
671
|
}
|
|
617
672
|
|
|
673
|
+
/**
|
|
674
|
+
* Read the colours a page asks to be framed in, as a mobile browser does:
|
|
675
|
+
* the status bar takes the page's `theme-color` (honouring its `media`),
|
|
676
|
+
* and everything else the root background, falling through to the body
|
|
677
|
+
* and then to the canvas default for the page's colour scheme.
|
|
678
|
+
*
|
|
679
|
+
* Read from the DOM, never sampled from pixels — a sampled edge picks up
|
|
680
|
+
* whatever header, image or button happens to touch it, which is how three
|
|
681
|
+
* sides of one page came out three different colours.
|
|
682
|
+
*/
|
|
683
|
+
private async readPageColors(page: Page): Promise<PageColors | null> {
|
|
684
|
+
const read = page.evaluate(() => {
|
|
685
|
+
const probe = document.createElement('canvas').getContext('2d');
|
|
686
|
+
const normalise = (colour: string | null | undefined): string | null => {
|
|
687
|
+
if (!colour || !probe) return null;
|
|
688
|
+
probe.fillStyle = '#000001';
|
|
689
|
+
probe.fillStyle = colour;
|
|
690
|
+
const value = String(probe.fillStyle);
|
|
691
|
+
return value === '#000001' && colour.trim().toLowerCase() !== '#000001' ? null : value;
|
|
692
|
+
};
|
|
693
|
+
const opaque = (colour: string | null): string | null => {
|
|
694
|
+
if (!colour) return null;
|
|
695
|
+
const alpha = /rgba?\([^)]*,\s*([\d.]+)\s*\)/.exec(colour);
|
|
696
|
+
return alpha && Number(alpha[1]) === 0 ? null : colour;
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
let theme: string | null = null;
|
|
700
|
+
for (const meta of Array.from(document.querySelectorAll<HTMLMetaElement>('meta[name="theme-color"]'))) {
|
|
701
|
+
const media = meta.getAttribute('media');
|
|
702
|
+
if (!media || matchMedia(media).matches) {
|
|
703
|
+
theme = opaque(normalise(meta.content));
|
|
704
|
+
if (theme) break;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
const root = opaque(normalise(getComputedStyle(document.documentElement).backgroundColor));
|
|
709
|
+
const body = document.body ? opaque(normalise(getComputedStyle(document.body).backgroundColor)) : null;
|
|
710
|
+
const darkCanvas =
|
|
711
|
+
getComputedStyle(document.documentElement).colorScheme.includes('dark') &&
|
|
712
|
+
matchMedia('(prefers-color-scheme: dark)').matches;
|
|
713
|
+
const background = root ?? body ?? (darkCanvas ? '#121212' : '#ffffff');
|
|
714
|
+
|
|
715
|
+
return { statusBar: theme ?? background, background };
|
|
716
|
+
});
|
|
717
|
+
// A page mid-navigation can reject after the timeout has already won;
|
|
718
|
+
// caught here so that late rejection is not left unhandled.
|
|
719
|
+
const settled = read.catch(() => null);
|
|
720
|
+
const timeout = new Promise<null>((resolve) => setTimeout(() => resolve(null), 1000));
|
|
721
|
+
return await Promise.race([settled, timeout]);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/** Re-read a tab's page colours and tell viewers when they changed. */
|
|
725
|
+
private async refreshPageColors(tabId: string): Promise<void> {
|
|
726
|
+
const tab = this.getTab(tabId);
|
|
727
|
+
if (!tab || tab.page.isClosed()) return;
|
|
728
|
+
|
|
729
|
+
const colors = await this.readPageColors(tab.page);
|
|
730
|
+
if (!colors) return;
|
|
731
|
+
if (tab.pageColors?.statusBar === colors.statusBar && tab.pageColors?.background === colors.background) return;
|
|
732
|
+
|
|
733
|
+
tab.pageColors = colors;
|
|
734
|
+
this.emit('preview:browser-page-colors', { tabId, ...colors, timestamp: Date.now() });
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Only phones and tablets have bands to paint, and only a tab someone is
|
|
739
|
+
* watching needs them current. Sleeping tabs are left alone — running
|
|
740
|
+
* script in a frozen page would wake it.
|
|
741
|
+
*/
|
|
742
|
+
private async pollPageColors(): Promise<void> {
|
|
743
|
+
for (const tab of this.tabManager.getAllTabs()) {
|
|
744
|
+
if (tab.deviceSize !== 'mobile' && tab.deviceSize !== 'tablet') continue;
|
|
745
|
+
if (!this.videoCapture.isStreaming(tab.id) || this.lifecycle.isFrozen(tab.id)) continue;
|
|
746
|
+
await this.refreshPageColors(tab.id);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
618
750
|
/**
|
|
619
751
|
* Resolve the page's favicon to an absolute URL, falling back to the
|
|
620
752
|
* origin's /favicon.ico the way a browser does.
|
|
@@ -727,11 +859,29 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
727
859
|
}
|
|
728
860
|
|
|
729
861
|
/**
|
|
730
|
-
* Change
|
|
862
|
+
* Change the device class, orientation or exact size of an existing tab,
|
|
863
|
+
* and rebuild the capture around it.
|
|
864
|
+
*
|
|
865
|
+
* One call for every caller — the viewer's device menu, a drag, an agent's
|
|
866
|
+
* `set_viewport`. The agent's path used to stop at the page's viewport,
|
|
867
|
+
* leaving the capture sized for the old shape until something else
|
|
868
|
+
* happened to restart it.
|
|
731
869
|
*/
|
|
732
|
-
async setViewport(
|
|
870
|
+
async setViewport(
|
|
871
|
+
tabId: string,
|
|
872
|
+
request: DeviceRequest & { emulation?: EmulationPatch | null }
|
|
873
|
+
): Promise<boolean> {
|
|
733
874
|
await this.ensureTabAwake(tabId);
|
|
734
|
-
|
|
875
|
+
const ok = await this.tabManager.setViewport(tabId, request);
|
|
876
|
+
if (!ok) return false;
|
|
877
|
+
|
|
878
|
+
const tab = this.getTab(tabId);
|
|
879
|
+
// False only means nothing is streaming yet; the stream that starts
|
|
880
|
+
// later is sized from the viewport just set.
|
|
881
|
+
if (tab) await this.videoCapture.updateViewport(tabId, tab);
|
|
882
|
+
// A colour-scheme change recolours the page without a navigation.
|
|
883
|
+
void this.refreshPageColors(tabId);
|
|
884
|
+
return true;
|
|
735
885
|
}
|
|
736
886
|
|
|
737
887
|
/**
|
|
@@ -956,17 +1106,22 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
956
1106
|
* it only happens on a fullscreen the page did not ask for, which is rare
|
|
957
1107
|
* enough that the restart it costs is not worth trying to avoid.
|
|
958
1108
|
*/
|
|
959
|
-
private async restoreEmulatedViewport(tabId: string, requestId: string): Promise<void> {
|
|
1109
|
+
private async restoreEmulatedViewport(tabId: string, requestId: string | null): Promise<void> {
|
|
960
1110
|
try {
|
|
961
1111
|
const tab = this.getTab(tabId);
|
|
962
1112
|
if (tab) {
|
|
963
|
-
const { width, height } =
|
|
1113
|
+
const { width, height } = tab.viewport;
|
|
1114
|
+
|
|
1115
|
+
// A fullscreen that never exited leaves the window itself in
|
|
1116
|
+
// `fullscreen` state, and no viewport override survives that — the
|
|
1117
|
+
// surface stays the window's shape. Put the window back first.
|
|
1118
|
+
await this.normalizeWindow(tab.page);
|
|
964
1119
|
|
|
965
1120
|
// The capture path re-sends the override and recomputes the screencast
|
|
966
1121
|
// geometry with it. With no stream running there is no geometry to
|
|
967
1122
|
// recompute and the override is all that is needed.
|
|
968
|
-
const restored = await this.videoCapture.updateViewport(tabId, tab
|
|
969
|
-
if (!restored) await tab.page
|
|
1123
|
+
const restored = await this.videoCapture.updateViewport(tabId, tab);
|
|
1124
|
+
if (!restored) await applyViewport(tab.page, tab);
|
|
970
1125
|
|
|
971
1126
|
debug.log('preview', `🖥️ Restored emulated viewport for tab ${tabId}: ${width}x${height}`);
|
|
972
1127
|
}
|
|
@@ -975,7 +1130,40 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
975
1130
|
} finally {
|
|
976
1131
|
// The page holds a promise on this. Nothing awaits it, but an unsettled
|
|
977
1132
|
// request sits in the pending map until it times out.
|
|
978
|
-
this.hostBridge.respond(requestId, { ok: true });
|
|
1133
|
+
if (requestId) this.hostBridge.respond(requestId, { ok: true });
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
/** Take a tab's window out of fullscreen/maximized/minimized, if it is in one. */
|
|
1138
|
+
private async normalizeWindow(page: Page): Promise<void> {
|
|
1139
|
+
const cdp = await page.createCDPSession().catch(() => null);
|
|
1140
|
+
if (!cdp) return;
|
|
1141
|
+
try {
|
|
1142
|
+
const { windowId, bounds } = (await cdp.send('Browser.getWindowForTarget')) as {
|
|
1143
|
+
windowId: number;
|
|
1144
|
+
bounds: { windowState?: string };
|
|
1145
|
+
};
|
|
1146
|
+
if (bounds.windowState && bounds.windowState !== 'normal') {
|
|
1147
|
+
await cdp.send('Browser.setWindowBounds', { windowId, bounds: { windowState: 'normal' } });
|
|
1148
|
+
|
|
1149
|
+
// The window resizes asynchronously. A viewport override sent
|
|
1150
|
+
// before it has settled is applied to the old surface and then
|
|
1151
|
+
// stranded again by the resize — measured: back at 1366×681.
|
|
1152
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
1153
|
+
const current = (await cdp.send('Browser.getWindowBounds', { windowId })) as {
|
|
1154
|
+
bounds: { windowState?: string };
|
|
1155
|
+
};
|
|
1156
|
+
if (current.bounds.windowState === 'normal') break;
|
|
1157
|
+
await sleep(25);
|
|
1158
|
+
}
|
|
1159
|
+
await sleep(WINDOW_SETTLE_MS);
|
|
1160
|
+
debug.log('preview', `🪟 Window was left ${bounds.windowState}; set back to normal`);
|
|
1161
|
+
}
|
|
1162
|
+
} catch {
|
|
1163
|
+
// Not every build lets a page session ask about its window; the
|
|
1164
|
+
// viewport override below is the part that matters.
|
|
1165
|
+
} finally {
|
|
1166
|
+
await cdp.detach().catch(() => {});
|
|
979
1167
|
}
|
|
980
1168
|
}
|
|
981
1169
|
|
|
@@ -1033,21 +1221,13 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
1033
1221
|
this.fullscreenTabs.delete(tabId);
|
|
1034
1222
|
this.emit('preview:browser-fullscreen-state', { tabId, active: false });
|
|
1035
1223
|
|
|
1036
|
-
const
|
|
1037
|
-
|
|
1038
|
-
if (!restored) await tab.page.setViewport({ width, height }).catch(() => {});
|
|
1224
|
+
const restored = await this.videoCapture.updateViewport(tabId, tab);
|
|
1225
|
+
if (!restored) await applyViewport(tab.page, tab).catch(() => {});
|
|
1039
1226
|
|
|
1040
1227
|
debug.log('preview', `🖥️ Forced tab ${tabId} out of full screen`);
|
|
1041
1228
|
return true;
|
|
1042
1229
|
}
|
|
1043
1230
|
|
|
1044
|
-
async updateWebCodecsViewport(tabId: string, width: number, height: number): Promise<boolean> {
|
|
1045
|
-
const tab = this.getTab(tabId);
|
|
1046
|
-
if (!tab) {
|
|
1047
|
-
return false;
|
|
1048
|
-
}
|
|
1049
|
-
return await this.videoCapture.updateViewport(tabId, tab, width, height);
|
|
1050
|
-
}
|
|
1051
1231
|
|
|
1052
1232
|
async getWebCodecsOffer(tabId: string, viewerId: string): Promise<RTCSessionDescriptionInit | null> {
|
|
1053
1233
|
const tab = this.getTab(tabId);
|
|
@@ -1178,6 +1358,21 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
1178
1358
|
return await this.dialogHandler.respondToDialog(response);
|
|
1179
1359
|
}
|
|
1180
1360
|
|
|
1361
|
+
/** The dialog a tab's page is blocked on, if any. */
|
|
1362
|
+
getPendingDialog(tabId: string): PendingDialogInfo | null {
|
|
1363
|
+
return this.dialogHandler.getPendingDialog(tabId);
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
/** Resolve when a tab raises a dialog; `dispose` once the race is decided. */
|
|
1367
|
+
waitForDialog(tabId: string): { promise: Promise<PendingDialogInfo>; dispose: () => void } {
|
|
1368
|
+
return this.dialogHandler.waitForDialog(tabId);
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/** Answer the dialog a tab has open. Null when there was none to answer. */
|
|
1372
|
+
async respondToTabDialog(tabId: string, accept: boolean, promptText?: string): Promise<PendingDialogInfo | null> {
|
|
1373
|
+
return this.dialogHandler.respondForTab(tabId, accept, promptText);
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1181
1376
|
// ============================================================================
|
|
1182
1377
|
// Native UI Methods (Select & Context Menu)
|
|
1183
1378
|
// ============================================================================
|
|
@@ -1234,6 +1429,119 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
1234
1429
|
return result;
|
|
1235
1430
|
}
|
|
1236
1431
|
|
|
1432
|
+
// ============================================================================
|
|
1433
|
+
// Diagnostics
|
|
1434
|
+
// ============================================================================
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* What every tab of this workspace is doing and costing, for the
|
|
1438
|
+
* diagnostics panel.
|
|
1439
|
+
*
|
|
1440
|
+
* Nothing here runs script in a page: a frozen tab must stay frozen for
|
|
1441
|
+
* being looked at, and a tab paused on a dialog would hang the read. Page
|
|
1442
|
+
* metrics come over the DevTools protocol, which answers either way, and
|
|
1443
|
+
* stream counters are only read from tabs that are actually streaming.
|
|
1444
|
+
*/
|
|
1445
|
+
async getDiagnostics() {
|
|
1446
|
+
const tabs = await Promise.all(
|
|
1447
|
+
this.getAllTabs().map(async (tab) => {
|
|
1448
|
+
const frozen = this.lifecycle.isFrozen(tab.id);
|
|
1449
|
+
const dialog = this.dialogHandler.getPendingDialog(tab.id);
|
|
1450
|
+
const owner = browserMcpControl.getTabOwner(tab.id);
|
|
1451
|
+
|
|
1452
|
+
let jsHeapUsedBytes: number | null = null;
|
|
1453
|
+
let domNodes: number | null = null;
|
|
1454
|
+
if (!tab.page.isClosed()) {
|
|
1455
|
+
const metrics = await Promise.race([
|
|
1456
|
+
tab.page.metrics().catch(() => null),
|
|
1457
|
+
new Promise<null>((resolve) => setTimeout(() => resolve(null), 1500))
|
|
1458
|
+
]);
|
|
1459
|
+
jsHeapUsedBytes = metrics?.JSHeapUsedSize ?? null;
|
|
1460
|
+
domNodes = metrics?.Nodes ?? null;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
const streaming = this.isWebCodecsActive(tab.id);
|
|
1464
|
+
const stream =
|
|
1465
|
+
streaming && !frozen && !dialog
|
|
1466
|
+
? await Promise.race([
|
|
1467
|
+
this.getWebCodecsStats(tab.id).catch(() => null),
|
|
1468
|
+
new Promise<null>((resolve) => setTimeout(() => resolve(null), 1500))
|
|
1469
|
+
])
|
|
1470
|
+
: null;
|
|
1471
|
+
|
|
1472
|
+
return {
|
|
1473
|
+
id: tab.id,
|
|
1474
|
+
title: tab.title,
|
|
1475
|
+
url: tab.page.isClosed() ? tab.url : tab.page.url(),
|
|
1476
|
+
state: frozen ? ('frozen' as const) : ('active' as const),
|
|
1477
|
+
watched: this.lifecycle.hasViewers(tab.id),
|
|
1478
|
+
isLoading: !!tab.isLoading,
|
|
1479
|
+
openedBy: tab.openedBy?.kind ?? 'user',
|
|
1480
|
+
agentHeld: !!owner,
|
|
1481
|
+
dialog: dialog ? { type: dialog.type, message: dialog.message } : null,
|
|
1482
|
+
createdAt: tab.createdAt,
|
|
1483
|
+
lastAccessedAt: tab.lastAccessedAt,
|
|
1484
|
+
jsHeapUsedBytes,
|
|
1485
|
+
domNodes,
|
|
1486
|
+
stream: stream
|
|
1487
|
+
? {
|
|
1488
|
+
videoBytesSent: stream.videoBytesSent ?? 0,
|
|
1489
|
+
videoFramesEncoded: stream.videoFramesEncoded ?? 0,
|
|
1490
|
+
connectionState: stream.connectionState ?? 'unknown'
|
|
1491
|
+
}
|
|
1492
|
+
: null
|
|
1493
|
+
};
|
|
1494
|
+
})
|
|
1495
|
+
);
|
|
1496
|
+
|
|
1497
|
+
return { tabs, clipboard: this.clipboard.describe() };
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
// ============================================================================
|
|
1501
|
+
// Clipboard
|
|
1502
|
+
// ============================================================================
|
|
1503
|
+
|
|
1504
|
+
/**
|
|
1505
|
+
* Clipboard traffic from a page, answered here rather than by a viewer.
|
|
1506
|
+
*
|
|
1507
|
+
* Writes (and copy events) go into the workspace clipboard straight away:
|
|
1508
|
+
* there is no decision in them, and waiting on a device meant a page's
|
|
1509
|
+
* "Copy" button failed whenever nobody was watching. Reads are answered from
|
|
1510
|
+
* the workspace clipboard while an agent holds the tab — the agent is the
|
|
1511
|
+
* user there, and a prompt on someone's screen would stall its run. A read
|
|
1512
|
+
* on a tab a person is driving still asks that person, as a browser would.
|
|
1513
|
+
*/
|
|
1514
|
+
private answerClipboardRequest(tabId: string, requestId: string, kind: string, payload: unknown): boolean {
|
|
1515
|
+
if (kind === 'clipboard-write' || kind === 'clipboard-copied') {
|
|
1516
|
+
const text = (payload as { text?: unknown } | null)?.text;
|
|
1517
|
+
if (typeof text === 'string') this.clipboard.write(text, 'page');
|
|
1518
|
+
this.hostBridge.respond(requestId, { ok: true });
|
|
1519
|
+
return true;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
if (kind === 'clipboard-read' && browserMcpControl.isTabControlled(tabId, this.projectId)) {
|
|
1523
|
+
this.hostBridge.respond(requestId, { ok: true, result: this.clipboard.read() });
|
|
1524
|
+
return true;
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
return false;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/** The workspace clipboard's text. */
|
|
1531
|
+
getClipboardText(): string {
|
|
1532
|
+
return this.clipboard.read();
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
/** Who last wrote the workspace clipboard, for diagnostics. */
|
|
1536
|
+
describeClipboard() {
|
|
1537
|
+
return this.clipboard.describe();
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
/** Record a copy made somewhere other than a page (the user's device, the agent). */
|
|
1541
|
+
setClipboardText(text: string, source: ClipboardSource): void {
|
|
1542
|
+
this.clipboard.write(text, source);
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1237
1545
|
// ============================================================================
|
|
1238
1546
|
// Host Bridge Methods
|
|
1239
1547
|
// ============================================================================
|
|
@@ -1285,6 +1593,10 @@ export class BrowserPreviewService extends EventEmitter {
|
|
|
1285
1593
|
// Cleanup Methods
|
|
1286
1594
|
// ============================================================================
|
|
1287
1595
|
async cleanup() {
|
|
1596
|
+
if (this.pageColorsTimer) {
|
|
1597
|
+
clearInterval(this.pageColorsTimer);
|
|
1598
|
+
this.pageColorsTimer = null;
|
|
1599
|
+
}
|
|
1288
1600
|
// Clear all cursor tracking
|
|
1289
1601
|
this.interactionHandler.clearAllSessionCursors();
|
|
1290
1602
|
// Release host-bridge scratch dirs and unblock any parked page promises
|
|
@@ -1451,6 +1763,10 @@ class BrowserPreviewServiceManager {
|
|
|
1451
1763
|
});
|
|
1452
1764
|
|
|
1453
1765
|
// Forward live tab metadata (title, favicon, back/forward availability)
|
|
1766
|
+
service.on('preview:browser-page-colors', (data) => {
|
|
1767
|
+
ws.emit.project(roomId, 'preview:browser-page-colors', { ...data, projectId });
|
|
1768
|
+
});
|
|
1769
|
+
|
|
1454
1770
|
service.on('preview:browser-tab-meta', (data) => {
|
|
1455
1771
|
ws.emit.project(roomId, 'preview:browser-tab-meta', { ...data, projectId });
|
|
1456
1772
|
});
|
|
@@ -1471,12 +1787,15 @@ class BrowserPreviewServiceManager {
|
|
|
1471
1787
|
});
|
|
1472
1788
|
|
|
1473
1789
|
// Forward console events
|
|
1790
|
+
// Console lines are a panel's live detail, as frequent as the page is
|
|
1791
|
+
// chatty: only connections with a Preview open receive them. A panel that
|
|
1792
|
+
// opens later seeds itself from the console history.
|
|
1474
1793
|
service.on('preview:browser-console-message', (data) => {
|
|
1475
|
-
|
|
1794
|
+
emitToPreviewWatchers(roomId, 'preview:browser-console-message', data);
|
|
1476
1795
|
});
|
|
1477
1796
|
|
|
1478
1797
|
service.on('preview:browser-console-clear', (data) => {
|
|
1479
|
-
|
|
1798
|
+
emitToPreviewWatchers(roomId, 'preview:browser-console-clear', data);
|
|
1480
1799
|
});
|
|
1481
1800
|
|
|
1482
1801
|
// Forward dialog events
|
|
@@ -1511,6 +1830,12 @@ class BrowserPreviewServiceManager {
|
|
|
1511
1830
|
ws.emit.project(roomId, 'preview:browser-copy-to-clipboard', data);
|
|
1512
1831
|
});
|
|
1513
1832
|
|
|
1833
|
+
// The workspace clipboard changed — every device of this project writes it
|
|
1834
|
+
// to its own clipboard (when focused; otherwise on its next focus).
|
|
1835
|
+
service.on('preview:browser-clipboard-sync', (data) => {
|
|
1836
|
+
ws.emit.project(roomId, 'preview:browser-clipboard-sync', { ...data, projectId });
|
|
1837
|
+
});
|
|
1838
|
+
|
|
1514
1839
|
service.on('preview:browser-open-url-new-tab', (data) => {
|
|
1515
1840
|
ws.emit.project(roomId, 'preview:browser-open-url-new-tab', data);
|
|
1516
1841
|
});
|
|
@@ -1589,6 +1914,7 @@ class BrowserPreviewServiceManager {
|
|
|
1589
1914
|
// No longer pinned: an unwatched tab the agent has let go of is free
|
|
1590
1915
|
// to fall asleep on the usual timer.
|
|
1591
1916
|
this.services.get(data.projectId)?.noteTabActivity(data.browserTabId);
|
|
1917
|
+
forgetAgentCursor(data.projectId, data.browserTabId);
|
|
1592
1918
|
ws.emit.project(data.projectId, 'preview:browser-mcp-control-end', {
|
|
1593
1919
|
browserTabId: data.browserTabId,
|
|
1594
1920
|
projectId: data.projectId,
|
|
@@ -1605,21 +1931,49 @@ class BrowserPreviewServiceManager {
|
|
|
1605
1931
|
});
|
|
1606
1932
|
});
|
|
1607
1933
|
|
|
1934
|
+
// The agent's cursor moves many times a second while it works and is only
|
|
1935
|
+
// drawn inside a Preview, so its steps go to connections with one open;
|
|
1936
|
+
// where it came to rest is remembered for a Preview that opens later.
|
|
1608
1937
|
browserMcpControl.on('cursor-position', (data) => {
|
|
1609
1938
|
if (!data.projectId) return;
|
|
1610
|
-
|
|
1939
|
+
const cursor = {
|
|
1611
1940
|
sessionId: data.tabId,
|
|
1612
1941
|
x: data.x,
|
|
1613
1942
|
y: data.y,
|
|
1614
1943
|
pressed: data.pressed ?? false,
|
|
1615
1944
|
timestamp: data.timestamp,
|
|
1616
1945
|
source: 'mcp' as const
|
|
1946
|
+
};
|
|
1947
|
+
rememberAgentCursor(data.projectId, cursor);
|
|
1948
|
+
emitToPreviewWatchers(data.projectId, 'preview:browser-mcp-cursor-position', cursor);
|
|
1949
|
+
});
|
|
1950
|
+
|
|
1951
|
+
browserMcpControl.on('cursor-glide', (data) => {
|
|
1952
|
+
if (!data.projectId) return;
|
|
1953
|
+
rememberAgentCursor(data.projectId, {
|
|
1954
|
+
sessionId: data.tabId,
|
|
1955
|
+
x: data.to.x,
|
|
1956
|
+
y: data.to.y,
|
|
1957
|
+
pressed: data.pressed ?? false,
|
|
1958
|
+
timestamp: data.timestamp,
|
|
1959
|
+
source: 'mcp' as const
|
|
1960
|
+
});
|
|
1961
|
+
emitToPreviewWatchers(data.projectId, 'preview:browser-mcp-cursor-glide', {
|
|
1962
|
+
sessionId: data.tabId,
|
|
1963
|
+
from: data.from,
|
|
1964
|
+
control: data.control,
|
|
1965
|
+
to: data.to,
|
|
1966
|
+
durationMs: data.durationMs,
|
|
1967
|
+
pressed: data.pressed,
|
|
1968
|
+
easing: data.easing,
|
|
1969
|
+
timestamp: data.timestamp,
|
|
1970
|
+
source: 'mcp' as const
|
|
1617
1971
|
});
|
|
1618
1972
|
});
|
|
1619
1973
|
|
|
1620
1974
|
browserMcpControl.on('cursor-click', (data) => {
|
|
1621
1975
|
if (!data.projectId) return;
|
|
1622
|
-
|
|
1976
|
+
emitToPreviewWatchers(data.projectId, 'preview:browser-mcp-cursor-click', {
|
|
1623
1977
|
sessionId: data.tabId,
|
|
1624
1978
|
x: data.x,
|
|
1625
1979
|
y: data.y,
|