agent-relay 1.3.0 → 1.3.2

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 (240) hide show
  1. package/.trajectories/active/traj_3yx9dy148mge.json +42 -0
  2. package/.trajectories/completed/2026-01/traj_1g7yx6qtg4ai.json +49 -0
  3. package/.trajectories/completed/2026-01/traj_1g7yx6qtg4ai.md +31 -0
  4. package/.trajectories/completed/2026-01/traj_4qwd4zmhfwp4.json +49 -0
  5. package/.trajectories/completed/2026-01/traj_4qwd4zmhfwp4.md +31 -0
  6. package/.trajectories/completed/2026-01/traj_6unwwmgyj5sq.json +109 -0
  7. package/.trajectories/completed/2026-01/traj_a0tqx8biw9c4.json +49 -0
  8. package/.trajectories/completed/2026-01/traj_a0tqx8biw9c4.md +31 -0
  9. package/.trajectories/completed/2026-01/traj_ax8uungxz2qh.json +66 -0
  10. package/.trajectories/completed/2026-01/traj_ax8uungxz2qh.md +36 -0
  11. package/.trajectories/completed/2026-01/traj_c9izbh2snpzf.json +49 -0
  12. package/.trajectories/completed/2026-01/traj_c9izbh2snpzf.md +31 -0
  13. package/.trajectories/completed/2026-01/traj_cpn70dw066nt.json +65 -0
  14. package/.trajectories/completed/2026-01/traj_cpn70dw066nt.md +37 -0
  15. package/.trajectories/completed/2026-01/traj_erglv2f8t9eh.json +36 -0
  16. package/.trajectories/completed/2026-01/traj_erglv2f8t9eh.md +21 -0
  17. package/.trajectories/completed/2026-01/traj_he75f24d1xfm.json +101 -0
  18. package/.trajectories/completed/2026-01/traj_he75f24d1xfm.md +52 -0
  19. package/.trajectories/completed/2026-01/traj_lgtodco7dp1n.json +61 -0
  20. package/.trajectories/completed/2026-01/traj_lgtodco7dp1n.md +36 -0
  21. package/.trajectories/completed/2026-01/traj_oszg9flv74pk.json +73 -0
  22. package/.trajectories/completed/2026-01/traj_oszg9flv74pk.md +41 -0
  23. package/.trajectories/completed/2026-01/traj_pulomd3y8cvj.json +77 -0
  24. package/.trajectories/completed/2026-01/traj_pulomd3y8cvj.md +42 -0
  25. package/.trajectories/completed/2026-01/traj_rsavt0jipi3c.json +109 -0
  26. package/.trajectories/completed/2026-01/traj_rsavt0jipi3c.md +56 -0
  27. package/.trajectories/completed/2026-01/traj_x721m1j9rzup.json +113 -0
  28. package/.trajectories/completed/2026-01/traj_x721m1j9rzup.md +57 -0
  29. package/.trajectories/completed/2026-01/traj_xjqvmep5ed3h.json +61 -0
  30. package/.trajectories/completed/2026-01/traj_xjqvmep5ed3h.md +36 -0
  31. package/.trajectories/completed/2026-01/traj_y7n6hfbf7dmg.json +49 -0
  32. package/.trajectories/completed/2026-01/traj_y7n6hfbf7dmg.md +31 -0
  33. package/.trajectories/completed/2026-01/traj_yvfkwnkdiso2.json +49 -0
  34. package/.trajectories/completed/2026-01/traj_yvfkwnkdiso2.md +31 -0
  35. package/.trajectories/index.json +140 -1
  36. package/TRAIL_GIT_AUTH_FIX.md +113 -0
  37. package/deploy/workspace/codex.config.toml +1 -1
  38. package/deploy/workspace/entrypoint.sh +20 -79
  39. package/deploy/workspace/gh-relay +156 -0
  40. package/deploy/workspace/git-credential-relay +5 -1
  41. package/dist/bridge/multi-project-client.js +13 -10
  42. package/dist/bridge/spawner.d.ts +2 -0
  43. package/dist/bridge/spawner.js +19 -1
  44. package/dist/bridge/types.d.ts +2 -0
  45. package/dist/cli/index.d.ts +1 -1
  46. package/dist/cli/index.js +115 -69
  47. package/dist/cloud/api/admin.js +16 -3
  48. package/dist/cloud/api/codex-auth-helper.js +28 -8
  49. package/dist/cloud/api/consensus.d.ts +13 -0
  50. package/dist/cloud/api/consensus.js +259 -0
  51. package/dist/cloud/api/daemons.js +205 -1
  52. package/dist/cloud/api/git.js +37 -7
  53. package/dist/cloud/api/onboarding.js +4 -1
  54. package/dist/cloud/api/provider-env.d.ts +5 -0
  55. package/dist/cloud/api/provider-env.js +27 -0
  56. package/dist/cloud/api/providers.js +2 -0
  57. package/dist/cloud/api/test-helpers.js +130 -0
  58. package/dist/cloud/api/workspaces.js +38 -3
  59. package/dist/cloud/db/bulk-ingest.d.ts +88 -0
  60. package/dist/cloud/db/bulk-ingest.js +268 -0
  61. package/dist/cloud/db/drizzle.d.ts +33 -0
  62. package/dist/cloud/db/drizzle.js +174 -2
  63. package/dist/cloud/db/index.d.ts +24 -5
  64. package/dist/cloud/db/index.js +19 -4
  65. package/dist/cloud/db/schema.d.ts +397 -3
  66. package/dist/cloud/db/schema.js +75 -1
  67. package/dist/cloud/provisioner/index.d.ts +8 -0
  68. package/dist/cloud/provisioner/index.js +256 -50
  69. package/dist/cloud/server.js +47 -3
  70. package/dist/cloud/services/index.d.ts +1 -0
  71. package/dist/cloud/services/index.js +2 -0
  72. package/dist/cloud/services/nango.d.ts +3 -4
  73. package/dist/cloud/services/nango.js +11 -33
  74. package/dist/cloud/services/workspace-keepalive.d.ts +76 -0
  75. package/dist/cloud/services/workspace-keepalive.js +234 -0
  76. package/dist/config/relay-config.d.ts +23 -0
  77. package/dist/config/relay-config.js +23 -0
  78. package/dist/daemon/agent-manager.d.ts +20 -1
  79. package/dist/daemon/agent-manager.js +47 -0
  80. package/dist/daemon/agent-registry.js +4 -4
  81. package/dist/daemon/agent-signing.d.ts +158 -0
  82. package/dist/daemon/agent-signing.js +523 -0
  83. package/dist/daemon/api.js +18 -1
  84. package/dist/daemon/cli-auth.d.ts +4 -1
  85. package/dist/daemon/cli-auth.js +55 -11
  86. package/dist/daemon/cloud-sync.d.ts +47 -1
  87. package/dist/daemon/cloud-sync.js +152 -3
  88. package/dist/daemon/connection.d.ts +28 -0
  89. package/dist/daemon/connection.js +98 -15
  90. package/dist/daemon/consensus-integration.d.ts +167 -0
  91. package/dist/daemon/consensus-integration.js +371 -0
  92. package/dist/daemon/consensus.d.ts +271 -0
  93. package/dist/daemon/consensus.js +632 -0
  94. package/dist/daemon/delivery-tracker.d.ts +34 -0
  95. package/dist/daemon/delivery-tracker.js +104 -0
  96. package/dist/daemon/enhanced-features.d.ts +118 -0
  97. package/dist/daemon/enhanced-features.js +178 -0
  98. package/dist/daemon/index.d.ts +4 -0
  99. package/dist/daemon/index.js +5 -0
  100. package/dist/daemon/rate-limiter.d.ts +68 -0
  101. package/dist/daemon/rate-limiter.js +130 -0
  102. package/dist/daemon/router.d.ts +18 -11
  103. package/dist/daemon/router.js +55 -111
  104. package/dist/daemon/server.d.ts +13 -1
  105. package/dist/daemon/server.js +71 -9
  106. package/dist/daemon/sync-queue.d.ts +116 -0
  107. package/dist/daemon/sync-queue.js +361 -0
  108. package/dist/health-worker-manager.d.ts +62 -0
  109. package/dist/health-worker-manager.js +144 -0
  110. package/dist/health-worker.d.ts +9 -0
  111. package/dist/health-worker.js +79 -0
  112. package/dist/index.d.ts +2 -1
  113. package/dist/index.js +5 -1
  114. package/dist/memory/context-compaction.d.ts +156 -0
  115. package/dist/memory/context-compaction.js +453 -0
  116. package/dist/memory/index.d.ts +1 -0
  117. package/dist/memory/index.js +1 -0
  118. package/dist/protocol/channels.js +4 -4
  119. package/dist/protocol/framing.d.ts +72 -10
  120. package/dist/protocol/framing.js +194 -25
  121. package/dist/storage/adapter.d.ts +8 -1
  122. package/dist/storage/adapter.js +11 -0
  123. package/dist/storage/batched-sqlite-adapter.d.ts +71 -0
  124. package/dist/storage/batched-sqlite-adapter.js +183 -0
  125. package/dist/storage/dead-letter-queue.d.ts +196 -0
  126. package/dist/storage/dead-letter-queue.js +427 -0
  127. package/dist/storage/dlq-adapter.d.ts +195 -0
  128. package/dist/storage/dlq-adapter.js +664 -0
  129. package/dist/trajectory/config.d.ts +32 -14
  130. package/dist/trajectory/config.js +38 -16
  131. package/dist/trajectory/integration.js +217 -64
  132. package/dist/utils/git-remote.d.ts +47 -0
  133. package/dist/utils/git-remote.js +125 -0
  134. package/dist/utils/id-generator.d.ts +35 -0
  135. package/dist/utils/id-generator.js +60 -0
  136. package/dist/utils/index.d.ts +1 -0
  137. package/dist/utils/index.js +1 -0
  138. package/dist/utils/precompiled-patterns.d.ts +110 -0
  139. package/dist/utils/precompiled-patterns.js +322 -0
  140. package/dist/wrapper/auth-detection.js +1 -1
  141. package/dist/wrapper/base-wrapper.d.ts +36 -0
  142. package/dist/wrapper/base-wrapper.js +48 -2
  143. package/dist/wrapper/client.d.ts +14 -4
  144. package/dist/wrapper/client.js +84 -31
  145. package/dist/wrapper/idle-detector.d.ts +102 -0
  146. package/dist/wrapper/idle-detector.js +279 -0
  147. package/dist/wrapper/parser.d.ts +4 -0
  148. package/dist/wrapper/parser.js +19 -1
  149. package/dist/wrapper/pty-wrapper.d.ts +7 -1
  150. package/dist/wrapper/pty-wrapper.js +51 -27
  151. package/dist/wrapper/tmux-wrapper.d.ts +12 -1
  152. package/dist/wrapper/tmux-wrapper.js +65 -17
  153. package/package.json +5 -5
  154. package/scripts/run-migrations.js +43 -0
  155. package/scripts/verify-schema.js +134 -0
  156. package/tests/benchmarks/protocol.bench.ts +310 -0
  157. package/dist/dashboard/out/404.html +0 -1
  158. package/dist/dashboard/out/_next/static/T1tgCqVWHFIkV7ClEtzD7/_buildManifest.js +0 -1
  159. package/dist/dashboard/out/_next/static/T1tgCqVWHFIkV7ClEtzD7/_ssgManifest.js +0 -1
  160. package/dist/dashboard/out/_next/static/chunks/116-2502180def231162.js +0 -1
  161. package/dist/dashboard/out/_next/static/chunks/117-f7b8ab0809342e77.js +0 -2
  162. package/dist/dashboard/out/_next/static/chunks/282-980c2eb8fff20123.js +0 -1
  163. package/dist/dashboard/out/_next/static/chunks/532-bace199897eeab37.js +0 -9
  164. package/dist/dashboard/out/_next/static/chunks/648-5cc6e1921389a58a.js +0 -1
  165. package/dist/dashboard/out/_next/static/chunks/766-b54f0853794b78c3.js +0 -1
  166. package/dist/dashboard/out/_next/static/chunks/83-b51836037078006c.js +0 -1
  167. package/dist/dashboard/out/_next/static/chunks/891-6cd50de1224f70bb.js +0 -1
  168. package/dist/dashboard/out/_next/static/chunks/899-bb19a9b3d9b39ea6.js +0 -1
  169. package/dist/dashboard/out/_next/static/chunks/app/_not-found/page-53b8a69f76db17d0.js +0 -1
  170. package/dist/dashboard/out/_next/static/chunks/app/app/onboarding/page-8939b0fc700f7eca.js +0 -1
  171. package/dist/dashboard/out/_next/static/chunks/app/app/page-5af1b6b439858aa6.js +0 -1
  172. package/dist/dashboard/out/_next/static/chunks/app/connect-repos/page-f45ecbc3e06134fc.js +0 -1
  173. package/dist/dashboard/out/_next/static/chunks/app/history/page-8c8bed33beb2bf1c.js +0 -1
  174. package/dist/dashboard/out/_next/static/chunks/app/layout-2433bb48965f4333.js +0 -1
  175. package/dist/dashboard/out/_next/static/chunks/app/login/page-16f3b49e55b1e0ed.js +0 -1
  176. package/dist/dashboard/out/_next/static/chunks/app/metrics/page-ac39dc0cc3c26fa7.js +0 -1
  177. package/dist/dashboard/out/_next/static/chunks/app/page-4a5938c18a11a654.js +0 -1
  178. package/dist/dashboard/out/_next/static/chunks/app/pricing/page-982a7000fee44014.js +0 -1
  179. package/dist/dashboard/out/_next/static/chunks/app/providers/page-ac3a6ac433fd6001.js +0 -1
  180. package/dist/dashboard/out/_next/static/chunks/app/providers/setup/[provider]/page-09f9caae98a18c09.js +0 -1
  181. package/dist/dashboard/out/_next/static/chunks/app/signup/page-547dd0ca55ecd0ba.js +0 -1
  182. package/dist/dashboard/out/_next/static/chunks/e868780c-48e5f147c90a3a41.js +0 -18
  183. package/dist/dashboard/out/_next/static/chunks/fd9d1056-609918ca7b6280bb.js +0 -1
  184. package/dist/dashboard/out/_next/static/chunks/framework-f66176bb897dc684.js +0 -1
  185. package/dist/dashboard/out/_next/static/chunks/main-2ee6beb2ae96d210.js +0 -1
  186. package/dist/dashboard/out/_next/static/chunks/main-app-5d692157a8eb1fd9.js +0 -1
  187. package/dist/dashboard/out/_next/static/chunks/pages/_app-72b849fbd24ac258.js +0 -1
  188. package/dist/dashboard/out/_next/static/chunks/pages/_error-7ba65e1336b92748.js +0 -1
  189. package/dist/dashboard/out/_next/static/chunks/polyfills-42372ed130431b0a.js +0 -1
  190. package/dist/dashboard/out/_next/static/chunks/webpack-1cdd8ed57114d5e1.js +0 -1
  191. package/dist/dashboard/out/_next/static/css/85d2af9c7ac74d62.css +0 -1
  192. package/dist/dashboard/out/_next/static/css/fe4b28883eeff359.css +0 -1
  193. package/dist/dashboard/out/alt-logos/agent-relay-logo-128.png +0 -0
  194. package/dist/dashboard/out/alt-logos/agent-relay-logo-256.png +0 -0
  195. package/dist/dashboard/out/alt-logos/agent-relay-logo-32.png +0 -0
  196. package/dist/dashboard/out/alt-logos/agent-relay-logo-512.png +0 -0
  197. package/dist/dashboard/out/alt-logos/agent-relay-logo-64.png +0 -0
  198. package/dist/dashboard/out/alt-logos/agent-relay-logo.svg +0 -45
  199. package/dist/dashboard/out/alt-logos/logo.svg +0 -38
  200. package/dist/dashboard/out/alt-logos/monogram-logo-128.png +0 -0
  201. package/dist/dashboard/out/alt-logos/monogram-logo-256.png +0 -0
  202. package/dist/dashboard/out/alt-logos/monogram-logo-32.png +0 -0
  203. package/dist/dashboard/out/alt-logos/monogram-logo-512.png +0 -0
  204. package/dist/dashboard/out/alt-logos/monogram-logo-64.png +0 -0
  205. package/dist/dashboard/out/alt-logos/monogram-logo.svg +0 -38
  206. package/dist/dashboard/out/app/onboarding.html +0 -1
  207. package/dist/dashboard/out/app/onboarding.txt +0 -7
  208. package/dist/dashboard/out/app.html +0 -1
  209. package/dist/dashboard/out/app.txt +0 -7
  210. package/dist/dashboard/out/apple-icon.png +0 -0
  211. package/dist/dashboard/out/connect-repos.html +0 -1
  212. package/dist/dashboard/out/connect-repos.txt +0 -7
  213. package/dist/dashboard/out/history.html +0 -1
  214. package/dist/dashboard/out/history.txt +0 -7
  215. package/dist/dashboard/out/index.html +0 -1
  216. package/dist/dashboard/out/index.txt +0 -7
  217. package/dist/dashboard/out/login.html +0 -6
  218. package/dist/dashboard/out/login.txt +0 -7
  219. package/dist/dashboard/out/metrics.html +0 -1
  220. package/dist/dashboard/out/metrics.txt +0 -7
  221. package/dist/dashboard/out/pricing.html +0 -13
  222. package/dist/dashboard/out/pricing.txt +0 -7
  223. package/dist/dashboard/out/providers/setup/claude.html +0 -1
  224. package/dist/dashboard/out/providers/setup/claude.txt +0 -8
  225. package/dist/dashboard/out/providers/setup/codex.html +0 -1
  226. package/dist/dashboard/out/providers/setup/codex.txt +0 -8
  227. package/dist/dashboard/out/providers.html +0 -1
  228. package/dist/dashboard/out/providers.txt +0 -7
  229. package/dist/dashboard/out/signup.html +0 -6
  230. package/dist/dashboard/out/signup.txt +0 -7
  231. package/dist/dashboard-server/metrics.d.ts +0 -105
  232. package/dist/dashboard-server/metrics.js +0 -193
  233. package/dist/dashboard-server/needs-attention.d.ts +0 -24
  234. package/dist/dashboard-server/needs-attention.js +0 -78
  235. package/dist/dashboard-server/server.d.ts +0 -15
  236. package/dist/dashboard-server/server.js +0 -3776
  237. package/dist/dashboard-server/start.d.ts +0 -6
  238. package/dist/dashboard-server/start.js +0 -13
  239. package/dist/dashboard-server/user-bridge.d.ts +0 -103
  240. package/dist/dashboard-server/user-bridge.js +0 -189
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Standalone dashboard starter for local development
4
- */
5
- export {};
6
- //# sourceMappingURL=start.d.ts.map
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Standalone dashboard starter for local development
4
- */
5
- import { startDashboard } from './server.js';
6
- import { getProjectPaths } from '../utils/project-namespace.js';
7
- const port = parseInt(process.env.DASHBOARD_PORT || '3888', 10);
8
- const paths = getProjectPaths();
9
- console.log(`Starting dashboard for project: ${paths.projectRoot}`);
10
- console.log(`Data dir: ${paths.dataDir}`);
11
- console.log(`Database: ${paths.dbPath}`);
12
- startDashboard(port, paths.dataDir, paths.teamDir, paths.dbPath).catch(console.error);
13
- //# sourceMappingURL=start.js.map
@@ -1,103 +0,0 @@
1
- /**
2
- * User Bridge - Bridges dashboard WebSocket users to the relay daemon.
3
- *
4
- * This module allows human users connected via WebSocket to:
5
- * - Register as "user" entities in the relay daemon
6
- * - Join/leave channels
7
- * - Send/receive messages through the relay daemon
8
- * - Communicate with agents and other users
9
- */
10
- import type { WebSocket } from 'ws';
11
- /**
12
- * Relay client interface (subset of RelayClient for dependency injection)
13
- */
14
- export interface IRelayClient {
15
- connect(): Promise<void>;
16
- disconnect(): void;
17
- state: string;
18
- sendMessage(to: string, body: string, kind?: string, data?: unknown, thread?: string): boolean;
19
- onMessage?: (from: string, payload: any, messageId: string, meta?: any, originalTo?: string) => void;
20
- }
21
- /**
22
- * Factory function type for creating relay clients
23
- */
24
- export type RelayClientFactory = (options: {
25
- socketPath: string;
26
- agentName: string;
27
- entityType: 'user';
28
- displayName?: string;
29
- avatarUrl?: string;
30
- }) => Promise<IRelayClient>;
31
- /**
32
- * Options for creating a UserBridge
33
- */
34
- export interface UserBridgeOptions {
35
- socketPath: string;
36
- createRelayClient: RelayClientFactory;
37
- }
38
- /**
39
- * Message options for sending
40
- */
41
- export interface SendMessageOptions {
42
- thread?: string;
43
- data?: Record<string, unknown>;
44
- }
45
- /**
46
- * UserBridge manages the connection between dashboard WebSocket users
47
- * and the relay daemon.
48
- */
49
- export declare class UserBridge {
50
- private readonly socketPath;
51
- private readonly createRelayClient;
52
- private readonly users;
53
- constructor(options: UserBridgeOptions);
54
- /**
55
- * Register a user with the relay daemon.
56
- * Creates a relay client connection for the user.
57
- */
58
- registerUser(username: string, webSocket: WebSocket, options?: {
59
- avatarUrl?: string;
60
- displayName?: string;
61
- }): Promise<void>;
62
- /**
63
- * Unregister a user and disconnect their relay client.
64
- */
65
- unregisterUser(username: string): void;
66
- /**
67
- * Check if a user is registered.
68
- */
69
- isUserRegistered(username: string): boolean;
70
- /**
71
- * Get list of all registered users.
72
- */
73
- getRegisteredUsers(): string[];
74
- /**
75
- * Join a channel.
76
- */
77
- joinChannel(username: string, channel: string): Promise<boolean>;
78
- /**
79
- * Leave a channel.
80
- */
81
- leaveChannel(username: string, channel: string): Promise<boolean>;
82
- /**
83
- * Get channels a user has joined.
84
- */
85
- getUserChannels(username: string): string[];
86
- /**
87
- * Send a message to a channel.
88
- */
89
- sendChannelMessage(username: string, channel: string, body: string, options?: SendMessageOptions): Promise<boolean>;
90
- /**
91
- * Send a direct message to another user or agent.
92
- */
93
- sendDirectMessage(fromUsername: string, toName: string, body: string, options?: SendMessageOptions): Promise<boolean>;
94
- /**
95
- * Handle incoming message from relay daemon.
96
- */
97
- private handleIncomingMessage;
98
- /**
99
- * Dispose of all user sessions.
100
- */
101
- dispose(): void;
102
- }
103
- //# sourceMappingURL=user-bridge.d.ts.map
@@ -1,189 +0,0 @@
1
- /**
2
- * User Bridge - Bridges dashboard WebSocket users to the relay daemon.
3
- *
4
- * This module allows human users connected via WebSocket to:
5
- * - Register as "user" entities in the relay daemon
6
- * - Join/leave channels
7
- * - Send/receive messages through the relay daemon
8
- * - Communicate with agents and other users
9
- */
10
- /**
11
- * UserBridge manages the connection between dashboard WebSocket users
12
- * and the relay daemon.
13
- */
14
- export class UserBridge {
15
- socketPath;
16
- createRelayClient;
17
- users = new Map();
18
- constructor(options) {
19
- this.socketPath = options.socketPath;
20
- this.createRelayClient = options.createRelayClient;
21
- }
22
- /**
23
- * Register a user with the relay daemon.
24
- * Creates a relay client connection for the user.
25
- */
26
- async registerUser(username, webSocket, options) {
27
- // If user already registered, unregister first
28
- if (this.users.has(username)) {
29
- this.unregisterUser(username);
30
- }
31
- // Create relay client for this user
32
- const relayClient = await this.createRelayClient({
33
- socketPath: this.socketPath,
34
- agentName: username,
35
- entityType: 'user',
36
- displayName: options?.displayName,
37
- avatarUrl: options?.avatarUrl,
38
- });
39
- // Connect to daemon
40
- await relayClient.connect();
41
- // Set up message handler to forward messages to WebSocket
42
- relayClient.onMessage = (from, payload, _messageId, _meta, _originalTo) => {
43
- const body = typeof payload === 'object' && payload !== null && 'body' in payload
44
- ? payload.body
45
- : String(payload);
46
- this.handleIncomingMessage(username, from, body, payload);
47
- };
48
- // Create session
49
- const session = {
50
- username,
51
- relayClient,
52
- webSocket,
53
- channels: new Set(),
54
- avatarUrl: options?.avatarUrl,
55
- };
56
- this.users.set(username, session);
57
- // Set up WebSocket close handler
58
- webSocket.on('close', () => {
59
- this.unregisterUser(username);
60
- });
61
- console.log(`[user-bridge] User ${username} registered with relay daemon`);
62
- }
63
- /**
64
- * Unregister a user and disconnect their relay client.
65
- */
66
- unregisterUser(username) {
67
- const session = this.users.get(username);
68
- if (!session)
69
- return;
70
- session.relayClient.disconnect();
71
- this.users.delete(username);
72
- console.log(`[user-bridge] User ${username} unregistered from relay daemon`);
73
- }
74
- /**
75
- * Check if a user is registered.
76
- */
77
- isUserRegistered(username) {
78
- return this.users.has(username);
79
- }
80
- /**
81
- * Get list of all registered users.
82
- */
83
- getRegisteredUsers() {
84
- return Array.from(this.users.keys());
85
- }
86
- /**
87
- * Join a channel.
88
- */
89
- async joinChannel(username, channel) {
90
- const session = this.users.get(username);
91
- if (!session) {
92
- console.warn(`[user-bridge] Cannot join channel - user ${username} not registered`);
93
- return false;
94
- }
95
- // Send channel join via relay client
96
- session.relayClient.sendMessage(channel, '', 'channel_join');
97
- // Track membership
98
- session.channels.add(channel);
99
- console.log(`[user-bridge] User ${username} joined channel ${channel}`);
100
- return true;
101
- }
102
- /**
103
- * Leave a channel.
104
- */
105
- async leaveChannel(username, channel) {
106
- const session = this.users.get(username);
107
- if (!session) {
108
- console.warn(`[user-bridge] Cannot leave channel - user ${username} not registered`);
109
- return false;
110
- }
111
- // Send channel leave via relay client
112
- session.relayClient.sendMessage(channel, '', 'channel_leave');
113
- // Update membership
114
- session.channels.delete(channel);
115
- console.log(`[user-bridge] User ${username} left channel ${channel}`);
116
- return true;
117
- }
118
- /**
119
- * Get channels a user has joined.
120
- */
121
- getUserChannels(username) {
122
- const session = this.users.get(username);
123
- return session ? Array.from(session.channels) : [];
124
- }
125
- /**
126
- * Send a message to a channel.
127
- */
128
- async sendChannelMessage(username, channel, body, options) {
129
- const session = this.users.get(username);
130
- if (!session) {
131
- console.warn(`[user-bridge] Cannot send - user ${username} not registered`);
132
- return false;
133
- }
134
- return session.relayClient.sendMessage(channel, body, 'message', options?.data, options?.thread);
135
- }
136
- /**
137
- * Send a direct message to another user or agent.
138
- */
139
- async sendDirectMessage(fromUsername, toName, body, options) {
140
- const session = this.users.get(fromUsername);
141
- if (!session) {
142
- console.warn(`[user-bridge] Cannot send DM - user ${fromUsername} not registered`);
143
- return false;
144
- }
145
- return session.relayClient.sendMessage(toName, body, 'message', options?.data, options?.thread);
146
- }
147
- /**
148
- * Handle incoming message from relay daemon.
149
- */
150
- handleIncomingMessage(username, from, body, envelope) {
151
- const session = this.users.get(username);
152
- if (!session)
153
- return;
154
- const ws = session.webSocket;
155
- if (ws.readyState !== 1)
156
- return; // Not OPEN
157
- // Determine message type from envelope
158
- const env = envelope;
159
- if (env.type === 'CHANNEL_MESSAGE') {
160
- // Channel message
161
- ws.send(JSON.stringify({
162
- type: 'channel_message',
163
- channel: env.payload?.channel,
164
- from,
165
- body: env.payload?.body || body,
166
- timestamp: new Date().toISOString(),
167
- }));
168
- }
169
- else {
170
- // Direct message (DELIVER)
171
- ws.send(JSON.stringify({
172
- type: 'direct_message',
173
- from,
174
- body: env.payload?.body || body,
175
- timestamp: new Date().toISOString(),
176
- }));
177
- }
178
- }
179
- /**
180
- * Dispose of all user sessions.
181
- */
182
- dispose() {
183
- for (const [username] of this.users) {
184
- this.unregisterUser(username);
185
- }
186
- console.log('[user-bridge] Disposed all user sessions');
187
- }
188
- }
189
- //# sourceMappingURL=user-bridge.js.map