@myrialabs/clopen 0.4.47 → 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.
Files changed (325) hide show
  1. package/README.md +11 -11
  2. package/backend/artifacts/project/sources.ts +1 -1
  3. package/backend/auth/auth-service.ts +52 -358
  4. package/backend/auth/onboarding.test.ts +2 -3
  5. package/backend/auth/permissions.test.ts +10 -20
  6. package/backend/auth/permissions.ts +4 -290
  7. package/backend/auth/rate-limiter.test.ts +8 -9
  8. package/backend/auth/rate-limiter.ts +0 -2
  9. package/backend/auth/tokens.ts +1 -8
  10. package/backend/bootstrap.ts +7 -0
  11. package/backend/chat/attachments.test.ts +88 -0
  12. package/backend/chat/attachments.ts +159 -0
  13. package/backend/chat/engine-handoff.test.ts +0 -2
  14. package/backend/chat/stream-manager.ts +62 -62
  15. package/backend/chat/turn-answer.test.ts +64 -0
  16. package/backend/chat/turn-answer.ts +125 -0
  17. package/backend/chat-apps/awaiting.test.ts +39 -0
  18. package/backend/chat-apps/awaiting.ts +49 -0
  19. package/backend/chat-apps/conversation.ts +746 -0
  20. package/backend/chat-apps/inbound.ts +324 -0
  21. package/backend/chat-apps/index.ts +309 -0
  22. package/backend/chat-apps/link-events.ts +20 -0
  23. package/backend/chat-apps/media.test.ts +62 -0
  24. package/backend/chat-apps/media.ts +208 -0
  25. package/backend/chat-apps/messages.test.ts +229 -0
  26. package/backend/chat-apps/messages.ts +365 -0
  27. package/backend/chat-apps/outbound.ts +243 -0
  28. package/backend/chat-apps/pairing.test.ts +45 -0
  29. package/backend/chat-apps/pairing.ts +74 -0
  30. package/backend/chat-apps/platforms/index.ts +20 -0
  31. package/backend/chat-apps/platforms/telegram.test.ts +35 -0
  32. package/backend/chat-apps/platforms/telegram.ts +191 -0
  33. package/backend/chat-apps/platforms/types.ts +114 -0
  34. package/backend/chat-apps/questions.ts +133 -0
  35. package/backend/chat-apps/runtime.ts +572 -0
  36. package/backend/chat-apps/storage.test.ts +201 -0
  37. package/backend/chat-apps/turns.test.ts +45 -0
  38. package/backend/chat-apps/turns.ts +208 -0
  39. package/backend/containers/pty.ts +3 -11
  40. package/backend/control/actions/accounts.ts +89 -0
  41. package/backend/control/actions/files.ts +116 -0
  42. package/backend/control/actions/models.ts +188 -0
  43. package/backend/control/actions/projects.ts +272 -0
  44. package/backend/control/actions/sessions.ts +280 -0
  45. package/backend/control/actions/skills.ts +111 -0
  46. package/backend/control/control.test.ts +169 -0
  47. package/backend/control/define.ts +20 -0
  48. package/backend/control/folders.test.ts +67 -0
  49. package/backend/control/index.ts +213 -0
  50. package/backend/control/invoke.ts +44 -0
  51. package/backend/control/links.ts +35 -0
  52. package/backend/control/paging.ts +26 -0
  53. package/backend/control/types.ts +117 -0
  54. package/backend/control/workspace.ts +127 -0
  55. package/backend/database/migrations/084_create_channel_links.ts +71 -0
  56. package/backend/database/migrations/085_add_home_projects.ts +36 -0
  57. package/backend/database/migrations/086_single_owner.test.ts +170 -0
  58. package/backend/database/migrations/086_single_owner.ts +418 -0
  59. package/backend/database/migrations/index.ts +21 -0
  60. package/backend/database/queries/auth-queries.ts +7 -85
  61. package/backend/database/queries/channel-queries.ts +270 -0
  62. package/backend/database/queries/db-client-connection-queries.ts +18 -56
  63. package/backend/database/queries/file-share-queries.ts +5 -23
  64. package/backend/database/queries/git-identity-queries.ts +31 -42
  65. package/backend/database/queries/graph-queries.ts +1 -1
  66. package/backend/database/queries/index.ts +13 -1
  67. package/backend/database/queries/message-queries.test.ts +146 -0
  68. package/backend/database/queries/message-queries.ts +42 -1
  69. package/backend/database/queries/permission-set-queries.ts +1 -1
  70. package/backend/database/queries/profile-queries.ts +1 -1
  71. package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
  72. package/backend/database/queries/project-queries.ts +50 -63
  73. package/backend/database/queries/session-queries.ts +28 -56
  74. package/backend/database/queries/ssh-connection-queries.ts +18 -41
  75. package/backend/db-client/integrations/projector.ts +0 -5
  76. package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
  77. package/backend/engine/adapters/claude/message-converter.ts +25 -2
  78. package/backend/engine/adapters/cline/message-converter.ts +0 -1
  79. package/backend/engine/adapters/cline/stream.ts +11 -15
  80. package/backend/engine/adapters/codex/message-converter.ts +0 -2
  81. package/backend/engine/adapters/copilot/message-converter.ts +1 -2
  82. package/backend/engine/adapters/cursor/message-converter.ts +0 -1
  83. package/backend/engine/adapters/opencode/message-converter.ts +2 -4
  84. package/backend/engine/adapters/opencode/stream.ts +11 -0
  85. package/backend/engine/adapters/parent-scope.test.ts +38 -0
  86. package/backend/engine/adapters/parent-scope.ts +44 -0
  87. package/backend/engine/adapters/pi/message-converter.ts +0 -1
  88. package/backend/engine/adapters/pi/stream.ts +4 -5
  89. package/backend/engine/adapters/qwen/message-converter.ts +0 -2
  90. package/backend/engine/bootstrap-default-engine.ts +2 -2
  91. package/backend/engine/docs/adapter-contract.md +8 -1
  92. package/backend/engine/install-runner.ts +8 -17
  93. package/backend/files/file-shares.ts +20 -44
  94. package/backend/files/file-size-limit.ts +3 -3
  95. package/backend/files/image-processing.ts +1 -1
  96. package/backend/files/os-clipboard.ts +2 -2
  97. package/backend/git/git-executor.ts +25 -5
  98. package/backend/git/git-service.ts +420 -19
  99. package/backend/git/identity/credential-helper.test.ts +2 -7
  100. package/backend/git/identity/import-local.test.ts +11 -16
  101. package/backend/git/identity/import-local.ts +12 -12
  102. package/backend/git/identity/index.ts +10 -24
  103. package/backend/git/identity/resolve.ts +13 -14
  104. package/backend/git/identity/scope-config.ts +33 -28
  105. package/backend/git/identity/service.ts +44 -47
  106. package/backend/git/op-lock.test.ts +111 -0
  107. package/backend/git/op-lock.ts +180 -0
  108. package/backend/git/remote-sync.test.ts +249 -0
  109. package/backend/host/metrics.ts +1 -1
  110. package/backend/http/bearer-auth.ts +1 -2
  111. package/backend/http/files-download.test.ts +8 -9
  112. package/backend/http/files-download.ts +2 -2
  113. package/backend/http/files-shared.test.ts +62 -89
  114. package/backend/http/files-shared.ts +2 -2
  115. package/backend/http/files-upload.test.ts +3 -7
  116. package/backend/http/files-upload.ts +3 -3
  117. package/backend/http/notes-images.test.ts +15 -38
  118. package/backend/http/notes-images.ts +6 -8
  119. package/backend/http/ssh-sftp.ts +5 -10
  120. package/backend/index.ts +21 -7
  121. package/backend/integrations/accounts.ts +61 -3
  122. package/backend/integrations/index.ts +2 -2
  123. package/backend/integrations/registry/define.ts +15 -0
  124. package/backend/integrations/registry/index.ts +2 -0
  125. package/backend/integrations/registry/providers/telegram.ts +54 -0
  126. package/backend/integrations/registry/types.ts +21 -1
  127. package/backend/integrations/webhooks/gateway.ts +7 -6
  128. package/backend/integrations/webhooks/verify.test.ts +30 -0
  129. package/backend/integrations/webhooks/verify.ts +4 -0
  130. package/backend/mcp/external/project.ts +1 -1
  131. package/backend/mcp/internal/remote-server.test.ts +1 -3
  132. package/backend/mcp/internal/remote-server.ts +4 -4
  133. package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
  134. package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
  135. package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
  136. package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
  137. package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
  138. package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
  139. package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
  140. package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
  141. package/backend/memory/redact.ts +1 -1
  142. package/backend/notes/access.test.ts +28 -29
  143. package/backend/notes/access.ts +6 -11
  144. package/backend/permissions/service.ts +1 -1
  145. package/backend/preview/browser/browser-clipboard.test.ts +46 -0
  146. package/backend/preview/browser/browser-clipboard.ts +67 -0
  147. package/backend/preview/browser/browser-dialog-handler.ts +95 -6
  148. package/backend/preview/browser/browser-host-bridge.ts +9 -0
  149. package/backend/preview/browser/browser-interaction-handler.ts +316 -86
  150. package/backend/preview/browser/browser-mcp-control.ts +34 -0
  151. package/backend/preview/browser/browser-pool.ts +67 -6
  152. package/backend/preview/browser/browser-preview-service.ts +361 -25
  153. package/backend/preview/browser/browser-tab-manager.ts +66 -23
  154. package/backend/preview/browser/browser-video-capture.ts +92 -5
  155. package/backend/preview/browser/element-locator.ts +190 -17
  156. package/backend/preview/browser/keyboard-chords.test.ts +68 -0
  157. package/backend/preview/browser/keyboard-chords.ts +132 -0
  158. package/backend/preview/browser/paste.ts +81 -0
  159. package/backend/preview/browser/process-usage.ts +142 -0
  160. package/backend/preview/browser/profile-lock.ts +209 -0
  161. package/backend/preview/browser/scripts/host-bridge.ts +59 -0
  162. package/backend/preview/browser/scripts/video-stream.ts +58 -0
  163. package/backend/preview/browser/types.ts +40 -2
  164. package/backend/preview/browser/viewport.test.ts +45 -0
  165. package/backend/preview/browser/viewport.ts +96 -0
  166. package/backend/profiles/service.ts +2 -2
  167. package/backend/project/status-manager.ts +43 -172
  168. package/backend/projects/home.ts +61 -0
  169. package/backend/projects/project-cleanup.integration.test.ts +2 -2
  170. package/backend/projects/project-cleanup.ts +0 -8
  171. package/backend/skills/service.ts +2 -3
  172. package/backend/snapshot/helpers.ts +0 -1
  173. package/backend/snapshot/restore.ts +252 -0
  174. package/backend/ssh/ptykit.ts +1 -2
  175. package/backend/terminal/ptykit.ts +5 -8
  176. package/backend/tunnel/public-origin.ts +31 -20
  177. package/backend/utils/user-helpers.ts +0 -55
  178. package/backend/utils/ws.ts +61 -154
  179. package/backend/worktrees/branching/engine.ts +3 -16
  180. package/backend/worktrees/branching/index.ts +1 -1
  181. package/backend/worktrees/branching/projector.ts +1 -1
  182. package/backend/worktrees/branching/service.ts +13 -25
  183. package/backend/ws/access.ts +12 -21
  184. package/backend/ws/artifacts/generate.ts +2 -2
  185. package/backend/ws/auth/device.ts +16 -71
  186. package/backend/ws/auth/index.ts +4 -22
  187. package/backend/ws/auth/login.test.ts +14 -60
  188. package/backend/ws/auth/login.ts +24 -124
  189. package/backend/ws/auth/status.ts +0 -1
  190. package/backend/ws/chat/composer.ts +118 -118
  191. package/backend/ws/chat/stream.ts +64 -47
  192. package/backend/ws/chat-apps/index.ts +117 -0
  193. package/backend/ws/containers/actions.ts +11 -25
  194. package/backend/ws/containers/index.ts +3 -4
  195. package/backend/ws/containers/list.ts +10 -36
  196. package/backend/ws/containers/logs.ts +2 -2
  197. package/backend/ws/containers/tunnel.ts +1 -2
  198. package/backend/ws/db-client/access.ts +2 -16
  199. package/backend/ws/db-client/accounts.ts +5 -15
  200. package/backend/ws/db-client/connections.ts +17 -25
  201. package/backend/ws/db-client/context.ts +1 -1
  202. package/backend/ws/db-client/env.ts +7 -10
  203. package/backend/ws/db-client/index.ts +2 -2
  204. package/backend/ws/db-client/io.ts +5 -5
  205. package/backend/ws/db-client/query-history-retention.test.ts +8 -8
  206. package/backend/ws/db-client/query.ts +18 -17
  207. package/backend/ws/db-client/schema.ts +13 -13
  208. package/backend/ws/db-client/structure.ts +35 -35
  209. package/backend/ws/db-client/supabase.ts +4 -21
  210. package/backend/ws/deployments/context.ts +1 -1
  211. package/backend/ws/deployments/crud.ts +0 -5
  212. package/backend/ws/engine/access.ts +7 -20
  213. package/backend/ws/engine/claude/accounts.ts +4 -4
  214. package/backend/ws/engine/cline/accounts.ts +5 -5
  215. package/backend/ws/engine/codex/accounts.ts +3 -3
  216. package/backend/ws/engine/pi/accounts.ts +5 -5
  217. package/backend/ws/files/clipboard.ts +8 -27
  218. package/backend/ws/files/image-edit.ts +6 -6
  219. package/backend/ws/files/index.ts +1 -1
  220. package/backend/ws/files/path-access.test.ts +32 -131
  221. package/backend/ws/files/path-access.ts +8 -87
  222. package/backend/ws/files/read.ts +15 -19
  223. package/backend/ws/files/reveal.ts +3 -3
  224. package/backend/ws/files/search.ts +7 -7
  225. package/backend/ws/files/share.ts +9 -13
  226. package/backend/ws/files/state.ts +9 -12
  227. package/backend/ws/files/watch.ts +3 -3
  228. package/backend/ws/files/write.ts +30 -31
  229. package/backend/ws/git/branch.ts +80 -59
  230. package/backend/ws/git/commit.ts +63 -44
  231. package/backend/ws/git/conflict.ts +16 -18
  232. package/backend/ws/git/identity-context.ts +8 -17
  233. package/backend/ws/git/identity.ts +17 -27
  234. package/backend/ws/git/index.ts +3 -1
  235. package/backend/ws/git/op-state.ts +139 -0
  236. package/backend/ws/git/remote.ts +241 -141
  237. package/backend/ws/git/repo-context.ts +67 -0
  238. package/backend/ws/git/staging.ts +18 -28
  239. package/backend/ws/git/status.ts +5 -2
  240. package/backend/ws/index.ts +5 -1
  241. package/backend/ws/instructions/crud.ts +1 -1
  242. package/backend/ws/integrations/crud.ts +1 -3
  243. package/backend/ws/mcp/crud.ts +3 -5
  244. package/backend/ws/mcp/tools.ts +1 -1
  245. package/backend/ws/memory/crud.ts +14 -46
  246. package/backend/ws/memory/index.ts +2 -2
  247. package/backend/ws/messages/crud.ts +29 -8
  248. package/backend/ws/notes/index.ts +33 -39
  249. package/backend/ws/permissions/crud.ts +3 -4
  250. package/backend/ws/ports/index.ts +1 -2
  251. package/backend/ws/ports/kill.ts +5 -10
  252. package/backend/ws/ports/list.ts +4 -10
  253. package/backend/ws/preview/access.ts +1 -1
  254. package/backend/ws/preview/browser/interact.ts +52 -79
  255. package/backend/ws/preview/browser/native-ui.ts +24 -0
  256. package/backend/ws/preview/browser/stats.ts +98 -1
  257. package/backend/ws/preview/browser/tab-info.ts +15 -0
  258. package/backend/ws/preview/browser/tab.ts +19 -4
  259. package/backend/ws/preview/index.ts +27 -0
  260. package/backend/ws/profiles/crud.ts +6 -8
  261. package/backend/ws/project-artifacts/index.ts +30 -31
  262. package/backend/ws/projects/crud.ts +33 -35
  263. package/backend/ws/projects/index.ts +3 -8
  264. package/backend/ws/projects/info.ts +3 -3
  265. package/backend/ws/projects/overview.ts +19 -30
  266. package/backend/ws/projects/status.ts +17 -57
  267. package/backend/ws/sessions/crud.ts +34 -45
  268. package/backend/ws/sessions/index.ts +1 -1
  269. package/backend/ws/settings/crud.ts +1 -1
  270. package/backend/ws/skills/crud.ts +3 -4
  271. package/backend/ws/skills/index.ts +1 -1
  272. package/backend/ws/snapshot/changes.ts +7 -7
  273. package/backend/ws/snapshot/restore.ts +11 -295
  274. package/backend/ws/snapshot/timeline.ts +2 -4
  275. package/backend/ws/ssh/access.ts +6 -21
  276. package/backend/ws/ssh/connections.ts +21 -31
  277. package/backend/ws/ssh/forwards.ts +12 -12
  278. package/backend/ws/ssh/sftp.ts +34 -34
  279. package/backend/ws/ssh/tunnel.ts +1 -2
  280. package/backend/ws/stack/install.ts +7 -17
  281. package/backend/ws/subagents/crud.ts +1 -1
  282. package/backend/ws/tunnel/share.ts +0 -2
  283. package/backend/ws/user/crud.ts +1 -59
  284. package/backend/ws/user/index.ts +1 -1
  285. package/backend/ws/work/context.ts +1 -1
  286. package/backend/ws/work/crud.ts +0 -5
  287. package/backend/ws/workspace/state.ts +10 -13
  288. package/backend/ws/worktrees/branching.ts +7 -36
  289. package/backend/ws/worktrees/crud.ts +2 -2
  290. package/bin/clopen.ts +10 -11
  291. package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
  292. package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
  293. package/dist/assets/main-BUiUL3eZ.css +1 -0
  294. package/dist/assets/main-nBOb9YOA.js +1240 -0
  295. package/dist/index.html +2 -2
  296. package/package.json +2 -1
  297. package/shared/constants/attachments.ts +14 -0
  298. package/shared/constants/engine-tools.ts +1 -1
  299. package/shared/constants/preview.test.ts +259 -0
  300. package/shared/constants/preview.ts +1018 -57
  301. package/shared/constants/tool-icons.ts +5 -0
  302. package/shared/types/containers/container.ts +1 -1
  303. package/shared/types/database/schema.ts +9 -6
  304. package/shared/types/git-identity.ts +1 -1
  305. package/shared/types/git.ts +116 -0
  306. package/shared/types/integrations.ts +7 -0
  307. package/shared/types/stores/settings.ts +1 -1
  308. package/shared/types/unified/index.ts +1 -1
  309. package/shared/types/unified/message.ts +0 -7
  310. package/shared/types/unified/stream.ts +2 -4
  311. package/shared/types/unified/tool.ts +15 -1
  312. package/shared/utils/ask-user-question.test.ts +319 -0
  313. package/shared/utils/ask-user-question.ts +154 -0
  314. package/shared/utils/home-project.ts +25 -0
  315. package/shared/utils/logger.ts +2 -0
  316. package/shared/utils/ws-server.ts +32 -7
  317. package/backend/auth/session-invalidation.test.ts +0 -112
  318. package/backend/auth/session-invalidation.ts +0 -77
  319. package/backend/project/status-manager.test.ts +0 -32
  320. package/backend/ws/auth/invites.ts +0 -94
  321. package/backend/ws/auth/users.ts +0 -112
  322. package/backend/ws/projects/presence.ts +0 -46
  323. package/backend/ws/stack/access.ts +0 -31
  324. package/dist/assets/main-BiDNMWb3.css +0 -1
  325. 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
- * Broadcast presence + notify project members when a chat message may flip the
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
- * Shared by the initial-stream and reconnect message handlers so the two paths
59
- * cannot drift apart again.
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 all project members when AskUserQuestion arrives (sound + push)
83
- if (askToolUse && projectId) {
95
+ // Notify every device when AskUserQuestion arrives (sound + push)
96
+ if (askToolUse) {
84
97
  const context = resolveNotificationContext(projectId, chatSessionId);
85
98
 
86
- ws.emit.projectMembers(projectId, 'chat:waiting-input', {
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 all project members (cross-project notification for sound + push)
140
- ws.emit.projectMembers(projectId, 'chat:stream-finished', {
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 project members when a snapshot is captured (so the timeline modal can refresh stats)
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.projectMembers(projectId, 'snapshot:captured', { projectId, chatSessionId });
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
- // Broadcast presence + notify when waiting-input state may change
235
- handleWaitingInputChange(event, chatSessionId, projectId);
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
- const streamId = await streamManager.startStream({ ...request, projectPath: workingRoot });
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, sender info and the saved message id).
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(conn, data.chatSessionId);
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(conn, data.chatSessionId);
501
+ requireSessionAccess(data.chatSessionId);
482
502
  const projectId = ws.getProjectId(conn);
483
503
 
484
- // The WS user id is server-trusted (unlike the client-supplied sender)
485
- // and routes background Web Push to the requester's devices. Missing
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(conn, data.chatSessionId);
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(conn, data.chatSessionId);
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(conn, data.chatSessionId);
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(conn, data.chatSessionId);
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
- // Collaborative model sync - broadcast model changes to other users in the same chat session
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 collaborators never end up on a level the model lacks.
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, conn }) => {
723
- requireSessionAccess(conn, data.chatSessionId);
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
- // Collaborative account sync - broadcast account changes to other users in the same chat session
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, conn }) => {
770
- requireSessionAccess(conn, data.chatSessionId);
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, conn }) => {
807
- requireSessionAccess(conn, data.chatSessionId);
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
- // Collaborative profile sync — broadcast + persist the per-session active
827
- // profile, mirroring chat:model-sync. Non-admin: choosing a profile is a run
828
- // choice like the model, not an admin mutation of the profile itself.
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, conn }) => {
837
- requireSessionAccess(conn, data.chatSessionId);
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. Admin only, all of it.
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 { requireHostAccess } from './list';
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, conn }) => {
59
- requireManageAccess(conn, data.hostId);
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, conn }) => {
101
- requireManageAccess(conn, data.hostId);
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
- requireManageAccess(conn, data.hostId);
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
- requireHostAccess(conn, data.hostId);
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, conn }) => {
152
- requireManageAccess(conn, data.hostId);
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 is open to any signed-in user who
5
- * can already reach the host; `containers:action` is registered in
6
- * ADMIN_ONLY_ROUTES, and opening a shell is gated inside the PtyKit server's
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
- * A member may only watch an SSH host they can already reach. The local machine
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
- const userId = ws.getUserId(conn);
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
- requireHostAccess(conn, data.hostId);
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, conn }) => {
87
- requireHostAccess(conn, data.hostId);
88
- const detail = await inspectContainer(data.hostId, data.containerId);
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
- requireHostAccess(conn, data.hostId);
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, conn }) => {
143
- requireHostAccess(conn, data.hostId);
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 { requireHostAccess } from './list';
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
- requireHostAccess(conn, data.hostId);
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, isAdmin, connId },
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 interface DbClientPrincipal {
6
- userId: string;
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
  }