@principal-ai/control-tower-core 0.4.0 → 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 {
@@ -7112,4 +7234,4 @@ export {
7112
7234
  BaseClient
7113
7235
  };
7114
7236
 
7115
- //# debugId=83C48EE48B6503C464756E2164756E21
7237
+ //# debugId=1FAB6CDDEC349C3164756E2164756E21