@principal-ai/control-tower-core 0.3.0 → 0.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/dist/index.mjs CHANGED
@@ -6378,6 +6378,7 @@ class BaseServer extends TypedEventEmitter {
6378
6378
  const client = {
6379
6379
  id: payload.clientId,
6380
6380
  userId: payload.userId || "",
6381
+ deviceId: payload.clientId,
6381
6382
  roomIds,
6382
6383
  get roomId() {
6383
6384
  return roomIds.size > 0 ? roomIds.values().next().value || null : null;
@@ -6457,6 +6458,7 @@ class BaseServer extends TypedEventEmitter {
6457
6458
  const client = {
6458
6459
  id: clientId,
6459
6460
  userId: "",
6461
+ deviceId: clientId,
6460
6462
  roomIds,
6461
6463
  get roomId() {
6462
6464
  return roomIds.size > 0 ? roomIds.values().next().value || null : null;
@@ -6485,10 +6487,10 @@ class BaseServer extends TypedEventEmitter {
6485
6487
  }
6486
6488
  if (this.presenceManager?.isEnabled() && client.userId) {
6487
6489
  try {
6488
- const presence = await this.presenceManager.disconnectDevice(client.userId, clientId);
6490
+ const presence = await this.presenceManager.disconnectDevice(client.userId, client.deviceId);
6489
6491
  await this.emit("presence_device_disconnected", {
6490
6492
  userId: client.userId,
6491
- deviceId: clientId,
6493
+ deviceId: client.deviceId,
6492
6494
  timestamp: Date.now()
6493
6495
  });
6494
6496
  const presenceConfig = this.presenceManager.getConfig();
@@ -6497,7 +6499,7 @@ class BaseServer extends TypedEventEmitter {
6497
6499
  type: "presence:user_offline",
6498
6500
  payload: {
6499
6501
  userId: client.userId,
6500
- deviceId: clientId,
6502
+ deviceId: client.deviceId,
6501
6503
  status: presence?.status || "offline",
6502
6504
  gracePeriod: presenceConfig.gracePeriod
6503
6505
  }
@@ -6511,6 +6513,17 @@ class BaseServer extends TypedEventEmitter {
6511
6513
  }
6512
6514
  }
6513
6515
  for (const roomId of client.roomIds) {
6516
+ try {
6517
+ await this.experimental.broadcastWhere((c) => c.roomIds.has(roomId) && c.id !== clientId, {
6518
+ type: "member_left",
6519
+ payload: {
6520
+ roomId,
6521
+ userId: client.userId,
6522
+ clientId,
6523
+ timestamp: Date.now()
6524
+ }
6525
+ });
6526
+ } catch {}
6514
6527
  await this.roomManager.leaveRoom(roomId, client.userId);
6515
6528
  await this.emit("client_left_room", { clientId, roomId });
6516
6529
  }
@@ -6527,7 +6540,7 @@ class BaseServer extends TypedEventEmitter {
6527
6540
  return;
6528
6541
  }
6529
6542
  if (this.presenceManager?.isEnabled() && client.userId && client.authenticated) {
6530
- await this.updatePresenceActivity(client.userId, clientId, "message");
6543
+ await this.updatePresenceActivity(client.userId, client.deviceId, "message");
6531
6544
  }
6532
6545
  switch (message.type) {
6533
6546
  case "authenticate":
@@ -6716,6 +6729,17 @@ class BaseServer extends TypedEventEmitter {
6716
6729
  if (!client.roomIds.has(roomId)) {
6717
6730
  continue;
6718
6731
  }
6732
+ try {
6733
+ await this.experimental.broadcastWhere((c) => c.roomIds.has(roomId) && c.id !== clientId, {
6734
+ type: "member_left",
6735
+ payload: {
6736
+ roomId,
6737
+ userId: client.userId,
6738
+ clientId,
6739
+ timestamp: Date.now()
6740
+ }
6741
+ });
6742
+ } catch {}
6719
6743
  await this.roomManager.leaveRoom(roomId, client.userId);
6720
6744
  client.roomIds.delete(roomId);
6721
6745
  await this.emit("client_left_room", { clientId, roomId });
@@ -6813,10 +6837,12 @@ class BaseServer extends TypedEventEmitter {
6813
6837
  }
6814
6838
  }
6815
6839
  async sendToClient(clientId, message) {
6840
+ const messageId = message.id || this.generateId();
6841
+ const { id: _id, ...messageWithoutId } = message;
6816
6842
  const transportMessage = {
6817
- id: this.generateId(),
6843
+ id: messageId,
6818
6844
  type: "server_message",
6819
- payload: { clientId, ...message },
6845
+ payload: { clientId, ...messageWithoutId },
6820
6846
  timestamp: Date.now()
6821
6847
  };
6822
6848
  await this.transport.send(transportMessage);
@@ -6888,7 +6914,16 @@ class BaseServer extends TypedEventEmitter {
6888
6914
  });
6889
6915
  }
6890
6916
  getDeviceIdFromClientId(clientId) {
6891
- return clientId;
6917
+ const client = this.clients.get(clientId);
6918
+ return client?.deviceId ?? clientId;
6919
+ }
6920
+ setClientDeviceId(clientId, deviceId) {
6921
+ const client = this.clients.get(clientId);
6922
+ if (client) {
6923
+ client.deviceId = deviceId;
6924
+ return true;
6925
+ }
6926
+ return false;
6892
6927
  }
6893
6928
  }
6894
6929
  // src/server/ServerBuilder.ts
@@ -7057,4 +7092,4 @@ export {
7057
7092
  BaseClient
7058
7093
  };
7059
7094
 
7060
- //# debugId=A1A2F55B1633C22A64756E2164756E21
7095
+ //# debugId=2344FC62E16D571364756E2164756E21