@principal-ai/control-tower-core 0.1.4 → 0.1.5
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/dist/abstractions/AuthAdapter.d.ts +8 -5
- package/dist/abstractions/AuthAdapter.d.ts.map +1 -1
- package/dist/abstractions/TransportAdapter.d.ts +5 -0
- package/dist/abstractions/TransportAdapter.d.ts.map +1 -1
- package/dist/adapters/mock/MockAuthAdapter.d.ts +4 -1
- package/dist/adapters/mock/MockAuthAdapter.d.ts.map +1 -1
- package/dist/adapters/mock/MockAuthAdapter.js +57 -13
- package/dist/adapters/websocket/WebSocketTransportAdapter.d.ts +60 -0
- package/dist/adapters/websocket/WebSocketTransportAdapter.d.ts.map +1 -0
- package/dist/adapters/websocket/WebSocketTransportAdapter.js +380 -0
- package/dist/adapters/websocket/index.d.ts +2 -0
- package/dist/adapters/websocket/index.d.ts.map +1 -0
- package/dist/adapters/websocket/index.js +1 -0
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.js +4 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +22 -7
- package/dist/index.mjs +3386 -17
- package/dist/index.mjs.map +22 -7
- package/dist/server/BaseServer.d.ts +14 -1
- package/dist/server/BaseServer.d.ts.map +1 -1
- package/dist/server/BaseServer.js +103 -0
- package/dist/server/ServerBuilder.d.ts +9 -0
- package/dist/server/ServerBuilder.d.ts.map +1 -1
- package/dist/server/ServerBuilder.js +16 -1
- package/dist/types/auth.d.ts +14 -7
- package/dist/types/auth.d.ts.map +1 -1
- package/package.json +5 -2
|
@@ -5,6 +5,9 @@ import type { IStorageAdapter } from '../abstractions/StorageAdapter';
|
|
|
5
5
|
import type { RoomManager } from '../abstractions/RoomManager';
|
|
6
6
|
import type { LockManager } from '../abstractions/LockManager';
|
|
7
7
|
import { TypedEventEmitter } from '../abstractions/EventEmitter';
|
|
8
|
+
import type { Server as HttpServer } from 'http';
|
|
9
|
+
import type { Server as HttpsServer } from 'https';
|
|
10
|
+
import type { WebSocketServer } from 'ws';
|
|
8
11
|
export interface ServerConfig {
|
|
9
12
|
transport: ITransportAdapter;
|
|
10
13
|
auth?: IAuthAdapter;
|
|
@@ -12,6 +15,9 @@ export interface ServerConfig {
|
|
|
12
15
|
roomManager: RoomManager;
|
|
13
16
|
lockManager: LockManager;
|
|
14
17
|
defaultRoomConfig?: Partial<RoomConfig>;
|
|
18
|
+
httpServer?: HttpServer | HttpsServer;
|
|
19
|
+
webSocketPath?: string;
|
|
20
|
+
webSocketServer?: WebSocketServer;
|
|
15
21
|
}
|
|
16
22
|
export interface ConnectedClient {
|
|
17
23
|
id: string;
|
|
@@ -79,10 +85,15 @@ export declare class BaseServer extends TypedEventEmitter<ServerEvents> {
|
|
|
79
85
|
private clients;
|
|
80
86
|
private clientMessageHandlers;
|
|
81
87
|
private running;
|
|
88
|
+
private initialized;
|
|
89
|
+
private mode;
|
|
82
90
|
constructor(config: ServerConfig);
|
|
83
|
-
start(port
|
|
91
|
+
start(port?: number): Promise<void>;
|
|
92
|
+
initialize(): Promise<void>;
|
|
84
93
|
stop(): Promise<void>;
|
|
85
94
|
private handleTransportMessage;
|
|
95
|
+
private handleConnectionMessage;
|
|
96
|
+
private handleClientAuthenticatedMessage;
|
|
86
97
|
private handleTransportError;
|
|
87
98
|
private handleTransportClose;
|
|
88
99
|
private addClient;
|
|
@@ -101,5 +112,7 @@ export declare class BaseServer extends TypedEventEmitter<ServerEvents> {
|
|
|
101
112
|
getConnectedClients(): ConnectedClient[];
|
|
102
113
|
getClient(clientId: string): ConnectedClient | null;
|
|
103
114
|
isRunning(): boolean;
|
|
115
|
+
getMode(): 'standalone' | 'integration';
|
|
116
|
+
isInitialized(): boolean;
|
|
104
117
|
}
|
|
105
118
|
//# sourceMappingURL=BaseServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseServer.d.ts","sourceRoot":"","sources":["../../src/server/BaseServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,KAAK,EACL,IAAI,EAEJ,UAAU,EACV,IAAI,EAEL,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseServer.d.ts","sourceRoot":"","sources":["../../src/server/BaseServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,KAAK,EACL,IAAI,EAEJ,UAAU,EACV,IAAI,EAEL,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAE1C,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,iBAA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A4BjB,iBAAiB;YA8BjB,YAAY;IAW1B,OAAO,CAAC,UAAU;IAKZ,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7D,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/C,mBAAmB,IAAI,eAAe,EAAE;IAIxC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAInD,SAAS,IAAI,OAAO;IAIpB,OAAO,IAAI,YAAY,GAAG,aAAa;IAIvC,aAAa,IAAI,OAAO;CAGzB"}
|
|
@@ -5,12 +5,22 @@ export class BaseServer extends TypedEventEmitter {
|
|
|
5
5
|
this.clients = new Map();
|
|
6
6
|
this.clientMessageHandlers = new Map();
|
|
7
7
|
this.running = false;
|
|
8
|
+
this.initialized = false;
|
|
8
9
|
this.config = config;
|
|
9
10
|
this.transport = config.transport;
|
|
10
11
|
this.auth = config.auth;
|
|
11
12
|
this.storage = config.storage;
|
|
12
13
|
this.roomManager = config.roomManager;
|
|
13
14
|
this.lockManager = config.lockManager;
|
|
15
|
+
// Determine mode based on configuration
|
|
16
|
+
this.mode = (config.httpServer || config.webSocketServer) ? 'integration' : 'standalone';
|
|
17
|
+
// Connect auth adapter to transport if both exist and transport supports it
|
|
18
|
+
if (this.auth && this.transport) {
|
|
19
|
+
const transportWithAuth = this.transport;
|
|
20
|
+
if (typeof transportWithAuth.setAuthAdapter === 'function') {
|
|
21
|
+
transportWithAuth.setAuthAdapter(this.auth);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
14
24
|
// Set up transport event handlers
|
|
15
25
|
this.transport.onMessage(this.handleTransportMessage.bind(this));
|
|
16
26
|
this.transport.onError(this.handleTransportError.bind(this));
|
|
@@ -18,12 +28,19 @@ export class BaseServer extends TypedEventEmitter {
|
|
|
18
28
|
}
|
|
19
29
|
// Server Lifecycle
|
|
20
30
|
async start(port) {
|
|
31
|
+
if (this.mode === 'integration') {
|
|
32
|
+
throw new Error('Cannot use start() in integration mode. Use initialize() instead.');
|
|
33
|
+
}
|
|
34
|
+
if (!port) {
|
|
35
|
+
throw new Error('Port is required for standalone mode');
|
|
36
|
+
}
|
|
21
37
|
if (this.running) {
|
|
22
38
|
throw new Error('Server is already running');
|
|
23
39
|
}
|
|
24
40
|
try {
|
|
25
41
|
await this.transport.connect(`ws://localhost:${port}`, { url: `ws://localhost:${port}` });
|
|
26
42
|
this.running = true;
|
|
43
|
+
this.initialized = true;
|
|
27
44
|
await this.emit('started', { port });
|
|
28
45
|
}
|
|
29
46
|
catch (error) {
|
|
@@ -31,6 +48,45 @@ export class BaseServer extends TypedEventEmitter {
|
|
|
31
48
|
throw error;
|
|
32
49
|
}
|
|
33
50
|
}
|
|
51
|
+
async initialize() {
|
|
52
|
+
if (this.mode === 'standalone') {
|
|
53
|
+
throw new Error('Cannot use initialize() in standalone mode. Use start() instead.');
|
|
54
|
+
}
|
|
55
|
+
if (this.initialized) {
|
|
56
|
+
throw new Error('Server is already initialized');
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const transport = this.transport;
|
|
60
|
+
if (this.config.webSocketServer) {
|
|
61
|
+
// Attach to existing WebSocket server
|
|
62
|
+
if (typeof transport.attachToWebSocketServer === 'function') {
|
|
63
|
+
await transport.attachToWebSocketServer(this.config.webSocketServer);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error('Transport adapter does not support attachToWebSocketServer');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (this.config.httpServer) {
|
|
70
|
+
// Attach to existing HTTP server
|
|
71
|
+
if (typeof transport.attach === 'function') {
|
|
72
|
+
await transport.attach(this.config.httpServer, this.config.webSocketPath || '/ws');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error('Transport adapter does not support attach');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new Error('Either httpServer or webSocketServer must be provided in integration mode');
|
|
80
|
+
}
|
|
81
|
+
this.running = true;
|
|
82
|
+
this.initialized = true;
|
|
83
|
+
await this.emit('started', { port: 0 }); // Port 0 indicates integration mode
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
await this.emit('error', { error: error, context: 'server_initialize' });
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
34
90
|
async stop() {
|
|
35
91
|
if (!this.running) {
|
|
36
92
|
return;
|
|
@@ -52,6 +108,15 @@ export class BaseServer extends TypedEventEmitter {
|
|
|
52
108
|
}
|
|
53
109
|
// Client Management
|
|
54
110
|
async handleTransportMessage(message) {
|
|
111
|
+
// Handle special transport messages
|
|
112
|
+
if (message.type === 'connection') {
|
|
113
|
+
await this.handleConnectionMessage(message);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (message.type === 'client_authenticated') {
|
|
117
|
+
await this.handleClientAuthenticatedMessage(message);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
55
120
|
// Transport messages contain clientId in the payload for routing
|
|
56
121
|
const payload = message.payload;
|
|
57
122
|
const { clientId, ...clientMessage } = payload;
|
|
@@ -79,6 +144,38 @@ export class BaseServer extends TypedEventEmitter {
|
|
|
79
144
|
});
|
|
80
145
|
}
|
|
81
146
|
}
|
|
147
|
+
async handleConnectionMessage(message) {
|
|
148
|
+
const payload = message.payload;
|
|
149
|
+
// Add the client with initial auth state
|
|
150
|
+
const client = {
|
|
151
|
+
id: payload.clientId,
|
|
152
|
+
userId: payload.userId || '',
|
|
153
|
+
roomId: null,
|
|
154
|
+
authenticated: payload.authenticated,
|
|
155
|
+
connectedAt: Date.now()
|
|
156
|
+
};
|
|
157
|
+
this.clients.set(payload.clientId, client);
|
|
158
|
+
this.clientMessageHandlers.set(payload.clientId, this.createClientMessageHandler(payload.clientId));
|
|
159
|
+
await this.emit('client_connected', { client });
|
|
160
|
+
if (payload.authenticated) {
|
|
161
|
+
await this.emit('client_authenticated', {
|
|
162
|
+
clientId: payload.clientId,
|
|
163
|
+
userId: payload.userId || ''
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async handleClientAuthenticatedMessage(message) {
|
|
168
|
+
const payload = message.payload;
|
|
169
|
+
const client = this.clients.get(payload.clientId);
|
|
170
|
+
if (client) {
|
|
171
|
+
client.authenticated = true;
|
|
172
|
+
client.userId = payload.userId;
|
|
173
|
+
await this.emit('client_authenticated', {
|
|
174
|
+
clientId: payload.clientId,
|
|
175
|
+
userId: payload.userId
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
82
179
|
async handleTransportError(error) {
|
|
83
180
|
await this.emit('error', { error, context: 'transport' });
|
|
84
181
|
}
|
|
@@ -364,4 +461,10 @@ export class BaseServer extends TypedEventEmitter {
|
|
|
364
461
|
isRunning() {
|
|
365
462
|
return this.running;
|
|
366
463
|
}
|
|
464
|
+
getMode() {
|
|
465
|
+
return this.mode;
|
|
466
|
+
}
|
|
467
|
+
isInitialized() {
|
|
468
|
+
return this.initialized;
|
|
469
|
+
}
|
|
367
470
|
}
|
|
@@ -5,6 +5,9 @@ import type { RoomManager } from '../abstractions/RoomManager';
|
|
|
5
5
|
import type { LockManager } from '../abstractions/LockManager';
|
|
6
6
|
import type { RoomConfig } from '../types';
|
|
7
7
|
import { BaseServer } from './BaseServer';
|
|
8
|
+
import type { Server as HttpServer } from 'http';
|
|
9
|
+
import type { Server as HttpsServer } from 'https';
|
|
10
|
+
import type { WebSocketServer } from 'ws';
|
|
8
11
|
export declare class ServerBuilder {
|
|
9
12
|
private transport?;
|
|
10
13
|
private auth?;
|
|
@@ -12,12 +15,18 @@ export declare class ServerBuilder {
|
|
|
12
15
|
private roomManager?;
|
|
13
16
|
private lockManager?;
|
|
14
17
|
private defaultRoomConfig?;
|
|
18
|
+
private httpServer?;
|
|
19
|
+
private webSocketPath?;
|
|
20
|
+
private webSocketServer?;
|
|
15
21
|
withTransport(transport: ITransportAdapter): this;
|
|
16
22
|
withAuth(auth: IAuthAdapter): this;
|
|
17
23
|
withStorage(storage: IStorageAdapter): this;
|
|
18
24
|
withRoomManager(roomManager: RoomManager): this;
|
|
19
25
|
withLockManager(lockManager: LockManager): this;
|
|
20
26
|
withDefaultRoomConfig(config: Partial<RoomConfig>): this;
|
|
27
|
+
withHttpServer(server: HttpServer | HttpsServer): this;
|
|
28
|
+
withWebSocketPath(path: string): this;
|
|
29
|
+
withWebSocketServer(wss: WebSocketServer): this;
|
|
21
30
|
build(): BaseServer;
|
|
22
31
|
}
|
|
23
32
|
//# sourceMappingURL=ServerBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerBuilder.d.ts","sourceRoot":"","sources":["../../src/server/ServerBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAqB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"ServerBuilder.d.ts","sourceRoot":"","sources":["../../src/server/ServerBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6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pB"}
|
|
@@ -24,6 +24,18 @@ export class ServerBuilder {
|
|
|
24
24
|
this.defaultRoomConfig = config;
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
27
|
+
withHttpServer(server) {
|
|
28
|
+
this.httpServer = server;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
withWebSocketPath(path) {
|
|
32
|
+
this.webSocketPath = path;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
withWebSocketServer(wss) {
|
|
36
|
+
this.webSocketServer = wss;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
27
39
|
build() {
|
|
28
40
|
if (!this.transport) {
|
|
29
41
|
throw new Error('Transport adapter is required');
|
|
@@ -44,7 +56,10 @@ export class ServerBuilder {
|
|
|
44
56
|
maxUsers: 50,
|
|
45
57
|
maxHistory: 100,
|
|
46
58
|
permissions: ['read', 'write']
|
|
47
|
-
}
|
|
59
|
+
},
|
|
60
|
+
httpServer: this.httpServer,
|
|
61
|
+
webSocketPath: this.webSocketPath,
|
|
62
|
+
webSocketServer: this.webSocketServer
|
|
48
63
|
};
|
|
49
64
|
return new BaseServer(config);
|
|
50
65
|
}
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
export interface TokenPayload {
|
|
2
2
|
userId: string;
|
|
3
|
-
email
|
|
4
|
-
username
|
|
3
|
+
email?: string;
|
|
4
|
+
username?: string;
|
|
5
5
|
permissions?: string[];
|
|
6
6
|
roomId?: string;
|
|
7
7
|
expiresAt?: number;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
8
9
|
}
|
|
9
10
|
export interface AuthResult {
|
|
10
|
-
|
|
11
|
+
success: boolean;
|
|
12
|
+
token?: string;
|
|
11
13
|
refreshToken?: string;
|
|
12
|
-
user
|
|
13
|
-
|
|
14
|
+
user?: TokenPayload;
|
|
15
|
+
userId?: string;
|
|
16
|
+
expiresIn?: number;
|
|
17
|
+
error?: string;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
14
19
|
}
|
|
15
|
-
export type CredentialType = 'password' | 'oauth' | 'token';
|
|
20
|
+
export type CredentialType = 'password' | 'oauth' | 'token' | 'jwt' | 'bearer' | 'apikey' | 'custom';
|
|
16
21
|
export type OAuthProvider = 'github' | 'gitlab' | 'bitbucket';
|
|
17
22
|
export interface Credentials {
|
|
18
23
|
type: CredentialType;
|
|
19
24
|
username?: string;
|
|
20
25
|
password?: string;
|
|
21
26
|
token?: string;
|
|
27
|
+
apiKey?: string;
|
|
22
28
|
provider?: OAuthProvider;
|
|
23
29
|
code?: string;
|
|
24
30
|
redirectUri?: string;
|
|
31
|
+
[key: string]: unknown;
|
|
25
32
|
}
|
|
26
33
|
export interface JWTConfig {
|
|
27
34
|
secret: string;
|
|
@@ -36,5 +43,5 @@ export interface OAuthConfig {
|
|
|
36
43
|
scope?: string[];
|
|
37
44
|
provider: OAuthProvider;
|
|
38
45
|
}
|
|
39
|
-
export type AuthProvider = 'jwt' | 'oauth' | 'basic';
|
|
46
|
+
export type AuthProvider = 'jwt' | 'oauth' | 'basic' | 'bearer' | 'apikey' | 'custom';
|
|
40
47
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/types/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC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AAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principal-ai/control-tower-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Centralized, runtime-agnostic library for real-time collaboration and synchronization",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -38,12 +38,15 @@
|
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@eslint/js": "^9.36.0",
|
|
40
40
|
"@types/bun": "latest",
|
|
41
|
+
"@types/ws": "^8.18.1",
|
|
41
42
|
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
|
42
43
|
"@typescript-eslint/parser": "^8.44.0",
|
|
43
44
|
"eslint": "^9.36.0",
|
|
44
45
|
"typescript": "^5.3.3"
|
|
45
46
|
},
|
|
46
|
-
"dependencies": {
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"ws": "^8.18.3"
|
|
49
|
+
},
|
|
47
50
|
"engines": {
|
|
48
51
|
"bun": ">=1.0.0"
|
|
49
52
|
}
|