@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
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Everything about the message box that outlives a page load, per chat session:
|
|
5
5
|
*
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
8
|
-
* shared box let two people overwrite each other keystroke by keystroke.
|
|
9
|
-
* - Edit mode is per user too. Collaborators only learn THAT someone is
|
|
10
|
-
* editing; they never enter (or cancel, or submit) another person's edit.
|
|
6
|
+
* - The draft: text and attachments typed in a session wait on any device.
|
|
7
|
+
* - Edit mode: which message is being edited, restored with the session.
|
|
11
8
|
* - The message queue holds what was sent while the AI was still working, and
|
|
12
9
|
* the server starts the next one when a turn completes — so a queued message
|
|
13
10
|
* is sent even if every tab that queued it has been closed.
|
|
@@ -26,6 +23,7 @@ import { messageQueries } from '../../database/queries';
|
|
|
26
23
|
import { INITIAL_NODE_ID } from '../../snapshot/helpers';
|
|
27
24
|
import { requireSessionAccess } from '../access';
|
|
28
25
|
import { bridgeStreamToRoom, startChatStream } from './stream';
|
|
26
|
+
import { registerComposer } from '../../chat-apps';
|
|
29
27
|
|
|
30
28
|
// ============================================================================
|
|
31
29
|
// State
|
|
@@ -57,37 +55,44 @@ interface Draft {
|
|
|
57
55
|
interface EditState {
|
|
58
56
|
messageId: string;
|
|
59
57
|
messageTimestamp: string | null;
|
|
60
|
-
userName: string;
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
interface QueuedMessage {
|
|
64
61
|
id: string;
|
|
65
|
-
userId: string;
|
|
66
|
-
userName: string;
|
|
67
62
|
createdAt: string;
|
|
68
63
|
text: string;
|
|
69
64
|
attachmentCount: number;
|
|
70
65
|
request: StreamRequest;
|
|
71
66
|
}
|
|
72
67
|
|
|
73
|
-
/**
|
|
68
|
+
/** chatSessionId → its draft. */
|
|
74
69
|
const drafts = new Map<string, Draft>();
|
|
75
|
-
/** chatSessionId →
|
|
76
|
-
const edits = new Map<string,
|
|
70
|
+
/** chatSessionId → the message being edited. */
|
|
71
|
+
const edits = new Map<string, EditState>();
|
|
77
72
|
/** chatSessionId → messages waiting for the current turn to finish, in order. */
|
|
78
73
|
const queues = new Map<string, QueuedMessage[]>();
|
|
79
74
|
/** Sessions whose next queued message is being started right now. */
|
|
80
75
|
const draining = new Set<string>();
|
|
81
76
|
|
|
82
|
-
function draftKey(chatSessionId: string, userId: string): string {
|
|
83
|
-
return `${chatSessionId}\u0000${userId}`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
77
|
function isSessionBusy(chatSessionId: string, projectId: string): boolean {
|
|
87
78
|
if (draining.has(chatSessionId)) return true;
|
|
88
79
|
return streamManager.getSessionStream(chatSessionId, projectId)?.status === 'active';
|
|
89
80
|
}
|
|
90
81
|
|
|
82
|
+
function isSessionStreaming(chatSessionId: string): boolean {
|
|
83
|
+
return streamManager.getActiveStreams().some((stream) => stream.chatSessionId === chatSessionId);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Whether a message can be edited right now: it is on the branch the session
|
|
88
|
+
* is showing, and no turn is running (an edit rewinds the branch, which a
|
|
89
|
+
* running turn is still writing to).
|
|
90
|
+
*/
|
|
91
|
+
function isEditable(chatSessionId: string, messageId: string): boolean {
|
|
92
|
+
if (isSessionStreaming(chatSessionId)) return false;
|
|
93
|
+
return messageQueries.isOnActivePath(chatSessionId, messageId);
|
|
94
|
+
}
|
|
95
|
+
|
|
91
96
|
function promptText(prompt: any): string {
|
|
92
97
|
const content = Array.isArray(prompt?.content) ? prompt.content : [];
|
|
93
98
|
return content
|
|
@@ -101,19 +106,9 @@ function promptAttachmentCount(prompt: any): number {
|
|
|
101
106
|
return content.filter((block: any) => block?.type === 'image' || block?.type === 'document').length;
|
|
102
107
|
}
|
|
103
108
|
|
|
104
|
-
function editorsFor(chatSessionId: string, exceptUserId?: string) {
|
|
105
|
-
const sessionEdits = edits.get(chatSessionId);
|
|
106
|
-
if (!sessionEdits) return [];
|
|
107
|
-
return [...sessionEdits.entries()]
|
|
108
|
-
.filter(([userId]) => userId !== exceptUserId)
|
|
109
|
-
.map(([userId, edit]) => ({ userId, userName: edit.userName, messageId: edit.messageId }));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
109
|
function queueView(chatSessionId: string) {
|
|
113
110
|
return (queues.get(chatSessionId) ?? []).map((item) => ({
|
|
114
111
|
id: item.id,
|
|
115
|
-
userId: item.userId,
|
|
116
|
-
userName: item.userName,
|
|
117
112
|
createdAt: item.createdAt,
|
|
118
113
|
text: item.text,
|
|
119
114
|
attachmentCount: item.attachmentCount
|
|
@@ -160,6 +155,52 @@ async function startPrepared(item: QueuedMessage): Promise<void> {
|
|
|
160
155
|
bridgeStreamToRoom(streamId, request.chatSessionId, request.projectId);
|
|
161
156
|
}
|
|
162
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Send a message the way the composer does: start it now if the session is
|
|
160
|
+
* idle and nothing is queued ahead of it, otherwise queue it behind the turn.
|
|
161
|
+
* Shared by `chat:queue-add` and anything server-side that sends on the
|
|
162
|
+
* owner's behalf — a reply from a chat app arrives with no tab open at all.
|
|
163
|
+
*/
|
|
164
|
+
export async function submitPrompt(input: {
|
|
165
|
+
request: StreamRequest;
|
|
166
|
+
}): Promise<{ outcome: 'started' | 'queued'; queueId: string }> {
|
|
167
|
+
const { chatSessionId, projectId } = input.request;
|
|
168
|
+
const item: QueuedMessage = {
|
|
169
|
+
id: crypto.randomUUID(),
|
|
170
|
+
createdAt: new Date().toISOString(),
|
|
171
|
+
text: promptText(input.request.prompt),
|
|
172
|
+
attachmentCount: promptAttachmentCount(input.request.prompt),
|
|
173
|
+
request: input.request
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
if (!isSessionBusy(chatSessionId, projectId) && !queues.get(chatSessionId)?.length) {
|
|
177
|
+
await startQueued(item);
|
|
178
|
+
return { outcome: 'started', queueId: item.id };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const queue = queues.get(chatSessionId) ?? [];
|
|
182
|
+
queue.push(item);
|
|
183
|
+
queues.set(chatSessionId, queue);
|
|
184
|
+
broadcastQueue(chatSessionId);
|
|
185
|
+
return { outcome: 'queued', queueId: item.id };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Replace the content of a message still waiting in the queue — editing it
|
|
190
|
+
* before it ran. Returns false when it already started (or was dropped).
|
|
191
|
+
*/
|
|
192
|
+
export function replaceQueuedPrompt(chatSessionId: string, queueId: string, content: unknown[]): boolean {
|
|
193
|
+
const item = queues.get(chatSessionId)?.find((entry) => entry.id === queueId);
|
|
194
|
+
if (!item) return false;
|
|
195
|
+
item.request = { ...item.request, prompt: { ...item.request.prompt, content } as StreamRequest['prompt'] };
|
|
196
|
+
item.text = promptText(item.request.prompt);
|
|
197
|
+
item.attachmentCount = promptAttachmentCount(item.request.prompt);
|
|
198
|
+
broadcastQueue(chatSessionId);
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
registerComposer({ submit: submitPrompt, replaceQueued: replaceQueuedPrompt });
|
|
203
|
+
|
|
163
204
|
// ============================================================================
|
|
164
205
|
// Lifecycle
|
|
165
206
|
// ============================================================================
|
|
@@ -192,11 +233,17 @@ streamManager.on('stream:lifecycle', (event: { status: string; streamId: string;
|
|
|
192
233
|
})();
|
|
193
234
|
});
|
|
194
235
|
|
|
236
|
+
// A new turn ends any edit in its session. The client that sent it leaves edit
|
|
237
|
+
// mode itself, but that notice travels fire-and-forget and is lost with a
|
|
238
|
+
// socket that dies under it; an edit left here would be restored on the next
|
|
239
|
+
// load as if it were still going — over a turn the user already sent.
|
|
240
|
+
streamManager.on('session:turn-started', (chatSessionId: string) => {
|
|
241
|
+
edits.delete(chatSessionId);
|
|
242
|
+
});
|
|
243
|
+
|
|
195
244
|
// Deleting a session drops everything its composer was holding.
|
|
196
245
|
streamManager.on('session:cleanup', (chatSessionId: string) => {
|
|
197
|
-
|
|
198
|
-
if (key.startsWith(`${chatSessionId}\u0000`)) drafts.delete(key);
|
|
199
|
-
}
|
|
246
|
+
drafts.delete(chatSessionId);
|
|
200
247
|
edits.delete(chatSessionId);
|
|
201
248
|
queues.delete(chatSessionId);
|
|
202
249
|
});
|
|
@@ -220,16 +267,8 @@ const engineSchema = t.Object({
|
|
|
220
267
|
account: t.Object({ id: t.Number(), name: t.String() })
|
|
221
268
|
});
|
|
222
269
|
|
|
223
|
-
const editorSchema = t.Object({
|
|
224
|
-
userId: t.String(),
|
|
225
|
-
userName: t.String(),
|
|
226
|
-
messageId: t.String()
|
|
227
|
-
});
|
|
228
|
-
|
|
229
270
|
const queueItemSchema = t.Object({
|
|
230
271
|
id: t.String(),
|
|
231
|
-
userId: t.String(),
|
|
232
|
-
userName: t.String(),
|
|
233
272
|
createdAt: t.String(),
|
|
234
273
|
text: t.String(),
|
|
235
274
|
attachmentCount: t.Number()
|
|
@@ -256,23 +295,28 @@ export const composerHandler = createRouter()
|
|
|
256
295
|
t.Object({ messageId: t.String(), messageTimestamp: t.Union([t.String(), t.Null()]) }),
|
|
257
296
|
t.Null()
|
|
258
297
|
]),
|
|
259
|
-
editors: t.Array(editorSchema),
|
|
260
298
|
queue: t.Array(queueItemSchema)
|
|
261
299
|
})
|
|
262
|
-
}, ({ data
|
|
263
|
-
requireSessionAccess(
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
300
|
+
}, ({ data }) => {
|
|
301
|
+
requireSessionAccess(data.chatSessionId);
|
|
302
|
+
const draft = drafts.get(data.chatSessionId);
|
|
303
|
+
let edit = edits.get(data.chatSessionId);
|
|
304
|
+
// An edit is only handed back while it can still be submitted: the branch
|
|
305
|
+
// may have moved past the message (undo, another device's edit) or a turn
|
|
306
|
+
// may be running, and restoring it then would show "Editing" over a
|
|
307
|
+
// conversation it no longer applies to.
|
|
308
|
+
if (edit && !isEditable(data.chatSessionId, edit.messageId)) {
|
|
309
|
+
edits.delete(data.chatSessionId);
|
|
310
|
+
edit = undefined;
|
|
311
|
+
}
|
|
267
312
|
return {
|
|
268
313
|
draft: draft ?? { text: '', attachments: [], textRevision: 0, attachmentsRevision: 0 },
|
|
269
|
-
edit:
|
|
270
|
-
editors: editorsFor(data.chatSessionId, userId),
|
|
314
|
+
edit: edit ? { messageId: edit.messageId, messageTimestamp: edit.messageTimestamp } : null,
|
|
271
315
|
queue: queueView(data.chatSessionId)
|
|
272
316
|
};
|
|
273
317
|
})
|
|
274
318
|
|
|
275
|
-
// Save
|
|
319
|
+
// Save the draft. Omitted fields are left as they are, so typing
|
|
276
320
|
// sends text only and attachments travel only when they change. A part is
|
|
277
321
|
// only replaced by a write newer than the one it holds.
|
|
278
322
|
.on('chat:draft-save', {
|
|
@@ -282,10 +326,9 @@ export const composerHandler = createRouter()
|
|
|
282
326
|
text: t.Optional(t.String()),
|
|
283
327
|
attachments: t.Optional(t.Array(attachmentSchema))
|
|
284
328
|
})
|
|
285
|
-
}, ({ data
|
|
286
|
-
requireSessionAccess(
|
|
287
|
-
const
|
|
288
|
-
const draft = drafts.get(key) ?? { text: '', attachments: [], textRevision: 0, attachmentsRevision: 0 };
|
|
329
|
+
}, ({ data }) => {
|
|
330
|
+
requireSessionAccess(data.chatSessionId);
|
|
331
|
+
const draft = drafts.get(data.chatSessionId) ?? { text: '', attachments: [], textRevision: 0, attachmentsRevision: 0 };
|
|
289
332
|
if (data.text !== undefined && data.revision > draft.textRevision) {
|
|
290
333
|
draft.text = data.text;
|
|
291
334
|
draft.textRevision = data.revision;
|
|
@@ -294,64 +337,52 @@ export const composerHandler = createRouter()
|
|
|
294
337
|
draft.attachments = data.attachments;
|
|
295
338
|
draft.attachmentsRevision = data.revision;
|
|
296
339
|
}
|
|
297
|
-
drafts.set(
|
|
340
|
+
drafts.set(data.chatSessionId, draft);
|
|
298
341
|
})
|
|
299
342
|
|
|
300
|
-
// Enter (messageId) or leave (null) edit mode
|
|
343
|
+
// Enter (messageId) or leave (null) edit mode.
|
|
301
344
|
.on('chat:edit-mode', {
|
|
302
345
|
data: t.Object({
|
|
303
346
|
chatSessionId: t.String(),
|
|
304
347
|
messageId: t.Union([t.String(), t.Null()]),
|
|
305
|
-
messageTimestamp: t.Union([t.String(), t.Null()])
|
|
306
|
-
userName: t.String()
|
|
348
|
+
messageTimestamp: t.Union([t.String(), t.Null()])
|
|
307
349
|
})
|
|
308
|
-
}, ({ data
|
|
309
|
-
requireSessionAccess(
|
|
310
|
-
const userId = ws.getUserId(conn);
|
|
350
|
+
}, ({ data }) => {
|
|
351
|
+
requireSessionAccess(data.chatSessionId);
|
|
311
352
|
|
|
312
353
|
if (data.messageId) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
throw new Error('Message not found in this chat session');
|
|
354
|
+
if (!isEditable(data.chatSessionId, data.messageId)) {
|
|
355
|
+
throw new Error('This message cannot be edited right now');
|
|
316
356
|
}
|
|
317
|
-
|
|
318
|
-
sessionEdits.set(userId, {
|
|
357
|
+
edits.set(data.chatSessionId, {
|
|
319
358
|
messageId: data.messageId,
|
|
320
|
-
messageTimestamp: data.messageTimestamp
|
|
321
|
-
userName: data.userName
|
|
359
|
+
messageTimestamp: data.messageTimestamp
|
|
322
360
|
});
|
|
323
|
-
edits.set(data.chatSessionId, sessionEdits);
|
|
324
361
|
} else {
|
|
325
|
-
|
|
326
|
-
sessionEdits?.delete(userId);
|
|
327
|
-
if (sessionEdits && sessionEdits.size === 0) edits.delete(data.chatSessionId);
|
|
362
|
+
edits.delete(data.chatSessionId);
|
|
328
363
|
}
|
|
329
|
-
|
|
330
|
-
ws.emit.chatSession(data.chatSessionId, 'chat:edit-presence', {
|
|
331
|
-
chatSessionId: data.chatSessionId,
|
|
332
|
-
userId,
|
|
333
|
-
userName: data.userName,
|
|
334
|
-
messageId: data.messageId
|
|
335
|
-
});
|
|
336
364
|
})
|
|
337
365
|
|
|
338
366
|
// Where submitting an edit rewinds to: the edited message's parent. Resolved
|
|
339
367
|
// here from the database, never carried by the client — a client that lost
|
|
340
368
|
// it (refresh, another device) used to fall back to the very beginning of
|
|
341
369
|
// the session and revert every change the chat had made.
|
|
370
|
+
// Null when the message is gone (another device rewound past it): the edit
|
|
371
|
+
// has nothing left to replace, which the client resolves by ending it.
|
|
342
372
|
.http('chat:edit-target', {
|
|
343
373
|
data: t.Object({
|
|
344
374
|
chatSessionId: t.String(),
|
|
345
375
|
messageId: t.String()
|
|
346
376
|
}),
|
|
347
377
|
response: t.Object({
|
|
348
|
-
targetId: t.String()
|
|
378
|
+
targetId: t.Union([t.String(), t.Null()])
|
|
349
379
|
})
|
|
350
|
-
}, ({ data
|
|
351
|
-
requireSessionAccess(
|
|
380
|
+
}, ({ data }) => {
|
|
381
|
+
requireSessionAccess(data.chatSessionId);
|
|
352
382
|
const message = messageQueries.getById(data.messageId);
|
|
353
383
|
if (!message || message.session_id !== data.chatSessionId) {
|
|
354
|
-
|
|
384
|
+
edits.delete(data.chatSessionId);
|
|
385
|
+
return { targetId: null };
|
|
355
386
|
}
|
|
356
387
|
return { targetId: message.parent_message_id || INITIAL_NODE_ID };
|
|
357
388
|
})
|
|
@@ -364,59 +395,39 @@ export const composerHandler = createRouter()
|
|
|
364
395
|
projectPath: t.String(),
|
|
365
396
|
prompt: t.Any(),
|
|
366
397
|
engine: engineSchema,
|
|
367
|
-
sender: t.Object({ id: t.String(), name: t.String() }),
|
|
368
398
|
profileId: t.Optional(t.Union([t.Number(), t.Null()])),
|
|
369
399
|
reasoningEffort: t.Optional(t.Union([t.String(), t.Null()]))
|
|
370
400
|
})
|
|
371
401
|
}, async ({ data, conn }) => {
|
|
372
|
-
requireSessionAccess(
|
|
402
|
+
requireSessionAccess(data.chatSessionId);
|
|
373
403
|
const userId = ws.getUserId(conn);
|
|
374
404
|
const projectId = ws.getProjectId(conn);
|
|
375
405
|
|
|
376
|
-
|
|
377
|
-
id: crypto.randomUUID(),
|
|
378
|
-
userId,
|
|
379
|
-
userName: data.sender.name,
|
|
380
|
-
createdAt: new Date().toISOString(),
|
|
381
|
-
text: promptText(data.prompt),
|
|
382
|
-
attachmentCount: promptAttachmentCount(data.prompt),
|
|
406
|
+
await submitPrompt({
|
|
383
407
|
request: {
|
|
384
408
|
projectPath: data.projectPath,
|
|
385
409
|
projectId,
|
|
386
410
|
chatSessionId: data.chatSessionId,
|
|
387
411
|
prompt: data.prompt,
|
|
388
412
|
engine: data.engine,
|
|
389
|
-
sender: data.sender,
|
|
390
413
|
profileId: data.profileId,
|
|
391
414
|
reasoningEffort: data.reasoningEffort,
|
|
392
415
|
requestedByUserId: userId
|
|
393
416
|
}
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
if (!isSessionBusy(data.chatSessionId, projectId) && !queues.get(data.chatSessionId)?.length) {
|
|
397
|
-
await startQueued(item);
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
const queue = queues.get(data.chatSessionId) ?? [];
|
|
402
|
-
queue.push(item);
|
|
403
|
-
queues.set(data.chatSessionId, queue);
|
|
404
|
-
broadcastQueue(data.chatSessionId);
|
|
417
|
+
});
|
|
405
418
|
})
|
|
406
419
|
|
|
407
|
-
// Drop a queued message.
|
|
420
|
+
// Drop a queued message.
|
|
408
421
|
.on('chat:queue-remove', {
|
|
409
422
|
data: t.Object({
|
|
410
423
|
chatSessionId: t.String(),
|
|
411
424
|
id: t.String()
|
|
412
425
|
})
|
|
413
|
-
}, ({ data
|
|
414
|
-
requireSessionAccess(
|
|
415
|
-
const userId = ws.getUserId(conn);
|
|
426
|
+
}, ({ data }) => {
|
|
427
|
+
requireSessionAccess(data.chatSessionId);
|
|
416
428
|
const queue = queues.get(data.chatSessionId);
|
|
417
429
|
const index = queue?.findIndex((item) => item.id === data.id) ?? -1;
|
|
418
430
|
if (!queue || index === -1) return;
|
|
419
|
-
if (queue[index].userId !== userId) throw new Error('Only the author can remove a queued message');
|
|
420
431
|
queue.splice(index, 1);
|
|
421
432
|
if (queue.length === 0) queues.delete(data.chatSessionId);
|
|
422
433
|
broadcastQueue(data.chatSessionId);
|
|
@@ -441,13 +452,11 @@ export const composerHandler = createRouter()
|
|
|
441
452
|
}),
|
|
442
453
|
t.Null()
|
|
443
454
|
])
|
|
444
|
-
}, ({ data
|
|
445
|
-
requireSessionAccess(
|
|
446
|
-
const userId = ws.getUserId(conn);
|
|
455
|
+
}, ({ data }) => {
|
|
456
|
+
requireSessionAccess(data.chatSessionId);
|
|
447
457
|
const queue = queues.get(data.chatSessionId);
|
|
448
458
|
const index = queue?.findIndex((item) => item.id === data.id) ?? -1;
|
|
449
459
|
if (!queue || index === -1) return null;
|
|
450
|
-
if (queue[index].userId !== userId) throw new Error('Only the author can edit a queued message');
|
|
451
460
|
const [item] = queue.splice(index, 1);
|
|
452
461
|
if (queue.length === 0) queues.delete(data.chatSessionId);
|
|
453
462
|
broadcastQueue(data.chatSessionId);
|
|
@@ -472,13 +481,11 @@ export const composerHandler = createRouter()
|
|
|
472
481
|
id: t.String()
|
|
473
482
|
})
|
|
474
483
|
}, async ({ data, conn }) => {
|
|
475
|
-
requireSessionAccess(
|
|
476
|
-
const userId = ws.getUserId(conn);
|
|
484
|
+
requireSessionAccess(data.chatSessionId);
|
|
477
485
|
const projectId = ws.getProjectId(conn);
|
|
478
486
|
const queue = queues.get(data.chatSessionId);
|
|
479
487
|
const index = queue?.findIndex((item) => item.id === data.id) ?? -1;
|
|
480
488
|
if (!queue || index === -1) return;
|
|
481
|
-
if (queue[index].userId !== userId) throw new Error('Only the author can send a queued message');
|
|
482
489
|
|
|
483
490
|
const [item] = queue.splice(index, 1);
|
|
484
491
|
if (isSessionBusy(data.chatSessionId, projectId)) {
|
|
@@ -491,13 +498,6 @@ export const composerHandler = createRouter()
|
|
|
491
498
|
await startQueued(item);
|
|
492
499
|
})
|
|
493
500
|
|
|
494
|
-
.emit('chat:edit-presence', t.Object({
|
|
495
|
-
chatSessionId: t.String(),
|
|
496
|
-
userId: t.String(),
|
|
497
|
-
userName: t.String(),
|
|
498
|
-
messageId: t.Union([t.String(), t.Null()])
|
|
499
|
-
}))
|
|
500
|
-
|
|
501
501
|
.emit('chat:queue', t.Object({
|
|
502
502
|
chatSessionId: t.String(),
|
|
503
503
|
items: t.Array(queueItemSchema)
|