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.
- package/.trajectories/active/traj_3yx9dy148mge.json +42 -0
- package/.trajectories/completed/2026-01/traj_1g7yx6qtg4ai.json +49 -0
- package/.trajectories/completed/2026-01/traj_1g7yx6qtg4ai.md +31 -0
- package/.trajectories/completed/2026-01/traj_4qwd4zmhfwp4.json +49 -0
- package/.trajectories/completed/2026-01/traj_4qwd4zmhfwp4.md +31 -0
- package/.trajectories/completed/2026-01/traj_6unwwmgyj5sq.json +109 -0
- package/.trajectories/completed/2026-01/traj_a0tqx8biw9c4.json +49 -0
- package/.trajectories/completed/2026-01/traj_a0tqx8biw9c4.md +31 -0
- package/.trajectories/completed/2026-01/traj_ax8uungxz2qh.json +66 -0
- package/.trajectories/completed/2026-01/traj_ax8uungxz2qh.md +36 -0
- package/.trajectories/completed/2026-01/traj_c9izbh2snpzf.json +49 -0
- package/.trajectories/completed/2026-01/traj_c9izbh2snpzf.md +31 -0
- package/.trajectories/completed/2026-01/traj_cpn70dw066nt.json +65 -0
- package/.trajectories/completed/2026-01/traj_cpn70dw066nt.md +37 -0
- package/.trajectories/completed/2026-01/traj_erglv2f8t9eh.json +36 -0
- package/.trajectories/completed/2026-01/traj_erglv2f8t9eh.md +21 -0
- package/.trajectories/completed/2026-01/traj_he75f24d1xfm.json +101 -0
- package/.trajectories/completed/2026-01/traj_he75f24d1xfm.md +52 -0
- package/.trajectories/completed/2026-01/traj_lgtodco7dp1n.json +61 -0
- package/.trajectories/completed/2026-01/traj_lgtodco7dp1n.md +36 -0
- package/.trajectories/completed/2026-01/traj_oszg9flv74pk.json +73 -0
- package/.trajectories/completed/2026-01/traj_oszg9flv74pk.md +41 -0
- package/.trajectories/completed/2026-01/traj_pulomd3y8cvj.json +77 -0
- package/.trajectories/completed/2026-01/traj_pulomd3y8cvj.md +42 -0
- package/.trajectories/completed/2026-01/traj_rsavt0jipi3c.json +109 -0
- package/.trajectories/completed/2026-01/traj_rsavt0jipi3c.md +56 -0
- package/.trajectories/completed/2026-01/traj_x721m1j9rzup.json +113 -0
- package/.trajectories/completed/2026-01/traj_x721m1j9rzup.md +57 -0
- package/.trajectories/completed/2026-01/traj_xjqvmep5ed3h.json +61 -0
- package/.trajectories/completed/2026-01/traj_xjqvmep5ed3h.md +36 -0
- package/.trajectories/completed/2026-01/traj_y7n6hfbf7dmg.json +49 -0
- package/.trajectories/completed/2026-01/traj_y7n6hfbf7dmg.md +31 -0
- package/.trajectories/completed/2026-01/traj_yvfkwnkdiso2.json +49 -0
- package/.trajectories/completed/2026-01/traj_yvfkwnkdiso2.md +31 -0
- package/.trajectories/index.json +140 -1
- package/TRAIL_GIT_AUTH_FIX.md +113 -0
- package/deploy/workspace/codex.config.toml +1 -1
- package/deploy/workspace/entrypoint.sh +20 -79
- package/deploy/workspace/gh-relay +156 -0
- package/deploy/workspace/git-credential-relay +5 -1
- package/dist/bridge/multi-project-client.js +13 -10
- package/dist/bridge/spawner.d.ts +2 -0
- package/dist/bridge/spawner.js +19 -1
- package/dist/bridge/types.d.ts +2 -0
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +115 -69
- package/dist/cloud/api/admin.js +16 -3
- package/dist/cloud/api/codex-auth-helper.js +28 -8
- package/dist/cloud/api/consensus.d.ts +13 -0
- package/dist/cloud/api/consensus.js +259 -0
- package/dist/cloud/api/daemons.js +205 -1
- package/dist/cloud/api/git.js +37 -7
- package/dist/cloud/api/onboarding.js +4 -1
- package/dist/cloud/api/provider-env.d.ts +5 -0
- package/dist/cloud/api/provider-env.js +27 -0
- package/dist/cloud/api/providers.js +2 -0
- package/dist/cloud/api/test-helpers.js +130 -0
- package/dist/cloud/api/workspaces.js +38 -3
- package/dist/cloud/db/bulk-ingest.d.ts +88 -0
- package/dist/cloud/db/bulk-ingest.js +268 -0
- package/dist/cloud/db/drizzle.d.ts +33 -0
- package/dist/cloud/db/drizzle.js +174 -2
- package/dist/cloud/db/index.d.ts +24 -5
- package/dist/cloud/db/index.js +19 -4
- package/dist/cloud/db/schema.d.ts +397 -3
- package/dist/cloud/db/schema.js +75 -1
- package/dist/cloud/provisioner/index.d.ts +8 -0
- package/dist/cloud/provisioner/index.js +256 -50
- package/dist/cloud/server.js +47 -3
- package/dist/cloud/services/index.d.ts +1 -0
- package/dist/cloud/services/index.js +2 -0
- package/dist/cloud/services/nango.d.ts +3 -4
- package/dist/cloud/services/nango.js +11 -33
- package/dist/cloud/services/workspace-keepalive.d.ts +76 -0
- package/dist/cloud/services/workspace-keepalive.js +234 -0
- package/dist/config/relay-config.d.ts +23 -0
- package/dist/config/relay-config.js +23 -0
- package/dist/daemon/agent-manager.d.ts +20 -1
- package/dist/daemon/agent-manager.js +47 -0
- package/dist/daemon/agent-registry.js +4 -4
- package/dist/daemon/agent-signing.d.ts +158 -0
- package/dist/daemon/agent-signing.js +523 -0
- package/dist/daemon/api.js +18 -1
- package/dist/daemon/cli-auth.d.ts +4 -1
- package/dist/daemon/cli-auth.js +55 -11
- package/dist/daemon/cloud-sync.d.ts +47 -1
- package/dist/daemon/cloud-sync.js +152 -3
- package/dist/daemon/connection.d.ts +28 -0
- package/dist/daemon/connection.js +98 -15
- package/dist/daemon/consensus-integration.d.ts +167 -0
- package/dist/daemon/consensus-integration.js +371 -0
- package/dist/daemon/consensus.d.ts +271 -0
- package/dist/daemon/consensus.js +632 -0
- package/dist/daemon/delivery-tracker.d.ts +34 -0
- package/dist/daemon/delivery-tracker.js +104 -0
- package/dist/daemon/enhanced-features.d.ts +118 -0
- package/dist/daemon/enhanced-features.js +178 -0
- package/dist/daemon/index.d.ts +4 -0
- package/dist/daemon/index.js +5 -0
- package/dist/daemon/rate-limiter.d.ts +68 -0
- package/dist/daemon/rate-limiter.js +130 -0
- package/dist/daemon/router.d.ts +18 -11
- package/dist/daemon/router.js +55 -111
- package/dist/daemon/server.d.ts +13 -1
- package/dist/daemon/server.js +71 -9
- package/dist/daemon/sync-queue.d.ts +116 -0
- package/dist/daemon/sync-queue.js +361 -0
- package/dist/health-worker-manager.d.ts +62 -0
- package/dist/health-worker-manager.js +144 -0
- package/dist/health-worker.d.ts +9 -0
- package/dist/health-worker.js +79 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -1
- package/dist/memory/context-compaction.d.ts +156 -0
- package/dist/memory/context-compaction.js +453 -0
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.js +1 -0
- package/dist/protocol/channels.js +4 -4
- package/dist/protocol/framing.d.ts +72 -10
- package/dist/protocol/framing.js +194 -25
- package/dist/storage/adapter.d.ts +8 -1
- package/dist/storage/adapter.js +11 -0
- package/dist/storage/batched-sqlite-adapter.d.ts +71 -0
- package/dist/storage/batched-sqlite-adapter.js +183 -0
- package/dist/storage/dead-letter-queue.d.ts +196 -0
- package/dist/storage/dead-letter-queue.js +427 -0
- package/dist/storage/dlq-adapter.d.ts +195 -0
- package/dist/storage/dlq-adapter.js +664 -0
- package/dist/trajectory/config.d.ts +32 -14
- package/dist/trajectory/config.js +38 -16
- package/dist/trajectory/integration.js +217 -64
- package/dist/utils/git-remote.d.ts +47 -0
- package/dist/utils/git-remote.js +125 -0
- package/dist/utils/id-generator.d.ts +35 -0
- package/dist/utils/id-generator.js +60 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/precompiled-patterns.d.ts +110 -0
- package/dist/utils/precompiled-patterns.js +322 -0
- package/dist/wrapper/auth-detection.js +1 -1
- package/dist/wrapper/base-wrapper.d.ts +36 -0
- package/dist/wrapper/base-wrapper.js +48 -2
- package/dist/wrapper/client.d.ts +14 -4
- package/dist/wrapper/client.js +84 -31
- package/dist/wrapper/idle-detector.d.ts +102 -0
- package/dist/wrapper/idle-detector.js +279 -0
- package/dist/wrapper/parser.d.ts +4 -0
- package/dist/wrapper/parser.js +19 -1
- package/dist/wrapper/pty-wrapper.d.ts +7 -1
- package/dist/wrapper/pty-wrapper.js +51 -27
- package/dist/wrapper/tmux-wrapper.d.ts +12 -1
- package/dist/wrapper/tmux-wrapper.js +65 -17
- package/package.json +5 -5
- package/scripts/run-migrations.js +43 -0
- package/scripts/verify-schema.js +134 -0
- package/tests/benchmarks/protocol.bench.ts +310 -0
- package/dist/dashboard/out/404.html +0 -1
- package/dist/dashboard/out/_next/static/T1tgCqVWHFIkV7ClEtzD7/_buildManifest.js +0 -1
- package/dist/dashboard/out/_next/static/T1tgCqVWHFIkV7ClEtzD7/_ssgManifest.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/116-2502180def231162.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/117-f7b8ab0809342e77.js +0 -2
- package/dist/dashboard/out/_next/static/chunks/282-980c2eb8fff20123.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/532-bace199897eeab37.js +0 -9
- package/dist/dashboard/out/_next/static/chunks/648-5cc6e1921389a58a.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/766-b54f0853794b78c3.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/83-b51836037078006c.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/891-6cd50de1224f70bb.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/899-bb19a9b3d9b39ea6.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/_not-found/page-53b8a69f76db17d0.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/app/onboarding/page-8939b0fc700f7eca.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/app/page-5af1b6b439858aa6.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/connect-repos/page-f45ecbc3e06134fc.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/history/page-8c8bed33beb2bf1c.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/layout-2433bb48965f4333.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/login/page-16f3b49e55b1e0ed.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/metrics/page-ac39dc0cc3c26fa7.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/page-4a5938c18a11a654.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/pricing/page-982a7000fee44014.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/providers/page-ac3a6ac433fd6001.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/providers/setup/[provider]/page-09f9caae98a18c09.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/signup/page-547dd0ca55ecd0ba.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/e868780c-48e5f147c90a3a41.js +0 -18
- package/dist/dashboard/out/_next/static/chunks/fd9d1056-609918ca7b6280bb.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/framework-f66176bb897dc684.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/main-2ee6beb2ae96d210.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/main-app-5d692157a8eb1fd9.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/pages/_app-72b849fbd24ac258.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/pages/_error-7ba65e1336b92748.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/polyfills-42372ed130431b0a.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/webpack-1cdd8ed57114d5e1.js +0 -1
- package/dist/dashboard/out/_next/static/css/85d2af9c7ac74d62.css +0 -1
- package/dist/dashboard/out/_next/static/css/fe4b28883eeff359.css +0 -1
- package/dist/dashboard/out/alt-logos/agent-relay-logo-128.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo-256.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo-32.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo-512.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo-64.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo.svg +0 -45
- package/dist/dashboard/out/alt-logos/logo.svg +0 -38
- package/dist/dashboard/out/alt-logos/monogram-logo-128.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo-256.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo-32.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo-512.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo-64.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo.svg +0 -38
- package/dist/dashboard/out/app/onboarding.html +0 -1
- package/dist/dashboard/out/app/onboarding.txt +0 -7
- package/dist/dashboard/out/app.html +0 -1
- package/dist/dashboard/out/app.txt +0 -7
- package/dist/dashboard/out/apple-icon.png +0 -0
- package/dist/dashboard/out/connect-repos.html +0 -1
- package/dist/dashboard/out/connect-repos.txt +0 -7
- package/dist/dashboard/out/history.html +0 -1
- package/dist/dashboard/out/history.txt +0 -7
- package/dist/dashboard/out/index.html +0 -1
- package/dist/dashboard/out/index.txt +0 -7
- package/dist/dashboard/out/login.html +0 -6
- package/dist/dashboard/out/login.txt +0 -7
- package/dist/dashboard/out/metrics.html +0 -1
- package/dist/dashboard/out/metrics.txt +0 -7
- package/dist/dashboard/out/pricing.html +0 -13
- package/dist/dashboard/out/pricing.txt +0 -7
- package/dist/dashboard/out/providers/setup/claude.html +0 -1
- package/dist/dashboard/out/providers/setup/claude.txt +0 -8
- package/dist/dashboard/out/providers/setup/codex.html +0 -1
- package/dist/dashboard/out/providers/setup/codex.txt +0 -8
- package/dist/dashboard/out/providers.html +0 -1
- package/dist/dashboard/out/providers.txt +0 -7
- package/dist/dashboard/out/signup.html +0 -6
- package/dist/dashboard/out/signup.txt +0 -7
- package/dist/dashboard-server/metrics.d.ts +0 -105
- package/dist/dashboard-server/metrics.js +0 -193
- package/dist/dashboard-server/needs-attention.d.ts +0 -24
- package/dist/dashboard-server/needs-attention.js +0 -78
- package/dist/dashboard-server/server.d.ts +0 -15
- package/dist/dashboard-server/server.js +0 -3776
- package/dist/dashboard-server/start.d.ts +0 -6
- package/dist/dashboard-server/start.js +0 -13
- package/dist/dashboard-server/user-bridge.d.ts +0 -103
- package/dist/dashboard-server/user-bridge.js +0 -189
|
@@ -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
|