@principal-ai/control-tower-core 0.3.2 → 0.4.1

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
@@ -3501,6 +3501,128 @@ class DefaultPresenceManager extends PresenceManager {
3501
3501
  getUniqueUserCount() {
3502
3502
  return this.userPresences.size + this.gracePeriodEntries.size;
3503
3503
  }
3504
+ serializePresence(presence) {
3505
+ const { devices, extended, ...rest } = presence;
3506
+ return {
3507
+ ...rest,
3508
+ devices: Object.fromEntries(devices),
3509
+ ...extended || {}
3510
+ };
3511
+ }
3512
+ async handlePresenceMessage(userId, deviceId, message, sendResponse) {
3513
+ switch (message.type) {
3514
+ case "presence:get_users": {
3515
+ const onlineUsers = await this.getOnlineUsers();
3516
+ const users = onlineUsers.map((u) => this.serializePresence(u));
3517
+ const response = {
3518
+ users,
3519
+ stats: {
3520
+ totalOnline: users.length
3521
+ }
3522
+ };
3523
+ await sendResponse({ type: "presence:get_users", payload: response });
3524
+ return true;
3525
+ }
3526
+ case "presence:get_user": {
3527
+ const { userId: targetUserId } = message.payload;
3528
+ const userPresence = await this.getUserPresence(targetUserId);
3529
+ const response = {
3530
+ user: userPresence ? this.serializePresence(userPresence) : null
3531
+ };
3532
+ await sendResponse({ type: "presence:get_user", payload: response });
3533
+ return true;
3534
+ }
3535
+ case "presence:set_status": {
3536
+ const { status, statusMessage } = message.payload;
3537
+ await this.setUserStatus(userId, status);
3538
+ if (this.config.broadcastPresenceUpdates && this.server) {
3539
+ const experimental = this.server.experimental;
3540
+ await experimental?.broadcastAuthenticated({
3541
+ type: "presence:status_changed",
3542
+ payload: { userId, status, statusMessage }
3543
+ });
3544
+ }
3545
+ const response = { success: true };
3546
+ await sendResponse({ type: "presence:set_status", payload: response });
3547
+ return true;
3548
+ }
3549
+ case "presence:set_visibility": {
3550
+ const { visible } = message.payload;
3551
+ for (const ext of this.extensions) {
3552
+ if (typeof ext.setVisibility === "function") {
3553
+ ext.setVisibility(userId, visible);
3554
+ break;
3555
+ }
3556
+ }
3557
+ const response = { success: true };
3558
+ await sendResponse({ type: "presence:set_visibility", payload: response });
3559
+ return true;
3560
+ }
3561
+ case "presence:repo_status_update": {
3562
+ const { repoId, gitStatus } = message.payload;
3563
+ let updated = false;
3564
+ for (const ext of this.extensions) {
3565
+ if (typeof ext.updateRepositoryGitStatus === "function") {
3566
+ updated = ext.updateRepositoryGitStatus(userId, repoId, deviceId, gitStatus);
3567
+ break;
3568
+ }
3569
+ }
3570
+ if (!updated) {
3571
+ const response2 = {
3572
+ success: false,
3573
+ message: "Repository session not found"
3574
+ };
3575
+ await sendResponse({ type: "presence:repo_status_update", payload: response2 });
3576
+ return true;
3577
+ }
3578
+ if (this.config.broadcastPresenceUpdates && this.server) {
3579
+ let visible = true;
3580
+ for (const ext of this.extensions) {
3581
+ const shouldShow = await ext.shouldBeVisible?.(userId);
3582
+ if (shouldShow === false) {
3583
+ visible = false;
3584
+ break;
3585
+ }
3586
+ }
3587
+ if (visible) {
3588
+ const experimental = this.server.experimental;
3589
+ await experimental?.broadcastAuthenticated({
3590
+ type: "presence:repo_status_changed",
3591
+ payload: { userId, repoId, deviceId, gitStatus }
3592
+ });
3593
+ }
3594
+ }
3595
+ const response = {
3596
+ success: true,
3597
+ message: "Status updated"
3598
+ };
3599
+ await sendResponse({ type: "presence:repo_status_update", payload: response });
3600
+ return true;
3601
+ }
3602
+ default: {
3603
+ for (const ext of this.extensions) {
3604
+ if (ext.handleMessage) {
3605
+ const result = await ext.handleMessage(userId, deviceId, message.type, message.payload);
3606
+ if (result) {
3607
+ await sendResponse({
3608
+ type: message.type,
3609
+ payload: result.response
3610
+ });
3611
+ if (result.broadcast && this.server) {
3612
+ const experimental = this.server.experimental;
3613
+ await experimental?.broadcastAuthenticated({
3614
+ type: result.broadcast.type,
3615
+ payload: result.broadcast.payload
3616
+ });
3617
+ }
3618
+ return true;
3619
+ }
3620
+ }
3621
+ }
3622
+ return false;
3623
+ }
3624
+ }
3625
+ }
3504
3626
  }
3505
3627
  // src/abstractions/EventEmitter.ts
3506
3628
  class TypedEventEmitter {
@@ -5737,6 +5859,9 @@ class BaseClient extends TypedEventEmitter {
5737
5859
  case "error":
5738
5860
  await this.handleServerError(message.payload);
5739
5861
  break;
5862
+ default:
5863
+ await this.emit(message.type, message.payload);
5864
+ break;
5740
5865
  }
5741
5866
  } catch (error) {
5742
5867
  await this.emit("error", { error });
@@ -5951,6 +6076,12 @@ class PresenceClient extends TypedEventEmitter {
5951
6076
  throw new Error(response.error || "Failed to report repo focused");
5952
6077
  }
5953
6078
  }
6079
+ async updateRepoStatus(repoId, gitStatus) {
6080
+ const response = await this.client.request("presence:repo_status_update", { repoId, gitStatus });
6081
+ if (!response.success) {
6082
+ throw new Error(response.message || "Failed to update repo status");
6083
+ }
6084
+ }
5954
6085
  getClient() {
5955
6086
  return this.client;
5956
6087
  }
@@ -5983,6 +6114,17 @@ class PresenceClient extends TypedEventEmitter {
5983
6114
  });
5984
6115
  }
5985
6116
  });
6117
+ this.client.on("presence:repo_status_changed", (data) => {
6118
+ if (data && typeof data === "object") {
6119
+ const payload = data;
6120
+ this.emit("repoStatusChanged", {
6121
+ userId: payload.userId,
6122
+ repoId: payload.repoId,
6123
+ deviceId: payload.deviceId,
6124
+ gitStatus: payload.gitStatus
6125
+ });
6126
+ }
6127
+ });
5986
6128
  this.client.on("disconnected", () => {
5987
6129
  this.emit("disconnected", {});
5988
6130
  if (this.autoReconnectEnabled) {
@@ -7092,4 +7234,4 @@ export {
7092
7234
  BaseClient
7093
7235
  };
7094
7236
 
7095
- //# debugId=2344FC62E16D571364756E2164756E21
7237
+ //# debugId=1FAB6CDDEC349C3164756E2164756E21