@myrialabs/clopen 0.4.46 → 0.4.48
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/stream-manager.ts +62 -62
- 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.test.ts +170 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- 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 +13 -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/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/presets.ts +27 -2
- package/backend/engine/adapters/opencode/server.ts +6 -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/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- 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/index.ts +21 -7
- 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 +361 -25
- 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/helpers.ts +0 -1
- package/backend/snapshot/restore.ts +252 -0
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +5 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws.ts +61 -154
- 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 +64 -47
- 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/opencode/providers.ts +2 -1
- 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 +15 -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/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 +29 -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 +27 -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 +34 -45
- 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 +7 -7
- 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/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 +10 -11
- package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
- package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
- package/dist/assets/main-BUiUL3eZ.css +1 -0
- package/dist/assets/main-nBOb9YOA.js +1240 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- 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 +2 -4
- 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/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/ws-server.ts +32 -7
- 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
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from '$shared/constants/notification-messages';
|
|
25
25
|
import { requireSessionAccess } from '../access';
|
|
26
26
|
import { resolveSessionPath } from '../../worktrees';
|
|
27
|
+
import { normalizeAttachments } from '../../chat/attachments';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Where a notification-worthy event happened, resolved once on the server.
|
|
@@ -49,14 +50,25 @@ function resolveNotificationContext(
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
|
-
*
|
|
53
|
+
* Where tapping a notification lands: the session it is about, through the
|
|
54
|
+
* `#session/<project>/<session>` route, instead of whatever was open last.
|
|
55
|
+
*/
|
|
56
|
+
function sessionLinkPath(projectId: string, chatSessionId: string): string {
|
|
57
|
+
return `/#session/${encodeURIComponent(projectId)}/${encodeURIComponent(chatSessionId)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Broadcast presence + notify every device when a chat message may flip the
|
|
53
62
|
* stream's waiting-for-input state (an AskUserQuestion tool_use arrives, or a
|
|
54
63
|
* tool_result answers it). `event.data.message` IS the UnifiedMessage, so its
|
|
55
64
|
* blocks live at `.content` — reading `.message.content` (one level too deep)
|
|
56
65
|
* silently yields `[]` and the status indicators never update until refresh.
|
|
57
66
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
67
|
+
* Driven by the stream manager's global `stream:message`, NOT by the per-room
|
|
68
|
+
* bridge. A bridge lives only as long as the connection that opened it, so a
|
|
69
|
+
* question arriving after the user closed the tab used to reach nobody — no
|
|
70
|
+
* presence, no push — which is exactly when a notification matters. It also
|
|
71
|
+
* fired once per attached tab; the global event fires once per message.
|
|
60
72
|
*/
|
|
61
73
|
function handleWaitingInputChange(
|
|
62
74
|
event: StreamEvent,
|
|
@@ -65,6 +77,7 @@ function handleWaitingInputChange(
|
|
|
65
77
|
): void {
|
|
66
78
|
const message = event.data?.message;
|
|
67
79
|
const msgContent = Array.isArray(message?.content) ? message.content : [];
|
|
80
|
+
if (!projectId) return;
|
|
68
81
|
|
|
69
82
|
const askToolUse = msgContent.find(
|
|
70
83
|
(item: any) => item.type === 'tool_use' && item.name === 'AskUserQuestion'
|
|
@@ -79,11 +92,11 @@ function handleWaitingInputChange(
|
|
|
79
92
|
});
|
|
80
93
|
}
|
|
81
94
|
|
|
82
|
-
// Notify
|
|
83
|
-
if (askToolUse
|
|
95
|
+
// Notify every device when AskUserQuestion arrives (sound + push)
|
|
96
|
+
if (askToolUse) {
|
|
84
97
|
const context = resolveNotificationContext(projectId, chatSessionId);
|
|
85
98
|
|
|
86
|
-
ws.emit.
|
|
99
|
+
ws.emit.signedIn('chat:waiting-input', {
|
|
87
100
|
projectId,
|
|
88
101
|
chatSessionId,
|
|
89
102
|
toolUseId: askToolUse.id,
|
|
@@ -101,7 +114,8 @@ function handleWaitingInputChange(
|
|
|
101
114
|
if (requestedByUserId) {
|
|
102
115
|
void sendPushToUser(requestedByUserId, {
|
|
103
116
|
...chatNotificationMessage('waiting-input', context),
|
|
104
|
-
tag: waitingInputPushTag(askToolUse.id)
|
|
117
|
+
tag: waitingInputPushTag(askToolUse.id),
|
|
118
|
+
url: sessionLinkPath(projectId, chatSessionId)
|
|
105
119
|
}).catch((error) => {
|
|
106
120
|
debug.warn('notification', 'Background waiting-input push failed:', error);
|
|
107
121
|
});
|
|
@@ -109,6 +123,14 @@ function handleWaitingInputChange(
|
|
|
109
123
|
}
|
|
110
124
|
}
|
|
111
125
|
|
|
126
|
+
streamManager.on('stream:message', (payload: { event: StreamEvent; chatSessionId: string; projectId?: string }) => {
|
|
127
|
+
try {
|
|
128
|
+
handleWaitingInputChange(payload.event, payload.chatSessionId, payload.projectId);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
debug.error('chat', 'Waiting-input handling failed:', err);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
112
134
|
// ============================================================================
|
|
113
135
|
// Global stream lifecycle handler (module-level, not per-connection)
|
|
114
136
|
//
|
|
@@ -136,8 +158,8 @@ streamManager.on('stream:lifecycle', (event: { status: string; streamId: string;
|
|
|
136
158
|
// two copies of one event cannot word themselves differently.
|
|
137
159
|
const context = resolveNotificationContext(projectId, chatSessionId);
|
|
138
160
|
|
|
139
|
-
// Notify
|
|
140
|
-
ws.emit.
|
|
161
|
+
// Notify every device (cross-project notification for sound + push)
|
|
162
|
+
ws.emit.signedIn('chat:stream-finished', {
|
|
141
163
|
projectId,
|
|
142
164
|
chatSessionId: chatSessionId || '',
|
|
143
165
|
streamId,
|
|
@@ -158,7 +180,8 @@ streamManager.on('stream:lifecycle', (event: { status: string; streamId: string;
|
|
|
158
180
|
status === 'error' ? 'error' : status === 'cancelled' ? 'cancelled' : 'completed';
|
|
159
181
|
void sendPushToUser(requestedByUserId, {
|
|
160
182
|
...chatNotificationMessage(notificationEvent, context),
|
|
161
|
-
tag: chatStreamPushTag(streamId)
|
|
183
|
+
tag: chatStreamPushTag(streamId),
|
|
184
|
+
...(chatSessionId ? { url: sessionLinkPath(projectId, chatSessionId) } : {})
|
|
162
185
|
}).catch((error) => {
|
|
163
186
|
debug.warn('notification', 'Background stream-finished push failed:', error);
|
|
164
187
|
});
|
|
@@ -170,12 +193,12 @@ streamManager.on('stream:lifecycle', (event: { status: string; streamId: string;
|
|
|
170
193
|
});
|
|
171
194
|
});
|
|
172
195
|
|
|
173
|
-
// Notify
|
|
196
|
+
// Notify every device when a snapshot is captured (so the timeline modal can refresh stats)
|
|
174
197
|
streamManager.on('snapshot:captured', (event: { projectId: string; chatSessionId: string }) => {
|
|
175
198
|
const { projectId, chatSessionId } = event;
|
|
176
199
|
if (!projectId) return;
|
|
177
200
|
|
|
178
|
-
ws.emit.
|
|
201
|
+
ws.emit.signedIn('snapshot:captured', { projectId, chatSessionId });
|
|
179
202
|
});
|
|
180
203
|
|
|
181
204
|
// In-memory store for model state per chat session (keyed by chatSessionId)
|
|
@@ -226,13 +249,11 @@ export function bridgeStreamToRoom(
|
|
|
226
249
|
timestamp: event.data.timestamp,
|
|
227
250
|
message_id: event.data.message_id,
|
|
228
251
|
parent_message_id: event.data.parent_message_id,
|
|
229
|
-
sender_id: event.data.sender_id,
|
|
230
|
-
sender_name: event.data.sender_name,
|
|
231
252
|
engine: event.data.engine,
|
|
232
253
|
seq: event.seq
|
|
233
254
|
});
|
|
234
|
-
//
|
|
235
|
-
|
|
255
|
+
// Waiting-input presence and notifications are handled once per
|
|
256
|
+
// message by the global `stream:message` listener above.
|
|
236
257
|
break;
|
|
237
258
|
}
|
|
238
259
|
|
|
@@ -336,12 +357,15 @@ export async function startChatStream(request: StreamRequest): Promise<string |
|
|
|
336
357
|
workingRoot
|
|
337
358
|
});
|
|
338
359
|
|
|
339
|
-
|
|
360
|
+
// One attachment rule for the web and every chat app: what the model
|
|
361
|
+
// reads inline stays inline, anything else is saved and named.
|
|
362
|
+
const prepared = await normalizeAttachments(request, workingRoot);
|
|
363
|
+
const streamId = await streamManager.startStream({ ...prepared, projectPath: workingRoot });
|
|
340
364
|
debug.log('chat', 'Stream started with ID:', streamId);
|
|
341
365
|
|
|
342
366
|
// The connection event from startStream() fires before anyone subscribes,
|
|
343
367
|
// so it is announced here. The user message reaches the room through the
|
|
344
|
-
// bridge (it carries resume
|
|
368
|
+
// bridge (it carries resume and the saved message id).
|
|
345
369
|
const stream = streamManager.getStream(streamId);
|
|
346
370
|
if (stream) {
|
|
347
371
|
ws.emit.chatSession(request.chatSessionId, 'chat:connection', {
|
|
@@ -377,7 +401,7 @@ export const streamHandler = createRouter()
|
|
|
377
401
|
chatSessionId: t.String()
|
|
378
402
|
})
|
|
379
403
|
}, ({ data, conn }) => {
|
|
380
|
-
requireSessionAccess(
|
|
404
|
+
requireSessionAccess(data.chatSessionId);
|
|
381
405
|
// Leave all previous chat sessions first (1 session at a time per connection)
|
|
382
406
|
ws.leaveAllChatSessions(conn);
|
|
383
407
|
ws.joinChatSession(conn, data.chatSessionId);
|
|
@@ -466,10 +490,6 @@ export const streamHandler = createRouter()
|
|
|
466
490
|
name: t.String()
|
|
467
491
|
})
|
|
468
492
|
}),
|
|
469
|
-
sender: t.Object({
|
|
470
|
-
id: t.String(),
|
|
471
|
-
name: t.String()
|
|
472
|
-
}),
|
|
473
493
|
// Active Profile for this session (null = explicit none; absent = use
|
|
474
494
|
// the project default). Persisted like engine/model.
|
|
475
495
|
profileId: t.Optional(t.Union([t.Number(), t.Null()])),
|
|
@@ -478,11 +498,11 @@ export const streamHandler = createRouter()
|
|
|
478
498
|
reasoningEffort: t.Optional(t.Union([t.String(), t.Null()]))
|
|
479
499
|
})
|
|
480
500
|
}, async ({ data, conn }) => {
|
|
481
|
-
requireSessionAccess(
|
|
501
|
+
requireSessionAccess(data.chatSessionId);
|
|
482
502
|
const projectId = ws.getProjectId(conn);
|
|
483
503
|
|
|
484
|
-
// The WS user id is server-trusted
|
|
485
|
-
//
|
|
504
|
+
// The WS user id is server-trusted and routes background Web Push to
|
|
505
|
+
// the requester's devices. Missing
|
|
486
506
|
// context must not break the stream — push is best-effort.
|
|
487
507
|
let requestedByUserId: string | undefined;
|
|
488
508
|
try {
|
|
@@ -497,7 +517,6 @@ export const streamHandler = createRouter()
|
|
|
497
517
|
chatSessionId: data.chatSessionId,
|
|
498
518
|
prompt: data.prompt,
|
|
499
519
|
engine: data.engine,
|
|
500
|
-
sender: data.sender,
|
|
501
520
|
profileId: data.profileId,
|
|
502
521
|
reasoningEffort: data.reasoningEffort,
|
|
503
522
|
requestedByUserId
|
|
@@ -516,7 +535,7 @@ export const streamHandler = createRouter()
|
|
|
516
535
|
chatSessionId: t.String()
|
|
517
536
|
})
|
|
518
537
|
}, async ({ data, conn }) => {
|
|
519
|
-
requireSessionAccess(
|
|
538
|
+
requireSessionAccess(data.chatSessionId);
|
|
520
539
|
const projectId = ws.getProjectId(conn);
|
|
521
540
|
|
|
522
541
|
try {
|
|
@@ -557,7 +576,7 @@ export const streamHandler = createRouter()
|
|
|
557
576
|
answers: t.Record(t.String(), t.String())
|
|
558
577
|
})
|
|
559
578
|
}, async ({ data, conn }) => {
|
|
560
|
-
requireSessionAccess(
|
|
579
|
+
requireSessionAccess(data.chatSessionId);
|
|
561
580
|
const projectId = ws.getProjectId(conn);
|
|
562
581
|
|
|
563
582
|
try {
|
|
@@ -607,7 +626,7 @@ export const streamHandler = createRouter()
|
|
|
607
626
|
const projectId = ws.getProjectId(conn);
|
|
608
627
|
|
|
609
628
|
if (data.chatSessionId) {
|
|
610
|
-
requireSessionAccess(
|
|
629
|
+
requireSessionAccess(data.chatSessionId);
|
|
611
630
|
}
|
|
612
631
|
|
|
613
632
|
const streamState = data.chatSessionId
|
|
@@ -657,7 +676,7 @@ export const streamHandler = createRouter()
|
|
|
657
676
|
chatSessionId: t.String()
|
|
658
677
|
})
|
|
659
678
|
}, async ({ data, conn }) => {
|
|
660
|
-
requireSessionAccess(
|
|
679
|
+
requireSessionAccess(data.chatSessionId);
|
|
661
680
|
const projectId = ws.getProjectId(conn);
|
|
662
681
|
const chatSessionId = data.chatSessionId;
|
|
663
682
|
|
|
@@ -703,7 +722,7 @@ export const streamHandler = createRouter()
|
|
|
703
722
|
}
|
|
704
723
|
})
|
|
705
724
|
|
|
706
|
-
//
|
|
725
|
+
// Model sync - broadcast model changes to the other devices on the same chat session
|
|
707
726
|
.on('chat:model-sync', {
|
|
708
727
|
data: t.Object({
|
|
709
728
|
senderId: t.String(),
|
|
@@ -713,14 +732,14 @@ export const streamHandler = createRouter()
|
|
|
713
732
|
modelId: t.String(),
|
|
714
733
|
modelName: t.String(),
|
|
715
734
|
// The reasoning level travels with the model pick (it is re-seeded per
|
|
716
|
-
// model), so
|
|
735
|
+
// model), so other devices never end up on a level the model lacks.
|
|
717
736
|
reasoningEffort: t.Optional(t.Union([t.String(), t.Null()])),
|
|
718
737
|
// Per-tab id of the sender; lets the sender drop its own echo without
|
|
719
738
|
// also dropping the same user's other tabs/devices.
|
|
720
739
|
clientId: t.Optional(t.String())
|
|
721
740
|
})
|
|
722
|
-
}, ({ data
|
|
723
|
-
requireSessionAccess(
|
|
741
|
+
}, ({ data }) => {
|
|
742
|
+
requireSessionAccess(data.chatSessionId);
|
|
724
743
|
const chatSessionId = data.chatSessionId;
|
|
725
744
|
|
|
726
745
|
// Store latest model state on server for late joiners / refresh
|
|
@@ -757,7 +776,7 @@ export const streamHandler = createRouter()
|
|
|
757
776
|
});
|
|
758
777
|
})
|
|
759
778
|
|
|
760
|
-
//
|
|
779
|
+
// Account sync - broadcast account changes to the other devices on the same chat session
|
|
761
780
|
.on('chat:account-sync', {
|
|
762
781
|
data: t.Object({
|
|
763
782
|
senderId: t.String(),
|
|
@@ -766,8 +785,8 @@ export const streamHandler = createRouter()
|
|
|
766
785
|
accountName: t.Optional(t.Union([t.String(), t.Null()])),
|
|
767
786
|
clientId: t.Optional(t.String())
|
|
768
787
|
})
|
|
769
|
-
}, ({ data
|
|
770
|
-
requireSessionAccess(
|
|
788
|
+
}, ({ data }) => {
|
|
789
|
+
requireSessionAccess(data.chatSessionId);
|
|
771
790
|
const chatSessionId = data.chatSessionId;
|
|
772
791
|
|
|
773
792
|
// Store latest account state on server for late joiners / refresh
|
|
@@ -803,8 +822,8 @@ export const streamHandler = createRouter()
|
|
|
803
822
|
reasoningEffort: t.Union([t.String(), t.Null()]),
|
|
804
823
|
clientId: t.Optional(t.String())
|
|
805
824
|
})
|
|
806
|
-
}, ({ data
|
|
807
|
-
requireSessionAccess(
|
|
825
|
+
}, ({ data }) => {
|
|
826
|
+
requireSessionAccess(data.chatSessionId);
|
|
808
827
|
const chatSessionId = data.chatSessionId;
|
|
809
828
|
|
|
810
829
|
// Persist to the session record so refreshes and late joiners get it.
|
|
@@ -823,9 +842,9 @@ export const streamHandler = createRouter()
|
|
|
823
842
|
});
|
|
824
843
|
})
|
|
825
844
|
|
|
826
|
-
//
|
|
827
|
-
//
|
|
828
|
-
//
|
|
845
|
+
// Profile sync — broadcast + persist the per-session active profile,
|
|
846
|
+
// mirroring chat:model-sync: choosing a profile is a run choice like the
|
|
847
|
+
// model, not an edit of the profile itself.
|
|
829
848
|
.on('chat:profile-sync', {
|
|
830
849
|
data: t.Object({
|
|
831
850
|
senderId: t.String(),
|
|
@@ -833,8 +852,8 @@ export const streamHandler = createRouter()
|
|
|
833
852
|
profileId: t.Union([t.Number(), t.Null()]),
|
|
834
853
|
clientId: t.Optional(t.String())
|
|
835
854
|
})
|
|
836
|
-
}, ({ data
|
|
837
|
-
requireSessionAccess(
|
|
855
|
+
}, ({ data }) => {
|
|
856
|
+
requireSessionAccess(data.chatSessionId);
|
|
838
857
|
try {
|
|
839
858
|
sessionQueries.updateProfile(data.chatSessionId, data.profileId);
|
|
840
859
|
} catch (err) {
|
|
@@ -900,8 +919,6 @@ export const streamHandler = createRouter()
|
|
|
900
919
|
timestamp: t.String(),
|
|
901
920
|
message_id: t.Optional(t.String()),
|
|
902
921
|
parent_message_id: t.Optional(t.Union([t.String(), t.Null()])),
|
|
903
|
-
sender_id: t.Optional(t.String()),
|
|
904
|
-
sender_name: t.Optional(t.String()),
|
|
905
922
|
engine: t.Optional(t.String()),
|
|
906
923
|
seq: t.Optional(t.Number())
|
|
907
924
|
}))
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat Apps Router
|
|
3
|
+
*
|
|
4
|
+
* Pairing chats with the connected bots: which bots there are and how they
|
|
5
|
+
* are doing, a pairing link, switching a chat on or off, a test message,
|
|
6
|
+
* unlinking, and the command reference. Connecting or removing the BOT itself
|
|
7
|
+
* is an integration. What a paired chat can DO is the control catalog.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { t } from 'elysia';
|
|
11
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
12
|
+
import { ws } from '$backend/utils/ws';
|
|
13
|
+
import {
|
|
14
|
+
cancelPairingLink,
|
|
15
|
+
createPairingLink,
|
|
16
|
+
listChannelBots,
|
|
17
|
+
listChatAppCommands,
|
|
18
|
+
onBotsChanged,
|
|
19
|
+
onLinksChanged,
|
|
20
|
+
removeChannelLink,
|
|
21
|
+
sendChannelTest,
|
|
22
|
+
setChannelLinkEnabled
|
|
23
|
+
} from '$backend/chat-apps';
|
|
24
|
+
|
|
25
|
+
const LINK_SCHEMA = t.Object({
|
|
26
|
+
id: t.String(),
|
|
27
|
+
displayName: t.Union([t.String(), t.Null()]),
|
|
28
|
+
isEnabled: t.Boolean(),
|
|
29
|
+
createdAt: t.String(),
|
|
30
|
+
lastUsedAt: t.Union([t.String(), t.Null()])
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const BOT_SCHEMA = t.Object({
|
|
34
|
+
accountId: t.String(),
|
|
35
|
+
provider: t.String(),
|
|
36
|
+
label: t.String(),
|
|
37
|
+
botName: t.Union([t.String(), t.Null()]),
|
|
38
|
+
projectId: t.Union([t.String(), t.Null()]),
|
|
39
|
+
running: t.Boolean(),
|
|
40
|
+
mode: t.Union([t.Literal('webhook'), t.Literal('polling'), t.Null()]),
|
|
41
|
+
originSource: t.Union([t.Literal('configured'), t.Literal('domain'), t.Literal('tunnel'), t.Null()]),
|
|
42
|
+
connection: t.Union([t.Literal('connecting'), t.Literal('open'), t.Literal('closed'), t.Null()]),
|
|
43
|
+
error: t.Union([t.String(), t.Null()]),
|
|
44
|
+
control: t.Boolean(),
|
|
45
|
+
links: t.Array(LINK_SCHEMA)
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const OK = t.Object({ ok: t.Boolean() });
|
|
49
|
+
|
|
50
|
+
// A chat pairs or changes itself from the phone, and a bot comes up or goes
|
|
51
|
+
// down, with no request from any tab. Every open Settings page re-reads.
|
|
52
|
+
onLinksChanged(() => ws.emit.global('chat-apps:changed', {}));
|
|
53
|
+
onBotsChanged(() => ws.emit.global('chat-apps:changed', {}));
|
|
54
|
+
|
|
55
|
+
export const chatAppsRouter = createRouter()
|
|
56
|
+
.http('chat-apps:bots', {
|
|
57
|
+
data: t.Object({
|
|
58
|
+
/** The tab's own origin: a non-local one is a better webhook address than a tunnel. */
|
|
59
|
+
requestOrigin: t.Optional(t.String())
|
|
60
|
+
}),
|
|
61
|
+
response: t.Array(BOT_SCHEMA)
|
|
62
|
+
}, async ({ data }) => {
|
|
63
|
+
return listChannelBots(data.requestOrigin);
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
.http('chat-apps:pair', {
|
|
67
|
+
data: t.Object({ accountId: t.String() }),
|
|
68
|
+
response: t.Object({ url: t.String(), expiresAt: t.String(), ttlSeconds: t.Number() })
|
|
69
|
+
}, async ({ data, conn }) => {
|
|
70
|
+
return createPairingLink(ws.getUserId(conn), data.accountId);
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
.http('chat-apps:pair-cancel', {
|
|
74
|
+
data: t.Object({ accountId: t.String() }),
|
|
75
|
+
response: OK
|
|
76
|
+
}, async ({ data, conn }) => {
|
|
77
|
+
cancelPairingLink(ws.getUserId(conn), data.accountId);
|
|
78
|
+
return { ok: true };
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
.http('chat-apps:set-enabled', {
|
|
82
|
+
data: t.Object({ linkId: t.String(), enabled: t.Boolean() }),
|
|
83
|
+
response: OK
|
|
84
|
+
}, async ({ data }) => {
|
|
85
|
+
await setChannelLinkEnabled(data.linkId, data.enabled);
|
|
86
|
+
return { ok: true };
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
.http('chat-apps:unlink', {
|
|
90
|
+
data: t.Object({ linkId: t.String() }),
|
|
91
|
+
response: OK
|
|
92
|
+
}, async ({ data }) => {
|
|
93
|
+
await removeChannelLink(data.linkId);
|
|
94
|
+
return { ok: true };
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
.http('chat-apps:test', {
|
|
98
|
+
data: t.Object({ linkId: t.String() }),
|
|
99
|
+
response: OK
|
|
100
|
+
}, async ({ data }) => {
|
|
101
|
+
await sendChannelTest(data.linkId);
|
|
102
|
+
return { ok: true };
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
.http('chat-apps:commands', {
|
|
106
|
+
data: t.Object({}),
|
|
107
|
+
response: t.Array(t.Object({
|
|
108
|
+
command: t.String(),
|
|
109
|
+
hint: t.Union([t.String(), t.Null()]),
|
|
110
|
+
description: t.String(),
|
|
111
|
+
group: t.String()
|
|
112
|
+
}))
|
|
113
|
+
}, async () => {
|
|
114
|
+
return listChatAppCommands();
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
.emit('chat-apps:changed', t.Object({}));
|
|
@@ -1,30 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Containers — changing something
|
|
3
|
-
*
|
|
4
|
-
* The routes are listed in ADMIN_ONLY_ROUTES; these handlers still check host
|
|
5
|
-
* access against the caller's real role rather than a hardcoded one, because a
|
|
6
|
-
* gate that trusts its caller is no gate at all.
|
|
7
|
-
*
|
|
8
|
-
* Stopping a container takes down whatever it serves, for everyone — the same
|
|
9
|
-
* reason stopping a port is admin-only — and removing an image or a volume
|
|
10
|
-
* takes down something nobody can bring back by pressing start.
|
|
2
|
+
* Containers — changing something: start/stop/restart, remove, prune. Every
|
|
3
|
+
* handler first confirms the host is the local machine or a saved SSH host.
|
|
11
4
|
*/
|
|
12
5
|
|
|
13
6
|
import { t } from 'elysia';
|
|
14
7
|
import { createRouter } from '$shared/utils/ws-server';
|
|
15
|
-
import { LOCAL_HOST_ID } from '$shared/types/host';
|
|
16
8
|
import { removeResource, runContainerAction } from '../../containers/actions';
|
|
17
9
|
import { dismissPrune, pruneJobFor, startPrune } from '../../containers/prune-job';
|
|
18
|
-
import {
|
|
10
|
+
import { requireHost } from './list';
|
|
19
11
|
import { containerMonitor } from '../../containers/monitor';
|
|
20
|
-
import { sshConnectionQueries } from '../../database/queries';
|
|
21
12
|
import { ws } from '../../utils/ws';
|
|
22
13
|
|
|
23
|
-
function requireManageAccess(conn: Parameters<typeof ws.getUserId>[0], hostId: string): void {
|
|
24
|
-
if (hostId === LOCAL_HOST_ID) return;
|
|
25
|
-
sshConnectionQueries.ensureAccess(hostId, ws.getUserId(conn), ws.getRole(conn) === 'admin');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
14
|
const ACTIONS = [
|
|
29
15
|
t.Literal('start'),
|
|
30
16
|
t.Literal('stop'),
|
|
@@ -55,8 +41,8 @@ export const containersActionHandler = createRouter()
|
|
|
55
41
|
}),
|
|
56
42
|
response: t.Any()
|
|
57
43
|
},
|
|
58
|
-
async ({ data
|
|
59
|
-
|
|
44
|
+
async ({ data }) => {
|
|
45
|
+
requireHost(data.hostId);
|
|
60
46
|
|
|
61
47
|
// Re-read before acting rather than trusting the row the client clicked:
|
|
62
48
|
// a listing is a second or two old, and a container can be removed and
|
|
@@ -97,8 +83,8 @@ export const containersActionHandler = createRouter()
|
|
|
97
83
|
}),
|
|
98
84
|
response: t.Any()
|
|
99
85
|
},
|
|
100
|
-
async ({ data
|
|
101
|
-
|
|
86
|
+
async ({ data }) => {
|
|
87
|
+
requireHost(data.hostId);
|
|
102
88
|
return { result: await removeResource(data.hostId, data.kind, data.id, data.force === true) };
|
|
103
89
|
}
|
|
104
90
|
)
|
|
@@ -124,7 +110,7 @@ export const containersActionHandler = createRouter()
|
|
|
124
110
|
response: t.Any()
|
|
125
111
|
},
|
|
126
112
|
async ({ data, conn }) => {
|
|
127
|
-
|
|
113
|
+
requireHost(data.hostId);
|
|
128
114
|
return { job: startPrune(data.hostId, data.kinds, ws.getUserId(conn)) };
|
|
129
115
|
}
|
|
130
116
|
)
|
|
@@ -139,7 +125,7 @@ export const containersActionHandler = createRouter()
|
|
|
139
125
|
'containers:prune-status',
|
|
140
126
|
{ data: t.Object({ hostId: t.String({ minLength: 1 }) }), response: t.Any() },
|
|
141
127
|
async ({ data, conn }) => {
|
|
142
|
-
|
|
128
|
+
requireHost(data.hostId);
|
|
143
129
|
return { job: pruneJobFor(data.hostId, ws.getUserId(conn)) };
|
|
144
130
|
}
|
|
145
131
|
)
|
|
@@ -148,8 +134,8 @@ export const containersActionHandler = createRouter()
|
|
|
148
134
|
.http(
|
|
149
135
|
'containers:prune-dismiss',
|
|
150
136
|
{ data: t.Object({ hostId: t.String({ minLength: 1 }) }), response: t.Any() },
|
|
151
|
-
async ({ data
|
|
152
|
-
|
|
137
|
+
async ({ data }) => {
|
|
138
|
+
requireHost(data.hostId);
|
|
153
139
|
dismissPrune(data.hostId);
|
|
154
140
|
return { ok: true };
|
|
155
141
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Container manager WebSocket router.
|
|
3
3
|
*
|
|
4
|
-
* Reading the list, the detail and the logs
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* own `authorize`.
|
|
4
|
+
* Reading the list, the detail and the logs of a host that still exists;
|
|
5
|
+
* changing containers; and a shell, authorized inside the PtyKit server's own
|
|
6
|
+
* `authorize`.
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
import { t } from 'elysia';
|
|
@@ -20,23 +20,17 @@ import { stopLogStreamsForUser } from '../../containers/logs';
|
|
|
20
20
|
import { sshConnectionQueries } from '../../database/queries';
|
|
21
21
|
import { ws } from '../../utils/ws';
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
* is watchable by anyone signed in — it is the machine they are already using
|
|
26
|
-
* Clopen on.
|
|
27
|
-
*/
|
|
28
|
-
export function requireHostAccess(conn: Parameters<typeof ws.getUserId>[0], hostId: string): void {
|
|
23
|
+
/** The local machine, or a saved SSH host that still exists. */
|
|
24
|
+
export function requireHost(hostId: string): void {
|
|
29
25
|
if (hostId === LOCAL_HOST_ID) return;
|
|
30
|
-
|
|
31
|
-
const isAdmin = ws.getRole(conn) === 'admin';
|
|
32
|
-
sshConnectionQueries.ensureAccess(hostId, userId, isAdmin);
|
|
26
|
+
sshConnectionQueries.require(hostId);
|
|
33
27
|
}
|
|
34
28
|
|
|
35
29
|
const hostSchema = t.Object({ hostId: t.String({ minLength: 1 }) });
|
|
36
30
|
|
|
37
31
|
export const containersListHandler = createRouter()
|
|
38
32
|
.http('containers:watch', { data: hostSchema, response: t.Any() }, async ({ data, conn }) => {
|
|
39
|
-
|
|
33
|
+
requireHost(data.hostId);
|
|
40
34
|
const userId = ws.getUserId(conn);
|
|
41
35
|
|
|
42
36
|
const result = await containerMonitor.watch(data.hostId, userId);
|
|
@@ -68,11 +62,6 @@ export const containersListHandler = createRouter()
|
|
|
68
62
|
|
|
69
63
|
/**
|
|
70
64
|
* Everything `inspect` knows, read only when a detail pane opens.
|
|
71
|
-
*
|
|
72
|
-
* Environment values are stripped for anyone but an admin. A container's env
|
|
73
|
-
* is where its database password lives, and this panel is reachable by every
|
|
74
|
-
* member and through a shared Remote Access link — so the keys are shown,
|
|
75
|
-
* which is what makes the pane useful, and the values are not.
|
|
76
65
|
*/
|
|
77
66
|
.http(
|
|
78
67
|
'containers:inspect',
|
|
@@ -83,30 +72,15 @@ export const containersListHandler = createRouter()
|
|
|
83
72
|
}),
|
|
84
73
|
response: t.Any()
|
|
85
74
|
},
|
|
86
|
-
async ({ data
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!detail || ws.getRole(conn) === 'admin') return { detail, envRedacted: false };
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
detail: {
|
|
93
|
-
...detail,
|
|
94
|
-
env: detail.env.map((line) => {
|
|
95
|
-
const split = line.indexOf('=');
|
|
96
|
-
return split <= 0 ? line : `${line.slice(0, split)}=`;
|
|
97
|
-
})
|
|
98
|
-
},
|
|
99
|
-
envRedacted: true
|
|
100
|
-
};
|
|
75
|
+
async ({ data }) => {
|
|
76
|
+
requireHost(data.hostId);
|
|
77
|
+
return { detail: await inspectContainer(data.hostId, data.containerId) };
|
|
101
78
|
}
|
|
102
79
|
)
|
|
103
80
|
|
|
104
81
|
/**
|
|
105
82
|
* What the host is holding and how much of it is reclaimable.
|
|
106
83
|
*
|
|
107
|
-
* Read-only, so any member may ask — it is the same `system df` they would
|
|
108
|
-
* run in a terminal, and knowing the disk is full is not a privilege.
|
|
109
|
-
*
|
|
110
84
|
* Returns whatever was last measured, immediately, and reports whether a
|
|
111
85
|
* fresh reading is on its way; that one arrives as
|
|
112
86
|
* `containers:disk-usage-measured`. The measurement cannot be awaited here
|
|
@@ -124,7 +98,7 @@ export const containersListHandler = createRouter()
|
|
|
124
98
|
response: t.Any()
|
|
125
99
|
},
|
|
126
100
|
async ({ data, conn }) => {
|
|
127
|
-
|
|
101
|
+
requireHost(data.hostId);
|
|
128
102
|
return requestDiskUsage(data.hostId, ws.getUserId(conn), data.force ?? false);
|
|
129
103
|
}
|
|
130
104
|
)
|
|
@@ -139,8 +113,8 @@ export const containersListHandler = createRouter()
|
|
|
139
113
|
}),
|
|
140
114
|
response: t.Any()
|
|
141
115
|
},
|
|
142
|
-
async ({ data
|
|
143
|
-
|
|
116
|
+
async ({ data }) => {
|
|
117
|
+
requireHost(data.hostId);
|
|
144
118
|
return { stats: await readStats(data.hostId, data.containerId) };
|
|
145
119
|
}
|
|
146
120
|
);
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { t } from 'elysia';
|
|
11
11
|
import { createRouter } from '$shared/utils/ws-server';
|
|
12
12
|
import { startLogStream, stopLogStream } from '../../containers/logs';
|
|
13
|
-
import {
|
|
13
|
+
import { requireHost } from './list';
|
|
14
14
|
import { ws } from '../../utils/ws';
|
|
15
15
|
|
|
16
16
|
export const containersLogsHandler = createRouter()
|
|
@@ -24,7 +24,7 @@ export const containersLogsHandler = createRouter()
|
|
|
24
24
|
response: t.Any()
|
|
25
25
|
},
|
|
26
26
|
async ({ data, conn }) => {
|
|
27
|
-
|
|
27
|
+
requireHost(data.hostId);
|
|
28
28
|
const userId = ws.getUserId(conn);
|
|
29
29
|
|
|
30
30
|
const started = await startLogStream(data.hostId, data.containerId, userId);
|
|
@@ -35,9 +35,8 @@ function getContainerPtyConnection(conn: WSConnection): PtyKitConnection {
|
|
|
35
35
|
if (existing) return existing;
|
|
36
36
|
|
|
37
37
|
const userId = ws.getUserId(conn);
|
|
38
|
-
const isAdmin = ws.getRole(conn) === 'admin';
|
|
39
38
|
const ptyConn = containerPtyKitServer.createConnection({
|
|
40
|
-
data: { userId,
|
|
39
|
+
data: { userId, connId },
|
|
41
40
|
send: (frame) => {
|
|
42
41
|
ws.sendToConnectionId(connId, JSON.stringify({ action: 'containers:pty-out', payload: frame }));
|
|
43
42
|
}
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
import type { WSConnection } from '$shared/utils/ws-server';
|
|
2
|
-
import { ws } from '$backend/utils/ws';
|
|
3
1
|
import { dbClientConnectionQueries } from '../../database/queries';
|
|
4
2
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
isAdmin: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function getDbClientPrincipal(conn: WSConnection): DbClientPrincipal {
|
|
11
|
-
const userId = ws.getUserId(conn);
|
|
12
|
-
const isAdmin = ws.getRole(conn) === 'admin';
|
|
13
|
-
return { userId, isAdmin };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function requireDbClientConnectionAccess(conn: WSConnection, connectionId: string) {
|
|
17
|
-
const { userId, isAdmin } = getDbClientPrincipal(conn);
|
|
18
|
-
return dbClientConnectionQueries.ensureAccess(connectionId, userId, isAdmin);
|
|
3
|
+
export function requireDbClientConnection(connectionId: string) {
|
|
4
|
+
return dbClientConnectionQueries.require(connectionId);
|
|
19
5
|
}
|